438 439 440 /* 441 * Figure F.12: extend sign bit. 442 * On some machines, a shift and add will be faster than a table lookup. 443 */ 444 445 #ifdef AVOID_TABLES 446 447 #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) 448 449 #else 450 451 #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) 452 453 static const int extend_test[16] = /* entry n is 2**(n-1) */ 454 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 455 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; 456 457 static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ 458 { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, 459 ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, 460 ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, 461 ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }; 462 463 #endif /* AVOID_TABLES */ 464 465 466 /* 467 * Check for a restart marker & resynchronize decoder. 468 * Returns FALSE if must suspend. 469 */ 470 471 LOCAL(boolean) 472 process_restart (j_decompress_ptr cinfo) 473 { 474 huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; 475 int ci; 476 477 /* Throw away any unused bits remaining in bit buffer; */ 478 /* include any full bytes in next_marker's count of discarded bytes */ 479 cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; 480 entropy->bitstate.bits_left = 0; 481 | 438 439 440 /* 441 * Figure F.12: extend sign bit. 442 * On some machines, a shift and add will be faster than a table lookup. 443 */ 444 445 #ifdef AVOID_TABLES 446 447 #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) 448 449 #else 450 451 #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x)) 452 453 static const int extend_test[16] = /* entry n is 2**(n-1) */ 454 { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 455 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }; 456 457 static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */ 458 { 0, 459 (int)(((unsigned)(~0)<<1) + 1), (int)(((unsigned)(~0)<<2) + 1), 460 (int)(((unsigned)(~0)<<3) + 1), (int)(((unsigned)(~0)<<4) + 1), 461 (int)(((unsigned)(~0)<<5) + 1), (int)(((unsigned)(~0)<<6) + 1), 462 (int)(((unsigned)(~0)<<7) + 1), (int)(((unsigned)(~0)<<8) + 1), 463 (int)(((unsigned)(~0)<<9) + 1), (int)(((unsigned)(~0)<<10) + 1), 464 (int)(((unsigned)(~0)<<11) + 1), (int)(((unsigned)(~0)<<12) + 1), 465 (int)(((unsigned)(~0)<<13) + 1), (int)(((unsigned)(~0)<<14) + 1), 466 (int)(((unsigned)(~0)<<15) + 1) }; 467 468 #endif /* AVOID_TABLES */ 469 470 471 /* 472 * Check for a restart marker & resynchronize decoder. 473 * Returns FALSE if must suspend. 474 */ 475 476 LOCAL(boolean) 477 process_restart (j_decompress_ptr cinfo) 478 { 479 huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; 480 int ci; 481 482 /* Throw away any unused bits remaining in bit buffer; */ 483 /* include any full bytes in next_marker's count of discarded bytes */ 484 cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; 485 entropy->bitstate.bits_left = 0; 486 |