diff options
author | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-03-04 21:01:54 +0000 |
---|---|---|
committer | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-03-04 21:01:54 +0000 |
commit | 156ec7764eec11e78de6b7a17cef7679a9e30a63 (patch) | |
tree | a37ef9ade32aa15f51049aed533c7e7258749c6f /libmpeg2/slice.c | |
parent | c25474941c626032141c0a142274ce6769927d86 (diff) | |
download | mpv-156ec7764eec11e78de6b7a17cef7679a9e30a63.tar.bz2 mpv-156ec7764eec11e78de6b7a17cef7679a9e30a63.tar.xz |
libmpeg2-0.2.0 merge
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@37 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpeg2/slice.c')
-rw-r--r-- | libmpeg2/slice.c | 928 |
1 files changed, 463 insertions, 465 deletions
diff --git a/libmpeg2/slice.c b/libmpeg2/slice.c index 13940b3387..5c235d86ca 100644 --- a/libmpeg2/slice.c +++ b/libmpeg2/slice.c @@ -1,6 +1,6 @@ /* * slice.c - * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> + * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -24,6 +24,7 @@ #include <string.h> #include <inttypes.h> +#include "video_out.h" #include "mpeg2_internal.h" #include "attributes.h" @@ -31,8 +32,6 @@ extern mc_functions_t mc_functions; extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride); extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride); -static int16_t DCTblock[64] ATTR_ALIGN(16); - #include "vlc.h" static int non_linear_quantizer_scale [] = { @@ -42,24 +41,23 @@ static int non_linear_quantizer_scale [] = { 56, 64, 72, 80, 88, 96, 104, 112 }; -static inline int get_macroblock_modes (slice_t * slice, int picture_structure, - int picture_coding_type, - int frame_pred_frame_dct) +static inline int get_macroblock_modes (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int macroblock_modes; MBtab * tab; - switch (picture_coding_type) { + switch (picture->picture_coding_type) { case I_TYPE: tab = MB_I + UBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if ((! frame_pred_frame_dct) && (picture_structure == FRAME_PICTURE)) { + if ((! (picture->frame_pred_frame_dct)) && + (picture->picture_structure == FRAME_PICTURE)) { macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; DUMPBITS (bit_buf, bits, 1); } @@ -72,13 +70,13 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if (picture_structure != FRAME_PICTURE) { + if (picture->picture_structure != FRAME_PICTURE) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; - } else if (frame_pred_frame_dct) { + } else if (picture->frame_pred_frame_dct) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) macroblock_modes |= MC_FRAME; return macroblock_modes; @@ -100,14 +98,14 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; - if (picture_structure != FRAME_PICTURE) { + if (picture->picture_structure != FRAME_PICTURE) { if (! (macroblock_modes & MACROBLOCK_INTRA)) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; - } else if (frame_pred_frame_dct) { - //if (! (macroblock_modes & MACROBLOCK_INTRA)) + } else if (picture->frame_pred_frame_dct) { + /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ macroblock_modes |= MC_FRAME; return macroblock_modes; } else { @@ -136,18 +134,18 @@ static inline int get_macroblock_modes (slice_t * slice, int picture_structure, #undef bit_ptr } -static inline int get_quantizer_scale (slice_t * slice, int q_scale_type) +static inline int get_quantizer_scale (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int quantizer_scale_code; quantizer_scale_code = UBITS (bit_buf, 5); DUMPBITS (bit_buf, bits, 5); - if (q_scale_type) + if (picture->q_scale_type) return non_linear_quantizer_scale [quantizer_scale_code]; else return quantizer_scale_code << 1; @@ -156,11 +154,11 @@ static inline int get_quantizer_scale (slice_t * slice, int q_scale_type) #undef bit_ptr } -static inline int get_motion_delta (slice_t * slice, int f_code) +static inline int get_motion_delta (picture_t * picture, int f_code) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int delta; int sign; @@ -226,11 +224,11 @@ static inline int bound_motion_vector (int vector, int f_code) #endif } -static inline int get_dmv (slice_t * slice) +static inline int get_dmv (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DMVtab * tab; @@ -242,11 +240,11 @@ static inline int get_dmv (slice_t * slice) #undef bit_ptr } -static inline int get_coded_block_pattern (slice_t * slice) +static inline int get_coded_block_pattern (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) CBPtab * tab; @@ -270,11 +268,11 @@ static inline int get_coded_block_pattern (slice_t * slice) #undef bit_ptr } -static inline int get_luma_dc_dct_diff (slice_t * slice) +static inline int get_luma_dc_dct_diff (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DCtab * tab; int size; int dc_diff; @@ -307,11 +305,11 @@ static inline int get_luma_dc_dct_diff (slice_t * slice) #undef bit_ptr } -static inline int get_chroma_dc_dct_diff (slice_t * slice) +static inline int get_chroma_dc_dct_diff (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) DCtab * tab; int size; int dc_diff; @@ -344,35 +342,34 @@ static inline int get_chroma_dc_dct_diff (slice_t * slice) #undef bit_ptr } -#define SATURATE(val) \ -do { \ - if (val > 2047) \ - val = 2047; \ - else if (val < -2048) \ - val = -2048; \ +#define SATURATE(val) \ +do { \ + if ((uint32_t)(val + 2048) > 4095) \ + val = (val > 0) ? 2047 : -2048; \ } while (0) -static void get_intra_block_B14 (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_intra_block_B14 (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; + dest = picture->DCTblock; i = 0; mismatch = ~dest[0]; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -383,7 +380,7 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -391,7 +388,7 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -411,11 +408,11 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -456,36 +453,37 @@ static void get_intra_block_B14 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_intra_block_B15 (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_intra_block_B15 (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; + dest = picture->DCTblock; i = 0; mismatch = ~dest[0]; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -503,7 +501,7 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -517,16 +515,16 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, } else { - // end of block. I commented out this code because if we - // dont exit here we will still exit at the later test :) + /* end of block. I commented out this code because if we */ + /* dont exit here we will still exit at the later test :) */ - //if (i >= 128) break; // end of block + /* if (i >= 128) break; */ /* end of block */ - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check against buffer overflow + break; /* illegal, check against buffer overflow */ j = scan[i]; @@ -568,36 +566,37 @@ static void get_intra_block_B15 (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 4); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_non_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_non_intra_block (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->non_intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; int mismatch; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = -1; mismatch = 1; + dest = picture->DCTblock; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); if (bit_buf >= 0x28000000) { @@ -614,7 +613,7 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, entry_1: i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -622,7 +621,7 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -645,11 +644,11 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -690,34 +689,35 @@ static void get_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } dest[63] ^= mismatch & 1; - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_mpeg1_intra_block (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = 0; + dest = picture->DCTblock; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); @@ -728,7 +728,7 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -736,10 +736,10 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; - // oddification + /* oddification */ val = (val - 1) | 1; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -758,11 +758,11 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -775,7 +775,7 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, } val = (val * quantizer_scale * quant_matrix[j]) / 16; - // oddification + /* oddification */ val = (val + ~SBITS (val, 1)) | 1; SATURATE (val); @@ -809,33 +809,34 @@ static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, - int16_t * dest) +static void get_mpeg1_non_intra_block (picture_t * picture) { int i; int j; int val; uint8_t * scan = picture->scan; uint8_t * quant_matrix = picture->non_intra_quantizer_matrix; - int quantizer_scale = slice->quantizer_scale; + int quantizer_scale = picture->quantizer_scale; DCTtab * tab; uint32_t bit_buf; int bits; uint8_t * bit_ptr; + int16_t * dest; i = -1; + dest = picture->DCTblock; - bit_buf = slice->bitstream_buf; - bits = slice->bitstream_bits; - bit_ptr = slice->bitstream_ptr; + bit_buf = picture->bitstream_buf; + bits = picture->bitstream_bits; + bit_ptr = picture->bitstream_ptr; NEEDBITS (bit_buf, bits, bit_ptr); if (bit_buf >= 0x28000000) { @@ -852,7 +853,7 @@ static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, entry_1: i += tab->run; if (i >= 64) - break; // end of block + break; /* end of block */ normal_code: j = scan[i]; @@ -860,10 +861,10 @@ static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, bits += tab->len + 1; val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; - // oddification + /* oddification */ val = (val - 1) | 1; - // if (bitstream_get (1)) val = -val; + /* if (bitstream_get (1)) val = -val; */ val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SATURATE (val); @@ -885,11 +886,11 @@ static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; - // escape code + /* escape code */ i += UBITS (bit_buf << 6, 6) - 64; if (i >= 64) - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ j = scan[i]; @@ -903,7 +904,7 @@ static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, val = 2 * (val + SBITS (val, 1)) + 1; val = (val * quantizer_scale * quant_matrix[j]) / 32; - // oddification + /* oddification */ val = (val + ~SBITS (val, 1)) | 1; SATURATE (val); @@ -937,19 +938,19 @@ static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, if (i < 64) goto normal_code; } - break; // illegal, but check needed to avoid buffer overflow + break; /* illegal, check needed to avoid buffer overflow */ } - DUMPBITS (bit_buf, bits, 2); // dump end of block code - slice->bitstream_buf = bit_buf; - slice->bitstream_bits = bits; - slice->bitstream_ptr = bit_ptr; + DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ + picture->bitstream_buf = bit_buf; + picture->bitstream_bits = bits; + picture->bitstream_ptr = bit_ptr; } -static inline int get_macroblock_address_increment (slice_t * slice) +static inline int get_macroblock_address_increment (picture_t * picture) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) MBAtab * tab; int mba; @@ -966,14 +967,14 @@ static inline int get_macroblock_address_increment (slice_t * slice) DUMPBITS (bit_buf, bits, tab->len); return mba + tab->mba; } else switch (UBITS (bit_buf, 11)) { - case 8: // macroblock_escape + case 8: /* macroblock_escape */ mba += 33; - // no break here on purpose - case 15: // macroblock_stuffing (MPEG1 only) + /* no break here on purpose */ + case 15: /* macroblock_stuffing (MPEG1 only) */ DUMPBITS (bit_buf, bits, 11); NEEDBITS (bit_buf, bits, bit_ptr); break; - default: // end of slice, or error + default: /* end of slice, or error */ return 0; } } @@ -983,43 +984,44 @@ static inline int get_macroblock_address_increment (slice_t * slice) #undef bit_ptr } -static inline void slice_intra_DCT (picture_t * picture, slice_t * slice, - int cc, uint8_t * dest, int stride) +static inline void slice_intra_DCT (picture_t * picture, int cc, + uint8_t * dest, int stride) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) NEEDBITS (bit_buf, bits, bit_ptr); - //Get the intra DC coefficient and inverse quantize it + /* Get the intra DC coefficient and inverse quantize it */ if (cc == 0) - slice->dc_dct_pred[0] += get_luma_dc_dct_diff (slice); + picture->dc_dct_pred[0] += get_luma_dc_dct_diff (picture); else - slice->dc_dct_pred[cc] += get_chroma_dc_dct_diff (slice); - DCTblock[0] = slice->dc_dct_pred[cc] << (3 - picture->intra_dc_precision); + picture->dc_dct_pred[cc] += get_chroma_dc_dct_diff (picture); + picture->DCTblock[0] = + picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision); + memset (picture->DCTblock + 1, 0, 63 * sizeof (int16_t)); if (picture->mpeg1) { if (picture->picture_coding_type != D_TYPE) - get_mpeg1_intra_block (picture, slice, DCTblock); + get_mpeg1_intra_block (picture); } else if (picture->intra_vlc_format) - get_intra_block_B15 (picture, slice, DCTblock); + get_intra_block_B15 (picture); else - get_intra_block_B14 (picture, slice, DCTblock); - idct_block_copy (DCTblock, dest, stride); - memset (DCTblock, 0, sizeof (DCTblock)); + get_intra_block_B14 (picture); + idct_block_copy (picture->DCTblock, dest, stride); #undef bit_buf #undef bits #undef bit_ptr } -static inline void slice_non_intra_DCT (picture_t * picture, slice_t * slice, - uint8_t * dest, int stride) +static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest, + int stride) { + memset (picture->DCTblock, 0, 64 * sizeof (int16_t)); if (picture->mpeg1) - get_mpeg1_non_intra_block (picture, slice, DCTblock); + get_mpeg1_non_intra_block (picture); else - get_non_intra_block (picture, slice, DCTblock); - idct_block_add (DCTblock, dest, stride); - memset (DCTblock, 0, sizeof (DCTblock)); + get_non_intra_block (picture); + idct_block_add (picture->DCTblock, dest, stride); } static inline void motion_block (void (** table) (uint8_t *, uint8_t *, @@ -1058,22 +1060,24 @@ static inline void motion_block (void (** table) (uint8_t *, uint8_t *, } -static void motion_mp1 (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_mp1 (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int motion_x, motion_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[0]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[0]); motion_y = bound_motion_vector (motion_y, motion->f_code[0]); motion->pmv[0][1] = motion_y; @@ -1083,14 +1087,14 @@ static void motion_mp1 (slice_t * slice, motion_t * motion, } motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_mp1_reuse (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_mp1_reuse (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { int motion_x, motion_y; @@ -1104,42 +1108,44 @@ static void motion_mp1_reuse (slice_t * slice, motion_t * motion, } motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); } -static void motion_fr_frame (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_frame (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int motion_x, motion_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); + motion_y = motion->pmv[0][1] + get_motion_delta (picture, + motion->f_code[1]); motion_y = bound_motion_vector (motion_y, motion->f_code[1]); motion->pmv[1][1] = motion->pmv[0][1] = motion_y; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width, 16, 0); + motion->ref[0], offset, stride, 16, 0); #undef bit_buf #undef bits #undef bit_ptr } -static void motion_fr_field (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_field (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int motion_x, motion_y; int field_select; @@ -1147,143 +1153,147 @@ static void motion_fr_field (slice_t * slice, motion_t * motion, field_select = SBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, 1); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[0][1] = motion_y << 1; motion_block (table, motion_x, motion_y, dest, offset, - motion->ref[0], offset + (field_select & width), - width * 2, 8, 0); + motion->ref[0], offset + (field_select & stride), + stride * 2, 8, 0); NEEDBITS (bit_buf, bits, bit_ptr); field_select = SBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, 1); - motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[1][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[1][1] = motion_y << 1; - motion_block (table, motion_x, motion_y, dest, offset + width, - motion->ref[0], offset + (field_select & width), - width * 2, 8, 0); + motion_block (table, motion_x, motion_y, dest, offset + stride, + motion->ref[0], offset + (field_select & stride), + stride * 2, 8, 0); #undef bit_buf #undef bits #undef bit_ptr } -static int motion_dmv_top_field_first; -static void motion_fr_dmv (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +static void motion_fr_dmv (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { -#define bit_buf (slice->bitstream_buf) -#define bits (slice->bitstream_bits) -#define bit_ptr (slice->bitstream_ptr) +#define bit_buf (picture->bitstream_buf) +#define bits (picture->bitstream_bits) +#define bit_ptr (picture->bitstream_ptr) int motion_x, motion_y; int dmv_x, dmv_y; int m; int other_x, other_y; NEEDBITS (bit_buf, bits, bit_ptr); - motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); + motion_x = motion->pmv[0][0] + get_motion_delta (picture, + motion->f_code[0]); motion_x = bound_motion_vector (motion_x, motion->f_code[0]); motion->pmv[1][0] = motion->pmv[0][0] = motion_x; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_x = get_dmv (slice); + dmv_x = get_dmv (picture); NEEDBITS (bit_buf, bits, bit_ptr); - motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, + motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture, motion->f_code[1]); - //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); + /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; NEEDBITS (bit_buf, bits, bit_ptr); - dmv_y = get_dmv (slice); + dmv_y = get_dmv (picture); motion_block (mc_functions.put, motion_x, motion_y, dest, offset, - motion->ref[0], offset, width * 2, 8, 0); + motion->ref[0], offset, stride * 2, 8, 0); - m = motion_dmv_top_field_first ? 1 : 3; + m = picture->top_field_first ? 1 : 3; other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; motion_block (mc_functions.avg, other_x, other_y, dest, offset, - motion->ref[0], offset + width, width * 2, 8, 0); + motion->ref[0], offset + stride, stride * 2, 8, 0); - motion_block (mc_functions.put, motion_x, motion_y, dest, offset + width, - motion->ref[0], offset + width, width * 2, 8, 0); + motion_block (mc_functions.put, motion_x, motion_y, dest, offset + stride, + motion->ref[0], offset + stride, stride * 2, 8, 0); - m = motion_dmv_top_field_first ? 3 : 1; + m = picture->top_field_first ? 3 : 1; other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; - motion_block (mc_functions.avg, other_x, other_y, dest, offset + width, - motion->ref[0], offset, width * 2, 8, 0); + motion_block (mc_functions.avg, other_x, other_y, dest, offset + stride, + motion->ref[0], offset, stride * 2, 8, 0); #undef bit_buf #undef bits #undef bit_ptr } -// like motion_frame, but reuse previous motion vectors -static void motion_fr_reuse (slice_t * slice, motion_t * motion, - uint8_t * dest[3], int offset, int width, +/* like motion_frame, but reuse previous motion vectors */ +static void motion_fr_reuse (picture_t * picture, motion_t * motion, + uint8_t * dest[3], int offset, int stride, void (** table) (uint8_t *, uint8_t *, int, int)) { motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, - motion->ref[0], offset, width, 16, 0); |