src/java.desktop/share/classes/java/awt/image/IndexColorModel.java
author ssadetsky
Wed, 22 Nov 2017 14:04:51 -0800
changeset 47971 75686e8da573
parent 47216 71c04702a3d5
child 52248 2e330da7cbf4
permissions -rw-r--r--
8190228: Remove redundant modifiers in java.desktop module. Reviewed-by: serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43827
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
     2
 * Copyright (c) 1995, 2017, 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.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.color.ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.math.BigInteger;
43827
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
    31
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    34
 * The {@code IndexColorModel} class is a {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * class that works with pixel values consisting of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * single sample that is an index into a fixed colormap in the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * sRGB color space.  The colormap specifies red, green, blue, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * optional alpha components corresponding to each index.  All components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * are represented in the colormap as 8-bit unsigned integral values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Some constructors allow the caller to specify "holes" in the colormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * by indicating which colormap entries are valid and which represent
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    42
 * unusable colors via the bits set in a {@code BigInteger} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This color model is similar to an X11 PseudoColor visual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Some constructors provide a means to specify an alpha component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * for each pixel in the colormap, while others either provide no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * such means or, in some cases, a flag to indicate whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * colormap data contains alpha values.  If no alpha is supplied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the constructor, an opaque alpha component (alpha = 1.0) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * assumed for each entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * An optional transparent pixel value can be supplied that indicates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * pixel to be made completely transparent, regardless of any alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * component supplied or assumed for that pixel value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Note that the color components in the colormap of an
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    55
 * {@code IndexColorModel} objects are never pre-multiplied with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the alpha components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
45025
9ad3afa82b5e 8179596: Update java.desktop to be HTML-5 friendly
serb
parents: 44534
diff changeset
    58
 * <a id="transparency">
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    59
 * The transparency of an {@code IndexColorModel} object is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * determined by examining the alpha components of the colors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * colormap and choosing the most specific value after considering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the optional alpha values and any transparent index specified.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    63
 * The transparency value is {@code Transparency.OPAQUE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * only if all valid colors in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the colormap are opaque and there is no valid transparent pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * If all valid colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * in the colormap are either completely opaque (alpha = 1.0) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * completely transparent (alpha = 0.0), which typically occurs when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * a valid transparent pixel is specified,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    70
 * the value is {@code Transparency.BITMASK}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    71
 * Otherwise, the value is {@code Transparency.TRANSLUCENT}, indicating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * that some valid color has an alpha component that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * neither completely transparent nor completely opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * (0.0 &lt; alpha &lt; 1.0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    78
 * If an {@code IndexColorModel} object has
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    79
 * a transparency value of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    80
 * then the {@code hasAlpha}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    81
 * and {@code getNumComponents} methods
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    82
 * (both inherited from {@code ColorModel})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * return false and 3, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * For any other transparency value,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    85
 * {@code hasAlpha} returns true
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
    86
 * and {@code getNumComponents} returns 4.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p>
45025
9ad3afa82b5e 8179596: Update java.desktop to be HTML-5 friendly
serb
parents: 44534
diff changeset
    89
 * <a id="index_values">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * The values used to index into the colormap are taken from the least
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * significant <em>n</em> bits of pixel representations where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <em>n</em> is based on the pixel size specified in the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * For pixel sizes smaller than 8 bits, <em>n</em> is rounded up to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * power of two (3 becomes 4 and 5,6,7 become 8).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * For pixel sizes between 8 and 16 bits, <em>n</em> is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * pixel size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * Pixel sizes larger than 16 bits are not supported by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Higher order bits beyond <em>n</em> are ignored in pixel representations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Index values greater than or equal to the map size, but less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * 2<sup><em>n</em></sup>, are undefined and return 0 for all color and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * alpha components.
19169
1807a84c3d63 8022447: Fix doclint warnings in java.awt.image
prr
parents: 7762
diff changeset
   102
 * </a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * For those methods that use a primitive array pixel representation of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   105
 * type {@code transferType}, the array length is always one.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   106
 * The transfer types supported are {@code DataBuffer.TYPE_BYTE} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   107
 * {@code DataBuffer.TYPE_USHORT}.  A single int pixel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * representation is valid for all objects of this class, since it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * always possible to represent pixel values used with this class in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * single int.  Therefore, methods that use this representation do
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   111
 * not throw an {@code IllegalArgumentException} due to an invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * pixel value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * Many of the methods in this class are final.  The reason for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * this is that the underlying native graphics code makes assumptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * about the layout and operation of this class and those assumptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * are reflected in the implementations of the methods here that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * marked final.  You can subclass this class for other reasons, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * you cannot override or modify the behaviour of those methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @see ColorSpace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see DataBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
public class IndexColorModel extends ColorModel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private int rgb[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private int map_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private int pixel_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private int transparent_index = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private boolean allgrayopaque;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private BigInteger validBits;
43827
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
   133
    private volatile int hashCode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
6861
0c879c7c2ea2 6925710: IndexColorModel.finalize can be made to double free
bae
parents: 5506
diff changeset
   135
    private sun.awt.image.BufImgSurfaceData.ICMColorData colorData = null;
0c879c7c2ea2 6925710: IndexColorModel.finalize can be made to double free
bae
parents: 5506
diff changeset
   136
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static int[] opaqueBits = {8, 8, 8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static int[] alphaBits = {8, 8, 8, 8};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   140
    private static native void initIDs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ColorModel.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   146
     * Constructs an {@code IndexColorModel} from the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * arrays of red, green, and blue components.  Pixels described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * by this color model all have alpha components of 255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * unnormalized (1.0&nbsp;normalized), which means they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * are fully opaque.  All of the arrays specifying the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * components must have at least the specified number of entries.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   152
     * The {@code ColorSpace} is the default sRGB space.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Since there is no alpha information in any of the arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * to this constructor, the transparency value is always
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   155
     * {@code Transparency.OPAQUE}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   156
     * The transfer type is the smallest of {@code DataBuffer.TYPE_BYTE}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   157
     * or {@code DataBuffer.TYPE_USHORT} that can hold a single pixel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param r         the array of red color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param g         the array of green color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param b         the array of blue color components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   163
     * @throws IllegalArgumentException if {@code bits} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *         than 1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   165
     * @throws IllegalArgumentException if {@code size} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *         than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public IndexColorModel(int bits, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                           byte r[], byte g[], byte b[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        super(bits, opaqueBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
              ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              false, false, OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
              ColorModel.getDefaultTransferType(bits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        setRGBs(size, r, g, b, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   183
     * Constructs an {@code IndexColorModel} from the given arrays
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * of red, green, and blue components.  Pixels described by this color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * model all have alpha components of 255 unnormalized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * (1.0&nbsp;normalized), which means they are fully opaque, except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * for the indicated pixel to be made transparent.  All of the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * specifying the color components must have at least the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * number of entries.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   190
     * The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   191
     * The transparency value may be {@code Transparency.OPAQUE} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   192
     * {@code Transparency.BITMASK} depending on the arguments, as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * specified in the <a href="#transparency">class description</a> above.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   194
     * The transfer type is the smallest of {@code DataBuffer.TYPE_BYTE}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   195
     * or {@code DataBuffer.TYPE_USHORT} that can hold a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * single pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param r         the array of red color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param g         the array of green color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param b         the array of blue color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param trans     the index of the transparent pixel
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   203
     * @throws IllegalArgumentException if {@code bits} is less than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   205
     * @throws IllegalArgumentException if {@code size} is less than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *          1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public IndexColorModel(int bits, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                           byte r[], byte g[], byte b[], int trans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        super(bits, opaqueBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
              ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
              false, false, OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
              ColorModel.getDefaultTransferType(bits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        setRGBs(size, r, g, b, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        setTransparentPixel(trans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   224
     * Constructs an {@code IndexColorModel} from the given
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * arrays of red, green, blue and alpha components.  All of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * arrays specifying the components must have at least the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * number of entries.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   228
     * The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   229
     * The transparency value may be any of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   230
     * {@code Transparency.BITMASK},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   231
     * or {@code Transparency.TRANSLUCENT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * depending on the arguments, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * in the <a href="#transparency">class description</a> above.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   234
     * The transfer type is the smallest of {@code DataBuffer.TYPE_BYTE}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   235
     * or {@code DataBuffer.TYPE_USHORT} that can hold a single pixel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param r         the array of red color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param g         the array of green color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param b         the array of blue color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param a         the array of alpha value components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   242
     * @throws IllegalArgumentException if {@code bits} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *           than 1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   244
     * @throws IllegalArgumentException if {@code size} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *           than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public IndexColorModel(int bits, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                           byte r[], byte g[], byte b[], byte a[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        super (bits, alphaBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
               ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
               true, false, TRANSLUCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
               ColorModel.getDefaultTransferType(bits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        setRGBs (size, r, g, b, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   262
     * Constructs an {@code IndexColorModel} from a single
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * array of interleaved red, green, blue and optional alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * components.  The array must have enough values in it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * fill all of the needed component arrays of the specified
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   266
     * size.  The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   267
     * The transparency value may be any of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   268
     * {@code Transparency.BITMASK},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   269
     * or {@code Transparency.TRANSLUCENT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * depending on the arguments, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * in the <a href="#transparency">class description</a> above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * The transfer type is the smallest of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   273
     * {@code DataBuffer.TYPE_BYTE} or {@code DataBuffer.TYPE_USHORT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * that can hold a single pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param cmap      the array of color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param start     the starting offset of the first color component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param hasalpha  indicates whether alpha values are contained in
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   281
     *                  the {@code cmap} array
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   282
     * @throws IllegalArgumentException if {@code bits} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *           than 1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   284
     * @throws IllegalArgumentException if {@code size} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *           than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public IndexColorModel(int bits, int size, byte cmap[], int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                           boolean hasalpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        this(bits, size, cmap, start, hasalpha, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   297
     * Constructs an {@code IndexColorModel} from a single array of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * interleaved red, green, blue and optional alpha components.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * specified transparent index represents a pixel that is made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * entirely transparent regardless of any alpha value specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * for it.  The array must have enough values in it to fill all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * of the needed component arrays of the specified size.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   303
     * The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   304
     * The transparency value may be any of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   305
     * {@code Transparency.BITMASK},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   306
     * or {@code Transparency.TRANSLUCENT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * depending on the arguments, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * in the <a href="#transparency">class description</a> above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * The transfer type is the smallest of
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   310
     * {@code DataBuffer.TYPE_BYTE} or {@code DataBuffer.TYPE_USHORT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * that can hold a single pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param cmap      the array of color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param start     the starting offset of the first color component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param hasalpha  indicates whether alpha values are contained in
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   317
     *                  the {@code cmap} array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param trans     the index of the fully transparent pixel
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   319
     * @throws IllegalArgumentException if {@code bits} is less than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *               1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   321
     * @throws IllegalArgumentException if {@code size} is less than
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *               1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public IndexColorModel(int bits, int size, byte cmap[], int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                           boolean hasalpha, int trans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // REMIND: This assumes the ordering: RGB[A]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        super(bits, opaqueBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
              ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
              false, false, OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
              ColorModel.getDefaultTransferType(bits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            throw new IllegalArgumentException("Map size ("+size+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                               ") must be >= 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        map_size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        rgb = new int[calcRealMapSize(bits, size)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        int j = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        int alpha = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        boolean allgray = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        int transparency = OPAQUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            int r = cmap[j++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            int g = cmap[j++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            int b = cmap[j++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            allgray = allgray && (r == g) && (g == b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            if (hasalpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                alpha = cmap[j++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                if (alpha != 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    if (alpha == 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        if (transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                            transparency = BITMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        if (transparent_index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            transparent_index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        transparency = TRANSLUCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    allgray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            rgb[i] = (alpha << 24) | (r << 16) | (g << 8) | b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        this.allgrayopaque = allgray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        setTransparency(transparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        setTransparentPixel(trans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   376
     * Constructs an {@code IndexColorModel} from an array of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * ints where each int is comprised of red, green, blue, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * optional alpha components in the default RGB color model format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * The specified transparent index represents a pixel that is made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * entirely transparent regardless of any alpha value specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * for it.  The array must have enough values in it to fill all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * of the needed component arrays of the specified size.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   383
     * The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   384
     * The transparency value may be any of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   385
     * {@code Transparency.BITMASK},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   386
     * or {@code Transparency.TRANSLUCENT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * depending on the arguments, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * in the <a href="#transparency">class description</a> above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @param bits      the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param size      the size of the color component arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param cmap      the array of color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param start     the starting offset of the first color component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param hasalpha  indicates whether alpha values are contained in
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   394
     *                  the {@code cmap} array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param trans     the index of the fully transparent pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param transferType the data type of the array used to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *           pixel values.  The data type must be either
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   398
     *           {@code DataBuffer.TYPE_BYTE} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   399
     *           {@code DataBuffer.TYPE_USHORT}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   400
     * @throws IllegalArgumentException if {@code bits} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *           than 1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   402
     * @throws IllegalArgumentException if {@code size} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *           than 1
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   404
     * @throws IllegalArgumentException if {@code transferType} is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   405
     *           one of {@code DataBuffer.TYPE_BYTE} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   406
     *           {@code DataBuffer.TYPE_USHORT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public IndexColorModel(int bits, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                           int cmap[], int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                           boolean hasalpha, int trans, int transferType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // REMIND: This assumes the ordering: RGB[A]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        super(bits, opaqueBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
              ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
              false, false, OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
              transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            throw new IllegalArgumentException("Map size ("+size+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                               ") must be >= 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if ((transferType != DataBuffer.TYPE_BYTE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            (transferType != DataBuffer.TYPE_USHORT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            throw new IllegalArgumentException("transferType must be either" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                "DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        setRGBs(size, cmap, start, hasalpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        setTransparentPixel(trans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   437
     * Constructs an {@code IndexColorModel} from an
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   438
     * {@code int} array where each {@code int} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * comprised of red, green, blue, and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * components in the default RGB color model format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * The array must have enough values in it to fill all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * of the needed component arrays of the specified size.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   443
     * The {@code ColorSpace} is the default sRGB space.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   444
     * The transparency value may be any of {@code Transparency.OPAQUE},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   445
     * {@code Transparency.BITMASK},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   446
     * or {@code Transparency.TRANSLUCENT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * depending on the arguments, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * in the <a href="#transparency">class description</a> above.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   449
     * The transfer type must be one of {@code DataBuffer.TYPE_BYTE}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   450
     * {@code DataBuffer.TYPE_USHORT}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   451
     * The {@code BigInteger} object specifies the valid/invalid pixels
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   452
     * in the {@code cmap} array.  A pixel is valid if the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   453
     * {@code BigInteger} value at that index is set, and is invalid
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   454
     * if the {@code BigInteger} bit  at that index is not set.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @param bits the number of bits each pixel occupies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param size the size of the color component array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param cmap the array of color components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param start the starting offset of the first color component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param transferType the specified data type
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   460
     * @param validBits a {@code BigInteger} object.  If a bit is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *    set in the BigInteger, the pixel at that index is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *    If a bit is not set, the pixel at that index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *    is considered invalid.  If null, all pixels are valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *    Only bits from 0 to the map size are considered.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   465
     * @throws IllegalArgumentException if {@code bits} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *           than 1 or greater than 16
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   467
     * @throws IllegalArgumentException if {@code size} is less
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *           than 1
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   469
     * @throws IllegalArgumentException if {@code transferType} is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   470
     *           one of {@code DataBuffer.TYPE_BYTE} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   471
     *           {@code DataBuffer.TYPE_USHORT}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public IndexColorModel(int bits, int size, int cmap[], int start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                           int transferType, BigInteger validBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        super (bits, alphaBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
               ColorSpace.getInstance(ColorSpace.CS_sRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
               true, false, TRANSLUCENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
               transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (bits < 1 || bits > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            throw new IllegalArgumentException("Number of bits must be between"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                               +" 1 and 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            throw new IllegalArgumentException("Map size ("+size+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                               ") must be >= 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if ((transferType != DataBuffer.TYPE_BYTE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            (transferType != DataBuffer.TYPE_USHORT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            throw new IllegalArgumentException("transferType must be either" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                "DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (validBits != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            // Check to see if it is all valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            for (int i=0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                if (!validBits.testBit(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    this.validBits = validBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        setRGBs(size, cmap, start, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        calculatePixelMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    private void setRGBs(int size, byte r[], byte g[], byte b[], byte a[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (size < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            throw new IllegalArgumentException("Map size ("+size+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                               ") must be >= 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        map_size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        rgb = new int[calcRealMapSize(pixel_bits, size)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        int alpha = 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int transparency = OPAQUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        boolean allgray = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            int rc = r[i] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            int gc = g[i] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            int bc = b[i] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            allgray = allgray && (rc == gc) && (gc == bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                alpha = a[i] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                if (alpha != 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    if (alpha == 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        if (transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                            transparency = BITMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                        if (transparent_index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                            transparent_index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        transparency = TRANSLUCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    allgray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            rgb[i] = (alpha << 24) | (rc << 16) | (gc << 8) | bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        this.allgrayopaque = allgray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        setTransparency(transparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private void setRGBs(int size, int cmap[], int start, boolean hasalpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        map_size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        rgb = new int[calcRealMapSize(pixel_bits, size)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        int j = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        int transparency = OPAQUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        boolean allgray = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        BigInteger validBits = this.validBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        for (int i = 0; i < size; i++, j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (validBits != null && !validBits.testBit(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            int cmaprgb = cmap[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            int r = (cmaprgb >> 16) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            int g = (cmaprgb >>  8) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            int b = (cmaprgb      ) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            allgray = allgray && (r == g) && (g == b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if (hasalpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                int alpha = cmaprgb >>> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if (alpha != 0xff) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    if (alpha == 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                        if (transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            transparency = BITMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                        if (transparent_index < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                            transparent_index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        transparency = TRANSLUCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    allgray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                cmaprgb |= 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            rgb[i] = cmaprgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        this.allgrayopaque = allgray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        setTransparency(transparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    private int calcRealMapSize(int bits, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        int newSize = Math.max(1 << bits, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        return Math.max(newSize, 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private BigInteger getAllValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int numbytes = (map_size+7)/8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        byte[] valid = new byte[numbytes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        java.util.Arrays.fill(valid, (byte)0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        valid[0] = (byte)(0xff >>> (numbytes*8 - map_size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return new BigInteger(1, valid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Returns the transparency.  Returns either OPAQUE, BITMASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * or TRANSLUCENT
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   604
     * @return the transparency of this {@code IndexColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see Transparency#OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @see Transparency#BITMASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @see Transparency#TRANSLUCENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    public int getTransparency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Returns an array of the number of bits for each color/alpha component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * The array contains the color components in the order red, green,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * blue, followed by the alpha component, if present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @return an array containing the number of bits of each color
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   618
     *         and alpha component of this {@code IndexColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public int[] getComponentSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if (nBits == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            if (supportsAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                nBits = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                nBits[3] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                nBits = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            nBits[0] = nBits[1] = nBits[2] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
7747
44fa19e4dc49 7006948: FindBugs warning in IndexColorModel class
bae
parents: 6861
diff changeset
   631
        return nBits.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Returns the size of the color/alpha component arrays in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   636
     * {@code IndexColorModel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @return the size of the color and alpha component arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   639
    public final int getMapSize() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return map_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Returns the index of a transparent pixel in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   645
     * {@code IndexColorModel} or -1 if there is no pixel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * with an alpha value of 0.  If a transparent pixel was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * explicitly specified in one of the constructors by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * index, then that index will be preferred, otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * the index of any pixel which happens to be fully transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * may be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return the index of a transparent pixel in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   652
     *         {@code IndexColorModel} object, or -1 if there
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *         is no such pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   655
    public final int getTransparentPixel() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return transparent_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Copies the array of red color components into the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Only the initial entries of the array as specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * {@link #getMapSize() getMapSize} are written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @param r the specified array into which the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *      array of red color components are copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   666
    public final void getReds(byte r[]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        for (int i = 0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            r[i] = (byte) (rgb[i] >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Copies the array of green color components into the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Only the initial entries of the array as specified by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   675
     * {@code getMapSize} are written.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param g the specified array into which the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *      array of green color components are copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   679
    public final void getGreens(byte g[]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        for (int i = 0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            g[i] = (byte) (rgb[i] >> 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * Copies the array of blue color components into the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Only the initial entries of the array as specified by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   688
     * {@code getMapSize} are written.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @param b the specified array into which the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *      array of blue color components are copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   692
    public final void getBlues(byte b[]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        for (int i = 0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            b[i] = (byte) rgb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Copies the array of alpha transparency components into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * specified array.  Only the initial entries of the array as specified
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   701
     * by {@code getMapSize} are written.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @param a the specified array into which the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *      array of alpha components are copied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   705
    public final void getAlphas(byte a[]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        for (int i = 0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            a[i] = (byte) (rgb[i] >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * Converts data for each index from the color and alpha component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * arrays to an int in the default RGB ColorModel format and copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * the resulting 32-bit ARGB values into the specified array.  Only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * the initial entries of the array as specified by
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   716
     * {@code getMapSize} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @param rgb the specified array into which the converted ARGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *        values from this array of color and alpha components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *        are copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   722
    public final void getRGBs(int rgb[]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        System.arraycopy(this.rgb, 0, rgb, 0, map_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    private void setTransparentPixel(int trans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (trans >= 0 && trans < map_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            rgb[trans] &= 0x00ffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            transparent_index = trans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            allgrayopaque = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (this.transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                setTransparency(BITMASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    private void setTransparency(int transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        if (this.transparency != transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            this.transparency = transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if (transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                supportsAlpha = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                numComponents = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                nBits = opaqueBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                supportsAlpha = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                numComponents = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                nBits = alphaBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * This method is called from the constructors to set the pixel_mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * value, which is based on the value of pixel_bits.  The pixel_mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * value is used to mask off the pixel parameters for methods such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * as getRed(), getGreen(), getBlue(), getAlpha(), and getRGB().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   758
    private void calculatePixelMask() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        // Note that we adjust the mask so that our masking behavior here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        // is consistent with that of our native rendering loops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        int maskbits = pixel_bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        if (maskbits == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            maskbits = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        } else if (maskbits > 4 && maskbits < 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            maskbits = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        pixel_mask = (1 << maskbits) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Returns the red color component for the specified pixel, scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * from 0 to 255 in the default RGB ColorSpace, sRGB.  The pixel value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * is specified as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Only the lower <em>n</em> bits of the pixel value, as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * calculate the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * The returned value is a non pre-multiplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @return the value of the red color component for the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   781
    public final int getRed(int pixel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return (rgb[pixel & pixel_mask] >> 16) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Returns the green color component for the specified pixel, scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * from 0 to 255 in the default RGB ColorSpace, sRGB.  The pixel value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * is specified as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Only the lower <em>n</em> bits of the pixel value, as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * calculate the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * The returned value is a non pre-multiplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @return the value of the green color component for the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   796
    public final int getGreen(int pixel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return (rgb[pixel & pixel_mask] >> 8) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Returns the blue color component for the specified pixel, scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * from 0 to 255 in the default RGB ColorSpace, sRGB.  The pixel value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * is specified as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Only the lower <em>n</em> bits of the pixel value, as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * calculate the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * The returned value is a non pre-multiplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @return the value of the blue color component for the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   811
    public final int getBlue(int pixel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return rgb[pixel & pixel_mask] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Returns the alpha component for the specified pixel, scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * from 0 to 255.  The pixel value is specified as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * Only the lower <em>n</em> bits of the pixel value, as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * calculate the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @return the value of the alpha component for the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   824
    public final int getAlpha(int pixel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        return (rgb[pixel & pixel_mask] >> 24) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Returns the color/alpha components of the pixel in the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * RGB color model format.  The pixel value is specified as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Only the lower <em>n</em> bits of the pixel value, as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * calculate the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * The returned value is in a non pre-multiplied format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @return the color and alpha components of the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @see ColorModel#getRGBdefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   839
    public final int getRGB(int pixel) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        return rgb[pixel & pixel_mask];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    private static final int CACHESIZE = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    private int lookupcache[] = new int[CACHESIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * Returns a data element array representation of a pixel in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * ColorModel, given an integer pixel representation in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * default RGB color model.  This array can then be passed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * {@link WritableRaster#setDataElements(int, int, java.lang.Object) setDataElements}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * method of a {@link WritableRaster} object.  If the pixel variable is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   852
     * {@code null}, a new array is allocated.  If {@code pixel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   853
     * is not {@code null}, it must be
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   854
     * a primitive array of type {@code transferType}; otherwise, a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   855
     * {@code ClassCastException} is thrown.  An
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   856
     * {@code ArrayIndexOutOfBoundsException} is
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   857
     * thrown if {@code pixel} is not large enough to hold a pixel
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   858
     * value for this {@code ColorModel}.  The pixel array is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   860
     * Since {@code IndexColorModel} can be subclassed, subclasses
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * inherit the implementation of this method and if they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * override it then they throw an exception if they use an
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   863
     * unsupported {@code transferType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @param rgb the integer pixel representation in the default RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * color model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @return an array representation of the specified pixel in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   869
     *  {@code IndexColorModel}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   870
     * @throws ClassCastException if {@code pixel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   871
     *  is not a primitive array of type {@code transferType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @throws ArrayIndexOutOfBoundsException if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   873
     *  {@code pixel} is not large enough to hold a pixel value
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   874
     *  for this {@code ColorModel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
   875
     * @throws UnsupportedOperationException if {@code transferType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *         is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @see WritableRaster#setDataElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @see SampleModel#setDataElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    public synchronized Object getDataElements(int rgb, Object pixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        int red = (rgb>>16) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        int green = (rgb>>8) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        int blue  = rgb & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        int alpha = (rgb>>>24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        int pix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        // Note that pixels are stored at lookupcache[2*i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        // and the rgb that was searched is stored at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        // lookupcache[2*i+1].  Also, the pixel is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        // inverted using the unary complement operator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // before storing in the cache so it can never be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        for (int i = CACHESIZE - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if ((pix = lookupcache[i]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            if (rgb == lookupcache[i+1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                return installpixel(pixel, ~pix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        if (allgrayopaque) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            // IndexColorModel objects are all tagged as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            // non-premultiplied so ignore the alpha value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            // of the incoming color, convert the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            // non-premultiplied color components to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            // grayscale value and search for the closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            // gray value in the palette.  Since all colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            // in the palette are gray, we only need compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            // to one of the color components for a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            // using a simple linear distance formula.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            int minDist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            int d;
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   914
            int gray = (red*77 + green*150 + blue*29 + 128)/256;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            for (int i = 0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                if (this.rgb[i] == 0x0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    // For allgrayopaque colormaps, entries are 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    // iff they are an invalid color and should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    // ignored during color searches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                d = (this.rgb[i] & 0xff) - gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                if (d < 0) d = -d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                if (d < minDist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                    pix = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    if (d == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                    minDist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        } else if (transparency == OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            // IndexColorModel objects are all tagged as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            // non-premultiplied so ignore the alpha value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            // of the incoming color and search for closest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            // color match independently using a 3 component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            // Euclidean distance formula.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            // For opaque colormaps, palette entries are 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            // iff they are an invalid color and should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            // ignored during color searches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            // As an optimization, exact color searches are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            // likely to be fairly common in opaque colormaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            // so first we will do a quick search for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            // exact match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            int smallestError = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            int lut[] = this.rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            int lutrgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            for (int i=0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                lutrgb = lut[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                if (lutrgb == rgb && lutrgb != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    pix = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    smallestError = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            if (smallestError != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                for (int i=0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    lutrgb = lut[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                    if (lutrgb == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    int tmp = ((lutrgb >> 16) & 0xff) - red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    int currentError = tmp*tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                        tmp = ((lutrgb >> 8) & 0xff) - green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        currentError += tmp * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                        if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                            tmp = (lutrgb & 0xff) - blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                            currentError += tmp * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                            if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                pix = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                smallestError = currentError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        } else if (alpha == 0 && transparent_index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            // Special case - transparent color maps to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            // specified transparent pixel, if there is one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            pix = transparent_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            // IndexColorModel objects are all tagged as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            // non-premultiplied so use non-premultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            // color components in the distance calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            // Look for closest match using a 4 component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            // Euclidean distance formula.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            int smallestError = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            int lut[] = this.rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            for (int i=0; i < map_size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                int lutrgb = lut[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                if (lutrgb == rgb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                    if (validBits != null && !validBits.testBit(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    pix = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                int tmp = ((lutrgb >> 16) & 0xff) - red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                int currentError = tmp*tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    tmp = ((lutrgb >> 8) & 0xff) - green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    currentError += tmp * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        tmp = (lutrgb & 0xff) - blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                        currentError += tmp * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        if (currentError < smallestError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                            tmp = (lutrgb >>> 24) - alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                            currentError += tmp * tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                            if (currentError < smallestError &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                (validBits == null || validBits.testBit(i)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                pix = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                                smallestError = currentError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        System.arraycopy(lookupcache, 2, lookupcache, 0, CACHESIZE - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        lookupcache[CACHESIZE - 1] = rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        lookupcache[CACHESIZE - 2] = ~pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        return installpixel(pixel, pix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    private Object installpixel(Object pixel, int pix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        switch (transferType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            int[] intObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            if (pixel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                pixel = intObj = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                intObj = (int[]) pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            intObj[0] = pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            byte[] byteObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            if (pixel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                pixel = byteObj = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                byteObj = (byte[]) pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            byteObj[0] = (byte) pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            short[] shortObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            if (pixel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                pixel = shortObj = new short[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                shortObj = (short[]) pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            shortObj[0] = (short) pix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            throw new UnsupportedOperationException("This method has not been "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                             "implemented for transferType " + transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        return pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * Returns an array of unnormalized color/alpha components for a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1072
     * specified pixel in this {@code ColorModel}.  The pixel value
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1073
     * is specified as an int.  If the {@code components} array is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * a new array is allocated that contains
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1075
     * {@code offset + getNumComponents()} elements.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1076
     * The {@code components} array is returned,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * with the alpha component included
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1078
     * only if {@code hasAlpha} returns true.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1079
     * Color/alpha components are stored in the {@code components} array starting
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1080
     * at {@code offset} even if the array is allocated by this method.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1081
     * An {@code ArrayIndexOutOfBoundsException}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1082
     * is thrown if  the {@code components} array is not {@code null} and is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * not large enough to hold all the color and alpha components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1084
     * starting at {@code offset}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @param components the array to receive the color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * components of the specified pixel
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1088
     * @param offset the offset into the {@code components} array at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * which to start storing the color and alpha components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @return an array containing the color and alpha components of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * specified pixel starting at the specified offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @see ColorModel#hasAlpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * @see ColorModel#getNumComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    public int[] getComponents(int pixel, int[] components, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        if (components == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            components = new int[offset+numComponents];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        // REMIND: Needs to change if different color space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        components[offset+0] = getRed(pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        components[offset+1] = getGreen(pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        components[offset+2] = getBlue(pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        if (supportsAlpha && (components.length-offset) > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            components[offset+3] = getAlpha(pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        return components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * Returns an array of unnormalized color/alpha components for
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1113
     * a specified pixel in this {@code ColorModel}.  The pixel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * value is specified by an array of data elements of type
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1115
     * {@code transferType} passed in as an object reference.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1116
     * If {@code pixel} is not a primitive array of type
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1117
     * {@code transferType}, a {@code ClassCastException}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1118
     * is thrown.  An {@code ArrayIndexOutOfBoundsException}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1119
     * is thrown if {@code pixel} is not large enough to hold
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1120
     * a pixel value for this {@code ColorModel}.  If the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1121
     * {@code components} array is {@code null}, a new array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * is allocated that contains
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1123
     * {@code offset + getNumComponents()} elements.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1124
     * The {@code components} array is returned,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * with the alpha component included
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1126
     * only if {@code hasAlpha} returns true.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1127
     * Color/alpha components are stored in the {@code components}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1128
     * array starting at {@code offset} even if the array is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * allocated by this method.  An
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1130
     * {@code ArrayIndexOutOfBoundsException} is also
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1131
     * thrown if  the {@code components} array is not
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1132
     * {@code null} and is not large enough to hold all the color
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1133
     * and alpha components starting at {@code offset}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1135
     * Since {@code IndexColorModel} can be subclassed, subclasses
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * inherit the implementation of this method and if they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * override it then they throw an exception if they use an
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1138
     * unsupported {@code transferType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @param pixel the specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @param components an array that receives the color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * components of the specified pixel
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1143
     * @param offset the index into the {@code components} array at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * which to begin storing the color and alpha components of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * specified pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @return an array containing the color and alpha components of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * specified pixel starting at the specified offset.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1148
     * @throws ArrayIndexOutOfBoundsException if {@code pixel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *            is not large enough to hold a pixel value for this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1150
     *            {@code ColorModel} or if the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1151
     *            {@code components} array is not {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *            and is not large enough to hold all the color
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1153
     *            and alpha components starting at {@code offset}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1154
     * @throws ClassCastException if {@code pixel} is not a
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1155
     *            primitive array of type {@code transferType}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1156
     * @throws UnsupportedOperationException if {@code transferType}
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19169
diff changeset
  1157
     *         is not one of the supported transfer types
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @see ColorModel#hasAlpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * @see ColorModel#getNumComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public int[] getComponents(Object pixel, int[] components, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        int intpixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        switch (transferType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
               byte bdata[] = (byte[])pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
               intpixel = bdata[0] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
               short sdata[] = (short[])pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
               intpixel = sdata[0] & 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
               int idata[] = (int[])pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
               intpixel = idata[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
               throw new UnsupportedOperationException("This method has not been "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                   "implemented for transferType " + transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        return getComponents(intpixel, components, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * Returns a pixel value represented as an int in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1185
     * {@code ColorModel} given an array of unnormalized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * color/alpha components.  An
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1187
     * {@code ArrayIndexOutOfBoundsException}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1188
     * is thrown if the {@code components} array is not large
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * enough to hold all of the color and alpha components starting
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1190
     * at {@code offset}.  Since
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1191
     * {@code ColorModel} can be subclassed, subclasses inherit the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * implementation of this method and if they don't override it then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * they throw an exception if they use an unsupported transferType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @param components an array of unnormalized color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1196
     * @param offset the index into {@code components} at which to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * begin retrieving the color and alpha components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1198
     * @return an {@code int} pixel value in this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1199
     * {@code ColorModel} corresponding to the specified components.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * @throws ArrayIndexOutOfBoundsException if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1201
     *  the {@code components} array is not large enough to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *  hold all of the color and alpha components starting at
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1203
     *  {@code offset}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1204
     * @throws UnsupportedOperationException if {@code transferType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *         is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    public int getDataElement(int[] components, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        int rgb = (components[offset+0]<<16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            | (components[offset+1]<<8) | (components[offset+2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        if (supportsAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            rgb |= (components[offset+3]<<24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            rgb |= 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        Object inData = getDataElements(rgb, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        int pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        switch (transferType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
               byte bdata[] = (byte[])inData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
               pixel = bdata[0] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
               short sdata[] = (short[])inData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
               pixel = sdata[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
               int idata[] = (int[])inData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
               pixel = idata[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
               throw new UnsupportedOperationException("This method has not been "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                   "implemented for transferType " + transferType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        return pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Returns a data element array representation of a pixel in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1240
     * {@code ColorModel} given an array of unnormalized color/alpha
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * components.  This array can then be passed to the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1242
     * {@code setDataElements} method of a {@code WritableRaster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1243
     * object.  An {@code ArrayIndexOutOfBoundsException} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * thrown if the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1245
     * {@code components} array is not large enough to hold all of the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1246
     * color and alpha components starting at {@code offset}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1247
     * If the pixel variable is {@code null}, a new array
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1248
     * is allocated.  If {@code pixel} is not {@code null},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1249
     * it must be a primitive array of type {@code transferType};
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1250
     * otherwise, a {@code ClassCastException} is thrown.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1251
     * An {@code ArrayIndexOutOfBoundsException} is thrown if pixel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * is not large enough to hold a pixel value for this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1253
     * {@code ColorModel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1255
     * Since {@code IndexColorModel} can be subclassed, subclasses
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * inherit the implementation of this method and if they don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * override it then they throw an exception if they use an
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1258
     * unsupported {@code transferType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * @param components an array of unnormalized color and alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1262
     * @param offset the index into {@code components} at which to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * begin retrieving color and alpha components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1264
     * @param pixel the {@code Object} representing an array of color
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * and alpha components
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1266
     * @return an {@code Object} representing an array of color and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * alpha components.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1268
     * @throws ClassCastException if {@code pixel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1269
     *  is not a primitive array of type {@code transferType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @throws ArrayIndexOutOfBoundsException if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1271
     *  {@code pixel} is not large enough to hold a pixel value
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1272
     *  for this {@code ColorModel} or the {@code components}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     *  array is not large enough to hold all of the color and alpha
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1274
     *  components starting at {@code offset}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1275
     * @throws UnsupportedOperationException if {@code transferType}
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19169
diff changeset
  1276
     *         is not one of the supported transfer types
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @see WritableRaster#setDataElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * @see SampleModel#setDataElements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    public Object getDataElements(int[] components, int offset, Object pixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        int rgb = (components[offset+0]<<16) | (components[offset+1]<<8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            | (components[offset+2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        if (supportsAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            rgb |= (components[offset+3]<<24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            rgb &= 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        return getDataElements(rgb, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1293
     * Creates a {@code WritableRaster} with the specified width
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1294
     * and height that has a data layout ({@code SampleModel})
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1295
     * compatible with this {@code ColorModel}.  This method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * only works for color models with 16 or fewer bits per pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1298
     * Since {@code IndexColorModel} can be subclassed, any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * subclass that supports greater than 16 bits per pixel must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * override this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1302
     * @param w the width to apply to the new {@code WritableRaster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1303
     * @param h the height to apply to the new {@code WritableRaster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1304
     * @return a {@code WritableRaster} object with the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @throws UnsupportedOperationException if the number of bits in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     *         pixel is greater than 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * @see WritableRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * @see SampleModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    public WritableRaster createCompatibleWritableRaster(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        WritableRaster raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        if (pixel_bits == 1 || pixel_bits == 2 || pixel_bits == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            // TYPE_BINARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                                               w, h, 1, pixel_bits, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        else if (pixel_bits <= 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                                                  w,h,1,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        else if (pixel_bits <= 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                                                  w,h,1,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                UnsupportedOperationException("This method is not supported "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                              " for pixel bits > 16.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        return raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1336
      * Returns {@code true} if {@code raster} is compatible
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1337
      * with this {@code ColorModel} or {@code false} if it
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1338
      * is not compatible with this {@code ColorModel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
      * @param raster the {@link Raster} object to test for compatibility
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1340
      * @return {@code true} if {@code raster} is compatible
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1341
      * with this {@code ColorModel}; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    public boolean isCompatibleRaster(Raster raster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        int size = raster.getSampleModel().getSampleSize(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        return ((raster.getTransferType() == transferType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                (raster.getNumBands() == 1) && ((1 << size) >= map_size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1352
     * Creates a {@code SampleModel} with the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * width and height that has a data layout compatible with
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1354
     * this {@code ColorModel}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1355
     * @param w the width to apply to the new {@code SampleModel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1356
     * @param h the height to apply to the new {@code SampleModel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1357
     * @return a {@code SampleModel} object with the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * width and height.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1359
     * @throws IllegalArgumentException if {@code w} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1360
     *         {@code h} is not greater than 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @see SampleModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    public SampleModel createCompatibleSampleModel(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        int[] off = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        off[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (pixel_bits == 1 || pixel_bits == 2 || pixel_bits == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            return new MultiPixelPackedSampleModel(transferType, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                                   pixel_bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            return new ComponentSampleModel(transferType, w, h, 1, w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                                            off);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1377
     * Checks if the specified {@code SampleModel} is compatible
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1378
     * with this {@code ColorModel}.  If {@code sm} is
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1379
     * {@code null}, this method returns {@code false}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1380
     * @param sm the specified {@code SampleModel},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1381
     *           or {@code null}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1382
     * @return {@code true} if the specified {@code SampleModel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1383
     * is compatible with this {@code ColorModel}; {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * @see SampleModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    public boolean isCompatibleSampleModel(SampleModel sm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // fix 4238629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        if (! (sm instanceof ComponentSampleModel) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            ! (sm instanceof MultiPixelPackedSampleModel)   ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        // Transfer type must be the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        if (sm.getTransferType() != transferType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        if (sm.getNumBands() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1407
     * Returns a new {@code BufferedImage} of TYPE_INT_ARGB or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1408
     * TYPE_INT_RGB that has a {@code Raster} with pixel data
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1409
     * computed by expanding the indices in the source {@code Raster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1410
     * using the color/alpha component arrays of this {@code ColorModel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * Only the lower <em>n</em> bits of each index value in the source
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1412
     * {@code Raster}, as specified in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * <a href="#index_values">class description</a> above, are used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * compute the color/alpha values in the returned image.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1415
     * If {@code forceARGB} is {@code true}, a TYPE_INT_ARGB image is
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1416
     * returned regardless of whether or not this {@code ColorModel}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * has an alpha component array or a transparent pixel.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1418
     * @param raster the specified {@code Raster}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1419
     * @param forceARGB if {@code true}, the returned
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1420
     *     {@code BufferedImage} is TYPE_INT_ARGB; otherwise it is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     *     TYPE_INT_RGB
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1422
     * @return a {@code BufferedImage} created with the specified
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1423
     *     {@code Raster}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @throws IllegalArgumentException if the raster argument is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     *           compatible with this IndexColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    public BufferedImage convertToIntDiscrete(Raster raster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                                              boolean forceARGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        ColorModel cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        if (!isCompatibleRaster(raster)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            throw new IllegalArgumentException("This raster is not compatible" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                 "with this IndexColorModel.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        if (forceARGB || transparency == TRANSLUCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            cm = ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        else if (transparency == BITMASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            cm = new DirectColorModel(25, 0xff0000, 0x00ff00, 0x0000ff,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                                      0x1000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            cm = new DirectColorModel(24, 0xff0000, 0x00ff00, 0x0000ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        int w = raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        int h = raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        WritableRaster discreteRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                  cm.createCompatibleWritableRaster(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        Object obj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        int[] data = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        int rX = raster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        int rY = raster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        for (int y=0; y < h; y++, rY++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            obj = raster.getDataElements(rX, rY, w, 1, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            if (obj instanceof int[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                data = (int[])obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                data = DataBuffer.toIntArray(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            for (int x=0; x < w; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                data[x] = rgb[data[x] & pixel_mask];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            discreteRaster.setDataElements(0, y, w, 1, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        return new BufferedImage(cm, discreteRaster, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * Returns whether or not the pixel is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @param pixel the specified pixel value
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1475
     * @return {@code true} if {@code pixel}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1476
     * is valid; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    public boolean isValid(int pixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        return ((pixel >= 0 && pixel < map_size) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                (validBits == null || validBits.testBit(pixel)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * Returns whether or not all of the pixels are valid.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1486
     * @return {@code true} if all pixels are valid;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1487
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    public boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        return (validBits == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1495
     * Returns a {@code BigInteger} that indicates the valid/invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * pixels in the colormap.  A bit is valid if the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1497
     * {@code BigInteger} value at that index is set, and is invalid
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1498
     * if the {@code BigInteger} value at that index is not set.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1499
     * The only valid ranges to query in the {@code BigInteger} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * between 0 and the map size.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1501
     * @return a {@code BigInteger} indicating the valid/invalid pixels.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    public BigInteger getValidPixels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        if (validBits == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            return getAllValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            return validBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * Disposes of system resources associated with this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1515
     * {@code ColorModel} once this {@code ColorModel} is no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * longer referenced.
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1517
     *
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1518
     * @deprecated The {@code finalize} method has been deprecated.
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1519
     *     Subclasses that override {@code finalize} in order to perform cleanup
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1520
     *     should be modified to use alternative cleanup mechanisms and
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1521
     *     to remove the overriding {@code finalize} method.
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1522
     *     When overriding the {@code finalize} method, its implementation must explicitly
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1523
     *     ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1524
     *     See the specification for {@link Object#finalize()} for further
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1525
     *     information about migration options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     */
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1527
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    public void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1532
     * Returns the {@code String} representation of the contents of
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1533
     * this {@code ColorModel} object.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1534
     * @return a {@code String} representing the contents of this
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 32865
diff changeset
  1535
     * {@code ColorModel} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
       return new String("IndexColorModel: #pixelBits = "+pixel_bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                         + " numComponents = "+numComponents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                         + " color space = "+colorSpace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                         + " transparency = "+transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                         + " transIndex   = "+transparent_index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                         + " has alpha = "+supportsAlpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                         + " isAlphaPre = "+isAlphaPremultiplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                         );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    }
43827
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1547
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1548
    /**
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1549
     * Tests if the specified {@code Object} is an
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1550
     * instance of {@code IndexColorModel}
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1551
     * and if it equals this {@code IndexColorModel}
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1552
     * @param obj the {@code Object} to test for equality
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1553
     * @return {@code true} if the specified {@code Object}
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1554
     * equals this {@code IndexColorModel}; {@code false} otherwise.
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1555
     */
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1556
    @Override
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1557
    public boolean equals(Object obj) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1558
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1559
        if (!(obj instanceof IndexColorModel)) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1560
            return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1561
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1562
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1563
        IndexColorModel cm = (IndexColorModel) obj;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1564
        if (supportsAlpha != cm.hasAlpha() ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1565
            isAlphaPremultiplied != cm.isAlphaPremultiplied() ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1566
            pixel_bits != cm.getPixelSize() ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1567
            transparency != cm.getTransparency() ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1568
            numComponents != cm.getNumComponents() ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1569
            (!(colorSpace.equals(cm.colorSpace))) ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1570
            transferType != cm.transferType ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1571
            map_size != cm.map_size ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1572
            transparent_index != cm.transparent_index)
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1573
        {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1574
            return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1575
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1576
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1577
        if (!(Arrays.equals(nBits, cm.getComponentSize()))) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1578
            return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1579
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1580
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1581
        // verify whether we have to check equality of all bits in validBits
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1582
        boolean testValidBits;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1583
        if (validBits == cm.validBits) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1584
            testValidBits = false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1585
        } else if (validBits == null || cm.validBits == null) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1586
            return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1587
        } else if (validBits.equals(cm.validBits)) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1588
            testValidBits = false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1589
        } else {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1590
            testValidBits = true;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1591
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1592
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1593
        if (testValidBits) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1594
            for (int i = 0; i < map_size; i++) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1595
                if (rgb[i] != cm.rgb[i] ||
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1596
                    validBits.testBit(i) != cm.validBits.testBit(i))
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1597
                {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1598
                    return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1599
                }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1600
            }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1601
        } else {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1602
            for (int i = 0; i < map_size; i++) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1603
                if (rgb[i] != cm.rgb[i]) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1604
                    return false;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1605
                }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1606
            }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1607
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1608
        return true;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1609
    }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1610
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1611
    /**
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1612
     * Returns the hash code for IndexColorModel.
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1613
     *
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1614
     * @return    a hash code for IndexColorModel
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1615
     */
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1616
    @Override
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1617
    public int hashCode() {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1618
        int result = hashCode;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1619
        if (result == 0) {
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1620
            /*
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1621
             * We are intentionally not calculating hashCode for validBits,
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1622
             * because it is only used for 8-bit indexed screens and they
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1623
             * are very rare. It is very unlikely for 2 IndexColorModels
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1624
             * to have different valiBits and have same value for all
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1625
             * other properties.
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1626
             */
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1627
            result = 7;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1628
            result = 89 * result + this.pixel_bits;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1629
            result = 89 * result + Arrays.hashCode(this.nBits);
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1630
            result = 89 * result + this.transparency;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1631
            result = 89 * result + (this.supportsAlpha ? 1 : 0);
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1632
            result = 89 * result + (this.isAlphaPremultiplied ? 1 : 0);
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1633
            result = 89 * result + this.numComponents;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1634
            result = 89 * result + this.colorSpace.hashCode();
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1635
            result = 89 * result + this.transferType;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1636
            result = 89 * result + Arrays.hashCode(this.rgb);
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1637
            result = 89 * result + this.map_size;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1638
            result = 89 * result + this.transparent_index;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1639
            hashCode = result;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1640
        }
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1641
        return result;
a02bc4e52007 7107905: ColorModel subclasses are missing hashCode() or equals() or both methods
jdv
parents: 35667
diff changeset
  1642
    }
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 43827
diff changeset
  1643
}