Revision 19716d64

View differences:

libavcodec/huffyuv.c
70 70
    uint64_t stats[3][256];
71 71
    uint8_t len[3][256];
72 72
    uint32_t bits[3][256];
73
    VLC vlc[3];
73
    VLC vlc[6];                             //Y,U,V,YY,YU,YV
74
    uint16_t pix2_map[3][1<<VLC_BITS];
74 75
    AVFrame picture;
75 76
    uint8_t *bitstream_buffer;
76 77
    unsigned int bitstream_buffer_size;
......
318 319
}
319 320
#endif /* CONFIG_ENCODERS */
320 321

  
322
static void generate_joint_tables(HYuvContext *s){
323
    // TODO modify init_vlc to allow sparse tables, and eliminate pix2_map
324
    // TODO rgb
325
    if(s->bitstream_bpp < 24){
326
        uint16_t bits[1<<VLC_BITS];
327
        uint8_t len[1<<VLC_BITS];
328
        int p, i, y, u;
329
        for(p=0; p<3; p++){
330
            for(i=y=0; y<256; y++){
331
                int len0 = s->len[0][y];
332
                int limit = VLC_BITS - len0;
333
                if(limit > 0){
334
                    for(u=0; u<256; u++){
335
                        int len1 = s->len[p][u];
336
                        if(len1 <= limit){
337
                            len[i] = len0 + len1;
338
                            bits[i] = (s->bits[0][y] << len1) + s->bits[p][u];
339
                            s->pix2_map[p][i] = (y<<8) + u;
340
                            i++;
341
                        }
342
                    }
343
                }
344
            }
345
            free_vlc(&s->vlc[3+p]);
346
            init_vlc(&s->vlc[3+p], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0);
347
        }
348
    }
349
}
350

  
321 351
static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
322 352
    GetBitContext gb;
323 353
    int i;
......
339 369
        init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
340 370
    }
341 371

  
372
    generate_joint_tables(s);
373

  
342 374
    return (get_bits_count(&gb)+7)/8;
343 375
}
344 376

  
......
367 399
        init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
368 400
    }
369 401

  
402
    generate_joint_tables(s);
403

  
370 404
    return 0;
371 405
#else
372 406
    av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
......
653 687
}
654 688
#endif /* CONFIG_ENCODERS */
655 689

  
690
/* TODO instead of restarting the read when the code isn't in the first level
691
 * of the joint table, jump into the 2nd level of the individual table. */
692
#define READ_2PIX(dst0, dst1, plane1){\
693
    int code = get_vlc2(&s->gb, s->vlc[3+plane1].table, VLC_BITS, 1);\
694
    if(code >= 0){\
695
        int x = s->pix2_map[plane1][code];\
696
        dst0 = x>>8;\
697
        dst1 = x;\
698
    }else{\
699
        dst0 = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);\
700
        dst1 = get_vlc2(&s->gb, s->vlc[plane1].table, VLC_BITS, 3);\
701
    }\
702
}
703

  
656 704
static void decode_422_bitstream(HYuvContext *s, int count){
657 705
    int i;
658 706

  
659 707
    count/=2;
660 708

  
661 709
    for(i=0; i<count; i++){
662
        s->temp[0][2*i  ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
663
        s->temp[1][  i  ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
664
        s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
665
        s->temp[2][  i  ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
710
        READ_2PIX(s->temp[0][2*i  ], s->temp[1][i], 1);
711
        READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2);
666 712
    }
667 713
}
668 714

  
......
672 718
    count/=2;
673 719

  
674 720
    for(i=0; i<count; i++){
675
        s->temp[0][2*i  ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
676
        s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
721
        READ_2PIX(s->temp[0][2*i  ], s->temp[0][2*i+1], 0);
677 722
    }
678 723
}
679 724

  

Also available in: Unified diff