KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > color > ICCColorSpaceExt


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.color;
19
20 import java.awt.color.ColorSpace JavaDoc;
21 import java.awt.color.ICC_ColorSpace JavaDoc;
22 import java.awt.color.ICC_Profile JavaDoc;
23
24 /**
25  * This class extends the ICCColorSpace class by providing
26  * convenience methods to convert to sRGB using various
27  * methods, forcing a givent intent, such as perceptual or
28  * relative colorimetric.
29  *
30  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
31  * @version $Id: ICCColorSpaceExt.java,v 1.4 2004/08/18 07:13:45 vhardy Exp $
32  */

33 public class ICCColorSpaceExt extends ICC_ColorSpace JavaDoc {
34     public static final int PERCEPTUAL = 0;
35     public static final int RELATIVE_COLORIMETRIC = 1;
36     public static final int ABSOLUTE_COLORIMETRIC = 2;
37     public static final int SATURATION = 3;
38     public static final int AUTO = 4;
39
40     static final ColorSpace JavaDoc sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
41     int intent;
42     
43     public ICCColorSpaceExt(ICC_Profile JavaDoc p, int intent){
44         super(p);
45
46         this.intent = intent;
47         switch(intent){
48         case AUTO:
49         case RELATIVE_COLORIMETRIC:
50         case ABSOLUTE_COLORIMETRIC:
51         case SATURATION:
52         case PERCEPTUAL:
53             break;
54         default:
55             throw new IllegalArgumentException JavaDoc();
56         }
57
58         /**
59          * Apply the requested intent into the profile
60          */

61         if(intent != AUTO){
62             byte[] hdr = p.getData(ICC_Profile.icSigHead);
63             hdr[ICC_Profile.icHdrRenderingIntent] = (byte)intent;
64         }
65     }
66
67     /**
68      * Returns the sRGB value obtained by forcing the
69      * conversion method to the intent passed to the
70      * constructor
71      */

72     public float[] intendedToRGB(float[] values){
73         switch(intent){
74             case ABSOLUTE_COLORIMETRIC:
75             return absoluteColorimetricToRGB(values);
76             case PERCEPTUAL:
77             case AUTO:
78             return perceptualToRGB(values);
79             case RELATIVE_COLORIMETRIC:
80             return relativeColorimetricToRGB(values);
81             case SATURATION:
82             return saturationToRGB(values);
83             default:
84             throw new Error JavaDoc();
85         }
86     }
87
88     /**
89      * Perceptual conversion is the method implemented by the
90      * base class's toRGB method
91      */

92     public float[] perceptualToRGB(float[] values){
93         return toRGB(values);
94     }
95
96     /**
97      * Relative colorimetric needs to happen through CIEXYZ
98      * conversion
99      */

100     public float[] relativeColorimetricToRGB(float[] values){
101         float[] ciexyz = toCIEXYZ(values);
102         return sRGB.fromCIEXYZ(ciexyz);
103     }
104
105     /**
106      * Absolute colorimetric. NOT IMPLEMENTED.
107      * Temporarily returns same as perceptual
108      */

109     public float[] absoluteColorimetricToRGB(float[] values){
110         return perceptualToRGB(values);
111     }
112
113     /**
114      * Saturation. NOT IMPLEMENTED. Temporarily returns same
115      * as perceptual.
116      */

117     public float[] saturationToRGB(float[] values){
118         return perceptualToRGB(values);
119     }
120 }
121
Popular Tags