diff options
Diffstat (limited to '3rdparty/libjpeg/jdhuff.c')
-rw-r--r-- | 3rdparty/libjpeg/jdhuff.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/3rdparty/libjpeg/jdhuff.c b/3rdparty/libjpeg/jdhuff.c index 06f92fe47f6..6920e207c8e 100644 --- a/3rdparty/libjpeg/jdhuff.c +++ b/3rdparty/libjpeg/jdhuff.c @@ -2,7 +2,7 @@ * jdhuff.c * * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2006-2009 by Guido Vollbeding. + * Modified 2006-2013 by Guido Vollbeding. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * @@ -628,6 +628,22 @@ jpeg_huff_decode (bitread_working_state * state, /* + * Finish up at the end of a Huffman-compressed scan. + */ + +METHODDEF(void) +finish_pass_huff (j_decompress_ptr cinfo) +{ + huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; + + /* Throw away any unused bits remaining in bit buffer; */ + /* include any full bytes in next_marker's count of discarded bytes */ + cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; + entropy->bitstate.bits_left = 0; +} + + +/* * Check for a restart marker & resynchronize decoder. * Returns FALSE if must suspend. */ @@ -638,10 +654,7 @@ process_restart (j_decompress_ptr cinfo) huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; int ci; - /* Throw away any unused bits remaining in bit buffer; */ - /* include any full bytes in next_marker's count of discarded bytes */ - cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8; - entropy->bitstate.bits_left = 0; + finish_pass_huff(cinfo); /* Advance past the RSTn marker */ if (! (*cinfo->marker->read_restart_marker) (cinfo)) @@ -797,7 +810,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* There is always only one block per MCU */ - if (EOBRUN > 0) /* if it's a band of zeroes... */ + if (EOBRUN) /* if it's a band of zeroes... */ EOBRUN--; /* ...process it now (we do nothing) */ else { BITREAD_LOAD_STATE(cinfo,entropy->bitstate); @@ -816,18 +829,17 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* Scale and output coefficient in natural (dezigzagged) order */ (*block)[natural_order[k]] = (JCOEF) (s << Al); } else { - if (r == 15) { /* ZRL */ - k += 15; /* skip 15 zeroes in band */ - } else { /* EOBr, run length is 2^r + appended bits */ - EOBRUN = 1 << r; + if (r != 15) { /* EOBr, run length is 2^r + appended bits */ if (r) { /* EOBr, r > 0 */ + EOBRUN = 1 << r; CHECK_BIT_BUFFER(br_state, r, return FALSE); r = GET_BITS(r); EOBRUN += r; + EOBRUN--; /* this band is processed at this moment */ } - EOBRUN--; /* this band is processed at this moment */ break; /* force end-of-band */ } + k += 15; /* ZRL: skip 15 zeroes in band */ } } @@ -847,17 +859,15 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* * MCU decoding for DC successive approximation refinement scan. - * Note: we assume such scans can be multi-component, although the spec - * is not very clear on the point. + * Note: we assume such scans can be multi-component, + * although the spec is not very clear on the point. */ METHODDEF(boolean) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; - int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ - int blkn; - JBLOCKROW block; + int p1, blkn; BITREAD_STATE_VARS; /* Process restart marker if needed; may have to suspend */ @@ -874,15 +884,15 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); + p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ + /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { - block = MCU_data[blkn]; - /* Encoded data is simply the next bit of the two's-complement DC value */ CHECK_BIT_BUFFER(br_state, 1, return FALSE); if (GET_BITS(1)) - (*block)[0] |= p1; + MCU_data[blkn][0][0] |= p1; /* Note: since we use |=, repeating the assignment later is safe */ } @@ -951,7 +961,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) k = cinfo->Ss; if (EOBRUN == 0) { - for (; k <= Se; k++) { + do { HUFF_DECODE(s, br_state, tbl, goto undoit, label3); r = s >> 4; s &= 15; @@ -981,7 +991,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) */ do { thiscoef = *block + natural_order[k]; - if (*thiscoef != 0) { + if (*thiscoef) { CHECK_BIT_BUFFER(br_state, 1, goto undoit); if (GET_BITS(1)) { if ((*thiscoef & p1) == 0) { /* do nothing if already set it */ @@ -1004,18 +1014,19 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* Remember its position in case we have to suspend */ newnz_pos[num_newnz++] = pos; } - } + k++; + } while (k <= Se); } - if (EOBRUN > 0) { + if (EOBRUN) { /* Scan any remaining coefficient positions after the end-of-band * (the last newly nonzero coefficient, if any). Append a correction * bit to each already-nonzero coefficient. A correction bit is 1 * if the absolute value of the coefficient must be increased. */ - for (; k <= Se; k++) { + do { thiscoef = *block + natural_order[k]; - if (*thiscoef != 0) { + if (*thiscoef) { CHECK_BIT_BUFFER(br_state, 1, goto undoit); if (GET_BITS(1)) { if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ @@ -1026,7 +1037,8 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) } } } - } + k++; + } while (k <= Se); /* Count one block completed in EOB run */ EOBRUN--; } @@ -1043,7 +1055,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) undoit: /* Re-zero any output coefficients that we made newly nonzero */ - while (num_newnz > 0) + while (num_newnz) (*block)[newnz_pos[--num_newnz]] = 0; return FALSE; @@ -1514,8 +1526,9 @@ jinit_huff_decoder (j_decompress_ptr cinfo) entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_decoder)); - cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; + cinfo->entropy = &entropy->pub; entropy->pub.start_pass = start_pass_huff_decoder; + entropy->pub.finish_pass = finish_pass_huff; if (cinfo->progressive_mode) { /* Create progression status table */ |