1 |
771 |
jeremybenn |
/* ColorSpace.java -- transforms between color spaces
|
2 |
|
|
Copyright (C) 2000, 2002 Free Software Foundation
|
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 |
|
|
import java.io.Serializable;
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* NEEDS DOCUMENTATION
|
45 |
|
|
*
|
46 |
|
|
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
47 |
|
|
* @since 1.2
|
48 |
|
|
*/
|
49 |
|
|
public abstract class ColorSpace implements Serializable
|
50 |
|
|
{
|
51 |
|
|
/**
|
52 |
|
|
* Compatible with JDK 1.2+.
|
53 |
|
|
*/
|
54 |
|
|
private static final long serialVersionUID = -409452704308689724L;
|
55 |
|
|
|
56 |
|
|
public static final int TYPE_XYZ = 0;
|
57 |
|
|
public static final int TYPE_Lab = 1;
|
58 |
|
|
public static final int TYPE_Luv = 2;
|
59 |
|
|
public static final int TYPE_YCbCr = 3;
|
60 |
|
|
public static final int TYPE_Yxy = 4;
|
61 |
|
|
public static final int TYPE_RGB = 5;
|
62 |
|
|
public static final int TYPE_GRAY = 6;
|
63 |
|
|
public static final int TYPE_HSV = 7;
|
64 |
|
|
public static final int TYPE_HLS = 8;
|
65 |
|
|
public static final int TYPE_CMYK = 9;
|
66 |
|
|
// mysterious gap in the enumeration sequenece
|
67 |
|
|
public static final int TYPE_CMY = 11;
|
68 |
|
|
public static final int TYPE_2CLR = 12;
|
69 |
|
|
public static final int TYPE_3CLR = 13;
|
70 |
|
|
public static final int TYPE_4CLR = 14;
|
71 |
|
|
public static final int TYPE_5CLR = 15;
|
72 |
|
|
public static final int TYPE_6CLR = 16;
|
73 |
|
|
public static final int TYPE_7CLR = 17;
|
74 |
|
|
public static final int TYPE_8CLR = 18;
|
75 |
|
|
public static final int TYPE_9CLR = 19;
|
76 |
|
|
public static final int TYPE_ACLR = 20;
|
77 |
|
|
public static final int TYPE_BCLR = 21;
|
78 |
|
|
public static final int TYPE_CCLR = 22;
|
79 |
|
|
public static final int TYPE_DCLR = 23;
|
80 |
|
|
public static final int TYPE_ECLR = 24;
|
81 |
|
|
public static final int TYPE_FCLR = 25;
|
82 |
|
|
|
83 |
|
|
public static final int CS_sRGB = 1000;
|
84 |
|
|
public static final int CS_LINEAR_RGB = 1004;
|
85 |
|
|
public static final int CS_CIEXYZ = 1001;
|
86 |
|
|
public static final int CS_PYCC = 1002;
|
87 |
|
|
public static final int CS_GRAY = 1003;
|
88 |
|
|
|
89 |
|
|
private static final int CS_BASE = CS_sRGB;
|
90 |
|
|
private static final int CS_END = CS_LINEAR_RGB + 1;
|
91 |
|
|
private static final int CS_COUNT = CS_END - CS_BASE;
|
92 |
|
|
|
93 |
|
|
// Instances are lazily instantiated
|
94 |
|
|
private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT];
|
95 |
|
|
|
96 |
|
|
/**
|
97 |
|
|
* @serial
|
98 |
|
|
*/
|
99 |
|
|
// Visible in subclass.
|
100 |
|
|
final int type;
|
101 |
|
|
|
102 |
|
|
/**
|
103 |
|
|
* @serial
|
104 |
|
|
*/
|
105 |
|
|
// Visible in subclass.
|
106 |
|
|
final int numComponents;
|
107 |
|
|
|
108 |
|
|
protected ColorSpace(int type, int numcomponents)
|
109 |
|
|
{
|
110 |
|
|
this.type = type;
|
111 |
|
|
numComponents = numcomponents;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
public static ColorSpace getInstance(int colorspace)
|
115 |
|
|
{
|
116 |
|
|
if ((colorspace >= CS_BASE) && (colorspace < CS_END))
|
117 |
|
|
{
|
118 |
|
|
int instanceIndex = colorspace - CS_BASE;
|
119 |
|
|
if (INSTANCES[instanceIndex] == null)
|
120 |
|
|
{
|
121 |
|
|
ICC_Profile profile = new ICC_Profile(colorspace);
|
122 |
|
|
INSTANCES[instanceIndex] = new ICC_ColorSpace(profile);
|
123 |
|
|
}
|
124 |
|
|
return INSTANCES[instanceIndex];
|
125 |
|
|
}
|
126 |
|
|
throw new IllegalArgumentException("unknown/unsupported colorspace");
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
public boolean isCS_sRGB()
|
130 |
|
|
{
|
131 |
|
|
return type == CS_sRGB;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
/**
|
135 |
|
|
* Transforms a color value assumed to be in this ColorSpace into a value in
|
136 |
|
|
* the default CS_sRGB color space.
|
137 |
|
|
*
|
138 |
|
|
* @exception ArrayIndexOutOfBoundsException If array length is not at least
|
139 |
|
|
* the number of components in this ColorSpace.
|
140 |
|
|
*/
|
141 |
|
|
public abstract float[] toRGB(float[] colorvalue);
|
142 |
|
|
|
143 |
|
|
public abstract float[] fromRGB(float[] rgbvalue);
|
144 |
|
|
|
145 |
|
|
public abstract float[] toCIEXYZ(float[] colorvalue);
|
146 |
|
|
|
147 |
|
|
public abstract float[] fromCIEXYZ(float[] colorvalue);
|
148 |
|
|
|
149 |
|
|
public int getType()
|
150 |
|
|
{
|
151 |
|
|
return type;
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
public int getNumComponents()
|
155 |
|
|
{
|
156 |
|
|
return numComponents;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
public String getName(int idx)
|
160 |
|
|
{
|
161 |
|
|
return "type " + type;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
/**
|
165 |
|
|
* @since 1.4
|
166 |
|
|
*/
|
167 |
|
|
public float getMinValue(int idx)
|
168 |
|
|
{
|
169 |
|
|
if (idx < 0 || idx >= numComponents)
|
170 |
|
|
throw new IllegalArgumentException();
|
171 |
|
|
return 0;
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
|
|
* @since 1.4
|
176 |
|
|
*/
|
177 |
|
|
public float getMaxValue(int idx)
|
178 |
|
|
{
|
179 |
|
|
if (idx < 0 || idx >= numComponents)
|
180 |
|
|
throw new IllegalArgumentException();
|
181 |
|
|
return 1;
|
182 |
|
|
}
|
183 |
|
|
} // class ColorSpace
|