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.

682 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, FF_HUFFMAN_BITS,
  222. nodes, vp6_huff_cmp,
  223. FF_HUFFMAN_FLAG_HNODE_FIRST);
  224. }
  225. static int vp6_parse_coeff_models(VP56Context *s)
  226. {
  227. VP56RangeCoder *c = &s->c;
  228. VP56Model *model = s->modelp;
  229. int def_prob[11];
  230. int node, cg, ctx, pos;
  231. int ct; /* code type */
  232. int pt; /* plane type (0 for Y, 1 for U or V) */
  233. memset(def_prob, 0x80, sizeof(def_prob));
  234. for (pt=0; pt<2; pt++)
  235. for (node=0; node<11; node++)
  236. if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {
  237. def_prob[node] = vp56_rac_gets_nn(c, 7);
  238. model->coeff_dccv[pt][node] = def_prob[node];
  239. } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
  240. model->coeff_dccv[pt][node] = def_prob[node];
  241. }
  242. if (vp56_rac_get(c)) {
  243. for (pos=1; pos<64; pos++)
  244. if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))
  245. model->coeff_reorder[pos] = vp56_rac_gets(c, 4);
  246. vp6_coeff_order_table_init(s);
  247. }
  248. for (cg=0; cg<2; cg++)
  249. for (node=0; node<14; node++)
  250. if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))
  251. model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);
  252. for (ct=0; ct<3; ct++)
  253. for (pt=0; pt<2; pt++)
  254. for (cg=0; cg<6; cg++)
  255. for (node=0; node<11; node++)
  256. if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {
  257. def_prob[node] = vp56_rac_gets_nn(c, 7);
  258. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  259. } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
  260. model->coeff_ract[pt][ct][cg][node] = def_prob[node];
  261. }
  262. if (s->use_huffman) {
  263. for (pt=0; pt<2; pt++) {
  264. if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
  265. vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
  266. return -1;
  267. if (vp6_build_huff_tree(s, model->coeff_runv[pt],
  268. vp6_huff_run_map, 9, &s->runv_vlc[pt]))
  269. return -1;
  270. for (ct=0; ct<3; ct++)
  271. for (cg = 0; cg < 6; cg++)
  272. if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
  273. vp6_huff_coeff_map, 12,
  274. &s->ract_vlc[pt][ct][cg]))
  275. return -1;
  276. }
  277. memset(s->nb_null, 0, sizeof(s->nb_null));
  278. } else {
  279. /* coeff_dcct is a linear combination of coeff_dccv */
  280. for (pt=0; pt<2; pt++)
  281. for (ctx=0; ctx<3; ctx++)
  282. for (node=0; node<5; node++)
  283. 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);
  284. }
  285. return 0;
  286. }
  287. static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
  288. {
  289. VP56RangeCoder *c = &s->c;
  290. VP56Model *model = s->modelp;
  291. int comp;
  292. *vect = (VP56mv) {0,0};
  293. if (s->vector_candidate_pos < 2)
  294. *vect = s->vector_candidate[0];
  295. for (comp=0; comp<2; comp++) {
  296. int i, delta = 0;
  297. if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
  298. static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
  299. for (i=0; i<sizeof(prob_order); i++) {
  300. int j = prob_order[i];
  301. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][j])<<j;
  302. }
  303. if (delta & 0xF0)
  304. delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3;
  305. else
  306. delta |= 8;
  307. } else {
  308. delta = vp56_rac_get_tree(c, ff_vp56_pva_tree,
  309. model->vector_pdv[comp]);
  310. }
  311. if (delta && vp56_rac_get_prob(c, model->vector_sig[comp]))
  312. delta = -delta;
  313. if (!comp)
  314. vect->x += delta;
  315. else
  316. vect->y += delta;
  317. }
  318. }
  319. /**
  320. * Read number of consecutive blocks with null DC or AC.
  321. * This value is < 74.
  322. */
  323. static unsigned vp6_get_nb_null(VP56Context *s)
  324. {
  325. unsigned val = get_bits(&s->gb, 2);
  326. if (val == 2)
  327. val += get_bits(&s->gb, 2);
  328. else if (val == 3) {
  329. val = get_bits1(&s->gb) << 2;
  330. val = 6+val + get_bits(&s->gb, 2+val);
  331. }
  332. return val;
  333. }
  334. static void vp6_parse_coeff_huffman(VP56Context *s)
  335. {
  336. VP56Model *model = s->modelp;
  337. uint8_t *permute = s->idct_scantable;
  338. VLC *vlc_coeff;
  339. int coeff, sign, coeff_idx;
  340. int b, cg, idx;
  341. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  342. for (b=0; b<6; b++) {
  343. int ct = 0; /* code type */
  344. if (b > 3) pt = 1;
  345. vlc_coeff = &s->dccv_vlc[pt];
  346. for (coeff_idx = 0;;) {
  347. int run = 1;
  348. if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
  349. s->nb_null[coeff_idx][pt]--;
  350. if (coeff_idx)
  351. break;
  352. } else {
  353. if (get_bits_left(&s->gb) <= 0)
  354. return;
  355. coeff = get_vlc2(&s->gb, vlc_coeff->table, FF_HUFFMAN_BITS, 3);
  356. if (coeff == 0) {
  357. if (coeff_idx) {
  358. int pt = (coeff_idx >= 6);
  359. run += get_vlc2(&s->gb, s->runv_vlc[pt].table, FF_HUFFMAN_BITS, 3);
  360. if (run >= 9)
  361. run += get_bits(&s->gb, 6);
  362. } else
  363. s->nb_null[0][pt] = vp6_get_nb_null(s);
  364. ct = 0;
  365. } else if (coeff == 11) { /* end of block */
  366. if (coeff_idx == 1) /* first AC coeff ? */
  367. s->nb_null[1][pt] = vp6_get_nb_null(s);
  368. break;
  369. } else {
  370. int coeff2 = ff_vp56_coeff_bias[coeff];
  371. if (coeff > 4)
  372. coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
  373. ct = 1 + (coeff2 > 1);
  374. sign = get_bits1(&s->gb);
  375. coeff2 = (coeff2 ^ -sign) + sign;
  376. if (coeff_idx)
  377. coeff2 *= s->dequant_ac;
  378. idx = model->coeff_index_to_pos[coeff_idx];
  379. s->block_coeff[b][permute[idx]] = coeff2;
  380. }
  381. }
  382. coeff_idx+=run;
  383. if (coeff_idx >= 64)
  384. break;
  385. cg = FFMIN(vp6_coeff_groups[coeff_idx], 3);
  386. vlc_coeff = &s->ract_vlc[pt][ct][cg];
  387. }
  388. }
  389. }
  390. static void vp6_parse_coeff(VP56Context *s)
  391. {
  392. VP56RangeCoder *c = s->ccp;
  393. VP56Model *model = s->modelp;
  394. uint8_t *permute = s->idct_scantable;
  395. uint8_t *model1, *model2, *model3;
  396. int coeff, sign, coeff_idx;
  397. int b, i, cg, idx, ctx;
  398. int pt = 0; /* plane type (0 for Y, 1 for U or V) */
  399. for (b=0; b<6; b++) {
  400. int ct = 1; /* code type */
  401. int run = 1;
  402. if (b > 3) pt = 1;
  403. ctx = s->left_block[ff_vp56_b6to4[b]].not_null_dc
  404. + s->above_blocks[s->above_block_idx[b]].not_null_dc;
  405. model1 = model->coeff_dccv[pt];
  406. model2 = model->coeff_dcct[pt][ctx];
  407. coeff_idx = 0;
  408. for (;;) {
  409. if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) {
  410. /* parse a coeff */
  411. if (vp56_rac_get_prob(c, model2[2])) {
  412. if (vp56_rac_get_prob(c, model2[3])) {
  413. idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1);
  414. coeff = ff_vp56_coeff_bias[idx+5];
  415. for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--)
  416. coeff += vp56_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
  417. } else {
  418. if (vp56_rac_get_prob(c, model2[4]))
  419. coeff = 3 + vp56_rac_get_prob(c, model1[5]);
  420. else
  421. coeff = 2;
  422. }
  423. ct = 2;
  424. } else {
  425. ct = 1;
  426. coeff = 1;
  427. }
  428. sign = vp56_rac_get(c);
  429. coeff = (coeff ^ -sign) + sign;
  430. if (coeff_idx)
  431. coeff *= s->dequant_ac;
  432. idx = model->coeff_index_to_pos[coeff_idx];
  433. s->block_coeff[b][permute[idx]] = coeff;
  434. run = 1;
  435. } else {
  436. /* parse a run */
  437. ct = 0;
  438. if (coeff_idx > 0) {
  439. if (!vp56_rac_get_prob(c, model2[1]))
  440. break;
  441. model3 = model->coeff_runv[coeff_idx >= 6];
  442. run = vp56_rac_get_tree(c, vp6_pcr_tree, model3);
  443. if (!run)
  444. for (run=9, i=0; i<6; i++)
  445. run += vp56_rac_get_prob(c, model3[i+8]) << i;
  446. }
  447. }
  448. coeff_idx += run;
  449. if (coeff_idx >= 64)
  450. break;
  451. cg = vp6_coeff_groups[coeff_idx];
  452. model1 = model2 = model->coeff_ract[pt][ct][cg];
  453. }
  454. s->left_block[ff_vp56_b6to4[b]].not_null_dc =
  455. s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0];
  456. }
  457. }
  458. static int vp6_block_variance(uint8_t *src, ptrdiff_t stride)
  459. {
  460. int sum = 0, square_sum = 0;
  461. int y, x;
  462. for (y=0; y<8; y+=2) {
  463. for (x=0; x<8; x+=2) {
  464. sum += src[x];
  465. square_sum += src[x]*src[x];
  466. }
  467. src += 2*stride;
  468. }
  469. return (16*square_sum - sum*sum) >> 8;
  470. }
  471. static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, ptrdiff_t stride,
  472. int delta, const int16_t *weights)
  473. {
  474. int x, y;
  475. for (y=0; y<8; y++) {
  476. for (x=0; x<8; x++) {
  477. dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
  478. + src[x ] * weights[1]
  479. + src[x+delta ] * weights[2]
  480. + src[x+2*delta] * weights[3] + 64) >> 7);
  481. }
  482. src += stride;
  483. dst += stride;
  484. }
  485. }
  486. static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src,
  487. ptrdiff_t stride, int h_weight, int v_weight)
  488. {
  489. uint8_t *tmp = s->edge_emu_buffer+16;
  490. s->h264chroma.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0);
  491. s->h264chroma.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight);
  492. }
  493. static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src,
  494. int offset1, int offset2, ptrdiff_t stride,
  495. VP56mv mv, int mask, int select, int luma)
  496. {
  497. int filter4 = 0;
  498. int x8 = mv.x & mask;
  499. int y8 = mv.y & mask;
  500. if (luma) {
  501. x8 *= 2;
  502. y8 *= 2;
  503. filter4 = s->filter_mode;
  504. if (filter4 == 2) {
  505. if (s->max_vector_length &&
  506. (FFABS(mv.x) > s->max_vector_length ||
  507. FFABS(mv.y) > s->max_vector_length)) {
  508. filter4 = 0;
  509. } else if (s->sample_variance_threshold
  510. && (vp6_block_variance(src+offset1, stride)
  511. < s->sample_variance_threshold)) {
  512. filter4 = 0;
  513. }
  514. }
  515. }
  516. if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
  517. offset1 = offset2;
  518. }
  519. if (filter4) {
  520. if (!y8) { /* left or right combine */
  521. vp6_filter_hv4(dst, src+offset1, stride, 1,
  522. vp6_block_copy_filter[select][x8]);
  523. } else if (!x8) { /* above or below combine */
  524. vp6_filter_hv4(dst, src+offset1, stride, stride,
  525. vp6_block_copy_filter[select][y8]);
  526. } else {
  527. s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride,
  528. vp6_block_copy_filter[select][x8],
  529. vp6_block_copy_filter[select][y8]);
  530. }
  531. } else {
  532. if (!x8 || !y8) {
  533. s->h264chroma.put_h264_chroma_pixels_tab[0](dst, src + offset1, stride, 8, x8, y8);
  534. } else {
  535. vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8);
  536. }
  537. }
  538. }
  539. static av_cold int vp6_decode_init(AVCodecContext *avctx)
  540. {
  541. VP56Context *s = avctx->priv_data;
  542. int ret;
  543. if ((ret = ff_vp56_init(avctx, avctx->codec->id == AV_CODEC_ID_VP6,
  544. avctx->codec->id == AV_CODEC_ID_VP6A)) < 0)
  545. return ret;
  546. ff_vp6dsp_init(&s->vp56dsp);
  547. s->vp56_coord_div = vp6_coord_div;
  548. s->parse_vector_adjustment = vp6_parse_vector_adjustment;
  549. s->filter = vp6_filter;
  550. s->default_models_init = vp6_default_models_init;
  551. s->parse_vector_models = vp6_parse_vector_models;
  552. s->parse_coeff_models = vp6_parse_coeff_models;
  553. s->parse_header = vp6_parse_header;
  554. return 0;
  555. }
  556. static av_cold int vp6_decode_free(AVCodecContext *avctx)
  557. {
  558. VP56Context *s = avctx->priv_data;
  559. int pt, ct, cg;
  560. ff_vp56_free(avctx);
  561. for (pt=0; pt<2; pt++) {
  562. ff_free_vlc(&s->dccv_vlc[pt]);
  563. ff_free_vlc(&s->runv_vlc[pt]);
  564. for (ct=0; ct<3; ct++)
  565. for (cg=0; cg<6; cg++)
  566. ff_free_vlc(&s->ract_vlc[pt][ct][cg]);
  567. }
  568. return 0;
  569. }
  570. AVCodec ff_vp6_decoder = {
  571. .name = "vp6",
  572. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"),
  573. .type = AVMEDIA_TYPE_VIDEO,
  574. .id = AV_CODEC_ID_VP6,
  575. .priv_data_size = sizeof(VP56Context),
  576. .init = vp6_decode_init,
  577. .close = vp6_decode_free,
  578. .decode = ff_vp56_decode_frame,
  579. .capabilities = AV_CODEC_CAP_DR1,
  580. };
  581. /* flash version, not flipped upside-down */
  582. AVCodec ff_vp6f_decoder = {
  583. .name = "vp6f",
  584. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"),
  585. .type = AVMEDIA_TYPE_VIDEO,
  586. .id = AV_CODEC_ID_VP6F,
  587. .priv_data_size = sizeof(VP56Context),
  588. .init = vp6_decode_init,
  589. .close = vp6_decode_free,
  590. .decode = ff_vp56_decode_frame,
  591. .capabilities = AV_CODEC_CAP_DR1,
  592. };
  593. /* flash version, not flipped upside-down, with alpha channel */
  594. AVCodec ff_vp6a_decoder = {
  595. .name = "vp6a",
  596. .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"),
  597. .type = AVMEDIA_TYPE_VIDEO,
  598. .id = AV_CODEC_ID_VP6A,
  599. .priv_data_size = sizeof(VP56Context),
  600. .init = vp6_decode_init,
  601. .close = vp6_decode_free,
  602. .decode = ff_vp56_decode_frame,
  603. .capabilities = AV_CODEC_CAP_DR1,
  604. };