📄 vp6.c
字号:
* Read number of consecutive blocks with null DC or AC. * This value is < 74. */static unsigned vp6_get_nb_null(vp56_context_t *s){ unsigned val = get_bits(&s->gb, 2); if (val == 2) val += get_bits(&s->gb, 2); else if (val == 3) { val = get_bits1(&s->gb) << 2; val = 6+val + get_bits(&s->gb, 2+val); } return val;}static void vp6_parse_coeff_huffman(vp56_context_t *s){ vp56_model_t *model = s->modelp; uint8_t *permute = s->scantable.permutated; VLC *vlc_coeff; int coeff, sign, coeff_idx; int b, cg, idx; int pt = 0; /* plane type (0 for Y, 1 for U or V) */ for (b=0; b<6; b++) { int ct = 0; /* code type */ if (b > 3) pt = 1; vlc_coeff = &s->dccv_vlc[pt]; for (coeff_idx=0; coeff_idx<64; ) { int run = 1; if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) { s->nb_null[coeff_idx][pt]--; if (coeff_idx) break; } else { coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3); if (coeff == 0) { if (coeff_idx) { int pt = (coeff_idx >= 6); run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3); if (run >= 9) run += get_bits(&s->gb, 6); } else s->nb_null[0][pt] = vp6_get_nb_null(s); ct = 0; } else if (coeff == 11) { /* end of block */ if (coeff_idx == 1) /* first AC coeff ? */ s->nb_null[1][pt] = vp6_get_nb_null(s); break; } else { int coeff2 = vp56_coeff_bias[coeff]; if (coeff > 4) coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11); ct = 1 + (coeff2 > 1); sign = get_bits1(&s->gb); coeff2 = (coeff2 ^ -sign) + sign; if (coeff_idx) coeff2 *= s->dequant_ac; idx = model->coeff_index_to_pos[coeff_idx]; s->block_coeff[b][permute[idx]] = coeff2; } } coeff_idx+=run; cg = FFMIN(vp6_coeff_groups[coeff_idx], 3); vlc_coeff = &s->ract_vlc[pt][ct][cg]; } }}static void vp6_parse_coeff(vp56_context_t *s){ vp56_range_coder_t *c = s->ccp; vp56_model_t *model = s->modelp; uint8_t *permute = s->scantable.permutated; uint8_t *model1, *model2, *model3; int coeff, sign, coeff_idx; int b, i, cg, idx, ctx; int pt = 0; /* plane type (0 for Y, 1 for U or V) */ for (b=0; b<6; b++) { int ct = 1; /* code type */ int run = 1; if (b > 3) pt = 1; ctx = s->left_block[vp56_b6to4[b]].not_null_dc + s->above_blocks[s->above_block_idx[b]].not_null_dc; model1 = model->coeff_dccv[pt]; model2 = model->coeff_dcct[pt][ctx]; for (coeff_idx=0; coeff_idx<64; ) { if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) { /* parse a coeff */ if (vp56_rac_get_prob(c, model2[2])) { if (vp56_rac_get_prob(c, model2[3])) { idx = vp56_rac_get_tree(c, vp56_pc_tree, model1); coeff = vp56_coeff_bias[idx+5]; for (i=vp56_coeff_bit_length[idx]; i>=0; i--) coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i; } else { if (vp56_rac_get_prob(c, model2[4])) coeff = 3 + vp56_rac_get_prob(c, model1[5]); else coeff = 2; } ct = 2; } else { ct = 1; coeff = 1; } sign = vp56_rac_get(c); coeff = (coeff ^ -sign) + sign; if (coeff_idx) coeff *= s->dequant_ac; idx = model->coeff_index_to_pos[coeff_idx]; s->block_coeff[b][permute[idx]] = coeff; run = 1; } else { /* parse a run */ ct = 0; if (coeff_idx > 0) { if (!vp56_rac_get_prob(c, model2[1])) break; model3 = model->coeff_runv[coeff_idx >= 6]; run = vp56_rac_get_tree(c, vp6_pcr_tree, model3); if (!run) for (run=9, i=0; i<6; i++) run += vp56_rac_get_prob(c, model3[i+8]) << i; } } cg = vp6_coeff_groups[coeff_idx+=run]; model1 = model2 = model->coeff_ract[pt][ct][cg]; } s->left_block[vp56_b6to4[b]].not_null_dc = s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0]; }}static int vp6_adjust(int v, int t){ int V = v, s = v >> 31; V ^= s; V -= s; if (V-t-1 >= (unsigned)(t-1)) return v; V = 2*t - V; V += s; V ^= s; return V;}static int vp6_block_variance(uint8_t *src, int stride){ int sum = 0, square_sum = 0; int y, x; for (y=0; y<8; y+=2) { for (x=0; x<8; x+=2) { sum += src[x]; square_sum += src[x]*src[x]; } src += 2*stride; } return (16*square_sum - sum*sum) >> 8;}static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride, int delta, const int16_t *weights){ int x, y; for (y=0; y<8; y++) { for (x=0; x<8; x++) { dst[x] = av_clip_uint8(( src[x-delta ] * weights[0] + src[x ] * weights[1] + src[x+delta ] * weights[2] + src[x+2*delta] * weights[3] + 64) >> 7); } src += stride; dst += stride; }}static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src, int stride, int h_weight, int v_weight){ uint8_t *tmp = s->edge_emu_buffer+16; s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0); s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);}static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride, const int16_t *h_weights,const int16_t *v_weights){ int x, y; int tmp[8*11]; int *t = tmp; src -= stride; for (y=0; y<11; y++) { for (x=0; x<8; x++) { t[x] = av_clip_uint8(( src[x-1] * h_weights[0] + src[x ] * h_weights[1] + src[x+1] * h_weights[2] + src[x+2] * h_weights[3] + 64) >> 7); } src += stride; t += 8; } t = tmp + 8; for (y=0; y<8; y++) { for (x=0; x<8; x++) { dst[x] = av_clip_uint8(( t[x-8 ] * v_weights[0] + t[x ] * v_weights[1] + t[x+8 ] * v_weights[2] + t[x+16] * v_weights[3] + 64) >> 7); } dst += stride; t += 8; }}static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src, int offset1, int offset2, int stride, vp56_mv_t mv, int mask, int select, int luma){ int filter4 = 0; int x8 = mv.x & mask; int y8 = mv.y & mask; if (luma) { x8 *= 2; y8 *= 2; filter4 = s->filter_mode; if (filter4 == 2) { if (s->max_vector_length && (FFABS(mv.x) > s->max_vector_length || FFABS(mv.y) > s->max_vector_length)) { filter4 = 0; } else if (s->sample_variance_threshold && (vp6_block_variance(src+offset1, stride) < s->sample_variance_threshold)) { filter4 = 0; } } } if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) { offset1 = offset2; } if (filter4) { if (!y8) { /* left or right combine */ vp6_filter_hv4(dst, src+offset1, stride, 1, vp6_block_copy_filter[select][x8]); } else if (!x8) { /* above or below combine */ vp6_filter_hv4(dst, src+offset1, stride, stride, vp6_block_copy_filter[select][y8]); } else { vp6_filter_diag4(dst, src+offset1 + ((mv.x^mv.y)>>31), stride, vp6_block_copy_filter[select][x8], vp6_block_copy_filter[select][y8]); } } else { if (!x8 || !y8) { s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8); } else { vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8); } }}static int vp6_decode_init(AVCodecContext *avctx){ vp56_context_t *s = avctx->priv_data; vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6, avctx->codec->id == CODEC_ID_VP6A); s->vp56_coord_div = vp6_coord_div; s->parse_vector_adjustment = vp6_parse_vector_adjustment; s->adjust = vp6_adjust; s->filter = vp6_filter; s->default_models_init = vp6_default_models_init; s->parse_vector_models = vp6_parse_vector_models; s->parse_coeff_models = vp6_parse_coeff_models; s->parse_header = vp6_parse_header; return 0;}AVCodec vp6_decoder = { "vp6", CODEC_TYPE_VIDEO, CODEC_ID_VP6, sizeof(vp56_context_t), vp6_decode_init, NULL, vp56_free, vp56_decode_frame, CODEC_CAP_DR1,};/* flash version, not flipped upside-down */AVCodec vp6f_decoder = { "vp6f", CODEC_TYPE_VIDEO, CODEC_ID_VP6F, sizeof(vp56_context_t), vp6_decode_init, NULL, vp56_free, vp56_decode_frame, CODEC_CAP_DR1,};/* flash version, not flipped upside-down, with alpha channel */AVCodec vp6a_decoder = { "vp6a", CODEC_TYPE_VIDEO, CODEC_ID_VP6A, sizeof(vp56_context_t), vp6_decode_init, NULL, vp56_free, vp56_decode_frame, CODEC_CAP_DR1,};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -