1 7 8 package java.awt.image; 9 10 11 26 public class ByteLookupTable extends LookupTable { 27 28 31 32 byte data[][]; 33 34 49 public ByteLookupTable(int offset, byte data[][]) { 50 super(offset,data.length); 51 numComponents = data.length; 52 numEntries = data[0].length; 53 this.data = new byte[numComponents][]; 54 for (int i=0; i < numComponents; i++) { 56 this.data[i] = data[i]; 57 } 58 } 59 60 73 public ByteLookupTable(int offset, byte data[]) { 74 super(offset,data.length); 75 numComponents = 1; 76 numEntries = data.length; 77 this.data = new byte[1][]; 78 this.data[0] = data; 79 } 80 81 87 public final byte[][] getTable(){ 88 return data; 89 } 90 91 110 public int[] lookupPixel(int[] src, int[] dst){ 111 if (dst == null) { 112 dst = new int[src.length]; 114 } 115 116 if (numComponents == 1) { 117 for (int i=0; i < src.length; i++) { 119 int s = src[i] - offset; 120 if (s < 0) { 121 throw new ArrayIndexOutOfBoundsException ("src["+i+ 122 "]-offset is "+ 123 "less than zero"); 124 } 125 dst[i] = (int) data[0][s]; 126 } 127 } 128 else { 129 for (int i=0; i < src.length; i++) { 130 int s = src[i] - offset; 131 if (s < 0) { 132 throw new ArrayIndexOutOfBoundsException ("src["+i+ 133 "]-offset is "+ 134 "less than zero"); 135 } 136 dst[i] = (int) data[i][s]; 137 } 138 } 139 return dst; 140 } 141 142 161 public byte[] lookupPixel(byte[] src, byte[] dst){ 162 if (dst == null) { 163 dst = new byte[src.length]; 165 } 166 167 if (numComponents == 1) { 168 for (int i=0; i < src.length; i++) { 170 int s = (src[i]&0xff) - offset; 171 if (s < 0) { 172 throw new ArrayIndexOutOfBoundsException ("src["+i+ 173 "]-offset is "+ 174 "less than zero"); 175 } 176 dst[i] = data[0][s]; 177 } 178 } 179 else { 180 for (int i=0; i < src.length; i++) { 181 int s = (src[i]&0xff) - offset; 182 if (s < 0) { 183 throw new ArrayIndexOutOfBoundsException ("src["+i+ 184 "]-offset is "+ 185 "less than zero"); 186 } 187 dst[i] = data[i][s]; 188 } 189 } 190 return dst; 191 } 192 193 } 194 | Popular Tags |