Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 189)
@@ -56,5 +56,5 @@
 // ====================================================================================================================
 
-#define NV_VERSION        "1.2"                 ///< Current software version
+#define NV_VERSION        "2.0rc1"                 ///< Current software version
 
 // ====================================================================================================================
@@ -110,5 +110,7 @@
 #define MAX_NUM_REF_PICS            16          ///< max. number of pictures used for reference
 #define MAX_NUM_REF                 16          ///< max. number of entries in picture reference list
+#if !L0034_COMBINED_LIST_CLEANUP
 #define MAX_NUM_REF_LC              MAX_NUM_REF_PICS  // TODO: remove this macro definition (leftover from combined list concept)
+#endif
 
 #define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
@@ -197,5 +199,5 @@
   
   NAL_UNIT_CODED_SLICE_TSA_N,     // 2
-  NAL_UNIT_CODED_SLICE_TLA,       // 3   // Current name in the spec: TSA_R
+  NAL_UNIT_CODED_SLICE_TLA_R,       // 3
   
   NAL_UNIT_CODED_SLICE_STSA_N,    // 4
@@ -203,33 +205,33 @@
 
   NAL_UNIT_CODED_SLICE_RADL_N,    // 6
-  NAL_UNIT_CODED_SLICE_DLP,       // 7 // Current name in the spec: RADL_R
+  NAL_UNIT_CODED_SLICE_RADL_R,      // 7
   
   NAL_UNIT_CODED_SLICE_RASL_N,    // 8
-  NAL_UNIT_CODED_SLICE_TFD,       // 9 // Current name in the spec: RASL_R
-
-  NAL_UNIT_RESERVED_10,
-  NAL_UNIT_RESERVED_11,
-  NAL_UNIT_RESERVED_12,
-  NAL_UNIT_RESERVED_13,
-  NAL_UNIT_RESERVED_14,
-  NAL_UNIT_RESERVED_15,
-
-  NAL_UNIT_CODED_SLICE_BLA,       // 16   // Current name in the spec: BLA_W_LP
-  NAL_UNIT_CODED_SLICE_BLANT,     // 17   // Current name in the spec: BLA_W_DLP
+  NAL_UNIT_CODED_SLICE_RASL_R,      // 9
+
+  NAL_UNIT_RESERVED_VCL_N10,
+  NAL_UNIT_RESERVED_VCL_R11,
+  NAL_UNIT_RESERVED_VCL_N12,
+  NAL_UNIT_RESERVED_VCL_R13,
+  NAL_UNIT_RESERVED_VCL_N14,
+  NAL_UNIT_RESERVED_VCL_R15,
+
+  NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
+  NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
   NAL_UNIT_CODED_SLICE_BLA_N_LP,  // 18
-  NAL_UNIT_CODED_SLICE_IDR,       // 19  // Current name in the spec: IDR_W_DLP
+  NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
   NAL_UNIT_CODED_SLICE_IDR_N_LP,  // 20
   NAL_UNIT_CODED_SLICE_CRA,       // 21
-  NAL_UNIT_RESERVED_22,
-  NAL_UNIT_RESERVED_23,
-
-  NAL_UNIT_RESERVED_24,
-  NAL_UNIT_RESERVED_25,
-  NAL_UNIT_RESERVED_26,
-  NAL_UNIT_RESERVED_27,
-  NAL_UNIT_RESERVED_28,
-  NAL_UNIT_RESERVED_29,
-  NAL_UNIT_RESERVED_30,
-  NAL_UNIT_RESERVED_31,
+  NAL_UNIT_RESERVED_IRAP_VCL22,
+  NAL_UNIT_RESERVED_IRAP_VCL23,
+
+  NAL_UNIT_RESERVED_VCL24,
+  NAL_UNIT_RESERVED_VCL25,
+  NAL_UNIT_RESERVED_VCL26,
+  NAL_UNIT_RESERVED_VCL27,
+  NAL_UNIT_RESERVED_VCL28,
+  NAL_UNIT_RESERVED_VCL29,
+  NAL_UNIT_RESERVED_VCL30,
+  NAL_UNIT_RESERVED_VCL31,
 
   NAL_UNIT_VPS,                   // 32
@@ -240,13 +242,13 @@
   NAL_UNIT_EOB,                   // 37
   NAL_UNIT_FILLER_DATA,           // 38
-  NAL_UNIT_SEI,                   // 39 Prefix SEI
-  NAL_UNIT_SEI_SUFFIX,            // 40 Suffix SEI
-  NAL_UNIT_RESERVED_41,
-  NAL_UNIT_RESERVED_42,
-  NAL_UNIT_RESERVED_43,
-  NAL_UNIT_RESERVED_44,
-  NAL_UNIT_RESERVED_45,
-  NAL_UNIT_RESERVED_46,
-  NAL_UNIT_RESERVED_47,
+  NAL_UNIT_PREFIX_SEI,              // 39
+  NAL_UNIT_SUFFIX_SEI,              // 40
+  NAL_UNIT_RESERVED_NVCL41,
+  NAL_UNIT_RESERVED_NVCL42,
+  NAL_UNIT_RESERVED_NVCL43,
+  NAL_UNIT_RESERVED_NVCL44,
+  NAL_UNIT_RESERVED_NVCL45,
+  NAL_UNIT_RESERVED_NVCL46,
+  NAL_UNIT_RESERVED_NVCL47,
   NAL_UNIT_UNSPECIFIED_48,
   NAL_UNIT_UNSPECIFIED_49,
Index: trunk/source/Lib/TLibCommon/NAL.h
===================================================================
--- trunk/source/Lib/TLibCommon/NAL.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/NAL.h	(revision 189)
@@ -76,24 +76,24 @@
     return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLANT
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_DLP
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N
-        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TFD;
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R;
   }
 #if L0045_NON_NESTED_SEI_RESTRICTIONS
   Bool isSei()
   {
-    return m_nalUnitType == NAL_UNIT_SEI 
-        || m_nalUnitType == NAL_UNIT_SEI_SUFFIX;
+    return m_nalUnitType == NAL_UNIT_PREFIX_SEI 
+        || m_nalUnitType == NAL_UNIT_SUFFIX_SEI;
   }
 
Index: trunk/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/SEI.cpp	(revision 189)
@@ -38,4 +38,9 @@
 #include "CommonDef.h"
 #include "SEI.h"
+
+#if J0149_TONE_MAPPING_SEI 
+//Table D-7 Meaning of camera iso sensitivity indicator and exposure index rating indicator
+Int  Table_exp_indicator[32] = {0, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, -1};
+#endif
 
 SEIMessages getSeisByType(SEIMessages &seiList, SEI::PayloadType seiType)
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 189)
@@ -355,4 +355,58 @@
 };
 
+#if L0208_SOP_DESCRIPTION_SEI
+class SEISOPDescription : public SEI
+{
+public:
+  PayloadType payloadType() const { return SOP_DESCRIPTION; }
+
+  SEISOPDescription() {}
+  virtual ~SEISOPDescription() {}
+
+  UInt m_sopSeqParameterSetId;
+  UInt m_numPicsInSopMinus1;
+
+  UInt m_sopDescVclNaluType[MAX_NUM_PICS_IN_SOP];
+  UInt m_sopDescTemporalId[MAX_NUM_PICS_IN_SOP];
+  UInt m_sopDescStRpsIdx[MAX_NUM_PICS_IN_SOP];
+  Int m_sopDescPocDelta[MAX_NUM_PICS_IN_SOP];
+};
+#endif
+
+#if J0149_TONE_MAPPING_SEI 
+class SEIToneMappingInfo : public SEI
+{
+public:
+  PayloadType payloadType() const { return TONE_MAPPING_INFO; }
+  SEIToneMappingInfo() {}
+  virtual ~SEIToneMappingInfo() {}
+
+  Int    m_toneMapId;
+  Bool   m_toneMapCancelFlag;
+  Bool   m_toneMapPersistenceFlag;
+  Int    m_codedDataBitDepth;
+  Int    m_targetBitDepth;
+  Int    m_modelId;
+  Int    m_minValue;
+  Int    m_maxValue;
+  Int    m_sigmoidMidpoint;
+  Int    m_sigmoidWidth;
+  std::vector<Int> m_startOfCodedInterval;
+  Int    m_numPivots;
+  std::vector<Int> m_codedPivotValue;
+  std::vector<Int> m_targetPivotValue;
+  Int    m_cameraIsoSpeedIdc;
+  Int    m_cameraIsoSpeedValue;
+  Int    m_exposureCompensationValueSignFlag;
+  Int    m_exposureCompensationValueNumerator;
+  Int    m_exposureCompensationValueDenomIdc;
+  Int    m_refScreenLuminanceWhite;
+  Int    m_extendedRangeWhiteLevel;
+  Int    m_nominalBlackLevelLumaCodeValue;
+  Int    m_nominalWhiteLevelLumaCodeValue;
+  Int    m_extendedWhiteLevelLumaCodeValue;
+};
+#endif
+
 typedef std::list<SEI*> SEIMessages;
 
@@ -366,3 +420,35 @@
 Void deleteSEIs (SEIMessages &seiList);
 
+#if K0180_SCALABLE_NESTING_SEI
+class SEIScalableNesting : public SEI
+{
+public:
+  PayloadType payloadType() const { return SCALABLE_NESTING; }
+
+  SEIScalableNesting() {}
+  virtual ~SEIScalableNesting()
+  {
+    if (!m_callerOwnsSEIs)
+    {
+      deleteSEIs(m_nestedSEIs);
+    }
+  }
+
+  Bool  m_bitStreamSubsetFlag;
+  Bool  m_nestingOpFlag;
+  Bool  m_defaultOpFlag;                             //value valid if m_nestingOpFlag != 0
+  UInt  m_nestingNumOpsMinus1;                       // -"-
+  UInt  m_nestingMaxTemporalIdPlus1[MAX_TLAYER];     // -"-
+  UInt  m_nestingOpIdx[MAX_NESTING_NUM_OPS];         // -"-
+
+  Bool  m_allLayersFlag;                             //value valid if m_nestingOpFlag == 0
+  UInt  m_nestingNoOpMaxTemporalIdPlus1;             //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0
+  UInt  m_nestingNumLayersMinus1;                    //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0
+  UChar m_nestingLayerId[MAX_NESTING_NUM_LAYER];     //value valid if m_nestingOpFlag == 0 and m_allLayersFlag == 0. This can e.g. be a static array of 64 unsigned char values
+
+  Bool  m_callerOwnsSEIs;
+  SEIMessages m_nestedSEIs;
+};
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibCommon/TComBitStream.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 189)
@@ -177,4 +177,5 @@
   }
 }
+
 Void TComOutputBitstream::writeByteAlignment()
 {
@@ -182,4 +183,37 @@
   writeAlignZero();
 }
+
+Int TComOutputBitstream::countStartCodeEmulations()
+{
+  UInt cnt = 0;
+  vector<uint8_t>& rbsp   = getFIFO();
+  for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
+  {
+    vector<uint8_t>::iterator found = it;
+    do
+    {
+      // find the next emulated 00 00 {00,01,02,03}
+      // NB, end()-1, prevents finding a trailing two byte sequence
+      found = search_n(found, rbsp.end()-1, 2, 0);
+      found++;
+      // if not found, found == end, otherwise found = second zero byte
+      if (found == rbsp.end())
+      {
+        break;
+      }
+      if (*(++found) <= 3)
+      {
+        break;
+      }
+    } while (true);
+    it = found;
+    if (found != rbsp.end())
+    {
+      cnt++;
+    }
+  }
+  return cnt;
+}
+
 /**
  * read #uiNumberOfBits# from bitstream without updating the bitstream
Index: trunk/source/Lib/TLibCommon/TComBitStream.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 189)
@@ -154,4 +154,7 @@
   Void          addSubstream    ( TComOutputBitstream* pcSubstream );
   Void writeByteAlignment();
+
+  //! returns the number of start code emulations contained in the current buffer
+  Int countStartCodeEmulations();
 };
 
@@ -163,4 +166,5 @@
 {
   std::vector<uint8_t> *m_fifo; /// FIFO for storage of complete bytes
+  std::vector<UInt> m_emulationPreventionByteLocation;
 
 protected:
@@ -206,4 +210,11 @@
   UInt  getNumBitsRead() { return m_numBitsRead; }
   Void readByteAlignment();
+
+  Void      pushEmulationPreventionByteLocation ( UInt pos )                  { m_emulationPreventionByteLocation.push_back( pos ); }
+  UInt      numEmulationPreventionBytesRead     ()                            { return (UInt) m_emulationPreventionByteLocation.size();    }
+  std::vector<UInt>  getEmulationPreventionByteLocation  ()                   { return m_emulationPreventionByteLocation;           }
+  UInt      getEmulationPreventionByteLocation  ( UInt idx )                  { return m_emulationPreventionByteLocation[ idx ];    }
+  Void      clearEmulationPreventionByteLocation()                            { m_emulationPreventionByteLocation.clear();          }
+  Void      setEmulationPreventionByteLocation  ( std::vector<UInt> vec )     { m_emulationPreventionByteLocation = vec;            }
 };
 
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 189)
@@ -1802,4 +1802,10 @@
 UInt TComDataCU::getCtxIntraBLFlag( UInt uiAbsPartIdx )
 {
+#if INTRA_BL_CTX_CHANGE
+  Int cuDepth = getDepth(uiAbsPartIdx);
+  Int maxCuDepth = g_uiMaxCUDepth - g_uiAddCUDepth;
+  UInt uiCtx = (maxCuDepth==3 && cuDepth > 0) ? (cuDepth - 1) : cuDepth;
+  return uiCtx;
+#else
   TComDataCU* pcTempCU;
   UInt        uiTempPartIdx;
@@ -1824,4 +1830,5 @@
   
   return uiCtx;
+#endif
 }
 #endif
@@ -1835,5 +1842,5 @@
   {
     Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR())
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
@@ -1843,5 +1850,5 @@
   {
     Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR())
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
@@ -1859,5 +1866,5 @@
   Bool checkZeroMVILR = true;
 
-  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR())
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
   {
     AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
@@ -2530,12 +2537,5 @@
   if(m_layerId)  
   {
-#if MV_SCALING_POS_FIX
     pcColCU = getBaseColCU( xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
-#else
-    UInt uiPartIdxCenter;
-    xDeriveCenterIdx( cCurPS, uiPUIdx, uiPartIdxCenter );
-    uiPartIdxCenter -= m_uiAbsIdxInLCU;
-    pcColCU = getBaseColCU( uiPartIdxCenter, uiCUAddrBase, uiAbsPartAddrBase );
-#endif
     
 #if INTRA_BL
@@ -2671,5 +2671,5 @@
 #endif
   Bool isAvailableB0 = pcCUAboveRight &&
-#if SVC_MVP
+#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
   ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveRight->hasEqualMotion( uiAboveRightPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
 #endif
@@ -2715,5 +2715,5 @@
   Bool isAvailableA0 = pcCULeftBottom &&
   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
-#if SVC_MVP
+#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
   ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeftBottom->hasEqualMotion( uiLeftBottomPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0])) &&
 #endif
@@ -2759,5 +2759,5 @@
     Bool isAvailableB2 = pcCUAboveLeft &&
     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
-#if SVC_MVP
+#if SVC_MVP && !IL_MRG_SIMPLIFIED_PRUNING
     ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveLeft->hasEqualMotion( uiAboveLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
 #endif
@@ -4175,5 +4175,6 @@
   TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
 
-#if SVC_UPSAMPLING
+#if !SIMPLIFIED_MV_POS_SCALING
+#if SVC_UPSAMPLING && !ILP_DECODED_PICTURE
   const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
   const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
@@ -4191,4 +4192,5 @@
   Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
 #endif
+#endif
 
   uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
@@ -4197,13 +4199,37 @@
   UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
 
+#if SIMPLIFIED_MV_POS_SCALING
+#if SCALED_REF_LAYER_OFFSETS
+  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowLeftOffset();
+  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowTopOffset();
+  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
+  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+#else
+  Int iBX = (uiPelX*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
+  Int iBY = (uiPelY*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+#endif
+#else
   Int iBX = (uiPelX*widthBL + widthEL/2)/widthEL;
   Int iBY = (uiPelY*heightBL+ heightEL/2)/heightEL;
-
+#endif
+
+#if SCALED_REF_LAYER_OFFSETS
+  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
+       iBX < 0                                        || iBY < 0                                           )
+#else
   if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+#endif
   {
     return NULL;
   }
 
-#if AVC_SYNTAX
+#if AVC_SYNTAX && !ILP_DECODED_PICTURE
+#if !ILP_DECODED_PICTURE
+  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
+  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
+
+  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+#endif
   if( iBX >= widthBL || iBY >= heightBL ) //outside of the reference layer cropped picture
   {
@@ -4228,6 +4254,7 @@
   TComMvField cMvFieldBase;
   TComMv cMv;
-
-#if MV_SCALING_FIX
+#if SIMPLIFIED_MV_POS_SCALING
+  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[m_layerId][0], g_mvScalingFactor[m_layerId][1] );
+#else
   const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
   const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
@@ -4238,11 +4265,4 @@
   Int widthEL   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
   Int heightEL  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#else
-  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
-  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
-
-  Int widthEL   = m_pcPic->getPicYuvRec()->getWidth();
-  Int heightEL  = m_pcPic->getPicYuvRec()->getHeight();
-#endif
 
   Int iMvX = (rcMvFieldBase.getHor()*widthEL + (widthBL/2 -1) * (rcMvFieldBase.getHor() > 0 ? 1: -1) )/widthBL;
@@ -4250,4 +4270,5 @@
 
   cMv.set(iMvX, iMvY);
+#endif
 
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
Index: trunk/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 189)
@@ -57,10 +57,10 @@
 // ====================================================================================================================
 
-const UChar tctable_8x8[54] =
+const UChar TComLoopFilter::sm_tcTable[54] =
 {
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,8,9,10,11,13,14,16,18,20,22,24
 };
 
-const UChar betatable_8x8[52] =
+const UChar TComLoopFilter::sm_betaTable[52] =
 {
   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64
@@ -585,6 +585,6 @@
       Int iIndexB = Clip3(0, MAX_QP, iQP + (betaOffsetDiv2 << 1));
       
-      Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
-      Int iBeta = betatable_8x8[iIndexB]*iBitdepthScale;
+      Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
+      Int iBeta = sm_betaTable[iIndexB]*iBitdepthScale;
       Int iSideThreshold = (iBeta+(iBeta>>1))>>3;
       Int iThrCut = iTc*10;
@@ -735,5 +735,5 @@
 
         Int iIndexTC = Clip3(0, MAX_QP+DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET*(ucBs - 1) + (tcOffsetDiv2 << 1));
-        Int iTc =  tctable_8x8[iIndexTC]*iBitdepthScale;
+        Int iTc =  sm_tcTable[iIndexTC]*iBitdepthScale;
 
         for ( UInt uiStep = 0; uiStep < uiPelsInPartChroma; uiStep++ )
Index: trunk/source/Lib/TLibCommon/TComLoopFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComLoopFilter.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComLoopFilter.h	(revision 189)
@@ -99,4 +99,7 @@
   __inline Int xCalcDQ( Pel* piSrc, Int iOffset);
   
+  static const UChar sm_tcTable[54];
+  static const UChar sm_betaTable[52];
+
 public:
   TComLoopFilter();
@@ -111,4 +114,10 @@
   /// picture-level deblocking filter
   Void loopFilterPic( TComPic* pcPic );
+
+  static Int getBeta( Int qp )
+  {
+    Int indexB = Clip3( 0, MAX_QP, qp );
+    return sm_betaTable[ indexB ];
+  }
 };
 
Index: trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMv.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComMv.h	(revision 189)
@@ -149,4 +149,12 @@
     return TComMv( mvx, mvy );
   }
+#if SIMPLIFIED_MV_POS_SCALING
+  const TComMv scaleMv( Int iScaleX, Int iScaleY ) const
+  {
+    Int mvx = Clip3( -32768, 32767, (iScaleX * getHor() + 127 + (iScaleX * getHor() < 0)) >> 8 );
+    Int mvy = Clip3( -32768, 32767, (iScaleY * getVer() + 127 + (iScaleY * getVer() < 0)) >> 8 );
+    return TComMv( mvx, mvy );
+  }
+#endif
 };// END CLASS DEFINITION TComMV
 
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 189)
@@ -116,27 +116,4 @@
   return;
 }
-#if REF_IDX_FRAMEWORK
-Void TComPic::createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps,  Bool bIsVirtual)
-{
-  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
-  if (!bIsVirtual)
-  {
-    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
-  }
-  m_apcPicYuv[1]  = NULL;
- 
-#if SVC_UPSAMPLING
-  if (m_bSpatialEnhLayer)
-  {
-    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
-  }
-#endif
-
-  /* there are no SEI messages associated with this picture initially */
-  m_SEIs.clear();
-  m_bUsedByCurr = false;
-  return;
-}
-#endif
 #else
 Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
@@ -559,5 +536,5 @@
 }
 
-Void TComPic:: copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
+Void TComPic::copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
 {
   Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); 
@@ -585,44 +562,7 @@
 
 #if REF_IDX_MFM
-#if !REUSE_BLKMAPPING
-Void TComPic::deriveUnitIdxBase( UInt upsamplePelX, UInt upsamplePelY, UInt ratio, UInt& baseCUAddr, UInt& baseAbsPartIdx )
-{
-  //pixel in the base layer
-
-  UInt pelX       = (upsamplePelX<<1)/ratio;
-  UInt pelY       = (upsamplePelY<<1)/ratio;
-  UInt baseWidth  = getPicYuvRec()->getWidth();
-  UInt baseHeight = getPicYuvRec()->getHeight();
-  
-  UInt widthInCU       = ( baseWidth % g_uiMaxCUWidth  ) ? baseWidth /g_uiMaxCUWidth  + 1 : baseWidth /g_uiMaxCUWidth;
-
-#if MFM_CLIPPING_FIX
-  pelX     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getWidth() - 1, pelX);
-  pelY     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getHeight() - 1, pelY);
-#else
-  UInt heightInCU      = ( baseHeight% g_uiMaxCUHeight ) ? baseHeight/ g_uiMaxCUHeight + 1 : baseHeight/ g_uiMaxCUHeight;
-
-  pelX     = (UInt)Clip3<UInt>(0, widthInCU * g_uiMaxCUWidth - 1, pelX);
-  pelY     = (UInt)Clip3<UInt>(0, heightInCU * g_uiMaxCUHeight - 1, pelY);
-#endif
-  
-  baseCUAddr = pelY / g_uiMaxCUHeight * widthInCU + pelX / g_uiMaxCUWidth;
-
-  UInt widthMinPU = g_uiMaxCUWidth / (1<<g_uiMaxCUDepth);
-  UInt heightMinPU = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
-  
-  UInt absPelX = pelX - (pelX / g_uiMaxCUWidth) * g_uiMaxCUWidth;
-  UInt absPelY = pelY - (pelY / g_uiMaxCUHeight) * g_uiMaxCUHeight;
-
-  UInt rasterIdx = absPelY / heightMinPU * (g_uiMaxCUWidth/widthMinPU) + absPelX / widthMinPU;
-  baseAbsPartIdx = g_auiRasterToZscan[rasterIdx];
-
-  return;
-}
-#endif
-
 Void TComPic::copyUpsampledMvField(TComPic* pcPicBase)
 {
-#if !REUSE_MVSCALE || !REUSE_BLKMAPPING || AVC_SYNTAX
+#if AVC_SYNTAX && !ILP_DECODED_PICTURE
   const Window &confBL = pcPicBase->getConformanceWindow();
   const Window &confEL = getPicYuvRec()->getConformanceWindow();
@@ -633,24 +573,4 @@
   Int widthEL   = getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
   Int heightEL  = getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-  
-#if !REUSE_MVSCALE  || !REUSE_BLKMAPPING
-  UInt upSampleRatio = 0;
-  if(widthEL == widthBL && heightEL == heightBL)
-  {
-    upSampleRatio = 2;
-  }
-  else if(2*widthEL == 3*widthBL && 2*heightEL == 3*heightBL)
-  {
-    upSampleRatio = 3;
-  }
-  else if(widthEL == 2*widthBL && heightEL == 2*heightBL)
-  {
-    upSampleRatio = 4;
-  }
-  else
-  {
-    assert(0);
-  }
 #endif
 
@@ -671,49 +591,21 @@
       UInt baseCUAddr, baseAbsPartIdx;
 
-#if REUSE_BLKMAPPING
       TComDataCU *pcColCU = 0;
       pcColCU = pcCUDes->getBaseColCU(pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
-#else 
-      pcPicBase->deriveUnitIdxBase(pelX + 8, pelY + 8, upSampleRatio, baseCUAddr, baseAbsPartIdx);
-#endif
-
-#if AVC_SYNTAX
+
+#if AVC_SYNTAX && !ILP_DECODED_PICTURE
       Int xBL = ( (pelX + 8) * widthBL + widthEL/2 ) / widthEL;
       Int yBL = ( (pelY + 8) * heightBL+ heightEL/2 ) / heightEL;
 
-#if REUSE_BLKMAPPING
       if( ( xBL < widthBL && yBL < heightBL ) && pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
 #else
-      if( ( xBL < widthBL && yBL < heightBL ) && (pcPicBase->getCU(baseCUAddr)->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(baseCUAddr)->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
-#endif
-#else
-#if REUSE_BLKMAPPING
       if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
-#else
-      if( (pcPicBase->getCU(baseCUAddr)->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(baseCUAddr)->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
-#endif
 #endif
       {
         for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
         {
-#if REUSE_MVSCALE
           TComMvField sMvFieldBase, sMvField;
-#if REUSE_BLKMAPPING
           pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
-#else
-          pcPicBase->getCU(baseCUAddr)->getMvField( pcPicBase->getCU(baseCUAddr), baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
-#endif
           pcCUDes->scaleBaseMV( sMvField, sMvFieldBase );
-#else
-          TComMv cMv = pcPicBase->getCU(baseCUAddr)->getCUMvField((RefPicList)refPicList)->getMv(baseAbsPartIdx);
-          Int refIdx = pcPicBase->getCU(baseCUAddr)->getCUMvField((RefPicList)refPicList)->getRefIdx(baseAbsPartIdx);
-
-          Int hor =  ((Int)upSampleRatio * cMv.getHor())/2 ;
-          Int ver =  ((Int)upSampleRatio * cMv.getVer())/2 ;
-
-          TComMv cScaledMv(hor, ver);
-          TComMvField sMvField;
-          sMvField.setMvField(cScaledMv, refIdx);
-#endif
 
           pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
@@ -739,7 +631,5 @@
   }
 }
-#endif
-
-#if RAP_MFM_INIT
+
 Void TComPic::initUpsampledMvField()
 {
@@ -774,7 +664,12 @@
   }
 
+#if ILP_DECODED_PICTURE
+  UInt   width      = this->getPicYuvRec()->getWidth();
+  UInt   height     = this->getPicYuvRec()->getHeight();
+#else
   const Window &conf = this->getPicYuvRec()->getConformanceWindow();
   UInt   width      = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
   UInt   height     = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
+#endif
   UInt64 poc        = (UInt64)this->getPOC();
   UInt   partWidth  = width / 4;
@@ -853,7 +748,12 @@
   }
 
+#if ILP_DECODED_PICTURE
+  UInt   width       = this->getPicYuvRec()->getWidth();
+  UInt   height      = this->getPicYuvRec()->getHeight();
+#else
   const Window &conf = this->getConformanceWindow();
   UInt   width       = this->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
   UInt   height      = this->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
+#endif
 
   UInt64 poc        = (UInt64)this->getPOC();
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 189)
@@ -103,8 +103,4 @@
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
                         Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
-#if REF_IDX_FRAMEWORK
-  Void          createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps = NULL, Bool bIsVirtual = false );  
-  Void          setPicYuvRec(TComPicYuv *pPicYuv) { m_apcPicYuv[1]=pPicYuv; }
-#endif
 #else
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
@@ -124,15 +120,10 @@
 #endif
 #if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
-  Bool          isILR( UInt refLayer = 0 )   {return (getIsLongTerm() && m_layerId == refLayer);}
+  Bool          isILR( UInt currLayerId )   { return ( getIsLongTerm() && m_layerId < currLayerId ); }
 #endif
 
 #if REF_IDX_MFM
   Void          copyUpsampledMvField  (  TComPic* pcPicBase );
-#if !REUSE_BLKMAPPING
-  Void          deriveUnitIdxBase     (  UInt upsamplePelX, UInt upsamplePelY, UInt ratio, UInt& baseCUAddr, UInt& baseAbsPartIdx );
-#endif
-#if RAP_MFM_INIT
   Void          initUpsampledMvField  ();
-#endif
 #endif
 
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 189)
@@ -60,4 +60,5 @@
   m_piPicOrgU       = NULL;
   m_piPicOrgV       = NULL;
+  
   m_bIsBorderExtended = false;
 }
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 189)
@@ -83,6 +83,6 @@
   if( m_piYuvExt == NULL )
   {
-    Int extWidth  = g_uiMaxCUWidth + 16; 
-    Int extHeight = g_uiMaxCUHeight + 1;
+    Int extWidth  = MAX_CU_SIZE + 16; 
+    Int extHeight = MAX_CU_SIZE + 1;
     Int i, j;
     for (i = 0; i < 4; i++)
@@ -94,18 +94,18 @@
       }
     }
-    m_iYuvExtHeight  = ((g_uiMaxCUHeight + 2) << 4);
-    m_iYuvExtStride = ((g_uiMaxCUWidth  + 8) << 4);
+    m_iYuvExtHeight  = ((MAX_CU_SIZE + 2) << 4);
+    m_iYuvExtStride = ((MAX_CU_SIZE  + 8) << 4);
     m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ];
 
     // new structure
-    m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
-    m_acYuvPred[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight );
-
-    m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight );
-  }
-
-  if (m_iLumaRecStride != (g_uiMaxCUWidth>>1) + 1)
-  {
-    m_iLumaRecStride =  (g_uiMaxCUWidth>>1) + 1;
+    m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE );
+    m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE );
+
+    m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE );
+  }
+
+  if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1)
+  {
+    m_iLumaRecStride =  (MAX_CU_SIZE>>1) + 1;
     if (!m_pLumaRecBuffer)
     {
@@ -495,5 +495,5 @@
 
 #if REF_IDX_ME_ZEROMV
-  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR() && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR() == false );
+  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) == false );
 #endif
 
@@ -773,8 +773,15 @@
 
 #if SVC_UPSAMPLING
+#if SCALED_REF_LAYER_OFFSETS
+Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
+{
+  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic, window);
+}
+#else
 Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
 {
   m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
 }
+#endif
 #endif
 //! \}
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 189)
@@ -122,5 +122,9 @@
 
 #if SVC_UPSAMPLING
+#if SCALED_REF_LAYER_OFFSETS
+  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
   Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+#endif
 #endif
 };
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 189)
@@ -62,5 +62,4 @@
   g_aucConvertToBit[ i ] = c;
   
-  // g_auiFrameScanXY[ g_aucConvertToBit[ transformSize ] ]: zigzag scan array for transformSize
   c=2;
   for ( i=0; i<MAX_CU_DEPTH; i++ )
@@ -77,7 +76,5 @@
 Void destroyROM()
 {
-  Int i;
-  
-  for ( i=0; i<MAX_CU_DEPTH; i++ )
+  for (Int i=0; i<MAX_CU_DEPTH; i++ )
   {
     delete[] g_auiSigLastScan[0][i];
@@ -521,3 +518,8 @@
 Int  g_eTTable[4] = {0,3,1,2};
 
+#if SIMPLIFIED_MV_POS_SCALING
+Int g_mvScalingFactor  [MAX_LAYERS][2] = {{0,0}, {0,0}};
+Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}};
+#endif
+
 //! \}
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 189)
@@ -273,4 +273,10 @@
 extern UInt g_scalingListNum  [SCALING_LIST_SIZE_NUM];
 extern Int  g_eTTable[4];
+
+#if SIMPLIFIED_MV_POS_SCALING
+extern Int g_mvScalingFactor  [MAX_LAYERS][2];
+extern Int g_posScalingFactor [MAX_LAYERS][2];
+#endif
+
 //! \}
 
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 189)
@@ -54,5 +54,5 @@
 , m_iPOC                          ( 0 )
 , m_iLastIDR                      ( 0 )
-, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR )
+, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
 , m_eSliceType                    ( I_SLICE )
 , m_iSliceQp                      ( 0 )
@@ -65,6 +65,8 @@
 , m_deblockingFilterBetaOffsetDiv2 ( 0 )
 , m_deblockingFilterTcOffsetDiv2   ( 0 )
+#if !L0034_COMBINED_LIST_CLEANUP
 , m_bRefPicListModificationFlagLC ( false )
 , m_bRefPicListCombinationFlag    ( false )
+#endif
 , m_bCheckLDC                     ( false )
 , m_iSliceQpDelta                 ( 0 )
@@ -84,5 +86,7 @@
 , m_dLambda                       ( 0.0 )
 #endif
-, m_bNoBackPredFlag               ( false )
+#if !L0034_COMBINED_LIST_CLEANUP
+, m_bNoBackPredFlag             ( false )
+#endif
 , m_uiTLayer                      ( 0 )
 #if SVC_EXTENSION
@@ -113,11 +117,28 @@
 , m_enableTMVPFlag                ( true )
 {
+#if L0034_COMBINED_LIST_CLEANUP
+  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
+#else
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
+#endif
   
-#if REF_LIST_BUGFIX
-  m_aiNumILRRefIdx = 0;
-#endif
+#if REF_IDX_FRAMEWORK
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  m_activeNumILRRefIdx        = 0; 
+  m_interLayerPredEnabledFlag = 0;
+  ::memset( m_interLayerPredLayerIdc, 0, sizeof(m_interLayerPredLayerIdc) );
+#else
+  m_numILRRefIdx = 0;
+#endif 
+#endif
+
   initEqualRef();
   
+#if L0034_COMBINED_LIST_CLEANUP
+  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
+  {
+    m_list1IdxToList0Idx[idx] = -1;
+  }
+#else
   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
   {
@@ -129,4 +150,5 @@
     m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
   }    
+#endif
   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
   {
@@ -136,5 +158,5 @@
     m_aiRefPOCList  [1][iNumCount] = 0;
   }
-  resetWpScaling(m_weightPredTable);
+  resetWpScaling();
   initWpAcDcParam();
   m_saoEnabledFlag = false;
@@ -159,13 +181,12 @@
   m_aiNumRefIdx[0]      = 0;
   m_aiNumRefIdx[1]      = 0;
-#if REF_LIST_BUGFIX
-  if(layerId)
-  {
-    m_aiNumILRRefIdx      = 1;  // to be set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
-  }
-  else
-  {
-    m_aiNumILRRefIdx = 0;
-  }
+#if REF_IDX_FRAMEWORK
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  m_activeNumILRRefIdx        = 0;
+  m_interLayerPredEnabledFlag = 0;
+#else
+  m_numILRRefIdx              = 0;
+#endif  
+
 #endif
   m_colFromL0Flag = 1;
@@ -173,12 +194,16 @@
   m_colRefIdx = 0;
   initEqualRef();
+#if !L0034_COMBINED_LIST_CLEANUP
   m_bNoBackPredFlag = false;
   m_bRefPicListCombinationFlag = false;
   m_bRefPicListModificationFlagLC = false;
+#endif
   m_bCheckLDC = false;
   m_iSliceQpDeltaCb = 0;
   m_iSliceQpDeltaCr = 0;
 
+#if !L0034_COMBINED_LIST_CLEANUP
   m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
+#endif
 
   m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
@@ -194,9 +219,9 @@
 Bool TComSlice::getRapPicFlag()
 {
-  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
+  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
 }
@@ -213,5 +238,5 @@
 }
 
-Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
+Void  TComSlice::sortPicList(TComList<TComPic*>& rcListPic)
 {
   TComPic*    pcPicExtract;
@@ -268,16 +293,30 @@
 
 
-TComPic* TComSlice::xGetLongTermRefPic (TComList<TComPic*>& rcListPic,
-                                        Int                 poc)
+TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
 {
   TComList<TComPic*>::iterator  iterPic = rcListPic.begin();  
   TComPic*                      pcPic = *(iterPic);
   TComPic*                      pcStPic = pcPic;
+  
+  Int pocCycle = 1 << getSPS()->getBitsForPOC();
+  if (!pocHasMsb)
+  {
+    poc = poc % pocCycle;
+  }
+  
   while ( iterPic != rcListPic.end() )
   {
     pcPic = *(iterPic);
-    if(pcPic && (pcPic->getPOC()%(1<<getSPS()->getBitsForPOC())) == (poc%(1<<getSPS()->getBitsForPOC())))
-    {
-      if(pcPic->getIsLongTerm())
+    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
+    {
+      Int picPoc = pcPic->getPOC();
+      if (!pocHasMsb)
+      {
+        picPoc = picPoc % pocCycle;
+      }
+      
+      if (poc == picPoc)
+      {
+       if (pcPic->getIsLongTerm())
       {
         return pcPic;
@@ -289,11 +328,13 @@
       break;
     }
+    }
 
     iterPic++;
   }
+  
   return  pcStPic;
 }
 
-Void TComSlice::setRefPOCList       ()
+Void TComSlice::setRefPOCList()
 {
   for (Int iDir = 0; iDir < 2; iDir++)
@@ -307,4 +348,22 @@
 }
 
+#if L0034_COMBINED_LIST_CLEANUP
+Void TComSlice::setList1IdxToList0Idx()
+{
+  Int idxL0, idxL1;
+  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
+  {
+    m_list1IdxToList0Idx[idxL1] = -1;
+    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
+    {
+      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
+      {
+        m_list1IdxToList0Idx[idxL1] = idxL0;
+        break;
+      }
+    }
+  }
+}
+#else
 Void TComSlice::generateCombinedList()
 {
@@ -369,23 +428,26 @@
   }
 }
-
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic)
-{
-#if REF_IDX_FRAMEWORK
-  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
-      (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
-      (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
-#else
-  if (m_eSliceType == I_SLICE)
-#endif
-  {
-    ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
-    ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-    
-    return;
-  }
+#endif
+
+#if FIX1071
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr, TComPic** ilpPic)
+#else
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
+#endif
+{
+#if FIX1071
+  if (!checkNumPocTotalCurr)
+#endif
+  {
+    if( m_eSliceType == I_SLICE )
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      return;
+    }
   
-  m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-  m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
 
   TComPic*  pcRefPic= NULL;
@@ -398,4 +460,15 @@
   Int i;
 
+#if REF_IDX_FRAMEWORK
+#if ZERO_NUM_DIRECT_LAYERS
+  if( m_layerId == 0 || ( m_layerId > 0 && ( m_activeNumILRRefIdx == 0 || !((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ) ) )
+#else
+  if ((getLayerId() == 0) || 
+      ((getSPS()->getLayerId()) &&  !((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
+       (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) )
+     )
+#endif
+  {
+#endif
   for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
   {
@@ -410,4 +483,5 @@
     }
   }
+  
   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
   {
@@ -422,9 +496,10 @@
     }
   }
+  
   for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
   {
     if(m_pcRPS->getUsed(i))
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
       pcRefPic->setIsLongTerm(1);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -434,15 +509,71 @@
     if(pcRefPic==NULL) 
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
     }
     pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
   }
-
+#if REF_IDX_FRAMEWORK
+  }
+#endif
+
+#if REF_IDX_FRAMEWORK
+  //inter-layer reference picture
+#if REF_IDX_MFM
+#if ZERO_NUM_DIRECT_LAYERS
+  if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
+#else
+  if (getLayerId())
+#endif
+  {
+    if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
+    { 
+      ilpPic[0]->copyUpsampledMvField(getBaseColPic());
+    }
+    else
+    {
+      ilpPic[0]->initUpsampledMvField();
+    }
+  #endif
+    ilpPic[0]->setIsLongTerm(1);
+  }
+#endif
   // ref_pic_list_init
   TComPic*  rpsCurrList0[MAX_NUM_REF+1];
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
+#if REF_IDX_FRAMEWORK
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_activeNumILRRefIdx;
+#else
+  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_numILRRefIdx;
+#endif 
+#else
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
-
-  {
+#endif
+#if FIX1071
+  if (checkNumPocTotalCurr)
+  {
+    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
+    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    if (getRapPicFlag())
+    {
+      assert(numPocTotalCurr == 0);
+    }
+
+    if (m_eSliceType == I_SLICE)
+  {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
+      return;
+    }
+    
+    assert(numPocTotalCurr != 0);
+    
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
+#endif
+  
     Int cIdx = 0;
     for ( i=0; i<NumPocStCurr0; i++, cIdx++)
@@ -458,9 +589,20 @@
       rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
     }
-  }
-
+#if REF_IDX_FRAMEWORK
+    if(getLayerId())
+    {
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+      for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)      
+#else
+      for( i = 0; i < m_numILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)
+#endif 
+      {
+        rpsCurrList0[cIdx] = ilpPic[i];
+      }
+    }
+#endif
   if (m_eSliceType==B_SLICE)
   {
-    Int cIdx = 0;
+    cIdx = 0;
     for ( i=0; i<NumPocStCurr1; i++, cIdx++)
     {
@@ -475,4 +617,17 @@
       rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
     }
+#if REF_IDX_FRAMEWORK
+    if(getLayerId())
+    {
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+      for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)
+#else
+      for( i = 0; i < m_numILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)
+#endif 
+      {
+        rpsCurrList1[cIdx] = ilpPic[i];
+      }
+    }
+#endif
   }
 
@@ -501,5 +656,5 @@
 }
 
-#if REF_LIST_BUGFIX
+#if REF_IDX_FRAMEWORK
 Void TComSlice::setRefPicListModificationSvc()
 {
@@ -509,6 +664,8 @@
   }
 
-  if(this->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && this->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)
+  if(this->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && this->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)
+  {
     return;
+  }
 
   TComRefPicListModification* refPicListModification = this->getRefPicListModification();
@@ -537,5 +694,9 @@
     else
     {
-      for(Int i = m_aiNumILRRefIdx; i > 0; i-- )
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+      for(Int i = m_activeNumILRRefIdx; i > 0; i-- )
+#else
+      for(Int i = m_numILRRefIdx; i > 0; i-- )
+#endif 
       {
         refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfRpsCurrTempList - i);
@@ -563,5 +724,9 @@
     else
     {
-      for(Int i = m_aiNumILRRefIdx; i > 0; i-- )
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+      for(Int i = m_activeNumILRRefIdx; i > 0; i-- )
+#else
+      for(Int i = m_numILRRefIdx; i > 0; i-- )
+#endif 
       {
         refPicListModification->setRefPicSetIdxL1(m_aiNumRefIdx[REF_PIC_LIST_1] - i, numberOfRpsCurrTempList - i);
@@ -569,149 +734,4 @@
     }
   }
-  return;
-}
-
-Void TComSlice::setRefPicListSvc( TComList<TComPic*>& rcListPic, TComPic** ilpPic )
-{
-  assert(getLayerId() > 0);
-
-  m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
-  m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-
-  TComPic*  pcRefPic= NULL;
-  TComPic*  RefPicSetStCurr0[16];
-  TComPic*  RefPicSetStCurr1[16];
-  TComPic*  RefPicSetLtCurr[16];
-  UInt NumPocStCurr0 = 0;
-  UInt NumPocStCurr1 = 0;
-  UInt NumPocLtCurr = 0;
-  Int i;
-
-  //temporal reference pictures
-  if( !(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) )
-  { 
-    for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
-    {
-      if(m_pcRPS->getUsed(i))
-      {
-        pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
-        pcRefPic->setIsLongTerm(0);
-        pcRefPic->getPicYuvRec()->extendPicBorder();
-        RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
-        NumPocStCurr0++;
-        pcRefPic->setCheckLTMSBPresent(false);  
-      }
-    }
-    for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
-    {
-      if(m_pcRPS->getUsed(i))
-      {
-        pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
-        pcRefPic->setIsLongTerm(0);
-        pcRefPic->getPicYuvRec()->extendPicBorder();
-        RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
-        NumPocStCurr1++;
-        pcRefPic->setCheckLTMSBPresent(false);  
-      }
-    }
-    for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
-    {
-      if(m_pcRPS->getUsed(i))
-      {
-        pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
-        pcRefPic->setIsLongTerm(1);
-        pcRefPic->getPicYuvRec()->extendPicBorder();
-        RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
-        NumPocLtCurr++;
-      }
-      if(pcRefPic==NULL) 
-      {
-        pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
-      }
-      pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
-    }
-  }
-
-  //inter-layer reference picture
-#if REF_IDX_MFM
-  assert(m_aiNumILRRefIdx == 1);
-  if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
-  { 
-    ilpPic[0]->copyUpsampledMvField(getBaseColPic());
-  }
-  else
-  {
-    ilpPic[0]->initUpsampledMvField();
-  }
-#endif
-  ilpPic[0]->setIsLongTerm(1);
-
-  // ref_pic_list_init
-  UInt cIdx = 0;
-  UInt num_ref_idx_l0_active_minus1 = m_aiNumRefIdx[0] - 1;
-  UInt num_ref_idx_l1_active_minus1 = m_aiNumRefIdx[1] - 1;
-  TComPic*  refPicListTemp0[MAX_NUM_REF+1];
-  TComPic*  refPicListTemp1[MAX_NUM_REF+1];
-  Int  numRpsCurrTempList0, numRpsCurrTempList1;
-
-  numRpsCurrTempList0 = numRpsCurrTempList1 = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_aiNumILRRefIdx;
-  if (numRpsCurrTempList0 <= num_ref_idx_l0_active_minus1)
-  {
-    numRpsCurrTempList0 = num_ref_idx_l0_active_minus1 + 1;
-  }
-  if (numRpsCurrTempList1 <= num_ref_idx_l1_active_minus1)
-  {
-    numRpsCurrTempList1 = num_ref_idx_l1_active_minus1 + 1;
-  }
-
-  assert(numRpsCurrTempList0 <= MAX_NUM_REF);
-  assert(numRpsCurrTempList1 <= MAX_NUM_REF);
-
-  cIdx = 0;
-  while (cIdx < numRpsCurrTempList0)
-  { 
-    for ( i=0; i<NumPocStCurr0 && cIdx<numRpsCurrTempList0; cIdx++,i++) 
-      refPicListTemp0[cIdx] = RefPicSetStCurr0[ i ];   
-    for ( i=0; i<NumPocStCurr1 && cIdx<numRpsCurrTempList0; cIdx++,i++) 
-      refPicListTemp0[cIdx] = RefPicSetStCurr1[ i ]; 
-    for ( i=0; i<NumPocLtCurr && cIdx<numRpsCurrTempList0; cIdx++,i++) 
-      refPicListTemp0[cIdx] = RefPicSetLtCurr[ i ];
-    for ( i=0; i<m_aiNumILRRefIdx && cIdx<numRpsCurrTempList0; cIdx++,i++)
-      refPicListTemp0[cIdx] = ilpPic[ i ];
-  }
-  cIdx = 0;
-  while (cIdx<numRpsCurrTempList1 && m_eSliceType==B_SLICE)
-  { 
-    for ( i=0; i<NumPocStCurr1 && cIdx<numRpsCurrTempList1; cIdx++,i++) 
-      refPicListTemp1[cIdx] = RefPicSetStCurr1[ i ];
-    for ( i=0; i<NumPocStCurr0 && cIdx<numRpsCurrTempList1; cIdx++,i++) 
-      refPicListTemp1[cIdx] = RefPicSetStCurr0[ i ]; 
-    for ( i=0; i<NumPocLtCurr && cIdx<numRpsCurrTempList1; cIdx++,i++) 
-      refPicListTemp1[cIdx] = RefPicSetLtCurr[ i ];
-    for ( i=0; i<m_aiNumILRRefIdx && cIdx<numRpsCurrTempList1; cIdx++,i++)
-      refPicListTemp1[cIdx] = ilpPic[ i ];
-  }
-  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
-  for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++)
-  {
-    m_apcRefPicList[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(rIdx) ] : refPicListTemp0[rIdx % numRpsCurrTempList0];
-    m_bIsUsedAsLongTerm[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? (m_RefPicListModification.getRefPicSetIdxL0(rIdx) >= (NumPocStCurr0 + NumPocStCurr1))
-      : ((rIdx % numRpsCurrTempList0) >= (NumPocStCurr0 + NumPocStCurr1));
-  }
-  if ( m_eSliceType == P_SLICE )
-  {
-    m_aiNumRefIdx[1] = 0;
-    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
-  }
-  else
-  {
-    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[1]-1); rIdx ++)
-    {
-      m_apcRefPicList[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(rIdx) ] : refPicListTemp1[rIdx % numRpsCurrTempList1];
-      m_bIsUsedAsLongTerm[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ?
-        (m_RefPicListModification.getRefPicSetIdxL1(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)): ((rIdx % numRpsCurrTempList1) >= (NumPocStCurr0 + NumPocStCurr1));
-    }
-  }
-
   return;
 }
@@ -724,5 +744,5 @@
 #if REF_IDX_FRAMEWORK
   if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
-    (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
+    (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
     (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
 #else
@@ -730,6 +750,10 @@
 #endif 
   {
-#if REF_LIST_BUGFIX
-    return m_aiNumILRRefIdx;
+#if REF_IDX_FRAMEWORK
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+    return m_activeNumILRRefIdx;
+#else
+    return getNumILRRefIdx();
+#endif 
 #else
     return 0;
@@ -743,8 +767,12 @@
     }
   }
-#if REF_LIST_BUGFIX
+#if REF_IDX_FRAMEWORK
   if(getLayerId())
   {
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+    numRpsCurrTempList += m_activeNumILRRefIdx;
+#else
     numRpsCurrTempList += getNumILRRefIdx();
+#endif
   }
 #endif
@@ -793,5 +821,5 @@
 }
 
-Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA)
+Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
 {
   for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
@@ -806,8 +834,15 @@
     if(pocCRA < MAX_UINT && getPOC() > pocCRA)
     {
+      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
+      {
+        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
+      }
+      else
+      {
       assert(pReferencePictureSet->getPOC(i) >= pocCRA);
     }
   }
-  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
+  }
+  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
   {
     pocCRA = getPOC();
@@ -819,6 +854,6 @@
     prevRAPisBLA = false;
   }
-  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
+  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
          || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
   {
@@ -851,8 +886,8 @@
   Int pocCurr = getPOC(); 
 
-  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
+  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
-    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
   {
@@ -866,6 +901,6 @@
       iterPic++;
     }
-    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
-      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
+    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
     {
@@ -881,5 +916,8 @@
       {
         rpcPic = *(iterPic);
-        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) rpcPic->getSlice(0)->setReferenced(false);
+        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
+        {
+          rpcPic->getSlice(0)->setReferenced(false);
+        }
         iterPic++;
       }
@@ -912,9 +950,19 @@
   m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
   
+#if L0034_COMBINED_LIST_CLEANUP
+  for (i = 0; i < 2; i++)
+#else
   for (i = 0; i < 3; i++)
+#endif
   {
     m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
   }
 
+#if L0034_COMBINED_LIST_CLEANUP
+  for (i = 0; i < MAX_NUM_REF; i++)
+  {
+    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
+  } 
+#else
   for (i = 0; i < 2; i++)
   {
@@ -933,4 +981,5 @@
   m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
   m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
+#endif
   m_bCheckLDC             = pSrc->m_bCheckLDC;
   m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
@@ -958,4 +1007,15 @@
 
   // access channel
+#if SVC_EXTENSION
+  m_pcVPS                = pSrc->m_pcVPS;
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  m_activeNumILRRefIdx         = pSrc->m_activeNumILRRefIdx;
+  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
+  m_numInterLayerRefPics       = pSrc->m_numInterLayerRefPics;
+  memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
+#elif REF_IDX_FRAMEWORK
+  m_numILRRefIdx               = pSrc->m_numILRRefIdx;
+#endif
+#endif
   m_pcSPS                = pSrc->m_pcSPS;
   m_pcPPS                = pSrc->m_pcPPS;
@@ -984,5 +1044,7 @@
   }
 
+#if !L0034_COMBINED_LIST_CLEANUP
   m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
+#endif
   m_uiTLayer                      = pSrc->m_uiTLayer;
   m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
@@ -1018,4 +1080,5 @@
 
 Int TComSlice::m_prevPOC = 0;
+
 /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
  * \param uiTLayer Temporal layer ID of the current slice
@@ -1078,11 +1141,14 @@
   Int i, isReference;
 
-  Int j = 0;
   // loop through all pictures in the reference picture buffer
   TComList<TComPic*>::iterator iterPic = rcListPic.begin();
   while ( iterPic != rcListPic.end())
   {
-    j++;
     rpcPic = *(iterPic++);
+
+    if(!rpcPic->getSlice( 0 )->isReferenced())
+    {
+      continue;
+    }
 
     isReference = 0;
@@ -1123,4 +1189,5 @@
     {            
       rpcPic->getSlice( 0 )->setReferenced( false );   
+      rpcPic->setUsedByCurr(0);
       rpcPic->setIsLongTerm(0);
     }
@@ -1128,5 +1195,5 @@
     assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
     //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
-    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
+    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     {
       assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
@@ -1145,5 +1212,5 @@
 {
   TComPic* rpcPic;
-  Int i, isAvailable, j;
+  Int i, isAvailable;
   Int atLeastOneLost = 0;
   Int atLeastOneRemoved = 0;
@@ -1154,5 +1221,4 @@
   for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
   {
-    j = 0;
     isAvailable = 0;
     // loop through all pictures in the reference picture buffer
@@ -1160,5 +1226,4 @@
     while ( iterPic != rcListPic.end())
     {
-      j++;
       rpcPic = *(iterPic++);
       if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
@@ -1183,8 +1248,16 @@
       while ( iterPic != rcListPic.end())
       {
-        j++;
         rpcPic = *(iterPic++);
 
-        if((rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == (this->getPOC() + pReferencePictureSet->getDeltaPOC(i))%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
+        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
+        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
+        Int refPoc = pReferencePictureSet->getPOC(i);
+        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
+        {
+          curPoc = curPoc % pocCycle;
+          refPoc = refPoc % pocCycle;
+        }
+        
+        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
         {
           isAvailable = 1;
@@ -1224,5 +1297,4 @@
   for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
   {
-    j = 0;
     isAvailable = 0;
     // loop through all pictures in the reference picture buffer
@@ -1230,5 +1302,4 @@
     while ( iterPic != rcListPic.end())
     {
-      j++;
       rpcPic = *(iterPic++);
 
@@ -1247,5 +1318,7 @@
         {
           if(printErrors)
+          {
             printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
+          }
           atLeastOneRemoved = 1;
         }
@@ -1253,5 +1326,7 @@
         {
           if(printErrors)
+          {
             printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
+          }
           atLeastOneLost = 1;
           iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
@@ -1399,5 +1474,5 @@
  * \returns Void
  */
-Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
+Void  TComSlice::resetWpScaling()
 {
   for ( Int e=0 ; e<2 ; e++ )
@@ -1407,5 +1482,5 @@
       for ( Int yuv=0 ; yuv<3 ; yuv++ )
       {
-        wpScalingParam  *pwp = &(wp[e][i][yuv]);
+        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
         pwp->bPresentFlag      = false;
         pwp->uiLog2WeightDenom = 0;
@@ -1423,13 +1498,4 @@
 Void  TComSlice::initWpScaling()
 {
-  initWpScaling(m_weightPredTable);
-}
-
-/** set WP tables 
- * \param wpScalingParam
- * \returns Void
- */
-Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
-{
   for ( Int e=0 ; e<2 ; e++ )
   {
@@ -1438,6 +1504,7 @@
       for ( Int yuv=0 ; yuv<3 ; yuv++ )
       {
-        wpScalingParam  *pwp = &(wp[e][i][yuv]);
-        if ( !pwp->bPresentFlag ) {
+        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
+        if ( !pwp->bPresentFlag ) 
+        {
           // Inferring values not present :
           pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
@@ -1477,10 +1544,19 @@
 , m_numOutputLayerSets        (0)  
 #endif
-{
-
+#if VPS_PROFILE_OUTPUT_LAYERS
+, m_numProfileTierLevel       (0)
+, m_moreOutputLayerSetsThanDefaultFlag (false)
+, m_numAddOutputLayerSets     (0)
+, m_defaultOneTargetOutputLayerFlag    (false)
+#endif
+{
   for( Int i = 0; i < MAX_TLAYER; i++)
   {
     m_numReorderPics[i] = 0;
+#if L0323_DPB
+    m_uiMaxDecPicBuffering[i] = 1; 
+#else
     m_uiMaxDecPicBuffering[i] = 0; 
+#endif
     m_uiMaxLatencyIncrease[i] = 0;
   }
@@ -1512,13 +1588,46 @@
   ::memset(m_refLayerId,           0, sizeof(m_refLayerId          ));
 #endif
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  ::memset(m_layerSetLayerIdList,  0, sizeof(m_layerSetLayerIdList));
+  ::memset(m_numLayerInIdList,     0, sizeof(m_numLayerInIdList   )); 
+#endif
+#if VPS_PROFILE_OUTPUT_LAYERS
+  ::memset(m_profileLevelTierIdx,  0, sizeof(m_profileLevelTierIdx));
+#endif
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  m_maxOneActiveRefLayerFlag = true;
+#endif
 }
 
 TComVPS::~TComVPS()
 {
-  if( m_hrdParameters    != NULL )     delete m_hrdParameters;
-  if( m_hrdOpSetIdx      != NULL )     delete m_hrdOpSetIdx;
-  if( m_cprmsPresentFlag != NULL )     delete m_cprmsPresentFlag;
-}
-
+  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
+  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
+  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
+}
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+Void TComVPS::deriveLayerIdListVariables()
+{
+  // For layer 0
+  setNumLayersInIdList(0, 1);
+  setLayerSetLayerIdList(0, 0, 0);
+
+  // For other layers
+  Int i, m, n;
+  for( i = 1; i <= getNumLayerSets() - 1; i++ )
+  {
+    n = 0;
+    for( m = 0; m <= this->getMaxLayerId(); m++)
+    {
+      if(this->getLayerIdIncludedFlag(i, m))
+      {
+        setLayerSetLayerIdList(i, n, m);
+        n++;
+      }
+    }
+    setNumLayersInIdList(i, n);
+  }
+}
+#endif
 // ------------------------------------------------------------------------------------------------
 // Sequence parameter set (SPS)
@@ -1533,9 +1642,9 @@
 , m_picWidthInLumaSamples     (352)
 , m_picHeightInLumaSamples    (288)
+, m_log2MinCodingBlockSize    (  0)
+, m_log2DiffMaxMinCodingBlockSize (0)
 , m_uiMaxCUWidth              ( 32)
 , m_uiMaxCUHeight             ( 32)
 , m_uiMaxCUDepth              (  3)
-, m_uiMinTrDepth              (  0)
-, m_uiMaxTrDepth              (  1)
 , m_bLongTermRefsPresent      (false)
 , m_uiQuadtreeTULog2MaxSize   (  0)
@@ -1547,5 +1656,7 @@
 , m_pcmLog2MaxSize            (  5)
 , m_uiPCMLog2MinSize          (  7)
+#if !L0034_COMBINED_LIST_CLEANUP
 , m_bUseLComb                 (false)
+#endif
 , m_bitDepthY                 (  8)
 , m_bitDepthC                 (  8)
@@ -1572,5 +1683,9 @@
   {
     m_uiMaxLatencyIncrease[i] = 0;
+#if L0323_DPB
+    m_uiMaxDecPicBuffering[i] = 1;
+#else
     m_uiMaxDecPicBuffering[i] = 0;
+#endif
     m_numReorderPics[i]       = 0;
   }
@@ -1591,4 +1706,5 @@
   m_RPSList.create(numRPS);
 }
+
 Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
 {
@@ -1835,12 +1951,15 @@
   return m_POC[bufferNum];
 }
+
 Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
 {
   m_POC[bufferNum] = POC;
 }
+
 Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
 {
   return m_bCheckLTMSB[bufferNum];
 }
+
 Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
 {
@@ -2022,4 +2141,5 @@
   return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
 }
+
 /** get scaling matrix from RefMatrixID
  * \param sizeId size index
@@ -2031,4 +2151,5 @@
   ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
 }
+
 /** parse syntax infomation 
  *  \param pchFile syntax infomation
@@ -2123,4 +2244,5 @@
   m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
 }
+
 /** destroy quantization matrix array
  */
@@ -2135,4 +2257,5 @@
   }
 }
+
 /** get default address of quantization matrix 
  * \param sizeId size index
@@ -2164,4 +2287,5 @@
   return src;
 }
+
 /** process of default matrix
  * \param sizeId size index
@@ -2173,4 +2297,5 @@
   setScalingListDC(sizeId,listId,SCALING_LIST_DC);
 }
+
 /** check DC value of matrix for default matrix signaling
  */
@@ -2240,5 +2365,5 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
-Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
 {
   TComPPS *pps = m_ppsMap.getPS(ppsId);
@@ -2246,7 +2371,7 @@
   {
     Int spsId = pps->getSPSId();
-    if (!isIDR && (spsId != m_activeSPSId))
-    {
-      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
+    if (!isIRAP && (spsId != m_activeSPSId))
+    {
+      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
       return false;
     }
@@ -2255,7 +2380,7 @@
     {
       Int vpsId = sps->getVPSId();
-      if (!isIDR && (vpsId != m_activeVPSId))
-      {
-        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IDR.");
+      if (!isIRAP && (vpsId != m_activeVPSId))
+      {
+        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
         return false;
       }
@@ -2345,5 +2470,5 @@
 // Assumed that RPL of the base layer is same to the EL, otherwise this information should be also dumped and read from the metadata file
   setPOC( pcSlice->getPOC() );
-  if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
+  if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
   {
     setSliceType( I_SLICE );
@@ -2395,54 +2520,4 @@
 #endif 
 
-#if REF_IDX_FRAMEWORK
-Void TComSlice::addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset )
-{
-  if(getSPS()->getLayerId() && m_eSliceType != I_SLICE)
-  {
-#if REF_IDX_MFM
-    assert(iRefPicNum == 1);
-#if RAP_MFM_INIT
-    if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
-#else
-    if( getPOC() != 0 )
-#endif
-    { 
-      pIlpPicList[0]->copyUpsampledMvField(getBaseColPic());
-    }
-#if RAP_MFM_INIT
-    else
-    {
-      pIlpPicList[0]->initUpsampledMvField();
-    }
-#endif
-#endif
-    //add to list 0;
-    Int iOffset;
-    m_aiNumRefIdx[REF_PIC_LIST_0] += iInsertOffset;
-    iOffset = m_aiNumRefIdx[REF_PIC_LIST_0];
-    for (Int i=0; i<iRefPicNum; i++)
-    {
-      pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
-      m_bIsUsedAsLongTerm[REF_PIC_LIST_0][iOffset + i] = 1; //mark ilp as long-term reference
-      m_apcRefPicList[REF_PIC_LIST_0][iOffset + i] = pIlpPicList[i]; 
-      m_aiNumRefIdx[REF_PIC_LIST_0]++;
-      //m_aiNumRefIdx[REF_PIC_LIST_C]++;
-    }
-    if(m_eSliceType == B_SLICE)
-    {
-      m_aiNumRefIdx[REF_PIC_LIST_1] += iInsertOffset;
-      iOffset = m_aiNumRefIdx[REF_PIC_LIST_1];
-      for (Int i=0; i<iRefPicNum; i++)
-      {
-        pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
-        m_bIsUsedAsLongTerm[REF_PIC_LIST_1][iOffset + i] = 1; //mark ilp as long-term reference
-        m_apcRefPicList[REF_PIC_LIST_1][iOffset + i] = pIlpPicList[i]; 
-        m_aiNumRefIdx[REF_PIC_LIST_1]++;
-        //m_aiNumRefIdx[REF_PIC_LIST_C]++;
-      }
-    }
-  }
-}
-
 #if REF_IDX_MFM
 Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic *pcRefPicBL )
@@ -2453,7 +2528,5 @@
   assert(thePoc == pcRefPicBL->getPOC());
 
-#if REUSE_MVSCALE || REUSE_BLKMAPPING
   ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
-#endif
 
   //copy reference pictures marking from the reference layer
@@ -2486,5 +2559,3 @@
 #endif
 
-
-#endif
 //! \}
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 189)
@@ -504,5 +504,8 @@
   Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
 #endif
-
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
   TComPTL     m_pcPTL;
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
@@ -547,5 +550,14 @@
   UInt       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
 #endif
-
+#if VPS_PROFILE_OUTPUT_LAYERS
+  UInt       m_numProfileTierLevel;
+  Bool       m_moreOutputLayerSetsThanDefaultFlag;
+  Int        m_numAddOutputLayerSets;
+  Bool       m_defaultOneTargetOutputLayerFlag;
+  Int        m_profileLevelTierIdx[64];     
+#endif
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Bool       m_maxOneActiveRefLayerFlag;
+#endif
 public:
   TComVPS();
@@ -604,5 +616,13 @@
   Bool    getLayerIdIncludedFlag(UInt opsIdx, UInt id)          { return m_layerIdIncludedFlag[opsIdx][id]; }
   Void    setLayerIdIncludedFlag(Bool v, UInt opsIdx, UInt id)  { m_layerIdIncludedFlag[opsIdx][id] = v;    }
-
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  Int     getLayerSetLayerIdList(Int set, Int layerId)          { return m_layerSetLayerIdList[set][layerId]; }
+  Void    setLayerSetLayerIdList(Int set, Int layerId, Int x)   { m_layerSetLayerIdList[set][layerId] = x   ; }
+
+  Int     getNumLayersInIdList(Int set)                          { return m_numLayerInIdList[set]; }
+  Void    setNumLayersInIdList(Int set, Int x)                   { m_numLayerInIdList[set] = x   ; }
+
+  Void    deriveLayerIdListVariables();
+#endif
   TComPTL* getPTL() { return &m_pcPTL; }
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
@@ -663,13 +683,33 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct dependency of layers
-  Bool   getDirectDependencyFlag(Int i, Int j)                  { return m_directDependencyFlag[i][j]; }
-  Void   setDirectDependencyFlag(Int i, Int j, Bool x)          { m_directDependencyFlag[i][j] = x;    }
-  
-  UInt   getNumDirectRefLayers(Int i)                                { return m_numDirectRefLayers[i];         }
-  Void   setNumDirectRefLayers(Int i, UInt x)                        { m_numDirectRefLayers[i] = x;            }
-
-  UInt   getRefLayerId(Int i, Int j)                            { return m_refLayerId[i][j];           }
-  Void   setRefLayerId(Int i, Int j, UInt x)                    { m_refLayerId[i][j] = x;              }
-#endif
+  Bool   getDirectDependencyFlag(Int currLayerId, Int refLayerId)               { return m_directDependencyFlag[currLayerId][refLayerId]; }
+  Void   setDirectDependencyFlag(Int currLayerId, Int refLayerId, Bool x)       { m_directDependencyFlag[currLayerId][refLayerId] = x;    }
+  
+  UInt   getNumDirectRefLayers(Int layerId)                                     { return m_numDirectRefLayers[layerId];                   }
+  Void   setNumDirectRefLayers(Int layerId, UInt refLayerNum)                   { m_numDirectRefLayers[layerId] = refLayerNum;            }
+
+  UInt   getRefLayerId(Int layerId, Int refLayerIdx)                            { return m_refLayerId[layerId][refLayerIdx];              }
+  Void   setRefLayerId(Int layerId, Int refLayerIdx, UInt refLayerId)           { m_refLayerId[layerId][refLayerIdx] = refLayerId;        }
+#endif
+#if VPS_PROFILE_OUTPUT_LAYERS
+  UInt   getNumProfileTierLevel()                                { return m_numProfileTierLevel; }
+  Void   setNumProfileTierLevel(Int x)                           { m_numProfileTierLevel = x;    }
+
+  Bool   getMoreOutputLayerSetsThanDefaultFlag()                 { return m_moreOutputLayerSetsThanDefaultFlag;}
+  Void   setMoreOutputLayerSetsThanDefaultFlag(Bool x)           { m_moreOutputLayerSetsThanDefaultFlag = x   ;}
+
+  Int    getNumAddOutputLayerSets()                              { return m_numAddOutputLayerSets; }
+  Void   setNumAddOutputLayerSets(Int x)                         { m_numAddOutputLayerSets = x   ; }
+
+  Bool   getDefaultOneTargetOutputLayerFlag()                 { return m_defaultOneTargetOutputLayerFlag;}
+  Void   setDefaultOneTargetOutputLayerFlag(Bool x)           { m_defaultOneTargetOutputLayerFlag= x    ;}
+
+  Int    getProfileLevelTierIdx(Int i)                        { return m_profileLevelTierIdx[i]; }
+  Void   setProfileLevelTierIdx(Int i, Int x)                 { m_profileLevelTierIdx[i] = x   ; }
+#endif
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Bool   getMaxOneActiveRefLayerFlag()                                          { return m_maxOneActiveRefLayerFlag;                      }
+  Void   setMaxOneActiveRefLayerFlag(Bool x)                                    { m_maxOneActiveRefLayerFlag = x;                         }
+#endif 
 };
 
@@ -908,11 +948,12 @@
   UInt        m_picHeightInLumaSamples;
   
-  Window      m_conformanceWindow;
-
+  Int         m_log2MinCodingBlockSize;
+  Int         m_log2DiffMaxMinCodingBlockSize;
   UInt        m_uiMaxCUWidth;
   UInt        m_uiMaxCUHeight;
   UInt        m_uiMaxCUDepth;
-  UInt        m_uiMinTrDepth;
-  UInt        m_uiMaxTrDepth;
+
+  Window      m_conformanceWindow;
+
   TComRPSList m_RPSList;
   Bool        m_bLongTermRefsPresent;
@@ -930,5 +971,7 @@
   Bool        m_useAMP;
 
+#if !L0034_COMBINED_LIST_CLEANUP
   Bool        m_bUseLComb;
+#endif
   
   // Parameter
@@ -978,4 +1021,7 @@
   Bool m_bMFMEnabledFlag;
 #endif
+#if SCALED_REF_LAYER_OFFSETS
+  Window      m_scaledRefLayerWindow;
+#endif
 public:
   TComSPS();
@@ -1009,4 +1055,10 @@
   Bool getUsedByCurrPicLtSPSFlag(Int i)        {return m_usedByCurrPicLtSPSFlag[i];}
   Void setUsedByCurrPicLtSPSFlag(Int i, Bool x)      { m_usedByCurrPicLtSPSFlag[i] = x;}
+
+  Int  getLog2MinCodingBlockSize() const           { return m_log2MinCodingBlockSize; }
+  Void setLog2MinCodingBlockSize(Int val)          { m_log2MinCodingBlockSize = val; }
+  Int  getLog2DiffMaxMinCodingBlockSize() const    { return m_log2DiffMaxMinCodingBlockSize; }
+  Void setLog2DiffMaxMinCodingBlockSize(Int val)   { m_log2DiffMaxMinCodingBlockSize = val; }
+
   Void setMaxCUWidth  ( UInt u ) { m_uiMaxCUWidth = u;      }
   UInt getMaxCUWidth  ()         { return  m_uiMaxCUWidth;  }
@@ -1025,8 +1077,4 @@
   Bool getUseAMP() { return m_useAMP; }
   Void setUseAMP( Bool b ) { m_useAMP = b; }
-  Void setMinTrDepth  ( UInt u ) { m_uiMinTrDepth = u;      }
-  UInt getMinTrDepth  ()         { return  m_uiMinTrDepth;  }
-  Void setMaxTrDepth  ( UInt u ) { m_uiMaxTrDepth = u;      }
-  UInt getMaxTrDepth  ()         { return  m_uiMaxTrDepth;  }
   Void setQuadtreeTULog2MaxSize( UInt u ) { m_uiQuadtreeTULog2MaxSize = u;    }
   UInt getQuadtreeTULog2MaxSize()         { return m_uiQuadtreeTULog2MaxSize; }
@@ -1050,6 +1098,8 @@
   
   // Tool list
+#if !L0034_COMBINED_LIST_CLEANUP
   Void setUseLComb    (Bool b)   { m_bUseLComb = b;         }
   Bool getUseLComb    ()         { return m_bUseLComb;      }
+#endif
 
   Bool getUseLossless ()         { return m_useLossless; }
@@ -1112,4 +1162,7 @@
   Void     setMFMEnabledFlag(Bool flag) {m_bMFMEnabledFlag = flag;}
   Bool     getMFMEnabledFlag()          {return m_bMFMEnabledFlag;}
+#endif
+#if SCALED_REF_LAYER_OFFSETS
+  Window&  getScaledRefLayerWindow(     )   { return m_scaledRefLayerWindow; }
 #endif
 };
@@ -1370,11 +1423,17 @@
   Int         m_deblockingFilterBetaOffsetDiv2;    //< beta offset for deblocking filter
   Int         m_deblockingFilterTcOffsetDiv2;      //< tc offset for deblocking filter
-  
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
+  Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
+#else
+#if REF_IDX_FRAMEWORK
+  Int         m_numILRRefIdx;       //< for inter-layer reference picture ser
+#endif
+#endif 
+#if L0034_COMBINED_LIST_CLEANUP
+  Int         m_list1IdxToList0Idx[MAX_NUM_REF];
+  Int         m_aiNumRefIdx   [2];    //  for multiple reference of current slice
+#else
   Int         m_aiNumRefIdx   [3];    //  for multiple reference of current slice
-
-#if REF_LIST_BUGFIX
-  Int         m_aiNumILRRefIdx;       //< for inter-layer reference picture ser
-#endif
-
   Int         m_iRefIdxOfLC[2][MAX_NUM_REF_LC];
   Int         m_eListIdFromIdxOfLC[MAX_NUM_REF_LC];
@@ -1384,4 +1443,5 @@
   Bool        m_bRefPicListModificationFlagLC;
   Bool        m_bRefPicListCombinationFlag;
+#endif
 
   Bool        m_bCheckLDC;
@@ -1421,6 +1481,7 @@
 
   Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
-  
+#if !L0034_COMBINED_LIST_CLEANUP
   Bool        m_bNoBackPredFlag;
+#endif
   UInt        m_uiTLayer;
 #if SVC_EXTENSION
@@ -1462,4 +1523,8 @@
 
   Bool       m_enableTMVPFlag;
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Bool       m_interLayerPredEnabledFlag;
+  Int        m_numInterLayerRefPics;
+#endif 
 public:
   TComSlice();
@@ -1517,8 +1582,5 @@
   Int       getDeblockingFilterBetaOffsetDiv2()         { return  m_deblockingFilterBetaOffsetDiv2; }
   Int       getDeblockingFilterTcOffsetDiv2()           { return  m_deblockingFilterTcOffsetDiv2; }
-#if REF_LIST_BUGFIX
-  Int       getNumILRRefIdx     ( )                     { return  m_aiNumILRRefIdx; }
-  Void      setNumILRRefIdx     ( Int i )                     { m_aiNumILRRefIdx = i; }
-#endif
+
   Int       getNumRefIdx        ( RefPicList e )                { return  m_aiNumRefIdx[e];             }
   TComPic*  getPic              ()                              { return  m_pcPic;                      }
@@ -1533,4 +1595,7 @@
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
   Int       getNumRpsCurrTempList();
+#if L0034_COMBINED_LIST_CLEANUP
+  Int       getList1IdxToList0Idx ( Int list1Idx )               { return m_list1IdxToList0Idx[list1Idx]; }
+#else
   Int       getRefIdxOfLC       (RefPicList e, Int iRefIdx)     { return m_iRefIdxOfLC[e][iRefIdx];           }
   Int       getListIdFromIdxOfLC(Int iRefIdx)                   { return m_eListIdFromIdxOfLC[iRefIdx];       }
@@ -1542,12 +1607,14 @@
   Bool      getRefPicListCombinationFlag()                      {return m_bRefPicListCombinationFlag;}
   Void      setRefPicListCombinationFlag(Bool bflag)            {m_bRefPicListCombinationFlag=bflag;}   
+#endif
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
   Bool      isReferenced()                                      { return m_bRefenced; }
   Void      setPOC              ( Int i )                       { m_iPOC              = i; if(getTLayer()==0) m_prevPOC=i; }
   Void      setNalUnitType      ( NalUnitType e )               { m_eNalUnitType      = e;      }
-  NalUnitType getNalUnitType    ()                              { return m_eNalUnitType;        }
+  NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
-  Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
-  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA);
+  Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
+  Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
+  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
   Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
@@ -1569,26 +1636,10 @@
   Void      setPic              ( TComPic* p )                  { m_pcPic             = p;      }
   Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
-  
-#if SVC_EXTENSION  
-  Void      setBaseColPic       ( TComPic* p)                   { m_pcBaseColPic = p; }
-  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
-  TComPic*  getBaseColPic       ()  { return m_pcBaseColPic; }
-
-  Void      setLayerId (UInt layerId) { m_layerId = layerId; }
-  UInt      getLayerId ()               { return m_layerId; }
-
-  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
-  TComPicYuv* getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
-
-#if AVC_SYNTAX
-  Void      initBaseLayerRPL( TComSlice *pcSlice );
-#endif
-#endif
-
-#if REF_IDX_MFM
-  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
-#endif
-
+
+#if FIX1071
+  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL );
+#else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
+#endif
   Void      setRefPOCList       ();
   Void      setColFromL0Flag    ( UInt colFromL0 ) { m_colFromL0Flag = colFromL0; }
@@ -1596,9 +1647,4 @@
   Void      setCheckLDC         ( Bool b )                      { m_bCheckLDC = b; }
   Void      setMvdL1ZeroFlag     ( Bool b)                       { m_bLMvdL1Zero = b; }
-
-#if REF_LIST_BUGFIX
-  Void      setRefPicListModificationSvc();
-  Void      setRefPicListSvc    ( TComList<TComPic*>& rcListPic, TComPic** ilpPic );
-#endif
 
   Bool      isIntra         ()                          { return  m_eSliceType == I_SLICE;  }
@@ -1628,8 +1674,11 @@
   
   static Void      sortPicList         ( TComList<TComPic*>& rcListPic );
-  
+#if L0034_COMBINED_LIST_CLEANUP
+  Void setList1IdxToList0Idx();
+#else
   Bool getNoBackPredFlag() { return m_bNoBackPredFlag; }
   Void setNoBackPredFlag( Bool b ) { m_bNoBackPredFlag = b; }
   Void generateCombinedList       ();
+#endif
 
   UInt getTLayer             ()                            { return m_uiTLayer;                      }
@@ -1679,6 +1728,5 @@
   Void  getWpScaling    ( RefPicList e, Int iRefIdx, wpScalingParam *&wp);
 
-  Void  resetWpScaling  (wpScalingParam  wp[2][MAX_NUM_REF][3]);
-  Void  initWpScaling    (wpScalingParam  wp[2][MAX_NUM_REF][3]);
+  Void  resetWpScaling  ();
   Void  initWpScaling   ();
   inline Bool applyWP   () { return( (m_eSliceType==P_SLICE && m_pcPPS->getUseWP()) || (m_eSliceType==B_SLICE && m_pcPPS->getWPBiPred()) ); }
@@ -1714,12 +1762,51 @@
   Void      setEnableTMVPFlag     ( Bool   b )    { m_enableTMVPFlag = b; }
   Bool      getEnableTMVPFlag     ()              { return m_enableTMVPFlag;}
+
+#if SVC_EXTENSION
+  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
+  Void      setBaseColPic       ( TComPic* p)     { m_pcBaseColPic = p; }
+  TComPic*  getBaseColPic       ()                { return m_pcBaseColPic; }
+
+  Void      setLayerId (UInt layerId)   { m_layerId = layerId; }
+  UInt      getLayerId ()               { return m_layerId;    }
+
+  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
+  TComPicYuv* getFullPelBaseRec   ()               { return  m_pcFullPelBaseRec;  }
+
+#if AVC_SYNTAX
+  Void      initBaseLayerRPL( TComSlice *pcSlice );
+#endif
+
 #if REF_IDX_FRAMEWORK
-  Void      addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset=0 );
-#endif
+  Void      setRefPicListModificationSvc();
+  Int       getNumILRRefIdx     ( )                     { return  m_pcVPS->getNumDirectRefLayers( m_layerId ); }
+
+#if REF_IDX_MFM
+  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
+#endif
+
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+  Int       getActiveNumILRRefIdx     ( )               { return  m_activeNumILRRefIdx; }
+  Void      setActiveNumILRRefIdx     ( Int i )         { m_activeNumILRRefIdx = i;     }  
+
+  Int       getInterLayerPredLayerIdc (UInt Idx )               { return  m_interLayerPredLayerIdc[Idx];}
+  Void      setInterLayerPredLayerIdc (UInt val, UInt Idx)      { m_interLayerPredLayerIdc[Idx] = val;  }
+
+  Void      setInterLayerPredEnabledFlag     ( Bool   val )    { m_interLayerPredEnabledFlag = val; }
+  Bool      getInterLayerPredEnabledFlag     ()                { return m_interLayerPredEnabledFlag;}
+
+  Void      setNumInterLayerRefPics          ( UInt   val )    { m_numInterLayerRefPics = val; }
+  UInt      getNumInterLayerRefPics          ()                { return m_numInterLayerRefPics;}  
+#else
+  Void      setNumILRRefIdx     ( Int i )               { m_numILRRefIdx = i;     }
+#endif 
+#endif
+
+#endif //SVC_EXTENSION
+
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
                          Int                 poc);
-  TComPic*  xGetLongTermRefPic  (TComList<TComPic*>& rcListPic,
-                         Int                 poc);
+  TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
 };// END CLASS DEFINITION TComSlice
 
@@ -1805,5 +1892,5 @@
   //! activate a PPS and depending on isIDR parameter also SPS and VPS
   //! \returns true, if activation is successful
-  Bool activatePPS(Int ppsId, Bool isIDR);
+  Bool activatePPS(Int ppsId, Bool isIRAP);
 
   TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
Index: trunk/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 189)
@@ -2007,5 +2007,5 @@
           }
           
-          if(piQCoef[minPos] == 32767 || piQCoef[minPos] == -32768)
+          if(piDstCoeff[minPos] == 32767 || piDstCoeff[minPos] == -32768)
           {
             finalChange = -1;
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 189)
@@ -128,5 +128,9 @@
 }
 
+#if SCALED_REF_LAYER_OFFSETS
+Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
+#else
 Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+#endif
 {
   assert ( NTAPS_US_LUMA == 8 );
@@ -136,4 +140,15 @@
 
   //========== Y component upsampling ===========
+#if SCALED_REF_LAYER_OFFSETS
+  const Window &scalEL = window;
+
+  Int widthBL   = pcBasePic->getWidth ();
+  Int heightBL  = pcBasePic->getHeight();
+  Int strideBL  = pcBasePic->getStride();
+
+  Int widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+  Int heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+  Int strideEL  = pcUsPic->getStride();
+#else
   const Window &confBL = pcBasePic->getConformanceWindow();
   const Window &confEL = pcUsPic->getConformanceWindow();
@@ -146,5 +161,5 @@
   Int heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
   Int strideEL  = pcUsPic->getStride();
-  
+#endif
   Pel* piTempBufY = pcTempPic->getLumaAddr();
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
@@ -329,10 +344,30 @@
   const Double sFactor12 = sFactor * 12;
 #endif
+#if ILP_DECODED_PICTURE
+  widthBL   = pcBasePic->getWidth ();
+  heightBL  = pcBasePic->getHeight();
+
+  widthEL   = pcUsPic->getWidth ();
+  heightEL  = pcUsPic->getHeight();
+#endif
+#if SCALED_REF_LAYER_OFFSETS
+  Int leftStartL = scalEL.getWindowLeftOffset();
+  Int rightEndL  = pcUsPic->getWidth() - scalEL.getWindowRightOffset();
+  Int topStartL  = scalEL.getWindowTopOffset();
+  Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
+#endif
 
   //========== horizontal upsampling ===========
   for( i = 0; i < widthEL; i++ )
   {
+#if SCALED_REF_LAYER_OFFSETS
+    Int x = Clip3( leftStartL, rightEndL - 1, i );
+#endif
 #if PHASE_DERIVATION_IN_INTEGER
+#if SCALED_REF_LAYER_OFFSETS
+    refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
+#else
     refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
     phase    = refPos16 & 15;
     refPos   = refPos16 >> 4;
@@ -366,8 +401,19 @@
   Int iOffset = 1 << (nShift - 1); 
 
+#if SCALED_REF_LAYER_OFFSETS
+  for( j = 0; j < pcTempPic->getHeight(); j++ )
+#else
   for( j = 0; j < heightEL; j++ )
-  {
+#endif
+  {
+#if SCALED_REF_LAYER_OFFSETS
+    Int y = Clip3(topStartL, bottomEndL - 1, j);
+#endif
 #if PHASE_DERIVATION_IN_INTEGER
+#if SCALED_REF_LAYER_OFFSETS
+    refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
+#else
     refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
     phase    = refPos16 & 15;
     refPos   = refPos16 >> 4;
@@ -382,12 +428,40 @@
     piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
     piDstY = piDstBufY + j * strideEL;
-
+#if SCALED_REF_LAYER_OFFSETS
+    for( i = 0; i < pcTempPic->getWidth(); i++ )
+#else
     for( i = 0; i < widthEL; i++ )
+#endif
     {
       *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+#if SCALED_REF_LAYER_OFFSETS
+      // Only increase the x position of reference upsample picture when within the window
+      // "-2" to ensure that pointer doesn't go beyond the boundary rightEndL-1
+      if( (i >= leftStartL) && (i <= rightEndL-2) )
+      {
+        piSrcY++;
+      }
+#else
       piSrcY++;
+#endif
       piDstY++;
     }
   }
+
+#if ILP_DECODED_PICTURE
+#if SCALED_REF_LAYER_OFFSETS
+  widthBL   = pcBasePic->getWidth ();
+  heightBL  = pcBasePic->getHeight();
+
+  widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+  heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+#else
+  widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+  widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
+#endif
 
   //========== UV component upsampling ===========
@@ -401,4 +475,10 @@
   strideBL  = pcBasePic->getCStride();
   strideEL  = pcUsPic->getCStride();
+#if SCALED_REF_LAYER_OFFSETS
+  Int leftStartC = scalEL.getWindowLeftOffset() >> 1;
+  Int rightEndC  = (pcUsPic->getWidth() >> 1) - (scalEL.getWindowRightOffset() >> 1);
+  Int topStartC  = scalEL.getWindowTopOffset() >> 1;
+  Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
+#endif
 
 #if PHASE_DERIVATION_IN_INTEGER
@@ -422,9 +502,24 @@
 #endif
 
+#if ILP_DECODED_PICTURE
+  widthBL   = pcBasePic->getWidth () >> 1;
+  heightBL  = pcBasePic->getHeight() >> 1;
+
+  widthEL   = pcUsPic->getWidth () >> 1;
+  heightEL  = pcUsPic->getHeight() >> 1;
+#endif
+
   //========== horizontal upsampling ===========
   for( i = 0; i < widthEL; i++ )
   {
+#if SCALED_REF_LAYER_OFFSETS
+    Int x = Clip3(leftStartC, rightEndC - 1, i);
+#endif
 #if PHASE_DERIVATION_IN_INTEGER
+#if SCALED_REF_LAYER_OFFSETS
+    refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
+#else
     refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
     phase    = refPos16 & 15;
     refPos   = refPos16 >> 4;
@@ -460,8 +555,19 @@
   pcTempPic->setHeight(heightEL << 1);
 
-  for( j = 0; j < heightEL; j++ )
-  {
+#if SCALED_REF_LAYER_OFFSETS
+  for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
+#else
+    for( j = 0; j < heightEL; j++ )
+#endif
+  {
+#if SCALED_REF_LAYER_OFFSETS
+    Int y = Clip3(topStartC, bottomEndC - 1, j);
+#endif
 #if PHASE_DERIVATION_IN_INTEGER
+#if SCALED_REF_LAYER_OFFSETS
+    refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
+#else
     refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
     phase    = refPos16 & 15;
     refPos   = refPos16 >> 4; 
@@ -488,11 +594,25 @@
     piDstV = piDstBufV + j*strideEL;
 
+#if SCALED_REF_LAYER_OFFSETS
+    for( i = 0; i < pcTempPic->getWidth() >> 1; i++ )
+#else
     for( i = 0; i < widthEL; i++ )
+#endif
     {
       *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
       *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
 
+#if SCALED_REF_LAYER_OFFSETS
+      // Only increase the x position of reference upsample picture when within the window
+      // "-2" to ensure that pointer doesn't go beyond the boundary rightEndC-1
+      if( (i >= leftStartC) && (i <= rightEndC-2) )
+      {
+        piSrcU++;
+        piSrcV++;
+      }
+#else
       piSrcU++;
       piSrcV++;
+#endif
       piDstU++;
       piDstV++;
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 189)
@@ -52,5 +52,9 @@
   ~TComUpsampleFilter(void);
 
+#if SCALED_REF_LAYER_OFFSETS
+  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+#else
  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 127)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 189)
@@ -44,4 +44,7 @@
 
 #if SVC_EXTENSION
+#define SCALED_REF_LAYER_OFFSETS         1      ///< M0309: Signal scaled reference layer offsets in SPS
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
 #define VPS_RENAME                       1      ///< Rename variables max_layer_id and num_layer_sets_minus1 in VPS
 #define VPS_EXTNS                        1      ///< Include function structure for VPS extensions
@@ -51,6 +54,11 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
-#endif
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+#define VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE   1
+#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
+#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
+#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
+#endif
+
+#define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
 
 #define SVC_COL_BLK                      1      ///< get co-located block
@@ -60,12 +68,11 @@
 #define CHROMA_UPSAMPLING                1      ///< L0335: Chroma upsampling with 5 bits coefficients
 
-#define MV_SCALING_FIX                   1      ///< fixing the base layer MV scaling
-#define MV_SCALING_POS_FIX               1      ///< use center pixels to get co-located base layer block
-#define MFM_CLIPPING_FIX                 1      ///< set the right picture size for the clipping
-
-#define AVC_BASE                         0      ///< YUV BL reading for AVC base SVC
-#define REF_IDX_FRAMEWORK                0      ///< inter-layer reference framework
-
-#if SVC_UPSAMPLING
+#define SIMPLIFIED_MV_POS_SCALING        1      ///< M0133/M0449: inter-layer MV scaling and pixel mapping position calculation
+#define ILP_DECODED_PICTURE              1      ///< M0274: use decoded picture for inter-layer prediction
+#define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
+
+#define REF_IDX_FRAMEWORK                1      ///< inter-layer reference framework
+
+#if SVC_UPSAMPLING && !ILP_DECODED_PICTURE
 #define JCTVC_L0178                      1      ///< implementation of JCTVC-L0178 (code only supports right and bottom croppping offsets)
 #endif
@@ -73,6 +80,7 @@
 #define IDR_ALIGNMENT                    1      ///< align IDR picures across layers 
 
+#define AVC_BASE                         1      ///< YUV BL reading for AVC base SVC
 #if AVC_BASE
-#define AVC_SYNTAX                       1      ///< Syntax reading for AVC base
+#define AVC_SYNTAX                       0      ///< Syntax reading for AVC base
 #endif
 
@@ -80,15 +88,9 @@
 #define REF_IDX_ME_ZEROMV                1      ///< L0051: use zero motion for inter-layer reference picture (without fractional ME)
 #define ENCODER_FAST_MODE                1      ///< L0174: enable encoder fast mode. TestMethod 1 is enabled by setting to 1 and TestMethod 2 is enable by setting to 2. By default it is set to 1.
-#if !AVC_BASE || AVC_SYNTAX
 #define REF_IDX_MFM                      1      ///< L0336: motion vector mapping of inter-layer reference picture
-#endif
-
-#if REF_IDX_MFM
-#define REUSE_MVSCALE                    1      ///< using the base layer MV scaling function
-#define REUSE_BLKMAPPING                 1      ///< using the base layer get co-located block function
-#define RAP_MFM_INIT                     1      ///< initilizing MFM when base layer is RAP picture
-#define REF_LIST_BUGFIX                  1
-#endif
-
+#define JCTVC_M0458_INTERLAYER_RPS_SIG   1      ///< implementation of JCTVC-L0178 (currently only one reference layer is supported )
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+#define ZERO_NUM_DIRECT_LAYERS           1      ///< support of zero direct reference layers
+#endif
 #else
 #define INTRA_BL                         1      ///< inter-layer texture prediction
@@ -97,4 +99,6 @@
 #define INTRA_BL_DST4x4                  1      ///< L0067/L0204: DST4x4 for Intra BL
 #define NO_RESIDUAL_FLAG_FOR_BLPRED      1      ///< L0437: Root cbf for Intra_BL
+#define IL_MRG_SIMPLIFIED_PRUNING        1      ///< M0124: simplified pruning, Only the left and above candidates are checked with BL-C candidate for redundancy removal 
+#define INTRA_BL_CTX_CHANGE              1      ///< M0075: spatial dependency removal for IntraBL flag context derivation
 
 // Hooks
@@ -109,4 +113,5 @@
 #endif
 #else
+#define ILP_DECODED_PICTURE              0
 #define SYNTAX_OUTPUT                    0
 #endif
@@ -114,4 +119,15 @@
 //! \ingroup TLibCommon
 //! \{
+
+#define FIX1071 1 ///< Temporary fix for issue #1071
+
+#define L0208_SOP_DESCRIPTION_SEI     1 ///< L0208: add SOP descrioption SEI
+#define MAX_NUM_PICS_IN_SOP           1024
+
+#define K0180_SCALABLE_NESTING_SEI  1   ///JCTVC-K0180 scalable nesting sei message
+#define MAX_NESTING_NUM_OPS         1024
+#define MAX_NESTING_NUM_LAYER       64
+
+#define J0149_TONE_MAPPING_SEI        1 ///< J0149: Tone mapping information SEI
 #define L0363_DU_BIT_RATE             1 ///< L0363: add bit_rate_du_value_minus1 to HRD parameters
 #define L0328_SPLICING                1 ///< L0328: splicing support in HRD
@@ -138,4 +154,8 @@
 #define SIGNAL_BITRATE_PICRATE_IN_VPS               0  ///< K0125: Signal bit_rate and pic_rate in VPS
 #define L0232_RD_PENALTY           1  ///< L0232: RD-penalty for 32x32 TU for intra in non-intra slices
+#define L0386_DB_METRIC            1  ///< L0386: non-normative blockiness metric (automatically configures deblocking parameters in bitstream)
+#define L0323_DPB                     1 ///< L0323: Specification of active reference indices and decoded picture buffer
+
+#define L0034_COMBINED_LIST_CLEANUP 1
 
 #if VPS_EXTN_MASK_AND_DIM_INFO
@@ -144,5 +164,5 @@
 #if VPS_RENAME
 #define MAX_VPS_LAYER_SETS_PLUS1                  1024
-#define MAX_VPS_LAYER_ID_PLUS1                    2
+#define MAX_VPS_LAYER_ID_PLUS1                    MAX_LAYERS
 #else
 #define MAX_VPS_NUM_HRD_PARAMETERS                1
@@ -477,5 +497,7 @@
   REF_PIC_LIST_0 = 0,   ///< reference list 0
   REF_PIC_LIST_1 = 1,   ///< reference list 1
+#if !L0034_COMBINED_LIST_CLEANUP
   REF_PIC_LIST_C = 2,   ///< combined reference list for uni-prediction in B-Slices
+#endif
   REF_PIC_LIST_X = 100  ///< special mark
 };
