< 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 


 480   /* Completed MCU, so update state */
 481   BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
 482 
 483   /* Account for restart interval (no-op if not using restarts) */
 484   entropy->restarts_to_go--;
 485 
 486   return TRUE;
 487 }
 488 
 489 
 490 /*
 491  * MCU decoding for AC successive approximation refinement scan.
 492  */
 493 
 494 METHODDEF(boolean)
 495 decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
 496 {
 497   phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
 498   int Se = cinfo->Se;
 499   int p1 = 1 << cinfo->Al;      /* 1 in the bit position being coded */
 500   int m1 = (-1) << cinfo->Al;   /* -1 in the bit position being coded */
 501   register int s, k, r;
 502   unsigned int EOBRUN;
 503   JBLOCKROW block;
 504   JCOEFPTR thiscoef;
 505   BITREAD_STATE_VARS;
 506   d_derived_tbl * tbl;
 507   int num_newnz;
 508   int newnz_pos[DCTSIZE2];
 509 
 510   /* Process restart marker if needed; may have to suspend */
 511   if (cinfo->restart_interval) {
 512     if (entropy->restarts_to_go == 0)
 513       if (! process_restart(cinfo))
 514         return FALSE;
 515   }
 516 
 517   /* If we've run out of data, don't modify the MCU.
 518    */
 519   if (! entropy->pub.insufficient_data) {
 520 




 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, (0xffffffff<<1) + 1, (0xffffffff<<2) + 1, (0xffffffff<<3) + 1, (0xffffffff<<4) + 1,
 219     (0xffffffff<<5) + 1, (0xffffffff<<6) + 1, (0xffffffff<<7) + 1, (0xffffffff<<8) + 1,
 220     (0xffffffff<<9) + 1, (0xffffffff<<10) + 1, (0xffffffff<<11) + 1, (0xffffffff<<12) + 1,
 221     (0xffffffff<<13) + 1, (0xffffffff<<14) + 1, (0xffffffff<<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 


 480   /* Completed MCU, so update state */
 481   BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
 482 
 483   /* Account for restart interval (no-op if not using restarts) */
 484   entropy->restarts_to_go--;
 485 
 486   return TRUE;
 487 }
 488 
 489 
 490 /*
 491  * MCU decoding for AC successive approximation refinement scan.
 492  */
 493 
 494 METHODDEF(boolean)
 495 decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
 496 {
 497   phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
 498   int Se = cinfo->Se;
 499   int p1 = 1 << cinfo->Al;          /* 1 in the bit position being coded */
 500   int m1 = 0xffffffff << cinfo->Al; /* -1 in the bit position being coded */
 501   register int s, k, r;
 502   unsigned int EOBRUN;
 503   JBLOCKROW block;
 504   JCOEFPTR thiscoef;
 505   BITREAD_STATE_VARS;
 506   d_derived_tbl * tbl;
 507   int num_newnz;
 508   int newnz_pos[DCTSIZE2];
 509 
 510   /* Process restart marker if needed; may have to suspend */
 511   if (cinfo->restart_interval) {
 512     if (entropy->restarts_to_go == 0)
 513       if (! process_restart(cinfo))
 514         return FALSE;
 515   }
 516 
 517   /* If we've run out of data, don't modify the MCU.
 518    */
 519   if (! entropy->pub.insufficient_data) {
 520 


< prev index next >