Java Code Examples for java.awt.image.renderable.ParameterBlock.getFloatParameter()

The following are Jave code examples for showing how to use getFloatParameter() of the java.awt.image.renderable.ParameterBlock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rastertheque   File: ScaleCRIF.java   Source Code and License Vote up 7 votes
/**
    * Gets the bounding box for the output of <code>ScaleOpImage</code>.
    * This method satisfies the implementation of CRIF.
    */
   public Rectangle2D getBounds2D(ParameterBlock paramBlock) {        

       RenderableImage source = paramBlock.getRenderableSource(0);

       float scale_x = paramBlock.getFloatParameter(0);
       float scale_y = paramBlock.getFloatParameter(1);
       float trans_x = paramBlock.getFloatParameter(2);
       float trans_y = paramBlock.getFloatParameter(3);
       Interpolation interp = (Interpolation)paramBlock.getObjectParameter(4);

// Get the source dimensions
float x0 = (float)source.getMinX();
float y0 = (float)source.getMinY() ;
float w = (float)source.getWidth();
float h = (float)source.getHeight();

// Forward map the source using x0, y0, w and h
float d_x0 = x0 * scale_x + trans_x;
float d_y0 = y0 * scale_y + trans_y;
float d_w = w * scale_x;
float d_h = h * scale_y;

return new Rectangle2D.Float(d_x0, d_y0, d_w, d_h);
   }
 
Example 2
Project: rastertheque   File: RotateCRIF.java   Source Code and License Vote up 6 votes
/**
    * Maps the output RenderContext into the RenderContext for the ith
    * source.
    * This method satisfies the implementation of CRIF.
    *
    * @param i               The index of the source image.
    * @param renderContext   The renderContext being applied to the operation.
    * @param paramBlock      The ParameterBlock containing the sources
    *                        and the translation factors.
    * @param image           The RenderableImageOp from which this method
    *                        was called.
    */
   public RenderContext mapRenderContext(int i,
                                         RenderContext renderContext,
				  ParameterBlock paramBlock,
				  RenderableImage image) {
       float x_center = paramBlock.getFloatParameter(0);
       float y_center = paramBlock.getFloatParameter(1);
       float angle = paramBlock.getFloatParameter(2);

       AffineTransform rotate =
           AffineTransform.getRotateInstance(angle, x_center, y_center);

       RenderContext RC = (RenderContext)renderContext.clone();
       AffineTransform usr2dev = RC.getTransform();
       usr2dev.concatenate(rotate);
RC.setTransform(usr2dev);
return RC;
   }
 
Example 3
Project: rastertheque   File: ScaleDescriptor.java   Source Code and License Vote up 6 votes
/**
 * Validates the input parameters.
 *
 * <p> In addition to the standard checks performed by the
 * superclass method, this method checks that "xScale" and "yScale"
 * are both greater than 0.
 */
protected boolean validateParameters(ParameterBlock args,
                                     StringBuffer msg) {
    if (!super.validateParameters(args, msg)) {
        return false;
    }

    float xScale = args.getFloatParameter(0);
    float yScale = args.getFloatParameter(1);
    if (xScale <= 0 || yScale <= 0) {
        msg.append(getName() + " " +
                   JaiI18N.getString("ScaleDescriptor6"));
 return false;
    }

    return true;
}
 
Example 4
Project: rastertheque   File: TranslateCRIF.java   Source Code and License Vote up 6 votes
/**
 * Gets the bounding box for output of <code>TranslateOpImage</code>.
 * This method satisfies the implementation of CRIF.
 */
public Rectangle2D getBounds2D(ParameterBlock paramBlock) {
    RenderableImage source = paramBlock.getRenderableSource(0);
    float xTrans = paramBlock.getFloatParameter(0);
    float yTrans = paramBlock.getFloatParameter(1);

    return new Rectangle2D.Float(source.getMinX() + xTrans,
                                 source.getMinY() + yTrans,
                                 source.getWidth(),
                                 source.getHeight());
}
 
Example 5
Project: rastertheque   File: ScaleCRIF.java   Source Code and License Vote up 6 votes
/**
    * Maps the output RenderContext into the RenderContext for the ith
    * source.
    * This method satisfies the implementation of CRIF.
    *
    * @param i               The index of the source image.
    * @param renderContext   The renderContext being applied to the operation.
    * @param paramBlock      The ParameterBlock containing the sources
    *                        and the translation factors.
    * @param image           The RenderableImageOp from which this method
    *                        was called.
    */
   public RenderContext mapRenderContext(int i,
                                         RenderContext renderContext,
				  ParameterBlock paramBlock,
				  RenderableImage image) {

float scale_x = paramBlock.getFloatParameter(0);
       float scale_y = paramBlock.getFloatParameter(1);
       float trans_x = paramBlock.getFloatParameter(2);
       float trans_y = paramBlock.getFloatParameter(3);

       AffineTransform scale = new AffineTransform(scale_x, 0.0, 0.0, scale_y,
                                                   trans_x, trans_y);

       RenderContext RC = (RenderContext)renderContext.clone();
       AffineTransform usr2dev = RC.getTransform();
       usr2dev.concatenate(scale);
RC.setTransform(usr2dev);
return RC;
   }
 
Example 6
Project: rastertheque   File: CropCRIF.java   Source Code and License Vote up 6 votes
/**
 * Creates a new instance of <code>CropOpImage</code> in the
 * rendered layer.
 *
 * @param args   The source image and bounding rectangle
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get the source image.
    RenderedImage src = (RenderedImage)args.getRenderedSource(0);

    // Get the parameters.
    float originX = args.getFloatParameter(0);
    float originY = args.getFloatParameter(1);
    float width   = args.getFloatParameter(2);
    float height  = args.getFloatParameter(3);

    // Return the OpImage.
    return new CropOpImage(src,
                           originX,
                           originY,
                           width,
                           height);
}
 
Example 7
Project: rastertheque   File: SubsampleBinaryToGrayCRIF.java   Source Code and License Vote up 6 votes
/**
    * Maps the output RenderContext into the RenderContext for the ith
    * source.
    * This method satisfies the implementation of CRIF.
    *
    * @param i               The index of the source image.
    * @param renderContext   The renderContext being applied to the operation.
    * @param paramBlock      The ParameterBlock containing the sources
    *                        and the translation factors.
    * @param image           The RenderableImageOp from which this method
    *                        was called.
    */
   public RenderContext mapRenderContext(int i,
                                         RenderContext renderContext,
				  ParameterBlock paramBlock,
				  RenderableImage image) {

float scale_x = paramBlock.getFloatParameter(0);
       float scale_y = paramBlock.getFloatParameter(1);

       AffineTransform scale = new AffineTransform(scale_x, 0.0, 0.0, scale_y,
                                                   0.0, 0.0);

       RenderContext RC = (RenderContext)renderContext.clone();
       AffineTransform usr2dev = RC.getTransform();
       usr2dev.concatenate(scale);
RC.setTransform(usr2dev);
return RC;
   }
 
Example 8
Project: rastertheque   File: SubsampleBinaryToGrayCRIF.java   Source Code and License Vote up 6 votes
/**
    * Gets the bounding box for the output of <code>SubsampleBinaryToGrayOpImage</code>.
    * This method satisfies the implementation of CRIF.
    */
   public Rectangle2D getBounds2D(ParameterBlock paramBlock) {        

       RenderableImage source = paramBlock.getRenderableSource(0);

       float scale_x = paramBlock.getFloatParameter(0);
       float scale_y = paramBlock.getFloatParameter(1);

// Get the source dimensions
float x0 = (float)source.getMinX();
float y0 = (float)source.getMinY() ;
float w = (float)source.getWidth();
float h = (float)source.getHeight();

// Forward map the source using x0, y0, w and h
float d_x0 = x0 * scale_x;
float d_y0 = y0 * scale_y;
float d_w = w * scale_x;
float d_h = h * scale_y;

// debugging
// System.out.println("*** CRIF getBounds2D() ");

return new Rectangle2D.Float(d_x0, d_y0, d_w, d_h);
   }
 
Example 9
Project: rastertheque   File: CropDescriptor.java   Source Code and License Vote up 6 votes
/**
 * Validates the input source and parameters in the renderable mode.
 *
 * <p> In addition to the standard checks performed by the
 * superclass method, this method checks that "x", "y", "width",
 * and "height" form a rectangle that is not empty and that
 * is fully contained within the bounds of the source image.
 */
private boolean validateRenderableArgs(ParameterBlock args,
                                           StringBuffer msg) {
    // Get parameters.
    float x_req = args.getFloatParameter(0);
    float y_req = args.getFloatParameter(1);
    float w_req = args.getFloatParameter(2);
    float h_req = args.getFloatParameter(3);

    // Create required rectangle.
    Rectangle2D rect_req =
        new Rectangle2D.Float(x_req, y_req, w_req, h_req);

    // Check for an empty rectangle.
    if(rect_req.isEmpty()) {
        msg.append(getName() + " " +
                   JaiI18N.getString("CropDescriptor5"));
        return false;
    }

    // Check for out-of-bounds
    RenderableImage src = (RenderableImage)args.getSource(0);

    Rectangle2D rect_src =
        new Rectangle2D.Float(src.getMinX(),
                              src.getMinY(),
                              src.getWidth(),
                              src.getHeight());

    if (!rect_src.contains(rect_req)) {
        msg.append(getName() + " " +
                   JaiI18N.getString("CropDescriptor6"));
        return false;
    }

    return true;
}
 
Example 10
Project: rastertheque   File: CropCRIF.java   Source Code and License Vote up 5 votes
/**
 * Returns the bounding box for the output of the operation.
 *
 * @param paramBlock A <code>ParameterBlock</code> containing the
 *        renderable sources and parameters of the operation.
 * @return A <code>Rectangle2D</code> specifying the bounding box.
 */
public Rectangle2D getBounds2D(ParameterBlock paramBlock) {
    // Return a rectangle representing the desired bounds.
    return new Rectangle2D.Float(paramBlock.getFloatParameter(0),
                                 paramBlock.getFloatParameter(1),
                                 paramBlock.getFloatParameter(2),
                                 paramBlock.getFloatParameter(3));
}
 
Example 11
Project: rastertheque   File: CropDescriptor.java   Source Code and License Vote up 5 votes
/**
    * Validates the input source and parameters in the rendered mode.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "x", "y", "width",
    * and "height" form a rectangle that is not empty and that
    * is fully contained within the bounds of the source image.
    */
   private boolean validateRenderedArgs(ParameterBlock args,
                                    StringBuffer msg) {

       // Get parameters.
       float x_req = args.getFloatParameter(0);
       float y_req = args.getFloatParameter(1);
       float w_req = args.getFloatParameter(2);
       float h_req = args.getFloatParameter(3);

       // Create required rectangle.
       Rectangle rect_req =
           (new Rectangle2D.Float(x_req, y_req, w_req, h_req)).getBounds();

       // Check for an empty rectangle.
       if(rect_req.isEmpty()) {
           msg.append(getName() + " " +
                      JaiI18N.getString("CropDescriptor5"));
           return false;
       }

       // Check for out-of-bounds
       RenderedImage src = (RenderedImage)args.getSource(0);

Rectangle srcBounds = 
  new Rectangle(src.getMinX(),
		src.getMinY(),
		src.getWidth(),
		src.getHeight());

       if (!srcBounds.contains(rect_req)) {
           msg.append(getName() + " " +
                      JaiI18N.getString("CropDescriptor6"));
           return false;
       }

       return true;
   }
 
Example 12
Project: rastertheque   File: SubsampleBinaryToGrayDescriptor.java   Source Code and License Vote up 5 votes
/**
    * Validates the input parameters.
    *
    * <p> In addition to the standard checks performed by the
    * superclass method, this method checks that "xScale" and "yScale"
    * are both greater than 0 and less than or equal to 1.
    *
    * <p> The src image must be a binary, a one band, one bit
    * per pixel image with a <code> MultiPixelPackedSampleModel</code>.
    */
   protected boolean validateParameters(ParameterBlock args,
                                        StringBuffer msg) {
       if (!super.validateParameters(args, msg)) {
           return false;
       }

       // Checks for source to be Binary and Dest Grayscale
       // to be in the RIF 

RenderedImage src = (RenderedImage)args.getSource(0);

PixelAccessor srcPA = new PixelAccessor(src);
if (!srcPA.isPacked || !srcPA.isMultiPixelPackedSM){
           msg.append(getName() + " " +
                      JaiI18N.getString("SubsampleBinaryToGray3"));
    return false;	  
}

       float xScale = args.getFloatParameter(0);
       float yScale = args.getFloatParameter(1);
       if (xScale <= 0.0F || yScale <= 0.0F || xScale > 1.0F || yScale > 1.0F) {
           msg.append(getName() + " " +
                      JaiI18N.getString("SubsampleBinaryToGray1") + " or " +
                      JaiI18N.getString("SubsampleBinaryToGray2"));
    return false;
       }

       return true;
   }
 
Example 13
Project: rastertheque   File: ConstantCRIF.java   Source Code and License Vote up 4 votes
/**
 * Creates a new instance of <code>ConstantOpImage</code>
 * in the renderable layer. This method satisfies the
 * implementation of CRIF.
 *
 * @pram renderContext  Rendering information.
 * @param paramBlock    The image layout for the output of
 *                      <code>ConstantOpImage</code>
 *                      and the constant pixel value.
 */
public RenderedImage create(RenderContext renderContext,
                            ParameterBlock paramBlock) {
    float minX = 0;
    float minY = 0;
    float width = paramBlock.getFloatParameter(0);
    float height = paramBlock.getFloatParameter(1);
    Number[] bandValues = (Number[])paramBlock.getObjectParameter(2);

    AffineTransform trans = renderContext.getTransform();
    float maxX, maxY;
    float[] ptSrc = new float[8];
    float[] ptDst = new float[8];

    ptSrc[0] = minX;
    ptSrc[1] = minY;
    ptSrc[2] = minX + width;
    ptSrc[3] = minY;
    ptSrc[4] = minX + width;
    ptSrc[5] = minY + height;
    ptSrc[6] = minX;
    ptSrc[7] = minY + height;
    trans.transform(ptSrc, 0, ptDst, 0, 4);
    
    minX = Math.min(ptDst[0], ptDst[2]);
    minX = Math.min(minX, ptDst[4]);
    minX = Math.min(minX, ptDst[6]);

    maxX = Math.max(ptDst[0], ptDst[2]);
    maxX = Math.max(maxX, ptDst[4]);
    maxX = Math.max(maxX, ptDst[6]);

    minY = Math.min(ptDst[1], ptDst[3]);
    minY = Math.min(minY, ptDst[5]);
    minY = Math.min(minY, ptDst[7]);

    maxY = Math.max(ptDst[1], ptDst[3]);
    maxY = Math.max(maxY, ptDst[5]);
    maxY = Math.max(maxY, ptDst[7]);

    int iMinX = (int)minX;
    int iMinY = (int)minY;
    int iWidth = (int)maxX - iMinX;
    int iHeight = (int)maxY - iMinY;

    return new ConstantOpImage(iMinX, iMinY, iWidth, iHeight,
                               Math.min(iWidth, DEFAULT_TILE_SIZE),
                               Math.min(iHeight, DEFAULT_TILE_SIZE),
                               bandValues);
}
 
Example 14
Project: rastertheque   File: RenderableCRIF.java   Source Code and License Vote up 4 votes
/**
 * Creates a RenderableImage pyramid from the source and parameters.
 * If the down sampler operation chain does not decrease both the
 * width and height at a given level an IllegalArgumentException will
 * be thrown.
 *
 * @param paramBlock The ParameterBlock containing a single RenderedImage
 * source and parameters sufficient to create an image pyramid.
 */
private RenderableImage createRenderable(ParameterBlock paramBlock) {
    // Create the Hashtable "just in time".
    if(mresTable == null) {
        mresTable = new Hashtable();
    }

    // Check for a SoftReference hashed on a ParameterBlock-derived key.
    Object key = getKey(paramBlock);
    SoftReference ref = (SoftReference)mresTable.get(key);

    // Retrieve the image from the SoftReference if possible.
    RenderableImage mres = null;
    if(ref != null && (mres = (RenderableImage)ref.get()) == null) {
        // null referent: remove the ParameterBlock key from the Hashtable.
        mresTable.remove(key);
    }

    // Derive the image if necessary.
    if(mres == null) {
        // Retrieve the source and parameters.
        RenderedImage source = paramBlock.getRenderedSource(0);
        RenderedOp downSampler =
            (RenderedOp)paramBlock.getObjectParameter(0);
        int maxLowResDim = paramBlock.getIntParameter(1);
        float minX = paramBlock.getFloatParameter(2);
        float minY = paramBlock.getFloatParameter(3);
        float height = paramBlock.getFloatParameter(4);

        // Create an image pyramid.
        ImageMIPMap pyramid = new ImageMIPMap(source, downSampler);

        // Create a Vector of RenderedImages from the pyramid.
        Vector sourceVector = new Vector();
        RenderedImage currentImage = pyramid.getCurrentImage();
        sourceVector.add(currentImage);
        while(currentImage.getWidth() > maxLowResDim ||
              currentImage.getHeight() > maxLowResDim) {
            RenderedImage nextImage = pyramid.getDownImage();
            if(nextImage.getWidth() >= currentImage.getWidth() ||
               nextImage.getHeight() >= currentImage.getHeight()) {
                throw new IllegalArgumentException(JaiI18N.getString("RenderableCRIF0"));
            }
            sourceVector.add(nextImage);
            currentImage = nextImage;
        }

        // Create a RenderableImage
        mres = new MultiResolutionRenderableImage(sourceVector,
                                                  minX, minY, height);

        // Store a SoftReference to the RenderableImage in the Hashtable.
        mresTable.put(key, new SoftReference(mres));
    }

    return mres;
}
 
Example 15
Project: rastertheque   File: ImageFunctionRIF.java   Source Code and License Vote up 4 votes
/**
 * Creates a new instance of ImageFunctionOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image, the X and Y scale factor,
 *                    and the interpolation method for resampling.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    ImageFunction function =
        (ImageFunction)paramBlock.getObjectParameter(0);

    // Ascertain that a supplied SampleModel has the requisite
    // number of bands vis-a-vis the ImageFunction.
    int numBandsRequired = function.isComplex() ?
        function.getNumElements() * 2 : function.getNumElements();
    if(layout != null &&
       layout.isValid(ImageLayout.SAMPLE_MODEL_MASK) &&
       layout.getSampleModel(null).getNumBands() != numBandsRequired ) {
        throw new RuntimeException(JaiI18N.getString("ImageFunctionRIF0"));
    }

    int minX = 0;
    int minY = 0;
    if (layout != null) {
        if (layout.isValid(ImageLayout.MIN_X_MASK)) {
            minX = layout.getMinX(null);
        }
        if (layout.isValid(ImageLayout.MIN_Y_MASK)) {
            minY = layout.getMinX(null);
        }
    }

    int width = paramBlock.getIntParameter(1);
    int height = paramBlock.getIntParameter(2);
    float xScale = paramBlock.getFloatParameter(3);
    float yScale = paramBlock.getFloatParameter(4);
    float xTrans = paramBlock.getFloatParameter(5);
    float yTrans = paramBlock.getFloatParameter(6);

    return new ImageFunctionOpImage(function,
                                    minX, minY,
                                    width, height,
                                    xScale, yScale,
                                    xTrans, yTrans,
                                    renderHints, layout);
}
 
Example 16
Project: rastertheque   File: SubsampleBinaryToGrayCRIF.java   Source Code and License Vote up 4 votes
/**
    * Creates a new instance of SubsampleBinaryToGrayOpImage in the rendered layer.
    * This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image, the X and Y scale factor
    */
   public RenderedImage create(ParameterBlock paramBlock,
                               RenderingHints renderHints) {
       // Get ImageLayout from renderHints if any.
       ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
       

       // Get BorderExtender from renderHints if any.
       BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

       RenderedImage source = paramBlock.getRenderedSource(0);
       float xScale = paramBlock.getFloatParameter(0);
       float yScale = paramBlock.getFloatParameter(1);

// Check and see if we are scaling by 1.0 in both x and y and no
       // translations. If so call the copy operation.
if (xScale == 1.0F && yScale == 1.0F){
    return new CopyOpImage(source, renderHints, layout);
}


       // The image is assumed to have
       // a MultiPixelPackedSampleModel and a byte, ushort,
       // or int DataBuffer we can access the pixel data directly.
       // Note that there is a potential loophole that has not been
       // resolved by Java2D as to whether the underlying DataBuffer
       // must be of one of the standard types.  Here we make the
       // assumption that it will be -- we can't check without
       // forcing an actual tile to be computed.
       //
       SampleModel sm = source.getSampleModel();
       if ((sm instanceof MultiPixelPackedSampleModel) &&
           (sm.getSampleSize(0) == 1) &&
           (sm.getDataType() == DataBuffer.TYPE_BYTE || 
            sm.getDataType() == DataBuffer.TYPE_USHORT || 
            sm.getDataType() == DataBuffer.TYPE_INT)) {
     
     int srcWidth = source.getWidth();
     int srcHeight= source.getHeight();
     float floatTol = .1F * Math.min(xScale/(srcWidth*xScale+1.0F), yScale/(srcHeight*yScale+1.0F));
     int invScale = (int) Math.round(1.0F/xScale);
     if(Math.abs((float)invScale - 1.0F/xScale) < floatTol  &&
	Math.abs((float)invScale - 1.0F/yScale) < floatTol){
       switch (invScale){
       case 2:
	 return new SubsampleBinaryToGray2x2OpImage(source, layout, renderHints);
       case 4:
	 return new SubsampleBinaryToGray4x4OpImage(source, layout, renderHints);
       default:
	 break;
       }
     }
     return new SubsampleBinaryToGrayOpImage(source,
					     layout,
					     renderHints,
					     xScale,
					     yScale);
     
}else{
    throw 
	new IllegalArgumentException(JaiI18N.getString("SubsampleBinaryToGray3"));
}
   }
 
Example 17
Project: rastertheque   File: RotateDescriptor.java   Source Code and License Vote up 4 votes
/**
 * Returns the specified property.
 *
 * @param name  Property name.
 * @param opNode Operation node.
 */
public Object getProperty(String name,
                          Object opNode) {
    validate(name, opNode);

    if(opNode instanceof RenderedOp &&
       name.equalsIgnoreCase("roi")) {
        RenderedOp op = (RenderedOp)opNode;

        ParameterBlock pb = op.getParameterBlock();

        // Retrieve the rendered source image and its ROI.
        RenderedImage src = pb.getRenderedSource(0);
        Object property = src.getProperty("ROI");
        if (property == null ||
            property.equals(java.awt.Image.UndefinedProperty) ||
            !(property instanceof ROI)) {
            return java.awt.Image.UndefinedProperty;
        }
        ROI srcROI = (ROI)property;

        // Retrieve the Interpolation object.
        Interpolation interp = (Interpolation)pb.getObjectParameter(3);

        // Determine the effective source bounds.
        Rectangle srcBounds = null;
        PlanarImage dst = op.getRendering();
        if (dst instanceof GeometricOpImage &&
            ((GeometricOpImage)dst).getBorderExtender() == null) {
            srcBounds =
                new Rectangle(src.getMinX() + interp.getLeftPadding(),
                              src.getMinY() + interp.getTopPadding(),
                              src.getWidth() - interp.getWidth() + 1,
                              src.getHeight() - interp.getHeight() + 1);
        } else {
            srcBounds = new Rectangle(src.getMinX(),
	  src.getMinY(),
	  src.getWidth(),
	  src.getHeight());
        }

        // If necessary, clip the ROI to the effective source bounds.
        if(!srcBounds.contains(srcROI.getBounds())) {
            srcROI = srcROI.intersect(new ROIShape(srcBounds));
        }

        // Retrieve the translation and rotation angle.
 double xorig = (double)pb.getFloatParameter(0);
 double yorig = (double)pb.getFloatParameter(1);
        double angle = (double)pb.getFloatParameter(2);

        // Create an transform representing the rotation.
        AffineTransform transform =
  AffineTransform.getRotateInstance(angle, xorig, yorig);

        // Create the rotated/translated ROI.
        ROI dstROI = srcROI.transform(transform);

        // Retrieve the destination bounds.
        Rectangle dstBounds = op.getBounds();

        // If necessary, clip the rotated ROI to the destination bounds.
        if(!dstBounds.contains(dstROI.getBounds())) {
            dstROI = dstROI.intersect(new ROIShape(dstBounds));
        }

        // Return the rotated and possibly clipped ROI.
        return dstROI;
    }

    return java.awt.Image.UndefinedProperty;
}
 
Example 18
Project: rastertheque   File: SubsampleBinaryToGrayDescriptor.java   Source Code and License Vote up 4 votes
/**
 * Returns the specified property.
 *
 * @param name  Property name.
 * @param opNode Operation node.
 */
public Object getProperty(String name,
                          Object opNode) {
    validate(name, opNode);

    if(opNode instanceof RenderedOp &&
       name.equalsIgnoreCase("roi")) {
        RenderedOp op = (RenderedOp)opNode;

        ParameterBlock pb = op.getParameterBlock();

        // Retrieve the rendered source image and its ROI.
        RenderedImage src = pb.getRenderedSource(0);

        Object property = src.getProperty("ROI");
        if (property == null ||
            property.equals(java.awt.Image.UndefinedProperty) ||
            !(property instanceof ROI)) {
            return java.awt.Image.UndefinedProperty;
        }
        ROI srcROI = (ROI)property;

        // Determine the effective source bounds.
        Rectangle srcBounds = new Rectangle(src.getMinX(),
		src.getMinY(),
		src.getWidth(),
		src.getHeight());

        // If necessary, clip the ROI to the effective source bounds.
        if(!srcBounds.contains(srcROI.getBounds())) {
            srcROI = srcROI.intersect(new ROIShape(srcBounds));
        }

        // Retrieve the scale factors and translation values.
        float sx = pb.getFloatParameter(0);
        float sy = pb.getFloatParameter(1);

        // Create an equivalent transform.
        AffineTransform transform =
            new AffineTransform(sx, 0.0, 0.0, sy, 0.0, 0.0);

        // Create the scaled ROI.
        ROI dstROI = srcROI.transform(transform);

        // Retrieve the destination bounds.
        Rectangle dstBounds = op.getBounds();

        // If necessary, clip the warped ROI to the destination bounds.
        if(!dstBounds.contains(dstROI.getBounds())) {
            dstROI = dstROI.intersect(new ROIShape(dstBounds));
        }

        // Return the warped and possibly clipped ROI.
        return dstROI;
    }

    return java.awt.Image.UndefinedProperty;
}
 
Example 19
Project: rastertheque   File: TranslateDescriptor.java   Source Code and License Vote up 4 votes
/**
 * Returns the specified property.
 *
 * @param name  Property name.
 * @param opNode Operation node.
 */
public Object getProperty(String name,
                          Object opNode) {
    validate(name, opNode);

    if(opNode instanceof RenderedOp &&
       name.equalsIgnoreCase("roi")) {
        RenderedOp op = (RenderedOp)opNode;

        ParameterBlock pb = op.getParameterBlock();

        // Retrieve the rendered source image and its ROI.
        RenderedImage src = pb.getRenderedSource(0);
        Object property = src.getProperty("ROI");
        if (property == null ||
            property.equals(java.awt.Image.UndefinedProperty) ||
            !(property instanceof ROI)) {
            return java.awt.Image.UndefinedProperty;
        }
        ROI srcROI = (ROI)property;

        // Retrieve the Interpolation object.
        Interpolation interp = (Interpolation)pb.getObjectParameter(2);

        // Determine the effective source bounds.
        Rectangle srcBounds = null;
        PlanarImage dst = op.getRendering();
        if (dst instanceof GeometricOpImage &&
            ((GeometricOpImage)dst).getBorderExtender() == null) {
            srcBounds =
                new Rectangle(src.getMinX() + interp.getLeftPadding(),
                              src.getMinY() + interp.getTopPadding(),
                              src.getWidth() - interp.getWidth() + 1,
                              src.getHeight() - interp.getHeight() + 1);
        } else {
            srcBounds = new Rectangle(src.getMinX(),
	  src.getMinY(),
	  src.getWidth(),
	  src.getHeight());
        }

        // If necessary, clip the ROI to the effective source bounds.
        if(!srcBounds.contains(srcROI.getBounds())) {
            srcROI = srcROI.intersect(new ROIShape(srcBounds));
        }

        // Retrieve the translation values.
        float tx = pb.getFloatParameter(0);
        float ty = pb.getFloatParameter(1);

        // Create a transform representing the translation.
        AffineTransform transform =
            AffineTransform.getTranslateInstance((double) tx,
                                                 (double) ty);
        // Create the translated ROI.
        ROI dstROI = srcROI.transform(transform);

        // Retrieve the destination bounds.
        Rectangle dstBounds = op.getBounds();

        // If necessary, clip the warped ROI to the destination bounds.
        if(!dstBounds.contains(dstROI.getBounds())) {
            dstROI = dstROI.intersect(new ROIShape(dstBounds));
        }

        // Return the warped and possibly clipped ROI.
        return dstROI;
    }

    return java.awt.Image.UndefinedProperty;
}
 
Example 20
Project: rastertheque   File: ScaleDescriptor.java   Source Code and License Vote up 4 votes
/**
 * Returns the specified property.
 *
 * @param name  Property name.
 * @param opNode Operation node.
 */
public Object getProperty(String name,
                          Object opNode) {
    validate(name, opNode);

    if(opNode instanceof RenderedOp &&
       name.equalsIgnoreCase("roi")) {
        RenderedOp op = (RenderedOp)opNode;

        ParameterBlock pb = op.getParameterBlock();

        // Retrieve the rendered source image and its ROI.
        RenderedImage src = pb.getRenderedSource(0);
        Object property = src.getProperty("ROI");
        if (property == null ||
            property.equals(java.awt.Image.UndefinedProperty) ||
            !(property instanceof ROI)) {
            return java.awt.Image.UndefinedProperty;
        }
        ROI srcROI = (ROI)property;

        // Retrieve the Interpolation object.
        Interpolation interp = (Interpolation)pb.getObjectParameter(4);

        // Determine the effective source bounds.
        Rectangle srcBounds = null;
        PlanarImage dst = op.getRendering();
        if (dst instanceof GeometricOpImage &&
            ((GeometricOpImage)dst).getBorderExtender() == null) {
            srcBounds =
                new Rectangle(src.getMinX() + interp.getLeftPadding(),
                              src.getMinY() + interp.getTopPadding(),
                              src.getWidth() - interp.getWidth() + 1,
                              src.getHeight() - interp.getHeight() + 1);
        } else {
            srcBounds = new Rectangle(src.getMinX(),
	  src.getMinY(),
	  src.getWidth(),
	  src.getHeight());
        }

        // If necessary, clip the ROI to the effective source bounds.
        if(!srcBounds.contains(srcROI.getBounds())) {
            srcROI = srcROI.intersect(new ROIShape(srcBounds));
        }

        // Retrieve the scale factors and translation values.
        float sx = pb.getFloatParameter(0);
        float sy = pb.getFloatParameter(1);
        float tx = pb.getFloatParameter(2);
        float ty = pb.getFloatParameter(3);

        // Create an equivalent transform.
        AffineTransform transform =
            new AffineTransform(sx, 0.0, 0.0, sy, tx, ty);

        // Create the scaled ROI.
        ROI dstROI = srcROI.transform(transform);

        // Retrieve the destination bounds.
        Rectangle dstBounds = op.getBounds();

        // If necessary, clip the warped ROI to the destination bounds.
        if(!dstBounds.contains(dstROI.getBounds())) {
            dstROI = dstROI.intersect(new ROIShape(dstBounds));
        }

        // Return the warped and possibly clipped ROI.
        return dstROI;
    }

    return java.awt.Image.UndefinedProperty;
}