/** * Returns the {@linkplain #getRenderedImage rendered image} as a planar image. * * @return The planar image. * @see #getRenderedImage * @see #getRenderedOperation * @see #getImageAsROI */ public final PlanarImage getPlanarImage() { return PlanarImage.wrapRenderedImage(getRenderedImage()); }
private RenderedImage getImageFromParentCoverage(GridCoverage2D parentCoverage) { if (parentCoverage == null) { return null; } RenderedImage ri = parentCoverage.getRenderedImage(); if (ri != null) { PlanarImage pi = PlanarImage.wrapRenderedImage(ri); pi.setProperty(PARENT_COVERAGE_PROPERTY, parentCoverage); ri = pi; } return ri; }
public void dispose(boolean force) { /////////////////////////////////////////////////////////////////////// // // Dispose local intermediate operations // /////////////////////////////////////////////////////////////////////// final Iterator<RenderedImage> it = intermediateOps.iterator(); while (it.hasNext()) { final PlanarImage image = PlanarImage.wrapRenderedImage((RenderedImage) it.next()); image.dispose(); } super.dispose(force); }
/** * Same as {@link #read(Object)} but ensures the result is a {@link BufferedImage}, eventually * transforming it if needs be. Callers that can deal with {@link RenderedImage} should use the * other method for efficiency sake. * * @return A image * @throws IOException */ public static BufferedImage readBufferedImage(Object input) throws IOException { RenderedImage ri = ImageIOExt.read(input); if (ri == null) { return null; } else if (ri instanceof BufferedImage) { return (BufferedImage) ri; } else { return PlanarImage.wrapRenderedImage(ri).getAsBufferedImage(); } }
/** * Constructs the {@link PlanarImage} from the {@linkplain SerializableRenderedImage} after * deserialization. */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); try { /* * Set the 'image' field using reflection, because this field is final. * This is a legal usage for deserialization according Field.set(...) * documentation in J2SE 1.5. */ final Field field = GridCoverage2D.class.getDeclaredField("image"); field.setAccessible(true); field.set(this, PlanarImage.wrapRenderedImage(serializedImage)); } catch (NoSuchFieldException cause) { InvalidClassException e = new InvalidClassException(cause.getLocalizedMessage()); e.initCause(cause); throw e; } catch (IllegalAccessException cause) { InvalidObjectException e = new InvalidObjectException(cause.getLocalizedMessage()); e.initCause(cause); throw e; } }
/** * Provides a hint that this {@link ImageWorker} will no longer be accessed from a reference in * user space. The results are equivalent to those that occur when the program loses its last * reference to this image, the garbage collector discovers this, and finalize is called. This * can be used as a hint in situations where waiting for garbage collection would be overly * conservative. * * <p>Mind, this also results in disposing the JAI Image chain attached to the image the worker * is applied to, so don't call this method on image changes (full/partial) that you want to * use. * * <p>{@link ImageWorker} defines this method to remove the image being disposed from the list * of sinks in all of its source images. The results of referencing an {@link ImageWorker} after * a call to dispose() are undefined. */ public final void dispose() { if (commonHints != null) { this.commonHints.clear(); } this.commonHints = null; this.roi = null; if (this.image instanceof PlanarImage) { ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(image)); } else if (this.image instanceof BufferedImage) { ((BufferedImage) this.image).flush(); this.image = null; } }
private BufferedImage readImage2(byte[] imageBytes) throws IOException { SeekableStream stream = new ByteArraySeekableStream(imageBytes); String decoderName = null; for (String dn : ImageCodec.getDecoderNames(stream)) { decoderName = dn; break; } ImageDecoder decoder = ImageCodec.createImageDecoder(decoderName, stream, null); PlanarImage img = PlanarImage.wrapRenderedImage(decoder.decodeAsRenderedImage()); return img.getAsBufferedImage(); }
/** * This method is responsible for creating a coverage from the supplied {@link RenderedImage}. * * @param image * @param sampleDimensions * @return * @throws IOException */ private GridCoverage2D prepareCoverage( RenderedImage image, GridSampleDimension[] sampleDimensions, double[] noData) throws IOException { Map<String, Object> properties = new HashMap<String, Object>(); if (noData != null && noData.length > 0) { CoverageUtilities.setNoDataProperty(properties, noData[0]); } properties.put(GridCoverage2DReader.SOURCE_URL_PROPERTY, datasetURL); return COVERAGE_FACTORY.create( request.name, image, new GridGeometry2D( new GridEnvelope2D(PlanarImage.wrapRenderedImage(image).getBounds()), PixelInCell.CELL_CORNER, finalGridToWorldCorner, this.targetBBox.getCoordinateReferenceSystem(), hints), sampleDimensions, null, properties); }
/** * Fallback Method, in some jre implementations, ImageIO.read(InputStream in) returns null. If * this happens, this method is called, which is not so efficient but it works * * @param imageBytes * @return * @throws IOException */ private BufferedImage readImage2(byte[] imageBytes) throws IOException { SeekableStream stream = new ByteArraySeekableStream(imageBytes); String decoderName = null; for (String dn : ImageCodec.getDecoderNames(stream)) { decoderName = dn; break; } ImageDecoder decoder = ImageCodec.createImageDecoder(decoderName, stream, null); PlanarImage img = PlanarImage.wrapRenderedImage(decoder.decodeAsRenderedImage()); return img.getAsBufferedImage(); } }
/** * Dispose the provided coverage for good. * * @param coverage */ private void disposeCoverage(GridCoverage2D coverage) { if (coverage == null) { return; } final RenderedImage im = coverage.getRenderedImage(); ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(im)); coverage.dispose(true); }
/** * Forces the image to start in the origin and have a rgb/rbga/gray/gray+alpha structure * * @param image1 * @return */ private RenderedImage normalizeImage(RenderedImage image1) { image1 = new ImageWorker(image1) .forceColorSpaceRGB() .forceComponentColorModel() .getRenderedImage(); if (image1.getMinX() != 0 || image1.getMinY() != 0) { image1 = PlanarImage.wrapRenderedImage(image1).getAsBufferedImage(); } return image1; }
input.getMinY() + input.getHeight()); ROI roi = new ROI(new ROIGeometry(JTS.toGeometry(env)).getAsImage()); PlanarImage pi = PlanarImage.wrapRenderedImage(input); pi.setProperty("ROI", roi); final Map sourceProperties = coverage.getProperties();
private static void testRasterSymbolizerHelper( final SubchainStyleVisitorCoverageProcessingAdapter rsh) { if (TestData.isInteractiveTest()) { ImageIOUtilities.visualize( ((GridCoverage2D) rsh.getOutput()).getRenderedImage(), rsh.getName().toString()); } else { PlanarImage.wrapRenderedImage(((GridCoverage2D) rsh.getOutput()).getRenderedImage()) .getTiles(); rsh.dispose(new Random().nextBoolean() ? true : false); } }
PlanarImage pimage = PlanarImage.wrapRenderedImage(rimage); bimg = pimage.getAsBufferedImage(null, cm);
protected GridCoverage2D execute() { return CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] { new Category("", Color.BLACK, 0) }, null) }, null, null); } };
protected GridCoverage2D execute() { return CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] { new Category("", Color.BLACK, 0) }, null) }, null, null); } };
.create( "name", PlanarImage.wrapRenderedImage(image), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}),
ParameterBlock pb = new ParameterBlock(); PlanarImage sourceImage = PlanarImage.wrapRenderedImage(getRenderedImage());
@org.junit.Test public void colorMap() throws IOException, TransformerException { // get a coverage GridCoverage2D gc = CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage(getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) }, null, null); testColorMap(gc); }
@Before public void setUp() throws Exception { // get a coverage final GridCoverage2D gc = CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) }, null, null); root1 = new RootNode(gc); root2 = new RootNode(gc); root3 = new RootNode(gc, null); }