Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 1196)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 1313)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
- *
-* Copyright (c) 2010-2015, ITU/ISO/IEC
+ * granted under this license.
+ *
+ * Copyright (c) 2010-2015, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -31,158 +31,85 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 /** \file     TComRom.h
     \brief    global variables & functions (header)
 */
-
 #ifndef __TCOMROM__
 #define __TCOMROM__
-
 #include "CommonDef.h"
-#include "TypeDef.h"
-
 #include<stdio.h>
 #include<iostream>
-
-#if H_3D_DIM
+#if NH_3D_DMM
 #include "TComWedgelet.h"
 #endif
-
 //! \ingroup TLibCommon
 //! \{
-
-// ====================================================================================================================
-// Macros
-// ====================================================================================================================
-
-#define     MAX_CU_DEPTH            6                           // log2(LCUSize)
-#define     MAX_CU_SIZE             (1<<(MAX_CU_DEPTH))         // maximum allowable size of CU
-#define     MIN_PU_SIZE             4
-#define     MAX_NUM_SPU_W           (MAX_CU_SIZE/MIN_PU_SIZE)   // maximum number of SPU in horizontal line
-
 // ====================================================================================================================
 // Initialize / destroy functions
 // ====================================================================================================================
-
 Void         initROM();
 Void         destroyROM();
-Void         initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight);
 // ====================================================================================================================
 // Data structure related table & variable
 // ====================================================================================================================
-
 // flexible conversion from relative to absolute index
-extern       UInt   g_auiZscanToRaster[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-extern       UInt   g_auiRasterToZscan[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-
+extern       UInt   g_auiZscanToRaster[ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ];
+extern       UInt   g_auiRasterToZscan[ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ];
+extern       UInt*  g_scanOrder[SCAN_NUMBER_OF_GROUP_TYPES][SCAN_NUMBER_OF_TYPES][ MAX_CU_DEPTH ][ MAX_CU_DEPTH ];
 Void         initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx );
 Void         initRasterToZscan ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth         );
-
 // conversion of partition index to picture pel position
-extern       UInt   g_auiRasterToPelX[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-extern       UInt   g_auiRasterToPelY[ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-
+extern       UInt   g_auiRasterToPelX[ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ];
+extern       UInt   g_auiRasterToPelY[ MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH ];
 Void         initRasterToPelXY ( UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth );
-
-// global variable (LCU width/height, max. CU depth)
-extern       UInt g_uiMaxCUWidth;
-extern       UInt g_uiMaxCUHeight;
-extern       UInt g_uiMaxCUDepth;
-extern       UInt g_uiAddCUDepth;
-
-#define MAX_TS_WIDTH  4
-#define MAX_TS_HEIGHT 4
-
-extern       UInt g_auiPUOffset[8];
-
-#define QUANT_IQUANT_SHIFT    20 // Q(QP%6) * IQ(QP%6) = 2^20
-#define QUANT_SHIFT           14 // Q(4) = 2^14
-#define SCALE_BITS            15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ
-#define MAX_TR_DYNAMIC_RANGE  15 // Maximum transform dynamic range (excluding sign bit)
-
-#define SHIFT_INV_1ST          7 // Shift after first inverse transform stage
-#define SHIFT_INV_2ND         12 // Shift after second inverse transform stage
-
-extern Int g_quantScales[6];             // Q(QP%6)  
-extern Int g_invQuantScales[6];          // IQ(QP%6)
-extern const Short g_aiT4[4][4];
-extern const Short g_aiT8[8][8];
-extern const Short g_aiT16[16][16];
-extern const Short g_aiT32[32][32];
-
+extern const UInt g_auiPUOffset[NUMBER_OF_PART_SIZES];
+extern const Int g_quantScales[SCALING_LIST_REM_NUM];             // Q(QP%6)
+extern const Int g_invQuantScales[SCALING_LIST_REM_NUM];          // IQ(QP%6)
+#if RExt__HIGH_PRECISION_FORWARD_TRANSFORM
+static const Int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS] = { 14, 6 };
+#else
+static const Int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS] = {  6, 6 };
+#endif
+extern const TMatrixCoeff g_aiT4 [TRANSFORM_NUMBER_OF_DIRECTIONS][4][4];
+extern const TMatrixCoeff g_aiT8 [TRANSFORM_NUMBER_OF_DIRECTIONS][8][8];
+extern const TMatrixCoeff g_aiT16[TRANSFORM_NUMBER_OF_DIRECTIONS][16][16];
+extern const TMatrixCoeff g_aiT32[TRANSFORM_NUMBER_OF_DIRECTIONS][32][32];
 // ====================================================================================================================
 // Luma QP to Chroma QP mapping
 // ====================================================================================================================
-
-extern const UChar  g_aucChromaScale      [58];
-
+static const Int chromaQPMappingTableSize = 58;
+extern const UChar  g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize];
 // ====================================================================================================================
 // Scanning order & context mapping table
 // ====================================================================================================================
-
-extern       UInt*  g_auiSigLastScan[ 3 ][ MAX_CU_DEPTH ];  // raster index from scanning index (diag, hor, ver)
-
-extern const UInt   g_uiGroupIdx[ 32 ];
-extern const UInt   g_uiMinInGroup[ 10 ];
-
-extern const UInt   g_sigLastScan8x8[ 3 ][ 4 ];           //!< coefficient group scan order for 8x8 TUs
-extern       UInt   g_sigLastScanCG32x32[ 64 ];
-
-// ====================================================================================================================
-// ADI table
-// ====================================================================================================================
-
-extern const UChar  g_aucIntraModeNumFast[ MAX_CU_DEPTH ];
-
-// ====================================================================================================================
-// Bit-depth
-// ====================================================================================================================
-
-extern        Int g_bitDepthY;
-extern        Int g_bitDepthC;
-extern       UInt g_uiPCMBitDepthLuma;
-extern       UInt g_uiPCMBitDepthChroma;
-
-// ====================================================================================================================
-// Texture type to integer mapping
-// ====================================================================================================================
-
-extern const UChar g_aucConvertTxtTypeToIdx[4];
-
-#if H_3D_DIM
+extern const UInt   ctxIndMap4x4[4*4];
+extern const UInt   g_uiGroupIdx[ MAX_TU_SIZE ];
+extern const UInt   g_uiMinInGroup[ LAST_SIGNIFICANT_GROUPS ];
+// ====================================================================================================================
+// Intra prediction table
+// ====================================================================================================================
+extern const UChar  g_aucIntraModeNumFast_UseMPM[MAX_CU_DEPTH];
+extern const UChar  g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH];
+extern const UChar  g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE];
 // ====================================================================================================================
 // Depth coding modes
 // ====================================================================================================================
-__inline Void mapDepthModeToIntraDir( UInt& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; }
-__inline Void mapDepthModeToIntraDir(  Int& intraMode ) { if( isDimMode( intraMode ) ) intraMode = DC_IDX; }
-
-#if H_3D_DIM_SDC || H_3D_DIM_DLT
-__inline UInt numBitsForValue( UInt value ) { UInt bits = 0; while (value != 0) { value >>= 1; bits++; } return bits; };
-#endif
-
-#if H_3D_DIM_DMM
+#if NH_3D_DMM
 extern const WedgeResolution                                 g_dmmWedgeResolution [6];
 extern const UChar                                           g_dmm1TabIdxBits     [6];
-extern const UChar                                           g_dmm3IntraTabIdxBits[6];
-
 extern Bool                                                  g_wedgePattern[32*32];
-
 extern       std::vector< std::vector<TComWedgelet> >        g_dmmWedgeLists;
-extern       std::vector< std::vector<TComWedgeRef> >        g_dmmWedgeRefLists;
 extern       std::vector< std::vector<TComWedgeNode> >       g_dmmWedgeNodeLists;
-
 Void initWedgeLists( Bool initNodeList = false );
 Void createWedgeList( UInt uiWidth, UInt uiHeight, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList, WedgeResolution eWedgeRes );
 Void addWedgeletToList( TComWedgelet cWedgelet, std::vector<TComWedgelet> &racWedgeList, std::vector<TComWedgeRef> &racWedgeRefList );
-#endif
-#endif
-
-// ==========================================
+WedgeList*     getWedgeListScaled    ( UInt blkSize );
+WedgeNodeList* getWedgeNodeListScaled( UInt blkSize );
+__inline Void mapDmmToIntraDir( UInt& intraMode ) { if( isDmmMode( intraMode ) ) intraMode = DC_IDX; }
+__inline Void mapDmmToIntraDir(  Int& intraMode ) { if( isDmmMode( intraMode ) ) intraMode = DC_IDX; }
+#endif
+// ====================================================================================================================
 // Mode-Dependent DST Matrices
-extern const Short g_as_DST_MAT_4 [4][4];
-extern const UChar g_aucDCTDSTMode_Vert[NUM_INTRA_MODE];
-extern const UChar g_aucDCTDSTMode_Hor[NUM_INTRA_MODE];
-// ==========================================
-
+// ====================================================================================================================
+extern const TMatrixCoeff g_as_DST_MAT_4 [TRANSFORM_NUMBER_OF_DIRECTIONS][4][4];
 #if H_MV_HLS_PTL_LIMITS
 class TComGeneralTierAndLevelLimits
@@ -203,5 +130,4 @@
     m_maxTileCols               ( maxTileCols                   );
   {};
-
   Int getMaxLumaPs                 ( ) { return m_maxLumaPs                 ; };
   Int getMaxCPBMainTier            ( ) { return m_maxCPBMainTier            ; };
@@ -210,5 +136,4 @@
   Int getMaxTileRows               ( ) { return m_maxTileRows               ; };
   Int getMaxTileCols               ( ) { return m_maxTileCols               ; };
-
 private:
   const Int m_maxLumaPs;
@@ -219,18 +144,16 @@
   const Int m_maxTileCols; 
 };
-
 extern std::map< Level::Name, TComGeneralTierAndLevelLimits > g_generalTierAndLevelLimits;   
-
 #endif
 // ====================================================================================================================
 // Misc.
 // ====================================================================================================================
-
 extern       Char   g_aucConvertToBit  [ MAX_CU_SIZE+1 ];   // from width to log2(width)-2
-
+#if NH_MV
+// Change later
 #ifndef ENC_DEC_TRACE
-#define ENC_DEC_TRACE   0  
-#endif
-
+#define ENC_DEC_TRACE 0
+#endif
+#endif
 #if ENC_DEC_TRACE
 extern FILE*  g_hTrace;
@@ -240,8 +163,6 @@
 extern Bool   g_HLSTraceEnable;
 extern UInt64 g_nSymbolCounter;
-
 #define COUNTER_START    1
 #define COUNTER_END      0 //( UInt64(1) << 63 )
-
 #define DTRACE_CABAC_F(x)     if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%f", x );
 #define DTRACE_CABAC_V(x)     if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "%d", x );
@@ -251,8 +172,7 @@
 #define DTRACE_CABAC_R( x,y ) if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, x,    y );
 #define DTRACE_CABAC_N        if ( ( g_nSymbolCounter >= COUNTER_START && g_nSymbolCounter <= COUNTER_END )|| g_bJustDoIt ) fprintf( g_hTrace, "\n"    );
-
 #if H_MV_ENC_DEC_TRAC
  extern Bool   g_traceCU; 
- extern Bool   g_tracePU; 
+ extern Bool   g_tracePU ; 
  extern Bool   g_traceTU; 
  extern Bool   g_disableHLSTrace;       // USE g_HLSTraceEnable to toggle HLS trace. Not this one!
@@ -263,9 +183,14 @@
  extern Bool   g_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only) 
  extern Bool   g_decTracePicOutput;     // Trace output of pictures
- extern Bool   g_stopAtPos;             // Stop at position
+ extern Bool   g_startStopTrace;             // Stop at position
  extern Bool   g_outputPos;             // Output position
  extern Bool   g_traceCameraParameters; // Trace camera parameters
  extern Bool   g_encNumberOfWrittenBits;// Trace number of written bits
-
+ extern Bool   g_traceEncFracBits;      // Trace fractional bits
+ extern Bool   g_traceIntraSearchCost;  // Trace intra mode cost
+ extern Bool   g_traceRDCost;          
+ extern Bool   g_traceModeCheck; 
+ extern Bool   g_traceSAOCost; 
+ extern UInt   g_indent; 
 #define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
 #define DTRACE_PU(x,y)             writeToTraceFile( x,y, g_tracePU );
@@ -275,10 +200,29 @@
 #define DTRACE_TU_S(x)             writeToTraceFile( x,   g_traceTU );
 
+#define D_DEC_INDENT( b )            decIndent        ( b );
+#define D_PRINT_INC_INDENT( b, str ) prinStrIncIndent( b, str );
+#define D_PRINT_INDENT( b, str )     printStrIndent   ( b, str);
+
+ Void           tracePSHeader   ( const Char* psName, Int layerId ); 
  Void           writeToTraceFile( const Char* symbolName, Int val, Bool doIt );
  Void           writeToTraceFile( const Char* symbolName, Bool doIt );
- Void           stopAtPos       ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight );
+ UInt64         incSymbolCounter();          
+ Void           stopAtPos       ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight );           
+
+ Void           printStr         ( std::string str );
+ Void           printStrIndent   ( Bool b, std::string str );
+ Void           prinStrIncIndent ( Bool b, std::string str );
+ Void           decIndent        ( Bool b );
+
+ template <typename T>
+ std::string n2s ( T Number )
+ {
+   std::ostringstream ss;
+   ss << Number;
+   return ss.str();
+ };
+
 #endif
 #else
-
 #define DTRACE_CABAC_F(x)
 #define DTRACE_CABAC_V(x)
@@ -288,96 +232,24 @@
 #define DTRACE_CABAC_R( x,y )
 #define DTRACE_CABAC_N
-
-#if H_MV_ENC_DEC_TRAC
 #define DTRACE_CU(x,y) ;             
 #define DTRACE_PU(x,y) ;            
 #define DTRACE_TU(x,y) ;            
-
 #define DTRACE_CU_S(x) ;            
 #define DTRACE_PU_S(x) ;            
 #define DTRACE_TU_S(x) ;            
 
-#endif
-#endif
-
-
-#define SCALING_LIST_NUM 6         ///< list number for quantization matrix
-#define SCALING_LIST_NUM_32x32 2   ///< list number for quantization matrix 32x32
-#define SCALING_LIST_REM_NUM 6     ///< remainder of QP/6
-#define SCALING_LIST_START_VALUE 8 ///< start value for dpcm mode
-#define MAX_MATRIX_COEF_NUM 64     ///< max coefficient number for quantization matrix
-#define MAX_MATRIX_SIZE_NUM 8      ///< max size number for quantization matrix
-#define SCALING_LIST_DC 16         ///< default DC value
-enum ScalingListSize
-{
-  SCALING_LIST_4x4 = 0,
-  SCALING_LIST_8x8,
-  SCALING_LIST_16x16,
-  SCALING_LIST_32x32,
-  SCALING_LIST_SIZE_NUM
-};
-static const Char MatrixType[4][6][20] =
-{
-  {
-  "INTRA4X4_LUMA",
-  "INTRA4X4_CHROMAU",
-  "INTRA4X4_CHROMAV",
-  "INTER4X4_LUMA",
-  "INTER4X4_CHROMAU",
-  "INTER4X4_CHROMAV"
-  },
-  {
-  "INTRA8X8_LUMA",
-  "INTRA8X8_CHROMAU", 
-  "INTRA8X8_CHROMAV", 
-  "INTER8X8_LUMA",
-  "INTER8X8_CHROMAU", 
-  "INTER8X8_CHROMAV"  
-  },
-  {
-  "INTRA16X16_LUMA",
-  "INTRA16X16_CHROMAU", 
-  "INTRA16X16_CHROMAV", 
-  "INTER16X16_LUMA",
-  "INTER16X16_CHROMAU", 
-  "INTER16X16_CHROMAV"  
-  },
-  {
-  "INTRA32X32_LUMA",
-  "INTER32X32_LUMA",
-  },
-};
-static const Char MatrixType_DC[4][12][22] =
-{
-  {
-  },
-  {
-  },
-  {
-  "INTRA16X16_LUMA_DC",
-  "INTRA16X16_CHROMAU_DC", 
-  "INTRA16X16_CHROMAV_DC", 
-  "INTER16X16_LUMA_DC",
-  "INTER16X16_CHROMAU_DC", 
-  "INTER16X16_CHROMAV_DC"  
-  },
-  {
-  "INTRA32X32_LUMA_DC",
-  "INTER32X32_LUMA_DC",
-  },
-};
-extern Int g_quantIntraDefault8x8[64];
-extern Int g_quantIntraDefault16x16[256];
-extern Int g_quantIntraDefault32x32[1024];
-extern Int g_quantInterDefault8x8[64];
-extern Int g_quantInterDefault16x16[256];
-extern Int g_quantInterDefault32x32[1024];
-extern Int g_quantTSDefault4x4[16];
-extern UInt g_scalingListSize [SCALING_LIST_SIZE_NUM];
-extern UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM];
-extern UInt g_scalingListNum  [SCALING_LIST_SIZE_NUM];
-extern Int  g_eTTable[4];
+#define D_DEC_INDENT( b ) ;
+#define D_PRINT_INC_INDENT( b, str );
+#define D_PRINT_INDENT( b, str );
+
+#endif
+const Char* nalUnitTypeToString(NalUnitType type);
+extern const Char *MatrixType[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
+extern const Char *MatrixType_DC[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM];
+extern const Int g_quantTSDefault4x4[4*4];
+extern const Int g_quantIntraDefault8x8[8*8];
+extern const Int g_quantInterDefault8x8[8*8];
+extern const UInt g_scalingListSize [SCALING_LIST_SIZE_NUM];
+extern const UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM];
 //! \}
-
 #endif  //__TCOMROM__
-
