Search in sources :

Example 11 with IndexColorModel

use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.

the class BufImgSurfaceData method createData.

public static SurfaceData createData(BufferedImage bufImg, double scaleX, double scaleY) {
    if (bufImg == null) {
        throw new NullPointerException("BufferedImage cannot be null");
    }
    SurfaceData sData;
    ColorModel cm = bufImg.getColorModel();
    int type = bufImg.getType();
    // REMIND: Check the image type and pick an appropriate subclass
    switch(type) {
        case BufferedImage.TYPE_INT_BGR:
            sData = createDataIC(bufImg, SurfaceType.IntBgr, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_RGB:
            sData = createDataIC(bufImg, SurfaceType.IntRgb, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_ARGB:
            sData = createDataIC(bufImg, SurfaceType.IntArgb, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_INT_ARGB_PRE:
            sData = createDataIC(bufImg, SurfaceType.IntArgbPre, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
            sData = createDataBC(bufImg, SurfaceType.ThreeByteBgr, 2, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_4BYTE_ABGR:
            sData = createDataBC(bufImg, SurfaceType.FourByteAbgr, 3, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            sData = createDataBC(bufImg, SurfaceType.FourByteAbgrPre, 3, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_565_RGB:
            sData = createDataSC(bufImg, SurfaceType.Ushort565Rgb, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_555_RGB:
            sData = createDataSC(bufImg, SurfaceType.Ushort555Rgb, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_BYTE_INDEXED:
            {
                SurfaceType sType;
                switch(cm.getTransparency()) {
                    case OPAQUE:
                        if (isOpaqueGray((IndexColorModel) cm)) {
                            sType = SurfaceType.Index8Gray;
                        } else {
                            sType = SurfaceType.ByteIndexedOpaque;
                        }
                        break;
                    case BITMASK:
                        sType = SurfaceType.ByteIndexedBm;
                        break;
                    case TRANSLUCENT:
                        sType = SurfaceType.ByteIndexed;
                        break;
                    default:
                        throw new InternalError("Unrecognized transparency");
                }
                sData = createDataBC(bufImg, sType, 0, scaleX, scaleY);
            }
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            sData = createDataBC(bufImg, SurfaceType.ByteGray, 0, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            sData = createDataSC(bufImg, SurfaceType.UshortGray, null, scaleX, scaleY);
            break;
        case BufferedImage.TYPE_BYTE_BINARY:
            {
                SurfaceType sType;
                SampleModel sm = bufImg.getRaster().getSampleModel();
                switch(sm.getSampleSize(0)) {
                    case 1:
                        sType = SurfaceType.ByteBinary1Bit;
                        break;
                    case 2:
                        sType = SurfaceType.ByteBinary2Bit;
                        break;
                    case 4:
                        sType = SurfaceType.ByteBinary4Bit;
                        break;
                    default:
                        throw new InternalError("Unrecognized pixel size");
                }
                sData = createDataBP(bufImg, sType, scaleX, scaleY);
            }
            break;
        case BufferedImage.TYPE_CUSTOM:
        default:
            {
                Raster raster = bufImg.getRaster();
                int numBands = raster.getNumBands();
                if (raster instanceof IntegerComponentRaster && raster.getNumDataElements() == 1 && ((IntegerComponentRaster) raster).getPixelStride() == 1) {
                    SurfaceType sType = SurfaceType.AnyInt;
                    if (cm instanceof DirectColorModel) {
                        DirectColorModel dcm = (DirectColorModel) cm;
                        int aMask = dcm.getAlphaMask();
                        int rMask = dcm.getRedMask();
                        int gMask = dcm.getGreenMask();
                        int bMask = dcm.getBlueMask();
                        if (numBands == 3 && aMask == 0 && rMask == DCM_RGBX_RED_MASK && gMask == DCM_RGBX_GREEN_MASK && bMask == DCM_RGBX_BLUE_MASK) {
                            sType = SurfaceType.IntRgbx;
                        } else if (numBands == 4 && aMask == DCM_ARGBBM_ALPHA_MASK && rMask == DCM_ARGBBM_RED_MASK && gMask == DCM_ARGBBM_GREEN_MASK && bMask == DCM_ARGBBM_BLUE_MASK) {
                            sType = SurfaceType.IntArgbBm;
                        } else {
                            sType = SurfaceType.AnyDcm;
                        }
                    }
                    sData = createDataIC(bufImg, sType, scaleX, scaleY);
                    break;
                } else if (raster instanceof ShortComponentRaster && raster.getNumDataElements() == 1 && ((ShortComponentRaster) raster).getPixelStride() == 1) {
                    SurfaceType sType = SurfaceType.AnyShort;
                    IndexColorModel icm = null;
                    if (cm instanceof DirectColorModel) {
                        DirectColorModel dcm = (DirectColorModel) cm;
                        int aMask = dcm.getAlphaMask();
                        int rMask = dcm.getRedMask();
                        int gMask = dcm.getGreenMask();
                        int bMask = dcm.getBlueMask();
                        if (numBands == 3 && aMask == 0 && rMask == DCM_555X_RED_MASK && gMask == DCM_555X_GREEN_MASK && bMask == DCM_555X_BLUE_MASK) {
                            sType = SurfaceType.Ushort555Rgbx;
                        } else if (numBands == 4 && aMask == DCM_4444_ALPHA_MASK && rMask == DCM_4444_RED_MASK && gMask == DCM_4444_GREEN_MASK && bMask == DCM_4444_BLUE_MASK) {
                            sType = SurfaceType.Ushort4444Argb;
                        }
                    } else if (cm instanceof IndexColorModel) {
                        icm = (IndexColorModel) cm;
                        if (icm.getPixelSize() == 12) {
                            if (isOpaqueGray(icm)) {
                                sType = SurfaceType.Index12Gray;
                            } else {
                                sType = SurfaceType.UshortIndexed;
                            }
                        } else {
                            icm = null;
                        }
                    }
                    sData = createDataSC(bufImg, sType, icm, scaleX, scaleY);
                    break;
                }
                sData = new BufImgSurfaceData(raster.getDataBuffer(), bufImg, SurfaceType.Custom, scaleX, scaleY);
            }
            break;
    }
    ((BufImgSurfaceData) sData).initSolidLoops();
    return sData;
}
Also used : Raster(java.awt.image.Raster) SurfaceType(sun.java2d.loops.SurfaceType) SampleModel(java.awt.image.SampleModel) SurfaceData(sun.java2d.SurfaceData) DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) IndexColorModel(java.awt.image.IndexColorModel)

Example 12 with IndexColorModel

use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.

the class BufImgSurfaceData method createDataBC.

public static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank, double scaleX, double scaleY) {
    ByteComponentRaster bcRaster = (ByteComponentRaster) bImg.getRaster();
    BufImgSurfaceData bisd = new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType, scaleX, scaleY);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);
    bisd.initRaster(bcRaster.getDataStorage(), bcRaster.getDataOffset(primaryBank), 0, bcRaster.getWidth(), bcRaster.getHeight(), bcRaster.getPixelStride(), bcRaster.getScanlineStride(), icm);
    return bisd;
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) IndexColorModel(java.awt.image.IndexColorModel)

Example 13 with IndexColorModel

use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.

the class ImageRepresentation method setColorModel.

public void setColorModel(ColorModel model) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    srcModel = model;
    // Check to see if model is INT_RGB
    if (model instanceof IndexColorModel) {
        if (model.getTransparency() == model.TRANSLUCENT) {
            // REMIND:
            // Probably need to composite anyway so force ARGB
            cmodel = ColorModel.getRGBdefault();
            srcLUT = null;
        } else {
            IndexColorModel icm = (IndexColorModel) model;
            numSrcLUT = icm.getMapSize();
            srcLUT = new int[Math.max(numSrcLUT, 256)];
            icm.getRGBs(srcLUT);
            srcLUTtransIndex = icm.getTransparentPixel();
            cmodel = model;
        }
    } else {
        if (cmodel == null) {
            cmodel = model;
            srcLUT = null;
        } else if (model instanceof DirectColorModel) {
            // If it is INT_RGB or INT_ARGB, use the model
            DirectColorModel dcm = (DirectColorModel) model;
            if ((dcm.getRedMask() == 0xff0000) && (dcm.getGreenMask() == 0xff00) && (dcm.getBlueMask() == 0x00ff)) {
                cmodel = model;
                srcLUT = null;
            }
        }
    }
    isSameCM = (cmodel == model);
}
Also used : DirectColorModel(java.awt.image.DirectColorModel) IndexColorModel(java.awt.image.IndexColorModel)

Example 14 with IndexColorModel

use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.

the class GIFImageReader method createIndexed.

// We don't check all parameters as ImageTypeSpecifier.createIndexed do
// since this method is private and we pass consistent data here
private ImageTypeSpecifier createIndexed(byte[] r, byte[] g, byte[] b, int bits) {
    ColorModel colorModel;
    if (imageMetadata.transparentColorFlag) {
        // Some files erroneously have a transparent color index
        // of 255 even though there are fewer than 256 colors.
        int idx = Math.min(imageMetadata.transparentColorIndex, r.length - 1);
        colorModel = new IndexColorModel(bits, r.length, r, g, b, idx);
    } else {
        colorModel = new IndexColorModel(bits, r.length, r, g, b);
    }
    SampleModel sampleModel;
    if (bits == 8) {
        int[] bandOffsets = { 0 };
        sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 1, 1, 1, 1, bandOffsets);
    } else {
        sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 1, 1, bits);
    }
    return new ImageTypeSpecifier(colorModel, sampleModel);
}
Also used : PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) PixelInterleavedSampleModel(java.awt.image.PixelInterleavedSampleModel) SampleModel(java.awt.image.SampleModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) Point(java.awt.Point) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IndexColorModel(java.awt.image.IndexColorModel)

Example 15 with IndexColorModel

use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.

the class PaletteBuilder method getIndexColorModel.

protected IndexColorModel getIndexColorModel() {
    int size = currSize;
    if (transColor != null) {
        // we need place for transparent color;
        size++;
    }
    byte[] red = new byte[size];
    byte[] green = new byte[size];
    byte[] blue = new byte[size];
    int index = 0;
    palette = new ColorNode[size];
    if (transColor != null) {
        index++;
    }
    if (root != null) {
        findPaletteEntry(root, index, red, green, blue);
    }
    IndexColorModel icm = null;
    if (transColor != null) {
        icm = new IndexColorModel(8, size, red, green, blue, 0);
    } else {
        icm = new IndexColorModel(8, currSize, red, green, blue);
    }
    return icm;
}
Also used : IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

IndexColorModel (java.awt.image.IndexColorModel)57 ColorModel (java.awt.image.ColorModel)24 BufferedImage (java.awt.image.BufferedImage)19 DirectColorModel (java.awt.image.DirectColorModel)11 SampleModel (java.awt.image.SampleModel)10 Point (java.awt.Point)8 WritableRaster (java.awt.image.WritableRaster)8 Rectangle (java.awt.Rectangle)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Raster (java.awt.image.Raster)7 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 ColorSpace (java.awt.color.ColorSpace)5 ComponentColorModel (java.awt.image.ComponentColorModel)5 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 Graphics (java.awt.Graphics)4 Graphics2D (java.awt.Graphics2D)4 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)4 RenderedImage (java.awt.image.RenderedImage)4 ByteComponentRaster (sun.awt.image.ByteComponentRaster)4 DataBufferByte (java.awt.image.DataBufferByte)3