public void testCreateFromBufferedImageType() { for (int i = BufferedImage.TYPE_INT_RGB; i <= BufferedImage.TYPE_BYTE_INDEXED; i++) { BufferedImage bi = new BufferedImage(1, 1, i); ColorModel expected = bi.getColorModel(); ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(i); ColorModel actual = typeSpecifier.getColorModel(); String msg = "Failed to create correct ImageTypeSpecifier, bufferedImageType = " + Integer.toString(i); assertEquals(msg, expected.getClass(), actual.getClass()); assertEquals(msg, expected.getColorSpace(), actual.getColorSpace()); assertEquals(msg, expected.getTransferType(), actual.getTransferType()); assertEquals(msg, expected.getTransparency(), actual.getTransparency()); } }
private void writeColorModel(DataOutput out, ColorModel colorModel) throws IOException { if (colorModel instanceof DirectColorModel) { out.writeInt(DIRECT_COLOR_MODEL); writeDirectColorModel(out, (DirectColorModel) colorModel); } else throw new SGIORuntimeException("Unsupported ColorModel " + colorModel.getClass().getName()); }
private void writeBufferedImageNoCompression(DataOutput out, BufferedImage image) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(byteStream); ColorModel colorModel = (ColorModel) image.getColorModel(); if (colorModel instanceof ComponentColorModel) { ComponentColorModel cm = (ComponentColorModel) colorModel; int numComponents = cm.getNumComponents(); int type; switch (numComponents) { case 3: type = BufferedImage.TYPE_INT_RGB; break; case 4: type = BufferedImage.TYPE_INT_ARGB; break; default: throw new SGIORuntimeException( "Unsupported ColorModel " + colorModel.getClass().getName()); } BufferedImage tmpBuf = new BufferedImage(image.getWidth(), image.getHeight(), type); WritableRaster dstRaster = tmpBuf.getRaster(); Raster srcRaster = image.getRaster(); dstRaster.setRect(srcRaster); image = tmpBuf; } writeColorModel(dataOut, image.getColorModel()); writeWritableRaster(dataOut, image.getRaster()); dataOut.writeBoolean(image.isAlphaPremultiplied()); dataOut.close(); byte[] buffer = byteStream.toByteArray(); out.writeInt(buffer.length); out.write(buffer); }
public static void dumpImageInfo(RenderedImage image) { final SampleModel sampleModel = image.getSampleModel(); final ColorModel colorModel = image.getColorModel(); System.out.println("image: " + image); System.out.println(" minX = " + image.getMinX()); System.out.println(" minY = " + image.getMinY()); System.out.println(" width = " + image.getWidth()); System.out.println(" height = " + image.getHeight()); System.out.println( " colorModel = " + (colorModel != null ? colorModel.getClass() : "null")); System.out.println( " colorSpace = " + (colorModel != null ? colorModel.getColorSpace() : "null")); System.out.println(" sampleModel = " + sampleModel.getClass()); System.out.println(" numBands = " + sampleModel.getNumBands()); System.out.println(" dataType = " + sampleModel.getDataType()); System.out.println(" transferType = " + sampleModel.getTransferType()); System.out.println(" tileGridXOffset = " + image.getTileGridXOffset()); System.out.println(" tileGridYOffset = " + image.getTileGridYOffset()); System.out.println(" minTileX = " + image.getMinTileX()); System.out.println(" minTileY = " + image.getMinTileY()); System.out.println(" tileWidth = " + image.getTileWidth()); System.out.println(" tileHeight = " + image.getTileHeight()); }