1 7 8 package com.sun.imageio.plugins.common; 9 10 import java.awt.color.ColorSpace ; 11 12 16 public class BogusColorSpace extends ColorSpace { 17 25 private static int getType(int numComponents) { 26 if(numComponents < 1) { 27 throw new IllegalArgumentException ("numComponents < 1!"); 28 } 29 30 int type; 31 switch(numComponents) { 32 case 1: 33 type = ColorSpace.TYPE_GRAY; 34 break; 35 default: 36 type = numComponents + 10; 40 } 41 42 return type; 43 } 44 45 53 public BogusColorSpace(int numComponents) { 54 super(getType(numComponents), numComponents); 55 } 56 57 63 public float[] toRGB(float[] colorvalue) { 64 if(colorvalue.length < getNumComponents()) { 65 throw new ArrayIndexOutOfBoundsException 66 ("colorvalue.length < getNumComponents()"); 67 } 68 69 float[] rgbvalue = new float[3]; 70 71 System.arraycopy(colorvalue, 0, rgbvalue, 0, 72 Math.min(3, getNumComponents())); 73 74 return colorvalue; 75 } 76 77 public float[] fromRGB(float[] rgbvalue) { 78 if(rgbvalue.length < 3) { 79 throw new ArrayIndexOutOfBoundsException 80 ("rgbvalue.length < 3"); 81 } 82 83 float[] colorvalue = new float[getNumComponents()]; 84 85 System.arraycopy(rgbvalue, 0, colorvalue, 0, 86 Math.min(3, colorvalue.length)); 87 88 return rgbvalue; 89 } 90 91 public float[] toCIEXYZ(float[] colorvalue) { 92 if(colorvalue.length < getNumComponents()) { 93 throw new ArrayIndexOutOfBoundsException 94 ("colorvalue.length < getNumComponents()"); 95 } 96 97 float[] xyzvalue = new float[3]; 98 99 System.arraycopy(colorvalue, 0, xyzvalue, 0, 100 Math.min(3, getNumComponents())); 101 102 return colorvalue; 103 } 104 105 public float[] fromCIEXYZ(float[] xyzvalue) { 106 if(xyzvalue.length < 3) { 107 throw new ArrayIndexOutOfBoundsException 108 ("xyzvalue.length < 3"); 109 } 110 111 float[] colorvalue = new float[getNumComponents()]; 112 113 System.arraycopy(xyzvalue, 0, colorvalue, 0, 114 Math.min(3, colorvalue.length)); 115 116 return xyzvalue; 117 } 118 } 119 | Popular Tags |