Search in sources :

Example 1 with SurfaceType

use of sun.java2d.loops.SurfaceType in project jdk8u_jdk by JetBrains.

the class SurfaceDataProxy method updateSurfaceDataBg.

/**
     * This is an alternate implementation for updating the cached
     * SurfaceData from the source (primary) SurfaceData using a
     * background color for transparent pixels.
     * A simple BlitBg is used to copy the pixels from the source to
     * the destination SurfaceData with the specified bgColor.
     * A subclass can override the normal updateSurfaceData method
     * and call this implementation instead if it wants to use color
     * keying for bitmask images.
     */
public void updateSurfaceDataBg(SurfaceData srcData, SurfaceData dstData, int w, int h, Color bgColor) {
    SurfaceType srcType = srcData.getSurfaceType();
    SurfaceType dstType = dstData.getSurfaceType();
    BlitBg blitbg = BlitBg.getFromCache(srcType, CompositeType.SrcNoEa, dstType);
    blitbg.BlitBg(srcData, dstData, AlphaComposite.Src, null, bgColor.getRGB(), 0, 0, 0, 0, w, h);
    dstData.markDirty();
}
Also used : BlitBg(sun.java2d.loops.BlitBg) SurfaceType(sun.java2d.loops.SurfaceType)

Example 2 with SurfaceType

use of sun.java2d.loops.SurfaceType 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 3 with SurfaceType

use of sun.java2d.loops.SurfaceType in project jdk8u_jdk by JetBrains.

the class BufImgSurfaceData method getSolidLoops.

public static synchronized RenderLoops getSolidLoops(SurfaceType type) {
    for (int i = CACHE_SIZE - 1; i >= 0; i--) {
        SurfaceType t = typecache[i];
        if (t == type) {
            return loopcache[i];
        } else if (t == null) {
            break;
        }
    }
    RenderLoops l = makeRenderLoops(SurfaceType.OpaqueColor, CompositeType.SrcNoEa, type);
    System.arraycopy(loopcache, 1, loopcache, 0, CACHE_SIZE - 1);
    System.arraycopy(typecache, 1, typecache, 0, CACHE_SIZE - 1);
    loopcache[CACHE_SIZE - 1] = l;
    typecache[CACHE_SIZE - 1] = type;
    return l;
}
Also used : RenderLoops(sun.java2d.loops.RenderLoops) SurfaceType(sun.java2d.loops.SurfaceType)

Example 4 with SurfaceType

use of sun.java2d.loops.SurfaceType in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method doCopyArea.

private void doCopyArea(int x, int y, int w, int h, int dx, int dy) {
    if (w <= 0 || h <= 0) {
        return;
    }
    SurfaceData theData = surfaceData;
    if (theData.copyArea(this, x, y, w, h, dx, dy)) {
        return;
    }
    if (transformState > TRANSFORM_TRANSLATESCALE) {
        throw new InternalError("transformed copyArea not implemented yet");
    }
    // REMIND: This method does not deal with missing data from the
    // source object (i.e. it does not send exposure events...)
    Region clip = getCompClip();
    Composite comp = composite;
    if (lastCAcomp != comp) {
        SurfaceType dsttype = theData.getSurfaceType();
        CompositeType comptype = imageComp;
        if (CompositeType.SrcOverNoEa.equals(comptype) && theData.getTransparency() == Transparency.OPAQUE) {
            comptype = CompositeType.SrcNoEa;
        }
        lastCAblit = Blit.locate(dsttype, comptype, dsttype);
        lastCAcomp = comp;
    }
    double[] coords = { x, y, x + w, y + h, x + dx, y + dy };
    transform.transform(coords, 0, coords, 0, 3);
    x = (int) Math.ceil(coords[0] - 0.5);
    y = (int) Math.ceil(coords[1] - 0.5);
    w = ((int) Math.ceil(coords[2] - 0.5)) - x;
    h = ((int) Math.ceil(coords[3] - 0.5)) - y;
    dx = ((int) Math.ceil(coords[4] - 0.5)) - x;
    dy = ((int) Math.ceil(coords[5] - 0.5)) - y;
    // In case of negative scale transform, reflect the rect coords.
    if (w < 0) {
        w *= -1;
        x -= w;
    }
    if (h < 0) {
        h *= -1;
        y -= h;
    }
    Blit ob = lastCAblit;
    if (dy == 0 && dx > 0 && dx < w) {
        while (w > 0) {
            int partW = Math.min(w, dx);
            w -= partW;
            int sx = x + w;
            ob.Blit(theData, theData, comp, clip, sx, y, sx + dx, y + dy, partW, h);
        }
        return;
    }
    if (dy > 0 && dy < h && dx > -w && dx < w) {
        while (h > 0) {
            int partH = Math.min(h, dy);
            h -= partH;
            int sy = y + h;
            ob.Blit(theData, theData, comp, clip, x, sy, x + dx, sy + dy, w, partH);
        }
        return;
    }
    ob.Blit(theData, theData, comp, clip, x, y, x + dx, y + dy, w, h);
}
Also used : Composite(java.awt.Composite) XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite) Region(sun.java2d.pipe.Region) Blit(sun.java2d.loops.Blit) SurfaceType(sun.java2d.loops.SurfaceType) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) CompositeType(sun.java2d.loops.CompositeType)

Example 5 with SurfaceType

use of sun.java2d.loops.SurfaceType in project jdk8u_jdk by JetBrains.

the class OGLDrawImage method renderImageXform.

@Override
protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
    //     - an appropriate TransformBlit primitive could not be found
    if (interpType != AffineTransformOp.TYPE_BICUBIC) {
        SurfaceData dstData = sg.surfaceData;
        SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_GENERIC, sg.imageComp, bgColor);
        if (srcData != null && !isBgOperation(srcData, bgColor) && (srcData.getSurfaceType() == OGLSurfaceData.OpenGLTexture || srcData.getSurfaceType() == OGLSurfaceData.OpenGLSurfaceRTT || interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR)) {
            SurfaceType srcType = srcData.getSurfaceType();
            SurfaceType dstType = dstData.getSurfaceType();
            TransformBlit blit = TransformBlit.getFromCache(srcType, sg.imageComp, dstType);
            if (blit != null) {
                blit.Transform(srcData, dstData, sg.composite, sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2 - sx1, sy2 - sy1);
                return;
            }
        }
    }
    super.renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor);
}
Also used : TransformBlit(sun.java2d.loops.TransformBlit) SurfaceData(sun.java2d.SurfaceData) SurfaceType(sun.java2d.loops.SurfaceType)

Aggregations

SurfaceType (sun.java2d.loops.SurfaceType)13 SurfaceData (sun.java2d.SurfaceData)6 InvalidPipeException (sun.java2d.InvalidPipeException)3 Blit (sun.java2d.loops.Blit)3 CompositeType (sun.java2d.loops.CompositeType)3 ColorModel (java.awt.image.ColorModel)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 RenderLoops (sun.java2d.loops.RenderLoops)2 TransformBlit (sun.java2d.loops.TransformBlit)2 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 GradientPaint (java.awt.GradientPaint)1 LinearGradientPaint (java.awt.LinearGradientPaint)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 TexturePaint (java.awt.TexturePaint)1 AffineTransform (java.awt.geom.AffineTransform)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 BufferedImage (java.awt.image.BufferedImage)1