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/21 10:18:10 UTC

svn commit: r956489 - in /xmlgraphics/commons/branches/Temp_Color: src/java/org/apache/xmlgraphics/image/loader/impl/ src/java/org/apache/xmlgraphics/java2d/color/ test/java/org/apache/xmlgraphics/java2d/ test/java/org/apache/xmlgraphics/java2d/color/

Author: jeremias
Date: Mon Jun 21 08:18:10 2010
New Revision: 956489

URL: http://svn.apache.org/viewvc?rev=956489&view=rev
Log:
Renamed CMYKColorSpace to the more accurate name "DeviceCMYKColorSpace", since it is really device-dependent.
Added initial infrastructure for handling CIE Lab and named color spaces.

Added:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java   (with props)
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java   (with props)
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java
      - copied, changed from r956483, xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CMYKColorSpace.java
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java   (with props)
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java   (with props)
    xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/
    xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/
    xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java   (with props)
Removed:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CMYKColorSpace.java
Modified:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorUtil.java

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java?rev=956489&r1=956488&r2=956489&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java Mon Jun 21 08:18:10 2010
@@ -39,7 +39,7 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.ImageInfo;
 import org.apache.xmlgraphics.image.loader.ImageSessionContext;
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-import org.apache.xmlgraphics.java2d.color.CMYKColorSpace;
+import org.apache.xmlgraphics.java2d.color.ColorSpaces;
 import org.apache.xmlgraphics.util.MimeConstants;
 
 /**
@@ -119,7 +119,7 @@ public class ImageLoaderRawJPEG extends 
                             colorSpace = ColorSpace.getInstance(
                               ColorSpace.CS_LINEAR_RGB);
                         } else if (numComponents == 4) {
-                            colorSpace = CMYKColorSpace.getInstance();
+                            colorSpace = ColorSpaces.getDeviceCMYKColorSpace();
                         } else {
                             throw new ImageException("Unsupported ColorSpace for image "
                                         + info

Added: 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=956489&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java Mon Jun 21 08:18:10 2010
@@ -0,0 +1,237 @@
+/*
+ * 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.ColorSpace;
+
+/**
+ * This class defines the CIE L*a*b* (CIE 1976) color space. Valid values for L* are between 0
+ * and 100, for a* and b* between -127 and +127.
+ * @see http://en.wikipedia.org/wiki/Lab_color_space
+ */
+public class CIELabColorSpace extends ColorSpace {
+
+    private static final long serialVersionUID = -1821569090707520704L;
+
+    //CIE XYZ tristimulus values of the reference white point: Observer= 2°, Illuminant= D65
+    private static final float REF_X_D65 = 95.047f;
+    private static final float REF_Y_D65 = 100.000f;
+    private static final float REF_Z_D65 = 108.883f;
+
+    //CIE XYZ tristimulus values of the reference white point: Illuminant= D50
+    private static final float REF_X_D50 = 96.42f;
+    private static final float REF_Y_D50 = 100.00f;
+    private static final float REF_Z_D50 = 82.49f;
+
+    private static final double d = 6.0 / 29.0;
+    private static final double refA = 1.0 / (3 * Math.pow(d, 2)); //7.787037...
+    private static final double refB = 16.0 / 116.0;
+    private static final double t0 = Math.pow(d, 3); //0.008856...
+
+    private float wpX;
+    private float wpY;
+    private float wpZ;
+
+    /**
+     * Default constructor using the D65 white point.
+     */
+    public CIELabColorSpace() {
+        this(getD65WhitePoint());
+    }
+
+    /**
+     * CIE Lab space constructor which allows to give an arbitrary white point.
+     * @param whitePoint the white point in XYZ coordinates (valid values: 0.0f to 1.0f, although
+     * values slightly larger than 1.0f are common)
+     */
+    public CIELabColorSpace(float[] whitePoint) {
+        super(ColorSpace.TYPE_Lab, 3);
+        checkNumComponents(whitePoint, 3);
+        this.wpX = whitePoint[0];
+        this.wpY = whitePoint[1];
+        this.wpZ = whitePoint[2];
+    }
+
+    /**
+     * Returns the D65 white point.
+     * @return the D65 white point.
+     */
+    public static float[] getD65WhitePoint() {
+        return new float[] {REF_X_D65, REF_Y_D65, REF_Z_D65};
+    }
+
+    /**
+     * Returns the D50 white point.
+     * @return the D50 white point.
+     */
+    public static float[] getD50WhitePoint() {
+        return new float[] {REF_X_D50, REF_Y_D50, REF_Z_D50};
+    }
+
+    private void checkNumComponents(float[] colorvalue) {
+        checkNumComponents(colorvalue, getNumComponents());
+    }
+
+    private void checkNumComponents(float[] colorvalue, int expected) {
+        if (colorvalue == null) {
+            throw new NullPointerException("color value may not be null");
+        }
+        if (colorvalue.length != expected) {
+            throw new IllegalArgumentException("Expected " + expected
+                    + " components, but got " + colorvalue.length);
+        }
+    }
+
+    /**
+     * Returns the configured white point.
+     * @return the white point in CIE XYZ coordinates
+     */
+    public float[] getWhitePoint() {
+        return new float[] {wpX, wpY, wpZ};
+    }
+
+    private static final String CIE_LAB_ONLY_HAS_3_COMPONENTS = "CIE Lab only has 3 components!";
+
+    /** {@inheritDoc} */
+    public float getMinValue(int component) {
+        switch (component) {
+        case 0: //L*
+            return 0f;
+        case 1: //a*
+        case 2: //b*
+            return -127f;
+        default:
+            throw new IllegalArgumentException(CIE_LAB_ONLY_HAS_3_COMPONENTS);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public float getMaxValue(int component) {
+        switch (component) {
+        case 0: //L*
+            return 1f;
+        case 1: //a*
+        case 2: //b*
+            return 127f;
+        default:
+            throw new IllegalArgumentException(CIE_LAB_ONLY_HAS_3_COMPONENTS);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getName(int component) {
+        switch (component) {
+        case 0:
+            return "L*";
+        case 1:
+            return "a*";
+        case 2:
+            return "b*";
+        default:
+            throw new IllegalArgumentException(CIE_LAB_ONLY_HAS_3_COMPONENTS);
+        }
+    }
+
+    //Note: the conversion functions used here were mostly borrowed from Apache Commons Sanselan
+    //and adjusted to the local requirements.
+
+    /** {@inheritDoc} */
+    public float[] fromCIEXYZ(float[] colorvalue) {
+        checkNumComponents(colorvalue, 3);
+        float X = colorvalue[0];
+        float Y = colorvalue[1];
+        float Z = colorvalue[2];
+
+        double var_X = X / wpX;
+        double var_Y = Y / wpY;
+        double var_Z = Z / wpZ;
+
+        if (var_X > t0) {
+            var_X = Math.pow(var_X, (1 / 3.0));
+        } else {
+            var_X = (refA * var_X) + refB;
+        }
+        if (var_Y > t0) {
+            var_Y = Math.pow(var_Y, 1 / 3.0);
+        } else {
+            var_Y = (refA * var_Y) + refB;
+        }
+        if (var_Z > t0) {
+            var_Z = Math.pow(var_Z, 1 / 3.0);
+        } else {
+            var_Z = (refA * var_Z) + refB;
+        }
+
+        float L = (float)((116 * var_Y) - 16);
+        float a = (float)(500 * (var_X - var_Y));
+        float b = (float)(200 * (var_Y - var_Z));
+        return new float[] {L, a, b};
+    }
+
+    /** {@inheritDoc} */
+    public float[] fromRGB(float[] rgbvalue) {
+        ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+        float[] xyz = sRGB.toCIEXYZ(rgbvalue);
+        return fromCIEXYZ(xyz);
+    }
+
+    /** {@inheritDoc} */
+    public float[] toCIEXYZ(float[] colorvalue) {
+        checkNumComponents(colorvalue);
+        float L = colorvalue[0];
+        float a = colorvalue[1];
+        float b = colorvalue[2];
+
+        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 {
+            var_Y = (var_Y - 16 / 116.0) / refA;
+        }
+        if (Math.pow(var_X, 3) > t0) {
+            var_X = Math.pow(var_X, 3);
+        } else {
+            var_X = (var_X - 16 / 116.0) / refA;
+        }
+        if (Math.pow(var_Z, 3) > t0) {
+            var_Z = Math.pow(var_Z, 3);
+        } else {
+            var_Z = (var_Z - 16 / 116.0) / refA;
+        }
+
+        float X = (float)(wpX * var_X / 100);
+        float Y = (float)(wpY * var_Y / 100);
+        float Z = (float)(wpZ * var_Z / 100);
+
+        return new float[] {X, Y, Z};
+    }
+
+    /** {@inheritDoc} */
+    public float[] toRGB(float[] colorvalue) {
+        ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+        float[] xyz = toCIEXYZ(colorvalue);
+        return sRGB.fromCIEXYZ(xyz);
+    }
+
+}

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CIELabColorSpace.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java?rev=956489&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java Mon Jun 21 08:18:10 2010
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Provides access to various color spaces.
+ */
+public class ColorSpaces {
+
+    private static DeviceCMYKColorSpace deviceCMYK;
+
+    public static synchronized DeviceCMYKColorSpace getDeviceCMYKColorSpace() {
+        if (deviceCMYK == null) {
+            deviceCMYK = new DeviceCMYKColorSpace();
+        }
+        return deviceCMYK;
+    }
+
+}

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java
------------------------------------------------------------------------------
    svn:keywords = Id

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=956489&r1=956488&r2=956489&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 Mon Jun 21 08:18:10 2010
@@ -81,7 +81,7 @@ public final class ColorUtil {
      */
     public static Color toCMYKGrayColor(float black) {
         float[] cmyk = new float[] {0f, 0f, 0f, 1.0f - black};
-        CMYKColorSpace cmykCs = CMYKColorSpace.getInstance();
+        DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace();
         float[] rgb = cmykCs.toRGB(cmyk);
         return ColorExt.createFromFoRgbIcc(rgb[0], rgb[1], rgb[2],
                 CMYK_PSEUDO_PROFILE, null, cmykCs, cmyk);

Copied: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java (from r956483, xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CMYKColorSpace.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java?p2=xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java&p1=xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CMYKColorSpace.java&r1=956483&r2=956489&rev=956489&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/CMYKColorSpace.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/DeviceCMYKColorSpace.java Mon Jun 21 08:18:10 2010
@@ -24,32 +24,19 @@ import java.awt.color.ColorSpace;
 /**
  * This class represents an uncalibrated CMYK color space.
  */
-public class CMYKColorSpace extends ColorSpace {
+public class DeviceCMYKColorSpace extends ColorSpace {
 
     private static final long serialVersionUID = 2925508946083542974L;
 
-    private static CMYKColorSpace instance;
-
     /**
      * Constructs an uncalibrated CMYK ColorSpace object with {@link ColorSpace#TYPE_CMYK} and
      * 4 components.
      * @see java.awt.color.ColorSpace#ColorSpace(int, int)
      */
-    protected CMYKColorSpace() {
+    public DeviceCMYKColorSpace() {
         super(TYPE_CMYK, 4);
     }
 
-    /**
-     * Returns an instance of an uncalibrated CMYK color space.
-     * @return CMYKColorSpace the requested color space object
-     */
-    public static CMYKColorSpace getInstance() {
-        if (instance == null) {
-            instance = new CMYKColorSpace();
-        }
-        return instance;
-    }
-
     /** {@inheritDoc} */
     public float[] toRGB(float[] colorvalue) {
         return new float [] {

Added: 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=956489&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java Mon Jun 21 08:18:10 2010
@@ -0,0 +1,69 @@
+/*
+ * 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 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
+ * URI in order to allow serialization of the color without having to serialize the full
+ * color profile, too.
+ */
+public class ICCColor extends Color {
+
+    private static final long serialVersionUID = -104707261086330666L;
+
+    private String profileName;
+    private URI profileURI;
+
+    /**
+     * Creates a new ICC-based color.
+     * @param cspace the color space
+     * @param profileName the color profile name
+     * @param profileURI the color profile URI
+     * @param components the component values
+     * @param alpha the alpha value
+     */
+    public ICCColor(ColorSpace cspace, String profileName, URI profileURI,
+            float[] components, float alpha) {
+        super(cspace, components, alpha);
+        this.profileName = profileName;
+        this.profileURI = profileURI;
+    }
+
+    /**
+     * Returns the name of the color profile as used in the SVG or XSL-FO.
+     * @return the color profile name
+     */
+    public String getColorProfileName() {
+        return this.profileName;
+    }
+
+    /**
+     * Returns the URI identifying the color profile.
+     * @return the URI identifying the color profile.
+     */
+    public URI getColorProfileURI() {
+        return this.profileURI;
+    }
+
+}

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=956489&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java Mon Jun 21 08:18:10 2010
@@ -0,0 +1,118 @@
+/*
+ * 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.ColorSpace;
+
+/**
+ * Implements a pseudo color space for a named color which is defined in the CIE XYZ color space.
+ * At the moment, this color space always returns the fully opaque color regardless of the single
+ * component value (tint) given to its conversion methods.
+ */
+public class NamedColorSpace extends ColorSpace {
+
+    private static final long serialVersionUID = -8957543225908514658L;
+
+    private String name;
+    private float[] xyz;
+
+    /**
+     * Creates a new named color.
+     * @param name the color name
+     * @param xyz the CIE XYZ coordinates (valid values: 0.0f to 1.0f, although
+     *                  values slightly larger than 1.0f are common)
+     */
+    public NamedColorSpace(String name, float[] xyz) {
+        super(ColorSpace.TYPE_GRAY, 1);
+        checkNumComponents(xyz, 3);
+        this.name = name;
+        this.xyz = new float[3];
+        System.arraycopy(xyz, 0, this.xyz, 0, 3);
+    }
+
+    private void checkNumComponents(float[] colorvalue, int expected) {
+        if (colorvalue == null) {
+            throw new NullPointerException("color value may not be null");
+        }
+        if (colorvalue.length != expected) {
+            throw new IllegalArgumentException("Expected " + expected
+                    + " components, but got " + colorvalue.length);
+        }
+    }
+
+    /**
+     * Returns the color name.
+     * @return the color name
+     */
+    public String getColorName() {
+        return this.name;
+    }
+
+    /** {@inheritDoc} */
+    public float getMinValue(int component) {
+        return getMaxValue(component); //same as min, i.e. always 1.0
+    }
+
+    /** {@inheritDoc} */
+    public float getMaxValue(int component) {
+        switch (component) {
+        case 0:
+            return 1f;
+        default:
+            throw new IllegalArgumentException("A named color space only has 1 component!");
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getName(int component) {
+        switch (component) {
+        case 0:
+            return "Tint";
+        default:
+            throw new IllegalArgumentException("A named color space only has 1 component!");
+        }
+    }
+
+    /** {@inheritDoc} */
+    public float[] fromCIEXYZ(float[] colorvalue) {
+        //ignore the given color values as this is a fixed color.
+        return new float[] {1.0f}; //Return value for full tint
+    }
+
+    /** {@inheritDoc} */
+    public float[] fromRGB(float[] rgbvalue) {
+        //ignore the given color values as this is a fixed color.
+        return new float[] {1.0f}; //Return value for full tint
+    }
+
+    /** {@inheritDoc} */
+    public float[] toCIEXYZ(float[] colorvalue) {
+        float[] ret = new float[3];
+        System.arraycopy(this.xyz, 0, ret, 0, this.xyz.length);
+        return ret;
+    }
+
+    /** {@inheritDoc} */
+    public float[] toRGB(float[] colorvalue) {
+        ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+        return sRGB.fromCIEXYZ(this.xyz);
+    }
+
+}

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 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=956489&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java Mon Jun 21 08:18:10 2010
@@ -0,0 +1,63 @@
+/*
+ * 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 named color spaces (and the CIE Lab color space implementation).
+ */
+public class NamedColorTest extends TestCase {
+
+    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);
+        //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);
+
+        //Build named color based on XYZ coordinates
+        NamedColorSpace ncs = new NamedColorSpace("Postgelb", c1xyz);
+        Color c1 = new Color(ncs, new float[] {1.0f}, 1.0f);
+
+        assertEquals(ncs, c1.getColorSpace());
+        float[] comp = c1.getColorComponents(null);
+        assertEquals(1, comp.length);
+        assertEquals(1.0f, comp[0], 0.001f);
+        float[] xyz = ncs.toCIEXYZ(new float[] {1.0f});
+        for (int i = 0; i < 3; i++) {
+            assertEquals(c1xyz[i], xyz[i], 0.001f);
+        }
+
+        assertEquals(254, c1.getRed());
+        assertEquals(195, c1.getGreen());
+        assertEquals(0, c1.getBlue());
+    }
+
+
+}

Propchange: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/NamedColorTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org