src/java.desktop/share/classes/java/awt/image/AreaAveragingScaleFilter.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ImageConsumer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * An ImageFilter class for scaling images using a simple area averaging
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * algorithm that produces smoother results than the nearest neighbor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>This class extends the basic ImageFilter Class to scale an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * image and provide a source for a new image containing the resampled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * image.  The pixels in the source image are blended to produce pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * for an image of the specified size.  The blending process is analogous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * to scaling up the source image to a multiple of the destination size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * using pixel replication and then scaling it back down to the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * size by simply averaging all the pixels in the supersized image that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * fall within a given pixel of the destination image.  If the data from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the source is not delivered in TopDownLeftRight order then the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * will back off to a simple pixel replication behavior and utilize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * requestTopDownLeftRightResend() method to refilter the pixels in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * better way at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>It is meant to be used in conjunction with a FilteredImageSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * object to produce scaled versions of existing images.  Due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * implementation dependencies, there may be differences in pixel values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * of an image filtered on different platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see FilteredImageSource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see ReplicateScaleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see ImageFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class AreaAveragingScaleFilter extends ReplicateScaleFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final ColorModel rgbmodel = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final int neededHints = (TOPDOWNLEFTRIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                            | COMPLETESCANLINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean passthrough;
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
    66
    private float[] reds, greens, blues, alphas;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int savedy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int savedyrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Constructs an AreaAveragingScaleFilter that scales the pixels from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * its source Image as specified by the width and height parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param width the target width to scale the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param height the target height to scale the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public AreaAveragingScaleFilter(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Detect if the data is being delivered with the necessary hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * to allow the averaging algorithm to do its work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Note: This method is intended to be called by the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    85
     * {@code ImageProducer} of the {@code Image} whose
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * pixels are being filtered.  Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see ImageConsumer#setHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void setHints(int hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        passthrough = ((hints & neededHints) != neededHints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super.setHints(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private void makeAccumBuffers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        reds = new float[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        greens = new float[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        blues = new float[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        alphas = new float[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private int[] calcRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        float origmult = ((float) srcWidth) * srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (outpixbuf == null || !(outpixbuf instanceof int[])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            outpixbuf = new int[destWidth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        int[] outpix = (int[]) outpixbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (int x = 0; x < destWidth; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            float mult = origmult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            int a = Math.round(alphas[x] / mult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (a <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                a = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            } else if (a >= 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                a = 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                // un-premultiply the components (by modifying mult here, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                // are effectively doing the divide by mult and divide by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                // alpha in the same step)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                mult = alphas[x] / 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            int r = Math.round(reds[x] / mult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            int g = Math.round(greens[x] / mult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            int b = Math.round(blues[x] / mult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (r < 0) {r = 0;} else if (r > 255) {r = 255;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (g < 0) {g = 0;} else if (g > 255) {g = 255;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (b < 0) {b = 0;} else if (b > 255) {b = 255;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            outpix[x] = (a << 24 | r << 16 | g << 8 | b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return outpix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private void accumPixels(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                             ColorModel model, Object pixels, int off,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                             int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (reds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            makeAccumBuffers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int sy = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int syrem = destHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        int dy, dyrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (sy == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            dy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            dyrem = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            dy = savedy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            dyrem = savedyrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        while (sy < y + h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            int amty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (dyrem == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                for (int i = 0; i < destWidth; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    alphas[i] = reds[i] = greens[i] = blues[i] = 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                dyrem = srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (syrem < dyrem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                amty = syrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                amty = dyrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            int sx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            int dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            int sxrem = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            int dxrem = srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            float a = 0f, r = 0f, g = 0f, b = 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            while (sx < w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                if (sxrem == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    sxrem = destWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    int rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    if (pixels instanceof byte[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                        rgb = ((byte[]) pixels)[off + sx] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        rgb = ((int[]) pixels)[off + sx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    // getRGB() always returns non-premultiplied components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    rgb = model.getRGB(rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    a = rgb >>> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    r = (rgb >> 16) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    g = (rgb >>  8) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    b = rgb & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    // premultiply the components if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    if (a != 255.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        float ascale = a / 255.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        r *= ascale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        g *= ascale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        b *= ascale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                int amtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if (sxrem < dxrem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    amtx = sxrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    amtx = dxrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                float mult = ((float) amtx) * amty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                alphas[dx] += mult * a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                reds[dx] += mult * r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                greens[dx] += mult * g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                blues[dx] += mult * b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if ((sxrem -= amtx) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    sx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                if ((dxrem -= amtx) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    dx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    dxrem = srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if ((dyrem -= amty) == 0) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   211
                int[] outpix = calcRow();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    consumer.setPixels(0, dy, destWidth, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                       rgbmodel, outpix, 0, destWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    dy++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                } while ((syrem -= amty) >= amty && amty == srcHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                syrem -= amty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (syrem == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                syrem = destHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                sy++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                off += scansize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        savedyrem = dyrem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        savedy = dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Combine the components for the delivered byte pixels into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * accumulation arrays and send on any averaged data for rows of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * pixels that are complete.  If the correct hints were not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * specified in the setHints call then relay the work to our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * superclass which is capable of scaling pixels regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * the delivery hints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Note: This method is intended to be called by the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   239
     * {@code ImageProducer} of the {@code Image}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * whose pixels are being filtered.  Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see ReplicateScaleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void setPixels(int x, int y, int w, int h,
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   247
                          ColorModel model, byte[] pixels, int off,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                          int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (passthrough) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            super.setPixels(x, y, w, h, model, pixels, off, scansize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            accumPixels(x, y, w, h, model, pixels, off, scansize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Combine the components for the delivered int pixels into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * accumulation arrays and send on any averaged data for rows of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * pixels that are complete.  If the correct hints were not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * specified in the setHints call then relay the work to our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * superclass which is capable of scaling pixels regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * the delivery hints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Note: This method is intended to be called by the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   265
     * {@code ImageProducer} of the {@code Image}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * whose pixels are being filtered.  Developers using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * this class to filter pixels from an image should avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * this method directly since that operation could interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * with the filtering operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see ReplicateScaleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void setPixels(int x, int y, int w, int h,
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   273
                          ColorModel model, int[] pixels, int off,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                          int scansize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (passthrough) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            super.setPixels(x, y, w, h, model, pixels, off, scansize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            accumPixels(x, y, w, h, model, pixels, off, scansize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}