1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avcodec/mjpegdec: Do not permute quantization tables

This fixes issues if the permutation changes, as quantizations tables would need to be reread

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2016-04-03 01:28:07 +02:00
parent c1f9734f97
commit de0bcea664

View File

@ -166,7 +166,7 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
/* quantize tables */
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
{
int len, index, i, j;
int len, index, i;
len = get_bits(&s->gb, 16) - 2;
@ -187,13 +187,12 @@ int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index);
/* read quant table */
for (i = 0; i < 64; i++) {
j = s->scantable.permutated[i];
s->quant_matrixes[index][j] = get_bits(&s->gb, pr ? 16 : 8);
s->quant_matrixes[index][i] = get_bits(&s->gb, pr ? 16 : 8);
}
// XXX FIXME finetune, and perhaps add dc too
s->qscale[index] = FFMAX(s->quant_matrixes[index][s->scantable.permutated[1]],
s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
s->qscale[index] = FFMAX(s->quant_matrixes[index][1],
s->quant_matrixes[index][8]) >> 1;
av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n",
index, s->qscale[index]);
len -= 1 + 64 * (1+pr);
@ -723,7 +722,7 @@ static int decode_block(MJpegDecodeContext *s, int16_t *block, int component,
return AVERROR_INVALIDDATA;
}
j = s->scantable.permutated[i];
block[j] = level * quant_matrix[j];
block[j] = level * quant_matrix[i];
}
} while (i < 63);
CLOSE_READER(re, &s->gb);}
@ -785,14 +784,14 @@ static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block,
if (i >= se) {
if (i == se) {
j = s->scantable.permutated[se];
block[j] = level * (quant_matrix[j] << Al);
block[j] = level * (quant_matrix[se] << Al);
break;
}
av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
return AVERROR_INVALIDDATA;
}
j = s->scantable.permutated[i];
block[j] = level * (quant_matrix[j] << Al);
block[j] = level * (quant_matrix[i] << Al);
} else {
if (run == 0xF) {// ZRL - skip 15 coefficients
i += 15;
@ -825,7 +824,7 @@ static int decode_block_progressive(MJpegDecodeContext *s, int16_t *block,
UPDATE_CACHE(re, &s->gb); \
sign = block[j] >> 15; \
block[j] += SHOW_UBITS(re, &s->gb, 1) * \
((quant_matrix[j] ^ sign) - sign) << Al; \
((quant_matrix[i] ^ sign) - sign) << Al; \
LAST_SKIP_BITS(re, &s->gb, 1); \
}
@ -871,7 +870,7 @@ static int decode_block_refinement(MJpegDecodeContext *s, int16_t *block,
ZERO_RUN;
j = s->scantable.permutated[i];
val--;
block[j] = ((quant_matrix[j] << Al) ^ val) - val;
block[j] = ((quant_matrix[i] << Al) ^ val) - val;
if (i == se) {
if (i > *last_nnz)
*last_nnz = i;