public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) { drawRenderedImage(renderableimage.createDefaultRendering(), affinetransform); }
/** * Reads an image from a GeoTIFF file. For more information, see <a * href="http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/jai/operator/ImageReadDescriptor.html#RenderedMode">ImageReadDescriptor</a> */ private static synchronized RenderedImage readImage(File inFile) throws IOException { final ParameterBlock readParams = new ParameterBlock(); ImageInputStreamSpi lSpi = ImageIOExt.getImageInputStreamSPI(inFile); PlanarImage lImage = null; ImageInputStream lImgIn = lSpi.createInputStreamInstance(inFile, false, null); readParams.add(lImgIn); readParams.add(0); readParams.add(Boolean.FALSE); readParams.add(Boolean.FALSE); readParams.add(Boolean.FALSE); readParams.add(null); readParams.add(null); readParams.add(null); readParams.add(READER_SPI.createReaderInstance()); lImage = JAI.create("ImageRead", readParams, null); final String lFileName = inFile.getName(); final int lExtIndex = lFileName.lastIndexOf('.'); final String lFileNameNoExt = lExtIndex < 0 ? lFileName : lFileName.substring(0, lExtIndex); lImage.setProperty("name", lFileNameNoExt); return lImage; }
private double[] getScalingParams(ParameterBlock paramBlock, boolean isScale2) { // Shearing is not taken into account. // params are ordered like this: scaleX, scaleY, transX, transY double[] scalingParams = new double[4]; for (int i = 0; i < 4; i++) { // Use proper datatype parameter getter depending on the type of operation scalingParams[i] = isScale2 ? paramBlock.getDoubleParameter(i) : paramBlock.getFloatParameter(i); } return scalingParams; }
public ImageWorker translate(float xTrans, float yTrans, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(xTrans); pb.add(yTrans); pb.add(interp); // do not use getRenderingHints() with translate, as it cannot deal with layout hints image = JAI.create("Translate", pb, commonHints); return this; }
public RenderedImage create(ParameterBlock pb, RenderingHints hints) { final RenderedImage image = (RenderedImage) pb.getSource(0); final IndexColorModel icm = (IndexColorModel) pb.getObjectParameter(0); final int quantizationColors = pb.getIntParameter(1); final int alpaThreshold = pb.getIntParameter(2); return new ColorInversion(image, icm, quantizationColors, alpaThreshold); } }
/** Scales the underlying raster using the provided parameters. */ public ImageWorker scale( double xScale, double yScale, double xTrans, double yTrans, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. double[] scalingParams = new double[] {xScale, yScale, xTrans, yTrans}; scale(pb, scalingParams, interp, getRenderingHints()); // getting the new ROI property updateROI(true, SCALE_OP_NAME); return this; }
public RenderedImage create(ParameterBlock pb, RenderingHints hints) { final RenderedImage image = (RenderedImage) pb.getSource(0); final int numColors = pb.getIntParameter(0); final int alpaThreshold = pb.getIntParameter(1); final int subsx = pb.getIntParameter(2); final int subsy = pb.getIntParameter(3); return new ColorReduction(image, hints, numColors, alpaThreshold, subsx, subsy); } }
/** * Returns {@code true} if this operation supports the specified mode, and is capable of * handling the given input source(s) for the specified mode. * * @param modeName The mode name (usually "Rendered"). * @param param The parameter block for the operation to performs. * @param message A buffer for formatting an error message if any. */ protected boolean validateSources( final String modeName, final ParameterBlock param, final StringBuffer message) { if (super.validateSources(modeName, param, message)) { for (int i = param.getNumSources(); --i >= 0; ) { final Object source = param.getSource(i); if (!(source instanceof RenderedImage)) { return false; } } return true; } return false; }
private void prepareAlgebricOperation( Operator op, ParameterBlock pb, ROI roi, Range nodata, boolean setDestNoData) { pb.set(op, 0); pb.set(roi, 1); pb.set(nodata, 2); if (background != null && background.length > 0) { pb.set(background[0], 3); // We must set the new NoData value if (setDestNoData && roi != null && nodata != null) { setNoData(RangeFactory.create(background[0], background[0])); } } }
/** Warps the underlying raster using the provided Warp object. */ public ImageWorker warp(Warp warp, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(warp, 0); pb.set(interp, 1); pb.set(roi, 3); pb.set(nodata, 4); pb.set(background, 2); image = JAI.create("Warp", pb, getRenderingHints()); updateROI(true, null); return this; }
public ImageWorker border( int leftPad, int rightPad, int topPad, int bottomPad, BorderExtender ext) { ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(leftPad); pb.add(rightPad); pb.add(topPad); pb.add(bottomPad); pb.add(ext); pb.add(nodata); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.add(background); } } image = JAI.create("Border", pb, getRenderingHints()); return this; }
SeekableStream seekableStream = new FileSeekableStream(new File("front.jpg")); ParameterBlock pb = new ParameterBlock(); pb.add(seekableStream); BufferedImage image = JAI.create("jpeg", pb).getAsBufferedImage();
/** * Returns the {@linkplain #getRenderedImage rendered image} after null operation. This * operation may be used for setting new ImageProperties or for applying new RenderingHints. * * @return The rendered operation. * @see #getRenderedImage * @see #getPlanarImage * @see #getImageAsROI */ public ImageWorker nullOp() { // Creating a parameter block ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // Executing the operation image = JAI.create("Null", pb, getRenderingHints()); return this; }
/** * Returns {@code true} if this operation supports the specified mode, and is capable of * handling the given input source(s) for the specified mode. * * @param modeName The mode name (usually "Rendered"). * @param param The parameter block for the operation to performs. * @param message A buffer for formatting an error message if any. */ protected boolean validateSources( final String modeName, final ParameterBlock param, final StringBuffer message) { if (super.validateSources(modeName, param, message)) { for (int i = param.getNumSources(); --i >= 0; ) { final Object source = param.getSource(i); if (!(source instanceof RenderedImage)) { return false; } } return true; } return false; }
private void prepareOpConstOperation( Operator op, double[] values, ParameterBlock pb, ROI roi, Range nodata, boolean setDestNoData) { pb.set(op, 1); pb.set(values, 0); pb.set(roi, 2); pb.set(nodata, 3); if (background != null && background.length > 0) { pb.set(background[0], 4); // We must set the new NoData value if (setDestNoData && roi != null && nodata != null) { setNoData(RangeFactory.create(background[0], background[0])); } } }
/** Apply a rescale operation on the underlying image. */ public ImageWorker rescale(double[] scale, double[] offset) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(scale, 0); // The per-band constants to multiply by. pb.set(offset, 1); // The per-band offsets to be added. pb.set(roi, 2); // ROI pb.set(nodata, 3); // NoData range if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 5); // destination No Data value } } image = JAI.create("Rescale", pb, getRenderingHints()); return this; }
/** Warps the underlying using the provided Warp object. */ public ImageWorker colorIndex(ColorIndexer indexer) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(indexer, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background, 3); } } image = JAI.create("ColorIndexer", pb, getRenderingHints()); return this; }
/** Apply a rescale operation on the underlying image. */ public ImageWorker bandCombine(double[][] coeff) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(coeff, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 3); } } image = JAI.create("BandCombine", pb, getRenderingHints()); return this; }
/** * Retains inconditionnaly certain bands of {@linkplain #image}. All other bands (if any) are * discarded without any further processing. * * @param bands the bands to retain. * @return this {@link ImageWorker}. * @see #getNumBands * @see #retainFirstBand * @see BandSelectDescriptor */ public final ImageWorker retainBands(final int[] bands) { // ParameterBlock creation ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(bands, 0); image = JAI.create("BandSelect", pb, getRenderingHints()); return this; }