< 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         if (!(obj instanceof IndexColorModel)) {
1551             return false;
1552         }
1553 
1554         IndexColorModel cm = (IndexColorModel) obj;
1555         if (this == cm) {
1556             return true;
1557         }
1558 
1559         if (!super.equals(obj)) {
1560             return false;
1561         }
1562 
1563         if (map_size != cm.map_size ||
1564             transparent_index != cm.transparent_index)
1565         {
1566             return false;
1567         }
1568 
1569         // verify whether we have to check equality of all bits in validBits
1570         boolean testValidBits;
1571         if (validBits == cm.validBits) {
1572             testValidBits = false;
1573         } else if (validBits == null || cm.validBits == null) {
1574             return false;
1575         } else if (validBits.equals(cm.validBits)) {
1576             testValidBits = false;
1577         } else {
1578             testValidBits = true;
1579         }
1580 
1581         if (testValidBits) {
1582             for (int i = 0; i < map_size; i++) {
1583                 if (rgb[i] != cm.rgb[i] ||
1584                     validBits.testBit(i) != cm.validBits.testBit(i))
1585                 {
1586                     return false;
1587                 }
1588             }
1589         } else {
1590             for (int i = 0; i < map_size; i++) {
1591                 if (rgb[i] != cm.rgb[i]) {
1592                     return false;
1593                 }
1594             }
1595         }
1596         return true;
1597     }
1598 
1599     /**
1600      * Returns the hash code for IndexColorModel.
1601      *
1602      * @return    a hash code for IndexColorModel
1603      */
1604     @Override
1605     public int hashCode() {
1606         int hash = 7;
1607         hash = 43 * hash + super.hashCode();
1608         hash = 43 * hash + Arrays.hashCode(this.rgb);
1609         hash = 43 * hash + this.map_size;
1610         hash = 43 * hash + this.transparent_index;
1611         hash = 43 * hash + Objects.hashCode(this.validBits);
1612         return hash;
1613     }
1614 }
< prev index next >