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/12/10 16:25:21 UTC
svn commit: r1044400 - in /xmlgraphics/commons/branches/Temp_Color:
src/java/org/apache/xmlgraphics/java2d/color/
src/java/org/apache/xmlgraphics/java2d/color/profile/
test/java/org/apache/xmlgraphics/java2d/color/profile/
Author: jeremias
Date: Fri Dec 10 15:25:20 2010
New Revision: 1044400
URL: http://svn.apache.org/viewvc?rev=1044400&view=rev
Log:
Switch to enum for named color profiles.
Modified:
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/RenderingIntent.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java
xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParser.java
xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/RenderingIntent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/RenderingIntent.java?rev=1044400&r1=1044399&r2=1044400&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/RenderingIntent.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/RenderingIntent.java Fri Dec 10 15:25:20 2010
@@ -19,19 +19,21 @@
package org.apache.xmlgraphics.java2d.color;
+import java.awt.color.ICC_Profile;
+
/**
* Enumeration for rendering intents.
*/
public enum RenderingIntent {
/** Perceptual rendering intent. Typical use: scanned images. */
- PERCEPTUAL(0),
+ PERCEPTUAL(ICC_Profile.icPerceptual),
/** Relative colorimetric rendering intent. Typical use: vector graphics. */
- RELATIVE_COLORIMETRIC(1),
+ RELATIVE_COLORIMETRIC(ICC_Profile.icRelativeColorimetric),
/** Absolute colorimetric rendering intent. Typical use: logos and solid colors. */
- ABSOLUTE_COLORIMETRIC(2),
+ ABSOLUTE_COLORIMETRIC(ICC_Profile.icAbsoluteColorimetric),
/** Saturation rendering intent. Typical use: business graphics. */
- SATURATION(3),
+ SATURATION(ICC_Profile.icSaturation),
/** Automatic rendering intent. The color profile's intent isn't overridden. */
AUTO(4);
@@ -43,11 +45,28 @@ public enum RenderingIntent {
/**
* Returns an integer value identifying the rendering intent. This is the same value defined
- * by the ICC specification (0..3) plus one for "auto" (4).
+ * by the ICC specification (0..3) plus one for "auto" (4). (See also {@link ICC_Profile}.ic*)
* @return the integer value
*/
public int getIntegerValue() {
return this.intValue;
}
+ /**
+ * Returns the enum value for the given integer rendering intent (as defined by the ICC
+ * specification).
+ * @param value the rendering intent as ICC value
+ * @return the matching enum
+ */
+ public static RenderingIntent fromICCValue(int value) {
+ switch (value) {
+ case ICC_Profile.icPerceptual: return PERCEPTUAL;
+ case ICC_Profile.icRelativeColorimetric: return RELATIVE_COLORIMETRIC;
+ case ICC_Profile.icAbsoluteColorimetric: return ABSOLUTE_COLORIMETRIC;
+ case ICC_Profile.icSaturation: return SATURATION;
+ default:
+ throw new IllegalArgumentException("Invalid value for rendering intent: " + value);
+ }
+ }
+
}
Modified: xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java?rev=1044400&r1=1044399&r2=1044400&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/src/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfile.java Fri Dec 10 15:25:20 2010
@@ -22,6 +22,7 @@ package org.apache.xmlgraphics.java2d.co
import java.awt.color.ICC_Profile;
import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
/**
* Simplified in-memory representation of an ICC named color profile.
@@ -31,25 +32,28 @@ public class NamedColorProfile {
private String profileName;
private String copyright;
private NamedColorSpace[] namedColors;
- private int renderingIntent = ICC_Profile.icPerceptual;
+ private RenderingIntent renderingIntent = RenderingIntent.PERCEPTUAL;
/**
* Creates a new named color profile.
* @param profileName the profile name
* @param copyright the copyright
* @param namedColors the array of named colors
+ * @param intent the rendering intent
*/
- public NamedColorProfile(String profileName, String copyright, NamedColorSpace[] namedColors) {
+ public NamedColorProfile(String profileName, String copyright, NamedColorSpace[] namedColors,
+ RenderingIntent intent) {
this.profileName = profileName;
this.copyright = copyright;
this.namedColors = namedColors;
+ this.renderingIntent = intent;
}
/**
* Returns the color profile's rendering intent.
* @return the rendering intent (See {@link ICC_Profile}.ic*)
*/
- public int getRenderingIntent() {
+ public RenderingIntent getRenderingIntent() {
return this.renderingIntent;
}
@@ -96,6 +100,7 @@ public class NamedColorProfile {
}
/** {@inheritDoc} */
+ @Override
public String toString() {
StringBuffer sb = new StringBuffer("Named color profile: ");
sb.append(getProfileName());
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=1044400&r1=1044399&r2=1044400&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 Fri Dec 10 15:25:20 2010
@@ -29,6 +29,7 @@ import java.io.IOException;
import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
import org.apache.xmlgraphics.java2d.color.ColorSpaces;
import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
/**
* This class is a parser for ICC named color profiles. It uses Java's {@link ICC_Profile} class
@@ -63,8 +64,9 @@ public class NamedColorProfileParser {
}
String profileDescription = getProfileDescription(profile);
String copyright = getCopyright(profile);
+ RenderingIntent intent = getRenderingIntent(profile);
NamedColorSpace[] ncs = readNamedColors(profile, profileName, profileURI);
- return new NamedColorProfile(profileDescription, copyright, ncs);
+ return new NamedColorProfile(profileDescription, copyright, ncs, intent);
}
/**
@@ -87,6 +89,12 @@ public class NamedColorProfileParser {
return readSimpleString(tag);
}
+ private RenderingIntent getRenderingIntent(ICC_Profile profile) throws IOException {
+ byte[] hdr = profile.getData(ICC_Profile.icSigHead);
+ int value = hdr[ICC_Profile.icHdrRenderingIntent];
+ return RenderingIntent.fromICCValue(value);
+ }
+
private NamedColorSpace[] readNamedColors(ICC_Profile profile,
String profileName, String profileURI) throws IOException {
byte[] tag = profile.getData(ICC_Profile.icSigNamedColor2Tag);
Modified: xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java?rev=1044400&r1=1044399&r2=1044400&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java (original)
+++ xmlgraphics/commons/branches/Temp_Color/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java Fri Dec 10 15:25:20 2010
@@ -27,6 +27,7 @@ import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.RenderingIntent;
/**
* Tests the {@link NamedColorProfileParser}.
@@ -48,7 +49,7 @@ public class NamedColorProfileParserTest
NamedColorProfile ncp = parser.parseProfile(iccProfile);
assertEquals("Named Color Profile Example", ncp.getProfileName());
assertEquals("The Apache Software Foundation", ncp.getCopyright());
- assertEquals(ICC_Profile.icPerceptual, ncp.getRenderingIntent());
+ assertEquals(RenderingIntent.PERCEPTUAL, ncp.getRenderingIntent());
NamedColorSpace[] namedColors = ncp.getNamedColors();
assertEquals(2, namedColors.length);
NamedColorSpace ncs;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org