Merge from the pain train
[official-gcc.git] / libjava / java / awt / color / ColorSpace.java
blobdd7121ec0bfb5792c5ca33450eb969b2d37a5f80
1 /* ColorSpace.java -- transforms between color spaces
2 Copyright (C) 2000, 2002 Free Software Foundation
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)
9 any later version.
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
19 02111-1307 USA.
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.
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;
41 import java.io.Serializable;
43 /**
44 * NEEDS DOCUMENTATION
46 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
47 * @since 1.2
49 public abstract class ColorSpace implements Serializable
51 /**
52 * Compatible with JDK 1.2+.
54 private static final long serialVersionUID = -409452704308689724L;
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;
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;
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;
93 // Instances are lazily instantiated
94 private static final ColorSpace[] INSTANCES = new ColorSpace[CS_COUNT];
96 /**
97 * @serial
99 // Visible in subclass.
100 final int type;
103 * @serial
105 // Visible in subclass.
106 final int numComponents;
108 protected ColorSpace(int type, int numcomponents)
110 this.type = type;
111 numComponents = numcomponents;
114 public static ColorSpace getInstance(int colorspace)
116 if ((colorspace >= CS_BASE) && (colorspace < CS_END))
118 int instanceIndex = colorspace - CS_BASE;
119 if (INSTANCES[instanceIndex] == null)
121 ICC_Profile profile = new ICC_Profile(colorspace);
122 INSTANCES[instanceIndex] = new ICC_ColorSpace(profile);
124 return INSTANCES[instanceIndex];
126 throw new IllegalArgumentException("unknown/unsupported colorspace");
129 public boolean isCS_sRGB()
131 return type == CS_sRGB;
135 * Transforms a color value assumed to be in this ColorSpace into a value in
136 * the default CS_sRGB color space.
138 * @exception ArrayIndexOutOfBoundsException If array length is not at least
139 * the number of components in this ColorSpace.
141 public abstract float[] toRGB(float[] colorvalue);
143 public abstract float[] fromRGB(float[] rgbvalue);
145 public abstract float[] toCIEXYZ(float[] colorvalue);
147 public abstract float[] fromCIEXYZ(float[] colorvalue);
149 public int getType()
151 return type;
154 public int getNumComponents()
156 return numComponents;
159 public String getName(int idx)
161 return "type " + type;
165 * @since 1.4
167 public float getMinValue(int idx)
169 if (idx < 0 || idx >= numComponents)
170 throw new IllegalArgumentException();
171 return 0;
175 * @since 1.4
177 public float getMaxValue(int idx)
179 if (idx < 0 || idx >= numComponents)
180 throw new IllegalArgumentException();
181 return 1;
183 } // class ColorSpace