< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 29,42 **** import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import sun.java2d.cmm.CMSManager; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; - import java.awt.Toolkit; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; /** * The {@code ColorModel} abstract class encapsulates the * methods for translating a pixel value to color components * (for example, red, green, and blue) and an alpha component. --- 29,42 ---- import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import sun.java2d.cmm.CMSManager; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; + import java.util.Arrays; /** * The {@code ColorModel} abstract class encapsulates the * methods for translating a pixel value to color components * (for example, red, green, and blue) and an alpha component.
*** 360,370 **** else { this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; } ! nBits = bits.clone(); this.pixel_bits = pixel_bits; if (pixel_bits <= 0) { throw new IllegalArgumentException("Number of pixel bits must "+ "be > 0"); } --- 360,377 ---- else { this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; } ! /* ! * We need significant bits value only for the length ! * of number of components, so we truncate remaining part. ! * It also helps in hashCode calculation since bits[] can contain ! * different values after the length of number of components between ! * two ColorModels. ! */ ! nBits = Arrays.copyOf(bits, numComponents); this.pixel_bits = pixel_bits; if (pixel_bits <= 0) { throw new IllegalArgumentException("Number of pixel bits must "+ "be > 0"); }
*** 1439,1514 **** return getNormalizedComponents(components, 0, normComponents, normOffset); } /** - * Tests if the specified {@code Object} is an instance of - * {@code ColorModel} and if it equals this - * {@code ColorModel}. - * @param obj the {@code Object} to test for equality - * @return {@code true} if the specified {@code Object} - * is an instance of {@code ColorModel} and equals this - * {@code ColorModel}; {@code false} otherwise. - */ - public boolean equals(Object obj) { - if (!(obj instanceof ColorModel)) { - return false; - } - ColorModel cm = (ColorModel) obj; - - if (this == cm) { - return true; - } - if (supportsAlpha != cm.hasAlpha() || - isAlphaPremultiplied != cm.isAlphaPremultiplied() || - pixel_bits != cm.getPixelSize() || - transparency != cm.getTransparency() || - numComponents != cm.getNumComponents()) - { - return false; - } - - int[] nb = cm.getComponentSize(); - - if ((nBits != null) && (nb != null)) { - for (int i = 0; i < numComponents; i++) { - if (nBits[i] != nb[i]) { - return false; - } - } - } else { - return ((nBits == null) && (nb == null)); - } - - return true; - } - - /** - * Returns the hash code for this ColorModel. - * - * @return a hash code for this ColorModel. - */ - public int hashCode() { - - int result = 0; - - result = (supportsAlpha ? 2 : 3) + - (isAlphaPremultiplied ? 4 : 5) + - pixel_bits * 6 + - transparency * 7 + - numComponents * 8; - - if (nBits != null) { - for (int i = 0; i < numComponents; i++) { - result = result + nBits[i] * (i + 9); - } - } - - return result; - } - - /** * Returns the {@code ColorSpace} associated with this * {@code ColorModel}. * @return the {@code ColorSpace} of this * {@code ColorModel}. */ --- 1446,1455 ----
< prev index next >