1 |
771 |
jeremybenn |
/* ICC_ProfileGray.java -- the ICC profile for a Gray colorspace
|
2 |
|
|
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
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., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 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 |
|
|
|
39 |
|
|
package java.awt.color;
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
|
|
* ICC_ProfileGray - a special case of ICC_Profiles.
|
43 |
|
|
*
|
44 |
|
|
* The ICC_Profile.getInstance() method will return an instance of the
|
45 |
|
|
* ICC_ProfileGray subclass when all the following conditions are met:
|
46 |
|
|
* The device color space of the profile is TYPE_GRAY.
|
47 |
|
|
* The profile contains a gray TRCTag.
|
48 |
|
|
* The profile contains a mediaWhitePointTag.
|
49 |
|
|
*
|
50 |
|
|
* As per the ICC specification, the color space conversion can then
|
51 |
|
|
* be done through the following method:
|
52 |
|
|
* linearGray = grayTRC[deviceGray]
|
53 |
|
|
*
|
54 |
|
|
* Note that if the profile contains a CLUT for the color space conversion,
|
55 |
|
|
* it should be used instead, and the TRC information ignored.
|
56 |
|
|
*
|
57 |
|
|
* @author Sven de Marothy
|
58 |
|
|
* @since 1.2
|
59 |
|
|
*/
|
60 |
|
|
public class ICC_ProfileGray extends ICC_Profile
|
61 |
|
|
{
|
62 |
|
|
/**
|
63 |
|
|
* Compatible with JDK 1.2+.
|
64 |
|
|
*/
|
65 |
|
|
private static final long serialVersionUID = -1124721290732002649L;
|
66 |
|
|
private transient float[] whitePoint;
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Package-private constructor used by ICC_ColorSpace for creating an
|
70 |
|
|
* ICC_ProfileGray from a predefined ColorSpace (CS_GRAY)
|
71 |
|
|
*/
|
72 |
|
|
ICC_ProfileGray(int cspace)
|
73 |
|
|
{
|
74 |
|
|
super(cspace);
|
75 |
|
|
whitePoint = getXYZData(icSigMediaWhitePointTag);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Package-private constructor used by ICC_ColorSpace for creating an
|
80 |
|
|
* ICC_ProfileGray from profile data.
|
81 |
|
|
*/
|
82 |
|
|
ICC_ProfileGray(byte[] data)
|
83 |
|
|
{
|
84 |
|
|
super(data);
|
85 |
|
|
whitePoint = getXYZData(icSigMediaWhitePointTag);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Returns the media white point of the profile.
|
91 |
|
|
*/
|
92 |
|
|
public float[] getMediaWhitePoint()
|
93 |
|
|
{
|
94 |
|
|
float[] wp = new float[3];
|
95 |
|
|
wp[0] = whitePoint[0];
|
96 |
|
|
wp[1] = whitePoint[1];
|
97 |
|
|
wp[2] = whitePoint[2];
|
98 |
|
|
return wp;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Returns the TRC gamma value.
|
103 |
|
|
* @throws ProfileDataException if the TRC is described by a lookup
|
104 |
|
|
* table and not a gamma value.
|
105 |
|
|
*/
|
106 |
|
|
public float getGamma()
|
107 |
|
|
{
|
108 |
|
|
short[] data = getCurve(icSigGrayTRCTag);
|
109 |
|
|
if (data == null)
|
110 |
|
|
throw new IllegalArgumentException("Couldn't read Gray TRC data.");
|
111 |
|
|
if (data.length != 1)
|
112 |
|
|
throw new ProfileDataException("TRC is a table, not a gamma value.");
|
113 |
|
|
|
114 |
|
|
// convert the unsigned 7.8 fixed-point gamma to a float.
|
115 |
|
|
double gamma = (double) (data[0] & (0xFFFF)) / 256.0;
|
116 |
|
|
return (float) gamma;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Returns the TRC lookup table.
|
121 |
|
|
* @throws ProfileDataException if the TRC is described by a gamma value
|
122 |
|
|
* and not a lookup table.
|
123 |
|
|
*/
|
124 |
|
|
public short[] getTRC()
|
125 |
|
|
{
|
126 |
|
|
short[] data = getCurve(icSigGrayTRCTag);
|
127 |
|
|
if (data == null)
|
128 |
|
|
throw new IllegalArgumentException("Couldn't read Gray TRC data.");
|
129 |
|
|
if (data.length <= 1)
|
130 |
|
|
throw new ProfileDataException("Gamma value, not a TRC table.");
|
131 |
|
|
return data;
|
132 |
|
|
}
|
133 |
|
|
} // class ICC_ProfileGray
|