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/07/07 15:48:22 UTC
svn commit: r961376 - in /xmlgraphics/commons/branches/Temp_Color:
src/java/org/apache/xmlgraphics/java2d/color/
src/java/org/apache/xmlgraphics/java2d/color/profile/
src/java/org/apache/xmlgraphics/ps/
test/java/org/apache/xmlgraphics/java2d/color/
Author: jeremias
Date: Wed Jul 7 13:48:21 2010
New Revision: 961376
URL: http://svn.apache.org/viewvc?rev=961376&view=rev
Log:
Added interface for ColorSpace to report their origin (name and URI) where useful. (required by FOP to re-generate function strings)
Ported and slightly extended Batik's ICCColorSpaceExt which extends ICC_ColorSpace.
Added abstract class for all device-specific color spaces (does nothing specific but is useful for checking whether a color space is device-specific.
Renamed ColorExt to ColorWithAlternatives.
Removed unused ICCColor (ColorWithAlternatives replaces that, too)
Added:
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java (with props)
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java (with props)
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java
- copied, changed from r958985, 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/ICCColorSpaceExt.java
- copied, changed from r960569, xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java
Removed:
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/ICCColor.java
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/ColorSpaces.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/NamedColorSpace.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.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/ColorExtTest.java
Added: 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=961376&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java Wed Jul 7 13:48:21 2010
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * Base class for device-specific (uncalibrated) color spaces.
+ */
+public abstract class AbstractDeviceSpecificColorSpace extends ColorSpace {
+
+ protected AbstractDeviceSpecificColorSpace(int type, int numcomponents) {
+ super(type, numcomponents);
+ }
+
+}
Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/AbstractDeviceSpecificColorSpace.java
------------------------------------------------------------------------------
svn:keywords = Id
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -285,8 +285,8 @@ public class CIELabColorSpace extends Co
for (int i = 0; i < c; i++) {
normalized[i] = normalize(colorvalue[i], i);
}
- //Using ICCColor for better equals() functionality
- return new ICCColor(this, null, null, normalized, alpha);
+ //Using ColorWithAlternatives for better equals() functionality
+ return new ColorWithAlternatives(this, normalized, alpha, null);
}
/**
Added: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java?rev=961376&view=auto
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java (added)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java Wed Jul 7 13:48:21 2010
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Interface used to decorate {@link ColorSpace} subclasses to report the origin of the
+ * associated color profile.
+ */
+public interface ColorSpaceOrigin {
+
+ /**
+ * Returns the name of the profile used to identify the color space in a particular context.
+ * @return the profile name
+ */
+ String getProfileName();
+
+ /**
+ * Returns the URI identifying the associate color profile.
+ * @return the profile URI
+ */
+ String getProfileURI();
+
+}
Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorSpaceOrigin.java
------------------------------------------------------------------------------
svn:keywords = Id
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -19,6 +19,8 @@
package org.apache.xmlgraphics.java2d.color;
+import java.awt.color.ColorSpace;
+
/**
* Provides access to various color spaces.
*/
@@ -40,6 +42,15 @@ public class ColorSpaces {
}
/**
+ * Indicates whether the given color space is device-specific (i.e. uncalibrated).
+ * @param cs the color space to check
+ * @return true if the color space is device-specific
+ */
+ public static boolean isDeviceColorSpace(ColorSpace cs) {
+ return (cs instanceof AbstractDeviceSpecificColorSpace);
+ }
+
+ /**
* Returns an instance of the CIE L*a*b* color space using the D50 white point.
* @return an instance of the requested CIE L*a*b* color space
*/
@@ -61,4 +72,28 @@ public class ColorSpaces {
return cieLabD65;
}
+ private static final ColorSpaceOrigin UNKNOWN_ORIGIN = new ColorSpaceOrigin() {
+
+ public String getProfileURI() {
+ return null;
+ }
+
+ public String getProfileName() {
+ return null;
+ }
+ };
+
+ /**
+ * Returns information about the origin of a color space.
+ * @param cs the color space
+ * @return the origin information
+ */
+ public static ColorSpaceOrigin getColorSpaceOrigin(ColorSpace cs) {
+ if (cs instanceof ColorSpaceOrigin) {
+ return (ColorSpaceOrigin)cs;
+ } else {
+ return UNKNOWN_ORIGIN;
+ }
+ }
+
}
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -57,7 +57,7 @@ public final class ColorUtil {
cols[1] -= cols[1] * -factor;
cols[2] -= cols[2] * -factor;
}
- return new ColorExt(cols[0], cols[1], cols[2], cols[3], null);
+ return new ColorWithAlternatives(cols[0], cols[1], cols[2], cols[3], null);
}
@@ -80,6 +80,7 @@ public final class ColorUtil {
//Calculated color components
float[] cmyk = new float[] {0f, 0f, 0f, 1.0f - black};
//Create native color
- return DeviceCMYKColorSpace.createColorExt(cmyk);
+ return DeviceCMYKColorSpace.createCMYKColor(cmyk);
}
+
}
Copied: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java (from r958985, 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/ColorWithAlternatives.java?p2=xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternatives.java&p1=xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ColorExt.java&r1=958985&r2=961376&rev=961376&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/ColorWithAlternatives.java Wed Jul 7 13:48:21 2010
@@ -23,105 +23,127 @@ import java.awt.Color;
import java.awt.color.ColorSpace;
/**
- * Extended {@link Color} class allowing to specify a prioritized list of alternate colors.
- * An instance of this class should normally be an sRGB fallback color. The alternate colors
- * shall be the ones that are preferred if an output format supports them. This is done so because
- * it allows to specify the exact sRGB value that should be used if the alternate color spaces
- * are not supported. Colors in other color spaces will often not return the exact desired sRGB
- * value when converting native color values to sRGB through their {@link ColorSpace} instance.
+ * Extended {@link Color} class allowing to specify a prioritized list of alternative colors.
+ * The alternative colors shall be the ones that are preferred if an output format supports them.
+ * This is normally used for passing device-specific colors through to the output format.
+ * <p>
+ * An additional benefit of this class is a better {@link ColorWithAlternatives#equals(Object)}
+ * method than the one from {@link Color} which only takes the sRGB values into account.
+ * <p>
+ * This class only adds a single reference to a color array which should not increase memory
+ * consumption by much if no alternative colors are specified.
*/
-public final class ColorExt extends Color {
+public class ColorWithAlternatives extends Color {
private static final long serialVersionUID = -6125884937776779150L;
- private Color[] alternateColors;
+ private Color[] alternativeColors;
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(float, float, float, float)
*/
- public ColorExt(float r, float g, float b, float a, Color[] alternateColors) {
+ public ColorWithAlternatives(float r, float g, float b, float a, Color[] alternativeColors) {
super(r, g, b, a);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(float, float, float)
*/
- public ColorExt(float r, float g, float b, Color[] alternateColors) {
+ public ColorWithAlternatives(float r, float g, float b, Color[] alternativeColors) {
super(r, g, b);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(int, boolean)
*/
- public ColorExt(int rgba, boolean hasalpha, Color[] alternateColors) {
+ public ColorWithAlternatives(int rgba, boolean hasalpha, Color[] alternativeColors) {
super(rgba, hasalpha);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(int, int, int, int)
*/
- public ColorExt(int r, int g, int b, int a, Color[] alternateColors) {
+ public ColorWithAlternatives(int r, int g, int b, int a, Color[] alternativeColors) {
super(r, g, b, a);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(int, int, int)
*/
- public ColorExt(int r, int g, int b, Color[] alternateColors) {
+ public ColorWithAlternatives(int r, int g, int b, Color[] alternativeColors) {
super(r, g, b);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
/**
- * @param alternateColors the prioritized list of alternative colors.
+ * @param alternativeColors the prioritized list of alternative colors.
* @see Color#Color(int)
*/
- public ColorExt(int rgb, Color[] alternateColors) {
+ public ColorWithAlternatives(int rgb, Color[] alternativeColors) {
super(rgb);
- initAlternateColors(alternateColors);
+ initAlternativeColors(alternativeColors);
}
- private void initAlternateColors(Color[] colors) {
+ /**
+ * @param alternativeColors the prioritized list of alternative colors.
+ * @see Color#Color(ColorSpace, float[], float)
+ */
+ public ColorWithAlternatives(ColorSpace cspace, float[] components, float alpha,
+ Color[] alternativeColors) {
+ super(cspace, components, alpha);
+ initAlternativeColors(alternativeColors);
+ }
+
+ private void initAlternativeColors(Color[] colors) {
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);
+ this.alternativeColors = new Color[colors.length];
+ System.arraycopy(colors, 0, this.alternativeColors, 0, colors.length);
}
}
/**
- * Returns the list of alternate colors. An empty array will be returned if no alternative
+ * Returns the list of alternative colors. An empty array will be returned if no alternative
* colors are available.
- * @return the list of alternate colors
+ * @return the list of alternative colors
*/
- public Color[] getAlternateColors() {
- if (this.alternateColors != null) {
- Color[] cols = new Color[this.alternateColors.length];
- System.arraycopy(this.alternateColors, 0, cols, 0, this.alternateColors.length);
+ public Color[] getAlternativeColors() {
+ if (this.alternativeColors != null) {
+ Color[] cols = new Color[this.alternativeColors.length];
+ System.arraycopy(this.alternativeColors, 0, cols, 0, this.alternativeColors.length);
return cols;
} else {
return new Color[0];
}
}
+ /**
+ * Indicates whether alternative colors are available.
+ * @return true if alternative colors are available.
+ */
+ public boolean hasAlternativeColors() {
+ return this.alternativeColors != null && this.alternativeColors.length > 0;
+ }
+
/** {@inheritDoc} */
public boolean equals(Object obj) {
if (!(obj instanceof Color)) {
return false;
}
Color otherCol = (Color)obj;
+ /* java.awt.Color from Sun does not consistenly convert floats to [0..255]
if (getRGB() != otherCol.getRGB()) {
return false;
- }
+ }*/
if (!getColorSpace().equals(otherCol.getColorSpace())) {
return false;
}
@@ -135,28 +157,28 @@ public final class ColorExt extends Colo
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
+ if (getClass() != obj.getClass() && this.alternativeColors != null) {
+ //We're quite strict here to preserve the additional functionality of this class.
+ //If we don't do this, a renderer may not detect the difference between this class
+ //and a Color with the same sRGB value 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) {
+ ColorWithAlternatives other = (ColorWithAlternatives)obj;
+ if (this.alternativeColors == null && other.alternativeColors != null) {
return false;
- } else if (this.alternateColors != null && other.alternateColors == null) {
+ } else if (this.alternativeColors != null && other.alternativeColors == null) {
return false;
}
- if (this.alternateColors != null
- && this.alternateColors.length != other.alternateColors.length) {
+ if (this.alternativeColors != null
+ && this.alternativeColors.length != other.alternativeColors.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 (this.alternativeColors != null) {
+ for (int i = 0, c = this.alternativeColors.length; i < c; i++) {
+ Color col1 = this.alternativeColors[i];
+ Color col2 = other.alternativeColors[i];
if (!col1.equals(col2)) {
return false;
}
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -25,7 +25,7 @@ import java.awt.color.ColorSpace;
/**
* This class represents an uncalibrated CMYK color space.
*/
-public class DeviceCMYKColorSpace extends ColorSpace {
+public class DeviceCMYKColorSpace extends AbstractDeviceSpecificColorSpace implements ColorSpaceOrigin {
private static final long serialVersionUID = 2925508946083542974L;
@@ -64,13 +64,27 @@ public class DeviceCMYKColorSpace extend
throw new UnsupportedOperationException("NYI");
}
- public static ColorExt createColorExt(float[] cmykComponents) {
+ /**
+ * Creates a color instance representing a device-specific CMYK color. An sRGB value
+ * is calculated from the CMYK colors but it may not correctly represent the given CMYK
+ * values.
+ * @param cmykComponents the CMYK components
+ * @return the device-specific color
+ */
+ public static Color createCMYKColor(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;
+ Color cmykColor = new ColorWithAlternatives(cmykCs, cmykComponents, 1.0f, null);
+ return cmykColor;
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileName() {
+ return PSEUDO_PROFILE_NAME;
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileURI() {
+ return null; //No URI
}
}
Copied: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java (from r960569, xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java?p2=xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java&p1=xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java&r1=960569&r2=961376&rev=961376&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/ICCColorSpaceExt.java Wed Jul 7 13:48:21 2010
@@ -16,7 +16,7 @@
limitations under the License.
*/
-package org.apache.batik.ext.awt.color;
+package org.apache.xmlgraphics.java2d.color;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
@@ -28,10 +28,10 @@ import java.awt.color.ICC_Profile;
* methods, forcing a givent intent, such as perceptual or
* relative colorimetric.
*
- * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
* @version $Id$
*/
-public class ICCColorSpaceExt extends ICC_ColorSpace {
+public class ICCColorSpaceExt extends ICC_ColorSpace implements ColorSpaceOrigin {
+
public static final int PERCEPTUAL = 0;
public static final int RELATIVE_COLORIMETRIC = 1;
public static final int ABSOLUTE_COLORIMETRIC = 2;
@@ -39,9 +39,13 @@ public class ICCColorSpaceExt extends IC
public static final int AUTO = 4;
static final ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
- int intent;
- public ICCColorSpaceExt(ICC_Profile p, int intent){
+ private int intent;
+ private String profileName;
+ private String profileURI;
+
+
+ public ICCColorSpaceExt(ICC_Profile p, int intent, String profileName, String profileURI) {
super(p);
this.intent = intent;
@@ -59,10 +63,13 @@ 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;
}
+
+ this.profileName = profileName;
+ this.profileURI = profileURI;
}
/**
@@ -118,4 +125,15 @@ public class ICCColorSpaceExt extends IC
public float[] saturationToRGB(float[] values){
return perceptualToRGB(values);
}
+
+ /** {@inheritDoc} */
+ public String getProfileName() {
+ return this.profileName;
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileURI() {
+ return this.profileURI;
+ }
+
}
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -27,12 +27,15 @@ import java.awt.color.ColorSpace;
* 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 {
+public class NamedColorSpace extends ColorSpace implements ColorSpaceOrigin {
private static final long serialVersionUID = -8957543225908514658L;
- private String name;
- private float[] xyz;
+ private final String name;
+ private final float[] xyz;
+
+ private final String profileName;
+ private final String profileURI;
/**
* Creates a new named color.
@@ -41,6 +44,18 @@ public class NamedColorSpace extends Col
* values slightly larger than 1.0f are common)
*/
public NamedColorSpace(String name, float[] xyz) {
+ this(name, xyz, null, null);
+ }
+
+ /**
+ * 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)
+ * @param profileName Optional profile name associated with this color space
+ * @param profileURI Optional profile URI associated with this color space
+ */
+ public NamedColorSpace(String name, float[] xyz, String profileName, String profileURI) {
super(ColorSpace.TYPE_GRAY, 1);
checkNumComponents(xyz, 3);
if (name == null || name.trim().length() == 0) {
@@ -49,6 +64,21 @@ public class NamedColorSpace extends Col
this.name = name.trim();
this.xyz = new float[3];
System.arraycopy(xyz, 0, this.xyz, 0, 3);
+ this.profileName = profileName;
+ this.profileURI = profileURI;
+ }
+
+ /**
+ * 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.
+ * @param profileName Optional profile name associated with this color space
+ * @param profileURI Optional profile URI associated with this color space
+ */
+ public NamedColorSpace(String name, Color color, String profileName, String profileURI) {
+ this(name, color.getColorSpace().toCIEXYZ(color.getColorComponents(null)),
+ profileName, profileURI);
}
/**
@@ -58,7 +88,7 @@ public class NamedColorSpace extends Col
* available.
*/
public NamedColorSpace(String name, Color color) {
- this(name, color.getColorSpace().toCIEXYZ(color.getColorComponents(null)));
+ this(name, color.getColorSpace().toCIEXYZ(color.getColorComponents(null)), null, null);
}
private void checkNumComponents(float[] colorvalue, int expected) {
@@ -79,6 +109,16 @@ public class NamedColorSpace extends Col
return this.name;
}
+ /** {@inheritDoc} */
+ public String getProfileName() {
+ return this.profileName;
+ }
+
+ /** {@inheritDoc} */
+ public String getProfileURI() {
+ return this.profileURI;
+ }
+
/**
* Returns the XYZ coordinates of the named color.
* @return the XYZ coordinates of the named color
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java?rev=961376&r1=961375&r2=961376&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java Wed Jul 7 13:48:21 2010
@@ -51,19 +51,32 @@ public class NamedColorProfileParser {
/**
* Parses a named color profile (NCP).
* @param profile the profile to analyze
+ * @param profileName Optional profile name associated with this color profile
+ * @param profileURI Optional profile URI associated with this color profile
* @return an object representing the parsed NCP
* @throws IOException if an I/O error occurs
*/
- public NamedColorProfile parseProfile(ICC_Profile profile) throws IOException {
+ public NamedColorProfile parseProfile(ICC_Profile profile,
+ String profileName, String profileURI) throws IOException {
if (!isNamedColorProfile(profile)) {
throw new IllegalArgumentException("Given profile is not a named color profile (NCP)");
}
String profileDescription = getProfileDescription(profile);
String copyright = getCopyright(profile);
- NamedColorSpace[] ncs = readNamedColors(profile);
+ NamedColorSpace[] ncs = readNamedColors(profile, profileName, profileURI);
return new NamedColorProfile(profileDescription, copyright, ncs);
}
+ /**
+ * Parses a named color profile (NCP).
+ * @param profile the profile to analyze
+ * @return an object representing the parsed NCP
+ * @throws IOException if an I/O error occurs
+ */
+ public NamedColorProfile parseProfile(ICC_Profile profile) throws IOException {
+ return parseProfile(profile, null, null);
+ }
+
private String getProfileDescription(ICC_Profile profile) throws IOException {
byte[] tag = profile.getData(ICC_Profile.icSigProfileDescriptionTag);
return readSimpleString(tag);
@@ -74,7 +87,8 @@ public class NamedColorProfileParser {
return readSimpleString(tag);
}
- private NamedColorSpace[] readNamedColors(ICC_Profile profile) throws IOException {
+ private NamedColorSpace[] readNamedColors(ICC_Profile profile,
+ String profileName, String profileURI) throws IOException {
byte[] tag = profile.getData(ICC_Profile.icSigNamedColor2Tag);
DataInput din = new DataInputStream(new ByteArrayInputStream(tag));
int sig = din.readInt();
@@ -101,13 +115,14 @@ public class NamedColorProfileParser {
switch (profile.getPCSType()) {
case ColorSpace.TYPE_XYZ:
- result[i] = new NamedColorSpace(name, colorvalue);
+ result[i] = new NamedColorSpace(name, colorvalue, profileName, profileURI);
break;
case ColorSpace.TYPE_Lab:
//Not sure if this always D50 here,
//but the illuminant in the header is fixed to D50.
CIELabColorSpace labCS = ColorSpaces.getCIELabColorSpaceD50();
- result[i] = new NamedColorSpace(name, labCS.toColor(colorvalue, 1.0f));
+ result[i] = new NamedColorSpace(name, labCS.toColor(colorvalue, 1.0f),
+ profileName, profileURI);
break;
default:
throw new UnsupportedOperationException(
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java?rev=961376&r1=961375&r2=961376&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/ps/PSGenerator.java Wed Jul 7 13:48:21 2010
@@ -37,8 +37,8 @@ import javax.xml.transform.Source;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.xmlgraphics.java2d.color.ColorExt;
import org.apache.xmlgraphics.java2d.color.ColorUtil;
+import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
/**
@@ -647,10 +647,10 @@ public class PSGenerator implements PSCo
StringBuffer codeBuffer = new StringBuffer();
boolean established = false;
- if (color instanceof ColorExt) {
- ColorExt colExt = (ColorExt)color;
+ if (color instanceof ColorWithAlternatives) {
+ ColorWithAlternatives colExt = (ColorWithAlternatives)color;
//Alternate colors have priority
- Color[] alt = colExt.getAlternateColors();
+ Color[] alt = colExt.getAlternativeColors();
for (int i = 0, c = alt.length; i < c; i++) {
Color col = alt[i];
established = establishColorFromColor(codeBuffer, col);
@@ -686,9 +686,10 @@ public class PSGenerator implements PSCo
codeBuffer.append(formatDouble(comps[i]));
}
codeBuffer.append(" ").append(mapCommand("setcmykcolor"));
- return true;
+ } else {
+ establishDeviceRGB(codeBuffer, color);
}
- return false;
+ return true;
}
private void establishDeviceRGB(StringBuffer codeBuffer, Color color) {
@@ -706,7 +707,7 @@ public class PSGenerator implements PSCo
if (gray) {
codeBuffer.append(formatDouble(comps[0]));
} else {
- for (int i = 0; i < color.getColorSpace().getNumComponents(); i++) {
+ for (int i = 0, c = comps.length; i < c; i++) {
if (i > 0) {
codeBuffer.append(" ");
}
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=961376&r1=961375&r2=961376&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 Wed Jul 7 13:48:21 2010
@@ -31,22 +31,17 @@ public class ColorConverterTest extends
Color rgb = new Color(255, 184, 0);
Color gray = converter.convert(rgb);
- assertEquals(0xFFB9B9B9, gray.getRGB());
-
- ColorExt grayExt = (ColorExt)gray;
- Color[] altArray = grayExt.getAlternateColors();
- assertEquals(1, altArray.length);
- ICCColor alt = (ICCColor)altArray[0];
- assertEquals("#CMYK", alt.getColorProfileName());
- assertNull(alt.getColorProfileSource());
- assertEquals(ColorSpace.TYPE_CMYK, alt.getColorSpace().getType());
- float[] comps = alt.getColorComponents(null);
+ ColorSpaceOrigin origin = ColorSpaces.getColorSpaceOrigin(gray.getColorSpace());
+ assertEquals("#CMYK", origin.getProfileName());
+ assertNull(origin.getProfileURI());
+ assertEquals(ColorSpace.TYPE_CMYK, gray.getColorSpace().getType());
+ float[] comps = gray.getColorComponents(null);
assertEquals(4, comps.length);
assertEquals(0.0f, comps[0], 0.1f);
assertEquals(0.0f, comps[1], 0.1f);
assertEquals(0.0f, comps[2], 0.1f);
assertEquals(0.273f, comps[3], 0.01f);
- assertEquals(0xFFB9B9B9, alt.getRGB());
+ assertEquals(0xFFB9B9B9, gray.getRGB());
}
}
Modified: 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=961376&r1=961375&r2=961376&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/ColorExtTest.java Wed Jul 7 13:48:21 2010
@@ -24,12 +24,12 @@ import java.awt.Color;
import junit.framework.TestCase;
/**
- * Tests the {@link ColorExt} class.
+ * Tests the {@link ColorWithAlternatives} class.
*/
public class ColorExtTest extends TestCase {
public void testEquals() throws Exception {
- Color col1 = new ColorExt(255, 204, 0, null);
+ Color col1 = new ColorWithAlternatives(255, 204, 0, null);
Color col2 = new Color(255, 204, 0);
assertEquals(col1, col2);
@@ -37,7 +37,7 @@ public class ColorExtTest extends TestCa
CIELabColorSpace lab = ColorSpaces.getCIELabColorSpaceD50();
Color postgelbLab = lab.toColor(83.25f, 16.45f, 96.89f, 1.0f);
- col1 = new ColorExt(255, 204, 0, new Color[] {postgelbLab});
+ col1 = new ColorWithAlternatives(255, 204, 0, new Color[] {postgelbLab});
assertFalse(col1.equals(col2));
//Unfortunately, Color.equals() can't detect the color difference!
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org