int tileCount = tileArea.area(); int[] masks = colorModel.getMasks(); DataBufferInt imageBuffer = new DataBufferInt(width * height); WritableRaster raster = Raster.createPackedRaster(imageBuffer, width, height, width, masks, null);
private int[] createBandOffsets(final ColorModel colorModel) { notNull(colorModel, "colorModel"); if (colorModel instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) colorModel; int[] masks = dcm.getMasks(); int[] offs = new int[masks.length]; for (int i = 0; i < masks.length; i++) { int mask = masks[i]; int off = 0; // TODO: FixMe! This only works for standard 8 bit masks (0xFF) if (mask != 0) { while ((mask & 0xFF) == 0) { mask >>>= 8; off++; } } offs[i] = off; } return offs; } throw new IllegalArgumentException(String.format("%s not supported", colorModel.getClass().getSimpleName())); }
cm = new DirectColorModel(15, 0x7C00, 0x03E0, 0x001F); // See BufferedImage TYPE_USHORT_555_RGB DataBuffer db = new DataBufferUShort(shortArray, shortArray.length); raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null); raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null);
private void readBitmap32(final BitmapDescriptor pBitmap) throws IOException { int[] pixels = new int[pBitmap.getWidth() * pBitmap.getHeight()]; // Will create TYPE_INT_ARGB DirectColorModel cm = (DirectColorModel) ColorModel.getRGBdefault(); DataBuffer buffer = new DataBufferInt(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } // There might be a mask here as well, but we'll ignore it, // and use the 8 bit alpha channel in the ARGB pixel data }
private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException { // TODO: No idea if this actually works.. short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()]; // TODO: Support TYPE_USHORT_565 and the RGB 444/ARGB 4444 layouts // Will create TYPE_USHORT_555 DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F); DataBuffer buffer = new DataBufferShort(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); // Skip to 32 bit boundary if (pBitmap.getWidth() % 2 != 0) { imageInput.readShort(); } if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } // TODO: Might be mask!? }
buf.append("Direct Color Model "); int[] masks = dcm.getMasks(); int totalBits = 0; MaskEntry[] entries = new MaskEntry[masks.length];
final int[] templateMasks = new int[] {0x00ff0000 /*R*/, 0x0000ff00 /*G*/, 0x000000ff /*B*/, 0xff000000 /*A*/}; int[] masks = dcm.getMasks(); if (!Arrays.equals(templateMasks, masks)) { return false; //no flexibility here right now, might never be used anyway
/** * Creates a BufferedImage that shares the data of this Img. Changes in * this Img are reflected in the created BufferedImage and vice versa. * The created BufferedImage uses an ARGB DirectColorModel with an * underlying DataBufferInt (similar to {@link BufferedImage#TYPE_INT_ARGB}) * @return BufferedImage sharing this Img's data. * @see #createRemoteImg(BufferedImage) * @see #toBufferedImage() * @since 1.0 */ @Override public BufferedImage getRemoteBufferedImage(){ DirectColorModel cm = new DirectColorModel(32, 0x00ff0000, // Red 0x0000ff00, // Green 0x000000ff, // Blue 0xff000000 // Alpha ); DataBufferInt buffer = new DataBufferInt(getData(), numValues()); WritableRaster raster = Raster.createPackedRaster(buffer, getWidth(), getHeight(), getWidth(), cm.getMasks(), null); BufferedImage bimg = new BufferedImage(cm, raster, false, null); return bimg; }
cm = new DirectColorModel(15, 0x7C00, 0x03E0, 0x001F); // See BufferedImage TYPE_USHORT_555_RGB DataBuffer db = new DataBufferUShort(shortArray, shortArray.length); raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null); raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null);
cm = new DirectColorModel(15, 0x7C00, 0x03E0, 0x001F); // See BufferedImage TYPE_USHORT_555_RGB DataBuffer db = new DataBufferUShort(shortArray, shortArray.length); raster = Raster.createPackedRaster(db, pBounds.width, pBounds.height, pBounds.width, cm.getMasks(), null); // TODO: last param should ideally be srcRect.getLocation() raster = Raster.createPackedRaster(db, pBounds.width, pBounds.height, pBounds.width, cm.getMasks(), null); // TODO: last param should ideally be srcRect.getLocation()
private void readBitmap32(final BitmapDescriptor pBitmap) throws IOException { int[] pixels = new int[pBitmap.getWidth() * pBitmap.getHeight()]; // Will create TYPE_INT_ARGB DirectColorModel cm = (DirectColorModel) ColorModel.getRGBdefault(); DataBuffer buffer = new DataBufferInt(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } }
private void readBitmap32(final BitmapDescriptor pBitmap) throws IOException { int[] pixels = new int[pBitmap.getWidth() * pBitmap.getHeight()]; // Will create TYPE_INT_ARGB DirectColorModel cm = (DirectColorModel) ColorModel.getRGBdefault(); DataBuffer buffer = new DataBufferInt(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } // There might be a mask here as well, but we'll ignore it, // and use the 8 bit alpha channel in the ARGB pixel data }
private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException { // TODO: No idea if this actually works.. short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()]; // Will create TYPE_USHORT_555; DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F); DataBuffer buffer = new DataBufferShort(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); // Skip to 32 bit boundary if (pBitmap.getWidth() % 2 != 0) { imageInput.readShort(); } if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } }
private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException { // TODO: No idea if this actually works.. short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()]; // TODO: Support TYPE_USHORT_565 and the RGB 444/ARGB 4444 layouts // Will create TYPE_USHORT_555 DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F); DataBuffer buffer = new DataBufferShort(pixels, pixels.length); WritableRaster raster = Raster.createPackedRaster( buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null ); pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); for (int y = 0; y < pBitmap.getHeight(); y++) { int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth(); imageInput.readFully(pixels, offset, pBitmap.getWidth()); // Skip to 32 bit boundary if (pBitmap.getWidth() % 2 != 0) { imageInput.readShort(); } if (abortRequested()) { processReadAborted(); break; } processImageProgress(100 * y / (float) pBitmap.getHeight()); } // TODO: Might be mask!? }