< prev index next >

src/java.desktop/share/classes/java/awt/image/IndexColorModel.java

Print this page




  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


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


1516      * longer referenced.
1517      */
1518     public void finalize() {
1519     }
1520 
1521     /**
1522      * Returns the {@code String} representation of the contents of
1523      * this {@code ColorModel} object.
1524      * @return a {@code String} representing the contents of this
1525      * {@code ColorModel} object.
1526      */
1527     public String toString() {
1528        return new String("IndexColorModel: #pixelBits = "+pixel_bits
1529                          + " numComponents = "+numComponents
1530                          + " color space = "+colorSpace
1531                          + " transparency = "+transparency
1532                          + " transIndex   = "+transparent_index
1533                          + " has alpha = "+supportsAlpha
1534                          + " isAlphaPre = "+isAlphaPremultiplied
1535                          );
1536     }
1537 
1538     /**
1539      * Tests if the specified {@code Object} is an instance
1540      * of {@code IndexColorModel} and equals this
1541      * {@code IndexColorModel}.
1542      * @param obj the {@code Object} to test for equality
1543      * @return {@code true} if the specified {@code Object}
1544      * is an instance of {@code IndexColorModel} and equals this
1545      * {@code IndexColorModel}; {@code false} otherwise.
1546      */
1547     @Override
1548     public boolean equals(Object obj) {
1549 
1550         IndexColorModel cm = (IndexColorModel) obj;
1551         if (this == cm) {
1552             return true;
1553         }
1554 
1555         if (!super.equals(obj)) {
1556             return false;
1557         }
1558 
1559         if (map_size != cm.map_size ||
1560             transparent_index != cm.transparent_index)
1561         {
1562             return false;
1563         }
1564 
1565         // verify whether we have to check equality of all bits in validBits
1566         boolean testValidBits;
1567         if (validBits == cm.validBits) {
1568             testValidBits = false;
1569         } else if (validBits == null || cm.validBits == null) {
1570             return false;
1571         } else if (validBits.equals(cm.validBits)) {
1572             testValidBits = false;
1573         } else {
1574             testValidBits = true;
1575         }
1576 
1577         if (testValidBits) {
1578             for (int i = 0; i < map_size; i++) {
1579                 if (rgb[i] != cm.rgb[i] ||
1580                     validBits.testBit(i) != cm.validBits.testBit(i))
1581                 {
1582                     return false;
1583                 }
1584             }
1585         } else {
1586             for (int i = 0; i < map_size; i++) {
1587                 if (rgb[i] != cm.rgb[i]) {
1588                     return false;
1589                 }
1590             }
1591         }
1592         return true;
1593     }
1594 
1595     /**
1596      * Returns the hash code for IndexColorModel.
1597      *
1598      * @return    a hash code for IndexColorModel
1599      */
1600     @Override
1601     public int hashCode() {
1602         int hash = 7;
1603         hash = 43 * hash + super.hashCode();
1604         hash = 43 * hash + Arrays.hashCode(this.rgb);
1605         hash = 43 * hash + this.map_size;
1606         hash = 43 * hash + this.transparent_index;
1607         hash = 43 * hash + Objects.hashCode(this.validBits);
1608         return hash;
1609     }
1610 }
< prev index next >