001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Oleg V. Khaschansky
019: * @version $Revision$
020: */package java.awt.color;
021:
022: import java.io.Serializable;
023:
024: import org.apache.harmony.awt.gl.color.LUTColorConverter;
025: import org.apache.harmony.awt.internal.nls.Messages;
026:
027: public abstract class ColorSpace implements Serializable {
028:
029: private static final long serialVersionUID = -409452704308689724L;
030:
031: public static final int TYPE_XYZ = 0;
032:
033: public static final int TYPE_Lab = 1;
034:
035: public static final int TYPE_Luv = 2;
036:
037: public static final int TYPE_YCbCr = 3;
038:
039: public static final int TYPE_Yxy = 4;
040:
041: public static final int TYPE_RGB = 5;
042:
043: public static final int TYPE_GRAY = 6;
044:
045: public static final int TYPE_HSV = 7;
046:
047: public static final int TYPE_HLS = 8;
048:
049: public static final int TYPE_CMYK = 9;
050:
051: public static final int TYPE_CMY = 11;
052:
053: public static final int TYPE_2CLR = 12;
054:
055: public static final int TYPE_3CLR = 13;
056:
057: public static final int TYPE_4CLR = 14;
058:
059: public static final int TYPE_5CLR = 15;
060:
061: public static final int TYPE_6CLR = 16;
062:
063: public static final int TYPE_7CLR = 17;
064:
065: public static final int TYPE_8CLR = 18;
066:
067: public static final int TYPE_9CLR = 19;
068:
069: public static final int TYPE_ACLR = 20;
070:
071: public static final int TYPE_BCLR = 21;
072:
073: public static final int TYPE_CCLR = 22;
074:
075: public static final int TYPE_DCLR = 23;
076:
077: public static final int TYPE_ECLR = 24;
078:
079: public static final int TYPE_FCLR = 25;
080:
081: public static final int CS_sRGB = 1000;
082:
083: public static final int CS_LINEAR_RGB = 1004;
084:
085: public static final int CS_CIEXYZ = 1001;
086:
087: public static final int CS_PYCC = 1002;
088:
089: public static final int CS_GRAY = 1003;
090:
091: private static ColorSpace cs_Gray = null;
092: private static ColorSpace cs_PYCC = null;
093: private static ColorSpace cs_CIEXYZ = null;
094: private static ColorSpace cs_LRGB = null;
095: private static ColorSpace cs_sRGB = null;
096:
097: private int type;
098: private int numComponents;
099:
100: protected ColorSpace(int type, int numcomponents) {
101: this .numComponents = numcomponents;
102: this .type = type;
103: }
104:
105: public String getName(int idx) {
106: if (idx < 0 || idx > numComponents - 1) {
107: // awt.16A=Invalid component index: {0}
108: throw new IllegalArgumentException(Messages.getString(
109: "awt.16A", idx)); //$NON-NLS-1$
110: }
111:
112: return "Unnamed color component #" + idx; //$NON-NLS-1$
113: }
114:
115: public abstract float[] toRGB(float[] colorvalue);
116:
117: public abstract float[] toCIEXYZ(float[] colorvalue);
118:
119: public abstract float[] fromRGB(float[] rgbvalue);
120:
121: public abstract float[] fromCIEXYZ(float[] colorvalue);
122:
123: public float getMinValue(int component) {
124: if (component < 0 || component > numComponents - 1) {
125: // awt.16A=Invalid component index: {0}
126: throw new IllegalArgumentException(Messages.getString(
127: "awt.16A", component)); //$NON-NLS-1$
128: }
129: return 0;
130: }
131:
132: public float getMaxValue(int component) {
133: if (component < 0 || component > numComponents - 1) {
134: // awt.16A=Invalid component index: {0}
135: throw new IllegalArgumentException(Messages.getString(
136: "awt.16A", component)); //$NON-NLS-1$
137: }
138: return 1;
139: }
140:
141: public boolean isCS_sRGB() {
142: // If our color space is sRGB, then cs_sRGB
143: // is already initialized
144: return (this == cs_sRGB);
145: }
146:
147: public int getType() {
148: return type;
149: }
150:
151: public int getNumComponents() {
152: return numComponents;
153: }
154:
155: public static ColorSpace getInstance(int colorspace) {
156: switch (colorspace) {
157: case CS_sRGB:
158: if (cs_sRGB == null) {
159: cs_sRGB = new ICC_ColorSpace(new ICC_ProfileStub(
160: CS_sRGB));
161: LUTColorConverter.sRGB_CS = cs_sRGB;
162: //ICC_Profile.getInstance (CS_sRGB));
163: }
164: return cs_sRGB;
165: case CS_CIEXYZ:
166: if (cs_CIEXYZ == null) {
167: cs_CIEXYZ = new ICC_ColorSpace(new ICC_ProfileStub(
168: CS_CIEXYZ));
169: //ICC_Profile.getInstance (CS_CIEXYZ));
170: }
171: return cs_CIEXYZ;
172: case CS_GRAY:
173: if (cs_Gray == null) {
174: cs_Gray = new ICC_ColorSpace(new ICC_ProfileStub(
175: CS_GRAY));
176: LUTColorConverter.LINEAR_GRAY_CS = cs_Gray;
177: //ICC_Profile.getInstance (CS_GRAY));
178: }
179: return cs_Gray;
180: case CS_PYCC:
181: if (cs_PYCC == null) {
182: cs_PYCC = new ICC_ColorSpace(new ICC_ProfileStub(
183: CS_PYCC));
184: //ICC_Profile.getInstance (CS_PYCC));
185: }
186: return cs_PYCC;
187: case CS_LINEAR_RGB:
188: if (cs_LRGB == null) {
189: cs_LRGB = new ICC_ColorSpace(new ICC_ProfileStub(
190: CS_LINEAR_RGB));
191: LUTColorConverter.LINEAR_GRAY_CS = cs_Gray;
192: //ICC_Profile.getInstance (CS_LINEAR_RGB));
193: }
194: return cs_LRGB;
195: default:
196: }
197:
198: // Unknown argument passed
199: // awt.16B=Not a predefined colorspace
200: throw new IllegalArgumentException(Messages
201: .getString("awt.16B")); //$NON-NLS-1$
202: }
203: }
|