xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r1028215 - /xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/
Date Thu, 28 Oct 2010 08:23:35 GMT
Author: jeremias
Date: Thu Oct 28 08:23:34 2010
New Revision: 1028215

URL: http://svn.apache.org/viewvc?rev=1028215&view=rev
Log:
Code style improvements and javadocs.

Modified:
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
    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/ColorSpaces.java
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.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/ICCColorSpaceExt.java
    xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/NamedColorSpace.java

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java?rev=1028215&r1=1028214&r2=1028215&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
Thu Oct 28 08:23:34 2010
@@ -28,6 +28,11 @@ public abstract class AbstractDeviceSpec
 
     private static final long serialVersionUID = -4888985582872101875L;
 
+    /**
+     * Creates a new instance.
+     * @param type the color space type ({@link ColorSpace}.TYPE_*)
+     * @param numcomponents the number of color components applicable to the color space
+     */
     protected AbstractDeviceSpecificColorSpace(int type, int numcomponents) {
         super(type, numcomponents);
     }

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=1028215&r1=1028214&r2=1028215&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
Thu Oct 28 08:23:34 2010
@@ -41,10 +41,10 @@ public class CIELabColorSpace extends Co
     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 static final double D = 6.0 / 29.0;
+    private static final double REF_A = 1.0 / (3 * Math.pow(D, 2)); //7.787037...
+    private static final double REF_B = 16.0 / 116.0;
+    private static final double T0 = Math.pow(D, 3); //0.008856...
 
     private float wpX;
     private float wpY;
@@ -156,39 +156,39 @@ public class CIELabColorSpace extends Co
     /** {@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;
+        float x = colorvalue[0];
+        float y = colorvalue[1];
+        float z = colorvalue[2];
+
+        double varX = x / wpX;
+        double varY = y / wpY;
+        double varZ = z / wpZ;
 
-        if (var_X > t0) {
-            var_X = Math.pow(var_X, (1 / 3.0));
+        if (varX > T0) {
+            varX = Math.pow(varX, (1 / 3.0));
         } else {
-            var_X = (refA * var_X) + refB;
+            varX = (REF_A * varX) + REF_B;
         }
-        if (var_Y > t0) {
-            var_Y = Math.pow(var_Y, 1 / 3.0);
+        if (varY > T0) {
+            varY = Math.pow(varY, 1 / 3.0);
         } else {
-            var_Y = (refA * var_Y) + refB;
+            varY = (REF_A * varY) + REF_B;
         }
-        if (var_Z > t0) {
-            var_Z = Math.pow(var_Z, 1 / 3.0);
+        if (varZ > T0) {
+            varZ = Math.pow(varZ, 1 / 3.0);
         } else {
-            var_Z = (refA * var_Z) + refB;
+            varZ = (REF_A * varZ) + REF_B;
         }
 
-        float L = (float)((116 * var_Y) - 16);
-        float a = (float)(500 * (var_X - var_Y));
-        float b = (float)(200 * (var_Y - var_Z));
+        float l = (float)((116 * varY) - 16);
+        float a = (float)(500 * (varX - varY));
+        float b = (float)(200 * (varY - varZ));
 
         //Normalize to range 0.0..1.0
-        L = normalize(L, 0);
+        l = normalize(l, 0);
         a = normalize(a, 1);
         b = normalize(b, 2);
-        return new float[] {L, a, b};
+        return new float[] {l, a, b};
     }
 
     /** {@inheritDoc} */
@@ -202,40 +202,40 @@ public class CIELabColorSpace extends Co
     public float[] toCIEXYZ(float[] colorvalue) {
         checkNumComponents(colorvalue);
         //Scale to native value range
-        float L = denormalize(colorvalue[0], 0);
+        float l = denormalize(colorvalue[0], 0);
         float a = denormalize(colorvalue[1], 1);
         float b = denormalize(colorvalue[2], 2);
 
-        return toCIEXYZNative(L, a, b);
+        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;
+    public float[] toCIEXYZNative(float l, float a, float b) {
+        double varY = (l + 16) / 116.0;
+        double varX = a / 500 + varY;
+        double varZ = varY - b / 200.0;
 
-        if (Math.pow(var_Y, 3) > t0) {
-            var_Y = Math.pow(var_Y, 3);
+        if (Math.pow(varY, 3) > T0) {
+            varY = Math.pow(varY, 3);
         } else {
-            var_Y = (var_Y - 16 / 116.0) / refA;
+            varY = (varY - 16 / 116.0) / REF_A;
         }
-        if (Math.pow(var_X, 3) > t0) {
-            var_X = Math.pow(var_X, 3);
+        if (Math.pow(varX, 3) > T0) {
+            varX = Math.pow(varX, 3);
         } else {
-            var_X = (var_X - 16 / 116.0) / refA;
+            varX = (varX - 16 / 116.0) / REF_A;
         }
-        if (Math.pow(var_Z, 3) > t0) {
-            var_Z = Math.pow(var_Z, 3);
+        if (Math.pow(varZ, 3) > T0) {
+            varZ = Math.pow(varZ, 3);
         } else {
-            var_Z = (var_Z - 16 / 116.0) / refA;
+            varZ = (varZ - 16 / 116.0) / REF_A;
         }
 
-        float X = (float)(wpX * var_X / 100);
-        float Y = (float)(wpY * var_Y / 100);
-        float Z = (float)(wpZ * var_Z / 100);
+        float x = (float)(wpX * varX / 100);
+        float y = (float)(wpY * varY / 100);
+        float z = (float)(wpZ * varZ / 100);
 
-        return new float[] {X, Y, Z};
+        return new float[] {x, y, z};
     }
 
     /** {@inheritDoc} */
@@ -292,14 +292,14 @@ public class CIELabColorSpace extends Co
     /**
      * 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 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);
+    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/ColorSpaces.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java?rev=1028215&r1=1028214&r2=1028215&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaces.java
Thu Oct 28 08:23:34 2010
@@ -24,12 +24,16 @@ import java.awt.color.ColorSpace;
 /**
  * Provides access to various color spaces.
  */
-public class ColorSpaces {
+public final class ColorSpaces {
 
     private static DeviceCMYKColorSpace deviceCMYK;
     private static CIELabColorSpace cieLabD50;
     private static CIELabColorSpace cieLabD65;
 
+    private ColorSpaces() {
+        //Don't instantiate this class
+    }
+
     /**
      * Returns an instance of the device-specific CMYK color space.
      * @return an instance of the device-specific CMYK color space

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java?rev=1028215&r1=1028214&r2=1028215&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
Thu Oct 28 08:23:34 2010
@@ -40,6 +40,11 @@ public class ColorWithAlternatives exten
     private Color[] alternativeColors;
 
     /**
+     * Constructor for RGBA colors.
+     * @param r the red component
+     * @param g the green component
+     * @param b the blue component
+     * @param a the alpha component
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(float, float, float, float)
      */
@@ -49,6 +54,10 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for RGB colors.
+     * @param r the red component
+     * @param g the green component
+     * @param b the blue component
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(float, float, float)
      */
@@ -58,6 +67,9 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for RGBA colors.
+     * @param rgba the combined RGBA value
+     * @param hasalpha true if the alpha bits are valid, false otherwise
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(int, boolean)
      */
@@ -67,6 +79,11 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for RGBA colors.
+     * @param r the red component
+     * @param g the green component
+     * @param b the blue component
+     * @param a the alpha component
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(int, int, int, int)
      */
@@ -76,6 +93,10 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for RGB colors.
+     * @param r the red component
+     * @param g the green component
+     * @param b the blue component
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(int, int, int)
      */
@@ -85,6 +106,8 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for RGB colors.
+     * @param rgb the combined RGB components
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(int)
      */
@@ -94,6 +117,10 @@ public class ColorWithAlternatives exten
     }
 
     /**
+     * Constructor for colors with an arbitrary color space.
+     * @param cspace the color space
+     * @param components the color components
+     * @param alpha the alpha component
      * @param alternativeColors the prioritized list of alternative colors.
      * @see Color#Color(ColorSpace, float[], float)
      */
@@ -204,4 +231,10 @@ public class ColorWithAlternatives exten
         return true;
     }
 
+    /** {@inheritDoc} */
+    public int hashCode() {
+        //No special treatment necessary for the alternative colors
+        return super.hashCode();
+    }
+
 }

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=1028215&r1=1028214&r2=1028215&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
Thu Oct 28 08:23:34 2010
@@ -25,7 +25,8 @@ import java.awt.color.ColorSpace;
 /**
  * This class represents an uncalibrated CMYK color space.
  */
-public class DeviceCMYKColorSpace extends AbstractDeviceSpecificColorSpace implements ColorSpaceOrigin
{
+public class DeviceCMYKColorSpace extends AbstractDeviceSpecificColorSpace
+            implements ColorSpaceOrigin {
 
     private static final long serialVersionUID = 2925508946083542974L;
 

Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java?rev=1028215&r1=1028214&r2=1028215&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java
(original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java
Thu Oct 28 08:23:34 2010
@@ -1,21 +1,22 @@
 /*
+ * 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.
+ */
 
-   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;
@@ -25,33 +26,46 @@ import java.awt.color.ICC_Profile;
 /**
  * This class extends the ICCColorSpace class by providing
  * convenience methods to convert to sRGB using various
- * methods, forcing a givent intent, such as perceptual or
- * relative colorimetric.
- *
- * @version $Id$
+ * methods, forcing a given intent, such as perceptual or
+ * relative colorimetric. It also additionally holds the name
+ * and source URI of the color profile.
  */
 public class ICCColorSpaceExt extends ICC_ColorSpace implements ColorSpaceOrigin {
 
     private static final long serialVersionUID = -3338065900662625221L;
 
+    /** Constant for the perceptual rendering intent. Typical use: scanned images. */
     public static final int PERCEPTUAL = 0;
+    /** Constant for the relative colorimetric rendering intent. Typical use: vector graphics.
*/
     public static final int RELATIVE_COLORIMETRIC = 1;
+    /**
+     * Constant for the absolute colorimetric rendering intent.
+     * Typical use: logos and solid colors.
+     */
     public static final int ABSOLUTE_COLORIMETRIC = 2;
+    /** Constant for the saturation rendering intent. Typical use: business graphics. */
     public static final int SATURATION = 3;
+    /** Automatic rendering intent. The color profile's intent isn't overridden. */
     public static final int AUTO = 4;
 
-    static final ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+    static final ColorSpace SRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
 
     private int intent;
     private String profileName;
     private String profileURI;
 
-
+    /**
+     * Creates a new ICC-based color space.
+     * @param p the color profile
+     * @param intent the overriding rendering intent (use {@link #AUTO} no preserve the profile's)
+     * @param profileName the color profile name
+     * @param profileURI the source URI of the color profile
+     */
     public ICCColorSpaceExt(ICC_Profile p, int intent, String profileName, String profileURI)
{
         super(p);
 
         this.intent = intent;
-        switch(intent){
+        switch(intent) {
         case AUTO:
         case RELATIVE_COLORIMETRIC:
         case ABSOLUTE_COLORIMETRIC:
@@ -65,7 +79,7 @@ public class ICCColorSpaceExt extends IC
         /**
          * Apply the requested intent into the profile
          */
-        if (intent != AUTO){
+        if (intent != AUTO) {
             byte[] hdr = p.getData(ICC_Profile.icSigHead);
             hdr[ICC_Profile.icHdrRenderingIntent] = (byte)intent;
         }
@@ -77,10 +91,12 @@ public class ICCColorSpaceExt extends IC
     /**
      * Returns the sRGB value obtained by forcing the
      * conversion method to the intent passed to the
-     * constructor
+     * constructor.
+     * @param values the color values in the local color space
+     * @return the sRGB values
      */
-    public float[] intendedToRGB(float[] values){
-        switch(intent){
+    public float[] intendedToRGB(float[] values) {
+        switch(intent) {
             case ABSOLUTE_COLORIMETRIC:
             return absoluteColorimetricToRGB(values);
             case PERCEPTUAL:
@@ -98,33 +114,41 @@ public class ICCColorSpaceExt extends IC
     /**
      * Perceptual conversion is the method implemented by the
      * base class's toRGB method
+     * @param values the color values in the local color space
+     * @return the sRGB values
      */
-    public float[] perceptualToRGB(float[] values){
+    public float[] perceptualToRGB(float[] values) {
         return toRGB(values);
     }
 
     /**
      * Relative colorimetric needs to happen through CIEXYZ
-     * conversion
+     * conversion.
+     * @param values the color values in the local color space
+     * @return the sRGB values
      */
-    public float[] relativeColorimetricToRGB(float[] values){
+    public float[] relativeColorimetricToRGB(float[] values) {
         float[] ciexyz = toCIEXYZ(values);
-        return sRGB.fromCIEXYZ(ciexyz);
+        return SRGB.fromCIEXYZ(ciexyz);
     }
 
     /**
      * Absolute colorimetric. NOT IMPLEMENTED.
-     * Temporarily returns same as perceptual
+     * Temporarily returns same as perceptual.
+     * @param values the color values in the local color space
+     * @return the sRGB values
      */
-    public float[] absoluteColorimetricToRGB(float[] values){
+    public float[] absoluteColorimetricToRGB(float[] values) {
         return perceptualToRGB(values);
     }
 
     /**
      * Saturation. NOT IMPLEMENTED. Temporarily returns same
      * as perceptual.
+     * @param values the color values in the local color space
+     * @return the sRGB values
      */
-    public float[] saturationToRGB(float[] values){
+    public float[] saturationToRGB(float[] values) {
         return perceptualToRGB(values);
     }
 

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=1028215&r1=1028214&r2=1028215&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
Thu Oct 28 08:23:34 2010
@@ -207,6 +207,11 @@ public class NamedColorSpace extends Col
     }
 
     /** {@inheritDoc} */
+    public int hashCode() {
+        return (this.profileName + name).hashCode();
+    }
+
+    /** {@inheritDoc} */
     public String toString() {
         return "Named Color Space: " + getColorName();
     }



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


Mime
View raw message