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

📄 prederrorcod.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
字号:
/*COPYRIGHT, LICENSE AND WARRANTY INFORMATIONThis software module has been originally developed by Nokia Corporation. Provided that a person, entity or a company willing to use the Software (hereinafter Licensee) comply with all the terms and conditions of this Statement and subject to the limitations set forth in this Statement Nokia grants to such Licensee a non-exclusive, sub-licensable, worldwide, limited license under copyrights owned by Nokia to use the Software for the sole purpose of creating, manufacturing, selling, marketing, or  distributing (including the right to make modifications to the Software) a fully compliant decoder implementation (hereinafter "Decoder") of ITU-T Recommendation H.264 / ISO/IEC International Standard 14496-10 and an encoder implementation producing output that is decodable with the Decoder.Nokia retains the ownership of copyrights to the Software. There is no patent nor other intellectual property right of Nokia licensed under this Statement (except the copyright license above). Licensee hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if patent licenses  are required, it is their responsibility to acquire the license before utilizing the Software.The license by Nokia is subject to that the Licensee grants to Nokia the non-exclusive, worldwide, royalty-free, perpetual and irrevocable covenant that the Licensee(s) shall not bring a suit before any court or administrative agency or otherwise assert a claim for infringement under the Licensee intellectual property rights that, but for a license, would be infringed by the Software against     (a)  Nokia or Nokia's Affiliate; or     (b)  other recipient of a license and covenant not to sue with respect         to the Software from Nokia; or    (c)  contractor, customer or distributor of a party listed above in a         or b,  which suit or claim is related to the Software or use thereof.The Licensee(s) further agrees to grant a reciprocal license to Nokia (as granted by Nokia to the Licensee(s) on the modifications made by Licensee(s) to the Software. THE SOFTWARE IS PROVIDED "AS IS" AND THE ORIGINAL DEVELOPER DISCLAIMS ANY AND ALL WARRANTIES WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THOSE INTENDING TO USE THE SOFTWARE ARE EXPRESSLY ADVISED THAT ITS USE MAY INFRINGE EXISTING PATENTS AND BE SUBJECT TO ROYALTY PAYMENTS TO PATENT OWNERS. ANYONE USING THE SOFTWARE ON THE BASIS OF THIS LICENSE AGREES TO OBTAIN THE NECESSARY PERMISSIONS FROM ANY AND ALL APPLICABLE PATENT OWNERS FOR SUCH USE.IN NO EVENT SHALL THE ORIGINAL DEVELOPER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.This copyright, license and warranty information notice must be retained in all copies and derivative works of the Software or substantial portions thereof.*/#include <string.h>#include "globals.h"#include "transform.h"#include "vlcutility.h"#include "prederrordec.h"/* * * pecCodeBlock: * * Parameters: *      orig                  Original pixels for a block *      pred                  Predicted pixels for a block *      coef                  Return pointer for coefficients *      qp                    Quantization parameter *      picType               Type of picture (intra/inter) * * Function: *      Compute prediction error block, transform it and quantize coefficients * * Returns: *      Number of nonzero coefficients */int pecCodeBlock(u_int8 orig[BLK_SIZE][MBK_SIZE],                 u_int8 pred[BLK_SIZE][MBK_SIZE],                 int coef[BLK_SIZE][BLK_SIZE],                 int skip,                 int qp,                  int picType){  int nonZero;  int i, j;  for (j = 0; j < BLK_SIZE; j++)    for (i = 0; i < BLK_SIZE; i++)      coef[j][i] = orig[j][i] - pred[j][i];    /* 4x4 DCT */  traDCT4x4(coef);  /* Normal quantization */  // in JM, quantization for intra16x16 is handled as in an I-frame  nonZero = traQuant4x4(&coef[0][0], skip, qp, picType);  return nonZero;}/* * * pecCodeMB: * * Parameters: *      mb                    Macroblock structure *      picType               Type of picture (intra/inter) * * Function: *      Transform and quantize prediction error of all luma blocks in MB * * Returns: *      - */void pecCodeLumaMB(macroblock_s *pMb,                    u_int8 pred[MBK_SIZE][MBK_SIZE],                   int skip,                   int picType){  int coefQ[BLK_SIZE*BLK_SIZE];  int mbCoefCost, coefCost;  int mbNonZeros, blk8x8NonZeros;  int blk8x8, blkIdx;  int nonZero;  pMb->cbpY = 0;  /*  * Luma AC DCT & quantization  */  mbCoefCost = 0;  /* Set MB coef cost to zero */  mbNonZeros = 0;  for (blk8x8 = 0; blk8x8 < 16; blk8x8 += 4)  {    coefCost = 0;  /* Set 8x8 block coef cost to zero */    blk8x8NonZeros = 0;    for (blkIdx = blk8x8; blkIdx < (blk8x8 + 4); blkIdx ++)    {      int blkX, blkY;      blkX = blkRasterOrder[blkIdx] & 3;      blkY = blkRasterOrder[blkIdx] >> 2;      nonZero = pecCodeBlock(        (u_int8 (*) [MBK_SIZE]) & pMb->origY[blkY * BLK_SIZE][blkX * BLK_SIZE],        (u_int8 (*) [MBK_SIZE]) & pred[blkY * BLK_SIZE][blkX * BLK_SIZE],        pMb->coefY[blkIdx],        skip, pMb->qp, picType);      // record DC coefficient anyway      pMb->dcCoefY[blkY][blkX] = pMb->coefY[blkIdx][0][0];      if (nonZero)      {        // Update luma CBP        pMb->cbpY |= 1 << blkIdx;        if (pMb->coeffElim)        {          blk8x8NonZeros += nonZero;          vlcuZigZagScan4x4(pMb->coefY[blkIdx], coefQ);          coefCost += traGetCoefCost(coefQ + skip, nonZero);        }      }    }    /* Set INTER 8x8 block to zero if coefficient cost */    /* for block is below threshold                    */    if (pMb->coeffElim)    {      if (coefCost <= pMb->coeffElimTh8x8 && blk8x8NonZeros > 0) {        blk8x8NonZeros = 0;        pMb->cbpY &= ~(0x0F << blk8x8);        memset(pMb->coefY[blk8x8], 0, 4 * BLK_SIZE * BLK_SIZE * sizeof(int));      }      mbCoefCost += coefCost;      mbNonZeros += blk8x8NonZeros;    }  }  /* Set INTER MB to zero, if coefficient cost for MB is below threshold */  if (pMb->coeffElim)  {    if (mbCoefCost <= pMb->coeffElimThLuma && mbNonZeros > 0) {      memset(pMb->coefY, 0, MBK_SIZE*MBK_SIZE*sizeof(int));      pMb->cbpY = 0;    }  }  /*  * Transform and quantize luma DC (if 16x16 intra mode)  */  pMb->lumaNonzeroDC = 0;  if (skip) {    /* 4x4 DC DCT */    traHada4x4(pMb->dcCoefY);    /* Quant */    // DBG, check the second from the last parameter, different for luma and chroma    pMb->lumaNonzeroDC = traQuantDC      (& pMb->dcCoefY[0][0], pMb->qp, picType, BLK_PER_MB*BLK_PER_MB, 0);  }}/* * * pecCodeChromaMB: * * Parameters: *      pMb                   Macroblock structure *      picType               Type of picture (intra/inter) * * Function: *      Transform and quantize prediction error of all chroma blocks in MB * * Returns: *      - */void pecCodeChromaMB(macroblock_s *pMb,                      u_int8 predC[MBK_SIZE/2][2*(MBK_SIZE/2)],                     int picType){  int comp, blkIdxX, blkIdxY;  int coefQ[BLK_SIZE*BLK_SIZE];  int mbCoefCost;  int totalNonZero;  int nonZero;  int cbpBit;  pMb->cbpChromaDC = pMb->cbpC = 0;  cbpBit = 1;  for (comp = 0; comp < 2; comp++) {    /*     * Chroma AC transform and quantization     */    mbCoefCost = 0;  /* Set MB coef cost to zero */    totalNonZero = 0;    for (blkIdxY = 0; blkIdxY < BLK_PER_MB/2; blkIdxY ++) {      for (blkIdxX = 0; blkIdxX < BLK_PER_MB/2; blkIdxX ++) {        nonZero = pecCodeBlock(          (u_int8 (*) [MBK_SIZE]) & pMb->origC[blkIdxY*BLK_SIZE][comp*(MBK_SIZE/2)+blkIdxX*BLK_SIZE],          (u_int8 (*) [MBK_SIZE]) & predC[blkIdxY*BLK_SIZE][comp*(MBK_SIZE/2)+blkIdxX*BLK_SIZE],          pMb->coefC[comp][blkIdxY][blkIdxX], 1, pMb->qpC, picType);        /* Take DC coef out */        pMb->dcCoefC[comp][blkIdxY][blkIdxX] =           pMb->coefC[comp][blkIdxY][blkIdxX][0][0];        if (nonZero)        {          if (pMb->coeffElim)          {            totalNonZero += nonZero;            vlcuZigZagScan4x4(pMb->coefC[comp][blkIdxY][blkIdxX], coefQ);            mbCoefCost += traGetCoefCost(coefQ + 1, nonZero);          }          pMb->cbpC |= cbpBit;        }        cbpBit <<= 1;      }    }    /* Set INTER Chroma MB to zero, if coefficient cost for MB is below threshold */    if ((pMb->coeffElim) && (mbCoefCost <= pMb->coeffElimThChroma) && (totalNonZero > 0))    {      int cbpMask;      cbpMask = (1 << (BLK_PER_MB/2*BLK_PER_MB/2)) - 1;      pMb->cbpC &= ~(cbpMask << (comp*(BLK_PER_MB/2*BLK_PER_MB/2)));      memset(pMb->coefC[comp], 0, MBK_SIZE/2*MBK_SIZE/2*sizeof(int));    }    /*     * Chroma DC transform and quantization     */    /* 2x2 DC DCT */    traDCT2x2(pMb->dcCoefC[comp]);    /* 2x2 DC quant */    // DBG treat chroma and luma differently    nonZero = traQuantDC(& pMb->dcCoefC[comp][0][0],                          pMb->qpC, picType, BLK_PER_MB/2*BLK_PER_MB/2, 1);    /* Update chroma CBP */    if (nonZero)      pMb->cbpChromaDC |= 1 << comp;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -