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.

674 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 (buf_size < 0)
  122. return 0;
  123. if (s->use_huffman) {
  124. s->parse_coeff = vp6_parse_coeff_huffman;
  125. init_get_bits(&s->gb, buf, buf_size<<3);
  126. } else {
  127. vp56_init_range_decoder(&s->cc, buf, buf_size);
  128. s->ccp = &s->cc;
  129. }
  130. } else {
  131. s->ccp = &s->c;
  132. }
  133. return res;
  134. }
  135. static void vp6_coeff_order_table_init(vp56_context_t *s)
  136. {
  137. int i, pos, idx = 1;
  138. s->modelp->coeff_index_to_pos[0] = 0;
  139. for (i=0; i<16; i++)
  140. for (pos=1; pos<64; pos++)
  141. if (s->modelp->coeff_reorder[pos] == i)
  142. s->modelp->coeff_index_to_pos[idx++] = pos;
  143. }
  144. static void vp6_default_models_init(vp56_context_t *s)
  145. {
  146. vp56_model_t *model = s->modelp;
  147. model->vector_dct[0] = 0xA2;
  148. model->vector_dct[1] = 0xA4;
  149. model->vector_sig[0] = 0x80;
  150. model->vector_sig[1] = 0x80;
  151. memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
  152. memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));
  153. memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));
  154. memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));
  155. memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));
  156. vp6_coeff_order_table_init(s);
  157. }
  158. static void vp6_parse_vector_models(vp56_context_t *s)
  159. {
  160. vp56_range_coder_t *c = &s->c;
  161. vp56_model_t *model = s->modelp;
  162. int comp, node;
  163. for (comp=0; comp<2; comp++) {
  164. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0]))
  165. model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
  166. if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1]))
  167. model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
  168. }
  169. for (comp=0; comp<2; comp++)
  170. for (node=0; node<7; node++)
  171. if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node]))
  172. model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
  173. for (comp=0; comp<2; comp++)
  174. for (node=0; node<8; node++)
  175. if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node]))
  176. model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7);
  177. }
  178. /* nodes must ascend by count, but with descending symbol order */
  179. static int vp6_huff_cmp(const void *va, const void *vb)
  180. {
  181. const Node *a = va, *b = vb;
  182. return (a->count - b->count)*16 + (b->sym - a->sym);
  183. }
  184. static void vp6_build_huff_tree(vp56_context_t *s, uint8_t coeff_model[],
  185. const uint8_t *map, unsigned size, VLC *vlc)
  186. {
  187. Node nodes[2*size], *tmp = &nodes[size];
  188. int a, b, i;
  189. /* first compute probabilities from model */
  190. tmp[0].count = 256;
  191. for (i=0; i<size-1; i++) {
  192. a = tmp[i].count * coeff_model[i] >> 8;
  193. b = tmp[i].count * (255 - coeff_model[i]) >> 8;
  194. nodes[map[2*i ]].count = a + !a;
  195. nodes[map[2*i+1]].count = b + !b;
  196. }
  197. /* then build the huffman tree accodring to probabilities */
  198. ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
  199. FF_HUFFMAN_FLAG_HNODE_FIRST);
  200. }
  201. static void vp6_parse_coeff_models(vp56_context_t *s)
  202. {
  203. vp56_range_coder_t *c = &s->c;
  204. vp56_model_t *model = s->modelp;
  205. int def_prob[11];
  206. int node, cg, ctx, pos;
  207. int ct; /* code type */
  208. int pt; /* plane type (0 for Y, 1 for U or V) */
  209. memset(def_prob, 0x80, sizeof(def_prob));
  210. for (pt=0; pt<2; pt++)
  211. for (node=0; node<11; node++)
  212. if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
  213. def_prob[node] = vp56_rac_gets_nn(c, 7);
  214. model->coeff_dccv[pt][node] = def_prob[node];
  215. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  216. model->coeff_dccv[pt][node] = def_prob[node];
  217. }
  218. if (vp56_rac_get(c)) {
  219. for (pos=1; pos<64; pos++)
  220. if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
  221. model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
  222. vp6_coeff_order_table_init(s);
  223. }
  224. for (cg=0; cg<2; cg++)
  225. for (node=0; node<14; node++)
  226. if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
  227. model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
  228. for (ct=0; ct<3; ct++)
  229. for (pt=0; pt<2; pt++)
  230. for (cg=0; cg<6; cg++)
  231. for (node=0; node<11; node++)
  232. if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
  233. def_prob[node] = vp56_rac_gets_nn(c, 7);
  234. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  235. } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
  236. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  237. }
  238. if (s->use_huffman) {
  239. for (pt=0; pt<2; pt++) {
  240. vp6_build_huff_tree(s, model->coeff_dccv[pt],
  241. vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);
  242. vp6_build_huff_tree(s, model->coeff_runv[pt],
  243. vp6_huff_run_map, 9, &s->runv_vlc[pt]);
  244. for (ct=0; ct<3; ct++)
  245. for (cg = 0; cg < 6; cg++)
  246. vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
  247. vp6_huff_coeff_map, 12,
  248. &s->ract_vlc[pt][ct][cg]);
  249. }
  250. memset(s->nb_null, 0, sizeof(s->nb_null));
  251. } else {
  252. /* coeff_dcct is a linear combination of coeff_dccv */
  253. for (pt=0; pt<2; pt++)
  254. for (ctx=0; ctx<3; ctx++)
  255. for (node=0; node<5; node++)
  256. 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);
  257. }
  258. }
  259. static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect)
  260. {
  261. vp56_range_coder_t *c = &s->c;
  262. vp56_model_t *model = s->modelp;
  263. int comp;
  264. *vect = (vp56_mv_t) {0,0};
  265. if (s->vector_candidate_pos < 2)
  266. *vect = s->vector_candidate[0];
  267. for (comp=0; comp<2; comp++) {
  268. int i, delta = 0;
  269. if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
  270. static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
  271. for (i=0; i<sizeof(prob_order); i++) {
  272. int j = prob_order[i];
  273. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
  274. }
  275. if (delta & 0xF0)
  276. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
  277. else
  278. delta |= 8;
  279. } else {
  280. delta = vp56_rac_get_tree(c, vp56_pva_tree,
  281. model->vector_pdv[comp]);
  282. }
  283. if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
  284. delta = -delta;
  285. if (!comp)
  286. vect->x += delta;
  287. else
  288. vect->y += delta;
  289. }
  290. }
  291. /**
  292. * Read number of consecutive blocks with null DC or AC.
  293. * This value is < 74.
  294. */
  295. static unsigned vp6_get_nb_null(vp56_context_t *s)
  296. {
  297. unsigned val = get_bits(&s->gb, 2);
  298. if (val == 2)
  299. val += get_bits(&s->gb, 2);
  300. else if (val == 3) {
  301. val = get_bits1(&s->gb) << 2;
  302. val = 6+val + get_bits(&s->gb, 2+val);
  303. }
  304. return val;
  305. }
  306. static void vp6_parse_coeff_huffman(vp56_context_t *s)
  307. {
  308. vp56_model_t *model = s->modelp;
  309. uint8_t *permute = s->scantable.permutated;
  310. VLC *vlc_coeff;
  311. int coeff, sign, coeff_idx;
  312. int b, cg, idx;
  313. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  314. for (b=0; b<6; b++) {
  315. int ct = 0; /* code type */
  316. if (b > 3) pt = 1;
  317. vlc_coeff = &s->dccv_vlc[pt];
  318. for (coeff_idx=0; coeff_idx<64; ) {
  319. int run = 1;
  320. if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
  321. s->nb_null[coeff_idx][pt]--;
  322. if (coeff_idx)
  323. break;
  324. } else {
  325. coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3);
  326. if (coeff == 0) {
  327. if (coeff_idx) {
  328. int pt = (coeff_idx >= 6);
  329. run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3);
  330. if (run >= 9)
  331. run += get_bits(&s->gb, 6);
  332. } else
  333. s->nb_null[0][pt] = vp6_get_nb_null(s);
  334. ct = 0;
  335. } else if (coeff == 11) { /* end of block */
  336. if (coeff_idx == 1) /* first AC coeff ? */
  337. s->nb_null[1][pt] = vp6_get_nb_null(s);
  338. break;
  339. } else {
  340. int coeff2 = vp56_coeff_bias[coeff];
  341. if (coeff > 4)
  342. coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
  343. ct = 1 + (coeff2 > 1);
  344. sign = get_bits1(&s->gb);
  345. coeff2 = (coeff2 ^ -sign) + sign;
  346. if (coeff_idx)
  347. coeff2 *= s->dequant_ac;
  348. idx = model->coeff_index_to_pos[coeff_idx];
  349. s->block_coeff[b][permute[idx]] = coeff2;
  350. }
  351. }
  352. coeff_idx+=run;
  353. cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
  354. vlc_coeff = &s->ract_vlc[pt][ct][cg];
  355. }
  356. }
  357. }
  358. static void vp6_parse_coeff(vp56_context_t *s)
  359. {
  360. vp56_range_coder_t *c = s->ccp;
  361. vp56_model_t *model = s->modelp;
  362. uint8_t *permute = s->scantable.permutated;
  363. uint8_t *model1, *model2, *model3;
  364. int coeff, sign, coeff_idx;
  365. int b, i, cg, idx, ctx;
  366. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  367. for (b=0; b<6; b++) {
  368. int ct = 1; /* code type */
  369. int run = 1;
  370. if (b > 3) pt = 1;
  371. ctx = s->left_block[vp56_b6to4[b]].not_null_dc
  372. + s->above_blocks[s->above_block_idx[b]].not_null_dc;
  373. model1 = model->coeff_dccv[pt];
  374. model2 = model->coeff_dcct[pt][ctx];
  375. for (coeff_idx=0; coeff_idx<64; ) {
  376. if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
  377. /* parse a coeff */
  378. if (vp56_rac_get_prob(c, model2[2])) {
  379. if (vp56_rac_get_prob(c, model2[3])) {
  380. idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
  381. coeff = vp56_coeff_bias[idx+5];
  382. for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
  383. coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
  384. } else {
  385. if (vp56_rac_get_prob(c, model2[4]))
  386. coeff = 3 + vp56_rac_get_prob(c, model1[5]);
  387. else
  388. coeff = 2;
  389. }
  390. ct = 2;
  391. } else {
  392. ct = 1;
  393. coeff = 1;
  394. }
  395. sign = vp56_rac_get(c);
  396. coeff = (coeff ^ -sign) + sign;
  397. if (coeff_idx)
  398. coeff *= s->dequant_ac;
  399. idx = model->coeff_index_to_pos[coeff_idx];
  400. s->block_coeff[b][permute[idx]] = coeff;
  401. run = 1;
  402. } else {
  403. /* parse a run */
  404. ct = 0;
  405. if (coeff_idx > 0) {
  406. if (!vp56_rac_get_prob(c, model2[1]))
  407. break;
  408. model3 = model->coeff_runv[coeff_idx >= 6];
  409. run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
  410. if (!run)
  411. for (run=9, i=0; i<6; i++)
  412. run += vp56_rac_get_prob(c, model3[i+8]) << i;
  413. }
  414. }
  415. cg = vp6_coeff_groups[coeff_idx+=run];
  416. model1 = model2 = model->coeff_ract[pt][ct][cg];
  417. }
  418. s->left_block[vp56_b6to4[b]].not_null_dc =
  419. s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
  420. }
  421. }
  422. static int vp6_adjust(int v, int t)
  423. {
  424. int V = v, s = v >> 31;
  425. V ^= s;
  426. V -= s;
  427. if (V-t-1 >= (unsigned)(t-1))
  428. return v;
  429. V = 2*t - V;
  430. V += s;
  431. V ^= s;
  432. return V;
  433. }
  434. static int vp6_block_variance(uint8_t *src, int stride)
  435. {
  436. int sum = 0, square_sum = 0;
  437. int y, x;
  438. for (y=0; y<8; y+=2) {
  439. for (x=0; x<8; x+=2) {
  440. sum += src[x];
  441. square_sum += src[x]*src[x];
  442. }
  443. src += 2*stride;
  444. }
  445. return (16*square_sum - sum*sum) >> 8;
  446. }
  447. static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride,
  448. int delta, const int16_t *weights)
  449. {
  450. int x, y;
  451. for (y=0; y<8; y++) {
  452. for (x=0; x<8; x++) {
  453. dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
  454. + src[x ] * weights[1]
  455. + src[x+delta ] * weights[2]
  456. + src[x+2*delta] * weights[3] + 64) >> 7);
  457. }
  458. src += stride;
  459. dst += stride;
  460. }
  461. }
  462. static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src,
  463. int stride, int h_weight, int v_weight)
  464. {
  465. uint8_t *tmp = s->edge_emu_buffer+16;
  466. s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
  467. s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
  468. }
  469. static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride,
  470. const int16_t *h_weights,const int16_t *v_weights)
  471. {
  472. int x, y;
  473. int tmp[8*11];
  474. int *t = tmp;
  475. src -= stride;
  476. for (y=0; y<11; y++) {
  477. for (x=0; x<8; x++) {
  478. t[x] = av_clip_uint8(( src[x-1] * h_weights[0]
  479. + src[x ] * h_weights[1]
  480. + src[x+1] * h_weights[2]
  481. + src[x+2] * h_weights[3] + 64) >> 7);
  482. }
  483. src += stride;
  484. t += 8;
  485. }
  486. t = tmp + 8;
  487. for (y=0; y<8; y++) {
  488. for (x=0; x<8; x++) {
  489. dst[x] = av_clip_uint8(( t[x-8 ] * v_weights[0]
  490. + t[x ] * v_weights[1]
  491. + t[x+8 ] * v_weights[2]
  492. + t[x+16] * v_weights[3] + 64) >> 7);
  493. }
  494. dst += stride;
  495. t += 8;
  496. }
  497. }
  498. static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src,
  499. int offset1, int offset2, int stride,
  500. vp56_mv_t mv, int mask, int select, int luma)
  501. {
  502. int filter4 = 0;
  503. int x8 = mv.x & mask;
  504. int y8 = mv.y & mask;
  505. if (luma) {
  506. x8 *= 2;
  507. y8 *= 2;
  508. filter4 = s->filter_mode;
  509. if (filter4 == 2) {
  510. if (s->max_vector_length &&
  511. (FFABS(mv.x) > s->max_vector_length ||
  512. FFABS(mv.y) > s->max_vector_length)) {
  513. filter4 = 0;
  514. } else if (s->sample_variance_threshold
  515. && (vp6_block_variance(src+offset1, stride)
  516. < s->sample_variance_threshold)) {
  517. filter4 = 0;
  518. }
  519. }
  520. }
  521. if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
  522. offset1 = offset2;
  523. }
  524. if (filter4) {
  525. if (!y8) { /* left or right combine */
  526. vp6_filter_hv4(dst, src+offset1, stride, 1,
  527. vp6_block_copy_filter[select][x8]);
  528. } else if (!x8) { /* above or below combine */
  529. vp6_filter_hv4(dst, src+offset1, stride, stride,
  530. vp6_block_copy_filter[select][y8]);
  531. } else {
  532. vp6_filter_diag4(dst, src+offset1 + ((mv.x^mv.y)>>31), stride,
  533. vp6_block_copy_filter[select][x8],
  534. vp6_block_copy_filter[select][y8]);
  535. }
  536. } else {
  537. if (!x8 || !y8) {
  538. s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8);
  539. } else {
  540. vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
  541. }
  542. }
  543. }
  544. static av_cold int vp6_decode_init(AVCodecContext *avctx)
  545. {
  546. vp56_context_t *s = avctx->priv_data;
  547. vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6,
  548. avctx->codec->id == CODEC_ID_VP6A);
  549. s->vp56_coord_div = vp6_coord_div;
  550. s->parse_vector_adjustment = vp6_parse_vector_adjustment;
  551. s->adjust = vp6_adjust;
  552. s->filter = vp6_filter;
  553. s->default_models_init = vp6_default_models_init;
  554. s->parse_vector_models = vp6_parse_vector_models;
  555. s->parse_coeff_models = vp6_parse_coeff_models;
  556. s->parse_header = vp6_parse_header;
  557. return 0;
  558. }
  559. AVCodec vp6_decoder = {
  560. "vp6",
  561. CODEC_TYPE_VIDEO,
  562. CODEC_ID_VP6,
  563. sizeof(vp56_context_t),
  564. vp6_decode_init,
  565. NULL,
  566. vp56_free,
  567. vp56_decode_frame,
  568. CODEC_CAP_DR1,
  569. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
  570. };
  571. /* flash version, not flipped upside-down */
  572. AVCodec vp6f_decoder = {
  573. "vp6f",
  574. CODEC_TYPE_VIDEO,
  575. CODEC_ID_VP6F,
  576. sizeof(vp56_context_t),
  577. vp6_decode_init,
  578. NULL,
  579. vp56_free,
  580. vp56_decode_frame,
  581. CODEC_CAP_DR1,
  582. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
  583. };
  584. /* flash version, not flipped upside-down, with alpha channel */
  585. AVCodec vp6a_decoder = {
  586. "vp6a",
  587. CODEC_TYPE_VIDEO,
  588. CODEC_ID_VP6A,
  589. sizeof(vp56_context_t),
  590. vp6_decode_init,
  591. NULL,
  592. vp56_free,
  593. vp56_decode_frame,
  594. CODEC_CAP_DR1,
  595. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
  596. };