ImageData data = new ImageData( bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette ); data.transparentPixel = colorModel.getTransparentPixel(); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[1];
/** Returns the transparent pixel value, or -1 if none. */ public final int getTransparentPixel() { final ColorModel cm = image.getColorModel(); return (cm instanceof IndexColorModel) ? ((IndexColorModel) cm).getTransparentPixel() : -1; }
private static Color getDefaultBackground(BufferedImage pImage) { if (pImage.getColorModel() instanceof IndexColorModel) { IndexColorModel cm = (IndexColorModel) pImage.getColorModel(); int transparent = cm.getTransparentPixel(); if (transparent >= 0) { return new Color(cm.getRGB(transparent), false); } } return null; }
/** * For a color-mapped raster, the no-data value is set to the {@link * IndexColorModel#getTransparentPixel() transparent pixel} * * @param colorMap * @return the index in the colorMap that's the transparent pixel as is to be used as no-data * value */ public static Number determineNoDataValue(IndexColorModel colorMap) { int noDataPixel = colorMap.getTransparentPixel(); if (-1 == noDataPixel) { // there were no room for a transparent pixel, find out the closest match noDataPixel = ColorUtilities.getTransparentPixel(colorMap); } return Integer.valueOf(noDataPixel); }
public BufferedImage filter(BufferedImage src, BufferedImage dest) { if (dest == null) dest = new BufferedImage( src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, icm); else { if (!(dest.getColorModel() instanceof IndexColorModel) || ((IndexColorModel) dest.getColorModel()).getTransparency() != this.transparencyIndex) throw new IllegalArgumentException(); if (((IndexColorModel) dest.getColorModel()).getTransparentPixel() != this.transparencyIndex) throw new IllegalArgumentException(); } final WritableRaster wr = dest.getRaster(); final Raster ir = src.getRaster(); this.rasterOp.filter(ir, wr); return dest; }
public InverseColorMapOp( final IndexColorModel destCM, final int quantizationColors, final int alphaThreshold) { this.rasterOp = new InverseColorMapRasterOp(destCM, quantizationColors, alphaThreshold); this.icm = destCM; this.alphaThreshold = alphaThreshold; hasAlpha = icm.hasAlpha(); transparencyIndex = icm.getTransparentPixel(); }
this.alphaThreshold = alphaThreshold; hasAlpha = icm.hasAlpha(); transparencyIndex = icm.getTransparentPixel(); final int mapSize = icm.getMapSize(); final byte[][] colorMap = new byte[3][hasAlpha ? (mapSize - 1) : mapSize];
int trasparentIdx = icm.getTransparentPixel(); if (icm.getTransparency() == Transparency.OPAQUE && trasparentIdx == -1) {
public BufferedImage createImageIndexed() { // TODO: This is very stupid, maybe we need a TYPE_CUSTOM image, with separate alphaRaster?! // As ICO has a separate bitmask, not related to palette index (allows 256 colors + trans) :-P IndexColorModel icm = createColorModel(); // This is slightly obscure, and should probably be moved.. Hashtable<String, Object> properties = null; if (entry instanceof DirectoryEntry.CUREntry) { properties = new Hashtable<>(1); properties.put("cursor_hotspot", ((DirectoryEntry.CUREntry) this.entry).getHotspot()); } BufferedImage image = new BufferedImage( icm, icm.createCompatibleWritableRaster(getWidth(), getHeight()), icm.isAlphaPremultiplied(), properties ); WritableRaster raster = image.getRaster(); // Make pixels transparent according to mask final int trans = icm.getTransparentPixel(); for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) { if (mask.isTransparent(x, y)) { bits[x + getWidth() * y] = trans; } } } raster.setSamples(0, 0, getWidth(), getHeight(), 0, bits); return image; }
int expectedLookedUp = icm.getRGB(icm.getTransparentPixel()); assertRGBEquals(x, y, expectedLookedUp & 0xff000000, actual & 0xff000000, 0);
int transparentPixel = colorMap.getTransparentPixel(); if (transparentPixel > -1) { return colorMap;
int transPixel = icm.getTransparency() == Transparency.BITMASK ? icm.getTransparentPixel() : 0; header = new BMHDChunk(pImage.getWidth(), pImage.getHeight(), icm.getPixelSize(), trans, compression, transPixel);
final int numComponents = cm.getNumComponents(); int transparency = cm.getTransparency(); int transparencyIndex = cm.getTransparentPixel(); final int mapSize = cm.getMapSize(); final int transparentRGB = transparentColor.getRGB() & 0x00FFFFFF;
int index = colors.getTransparentPixel(); if (index < 0) { index = 0;
@Test public void testGetColorModelGIF() { URL resource = getClass().getResource("/tux.gif"); assertNotNull(resource); Image source = Toolkit.getDefaultToolkit().createImage(resource); assertNotNull(source); BufferedImageFactory factory = new BufferedImageFactory(source); ColorModel colorModel = factory.getColorModel(); assertNotNull(colorModel); assertEquals(3, colorModel.getNumColorComponents()); assertEquals(ColorSpace.getInstance(ColorSpace.CS_sRGB), colorModel.getColorSpace()); assertTrue(colorModel instanceof IndexColorModel); assertTrue(colorModel.hasAlpha()); assertEquals(4, colorModel.getNumComponents()); assertTrue(((IndexColorModel) colorModel).getTransparentPixel() >= 0); assertEquals(Transparency.BITMASK, colorModel.getTransparency()); for (int i = 0; i < colorModel.getNumComponents(); i++) { assertEquals(8, colorModel.getComponentSize(i)); } }
private void assertHasAlpha(RenderedImage ri) { ColorModel cm = ri.getColorModel(); assertTrue(cm.hasAlpha()); int numComponents = cm.getNumComponents(); assertEquals(4, numComponents); // Make sure the topleft pixel is transparent Raster raster = ri.getTile(0, 0); if (cm instanceof ComponentColorModel) { // Get the value of the alpha component assertEquals(0, raster.getSample(0, 0, numComponents - 1)); } else if (cm instanceof IndexColorModel) { int transparentPixel = ((IndexColorModel) cm).getTransparentPixel(); assertEquals(transparentPixel, raster.getSample(0, 0, 0)); } } }
final int transparentPixel = index.getTransparentPixel(); for (int i = 0; i < alphas.length; i++) { alphas[i] = (byte) Math.round((0xFF & alphas[i]) * opacity);
transparent &= (1 << pixelSize) - 1; forceBitmask = !translucent && oldCM.getTransparency() == Transparency.TRANSLUCENT; if (forceBitmask || oldCM.getTransparentPixel() != transparent) { final int mapSize = Math.max(oldCM.getMapSize(), transparent + 1); final byte[][] RGBA = new byte[translucent ? 4 : 3][mapSize];
if (oldCM.getTransparentPixel() == suggestedTransparent) {
bgColorIndex = icm.getTransparentPixel();