Examples of IndexColorModel


Examples of java.awt.image.IndexColorModel

            }
            if (sampleModel.getNumBands() != 1) {
                throw new RuntimeException(PropertyUtil.getString("PNGImageEncoder3"));
            }

            IndexColorModel icm = (IndexColorModel)colorModel;
            int size = icm.getMapSize();

            redPalette = new byte[size];
            greenPalette = new byte[size];
            bluePalette = new byte[size];
            alphaPalette = new byte[size];

            icm.getReds(redPalette);
            icm.getGreens(greenPalette);
            icm.getBlues(bluePalette);
            icm.getAlphas(alphaPalette);

            this.bpp = 1;

            if (param == null) {
                param = createGrayParam(redPalette,
View Full Code Here

Examples of java.awt.image.IndexColorModel

        SampleModel sm = theTile.getSampleModel();
        ColorModel  cm;

        if ((colorType == PNG_COLOR_PALETTE) && !expandPalette) {
            if (outputHasAlphaPalette) {
                cm = new IndexColorModel(bitDepth,
                                                 paletteEntries,
                                                 redPalette,
                                                 greenPalette,
                                                 bluePalette,
                                                 alphaPalette);
            } else {
                cm = new IndexColorModel(bitDepth,
                                                 paletteEntries,
                                                 redPalette,
                                                 greenPalette,
                                                 bluePalette);
            }
        } else if ((colorType == PNG_COLOR_GRAY) &&
                   (bitDepth < 8) && !output8BitGray) {
            byte[] palette = expandBits[bitDepth];
            cm = new IndexColorModel(bitDepth,
                                             palette.length,
                                             palette,
                                             palette,
                                             palette);
        } else {
View Full Code Here

Examples of java.awt.image.IndexColorModel

            colorModel instanceof IndexColorModel &&
            dataType != DataBuffer.TYPE_BYTE) {
            // Don't support (unsigned) short palette-color images.
            throw new RuntimeException(PropertyUtil.getString("TIFFImageEncoder6"));
        }
        IndexColorModel icm = null;
        int sizeOfColormap = 0;
        char[] colormap = null;

        // Set image type.
        int imageType = TIFF_UNSUPPORTED;
        int numExtraSamples = 0;
        int extraSampleType = EXTRA_SAMPLE_UNSPECIFIED;
        if (colorModel instanceof IndexColorModel) { // Bilevel or palette
            icm = (IndexColorModel)colorModel;
            int mapSize = icm.getMapSize();

            if (sampleSize[0] == 1 && numBands == 1) { // Bilevel image

                if (mapSize != 2) {
                    throw new IllegalArgumentException(PropertyUtil.getString("TIFFImageEncoder7"));
                }

                byte[] r = new byte[mapSize];
                icm.getReds(r);
                byte[] g = new byte[mapSize];
                icm.getGreens(g);
                byte[] b = new byte[mapSize];
                icm.getBlues(b);

                if ((r[0] & 0xff) == 0 &&
                    (r[1] & 0xff) == 255 &&
                    (g[0] & 0xff) == 0 &&
                    (g[1] & 0xff) == 255 &&
                    (b[0] & 0xff) == 0 &&
                    (b[1] & 0xff) == 255) {

                    imageType = TIFF_BILEVEL_BLACK_IS_ZERO;

                } else if ((r[0] & 0xff) == 255 &&
                           (r[1] & 0xff) == 0 &&
                           (g[0] & 0xff) == 255 &&
                           (g[1] & 0xff) == 0 &&
                           (b[0] & 0xff) == 255 &&
                           (b[1] & 0xff) == 0) {

                    imageType = TIFF_BILEVEL_WHITE_IS_ZERO;

                } else {
                    imageType = TIFF_PALETTE;
                }

            } else if (numBands == 1) { // Non-bilevel image.
                // Palette color image.
                imageType = TIFF_PALETTE;
            }
        } else if (colorModel == null) {

            if (sampleSize[0] == 1 && numBands == 1) { // bilevel
                imageType = TIFF_BILEVEL_BLACK_IS_ZERO;
            } else { // generic image
                imageType = TIFF_GENERIC;
                if (numBands > 1) {
                    numExtraSamples = numBands - 1;
                }
            }

        } else { // colorModel is non-null but not an IndexColorModel
            ColorSpace colorSpace = colorModel.getColorSpace();

            switch(colorSpace.getType()) {
            case ColorSpace.TYPE_CMYK:
                imageType = TIFF_CMYK;
                break;
            case ColorSpace.TYPE_GRAY:
                imageType = TIFF_GRAY;
                break;
            case ColorSpace.TYPE_Lab:
                imageType = TIFF_CIELAB;
                break;
            case ColorSpace.TYPE_RGB:
                if (compression == COMP_JPEG_TTN2
                        && encodeParam.getJPEGCompressRGBToYCbCr()) {
                    imageType = TIFF_YCBCR;
                } else {
                    imageType = TIFF_RGB;
                }
                break;
            case ColorSpace.TYPE_YCbCr:
                imageType = TIFF_YCBCR;
                break;
            default:
                imageType = TIFF_GENERIC; // generic
                break;
            }

            if (imageType == TIFF_GENERIC) {
                numExtraSamples = numBands - 1;
            } else if (numBands > 1) {
                numExtraSamples = numBands - colorSpace.getNumComponents();
            }

            if (numExtraSamples == 1 && colorModel.hasAlpha()) {
                extraSampleType = colorModel.isAlphaPremultiplied() ?
                    EXTRA_SAMPLE_ASSOCIATED_ALPHA :
                    EXTRA_SAMPLE_UNASSOCIATED_ALPHA;
            }
        }

        if (imageType == TIFF_UNSUPPORTED) {
            throw new RuntimeException(PropertyUtil.getString("TIFFImageEncoder8"));
        }

        int photometricInterpretation = -1;
        switch (imageType) {

        case TIFF_BILEVEL_WHITE_IS_ZERO:
            photometricInterpretation = 0;
            break;

        case TIFF_BILEVEL_BLACK_IS_ZERO:
            photometricInterpretation = 1;
            break;

        case TIFF_GRAY:
        case TIFF_GENERIC:
            // Since the CS_GRAY colorspace is always of type black_is_zero
            photometricInterpretation = 1;
            break;

        case TIFF_PALETTE:
            photometricInterpretation = 3;

            icm = (IndexColorModel)colorModel;
            sizeOfColormap = icm.getMapSize();

            byte[] r = new byte[sizeOfColormap];
            icm.getReds(r);
            byte[] g = new byte[sizeOfColormap];
            icm.getGreens(g);
            byte[] b = new byte[sizeOfColormap];
            icm.getBlues(b);

            int redIndex = 0, greenIndex = sizeOfColormap;
            int blueIndex = 2 * sizeOfColormap;
            colormap = new char[sizeOfColormap * 3];
            for (int i = 0; i < sizeOfColormap; i++) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.