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; }
static ImageTypeSpecifier createFromIndexColorModel(final IndexColorModel pColorModel) { // For some reason, we need a sample model return new ImageTypeSpecifier(notNull(pColorModel, "colorModel"), pColorModel.createCompatibleSampleModel(1, 1)) { @Override public final BufferedImage createBufferedImage(final int pWidth, final int pHeight) { try { // This is a fix for the super-method, that first creates a sample model, and then // creates a raster from it, using Raster.createWritableRaster. The problem with // that approach, is that it always creates a TYPE_CUSTOM BufferedImage for indexed images. WritableRaster raster = colorModel.createCompatibleWritableRaster(pWidth, pHeight); return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), new Hashtable()); } catch (NegativeArraySizeException e) { // Exception most likely thrown from a DataBuffer constructor throw new IllegalArgumentException("Array size > Integer.MAX_VALUE!"); } } }; } }
private ImageLayout getImageLayout(RenderedImage image, RenderingHints hints) { ImageLayout layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout == null) layout = new ImageLayout(image); layout.setColorModel(this.paletteBuilder.getIndexColorModel()); layout.setSampleModel( paletteBuilder .getIndexColorModel() .createCompatibleSampleModel(image.getWidth(), image.getHeight())); return layout; }
public ColorInversion( RenderedImage image, IndexColorModel icm, int quantizationColors, int alpaThreshold) { super(image, new ImageLayout(image), null, false); this.setSource(image, 0); this.op = new InverseColorMapRasterOp(icm, quantizationColors, alpaThreshold); // setlayout; setImageLayout( new ImageLayout(image) .setColorModel(icm) .setSampleModel( icm.createCompatibleSampleModel( image.getWidth(), image.getHeight()))); }
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 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; }
IndexedImageTypeSpecifier(IndexColorModel pColorModel) { // For some reason, we need a sample model super(pColorModel, pColorModel.createCompatibleSampleModel(1, 1)); }
@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) ); }
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; }
static ImageTypeSpecifier createFromIndexColorModel(final IndexColorModel pColorModel) { // For some reason, we need a sample model return new ImageTypeSpecifier(notNull(pColorModel, "colorModel"), pColorModel.createCompatibleSampleModel(1, 1)) { @Override public final BufferedImage createBufferedImage(final int pWidth, final int pHeight) { try { // This is a fix for the super-method, that first creates a sample model, and then // creates a raster from it, using Raster.createWritableRaster. The problem with // that approach, is that it always creates a TYPE_CUSTOM BufferedImage for indexed images. WritableRaster raster = colorModel.createCompatibleWritableRaster(pWidth, pHeight); return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), new Hashtable()); } catch (NegativeArraySizeException e) { // Exception most likely thrown from a DataBuffer constructor throw new IllegalArgumentException("Array size > Integer.MAX_VALUE!"); } } }; } }
public static BufferedImage createIndexedImage(int width, int height, byte[] data, IndexColorModel cm) { final int numSamples = data.length; SampleModel sm = cm.createCompatibleSampleModel(width, height); DataBuffer db = new DataBufferByte(data, numSamples); WritableRaster wr = WritableRaster.createWritableRaster(sm, db, null); return new BufferedImage(cm, wr, false, null); }
private ImageLayout getImageLayout(RenderedImage image, RenderingHints hints) { ImageLayout layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout == null) layout = new ImageLayout(image); layout.setColorModel(this.paletteBuilder.getIndexColorModel()); layout.setSampleModel(paletteBuilder.getIndexColorModel().createCompatibleSampleModel(image.getWidth(),image.getHeight())); return layout; }
public BufferedImage createImage() { bProcessor = (ByteProcessor)imp.getProcessor(); byte[] pixels = (byte[])bProcessor.getPixels(); IndexColorModel cm = getDefaultColorModel(); SampleModel sm = cm.createCompatibleSampleModel(w, h); DataBufferByte db = new DataBufferByte(pixels, w * h, 0); WritableRaster raster = Raster.createWritableRaster(sm, db, null); return new BufferedImage(cm, raster, false, null); }
public ColorInversion(RenderedImage image,IndexColorModel icm, int quantizationColors, int alpaThreshold) { super(image, new ImageLayout(image), null, false); this.setSource(image, 0); this.op=new InverseColorMapRasterOp(icm,quantizationColors,alpaThreshold); // setlayout; setImageLayout( new ImageLayout(image).setColorModel(icm).setSampleModel(icm.createCompatibleSampleModel(image.getWidth(), image.getHeight()))); }
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 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; }
@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) ); }
/** * Creates a greyscale image from the given <code>{@link RasterDataNode}</code>. * <p/> * <p>The method uses the given raster data node's image information (an instance of <code>{@link * ImageInfo}</code>) to create the image. * * @param rasterDataNode the raster data node, must not be <code>null</code> * @param pm a monitor to inform the user about progress * * @return the color indexed image * * @throws IOException if the given raster data is not loaded and reload causes an I/O error * @see org.esa.beam.framework.datamodel.RasterDataNode#getImageInfo() */ public static BufferedImage createColorIndexedImage(final RasterDataNode rasterDataNode, ProgressMonitor pm) throws IOException { Guardian.assertNotNull("rasterDataNode", rasterDataNode); final int width = rasterDataNode.getSceneRasterWidth(); final int height = rasterDataNode.getSceneRasterHeight(); final ImageInfo imageInfo = rasterDataNode.getImageInfo(ProgressMonitor.NULL); final double newMin = imageInfo.getColorPaletteDef().getMinDisplaySample(); final double newMax = imageInfo.getColorPaletteDef().getMaxDisplaySample(); final byte[] colorIndexes = rasterDataNode.quantizeRasterData(newMin, newMax, 1.0, pm); final IndexColorModel cm = imageInfo.createIndexColorModel(rasterDataNode); final SampleModel sm = cm.createCompatibleSampleModel(width, height); final DataBuffer db = new DataBufferByte(colorIndexes, colorIndexes.length); final WritableRaster wr = WritableRaster.createWritableRaster(sm, db, null); return new BufferedImage(cm, wr, false, null); }
@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) ); }