📄 umc_mpeg2_dec_blk.cpp
字号:
for (;;) {
if ((code & 0xc0000000) == 0x80000000) {
break;
} else if (code >= 0x08000000) {
tbl = MPEG2_VLC_TAB1[UHBITS(code - 0x08000000, 8)];
common:
i++;
UNPACK_VLC1(tbl, run, val, len)
i += run;
i &= 63; // just in case
j = scanMatrix[i];
q = pQuantMatrix[j];
val = val * quant;
val = (val * q) >> 5;
sign = SHBITS(code << len, 1);
APPLY_SIGN(val, sign);
SKIP_BITS(BS, (len+1));
pDstBlock[j] = val;
mask ^= val;
SHOW_HI9BITS(BS, code);
continue;
} else if (code >= 0x04000000) {
EXPAND_17BITS(BS, code);
i += 1 + UHBITS(code << 6, 6);
i &= 63;
j = scanMatrix[i];
EXPAND_25BITS(BS, code);
code <<= 12;
q = quant*pQuantMatrix[j];
val = 2 * (SHBITS(code, 12) + SHBITS(code, 1)) + 1;
val = (val * q) / 32;
SAT(val)
pDstBlock[j] = val;
mask ^= val;
SKIP_BITS(BS, 24);
SHOW_HI9BITS(BS, code);
continue;
} else {
EXPAND_17BITS(BS, code);
if (code >= 0x00800000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_10BIT + UHBITS(code, 13)];
goto common;
} else if (code >= 0x00200000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_15BIT + UHBITS(code, 15)];
goto common;
} else {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_16BIT + UHBITS(code, 16)];
if (code < 16)
return ippStsVLCErr;
code <<= 16;
SKIP_BITS(BS, 16);
goto common;
}
}
}
} else {
Ipp32s q_mul1 = quant << 3;
//pQuantMatrix = Qmatrix;
if (code & 0x80000000) { /* first 2-bit code */
val = q_mul1 + q_mul1 + (q_mul1 &~ 15);
val >>= 4;
sign = SHBITS(code + code, 1);
APPLY_SIGN(val, sign);
if ((code & 0x30000000) == 0x20000000) { /* end */
SKIP_BITS(BS, 4);
COPY_BITSTREAM(*BitStream, BS)
IDCT_INTER1(val, idct, pSrcDst, srcDstStep);
return ippStsOk;
}
for (k = 0; k < 64; k++) {
pDstBlock[k] = 0;
}
pDstBlock[0] = val;
mask = 1 ^ val;
SKIP_BITS(BS, 2);
SHOW_HI9BITS(BS, code);
i = 0;
} else {
for (k = 0; k < 64; k++) {
pDstBlock[k] = 0;
}
i = -1;
mask = 1;
}
for (;;) {
if ((code & 0xc0000000) == 0x80000000) {
break;
} else if (code >= 0x08000000) {
tbl = MPEG2_VLC_TAB1[UHBITS(code - 0x08000000, 8)];
common2:
i++;
UNPACK_VLC1(tbl, run, val, len)
i += run;
i &= 63; // just in case
j = scanMatrix[i];
val = (val*q_mul1) >> 4;
sign = SHBITS(code << len, 1);
APPLY_SIGN(val, sign);
SKIP_BITS(BS, (len+1));
pDstBlock[j] = val;
mask ^= val;
SHOW_HI9BITS(BS, code);
continue;
} else if (code >= 0x04000000) {
EXPAND_17BITS(BS, code);
i += 1 + UHBITS(code << 6, 6);
i &= 63;
j = scanMatrix[i];
EXPAND_25BITS(BS, code);
code <<= 12;
val = 2 * (SHBITS(code, 12) + SHBITS(code, 1)) + 1;
val = (val * quant) / 2;
SAT(val)
pDstBlock[j] = val;
mask ^= val;
SKIP_BITS(BS, 24);
SHOW_HI9BITS(BS, code);
continue;
} else {
EXPAND_17BITS(BS, code);
if (code >= 0x00800000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_10BIT + UHBITS(code, 13)];
goto common2;
} else if (code >= 0x00200000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_15BIT + UHBITS(code, 15)];
goto common2;
} else {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_16BIT + UHBITS(code, 16)];
if (code < 16)
return ippStsVLCErr;
code <<= 16;
SKIP_BITS(BS, 16);
goto common2;
}
}
}
}
pDstBlock[63] ^= mask & 1;
SKIP_BITS(BS, 2);
COPY_BITSTREAM(*BitStream, BS)
IDCT_INTER(pDstBlock, i, idct, pSrcDst, srcDstStep);
return ippStsOk;
}
/* ///////////////////////////////////////////////////////////////////////////
// Name:
// ippiDecodeIntra8x8IDCT_MPEG2_1u8u
// ippiDecodeIntra8x8IDCT_MPEG1_1u8u
//
// Purpose:
// Performs VLC decoding of DCT coefficients for one intra 8x8 block,
// dequantization of coefficients, inverse DCT and storing of resulted
// 8x8 block to destination.
//
// Parameters:
// ppBitStream Pointer to the pointer to the current byte in
// the bitstream, it is updated after block decoding.
// pBitOffset Pointer to the bit position in the byte pointed by
// *ppBitStream, it is updated after block decoding.
// Must be in the range [0, 7].
// pQuantSpec Pointer to the structure IppiDecodeIntraSpec_MPEG2
// QP Quantization parameter.
// blockType Indicates the type of block, takes one of the following
// values:
// IPPVC_BLOCK_LUMA - for luma blocks,
// IPPVC_BLOCK_CHROMA - for chroma blocks
// And in case of MPEG1 D-type block, IPPVC_BLOCK_MPEG1_DTYPE
// have to be added to IPPVC_BLOCK_LUMA or IPPVC_BLOCK_CHROMA.
// pDCPred Pointer to the value to be added to the DC coefficient
// pDst Pointer to the 8x8 block in the destination image
// dstStep Step through the destination image
//
// Returns:
// ippStsNoErr No error.
// ippStsNullPtrErr One of the specified pointers is NULL.
// ippStsVLCErr An illegal code is detected through the
// stream processing.
*/
MP2_FUNC(IppStatus, ippiDecodeIntra8x8IDCT_MPEG2_1u8u, (
Ipp8u** BitStream_curr_ptr,
Ipp32s* BitStream_bit_offset,
IppiDecodeIntraSpec_MPEG2* pQuantSpec,
Ipp32s quant,
Ipp32s chromaFlag,
Ipp16s* dct_dc_past,
Ipp8u* pDst,
Ipp32s dstStep))
{
Ipp32s intra_vlc_format = pQuantSpec->intraVLCFormat;
Ipp32s intra_dc_shift = pQuantSpec->intraShiftDC;
DEF_VARS();
Ipp32s mask;
COPY_BITSTREAM(BS, *BitStream)
/* DC */
DECODE_DC(val)
val += *dct_dc_past;
*dct_dc_past = val;
val <<= intra_dc_shift;
#ifdef MISMATCH_INTRA
mask = ~val;
#endif
i = 0;
SHOW_HI9BITS(BS, code);
if (intra_vlc_format) {
if ((code & 0xf0000000) == 0x60000000) { /* end */
SKIP_BITS(BS, 4);
COPY_BITSTREAM(*BitStream, BS)
IDCT_INTRA1(val, idct, pDst, dstStep);
return ippStsOk;
}
for (k = 0; k < 64; k++) {
pDstBlock[k] = 0;
}
pDstBlock[0] = val;
for (;;) {
if ((code & 0xf0000000) == 0x60000000) {
break;
} else if (code >= 0x08000000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_8BIT_INTRA + UHBITS(code, 8)];
} else if (code >= 0x04000000) {
EXPAND_17BITS(BS, code);
i += 1 + UHBITS (code << 6, 6);
i &= 63;
j = scanMatrix[i];
EXPAND_25BITS(BS, code);
code <<= 12;
val = SHBITS(code, 12);
val = (val * (quant*pQuantMatrix[j])) / 16;
SAT(val)
pDstBlock[j] = val;
#ifdef MISMATCH_INTRA
mask ^= val;
#endif
SKIP_BITS(BS, 24);
SHOW_HI9BITS(BS, code);
continue;
} else {
EXPAND_17BITS(BS, code);
if (code >= 0x02000000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_10BIT_INTRA + UHBITS(code, 10)];
} else if (code >= 0x00800000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_10BIT + UHBITS(code, 13)];
} else if (code >= 0x00200000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_15BIT + UHBITS(code, 15)];
} else {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_16BIT + UHBITS(code, 16)];
if (code < 16)
return ippStsVLCErr;
code <<= 16;
SKIP_BITS(BS, 16);
}
}
i++;
UNPACK_VLC2(tbl, run, val, len)
i += run;
i &= 63;
j = scanMatrix[i];
val = (val*(quant*pQuantMatrix[j])) >> 4;
sign = SHBITS(code << len, 1);
APPLY_SIGN(val, sign);
SKIP_BITS(BS, (len + 1));
pDstBlock[j] = val;
#ifdef MISMATCH_INTRA
mask ^= val;
#endif
SHOW_HI9BITS(BS, code);
}
#ifdef MISMATCH_INTRA
pDstBlock[63] ^= mask & 1;
#endif
SKIP_BITS(BS, 4);
COPY_BITSTREAM(*BitStream, BS)
} else {
for (k = 0; k < 64; k++) {
pDstBlock[k] = 0;
}
pDstBlock[0] = val;
for (;;) {
if ((code & 0xc0000000) == 0x80000000) {
break;
} else if (code >= 0x08000000) {
tbl = MPEG2_VLC_TAB1[UHBITS(code - 0x08000000, 8)];
} else if (code >= 0x04000000) {
EXPAND_17BITS(BS, code);
i += 1 + UHBITS (code << 6, 6);
i &= 63;
j = scanMatrix[i];
EXPAND_25BITS(BS, code);
code <<= 12;
val = SHBITS(code, 12);
val = (val * (quant*pQuantMatrix[j])) / 16;
SAT(val)
pDstBlock[j] = val;
#ifdef MISMATCH_INTRA
mask ^= val;
#endif
SKIP_BITS(BS, 24);
SHOW_HI9BITS(BS, code);
continue;
} else {
EXPAND_17BITS(BS, code);
if (code >= 0x00800000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_10BIT + UHBITS(code, 13)];
} else if (code >= 0x00200000) {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_15BIT + UHBITS(code, 15)];
} else {
tbl = MPEG2_VLC_TAB1[TAB1_OFFSET_16BIT + UHBITS(code, 16)];
if (code < 16)
return ippStsVLCErr;
code <<= 16;
SKIP_BITS(BS, 16);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -