📄 slice.c
字号:
break; /* illegal, check needed to avoid buffer overflow */
j = scan[i];
DUMPBITS (bit_buf, bits, 12);
NEEDBITS (bit_buf, bits, bit_ptr);
val = SBITS (bit_buf, 8);
if (! (val & 0x7f)) {
DUMPBITS (bit_buf, bits, 8);
val = UBITS (bit_buf, 8) + 2 * val;
}
val = (val * quant_matrix[j]) / 16;
/* oddification */
val = (val + ~SBITS (val, 1)) | 1;
SATURATE (val);
dest[j] = val;
DUMPBITS (bit_buf, bits, 8);
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
} else if (bit_buf >= 0x02000000) {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
} else if (bit_buf >= 0x00800000) {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
} else if (bit_buf >= 0x00200000) {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
} else {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
i += tab->run;
if (i < 64)
goto normal_code;
}
break; /* illegal, check needed to avoid buffer overflow */
}
DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
}
static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
{
int i;
int j;
int val;
const uint8_t * const scan = decoder->scan;
const uint16_t * const quant_matrix = decoder->quantizer_matrix[1];
const DCTtab * tab;
uint32_t bit_buf;
int bits;
const uint8_t * bit_ptr;
int16_t * const dest = decoder->DCTblock;
i = -1;
bit_buf = decoder->bitstream_buf;
bits = decoder->bitstream_bits;
bit_ptr = decoder->bitstream_ptr;
NEEDBITS (bit_buf, bits, bit_ptr);
if (bit_buf >= 0x28000000) {
tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
goto entry_1;
} else
goto entry_2;
while (1) {
if (bit_buf >= 0x28000000) {
tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
entry_1:
i += tab->run;
if (i >= 64)
break; /* end of block */
normal_code:
j = scan[i];
bit_buf <<= tab->len;
bits += tab->len + 1;
val = ((2 * tab->level + 1) * quant_matrix[j]) >> 5;
/* oddification */
val = (val - 1) | 1;
/* if (bitstream_get (1)) val = -val; */
val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
SATURATE (val);
dest[j] = val;
bit_buf <<= 1;
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
}
entry_2:
if (bit_buf >= 0x04000000) {
tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
if (i < 64)
goto normal_code;
/* escape code */
i += UBITS (bit_buf << 6, 6) - 64;
if (i >= 64)
break; /* illegal, check needed to avoid buffer overflow */
j = scan[i];
DUMPBITS (bit_buf, bits, 12);
NEEDBITS (bit_buf, bits, bit_ptr);
val = SBITS (bit_buf, 8);
if (! (val & 0x7f)) {
DUMPBITS (bit_buf, bits, 8);
val = UBITS (bit_buf, 8) + 2 * val;
}
val = 2 * (val + SBITS (val, 1)) + 1;
val = (val * quant_matrix[j]) / 32;
/* oddification */
val = (val + ~SBITS (val, 1)) | 1;
SATURATE (val);
dest[j] = val;
DUMPBITS (bit_buf, bits, 8);
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
} else if (bit_buf >= 0x02000000) {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
} else if (bit_buf >= 0x00800000) {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
} else if (bit_buf >= 0x00200000) {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
} else {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
i += tab->run;
if (i < 64)
goto normal_code;
}
break; /* illegal, check needed to avoid buffer overflow */
}
DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
decoder->bitstream_ptr = bit_ptr;
return i;
}
static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder,
const int cc,
uint8_t * const dest, const int stride)
{
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
NEEDBITS (bit_buf, bits, bit_ptr);
/* Get the intra DC coefficient and inverse quantize it */
if (cc == 0)
decoder->DCTblock[0] =
decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder);
else
decoder->DCTblock[0] =
decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder);
if (decoder->mpeg1) {
if (decoder->coding_type != D_TYPE)
get_mpeg1_intra_block (decoder);
} else if (decoder->intra_vlc_format)
get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
else
get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
mpeg2_idct_copy (decoder->DCTblock, dest, stride);
#undef bit_buf
#undef bits
#undef bit_ptr
}
static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder,
const int cc,
uint8_t * const dest, const int stride)
{
int last;
if (decoder->mpeg1)
last = get_mpeg1_non_intra_block (decoder);
else
last = get_non_intra_block (decoder,
decoder->quantizer_matrix[cc ? 3 : 1]);
mpeg2_idct_add (last, decoder->DCTblock, dest, stride);
}
#define MOTION_420(table,ref,motion_x,motion_y,size,y) \
pos_x = 2 * decoder->offset + motion_x; \
pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
if (unlikely (pos_x > decoder->limit_x)) { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
motion_x = pos_x - 2 * decoder->offset; \
} \
if (unlikely (pos_y > decoder->limit_y_ ## size)) { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
} \
xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \
decoder->stride, size); \
motion_x /= 2; motion_y /= 2; \
xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
offset = (((decoder->offset + motion_x) >> 1) + \
((((decoder->v_offset + motion_y) >> 1) + y/2) * \
decoder->uv_stride)); \
table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \
(decoder->offset >> 1), ref[1] + offset, \
decoder->uv_stride, size/2); \
table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \
(decoder->offset >> 1), ref[2] + offset, \
decoder->uv_stride, size/2)
#define MOTION_FIELD_420(table,ref,motion_x,motion_y,dest_field,op,src_field) \
pos_x = 2 * decoder->offset + motion_x; \
pos_y = decoder->v_offset + motion_y; \
if (unlikely (pos_x > decoder->limit_x)) { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
motion_x = pos_x - 2 * decoder->offset; \
} \
if (unlikely (pos_y > decoder->limit_y)) { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
motion_y = pos_y - decoder->v_offset; \
} \
xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
decoder->offset, \
(ref[0] + (pos_x >> 1) + \
((pos_y op) + src_field) * decoder->stride), \
2 * decoder->stride, 8); \
motion_x /= 2; motion_y /= 2; \
xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
offset = (((decoder->offset + motion_x) >> 1) + \
(((decoder->v_offset >> 1) + (motion_y op) + src_field) * \
decoder->uv_stride)); \
table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
(decoder->offset >> 1), ref[1] + offset, \
2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \
(decoder->offset >> 1), ref[2] + offset, \
2 * decoder->uv_stride, 4)
#define MOTION_DMV_420(table,ref,motion_x,motion_y) \
pos_x = 2 * decoder->offset + motion_x; \
pos_y = decoder->v_offset + motion_y; \
if (unlikely (pos_x > decoder->limit_x)) { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
motion_x = pos_x - 2 * decoder->offset; \
} \
if (unlikely (pos_y > decoder->limit_y)) { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
motion_y = pos_y - decoder->v_offset; \
} \
xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
table[xy_half] (decoder->dest[0] + decoder->offset, \
ref[0] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
ref[0] + decoder->stride + offset, \
2 * decoder->stride, 8); \
motion_x /= 2; motion_y /= 2; \
xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
offset = (((decoder->offset + motion_x) >> 1) + \
(((decoder->v_offset >> 1) + (motion_y & ~1)) * \
decoder->uv_stride)); \
table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \
ref[1] + offset, 2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
(decoder->offset >> 1), \
ref[1] + decoder->uv_stride + offset, \
2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \
ref[2] + offset, 2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
(decoder->offset >> 1), \
ref[2] + decoder->uv_stride + offset, \
2 * decoder->uv_stride, 4)
#define MOTION_ZERO_420(table,ref) \
table[0] (decoder->dest[0] + decoder->offset, \
(ref[0] + decoder->offset + \
decoder->v_offset * decoder->stride), decoder->stride, 16); \
offset = ((decoder->offset >> 1) + \
(decoder->v_offset >> 1) * decoder->uv_stride); \
table[4] (decoder->dest[1] + (decoder->offset >> 1), \
ref[1] + offset, decoder->uv_stride, 8); \
table[4] (decoder->dest[2] + (decoder->offset >> 1), \
ref[2] + offset, decoder->uv_stride, 8)
#define MOTION_422(table,ref,motion_x,motion_y,size,y) \
pos_x = 2 * decoder->offset + motion_x; \
pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
if (unlikely (pos_x > decoder->limit_x)) { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
motion_x = pos_x - 2 * decoder->offset; \
} \
if (unlikely (pos_y > decoder->limit_y_ ## size)) { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
} \
xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
ref[0] + offset, decoder->stride, size); \
offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
motion_x /= 2; \
xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \
(decoder->offset >> 1), ref[1] + offset, \
decoder->uv_stride, size); \
table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \
(decoder->offset >> 1), ref[2] + offset, \
decoder->uv_stride, size)
#define MOTION_FIELD_422(table,ref,motion_x,motion_y,dest_field,op,src_field) \
pos_x = 2 * decoder->offset + motion_x; \
pos_y = decoder->v_offset + motion_y; \
if (unlikely (pos_x > decoder->limit_x)) { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
motion_x = pos_x - 2 * decoder->offset; \
} \
if (unlikely (pos_y > decoder->limit_y)) { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
motion_y = pos_y - decoder->v_offset; \
} \
xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
decoder->offset, ref[0] + offset, \
2 * decoder->stride, 8); \
offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
motion_x /= 2; \
xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
(decoder->offset >> 1), ref[1] + offset, \
2 * decoder->uv_stride, 8); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -