Search in sources :

Example 1 with IntegerComponentRaster

use of sun.awt.image.IntegerComponentRaster in project jdk8u_jdk by JetBrains.

the class GradientPaintContext method getRaster.

/**
     * Return a Raster containing the colors generated for the graphics
     * operation.
     * @param x,y,w,h The area in device space for which colors are
     * generated.
     */
public Raster getRaster(int x, int y, int w, int h) {
    double rowrel = (x - x1) * dx + (y - y1) * dy;
    Raster rast = saved;
    if (rast == null || rast.getWidth() < w || rast.getHeight() < h) {
        rast = getCachedRaster(model, w, h);
        saved = rast;
    }
    IntegerComponentRaster irast = (IntegerComponentRaster) rast;
    int off = irast.getDataOffset(0);
    int adjust = irast.getScanlineStride() - w;
    int[] pixels = irast.getDataStorage();
    if (cyclic) {
        cycleFillRaster(pixels, off, adjust, w, h, rowrel, dx, dy);
    } else {
        clipFillRaster(pixels, off, adjust, w, h, rowrel, dx, dy);
    }
    irast.markDirty();
    return rast;
}
Also used : Raster(java.awt.image.Raster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster)

Example 2 with IntegerComponentRaster

use of sun.awt.image.IntegerComponentRaster in project jdk8u_jdk by JetBrains.

the class ColorPaintContext method getRaster.

public synchronized Raster getRaster(int x, int y, int w, int h) {
    WritableRaster t = savedTile;
    if (t == null || w > t.getWidth() || h > t.getHeight()) {
        t = getColorModel().createCompatibleWritableRaster(w, h);
        IntegerComponentRaster icr = (IntegerComponentRaster) t;
        Arrays.fill(icr.getDataStorage(), color);
        // Note - markDirty is probably unnecessary since icr is brand new
        icr.markDirty();
        if (w <= 64 && h <= 64) {
            savedTile = t;
        }
    }
    return t;
}
Also used : WritableRaster(java.awt.image.WritableRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster)

Example 3 with IntegerComponentRaster

use of sun.awt.image.IntegerComponentRaster in project jdk8u_jdk by JetBrains.

the class XorCopyArgbToAny method Blit.

public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int srcx, int srcy, int dstx, int dsty, int w, int h) {
    Raster srcRast = src.getRaster(srcx, srcy, w, h);
    ColorModel srcCM = src.getColorModel();
    Raster dstRast = dst.getRaster(dstx, dsty, w, h);
    IntegerComponentRaster icr = (IntegerComponentRaster) dstRast;
    int[] dstPix = icr.getDataStorage();
    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip, srcx, srcy, dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();
    Object srcPix = null;
    int dstScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int[] span = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = icr.getDataOffset(0) + span[1] * dstScan + span[0];
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                srcPix = srcRast.getDataElements(x + srcx, y + srcy, srcPix);
                dstPix[off++] = srcCM.getRGB(srcPix);
            }
            rowoff += dstScan;
        }
    }
    // Pixels in the dest were modified directly, we must
    // manually notify the raster that it was modified
    icr.markDirty();
// REMIND: We need to do something to make sure that dstRast
// is put back to the destination (as in the native Release
// function)
// src.releaseRaster(srcRast);  // NOP?
// dst.releaseRaster(dstRast);
}
Also used : SpanIterator(sun.java2d.pipe.SpanIterator) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) WritableRaster(java.awt.image.WritableRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) Region(sun.java2d.pipe.Region)

Example 4 with IntegerComponentRaster

use of sun.awt.image.IntegerComponentRaster in project jdk8u_jdk by JetBrains.

the class LCMSImageLayout method createImageLayout.

/* This method creates a layout object for given image.
     * Returns null if the image is not supported by current implementation.
     */
public static LCMSImageLayout createImageLayout(BufferedImage image) throws ImageLayoutException {
    LCMSImageLayout l = new LCMSImageLayout();
    switch(image.getType()) {
        case BufferedImage.TYPE_INT_RGB:
            l.pixelType = PT_ARGB_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_INT_ARGB:
            l.pixelType = PT_ARGB_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_INT_BGR:
            l.pixelType = PT_ABGR_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
            l.pixelType = PT_BGR_8;
            break;
        case BufferedImage.TYPE_4BYTE_ABGR:
            l.pixelType = PT_ABGR_8;
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            l.pixelType = PT_GRAY_8;
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            l.pixelType = PT_GRAY_16;
            break;
        default:
            /* ColorConvertOp creates component images as
                 * default destination, so this kind of images
                 * has to be supported.
                 */
            ColorModel cm = image.getColorModel();
            if (cm instanceof ComponentColorModel) {
                ComponentColorModel ccm = (ComponentColorModel) cm;
                // verify whether the component size is fine
                int[] cs = ccm.getComponentSize();
                for (int s : cs) {
                    if (s != 8) {
                        return null;
                    }
                }
                return createImageLayout(image.getRaster());
            }
            return null;
    }
    l.width = image.getWidth();
    l.height = image.getHeight();
    switch(image.getType()) {
        case BufferedImage.TYPE_INT_RGB:
        case BufferedImage.TYPE_INT_ARGB:
        case BufferedImage.TYPE_INT_BGR:
            do {
                IntegerComponentRaster intRaster = (IntegerComponentRaster) image.getRaster();
                l.nextRowOffset = safeMult(4, intRaster.getScanlineStride());
                l.nextPixelOffset = safeMult(4, intRaster.getPixelStride());
                l.offset = safeMult(4, intRaster.getDataOffset(0));
                l.dataArray = intRaster.getDataStorage();
                l.dataArrayLength = 4 * intRaster.getDataStorage().length;
                l.dataType = DT_INT;
                if (l.nextRowOffset == l.width * 4 * intRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
        case BufferedImage.TYPE_4BYTE_ABGR:
            do {
                ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
                l.nextRowOffset = byteRaster.getScanlineStride();
                l.nextPixelOffset = byteRaster.getPixelStride();
                int firstBand = image.getSampleModel().getNumBands() - 1;
                l.offset = byteRaster.getDataOffset(firstBand);
                l.dataArray = byteRaster.getDataStorage();
                l.dataArrayLength = byteRaster.getDataStorage().length;
                l.dataType = DT_BYTE;
                if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            do {
                ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
                l.nextRowOffset = byteRaster.getScanlineStride();
                l.nextPixelOffset = byteRaster.getPixelStride();
                l.dataArrayLength = byteRaster.getDataStorage().length;
                l.offset = byteRaster.getDataOffset(0);
                l.dataArray = byteRaster.getDataStorage();
                l.dataType = DT_BYTE;
                if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            do {
                ShortComponentRaster shortRaster = (ShortComponentRaster) image.getRaster();
                l.nextRowOffset = safeMult(2, shortRaster.getScanlineStride());
                l.nextPixelOffset = safeMult(2, shortRaster.getPixelStride());
                l.offset = safeMult(2, shortRaster.getDataOffset(0));
                l.dataArray = shortRaster.getDataStorage();
                l.dataArrayLength = 2 * shortRaster.getDataStorage().length;
                l.dataType = DT_SHORT;
                if (l.nextRowOffset == l.width * 2 * shortRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        default:
            return null;
    }
    l.verify();
    return l;
}
Also used : ShortComponentRaster(sun.awt.image.ShortComponentRaster) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ByteComponentRaster(sun.awt.image.ByteComponentRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster)

Example 5 with IntegerComponentRaster

use of sun.awt.image.IntegerComponentRaster in project jdk8u_jdk by JetBrains.

the class ImageRepresentation method setPixels.

public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pix, int off, int scansize) {
    int lineOff = off;
    int poff;
    int[] newLUT = null;
    if (src != null) {
        src.checkSecurity(null, false);
    }
    // REMIND: What if the model doesn't fit in default color model?
    synchronized (this) {
        if (bimage == null) {
            if (cmodel == null) {
                cmodel = model;
            }
            createBufferedImage();
        }
        if (w <= 0 || h <= 0) {
            return;
        }
        int biWidth = biRaster.getWidth();
        int biHeight = biRaster.getHeight();
        // Overflow protection below
        int x1 = x + w;
        // Overflow protection below
        int y1 = y + h;
        if (x < 0) {
            off -= x;
            x = 0;
        } else if (x1 < 0) {
            // Must be overflow
            x1 = biWidth;
        }
        if (y < 0) {
            off -= y * scansize;
            y = 0;
        } else if (y1 < 0) {
            // Must be overflow
            y1 = biHeight;
        }
        if (x1 > biWidth) {
            x1 = biWidth;
        }
        if (y1 > biHeight) {
            y1 = biHeight;
        }
        if (x >= x1 || y >= y1) {
            return;
        }
        // x,y,x1,y1 are all >= 0, so w,h must be >= 0
        w = x1 - x;
        h = y1 - y;
        // off is first pixel read so it must be in bounds
        if (off < 0 || off >= pix.length) {
            // They overflowed their own array
            throw new ArrayIndexOutOfBoundsException("Data offset out of bounds.");
        }
        // pix.length and off are >= 0 so remainder >= 0
        int remainder = pix.length - off;
        if (remainder < w) {
            // They overflowed their own array
            throw new ArrayIndexOutOfBoundsException("Data array is too short.");
        }
        int num;
        if (scansize < 0) {
            num = (off / -scansize) + 1;
        } else if (scansize > 0) {
            num = ((remainder - w) / scansize) + 1;
        } else {
            num = h;
        }
        if (h > num) {
            // They overflowed their own array.
            throw new ArrayIndexOutOfBoundsException("Data array is too short.");
        }
        if (isSameCM && (cmodel != model) && (srcLUT != null) && (model instanceof IndexColorModel) && (biRaster instanceof ByteComponentRaster)) {
            IndexColorModel icm = (IndexColorModel) model;
            ByteComponentRaster bct = (ByteComponentRaster) biRaster;
            int numlut = numSrcLUT;
            if (!setDiffICM(x, y, w, h, srcLUT, srcLUTtransIndex, numSrcLUT, icm, pix, off, scansize, bct, bct.getDataOffset(0))) {
                convertToRGB();
            } else {
                // Note that setDiffICM modified the raster directly
                // so we must mark it as changed
                bct.markDirty();
                if (numlut != numSrcLUT) {
                    boolean hasAlpha = icm.hasAlpha();
                    if (srcLUTtransIndex != -1) {
                        hasAlpha = true;
                    }
                    int nbits = icm.getPixelSize();
                    icm = new IndexColorModel(nbits, numSrcLUT, srcLUT, 0, hasAlpha, srcLUTtransIndex, (nbits > 8 ? DataBuffer.TYPE_USHORT : DataBuffer.TYPE_BYTE));
                    cmodel = icm;
                    bimage = createImage(icm, bct, false, null);
                }
                return;
            }
        }
        if (isDefaultBI) {
            int pixel;
            IntegerComponentRaster iraster = (IntegerComponentRaster) biRaster;
            if (srcLUT != null && model instanceof IndexColorModel) {
                if (model != srcModel) {
                    // Fill in the new lut
                    ((IndexColorModel) model).getRGBs(srcLUT);
                    srcModel = model;
                }
                if (s_useNative) {
                    // so we must mark it as changed afterwards
                    if (setICMpixels(x, y, w, h, srcLUT, pix, off, scansize, iraster)) {
                        iraster.markDirty();
                    } else {
                        abort();
                        return;
                    }
                } else {
                    int[] storage = new int[w * h];
                    int soff = 0;
                    // It is an IndexColorModel
                    for (int yoff = 0; yoff < h; yoff++, lineOff += scansize) {
                        poff = lineOff;
                        for (int i = 0; i < w; i++) {
                            storage[soff++] = srcLUT[pix[poff++] & 0xff];
                        }
                    }
                    iraster.setDataElements(x, y, w, h, storage);
                }
            } else {
                int[] storage = new int[w];
                for (int yoff = y; yoff < y + h; yoff++, lineOff += scansize) {
                    poff = lineOff;
                    for (int i = 0; i < w; i++) {
                        storage[i] = model.getRGB(pix[poff++] & 0xff);
                    }
                    iraster.setDataElements(x, yoff, w, 1, storage);
                }
                availinfo |= ImageObserver.SOMEBITS;
            }
        } else if ((cmodel == model) && (biRaster instanceof ByteComponentRaster) && (biRaster.getNumDataElements() == 1)) {
            ByteComponentRaster bt = (ByteComponentRaster) biRaster;
            if (off == 0 && scansize == w) {
                bt.putByteData(x, y, w, h, pix);
            } else {
                byte[] bpix = new byte[w];
                poff = off;
                for (int yoff = y; yoff < y + h; yoff++) {
                    System.arraycopy(pix, poff, bpix, 0, w);
                    bt.putByteData(x, yoff, w, 1, bpix);
                    poff += scansize;
                }
            }
        } else {
            for (int yoff = y; yoff < y + h; yoff++, lineOff += scansize) {
                poff = lineOff;
                for (int xoff = x; xoff < x + w; xoff++) {
                    bimage.setRGB(xoff, yoff, model.getRGB(pix[poff++] & 0xff));
                }
            }
            availinfo |= ImageObserver.SOMEBITS;
        }
    }
    if ((availinfo & ImageObserver.FRAMEBITS) == 0) {
        newInfo(image, ImageObserver.SOMEBITS, x, y, w, h);
    }
}
Also used : ByteComponentRaster(sun.awt.image.ByteComponentRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

IntegerComponentRaster (sun.awt.image.IntegerComponentRaster)8 ColorModel (java.awt.image.ColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 ByteComponentRaster (sun.awt.image.ByteComponentRaster)2 Point (java.awt.Point)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 ImageRepresentation (sun.awt.image.ImageRepresentation)1 ShortComponentRaster (sun.awt.image.ShortComponentRaster)1 ToolkitImage (sun.awt.image.ToolkitImage)1 Region (sun.java2d.pipe.Region)1 SpanIterator (sun.java2d.pipe.SpanIterator)1