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.

676 lines
23KB

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