Java Code Examples for java.awt.image.ColorModel#getDataElements()

The following examples show how to use java.awt.image.ColorModel#getDataElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PixelConverter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
 
Example 2
Source File: PixelConverter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
 
Example 3
Source File: GeneralRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 4
Source File: GeneralRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
                                          SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    return new SolidPixelWriter(srcPixel);
}
 
Example 5
Source File: GeneralRenderer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
                                          SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    return new SolidPixelWriter(srcPixel);
}
 
Example 6
Source File: GeneralRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 7
Source File: GeneralRenderer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
                                          SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    return new SolidPixelWriter(srcPixel);
}
 
Example 8
Source File: GeneralRenderer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 9
Source File: GeneralRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 10
Source File: PixelConverter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
 
Example 11
Source File: GeneralRenderer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
                                          SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    return new SolidPixelWriter(srcPixel);
}
 
Example 12
Source File: PixelConverter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public int rgbToPixel(int rgb, ColorModel cm) {
    Object obj = cm.getDataElements(rgb, null);
    switch (cm.getTransferType()) {
    case DataBuffer.TYPE_BYTE:
        byte[] bytearr = (byte[]) obj;
        int pix = 0;

        switch(bytearr.length) {
        default: // bytearr.length >= 4
            pix = bytearr[3] << 24;
            // FALLSTHROUGH
        case 3:
            pix |= (bytearr[2] & 0xff) << 16;
            // FALLSTHROUGH
        case 2:
            pix |= (bytearr[1] & 0xff) << 8;
            // FALLSTHROUGH
        case 1:
            pix |= (bytearr[0] & 0xff);
        }

        return pix;
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT:
        short[] shortarr = (short[]) obj;

        return (((shortarr.length > 1) ? shortarr[1] << 16 : 0) |
                shortarr[0] & 0xffff);
    case DataBuffer.TYPE_INT:
        return ((int[]) obj)[0];
    default:
        return rgb;
    }
}
 
Example 13
Source File: GeneralRenderer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
                                          SurfaceData sData)
{
    ColorModel dstCM = sData.getColorModel();
    Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);

    return new SolidPixelWriter(srcPixel);
}
 
Example 14
Source File: GeneralRenderer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 15
Source File: CustomComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int span[] = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}
 
Example 16
Source File: CustomComponent.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int[] span = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}
 
Example 17
Source File: CustomComponent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int span[] = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}
 
Example 18
Source File: CustomComponent.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int span[] = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}
 
Example 19
Source File: CustomComponent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int span[] = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}
 
Example 20
Source File: CustomComponent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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);
    IntegerComponentRaster icr = (IntegerComponentRaster) srcRast;
    int[] srcPix = icr.getDataStorage();

    WritableRaster dstRast =
        (WritableRaster) dst.getRaster(dstx, dsty, w, h);
    ColorModel dstCM = dst.getColorModel();

    Region roi = CustomComponent.getRegionOfInterest(src, dst, clip,
                                                     srcx, srcy,
                                                     dstx, dsty, w, h);
    SpanIterator si = roi.getSpanIterator();

    Object dstPix = null;

    int srcScan = icr.getScanlineStride();
    // assert(icr.getPixelStride() == 1);
    srcx -= dstx;
    srcy -= dsty;
    int span[] = new int[4];
    while (si.nextSpan(span)) {
        int rowoff = (icr.getDataOffset(0) +
                      (srcy + span[1]) * srcScan +
                      (srcx + span[0]));
        for (int y = span[1]; y < span[3]; y++) {
            int off = rowoff;
            for (int x = span[0]; x < span[2]; x++) {
                dstPix = dstCM.getDataElements(srcPix[off++], dstPix);
                dstRast.setDataElements(x, y, dstPix);
            }
            rowoff += srcScan;
        }
    }
    // 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);
}