You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2010/06/25 13:47:57 UTC
svn commit: r957898 - in /xmlgraphics/commons/branches/Temp_Color:
src/java/org/apache/xmlgraphics/java2d/color/
test/java/org/apache/xmlgraphics/java2d/color/
Author: jeremias
Date: Fri Jun 25 11:47:57 2010
New Revision: 957898
URL: http://svn.apache.org/viewvc?rev=957898&view=rev
Log:
Added an equals() method to ColorExt.java
Use ColorExt whenever possible instead of java.awt.Color due to the way its equals() method is written (it doesn't detect two different colors with the same sRGB fallback).
Change CIE Lab color space to normalize the native color components to the range 0.0..1.0 because, oddly, Color requires that even through ColorSpace provides methods for the min and max values for each component.
Accessors for XYZ and derived sRGB values for NamedColor, as well as an equals() method.
Changed ICCColor.profileURI to .profileSrc with a String instead of an URI because we use Strings all over which may not always be valid URIs (ex. filenames are supported as a convenience).
Added:
xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java (with props)
Modified:
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java
xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java
xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java Fri Jun 25 11:47:57 2010
@@ -19,6 +19,7 @@
package org.apache.xmlgraphics.java2d.color;
+import java.awt.Color;
import java.awt.color.ColorSpace;
/**
@@ -182,6 +183,11 @@ public class CIELabColorSpace extends Co
float L = (float)((116 * var_Y) - 16);
float a = (float)(500 * (var_X - var_Y));
float b = (float)(200 * (var_Y - var_Z));
+
+ //Normalize to range 0.0..1.0
+ L = normalize(L, 0);
+ a = normalize(a, 1);
+ b = normalize(b, 2);
return new float[] {L, a, b};
}
@@ -195,15 +201,20 @@ public class CIELabColorSpace extends Co
/** {@inheritDoc} */
public float[] toCIEXYZ(float[] colorvalue) {
checkNumComponents(colorvalue);
- float L = colorvalue[0];
- float a = colorvalue[1];
- float b = colorvalue[2];
+ //Scale to native value range
+ float L = denormalize(colorvalue[0], 0);
+ float a = denormalize(colorvalue[1], 1);
+ float b = denormalize(colorvalue[2], 2);
+
+ return toCIEXYZNative(L, a, b);
+ }
+ /** {@inheritDoc} */
+ public float[] toCIEXYZNative(float L, float a, float b) {
double var_Y = (L + 16) / 116.0;
double var_X = a / 500 + var_Y;
double var_Z = var_Y - b / 200.0;
-
if (Math.pow(var_Y, 3) > t0) {
var_Y = Math.pow(var_Y, 3);
} else {
@@ -234,4 +245,46 @@ public class CIELabColorSpace extends Co
return sRGB.fromCIEXYZ(xyz);
}
+ private float getNativeValueRange(int component) {
+ return getMaxValue(component) - getMinValue(component);
+ }
+
+ private float normalize(float value, int component) {
+ return (value - getMinValue(component)) / getNativeValueRange(component);
+ }
+
+ private float denormalize(float value, int component) {
+ return value * getNativeValueRange(component) + getMinValue(component);
+ }
+
+ /**
+ * Creates a {@link Color} instance from color values usually used by the L*a*b* color space
+ * by scaling them to the 0.0..1.0 range expected by Color's constructor.
+ * @param colorvalue the original color values
+ * (native value range, i.e. not normalized to 0.0..1.0)
+ * @param alpha the alpha component
+ * @return the requested color instance
+ */
+ public Color toColor(float[] colorvalue, float alpha) {
+ int c = colorvalue.length;
+ float[] normalized = new float[c];
+ for (int i = 0; i < c; i++) {
+ normalized[i] = normalize(colorvalue[i], i);
+ }
+ return new Color(this, normalized, alpha);
+ }
+
+ /**
+ * Creates a {@link Color} instance from color values usually used by the L*a*b* color space
+ * by scaling them to the 0.0..1.0 range expected by Color's constructor.
+ * @param L the L* component
+ * @param a the a* component
+ * @param b the b* component
+ * @param alpha the alpha component
+ * @return the requested color instance
+ */
+ public Color toColor(float L, float a, float b, float alpha) {
+ return toColor(new float[] {L, a, b}, alpha);
+ }
+
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java Fri Jun 25 11:47:57 2010
@@ -91,19 +91,79 @@ public final class ColorExt extends Colo
}
private void initAlternateColors(Color[] colors) {
- //Colors are immutable but array are not, so copy
- this.alternateColors = new Color[colors.length];
- System.arraycopy(colors, 0, this.alternateColors, 0, colors.length);
+ if (colors != null) {
+ //Colors are immutable but array are not, so copy
+ this.alternateColors = new Color[colors.length];
+ System.arraycopy(colors, 0, this.alternateColors, 0, colors.length);
+ }
}
/**
- * Returns the list of alternate colors.
+ * Returns the list of alternate colors. An empty array will be returned if no alternative
+ * colors are available.
* @return the list of alternate colors
*/
public Color[] getAlternateColors() {
- Color[] cols = new Color[this.alternateColors.length];
- System.arraycopy(this.alternateColors, 0, cols, 0, this.alternateColors.length);
- return cols;
+ if (this.alternateColors != null) {
+ Color[] cols = new Color[this.alternateColors.length];
+ System.arraycopy(this.alternateColors, 0, cols, 0, this.alternateColors.length);
+ return cols;
+ } else {
+ return new Color[0];
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Color)) {
+ return false;
+ }
+ Color otherCol = (Color)obj;
+ if (getRGB() != otherCol.getRGB()) {
+ return false;
+ }
+ if (!getColorSpace().equals(otherCol.getColorSpace())) {
+ return false;
+ }
+ float[] comps = getComponents(null);
+ float[] otherComps = otherCol.getComponents(null);
+ if (comps.length != otherComps.length) {
+ return false;
+ }
+ for (int i = 0, c = comps.length; i < c; i++) {
+ if (comps[i] != otherComps[i]) {
+ return false;
+ }
+ }
+ if (getClass() != obj.getClass() && this.alternateColors != null) {
+ //We're quite strict here to preserve the additional functionality of ColorExt.
+ //If we don't do this, a renderer may not detect the difference between a ColorExt
+ //and a Color with the same sRGB fallback but with additional color alternatives
+ //taking precedence in some renderers.
+ return false;
+ }
+ if (getClass() == obj.getClass() ) {
+ ColorExt other = (ColorExt)obj;
+ if (this.alternateColors == null && other.alternateColors != null) {
+ return false;
+ } else if (this.alternateColors != null && other.alternateColors == null) {
+ return false;
+ }
+ if (this.alternateColors != null
+ && this.alternateColors.length != other.alternateColors.length) {
+ return false;
+ }
+ if (this.alternateColors != null) {
+ for (int i = 0, c = this.alternateColors.length; i < c; i++) {
+ Color col1 = this.alternateColors[i];
+ Color col2 = other.alternateColors[i];
+ if (!col1.equals(col2)) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
}
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java Fri Jun 25 11:47:57 2010
@@ -57,7 +57,7 @@ public final class ColorUtil {
cols[1] -= cols[1] * -factor;
cols[2] -= cols[2] * -factor;
}
- return new Color(cols[0], cols[1], cols[2], cols[3]);
+ return new ColorExt(cols[0], cols[1], cols[2], cols[3], null);
}
@@ -80,11 +80,6 @@ public final class ColorUtil {
//Calculated color components
float[] cmyk = new float[] {0f, 0f, 0f, 1.0f - black};
//Create native color
- DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace();
- Color cmykColor = new ICCColor(cmykCs,
- DeviceCMYKColorSpace.PSEUDO_PROFILE_NAME, null, cmyk, 1.0f);
- //Calculate an sRGB equivalent for the gray value
- float[] rgb = cmykCs.toRGB(cmyk);
- return new ColorExt(rgb[0], rgb[1], rgb[2], new Color[] {cmykColor});
+ return DeviceCMYKColorSpace.createColorExt(cmyk);
}
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java Fri Jun 25 11:47:57 2010
@@ -19,6 +19,7 @@
package org.apache.xmlgraphics.java2d.color;
+import java.awt.Color;
import java.awt.color.ColorSpace;
/**
@@ -63,4 +64,13 @@ public class DeviceCMYKColorSpace extend
throw new UnsupportedOperationException("NYI");
}
+ public static ColorExt createColorExt(float[] cmykComponents) {
+ DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace();
+ float[] rgb = cmykCs.toRGB(cmykComponents);
+ ICCColor alt = new ICCColor(cmykCs,
+ PSEUDO_PROFILE_NAME, null, cmykComponents, 1.0f);
+ ColorExt colorExt = new ColorExt(rgb[0], rgb[1], rgb[2], new Color[] {alt});
+ return colorExt;
+ }
+
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java Fri Jun 25 11:47:57 2010
@@ -21,7 +21,6 @@ package org.apache.xmlgraphics.java2d.co
import java.awt.Color;
import java.awt.color.ColorSpace;
-import java.net.URI;
/**
* This class extends AWT's {@link Color} class by fields for the profile name and the profile
@@ -33,21 +32,21 @@ public class ICCColor extends Color {
private static final long serialVersionUID = -104707261086330666L;
private String profileName;
- private URI profileURI;
+ private String profileSource;
/**
* Creates a new ICC-based color.
* @param cspace the color space
* @param profileName the color profile name
- * @param profileURI the color profile URI
+ * @param profileSource the color profile URI
* @param components the component values
* @param alpha the alpha value
*/
- public ICCColor(ColorSpace cspace, String profileName, URI profileURI,
+ public ICCColor(ColorSpace cspace, String profileName, String profileSource,
float[] components, float alpha) {
super(cspace, components, alpha);
this.profileName = profileName;
- this.profileURI = profileURI;
+ this.profileSource = profileSource;
}
/**
@@ -62,8 +61,40 @@ public class ICCColor extends Color {
* Returns the URI identifying the color profile.
* @return the URI identifying the color profile.
*/
- public URI getColorProfileURI() {
- return this.profileURI;
+ public String getColorProfileSource() {
+ return this.profileSource;
+ }
+
+ /** {@inheritDoc} */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ICCColor)) {
+ return false;
+ }
+ ICCColor other = (ICCColor)obj;
+ if (getRGB() != other.getRGB()) {
+ return false;
+ }
+ if (!getColorSpace().equals(other.getColorSpace())) {
+ return false;
+ }
+ float[] comps = getComponents(null);
+ float[] otherComps = other.getComponents(null);
+ if (comps.length != otherComps.length) {
+ return false;
+ }
+ for (int i = 0, c = comps.length; i < c; i++) {
+ if (comps[i] != otherComps[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(super.toString());
+ sb.append(' ').append(getColorProfileName());
+ return sb.toString();
}
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java Fri Jun 25 11:47:57 2010
@@ -19,6 +19,7 @@
package org.apache.xmlgraphics.java2d.color;
+import java.awt.Color;
import java.awt.color.ColorSpace;
/**
@@ -42,11 +43,24 @@ public class NamedColorSpace extends Col
public NamedColorSpace(String name, float[] xyz) {
super(ColorSpace.TYPE_GRAY, 1);
checkNumComponents(xyz, 3);
- this.name = name;
+ if (name == null || name.trim().length() == 0) {
+ throw new IllegalArgumentException("No name provided for named color space");
+ }
+ this.name = name.trim();
this.xyz = new float[3];
System.arraycopy(xyz, 0, this.xyz, 0, 3);
}
+ /**
+ * Creates a new named color.
+ * @param name the color name
+ * @param color the color to use when the named color's specific color properties are not
+ * available.
+ */
+ public NamedColorSpace(String name, Color color) {
+ this(name, color.getColorSpace().toCIEXYZ(color.getColorComponents(null)));
+ }
+
private void checkNumComponents(float[] colorvalue, int expected) {
if (colorvalue == null) {
throw new NullPointerException("color value may not be null");
@@ -65,6 +79,26 @@ public class NamedColorSpace extends Col
return this.name;
}
+ /**
+ * Returns the XYZ coordinates of the named color.
+ * @return the XYZ coordinates of the named color
+ */
+ public float[] getXYZ() {
+ float[] result = new float[this.xyz.length];
+ System.arraycopy(this.xyz, 0, result, 0, this.xyz.length);
+ return result;
+ }
+
+ /**
+ * Returns an sRGB-based color representing the full-tint color defined by this named color
+ * space.
+ * @return the sRGB color
+ */
+ public Color getRGBColor() {
+ float[] comps = toRGB(this.xyz);
+ return new Color(comps[0], comps[1], comps[2]);
+ }
+
/** {@inheritDoc} */
public float getMinValue(int component) {
return getMaxValue(component); //same as min, i.e. always 1.0
@@ -115,4 +149,26 @@ public class NamedColorSpace extends Col
return sRGB.fromCIEXYZ(this.xyz);
}
+ /** {@inheritDoc} */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof NamedColorSpace)) {
+ return false;
+ }
+ NamedColorSpace other = (NamedColorSpace)obj;
+ if (!this.name.equals(other.name)) {
+ return false;
+ }
+ for (int i = 0, c = this.xyz.length; i < c; i++) {
+ if (this.xyz[i] != other.xyz[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "Named Color Space: " + getColorName();
+ }
+
}
Modified: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java Fri Jun 25 11:47:57 2010
@@ -38,7 +38,7 @@ public class ColorConverterTest extends
assertEquals(1, altArray.length);
ICCColor alt = (ICCColor)altArray[0];
assertEquals("#CMYK", alt.getColorProfileName());
- assertNull(alt.getColorProfileURI());
+ assertNull(alt.getColorProfileSource());
assertEquals(ColorSpace.TYPE_CMYK, alt.getColorSpace().getType());
float[] comps = alt.getColorComponents(null);
assertEquals(4, comps.length);
Added: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java?rev=957898&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java Fri Jun 25 11:47:57 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d.color;
+
+import java.awt.Color;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the {@link ColorExt} class.
+ */
+public class ColorExtTest extends TestCase {
+
+ public void testEquals() throws Exception {
+ Color col1 = new ColorExt(255, 204, 0, null);
+ Color col2 = new Color(255, 204, 0);
+
+ assertEquals(col1, col2);
+ assertEquals(col2, col1);
+
+ CIELabColorSpace lab = new CIELabColorSpace(CIELabColorSpace.getD50WhitePoint());
+ Color postgelbLab = lab.toColor(83.25f, 16.45f, 96.89f, 1.0f);
+ col1 = new ColorExt(255, 204, 0, new Color[] {postgelbLab});
+
+ assertFalse(col1.equals(col2));
+ //Unfortunately, Color.equals() can't detect the color difference!
+ //col2.equals(col1) ===> true
+ }
+
+}
Propchange: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java?rev=957898&r1=957897&r2=957898&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java Fri Jun 25 11:47:57 2010
@@ -28,18 +28,20 @@ import junit.framework.TestCase;
*/
public class NamedColorTest extends TestCase {
+ private static final float POSTGELB_X = 0.6763079f;
+ private static final float POSTGELB_Y = 0.6263507f;
+ private static final float POSTGELB_Z = 0.04217565f;
+
public void testNamedColorWithCIELab() throws Exception {
CIELabColorSpace lab = new CIELabColorSpace(CIELabColorSpace.getD50WhitePoint());
//CIE Lab definition of "Postgelb" (postal yellow) at D50 as defined by Swiss Post
- float[] c1lab = new float[] {83.25f, 16.45f, 96.89f};
-
//Convert to XYZ
- float[] c1xyz = lab.toCIEXYZ(c1lab);
+ float[] c1xyz = lab.toCIEXYZNative(83.25f, 16.45f, 96.89f);
//Verify XYZ values are OK
- assertEquals(0.67631, c1xyz[0], 0.001f);
- assertEquals(0.62634, c1xyz[1], 0.001f);
- assertEquals(0.042191, c1xyz[2], 0.001f);
+ assertEquals(POSTGELB_X, c1xyz[0], 0.001f);
+ assertEquals(POSTGELB_Y, c1xyz[1], 0.001f);
+ assertEquals(POSTGELB_Z, c1xyz[2], 0.001f);
//Build named color based on XYZ coordinates
NamedColorSpace ncs = new NamedColorSpace("Postgelb", c1xyz);
@@ -59,5 +61,29 @@ public class NamedColorTest extends Test
assertEquals(0, c1.getBlue());
}
+ public void testEquals() throws Exception {
+ NamedColorSpace ncs1 = new NamedColorSpace("Postgelb",
+ new float[] {POSTGELB_X, POSTGELB_Y, POSTGELB_Z});
+
+ NamedColorSpace ncs2 = new NamedColorSpace("Postgelb",
+ new float[] {POSTGELB_X, POSTGELB_Y, POSTGELB_Z});
+ assertEquals(ncs1, ncs2);
+
+ //Construct the same NamedColorSpace via two different methods
+ CIELabColorSpace lab = new CIELabColorSpace(CIELabColorSpace.getD50WhitePoint());
+ Color postgelbLab = lab.toColor(83.25f, 16.45f, 96.89f, 1.0f);
+ float[] xyz = lab.toCIEXYZ(postgelbLab.getColorComponents(null));
+ xyz[0] = POSTGELB_X;
+ xyz[1] = POSTGELB_Y;
+ xyz[2] = POSTGELB_Z;
+ ncs1 = new NamedColorSpace("Postgelb", postgelbLab);
+ ncs2 = new NamedColorSpace("Postgelb", xyz);
+ assertEquals(ncs1, ncs2);
+
+ //Compare with a similar color coming from sRGB
+ Color rgb = new Color(255, 184, 0);
+ ncs2 = new NamedColorSpace("PostgelbFromRGB", rgb);
+ assertFalse(ncs1.equals(ncs2));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org