/** Builds a new tile, creating it from scratch. */ public WritableRaster createTile(SampleModel sampleModel, Point location) { // sanity checks if (sampleModel == null) { throw new NullPointerException("sampleModel cannot be null"); } if (location == null) { location = new Point(0, 0); } return RasterFactory.createWritableRaster(sampleModel, location); }
/** * Builds a 1x1 BufferedImage with the provided sample model and color model * * @return */ public BufferedImage toBufferedImage() { final SampleModel sm = sampleModel.createCompatibleSampleModel(1, 1); final WritableRaster raster = RasterFactory.createWritableRaster(sm, null); final BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null); return image; }
WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null); if (value != null) {
private WritableRaster buildSolidRaster(int tileWidth, int tileHeight, int value) { SampleModel sampleModel = getMPSampleModel(tileWidth, tileHeight); // build the raster WritableRaster newRaster = RasterFactory.createWritableRaster(sampleModel, new java.awt.Point(0, 0)); // sanity checks int dataType = sampleModel.getTransferType(); int numBands = sampleModel.getNumBands(); if (dataType != DataBuffer.TYPE_BYTE) { throw new IllegalArgumentException( "The code works only if the sample model data type is BYTE"); } if (numBands != 1) { throw new IllegalArgumentException("The code works only for single band rasters!"); } if (value != 0) { // flood fill int w = sampleModel.getWidth(); int h = sampleModel.getHeight(); int[] data = new int[w * h]; Arrays.fill(data, value); newRaster.setSamples(0, 0, w, h, 0, data); } return newRaster; }
RasterFactory.createWritableRaster(sampleModel, new java.awt.Point(0, 0));
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()); }
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()); }
@Override protected void computeRect(PlanarImage[] sourceImages, WritableRaster tile, Rectangle destRect) { WritableRaster wrappedTile = RasterFactory.createWritableRaster(tile.getSampleModel(), tile.getDataBuffer(), new Point(0, 0)); final BufferedImage image = new BufferedImage(colorModel, wrappedTile, false, null); final Graphics2D graphics2D = image.createGraphics(); graphics2D.translate(-tile.getMinX(), -tile.getMinY()); graphics2D.setColor(Color.WHITE); graphics2D.fill(shape); graphics2D.dispose(); final byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData(); for (int i = 0; i < data.length; i++) { data[i] = (data[i] != 0) ? TRUE : FALSE; } } }
SampleModel tileSampleModel = sampleModel.createCompatibleSampleModel(tileWidth, tileHeight); WritableRaster raster = RasterFactory.createWritableRaster(tileSampleModel, new java.awt.Point(0, 0)); BufferedImage bi = new BufferedImage(colorModel, raster, false, null); Graphics2D graphics = null;
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); }
/** * Builds a tile with constant value * * @param value the constant value * * @return the new tile */ private Raster constantTile(int value) { // build the raster WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, new java.awt.Point( 0, 0)); // sanity checks int dataType = sampleModel.getTransferType(); int numBands = sampleModel.getNumBands(); if (dataType != DataBuffer.TYPE_BYTE) { throw new IllegalArgumentException( "The code works only if the sample model data type is BYTE"); } if (numBands != 1) { throw new IllegalArgumentException("The code works only for single band rasters!"); } // flood fill DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer(); if (value == 1) { Arrays.fill(dataBuffer.getData(), (byte) 255); } return raster; }
private WritableRaster createTempWritableRaster(Raster src) { Point origin = new Point(src.getMinX(), src.getMinY()); return RasterFactory.createWritableRaster(src.getSampleModel(), origin); }
private WritableRaster createTempWritableRaster(Raster src) { Point origin = new Point(src.getMinX(), src.getMinY()); return RasterFactory.createWritableRaster(src.getSampleModel(), origin); }
@Override protected void computeRect(PlanarImage[] sourceImages, WritableRaster tile, Rectangle destRect) { final BufferedImage image = new BufferedImage(colorModel, RasterFactory.createWritableRaster(tile.getSampleModel(), tile.getDataBuffer(), new Point(0, 0)), false, null); final Graphics2D graphics2D = image.createGraphics(); graphics2D.translate(-tile.getMinX(), -tile.getMinY()); graphics2D.setColor(Color.WHITE); ProductNodeGroup<Placemark> placemarkGroup = getPlacemarkGroup(); Placemark[] placemarks = placemarkGroup.toArray(new Placemark[placemarkGroup.getNodeCount()]); for (Placemark placemark : placemarks) { final PixelPos pixelPos = placemark.getPixelPos(); if (pixelPos != null) { final int x = (int) pixelPos.x - placemarkSize / 2; final int y = (int) pixelPos.y - placemarkSize / 2; graphics2D.fillRect(x, y, placemarkSize, placemarkSize); } } graphics2D.dispose(); final byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData(); for (int i = 0; i < data.length; i++) { data[i] = (data[i] != 0) ? TRUE : FALSE; } }
public static TiledImage createTiledImage(float[][] data, int width, int height, int numBands) { int length = width * height; // create a float sample model SampleModel sampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT, width, height, numBands); // create a DataBuffer from the float[][] data array DataBufferFloat dataBuffer = new DataBufferFloat(data, length); // create a Raster Point origin = new Point(0, 0); Raster raster = RasterFactory.createWritableRaster(sampleModel, dataBuffer, origin); return createTiledImage(raster); }
/** * Builds a tile with constant value * * @param value the constant value * * @return the new tile */ private Raster constantTile(int value) { // build the raster WritableRaster raster = RasterFactory.createWritableRaster( sampleModel, new java.awt.Point(0, 0)); // sanity checks int dataType = sampleModel.getTransferType(); int numBands = sampleModel.getNumBands(); if(dataType != DataBuffer.TYPE_BYTE) { throw new IllegalArgumentException("The code works only if the sample model data type is BYTE"); } if(numBands != 1) { throw new IllegalArgumentException("The code works only for single band rasters!"); } // flood fill int w = sampleModel.getWidth(); int h = sampleModel.getHeight(); int[] data = new int[w * h]; Arrays.fill(data, value); raster.setSamples(0, 0, w, h, 0, data); return raster; }
/** * Builds a tile with constant value * * @param value the constant value * * @return the new tile */ private Raster constantTile(int value) { // build the raster WritableRaster raster = RasterFactory.createWritableRaster( sampleModel, new java.awt.Point(0, 0)); // sanity checks int dataType = sampleModel.getTransferType(); int numBands = sampleModel.getNumBands(); if(dataType != DataBuffer.TYPE_BYTE) { throw new IllegalArgumentException("The code works only if the sample model data type is BYTE"); } if(numBands != 1) { throw new IllegalArgumentException("The code works only for single band rasters!"); } // flood fill int w = sampleModel.getWidth(); int h = sampleModel.getHeight(); int[] data = new int[w * h]; Arrays.fill(data, value); raster.setSamples(0, 0, w, h, 0, data); return raster; }
/** * Write {@link java.awt.image.Raster} within {@link org.geotoolkit.image.io.large.TileRasterCache} object on hard disk at appropriate quad tree emplacement. * * @param lRaster object which contain raster. * @throws java.io.IOException if impossible to write raster on disk. */ private void writeRaster(final TileRasterCache lRaster) throws IOException { final Path tileFile = Paths.get(qTD.getPath(lRaster.getGridX(), lRaster.getGridY())); if (isWritableRenderedImage || !Files.exists(tileFile)) { final BufferedImage toWrite = new BufferedImage( cm, RasterFactory.createWritableRaster(lRaster.getRaster().getSampleModel(), lRaster.getRaster().getDataBuffer(), WPOINT), cm.isAlphaPremultiplied(), null); // TODO : Optimize using a "writer pool" instead of creating one each time ? final ImageWriter imgWriter = WRITER_SPI.createWriterInstance(); try { imgWriter.setOutput(tileFile); imgWriter.write(toWrite); imgWriter.dispose(); } finally { releaseWriter(imgWriter); } } }