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

The following are Jave code examples for showing how to use add() 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: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 6 votes
public static PlanarImage adjustBrightness(PlanarImage src, final double b) {
    final double[][] matrixRGB = {
            {1d, 0D, 0D, b},
            {0D, 1d, 0D, b},
            {0, 0D, 1d, b}

    };


    final double[][] matrixGrey = {
            {1d, b}
    };

    double[][] matrix;
    if (src.getSampleModel().getNumBands() > 1)
        matrix = matrixRGB;
    else matrix = matrixGrey;


    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb);
}
 
Example 2
Project: geoxygene   File: RenderGL11Util.java   Source Code and License Vote up 6 votes
private static void graphicFillLineString(final LineSymbolizer symbolizer, final Shape shape, final Image image, final float size, final double opacity) {
    Double width = new Double(Math.max(1, shape.getBounds2D().getWidth()));
    Double height = new Double(Math.max(1, shape.getBounds2D().getHeight()));
    Double shapeHeight = new Double(size);
    double factor = shapeHeight.doubleValue() / image.getHeight(null);
    Double shapeWidth = new Double(image.getWidth(null) * factor);
    AffineTransform transform = AffineTransform.getTranslateInstance(shape.getBounds2D().getMinX(), shape.getBounds2D().getMinY());
    Image scaledImage = image.getScaledInstance(shapeWidth.intValue(), shapeHeight.intValue(), Image.SCALE_FAST);
    BufferedImage buff = new BufferedImage(shapeWidth.intValue(), shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
    buff.getGraphics().drawImage(scaledImage, 0, 0, null);
    ParameterBlock p = new ParameterBlock();
    p.addSource(buff);
    p.add(width.intValue());
    p.add(height.intValue());
    RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
    BufferedImage bufferedImage = im.getAsBufferedImage();
    glDrawImage(bufferedImage, transform, null);
    bufferedImage.flush();
    im.dispose();
    scaledImage.flush();
    buff.flush();
}
 
Example 3
Project: geoxygene   File: LayerStylesPanel.java   Source Code and License Vote up 6 votes
private static void drawGraphicFillPolygon(Image image, float size, Graphics2D graphics, double opacity, double widthSymbol, double heightSymbol, double offsetYSymbol, double offsetXSymbol) {
    Double shapeHeight = new Double(size);
    double factor = shapeHeight / image.getHeight(null);
    Double shapeWidth = new Double(Math.max(image.getWidth(null) * factor, 1));
    AffineTransform transform = AffineTransform.getTranslateInstance(offsetXSymbol, offsetYSymbol);
    Image scaledImage = image.getScaledInstance(shapeWidth.intValue(), shapeHeight.intValue(), Image.SCALE_FAST);
    BufferedImage buff = new BufferedImage(shapeWidth.intValue(), shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
    buff.getGraphics().drawImage(scaledImage, 0, 0, null);
    ParameterBlock p = new ParameterBlock();
    p.addSource(buff);
    p.add((int) widthSymbol);
    p.add((int) heightSymbol);
    RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
    BufferedImage bufferedImage = im.getAsBufferedImage();
    graphics.drawImage(bufferedImage, transform, null);
    bufferedImage.flush();
    im.dispose();
    scaledImage.flush();
    buff.flush();
}
 
Example 4
Project: geoxygene   File: RasterClutterMethod.java   Source Code and License Vote up 6 votes
private double computeEdgeDensityClutter(PlanarImage image) {
  // first compute the RenderedOp that computes both vertical and
  // horizontal
  // edge detection
  KernelJAI sobelVertKernel = KernelJAI.GRADIENT_MASK_SOBEL_VERTICAL;
  KernelJAI sobelHorizKernel = KernelJAI.GRADIENT_MASK_SOBEL_HORIZONTAL;
  ParameterBlock pb = new ParameterBlock();
  pb.addSource(image);
  pb.add(sobelHorizKernel);
  pb.add(sobelVertKernel);
  RenderedOp renderedOp = JAI.create("gradientmagnitude", pb);
  BufferedImage edgeImage = renderedOp.getAsBufferedImage();

  // then compute a density value, i.e. the mean
  int edgeTotal = 0;
  for (int i = 0; i < edgeImage.getWidth(); i++)
    for (int j = 0; j < edgeImage.getHeight(); j++)
      edgeTotal += Math.abs(edgeImage.getRGB(i, j));

  return Math.abs(edgeTotal / (edgeImage.getWidth() * edgeImage.getHeight()));
}
 
Example 5
Project: Lucee4   File: Image.java   Source Code and License Vote up 6 votes
/**
 * add a border to image
 * @param thickness
 * @param color
 * @param borderType 
 */
public void addBorder(int thickness, Color color, int borderType)  throws ExpressionException{
	
	double colorArray[] = {color.getRed(), color.getGreen(), color.getBlue()};
	BorderExtender borderExtender = new BorderExtenderConstant(colorArray);
	
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(thickness);
	params.add(thickness);
	params.add(thickness);
	params.add(thickness);
	if(BORDER_TYPE_CONSTANT==borderType)	params.add(borderExtender);
	else 	params.add(BorderExtender.createInstance(borderType));
	//else if(BORDER_TYPE_WRAP==borderType)params.add(BorderExtender.createInstance(BorderExtender.BORDER_REFLECT));

	image((JAI.create("border", params)).getAsBufferedImage());
	
}
 
Example 6
Project: Lucee4   File: Image.java   Source Code and License Vote up 6 votes
public void _rotate(float x, float y, float angle, String interpolation) throws ExpressionException {

		float radiansAngle = (float)Math.toRadians(angle);

		// rotation center
		float centerX = (float)getWidth() / 2;
		float centerY = (float)getHeight() / 2;
		
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(image());
		pb.add(centerX);
		pb.add(centerY);
		pb.add(radiansAngle);
		pb.add(new javax.media.jai.InterpolationBicubic(10));
		
		// create a new, rotated image
		image(JAI.create("rotate", pb).getAsBufferedImage());

	}
 
Example 7
Project: Lucee4   File: Image.java   Source Code and License Vote up 6 votes
public void crop(float x, float y, float width, float height) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(x);
	params.add(y);

	float w = getWidth();
	float h = getHeight();
	
	if (w < x + width) params.add(w - x);
	else params.add(width);
	
	if (h < y + height) params.add(h - y);
	else params.add(height);
	
	image(JAI.create("crop", params).getAsBufferedImage());
}
 
Example 8
Project: Lucee   File: Image.java   Source Code and License Vote up 6 votes
public void blur(int blurFactor)  throws ExpressionException{
    ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(blurFactor);
	RenderingHints hint= new RenderingHints(JAI.KEY_BORDER_EXTENDER,BorderExtender.createInstance(1));
	image(JAI.create("boxfilter", params, hint).getAsBufferedImage());
}
 
Example 9
Project: Lucee   File: Image.java   Source Code and License Vote up 6 votes
public void _rotate(float x, float y, float angle, String interpolation) throws ExpressionException {

		float radiansAngle = (float)Math.toRadians(angle);

		// rotation center
		float centerX = (float)getWidth() / 2;
		float centerY = (float)getHeight() / 2;
		
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(image());
		pb.add(centerX);
		pb.add(centerY);
		pb.add(radiansAngle);
		pb.add(new javax.media.jai.InterpolationBicubic(10));
		
		// create a new, rotated image
		image(JAI.create("rotate", pb).getAsBufferedImage());

	}
 
Example 10
Project: Lucee   File: Image.java   Source Code and License Vote up 6 votes
public void crop(float x, float y, float width, float height) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(x);
	params.add(y);

	float w = getWidth();
	float h = getHeight();
	
	if (w < x + width) params.add(w - x);
	else params.add(width);
	
	if (h < y + height) params.add(h - y);
	else params.add(height);
	
	image(JAI.create("crop", params).getAsBufferedImage());
}
 
Example 11
Project: rastertheque   File: ImageMIPMap.java   Source Code and License Vote up 6 votes
/**
 * Constructor.  The down sampler is an "affine" operation that
 * uses the supplied <code>AffineTransform</code> and
 * <code>Interpolation</code> objects.
 * All input parameters are saved by reference.
 *
 * @param image  The image with the highest resolution.
 * @param transform  An affine matrix used with an "affine" operation
 *        to derive the lower resolution images.
 * @param interpolation  The interpolation method for the "affine"
 *        operation.  It may be <code>null</code>, in which case the
 *        default "nearest neighbor" interpolation method is used.
 *
 * @throws IllegalArgumentException if <code>image</code> is
 *         <code>null</code>.
 * @throws IllegalArgumentException if <code>transform</code> is
 *         <code>null</code>.
 */
public ImageMIPMap(RenderedImage image,
                   AffineTransform transform,
                   Interpolation interpolation) {
    this();

    if ( image == null || transform == null ) {
        throw new IllegalArgumentException(JaiI18N.getString("Generic0"));
    }

    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    pb.add(transform);
    pb.add(interpolation);

    downSampler = JAI.create("affine", pb);
    downSampler.removeSources();

    highestImage = image;
    currentImage = highestImage;
}
 
Example 12
Project: rastertheque   File: JAI.java   Source Code and License Vote up 6 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source,
 * 3 <code>float</code> parameters, 1 <code>int</code> parameter and 1 <code>Object</code> parameter.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>float</code> parameter.
 * @param param2  The <code>int</code> parameter.
 * @param param3  The second <code>float</code> parameter.
 * @param param4  The third <code>float</code> parameter.
 * @param param5  The <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                float param1,
                                int param2,
                                float param3,
                                float param4,
                                Object param5) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    args.add(param5);
    return create(opName, args, null);
}
 
Example 13
Project: rastertheque   File: ROI.java   Source Code and License Vote up 6 votes
/**
    * Performs an affine transformation and returns the result as a new
    * ROI.  The transformation is performed by an "Affine" RIF using the
    * indicated interpolation method.
    *
    * @param at an AffineTransform specifying the transformation.
    * @param interp the Interpolation to be used.
    * @throws IllegalArgumentException if at is null.
    * @throws IllegalArgumentException if interp is null.
    * @return a new ROI containing the transformed ROI data.
    */
   public ROI transform(AffineTransform at, Interpolation interp) {

if (at == null) {
    throw new IllegalArgumentException(JaiI18N.getString("ROI5"));
}

if (interp == null) {
    throw new IllegalArgumentException(JaiI18N.getString("ROI6"));
}

       ParameterBlock paramBlock = new ParameterBlock();
       paramBlock.add(at);
       paramBlock.add(interp);
       return performImageOp("Affine", paramBlock, 0, null);
   }
 
Example 14
Project: rastertheque   File: JAI.java   Source Code and License Vote up 6 votes
/**
 * Creates a <code>RenderedOp</code> that takes 2
 * <code>RenderedImage</code> sources and
 * 4 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src1    The first <code>RenderedImage</code> src.
 * @param src2    The second <code>RenderedImage</code> src.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The third <code>Object</code> parameter.
 * @param param4  The fourth <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src1,
                                RenderedImage src2,
                                Object param1,
                                Object param2,
                                Object param3,
                                Object param4) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src1);
    args.addSource(src2);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    return create(opName, args, null);
}
 
Example 15
Project: rastertheque   File: JAI.java   Source Code and License Vote up 6 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1 <code>RenderedImage</code> source,
 * 5 <code>int</code> parameters and 1 <code>Object</code> parameter.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>int</code> parameter.
 * @param param2  The second <code>int</code> parameter.
 * @param param3  The third <code>int</code> parameter.
 * @param param4  The fourth <code>int</code> parameter.
 * @param param5  The fifth <code>int</code> parameter.
 * @param param6  The <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                int param1,
                                int param2,
                                int param3,
                                int param4,
                                int param5,
                                Object param6) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    args.add(param5);
    args.add(param6);
    return create(opName, args, null);
}
 
Example 16
Project: rastertheque   File: JAI.java   Source Code and License Vote up 6 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source and
 * 5 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The third <code>Object</code> parameter.
 * @param param4  The fourth <code>Object</code> parameter.
 * @param param5  The fifth <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                Object param1,
                                Object param2,
                                Object param3,
                                Object param4,
                                Object param5) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    args.add(param5);
    return create(opName, args, null);
}
 
Example 17
Project: dhus-core   File: ProcessingUtils.java   Source Code and License Vote up 5 votes
public static RenderedImage resizeImage(RenderedImage image, int width, int height)
      throws InconsistentImageScale
{
   RenderedImage resizedImage=image;
   // Computes ratio and scale
   float scale=getScale(image.getWidth(),image.getHeight(),width,height);
   
   // Processing resize process
   ParameterBlock pb = new ParameterBlock();
   // The source image
   pb.addSource(resizedImage);
   // The xScale
   pb.add(scale);
   // The yScale
   pb.add(scale);
   // The x translation
   pb.add(0.0F);
   // The y translation
   pb.add(0.0F);
   // The interpolation
   pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
   resizedImage = JAI.create("scale", pb, null);
   
   LOGGER.debug("Image resized to : " + resizedImage.getWidth() + "x"
      + resizedImage.getHeight());
   
   return resizedImage;
}
 
Example 18
Project: cww_framework   File: ImageResize.java   Source Code and License Vote up 5 votes
/**
 * This method takes in an image as a byte array (currently supports GIF, JPG, PNG and
 * possibly other formats) and
 * resizes it to have a width no greater than the pMaxWidth parameter in pixels.
 * It converts the image to a standard
 * quality JPG and returns the byte array of that JPG image.
 *
 * @param pImageData
 *                the image data.
 * @param pMaxWidth
 *                the max width in pixels, 0 means do not scale.
 * @return the resized JPG image.
 * @throws IOException
 *                 if the image could not be manipulated correctly.
 */
public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth) throws IOException {
    InputStream imageInputStream = new ByteArrayInputStream(pImageData);
    // read in the original image from an input stream
    SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
    RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
    ((OpImage) originalImage.getRendering()).setTileCache(null);
    int origImageWidth = originalImage.getWidth();
    // now resize the image
    double scale = 1.0;
    if (pMaxWidth > 0 && origImageWidth > pMaxWidth) {
        scale = (double) pMaxWidth / originalImage.getWidth();
    }
    ParameterBlock paramBlock = new ParameterBlock();
    paramBlock.addSource(originalImage); // The source image
    paramBlock.add(scale); // The xScale
    paramBlock.add(scale); // The yScale
    paramBlock.add(0.0); // The x translation
    paramBlock.add(0.0); // The y translation

    RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    RenderedOp resizedImage = JAI.create(JAI_SUBSAMPLE_AVERAGE_ACTION, paramBlock, qualityHints);

    // lastly, write the newly-resized image to an output stream, in a specific encoding
    ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
    JAI.create(JAI_ENCODE_ACTION, resizedImage, encoderOutputStream, JAI_ENCODE_FORMAT_JPEG, null);
    // Export to Byte Array
    byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
    return resizedImageByteArray;
}
 
Example 19
Project: audiveris   File: TestWarp.java   Source Code and License Vote up 5 votes
/**
 * Creates a new TestWarp object.
 */
public TestWarp (String path)
{
    srcImage = JAI.create("fileload", new ParameterBlock().add(path), null);
    //        srcImage = PictureLoader.loadImages(new File(path), null)
    //                                .get(1);
    //        srcImage = buildPattern(20, 10, 50, 50);
    dimension = new Dimension(srcImage.getWidth(), srcImage.getHeight());
    setPreferredSize(dimension);

    //        float[]        xCoeffs = new float[] { 0f, 1.25f, 0.04f };
    //        float[]        yCoeffs = new float[] { 0f, -0.02f, 1.5f };
    //        Warp           warp = new WarpAffine(xCoeffs, yCoeffs);
    //
    int xStep = 500;
    int xNumCells = 2;
    int yStep = 500;
    int yNumCells = 1;
    float[] warpPositions = new float[]{
        -100f, 0f, 500f, 100f, 1000f, 0f, // top line
        0f, 500f, 500f, 500f, 1000f, 500f
    }; // bot line
    Warp warp = new WarpGrid(0, xStep, xNumCells, 0, yStep, yNumCells, warpPositions);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(invert(srcImage));
    pb.add(warp);
    pb.add(new InterpolationBilinear());
    dstImage = invert(JAI.create("warp", pb));
    ((PlanarImage) dstImage).getTiles();
}
 
Example 20
Project: libraries   File: ImageContainerUtilities.java   Source Code and License Vote up 5 votes
public static RenderedOp crop(
    final RenderedImage renderedImage,
    final float x,
    final float y,
    final float width,
    final float height) {
  final ParameterBlock pb = new ParameterBlock();
  pb.addSource(renderedImage); // The source image
  pb.add(x);
  pb.add(y);
  pb.add(width);
  pb.add(height);
  return JAI.create("Crop", pb); //$NON-NLS-1$
}
 
Example 21
Project: libraries   File: ImageContainerUtilities.java   Source Code and License Vote up 5 votes
public static RenderedOp translate(final RenderedImage renderedImage, final float x, final float y) {
  final ParameterBlock params = new ParameterBlock();
  params.addSource(renderedImage);
  params.add(x);
  params.add(y);
  return JAI.create("Translate", params); //$NON-NLS-1$
}
 
Example 22
Project: orbit-image-analysis   File: MedianFilter.java   Source Code and License Vote up 5 votes
public PlanarImage process() {
    if (!parameterSet) throw new IllegalStateException("parameters not set");
    PlanarImage pi = source;
    //   for (int i=0; i<numIter; i++) {
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(pi);
    pb.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
    pb.add(radius);
    pi = JAI.create("MedianFilter", pb);
    //  }
    return pi;

}
 
Example 23
Project: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 5 votes
private PlanarImage activeChannels(PlanarImage source, boolean redActive, boolean greenActive, boolean blueActive) {
    final double[][] matrix = {
            {redActive ? 1D : 0D, 0D, 0D, 0d},
            {0D, greenActive ? 1D : 0D, 0D, 0d},
            {0D, 0D, blueActive ? 1D : 0D, 0d}
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(source);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, null);
}
 
Example 24
Project: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 5 votes
private RenderedOp convertColorToGray(PlanarImage src, double r, double g, double b) {
    final double[][] matrix = {
            {r, g, b, 0d} // .114D, 0.587D, 0.299D
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, /*ManipulationUtils.getRenderingHints(image)*/null);
}
 
Example 25
Project: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 5 votes
private RenderedOp convertColorToGray(PlanarImage src) {
    final double[][] matrix = {
            //  { 0.114D, 0.587D, 0.299D, 0d } // .114D, 0.587D, 0.299D
            {0.333D, 0.333D, 0.333D, 0d} // .114D, 0.587D, 0.299D
    };
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(matrix);
    return JAI.create("bandcombine", pb, /*ManipulationUtils.getRenderingHints(image)*/null);
}
 
Example 26
Project: orbit-image-analysis   File: TiledImagePainter.java   Source Code and License Vote up 5 votes
public void loadImageSpecial(RawDataFile rdf, int level) throws OrbitImageServletException, SQLException {
    int num = level;
    if (num < 1000)
        num++;   // +1 because orbit file system starts with 1 and not 0 (id, id.1, id.2, ...)  - but not for special layers like slide overview or label (>=1000)
    origImage = null;
    try {
        switch (level) {
            case RawUtilsCommon.LEVEL_LABEL: {
                origImage = new OrbitTiledImagePlanarImage(PlanarImage.wrapRenderedImage(DALConfig.getImageProvider().getLabelImage(rdf)));
                break;
            }
            case RawUtilsCommon.LEVEL_OVERVIEW: {
                origImage = new OrbitTiledImagePlanarImage(PlanarImage.wrapRenderedImage(DALConfig.getImageProvider().getOverviewImage(rdf)));
                break;
            }
            default: {
                origImage = new OrbitTiledImageIOrbitImage(wrapImage(DALConfig.getImageProvider().createOrbitImage(rdf, level)));
                break;
            }
        }
        if (origImage == null) return; // not available
        if (level == RawUtilsCommon.LEVEL_LABEL) {
            float centerX = (float) origImage.getWidth() / 2;
            float centerY = (float) origImage.getHeight() / 2;
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(origImage);
            pb.add(centerX);
            pb.add(centerY);
            pb.add(new Float(Math.toRadians(90)));
            pb.add(new javax.media.jai.InterpolationBicubic(10));
            origImage = JAI.create("rotate", pb);
        }

        setImage(origImage);
        imageName = rdf.toString();
        imageAdjustments = OrbitUtils.getAndParseImageAdjustments(rdf.getRawDataFileId());
    } catch (Exception e) {
        logger.error("Special layer not available for this image.");
    }
}
 
Example 27
Project: geoxygene   File: CartoPlugin.java   Source Code and License Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
  // get the filename
  JFileChooser fc = new JFileChooser();
  fc.setFileFilter(new ImageFileFilter());
  int returnVal = fc.showDialog(null, "Choose the image to assess");
  if (returnVal != JFileChooser.APPROVE_OPTION) {
    return;
  }
  File path = fc.getSelectedFile();
  BufferedImage image;
  try {
    image = ImageIO.read(path);
    TiledImage pImage = new TiledImage(image, true);
    RasterClutterMethod clutterMethod = new RasterClutterMethod(pImage);
    System.out.println(clutterMethod.getEdgeDensityClutter());

    // export image
    KernelJAI sobelVertKernel = KernelJAI.GRADIENT_MASK_SOBEL_VERTICAL;
    KernelJAI sobelHorizKernel = KernelJAI.GRADIENT_MASK_SOBEL_HORIZONTAL;
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    pb.add(sobelHorizKernel);
    pb.add(sobelVertKernel);
    RenderedOp renderedOp = JAI.create("gradientmagnitude", pb);
    BufferedImage edgeImage = renderedOp.getAsBufferedImage();
    File outputfile = new File(path.getParent() + "\\"
        + path.getName().substring(0, path.getName().length() - 4)
        + "_edge.png");
    ImageIO.write(edgeImage, "png", outputfile);
  } catch (IOException e1) {
    e1.printStackTrace();
  }
}
 
Example 28
Project: geoxygene   File: RenderUtil.java   Source Code and License Vote up 5 votes
private static void graphicFillLineString(Shape shape, Image image,
        float size, Graphics2D graphics, double opacity) {
    Double width = new Double(Math.max(1, shape.getBounds2D().getWidth()));
    Double height = new Double(
            Math.max(1, shape.getBounds2D().getHeight()));
    Double shapeHeight = new Double(size);
    double factor = shapeHeight.doubleValue() / image.getHeight(null);
    Double shapeWidth = new Double(image.getWidth(null) * factor);
    AffineTransform transform = AffineTransform.getTranslateInstance(
            shape.getBounds2D().getMinX(), shape.getBounds2D().getMinY());
    Image scaledImage = image.getScaledInstance(shapeWidth.intValue(),
            shapeHeight.intValue(), Image.SCALE_FAST);
    BufferedImage buff = new BufferedImage(shapeWidth.intValue(),
            shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
    buff.getGraphics().drawImage(scaledImage, 0, 0, null);
    ParameterBlock p = new ParameterBlock();
    p.addSource(buff);
    p.add(width.intValue());
    p.add(height.intValue());
    RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
    BufferedImage bufferedImage = im.getAsBufferedImage();
    graphics.drawImage(bufferedImage, transform, null);
    bufferedImage.flush();
    im.dispose();
    scaledImage.flush();
    buff.flush();
}
 
Example 29
Project: geoxygene   File: RenderUtil.java   Source Code and License Vote up 5 votes
private static void graphicFillPolygon(Shape shape, Image image, float size,
        Graphics2D graphics, double opacity) {
    Double width = new Double(Math.max(1, shape.getBounds2D().getWidth()));
    Double height = new Double(
            Math.max(1, shape.getBounds2D().getHeight()));
    Double shapeHeight = new Double(size);
    double factor = shapeHeight / image.getHeight(null);
    Double shapeWidth = new Double(
            Math.max(image.getWidth(null) * factor, 1));
    AffineTransform transform = AffineTransform.getTranslateInstance(
            shape.getBounds2D().getMinX(), shape.getBounds2D().getMinY());
    Image scaledImage = image.getScaledInstance(shapeWidth.intValue(),
            shapeHeight.intValue(), Image.SCALE_FAST);
    BufferedImage buff = new BufferedImage(shapeWidth.intValue(),
            shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
    buff.getGraphics().drawImage(scaledImage, 0, 0, null);
    ParameterBlock p = new ParameterBlock();
    p.addSource(buff);
    p.add(width.intValue());
    p.add(height.intValue());
    RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
    BufferedImage bufferedImage = im.getAsBufferedImage();
    graphics.setComposite(AlphaComposite
            .getInstance(AlphaComposite.SRC_OVER, (float) opacity));
    graphics.drawImage(bufferedImage, transform, null);
    bufferedImage.flush();
    im.dispose();
    scaledImage.flush();
    buff.flush();
}
 
Example 30
Project: qaf   File: ImageCompareUtil.java   Source Code and License Vote up 5 votes
private RenderedImage rescale(RenderedImage i) {
	float scaleW = ((float) baseSize) / i.getWidth();
	float scaleH = ((float) baseSize) / i.getHeight();
	// Scales the original image
	ParameterBlock pb = new ParameterBlock();
	pb.addSource(i);
	pb.add(scaleW);
	pb.add(scaleH);
	pb.add(0.0F);
	pb.add(0.0F);
	pb.add(new InterpolationNearest());
	// Creates a new, scaled image and uses it on the DisplayJAI component
	return JAI.create("scale", pb);
}
 
Example 31
Project: DataHubSystem   File: ProcessingUtils.java   Source Code and License Vote up 5 votes
public static RenderedImage resizeImage(RenderedImage image, int width, int height)
      throws InconsistentImageScale
{
   RenderedImage resizedImage=image;
   // Computes ratio and scale
   float scale=getScale(image.getWidth(),image.getHeight(),width,height);
   
   // Processing resize process
   ParameterBlock pb = new ParameterBlock();
   // The source image
   pb.addSource(resizedImage);
   // The xScale
   pb.add(scale);
   // The yScale
   pb.add(scale);
   // The x translation
   pb.add(0.0F);
   // The y translation
   pb.add(0.0F);
   // The interpolation
   pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
   resizedImage = JAI.create("scale", pb, null);
   
   LOGGER.debug("Image resized to : " + resizedImage.getWidth() + "x"
      + resizedImage.getHeight());
   
   return resizedImage;
}
 
Example 32
Project: Lucee4   File: Image.java   Source Code and License Vote up 5 votes
public void blur(int blurFactor)  throws ExpressionException{
    ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(blurFactor);
	RenderingHints hint= new RenderingHints(JAI.KEY_BORDER_EXTENDER,BorderExtender.createInstance(1));
	image(JAI.create("boxfilter", params, hint).getAsBufferedImage());
}
 
Example 33
Project: Lucee4   File: Image.java   Source Code and License Vote up 5 votes
public void sharpen(float gain)  throws ExpressionException{
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add((Object) null);
	params.add(new Float(gain));
	image(JAI.create("unsharpmask", params).getAsBufferedImage());
}
 
Example 34
Project: Lucee4   File: Image.java   Source Code and License Vote up 5 votes
public Image copy(float x, float y, float width, float height)  throws ExpressionException{
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(x);
	params.add(y);
	params.add(width);
	params.add(height);
	//image(JAI.create("crop", params).getAsBufferedImage());
	return new Image(JAI.create("crop", params).getAsBufferedImage());
}
 
Example 35
Project: irplus   File: JpegThumbnailTransformer.java   Source Code and License Vote up 5 votes
/**
 * Write the file using the JAI libraries.
 * 
 * @param image
 * @param transformFile
 */
private void writeWithJAI(RenderedImage image, File transformFile)
{
	// determine the scale for the x and y of the image
	float xScale = ((float)size)/((float)image.getWidth());
	float yScale = ((float)size)/((float)image.getHeight());
	

	log.debug("xScale = " + xScale + " yScale = " + yScale);
	ParameterBlock pb = new ParameterBlock();
	pb.addSource(image); // The source image
	pb.add(xScale);         // The xScale
	pb.add(yScale);         // The yScale
	pb.add(0.0F);           // The x translation
	pb.add(0.0F);           // The y translation
	
	RenderedImage scale = null;
	
	try
	{
	    scale = JAI.create("scale", pb);
	    JAI.create("filestore", scale, transformFile.getAbsolutePath(), "JPEG");
	}
	finally
	{
		scale = null;
	}
}
 
Example 36
Project: gama   File: ImageUtils.java   Source Code and License Vote up 5 votes
private BufferedImage privateReadFromFile(final File file) throws IOException {
	// System.out.println("READING " + file.getName());
	BufferedImage result = NO_IMAGE;
	if (file == null)
		return result;
	final String name = file.getName();
	String ext = null;
	if (name.contains(".")) {
		ext = name.substring(file.getName().lastIndexOf("."));
	}
	if (tiffExt.contains(ext)) {
		try (FileSeekableStream stream = new FileSeekableStream(file.getAbsolutePath())) {
			final TIFFDecodeParam decodeParam = new TIFFDecodeParam();
			decodeParam.setDecodePaletteAsShorts(true);
			final ParameterBlock params = new ParameterBlock();
			params.add(stream);
			final RenderedOp image1 = JAI.create("tiff", params);
			return image1.getAsBufferedImage();
		}
	} else if (gifExt.contains(ext)) {
		final GifDecoder d = new GifDecoder();
		d.read(new FileInputStream(file.getAbsolutePath()));
		return d.getImage();
	}

	try {
		result = ImageIO.read(file);
	} catch (final Exception e) {
		return NO_IMAGE;
	}
	return result;
}
 
Example 37
Project: Lucee   File: Image.java   Source Code and License Vote up 5 votes
public void sharpen(float gain)  throws ExpressionException{
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add((Object) null);
	params.add(new Float(gain));
	image(JAI.create("unsharpmask", params).getAsBufferedImage());
}
 
Example 38
Project: Lucee   File: Image.java   Source Code and License Vote up 5 votes
public Image copy(float x, float y, float width, float height)  throws ExpressionException{
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(x);
	params.add(y);
	params.add(width);
	params.add(height);
	//image(JAI.create("crop", params).getAsBufferedImage());
	return new Image(JAI.create("crop", params).getAsBufferedImage());
}
 
Example 39
Project: libreveris   File: JaiDewarper.java   Source Code and License Vote up 5 votes
public RenderedImage dewarpImage ()
{
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(Picture.invert(sheet.getPicture().getImage()));
    pb.add(dewarpGrid);
    pb.add(new InterpolationBilinear());

    RenderedImage dewarpedImage = Picture.invert(JAI.create("warp", pb));
    ((PlanarImage) dewarpedImage).getTiles();

    return dewarpedImage;
}
 
Example 40
Project: ant   File: Scale.java   Source Code and License Vote up 5 votes
/**
 * Scale an image.
 * @param image the image to scale.
 * @return the scaled image.
 */
public PlanarImage performScale(PlanarImage image) {
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image);
    float xFl = getWidth();
    float yFl = getHeight();

    if (!xPercent) {
        xFl = xFl / image.getWidth();
    }
    if (!yPercent) {
        yFl = yFl / image.getHeight();
    }

    if ("width".equals(proportions)) {
        yFl = xFl;
    } else if ("height".equals(proportions)) {
        xFl = yFl;
    } else if ("fit".equals(proportions)) {
        yFl = Math.min(xFl, yFl);
        xFl = yFl;
    } else if ("cover".equals(proportions)) {
        yFl = Math.max(xFl, yFl);
        xFl = yFl;
    }

    pb.add(Float.valueOf(xFl));
    pb.add(Float.valueOf(yFl));

    log("\tScaling to " + (xFl * HUNDRED) + "% x "
        + (yFl * HUNDRED) + "%");

    return JAI.create("scale", pb);
}
 
Example 41
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
    * Creates a <code>RenderedOp</code> that takes 1 <code>Object</code> parameter.
    *
    * @param opName  The name of the operation.
    * @param param   The <code>Object</code> parameter.
    */
   public static RenderedOp create(String opName,
                                   Object param) {
ParameterBlock args = new ParameterBlock();
       args.add(param);
return create(opName, args, null);
   }
 
Example 42
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 3 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The third <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                Object param1,
                                Object param2,
                                Object param3) {
    ParameterBlock args = new ParameterBlock();
    args.add(param1);
    args.add(param2);
    args.add(param3);
    return create(opName, args, null);
}
 
Example 43
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 4 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The third <code>Object</code> parameter.
 * @param param4  The fourth <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                Object param1,
                                Object param2,
                                Object param3,
                                Object param4) {
    ParameterBlock args = new ParameterBlock();
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    return create(opName, args, null);
}
 
Example 44
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 2 <code>Object</code> and 2 <code>int</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The first <code>int</code> parameter.
 * @param param3  The second <code>Object</code> parameter.
 * @param param4  The second <code>int</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                Object param1,
                                int param2,
                                Object param3,
                                int param4) {
    ParameterBlock args = new ParameterBlock();
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    return create(opName, args, null);
}
 
Example 45
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source and
 * 4 <code>int</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>int</code> parameter.
 * @param param2  The second <code>int</code> parameter.
 * @param param3  The third <code>int</code> parameter.
 * @param param4  The fourth <code>int</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                int param1,
                                int param2,
                                int param3,
                                int param4) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    return create(opName, args, null);
}
 
Example 46
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source
 * and 2 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                Object param1,
                                Object param2) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    return create(opName, args, null);
}
 
Example 47
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source
 * and 3 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The third <code>Object</code> parameter.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                Object param1,
                                Object param2,
                                Object param3) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    return create(opName, args, null);
}
 
Example 48
Project: rastertheque   File: JAI.java   Source Code and License Vote up 5 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source and
 * 2 <code>Object</code> parameters and 2 <code>int</code> parameters
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>Object</code> parameter.
 * @param param2  The second <code>Object</code> parameter.
 * @param param3  The first <code>int</code> parameter.
 * @param param4  The second <code>int</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                Object param1,
                                Object param2,
                                int param3,
                                int param4) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    args.add(param4);
    return create(opName, args, null);
}
 
Example 49
Project: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 4 votes
public static PlanarImage adjustContrast(PlanarImage src, double red, double green, double blue, double contrast, double brightness, OrbitUtils.ImageAdjustCachedParams cachedParams, TiledImagePainter tipForStats) {

        if (!cachedParams.isContrastAverageSet()) {

            PlanarImage statImg = loadImageForStats(src, tipForStats);

            final int numScan = 200;
            int skipW = Math.max(1, src.getWidth() / numScan);
            int skipH = Math.max(1, src.getHeight() / numScan);

            ParameterBlock mpb = new ParameterBlock();
            mpb.addSource(statImg); // The source image
            mpb.add(null); // null ROI means whole image
            mpb.add(skipW); // 1 check every pixel horizontally
            mpb.add(skipH); // 1 check every pixel vertically

            // Perform the mean operation on the source image
            PlanarImage meanImage = JAI.create("mean", mpb, null);
            // Retrieve the mean pixel value
            double[] mean = (double[]) meanImage.getProperty("mean");
            // Average the mean of all bands
            double sum = 0.0D;
            for (int i = 0; i < mean.length; i++) {
                sum += mean[i];
            }
            cachedParams.setContrastAverage(sum / (double) mean.length);
            cachedParams.setContrastAverageSet(true);
        }
        double average = cachedParams.getContrastAverage();

        // Create the lookup table based on the average mean
        byte[][] lut = new byte[3][256];
        for (int i = 0; i < 256; i++) {
            lut[0][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + red + brightness));
            lut[1][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + green + brightness));
            lut[2][i] = ManipulationUtils.clamp((int) ((average + (i - average) * contrast) + blue + brightness));
        }


        LookupTableJAI lookup = new LookupTableJAI(lut);
        PlanarImage result = JAI.create("lookup", src, lookup);
        result = makeCompatibleSamplemodel(src, result);
        return result;

    }
 
Example 50
Project: qaf   File: ImageCompareUtil.java   Source Code and License Vote up 4 votes
public boolean contains(String reference, String template, Point start) throws Exception {
	RenderedImage ref = (ImageIO.read(new File(reference)));

	// Calculate the signature vector for the reference.
	// Now we need a component to store X images in a stack, where X is the
	// number of images in the same directory as the original one.
	// For each image, calculate its signature and its distance from the
	// reference signature.
	RenderedImage other = ImageIO.read(new File(template));

	int x, y, h, w, th, tw;
	double distance = Double.MAX_VALUE;
	h = ref.getHeight();
	w = ref.getWidth();
	System.out.println("px width: " + ref.getData().getWidth() + "px height: " + ref.getData().getHeight());
	System.out.println("width: " + ref.getWidth() + "height: " + ref.getHeight());
	System.out.println("min x: " + ref.getData().getMinX() + " y: " + ref.getData().getMinY());

	th = other.getHeight();
	tw = other.getWidth();

	for (int r = 0; r <= (h - th); r += 5) {
		for (int c = 0; c <= (w - tw); c += 5) {
			ParameterBlock pb = new ParameterBlock();
			pb.addSource(ref);
			pb.add((float) c);
			pb.add((float) r);
			pb.add((float) tw);
			pb.add((float) th);
			pb.add(new InterpolationNearest());
			// Creates a new, scaled image and uses it on the DisplayJAI
			// component

			try {
				double tdistance = calcDistance(rescale(JAI.create("crop", pb)), rescale(other));
				if ((tdistance < distance)) {
					distance = tdistance;
				}

				if (distance == 0) {
					break;
				}
				System.out.println("distance" + distance + " x: " + r + " y: " + c);
			} catch (Exception e) {
				System.out.print("Error: " + e.toString());
				e.printStackTrace();
			}
		}

		if (distance == 0) {
			break;
		}
	}
	return distance < maxDiff;
}
 
Example 51
Project: cmoct-sourcecode   File: ReactiveHyperimeaTool.java   Source Code and License Vote up 4 votes
public static void saveTiff(final File[] files, File tiffFile)
		throws IOException
{

	class Temp implements Iterator
	{
		File[] images;

		int last = 0;

		public Temp(File[] file)
		{
			this.images = file;
		}

		@Override
		public boolean hasNext()
		{
			// TODO Auto-generated method stub
			return last < images.length;
		}

		@Override
		public Object next()
		{
			try
			{
				BufferedImage img = ImageIO.read(images[last++]);
				return ImageOperations.cropImage(img, new Rectangle(0, 0,
						img.getWidth(), 200));
			} catch (IOException e)
			{
				// TODO Auto-generated catch
				// block
				e.printStackTrace();
			}
			return null;
		}

		@Override
		public void remove()
		{
			// TODO Auto-generated method stub

		}
	}

	Temp fileHolder = new Temp(files);

	TIFFEncodeParam param = new TIFFEncodeParam();
	param.setExtraImages(fileHolder);
	param.setCompression(TIFFEncodeParam.COMPRESSION_NONE);

	ParameterBlock pb = new ParameterBlock();
	OutputStream os = new FileOutputStream(tiffFile);

	pb.addSource(fileHolder.next());
	// pb.addSource ( JAI.create ( "fileload",
	// filename ) ) ;
	pb.add(os);
	pb.add("TIFF");
	pb.add(param);
	JAI.create("encode", pb);
	os.close();

}
 
Example 52
Project: Lucee4   File: Image.java   Source Code and License Vote up 4 votes
public void flip(TransposeType transpose) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(transpose);
	image(JAI.create("transpose", params).getAsBufferedImage());
}
 
Example 53
Project: Lucee   File: Image.java   Source Code and License Vote up 4 votes
/**
 * add a border to image
 * @param thickness
 * @param color
 * @param borderType 
 */
public void addBorder(int thickness, Color color, int borderType)  throws ExpressionException{
	ColorModel cm = image().getColorModel();
	if (((cm instanceof IndexColorModel)) && (cm.hasAlpha()) && (!cm.isAlphaPremultiplied())) {
		image(paletteToARGB(image()));
		cm = image().getColorModel();
	}

	BufferedImage alpha = null;
	if ((cm.getNumComponents() > 3) && (cm.hasAlpha())) {
		alpha = getAlpha(image());
		image(removeAlpha(image()));
	}
	if (alpha != null) {
		ParameterBlock params1 = new ParameterBlock();
		params1.addSource(alpha);
		
		params1.add(thickness); // left
		params1.add(thickness); // right
		params1.add(thickness); // top
		params1.add(thickness); // bottom
		params1.add(new BorderExtenderConstant(new double[] { 255D }));
		
		RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE));
		alpha = JAI.create("border", params1, hints).getAsBufferedImage();
	}

    ParameterBlock params = new ParameterBlock();
    params.addSource(image());
    params.add(thickness); // left
	params.add(thickness); // right
	params.add(thickness); // top
	params.add(thickness); // bottom
    params.add(toBorderExtender(borderType,color));

    image(JAI.create("border", params).getAsBufferedImage());

    if (alpha != null) {
      image(addAlpha(image(), alpha, thickness, thickness));
    }
}
 
Example 54
Project: rastertheque   File: MultiResolutionRenderableImage.java   Source Code and License Vote up 4 votes
/**
 * Returns a rendering with a given width, height, and rendering
 * hints.
 *
 * <p> If a JAI rendering hint named
 * <code>JAI.KEY_INTERPOLATION</code> is provided, its
 * corresponding <code>Interpolation</code> object is used as an
 * argument to the JAI operator used to scale the image.  If no
 * such hint is present, an instance of
 * <code>InterpolationNearest</code> is used.
 *
 * @param width the width of the rendering in pixels.
 * @param height the height of the rendering in pixels.
 * @param hints a Hashtable of rendering hints.
 * @throws IllegalArgumentException if width or height are non-positive.
 */
public RenderedImage createScaledRendering(int width,
                                           int height,
                                           RenderingHints hints) {
    if(width <= 0 && height <= 0) {
        throw new IllegalArgumentException(
  JaiI18N.getString("MultiResolutionRenderableImage1"));
    }

    int res = numSources - 1;
    while (res > 0) {
        if(height > 0) {
            int imh = renderedSource[res].getHeight();
            if (imh >= height) {
                break;
            }
        } else {
            int imw = renderedSource[res].getWidth();
            if (imw >= width) {
                break;
            }
        }
        res--;
    }

    RenderedImage source = renderedSource[res];
    if(width <= 0) {
        width = (int)Math.round(height*source.getWidth()/source.getHeight());
    } else if(height <= 0) {
        height = (int)Math.round(width*source.getHeight()/source.getWidth());
    }
    double sx = (double)width/source.getWidth();
    double sy = (double)height/source.getHeight();
    double tx = (getMinX() - source.getMinX())*sx;
    double ty = (getMinY() - source.getMinY())*sy;

    Interpolation interp =
        Interpolation.getInstance(Interpolation.INTERP_NEAREST);
    if (hints != null) {
        Object obj = hints.get(JAI.KEY_INTERPOLATION);
        if (obj != null) {
            interp = (Interpolation)obj;
        }
    }

    ParameterBlock pb = new ParameterBlock();
    pb.addSource(source);
    pb.add((float)sx);
    pb.add((float)sy);
    pb.add((float)tx);
    pb.add((float)ty);
    pb.add(interp);

    return JAI.create("scale", pb, null);
}
 
Example 55
Project: rastertheque   File: OperationDescriptorImpl.java   Source Code and License Vote up 4 votes
private boolean validateParameters(ParameterListDescriptor pld,
			       ParameterBlock args,
                                      StringBuffer msg) {

if ((args == null) || (msg == null))
           throw new IllegalArgumentException(JaiI18N.getString("Generic0"));

       // The number of parameters this operation should have. 
       int numParams = pld.getNumParameters();

       // The number of parameters supplied. 
       int argNumParams = args.getNumParameters();

Object paramDefaults[] = pld.getParamDefaults();

// Check for the correct number of parameters. 
       if (argNumParams < numParams) {
           // The minimum number of parameters this operation must have. 
           if (argNumParams < getMinNumParameters(pld)) {
               msg.append(JaiI18N.formatMsg("OperationDescriptorImpl9",
	    new Object[] { getName(), new Integer(numParams)}));

               return false;

           } else {	// use default values
               for (int i = argNumParams; i < numParams; i++) {
                   args.add(paramDefaults[i]);
               }
           }
       }

       for (int i = 0; i < numParams; i++) {
           Object p = args.getObjectParameter(i);

    /* Check for null parameter. */
           if (p == null) {
               p = paramDefaults[i];	// get the default parameter value

               if (p == OperationDescriptor.NO_PARAMETER_DEFAULT) {
                   msg.append(
		    JaiI18N.formatMsg("OperationDescriptorImpl11",
		    new Object[] { getName(), new Integer(i) }));
                   return false;

               } else {
                   args.set(p, i);	// replace null parameter with default
               }
           }

    // Now check if the parameter value is valid
    try {
	if (!pld.isParameterValueValid(paramNames[i], p)) {
                   msg.append(
		JaiI18N.formatMsg("OperationDescriptorImpl10",
		    new Object[] { getName(), pld.getParamNames()[i] }));
	    return false;
	}
    } catch (IllegalArgumentException e) {
	msg.append(getName() + " - " + e.getLocalizedMessage());
	return false;
    }
}

       return true;
   }
 
Example 56
Project: Lucee   File: Image.java   Source Code and License Vote up 3 votes
public void flip(TransposeType transpose) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.add(transpose);
	image(JAI.create("transpose", params).getAsBufferedImage());
}
 
Example 57
Project: rastertheque   File: JAI.java   Source Code and License Vote up 3 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1 <code>Object</code> parameter and
 * 1 <code>int</code> parameter
 *
 * @param opName  The name of the operation.
 * @param param1  The <code>Object</code> parameter.
 * @param param2  The <code>int</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                Object param1,
                                int param2) {
    ParameterBlock args = new ParameterBlock();
    args.add(param1);
    args.add(param2);
    return create(opName, args, null);
}
 
Example 58
Project: rastertheque   File: JAI.java   Source Code and License Vote up 3 votes
/**
 * Creates a <code>RenderedOp</code> that takes 1
 * <code>RenderedImage</code> source,
 * 2 <code>float</code> and 1 <code>Object</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The first <code>float</code> parameter.
 * @param param2  The second <code>float</code> parameter.
 * @param param3  The <code>Object</code> parameter.
 * @deprecated as of JAI 1.1. Instead use
 *             <code>create(String,ParameterBlock)</code>.
 */
public static RenderedOp create(String opName,
                                RenderedImage src,
                                float param1,
                                float param2,
                                Object param3) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    return create(opName, args, null);
}