imgWriteParams.setCompressionQuality(quality); final ColorModel colorModel = renderedImage.getColorModel();// ColorModel.getRGBdefault(); imgWriteParams.setDestinationType(new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(16, 16)));
imgWriteParams.setCompressionQuality(quality); final ColorModel colorModel = renderedImage.getColorModel();// ColorModel.getRGBdefault(); imgWriteParams.setDestinationType(new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(16, 16)));
private static ImageTypeSpecifier createColorMappedImageSpec( final IndexColorModel colorModel, int sampleImageWidth, int sampleImageHeight) { final SampleModel sampleModel; final ImageTypeSpecifier its; LOGGER.fine("Found single-band colormapped raster, using its index color model"); sampleModel = colorModel.createCompatibleSampleModel(sampleImageWidth, sampleImageHeight); its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
/** * Returns <code>true</code> if PaletteBuilder is able to create palette for given rendered * image. * * @param image an instance of <code>RenderedImage</code> to be indexed. * @return <code>true</code> if the <code>PaletteBuilder</code> is likely to be able to create * palette for this image type. * @exception IllegalArgumentException if <code>image</code> is <code>null</code>. */ public static boolean canCreatePalette(RenderedImage image) { if (image == null) { throw new IllegalArgumentException("image == null"); } ImageTypeSpecifier type = new ImageTypeSpecifier(image); return canCreatePalette(type); }
public synchronized Iterator<ImageTypeSpecifier> getImageTypes(final int imageIndex) throws IOException { ensureOpen(); csm = rasterHandler.getSampleModel(); ccmdl = PlanarImage.createColorModel(csm); final List<ImageTypeSpecifier> l = new ArrayList<ImageTypeSpecifier>(); if (imageType == null) { imageType = new ImageTypeSpecifier(ccmdl, csm); l.add(imageType); } return l.iterator(); }
@Override public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException { final List<ImageTypeSpecifier> l = new java.util.ArrayList<ImageTypeSpecifier>(); final VariableAdapter wrapper = getCoverageDescriptor(imageIndex); if (wrapper != null) { final SampleModel sampleModel = wrapper.getSampleModel(); final ImageTypeSpecifier imageType = new ImageTypeSpecifier( ImageIOUtilities.createColorModel(sampleModel), sampleModel); l.add(imageType); } return l.iterator(); }
public static ImageTypeSpecifier createDiscreteAlphaIndexedFromIndexColorModel(final IndexColorModel pColorModel) { ColorModel colorModel = new DiscreteAlphaIndexColorModel(pColorModel); return new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)); } }
private static ImageTypeSpecifier create(final ColorSpace cs, final boolean hasAlpha, final boolean isAlphaPremultiplied, final SampleModel sampleModel) { return new ImageTypeSpecifier(new UInt32ColorModel(cs, hasAlpha, isAlphaPremultiplied), sampleModel); } }
private static ImageTypeSpecifier createRGBImageSpec( int sampleImageWidth, int sampleImageHeight, final int dataType) { final ImageTypeSpecifier its; ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB); boolean hasAlpha = false; boolean isAlphaPremultiplied = false; int transparency = Transparency.OPAQUE; int transferType = dataType; ColorModel colorModel = new ComponentColorModel( colorSpace, new int[] {8, 8, 8}, hasAlpha, isAlphaPremultiplied, transparency, transferType); SampleModel sampleModel = new BandedSampleModel(dataType, sampleImageWidth, sampleImageHeight, 3); its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
private static ImageTypeSpecifier createGrayscaleImageSpec( int sampleImageWidth, int sampleImageHeight, final int dataType, int bitsPerPixel) { final ImageTypeSpecifier its; ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); boolean hasAlpha = false; boolean isAlphaPremultiplied = false; int transparency = Transparency.OPAQUE; int transferType = dataType; int[] nbits = {bitsPerPixel}; ColorModel colorModel = new ComponentColorModelJAI( colorSpace, nbits, hasAlpha, isAlphaPremultiplied, transparency, transferType); SampleModel sampleModel = colorModel.createCompatibleSampleModel(sampleImageWidth, sampleImageHeight); its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
private static ImageTypeSpecifier createRGBAImageSpec( int sampleImageWidth, int sampleImageHeight, final int dataType) { final ImageTypeSpecifier its; ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB); boolean hasAlpha = true; boolean isAlphaPremultiplied = false; int transparency = Transparency.TRANSLUCENT; int transferType = dataType; int[] nBits = {8, 8, 8, 8}; ColorModel colorModel = new ComponentColorModelJAI( colorSpace, nBits, hasAlpha, isAlphaPremultiplied, transparency, transferType); /* * Do not use colorModel.createCompatibleSampleModel cause it creates a * PixelInterleavedSampleModel and we need a BandedSampleModel so it matches how the data * comes out of ArcSDE */ SampleModel sampleModel = new BandedSampleModel(dataType, sampleImageWidth, sampleImageHeight, 4); its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
private static ImageTypeSpecifier createOneBitColorMappedImageSpec( int sampleImageWidth, int sampleImageHeight, byte noDataValue) { assert noDataValue == 2; final int FALSE = ColorUtilities.getIntFromColor(255, 255, 255, 255); final int TRUE = ColorUtilities.getIntFromColor(0, 0, 0, 255); final int NODATA = ColorUtilities.getIntFromColor(255, 255, 255, 0); final int mapSize = 3; int[] cmap = new int[mapSize]; cmap[0] = FALSE; cmap[1] = TRUE; cmap[2] = NODATA; int transparentPixel = noDataValue; IndexColorModel colorModel = new IndexColorModel( 8, mapSize, cmap, 0, false, transparentPixel, DataBuffer.TYPE_BYTE); SampleModel sampleModel = colorModel.createCompatibleSampleModel(sampleImageWidth, sampleImageHeight); ImageTypeSpecifier its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
private ImageTypeSpecifier createPacked(final ColorSpace colorSpace, final int redMask, final int greenMask, final int blueMask, final int alphaMask, final int transferType, final boolean isAlphaPremultiplied) { Validate.isTrue(transferType == DataBuffer.TYPE_BYTE || transferType == DataBuffer.TYPE_USHORT, transferType, "transferType: %s"); int bits = transferType == DataBuffer.TYPE_BYTE ? 8 : 16; ColorModel colorModel = new DirectColorModel(colorSpace, bits, redMask, greenMask, blueMask, alphaMask, isAlphaPremultiplied, transferType); return new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)); }
private static ImageTypeSpecifier createFourBitColorMappedImageSpec( int sampleImageWidth, int sampleImageHeight, byte noDataValue) { int maxValue = (int) TYPE_4BIT.getSampleValueRange().getMaximum(); int mapSize = noDataValue > maxValue ? noDataValue : maxValue + 1; int[] cmap = new int[mapSize]; ColorUtilities.expand(new Color[] {Color.BLACK, Color.WHITE}, cmap, 0, maxValue); for (int i = maxValue; i < mapSize; i++) { cmap[i] = ColorUtilities.getIntFromColor(0, 0, 0, 0); } int transparentPixel = noDataValue; IndexColorModel colorModel = new IndexColorModel( 8, mapSize, cmap, 0, true, transparentPixel, DataBuffer.TYPE_BYTE); SampleModel sampleModel = colorModel.createCompatibleSampleModel(sampleImageWidth, sampleImageHeight); ImageTypeSpecifier its = new ImageTypeSpecifier(colorModel, sampleModel); return its; }
public BufferedImage read(final int imageIndex, ImageReadParam param) throws IOException { ensureOpen(); if (hasListeners) { clearAbortRequest(); processImageStarted(0); } Raster readRaster = readRaster(imageIndex, param); csm = rasterHandler.getSampleModel(); ccmdl = PlanarImage.createColorModel(csm); imageType = new ImageTypeSpecifier(ccmdl, csm); final BufferedImage bi = new BufferedImage(ccmdl, (WritableRaster) readRaster, false, null); if (hasListeners) { if (rasterHandler.isAborting()) processReadAborted(); else processImageComplete(); } return bi; }
private ImageTypeSpecifier createImageTypeSpecifier(int planarConfiguration, ColorSpace cs, int dataType, int significantSamples, int samplesPerPixel, boolean alpha, boolean alphaPremultiplied) throws IIOException { switch (planarConfiguration) { case TIFFBaseline.PLANARCONFIG_CHUNKY: if (samplesPerPixel > significantSamples) { return new ImageTypeSpecifier( new ExtraSamplesColorModel(cs, alpha, alphaPremultiplied, dataType, samplesPerPixel - significantSamples), new PixelInterleavedSampleModel(dataType, 1, 1, samplesPerPixel, samplesPerPixel, createOffsets(samplesPerPixel))); } return ImageTypeSpecifiers.createInterleaved(cs, createOffsets(significantSamples), dataType, alpha, alphaPremultiplied); case TIFFExtension.PLANARCONFIG_PLANAR: return ImageTypeSpecifiers.createBanded(cs, createOffsets(significantSamples), new int[significantSamples], dataType, alpha, alphaPremultiplied); default: throw new IIOException(String.format("Unsupported PlanarConfiguration (expected 1 or 2): %d", planarConfiguration)); } }
public static ImageTypeSpecifier createPacked(final ColorSpace colorSpace, final int redMask, final int greenMask, final int blueMask, final int alphaMask, final int transferType, boolean isAlphaPremultiplied) { if (transferType == DataBuffer.TYPE_BYTE || transferType == DataBuffer.TYPE_USHORT) { // ImageTypeSpecifier unconditionally uses bits == 32, we'll use a workaround for BYTE/USHORT types notNull(colorSpace, "colorSpace"); isTrue(colorSpace.getType() == ColorSpace.TYPE_RGB, colorSpace, "ColorSpace must be TYPE_RGB"); isTrue(redMask != 0 || greenMask != 0 || blueMask != 0 || alphaMask != 0, "No mask has at least 1 bit set"); int bits = transferType == DataBuffer.TYPE_BYTE ? 8 : 16; ColorModel colorModel = new DirectColorModel(colorSpace, bits, redMask, greenMask, blueMask, alphaMask, isAlphaPremultiplied, transferType); return new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)); } return ImageTypeSpecifier.createPacked(colorSpace, redMask, greenMask, blueMask, alphaMask, transferType, isAlphaPremultiplied); }
public static ImageTypeSpecifier createPackedGrayscale(final ColorSpace colorSpace, final int bits, final int dataType) { notNull(colorSpace, "colorSpace"); isTrue(colorSpace.getType() == ColorSpace.TYPE_GRAY, colorSpace, "ColorSpace must be TYPE_GRAY"); isTrue(bits == 1 || bits == 2 || bits == 4, bits, "bits must be 1, 2, or 4: %s"); isTrue(dataType == DataBuffer.TYPE_BYTE, dataType, "dataType must be TYPE_BYTE: %s"); int numEntries = 1 << bits; byte[] arr = new byte[numEntries]; byte[] arg = new byte[numEntries]; byte[] arb = new byte[numEntries]; // Scale array values according to color profile.. for (int i = 0; i < numEntries; i++) { float[] gray = new float[]{i / (float) (numEntries - 1)}; float[] rgb = colorSpace.toRGB(gray); arr[i] = (byte) (rgb[0] * 255); arg[i] = (byte) (rgb[1] * 255); arb[i] = (byte) (rgb[2]* 255); } ColorModel colorModel = new IndexColorModel(bits, numEntries, arr, arg, arb); SampleModel sampleModel = new MultiPixelPackedSampleModel(dataType, 1, 1, bits); return new ImageTypeSpecifier(colorModel, sampleModel); }
@Test public void testCreateDiscreteAlphaIndexedFromIndexColorModel8() { int[] colors = createIntLut(1 << 8); IndexColorModel colorModel = new IndexColorModel(8, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE); assertEquals( new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); }
@Test public void testCreateDiscreteAlphaIndexedFromIndexColorModel16() { int[] colors = createIntLut(1 << 16); IndexColorModel colorModel = new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT); assertEquals( new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); }