1 7 8 17 18 package javax.imageio.plugins.jpeg; 19 20 34 public class JPEGQTable { 35 36 37 private int[] table; 38 39 40 private static final byte QTABLESIZE = 64; 41 42 49 public static final JPEGQTable K1Luminance = new JPEGQTable (); 50 static { 51 int [] lumVals = { 52 16, 11, 10, 16, 24, 40, 51, 61, 53 12, 12, 14, 19, 26, 58, 60, 55, 54 14, 13, 16, 24, 40, 57, 69, 56, 55 14, 17, 22, 29, 51, 87, 80, 62, 56 18, 22, 37, 56, 68, 109, 103, 77, 57 24, 35, 55, 64, 81, 104, 113, 92, 58 49, 64, 78, 87, 103, 121, 120, 101, 59 72, 92, 95, 98, 112, 100, 103, 99 60 }; 61 62 K1Luminance.table = lumVals; 63 } 64 65 75 public static final JPEGQTable K1Div2Luminance = 76 K1Luminance.getScaledInstance(0.5f, true); 77 78 85 public static final JPEGQTable K2Chrominance = new JPEGQTable (); 86 static { 87 int [] chromVals = { 88 17, 18, 24, 47, 99, 99, 99, 99, 89 18, 21, 26, 66, 99, 99, 99, 99, 90 24, 26, 56, 99, 99, 99, 99, 99, 91 47, 66, 99, 99, 99, 99, 99, 99, 92 99, 99, 99, 99, 99, 99, 99, 99, 93 99, 99, 99, 99, 99, 99, 99, 99, 94 99, 99, 99, 99, 99, 99, 99, 99, 95 99, 99, 99, 99, 99, 99, 99, 99 96 }; 97 K2Chrominance.table = chromVals; 98 } 99 100 110 public static final JPEGQTable K2Div2Chrominance = 111 K2Chrominance.getScaledInstance(0.5f, true); 112 113 117 private JPEGQTable() {} 118 119 131 public JPEGQTable(int[] table) { 132 if (table == null) { 133 throw new IllegalArgumentException ("table == null!"); 134 } 135 if (table.length != QTABLESIZE) { 136 throw new IllegalArgumentException 137 ("Quantization table is the wrong size."); 138 } 139 140 this.table = (int[])table.clone(); 141 } 142 143 149 public int[] getTable() { 150 return (int[])table.clone(); 151 } 152 153 170 public JPEGQTable getScaledInstance(float scaleFactor, 171 boolean forceBaseline) { 172 int max = (forceBaseline) ? 255 : 32767; 173 int[] ret = new int[QTABLESIZE]; 174 175 for (int i = 0; i < QTABLESIZE; i++) { 176 float scaledValue = (float)Math.round(table[i]*scaleFactor); 177 int holder; 178 179 if (scaledValue <= 1.0F) { 181 holder = 1; 182 } else if (scaledValue >= max) { 183 holder = max; 184 } else { 185 holder = (int)scaledValue; 186 } 187 ret[i] = holder; 188 } 189 190 return new JPEGQTable (ret); 191 } 192 193 public String toString() { 194 StringBuffer sb = new StringBuffer (); 195 sb.append("JPEGQTable:\n"); 196 for (int i = 0; i< 8; i++) { 197 sb.append('\t'); 198 for (int j = 0; j < 8; j++) { 199 sb.append(table[i]).append(" "); 200 } 201 sb.append('\n'); 202 } 203 return sb.toString(); 204 } 205 } 206 | Popular Tags |