diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2002-02-13 15:26:28 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2002-02-13 15:26:28 +0000 |
commit | f004ca1c1b5d272d8344ef12ab006cfe52cbf023 (patch) | |
tree | 71cf9b347708375ebdf005bf665ff8b159217d3c /libavcodec/mpeg12.c | |
parent | 80feb2a23ec6cc2ce459404041485a6dfaaffbe6 (diff) | |
download | ffmpeg-f004ca1c1b5d272d8344ef12ab006cfe52cbf023.tar.gz |
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
Originally committed as revision 298 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/mpeg12.c')
-rw-r--r-- | libavcodec/mpeg12.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 76c1b61343..906643de16 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -33,6 +33,8 @@ #define EXT_START_CODE 0x000001b5 #define USER_START_CODE 0x000001b2 +#define ABS(a) ((a)<0 ? -(a) : (a)) + static void mpeg1_encode_block(MpegEncContext *s, DCTELEM *block, int component); @@ -196,6 +198,26 @@ void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; } + + /* build unified dc encoding tables */ + for(i=-255; i<256; i++) + { + int adiff, index; + int bits, code; + int diff=i; + + adiff = ABS(diff); + if(diff<0) diff--; + index = vlc_dc_table[adiff]; + + bits= vlc_dc_lum_bits[index] + index; + code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)); + mpeg1_lum_dc_uni[i+255]= bits + (code<<8); + + bits= vlc_dc_chroma_bits[index] + index; + code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)); + mpeg1_chr_dc_uni[i+255]= bits + (code<<8); + } } mpeg1_encode_sequence_header(s); @@ -333,19 +355,16 @@ static void mpeg1_encode_motion(MpegEncContext *s, int val) static inline void encode_dc(MpegEncContext *s, int diff, int component) { - int adiff, index; - - adiff = abs(diff); - index = vlc_dc_table[adiff]; if (component == 0) { - put_bits(&s->pb, vlc_dc_lum_bits[index], vlc_dc_lum_code[index]); + put_bits( + &s->pb, + mpeg1_lum_dc_uni[diff+255]&0xFF, + mpeg1_lum_dc_uni[diff+255]>>8); } else { - put_bits(&s->pb, vlc_dc_chroma_bits[index], vlc_dc_chroma_code[index]); - } - if (diff > 0) { - put_bits(&s->pb, index, (diff & ((1 << index) - 1))); - } else if (diff < 0) { - put_bits(&s->pb, index, ((diff - 1) & ((1 << index) - 1))); + put_bits( + &s->pb, + mpeg1_chr_dc_uni[diff+255]&0xFF, + mpeg1_chr_dc_uni[diff+255]>>8); } } |