public synchronized Iterator<ImageTypeSpecifier> getImageTypes(final int imageIndex) throws IOException { ensureOpen(); csm = rasterHandler.getSampleModel(); ccmdl = PlanarImage.createColorModel(csm); final List<ImageTypeSpecifier> l = new ArrayList<ImageTypeSpecifier>(); if (imageType == null) { imageType = new ImageTypeSpecifier(ccmdl, csm); l.add(imageType); } return l.iterator(); }
public BufferedImage read(final int imageIndex, ImageReadParam param) throws IOException { ensureOpen(); if (hasListeners) { clearAbortRequest(); processImageStarted(0); } Raster readRaster = readRaster(imageIndex, param); csm = rasterHandler.getSampleModel(); ccmdl = PlanarImage.createColorModel(csm); imageType = new ImageTypeSpecifier(ccmdl, csm); final BufferedImage bi = new BufferedImage(ccmdl, (WritableRaster) readRaster, false, null); if (hasListeners) { if (rasterHandler.isAborting()) processReadAborted(); else processImageComplete(); } return bi; }
if (cm == null) cm = PlanarImage.createColorModel(rimage.getSampleModel());
public static PlanarImage createPlanarImage(WritableRaster raster) { ColorModel cm = PlanarImage.createColorModel(raster.getSampleModel()); BufferedImage bi = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); return PlanarImage.wrapRenderedImage(bi); }
private static RenderedImage createRenderedImage(final int[] array, final int w, final int h) { // create rendered image with demension being width by height final SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_INT, w, h, 1); final ColorModel colourModel = PlanarImage.createColorModel(sampleModel); final DataBufferInt dataBuffer = new DataBufferInt(array, array.length); final WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0)); return new BufferedImage(colourModel, raster, false, new Hashtable()); }
private static RenderedImage createRenderedImage(double[] array, int width, int height) { // create rendered image with dimension being width by height final SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_DOUBLE, width, height, 1); final ColorModel colourModel = PlanarImage.createColorModel(sampleModel); final DataBufferDouble dataBuffer = new DataBufferDouble(array, array.length); final WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, new java.awt.Point(0, 0)); return new BufferedImage(colourModel, raster, false, new Hashtable()); }
private static RenderedImage createRenderedImage(final double[] array, final int width, final int height) { // create rendered image with demension being width by height final SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_DOUBLE, width, height, 1); final ColorModel colourModel = PlanarImage.createColorModel(sampleModel); final DataBufferDouble dataBuffer = new DataBufferDouble(array, array.length); final WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0)); return new BufferedImage(colourModel, raster, false, new Hashtable()); }
private static RenderedImage createRenderedImage(final double[] array, final int w, final int h) { // create rendered image with demension being width by height final SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_DOUBLE, w, h, 1); final ColorModel colourModel = PlanarImage.createColorModel(sampleModel); final DataBufferDouble dataBuffer = new DataBufferDouble(array, array.length); final WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0)); return new BufferedImage(colourModel, raster, false, new Hashtable()); }
public ShapeMaskOpImage(Shape shape, int width, int height, ResolutionLevel level) { super(DataBuffer.TYPE_BYTE, width, height, null, null, level); this.shape = AffineTransform.getScaleInstance(1.0 / getScale(), 1.0 / getScale()).createTransformedShape(shape); this.colorModel = PlanarImage.createColorModel(getSampleModel()); }
public ShapeMaskOpImage(Shape shape, int width, int height, Dimension tileSize, ResolutionLevel level) { super(DataBuffer.TYPE_BYTE, width, height, tileSize, null, level); this.shape = AffineTransform.getScaleInstance(1.0 / getScale(), 1.0 / getScale()).createTransformedShape(shape); this.colorModel = PlanarImage.createColorModel(getSampleModel()); }
private static RenderedImage createRenderedImage(final double[] array, final int w, final int h) { // create rendered image with dimension being width by height final SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_DOUBLE, w, h, 1); final ColorModel colourModel = PlanarImage.createColorModel(sampleModel); final DataBufferDouble dataBuffer = new DataBufferDouble(array, array.length); final WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, new Point(0, 0)); return new BufferedImage(colourModel, raster, false, null); }
public static ImageLayout createSingleBandedImageLayout(int dataBufferType, int width, int height, int tileWidth, int tileHeight) { SampleModel sampleModel = ImageUtils.createSingleBandedSampleModel(dataBufferType, tileWidth, tileHeight); ColorModel colorModel = PlanarImage.createColorModel(sampleModel); return new ImageLayout(0, 0, width, height, 0, 0, tileWidth, tileHeight, sampleModel, colorModel); }
private ImageLayout buildLayout(Rectangle bounds, Dimension tileSize, int dataType) { if (bounds == null) { throw new IllegalStateException( "Cannot determine output image layout, dest bounds have not been provided"); } ImageLayout layout = new ImageLayout(bounds.x, bounds.y, bounds.width, bounds.height); SampleModel sm = RasterFactory.createPixelInterleavedSampleModel( dataType, tileSize.width, tileSize.height, 1); layout.setSampleModel(sm); layout.setColorModel(PlanarImage.createColorModel(sm)); return layout; }
private ImageLayout buildLayout(Rectangle bounds, Dimension tileSize, int dataType) { if (bounds == null) { throw new IllegalStateException( "Cannot determine output image layout, dest bounds have not been provided"); } ImageLayout layout = new ImageLayout(bounds.x, bounds.y, bounds.width, bounds.height); SampleModel sm = RasterFactory.createPixelInterleavedSampleModel( dataType, tileSize.width, tileSize.height, 1); layout.setSampleModel(sm); layout.setColorModel(PlanarImage.createColorModel(sm)); return layout; }
private static ImageLayout createTwoBandedImageLayout(int width, int height, Dimension tileSize) { if (width < 0) { throw new IllegalArgumentException("width"); } if (height < 0) { throw new IllegalArgumentException("height"); } if (tileSize == null) { throw new IllegalArgumentException("tileSize"); } SampleModel sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, tileSize.width, tileSize.height, 2); ColorModel colorModel = PlanarImage.createColorModel(sampleModel); if (colorModel == null) { final int dataType = sampleModel.getDataType(); ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); int[] nBits = {DataBuffer.getDataTypeSize(dataType)}; colorModel = new ComponentColorModel(cs, nBits, false, true, Transparency.OPAQUE, dataType); } return new ImageLayout(0, 0, width, height, 0, 0, tileSize.width, tileSize.height, sampleModel, colorModel); }
private static ImageLayout createTwoBandedImageLayout(int width, int height, Dimension tileSize) { if (width < 0) { throw new IllegalArgumentException("width"); } if (height < 0) { throw new IllegalArgumentException("height"); } if (tileSize == null) { throw new IllegalArgumentException("tileSize"); } SampleModel sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, tileSize.width, tileSize.height, 2); ColorModel colorModel = PlanarImage.createColorModel(sampleModel); if (colorModel == null) { final int dataType = sampleModel.getDataType(); ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); int[] nBits = {DataBuffer.getDataTypeSize(dataType)}; colorModel = new ComponentColorModel(cs, nBits, false, true, Transparency.OPAQUE, dataType); } return new ImageLayout(0, 0, width, height, 0, 0, tileSize.width, tileSize.height, sampleModel, colorModel); }
private static TiledImage createImage() { PixelInterleavedSampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_USHORT, 120, 80, 1, 120, new int[]{0}); ColorModel cm = PlanarImage.createColorModel(sm); TiledImage image = new TiledImage(0, 0, 256, 256, 0, 0, sm, cm); return image; } }
@Test public void testPlanarImageTranslatedChild() throws Exception { SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 128, 128, 1, 128, new int[] {0}); TiledImage source = new TiledImage(0, 0, 512, 512, 0, 0, sm, PlanarImage.createColorModel(sm)); Raster[] tiles = source.getTiles(); assertEquals(16, tiles.length); // Without fix for GEOS-8137, this split call will cause a // java.lang.ClassCastException: java.awt.image.Raster cannot be cast to // java.awt.image.WritableRaster MetatileMapOutputFormat.split(key, source); } }
private Band createBand(String name, int dataType, int w, int h, float[] floats, Double noDataValue) { final SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, 1, w, new int[]{0}); final ColorModel cm = PlanarImage.createColorModel(sm); final TiledImage sourceImage = new TiledImage(0, 0, w, h, 0, 0, sm, cm); sourceImage.setData(WritableRaster.createWritableRaster(sm, new DataBufferFloat(floats, w * h), null)); final Band band = new Band(name, dataType, w, h); band.setSourceImage(sourceImage); if (noDataValue != null) { band.setNoDataValueUsed(true); band.setNoDataValue(noDataValue); } return band; } }
private static Band addBand(Product p, String name, int dataType, Double noDataValue, double scalingFactor) { final int width = p.getSceneRasterWidth(); final int height = p.getSceneRasterHeight(); final SampleModel sm = new PixelInterleavedSampleModel(ImageManager.getDataBufferType(dataType), width, height, 1, width, new int[]{0}); final ColorModel cm = PlanarImage.createColorModel(sm); final TiledImage sourceImage = new TiledImage(0, 0, width, height, 0, 0, sm, cm); final Band band = new Band(name, dataType, width, height); band.setScalingFactor(scalingFactor); if (noDataValue != null) { band.setNoDataValueUsed(true); band.setNoDataValue(noDataValue); } band.setSourceImage(sourceImage); p.addBand(band); return band; } }