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; }
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; }
pb.setSource(image, 1); pb.set(new Range[] {nodata, nodata2}, 0); if (isNoDataNeeded() || nodata2 != null) { if (background != null && background.length > 0) { double dest = background[0]; pb.set(dest, 1); pb.set(roi, 3); pb.set(addAlpha, 4); this.image = JAI.create("BandMerge", pb, this.getRenderingHints()); invalidateStatistics();
/** Performs Lookup on the underlying image */ public ImageWorker lookup(LookupTable table) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(table, 0); pb.set(roi, 2); // Convert the NoData if (nodata != null) { nodata = RangeFactory.convert(nodata, image.getSampleModel().getDataType()); } pb.set(nodata, 3); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 1); } } image = JAI.create("Lookup", 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; }
/** Apply a Raster classification on the underlying image. */ public ImageWorker classify(ColorMapTransform domain1D, Integer bandIndex) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(domain1D, 0); pb.set(bandIndex, 1); pb.set(roi, 2); pb.set(nodata, 3); if (isNoDataNeeded()) { if (domain1D.hasGaps()) { // We must set the new NoData value setNoData( RangeFactory.create( domain1D.getDefaultValue(), domain1D.getDefaultValue())); } } image = JAI.create("RasterClassifier", pb, getRenderingHints()); return this; }
/** Apply a Generic Piecewise operation on the underlying image. */ public ImageWorker piecewise(PiecewiseTransform1D transform, Integer bandIndex) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(transform, 0); pb.set(bandIndex, 1); pb.set(roi, 2); pb.set(nodata, 3); if (isNoDataNeeded()) { if (transform.hasGaps()) { // We must set the new NoData value setNoData( RangeFactory.create( transform.getDefaultValue(), transform.getDefaultValue())); } } image = JAI.create("GenericPiecewise", pb, getRenderingHints()); return this; }
/** * Inverts the pixel values of the {@linkplain #image}. * * @see InvertDescriptor */ public final ImageWorker invert() { // ParameterBlock creation ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { pb.set(AlgebraDescriptor.Operator.INVERT, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { double dest = background[0]; pb.set(dest, 3); } } image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Invert", pb, getRenderingHints()); } invalidateStatistics(); return this; }
/** Apply a rangeLookup operation on the underlying image. */ public ImageWorker rangeLookup(Object rangeLookup) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(rangeLookup, 0); pb.set(roi, 2); if (roi != null) { if (background != null && background.length > 0) { pb.set(background[0], 1); // We must set the new NoData value setNoData(RangeFactory.create(background[0], background[0])); } } if (JAIExt.isJAIExtOperation("RLookup")) { image = JAI.create("RLookup", pb, getRenderingHints()); } else { image = JAI.create("RangeLookup", pb, getRenderingHints()); } return this; }
/** Forces the provided {@link ColorModel} via the JAI ColorConvert operation. */ private void forceColorModel(final ColorModel cm) { final ImageLayout2 il = new ImageLayout2(image); il.setColorModel(cm); il.setSampleModel(cm.createCompatibleSampleModel(image.getWidth(), image.getHeight())); final RenderingHints oldRi = this.getRenderingHints(); final RenderingHints newRi = (RenderingHints) oldRi.clone(); newRi.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il)); setRenderingHints(newRi); // Setting the parameter blocks ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(cm, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { // Elaborating the final NoData value if (background.length != cm.getNumColorComponents()) { throw new IllegalArgumentException("Wrong DestinationNoData value defined"); } pb.set(background, 3); } } image = JAI.create("ColorConvert", pb, getRenderingHints()); // restore RI this.setRenderingHints(oldRi); // invalidate stats invalidateStatistics(); }
/** * Formats the underlying image to the provided data type. * * @param dataType to be used for this {@link FormatDescriptor} operation. * @return this {@link ImageWorker} */ public final ImageWorker format(final int dataType) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(dataType, 0); image = JAI.create("Format", pb, getRenderingHints()); setNoData(RangeFactory.convert(nodata, dataType)); // All post conditions for this method contract. assert image.getSampleModel().getDataType() == dataType; return this; }
pb.set(bands, 0); image = JAI.create("BandSelect", pb, getRenderingHints());
/** * If the was not already tiled, tile it. Note that no tiling will be done if * 'getRenderingHints()' failed to suggest a tile size. This method is for internal use by * {@link #write} methods only. * * @return this {@link ImageWorker}. */ public final ImageWorker tile() { final RenderingHints hints = getRenderingHints(); final ImageLayout layout = getImageLayout(hints); if (layout.isValid(ImageLayout.TILE_WIDTH_MASK) || layout.isValid(ImageLayout.TILE_HEIGHT_MASK)) { final int type = image.getSampleModel().getDataType(); // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(type, 0); image = JAI.create("Format", pb, hints); setNoData(RangeFactory.convert(nodata, type)); } return this; }