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

📄 globals.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"/* * convert from H.263 QP to H.26L quant given by: quant = pow(2,QP/6) */const int8 QP2QUANT[52] = {               1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,   1, 1, 1, 1, 2, 2, 2, 2,   3, 3, 3, 4, 4, 4, 5, 6,   6, 7, 8, 9,10,11,13,14,  16,17,20,23,25,29,32,36,  40,45,51,57,64,72,81,91};/* * Chroma QP = qpChroma[Luma QP] */const int8 qpChroma[52] = {    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,   12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,   28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,   37,38,38,38,39,39,39,39}; const int8 blkRasterOrder[16] = {  0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15,};const costMeasure_s initCostMeasure = {MAX_COST, MAX_COST, 0, 0, MAX_COST, MAX_COST, MAX_COST};/* * * staClear: * * Parameters: *      stat                  Statistics object * * Function: *      Zero out statistics * * Returns: *      - */void staClear(statSlice_s *stat){  memset(stat, 0, sizeof(statSlice_s));}void staNonSliceClear(statNonSliceNal_s *pstat){  memset(pstat, 0, sizeof(statNonSliceNal_s));}/* * * staAccumulate: * * Parameters: *      stat1                 Statistics destination object *      stat2                 Statistics object * * Function: *      Add statistics from stat2 to stat1 * * Returns: *      - */void staAccumulate(statSlice_s *stat1, statSlice_s *stat2){  int i;  stat1->nFrames += stat2->nFrames;  /*   * Accumulate bits   */  stat1->bitsNAL          += stat2->bitsNAL;  stat1->bitsHdr          += stat2->bitsHdr;  stat1->bitsSkipLen      += stat2->bitsSkipLen;  stat1->bitsMBtype       += stat2->bitsMBtype;  stat1->bitsPred         += stat2->bitsPred;  stat1->bitsVec          += stat2->bitsVec;  stat1->bitsCBP          += stat2->bitsCBP;  stat1->bitsCoefLumaDC   += stat2->bitsCoefLumaDC;  stat1->bitsCoefLuma     += stat2->bitsCoefLuma;  stat1->bitsCoefChromaDC += stat2->bitsCoefChromaDC;  stat1->bitsCoefChroma   += stat2->bitsCoefChroma;  stat1->bitsArithmeticStream += stat2->bitsArithmeticStream;  /*   * Accumulate modes   */  stat1->intraModeCtr1 += stat2->intraModeCtr1;  for (i = 0; i < MAX_MODES; i++)    stat1->intraModeCtr2[i] += stat2->intraModeCtr2[i];  for (i = 0; i < MAX_MODES; i++)    stat1->interModeCtr[i] += stat2->interModeCtr[i];  /*   * Accumulate psnr   */  stat1->psnrY += stat2->psnrY;  stat1->psnrU += stat2->psnrU;  stat1->psnrV += stat2->psnrV;}/* * * staGetTotalBits: * * Parameters: *      stat                  Statistics object * * Function: *      Get total number of bits in given statistics * * Returns: *      Number of bits * */int staGetTotalBits(statSlice_s *stat){  return (    stat->bitsNAL +    stat->bitsHdr +    stat->bitsSkipLen +    stat->bitsMBtype +    stat->bitsPred +    stat->bitsVec +    stat->bitsCBP +    stat->bitsCoefLumaDC +    stat->bitsCoefLuma +    stat->bitsCoefChromaDC +    stat->bitsCoefChroma +    stat->bitsArithmeticStream  );}/* * * staGetTotalChromaBits: * * Parameters: *      stat                  Statistics object * * Function: *      Get total number of chroma coef bits in given statistics * * Returns: *      Number of bits * */int staGetTotalChromaBits(statSlice_s *stat){  return (    stat->bitsCoefChromaDC +    stat->bitsCoefChroma  );}/* * * CalculateSsd: * * Parameters: *      orig                  Original pixels *      origBufWidth          Width of the original buffer *      reco                  Reconstructed pixels *      recoBufWidth          Width of the reconstructed pixel buffer *      width                 Number of pixels to compare, horizontally *      height                Number of pixels to compare, vertically * * Function: *      Calculate the sum of squared differences between the original pixels  *      and the reconstructed pixels. *       * Returns: *      Sum of squared difference. */int CalculateSsd(u_int8 *orig,                  int    origBufWidth,                  u_int8 *reco,                  int    recoBufWidth,                 int    width,                  int    height){  int i, j, ssd;  ssd = 0;  for (i = 0; i < height; i ++)  {    for (j = 0; j < width; j ++)    {      int diff;      diff = (int) orig[j] - (int) reco[j];      ssd += diff * diff;    }    orig += origBufWidth;    reco += recoBufWidth;  }  return ssd;}/* * * CalculateEdgeSsd: * * Parameters: *      orig                  Original pixels *      origBufWidth          Width of the original buffer *      reco                  Reconstructed pixels *      recoBufWidth          Width of the reconstructed pixel buffer *      width                 Number of pixels to compare, horizontally *      height                Number of pixels to compare, vertically * * Function: *      Calculate the sum of squared differences between the original pixels  *      and the reconstructed pixels at the right and bottom boundaries. *      The bottom-right corner will be included twice. *       * Returns: *      Sum of squared difference. */int CalculateEdgeSsd(u_int8 *orig,                      int    origBufWidth,                      u_int8 *reco,                      int    recoBufWidth,                     int    width,                      int    height,                     int    rightMb,                     int    bottomMb){  int i, diff, ssd;  ssd = 0;  if (! rightMb)  {    for (i = 0; i < height; i ++)    {      diff = (int) orig[i * origBufWidth + width - 1] - (int) reco[i * recoBufWidth + width - 1];      ssd += diff * diff;    }  }  if (! bottomMb)  {    orig += (height - 1) * origBufWidth;    reco += (height - 1) * recoBufWidth;    for (i = 0; i < width; i ++)    {      diff = (int) orig[i] - (int) reco[i];      ssd += diff * diff;    }  }  return ssd;}/* * * CalculateSAD: * * Parameters: *      orig                  Original pixels *      origBufWidth          Width of the original buffer *      reco                  Reconstructed pixels *      recoBufWidth          Width of the reconstructed pixel buffer *      width                 Number of pixels to compare, horizontally *      height                Number of pixels to compare, vertically * * Function: *      Calculate the sum of absolute differences between the original pixels  *      and the reconstructed pixels. *       * Returns: *      Sum of squared difference. */int CalculateSad(u_int8 *orig,                  int    origBufWidth,                  u_int8 *reco,                  int    recoBufWidth,                 int    width,                  int    height){  int i, j, sad;  sad = 0;  for (i = 0; i < height; i ++)  {    for (j = 0; j < width; j ++)    {      int diff;      diff = (int) orig[j] - (int) reco[j];    if(diff<0)      sad=sad-diff;    else      sad+=diff;          }    orig += origBufWidth;    reco += recoBufWidth;  }  return sad;}

⌨️ 快捷键说明

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