Revision 39922395 libavcodec/vp3.c

View differences:

libavcodec/vp3.c
316 316

  
317 317
    uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc
318 318
    uint8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16
319

  
320
     /* Huffman decode */
321
     int hti;
322
     unsigned int hbits;
323
     int entries;
324
     int huff_code_size;
325
     uint16_t huffman_table[80][32][2];
319 326
} Vp3DecodeContext;
320 327

  
321 328
static int theora_decode_comments(AVCodecContext *avctx, GetBitContext gb);
......
2656 2663
	    s->coded_intra_c_dequant[i] = vp31_intra_c_dequant[i];
2657 2664
	for (i = 0; i < 64; i++)
2658 2665
	    s->coded_inter_dequant[i] = vp31_inter_dequant[i];
2659
    }
2660 2666

  
2661
    /* init VLC tables */
2662
    for (i = 0; i < 16; i++) {
2663

  
2664
        /* DC histograms */
2665
        init_vlc(&s->dc_vlc[i], 5, 32,
2666
            &dc_bias[i][0][1], 4, 2,
2667
            &dc_bias[i][0][0], 4, 2, 0);
2668

  
2669
        /* group 1 AC histograms */
2670
        init_vlc(&s->ac_vlc_1[i], 5, 32,
2671
            &ac_bias_0[i][0][1], 4, 2,
2672
            &ac_bias_0[i][0][0], 4, 2, 0);
2673

  
2674
        /* group 2 AC histograms */
2675
        init_vlc(&s->ac_vlc_2[i], 5, 32,
2676
            &ac_bias_1[i][0][1], 4, 2,
2677
            &ac_bias_1[i][0][0], 4, 2, 0);
2678

  
2679
        /* group 3 AC histograms */
2680
        init_vlc(&s->ac_vlc_3[i], 5, 32,
2681
            &ac_bias_2[i][0][1], 4, 2,
2682
            &ac_bias_2[i][0][0], 4, 2, 0);
2683

  
2684
        /* group 4 AC histograms */
2685
        init_vlc(&s->ac_vlc_4[i], 5, 32,
2686
            &ac_bias_3[i][0][1], 4, 2,
2687
            &ac_bias_3[i][0][0], 4, 2, 0);
2667
        /* init VLC tables */
2668
        for (i = 0; i < 16; i++) {
2669

  
2670
            /* DC histograms */
2671
            init_vlc(&s->dc_vlc[i], 5, 32,
2672
                &dc_bias[i][0][1], 4, 2,
2673
                &dc_bias[i][0][0], 4, 2, 0);
2674

  
2675
            /* group 1 AC histograms */
2676
            init_vlc(&s->ac_vlc_1[i], 5, 32,
2677
                &ac_bias_0[i][0][1], 4, 2,
2678
                &ac_bias_0[i][0][0], 4, 2, 0);
2679

  
2680
            /* group 2 AC histograms */
2681
            init_vlc(&s->ac_vlc_2[i], 5, 32,
2682
                &ac_bias_1[i][0][1], 4, 2,
2683
                &ac_bias_1[i][0][0], 4, 2, 0);
2684

  
2685
            /* group 3 AC histograms */
2686
            init_vlc(&s->ac_vlc_3[i], 5, 32,
2687
                &ac_bias_2[i][0][1], 4, 2,
2688
                &ac_bias_2[i][0][0], 4, 2, 0);
2689

  
2690
            /* group 4 AC histograms */
2691
            init_vlc(&s->ac_vlc_4[i], 5, 32,
2692
                &ac_bias_3[i][0][1], 4, 2,
2693
                &ac_bias_3[i][0][0], 4, 2, 0);
2694
        }
2695
    } else {
2696
        for (i = 0; i < 16; i++) {
2697

  
2698
            /* DC histograms */
2699
            init_vlc(&s->dc_vlc[i], 5, 32,
2700
                &s->huffman_table[i][0][1], 4, 2,
2701
                &s->huffman_table[i][0][0], 4, 2, 0);
2702

  
2703
            /* group 1 AC histograms */
2704
            init_vlc(&s->ac_vlc_1[i], 5, 32,
2705
                &s->huffman_table[i+16][0][1], 4, 2,
2706
                &s->huffman_table[i+16][0][0], 4, 2, 0);
2707

  
2708
            /* group 2 AC histograms */
2709
            init_vlc(&s->ac_vlc_2[i], 5, 32,
2710
                &s->huffman_table[i+16*2][0][1], 4, 2,
2711
                &s->huffman_table[i+16*2][0][0], 4, 2, 0);
2712

  
2713
            /* group 3 AC histograms */
2714
            init_vlc(&s->ac_vlc_3[i], 5, 32,
2715
                &s->huffman_table[i+16*3][0][1], 4, 2,
2716
                &s->huffman_table[i+16*3][0][0], 4, 2, 0);
2717

  
2718
            /* group 4 AC histograms */
2719
            init_vlc(&s->ac_vlc_4[i], 5, 32,
2720
                &s->huffman_table[i+16*4][0][1], 4, 2,
2721
                &s->huffman_table[i+16*4][0][0], 4, 2, 0);
2722
        }
2688 2723
    }
2689 2724

  
2690 2725
    init_vlc(&s->superblock_run_length_vlc, 6, 34,
......
2938 2973
    return 0;
2939 2974
}
2940 2975

  
2976
static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
2977
{
2978
    Vp3DecodeContext *s = avctx->priv_data;
2979

  
2980
    if (get_bits(gb, 1)) {
2981
        int token;
2982
        if (s->entries >= 32) { /* overflow */
2983
            av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
2984
            return -1;
2985
        }
2986
        token = get_bits(gb, 5);
2987
        //av_log(avctx, AV_LOG_DEBUG, "hti %d hbits %x token %d entry : %d size %d\n", s->hti, s->hbits, token, s->entries, s->huff_code_size);
2988
        s->huffman_table[s->hti][token][0] = s->hbits;
2989
        s->huffman_table[s->hti][token][1] = s->huff_code_size;
2990
        s->entries++;
2991
    }
2992
    else {
2993
        if (s->huff_code_size >= 32) {/* overflow */
2994
            av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
2995
            return -1;
2996
        }
2997
        s->huff_code_size++;
2998
        s->hbits <<= 1;
2999
        read_huffman_tree(avctx, gb);
3000
        s->hbits |= 1;
3001
        read_huffman_tree(avctx, gb);
3002
        s->hbits >>= 1;
3003
        s->huff_code_size--;
3004
    }
3005
    return 0;
3006
}
3007

  
2941 3008
static int theora_decode_header(AVCodecContext *avctx, GetBitContext gb)
2942 3009
{
2943 3010
    Vp3DecodeContext *s = avctx->priv_data;
......
3070 3137
    for (i = 0; i < 64; i++)
3071 3138
	s->coded_inter_dequant[i] = get_bits(&gb, 8);
3072 3139

  
3073
    /* FIXME: read huffmann tree.. */
3140
    /* Huffman tables */
3141
    for (i = 0; i <= 1; i++) {
3142
        for (n = 0; n <= 2; n++) {
3143
            int newqr;
3144
            if (i > 0 || n > 0)
3145
                newqr = get_bits(&gb, 1);
3146
            else
3147
                newqr = 1;
3148
            if (!newqr) {
3149
                if (i > 0)
3150
                    get_bits(&gb, 1);
3151
            }
3152
            else {
3153
                int qi = 0;
3154
                skip_bits(&gb, av_log2(2)+1);
3155
                while (qi < 63) {
3156
                    qi += get_bits(&gb, av_log2(63-qi)+1) + 1;
3157
                    skip_bits(&gb, av_log2(2)+1);
3158
                }
3159
                if (qi > 63)
3160
                    av_log(NULL, AV_LOG_ERROR, "error...\n");
3161
            }
3162
        }
3163
    }
3164

  
3165
    for (s->hti = 0; s->hti < 80; s->hti++) {
3166
        s->entries = 0;
3167
        s->huff_code_size = 1;
3168
        if (!get_bits(&gb, 1)) {
3169
            s->hbits = 0;
3170
            read_huffman_tree(avctx, &gb);
3171
            s->hbits = 1;
3172
            read_huffman_tree(avctx, &gb);
3173
        }
3174
    }
3074 3175
    
3075 3176
    s->theora_tables = 1;
3076 3177
    

Also available in: Unified diff