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

The following examples show how to use java.awt.image.ColorModel#getRGB() . 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: RGBImageFilter.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel. Otherwise converts the buffer of byte
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, byte pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 2
Source File: RGBImageFilter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel. Otherwise converts the buffer of byte
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, byte pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 3
Source File: RGBImageFilter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel. Otherwise converts the buffer of byte
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, byte pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 4
Source File: RGBImageFilter.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel, otherwise converts the buffer of integer
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * Converts a buffer of integer pixels to the default RGB ColorModel
 * and passes the converted buffer to the filterRGBPixels method.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, int pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB(pixels[index]);
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 5
Source File: RGBImageFilter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel. Otherwise converts the buffer of byte
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, byte pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 6
Source File: RGBImageFilter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel. Otherwise converts the buffer of byte
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, byte pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB((pixels[index] & 0xff));
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 7
Source File: RGBImageFilter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If the ColorModel object is the same one that has already
 * been converted, then simply passes the pixels through with the
 * converted ColorModel, otherwise converts the buffer of integer
 * pixels to the default RGB ColorModel and passes the converted
 * buffer to the filterRGBPixels method to be converted one by one.
 * Converts a buffer of integer pixels to the default RGB ColorModel
 * and passes the converted buffer to the filterRGBPixels method.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 * @see ColorModel#getRGBdefault
 * @see #filterRGBPixels
 */
public void setPixels(int x, int y, int w, int h,
                      ColorModel model, int pixels[], int off,
                      int scansize) {
    if (model == origmodel) {
        consumer.setPixels(x, y, w, h, newmodel, pixels, off, scansize);
    } else {
        int filteredpixels[] = new int[w];
        int index = off;
        for (int cy = 0; cy < h; cy++) {
            for (int cx = 0; cx < w; cx++) {
                filteredpixels[cx] = model.getRGB(pixels[index]);
                index++;
            }
            index += scansize - w;
            filterRGBPixels(x, y + cy, w, 1, filteredpixels, 0, w);
        }
    }
}
 
Example 8
Source File: BMPPluginTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean compare(BufferedImage in, BufferedImage out) {
    int width = in.getWidth();
    int height = in.getHeight();
    if (out.getWidth() != width || out.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = in.getRaster();
    ColorModel oldcm = in.getColorModel();
    Raster newras = out.getRaster();
    ColorModel newcm = out.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j);
            }
        }
    }
    return true;
}
 
Example 9
Source File: BMPCompressionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean compare(final BufferedImage in, final BufferedImage out) {

            final int width = in.getWidth();
            int height = in.getHeight();
            if (out.getWidth() != width || out.getHeight() != height) {
                throw new RuntimeException("Dimensions changed!");
            }

            Raster oldras = in.getRaster();
            ColorModel oldcm = in.getColorModel();
            Raster newras = out.getRaster();
            ColorModel newcm = out.getColorModel();

            for (int j = 0; j < height; j++) {
                for (int i = 0; i < width; i++) {
                    Object oldpixel = oldras.getDataElements(i, j, null);
                    int oldrgb = oldcm.getRGB(oldpixel);
                    int oldalpha = oldcm.getAlpha(oldpixel);

                    Object newpixel = newras.getDataElements(i, j, null);
                    int newrgb = newcm.getRGB(newpixel);
                    int newalpha = newcm.getAlpha(newpixel);

                    if (newrgb != oldrgb ||
                        newalpha != oldalpha) {
                        // showDiff(in, out);
                        throw new RuntimeException("Pixels differ at " + i +
                                                   ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
                    }
                }
            }
            return true;
        }
 
Example 10
Source File: BMPWriteParamTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean compare(final BufferedImage in,
                               final BufferedImage out)
{
    final int width = in.getWidth();
    int height = in.getHeight();
    if (out.getWidth() != width || out.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = in.getRaster();
    ColorModel oldcm = in.getColorModel();
    Raster newras = out.getRaster();
    ColorModel newcm = out.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                // showDiff(in, out);
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
            }
        }
    }
    return true;
}
 
Example 11
Source File: ImageCompare.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void compare(BufferedImage oldimg,
                           BufferedImage newimg) {
    int width = oldimg.getWidth();
    int height = oldimg.getHeight();
    if (newimg.getWidth() != width || newimg.getHeight() != height) {
        throw new RuntimeException("Dimensions changed!");
    }

    Raster oldras = oldimg.getRaster();
    ColorModel oldcm = oldimg.getColorModel();
    Raster newras = newimg.getRaster();
    ColorModel newcm = newimg.getColorModel();

    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            Object oldpixel = oldras.getDataElements(i, j, null);
            int oldrgb = oldcm.getRGB(oldpixel);
            int oldalpha = oldcm.getAlpha(oldpixel);

            Object newpixel = newras.getDataElements(i, j, null);
            int newrgb = newcm.getRGB(newpixel);
            int newalpha = newcm.getAlpha(newpixel);

            if (newrgb != oldrgb ||
                newalpha != oldalpha) {
                throw new RuntimeException("Pixels differ at " + i +
                                           ", " + j);
            }
        }
    }
}
 
Example 12
Source File: AreaAveragingScaleFilter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 13
Source File: AreaAveragingScaleFilter.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 14
Source File: AreaAveragingScaleFilter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 15
Source File: CustomComponent.java    From jdk8u60 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);
    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);
}
 
Example 16
Source File: AreaAveragingScaleFilter.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 17
Source File: AreaAveragingScaleFilter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 18
Source File: AreaAveragingScaleFilter.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}
 
Example 19
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);
    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);
}
 
Example 20
Source File: AreaAveragingScaleFilter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private void accumPixels(int x, int y, int w, int h,
                         ColorModel model, Object pixels, int off,
                         int scansize) {
    if (reds == null) {
        makeAccumBuffers();
    }
    int sy = y;
    int syrem = destHeight;
    int dy, dyrem;
    if (sy == 0) {
        dy = 0;
        dyrem = 0;
    } else {
        dy = savedy;
        dyrem = savedyrem;
    }
    while (sy < y + h) {
        int amty;
        if (dyrem == 0) {
            for (int i = 0; i < destWidth; i++) {
                alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
            }
            dyrem = srcHeight;
        }
        if (syrem < dyrem) {
            amty = syrem;
        } else {
            amty = dyrem;
        }
        int sx = 0;
        int dx = 0;
        int sxrem = 0;
        int dxrem = srcWidth;
        float a = 0f, r = 0f, g = 0f, b = 0f;
        while (sx < w) {
            if (sxrem == 0) {
                sxrem = destWidth;
                int rgb;
                if (pixels instanceof byte[]) {
                    rgb = ((byte[]) pixels)[off + sx] & 0xff;
                } else {
                    rgb = ((int[]) pixels)[off + sx];
                }
                // getRGB() always returns non-premultiplied components
                rgb = model.getRGB(rgb);
                a = rgb >>> 24;
                r = (rgb >> 16) & 0xff;
                g = (rgb >>  8) & 0xff;
                b = rgb & 0xff;
                // premultiply the components if necessary
                if (a != 255.0f) {
                    float ascale = a / 255.0f;
                    r *= ascale;
                    g *= ascale;
                    b *= ascale;
                }
            }
            int amtx;
            if (sxrem < dxrem) {
                amtx = sxrem;
            } else {
                amtx = dxrem;
            }
            float mult = ((float) amtx) * amty;
            alphas[dx] += mult * a;
            reds[dx] += mult * r;
            greens[dx] += mult * g;
            blues[dx] += mult * b;
            if ((sxrem -= amtx) == 0) {
                sx++;
            }
            if ((dxrem -= amtx) == 0) {
                dx++;
                dxrem = srcWidth;
            }
        }
        if ((dyrem -= amty) == 0) {
            int outpix[] = calcRow();
            do {
                consumer.setPixels(0, dy, destWidth, 1,
                                   rgbmodel, outpix, 0, destWidth);
                dy++;
            } while ((syrem -= amty) >= amty && amty == srcHeight);
        } else {
            syrem -= amty;
        }
        if (syrem == 0) {
            syrem = destHeight;
            sy++;
            off += scansize;
        }
    }
    savedyrem = dyrem;
    savedy = dy;
}