Project

General

Profile

Patch #467 » dcmjpeg_buggy_cornell_encoder.patch

Jörg Riesmeier, 2013-06-27 17:11

View differences:

dcmjpeg/libijg16/jdhuff.c
if (l > 16) {
WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
return 0; /* fake a zero as the safest result */
#ifdef BUGGY_CORNELL_16BIT_JPEG_ENCODER
if (l == 17)
return 17; /* this is the result of the buggy Cornell encoder */
else
#endif
return 0; /* fake a zero as the safest result */
}
return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
dcmjpeg/libijg16/jdlhuff.c
/* Section H.2.2: decode the sample difference */
HUFF_DECODE(s, br_state, dctbl, return mcu_num, label1);
if (s) {
if (s == 16) /* special case: always output 32768 */
s = 32768;
else { /* normal case: fetch subsequent bits */
#ifdef BUGGY_CORNELL_16BIT_JPEG_ENCODER
if ((s == 16) && (bits_left < 16)) { /* standard case: always output 32768 */
s = 32768;
}
else if (s >= 16) { /* there are enough bits available, so check ... */
r = PEEK_BITS(16);
s = HUFF_EXTEND(r, 16);
if ((s & 0xffff) == 0x8000) { /* special case: handle buggy Cornell encoder */
DROP_BITS(16);
} else { /* standard case: always output 32768 */
if (s == 0x7fff)
DROP_BITS(16);
s = 32768;
}
}
#else
if (s == 16) /* special case: always output 32768 */
s = 32768;
#endif
else { /* normal case: fetch subsequent bits */
CHECK_BIT_BUFFER(br_state, s, return mcu_num);
r = GET_BITS(s);
s = HUFF_EXTEND(r, s);
(2-2/2)