1 /* ICC_ProfileRGB.java -- the ICC profile for a RGB colorspace
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package java
.awt
.color
;
42 * ICC_ProfileRGB - a special case of ICC_Profiles.
44 * The ICC_Profile.getInstance() method will return an instance of the
45 * ICC_ProfileRGB subclass when all the following conditions are met:
46 * The device color space of the profile is TYPE_RGB.
47 * The profile contains red, green and blue ColorantTags.
48 * The profile contains red, green and blue TRCTags.
49 * The profile contains a mediaWhitePointTag included.
51 * As per the ICC specification, the color space conversion can then
52 * be done through the following method:
53 * linearR = redTRC[deviceR]
54 * linearG = greenTRC[deviceG]
55 * linearB = blueTRC[deviceB]
56 * TRC curves are either a single gamma value, or a 1-dimensional lookup table.
58 * Followed by the matrix transform:
61 * Where PCS is the vector of profile color space (must be XYZ) coordinates,
62 * linear is the vector of linear RGB coordinates, and the matrix M is
63 * constructed from the ColorantTags, where the columns are red, green and
64 * blue respectively, and the rows are X, Y and Z.
66 * Note that if the profile contains a CLUT for the color space conversion,
67 * it should be used instead, and the TRC information ignored.
69 * @author Sven de Marothy
72 public class ICC_ProfileRGB
extends ICC_Profile
75 * Compatible with JDK 1.2+.
77 private static final long serialVersionUID
= 8505067385152579334L;
79 public static final int REDCOMPONENT
= 0;
81 public static final int GREENCOMPONENT
= 1;
83 public static final int BLUECOMPONENT
= 2;
85 private transient float[][] matrix
;
87 private transient float[] gamma
;
89 private transient float[] whitePoint
;
93 * Package-private constructor used by ICC_ColorSpace for creating an
94 * ICC_ProfileRGB from a predefined ColorSpace (CS_LINEAR_RGB and CS_sRGB)
96 ICC_ProfileRGB(int cspace
)
99 matrix
= createMatrix();
100 whitePoint
= getXYZData(icSigMediaWhitePointTag
);
104 * Package-private constructor used by ICC_ColorSpace for creating an
105 * ICC_ProfileRGB from profile data.
107 ICC_ProfileRGB(byte[] data
)
110 matrix
= createMatrix();
111 whitePoint
= getXYZData(icSigMediaWhitePointTag
);
115 * Returns the media white point of the profile.
117 public float[] getMediaWhitePoint()
119 float[] wp
= new float[3];
120 wp
[0] = whitePoint
[0];
121 wp
[1] = whitePoint
[1];
122 wp
[2] = whitePoint
[2];
127 * Returns the colorant matrix of the conversion.
129 public float[][] getMatrix()
131 float[][] mat
= new float[3][3];
132 for (int i
= 0; i
< 3; i
++)
133 for (int j
= 0; j
< 3; j
++)
134 mat
[i
][j
] = matrix
[i
][j
];
139 * Returns the gamma value of a component
140 * @throws ProfileDataException if the TRC is described by a lookup
141 * table and not a gamma value.
143 public float getGamma(int component
)
149 data
= getCurve(icSigRedTRCTag
);
152 data
= getCurve(icSigGreenTRCTag
);
155 data
= getCurve(icSigBlueTRCTag
);
158 throw new IllegalArgumentException("Not a valid component");
161 throw new IllegalArgumentException("Error reading TRC");
163 if (data
.length
!= 1)
164 throw new ProfileDataException("Not a single-gamma TRC");
166 // convert the unsigned 7.8 fixed-point gamma to a float.
167 float gamma
= (float) (((int) data
[0] & 0xFF00) >> 8);
168 double fraction
= ((int) data
[0] & 0x00FF) / 256.0;
169 gamma
+= (float) fraction
;
174 * Returns the TRC lookup table for a component
175 * @throws ProfileDataException if the TRC is described by a gamma
176 * value and not a lookup table.
178 public short[] getTRC(int component
)
184 data
= getCurve(icSigRedTRCTag
);
187 data
= getCurve(icSigGreenTRCTag
);
190 data
= getCurve(icSigBlueTRCTag
);
193 throw new IllegalArgumentException("Not a valid component");
196 throw new IllegalArgumentException("Error reading TRC");
198 if (data
.length
<= 1)
199 throw new ProfileDataException("Gamma value, not a TRC table.");
205 * Creates the colorspace conversion matrix from the RGB tristimulus
208 private float[][] createMatrix() throws IllegalArgumentException
210 float[][] mat
= new float[3][3];
214 r
= getXYZData(icSigRedColorantTag
);
215 g
= getXYZData(icSigGreenColorantTag
);
216 b
= getXYZData(icSigBlueColorantTag
);
217 if (r
== null || g
== null || b
== null)
218 throw new IllegalArgumentException("Error reading colorant tags!");
219 for (int i
= 0; i
< 3; i
++)
227 } // class ICC_ProfileRGB