Example usage for java.awt.image WritableRaster getPixel

List of usage examples for java.awt.image WritableRaster getPixel

Introduction

In this page you can find the example usage for java.awt.image WritableRaster getPixel.

Prototype

public int[] getPixel(int x, int y, int[] iArray) 

Source Link

Document

Returns the samples in an array of int for the specified pixel.

Usage

From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java

private void processPixels(final int process, final Raster src, final WritableRaster dst, final int xOffset,
        final int step, final int y, final int width) {
    int srcX, dstX;

    // Create an array suitable for holding one pixel
    final int[] ps = src.getPixel(0, 0, (int[]) null);
    final int[] pd = dst.getPixel(0, 0, (int[]) null);

    dstX = xOffset;/*from w  w  w. j  a  v  a2  s  .com*/
    switch (process) {
    case POST_NONE:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);
            dst.setPixel(dstX, y, ps);
            dstX += step;
        }
        break;

    case POST_GAMMA:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            for (int i = 0; i < this.inputBands; ++i) {
                final int x = ps[i];
                ps[i] = this.gammaLut[x];
            }

            dst.setPixel(dstX, y, ps);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            pd[0] = this.grayLut[ps[0]];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT_ADD_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.grayLut[val];
            if (val == this.grayTransparentAlpha) {
                pd[1] = 0;
            } else {
                pd[1] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_PALETTE_TO_RGB:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.redPalette[val];
            pd[1] = this.greenPalette[val];
            pd[2] = this.bluePalette[val];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_PALETTE_TO_RGBA:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.redPalette[val];
            pd[1] = this.greenPalette[val];
            pd[2] = this.bluePalette[val];
            pd[3] = this.alphaPalette[val];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_GRAY_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            int val = ps[0];
            if (this.performGammaCorrection) {
                val = this.gammaLut[val];
            }
            pd[0] = val;
            if (val == this.grayTransparentAlpha) {
                pd[1] = 0;
            } else {
                pd[1] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_RGB_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int r = ps[0];
            final int g = ps[1];
            final int b = ps[2];
            if (this.performGammaCorrection) {
                pd[0] = this.gammaLut[r];
                pd[1] = this.gammaLut[g];
                pd[2] = this.gammaLut[b];
            } else {
                pd[0] = r;
                pd[1] = g;
                pd[2] = b;
            }
            if (r == this.redTransparentAlpha && g == this.greenTransparentAlpha
                    && b == this.blueTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_REMOVE_GRAY_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int g = ps[0];
            if (this.performGammaCorrection) {
                pd[0] = this.gammaLut[g];
            } else {
                pd[0] = g;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_REMOVE_RGB_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int r = ps[0];
            final int g = ps[1];
            final int b = ps[2];
            if (this.performGammaCorrection) {
                pd[0] = this.gammaLut[r];
                pd[1] = this.gammaLut[g];
                pd[2] = this.gammaLut[b];
            } else {
                pd[0] = r;
                pd[1] = g;
                pd[2] = b;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GAMMA_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int alpha = ps[1];
            final int gamma = this.gammaLut[val];
            pd[0] = gamma;
            pd[1] = gamma;
            pd[2] = gamma;
            pd[3] = alpha;

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_ALPHA_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int alpha = ps[1];
            pd[0] = val;
            pd[1] = val;
            pd[2] = val;
            pd[3] = alpha;

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_GRAY_TRANS_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            int val = ps[0];
            if (this.performGammaCorrection) {
                val = this.gammaLut[val];
            }
            pd[0] = val;
            pd[1] = val;
            pd[2] = val;
            if (val == this.grayTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT_ADD_TRANS_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int val2 = this.grayLut[val];
            pd[0] = val2;
            pd[1] = val2;
            pd[2] = val2;
            if (val == this.grayTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;
    }
}

From source file:org.apache.xmlgraphics.image.codec.png.PNGRed.java

private void processPixels(final int process, final Raster src, final WritableRaster dst, final int xOffset,
        final int step, final int y, final int width) {
    int srcX, dstX;

    // Create an array suitable for holding one pixel
    final int[] ps = src.getPixel(0, 0, (int[]) null);
    final int[] pd = dst.getPixel(0, 0, (int[]) null);

    dstX = xOffset;/* w  w  w  .j ava 2s. com*/
    switch (process) {
    case POST_NONE:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);
            dst.setPixel(dstX, y, ps);
            dstX += step;
        }
        break;

    case POST_GAMMA:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            for (int i = 0; i < this.inputBands; ++i) {
                final int x = ps[i];
                ps[i] = this.gammaLut[x];
            }

            dst.setPixel(dstX, y, ps);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            pd[0] = this.grayLut[ps[0]];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT_ADD_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.grayLut[val];
            if (val == this.grayTransparentAlpha) {
                pd[1] = 0;
            } else {
                pd[1] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_PALETTE_TO_RGB:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.redPalette[val];
            pd[1] = this.greenPalette[val];
            pd[2] = this.bluePalette[val];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_PALETTE_TO_RGBA:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            pd[0] = this.redPalette[val];
            pd[1] = this.greenPalette[val];
            pd[2] = this.bluePalette[val];
            pd[3] = this.alphaPalette[val];

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_GRAY_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            int val = ps[0];
            if (this.performGammaCorrection) {
                val = this.gammaLut[val];
            }
            pd[0] = val;
            if (val == this.grayTransparentAlpha) {
                pd[1] = 0;
            } else {
                pd[1] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_RGB_TRANS:
        final boolean flagGammaCorrection = this.performGammaCorrection; // local
        // is
        // cheaper
        final int[] workGammaLut = this.gammaLut;
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int r = ps[0];
            final int g = ps[1];
            final int b = ps[2];
            if (flagGammaCorrection) {
                pd[0] = workGammaLut[r];
                pd[1] = workGammaLut[g];
                pd[2] = workGammaLut[b];
            } else {
                pd[0] = r;
                pd[1] = g;
                pd[2] = b;
            }
            if (r == this.redTransparentAlpha && g == this.greenTransparentAlpha
                    && b == this.blueTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_REMOVE_GRAY_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int g = ps[0];
            if (this.performGammaCorrection) {
                pd[0] = this.gammaLut[g];
            } else {
                pd[0] = g;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_REMOVE_RGB_TRANS:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int r = ps[0];
            final int g = ps[1];
            final int b = ps[2];
            if (this.performGammaCorrection) {
                pd[0] = this.gammaLut[r];
                pd[1] = this.gammaLut[g];
                pd[2] = this.gammaLut[b];
            } else {
                pd[0] = r;
                pd[1] = g;
                pd[2] = b;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GAMMA_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int alpha = ps[1];
            final int gamma = this.gammaLut[val];
            pd[0] = gamma;
            pd[1] = gamma;
            pd[2] = gamma;
            pd[3] = alpha;

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_ALPHA_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int alpha = ps[1];
            pd[0] = val;
            pd[1] = val;
            pd[2] = val;
            pd[3] = alpha;

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_ADD_GRAY_TRANS_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            int val = ps[0];
            if (this.performGammaCorrection) {
                val = this.gammaLut[val];
            }
            pd[0] = val;
            pd[1] = val;
            pd[2] = val;
            if (val == this.grayTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;

    case POST_GRAY_LUT_ADD_TRANS_EXP:
        for (srcX = 0; srcX < width; srcX++) {
            src.getPixel(srcX, 0, ps);

            final int val = ps[0];
            final int val2 = this.grayLut[val];
            pd[0] = val2;
            pd[1] = val2;
            pd[2] = val2;
            if (val == this.grayTransparentAlpha) {
                pd[3] = 0;
            } else {
                pd[3] = this.maxOpacity;
            }

            dst.setPixel(dstX, y, pd);
            dstX += step;
        }
        break;
    }
}