1 |
/* ICC_ProfileRGB.java -- the ICC profile for a RGB colorspace |
/* ICC_ProfileRGB.java -- the ICC profile for a RGB colorspace |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
|
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify |
|
|
it under the terms of the GNU General Public License as published by |
|
|
the Free Software Foundation; either version 2, or (at your option) |
|
|
any later version. |
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
General Public License for more details. |
|
|
|
|
|
You should have received a copy of the GNU General Public License |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the |
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
|
02111-1307 USA. |
|
|
|
|
|
Linking this library statically or dynamically with other modules is |
|
|
making a combined work based on this library. Thus, the terms and |
|
|
conditions of the GNU General Public License cover the whole |
|
|
combination. |
|
|
|
|
|
As a special exception, the copyright holders of this library give you |
|
|
permission to link this library with independent modules to produce an |
|
|
executable, regardless of the license terms of these independent |
|
|
modules, and to copy and distribute the resulting executable under |
|
|
terms of your choice, provided that you also meet, for each linked |
|
|
independent module, the terms and conditions of the license of that |
|
|
module. An independent module is a module which is not derived from |
|
|
or based on this library. If you modify this library, you may extend |
|
|
this exception to your version of the library, but you are not |
|
|
obligated to do so. If you do not wish to do so, delete this |
|
|
exception statement from your version. */ |
|
5 |
|
|
6 |
|
GNU Classpath is free software; you can redistribute it and/or modify |
7 |
|
it under the terms of the GNU General Public License as published by |
8 |
|
the Free Software Foundation; either version 2, or (at your option) |
9 |
|
any later version. |
10 |
|
|
11 |
|
GNU Classpath is distributed in the hope that it will be useful, but |
12 |
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
General Public License for more details. |
15 |
|
|
16 |
|
You should have received a copy of the GNU General Public License |
17 |
|
along with GNU Classpath; see the file COPYING. If not, write to the |
18 |
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
|
02111-1307 USA. |
20 |
|
|
21 |
|
Linking this library statically or dynamically with other modules is |
22 |
|
making a combined work based on this library. Thus, the terms and |
23 |
|
conditions of the GNU General Public License cover the whole |
24 |
|
combination. |
25 |
|
|
26 |
|
As a special exception, the copyright holders of this library give you |
27 |
|
permission to link this library with independent modules to produce an |
28 |
|
executable, regardless of the license terms of these independent |
29 |
|
modules, and to copy and distribute the resulting executable under |
30 |
|
terms of your choice, provided that you also meet, for each linked |
31 |
|
independent module, the terms and conditions of the license of that |
32 |
|
module. An independent module is a module which is not derived from |
33 |
|
or based on this library. If you modify this library, you may extend |
34 |
|
this exception to your version of the library, but you are not |
35 |
|
obligated to do so. If you do not wish to do so, delete this |
36 |
|
exception statement from your version. */ |
37 |
|
|
38 |
package java.awt.color; |
package java.awt.color; |
39 |
|
|
40 |
|
import java.nio.ByteBuffer; |
41 |
|
|
42 |
|
|
43 |
/** |
/** |
44 |
* STUBBED |
* ICC_ProfileRGB - a special case of ICC_Profiles. |
45 |
|
* |
46 |
|
* The ICC_Profile.getInstance() method will return an instance of the |
47 |
|
* ICC_ProfileRGB subclass when all the following conditions are met: |
48 |
|
* The device color space of the profile is TYPE_RGB. |
49 |
|
* The profile contains red, green and blue ColorantTags. |
50 |
|
* The profile contains red, green and blue TRCTags. |
51 |
|
* The profile contains a mediaWhitePointTag included. |
52 |
|
* |
53 |
|
* As per the ICC specification, the color space conversion can then |
54 |
|
* be done through the following method: |
55 |
|
* linearR = redTRC[deviceR] |
56 |
|
* linearG = greenTRC[deviceG] |
57 |
|
* linearB = blueTRC[deviceB] |
58 |
|
* TRC curves are either a single gamma value, or a 1-dimensional lookup table. |
59 |
|
* |
60 |
|
* Followed by the matrix transform: |
61 |
|
* PCS = M*linear |
62 |
|
* |
63 |
|
* Where PCS is the vector of profile color space (must be XYZ) coordinates, |
64 |
|
* linear is the vector of linear RGB coordinates, and the matrix M is |
65 |
|
* constructed from the ColorantTags, where the columns are red, green and |
66 |
|
* blue respectively, and the rows are X, Y and Z. |
67 |
|
* |
68 |
|
* Note that if the profile contains a CLUT for the color space conversion, |
69 |
|
* it should be used instead, and the TRC information ignored. |
70 |
|
* |
71 |
|
* @author Sven de Marothy |
72 |
* @since 1.2 |
* @since 1.2 |
73 |
*/ |
*/ |
74 |
public class ICC_ProfileRGB extends ICC_Profile |
public class ICC_ProfileRGB extends ICC_Profile |
79 |
private static final long serialVersionUID = 8505067385152579334L; |
private static final long serialVersionUID = 8505067385152579334L; |
80 |
|
|
81 |
public static final int REDCOMPONENT = 0; |
public static final int REDCOMPONENT = 0; |
82 |
|
|
83 |
public static final int GREENCOMPONENT = 1; |
public static final int GREENCOMPONENT = 1; |
84 |
|
|
85 |
public static final int BLUECOMPONENT = 2; |
public static final int BLUECOMPONENT = 2; |
86 |
|
|
87 |
ICC_ProfileRGB() |
private transient float[][] matrix; |
88 |
|
|
89 |
|
private transient float[] gamma; |
90 |
|
|
91 |
|
private transient float[] whitePoint; |
92 |
|
|
93 |
|
|
94 |
|
/** |
95 |
|
* Package-private constructor used by ICC_ColorSpace for creating an |
96 |
|
* ICC_ProfileRGB from a predefined ColorSpace (CS_LINEAR_RGB and CS_sRGB) |
97 |
|
*/ |
98 |
|
ICC_ProfileRGB(int cspace) |
99 |
|
{ |
100 |
|
super(cspace); |
101 |
|
matrix = createMatrix(); |
102 |
|
whitePoint = getXYZData(icSigMediaWhitePointTag); |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
|
* Package-private constructor used by ICC_ColorSpace for creating an |
107 |
|
* ICC_ProfileRGB from profile data. |
108 |
|
*/ |
109 |
|
ICC_ProfileRGB(byte[] data) |
110 |
{ |
{ |
111 |
super(ColorSpace.CS_sRGB); |
super(data); |
112 |
|
matrix = createMatrix(); |
113 |
|
whitePoint = getXYZData(icSigMediaWhitePointTag); |
114 |
} |
} |
115 |
|
|
116 |
|
/** |
117 |
|
* Returns the media white point of the profile. |
118 |
|
*/ |
119 |
public float[] getMediaWhitePoint() |
public float[] getMediaWhitePoint() |
120 |
{ |
{ |
121 |
return null; |
float[] wp = new float[3]; |
122 |
|
wp[0] = whitePoint[0]; |
123 |
|
wp[1] = whitePoint[1]; |
124 |
|
wp[2] = whitePoint[2]; |
125 |
|
return wp; |
126 |
} |
} |
127 |
|
|
128 |
|
/** |
129 |
|
* Returns the colorant matrix of the conversion. |
130 |
|
*/ |
131 |
public float[][] getMatrix() |
public float[][] getMatrix() |
132 |
{ |
{ |
133 |
return null; |
float[][] mat = new float[3][3]; |
134 |
|
for (int i = 0; i < 3; i++) |
135 |
|
for (int j = 0; j < 3; j++) |
136 |
|
mat[i][j] = matrix[i][j]; |
137 |
|
return mat; |
138 |
} |
} |
139 |
|
|
140 |
|
/** |
141 |
|
* Returns the gamma value of a component |
142 |
|
* @throws ProfileDataException if the TRC is described by a lookup |
143 |
|
* table and not a gamma value. |
144 |
|
*/ |
145 |
public float getGamma(int component) |
public float getGamma(int component) |
146 |
{ |
{ |
147 |
return 0; |
short[] data; |
148 |
|
switch (component) |
149 |
|
{ |
150 |
|
case REDCOMPONENT: |
151 |
|
data = getCurve(icSigRedTRCTag); |
152 |
|
break; |
153 |
|
case GREENCOMPONENT: |
154 |
|
data = getCurve(icSigGreenTRCTag); |
155 |
|
break; |
156 |
|
case BLUECOMPONENT: |
157 |
|
data = getCurve(icSigBlueTRCTag); |
158 |
|
break; |
159 |
|
default: |
160 |
|
throw new IllegalArgumentException("Not a valid component"); |
161 |
|
} |
162 |
|
if (data == null) |
163 |
|
throw new IllegalArgumentException("Error reading TRC"); |
164 |
|
|
165 |
|
if (data.length != 1) |
166 |
|
throw new ProfileDataException("Not a single-gamma TRC"); |
167 |
|
|
168 |
|
// convert the unsigned 7.8 fixed-point gamma to a float. |
169 |
|
float gamma = (float) (((int) data[0] & 0xFF00) >> 8); |
170 |
|
double fraction = ((int) data[0] & 0x00FF) / 256.0; |
171 |
|
gamma += (float) fraction; |
172 |
|
return gamma; |
173 |
} |
} |
174 |
|
|
175 |
|
/** |
176 |
|
* Returns the TRC lookup table for a component |
177 |
|
* @throws ProfileDataException if the TRC is described by a gamma |
178 |
|
* value and not a lookup table. |
179 |
|
*/ |
180 |
public short[] getTRC(int component) |
public short[] getTRC(int component) |
181 |
{ |
{ |
182 |
return null; |
short[] data; |
183 |
|
switch (component) |
184 |
|
{ |
185 |
|
case REDCOMPONENT: |
186 |
|
data = getCurve(icSigRedTRCTag); |
187 |
|
break; |
188 |
|
case GREENCOMPONENT: |
189 |
|
data = getCurve(icSigGreenTRCTag); |
190 |
|
break; |
191 |
|
case BLUECOMPONENT: |
192 |
|
data = getCurve(icSigBlueTRCTag); |
193 |
|
break; |
194 |
|
default: |
195 |
|
throw new IllegalArgumentException("Not a valid component"); |
196 |
|
} |
197 |
|
if (data == null) |
198 |
|
throw new IllegalArgumentException("Error reading TRC"); |
199 |
|
|
200 |
|
if (data.length <= 1) |
201 |
|
throw new ProfileDataException("Gamma value, not a TRC table."); |
202 |
|
|
203 |
|
return data; |
204 |
|
} |
205 |
|
|
206 |
|
/** |
207 |
|
* Creates the colorspace conversion matrix from the RGB tristimulus |
208 |
|
* values. |
209 |
|
*/ |
210 |
|
private float[][] createMatrix() throws IllegalArgumentException |
211 |
|
{ |
212 |
|
float[][] mat = new float[3][3]; |
213 |
|
float[] r; |
214 |
|
float[] g; |
215 |
|
float[] b; |
216 |
|
r = getXYZData(icSigRedColorantTag); |
217 |
|
g = getXYZData(icSigGreenColorantTag); |
218 |
|
b = getXYZData(icSigBlueColorantTag); |
219 |
|
if (r == null || g == null || b == null) |
220 |
|
throw new IllegalArgumentException("Error reading colorant tags!"); |
221 |
|
for (int i = 0; i < 3; i++) |
222 |
|
{ |
223 |
|
mat[i][0] = r[i]; |
224 |
|
mat[i][1] = g[i]; |
225 |
|
mat[i][2] = b[i]; |
226 |
|
} |
227 |
|
return mat; |
228 |
} |
} |
229 |
} // class ICC_ProfileRGB |
} // class ICC_ProfileRGB |