You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

672 lines
22KB

  1. /**
  2. * @file vp6.c
  3. * VP6 compatible video decoder
  4. *
  5. * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
  6. *
  7. * The VP6F decoder accepts an optional 1 byte extradata. It is composed of:
  8. * - upper 4bits: difference between encoded width and visible width
  9. * - lower 4bits: difference between encoded height and visible height
  10. *
  11. * This file is part of FFmpeg.
  12. *
  13. * FFmpeg is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * FFmpeg is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with FFmpeg; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. #include <stdlib.h>
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "bitstream.h"
  31. #include "huffman.h"
  32. #include "vp56.h"
  33. #include "vp56data.h"
  34. #include "vp6data.h"
  35. static void vp6_parse_coeff(vp56_context_t *s);
  36. static void vp6_parse_coeff_huffman(vp56_context_t *s);
  37. static int vp6_parse_header(vp56_context_t *s, const uint8_t *buf, int buf_size,
  38. int *golden_frame)
  39. {
  40. vp56_range_coder_t *c = &s->c;
  41. int parse_filter_info = 0;
  42. int coeff_offset = 0;
  43. int vrt_shift = 0;
  44. int sub_version;
  45. int rows, cols;
  46. int res = 1;
  47. int separated_coeff = buf[0] & 1;
  48. s->framep[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
  49. vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
  50. if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  51. sub_version = buf[1] >> 3;
  52. if (sub_version > 8)
  53. return 0;
  54. s->filter_header = buf[1] & 0x06;
  55. if (buf[1] & 1) {
  56. av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
  57. return 0;
  58. }
  59. if (separated_coeff || !s->filter_header) {
  60. coeff_offset = AV_RB16(buf+2) - 2;
  61. buf += 2;
  62. buf_size -= 2;
  63. }
  64. rows = buf[2]; /* number of stored macroblock rows */
  65. cols = buf[3]; /* number of stored macroblock cols */
  66. /* buf[4] is number of displayed macroblock rows */
  67. /* buf[5] is number of displayed macroblock cols */
  68. if (16*cols != s->avctx->coded_width ||
  69. 16*rows != s->avctx->coded_height) {
  70. avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
  71. if (s->avctx->extradata_size == 1) {
  72. s->avctx->width -= s->avctx->extradata[0] >> 4;
  73. s->avctx->height -= s->avctx->extradata[0] & 0x0F;
  74. }
  75. res = 2;
  76. }
  77. vp56_init_range_decoder(c, buf+6, buf_size-6);
  78. vp56_rac_gets(c, 2);
  79. parse_filter_info = s->filter_header;
  80. if (sub_version < 8)
  81. vrt_shift = 5;
  82. s->sub_version = sub_version;
  83. } else {
  84. if (!s->sub_version)
  85. return 0;
  86. if (separated_coeff || !s->filter_header) {
  87. coeff_offset = AV_RB16(buf+1) - 2;
  88. buf += 2;
  89. buf_size -= 2;
  90. }
  91. vp56_init_range_decoder(c, buf+1, buf_size-1);
  92. *golden_frame = vp56_rac_get(c);
  93. if (s->filter_header) {
  94. s->deblock_filtering = vp56_rac_get(c);
  95. if (s->deblock_filtering)
  96. vp56_rac_get(c);
  97. if (s->sub_version > 7)
  98. parse_filter_info = vp56_rac_get(c);
  99. }
  100. }
  101. if (parse_filter_info) {
  102. if (vp56_rac_get(c)) {
  103. s->filter_mode = 2;
  104. s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift;
  105. s->max_vector_length = 2 << vp56_rac_gets(c, 3);
  106. } else if (vp56_rac_get(c)) {
  107. s->filter_mode = 1;
  108. } else {
  109. s->filter_mode = 0;
  110. }
  111. if (s->sub_version > 7)
  112. s->filter_selection = vp56_rac_gets(c, 4);
  113. else
  114. s->filter_selection = 16;
  115. }
  116. s->use_huffman = vp56_rac_get(c);
  117. s->parse_coeff = vp6_parse_coeff;
  118. if (coeff_offset) {
  119. buf += coeff_offset;
  120. buf_size -= coeff_offset;
  121. if (s->use_huffman) {
  122. s->parse_coeff = vp6_parse_coeff_huffman;
  123. init_get_bits(&s->gb, buf, buf_size<<3);
  124. } else {
  125. vp56_init_range_decoder(&s->cc, buf, buf_size);
  126. s->ccp = &s->cc;
  127. }
  128. } else {
  129. s->ccp = &s->c;
  130. }
  131. return res;
  132. }
  133. static void vp6_coeff_order_table_init(vp56_context_t *s)
  134. {
  135. int i, pos, idx = 1;
  136. s->modelp->coeff_index_to_pos[0] = 0;
  137. for (i=0; i<16; i++)
  138. for (pos=1; pos<64; pos++)
  139. if (s->modelp->coeff_reorder[pos] == i)
  140. s->modelp->coeff_index_to_pos[idx++] = pos;
  141. }
  142. static void vp6_default_models_init(vp56_context_t *s)
  143. {
  144. vp56_model_t *model = s->modelp;
  145. model->vector_dct[0] = 0xA2;
  146. model->vector_dct[1] = 0xA4;
  147. model->vector_sig[0] = 0x80;
  148. model->vector_sig[1] = 0x80;
  149. memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
  150. memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));
  151. memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));
  152. memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));
  153. memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));
  154. vp6_coeff_order_table_init(s);
  155. }
  156. static void vp6_parse_vector_models(vp56_context_t *s)
  157. {
  158. vp56_range_coder_t *c = &s->c;
  159. vp56_model_t *model = s->modelp;
  160. int comp, node;
  161. for (comp=0; comp<2; comp++) {
  162. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
  163. model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
  164. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
  165. model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
  166. }
  167. for (comp=0; comp<2; comp++)
  168. for (node=0; node<7; node++)
  169. if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
  170. model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
  171. for (comp=0; comp<2; comp++)
  172. for (node=0; node<8; node++)
  173. if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
  174. model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
  175. }
  176. /* nodes must ascend by count, but with descending symbol order */
  177. static int vp6_huff_cmp(const void *va, const void *vb)
  178. {
  179. const Node *a = va, *b = vb;
  180. return (a->count - b->count)*16 + (b->sym - a->sym);
  181. }
  182. static void vp6_build_huff_tree(vp56_context_t *s, uint8_t coeff_model[],
  183. const uint8_t *map, unsigned size, VLC *vlc)
  184. {
  185. Node nodes[2*size], *tmp = &nodes[size];
  186. int a, b, i;
  187. /* first compute probabilities from model */
  188. tmp[0].count = 256;
  189. for (i=0; i<size-1; i++) {
  190. a = tmp[i].count * coeff_model[i] >> 8;
  191. b = tmp[i].count * (255 - coeff_model[i]) >> 8;
  192. nodes[map[2*i ]].count = a + !a;
  193. nodes[map[2*i+1]].count = b + !b;
  194. }
  195. /* then build the huffman tree accodring to probabilities */
  196. ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
  197. FF_HUFFMAN_FLAG_HNODE_FIRST);
  198. }
  199. static void vp6_parse_coeff_models(vp56_context_t *s)
  200. {
  201. vp56_range_coder_t *c = &s->c;
  202. vp56_model_t *model = s->modelp;
  203. int def_prob[11];
  204. int node, cg, ctx, pos;
  205. int ct; /* code type */
  206. int pt; /* plane type (0 for Y, 1 for U or V) */
  207. memset(def_prob, 0x80, sizeof(def_prob));
  208. for (pt=0; pt<2; pt++)
  209. for (node=0; node<11; node++)
  210. if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
  211. def_prob[node] = vp56_rac_gets_nn(c, 7);
  212. model->coeff_dccv[pt][node] = def_prob[node];
  213. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  214. model->coeff_dccv[pt][node] = def_prob[node];
  215. }
  216. if (vp56_rac_get(c)) {
  217. for (pos=1; pos<64; pos++)
  218. if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
  219. model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
  220. vp6_coeff_order_table_init(s);
  221. }
  222. for (cg=0; cg<2; cg++)
  223. for (node=0; node<14; node++)
  224. if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
  225. model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
  226. for (ct=0; ct<3; ct++)
  227. for (pt=0; pt<2; pt++)
  228. for (cg=0; cg<6; cg++)
  229. for (node=0; node<11; node++)
  230. if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
  231. def_prob[node] = vp56_rac_gets_nn(c, 7);
  232. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  233. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  234. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  235. }
  236. if (s->use_huffman) {
  237. for (pt=0; pt<2; pt++) {
  238. vp6_build_huff_tree(s, model->coeff_dccv[pt],
  239. vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);
  240. vp6_build_huff_tree(s, model->coeff_runv[pt],
  241. vp6_huff_run_map, 9, &s->runv_vlc[pt]);
  242. for (ct=0; ct<3; ct++)
  243. for (cg = 0; cg < 6; cg++)
  244. vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
  245. vp6_huff_coeff_map, 12,
  246. &s->ract_vlc[pt][ct][cg]);
  247. }
  248. memset(s->nb_null, 0, sizeof(s->nb_null));
  249. } else {
  250. /* coeff_dcct is a linear combination of coeff_dccv */
  251. for (pt=0; pt<2; pt++)
  252. for (ctx=0; ctx<3; ctx++)
  253. for (node=0; node<5; node++)
  254. 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);
  255. }
  256. }
  257. static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
  258. {
  259. vp56_range_coder_t *c = &s->c;
  260. vp56_model_t *model = s->modelp;
  261. int comp;
  262. *vect = (vp56_mv_t) {0,0};
  263. if (s->vector_candidate_pos < 2)
  264. *vect = s->vector_candidate[0];
  265. for (comp=0; comp<2; comp++) {
  266. int i, delta = 0;
  267. if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
  268. static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
  269. for (i=0; i<sizeof(prob_order); i++) {
  270. int j = prob_order[i];
  271. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
  272. }
  273. if (delta & 0xF0)
  274. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
  275. else
  276. delta |= 8;
  277. } else {
  278. delta = vp56_rac_get_tree(c, vp56_pva_tree,
  279. model->vector_pdv[comp]);
  280. }
  281. if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
  282. delta = -delta;
  283. if (!comp)
  284. vect->x += delta;
  285. else
  286. vect->y += delta;
  287. }
  288. }
  289. /**
  290. * Read number of consecutive blocks with null DC or AC.
  291. * This value is < 74.
  292. */
  293. static unsigned vp6_get_nb_null(vp56_context_t *s)
  294. {
  295. unsigned val = get_bits(&s->gb, 2);
  296. if (val == 2)
  297. val += get_bits(&s->gb, 2);
  298. else if (val == 3) {
  299. val = get_bits1(&s->gb) << 2;
  300. val = 6+val + get_bits(&s->gb, 2+val);
  301. }
  302. return val;
  303. }
  304. static void vp6_parse_coeff_huffman(vp56_context_t *s)
  305. {
  306. vp56_model_t *model = s->modelp;
  307. uint8_t *permute = s->scantable.permutated;
  308. VLC *vlc_coeff;
  309. int coeff, sign, coeff_idx;
  310. int b, cg, idx;
  311. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  312. for (b=0; b<6; b++) {
  313. int ct = 0; /* code type */
  314. if (b > 3) pt = 1;
  315. vlc_coeff = &s->dccv_vlc[pt];
  316. for (coeff_idx=0; coeff_idx<64; ) {
  317. int run = 1;
  318. if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
  319. s->nb_null[coeff_idx][pt]--;
  320. if (coeff_idx)
  321. break;
  322. } else {
  323. coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
  324. if (coeff == 0) {
  325. if (coeff_idx) {
  326. int pt = (coeff_idx >= 6);
  327. run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
  328. if (run >= 9)
  329. run += get_bits(&s->gb, 6);
  330. } else
  331. s->nb_null[0][pt] = vp6_get_nb_null(s);
  332. ct = 0;
  333. } else if (coeff == 11) { /* end of block */
  334. if (coeff_idx == 1) /* first AC coeff ? */
  335. s->nb_null[1][pt] = vp6_get_nb_null(s);
  336. break;
  337. } else {
  338. int coeff2 = vp56_coeff_bias[coeff];
  339. if (coeff > 4)
  340. coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
  341. ct = 1 + (coeff2 > 1);
  342. sign = get_bits1(&s->gb);
  343. coeff2 = (coeff2 ^ -sign) + sign;
  344. if (coeff_idx)
  345. coeff2 *= s->dequant_ac;
  346. idx = model->coeff_index_to_pos[coeff_idx];
  347. s->block_coeff[b][permute[idx]] = coeff2;
  348. }
  349. }
  350. coeff_idx+=run;
  351. cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
  352. vlc_coeff = &s->ract_vlc[pt][ct][cg];
  353. }
  354. }
  355. }
  356. static void vp6_parse_coeff(vp56_context_t *s)
  357. {
  358. vp56_range_coder_t *c = s->ccp;
  359. vp56_model_t *model = s->modelp;
  360. uint8_t *permute = s->scantable.permutated;
  361. uint8_t *model1, *model2, *model3;
  362. int coeff, sign, coeff_idx;
  363. int b, i, cg, idx, ctx;
  364. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  365. for (b=0; b<6; b++) {
  366. int ct = 1; /* code type */
  367. int run = 1;
  368. if (b > 3) pt = 1;
  369. ctx = s->left_block[vp56_b6to4[b]].not_null_dc
  370. + s->above_blocks[s->above_block_idx[b]].not_null_dc;
  371. model1 = model->coeff_dccv[pt];
  372. model2 = model->coeff_dcct[pt][ctx];
  373. for (coeff_idx=0; coeff_idx<64; ) {
  374. if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
  375. /* parse a coeff */
  376. if (vp56_rac_get_prob(c, model2[2])) {
  377. if (vp56_rac_get_prob(c, model2[3])) {
  378. idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
  379. coeff = vp56_coeff_bias[idx+5];
  380. for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
  381. coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
  382. } else {
  383. if (vp56_rac_get_prob(c, model2[4]))
  384. coeff = 3 + vp56_rac_get_prob(c, model1[5]);
  385. else
  386. coeff = 2;
  387. }
  388. ct = 2;
  389. } else {
  390. ct = 1;
  391. coeff = 1;
  392. }
  393. sign = vp56_rac_get(c);
  394. coeff = (coeff ^ -sign) + sign;
  395. if (coeff_idx)
  396. coeff *= s->dequant_ac;
  397. idx = model->coeff_index_to_pos[coeff_idx];
  398. s->block_coeff[b][permute[idx]] = coeff;
  399. run = 1;
  400. } else {
  401. /* parse a run */
  402. ct = 0;
  403. if (coeff_idx > 0) {
  404. if (!vp56_rac_get_prob(c, model2[1]))
  405. break;
  406. model3 = model->coeff_runv[coeff_idx >= 6];
  407. run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
  408. if (!run)
  409. for (run=9, i=0; i<6; i++)
  410. run += vp56_rac_get_prob(c, model3[i+8]) << i;
  411. }
  412. }
  413. cg = vp6_coeff_groups[coeff_idx+=run];
  414. model1 = model2 = model->coeff_ract[pt][ct][cg];
  415. }
  416. s->left_block[vp56_b6to4[b]].not_null_dc =
  417. s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
  418. }
  419. }
  420. static int vp6_adjust(int v, int t)
  421. {
  422. int V = v, s = v >> 31;
  423. V ^= s;
  424. V -= s;
  425. if (V-t-1 >= (unsigned)(t-1))
  426. return v;
  427. V = 2*t - V;
  428. V += s;
  429. V ^= s;
  430. return V;
  431. }
  432. static int vp6_block_variance(uint8_t *src, int stride)
  433. {
  434. int sum = 0, square_sum = 0;
  435. int y, x;
  436. for (y=0; y<8; y+=2) {
  437. for (x=0; x<8; x+=2) {
  438. sum += src[x];
  439. square_sum += src[x]*src[x];
  440. }
  441. src += 2*stride;
  442. }
  443. return (16*square_sum - sum*sum) >> 8;
  444. }
  445. static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
  446. int delta, const int16_t *weights)
  447. {
  448. int x, y;
  449. for (y=0; y<8; y++) {
  450. for (x=0; x<8; x++) {
  451. dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
  452. + src[x ] * weights[1]
  453. + src[x+delta ] * weights[2]
  454. + src[x+2*delta] * weights[3] + 64) >> 7);
  455. }
  456. src += stride;
  457. dst += stride;
  458. }
  459. }
  460. static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
  461. int stride, int h_weight, int v_weight)
  462. {
  463. uint8_t *tmp = s->edge_emu_buffer+16;
  464. s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
  465. s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
  466. }
  467. static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride,
  468. const int16_t *h_weights,const int16_t *v_weights)
  469. {
  470. int x, y;
  471. int tmp[8*11];
  472. int *t = tmp;
  473. src -= stride;
  474. for (y=0; y<11; y++) {
  475. for (x=0; x<8; x++) {
  476. t[x] = av_clip_uint8(( src[x-1] * h_weights[0]
  477. + src[x ] * h_weights[1]
  478. + src[x+1] * h_weights[2]
  479. + src[x+2] * h_weights[3] + 64) >> 7);
  480. }
  481. src += stride;
  482. t += 8;
  483. }
  484. t = tmp + 8;
  485. for (y=0; y<8; y++) {
  486. for (x=0; x<8; x++) {
  487. dst[x] = av_clip_uint8(( t[x-8 ] * v_weights[0]
  488. + t[x ] * v_weights[1]
  489. + t[x+8 ] * v_weights[2]
  490. + t[x+16] * v_weights[3] + 64) >> 7);
  491. }
  492. dst += stride;
  493. t += 8;
  494. }
  495. }
  496. static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src,
  497. int offset1, int offset2, int stride,
  498. vp56_mv_t mv, int mask, int select, int luma)
  499. {
  500. int filter4 = 0;
  501. int x8 = mv.x & mask;
  502. int y8 = mv.y & mask;
  503. if (luma) {
  504. x8 *= 2;
  505. y8 *= 2;
  506. filter4 = s->filter_mode;
  507. if (filter4 == 2) {
  508. if (s->max_vector_length &&
  509. (FFABS(mv.x) > s->max_vector_length ||
  510. FFABS(mv.y) > s->max_vector_length)) {
  511. filter4 = 0;
  512. } else if (s->sample_variance_threshold
  513. && (vp6_block_variance(src+offset1, stride)
  514. < s->sample_variance_threshold)) {
  515. filter4 = 0;
  516. }
  517. }
  518. }
  519. if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
  520. offset1 = offset2;
  521. }
  522. if (filter4) {
  523. if (!y8) { /* left or right combine */
  524. vp6_filter_hv4(dst, src+offset1, stride, 1,
  525. vp6_block_copy_filter[select][x8]);
  526. } else if (!x8) { /* above or below combine */
  527. vp6_filter_hv4(dst, src+offset1, stride, stride,
  528. vp6_block_copy_filter[select][y8]);
  529. } else {
  530. vp6_filter_diag4(dst, src+offset1 + ((mv.x^mv.y)>>31), stride,
  531. vp6_block_copy_filter[select][x8],
  532. vp6_block_copy_filter[select][y8]);
  533. }
  534. } else {
  535. if (!x8 || !y8) {
  536. s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
  537. } else {
  538. vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
  539. }
  540. }
  541. }
  542. static av_cold int vp6_decode_init(AVCodecContext *avctx)
  543. {
  544. vp56_context_t *s = avctx->priv_data;
  545. vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6,
  546. avctx->codec->id == CODEC_ID_VP6A);
  547. s->vp56_coord_div = vp6_coord_div;
  548. s->parse_vector_adjustment = vp6_parse_vector_adjustment;
  549. s->adjust = vp6_adjust;
  550. s->filter = vp6_filter;
  551. s->default_models_init = vp6_default_models_init;
  552. s->parse_vector_models = vp6_parse_vector_models;
  553. s->parse_coeff_models = vp6_parse_coeff_models;
  554. s->parse_header = vp6_parse_header;
  555. return 0;
  556. }
  557. AVCodec vp6_decoder = {
  558. "vp6",
  559. CODEC_TYPE_VIDEO,
  560. CODEC_ID_VP6,
  561. sizeof(vp56_context_t),
  562. vp6_decode_init,
  563. NULL,
  564. vp56_free,
  565. vp56_decode_frame,
  566. CODEC_CAP_DR1,
  567. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
  568. };
  569. /* flash version, not flipped upside-down */
  570. AVCodec vp6f_decoder = {
  571. "vp6f",
  572. CODEC_TYPE_VIDEO,
  573. CODEC_ID_VP6F,
  574. sizeof(vp56_context_t),
  575. vp6_decode_init,
  576. NULL,
  577. vp56_free,
  578. vp56_decode_frame,
  579. CODEC_CAP_DR1,
  580. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
  581. };
  582. /* flash version, not flipped upside-down, with alpha channel */
  583. AVCodec vp6a_decoder = {
  584. "vp6a",
  585. CODEC_TYPE_VIDEO,
  586. CODEC_ID_VP6A,
  587. sizeof(vp56_context_t),
  588. vp6_decode_init,
  589. NULL,
  590. vp56_free,
  591. vp56_decode_frame,
  592. CODEC_CAP_DR1,
  593. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
  594. };