comparison vp3.c @ 2702:5a4e5225cbb6 libavcodec

use VLCs for in place of get_fragment_run_length(), get_mode_code(), and get_motion_vector_vlc()
author melanson
date Tue, 17 May 2005 23:39:23 +0000
parents 1b4a3c083f9d
children 3817945001ce
comparison
equal deleted inserted replaced
2701:6a22fbe16d6d 2702:5a4e5225cbb6
13 * 13 *
14 * You should have received a copy of the GNU Lesser General Public 14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software 15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 17 *
18 * VP3 Video Decoder by Mike Melanson (melanson@pcisys.net)
19 * For more information about the VP3 coding process, visit:
20 * http://www.pcisys.net/~melanson/codecs/
21 *
22 * Theora decoder by Alex Beregszaszi
23 *
24 */ 18 */
25 19
26 /** 20 /**
27 * @file vp3.c 21 * @file vp3.c
28 * On2 VP3 Video Decoder 22 * On2 VP3 Video Decoder
23 *
24 * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
25 * For more information about the VP3 coding process, visit:
26 * http://multimedia.cx/
27 *
28 * Theora decoder by Alex Beregszaszi
29 */ 29 */
30 30
31 #include <stdio.h> 31 #include <stdio.h>
32 #include <stdlib.h> 32 #include <stdlib.h>
33 #include <string.h> 33 #include <string.h>
269 VLC ac_vlc_1[16]; 269 VLC ac_vlc_1[16];
270 VLC ac_vlc_2[16]; 270 VLC ac_vlc_2[16];
271 VLC ac_vlc_3[16]; 271 VLC ac_vlc_3[16];
272 VLC ac_vlc_4[16]; 272 VLC ac_vlc_4[16];
273 273
274 VLC superblock_run_length_vlc;
275 VLC fragment_run_length_vlc;
276 VLC mode_code_vlc;
277 VLC motion_vector_vlc;
278
274 /* these arrays need to be on 16-byte boundaries since SSE2 operations 279 /* these arrays need to be on 16-byte boundaries since SSE2 operations
275 * index into them */ 280 * index into them */
276 int16_t __align16 intra_y_dequant[64]; 281 int16_t __align16 intra_y_dequant[64];
277 int16_t __align16 intra_c_dequant[64]; 282 int16_t __align16 intra_c_dequant[64];
278 int16_t __align16 inter_dequant[64]; 283 int16_t __align16 inter_dequant[64];
1272 1277
1273 /* fragment may or may not be coded; this is the case 1278 /* fragment may or may not be coded; this is the case
1274 * that cares about the fragment coding runs */ 1279 * that cares about the fragment coding runs */
1275 if (current_run == 0) { 1280 if (current_run == 0) {
1276 bit ^= 1; 1281 bit ^= 1;
1282 #if 1
1283 current_run = get_vlc2(gb,
1284 s->fragment_run_length_vlc.table, 5, 2) + 1;
1285 #else
1277 current_run = get_fragment_run_length(gb); 1286 current_run = get_fragment_run_length(gb);
1287 #endif
1278 } 1288 }
1279 1289
1280 if (bit) { 1290 if (bit) {
1281 /* default mode; actual mode will be decoded in 1291 /* default mode; actual mode will be decoded in
1282 * the next phase */ 1292 * the next phase */
1402 1412
1403 /* mode 7 means get 3 bits for each coding mode */ 1413 /* mode 7 means get 3 bits for each coding mode */
1404 if (scheme == 7) 1414 if (scheme == 7)
1405 coding_mode = get_bits(gb, 3); 1415 coding_mode = get_bits(gb, 3);
1406 else 1416 else
1417 {
1418 #if 1
1419 coding_mode = ModeAlphabet[scheme]
1420 [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];
1421 #else
1407 coding_mode = ModeAlphabet[scheme][get_mode_code(gb)]; 1422 coding_mode = ModeAlphabet[scheme][get_mode_code(gb)];
1423 #endif
1424 }
1408 1425
1409 s->macroblock_coding[current_macroblock] = coding_mode; 1426 s->macroblock_coding[current_macroblock] = coding_mode;
1410 for (k = 0; k < 6; k++) { 1427 for (k = 0; k < 6; k++) {
1411 current_fragment = 1428 current_fragment =
1412 s->macroblock_fragments[current_macroblock * 6 + k]; 1429 s->macroblock_fragments[current_macroblock * 6 + k];
1489 1506
1490 case MODE_INTER_PLUS_MV: 1507 case MODE_INTER_PLUS_MV:
1491 case MODE_GOLDEN_MV: 1508 case MODE_GOLDEN_MV:
1492 /* all 6 fragments use the same motion vector */ 1509 /* all 6 fragments use the same motion vector */
1493 if (coding_mode == 0) { 1510 if (coding_mode == 0) {
1511 #if 1
1512 motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
1513 motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
1514 #else
1494 motion_x[0] = get_motion_vector_vlc(gb); 1515 motion_x[0] = get_motion_vector_vlc(gb);
1495 motion_y[0] = get_motion_vector_vlc(gb); 1516 motion_y[0] = get_motion_vector_vlc(gb);
1517 #endif
1496 } else { 1518 } else {
1497 motion_x[0] = get_motion_vector_fixed(gb); 1519 motion_x[0] = get_motion_vector_fixed(gb);
1498 motion_y[0] = get_motion_vector_fixed(gb); 1520 motion_y[0] = get_motion_vector_fixed(gb);
1499 } 1521 }
1500 for (k = 1; k < 6; k++) { 1522 for (k = 1; k < 6; k++) {
1516 /* fetch 4 vectors from the bitstream, one for each 1538 /* fetch 4 vectors from the bitstream, one for each
1517 * Y fragment, then average for the C fragment vectors */ 1539 * Y fragment, then average for the C fragment vectors */
1518 motion_x[4] = motion_y[4] = 0; 1540 motion_x[4] = motion_y[4] = 0;
1519 for (k = 0; k < 4; k++) { 1541 for (k = 0; k < 4; k++) {
1520 if (coding_mode == 0) { 1542 if (coding_mode == 0) {
1543 #if 1
1544 motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
1545 motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
1546 #else
1521 motion_x[k] = get_motion_vector_vlc(gb); 1547 motion_x[k] = get_motion_vector_vlc(gb);
1522 motion_y[k] = get_motion_vector_vlc(gb); 1548 motion_y[k] = get_motion_vector_vlc(gb);
1549 #endif
1523 } else { 1550 } else {
1524 motion_x[k] = get_motion_vector_fixed(gb); 1551 motion_x[k] = get_motion_vector_fixed(gb);
1525 motion_y[k] = get_motion_vector_fixed(gb); 1552 motion_y[k] = get_motion_vector_fixed(gb);
1526 } 1553 }
1527 motion_x[4] += motion_x[k]; 1554 motion_x[4] += motion_x[k];
2494 s->version = 0; 2521 s->version = 0;
2495 else 2522 else
2496 s->version = 1; 2523 s->version = 1;
2497 2524
2498 s->avctx = avctx; 2525 s->avctx = avctx;
2499 #if 0
2500 s->width = avctx->width;
2501 s->height = avctx->height;
2502 #else
2503 s->width = (avctx->width + 15) & 0xFFFFFFF0; 2526 s->width = (avctx->width + 15) & 0xFFFFFFF0;
2504 s->height = (avctx->height + 15) & 0xFFFFFFF0; 2527 s->height = (avctx->height + 15) & 0xFFFFFFF0;
2505 #endif
2506 avctx->pix_fmt = PIX_FMT_YUV420P; 2528 avctx->pix_fmt = PIX_FMT_YUV420P;
2507 avctx->has_b_frames = 0; 2529 avctx->has_b_frames = 0;
2508 if(avctx->idct_algo==FF_IDCT_AUTO) 2530 if(avctx->idct_algo==FF_IDCT_AUTO)
2509 avctx->idct_algo=FF_IDCT_VP3; 2531 avctx->idct_algo=FF_IDCT_VP3;
2510 dsputil_init(&s->dsp, avctx); 2532 dsputil_init(&s->dsp, avctx);
2605 /* group 4 AC histograms */ 2627 /* group 4 AC histograms */
2606 init_vlc(&s->ac_vlc_4[i], 5, 32, 2628 init_vlc(&s->ac_vlc_4[i], 5, 32,
2607 &ac_bias_3[i][0][1], 4, 2, 2629 &ac_bias_3[i][0][1], 4, 2,
2608 &ac_bias_3[i][0][0], 4, 2, 0); 2630 &ac_bias_3[i][0][0], 4, 2, 0);
2609 } 2631 }
2632
2633 init_vlc(&s->fragment_run_length_vlc, 5, 31,
2634 &fragment_run_length_vlc_table[0][1], 4, 2,
2635 &fragment_run_length_vlc_table[0][0], 4, 2, 0);
2636
2637 init_vlc(&s->mode_code_vlc, 3, 8,
2638 &mode_code_vlc_table[0][1], 2, 1,
2639 &mode_code_vlc_table[0][0], 2, 1, 0);
2640
2641 init_vlc(&s->motion_vector_vlc, 6, 63,
2642 &motion_vector_vlc_table[0][1], 2, 1,
2643 &motion_vector_vlc_table[0][0], 2, 1, 0);
2610 2644
2611 /* work out the block mapping tables */ 2645 /* work out the block mapping tables */
2612 s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); 2646 s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
2613 s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int)); 2647 s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int));
2614 s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int)); 2648 s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int));