List of usage examples for java.awt.image IndexColorModel IndexColorModel
public IndexColorModel(int bits, int size, int[] cmap, int start, int transferType, BigInteger validBits)
From source file:org.apache.xmlgraphics.image.codec.png.PNGRed.java
private void parse_IEND_chunk(final PNGChunk chunk) throws IOException { // Store text strings final int textLen = this.textKeys.size(); final String[] textArray = new String[2 * textLen]; for (int i = 0; i < textLen; ++i) { final String key = this.textKeys.get(i); final String val = this.textStrings.get(i); textArray[2 * i] = key;/*w w w .jav a2s. c o m*/ textArray[2 * i + 1] = val; if (this.emitProperties) { final String uniqueKey = "text_" + i + ':' + key; this.properties.put(uniqueKey.toLowerCase(), val); } } if (this.encodeParam != null) { this.encodeParam.setText(textArray); } // Store compressed text strings final int ztextLen = this.ztextKeys.size(); final String[] ztextArray = new String[2 * ztextLen]; for (int i = 0; i < ztextLen; ++i) { final String key = this.ztextKeys.get(i); final String val = this.ztextStrings.get(i); ztextArray[2 * i] = key; ztextArray[2 * i + 1] = val; if (this.emitProperties) { final String uniqueKey = "ztext_" + i + ':' + key; this.properties.put(uniqueKey.toLowerCase(), val); } } if (this.encodeParam != null) { this.encodeParam.setCompressedText(ztextArray); } // Parse prior IDAT chunks final InputStream seqStream = new SequenceInputStream(Collections.enumeration(this.streamVec)); final InputStream infStream = new InflaterInputStream(seqStream, new Inflater()); this.dataStream = new DataInputStream(infStream); // Create an empty WritableRaster int depth = this.bitDepth; if (this.colorType == PNG_COLOR_GRAY && this.bitDepth < 8 && this.output8BitGray) { depth = 8; } if (this.colorType == PNG_COLOR_PALETTE && this.expandPalette) { depth = 8; } final int width = this.bounds.width; final int height = this.bounds.height; final int bytesPerRow = (this.outputBands * width * depth + 7) / 8; final int scanlineStride = depth == 16 ? bytesPerRow / 2 : bytesPerRow; this.theTile = createRaster(width, height, this.outputBands, scanlineStride, depth); if (this.performGammaCorrection && this.gammaLut == null) { initGammaLut(this.bitDepth); } if (this.postProcess == POST_GRAY_LUT || this.postProcess == POST_GRAY_LUT_ADD_TRANS || this.postProcess == POST_GRAY_LUT_ADD_TRANS_EXP) { initGrayLut(this.bitDepth); } decodeImage(this.interlaceMethod == 1); // Free resources associated with compressed data. this.dataStream.close(); infStream.close(); seqStream.close(); this.streamVec = null; final SampleModel sm = this.theTile.getSampleModel(); ColorModel cm; if (this.colorType == PNG_COLOR_PALETTE && !this.expandPalette) { if (this.outputHasAlphaPalette) { cm = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette, this.greenPalette, this.bluePalette, this.alphaPalette); } else { cm = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette, this.greenPalette, this.bluePalette); } } else if (this.colorType == PNG_COLOR_GRAY && this.bitDepth < 8 && !this.output8BitGray) { final byte[] palette = this.expandBits[this.bitDepth]; cm = new IndexColorModel(this.bitDepth, palette.length, palette, palette, palette); } else { cm = createComponentColorModel(sm); } init((CachableRed) null, this.bounds, cm, sm, 0, 0, this.properties); }
From source file:org.apache.xmlgraphics.image.loader.impl.PNGFile.java
public ImageRawPNG getImageRawPNG(final ImageInfo info) throws ImageException, IOException { try (final InputStream seqStream = new SequenceInputStream(Collections.enumeration(this.streamVec))) { switch (this.colorType) { case PNG_COLOR_GRAY: if (this.hasPalette) { throw new ImageException("Corrupt PNG: color palette is not allowed!"); }//from w w w. j a va2 s.c o m this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); break; case PNG_COLOR_RGB: // actually a check of the sRGB chunk would be necessary to // confirm // if it's really sRGB this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); break; case PNG_COLOR_PALETTE: if (this.hasAlphaPalette) { this.colorModel = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette, this.greenPalette, this.bluePalette, this.alphaPalette); } else { this.colorModel = new IndexColorModel(this.bitDepth, this.paletteEntries, this.redPalette, this.greenPalette, this.bluePalette); } break; case PNG_COLOR_GRAY_ALPHA: if (this.hasPalette) { throw new ImageException("Corrupt PNG: color palette is not allowed!"); } this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); break; case PNG_COLOR_RGB_ALPHA: // actually a check of the sRGB chunk would be necessary to // confirm // if it's really sRGB this.colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); break; default: throw new ImageException("Unsupported color type: " + this.colorType); } // the iccProfile is still null for now final ImageRawPNG rawImage = new ImageRawPNG(info, seqStream, this.colorModel, this.bitDepth, this.iccProfile); if (this.isTransparent) { if (this.colorType == PNG_COLOR_GRAY) { rawImage.setGrayTransparentAlpha(this.grayTransparentAlpha); } else if (this.colorType == PNG_COLOR_RGB) { rawImage.setRGBTransparentAlpha(this.redTransparentAlpha, this.greenTransparentAlpha, this.blueTransparentAlpha); } else if (this.colorType == PNG_COLOR_PALETTE) { rawImage.setTransparent(); } else { // } } return rawImage; } }
From source file:org.kuali.kra.printing.service.impl.PersonSignatureServiceImpl.java
/** * This method is to get buffered image based on predefined parameters * @param params/*from www . j a v a 2 s .c o m*/ * @param imageData * @return */ protected BufferedImage getBufferedImage(ImageParameters params, byte[] imageData) { byte[] transparentColors = new byte[] { (byte) 0xFF, (byte) 0xFF }; byte[] colors = new byte[] { 0, (byte) 0xFF }; IndexColorModel colorModel = new IndexColorModel(1, 2, colors, colors, colors, transparentColors); BufferedImage image = new BufferedImage(params.getWidth(), params.getHeight(), BufferedImage.TYPE_BYTE_BINARY, colorModel); DataBufferByte buffer = new DataBufferByte(imageData, 1); WritableRaster raster = Raster.createPackedRaster(buffer, params.getWidth(), params.getHeight(), params.getBitsPerComponent(), new Point(0, 0)); image.setData(raster); return image; }