1 7 8 17 18 package com.sun.image.codec.jpeg; 19 20 21 22 32 public class JPEGQTable { 33 34 35 private int quantval[]; 36 37 38 private static final byte QTABLESIZE = 64; 39 40 46 public static final JPEGQTable StdLuminance = new JPEGQTable(); 47 static { 48 int [] lumVals = { 49 16, 11, 12, 14, 12, 10, 16, 14, 50 13, 14, 18, 17, 16, 19, 24, 40, 51 26, 24, 22, 22, 24, 49, 35, 37, 52 29, 40, 58, 51, 61, 60, 57, 51, 53 56, 55, 64, 72, 92, 78, 64, 68, 54 87, 69, 55, 56, 80, 109, 81, 87, 55 95, 98, 103, 104, 103, 62, 77, 113, 56 121, 112, 100, 120, 92, 101, 103, 99 57 }; 58 59 StdLuminance.quantval = lumVals; 60 } 61 62 68 public static final JPEGQTable StdChrominance = new JPEGQTable(); 69 static { 70 int [] chromVals = { 71 17, 18, 18, 24, 21, 24, 47, 26, 72 26, 47, 99, 66, 56, 66, 99, 99, 73 99, 99, 99, 99, 99, 99, 99, 99, 74 99, 99, 99, 99, 99, 99, 99, 99, 75 99, 99, 99, 99, 99, 99, 99, 99, 76 99, 99, 99, 99, 99, 99, 99, 99, 77 99, 99, 99, 99, 99, 99, 99, 99, 78 99, 99, 99, 99, 99, 99, 99, 99 79 }; 80 StdChrominance.quantval = chromVals; 81 } 82 83 84 88 private JPEGQTable() { 89 quantval = new int[QTABLESIZE]; 90 } 91 92 98 public JPEGQTable( int table[] ) { 99 if ( table.length != QTABLESIZE ) { 100 throw new IllegalArgumentException 101 ("Quantization table is the wrong size."); 102 } else { 103 quantval = new int[QTABLESIZE]; 104 System.arraycopy( table, 0, quantval, 0, QTABLESIZE ); 105 } 106 } 107 108 109 114 public int[] getTable() { 115 int[] table = new int[QTABLESIZE]; 116 System.arraycopy( quantval, 0, table, 0, QTABLESIZE ); 117 return table; 118 } 119 120 134 public JPEGQTable getScaledInstance(float scaleFactor, 135 boolean forceBaseline ) { 136 long max = (forceBaseline)?255L:32767L; 137 int []ret = new int[QTABLESIZE]; 138 139 for (int i=0; i<QTABLESIZE; i++ ) { 140 long holder = (long)((quantval[i] * scaleFactor) + 0.5); 141 142 if (holder <= 0L) holder = 1L; 144 145 if (holder > max ) holder = max; 147 148 ret[i] = (int)holder; 149 } 150 return new JPEGQTable(ret); 151 } 152 } 153 | Popular Tags |