mirror of
https://git.videolan.org/git/ffmpeg.git
synced 2024-08-20 08:15:06 +02:00
merge huffman tables so that we read 2 symbols at a time. 30% faster huffyuv decoding.
Originally committed as revision 9104 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
5faf2d3641
commit
19716d6478
@ -70,7 +70,8 @@ typedef struct HYuvContext{
|
|||||||
uint64_t stats[3][256];
|
uint64_t stats[3][256];
|
||||||
uint8_t len[3][256];
|
uint8_t len[3][256];
|
||||||
uint32_t bits[3][256];
|
uint32_t bits[3][256];
|
||||||
VLC vlc[3];
|
VLC vlc[6]; //Y,U,V,YY,YU,YV
|
||||||
|
uint16_t pix2_map[3][1<<VLC_BITS];
|
||||||
AVFrame picture;
|
AVFrame picture;
|
||||||
uint8_t *bitstream_buffer;
|
uint8_t *bitstream_buffer;
|
||||||
unsigned int bitstream_buffer_size;
|
unsigned int bitstream_buffer_size;
|
||||||
@ -318,6 +319,35 @@ static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_ENCODERS */
|
#endif /* CONFIG_ENCODERS */
|
||||||
|
|
||||||
|
static void generate_joint_tables(HYuvContext *s){
|
||||||
|
// TODO modify init_vlc to allow sparse tables, and eliminate pix2_map
|
||||||
|
// TODO rgb
|
||||||
|
if(s->bitstream_bpp < 24){
|
||||||
|
uint16_t bits[1<<VLC_BITS];
|
||||||
|
uint8_t len[1<<VLC_BITS];
|
||||||
|
int p, i, y, u;
|
||||||
|
for(p=0; p<3; p++){
|
||||||
|
for(i=y=0; y<256; y++){
|
||||||
|
int len0 = s->len[0][y];
|
||||||
|
int limit = VLC_BITS - len0;
|
||||||
|
if(limit > 0){
|
||||||
|
for(u=0; u<256; u++){
|
||||||
|
int len1 = s->len[p][u];
|
||||||
|
if(len1 <= limit){
|
||||||
|
len[i] = len0 + len1;
|
||||||
|
bits[i] = (s->bits[0][y] << len1) + s->bits[p][u];
|
||||||
|
s->pix2_map[p][i] = (y<<8) + u;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_vlc(&s->vlc[3+p]);
|
||||||
|
init_vlc(&s->vlc[3+p], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
|
static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
int i;
|
int i;
|
||||||
@ -339,6 +369,8 @@ printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j);
|
|||||||
init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
|
init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generate_joint_tables(s);
|
||||||
|
|
||||||
return (get_bits_count(&gb)+7)/8;
|
return (get_bits_count(&gb)+7)/8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +399,8 @@ static int read_old_huffman_tables(HYuvContext *s){
|
|||||||
init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
|
init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generate_joint_tables(s);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
|
av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
|
||||||
@ -653,16 +687,28 @@ static int encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_ENCODERS */
|
#endif /* CONFIG_ENCODERS */
|
||||||
|
|
||||||
|
/* TODO instead of restarting the read when the code isn't in the first level
|
||||||
|
* of the joint table, jump into the 2nd level of the individual table. */
|
||||||
|
#define READ_2PIX(dst0, dst1, plane1){\
|
||||||
|
int code = get_vlc2(&s->gb, s->vlc[3+plane1].table, VLC_BITS, 1);\
|
||||||
|
if(code >= 0){\
|
||||||
|
int x = s->pix2_map[plane1][code];\
|
||||||
|
dst0 = x>>8;\
|
||||||
|
dst1 = x;\
|
||||||
|
}else{\
|
||||||
|
dst0 = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);\
|
||||||
|
dst1 = get_vlc2(&s->gb, s->vlc[plane1].table, VLC_BITS, 3);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
static void decode_422_bitstream(HYuvContext *s, int count){
|
static void decode_422_bitstream(HYuvContext *s, int count){
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
count/=2;
|
count/=2;
|
||||||
|
|
||||||
for(i=0; i<count; i++){
|
for(i=0; i<count; i++){
|
||||||
s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
|
READ_2PIX(s->temp[0][2*i ], s->temp[1][i], 1);
|
||||||
s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
|
READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2);
|
||||||
s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
|
|
||||||
s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,8 +718,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count){
|
|||||||
count/=2;
|
count/=2;
|
||||||
|
|
||||||
for(i=0; i<count; i++){
|
for(i=0; i<count; i++){
|
||||||
s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
|
READ_2PIX(s->temp[0][2*i ], s->temp[0][2*i+1], 0);
|
||||||
s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user