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

The following are Jave code examples for showing how to use addSource() 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: Lucee   File: Image.java   Source Code and License Vote up 6 votes
public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException {
	
	RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION,interpolation);
	if(interpolation!=RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
		hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1)));
	}
	
	ParameterBlock pb = new ParameterBlock();
	pb.addSource(image());
	BufferedImage img = JAI.create("translate", pb).getAsBufferedImage();
	Graphics2D graphics = img.createGraphics();
	graphics.clearRect(0, 0, img.getWidth(), img.getHeight());
	AffineTransform at = new AffineTransform();
	at.setToIdentity();
	graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans);
	graphics.dispose();
	image(img);
}
 
Example 7
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 8
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 9
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 10
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 11
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
 * 6 <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.
 * @param param6  The sixth <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,
                                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 12
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 13
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 14
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 15
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 16
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 17
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 18
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 19
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 20
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 21
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 22
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 23
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 24
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 25
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 26
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 27
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 28
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 29
Project: s3tbx-scape-m   File: ScapeMUtils.java   Source Code and License Vote up 5 votes
public static RenderedOp getImagesAbsolute(RenderedImage image1) {
    // retrieve new image with absolute of pixels of source image

    // Create a ParameterBlock with the source image.
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(image1);
    return JAI.create("absolute", pb);
}
 
Example 30
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 31
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 32
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 33
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 34
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 35
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 36
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 37
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 38
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 39
Project: rastertheque   File: CropCRIF.java   Source Code and License Vote up 5 votes
/**
 * Creates a <Code>RenderedImage</Code> from the renderable layer.
 *
 * @param renderContext The rendering information associated with
 *        this rendering.
 * @param paramBlock The parameters used to create the image.
 * @return A <code>RenderedImage</code>.
 */
public RenderedImage create(RenderContext renderContext,
                            ParameterBlock paramBlock) {
    // Get the destination bounds in rendering-independent coordinates.
    Rectangle2D dstRect2D = getBounds2D(paramBlock);

    // Map the destination bounds to rendered coordinates. This method
    // will cause extra data to be present if there is any rotation or
    // shear.
    AffineTransform tf = renderContext.getTransform();
    Rectangle2D rect = tf.createTransformedShape(dstRect2D).getBounds2D();

    // Make sure that the rendered rectangle is non-empty.
    if(rect.getWidth() < 1.0 || rect.getHeight() < 1.0) {
        double w = Math.max(rect.getWidth(), 1.0);
        double h = Math.max(rect.getHeight(), 1.0);
        rect.setRect(rect.getMinX(), rect.getMinY(), w, h);
    }

    // Initialize the rendered ParameterBlock.
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(paramBlock.getRenderedSource(0));
    pb.set((float)rect.getMinX(), 0);
    pb.set((float)rect.getMinY(), 1);
    pb.set((float)rect.getWidth(), 2);
    pb.set((float)rect.getHeight(), 3);

    // Crop the rendered source.
    return JAI.create("crop", pb, renderContext.getRenderingHints());
}
 
Example 40
Project: rastertheque   File: ImageMIPMap.java   Source Code and License Vote up 5 votes
/**
 * Duplicates a <code>RenderedOp</code> chain.  Each node in the
 * chain must be a <code>RenderedOp</code>.  The <code>op</code>
 * parameter points to the last <code>RenderedOp</code> in the chain.
 * The very first op in the chain must have no sources and its source
 * will be set to the supplied image vector.  When traversing up the
 * chain, if any node has more than one source, the first source will
 * be used.  The first source of each node is duplicated; all other
 * sources are copied by reference.
 *
 * @param op RenderedOp chain
 * @param vector of source images
 *
 * @throws IllegalArgumentException if <code>op</code> is <code>null</code>.
 * @throws IllegalArgumentException if <code>images</code> is <code>null</code>.
 */
protected RenderedOp duplicate(RenderedOp op,
                               Vector images) {
    if (images == null) {
        throw new IllegalArgumentException(JaiI18N.getString("Generic0"));
    }

    //
    // Duplicates a RenderedOp with the original OperationRegistry,
    // OperationName, ParameterBlock, and RenderingHints copied over
    // by reference.  No property information is copied.
    //
    op = new RenderedOp(op.getRegistry(),
                        op.getOperationName(),
                        op.getParameterBlock(),
                        op.getRenderingHints());

    ParameterBlock pb = new ParameterBlock();
    pb.setParameters(op.getParameters());

    Vector srcs = op.getSources();
    int numSrcs = srcs.size();

    if (numSrcs == 0) {	// first op in the chain
        pb.setSources(images);

    } else {		// recursively duplicate source0
        pb.addSource(duplicate((RenderedOp)srcs.elementAt(0), images));

        for (int i = 1; i < numSrcs; i++) {
            pb.addSource(srcs.elementAt(i));
        }
    }

    op.setParameterBlock(pb);
    return op;
}
 
Example 41
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.
    *
    * @param opName  The name of the operation.
    * @param src     The <code>RenderedImage</code> src parameter.
    */
   public static RenderedOp create(String opName,
                                   RenderedImage src) {
ParameterBlock args = new ParameterBlock();
args.addSource(src);
       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 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 43
Project: modelingcommons   File: RasterDataset.java   Source Code and License Vote up 5 votes
/** */
public RasterDataset convolve (KernelJAI kernel) {
    ColorModel srcCM = new ValueColorModel(_raster);
    Object srcImg = new BufferedImage(srcCM, _raster, false, null);
    BorderExtender borderExtender = new BorderExtenderConstant(new double[] { Double.NaN });
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(srcImg);
    pb.add(kernel);
    RenderingHints hints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, borderExtender);
    RenderedOp dstImg = JAI.create("convolve", pb, hints);
    WritableRaster wr = srcCM.createCompatibleWritableRaster(dstImg.getWidth(), dstImg.getHeight());
    dstImg.copyData(wr);
    return new RasterDataset(_dimensions, wr);
}
 
Example 44
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 45
Project: orbit-image-analysis   File: OrbitTiledImage2.java   Source Code and License Vote up 4 votes
private PlanarImage mergeChannels(final OrbitTiledImage2 redChannel, final OrbitTiledImage2 greenChannel, final PlanarImage blueChannel, int tileX, int tileY, boolean redActive, boolean greenActive, boolean blueActive) {

        PlanarImage red = redChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(redChannel.getTile(tileX, tileY), null, redChannel.getSampleModel(), redChannel.getColorModel()));
        PlanarImage green = greenChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(greenChannel.getTile(tileX, tileY), null, greenChannel.getSampleModel(), greenChannel.getColorModel()));
        PlanarImage blue = blueChannel == null ? null : PlanarImage.wrapRenderedImage(createImage(blueChannel.getTile(tileX, tileY), null, blueChannel.getSampleModel(), blueChannel.getColorModel()));

        PlanarImage nullImage = null;
        if (red != null) nullImage = getNullImage(red);
        else if (green != null) nullImage = getNullImage(green);
        else if (blue != null) nullImage = getNullImage(blue);

        red = red == null ? nullImage : red;
        green = green == null ? nullImage : green;
        blue = blue == null ? nullImage : blue;

        red = redActive ? red : nullImage;
        green = greenActive ? green : nullImage;
        blue = blueActive ? blue : nullImage;

        if (red.getSampleModel().getNumBands() > 1)
            red = convertColorToGray(red, 1, 0, 0);
        if (green.getSampleModel().getNumBands() > 1)
            green = convertColorToGray(green, 0, 1, 0);
        if (blue.getSampleModel().getNumBands() > 1)
            blue = convertColorToGray(blue, 0, 0, 1);


        try {

            ParameterBlock pb = new ParameterBlock();
            if (originalWasGrayScale) {  // bgr fix
                pb.addSource(blue); // b
                pb.addSource(green); // g
                pb.addSource(red); // r
            } else { // rgb
                pb.addSource(red); // r
                pb.addSource(green); // g
                pb.addSource(blue); // b
            }
            PlanarImage merged = JAI.create("bandmerge", pb);

            return merged;
        } catch (Throwable e) {
            e.printStackTrace();
            return null;
        }


    }
 
Example 46
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 47
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 48
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 49
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 50
Project: Lucee4   File: Image.java   Source Code and License Vote up 4 votes
public void overlay(Image topImage) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.addSource(topImage.image());
	image(JAI.create("overlay", params).getAsBufferedImage());
}
 
Example 51
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 52
Project: Lucee   File: Image.java   Source Code and License Vote up 4 votes
public void invert()  throws ExpressionException{
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	image(JAI.create("invert", params).getAsBufferedImage());
}
 
Example 53
Project: Lucee   File: Image.java   Source Code and License Vote up 4 votes
public void overlay(Image topImage) throws ExpressionException {
	ParameterBlock params = new ParameterBlock();
	params.addSource(image());
	params.addSource(topImage.image());
	image(JAI.create("overlay", params).getAsBufferedImage());
}
 
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: RenderedOp.java   Source Code and License Vote up 4 votes
/**
 * Adds a source to the <code>ParameterBlock</code> of this node.
 * This is a convenience method that invokes
 * <code>setParameterBlock()</code> and so adheres to the same event
 * firing behavior.
 *
 * <p> The node is added automatically as a sink if the source is a
 * <code>PlanarImage</code> or a <code>CollectionImage</code>.
 *
 * @param source The source to be added to the
 *        <code>ParameterBlock</code>
 * @throws IllegalArgumentException if
 *         <code>source</code> is <code>null</code>.
 *
 * @since JAI 1.1
 */
public synchronized void addSource(Object source) {
    if (source == null)
 throw new IllegalArgumentException(JaiI18N.getString("Generic0"));

    ParameterBlock pb =
        (ParameterBlock)nodeSupport.getParameterBlock().clone();
    pb.addSource(source);
    nodeSupport.setParameterBlock(pb);

    if(source instanceof PlanarImage) {
        ((PlanarImage)source).addSink(this);
    } else if(source instanceof CollectionImage) {
        ((CollectionImage)source).addSink(this);
    }
}
 
Example 56
Project: rastertheque   File: CollectionOp.java   Source Code and License Vote up 4 votes
/**
 * This method performs the actions described by the documentation of
 * <code>createInstance()</code>.  The parameter value selects the method
 * used to render the source(s).
 *
 * @throws RuntimeException if the image factory charged with rendering
 *         the node is unable to create a rendering.
 */
private synchronized Collection createInstance(boolean isChainFrozen) {
    // Get the PB evaluating any DeferredData objects in the process.
    ParameterBlock args =
        ImageUtil.evaluateParameters(nodeSupport.getParameterBlock());

    ParameterBlock pb = new ParameterBlock();
    pb.setParameters(args.getParameters());

    int numSources = args.getNumSources();
    for (int i = 0; i < numSources; i++) {
        Object source = args.getSource(i);
        Object src = null;

        if (source instanceof RenderedOp) {
            src = isChainFrozen ?
                ((RenderedOp)source).getRendering() :
                ((RenderedOp)source).createInstance();
        } else if (source instanceof CollectionOp) {
            CollectionOp co = (CollectionOp)source;
            src = isChainFrozen ?
                co.getCollection() :
                co.createInstance();
        } else if (source instanceof RenderedImage ||
                   source instanceof RenderableImage ||
                   source instanceof Collection) {
            src = source;
        } else {
            // Source is some other type. Pass on (for now).
            src = source;
        }
        pb.addSource(src);
    }

    Collection instance = null;
    if(isRenderable) {
        instance = RCIFRegistry.create(nodeSupport.getRegistry(),
                                       nodeSupport.getOperationName(),
                                       pb);
    } else {
        CollectionImageFactory cif =
            CIFRegistry.get(nodeSupport.getRegistry(),
                            nodeSupport.getOperationName());
        instance = cif.create(pb, nodeSupport.getRenderingHints());

        // Set the CollectionImageFactory on the result.
        if(instance != null) {
            ((CollectionImage)instance).setImageFactory(cif);
        }
    }

    // Throw an error if the rendering is null.
    if (instance == null) {
        throw new RuntimeException(JaiI18N.getString("CollectionOp0"));
    }

    // Save the RenderingHints.
    oldHints = nodeSupport.getRenderingHints() == null ?
        null : (RenderingHints)nodeSupport.getRenderingHints().clone();

    return instance;
}
 
Example 57
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 58
Project: rastertheque   File: JAI.java   Source Code and License Vote up 3 votes
/**
    * Creates a <code>RenderedOp</code> that takes 1 Collection source.
    *
    * @param opName  The name of the operation.
    * @param srcCol  The Collection src parameter.
    * @deprecated as of JAI 1.1. Instead use
    *             <code>create(String,ParameterBlock)</code>.
    */
   public static RenderedOp create(String opName,
                                   Collection srcCol) {
ParameterBlock args = new ParameterBlock();
args.addSource(srcCol);
       return create(opName, args, null);
   }
 
Example 59
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 and
 * 1 <code>int</code> parameter.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param   The <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 param) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param);
    return create(opName, args, null);
}
 
Example 60
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,
 * 1 <code>Object</code> and 1 <code>float</code> parameter.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The <code>Object</code> parameter.
 * @param param2  The <code>float</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,
                                float param2) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    return create(opName, args, null);
}
 
Example 61
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,
 * 1 <code>Object</code> and 2 <code>int</code> parameters.
 *
 * @param opName  The name of the operation.
 * @param src     The <code>RenderedImage</code> src parameter.
 * @param param1  The <code>Object</code> parameter.
 * @param param2  The first <code>int</code> parameter.
 * @param param3  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,
                                int param2,
                                int param3) {
    ParameterBlock args = new ParameterBlock();
    args.addSource(src);
    args.add(param1);
    args.add(param2);
    args.add(param3);
    return create(opName, args, null);
}
 
Example 62
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);
}