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

The following are Jave code examples for showing how to use getRenderedSource() 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: 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 2
Project: rastertheque   File: DFTCRIF.java   Source Code and License Vote up 6 votes
/**
 * Creates a new instance of a DFT operator according to the scaling type.
 *
 * @param paramBlock The scaling type.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    
    
    RenderedImage source = paramBlock.getRenderedSource(0);
    EnumeratedParameter scalingType =
        (EnumeratedParameter)paramBlock.getObjectParameter(0);
    EnumeratedParameter dataNature =
        (EnumeratedParameter)paramBlock.getObjectParameter(1);

    FFT fft = new FFT(true, new Integer(scalingType.getValue()), 2);

    return new DFTOpImage(source, renderHints, layout, dataNature, fft);
}
 
Example 3
Project: rastertheque   File: GradientRIF.java   Source Code and License Vote up 6 votes
/**
 * Create a new instance of GradientOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the gradient's
 *                    horizontal kernel & vertical kernel.
 */
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);

    // Get the Horizontal & Vertical kernels
    KernelJAI kern_h = (KernelJAI)paramBlock.getObjectParameter(0);
    KernelJAI kern_v = (KernelJAI)paramBlock.getObjectParameter(1);
    
    return new GradientOpImage(source,
                               extender,
                               renderHints,
                               layout,
                               kern_h,
                               kern_v);
}
 
Example 4
Project: rastertheque   File: ColorQuantizerRIF.java   Source Code and License Vote up 5 votes
/**
    * <p> Creates a new instance of ColorQuantizerOpImage in the
    * rendered layer.  This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image, the color quantization algorithm
    *                    name, the maximum number of colors, the
    *                    parameter for training (the histogram size for
    *                    median-cut, the cycle for neuquant, and maximum tree
    *                    size for oct-tree), and the ROI.
    * @param renderHints RenderingHints.
    */
   public RenderedImage create(ParameterBlock paramBlock,
                               RenderingHints renderHints) {
       RenderedImage source = paramBlock.getRenderedSource(0);

       ImageLayout layout = renderHints == null ? null :
           (ImageLayout)renderHints.get(JAI.KEY_IMAGE_LAYOUT);

       ColorQuantizerType algorithm =
           (ColorQuantizerType)paramBlock.getObjectParameter(0);
       int maxColorNum = paramBlock.getIntParameter(1);
       int upperBound = paramBlock.getIntParameter(2);
       ROI roi= (ROI)paramBlock.getObjectParameter(3);
       int xPeriod = paramBlock.getIntParameter(4);
       int yPeriod = paramBlock.getIntParameter(5);

       // check if 3-band byte-type image
SampleModel sm = source.getSampleModel();
       if (sm.getNumBands() != 3  && sm.getDataType() == DataBuffer.TYPE_BYTE)
           throw new IllegalArgumentException("ColorQuantizerRIF0");

       if (algorithm.equals(ColorQuantizerDescriptor.NEUQUANT))
           return new NeuQuantOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);

       if (algorithm.equals(ColorQuantizerDescriptor.OCTTREE))
           return new OctTreeOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);
       else
           return new MedianCutOpImage(source, (Map)renderHints, layout,
                                       maxColorNum, upperBound, roi,
                                       xPeriod, yPeriod);

   }
 
Example 5
Project: rastertheque   File: ConjugateCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>ConjugateOpImage</code> in the rendered
 * layer.
 *
 * @param paramBlock  The source image of which to take the conjugate.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    return new ConjugateOpImage(paramBlock.getRenderedSource(0),
                                renderHints, layout);
}
 
Example 6
Project: rastertheque   File: IDCTCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of an IDCT operator.
 *
 * @param paramBlock The scaling type.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    
    
    RenderedImage source = paramBlock.getRenderedSource(0);

    return new DCTOpImage(source, renderHints, layout, new FCT(false, 2));
}
 
Example 7
Project: rastertheque   File: DCTCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of a DCT operator.
 *
 * @param paramBlock The scaling type.
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    RenderedImage source = paramBlock.getRenderedSource(0);

    return new DCTOpImage(source, renderHints, layout, new FCT(true, 2));
}
 
Example 8
Project: rastertheque   File: ThresholdCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>ThresholdOpImage</code> in the
 * rendered layer.
 *
 * @param args   The source image and the input parameters.
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    
    
    return new ThresholdOpImage(args.getRenderedSource(0),
                                renderHints,
                                layout,
                                (double[])args.getObjectParameter(0),
                                (double[])args.getObjectParameter(1),
                                (double[])args.getObjectParameter(2));
}
 
Example 9
Project: rastertheque   File: AndCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>AndOpImage</code> in the
 * rendered layer. This method satisifies the implementation of RIF.
 *
 * @param paramBlock   The two source images to be "anded" together.
 * @param renderHints  Optionally contains destination image layout.     
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    return new AndOpImage(paramBlock.getRenderedSource(0),
                          paramBlock.getRenderedSource(1),
                          renderHints,
                          layout);
}
 
Example 10
Project: rastertheque   File: AddConstCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>AddConstOpImage</code> in the
 * rendered layer.
 *
 * @param args   The source image and the constants.
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    return new AddConstOpImage(args.getRenderedSource(0),
                               renderHints,
                               layout,
                               (double[])args.getObjectParameter(0));
}
 
Example 11
Project: rastertheque   File: NotCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>NotOpImage</code> in the
 * rendered layer. This method satisifies the implementation of RIF.
 *
 * @param paramBlock   The source image to perform the logical "not"
 *                     operation on.
 * @param renderHints  Optionally contains destination image layout.     
 */
public RenderedImage create(ParameterBlock paramBlock,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    return new NotOpImage(paramBlock.getRenderedSource(0),
                          renderHints,
     layout);
}
 
Example 12
Project: rastertheque   File: BorderRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>BorderOpImage</code>
 * in the rendered layer.
 *
 * @param args   The source image and the border information
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    RenderedImage source = args.getRenderedSource(0);
    int leftPad = args.getIntParameter(0);
    int rightPad = args.getIntParameter(1);
    int topPad = args.getIntParameter(2);
    int bottomPad = args.getIntParameter(3);
    BorderExtender type =
        (BorderExtender)args.getObjectParameter(4);

    if (type ==
        BorderExtender.createInstance(BorderExtender.BORDER_WRAP)) {
        int minX = source.getMinX() - leftPad;
        int minY = source.getMinY() - topPad;
        int width = source.getWidth() + leftPad + rightPad;
        int height = source.getHeight() + topPad + bottomPad;

        return new PatternOpImage(source.getData(),
                                  source.getColorModel(),
                                  minX, minY,
                                  width, height);
    } else {
        return new BorderOpImage(source, renderHints, layout,
                                 leftPad, rightPad, topPad, bottomPad,
                                 type);
    }
}
 
Example 13
Project: rastertheque   File: PiecewiseCRIF.java   Source Code and License Vote up 5 votes
/**
    * Creates a new instance of <code>PiecewiseOpImage</code> in the
    * rendered layer.
    *
    * @param args   The source image and the breakpoints.
    * @param hints  Optionally contains destination image layout.
    */
   public RenderedImage create(ParameterBlock args,
                               RenderingHints renderHints) {
       // Get ImageLayout from renderHints if any.
       ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
       

return new PiecewiseOpImage(args.getRenderedSource(0),
			    renderHints,
			    layout,
			    (float[][][])args.getObjectParameter(0));
   }
 
Example 14
Project: rastertheque   File: BoxFilterRIF.java   Source Code and License Vote up 5 votes
/**
 * Create a new instance of SeparableConvolveOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
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);

    // Get the operation parameters.
    int width = paramBlock.getIntParameter(0);
    int height = paramBlock.getIntParameter(1);
    int xOrigin = paramBlock.getIntParameter(2);
    int yOrigin = paramBlock.getIntParameter(3);

    // Allocate and initialize arrays.
    float[] dataH = new float[width];
    Arrays.fill(dataH, 1.0F/(float)width);
    float[] dataV = null;
    if(height == width) {
        dataV = dataH;
    } else {
        dataV = new float[height];
        Arrays.fill(dataV, 1.0F/(float)height);
    }

    // Construct a separable kernel.
    KernelJAI kernel = new KernelJAI(width, height, xOrigin, yOrigin,
                                     dataH, dataV);

    // Construct and return the OpImage.
    return new SeparableConvolveOpImage(paramBlock.getRenderedSource(0),
                                        extender,
                                        renderHints,
                                        layout,
                                        kernel);
}
 
Example 15
Project: rastertheque   File: LookupCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a new instance of <code>LookupOpImage</code>
 * in the rendered layer.
 *
 * @param args   The source image and the lookup table.
 * @param hints  Optionally contains destination image layout.
 */
public RenderedImage create(ParameterBlock args,
                            RenderingHints renderHints) {
    // Get ImageLayout from renderHints if any.
    ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
    

    return new LookupOpImage(args.getRenderedSource(0),
                             renderHints,
                             layout,
                             (LookupTableJAI)args.getObjectParameter(0));
}
 
Example 16
Project: rastertheque   File: UnsharpMaskRIF.java   Source Code and License Vote up 4 votes
/**
    * Create a new instance of UnsharpMaskOpImage in the rendered layer.
    * This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image, the unsharp mask kernel and
    *			  the gain 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);

// map the input kernel + gain factor to an equivalent
// convolution kernel and then do a normal convolve.
KernelJAI unRotatedKernel =
	ImageUtil.getUnsharpMaskEquivalentKernel(
		(KernelJAI)paramBlock.getObjectParameter(0),
		paramBlock.getFloatParameter(1));

       KernelJAI kJAI = unRotatedKernel.getRotatedKernel();

RenderedImage source = paramBlock.getRenderedSource(0);
       int dataType = source.getSampleModel().getDataType();

       boolean dataTypeOk = (dataType == DataBuffer.TYPE_BYTE  ||
                             dataType == DataBuffer.TYPE_SHORT ||
                             dataType == DataBuffer.TYPE_INT);

       if ((kJAI.getWidth()   == 3) && (kJAI.getHeight()  == 3) &&
           (kJAI.getXOrigin() == 1) && (kJAI.getYOrigin() == 1) && dataTypeOk) {
           return new Convolve3x3OpImage(source,
                                         extender,
                                         renderHints,
                                         layout,
                                         kJAI);
       } else if (kJAI.isSeparable()) {
          return new SeparableConvolveOpImage(source,
                                              extender,
                                              renderHints,
                                              layout,
                                              kJAI);

       } else {
           return new ConvolveOpImage(source,
                                      extender,
                                      renderHints,
                                      layout,
                                      kJAI);
       }
   }
 
Example 17
Project: rastertheque   File: MaxFilterRIF.java   Source Code and License Vote up 4 votes
/**
 * Create a new instance of MaxFilterOpImage in the rendered layer.
 * This method satisfies the implementation of RIF.
 *
 * @param paramBlock  The source image and the convolution kernel.
 */
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);

    MaxFilterShape maskType =
        (MaxFilterShape)paramBlock.getObjectParameter(0);
    int maskSize = paramBlock.getIntParameter(1);
    RenderedImage ri = paramBlock.getRenderedSource(0);
    
    if(maskType.equals(MaxFilterDescriptor.MAX_MASK_SQUARE)) {
       return new MaxFilterSquareOpImage(ri,
                                         extender,
                                         renderHints,
                                         layout,
                                         maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_PLUS)) {
       return new MaxFilterPlusOpImage(ri,
                                       extender,
                                       renderHints,
                                       layout,
                                       maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_X)) {
       return new MaxFilterXOpImage(ri,
                                    extender,
                                    renderHints,
                                    layout,
                                    maskSize);
    } else if(maskType.equals(MaxFilterDescriptor.MAX_MASK_SQUARE_SEPARABLE)) {
       return new MaxFilterSeparableOpImage(ri,
                                            extender,
                                            renderHints,
                                            layout,
                                            maskSize);
    }
    return null;
}
 
Example 18
Project: rastertheque   File: TransposeDescriptor.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.
        PlanarImage src = (PlanarImage)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;
        }

        // Return undefined also if source ROI is empty.
        ROI srcROI = (ROI)property;
        if (srcROI.getBounds().isEmpty()) {
            return java.awt.Image.UndefinedProperty;
        }

        /// This should really create a proper AffineTransform
        /// and transform the ROI with it to avoid forcing
        /// ROI.getAsImage to be called.

        // Retrieve the transpose type and create a nearest neighbor
        // Interpolation object.
        TransposeType transposeType =
            (TransposeType)pb.getObjectParameter(0);
        Interpolation interp =
            Interpolation.getInstance(Interpolation.INTERP_NEAREST);

        // Return the transposed ROI.
        return new ROI(JAI.create("transpose", srcROI.getAsImage(),
                                  transposeType));
    }

    return java.awt.Image.UndefinedProperty;
}
 
Example 19
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 20
Project: rastertheque   File: DilateRIF.java   Source Code and License Vote up 4 votes
/**
    * Create a new instance of DilateOpImage in the rendered layer.
    * This method satisfies the implementation of RIF.
    *
    * @param paramBlock  The source image and the dilation kernel.
    */
   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);

       KernelJAI unRotatedKernel = 
           (KernelJAI)paramBlock.getObjectParameter(0);
       KernelJAI kJAI = unRotatedKernel.getRotatedKernel();

RenderedImage source = paramBlock.getRenderedSource(0);
SampleModel sm = source.getSampleModel();

// check dataType and binary 
       int dataType = sm.getDataType();

       boolean isBinary = (sm instanceof MultiPixelPackedSampleModel) &&
           (sm.getSampleSize(0) == 1) &&
           (dataType == DataBuffer.TYPE_BYTE || 
            dataType == DataBuffer.TYPE_USHORT || 
            dataType == DataBuffer.TYPE_INT);

// possible speed up later: 3x3 with table lookup
if (isBinary){


  return new DilateBinaryOpImage(source,
			 extender,
			 renderHints,
			 layout,
			 kJAI);
}else{
  return new DilateOpImage(source,
			 extender,
			 renderHints,
			 layout,
			 kJAI);
}
   }