1 |
/* Copyright (C) 2000, 2002 Free Software Foundation |
/* ColorSpace.java -- transforms between color spaces |
2 |
|
Copyright (C) 2000, 2002 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
package java.awt.color; |
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> |
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no> |
47 |
|
* @since 1.2 |
48 |
*/ |
*/ |
49 |
public abstract class ColorSpace |
public abstract class ColorSpace |
50 |
{ |
{ |
51 |
public static final int TYPE_XYZ = 0; |
/** |
52 |
public static final int TYPE_Lab = 1; |
* Compatible with JDK 1.2+. |
53 |
public static final int TYPE_Luv = 2; |
*/ |
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; |
public static final int TYPE_YCbCr = 3; |
60 |
public static final int TYPE_Yxy = 4; |
public static final int TYPE_Yxy = 4; |
61 |
public static final int TYPE_RGB = 5; |
public static final int TYPE_RGB = 5; |
62 |
public static final int TYPE_GRAY = 6; |
public static final int TYPE_GRAY = 6; |
63 |
public static final int TYPE_HSV = 7; |
public static final int TYPE_HSV = 7; |
64 |
public static final int TYPE_HLS = 8; |
public static final int TYPE_HLS = 8; |
65 |
public static final int TYPE_CMYK = 9; |
public static final int TYPE_CMYK = 9; |
66 |
// mysterious gap in the enumeration sequenece |
// mysterious gap in the enumeration sequenece |
67 |
public static final int TYPE_CMY = 11; |
public static final int TYPE_CMY = 11; |
68 |
public static final int TYPE_2CLR = 12; |
public static final int TYPE_2CLR = 12; |
69 |
public static final int TYPE_3CLR = 13; |
public static final int TYPE_3CLR = 13; |
70 |
public static final int TYPE_4CLR = 14; |
public static final int TYPE_4CLR = 14; |
79 |
public static final int TYPE_DCLR = 23; |
public static final int TYPE_DCLR = 23; |
80 |
public static final int TYPE_ECLR = 24; |
public static final int TYPE_ECLR = 24; |
81 |
public static final int TYPE_FCLR = 25; |
public static final int TYPE_FCLR = 25; |
82 |
|
|
83 |
public static final int CS_sRGB = 1000; |
public static final int CS_sRGB = 1000; |
|
public static final int CS_CIEXYZ = 1001; |
|
|
public static final int CS_PYCC = 1002; |
|
|
public static final int CS_GRAY = 1003; |
|
84 |
public static final int CS_LINEAR_RGB = 1004; |
public static final int CS_LINEAR_RGB = 1004; |
85 |
|
public static final int CS_CIEXYZ = 1001; |
86 |
private static final int CS_BASE = CS_sRGB; |
public static final int CS_PYCC = 1002; |
87 |
private static final int CS_END = CS_LINEAR_RGB+1; |
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; |
private static final int CS_COUNT = CS_END - CS_BASE; |
92 |
|
|
93 |
// Instances are lazily instantiated |
// Instances are lazily instantiated |
94 |
private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT]; |
private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT]; |
95 |
|
|
96 |
private int type; |
/** |
97 |
private int numcomponents; |
* @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) |
protected ColorSpace(int type, int numcomponents) |
109 |
{ |
{ |
110 |
this.type = type; |
this.type = type; |
111 |
this.numcomponents = numcomponents; |
numComponents = numcomponents; |
112 |
} |
} |
113 |
|
|
114 |
public static ColorSpace getInstance(int colorspace) |
public static ColorSpace getInstance(int colorspace) |
115 |
{ |
{ |
116 |
if ((colorspace >= CS_BASE) && (colorspace < CS_END)) |
if ((colorspace >= CS_BASE) && (colorspace < CS_END)) |
117 |
{ |
{ |
118 |
int instanceIndex = colorspace - CS_BASE; |
int instanceIndex = colorspace - CS_BASE; |
119 |
if (INSTANCES[instanceIndex] == null) |
if (INSTANCES[instanceIndex] == null) |
120 |
{ |
{ |
121 |
ICC_Profile profile = new ICC_Profile(colorspace); |
ICC_Profile profile = new ICC_Profile(colorspace); |
122 |
INSTANCES[instanceIndex] = new ICC_ColorSpace(profile); |
INSTANCES[instanceIndex] = new ICC_ColorSpace(profile); |
123 |
} |
} |
124 |
return INSTANCES[instanceIndex]; |
return INSTANCES[instanceIndex]; |
125 |
} |
} |
126 |
throw new IllegalArgumentException("unknown/unsupported colorspace"); |
throw new IllegalArgumentException("unknown/unsupported colorspace"); |
127 |
} |
} |
128 |
|
|
129 |
public boolean isCS_sRGB() |
public boolean isCS_sRGB() |
130 |
{ |
{ |
131 |
return false; |
return false; |
132 |
} |
} |
133 |
|
|
134 |
public abstract float[] toRGB(float[] colorvalue); |
public abstract float[] toRGB(float[] colorvalue); |
135 |
|
|
136 |
public abstract float[] fromRGB(float[] rgbvalue); |
public abstract float[] fromRGB(float[] rgbvalue); |
137 |
|
|
138 |
public abstract float[] toCIEXYZ(float[] colorvalue); |
public abstract float[] toCIEXYZ(float[] colorvalue); |
139 |
|
|
140 |
public abstract float[] fromCIEXYZ(float[] colorvalue); |
public abstract float[] fromCIEXYZ(float[] colorvalue); |
141 |
|
|
142 |
public int getType() |
public int getType() |
146 |
|
|
147 |
public int getNumComponents() |
public int getNumComponents() |
148 |
{ |
{ |
149 |
return numcomponents; |
return numComponents; |
150 |
} |
} |
151 |
|
|
152 |
public String getName(int idx) |
public String getName(int idx) |
153 |
{ |
{ |
154 |
return "type " + type; |
return "type " + type; |
155 |
} |
} |
156 |
|
|
157 |
public String toString() |
/** |
158 |
{ |
* @since 1.4 |
159 |
return getClass().getName() + "[type=" + type + "]"; |
*/ |
160 |
|
public float getMinValue(int idx) |
161 |
|
{ |
162 |
|
if (idx < 0 || idx >= numComponents) |
163 |
|
throw new IllegalArgumentException(); |
164 |
|
return 0; |
165 |
|
} |
166 |
|
|
167 |
|
/** |
168 |
|
* @since 1.4 |
169 |
|
*/ |
170 |
|
public float getMaxValue(int idx) |
171 |
|
{ |
172 |
|
if (idx < 0 || idx >= numComponents) |
173 |
|
throw new IllegalArgumentException(); |
174 |
|
return 1; |
175 |
} |
} |
176 |
} |
} // class ColorSpace |