/** * Creates a {@code WritableRaster} with the specified width and height that has a data layout * ({@code SampleModel}) compatible with this {@code ColorModel}. */ public WritableRaster createCompatibleWritableRaster(final int width, final int height) { return Raster.createBandedRaster(transferType, width, height, numBands, null); }
private void initRgbColorTable() throws IOException { int numBaseComponents = baseColorSpace.getNumberOfComponents(); // convert the color table into a 1-row BufferedImage in the base color space, // using a writable raster for high performance WritableRaster baseRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, actualMaxIndex + 1, 1, numBaseComponents, new Point(0, 0)); int[] base = new int[numBaseComponents]; for (int i = 0, n = actualMaxIndex; i <= n; i++) { for (int c = 0; c < numBaseComponents; c++) { base[c] = (int)(colorTable[i][c] * 255f); } baseRaster.setPixel(i, 0, base); } // convert the base image to RGB BufferedImage rgbImage = baseColorSpace.toRGBImage(baseRaster); WritableRaster rgbRaster = rgbImage.getRaster(); // build an RGB lookup table from the raster rgbColorTable = new int[actualMaxIndex + 1][3]; int[] nil = null; for (int i = 0, n = actualMaxIndex; i <= n; i++) { rgbColorTable[i] = rgbRaster.getPixel(i, 0, nil); } }
raster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, width, height, 1, new Point(0, 0));
WritableRaster componentRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, width, height, componentColorSpace.getNumberOfComponents(), new Point(0, 0));
WritableRaster altRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), alternateColorSpace.getNumberOfComponents(),
private Raster readMask(final IconResource resource) throws IOException { Dimension size = resource.size(); int width = size.width; int height = size.height; byte[] mask = new byte[width * height]; imageInput.seek(resource.start + ICNS.RESOURCE_HEADER_SIZE); if (resource.isMaskType()) { // 8 bit mask imageInput.readFully(mask, 0, resource.length - ICNS.RESOURCE_HEADER_SIZE); } else if (resource.hasMask()) { // Embedded 1bit mask byte[] maskData = new byte[(resource.length - ICNS.RESOURCE_HEADER_SIZE) / 2]; imageInput.skipBytes(maskData.length); // Skip the 1 bit image data imageInput.readFully(maskData); // Unpack 1bit mask to 8 bit int bitPos = 0x80; for (int i = 0, maskLength = mask.length; i < maskLength; i++) { mask[i] = (byte) ((maskData[i / 8] & bitPos) != 0 ? 0xff : 0x00); if ((bitPos >>= 1) == 0) { bitPos = 0x80; } } } else { throw new IllegalArgumentException(String.format("Not a mask resource: %s", resource)); } return Raster.createBandedRaster(new DataBufferByte(mask, mask.length), width, height, width, new int[]{0}, new int[]{0}, null); }
/** * Creates a {@code WritableRaster} with the specified width * and height that has a data layout ({@code SampleModel}) * compatible with this {@code ColorModel}. */ public WritableRaster createCompatibleWritableRaster(final int width, final int height) { return Raster.createBandedRaster(transferType, width, height, numBands, null); }
/** * Creates a {@code WritableRaster} with the specified width * and height that has a data layout ({@code SampleModel}) * compatible with this {@code ColorModel}. */ public WritableRaster createCompatibleWritableRaster(final int width, final int height) { return Raster.createBandedRaster(transferType, width, height, numBands, null); }
/** * Creates a {@code WritableRaster} with the specified width and height that has * a data layout ({@code SampleModel}) compatible with this {@code ColorModel}. * * The difference with standard implementation is that this method creates a banded raster on the assumption that * the number of bands is greater than 1. By contrast, the standard implementation provides various optimizations * for one-banded raster. */ @Override public WritableRaster createCompatibleWritableRaster(final int width, final int height) { return Raster.createBandedRaster(transferType, width, height, numBands, null); }
public Raster getRaster(int x, int y, int w, int h) { return Raster.createBandedRaster(0, 0, 0, 0, NULL_POINT); } }
raster = Raster.createBandedRaster(buffer, width, height, width, new int[]{0, 0, 0, 0}, createBandOffsets(bandLen), null); WritableRaster mask = Raster.createBandedRaster(new DataBufferByte(solid, solid.length), width, height, width, new int[]{0}, new int[]{0}, null); image.getAlphaRaster().setRect(mask);
/** * @return an empty image conforming to the request parameters */ public static BufferedImage prepareImage( String format, int width, int height, boolean transparent, Color bgColor ) { if ( format.equals( "image/png; mode=8bit" ) || format.equals( "image/png; subtype=8bit" ) || format.equals( "image/gif" ) ) { ColorModel cm = PlanarImage.getDefaultColorModel( TYPE_BYTE, 4 ); return new BufferedImage( cm, createBandedRaster( TYPE_BYTE, width, height, 4, null ), false, null ); } BufferedImage img = new BufferedImage( width, height, getType( transparent, format ) ); if ( !isTransparentAndTransparencySupported( format, transparent ) ) { Graphics2D g = img.createGraphics(); g.setBackground( bgColor ); g.clearRect( 0, 0, width, height ); g.dispose(); } return img; }
private BufferedImage readTrueColorPcx(InputStream is) throws Exception { byte brgb[] = IOUtils.readFully(is, 4096); byte pixels[] = new byte[bytesPerLine*NPlanes*height]; /** * A BufferedInputStream could have been constructed from the InputStream, * but for maximum decoding speed, one time reading of the image data * into memory is ideal though this is memory consuming. */ LOGGER.info("true color pcx image!"); readScanLines(brgb, brgb.length, pixels); is.close(); DataBuffer db = new DataBufferByte(pixels, pixels.length); int trans = Transparency.OPAQUE; int[] nBits = {8, 8, 8}; WritableRaster raster = Raster.createBandedRaster(db, width, height, bytesPerLine*3, new int[]{0, 0, 0}, new int[] {0, bytesPerLine, bytesPerLine*2}, null); ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), nBits, false, false, trans, DataBuffer.TYPE_BYTE); return new BufferedImage(cm, raster, false, null); }
/** * Creates a banded raster for the given data type. * * @param dataType the data type as one of the {@link DataBuffer} constants. * @param width the desired raster width. * @param height the desired raster height. * @param numBands the desired number of bands. * @return a writable raster of the given type and size. */ static WritableRaster createBandedRaster(final int dataType, final int width, final int height, final int numBands) { switch (dataType) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_USHORT: case DataBuffer.TYPE_INT: { // As of JDK7, the method called below supports only the above-cited types. return Raster.createBandedRaster(dataType, width, height, numBands, null); } default: { // For all other types, we need to create the sample model ourselves. return Raster.createWritableRaster(new BandedSampleModel(dataType, width, height, numBands), null); } } }
private void initRgbColorTable() throws IOException { int numBaseComponents = baseColorSpace.getNumberOfComponents(); // convert the color table into a 1-row BufferedImage in the base color space, // using a writable raster for high performance WritableRaster baseRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, actualMaxIndex + 1, 1, numBaseComponents, new Point(0, 0)); int[] base = new int[numBaseComponents]; for (int i = 0, n = actualMaxIndex; i <= n; i++) { for (int c = 0; c < numBaseComponents; c++) { base[c] = (int)(colorTable[i][c] * 255f); } baseRaster.setPixel(i, 0, base); } // convert the base image to RGB BufferedImage rgbImage = baseColorSpace.toRGBImage(baseRaster); WritableRaster rgbRaster = rgbImage.getRaster(); // build an RGB lookup table from the raster rgbColorTable = new int[actualMaxIndex + 1][3]; int[] nil = null; for (int i = 0, n = actualMaxIndex; i <= n; i++) { rgbColorTable[i] = rgbRaster.getPixel(i, 0, nil); } }
private void initRgbColorTable() throws IOException { int numBaseComponents = baseColorSpace.getNumberOfComponents(); // convert the color table into a 1-row BufferedImage in the base color space, // using a writable raster for high performance WritableRaster baseRaster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, actualMaxIndex + 1, 1, numBaseComponents, new Point(0, 0)); int[] base = new int[numBaseComponents]; for (int i = 0, n = actualMaxIndex; i <= n; i++) { for (int c = 0; c < numBaseComponents; c++) { base[c] = (int)(colorTable[i][c] * 255f); } baseRaster.setPixel(i, 0, base); } // convert the base image to RGB BufferedImage rgbImage = baseColorSpace.toRGBImage(baseRaster); WritableRaster rgbRaster = rgbImage.getRaster(); // build an RGB lookup table from the raster rgbColorTable = new int[actualMaxIndex + 1][3]; int[] nil = null; for (int i = 0, n = actualMaxIndex; i <= n; i++) { rgbColorTable[i] = rgbRaster.getPixel(i, 0, nil); } }
private PlanarImage[] createSourceImages(int width, int height) { WritableRaster sourceTile = Raster.createBandedRaster(DataBuffer.TYPE_INT, width, height, 1, new Point(0, 0)); ColorModel cm = PlanarImage.getDefaultColorModel(sourceTile.getDataBuffer().getDataType(), 1); BufferedImage bufferedImage = new BufferedImage(cm, sourceTile, false, null); return new PlanarImage[]{PlanarImage.wrapRenderedImage(bufferedImage)}; }
public PixelIteratorConform(WritableRenderedImage image) { super(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 5, 5, 1, null), null); this.pixelIter1 = new DefaultWritableIterator(image, image, null); this.pixelIter2 = PixelIteratorFactory.createDefaultWriteableIterator(image, image); }
public PixelIteratorConform(WritableRenderedImage image, Rectangle subArea) { super(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 5, 5, 1, null), null); this.pixelIter1 = new DefaultWritableIterator(image, image, subArea); this.pixelIter2 = PixelIteratorFactory.createDefaultWriteableIterator(image, image); }
private static PlanarImage[] createSourceImages(int width, int height) { WritableRaster sourceTile = Raster.createBandedRaster(DataBuffer.TYPE_INT, width, height, 1, new Point(0, 0)); int[] sourceData = new int[width * height]; for (int i = 0; i < sourceData.length; i++) { sourceData[i] = i + 1; } sourceTile.setPixels(0, 0, width, height, sourceData); ColorModel cm = PlanarImage.getDefaultColorModel(sourceTile.getDataBuffer().getDataType(), 1); BufferedImage bufferedImage = new BufferedImage(cm, sourceTile, false, null); return new PlanarImage[]{PlanarImage.wrapRenderedImage(bufferedImage)}; }