src/java.desktop/share/classes/java/awt/image/BandCombineOp.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
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2005, 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.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.color.ICC_Profile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.RenderingHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.image.ImagingLib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Arrays;
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 performs an arbitrary linear combination of the bands
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    39
 * in a {@code Raster}, using a specified matrix.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The width of the matrix must be equal to the number of bands in the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    42
 * source {@code Raster}, optionally plus one.  If there is one more
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * column in the matrix than the number of bands, there is an implied 1 at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * end of the vector of band samples representing a pixel.  The height
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of the matrix must be equal to the number of bands in the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    47
 * For example, a 3-banded {@code Raster} might have the following
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * transformation applied to each pixel in order to invert the second band of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    49
 * the {@code Raster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   [ 1.0   0.0   0.0    0.0  ]     [ b1 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   [ 0.0  -1.0   0.0  255.0  ]  x  [ b2 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   [ 0.0   0.0   1.0    0.0  ]     [ b3 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *                                   [ 1 ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Note that the source and destination can be the same object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class BandCombineOp implements  RasterOp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    float[][] matrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int nrows = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    int ncols = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    RenderingHints hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    67
     * Constructs a {@code BandCombineOp} with the specified matrix.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The width of the matrix must be equal to the number of bands in
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    69
     * the source {@code Raster}, optionally plus one.  If there is one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * more column in the matrix than the number of bands, there is an implied
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * 1 at the end of the vector of band samples representing a pixel.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * height of the matrix must be equal to the number of bands in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The first subscript is the row index and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * is the column index.  This operation uses none of the currently
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    77
     * defined rendering hints; the {@code RenderingHints} argument can be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param matrix The matrix to use for the band combine operation.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    81
     * @param hints The {@code RenderingHints} object for this operation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Not currently used so it can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public BandCombineOp (float[][] matrix, RenderingHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        nrows = matrix.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        ncols = matrix[0].length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        this.matrix = new float[nrows][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        for (int i=0; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            /* Arrays.copyOf is forgiving of the source array being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
             * too short, but it is also faster than other cloning
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
             * methods, so we provide our own protection for short
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
             * matrix rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (ncols > matrix[i].length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                throw new IndexOutOfBoundsException("row "+i+" too short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            this.matrix[i] = Arrays.copyOf(matrix[i], ncols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.hints  = hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns a copy of the linear combination matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return The matrix associated with this band combine operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public final float[][] getMatrix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        float[][] ret = new float[nrows][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        for (int i = 0; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            ret[i] = Arrays.copyOf(matrix[i], ncols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   116
     * Transforms the {@code Raster} using the matrix specified in the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   117
     * constructor. An {@code IllegalArgumentException} may be thrown if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the number of bands in the source or destination is incompatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the matrix.  See the class comments for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * If the destination is null, it will be created with a number of bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * equalling the number of rows in the matrix. No exception is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * if the operation causes a data overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   125
     * @param src The {@code Raster} to be filtered.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   126
     * @param dst The {@code Raster} in which to store the results
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * of the filter operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   129
     * @return The filtered {@code Raster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @throws IllegalArgumentException If the number of bands in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * source or destination is incompatible with the matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public WritableRaster filter(Raster src, WritableRaster dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        int nBands = src.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (ncols != nBands && ncols != (nBands+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new IllegalArgumentException("Number of columns in the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                               "matrix ("+ncols+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                               ") must be equal to the number"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                               " of bands ([+1]) in src ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                               nBands+").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            dst = createCompatibleDestRaster(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        else if (nrows != dst.getNumBands()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new IllegalArgumentException("Number of rows in the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                               "matrix ("+nrows+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                               ") must be equal to the number"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                               " of bands ([+1]) in dst ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                               nBands+").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (ImagingLib.filter(this, src, dst) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int[] pixel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        int[] dstPixel = new int[dst.getNumBands()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        float accum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int sminX = src.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int sY = src.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        int dminX = dst.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int dY = dst.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int sX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int dX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (ncols == nBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            for (int y=0; y < src.getHeight(); y++, sY++, dY++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                dX = dminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                sX = sminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                for (int x=0; x < src.getWidth(); x++, sX++, dX++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    pixel = src.getPixel(sX, sY, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    for (int r=0; r < nrows; r++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        accum = 0.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        for (int c=0; c < ncols; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                            accum += matrix[r][c]*pixel[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        dstPixel[r] = (int) accum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    dst.setPixel(dX, dY, dstPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // Need to add constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            for (int y=0; y < src.getHeight(); y++, sY++, dY++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                dX = dminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                sX = sminX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                for (int x=0; x < src.getWidth(); x++, sX++, dX++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    pixel = src.getPixel(sX, sY, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    for (int r=0; r < nrows; r++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        accum = 0.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        for (int c=0; c < nBands; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                            accum += matrix[r][c]*pixel[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        dstPixel[r] = (int) (accum+matrix[r][nBands]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    dst.setPixel(dX, dY, dstPixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns the bounding box of the transformed destination.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * this is not a geometric operation, the bounding box is the same for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the source and destination.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   210
     * An {@code IllegalArgumentException} may be thrown if the number of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * bands in the source is incompatible with the matrix.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the class comments for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   214
     * @param src The {@code Raster} to be filtered.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   216
     * @return The {@code Rectangle2D} representing the destination
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * image's bounding box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @throws IllegalArgumentException If the number of bands in the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * is incompatible with the matrix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public final Rectangle2D getBounds2D (Raster src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return src.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   228
     * Creates a zeroed destination {@code Raster} with the correct size
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * and number of bands.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   230
     * An {@code IllegalArgumentException} may be thrown if the number of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * bands in the source is incompatible with the matrix.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * the class comments for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   234
     * @param src The {@code Raster} to be filtered.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   236
     * @return The zeroed destination {@code Raster}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public WritableRaster createCompatibleDestRaster (Raster src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        int nBands = src.getNumBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if ((ncols != nBands) && (ncols != (nBands+1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new IllegalArgumentException("Number of columns in the "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                               "matrix ("+ncols+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                               ") must be equal to the number"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                               " of bands ([+1]) in src ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                               nBands+").");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (src.getNumBands() == nrows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return src.createCompatibleWritableRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new IllegalArgumentException("Don't know how to create a "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                               " compatible Raster with "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                               nrows+" bands.");
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns the location of the corresponding destination point given a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   259
     * point in the source {@code Raster}.  If {@code dstPt} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * specified, it is used to hold the return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Since this is not a geometric operation, the point returned
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   262
     * is the same as the specified {@code srcPt}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   264
     * @param srcPt The {@code Point2D} that represents the point in
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   265
     *              the source {@code Raster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   266
     * @param dstPt The {@code Point2D} in which to store the result.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   268
     * @return The {@code Point2D} in the destination image that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * corresponds to the specified point in the source image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public final Point2D getPoint2D (Point2D srcPt, Point2D dstPt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (dstPt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            dstPt = new Point2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        dstPt.setLocation(srcPt.getX(), srcPt.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return dstPt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Returns the rendering hints for this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   283
     * @return The {@code RenderingHints} object associated with this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * operation.  Returns null if no hints have been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public final RenderingHints getRenderingHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}