1 7 8 17 18 package java.awt.color; 19 20 import sun.awt.color.CMM; 21 22 23 77 78 79 80 public abstract class ColorSpace implements java.io.Serializable { 81 82 static final long serialVersionUID = -409452704308689724L; 83 84 private int type; 85 private int numComponents; 86 87 private static ColorSpace sRGBspace; 89 private static ColorSpace XYZspace; 90 private static ColorSpace PYCCspace; 91 private static ColorSpace GRAYspace; 92 private static ColorSpace LINEAR_RGBspace; 93 94 97 public static final int TYPE_XYZ = 0; 98 99 102 public static final int TYPE_Lab = 1; 103 104 107 public static final int TYPE_Luv = 2; 108 109 112 public static final int TYPE_YCbCr = 3; 113 114 117 public static final int TYPE_Yxy = 4; 118 119 122 public static final int TYPE_RGB = 5; 123 124 127 public static final int TYPE_GRAY = 6; 128 129 132 public static final int TYPE_HSV = 7; 133 134 137 public static final int TYPE_HLS = 8; 138 139 142 public static final int TYPE_CMYK = 9; 143 144 147 public static final int TYPE_CMY = 11; 148 149 152 public static final int TYPE_2CLR = 12; 153 154 157 public static final int TYPE_3CLR = 13; 158 159 162 public static final int TYPE_4CLR = 14; 163 164 167 public static final int TYPE_5CLR = 15; 168 169 172 public static final int TYPE_6CLR = 16; 173 174 177 public static final int TYPE_7CLR = 17; 178 179 182 public static final int TYPE_8CLR = 18; 183 184 187 public static final int TYPE_9CLR = 19; 188 189 192 public static final int TYPE_ACLR = 20; 193 194 197 public static final int TYPE_BCLR = 21; 198 199 202 public static final int TYPE_CCLR = 22; 203 204 207 public static final int TYPE_DCLR = 23; 208 209 212 public static final int TYPE_ECLR = 24; 213 214 217 public static final int TYPE_FCLR = 25; 218 219 225 public static final int CS_sRGB = 1000; 226 227 231 public static final int CS_LINEAR_RGB = 1004; 232 233 236 public static final int CS_CIEXYZ = 1001; 237 238 241 public static final int CS_PYCC = 1002; 242 243 246 public static final int CS_GRAY = 1003; 247 248 249 255 protected ColorSpace (int type, int numcomponents) { 256 this.type = type; 257 this.numComponents = numcomponents; 258 } 259 260 261 269 public static ColorSpace getInstance (int colorspace) 272 { 273 ColorSpace theColorSpace; 274 275 switch (colorspace) { 276 case CS_sRGB: 277 synchronized(ColorSpace .class) { 278 if (sRGBspace == null) { 279 ICC_Profile theProfile = ICC_Profile.getInstance (CS_sRGB); 280 sRGBspace = new ICC_ColorSpace (theProfile); 281 } 282 283 theColorSpace = sRGBspace; 284 } 285 break; 286 287 case CS_CIEXYZ: 288 synchronized(ColorSpace .class) { 289 if (XYZspace == null) { 290 ICC_Profile theProfile = 291 ICC_Profile.getInstance (CS_CIEXYZ); 292 XYZspace = new ICC_ColorSpace (theProfile); 293 } 294 295 theColorSpace = XYZspace; 296 } 297 break; 298 299 case CS_PYCC: 300 synchronized(ColorSpace .class) { 301 if (PYCCspace == null) { 302 ICC_Profile theProfile = ICC_Profile.getInstance (CS_PYCC); 303 PYCCspace = new ICC_ColorSpace (theProfile); 304 } 305 306 theColorSpace = PYCCspace; 307 } 308 break; 309 310 311 case CS_GRAY: 312 synchronized(ColorSpace .class) { 313 if (GRAYspace == null) { 314 ICC_Profile theProfile = ICC_Profile.getInstance (CS_GRAY); 315 GRAYspace = new ICC_ColorSpace (theProfile); 316 317 CMM.GRAYspace = GRAYspace; 318 } 319 320 theColorSpace = GRAYspace; 321 } 322 break; 323 324 325 case CS_LINEAR_RGB: 326 synchronized(ColorSpace .class) { 327 if (LINEAR_RGBspace == null) { 328 ICC_Profile theProfile = 329 ICC_Profile.getInstance(CS_LINEAR_RGB); 330 LINEAR_RGBspace = new ICC_ColorSpace (theProfile); 331 332 CMM.LINEAR_RGBspace = LINEAR_RGBspace; 333 } 334 335 theColorSpace = LINEAR_RGBspace; 336 } 337 break; 338 339 340 default: 341 throw new IllegalArgumentException ("Unknown color space"); 342 } 343 344 return theColorSpace; 345 } 346 347 348 353 public boolean isCS_sRGB () { 354 355 return (this == sRGBspace); 356 } 357 358 379 public abstract float[] toRGB(float[] colorvalue); 380 381 382 403 public abstract float[] fromRGB(float[] rgbvalue); 404 405 406 430 public abstract float[] toCIEXYZ(float[] colorvalue); 431 432 433 458 public abstract float[] fromCIEXYZ(float[] colorvalue); 459 460 472 public int getType() { 473 return type; 474 } 475 476 480 public int getNumComponents() { 481 return numComponents; 482 } 483 484 492 public String getName (int idx) { 493 494 if ((idx < 0) || (idx > numComponents - 1)) { 495 throw new IllegalArgumentException ( 496 "Component index out of range: " + idx); 497 } 498 return new String ("Unnamed color component("+idx+")"); 499 } 500 501 513 public float getMinValue(int component) { 514 if ((component < 0) || (component > numComponents - 1)) { 515 throw new IllegalArgumentException ( 516 "Component index out of range: " + component); 517 } 518 return 0.0f; 519 } 520 521 533 public float getMaxValue(int component) { 534 if ((component < 0) || (component > numComponents - 1)) { 535 throw new IllegalArgumentException ( 536 "Component index out of range: " + component); 537 } 538 return 1.0f; 539 } 540 541 543 static boolean isCS_CIEXYZ(ColorSpace cspace) { 544 return (cspace == XYZspace); 545 } 546 } 547 | Popular Tags |