vp6.c 21 KB

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