Utils.cpp
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:6k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /* $Id: Utils.cpp,v 1.2 2001/04/19 18:32:10 wmay Exp $ */
  2. /****************************************************************************/
  3. /*   MPEG4 Visual Texture Coding (VTC) Mode Software                        */
  4. /*                                                                          */
  5. /*   This software was jointly developed by the following participants:     */
  6. /*                                                                          */
  7. /*   Single-quant,  multi-quant and flow control                            */
  8. /*   are provided by  Sarnoff Corporation                                   */
  9. /*     Iraj Sodagar   (iraj@sarnoff.com)                                    */
  10. /*     Hung-Ju Lee    (hjlee@sarnoff.com)                                   */
  11. /*     Paul Hatrack   (hatrack@sarnoff.com)                                 */
  12. /*     Shipeng Li     (shipeng@sarnoff.com)                                 */
  13. /*     Bing-Bing Chai (bchai@sarnoff.com)                                   */
  14. /*     B.S. Srinivas  (bsrinivas@sarnoff.com)                               */
  15. /*                                                                          */
  16. /*   Bi-level is provided by Texas Instruments                              */
  17. /*     Jie Liang      (liang@ti.com)                                        */
  18. /*                                                                          */
  19. /*   Shape Coding is provided by  OKI Electric Industry Co., Ltd.           */
  20. /*     Zhixiong Wu    (sgo@hlabs.oki.co.jp)                                 */
  21. /*     Yoshihiro Ueda (yueda@hlabs.oki.co.jp)                               */
  22. /*     Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp)                        */
  23. /*                                                                          */
  24. /*   OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream         */
  25. /*   exchange and bug fixing.                                               */
  26. /*                                                                          */
  27. /*                                                                          */
  28. /* In the course of development of the MPEG-4 standard, this software       */
  29. /* module is an implementation of a part of one or more MPEG-4 tools as     */
  30. /* specified by the MPEG-4 standard.                                        */
  31. /*                                                                          */
  32. /* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use     */
  33. /* of the MPEG-4 standard free license to use this  software module or      */
  34. /* modifications thereof for hardware or software products claiming         */
  35. /* conformance to the MPEG-4 standard.                                      */
  36. /*                                                                          */
  37. /* Those intending to use this software module in hardware or software      */
  38. /* products are advised that use may infringe existing  patents. The        */
  39. /* original developers of this software module and their companies, the     */
  40. /* subsequent editors and their companies, and ISO/IEC have no liability    */
  41. /* and ISO/IEC have no liability for use of this software module or         */
  42. /* modification thereof in an implementation.                               */
  43. /*                                                                          */
  44. /* Permission is granted to MPEG members to use, copy, modify,              */
  45. /* and distribute the software modules ( or portions thereof )              */
  46. /* for standardization activity within ISO/IEC JTC1/SC29/WG11.              */
  47. /*                                                                          */
  48. /* Copyright 1995, 1996, 1997, 1998 ISO/IEC                                 */
  49. /****************************************************************************/
  50. /************************************************************/
  51. /*     Sarnoff Very Low Bit Rate Still Image Coder          */
  52. /*     Copyright 1995, 1996, 1997, 1998 Sarnoff Corporation */
  53. /************************************************************/
  54. #include <stdio.h>
  55. #include "dataStruct.hpp"
  56. #include "globals.hpp"
  57. #include "Utils.hpp"
  58. Void CVTCCommon::setSpatialLevelAndDimensions(Int spLayer, Int c)
  59. {
  60.   mzte_codec.m_iCurSpatialLev=spLayer;
  61.   mzte_codec.m_SPlayer[c].height
  62.     =mzte_codec.m_spaLayerHeight[spLayer][c];
  63.   mzte_codec.m_SPlayer[c].width
  64.     =mzte_codec.m_spaLayerWidth[spLayer][c];
  65. }
  66. Void CVTCCommon::updateResidMaxAndAssignSkips(Int c)
  67. {
  68.   Int rLev;
  69.   Int i;
  70.   Int x, y, spX, spY, spHeight, spWidth;
  71.   // hjlee 0901
  72.   WVTDECOMP_RES_NUMBITPLANES(c)=0;
  73.   for (i = 0; i <= mzte_codec.m_iCurSpatialLev; ++i)
  74.   {
  75.     prevQList2[c][i] = prevQList[c][i];
  76.     if (prevQList[c][i] == 0)
  77.       prevQList[c][i] = USER_Q(c);
  78.     rLev=quantRefLev(USER_Q(c), prevQList[c]+i, scaleLev[c][i]++)-1;
  79.     {
  80.       /* extern Int ceilLog2(Int x); */ /* defined in encQM.c */
  81.       Int v;
  82.       v = ceilLog2(rLev+1);
  83.       if (v > WVTDECOMP_RES_NUMBITPLANES(c))
  84. WVTDECOMP_RES_NUMBITPLANES(c) = v;
  85.     }
  86.     /*--- Set skip mode all coefficients in spatial level ---*/
  87.     if (i < mzte_codec.m_iCurSpatialLev)
  88.     {
  89.       /* Get spatial level dimensions of i^{th} spatial layer */
  90.   // hjlee 0901
  91.       spHeight = mzte_codec.m_spaLayerHeight[i][c];
  92.       spWidth  = mzte_codec.m_spaLayerWidth[i][c];
  93.       if (i==0)
  94.       {
  95.         spY = mzte_codec.m_iDCHeight;
  96.         spX = mzte_codec.m_iDCWidth;
  97.       }
  98.       else
  99.       {
  100. spY = mzte_codec.m_spaLayerHeight[i-1][c];
  101. spX = mzte_codec.m_spaLayerWidth[i-1][c];
  102.       }
  103.       /* HL */
  104.       for (y = 0; y < spY; ++y)
  105. for (x = spX; x < spWidth; ++x)
  106. {
  107.   if (rLev > 0)
  108. COEFF_SKIP(x,y,c) = 0;
  109.   else if (COEFF_SKIP(x,y,c)==0)     
  110. COEFF_SKIP(x,y,c)=1;
  111. }
  112.       
  113.       /* LH */
  114.       for (y = spY; y < spHeight; ++y)
  115. for (x = 0; x < spX; ++x)
  116. {
  117.   if (rLev > 0)
  118. COEFF_SKIP(x,y,c) = 0;
  119.   else if (COEFF_SKIP(x,y,c)==0)     
  120. COEFF_SKIP(x,y,c)=1;
  121. }
  122.       
  123.       /* HH */
  124.       for (y = spY; y < spHeight; ++y)
  125. for (x = spX; x < spWidth; ++x)
  126. {
  127.   if (rLev > 0)
  128. COEFF_SKIP(x,y,c) = 0;
  129.   else if (COEFF_SKIP(x,y,c)==0)     
  130. COEFF_SKIP(x,y,c)=1;
  131. }
  132.   }
  133. }
  134. // hjlee 0901 
  135. Int CVTCCommon::xy2wvtDecompLev(Int x, Int y)
  136. {
  137.   register Int i;
  138.   for (i=0; i<mzte_codec.m_iWvtDecmpLev; ++i)
  139.     if (x < (mzte_codec.m_iDCWidth<<i) && y < (mzte_codec.m_iDCHeight<<i))
  140.       break;
  141.   return i-1;
  142. }