[Ffmpeg-devel] Speed improvement for jpeg decoding
Cyril Russo
cyril.russo
Tue Nov 21 12:48:13 CET 2006
Hi,
Like diego said, here is a patch to speed up jpeg decoding by avoiding
a conditional test for each macroblock in a JPEG stream.
Like Michael said, I've tried to keep it as short as possible.
--- ../../mjpeg.c 2006-11-21 12:22:21.000000000 +0100
+++ mjpeg.c 2006-11-21 12:47:29.000000000 +0100
@@ -1565,9 +1565,19 @@ static int ljpeg_decode_yuv_scan(MJpegDe
return 0;
}
+/* decode block and dequantize - not progressive JPEG version wrapper */
+inline static int decode_block_notprogressive(MJpegDecodeContext *s,
DCTELEM *block,
+ int component, int dc_index, int ac_index,
int16_t *quant_matrix,
+ int ss, int se, int Ah, int Al, int *EOBRUN)
+{
+ return decode_block(s, block, component, dc_index, ac_index,
quant_matrix);
+}
+
static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components,
int ss, int se, int Ah, int Al){
int i, mb_x, mb_y;
int EOBRUN = 0;
+ int (*pdecode)(MJpegDecodeContext *, DCTELEM *, int, int, int,
int16_t *, int, int, int, int, int *) = s->progressive ?
decode_block_progressive : decode_block_notprogressive;
+ void (*pidct)(uint8_t *, int, DCTELEM *) = s->progressive ?
s->idct_add : s->idct_put;
if(Ah) return 0; /* TODO decode refinement planes too */
for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
@@ -1586,13 +1596,7 @@ static int mjpeg_decode_scan(MJpegDecode
y = 0;
for(j=0;j<n;j++) {
memset(s->block, 0, sizeof(s->block));
- if (!s->progressive && decode_block(s, s->block, i,
- s->dc_index[i], s->ac_index[i],
- s->quant_matrixes[
s->quant_index[c] ]) < 0) {
- dprintf("error y=%d x=%d\n", mb_y, mb_x);
- return -1;
- }
- if (s->progressive && decode_block_progressive(s,
s->block, i,
+ if (pdecode(s, s->block, i,
s->dc_index[i], s->ac_index[i],
s->quant_matrixes[
s->quant_index[c] ], ss, se, Ah, Al, &EOBRUN) < 0) {
dprintf("error y=%d x=%d\n", mb_y, mb_x);
@@ -1605,10 +1609,7 @@ static int mjpeg_decode_scan(MJpegDecode
if (s->interlaced && s->bottom_field)
ptr += s->linesize[c] >> 1;
//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y,
x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
- if(!s->progressive)
- s->idct_put(ptr, s->linesize[c], s->block);
- else
- s->idct_add(ptr, s->linesize[c], s->block);
+ pidct(ptr, s->linesize[c], s->block);
if (++x == h) {
x = 0;
y++;
--
Cyril RUSSO
More information about the ffmpeg-devel
mailing list