src/java.desktop/share/classes/java/awt/image/LookupOp.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47971 75686e8da573
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:
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
     1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47971
diff changeset
     3
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * 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
     8
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    24
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.color.ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.RenderingHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.awt.image.ImagingLib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class implements a lookup operation from the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to the destination.  The LookupTable object may contain a single array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * or multiple arrays, subject to the restrictions below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * For Rasters, the lookup operates on bands.  The number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * lookup arrays may be one, in which case the same array is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * applied to all bands, or it must equal the number of Source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Raster bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * For BufferedImages, the lookup operates on color and alpha components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The number of lookup arrays may be one, in which case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * same array is applied to all color (but not alpha) components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Otherwise, the number of lookup arrays may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * equal the number of Source color components, in which case no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * lookup of the alpha component (if present) is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * If neither of these cases apply, the number of lookup arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * must equal the number of Source color components plus alpha components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * in which case lookup is performed for all color and alpha components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This allows non-uniform rescaling of multi-band BufferedImages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * BufferedImage sources with premultiplied alpha data are treated in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * manner as non-premultiplied images for purposes of the lookup.  That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the lookup is done per band on the raw data of the BufferedImage source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * without regard to whether the data is premultiplied.  If a color conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * is required to the destination ColorModel, the premultiplied state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * both source and destination will be taken into account for this step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Images with an IndexColorModel cannot be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * If a RenderingHints object is specified in the constructor, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * color rendering hint and the dithering hint may be used when color
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * conversion is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * This class allows the Source to be the same as the Destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see LookupTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see java.awt.RenderingHints#KEY_COLOR_RENDERING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see java.awt.RenderingHints#KEY_DITHERING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class LookupOp implements BufferedImageOp, RasterOp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private LookupTable ltable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private int numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    RenderingHints hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    84
     * Constructs a {@code LookupOp} object given the lookup
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    85
     * table and a {@code RenderingHints} object, which might
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    86
     * be {@code null}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    87
     * @param lookup the specified {@code LookupTable}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    88
     * @param hints the specified {@code RenderingHints},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    89
     *        or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public LookupOp(LookupTable lookup, RenderingHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this.ltable = lookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.hints  = hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        numComponents = ltable.getNumComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    98
     * Returns the {@code LookupTable}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    99
     * @return the {@code LookupTable} of this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   100
     *         {@code LookupOp}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public final LookupTable getTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return ltable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   107
     * Performs a lookup operation on a {@code BufferedImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * If the color model in the source image is not the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * in the destination image, the pixels will be converted
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   110
     * in the destination.  If the destination image is {@code null},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   111
     * a {@code BufferedImage} will be created with an appropriate
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   112
     * {@code ColorModel}.  An {@code IllegalArgumentException}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * might be thrown if the number of arrays in the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   114
     * {@code LookupTable} does not meet the restrictions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * stated in the class comment above, or if the source image
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   116
     * has an {@code IndexColorModel}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   117
     * @param src the {@code BufferedImage} to be filtered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   118
     * @param dst the {@code BufferedImage} in which to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *            store the results of the filter operation
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   120
     * @return the filtered {@code BufferedImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @throws IllegalArgumentException if the number of arrays in the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   122
     *         {@code LookupTable} does not meet the restrictions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *         described in the class comments, or if the source image
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   124
     *         has an {@code IndexColorModel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        ColorModel srcCM = src.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int numBands = srcCM.getNumColorComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        ColorModel dstCM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (srcCM instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                IllegalArgumentException("LookupOp cannot be "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                         "performed on an indexed image");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        int numComponents = ltable.getNumComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (numComponents != 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            numComponents != srcCM.getNumComponents() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            numComponents != srcCM.getNumColorComponents())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException("Number of arrays in the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                               " lookup table ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                               numComponents+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                               " is not compatible with the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                               " src image: "+src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        boolean needToConvert = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int width = src.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int height = src.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            dst = createCompatibleDestImage(src, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            dstCM = srcCM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (width != dst.getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    IllegalArgumentException("Src width ("+width+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                             ") not equal to dst width ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                             dst.getWidth()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (height != dst.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    IllegalArgumentException("Src height ("+height+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                             ") not equal to dst height ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                             dst.getHeight()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            dstCM = dst.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (srcCM.getColorSpace().getType() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                dstCM.getColorSpace().getType())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                needToConvert = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                dst = createCompatibleDestImage(src, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        BufferedImage origDst = dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (ImagingLib.filter(this, src, dst) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // Do it the slow way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            WritableRaster srcRaster = src.getRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            WritableRaster dstRaster = dst.getRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (srcCM.hasAlpha()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if (numBands-1 == numComponents || numComponents == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    int minx = srcRaster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    int miny = srcRaster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    int[] bands = new int[numBands-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    for (int i=0; i < numBands-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        bands[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    srcRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        srcRaster.createWritableChild(minx, miny,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                                      srcRaster.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                                      srcRaster.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                                      minx, miny,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                                      bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (dstCM.hasAlpha()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                int dstNumBands = dstRaster.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                if (dstNumBands-1 == numComponents || numComponents == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    int minx = dstRaster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    int miny = dstRaster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    int[] bands = new int[numBands-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    for (int i=0; i < numBands-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        bands[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    dstRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        dstRaster.createWritableChild(minx, miny,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                                      dstRaster.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                                      dstRaster.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                                      minx, miny,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                                      bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            filter(srcRaster, dstRaster);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (needToConvert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // ColorModels are not the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            ColorConvertOp ccop = new ColorConvertOp(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            ccop.filter(dst, origDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return origDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   235
     * Performs a lookup operation on a {@code Raster}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   236
     * If the destination {@code Raster} is {@code null},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   237
     * a new {@code Raster} will be created.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   238
     * The {@code IllegalArgumentException} might be thrown
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   239
     * if the source {@code Raster} and the destination
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   240
     * {@code Raster} do not have the same
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * number of bands or if the number of arrays in the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   242
     * {@code LookupTable} does not meet the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * restrictions stated in the class comment above.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   244
     * @param src the source {@code Raster} to filter
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   245
     * @param dst the destination {@code WritableRaster} for the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   246
     *            filtered {@code src}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   247
     * @return the filtered {@code WritableRaster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @throws IllegalArgumentException if the source and destinations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *         rasters do not have the same number of bands, or the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   250
     *         number of arrays in the {@code LookupTable} does
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *         not meet the restrictions described in the class comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public final WritableRaster filter (Raster src, WritableRaster dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        int numBands  = src.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int height    = src.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        int width     = src.getWidth();
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47971
diff changeset
   258
        int[] srcPix  = new int[numBands];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // Create a new destination Raster, if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            dst = createCompatibleDestRaster(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        else if (height != dst.getHeight() || width != dst.getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                IllegalArgumentException ("Width or height of Rasters do not "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                          "match");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
40173
668a4cd8de97 6427331: NullPointerException in LookupOp.filter(Raster, WritableRaster)
aghaisas
parents: 35667
diff changeset
   270
        int dstLength = dst.getNumBands();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (numBands != dstLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                IllegalArgumentException ("Number of channels in the src ("
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                          + numBands +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                          ") does not match number of channels"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                          + " in the destination ("
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                          + dstLength + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int numComponents = ltable.getNumComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (numComponents != 1 && numComponents != src.getNumBands()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            throw new IllegalArgumentException("Number of arrays in the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                               " lookup table ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                               numComponents+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                               " is not compatible with the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                               " src Raster: "+src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (ImagingLib.filter(this, src, dst) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // Optimize for cases we know about
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (ltable instanceof ByteLookupTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            byteFilter ((ByteLookupTable) ltable, src, dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        width, height, numBands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        else if (ltable instanceof ShortLookupTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            shortFilter ((ShortLookupTable) ltable, src, dst, width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                         height, numBands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // Not one we recognize so do it slowly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            int sminX = src.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            int sY = src.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            int dminX = dst.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            int dY = dst.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            for (int y=0; y < height; y++, sY++, dY++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                int sX = sminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                int dX = dminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                for (int x=0; x < width; x++, sX++, dX++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    // Find data for all bands at this x,y position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    src.getPixel(sX, sY, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    // Lookup the data for all bands at this x,y position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    ltable.lookupPixel(srcPix, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    // Put it back for all bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    dst.setPixel(dX, dY, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Returns the bounding box of the filtered destination image.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * this is not a geometric operation, the bounding box does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * change.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   332
     * @param src the {@code BufferedImage} to be filtered
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return the bounds of the filtered definition image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public final Rectangle2D getBounds2D (BufferedImage src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return getBounds2D(src.getRaster());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Returns the bounding box of the filtered destination Raster.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * this is not a geometric operation, the bounding box does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * change.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   343
     * @param src the {@code Raster} to be filtered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   344
     * @return the bounds of the filtered definition {@code Raster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public final Rectangle2D getBounds2D (Raster src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return src.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Creates a zeroed destination image with the correct size and number of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   353
     * bands.  If destCM is {@code null}, an appropriate
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   354
     * {@code ColorModel} will be used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param src       Source image for the filter operation.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   356
     * @param destCM    the destination's {@code ColorModel}, which
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   357
     *                  can be {@code null}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   358
     * @return a filtered destination {@code BufferedImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public BufferedImage createCompatibleDestImage (BufferedImage src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                    ColorModel destCM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        BufferedImage image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        int w = src.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        int h = src.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        int transferType = DataBuffer.TYPE_BYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (destCM == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            ColorModel cm = src.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            Raster raster = src.getRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (cm instanceof ComponentColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                DataBuffer db = raster.getDataBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                boolean hasAlpha = cm.hasAlpha();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                boolean isPre    = cm.isAlphaPremultiplied();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                int trans        = cm.getTransparency();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                int[] nbits = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                if (ltable instanceof ByteLookupTable) {
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
   376
                    if (db.getDataType() == DataBuffer.TYPE_USHORT) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        // Dst raster should be of type byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                        if (hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                            nbits = new int[2];
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
   380
                            if (trans == java.awt.Transparency.BITMASK) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                nbits[1] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                nbits[1] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                            nbits = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        nbits[0] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    // For byte, no need to change the cm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                else if (ltable instanceof ShortLookupTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    transferType = DataBuffer.TYPE_USHORT;
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
   396
                    if (db.getDataType() == DataBuffer.TYPE_BYTE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        if (hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                            nbits = new int[2];
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 5506
diff changeset
   399
                            if (trans == java.awt.Transparency.BITMASK) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                nbits[1] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                nbits[1] = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                            nbits = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                        nbits[0] = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                if (nbits != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    cm = new ComponentColorModel(cm.getColorSpace(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                 nbits, hasAlpha, isPre,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                                 trans, transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            image = new BufferedImage(cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                      cm.createCompatibleWritableRaster(w, h),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                      cm.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            image = new BufferedImage(destCM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                      destCM.createCompatibleWritableRaster(w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                                            h),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                      destCM.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   435
     * Creates a zeroed-destination {@code Raster} with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * correct size and number of bands, given this source.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   437
     * @param src the {@code Raster} to be transformed
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   438
     * @return the zeroed-destination {@code Raster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public WritableRaster createCompatibleDestRaster (Raster src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return src.createCompatibleWritableRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Returns the location of the destination point given a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   446
     * point in the source.  If {@code dstPt} is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   447
     * {@code null}, it will be used to hold the return value.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   448
     * Since this is not a geometric operation, the {@code srcPt}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   449
     * will equal the {@code dstPt}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   450
     * @param srcPt a {@code Point2D} that represents a point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *        in the source image
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   452
     * @param dstPt a {@code Point2D} that represents the location
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *        in the destination
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   454
     * @return the {@code Point2D} in the destination that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *         corresponds to the specified point in the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public final Point2D getPoint2D (Point2D srcPt, Point2D dstPt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (dstPt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            dstPt = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        dstPt.setLocation(srcPt.getX(), srcPt.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return dstPt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Returns the rendering hints for this op.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   468
     * @return the {@code RenderingHints} object associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *         with this op.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public final RenderingHints getRenderingHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   475
    private void byteFilter(ByteLookupTable lookup, Raster src,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                                  WritableRaster dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                  int width, int height, int numBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        int[] srcPix = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        // Find the ref to the table and the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        byte[][] table = lookup.getTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        int offset = lookup.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        int tidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int step=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // Check if it is one lookup applied to all bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (table.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            step=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        int band;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        int len = table[0].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // Loop through the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        for ( y=0; y < height; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            tidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            for ( band=0; band < numBands; band++, tidx+=step) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                // Find data for this band, scanline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                srcPix = src.getSamples(0, y, width, 1, band, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                for ( x=0; x < width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    int index = srcPix[x]-offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    if (index < 0 || index > len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                            IllegalArgumentException("index ("+index+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                     "(out of range: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                                     " srcPix["+x+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                                     "]="+ srcPix[x]+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                                     " offset="+ offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    // Do the lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    srcPix[x] = table[tidx][index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                // Put it back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                dst.setSamples(0, y, width, 1, band, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   522
    private void shortFilter(ShortLookupTable lookup, Raster src,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                   WritableRaster dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                   int width, int height, int numBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        int band;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        int[] srcPix = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        // Find the ref to the table and the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        short[][] table = lookup.getTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        int offset = lookup.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        int tidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        int step=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        // Check if it is one lookup applied to all bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        if (table.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            step=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        int maxShort = (1<<16)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        // Loop through the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        for (y=0; y < height; y++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            tidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            for ( band=0; band < numBands; band++, tidx+=step) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                // Find data for this band, scanline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                srcPix = src.getSamples(0, y, width, 1, band, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                for ( x=0; x < width; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    index = srcPix[x]-offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    if (index < 0 || index > maxShort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                        throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                            IllegalArgumentException("index out of range "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                                     index+" x is "+x+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                                     "srcPix[x]="+srcPix[x]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                                     +" offset="+ offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    // Do the lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    srcPix[x] = table[tidx][index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                // Put it back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                dst.setSamples(0, y, width, 1, band, srcPix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
}