< prev index next >

src/java.desktop/share/native/libjavajpeg/jdphuff.c

Print this page




 198 
 199 
 200 /*
 201  * Figure F.12: extend sign bit.
 202  * On some machines, a shift and add will be faster than a table lookup.
 203  */
 204 
 205 #ifdef AVOID_TABLES
 206 
 207 #define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
 208 
 209 #else
 210 
 211 #define HUFF_EXTEND(x,s)  ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
 212 
 213 static const int extend_test[16] =   /* entry n is 2**(n-1) */
 214   { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
 215     0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
 216 
 217 static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
 218   { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
 219     ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
 220     ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
 221     ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };





 222 
 223 #endif /* AVOID_TABLES */
 224 
 225 
 226 /*
 227  * Check for a restart marker & resynchronize decoder.
 228  * Returns FALSE if must suspend.
 229  */
 230 
 231 LOCAL(boolean)
 232 process_restart (j_decompress_ptr cinfo)
 233 {
 234   phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
 235   int ci;
 236 
 237   /* Throw away any unused bits remaining in bit buffer; */
 238   /* include any full bytes in next_marker's count of discarded bytes */
 239   cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
 240   entropy->bitstate.bits_left = 0;
 241 




 198 
 199 
 200 /*
 201  * Figure F.12: extend sign bit.
 202  * On some machines, a shift and add will be faster than a table lookup.
 203  */
 204 
 205 #ifdef AVOID_TABLES
 206 
 207 #define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
 208 
 209 #else
 210 
 211 #define HUFF_EXTEND(x,s)  ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
 212 
 213 static const int extend_test[16] =   /* entry n is 2**(n-1) */
 214   { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
 215     0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
 216 
 217 static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
 218   { 0,
 219     (int)(((unsigned)(~0)<<1)  + 1), (int)(((unsigned)(~0)<<2)  + 1),
 220     (int)(((unsigned)(~0)<<3)  + 1), (int)(((unsigned)(~0)<<4)  + 1),
 221     (int)(((unsigned)(~0)<<5)  + 1), (int)(((unsigned)(~0)<<6)  + 1),
 222     (int)(((unsigned)(~0)<<7)  + 1), (int)(((unsigned)(~0)<<8)  + 1),
 223     (int)(((unsigned)(~0)<<9)  + 1), (int)(((unsigned)(~0)<<10) + 1),
 224     (int)(((unsigned)(~0)<<11) + 1), (int)(((unsigned)(~0)<<12) + 1),
 225     (int)(((unsigned)(~0)<<13) + 1), (int)(((unsigned)(~0)<<14) + 1),
 226     (int)(((unsigned)(~0)<<15) + 1) };
 227 
 228 #endif /* AVOID_TABLES */
 229 
 230 
 231 /*
 232  * Check for a restart marker & resynchronize decoder.
 233  * Returns FALSE if must suspend.
 234  */
 235 
 236 LOCAL(boolean)
 237 process_restart (j_decompress_ptr cinfo)
 238 {
 239   phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
 240   int ci;
 241 
 242   /* Throw away any unused bits remaining in bit buffer; */
 243   /* include any full bytes in next_marker's count of discarded bytes */
 244   cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
 245   entropy->bitstate.bits_left = 0;
 246 


< prev index next >