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.

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