11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.image;
27
28 import java.awt.Transparency;
29 import java.awt.color.ColorSpace;
30 import java.math.BigInteger;
31
32 /**
33 * The {@code IndexColorModel} class is a {@code ColorModel}
34 * class that works with pixel values consisting of a
35 * single sample that is an index into a fixed colormap in the default
36 * sRGB color space. The colormap specifies red, green, blue, and
37 * optional alpha components corresponding to each index. All components
38 * are represented in the colormap as 8-bit unsigned integral values.
39 * Some constructors allow the caller to specify "holes" in the colormap
40 * by indicating which colormap entries are valid and which represent
41 * unusable colors via the bits set in a {@code BigInteger} object.
42 * This color model is similar to an X11 PseudoColor visual.
43 * <p>
44 * Some constructors provide a means to specify an alpha component
45 * for each pixel in the colormap, while others either provide no
46 * such means or, in some cases, a flag to indicate whether the
47 * colormap data contains alpha values. If no alpha is supplied to
48 * the constructor, an opaque alpha component (alpha = 1.0) is
49 * assumed for each entry.
50 * An optional transparent pixel value can be supplied that indicates a
112 * <p>
113 * Many of the methods in this class are final. The reason for
114 * this is that the underlying native graphics code makes assumptions
115 * about the layout and operation of this class and those assumptions
116 * are reflected in the implementations of the methods here that are
117 * marked final. You can subclass this class for other reasons, but
118 * you cannot override or modify the behaviour of those methods.
119 *
120 * @see ColorModel
121 * @see ColorSpace
122 * @see DataBuffer
123 *
124 */
125 public class IndexColorModel extends ColorModel {
126 private int rgb[];
127 private int map_size;
128 private int pixel_mask;
129 private int transparent_index = -1;
130 private boolean allgrayopaque;
131 private BigInteger validBits;
132
133 private sun.awt.image.BufImgSurfaceData.ICMColorData colorData = null;
134
135 private static int[] opaqueBits = {8, 8, 8};
136 private static int[] alphaBits = {8, 8, 8, 8};
137
138 private static native void initIDs();
139 static {
140 ColorModel.loadLibraries();
141 initIDs();
142 }
143 /**
144 * Constructs an {@code IndexColorModel} from the specified
145 * arrays of red, green, and blue components. Pixels described
146 * by this color model all have alpha components of 255
147 * unnormalized (1.0 normalized), which means they
148 * are fully opaque. All of the arrays specifying the color
149 * components must have at least the specified number of entries.
150 * The {@code ColorSpace} is the default sRGB space.
151 * Since there is no alpha information in any of the arguments
1514 * longer referenced.
1515 */
1516 public void finalize() {
1517 }
1518
1519 /**
1520 * Returns the {@code String} representation of the contents of
1521 * this {@code ColorModel} object.
1522 * @return a {@code String} representing the contents of this
1523 * {@code ColorModel} object.
1524 */
1525 public String toString() {
1526 return new String("IndexColorModel: #pixelBits = "+pixel_bits
1527 + " numComponents = "+numComponents
1528 + " color space = "+colorSpace
1529 + " transparency = "+transparency
1530 + " transIndex = "+transparent_index
1531 + " has alpha = "+supportsAlpha
1532 + " isAlphaPre = "+isAlphaPremultiplied
1533 );
1534 }
1535 }
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.image;
27
28 import java.awt.Transparency;
29 import java.awt.color.ColorSpace;
30 import java.math.BigInteger;
31 import java.util.Arrays;
32 import java.util.Objects;
33
34 /**
35 * The {@code IndexColorModel} class is a {@code ColorModel}
36 * class that works with pixel values consisting of a
37 * single sample that is an index into a fixed colormap in the default
38 * sRGB color space. The colormap specifies red, green, blue, and
39 * optional alpha components corresponding to each index. All components
40 * are represented in the colormap as 8-bit unsigned integral values.
41 * Some constructors allow the caller to specify "holes" in the colormap
42 * by indicating which colormap entries are valid and which represent
43 * unusable colors via the bits set in a {@code BigInteger} object.
44 * This color model is similar to an X11 PseudoColor visual.
45 * <p>
46 * Some constructors provide a means to specify an alpha component
47 * for each pixel in the colormap, while others either provide no
48 * such means or, in some cases, a flag to indicate whether the
49 * colormap data contains alpha values. If no alpha is supplied to
50 * the constructor, an opaque alpha component (alpha = 1.0) is
51 * assumed for each entry.
52 * An optional transparent pixel value can be supplied that indicates a
114 * <p>
115 * Many of the methods in this class are final. The reason for
116 * this is that the underlying native graphics code makes assumptions
117 * about the layout and operation of this class and those assumptions
118 * are reflected in the implementations of the methods here that are
119 * marked final. You can subclass this class for other reasons, but
120 * you cannot override or modify the behaviour of those methods.
121 *
122 * @see ColorModel
123 * @see ColorSpace
124 * @see DataBuffer
125 *
126 */
127 public class IndexColorModel extends ColorModel {
128 private int rgb[];
129 private int map_size;
130 private int pixel_mask;
131 private int transparent_index = -1;
132 private boolean allgrayopaque;
133 private BigInteger validBits;
134 private volatile int hashCode;
135
136 private sun.awt.image.BufImgSurfaceData.ICMColorData colorData = null;
137
138 private static int[] opaqueBits = {8, 8, 8};
139 private static int[] alphaBits = {8, 8, 8, 8};
140
141 private static native void initIDs();
142 static {
143 ColorModel.loadLibraries();
144 initIDs();
145 }
146 /**
147 * Constructs an {@code IndexColorModel} from the specified
148 * arrays of red, green, and blue components. Pixels described
149 * by this color model all have alpha components of 255
150 * unnormalized (1.0 normalized), which means they
151 * are fully opaque. All of the arrays specifying the color
152 * components must have at least the specified number of entries.
153 * The {@code ColorSpace} is the default sRGB space.
154 * Since there is no alpha information in any of the arguments
1517 * longer referenced.
1518 */
1519 public void finalize() {
1520 }
1521
1522 /**
1523 * Returns the {@code String} representation of the contents of
1524 * this {@code ColorModel} object.
1525 * @return a {@code String} representing the contents of this
1526 * {@code ColorModel} object.
1527 */
1528 public String toString() {
1529 return new String("IndexColorModel: #pixelBits = "+pixel_bits
1530 + " numComponents = "+numComponents
1531 + " color space = "+colorSpace
1532 + " transparency = "+transparency
1533 + " transIndex = "+transparent_index
1534 + " has alpha = "+supportsAlpha
1535 + " isAlphaPre = "+isAlphaPremultiplied
1536 );
1537 }
1538
1539 /**
1540 * Tests if the specified {@code Object} equals this
1541 * {@code IndexColorModel}.
1542 * In order to protect the symmetry property of
1543 * {@code (a.equals(b) == b.equals(a))},
1544 * the target object must be the same class (and not a subclass)
1545 * as this object to evaluate as {@code equals}.
1546 * <p>
1547 * The target object and this object will be equal if and only if
1548 * {@link ColorModel#equals()} returns true and the following
1549 * properties are also the same:
1550 *
1551 * <ul>
1552 * <li>ColorMap size.
1553 * <li>Index of a transparent pixel in {@code IndexColorModel}
1554 * <li>ColorMap values.
1555 * <li>The list of valid pixel indices in ColorMap.
1556 * </ul>
1557 * <p>
1558 * @param obj the {@code Object} to test for equality
1559 * @return {@code true} if the specified {@code Object}
1560 * equals this {@code IndexColorModel}; {@code false} otherwise.
1561 */
1562 @Override
1563 public boolean equals(Object obj) {
1564 /*
1565 * We verify the type of argument obj in super.equals() where we check
1566 * for equality of class name.
1567 */
1568 if (!super.equals(obj)) {
1569 return false;
1570 }
1571
1572 IndexColorModel cm = (IndexColorModel) obj;
1573 if (map_size != cm.map_size ||
1574 transparent_index != cm.transparent_index)
1575 {
1576 return false;
1577 }
1578
1579 // verify whether we have to check equality of all bits in validBits
1580 boolean testValidBits;
1581 if (validBits == cm.validBits) {
1582 testValidBits = false;
1583 } else if (validBits == null || cm.validBits == null) {
1584 return false;
1585 } else if (validBits.equals(cm.validBits)) {
1586 testValidBits = false;
1587 } else {
1588 testValidBits = true;
1589 }
1590
1591 if (testValidBits) {
1592 for (int i = 0; i < map_size; i++) {
1593 if (rgb[i] != cm.rgb[i] ||
1594 validBits.testBit(i) != cm.validBits.testBit(i))
1595 {
1596 return false;
1597 }
1598 }
1599 } else {
1600 for (int i = 0; i < map_size; i++) {
1601 if (rgb[i] != cm.rgb[i]) {
1602 return false;
1603 }
1604 }
1605 }
1606 return true;
1607 }
1608
1609 /**
1610 * Returns the hash code for IndexColorModel.
1611 *
1612 * @return a hash code for IndexColorModel
1613 */
1614 @Override
1615 public int hashCode() {
1616 int result = hashCode;
1617 if (result == 0) {
1618 result = super.hashCode();
1619 result = 43 * result + Arrays.hashCode(this.rgb);
1620 result = 43 * result + this.map_size;
1621 result = 43 * result + this.transparent_index;
1622 hashCode = result;
1623 }
1624 return result;
1625 }
1626 }
|