001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.ext.awt.color;
020:
021: import java.awt.color.ColorSpace;
022: import java.awt.color.ICC_ColorSpace;
023: import java.awt.color.ICC_Profile;
024:
025: /**
026: * This class extends the ICCColorSpace class by providing
027: * convenience methods to convert to sRGB using various
028: * methods, forcing a givent intent, such as perceptual or
029: * relative colorimetric.
030: *
031: * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
032: * @version $Id: ICCColorSpaceExt.java 504084 2007-02-06 11:24:46Z dvholten $
033: */
034: public class ICCColorSpaceExt extends ICC_ColorSpace {
035: public static final int PERCEPTUAL = 0;
036: public static final int RELATIVE_COLORIMETRIC = 1;
037: public static final int ABSOLUTE_COLORIMETRIC = 2;
038: public static final int SATURATION = 3;
039: public static final int AUTO = 4;
040:
041: static final ColorSpace sRGB = ColorSpace
042: .getInstance(ColorSpace.CS_sRGB);
043: int intent;
044:
045: public ICCColorSpaceExt(ICC_Profile p, int intent) {
046: super (p);
047:
048: this .intent = intent;
049: switch (intent) {
050: case AUTO:
051: case RELATIVE_COLORIMETRIC:
052: case ABSOLUTE_COLORIMETRIC:
053: case SATURATION:
054: case PERCEPTUAL:
055: break;
056: default:
057: throw new IllegalArgumentException();
058: }
059:
060: /**
061: * Apply the requested intent into the profile
062: */
063: if (intent != AUTO) {
064: byte[] hdr = p.getData(ICC_Profile.icSigHead);
065: hdr[ICC_Profile.icHdrRenderingIntent] = (byte) intent;
066: }
067: }
068:
069: /**
070: * Returns the sRGB value obtained by forcing the
071: * conversion method to the intent passed to the
072: * constructor
073: */
074: public float[] intendedToRGB(float[] values) {
075: switch (intent) {
076: case ABSOLUTE_COLORIMETRIC:
077: return absoluteColorimetricToRGB(values);
078: case PERCEPTUAL:
079: case AUTO:
080: return perceptualToRGB(values);
081: case RELATIVE_COLORIMETRIC:
082: return relativeColorimetricToRGB(values);
083: case SATURATION:
084: return saturationToRGB(values);
085: default:
086: throw new Error("invalid intent:" + intent);
087: }
088: }
089:
090: /**
091: * Perceptual conversion is the method implemented by the
092: * base class's toRGB method
093: */
094: public float[] perceptualToRGB(float[] values) {
095: return toRGB(values);
096: }
097:
098: /**
099: * Relative colorimetric needs to happen through CIEXYZ
100: * conversion
101: */
102: public float[] relativeColorimetricToRGB(float[] values) {
103: float[] ciexyz = toCIEXYZ(values);
104: return sRGB.fromCIEXYZ(ciexyz);
105: }
106:
107: /**
108: * Absolute colorimetric. NOT IMPLEMENTED.
109: * Temporarily returns same as perceptual
110: */
111: public float[] absoluteColorimetricToRGB(float[] values) {
112: return perceptualToRGB(values);
113: }
114:
115: /**
116: * Saturation. NOT IMPLEMENTED. Temporarily returns same
117: * as perceptual.
118: */
119: public float[] saturationToRGB(float[] values) {
120: return perceptualToRGB(values);
121: }
122: }
|