libavcodec/vp6.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006  Aurelien Jacobs <aurel@gnuage.org>
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00030 #include <stdlib.h>
00031 
00032 #include "avcodec.h"
00033 #include "dsputil.h"
00034 #include "get_bits.h"
00035 #include "huffman.h"
00036 
00037 #include "vp56.h"
00038 #include "vp56data.h"
00039 #include "vp6data.h"
00040 
00041 #define VP6_MAX_HUFF_SIZE 12
00042 
00043 static void vp6_parse_coeff(VP56Context *s);
00044 static void vp6_parse_coeff_huffman(VP56Context *s);
00045 
00046 static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
00047                             int *golden_frame)
00048 {
00049     VP56RangeCoder *c = &s->c;
00050     int parse_filter_info = 0;
00051     int coeff_offset = 0;
00052     int vrt_shift = 0;
00053     int sub_version;
00054     int rows, cols;
00055     int res = 0;
00056     int separated_coeff = buf[0] & 1;
00057 
00058     s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
00059     ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
00060 
00061     if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
00062         sub_version = buf[1] >> 3;
00063         if (sub_version > 8)
00064             return AVERROR_INVALIDDATA;
00065         s->filter_header = buf[1] & 0x06;
00066         if (buf[1] & 1) {
00067             av_log_missing_feature(s->avctx, "Interlacing", 0);
00068             return AVERROR_PATCHWELCOME;
00069         }
00070         if (separated_coeff || !s->filter_header) {
00071             coeff_offset = AV_RB16(buf+2) - 2;
00072             buf += 2;
00073             buf_size -= 2;
00074         }
00075 
00076         rows = buf[2];  /* number of stored macroblock rows */
00077         cols = buf[3];  /* number of stored macroblock cols */
00078         /* buf[4] is number of displayed macroblock rows */
00079         /* buf[5] is number of displayed macroblock cols */
00080         if (!rows || !cols) {
00081             av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4);
00082             return AVERROR_INVALIDDATA;
00083         }
00084 
00085         if (!s->macroblocks || /* first frame */
00086             16*cols != s->avctx->coded_width ||
00087             16*rows != s->avctx->coded_height) {
00088             avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
00089             if (s->avctx->extradata_size == 1) {
00090                 s->avctx->width  -= s->avctx->extradata[0] >> 4;
00091                 s->avctx->height -= s->avctx->extradata[0] & 0x0F;
00092             }
00093             res = VP56_SIZE_CHANGE;
00094         }
00095 
00096         ff_vp56_init_range_decoder(c, buf+6, buf_size-6);
00097         vp56_rac_gets(c, 2);
00098 
00099         parse_filter_info = s->filter_header;
00100         if (sub_version < 8)
00101             vrt_shift = 5;
00102         s->sub_version = sub_version;
00103     } else {
00104         if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
00105             return AVERROR_INVALIDDATA;
00106 
00107         if (separated_coeff || !s->filter_header) {
00108             coeff_offset = AV_RB16(buf+1) - 2;
00109             buf += 2;
00110             buf_size -= 2;
00111         }
00112         ff_vp56_init_range_decoder(c, buf+1, buf_size-1);
00113 
00114         *golden_frame = vp56_rac_get(c);
00115         if (s->filter_header) {
00116             s->deblock_filtering = vp56_rac_get(c);
00117             if (s->deblock_filtering)
00118                 vp56_rac_get(c);
00119             if (s->sub_version > 7)
00120                 parse_filter_info = vp56_rac_get(c);
00121         }
00122     }
00123 
00124     if (parse_filter_info) {
00125         if (vp56_rac_get(c)) {
00126             s->filter_mode = 2;
00127             s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
00128             s->max_vector_length = 2 << vp56_rac_gets(c, 3);
00129         } else if (vp56_rac_get(c)) {
00130             s->filter_mode = 1;
00131         } else {
00132             s->filter_mode = 0;
00133         }
00134         if (s->sub_version > 7)
00135             s->filter_selection = vp56_rac_gets(c, 4);
00136         else
00137             s->filter_selection = 16;
00138     }
00139 
00140     s->use_huffman = vp56_rac_get(c);
00141 
00142     s->parse_coeff = vp6_parse_coeff;
00143     if (coeff_offset) {
00144         buf      += coeff_offset;
00145         buf_size -= coeff_offset;
00146         if (buf_size < 0) {
00147             if (s->framep[VP56_FRAME_CURRENT]->key_frame)
00148                 avcodec_set_dimensions(s->avctx, 0, 0);
00149             return AVERROR_INVALIDDATA;
00150         }
00151         if (s->use_huffman) {
00152             s->parse_coeff = vp6_parse_coeff_huffman;
00153             init_get_bits(&s->gb, buf, buf_size<<3);
00154         } else {
00155             ff_vp56_init_range_decoder(&s->cc, buf, buf_size);
00156             s->ccp = &s->cc;
00157         }
00158     } else {
00159         s->ccp = &s->c;
00160     }
00161 
00162     return res;
00163 }
00164 
00165 static void vp6_coeff_order_table_init(VP56Context *s)
00166 {
00167     int i, pos, idx = 1;
00168 
00169     s->modelp->coeff_index_to_pos[0] = 0;
00170     for (i=0; i<16; i++)
00171         for (pos=1; pos<64; pos++)
00172             if (s->modelp->coeff_reorder[pos] == i)
00173                 s->modelp->coeff_index_to_pos[idx++] = pos;
00174 }
00175 
00176 static void vp6_default_models_init(VP56Context *s)
00177 {
00178     VP56Model *model = s->modelp;
00179 
00180     model->vector_dct[0] = 0xA2;
00181     model->vector_dct[1] = 0xA4;
00182     model->vector_sig[0] = 0x80;
00183     model->vector_sig[1] = 0x80;
00184 
00185     memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
00186     memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));
00187     memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));
00188     memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));
00189     memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));
00190 
00191     vp6_coeff_order_table_init(s);
00192 }
00193 
00194 static void vp6_parse_vector_models(VP56Context *s)
00195 {
00196     VP56RangeCoder *c = &s->c;
00197     VP56Model *model = s->modelp;
00198     int comp, node;
00199 
00200     for (comp=0; comp<2; comp++) {
00201         if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
00202             model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
00203         if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
00204             model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
00205     }
00206 
00207     for (comp=0; comp<2; comp++)
00208         for (node=0; node<7; node++)
00209             if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
00210                 model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
00211 
00212     for (comp=0; comp<2; comp++)
00213         for (node=0; node<8; node++)
00214             if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
00215                 model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
00216 }
00217 
00218 /* nodes must ascend by count, but with descending symbol order */
00219 static int vp6_huff_cmp(const void *va, const void *vb)
00220 {
00221     const Node *a = va, *b = vb;
00222     return (a->count - b->count)*16 + (b->sym - a->sym);
00223 }
00224 
00225 static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
00226                                const uint8_t *map, unsigned size, VLC *vlc)
00227 {
00228     Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
00229     int a, b, i;
00230 
00231     /* first compute probabilities from model */
00232     tmp[0].count = 256;
00233     for (i=0; i<size-1; i++) {
00234         a = tmp[i].count *        coeff_model[i]  >> 8;
00235         b = tmp[i].count * (255 - coeff_model[i]) >> 8;
00236         nodes[map[2*i  ]].count = a + !a;
00237         nodes[map[2*i+1]].count = b + !b;
00238     }
00239 
00240     ff_free_vlc(vlc);
00241     /* then build the huffman tree according to probabilities */
00242     return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
00243                               FF_HUFFMAN_FLAG_HNODE_FIRST);
00244 }
00245 
00246 static int vp6_parse_coeff_models(VP56Context *s)
00247 {
00248     VP56RangeCoder *c = &s->c;
00249     VP56Model *model = s->modelp;
00250     int def_prob[11];
00251     int node, cg, ctx, pos;
00252     int ct;    /* code type */
00253     int pt;    /* plane type (0 for Y, 1 for U or V) */
00254 
00255     memset(def_prob, 0x80, sizeof(def_prob));
00256 
00257     for (pt=0; pt<2; pt++)
00258         for (node=0; node<11; node++)
00259             if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
00260                 def_prob[node] = vp56_rac_gets_nn(c, 7);
00261                 model->coeff_dccv[pt][node] = def_prob[node];
00262             } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
00263                 model->coeff_dccv[pt][node] = def_prob[node];
00264             }
00265 
00266     if (vp56_rac_get(c)) {
00267         for (pos=1; pos<64; pos++)
00268             if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
00269                 model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
00270         vp6_coeff_order_table_init(s);
00271     }
00272 
00273     for (cg=0; cg<2; cg++)
00274         for (node=0; node<14; node++)
00275             if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
00276                 model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
00277 
00278     for (ct=0; ct<3; ct++)
00279         for (pt=0; pt<2; pt++)
00280             for (cg=0; cg<6; cg++)
00281                 for (node=0; node<11; node++)
00282                     if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
00283                         def_prob[node] = vp56_rac_gets_nn(c, 7);
00284                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
00285                     } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
00286                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
00287                     }
00288 
00289     if (s->use_huffman) {
00290         for (pt=0; pt<2; pt++) {
00291             if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
00292                                     vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
00293                 return -1;
00294             if (vp6_build_huff_tree(s, model->coeff_runv[pt],
00295                                     vp6_huff_run_map, 9, &s->runv_vlc[pt]))
00296                 return -1;
00297             for (ct=0; ct<3; ct++)
00298                 for (cg = 0; cg < 6; cg++)
00299                     if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
00300                                             vp6_huff_coeff_map, 12,
00301                                             &s->ract_vlc[pt][ct][cg]))
00302                         return -1;
00303         }
00304         memset(s->nb_null, 0, sizeof(s->nb_null));
00305     } else {
00306     /* coeff_dcct is a linear combination of coeff_dccv */
00307     for (pt=0; pt<2; pt++)
00308         for (ctx=0; ctx<3; ctx++)
00309             for (node=0; node<5; node++)
00310                 model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);
00311     }
00312     return 0;
00313 }
00314 
00315 static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
00316 {
00317     VP56RangeCoder *c = &s->c;
00318     VP56Model *model = s->modelp;
00319     int comp;
00320 
00321     *vect = (VP56mv) {0,0};
00322     if (s->vector_candidate_pos < 2)
00323         *vect = s->vector_candidate[0];
00324 
00325     for (comp=0; comp<2; comp++) {
00326         int i, delta = 0;
00327 
00328         if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
00329             static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
00330             for (i=0; i<sizeof(prob_order); i++) {
00331                 int j = prob_order[i];
00332                 delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
00333             }
00334             if (delta & 0xF0)
00335                 delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
00336             else
00337                 delta |= 8;
00338         } else {
00339             delta = vp56_rac_get_tree(c, vp56_pva_tree,
00340                                       model->vector_pdv[comp]);
00341         }
00342 
00343         if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
00344             delta = -delta;
00345 
00346         if (!comp)
00347             vect->x += delta;
00348         else
00349             vect->y += delta;
00350     }
00351 }
00352 
00357 static unsigned vp6_get_nb_null(VP56Context *s)
00358 {
00359     unsigned val = get_bits(&s->gb, 2);
00360     if (val == 2)
00361         val += get_bits(&s->gb, 2);
00362     else if (val == 3) {
00363         val = get_bits1(&s->gb) << 2;
00364         val = 6+val + get_bits(&s->gb, 2+val);
00365     }
00366     return val;
00367 }
00368 
00369 static void vp6_parse_coeff_huffman(VP56Context *s)
00370 {
00371     VP56Model *model = s->modelp;
00372     uint8_t *permute = s->scantable.permutated;
00373     VLC *vlc_coeff;
00374     int coeff, sign, coeff_idx;
00375     int b, cg, idx;
00376     int pt = 0;    /* plane type (0 for Y, 1 for U or V) */
00377 
00378     for (b=0; b<6; b++) {
00379         int ct = 0;    /* code type */
00380         if (b > 3) pt = 1;
00381         vlc_coeff = &s->dccv_vlc[pt];
00382 
00383         for (coeff_idx = 0;;) {
00384             int run = 1;
00385             if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
00386                 s->nb_null[coeff_idx][pt]--;
00387                 if (coeff_idx)
00388                     break;
00389             } else {
00390                 if (get_bits_left(&s->gb) <= 0)
00391                     return;
00392                 coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
00393                 if (coeff == 0) {
00394                     if (coeff_idx) {
00395                         int pt = (coeff_idx >= 6);
00396                         run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
00397                         if (run >= 9)
00398                             run += get_bits(&s->gb, 6);
00399                     } else
00400                         s->nb_null[0][pt] = vp6_get_nb_null(s);
00401                     ct = 0;
00402                 } else if (coeff == 11) {  /* end of block */
00403                     if (coeff_idx == 1)    /* first AC coeff ? */
00404                         s->nb_null[1][pt] = vp6_get_nb_null(s);
00405                     break;
00406                 } else {
00407                     int coeff2 = vp56_coeff_bias[coeff];
00408                     if (coeff > 4)
00409                         coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
00410                     ct = 1 + (coeff2 > 1);
00411                     sign = get_bits1(&s->gb);
00412                     coeff2 = (coeff2 ^ -sign) + sign;
00413                     if (coeff_idx)
00414                         coeff2 *= s->dequant_ac;
00415                     idx = model->coeff_index_to_pos[coeff_idx];
00416                     s->block_coeff[b][permute[idx]] = coeff2;
00417                 }
00418             }
00419             coeff_idx+=run;
00420             if (coeff_idx >= 64)
00421                 break;
00422             cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
00423             vlc_coeff = &s->ract_vlc[pt][ct][cg];
00424         }
00425     }
00426 }
00427 
00428 static void vp6_parse_coeff(VP56Context *s)
00429 {
00430     VP56RangeCoder *c = s->ccp;
00431     VP56Model *model = s->modelp;
00432     uint8_t *permute = s->scantable.permutated;
00433     uint8_t *model1, *model2, *model3;
00434     int coeff, sign, coeff_idx;
00435     int b, i, cg, idx, ctx;
00436     int pt = 0;    /* plane type (0 for Y, 1 for U or V) */
00437 
00438     for (b=0; b<6; b++) {
00439         int ct = 1;    /* code type */
00440         int run = 1;
00441 
00442         if (b > 3) pt = 1;
00443 
00444         ctx = s->left_block[vp56_b6to4[b]].not_null_dc
00445               + s->above_blocks[s->above_block_idx[b]].not_null_dc;
00446         model1 = model->coeff_dccv[pt];
00447         model2 = model->coeff_dcct[pt][ctx];
00448 
00449         coeff_idx = 0;
00450         for (;;) {
00451             if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
00452                 /* parse a coeff */
00453                 if (vp56_rac_get_prob(c, model2[2])) {
00454                     if (vp56_rac_get_prob(c, model2[3])) {
00455                         idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
00456                         coeff = vp56_coeff_bias[idx+5];
00457                         for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
00458                             coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
00459                     } else {
00460                         if (vp56_rac_get_prob(c, model2[4]))
00461                             coeff = 3 + vp56_rac_get_prob(c, model1[5]);
00462                         else
00463                             coeff = 2;
00464                     }
00465                     ct = 2;
00466                 } else {
00467                     ct = 1;
00468                     coeff = 1;
00469                 }
00470                 sign = vp56_rac_get(c);
00471                 coeff = (coeff ^ -sign) + sign;
00472                 if (coeff_idx)
00473                     coeff *= s->dequant_ac;
00474                 idx = model->coeff_index_to_pos[coeff_idx];
00475                 s->block_coeff[b][permute[idx]] = coeff;
00476                 run = 1;
00477             } else {
00478                 /* parse a run */
00479                 ct = 0;
00480                 if (coeff_idx > 0) {
00481                     if (!vp56_rac_get_prob(c, model2[1]))
00482                         break;
00483 
00484                     model3 = model->coeff_runv[coeff_idx >= 6];
00485                     run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
00486                     if (!run)
00487                         for (run=9, i=0; i<6; i++)
00488                             run += vp56_rac_get_prob(c, model3[i+8]) << i;
00489                 }
00490             }
00491             coeff_idx += run;
00492             if (coeff_idx >= 64)
00493                 break;
00494             cg = vp6_coeff_groups[coeff_idx];
00495             model1 = model2 = model->coeff_ract[pt][ct][cg];
00496         }
00497 
00498         s->left_block[vp56_b6to4[b]].not_null_dc =
00499         s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
00500     }
00501 }
00502 
00503 static int vp6_block_variance(uint8_t *src, int stride)
00504 {
00505     int sum = 0, square_sum = 0;
00506     int y, x;
00507 
00508     for (y=0; y<8; y+=2) {
00509         for (x=0; x<8; x+=2) {
00510             sum += src[x];
00511             square_sum += src[x]*src[x];
00512         }
00513         src += 2*stride;
00514     }
00515     return (16*square_sum - sum*sum) >> 8;
00516 }
00517 
00518 static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
00519                            int delta, const int16_t *weights)
00520 {
00521     int x, y;
00522 
00523     for (y=0; y<8; y++) {
00524         for (x=0; x<8; x++) {
00525             dst[x] = av_clip_uint8((  src[x-delta  ] * weights[0]
00526                                  + src[x        ] * weights[1]
00527                                  + src[x+delta  ] * weights[2]
00528                                  + src[x+2*delta] * weights[3] + 64) >> 7);
00529         }
00530         src += stride;
00531         dst += stride;
00532     }
00533 }
00534 
00535 static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src,
00536                              int stride, int h_weight, int v_weight)
00537 {
00538     uint8_t *tmp = s->edge_emu_buffer+16;
00539     s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
00540     s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
00541 }
00542 
00543 static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
00544                        int offset1, int offset2, int stride,
00545                        VP56mv mv, int mask, int select, int luma)
00546 {
00547     int filter4 = 0;
00548     int x8 = mv.x & mask;
00549     int y8 = mv.y & mask;
00550 
00551     if (luma) {
00552         x8 *= 2;
00553         y8 *= 2;
00554         filter4 = s->filter_mode;
00555         if (filter4 == 2) {
00556             if (s->max_vector_length &&
00557                 (FFABS(mv.x) > s->max_vector_length ||
00558                  FFABS(mv.y) > s->max_vector_length)) {
00559                 filter4 = 0;
00560             } else if (s->sample_variance_threshold
00561                        && (vp6_block_variance(src+offset1, stride)
00562                            < s->sample_variance_threshold)) {
00563                 filter4 = 0;
00564             }
00565         }
00566     }
00567 
00568     if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
00569         offset1 = offset2;
00570     }
00571 
00572     if (filter4) {
00573         if (!y8) {                      /* left or right combine */
00574             vp6_filter_hv4(dst, src+offset1, stride, 1,
00575                            vp6_block_copy_filter[select][x8]);
00576         } else if (!x8) {               /* above or below combine */
00577             vp6_filter_hv4(dst, src+offset1, stride, stride,
00578                            vp6_block_copy_filter[select][y8]);
00579         } else {
00580             s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride,
00581                              vp6_block_copy_filter[select][x8],
00582                              vp6_block_copy_filter[select][y8]);
00583         }
00584     } else {
00585         if (!x8 || !y8) {
00586             s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
00587         } else {
00588             vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
00589         }
00590     }
00591 }
00592 
00593 static av_cold int vp6_decode_init(AVCodecContext *avctx)
00594 {
00595     VP56Context *s = avctx->priv_data;
00596 
00597     ff_vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6,
00598                         avctx->codec->id == CODEC_ID_VP6A);
00599     s->vp56_coord_div = vp6_coord_div;
00600     s->parse_vector_adjustment = vp6_parse_vector_adjustment;
00601     s->filter = vp6_filter;
00602     s->default_models_init = vp6_default_models_init;
00603     s->parse_vector_models = vp6_parse_vector_models;
00604     s->parse_coeff_models = vp6_parse_coeff_models;
00605     s->parse_header = vp6_parse_header;
00606 
00607     return 0;
00608 }
00609 
00610 static av_cold int vp6_decode_free(AVCodecContext *avctx)
00611 {
00612     VP56Context *s = avctx->priv_data;
00613     int pt, ct, cg;
00614 
00615     ff_vp56_free(avctx);
00616 
00617     for (pt=0; pt<2; pt++) {
00618         ff_free_vlc(&s->dccv_vlc[pt]);
00619         ff_free_vlc(&s->runv_vlc[pt]);
00620         for (ct=0; ct<3; ct++)
00621             for (cg=0; cg<6; cg++)
00622                 ff_free_vlc(&s->ract_vlc[pt][ct][cg]);
00623     }
00624     return 0;
00625 }
00626 
00627 AVCodec ff_vp6_decoder = {
00628     .name           = "vp6",
00629     .type           = AVMEDIA_TYPE_VIDEO,
00630     .id             = CODEC_ID_VP6,
00631     .priv_data_size = sizeof(VP56Context),
00632     .init           = vp6_decode_init,
00633     .close          = vp6_decode_free,
00634     .decode         = ff_vp56_decode_frame,
00635     .capabilities   = CODEC_CAP_DR1,
00636     .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
00637 };
00638 
00639 /* flash version, not flipped upside-down */
00640 AVCodec ff_vp6f_decoder = {
00641     .name           = "vp6f",
00642     .type           = AVMEDIA_TYPE_VIDEO,
00643     .id             = CODEC_ID_VP6F,
00644     .priv_data_size = sizeof(VP56Context),
00645     .init           = vp6_decode_init,
00646     .close          = vp6_decode_free,
00647     .decode         = ff_vp56_decode_frame,
00648     .capabilities   = CODEC_CAP_DR1,
00649     .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
00650 };
00651 
00652 /* flash version, not flipped upside-down, with alpha channel */
00653 AVCodec ff_vp6a_decoder = {
00654     .name           = "vp6a",
00655     .type           = AVMEDIA_TYPE_VIDEO,
00656     .id             = CODEC_ID_VP6A,
00657     .priv_data_size = sizeof(VP56Context),
00658     .init           = vp6_decode_init,
00659     .close          = vp6_decode_free,
00660     .decode         = ff_vp56_decode_frame,
00661     .capabilities   = CODEC_CAP_DR1,
00662     .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
00663 };