Originally committed as revision 1900 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Michael Niedermayer 22 years ago
parent 14b74d381a
commit 9fe690c88f
  1. 36
      libavcodec/mjpeg.c

@ -557,12 +557,7 @@ static inline void mjpeg_encode_dc(MpegEncContext *s, int val,
mant--; mant--;
} }
/* compute the log (XXX: optimize) */ nbits= av_log2(val) + 1;
nbits = 0;
while (val != 0) {
val = val >> 1;
nbits++;
}
put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
@ -613,12 +608,7 @@ static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
mant--; mant--;
} }
/* compute the log (XXX: optimize) */ nbits= av_log2(val) + 1;
nbits = 0;
while (val != 0) {
val = val >> 1;
nbits++;
}
code = (run << 4) | nbits; code = (run << 4) | nbits;
put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
@ -902,7 +892,7 @@ static int mjpeg_decode_sof0(MJpegDecodeContext *s)
static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
{ {
int code, diff; int code;
code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
if (code < 0) if (code < 0)
{ {
@ -910,20 +900,18 @@ static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
&s->vlcs[0][dc_index]); &s->vlcs[0][dc_index]);
return 0xffff; return 0xffff;
} }
if (code == 0) {
diff = 0; if(code)
} else { return get_xbits(&s->gb, code);
diff = get_xbits(&s->gb, code); else
} return 0;
return diff;
} }
/* decode block and dequantize */ /* decode block and dequantize */
static int decode_block(MJpegDecodeContext *s, DCTELEM *block, static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
int component, int dc_index, int ac_index, int quant_index) int component, int dc_index, int ac_index, int quant_index)
{ {
int nbits, code, i, j, level; int code, i, j, level, val;
int run, val;
VLC *ac_vlc; VLC *ac_vlc;
int16_t *quant_matrix; int16_t *quant_matrix;
@ -953,10 +941,8 @@ static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
if (code == 0xf0) { if (code == 0xf0) {
i += 16; i += 16;
} else { } else {
run = code >> 4; level = get_xbits(&s->gb, code & 0xf);
nbits = code & 0xf; i += code >> 4;
level = get_xbits(&s->gb, nbits);
i += run;
if (i >= 64) { if (i >= 64) {
dprintf("error count: %d\n", i); dprintf("error count: %d\n", i);
return -1; return -1;

Loading…
Cancel
Save