BufferedImage dest = new BufferedImage(this.getWidth(), this.getHeight(), cm.getPixelSize() < 8 ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_BYTE_INDEXED, cm); dest.createGraphics().drawImage(this.getImage(), 0, 0, null); return dest;
new ImageData( bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette ); data.transparentPixel = colorModel.getTransparentPixel(); WritableRaster raster = bufferedImage.getRaster();
private static boolean isIndexedPacked(IndexColorModel pColorModel) { return (pColorModel.getPixelSize() == 1 || pColorModel.getPixelSize() == 2 || pColorModel.getPixelSize() == 4); }
/** * Creates a {@code DiscreteAlphaIndexColorModel}, delegating color map look-ups * to the given {@code IndexColorModel}. * * @param icm The {@code IndexColorModel} delegate. Color map entries are assumed to be * fully opaque, any transparency or transparent index will be ignored. */ public DiscreteAlphaIndexColorModel(final IndexColorModel icm) { super( notNull(icm, "IndexColorModel").getPixelSize() * 2, new int[] {icm.getPixelSize(), icm.getPixelSize(), icm.getPixelSize(), icm.getPixelSize()}, icm.getColorSpace(), true, false, Transparency.TRANSLUCENT, icm.getTransferType() ); this.icm = icm; }
greens[trasparentIdx] = (byte) bg.getGreen(); blues[trasparentIdx] = (byte) bg.getBlue(); return new IndexColorModel(icm.getPixelSize(), size, reds, greens, blues); } else { return new IndexColorModel(icm.getPixelSize(), size, reds, greens, blues, alphas); } else { return new IndexColorModel(icm.getPixelSize(), size, reds, greens, blues);
public MutableIndexColorModel(final IndexColorModel base) { super(base.getPixelSize(), base.getComponentSize(), base.getColorSpace(), base.hasAlpha(), base.isAlphaPremultiplied(), base.getTransparency(), base.getTransferType()); this.rgbs = getRGBs(base); }
significantBits = colorMap.getPixelSize(); newTransferType = DataBuffer.TYPE_BYTE; } else if (DataBuffer.TYPE_BYTE == transferType && newMapSize == 257) {
cm = new IndexColorModel( cm.getPixelSize(), mapSize, rgb[0], rgb[1], rgb[2], transparencyIndex); } else { for (int k = 0; k < found; k++) { rgb[3][transparentPixelsIndexes.get(k)] = (byte) 0; cm = new IndexColorModel(cm.getPixelSize(), mapSize, rgb[0], rgb[1], rgb[2], rgb[3]);
int trans = icm.getTransparency() == Transparency.BITMASK ? BMHDChunk.MASK_TRANSPARENT_COLOR : BMHDChunk.MASK_NONE; int transPixel = icm.getTransparency() == Transparency.BITMASK ? icm.getTransparentPixel() : 0; header = new BMHDChunk(pImage.getWidth(), pImage.getHeight(), icm.getPixelSize(), trans, compression, transPixel);
private static boolean isIndexedPacked(IndexColorModel pColorModel) { return (pColorModel.getPixelSize() == 1 || pColorModel.getPixelSize() == 2 || pColorModel.getPixelSize() == 4); }
private static boolean isIndexedPacked(IndexColorModel pColorModel) { return (pColorModel.getPixelSize() == 1 || pColorModel.getPixelSize() == 2 || pColorModel.getPixelSize() == 4); }
/** * Creates a {@code DiscreteAlphaIndexColorModel}, delegating color map look-ups * to the given {@code IndexColorModel}. * * @param icm The {@code IndexColorModel} delegate. Color map entries are assumed to be * fully opaque, any transparency or transparent index will be ignored. */ public DiscreteAlphaIndexColorModel(final IndexColorModel icm) { super( notNull(icm, "IndexColorModel").getPixelSize() * 2, new int[] {icm.getPixelSize(), icm.getPixelSize(), icm.getPixelSize(), icm.getPixelSize()}, icm.getColorSpace(), true, false, Transparency.TRANSLUCENT, icm.getTransferType() ); this.icm = icm; }
index.getPixelSize(), index.getMapSize(), reds, greens, blues, alphas); LookupTable table = buildOpacityLookupTable(0, 1, -1, image.getSampleModel().getDataType());
final int pixelSize = oldCM.getPixelSize(); transparent &= (1 << pixelSize) - 1; forceBitmask = !translucent && oldCM.getTransparency() == Transparency.TRANSLUCENT;
private static ColorModel writeImageDictionary(Dimension imgDim, PSDictionary imageDict, ColorModel colorModel) { String w = Integer.toString(imgDim.width); String h = Integer.toString(imgDim.height); imageDict.put("/Width", w); imageDict.put("/Height", h); boolean invertColors = false; String decodeArray = getDecodeArray(colorModel.getNumColorComponents(), invertColors); int bitsPerComp = colorModel.getComponentSize(0); // Setup scanning for left-to-right and top-to-bottom imageDict.put("/ImageMatrix", "[" + w + " 0 0 " + h + " 0 0]"); if ((colorModel instanceof IndexColorModel)) { IndexColorModel indexColorModel = (IndexColorModel) colorModel; int c = indexColorModel.getMapSize(); int hival = c - 1; if (hival > 4095) { throw new UnsupportedOperationException("hival must not go beyond 4095"); } bitsPerComp = indexColorModel.getPixelSize(); int ceiling = ((int) Math.pow(2, bitsPerComp)) - 1; decodeArray = "[0 " + ceiling + "]"; } imageDict.put("/BitsPerComponent", Integer.toString(bitsPerComp)); imageDict.put("/Decode", decodeArray); return colorModel; }
/** * Returns an index color model with specified opacities (alphas). * @param icm an index color model from which to copy RGBs. * @param alpha array of opacities in the range [0.0,1.0]. * @return the index color model with alphas. */ public static IndexColorModel setAlpha(IndexColorModel icm, float[] alpha) { int bits = icm.getPixelSize(); int size = icm.getMapSize(); byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; byte[] a = new byte[size]; icm.getReds(r); icm.getGreens(g); icm.getBlues(b); int n = min(size,alpha.length); for (int i=0; i<n; ++i) a[i] = (byte)(255.0f*alpha[i]+0.5f); return new IndexColorModel(bits,size,r,g,b,a); }
/** * Returns an index color model with specified opacity (alpha). * @param icm an index color model from which to copy RGBs. * @param alpha opacity in the range [0.0,1.0]. * @return the index color model with alpha. */ public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) { int bits = icm.getPixelSize(); int size = icm.getMapSize(); byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; byte[] a = new byte[size]; icm.getReds(r); icm.getGreens(g); icm.getBlues(b); byte ia = (byte)(255.0*alpha+0.5); for (int i=0; i<size; ++i) a[i] = ia; return new IndexColorModel(bits,size,r,g,b,a); }
public MutableIndexColorModel(final IndexColorModel base) { super(base.getPixelSize(), base.getComponentSize(), base.getColorSpace(), base.hasAlpha(), base.isAlphaPremultiplied(), base.getTransparency(), base.getTransferType()); this.rgbs = getRGBs(base); }
icm.getPixelSize(), icm.getMapSize(), cmap, 0, true, -1, icm.getTransferType()); } else { targetCM = ColorModel.getRGBdefault();
int trans = icm.getTransparency() == Transparency.BITMASK ? BMHDChunk.MASK_TRANSPARENT_COLOR : BMHDChunk.MASK_NONE; int transPixel = icm.getTransparency() == Transparency.BITMASK ? icm.getTransparentPixel() : 0; header = new BMHDChunk(pImage.getWidth(), pImage.getHeight(), icm.getPixelSize(), trans, compression, transPixel);