⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_mpeg2_dec_blk.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//                     Must be in the range [0, 7].//    pQuantSpec       Pointer to the structure IppiDecodeInterSpec_MPEG2//    QP               Quantization parameter.//    pSrcDst          Pointer to the 8x8 block in the destination image//    srcDstStep       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.*/IppStatus _mp2_ReconstructDCTBlock_MPEG2_32s(Ipp8u  **BitStream_curr_ptr,                                             Ipp32s *BitStream_bit_offset,                                             Ipp32s *scanMatrix,                                             int    quant,                                             Ipp16s *pQuantMatrix,                                             Ipp16s *pDstBlock,                                             Ipp32s *pDstSize){  Ipp8u *BS_curr_ptr;  Ipp32s BS_bit_offset;  int i, j, k;  int val, run, len, sign, mask;  Ipp32u tbl;  Ipp32u code;  int q;  COPY_BITSTREAM(BS, *BitStream)  if (!pQuantMatrix) pQuantMatrix = Qmatrix;  mask = 1;  SHOW_HI9BITS(BS, code);  if (code & 0x80000000) { /* first 2-bit code */    val = (3*quant*pQuantMatrix[0]) >> 5;    sign = SHBITS(code + code, 1);    val = (val ^ sign) - sign;    if ((code & 0x30000000) == 0x20000000) { /* end */      pDstBlock[0] = val;      SKIP_BITS(BS, 4);      *pDstSize = 0;      COPY_BITSTREAM(*BitStream, BS)      return ippStsOk;    }    for (k = 0; k < 64; k++) {      pDstBlock[k] = 0;    }    pDstBlock[0] = val;    mask ^= val;    SKIP_BITS(BS, 2);    SHOW_HI9BITS(BS, code);    i = 0;  } else {    for (k = 0; k < 64; k++) {      pDstBlock[k] = 0;    }    i = -1;  }  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] * quant;      val = val * q >> 5;      sign = SHBITS(code << len, 1);      val = (val ^ sign) - 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;      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;      }    }  }  pDstBlock[63] ^= mask & 1;  SKIP_BITS(BS, 2);  *pDstSize = i;  COPY_BITSTREAM(*BitStream, BS)  return ippStsOk;}MP2_FUNC(IppStatus, ippiDecodeInter8x8IDCTAdd_MPEG2_1u8u, (    Ipp8u**                      ppBitStream,    int*                         pBitOffset,    IppiDecodeInterSpec_MPEG2*   pQuantSpec,    int                          QP,    Ipp8u*                       pSrcDst,    int                          srcDstStep)){  Ipp16s idct[64];  DEF_BLOCK;  IppStatus ret;  int num;  ret = _mp2_ReconstructDCTBlock_MPEG2_32s(    ppBitStream,    pBitOffset,    pQuantSpec->scanMatrix,    QP,    pQuantSpec->quantMatrix,    pDstBlock,    &num);  if (!num) {    int x = (pDstBlock[0] + 4) >> 3;    int i;    for (i = 0; i < 64; i++) { // vectorized      idct[i] = x;    }  } else {    ippiDCT8x8Inv_AANTransposed_16s_C1R(pDstBlock, idct, 16, num);  }  ippiAdd8x8_16s8u_C1IRS(idct, 16, pSrcDst, srcDstStep);  return ret;}/* /////////////////////////////////////////////////////////////////////////////  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,    int*                               BitStream_bit_offset,    IppiDecodeIntraSpec_MPEG2*         pQuantSpec,    int                                quant,    int                                chromaFlag,    Ipp16s*                            dct_dc_past,    Ipp8u*                             pDst,    int                                dstStep)){  int pDstSize[1];  int intra_vlc_format = pQuantSpec->intraVLCFormat;  Ipp32s *scanMatrix = pQuantSpec->scanMatrix;  Ipp16s *pQuantMatrix = pQuantSpec->quantMatrix;  Ipp32s intra_dc_shift = pQuantSpec->intraShiftDC;  DEF_BLOCK;  Ipp8u *BS_curr_ptr;  Ipp32s BS_bit_offset;  int i, j, k;  int val, run, len, sign, mask;  Ipp32u tbl;  Ipp32u code;  COPY_BITSTREAM(BS, *BitStream)  /* DC */  DECODE_DC(val)  val += *dct_dc_past;  *dct_dc_past = val;  val <<= intra_dc_shift;  mask = ~val;  i = 0;  SHOW_HI9BITS(BS, code);  if (intra_vlc_format) {    if ((code & 0xf0000000) == 0x60000000) { /* end */      pDstBlock[0] = val;      //*pDstSize = 0;      SKIP_BITS(BS, 4);      COPY_BITSTREAM(*BitStream, BS)      return ippiDCT8x8Inv_AANTransposed_16s8u_C1R(pDstBlock, pDst, dstStep, 0);    }    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;          pDstBlock[j] = val;          mask ^= val;          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);      val = (val ^ sign) - sign;      SKIP_BITS(BS, (len + 1));      pDstBlock[j] = val;      mask ^= val;      SHOW_HI9BITS(BS, code);    }    pDstBlock[63] ^= mask & 1;    *pDstSize = i;    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;        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)];        } 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 + -