Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1284)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1285)
@@ -4280,5 +4280,8 @@
   // compute actual CU depth with respect to config depth and max transform size
   g_uiAddCUDepth  = 0;
-  while( (m_acLayerCfg[layerId].m_uiMaxCUWidth>>m_acLayerCfg[layerId].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
+  while( (m_acLayerCfg[layerId].m_uiMaxCUWidth>>m_acLayerCfg[layerId].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) )
+  {
+    g_uiAddCUDepth++;
+  }
 
   g_uiAddCUDepth+=getMaxCUDepthOffset(m_chromaFormatIDC, m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize); // if minimum TU larger than 4x4, allow for additional part indices for 4:2:2 SubTUs.
@@ -4313,7 +4316,5 @@
     g_bitDepth   [channelType] = m_internalBitDepth[channelType];
 #endif
-    g_maxTrDynamicRange[channelType] = m_useExtendedPrecision? std::max<Int>(15, (g_bitDepth[channelType] + 6)) : 15;
-  }
-
+  }
 }
 #endif
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1284)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1285)
@@ -910,5 +910,4 @@
 //#endif
     m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]);
-    //g_maxTrDynamicRange[channelType] = m_useExtendedPrecision? std::max<Int>(15, (g_bitDepth[channelType] + 6)) : 15;
   }
 
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComChromaFormat.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComChromaFormat.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComChromaFormat.h	(revision 1285)
@@ -163,10 +163,10 @@
 //------------------------------------------------
 
-static inline Int getTransformShift(const ChannelType type, const UInt uiLog2TrSize)
+static inline Int getTransformShift(const ChannelType type, const UInt uiLog2TrSize, const Int maxLog2TrDynamicRange)
 {
 #if O0043_BEST_EFFORT_DECODING
-  return g_maxTrDynamicRange[type] - g_bitDepthInStream[type] - uiLog2TrSize;
+  return maxLog2TrDynamicRange - g_bitDepthInStream[type] - uiLog2TrSize;
 #else
-  return g_maxTrDynamicRange[type] - g_bitDepth[type] - uiLog2TrSize;
+  return maxLog2TrDynamicRange - g_bitDepth[type] - uiLog2TrSize;
 #endif
 }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 1285)
@@ -322,6 +322,4 @@
   }
 }
-
-Int g_maxTrDynamicRange[MAX_NUM_CHANNEL_TYPE];
 
 Int g_quantScales[SCALING_LIST_REM_NUM] =
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComRom.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComRom.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComRom.h	(revision 1285)
@@ -97,6 +97,4 @@
 #define SCALE_BITS                 15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ
 
-extern Int g_maxTrDynamicRange[MAX_NUM_CHANNEL_TYPE];
-
 #define SQRT2                      11585
 #define SQRT2_SHIFT                13
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1285)
@@ -1480,4 +1480,6 @@
   Int                    getBitDepth(ChannelType type) const                                             { return m_uiBitDepth[type];                                           }
   Void                   setBitDepth(ChannelType type, Int u )                                           { m_uiBitDepth[type] = u;                                              }
+  Int                    getMaxLog2TrDynamicRange(ChannelType channelType) const                         { return getUseExtendedPrecision() ? std::max<Int>(15, Int(m_uiBitDepth[channelType] + 6)) : 15; }
+
   Int                    getDifferentialLumaChromaBitDepth() const                                       { return Int(m_uiBitDepth[CHANNEL_TYPE_LUMA]) - Int(m_uiBitDepth[CHANNEL_TYPE_CHROMA]); }
   Int                    getQpBDOffset(ChannelType type) const                                           { return m_qpBDOffset[type];                                           }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 1285)
@@ -242,5 +242,5 @@
  *  \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only
  */
-Void xTr(Int bitDepth, Pel *block, TCoeff *coeff, UInt uiStride, UInt uiTrSize, Bool useDST, const Int maxTrDynamicRange)
+Void xTr(Int bitDepth, Pel *block, TCoeff *coeff, UInt uiStride, UInt uiTrSize, Bool useDST, const Int maxLog2TrDynamicRange)
 {
   UInt i,j,k;
@@ -273,5 +273,5 @@
   static const Int TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_FORWARD];
 
-  const Int shift_1st = (uiLog2TrSize +  bitDepth + TRANSFORM_MATRIX_SHIFT) - maxTrDynamicRange;
+  const Int shift_1st = (uiLog2TrSize +  bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange;
   const Int shift_2nd = uiLog2TrSize + TRANSFORM_MATRIX_SHIFT;
   const Int add_1st = (shift_1st>0) ? (1<<(shift_1st-1)) : 0;
@@ -315,5 +315,5 @@
  *  \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only
  */
-Void xITr(Int bitDepth, TCoeff *coeff, Pel *block, UInt uiStride, UInt uiTrSize, Bool useDST, const Int maxTrDynamicRange)
+Void xITr(Int bitDepth, TCoeff *coeff, Pel *block, UInt uiStride, UInt uiTrSize, Bool useDST, const Int maxLog2TrDynamicRange)
 {
   UInt i,j,k;
@@ -346,7 +346,7 @@
 
   const Int shift_1st = TRANSFORM_MATRIX_SHIFT + 1; //1 has been added to shift_1st at the expense of shift_2nd
-  const Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxTrDynamicRange - 1) - bitDepth;
-  const TCoeff clipMinimum = -(1 << maxTrDynamicRange);
-  const TCoeff clipMaximum =  (1 << maxTrDynamicRange) - 1;
+  const Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1) - bitDepth;
+  const TCoeff clipMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff clipMaximum =  (1 << maxLog2TrDynamicRange) - 1;
   assert(shift_2nd>=0);
   const Int add_1st = 1<<(shift_1st-1);
@@ -857,18 +857,18 @@
 
 /** MxN forward transform (2D)
-*  \param bitDepth          [in]  bit depth
-*  \param block             [in]  residual block
-*  \param coeff             [out] transform coefficients
-*  \param iWidth            [in]  width of transform
-*  \param iHeight           [in]  height of transform
-*  \param useDST            [in]
-*  \param maxTrDynamicRange [in]
+*  \param bitDepth              [in]  bit depth
+*  \param block                 [in]  residual block
+*  \param coeff                 [out] transform coefficients
+*  \param iWidth                [in]  width of transform
+*  \param iHeight               [in]  height of transform
+*  \param useDST                [in]
+*  \param maxLog2TrDynamicRange [in]
 
 */
-Void xTrMxN(Int bitDepth, TCoeff *block, TCoeff *coeff, Int iWidth, Int iHeight, Bool useDST, const Int maxTrDynamicRange)
+Void xTrMxN(Int bitDepth, TCoeff *block, TCoeff *coeff, Int iWidth, Int iHeight, Bool useDST, const Int maxLog2TrDynamicRange)
 {
   static const Int TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_FORWARD];
 
-  const Int shift_1st = ((g_aucConvertToBit[iWidth] + 2) +  bitDepth + TRANSFORM_MATRIX_SHIFT) - maxTrDynamicRange;
+  const Int shift_1st = ((g_aucConvertToBit[iWidth] + 2) +  bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange;
   const Int shift_2nd = (g_aucConvertToBit[iHeight] + 2) + TRANSFORM_MATRIX_SHIFT;
 
@@ -925,20 +925,20 @@
 
 /** MxN inverse transform (2D)
-*  \param bitDepth          [in]  bit depth
-*  \param coeff             [in]  transform coefficients
-*  \param block             [out] residual block
-*  \param iWidth            [in]  width of transform
-*  \param iHeight           [in]  height of transform
-*  \param useDST            [in]
-*  \param maxTrDynamicRange [in]
+*  \param bitDepth              [in]  bit depth
+*  \param coeff                 [in]  transform coefficients
+*  \param block                 [out] residual block
+*  \param iWidth                [in]  width of transform
+*  \param iHeight               [in]  height of transform
+*  \param useDST                [in]
+*  \param maxLog2TrDynamicRange [in]
 */
-Void xITrMxN(Int bitDepth, TCoeff *coeff, TCoeff *block, Int iWidth, Int iHeight, Bool useDST, const Int maxTrDynamicRange)
+Void xITrMxN(Int bitDepth, TCoeff *coeff, TCoeff *block, Int iWidth, Int iHeight, Bool useDST, const Int maxLog2TrDynamicRange)
 {
   static const Int TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_INVERSE];
 
   Int shift_1st = TRANSFORM_MATRIX_SHIFT + 1; //1 has been added to shift_1st at the expense of shift_2nd
-  Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxTrDynamicRange - 1) - bitDepth;
-  const TCoeff clipMinimum = -(1 << maxTrDynamicRange);
-  const TCoeff clipMaximum =  (1 << maxTrDynamicRange) - 1;
+  Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1) - bitDepth;
+  const TCoeff clipMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff clipMaximum =  (1 << maxLog2TrDynamicRange) - 1;
 
   assert(shift_1st >= 0);
@@ -997,5 +997,5 @@
 
 // To minimize the distortion only. No rate is considered.
-Void TComTrQuant::signBitHidingHDQ( const ComponentID compID, TCoeff* pQCoef, TCoeff* pCoef, TCoeff* deltaU, const TUEntropyCodingParameters &codingParameters )
+Void TComTrQuant::signBitHidingHDQ( const ComponentID compID, TCoeff* pQCoef, TCoeff* pCoef, TCoeff* deltaU, const TUEntropyCodingParameters &codingParameters, const Int maxLog2TrDynamicRange )
 {
   const UInt width     = codingParameters.widthInGroups  << MLS_CG_LOG2_WIDTH;
@@ -1003,6 +1003,6 @@
   const UInt groupSize = 1 << MLS_CG_SIZE;
 
-  const TCoeff entropyCodingMinimum = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-  const TCoeff entropyCodingMaximum =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+  const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff entropyCodingMaximum =  (1 << maxLog2TrDynamicRange) - 1;
 
   Int lastCG = -1;
@@ -1154,5 +1154,6 @@
 #endif
 
-  const Bool useTransformSkip = pcCU->getTransformSkip(uiAbsPartIdx, compID);
+  const Bool useTransformSkip      = pcCU->getTransformSkip(uiAbsPartIdx, compID);
+  const Int  maxLog2TrDynamicRange = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID));
 
   Bool useRDOQ = useTransformSkip ? m_useRDOQTS : m_useRDOQ;
@@ -1170,6 +1171,6 @@
     getTUEntropyCodingParameters(codingParameters, rTu, compID);
 
-    const TCoeff entropyCodingMinimum = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-    const TCoeff entropyCodingMaximum =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+    const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
+    const TCoeff entropyCodingMaximum =  (1 << maxLog2TrDynamicRange) - 1;
 
     TCoeff deltaU[MAX_TU_SIZE * MAX_TU_SIZE];
@@ -1191,5 +1192,5 @@
 
     // Represents scaling through forward transform
-    Int iTransformShift = getTransformShift(toChannelType(compID), uiLog2TrSize);
+    Int iTransformShift = getTransformShift(toChannelType(compID), uiLog2TrSize, maxLog2TrDynamicRange);
     if (useTransformSkip && pcCU->getSlice()->getSPS()->getUseExtendedPrecision())
     {
@@ -1241,5 +1242,5 @@
       if(uiAbsSum >= 2) //this prevents TUs with only one coefficient of value 1 from being tested
       {
-        signBitHidingHDQ( compID, piQCoef, piCoef, deltaU, codingParameters ) ;
+        signBitHidingHDQ( compID, piQCoef, piCoef, deltaU, codingParameters, maxLog2TrDynamicRange ) ;
       }
     }
@@ -1265,6 +1266,7 @@
   const UInt                 uiLog2TrSize       = rTu.GetEquivalentLog2TrSize(compID);
   const UInt                 numSamplesInBlock  = uiWidth*uiHeight;
-  const TCoeff               transformMinimum   = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-  const TCoeff               transformMaximum   =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+  const Int                  maxLog2TrDynamicRange  = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID));
+  const TCoeff               transformMinimum   = -(1 << maxLog2TrDynamicRange);
+  const TCoeff               transformMaximum   =  (1 << maxLog2TrDynamicRange) - 1;
   const Bool                 enableScalingLists = getUseScalingList(uiWidth, uiHeight, (pcCU->getTransformSkip(uiAbsPartIdx, compID) != 0));
   const Int                  scalingListType    = getScalingListType(pcCU->getPredictionMode(uiAbsPartIdx), compID);
@@ -1275,5 +1277,5 @@
   // Represents scaling through forward transform
   const Bool bClipTransformShiftTo0 = (pcCU->getTransformSkip(uiAbsPartIdx, compID) != 0) && pcCU->getSlice()->getSPS()->getUseExtendedPrecision();
-  const Int  originalTransformShift = getTransformShift(toChannelType(compID), uiLog2TrSize);
+  const Int  originalTransformShift = getTransformShift(toChannelType(compID), uiLog2TrSize, maxLog2TrDynamicRange);
   const Int  iTransformShift        = bClipTransformShiftTo0 ? std::max<Int>(0, originalTransformShift) : originalTransformShift;
 
@@ -1289,5 +1291,5 @@
     //(sizeof(Intermediate_Int) * 8)  =              inputBitDepth    +    dequantCoefBits                   - rightShift
     const UInt             dequantCoefBits     = 1 + IQUANT_SHIFT + SCALING_LIST_BITS;
-    const UInt             targetInputBitDepth = std::min<UInt>((g_maxTrDynamicRange[toChannelType(compID)] + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
+    const UInt             targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
 
     const Intermediate_Int inputMinimum        = -(1 << (targetInputBitDepth - 1));
@@ -1329,5 +1331,5 @@
     //iCoeffQ                         = Intermediate_Int((Int64(clipQCoef) * scale + iAdd) >> rightShift);
     //(sizeof(Intermediate_Int) * 8)  =                    inputBitDepth   + scaleBits      - rightShift
-    const UInt             targetInputBitDepth = std::min<UInt>((g_maxTrDynamicRange[toChannelType(compID)] + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - scaleBits));
+    const UInt             targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - scaleBits));
     const Intermediate_Int inputMinimum        = -(1 << (targetInputBitDepth - 1));
     const Intermediate_Int inputMaximum        =  (1 << (targetInputBitDepth - 1)) - 1;
@@ -1441,5 +1443,5 @@
       else
       {
-        xT( compID, rTu.useDST(compID), pcResidual, uiStride, m_plTempCoeff, uiWidth, uiHeight );
+        xT( compID, rTu.useDST(compID), pcResidual, uiStride, m_plTempCoeff, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID)) );
       }
 
@@ -1571,5 +1573,5 @@
     else
     {
-      xIT( compID, rTu.useDST(compID), m_plTempCoeff, pcResidual, uiStride, uiWidth, uiHeight );
+      xIT( compID, rTu.useDST(compID), m_plTempCoeff, pcResidual, uiStride, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID)) );
 
 #if defined DEBUG_STRING
@@ -1863,10 +1865,10 @@
  *  \param iHeight transform height
  */
-Void TComTrQuant::xT( const ComponentID compID, Bool useDST, Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, Int iWidth, Int iHeight )
+Void TComTrQuant::xT( const ComponentID compID, Bool useDST, Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange )
 {
 #if MATRIX_MULT
   if( iWidth == iHeight)
   {
-    xTr(g_bitDepth[toChannelType(compID)], piBlkResi, psCoeff, uiStride, (UInt)iWidth, useDST, g_maxTrDynamicRange[toChannelType(compID)]);
+    xTr(g_bitDepth[toChannelType(compID)], piBlkResi, psCoeff, uiStride, (UInt)iWidth, useDST, maxLog2TrDynamicRange);
     return;
   }
@@ -1884,5 +1886,5 @@
   }
 
-  xTrMxN( g_bitDepth[toChannelType(compID)], block, coeff, iWidth, iHeight, useDST, g_maxTrDynamicRange[toChannelType(compID)] );
+  xTrMxN( g_bitDepth[toChannelType(compID)], block, coeff, iWidth, iHeight, useDST, maxLog2TrDynamicRange );
 
   memcpy(psCoeff, coeff, (iWidth * iHeight * sizeof(TCoeff)));
@@ -1898,5 +1900,5 @@
  *  \param iHeight transform height
  */
-Void TComTrQuant::xIT( const ComponentID compID, Bool useDST, TCoeff* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight )
+Void TComTrQuant::xIT( const ComponentID compID, Bool useDST, TCoeff* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange )
 {
 #if MATRIX_MULT
@@ -1904,7 +1906,7 @@
   {
 #if O0043_BEST_EFFORT_DECODING
-    xITr(g_bitDepthInStream[toChannelType(compID)], plCoef, pResidual, uiStride, (UInt)iWidth, useDST, g_maxTrDynamicRange[toChannelType(compID)]);
+    xITr(g_bitDepthInStream[toChannelType(compID)], plCoef, pResidual, uiStride, (UInt)iWidth, useDST, maxLog2TrDynamicRange);
 #else
-    xITr(g_bitDepth[toChannelType(compID)], plCoef, pResidual, uiStride, (UInt)iWidth, useDST, g_maxTrDynamicRange[toChannelType(compID)]);
+    xITr(g_bitDepth[toChannelType(compID)], plCoef, pResidual, uiStride, (UInt)iWidth, useDST, maxLog2TrDynamicRange);
 #endif
     return;
@@ -1918,7 +1920,7 @@
 
 #if O0043_BEST_EFFORT_DECODING
-  xITrMxN( g_bitDepthInStream[toChannelType(compID)], coeff, block, iWidth, iHeight, useDST, g_maxTrDynamicRange[toChannelType(compID)] );
+  xITrMxN( g_bitDepthInStream[toChannelType(compID)], coeff, block, iWidth, iHeight, useDST, maxLog2TrDynamicRange );
 #else
-  xITrMxN( g_bitDepth[toChannelType(compID)], coeff, block, iWidth, iHeight, useDST, g_maxTrDynamicRange[toChannelType(compID)] );
+  xITrMxN( g_bitDepth[toChannelType(compID)], coeff, block, iWidth, iHeight, useDST, maxLog2TrDynamicRange );
 #endif
 
@@ -1944,6 +1946,7 @@
   const Int width           = rect.width;
   const Int height          = rect.height;
-
-  Int iTransformShift = getTransformShift(toChannelType(component), rTu.GetEquivalentLog2TrSize(component));
+  const Int maxLog2TrDynamicRange = rTu.getCU()->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(component));
+
+  Int iTransformShift = getTransformShift(toChannelType(component), rTu.GetEquivalentLog2TrSize(component), maxLog2TrDynamicRange);
   if (rTu.getCU()->getSlice()->getSPS()->getUseExtendedPrecision())
   {
@@ -1991,6 +1994,7 @@
   const Int width           = rect.width;
   const Int height          = rect.height;
-
-  Int iTransformShift = getTransformShift(toChannelType(component), rTu.GetEquivalentLog2TrSize(component));
+  const Int maxLog2TrDynamicRange = rTu.getCU()->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(component));
+
+  Int iTransformShift = getTransformShift(toChannelType(component), rTu.GetEquivalentLog2TrSize(component), maxLog2TrDynamicRange);
   if (rTu.getCU()->getSlice()->getSPS()->getUseExtendedPrecision())
   {
@@ -2058,4 +2062,5 @@
 
   const Bool             extendedPrecision = pcCU->getSlice()->getSPS()->getUseExtendedPrecision();
+  const Int              maxLog2TrDynamicRange = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID));
 
   /* for 422 chroma blocks, the effective scaling applied during transformation is not a power of 2, hence it cannot be
@@ -2066,5 +2071,5 @@
 
   // Represents scaling through forward transform
-  Int iTransformShift            = getTransformShift(channelType, uiLog2TrSize);
+  Int iTransformShift            = getTransformShift(channelType, uiLog2TrSize, maxLog2TrDynamicRange);
   if ((pcCU->getTransformSkip(uiAbsPartIdx, compID) != 0) && pcCU->getSlice()->getSPS()->getUseExtendedPrecision())
   {
@@ -2110,6 +2115,6 @@
   const Double defaultErrorScale              = getErrScaleCoeffNoScalingList(scalingListType, (uiLog2TrSize-2), cQP.rem);
 
-  const TCoeff entropyCodingMinimum = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-  const TCoeff entropyCodingMaximum =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+  const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff entropyCodingMaximum =  (1 << maxLog2TrDynamicRange) - 1;
 
 #if ADAPTIVE_QP_SELECTION
@@ -2813,12 +2818,12 @@
  * \returns cost of given absolute transform level
  */
-__inline Int TComTrQuant::xGetICRate         ( UInt                            uiAbsLevel,
-                                               UShort                          ui16CtxNumOne,
-                                               UShort                          ui16CtxNumAbs,
-                                               UShort                          ui16AbsGoRice,
-                                               UInt                            c1Idx,
-                                               UInt                            c2Idx,
-                                               Bool                            useLimitedPrefixLength,
-                                               ChannelType                     channelType
+__inline Int TComTrQuant::xGetICRate         ( const UInt    uiAbsLevel,
+                                               const UShort  ui16CtxNumOne,
+                                               const UShort  ui16CtxNumAbs,
+                                               const UShort  ui16AbsGoRice,
+                                               const UInt    c1Idx,
+                                               const UInt    c2Idx,
+                                               const Bool    useLimitedPrefixLength,
+                                               const Int     maxLog2TrDynamicRange
                                                ) const
 {
@@ -2837,5 +2842,5 @@
     else if (useLimitedPrefixLength)
     {
-      const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType]));
+      const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
 
       UInt prefixLength = 0;
@@ -2847,5 +2852,5 @@
       }
 
-      const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (g_maxTrDynamicRange[channelType] - ui16AbsGoRice) : (prefixLength + 1/*separator*/);
+      const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - ui16AbsGoRice) : (prefixLength + 1/*separator*/);
 
       iRate += (COEF_REMAIN_BIN_REDUCTION + prefixLength + suffixLength + ui16AbsGoRice) << 15;
@@ -2981,5 +2986,5 @@
  * \param format      chroma format
  */
-Void TComTrQuant::setScalingList(TComScalingList *scalingList, const ChromaFormat format)
+Void TComTrQuant::setScalingList(TComScalingList *scalingList, const ChromaFormat format, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE])
 {
   const Int minimumQp = 0;
@@ -2994,5 +2999,5 @@
         xSetScalingListEnc(scalingList,list,size,qp,format);
         xSetScalingListDec(*scalingList,list,size,qp,format);
-        setErrScaleCoeff(list,size,qp);
+        setErrScaleCoeff(list,size,qp,maxLog2TrDynamicRange);
       }
     }
@@ -3024,10 +3029,10 @@
  * \param qp   Quantization parameter
  */
-Void TComTrQuant::setErrScaleCoeff(UInt list, UInt size, Int qp)
+Void TComTrQuant::setErrScaleCoeff(UInt list, UInt size, Int qp, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE])
 {
   const UInt uiLog2TrSize = g_aucConvertToBit[ g_scalingListSizeX[size] ] + 2;
   const ChannelType channelType = ((list == 0) || (list == MAX_NUM_COMPONENT)) ? CHANNEL_TYPE_LUMA : CHANNEL_TYPE_CHROMA;
 
-  const Int iTransformShift = getTransformShift(channelType, uiLog2TrSize);  // Represents scaling through forward transform
+  const Int iTransformShift = getTransformShift(channelType, uiLog2TrSize, maxLog2TrDynamicRange[channelType]);  // Represents scaling through forward transform
 
   UInt i,uiMaxNumCoeff = g_scalingListSize[size];
@@ -3103,5 +3108,5 @@
 /** set flat matrix value to quantized coefficient
  */
-Void TComTrQuant::setFlatScalingList(const ChromaFormat format)
+Void TComTrQuant::setFlatScalingList(const ChromaFormat format, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE])
 {
   const Int minimumQp = 0;
@@ -3115,5 +3120,5 @@
       {
         xsetFlatScalingList(list,size,qp,format);
-        setErrScaleCoeff(list,size,qp);
+        setErrScaleCoeff(list,size,qp,maxLog2TrDynamicRange);
       }
     }
@@ -3250,5 +3255,6 @@
   const UInt           uiWidth                        = rect.width;
   const UInt           uiHeight                       = rect.height;
-  const Int            iTransformShift                = getTransformShift(toChannelType(compID), rTu.GetEquivalentLog2TrSize(compID));
+  const Int            maxLog2TrDynamicRange          = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID));
+  const Int            iTransformShift                = getTransformShift(toChannelType(compID), rTu.GetEquivalentLog2TrSize(compID), maxLog2TrDynamicRange);
   const Int            scalingListType                = getScalingListType(pcCU->getPredictionMode(uiAbsPartIdx), compID);
   const Bool           enableScalingLists             = getUseScalingList(uiWidth, uiHeight, true);
@@ -3293,6 +3299,6 @@
   const TCoeff quantisedCoefficient = (TCoeff((tmpLevel + iAdd ) >> iQBits)) * iSign;
 
-  const TCoeff entropyCodingMinimum = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-  const TCoeff entropyCodingMaximum =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+  const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff entropyCodingMaximum =  (1 << maxLog2TrDynamicRange) - 1;
   pcCoeff[ uiPos ] = Clip3<TCoeff>( entropyCodingMinimum, entropyCodingMaximum, quantisedCoefficient );
 }
@@ -3308,5 +3314,6 @@
   const Int            QP_per             = cQP.per;
   const Int            QP_rem             = cQP.rem;
-  const Int            iTransformShift    = getTransformShift(toChannelType(compID), rTu.GetEquivalentLog2TrSize(compID));
+  const Int            maxLog2TrDynamicRange = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(toChannelType(compID));
+  const Int            iTransformShift    = getTransformShift(toChannelType(compID), rTu.GetEquivalentLog2TrSize(compID), maxLog2TrDynamicRange);
   const Int            scalingListType    = getScalingListType(pcCU->getPredictionMode(uiAbsPartIdx), compID);
   const Bool           enableScalingLists = getUseScalingList(uiWidth, uiHeight, true);
@@ -3317,6 +3324,6 @@
   const Int rightShift = (IQUANT_SHIFT - (iTransformShift + QP_per)) + (enableScalingLists ? LOG2_SCALING_LIST_NEUTRAL_VALUE : 0);
 
-  const TCoeff transformMinimum = -(1 << g_maxTrDynamicRange[toChannelType(compID)]);
-  const TCoeff transformMaximum =  (1 << g_maxTrDynamicRange[toChannelType(compID)]) - 1;
+  const TCoeff transformMinimum = -(1 << maxLog2TrDynamicRange);
+  const TCoeff transformMaximum =  (1 << maxLog2TrDynamicRange) - 1;
 
   // Dequantisation
@@ -3327,5 +3334,5 @@
   {
     const UInt             dequantCoefBits     = 1 + IQUANT_SHIFT + SCALING_LIST_BITS;
-    const UInt             targetInputBitDepth = std::min<UInt>((g_maxTrDynamicRange[toChannelType(compID)] + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
+    const UInt             targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
 
     const Intermediate_Int inputMinimum        = -(1 << (targetInputBitDepth - 1));
@@ -3356,5 +3363,5 @@
     const Int scaleBits =     (IQUANT_SHIFT + 1)   ;
 
-    const UInt             targetInputBitDepth = std::min<UInt>((g_maxTrDynamicRange[toChannelType(compID)] + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - scaleBits));
+    const UInt             targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((sizeof(Intermediate_Int) * 8) + rightShift) - scaleBits));
     const Intermediate_Int inputMinimum        = -(1 << (targetInputBitDepth - 1));
     const Intermediate_Int inputMaximum        =  (1 << (targetInputBitDepth - 1)) - 1;
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComTrQuant.h	(revision 1285)
@@ -172,5 +172,5 @@
   Void initScalingList                      ();
   Void destroyScalingList                   ();
-  Void setErrScaleCoeff    ( UInt list, UInt size, Int qp );
+  Void setErrScaleCoeff    ( UInt list, UInt size, Int qp, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] );
   Double* getErrScaleCoeff              ( UInt list, UInt size, Int qp ) { return m_errScale             [size][list][qp]; };  //!< get Error Scale Coefficent
   Double& getErrScaleCoeffNoScalingList ( UInt list, UInt size, Int qp ) { return m_errScaleNoScalingList[size][list][qp]; };  //!< get Error Scale Coefficent
@@ -179,9 +179,9 @@
   Void setUseScalingList   ( Bool bUseScalingList){ m_scalingListEnabledFlag = bUseScalingList; };
   Bool getUseScalingList   (const UInt width, const UInt height, const Bool isTransformSkip){ return m_scalingListEnabledFlag && (!isTransformSkip || ((width == 4) && (height == 4))); };
-  Void setFlatScalingList  (const ChromaFormat format);
+  Void setFlatScalingList  (const ChromaFormat format, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE]);
   Void xsetFlatScalingList ( UInt list, UInt size, Int qp, const ChromaFormat format);
   Void xSetScalingListEnc  ( TComScalingList *scalingList, UInt list, UInt size, Int qp, const ChromaFormat format);
   Void xSetScalingListDec  ( const TComScalingList &scalingList, UInt list, UInt size, Int qp, const ChromaFormat format);
-  Void setScalingList      ( TComScalingList *scalingList, const ChromaFormat format);
+  Void setScalingList      ( TComScalingList *scalingList, const ChromaFormat format, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE]);
   Void setScalingListDec   ( const TComScalingList &scalingList, const ChromaFormat format);
   Void processScalingListEnc( Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc);
@@ -230,10 +230,10 @@
 private:
   // forward Transform
-  Void xT   ( const ComponentID compID, Bool useDST, Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, Int iWidth, Int iHeight );
+  Void xT   ( const ComponentID compID, Bool useDST, Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange );
 
   // skipping Transform
   Void xTransformSkip ( Pel* piBlkResi, UInt uiStride, TCoeff* psCoeff, TComTU &rTu, const ComponentID component );
 
-  Void signBitHidingHDQ( const ComponentID compID, TCoeff* pQCoef, TCoeff* pCoef, TCoeff* deltaU, const TUEntropyCodingParameters &codingParameters );
+  Void signBitHidingHDQ( const ComponentID compID, TCoeff* pQCoef, TCoeff* pCoef, TCoeff* deltaU, const TUEntropyCodingParameters &codingParameters, const Int maxLog2TrDynamicRange );
 
   // quantization
@@ -279,12 +279,12 @@
 
 
-  __inline Int xGetICRate  ( UInt   uiAbsLevel,
-                             UShort ui16CtxNumOne,
-                             UShort ui16CtxNumAbs,
-                             UShort ui16AbsGoRice,
-                             UInt   c1Idx,
-                             UInt   c2Idx,
-                             Bool   useLimitedPrefixLength,
-                             ChannelType channelType
+  __inline Int xGetICRate  ( const UInt   uiAbsLevel,
+                             const UShort ui16CtxNumOne,
+                             const UShort ui16CtxNumAbs,
+                             const UShort ui16AbsGoRice,
+                             const UInt   c1Idx,
+                             const UInt   c2Idx,
+                             const Bool   useLimitedPrefixLength,
+                             const Int maxLog2TrDynamicRange
                            ) const;
 
@@ -304,5 +304,5 @@
 
   // inverse transform
-  Void xIT    ( const ComponentID compID, Bool useDST, TCoeff* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight );
+  Void xIT    ( const ComponentID compID, Bool useDST, TCoeff* plCoef, Pel* pResidual, UInt uiStride, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange );
 
   // inverse skipping transform
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 1285)
@@ -299,7 +299,7 @@
  */
 #if RExt__DECODER_DEBUG_BIT_STATISTICS
-Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const class TComCodingStatisticsClassType &whichStat )
+Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat )
 #else
-Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType )
+Void TDecSbac::xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange )
 #endif
 {
@@ -309,5 +309,5 @@
   if (useLimitedPrefixLength)
   {
-    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType])) + COEF_REMAIN_BIN_REDUCTION;
+    const UInt longestPossiblePrefix = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange)) + COEF_REMAIN_BIN_REDUCTION;
 
     do
@@ -337,8 +337,8 @@
   else if (useLimitedPrefixLength)
   {
-    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType]));
+    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
 
     const UInt prefixLength = prefix - COEF_REMAIN_BIN_REDUCTION;
-    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (g_maxTrDynamicRange[channelType] - rParam) : prefixLength;
+    const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - rParam) : prefixLength;
 
     m_pcTDecBinIf->decodeBinsEP(codeWord, (suffixLength + rParam) RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(whichStat));
@@ -1283,4 +1283,5 @@
 
   const Bool         alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass();
+  const Int          maxLog2TrDynamicRange  = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(channelType);
 
 #if RExt__DECODER_DEBUG_BIT_STATISTICS
@@ -1546,5 +1547,5 @@
           {
             UInt uiLevel;
-            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, channelType RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
+            xReadCoefRemainExGolomb( uiLevel, uiGoRiceParam, extendedPrecision, maxLog2TrDynamicRange RExt__DECODER_DEBUG_BIT_STATISTICS_PASS_OPT_ARG(ctype_escs) );
 
             absCoeff[ idx ] = uiLevel + baseLevel;
@@ -1772,10 +1773,10 @@
         for(Int i=0; i< 4; i++)
         {
-#if SVC_EXTENSION
-          parseSaoMaxUvlc(uiSymbol,  saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
-#else
 #if O0043_BEST_EFFORT_DECODING
           Int saoMaxOffsetQVal = (1<<(min(bitDepthOrig, MAX_SAO_TRUNCATED_BITDEPTH)-5))-1;
           parseSaoMaxUvlc(uiSymbol, saoMaxOffsetQVal); //sao_offset_abs
+#else
+#if SVC_EXTENSION
+          parseSaoMaxUvlc(uiSymbol,  saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
 #else
           parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 1285)
@@ -106,10 +106,10 @@
   Void  xReadUnaryMaxSymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol, const class TComCodingStatisticsClassType &whichStat );
   Void  xReadEpExGolomb     ( UInt& ruiSymbol, UInt uiCount, const class TComCodingStatisticsClassType &whichStat );
-  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const class TComCodingStatisticsClassType &whichStat );
+  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange, const class TComCodingStatisticsClassType &whichStat );
 #else
   Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset );
   Void  xReadUnaryMaxSymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol );
   Void  xReadEpExGolomb     ( UInt& ruiSymbol, UInt uiCount );
-  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType );
+  Void  xReadCoefRemainExGolomb ( UInt &rSymbol, UInt &rParam, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange );
 #endif
 private:
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1285)
@@ -583,6 +583,5 @@
 #else
       g_bitDepth[channel] = sps->getBitDepth(ChannelType(channel));
-#endif
-      g_maxTrDynamicRange[channel] = (sps->getUseExtendedPrecision()) ? std::max<Int>(15, (g_bitDepth[channel] + 6)) : 15;
+#endif      
     }
     g_uiMaxCUWidth  = sps->getMaxCUWidth();
@@ -1799,8 +1798,13 @@
   else
   {
-#if SVC_EXTENSION
-    m_cTrQuant.setFlatScalingList(pcSlice->getChromaFormatIdc());
+    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
+    {
+        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
+        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
+    };
+#if SVC_EXTENSION
+    m_cTrQuant.setFlatScalingList(pcSlice->getChromaFormatIdc(), maxLog2TrDynamicRange);
 #else
-    m_cTrQuant.setFlatScalingList(pcSlice->getSPS()->getChromaFormatIdc());
+    m_cTrQuant.setFlatScalingList(pcSlice->getSPS()->getChromaFormatIdc(), maxLog2TrDynamicRange);
 #endif
     m_cTrQuant.setUseScalingList(false);
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 1285)
@@ -340,5 +340,5 @@
  * \param channelType             plane type (luma/chroma)
  */
-Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType )
+Void TEncSbac::xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const Int maxLog2TrDynamicRange )
 {
   Int codeNumber  = (Int)symbol;
@@ -353,5 +353,5 @@
   else if (useLimitedPrefixLength)
   {
-    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + g_maxTrDynamicRange[channelType]));
+    const UInt maximumPrefixLength = (32 - (COEF_REMAIN_BIN_REDUCTION + maxLog2TrDynamicRange));
 
     UInt prefixLength = 0;
@@ -362,5 +362,5 @@
     {
       prefixLength = maximumPrefixLength;
-      suffixLength = g_maxTrDynamicRange[channelType] - rParam;
+      suffixLength = maxLog2TrDynamicRange - rParam;
     }
     else
@@ -1254,4 +1254,5 @@
 
   const Bool         alignCABACBeforeBypass = pcCU->getSlice()->getSPS()->getAlignCABACBeforeBypass();
+  const Int          maxLog2TrDynamicRange  = pcCU->getSlice()->getSPS()->getMaxLog2TrDynamicRange(channelType);
 
   Bool beValid;
@@ -1504,5 +1505,5 @@
             const UInt escapeCodeValue = absCoeff[idx] - baseLevel;
 
-            xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, channelType );
+            xWriteCoefRemainExGolomb( escapeCodeValue, uiGoRiceParam, extendedPrecision, channelType, maxLog2TrDynamicRange );
 
             if (absCoeff[idx] > (3 << uiGoRiceParam))
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSbac.h	(revision 1285)
@@ -128,5 +128,5 @@
   Void  xWriteUnaryMaxSymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset, UInt uiMaxSymbol );
   Void  xWriteEpExGolomb     ( UInt uiSymbol, UInt uiCount );
-  Void  xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType );
+  Void  xWriteCoefRemainExGolomb ( UInt symbol, UInt &rParam, const Bool useLimitedPrefixLength, const ChannelType channelType, const Int maxLog2TrDynamicRange );
 
   Void  xCopyFrom            ( const TEncSbac* pSrc );
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1284)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1285)
@@ -275,11 +275,15 @@
   // Initialise scaling lists
   // The encoder will only use the SPS scaling lists. The PPS will never be marked present.
-
+  const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
+  {
+      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
+      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
+  };
   if(getUseScalingListId() == SCALING_LIST_OFF)
   {
 #if SVC_EXTENSION
-    getTrQuant()->setFlatScalingList(m_cVPS.getChromaFormatIdc(&m_cSPS, m_layerId));
+    getTrQuant()->setFlatScalingList(m_cVPS.getChromaFormatIdc(&m_cSPS, m_layerId), maxLog2TrDynamicRange);
 #else
-    getTrQuant()->setFlatScalingList(m_cSPS.getChromaFormatIdc());
+    getTrQuant()->setFlatScalingList(m_cSPS.getChromaFormatIdc(), maxLog2TrDynamicRange);
 #endif
     getTrQuant()->setUseScalingList(false);
@@ -301,5 +305,5 @@
 
       // infer the scaling list from the reference layer
-      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() );
+      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc(), maxLog2TrDynamicRange );
     }
     else
@@ -309,5 +313,6 @@
     m_cSPS.setScalingListPresentFlag(false);
     m_cPPS.setScalingListPresentFlag(false);
-    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc());
+
+    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc(), maxLog2TrDynamicRange);
 #if SVC_EXTENSION
     }
@@ -329,5 +334,5 @@
 
       // infer the scaling list from the reference layer
-      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc() );
+      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), m_cSPS.getChromaFormatIdc(), maxLog2TrDynamicRange );
     }
     else
@@ -344,5 +349,5 @@
     m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList());
     m_cPPS.setScalingListPresentFlag(false);
-    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc());
+    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), m_cSPS.getChromaFormatIdc(), maxLog2TrDynamicRange);
 #if SVC_EXTENSION
     }
