KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > color > ICC_ProfileRGB


1 /*
2  * @(#)ICC_ProfileRGB.java 1.22 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /**********************************************************************
9  **********************************************************************
10  **********************************************************************
11  *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
12  *** As an unpublished work pursuant to Title 17 of the United ***
13  *** States Code. All rights reserved. ***
14  **********************************************************************
15  **********************************************************************
16  **********************************************************************/

17
18 package java.awt.color;
19
20 import java.awt.image.LookupTable JavaDoc;
21 import sun.awt.color.ProfileDeferralInfo;
22
23 /**
24  *
25  * The ICC_ProfileRGB class is a subclass of the ICC_Profile class
26  * that represents profiles which meet the following criteria:
27  * <ul>
28  * <li>The profile's color space type is RGB.</li>
29  * <li>The profile includes the <code>redColorantTag</code>,
30  * <code>greenColorantTag</code>, <code>blueColorantTag</code>,
31  * <code>redTRCTag</code>, <code>greenTRCTag</code>,
32  * <code>blueTRCTag</code>, and <code>mediaWhitePointTag</code> tags.</li>
33  * </ul>
34  * The <code>ICC_Profile</code> <code>getInstance</code> method will
35  * return an <code>ICC_ProfileRGB</code> object when these conditions are met.
36  * Three-component, matrix-based input profiles and RGB display profiles are
37  * examples of this type of profile.
38  * <p>
39  * This profile class provides color transform matrices and lookup tables
40  * that Java or native methods can use directly to
41  * optimize color conversion in some cases.
42  * <p>
43  * To transform from a device profile color space to the CIEXYZ Profile
44  * Connection Space, each device color component is first linearized by
45  * a lookup through the corresponding tone reproduction curve (TRC).
46  * The resulting linear RGB components are converted to the CIEXYZ PCS
47  * using a a 3x3 matrix constructed from the RGB colorants.
48  * <pre>
49  *
50  * &nbsp; linearR = redTRC[deviceR]
51  *
52  * &nbsp; linearG = greenTRC[deviceG]
53  *
54  * &nbsp; linearB = blueTRC[deviceB]
55  *
56  * &nbsp; _ _ _ _ _ _
57  * &nbsp;[ PCSX ] [ redColorantX greenColorantX blueColorantX ] [ linearR ]
58  * &nbsp;[ ] [ ] [ ]
59  * &nbsp;[ PCSY ] = [ redColorantY greenColorantY blueColorantY ] [ linearG ]
60  * &nbsp;[ ] [ ] [ ]
61  * &nbsp;[_ PCSZ _] [_ redColorantZ greenColorantZ blueColorantZ _] [_ linearB _]
62  *
63  * </pre>
64  * The inverse transform is performed by converting PCS XYZ components to linear
65  * RGB components through the inverse of the above 3x3 matrix, and then converting
66  * linear RGB to device RGB through inverses of the TRCs.
67  * <p>
68  */

69
70
71
72 public class ICC_ProfileRGB
73 extends ICC_Profile JavaDoc {
74
75     /**
76      * Used to get a gamma value or TRC for the red component.
77      */

78     public static final int REDCOMPONENT = 0;
79
80     /**
81      * Used to get a gamma value or TRC for the green component.
82      */

83     public static final int GREENCOMPONENT = 1;
84
85     /**
86      * Used to get a gamma value or TRC for the blue component.
87      */

88     public static final int BLUECOMPONENT = 2;
89
90
91     /**
92      * Constructs an new <code>ICC_ProfileRGB</code> from a CMM ID.
93      *
94      * @param ID The CMM ID for the profile.
95      *
96      */

97     ICC_ProfileRGB(long ID) {
98         super(ID);
99     }
100
101     /**
102      * Constructs a new <code>ICC_ProfileRGB</code> from a
103      * ProfileDeferralInfo object.
104      *
105      * @param pdi
106      */

107     ICC_ProfileRGB(ProfileDeferralInfo pdi) {
108         super(pdi);
109     }
110
111
112     /**
113      * Returns an array that contains the components of the profile's
114      * <CODE>mediaWhitePointTag</CODE>.
115      *
116      * @return A 3-element <CODE>float</CODE> array containing the x, y,
117      * and z components of the profile's <CODE>mediaWhitePointTag</CODE>.
118      */

119     public float[] getMediaWhitePoint() {
120         return super.getMediaWhitePoint();
121     }
122
123
124     /**
125      * Returns a 3x3 <CODE>float</CODE> matrix constructed from the
126      * X, Y, and Z components of the profile's <CODE>redColorantTag</CODE>,
127      * <CODE>greenColorantTag</CODE>, and <CODE>blueColorantTag</CODE>.
128      * <p>
129      * This matrix can be used for color transforms in the forward
130      * direction of the profile--from the profile color space
131      * to the CIEXYZ PCS.
132      *
133      * @return A 3x3 <CODE>float</CODE> array that contains the x, y, and z
134      * components of the profile's <CODE>redColorantTag</CODE>,
135      * <CODE>greenColorantTag</CODE>, and <CODE>blueColorantTag</CODE>.
136      */

137     public float[][] getMatrix() {
138         float[][] theMatrix = new float[3][3];
139         float[] tmpMatrix;
140
141         tmpMatrix = getXYZTag(ICC_Profile.icSigRedColorantTag);
142         theMatrix[0][0] = tmpMatrix[0];
143         theMatrix[1][0] = tmpMatrix[1];
144         theMatrix[2][0] = tmpMatrix[2];
145         tmpMatrix = getXYZTag(ICC_Profile.icSigGreenColorantTag);
146         theMatrix[0][1] = tmpMatrix[0];
147         theMatrix[1][1] = tmpMatrix[1];
148         theMatrix[2][1] = tmpMatrix[2];
149         tmpMatrix = getXYZTag(ICC_Profile.icSigBlueColorantTag);
150         theMatrix[0][2] = tmpMatrix[0];
151         theMatrix[1][2] = tmpMatrix[1];
152         theMatrix[2][2] = tmpMatrix[2];
153         return theMatrix;
154     }
155
156     /**
157      * Returns a gamma value representing the tone reproduction curve
158      * (TRC) for a particular component. The component parameter
159      * must be one of REDCOMPONENT, GREENCOMPONENT, or BLUECOMPONENT.
160      * <p>
161      * If the profile
162      * represents the TRC for the corresponding component
163      * as a table rather than a single gamma value, an
164      * exception is thrown. In this case the actual table
165      * can be obtained through the {@link #getTRC(int)} method.
166      * When using a gamma value,
167      * the linear component (R, G, or B) is computed as follows:
168      * <pre>
169      *
170      * &nbsp; gamma
171      * &nbsp; linearComponent = deviceComponent
172      *
173      *</pre>
174      * @param component The <CODE>ICC_ProfileRGB</CODE> constant that
175      * represents the component whose TRC you want to retrieve
176      * @return the gamma value as a float.
177      * @exception ProfileDataException if the profile does not specify
178      * the corresponding TRC as a single gamma value.
179      */

180     public float getGamma(int component) {
181     float theGamma;
182     int theSignature;
183
184         switch (component) {
185         case REDCOMPONENT:
186             theSignature = ICC_Profile.icSigRedTRCTag;
187             break;
188
189         case GREENCOMPONENT:
190             theSignature = ICC_Profile.icSigGreenTRCTag;
191             break;
192
193         case BLUECOMPONENT:
194             theSignature = ICC_Profile.icSigBlueTRCTag;
195             break;
196
197         default:
198             throw new IllegalArgumentException JavaDoc("Must be Red, Green, or Blue");
199         }
200
201         theGamma = super.getGamma(theSignature);
202
203         return theGamma;
204     }
205
206     /**
207      * Returns the TRC for a particular component as an array.
208      * Component must be <code>REDCOMPONENT</code>,
209      * <code>GREENCOMPONENT</code>, or <code>BLUECOMPONENT</code>.
210      * Otherwise the returned array
211      * represents a lookup table where the input component value
212      * is conceptually in the range [0.0, 1.0]. Value 0.0 maps
213      * to array index 0 and value 1.0 maps to array index length-1.
214      * Interpolation might be used to generate output values for
215      * input values that do not map exactly to an index in the
216      * array. Output values also map linearly to the range [0.0, 1.0].
217      * Value 0.0 is represented by an array value of 0x0000 and
218      * value 1.0 by 0xFFFF. In other words, the values are really unsigned
219      * <code>short</code> values even though they are returned in a
220      * <code>short</code> array.
221      *
222      * If the profile has specified the corresponding TRC
223      * as linear (gamma = 1.0) or as a simple gamma value, this method
224      * throws an exception. In this case, the {@link #getGamma(int)}
225      * method should be used to get the gamma value.
226      *
227      * @param component The <CODE>ICC_ProfileRGB</CODE> constant that
228      * represents the component whose TRC you want to retrieve:
229      * <CODE>REDCOMPONENT</CODE>, <CODE>GREENCOMPONENT</CODE>, or
230      * <CODE>BLUECOMPONENT</CODE>.
231      *
232      * @return a short array representing the TRC.
233      * @exception ProfileDataException if the profile does not specify
234      * the corresponding TRC as a table.
235      */

236     public short[] getTRC(int component) {
237     short[] theTRC;
238     int theSignature;
239
240         switch (component) {
241         case REDCOMPONENT:
242             theSignature = ICC_Profile.icSigRedTRCTag;
243             break;
244
245         case GREENCOMPONENT:
246             theSignature = ICC_Profile.icSigGreenTRCTag;
247             break;
248
249         case BLUECOMPONENT:
250             theSignature = ICC_Profile.icSigBlueTRCTag;
251             break;
252
253         default:
254             throw new IllegalArgumentException JavaDoc("Must be Red, Green, or Blue");
255         }
256
257         theTRC = super.getTRC(theSignature);
258
259         return theTRC;
260     }
261
262 }
263
264
Popular Tags