< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2014, 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) 1997, 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
*** 25,34 **** --- 25,36 ---- package java.awt.image; import java.awt.Transparency; import java.awt.color.ColorSpace; + import java.util.Arrays; + import java.util.Objects; /** * The {@code PackedColorModel} class is an abstract * {@link ColorModel} class that works with pixel values which represent * color and alpha information as separate samples and which pack all
*** 86,95 **** --- 88,98 ---- public abstract class PackedColorModel extends ColorModel { int[] maskArray; int[] maskOffsets; float[] scaleFactors; + private volatile int hashCode; /** * Constructs a {@code PackedColorModel} from a color mask array, * which specifies which bits in an {@code int} pixel representation * contain each of the color samples, and an alpha mask. Color
*** 391,419 **** * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} * is an instance of {@code PackedColorModel} and equals this * {@code PackedColorModel}; {@code false} otherwise. */ public boolean equals(Object obj) { if (!(obj instanceof PackedColorModel)) { return false; } ! if (!super.equals(obj)) { return false; } - PackedColorModel cm = (PackedColorModel) obj; int numC = cm.getNumComponents(); for(int i=0; i < numC; i++) { if (maskArray[i] != cm.getMask(i)) { return false; } } return true; } private static final int[] createBitsArray(int[]colorMaskArray, int alphaMask) { int numColors = colorMaskArray.length; int numAlpha = (alphaMask == 0 ? 0 : 1); int[] arr = new int[numColors+numAlpha]; --- 394,466 ---- * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} * is an instance of {@code PackedColorModel} and equals this * {@code PackedColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { if (!(obj instanceof PackedColorModel)) { return false; } ! PackedColorModel cm = (PackedColorModel) obj; ! ! if (supportsAlpha != cm.hasAlpha() || ! isAlphaPremultiplied != cm.isAlphaPremultiplied() || ! pixel_bits != cm.getPixelSize() || ! transparency != cm.getTransparency() || ! numComponents != cm.getNumComponents() || ! (!(colorSpace.equals(cm.colorSpace))) || ! transferType != cm.transferType) ! { return false; } int numC = cm.getNumComponents(); for(int i=0; i < numC; i++) { if (maskArray[i] != cm.getMask(i)) { 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 PackedColorModel. + * + * @return a hash code for this PackedColorModel. + */ + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = 7; + result = 89 * result + this.pixel_bits; + result = 89 * result + Arrays.hashCode(this.nBits); + result = 89 * result + this.transparency; + result = 89 * result + (this.supportsAlpha ? 1 : 0); + result = 89 * result + (this.isAlphaPremultiplied ? 1 : 0); + result = 89 * result + this.numComponents; + result = 89 * result + Objects.hashCode(this.colorSpace); + result = 89 * result + this.transferType; + result = 89 * result + Arrays.hashCode(this.maskArray); + hashCode = result; + } + return result; + } + private static final int[] createBitsArray(int[]colorMaskArray, int alphaMask) { int numColors = colorMaskArray.length; int numAlpha = (alphaMask == 0 ? 0 : 1); int[] arr = new int[numColors+numAlpha];
< prev index next >