alpha = srcRaster.getSamples(0, y, w, 1, 1, alpha); dstRaster.setSamples(1, y + 1, w, 1, 0, gray); dstRaster.setSamples(1, y + 1, w, 1, 1, gray); dstRaster.setSamples(1, y + 1, w, 1, 2, gray); dstRaster.setSamples(1, y + 1, w, 1, 3, alpha);
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; }
mainRaster.setSamples(0, 0, origW, origH, 0, data);
public BufferedImage createImageIndexed() { // TODO: This is very stupid, maybe we need a TYPE_CUSTOM image, with separate alphaRaster?! // As ICO has a separate bitmask, not related to palette index (allows 256 colors + trans) :-P IndexColorModel icm = createColorModel(); // This is slightly obscure, and should probably be moved.. Hashtable<String, Object> properties = null; if (entry instanceof DirectoryEntry.CUREntry) { properties = new Hashtable<>(1); properties.put("cursor_hotspot", ((DirectoryEntry.CUREntry) this.entry).getHotspot()); } BufferedImage image = new BufferedImage( icm, icm.createCompatibleWritableRaster(getWidth(), getHeight()), icm.isAlphaPremultiplied(), properties ); WritableRaster raster = image.getRaster(); // Make pixels transparent according to mask final int trans = icm.getTransparentPixel(); for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { if (mask.isTransparent(x, y)) { bits[x + getWidth() * y] = trans; } } } raster.setSamples(0, 0, getWidth(), getHeight(), 0, bits); return image; }
@Override protected void store(final int x, final int y) { final int nx = length; for (int c = 0; c < componentCount; c++) dstRaster.setSamples(x, y, nx, 1, c, data[c]); } }
@Override protected void store(final int x, final int y) { final int nx = length; for (int c = 0; c < componentCount; c++) dstRaster.setSamples(x, y, nx, 1, c, data[c]); } }
@Override protected void store(final int x, final int y) { raster.setSamples(x, y, length, 1, 0, lineBuffer); }
@Override protected void store(final int x, final int y) { final int nx = length; for (int c = 0; c < componentCount; c++) dstRaster.setSamples(x, y, nx, 1, c, data[c]); } }
@Override protected void store(final int x, final int y) { raster.setSamples(x, y, length, 1, 0, lineBuffer); }
@Override protected void store(final int x, final int y) { raster.setSamples(x, y, length, 1, 0, lineBuffer); }
double[] samples = new double[destRegion.width * destRegion.height]; doubleBuffer.get(samples); raster.setSamples( xmin, ymin, FloatBuffer floatBuffer = array.getDataAsByteBuffer().asFloatBuffer(); floatBuffer.get(samples); raster.setSamples( xmin, ymin, destRegion.width, destRegion.height, dstBand, samples); break; int[] intSamples = new int[destRegion.width * destRegion.height]; intBuffer.get(intSamples); raster.setSamples( xmin, ymin,
BufferedImage outputImage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY); WritableRaster raster = outputImage.getRaster(); raster.setSamples(0, 0, w, h, 0, result); ImageIO.write(outputImage, INPUT_FILETYPE, new File(getOutputFileSystemString()));
public WritableRaster getRaster() { if (raster == null) { int bands = 1; Point location = new Point(0, 0); // DataBuffer.TYPE_DOUBLE is unsupported, may have to add a multiplication factor if rate/yield values are small raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT, nCols, nRows, bands, location); int[] values = new int[nCols * nRows]; Arrays.fill(values, Grid.EMPTY_VALUE); raster.setSamples(0, 0, nCols, nRows, 0, values); } return raster; }
public void setSamples(int[] values) { assert values != null; assert values.length == nCols * nRows; getRaster().setSamples(0, 0, nCols, nRows, 0, values); }
@Override public void setSamples(int[] values) { assert values != null; assert values.length == nCols * nRows; getRaster().setSamples(0, 0, nCols, nRows, 0, values); }
public void setSamples(int[] values) { assert values != null; assert values.length == nCols * nRows; getRaster().setSamples(0, 0, nCols, nRows, 0, values); }
public static void copyBand(Raster src, int srcBand, WritableRaster dst, int dstBand) { Rectangle srcR = new Rectangle(src.getMinX(), src.getMinY(), src.getWidth(), src.getHeight()); Rectangle dstR = new Rectangle(dst.getMinX(), dst.getMinY(), dst.getWidth(), dst.getHeight()); Rectangle cpR = srcR.intersection(dstR); int [] samples = null; for (int y=cpR.y; y< cpR.y+cpR.height; y++) { samples = src.getSamples(cpR.x, y, cpR.width, 1, srcBand, samples); dst.setSamples(cpR.x, y, cpR.width, 1, dstBand, samples); } } }
public static void copyBand(Raster src, int srcBand, WritableRaster dst, int dstBand) { Rectangle srcR = new Rectangle(src.getMinX(), src.getMinY(), src.getWidth(), src.getHeight()); Rectangle dstR = new Rectangle(dst.getMinX(), dst.getMinY(), dst.getWidth(), dst.getHeight()); Rectangle cpR = srcR.intersection(dstR); int [] samples = null; for (int y=cpR.y; y< cpR.y+cpR.height; y++) { samples = src.getSamples(cpR.x, y, cpR.width, 1, srcBand, samples); dst.setSamples(cpR.x, y, cpR.width, 1, dstBand, samples); } } }
public static void copyBand(Raster src, int srcBand, WritableRaster dst, int dstBand) { Rectangle srcR = new Rectangle(src.getMinX(), src.getMinY(), src.getWidth(), src.getHeight()); Rectangle dstR = new Rectangle(dst.getMinX(), dst.getMinY(), dst.getWidth(), dst.getHeight()); Rectangle cpR = srcR.intersection(dstR); int [] samples = null; for (int y=cpR.y; y< cpR.y+cpR.height; y++) { samples = src.getSamples(cpR.x, y, cpR.width, 1, srcBand, samples); dst.setSamples(cpR.x, y, cpR.width, 1, dstBand, samples); } } }
public static void copyBand(Raster src, int srcBand, WritableRaster dst, int dstBand) { Rectangle srcR = new Rectangle(src.getMinX(), src.getMinY(), src.getWidth(), src.getHeight()); Rectangle dstR = new Rectangle(dst.getMinX(), dst.getMinY(), dst.getWidth(), dst.getHeight()); Rectangle cpR = srcR.intersection(dstR); int [] samples = null; for (int y = cpR.y; y < cpR.y + cpR.height; y++) { samples = src.getSamples(cpR.x, y, cpR.width, 1, srcBand, samples); dst.setSamples(cpR.x, y, cpR.width, 1, dstBand, samples); } } }