Search in sources :

Example 16 with ColorModel

use of java.awt.image.ColorModel in project intellij-community by JetBrains.

the class ImagePreviewComponent method createLabel.

@NotNull
private static JLabel createLabel(@NotNull final BufferedImage image, long imageFileSize) {
    final int width = image.getWidth();
    final int height = image.getHeight();
    final ColorModel colorModel = image.getColorModel();
    final int i = colorModel.getPixelSize();
    return new JLabel(String.format("%dx%d, %dbpp, %s", width, height, i, StringUtil.formatFileSize(imageFileSize)));
}
Also used : ColorModel(java.awt.image.ColorModel) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ColorModel

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

the class XorPixelWriter method createXorPixelWriter.

static PixelWriter createXorPixelWriter(SunGraphics2D sg2d, SurfaceData sData) {
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);
    XORComposite comp = (XORComposite) sg2d.getComposite();
    int xorrgb = comp.getXorColor().getRGB();
    Object xorPixel = dstCM.getDataElements(xorrgb, null);
    switch(dstCM.getTransferType()) {
        case DataBuffer.TYPE_BYTE:
            return new XorPixelWriter.ByteData(srcPixel, xorPixel);
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_USHORT:
            return new XorPixelWriter.ShortData(srcPixel, xorPixel);
        case DataBuffer.TYPE_INT:
            return new XorPixelWriter.IntData(srcPixel, xorPixel);
        case DataBuffer.TYPE_FLOAT:
            return new XorPixelWriter.FloatData(srcPixel, xorPixel);
        case DataBuffer.TYPE_DOUBLE:
            return new XorPixelWriter.DoubleData(srcPixel, xorPixel);
        default:
            throw new InternalError("Unsupported XOR pixel type");
    }
}
Also used : ColorModel(java.awt.image.ColorModel)

Example 18 with ColorModel

use of java.awt.image.ColorModel 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 19 with ColorModel

use of java.awt.image.ColorModel 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 20 with ColorModel

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

the class SunGraphics2D method drawRenderedImage.

/**
     * Draws an image, applying a transform from image space into user space
     * before drawing.
     * The transformation from user space into device space is done with
     * the current transform in the Graphics2D.
     * The given transformation is applied to the image before the
     * transform attribute in the Graphics2D state is applied.
     * The rendering attributes applied include the clip, transform,
     * and composite attributes. Note that the result is
     * undefined, if the given transform is noninvertible.
     * @param img The image to be drawn. Does nothing if img is null.
     * @param xform The transformation from image space into user space.
     * @see #transform
     * @see #setTransform
     * @see #setComposite
     * @see #clip
     * @see #setClip
     */
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
    if (img == null) {
        return;
    }
    // BufferedImage case: use a simple drawImage call
    if (img instanceof BufferedImage) {
        BufferedImage bufImg = (BufferedImage) img;
        drawImage(bufImg, xform, null);
        return;
    }
    // transformState tracks the state of transform and
    // transX, transY contain the integer casts of the
    // translation factors
    boolean isIntegerTranslate = (transformState <= TRANSFORM_INT_TRANSLATE) && isIntegerTranslation(xform);
    // Include padding for interpolation/antialiasing if necessary
    int pad = isIntegerTranslate ? 0 : 3;
    Region clip;
    try {
        clip = getCompClip();
    } catch (InvalidPipeException e) {
        return;
    }
    // Determine the region of the image that may contribute to
    // the clipped drawing area
    Rectangle region = getImageRegion(img, clip, transform, xform, pad, pad);
    if (region.width <= 0 || region.height <= 0) {
        return;
    }
    // where both are integer translations.
    if (isIntegerTranslate) {
        // Use optimized code
        // Note that drawTranslatedRenderedImage calls copyImage
        // which takes the user space to device space transform into
        // account, but we need to provide the image space to user space
        // translations.
        drawTranslatedRenderedImage(img, region, (int) xform.getTranslateX(), (int) xform.getTranslateY());
        return;
    }
    // General case: cobble the necessary region into a single Raster
    Raster raster = img.getData(region);
    // Make a new Raster with the same contents as raster
    // but starting at (0, 0).  This raster is thus in the same
    // coordinate system as the SampleModel of the original raster.
    WritableRaster wRaster = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null);
    // If the original raster was in a different coordinate
    // system than its SampleModel, we need to perform an
    // additional translation in order to get the (minX, minY)
    // pixel of raster to be pixel (0, 0) of wRaster.  We also
    // have to have the correct width and height.
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();
    int px = minX - raster.getSampleModelTranslateX();
    int py = minY - raster.getSampleModelTranslateY();
    if (px != 0 || py != 0 || width != wRaster.getWidth() || height != wRaster.getHeight()) {
        wRaster = wRaster.createWritableChild(px, py, width, height, 0, 0, null);
    }
    // Now we have a BufferedImage starting at (0, 0)
    // with the same contents that started at (minX, minY)
    // in raster.  So we must draw the BufferedImage with a
    // translation of (minX, minY).
    AffineTransform transXform = (AffineTransform) xform.clone();
    transXform.translate(minX, minY);
    ColorModel cm = img.getColorModel();
    BufferedImage bufImg = new BufferedImage(cm, wRaster, cm.isAlphaPremultiplied(), null);
    drawImage(bufImg, transXform, null);
}
Also used : WritableRaster(java.awt.image.WritableRaster) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Rectangle(java.awt.Rectangle) Region(sun.java2d.pipe.Region) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Aggregations

ColorModel (java.awt.image.ColorModel)85 IndexColorModel (java.awt.image.IndexColorModel)35 WritableRaster (java.awt.image.WritableRaster)32 BufferedImage (java.awt.image.BufferedImage)30 DirectColorModel (java.awt.image.DirectColorModel)23 ComponentColorModel (java.awt.image.ComponentColorModel)18 Raster (java.awt.image.Raster)16 SampleModel (java.awt.image.SampleModel)16 ColorSpace (java.awt.color.ColorSpace)12 SurfaceData (sun.java2d.SurfaceData)9 ComponentSampleModel (java.awt.image.ComponentSampleModel)8 Graphics2D (java.awt.Graphics2D)7 Rectangle (java.awt.Rectangle)7 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)7 Point (java.awt.Point)5 Component (java.awt.Component)4 Paint (java.awt.Paint)4 AffineTransform (java.awt.geom.AffineTransform)4 DataBufferByte (java.awt.image.DataBufferByte)4 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)4