Package java.awt.image

Examples of java.awt.image.IndexColorModel


        width = bi.getWidth();
        height = bi.getHeight();

        int numPixels = width * height;

        IndexColorModel icm = (IndexColorModel) bi.getColorModel();
        int transparentIndex = icm.getTransparentPixel();
        int numColors = icm.getMapSize();

        // Figure out how many bits to use.
        int bitsPerPixel;
        if (numColors <= 2)
            bitsPerPixel = 1;
        else if (numColors <= 4)
            bitsPerPixel = 2;
        else if (numColors <= 16)
            bitsPerPixel = 4;
        else
            bitsPerPixel = 8;

        int initCodeSize;

        // Calculate number of bits we are expecting
        countdown = numPixels;

        // Indicate which pass we are on (if interlace)
        pass = 0;

        // The initial code size
        if (bitsPerPixel <= 1)
            initCodeSize = 2;
        else
            initCodeSize = bitsPerPixel;

        // Set up the current x and y position
        curx = 0;
        cury = 0;
        row = new int[width];

        // Write the Magic header
        writeString("GIF89a");

        // Write out the screen width and height
        writeWord(width);
        writeWord(height);

        // Indicate that there is a global colour map
        byte flags = (byte) 0x80; // Yes, there is a color map
        // OR in the resolution
        flags |= (byte) ((8 - 1) << 4);
        // Not sorted
        // OR in the Bits per Pixel
        flags |= (byte) ((bitsPerPixel - 1));
        // Write it out
        out.write(flags);

        // Write out the Background colour
        out.write((byte) 0);

        // Pixel aspect ratio - 1:1.
        //out.write((byte) 49);
        // Java's GIF reader currently has a bug, if the aspect ratio byte is
        // not zero it throws an ImageFormatException.  It doesn't know that
        // 49 means a 1:1 aspect ratio.  Well, whatever, zero works with all
        // the other decoders I've tried so it probably doesn't hurt.
        out.write((byte) 0);

        // Write out the Global Colour Map
        // Turn colors into colormap entries.
        int mapSize = 1 << bitsPerPixel;
        byte[] reds = new byte[mapSize], greens = new byte[mapSize], blues = new byte[mapSize];
        icm.getReds(reds);
        icm.getGreens(greens);
        icm.getBlues(blues);

        for (int i = 0; i < mapSize; ++i) {
            out.write(reds[i]);
            out.write(greens[i]);
            out.write(blues[i]);
View Full Code Here


       BufferedImage assignImageColors(BufferedImage image, boolean dither, boolean alphaToBitmask) {
           // Allocate image colormap.
           colorMap = new byte[4][numColors];
           root.fillColorMap(colorMap, firstColor);
           // create the right color model, depending on transparency settings:
           IndexColorModel icm;
          
           int width = image.getWidth();
           int height = image.getHeight();
          
           if (alphaToBitmask) {
               if (addTransparency) {
                   icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2], 0);
               } else {
                   icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2]);
               }
           } else {
               icm = new IndexColorModel(depth, numColors, colorMap[0], colorMap[1], colorMap[2], colorMap[3]);
           }

           // create the indexed BufferedImage:
           BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, icm);
View Full Code Here

            g[i + 1] = (byte) c.getGreen();
            b[i + 1] = (byte) c.getBlue();
            a[i + 1] = (byte) c.getAlpha();
        }

        IndexColorModel colorModel = new IndexColorModel(8, r.length, r, g, b, a);

        // create a image with the reduced colors
        BufferedImage reducedImage = new BufferedImage(width, height,
                BufferedImage.TYPE_BYTE_INDEXED, colorModel);
View Full Code Here

            g[i] = (byte) c.getGreen();
            b[i] = (byte) c.getBlue();
            a[i] = (byte) c.getAlpha();
        }

        IndexColorModel colorModel = new IndexColorModel(8, r.length, r, g, b, a);

        // create a image with the reduced colors
        BufferedImage reducedImage = new BufferedImage(width, height,
                BufferedImage.TYPE_BYTE_INDEXED, colorModel);
View Full Code Here

                // Set up the palette
                byte r[] = new byte[] { (byte) 255, (byte) 0 };
                byte g[] = new byte[] { (byte) 255, (byte) 0 };
                byte b[] = new byte[] { (byte) 255, (byte) 0 };

                colorModel = new IndexColorModel(1, 2, r, g, b);

            } else {

                image_type = XTIFF.TYPE_GREYSCALE_WHITE_IS_ZERO;

                if (bitsPerSample[0] == 4) {
                    sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 4);

                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            false);

                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);

                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            false);

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                            tileWidth,
                            tileHeight,
                            bands);

                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else {
                    throw new IllegalArgumentException(JaiI18N.getString("XTIFFImageDecoder14"));
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_BLACK_IS_ZERO:

            bands = 1;

            // Bilevel or Grayscale - BlackIsZero
            if (bitsPerSample[0] == 1) {

                image_type = XTIFF.TYPE_BILEVEL_BLACK_IS_ZERO;

                // Keep pixels packed, use IndexColorModel
                sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 1);

                // Set up the palette
                byte r[] = new byte[] { (byte) 0, (byte) 255 };
                byte g[] = new byte[] { (byte) 0, (byte) 255 };
                byte b[] = new byte[] { (byte) 0, (byte) 255 };

                // 1 Bit pixels packed into a byte, use IndexColorModel
                colorModel = new IndexColorModel(1, 2, r, g, b);

            } else {

                image_type = XTIFF.TYPE_GREYSCALE_BLACK_IS_ZERO;

                if (bitsPerSample[0] == 4) {
                    sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 4);
                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            true);
                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);
                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                            tileWidth,
                            tileHeight,
                            bands);
                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else {
                    throw new IllegalArgumentException(JaiI18N.getString("XTIFFImageDecoder14"));
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_RGB:

            bands = samplesPerPixel;

            // RGB full color image
            if (bitsPerSample[0] == 8) {

                sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                        tileWidth,
                        tileHeight,
                        bands);
            } else if (bitsPerSample[0] == 16) {

                sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                        tileWidth,
                        tileHeight,
                        bands);
            } else {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder15"));
            }

            if (samplesPerPixel < 3) {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder1"));

            } else if (samplesPerPixel == 3) {

                image_type = XTIFF.TYPE_RGB;
                // No alpha
                colorModel = ImageCodec.createComponentColorModel(sampleModel);

            } else if (samplesPerPixel == 4) {

                if (extraSamples == 0) {

                    image_type = XTIFF.TYPE_ORGB;
                    // Transparency.OPAQUE signifies image data that is
                    // completely opaque, meaning that all pixels have an alpha
                    // value of 1.0. So the extra band gets ignored, which is
                    // what we want.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            false,
                            Transparency.OPAQUE);

                } else if (extraSamples == 1) {

                    image_type = XTIFF.TYPE_ARGB_PRE;
                    // Pre multiplied alpha.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            true,
                            Transparency.TRANSLUCENT);

                } else if (extraSamples == 2) {

                    image_type = XTIFF.TYPE_ARGB;
                    // The extra sample here is unassociated alpha, usually a
                    // transparency mask, also called soft matte.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            false,
                            Transparency.BITMASK);
                }

            } else {
                image_type = XTIFF.TYPE_RGB_EXTRA;

                // For this case we can't display the image, so there is no
                // point in trying to reformat the data to be BGR followed by
                // the ExtraSamples, the way Java2D would like it, because
                // Java2D can't display it anyway. Therefore create a sample
                // model with increasing bandOffsets, and keep the colorModel
                // as null, as there is no appropriate ColorModel.

                int bandOffsets[] = new int[bands];
                for (int i = 0; i < bands; i++) {
                    bandOffsets[i] = i;
                }

                if (bitsPerSample[0] == 8) {

                    sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, bands, bands
                            * tileWidth, bandOffsets);
                    colorModel = null;

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = new PixelInterleavedSampleModel(dataType, tileWidth, tileHeight, bands, bands
                            * tileWidth, bandOffsets);
                    colorModel = null;
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_PALETTE:

            image_type = XTIFF.TYPE_PALETTE;

            // Get the colormap
            XTIFFField cfield = dir.getField(XTIFF.TIFFTAG_COLORMAP);
            if (cfield == null) {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder2"));
            } else {
                colormap = cfield.getAsChars();
            }

            // Could be either 1 or 3 bands depending on whether we use
            // IndexColorModel or not.
            if (decodePaletteAsShorts) {
                bands = 3;

                if (bitsPerSample[0] != 4 && bitsPerSample[0] != 8
                        && bitsPerSample[0] != 16) {
                    throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder13"));
                }

                // If no SampleFormat tag was specified and if the
                // bitsPerSample are less than or equal to 8, then the
                // dataType was initially set to byte, but now we want to
                // expand the palette as shorts, so the dataType should
                // be ushort.
                if (dataType == DataBuffer.TYPE_BYTE) {
                    dataType = DataBuffer.TYPE_USHORT;
                }

                // Data will have to be unpacked into a 3 band short image
                // as we do not have a IndexColorModel that can deal with
                // a colormodel whose entries are of short data type.
                sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                        tileWidth,
                        tileHeight,
                        bands);
                colorModel = ImageCodec.createComponentColorModel(sampleModel);

            } else {

                bands = 1;

                if (bitsPerSample[0] == 4) {
                    // Pixel data will not be unpacked, will use MPPSM to store
                    // packed data and IndexColorModel to do the unpacking.
                    sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, bitsPerSample[0]);
                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);
                } else if (bitsPerSample[0] == 16) {

                    // Here datatype has to be unsigned since we are storing
                    // indices into the IndexColorModel palette. Ofcourse
                    // the actual palette entries are allowed to be negative.
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_USHORT,
                            tileWidth,
                            tileHeight,
                            bands);
                } else {
                    throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder13"));
                }

                int bandLength = colormap.length / 3;
                byte r[] = new byte[bandLength];
                byte g[] = new byte[bandLength];
                byte b[] = new byte[bandLength];

                int gIndex = bandLength;
                int bIndex = bandLength * 2;

                if (dataType == DataBuffer.TYPE_SHORT) {

                    for (int i = 0; i < bandLength; i++) {
                        r[i] = param.decodeSigned16BitsTo8Bits((short) colormap[i]);
                        g[i] = param.decodeSigned16BitsTo8Bits((short) colormap[gIndex
                                + i]);
                        b[i] = param.decodeSigned16BitsTo8Bits((short) colormap[bIndex
                                + i]);
                    }

                } else {

                    for (int i = 0; i < bandLength; i++) {
                        r[i] = param.decode16BitsTo8Bits(colormap[i] & 0xffff);
                        g[i] = param.decode16BitsTo8Bits(colormap[gIndex + i] & 0xffff);
                        b[i] = param.decode16BitsTo8Bits(colormap[bIndex + i] & 0xffff);
                    }

                }

                colorModel = new IndexColorModel(bitsPerSample[0], bandLength, r, g, b);
            }

            break;

        case XTIFF.PHOTOMETRIC_TRANSPARENCY:
View Full Code Here

        if (colorModel != null && colorModel instanceof IndexColorModel
                && dataTypeIsShort) {
            // Don't support (unsigned) short palette-color images.
            throw new Error(JaiI18N.getString("TIFFImageEncoder2"));
        }
        IndexColorModel icm = null;
        int sizeOfColormap = 0;
        char colormap[] = null;

        // Basic fields - have to be in increasing numerical order BILEVEL
        // ImageWidth 256
        // ImageLength 257
        // BitsPerSample 258
        // Compression 259
        // PhotoMetricInterpretation 262
        // StripOffsets 273
        // RowsPerStrip 278
        // StripByteCounts 279
        // XResolution 282
        // YResolution 283
        // ResolutionUnit 296

        int photometricInterpretation = XTIFF.PHOTOMETRIC_RGB;
        int imageType = XTIFF_FULLCOLOR;

        // IMAGE TYPES POSSIBLE

        // Bilevel
        // BitsPerSample = 1
        // Compression = 1, 2, or 32773
        // PhotometricInterpretation either 0 or 1

        // Greyscale
        // BitsPerSample = 4 or 8
        // Compression = 1, 32773
        // PhotometricInterpretation either 0 or 1

        // Palette
        // ColorMap 320
        // BitsPerSample = 4 or 8
        // PhotometrciInterpretation = 3

        // Full color
        // BitsPerSample = 8, 8, 8
        // SamplesPerPixel = 3 or more 277
        // Compression = 1, 32773
        // PhotometricInterpretation = 2

        if (colorModel instanceof IndexColorModel) {

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

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

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

                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 = XTIFF_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 = XTIFF_BILEVEL_WHITE_IS_ZERO;

                } else {
                    imageType = XTIFF_PALETTE;
                }

            } else {
                // Palette color image.
                imageType = XTIFF_PALETTE;
            }
        } else {

            // If it is not an IndexColorModel, it can either be a greyscale
            // image or a full color image

            if ((colorModel == null || colorModel.getColorSpace().getType() == ColorSpace.TYPE_GRAY)
                    && numBands == 1) {
                // Greyscale image
                imageType = XTIFF_GREYSCALE;
            } else {
                // Full color image
                imageType = XTIFF_FULLCOLOR;
            }
        }

        switch (imageType) {

        case XTIFF_BILEVEL_WHITE_IS_ZERO:
            photometricInterpretation = XTIFF.PHOTOMETRIC_WHITE_IS_ZERO;
            break;

        case XTIFF_BILEVEL_BLACK_IS_ZERO:
            photometricInterpretation = XTIFF.PHOTOMETRIC_BLACK_IS_ZERO;
            break;

        case XTIFF_GREYSCALE:
            // Since the CS_GRAY colorspace is always of type black_is_zero
            photometricInterpretation = XTIFF.PHOTOMETRIC_BLACK_IS_ZERO;
            break;

        case XTIFF_PALETTE:
            photometricInterpretation = XTIFF.PHOTOMETRIC_PALETTE;

            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];
 
View Full Code Here

      cmap[0] = 0x00FFFFFF; // transparent and white
      for (int i = 1; i != 256; i++) {
        // 1 to 255 renders as (almost) white to black
        cmap[i] = 0xFF000000 | ((0xFF - i) * 0x010101);
      }
      IndexColorModel colorModel = new IndexColorModel(8,
              cmap.length, cmap, 0, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

      int[] shape = array.getShape();
      BufferedImage bi = new BufferedImage(shape[1], shape[0],BufferedImage.TYPE_BYTE_INDEXED, colorModel);

View Full Code Here

                throw new ImageReadException("Parsing XBM file failed, " +
                        "punctuation error");
        }

        int[] palette = {0xffffff, 0x000000};
        ColorModel colorModel = new IndexColorModel(1, 2,
                palette, 0, false, -1, DataBuffer.TYPE_BYTE);
        DataBufferByte dataBuffer = new DataBufferByte(imageData, imageData.length);
        WritableRaster raster = WritableRaster.createPackedRaster(dataBuffer,
                xbmHeader.width, xbmHeader.height, 1, null);
        BufferedImage image = new BufferedImage(colorModel, raster,
                colorModel.isAlphaPremultiplied(), new Properties());
        return image;
    }
View Full Code Here

            else
            {
                raster =  WritableRaster.createPackedRaster(dataBuffer,
                        xSize, ySize, pcxHeader.bitsPerPixel, null);
            }
            IndexColorModel colorModel = new IndexColorModel(pcxHeader.bitsPerPixel,
                    1 << pcxHeader.bitsPerPixel, palette, 0, false, -1, DataBuffer.TYPE_BYTE);
            return new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
        }
        else if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
                && pcxHeader.nPlanes <= 4)
        {
            IndexColorModel colorModel = new IndexColorModel(pcxHeader.nPlanes,
                    1 << pcxHeader.nPlanes, pcxHeader.colormap, 0, false, -1, DataBuffer.TYPE_BYTE);
            BufferedImage image = new BufferedImage(xSize, ySize, BufferedImage.TYPE_BYTE_BINARY, colorModel);
            byte[] unpacked = new byte[xSize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                int nextByte = 0;
                Arrays.fill(unpacked, (byte) 0);
                for (int plane = 0; plane < pcxHeader.nPlanes; plane++)
                {
                    for (int i = 0; i < pcxHeader.bytesPerLine; i++)
                    {
                        int b = 0xff & scanline[nextByte++];
                        for (int j = 0; j < 8 && 8*i + j < unpacked.length; j++)
                            unpacked[8*i + j] |= (byte) (((b >> (7 - j)) & 0x1) << plane);
                    }
                }
                image.getRaster().setDataElements(0, y, xSize, 1, unpacked);
            }
            return image;
        }
        else if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3)
        {
            byte[][] image = new byte[3][];
            image[0] = new byte[xSize*ySize];
            image[1] = new byte[xSize*ySize];
            image[2] = new byte[xSize*ySize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                System.arraycopy(scanline, 0, image[0], y*xSize, xSize);
                System.arraycopy(scanline, pcxHeader.bytesPerLine,
                        image[1], y*xSize, xSize);
                System.arraycopy(scanline, 2*pcxHeader.bytesPerLine,
                        image[2], y*xSize, xSize);
            }
            DataBufferByte dataBuffer = new DataBufferByte(image, image[0].length);
            WritableRaster raster = WritableRaster.createBandedRaster(dataBuffer,
                    xSize, ySize, xSize, new int[]{0,1,2},
                    new int[]{0,0,0}, null);
            ColorModel colorModel = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            return new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
        }
        else if ((pcxHeader.bitsPerPixel == 24 && pcxHeader.nPlanes == 1) ||
                (pcxHeader.bitsPerPixel == 32 && pcxHeader.nPlanes == 1))
        {
            int rowLength = 3 * xSize;
            byte[] image = new byte[rowLength * ySize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                if (pcxHeader.bitsPerPixel == 24)
                    System.arraycopy(scanline, 0, image, y*rowLength, rowLength);
                else
                {
                    for (int x = 0; x < xSize; x++)
                    {
                        image[y*rowLength + 3*x] = scanline[4*x];
                        image[y*rowLength + 3*x + 1] = scanline[4*x + 1];
                        image[y*rowLength + 3*x + 2] = scanline[4*x + 2];
                    }
                }
            }
            DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
            WritableRaster raster = WritableRaster.createInterleavedRaster(
                    dataBuffer, xSize, ySize, rowLength, 3,
                    new int[]{2,1,0}, null);
            ColorModel colorModel = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            return new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
        }
        else
        {
            throw new ImageReadException("Invalid/unsupported image with bitsPerPixel "
                    + pcxHeader.bitsPerPixel + " and planes " + pcxHeader.nPlanes);
View Full Code Here

            {
                Map.Entry entry = (Map.Entry)it.next();
                PaletteEntry paletteEntry = (PaletteEntry)entry.getValue();
                palette[paletteEntry.index] = paletteEntry.getBestARGB();
            }
            colorModel = new IndexColorModel(8, xpmHeader.palette.size(),
                    palette, 0, true, -1, DataBuffer.TYPE_BYTE);
            raster = WritableRaster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                    xpmHeader.width, xpmHeader.height, 1, null);
            bpp = 8;
        }
        else if (xpmHeader.palette.size() <= (1 << 16))
        {
            int[] palette = new int[xpmHeader.palette.size()];
            for (Iterator it = xpmHeader.palette.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry = (Map.Entry)it.next();
                PaletteEntry paletteEntry = (PaletteEntry)entry.getValue();
                palette[paletteEntry.index] = paletteEntry.getBestARGB();
            }
            colorModel = new IndexColorModel(16, xpmHeader.palette.size(),
                    palette, 0, true, -1, DataBuffer.TYPE_USHORT);
            raster = WritableRaster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
                    xpmHeader.width, xpmHeader.height, 1, null);
            bpp = 16;
        }
View Full Code Here

TOP

Related Classes of java.awt.image.IndexColorModel

Copyright © 2018 www.massapicom. 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.