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

📄 motcomp.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 2 页
字号:
/*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 <limits.h>#include "globals.h"#include "vlcutility.h"#include "macroblock.h"const int8 modeBlkIndices[5][4] = {  {0, 0, 0, 0},  {0, 0, 0, 0},  {0, 8, 0, 0},  {0, 2, 0, 0},  {0, 2, 8, 10},};// the first element is always reservedint8 modeNumBlocks[8] ={  16, 16, 8, 8, 4, 2, 2, 1};int8 modePartWidth[8] ={  4, 4, 4, 2, 2, 2, 1, 1};int8 modePartHeight[8] ={  4, 4, 2, 4, 2, 1, 2, 1};#define NA      -2#define MEDIAN(med, a0, a1, a2)   {             \    if ((a0) > (a1)) {                          \      if (a1 > (a2))        (med) = (a1);       \      else if ((a0) > (a2))  (med) = (a2);       \      else                  (med) = (a0);       \    } else if ((a0) > (a2))  (med) = (a0);       \    else if ((a1) > (a2))    (med) = (a2);       \    else                    (med) = (a1);       \  }static const int8 trIdx[8] = {0, 0, 0, 1, 1, 1, 2, 2};/* * * mcpFindPredMv: * * Parameters: *      pMb               Macroblock information *      refNum            Reference frame index for this partition *      mode              Indicate size of partition *      blkAddr           Addr of 1st block of partition in 4x4 block array * * Function: *      Calculate the MV predictor.  * * Returns: *      - * */motVec_s mcpFindPredMv(macroblock_s *pMb,                       int          refNum,                       int          mode,                       int          blkAddr){  motVec_s vecA;  motVec_s vecB;  motVec_s vecC;  motVec_s vecX;  int refLeft, refUp, refUpRight;  int numEqualRefs;  blkState_s *blkLeft, *blkUp, *blkUpRight;  /*   * Fetch vectors and reference frame numbers of blocks A, B and C   */  blkLeft    = pMb->blkLeft[blkAddr];  blkUp      = pMb->blkUp[blkAddr];  blkUpRight = pMb->blkUpRight[trIdx[mode]][blkAddr];  refLeft    = blkLeft->ref == refNum;  vecA       = blkLeft->mv;  refUp      = blkUp->ref == refNum;  vecB       = blkUp->mv;  refUpRight = blkUpRight->ref == refNum;  vecC       = blkUpRight->mv;  numEqualRefs = refLeft + refUp + refUpRight;  // put the most common case in the front  if ((mode > MOT_8x16) && (numEqualRefs > 1))  {    // performa median filtering    MEDIAN(vecX.x, vecA.x, vecB.x, vecC.x);    MEDIAN(vecX.y, vecA.y, vecB.y, vecC.y);  }  else  {    // directional prediction    if (mode == MOT_16x8)    {      if (blkAddr == 0)      {        if (refUp)          return vecB;      }      else       {        if (refLeft)          return vecA;      }    }    else if (mode == MOT_8x16)    {      if (blkAddr == 0)      {        if (refLeft)          return vecA;      }      else      {        // this could be real upRight, or upRight replaced by upLeft        if (refUpRight)          return vecC;      }    }    /*    * If only one of the neighboring block has the same reference    * frame number as the  current block, predict from that block.    */    // this is of little probabability, make it faster    if (numEqualRefs == 1)    {      if (refLeft)        vecX = vecA;      else if (refUp)        vecX = vecB;      else        vecX = vecC;    }    else if ((blkUp->ref == REF_NA) && (blkUpRight->ref == REF_NA) && (blkLeft->ref >= 0))    {      // if only vecA is available, vecA is set as the predictor      vecX = vecA;    }    else    {      // performa median filtering      MEDIAN(vecX.x, vecA.x, vecB.x, vecC.x);      MEDIAN(vecX.y, vecA.y, vecB.y, vecC.y);    }  }  return vecX;}/* * mcpFindDiffMvs: * * Parameters: *      pMb                 Macroblock information *      refIdxRange         Information related to motion estimation * * Function: *      Calculate the differential motion vectors and referenace frame indices *      for all MB partitions. We use the index tables to find the position of *      the first 4x4 block within the partition. * * Returns: *      - */int mcpFindDiffMvs(macroblock_s *pMb,                   int          refIdxRange){  int i, mpIdx, mpBlkAddr, blkAddr;  int mpBlkCount;  int mvBits, interMode, subMbMode, blkMode;  int numVecs, lastNumVecs;  motVec_s predVec;  blkState_s *mrPair, *blkInfo;  mvBits  = 0;  numVecs = 0;  interMode  = pMb->interMode;  subMbMode  = 0;  mpBlkCount = 1;  blkInfo    = & pMb->current[0][0];  for (mpIdx = 0; mpIdx < numOfRefPar[interMode - 1]; mpIdx ++)  {    mpBlkAddr = modeBlkIndices[interMode][mpIdx];    blkAddr   = mpBlkAddr;    pMb->refIndices[mpIdx] = (u_int8) blkInfo[mpBlkAddr].ref;    mvBits += vlcGetRefIndexBits(refIdxRange, pMb->refIndices[mpIdx]);    if (interMode == MOT_8x8)    {      // make index this way to use the same tables      subMbMode  = pMb->interSubMbModes[mpIdx];      mpBlkCount = numOfRefPar[subMbMode];    }    blkMode = interMode + subMbMode;    lastNumVecs = numVecs;    numVecs += mpBlkCount;    for (i = lastNumVecs; i < numVecs; i ++)    {      if (interMode == MOT_8x8)

⌨️ 快捷键说明

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