Index: branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1216)
+++ branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1219)
@@ -91,6 +91,6 @@
 #endif
 
-#if H_3D
-  TComDLT& dlt = m_dlt;
+#if NH_3D_DLT
+  TComDLT dlt = m_dlt;
 #endif
 
@@ -149,5 +149,5 @@
   m_ivPicLists.setVPS      ( &vps );
 #endif
-#if H_3D
+#if NH_3D_DLT
   xDeriveDltArray          ( vps, dlt );
 #endif
@@ -308,6 +308,6 @@
   m_cTEncTop.setVPS(&vps);
 
-#if H_3D
-  m_cTEncTop.setDLT(&dlt);
+#if NH_3D_DLT
+  m_cTEncTop.setDLT(dlt);
 #endif
 
@@ -1447,32 +1447,30 @@
 }
 
-#if H_3D_DIM_DLT
+#if NH_3D_DLT
 Void TAppEncTop::xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt)
 {
   TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
+  TComPicYuv*       pcDepthPicYuvTrueOrg = new TComPicYuv;
   // allocate original YUV buffer
-  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false );
+  pcDepthPicYuvTrueOrg->create( m_iSourceWidth, m_iSourceHeight, CHROMA_420, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxTotalCUDepth, false );
   
   TVideoIOYuv* depthVideoFile = new TVideoIOYuv;
   
-  UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1);
+  UInt uiMaxDepthValue = ((1 << m_inputBitDepth[CHANNEL_TYPE_LUMA])-1);
   
-  Bool abValidDepths[256];
+  std::vector<Bool> abValidDepths(256, false);
   
-  depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+  depthVideoFile->open( m_pchInputFileList[layer], false, m_inputBitDepth, m_MSBExtendedBitDepth, m_internalBitDepth );
   
-  // initialize boolean array
-  for(Int p=0; p<=uiMaxDepthValue; p++)
-    abValidDepths[p] = false;
+  Int iHeight   = pcDepthPicYuvOrg->getHeight(COMPONENT_Y);
+  Int iWidth    = pcDepthPicYuvOrg->getWidth(COMPONENT_Y);
+  Int iStride   = pcDepthPicYuvOrg->getStride(COMPONENT_Y);
   
-  Int iHeight   = pcDepthPicYuvOrg->getHeight();
-  Int iWidth    = pcDepthPicYuvOrg->getWidth();
-  Int iStride   = pcDepthPicYuvOrg->getStride();
-  
-  Pel* pInDM    = pcDepthPicYuvOrg->getLumaAddr();
+  Pel* pInDM    = pcDepthPicYuvOrg->getAddr(COMPONENT_Y);
   
   for(Int uiFrame=0; uiFrame < uiNumFrames; uiFrame++ )
   {
-    depthVideoFile->read( pcDepthPicYuvOrg, m_aiPad );
+    depthVideoFile->read( pcDepthPicYuvOrg, pcDepthPicYuvTrueOrg, IPCOLOURSPACE_UNCHANGED, m_aiPad, m_InputChromaFormatIDC, m_bClipInputVideoToRec709Range );
     
     // check all pixel values
@@ -1494,7 +1492,9 @@
   pcDepthPicYuvOrg->destroy();
   delete pcDepthPicYuvOrg;
+  pcDepthPicYuvTrueOrg->destroy();
+  delete pcDepthPicYuvTrueOrg;
   
   // convert boolean array to idx2Depth LUT
-  Int* aiIdx2DepthValue = (Int*) calloc(uiMaxDepthValue, sizeof(Int));
+  std::vector<Int> aiIdx2DepthValue(256, 0);
   Int iNumDepthValues = 0;
   for(Int p=0; p<=uiMaxDepthValue; p++)
@@ -1506,5 +1506,5 @@
   }
   
-  if( uiNumFrames == 0 || numBitsForValue(iNumDepthValues) == g_bitDepthY )
+  if( uiNumFrames == 0 || gCeilLog2(iNumDepthValues) == m_inputBitDepth[CHANNEL_TYPE_LUMA] )
   {
     dlt->setUseDLTFlag(layer, false);
@@ -1516,7 +1516,4 @@
     dlt->setDepthLUTs(layer, aiIdx2DepthValue, iNumDepthValues);
   }
-  
-  // free temporary memory
-  free(aiIdx2DepthValue);
 }
 #endif
@@ -2389,6 +2386,5 @@
 
 
-#if H_3D
-
+#if NH_3D_DLT
 Void TAppEncTop::xDeriveDltArray( TComVPS& vps, TComDLT& dlt )
 {
@@ -2411,4 +2407,92 @@
       bDltPresentFlag = bDltPresentFlag || dlt.getUseDLTFlag(layer);
       dlt.setInterViewDltPredEnableFlag(layer, (dlt.getUseDLTFlag(layer) && (layer>1)));
+      
+      // ----------------------------- determine whether to use bit-map -----------------------------
+      Bool bDltBitMapRepFlag       = false;
+      UInt uiNumBitsNonBitMap      = 0;
+      UInt uiNumBitsBitMap         = 0;
+      
+      UInt uiMaxDiff               = 0;
+      UInt uiMinDiff               = INT_MAX;
+      UInt uiLengthMinDiff         = 0;
+      UInt uiLengthDltDiffMinusMin = 0;
+      
+      std::vector<Int> aiIdx2DepthValue_coded(256, 0);
+      UInt uiNumDepthValues_coded = 0;
+      
+      uiNumDepthValues_coded = dlt.getNumDepthValues(layer);
+      for( UInt ui = 0; ui<uiNumDepthValues_coded; ui++ )
+      {
+        aiIdx2DepthValue_coded[ui] = dlt.idx2DepthValue(layer, ui);
+      }
+      
+      if( dlt.getInterViewDltPredEnableFlag( layer ) )
+      {
+        AOF( vps.getDepthId( 1 ) == 1 );
+        AOF( layer > 1 );
+        // assumes ref layer id to be 1
+        std::vector<Int> piRefDLT = dlt.idx2DepthValue( 1 );
+        UInt uiRefNum = dlt.getNumDepthValues( 1 );
+        dlt.getDeltaDLT(layer, piRefDLT, uiRefNum, aiIdx2DepthValue_coded, uiNumDepthValues_coded);
+      }
+      
+      std::vector<UInt> puiDltDiffValues(uiNumDepthValues_coded, 0);
+      
+      for (UInt d = 1; d < uiNumDepthValues_coded; d++)
+      {
+        puiDltDiffValues[d] = aiIdx2DepthValue_coded[d] - aiIdx2DepthValue_coded[d-1];
+        
+        if ( uiMaxDiff < puiDltDiffValues[d] )
+        {
+          uiMaxDiff = puiDltDiffValues[d];
+        }
+        
+        if ( uiMinDiff > puiDltDiffValues[d] )
+        {
+          uiMinDiff = puiDltDiffValues[d];
+        }
+      }
+      
+      // counting bits
+      // diff coding branch
+      uiNumBitsNonBitMap += 8;                          // u(v) bits for num_depth_values_in_dlt[layerId] (i.e. num_entry[ layerId ])
+      
+      if ( uiNumDepthValues_coded > 1 )
+      {
+        uiNumBitsNonBitMap += 8;                        // u(v) bits for max_diff[ layerId ]
+      }
+      
+      if ( uiNumDepthValues_coded > 2 )
+      {
+        uiLengthMinDiff    = (UInt) gCeilLog2(uiMaxDiff + 1);
+        uiNumBitsNonBitMap += uiLengthMinDiff;          // u(v)  bits for min_diff[ layerId ]
+      }
+      
+      uiNumBitsNonBitMap += 8;                          // u(v) bits for dlt_depth_value0[ layerId ]
+      
+      if (uiMaxDiff > uiMinDiff)
+      {
+        uiLengthDltDiffMinusMin = (UInt) gCeilLog2(uiMaxDiff - uiMinDiff + 1);
+        uiNumBitsNonBitMap += uiLengthDltDiffMinusMin * (uiNumDepthValues_coded - 1);  // u(v) bits for dlt_depth_value_diff_minus_min[ layerId ][ j ]
+      }
+      
+      // bit map branch
+      uiNumBitsBitMap = 1 << m_inputBitDepth[CHANNEL_TYPE_LUMA];
+      
+      // determine bDltBitMapFlag
+      bDltBitMapRepFlag = (uiNumBitsBitMap > uiNumBitsNonBitMap) ? false : true;
+      
+      dlt.setUseBitmapRep(layer, bDltBitMapRepFlag);
+      
+#ifdef DEBUG
+      printf("---------------------------------------------\n");
+      printf("LayerId: %d\n", layer);
+      printf("getUseDLTFlag: %d\n", dlt.getUseDLTFlag(layer));
+      printf("getInterViewDltPredEnableFlag: %d\n", dlt.getInterViewDltPredEnableFlag(layer));
+      printf("getUseBitmapRep: %d\n", dlt.getUseBitmapRep(layer));
+      printf("getNumDepthValues: %d\n", dlt.getNumDepthValues(layer));
+      for(Int i=0; i<dlt.getNumDepthValues(layer); i++)
+        printf("depthValue[%d] = %d\n", i, dlt.idx2DepthValue(layer, i));
+#endif
     }
   }
@@ -2416,4 +2500,5 @@
   dlt.setDltPresentFlag( bDltPresentFlag );
   dlt.setNumDepthViews ( iNumDepthViews  );
+  dlt.setDepthViewBitDepth( m_inputBitDepth[CHANNEL_TYPE_LUMA] );
 }
 #endif
Index: branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.h	(revision 1216)
+++ branches/HTM-14.1-update-dev1-RWTH/source/App/TAppEncoder/TAppEncTop.h	(revision 1219)
@@ -90,5 +90,5 @@
 #endif
 
-#if H_3D
+#if NH_3D_DLT
   TComDLT                    m_dlt;                         ///< dlt
 #endif
@@ -154,9 +154,7 @@
   Bool xLayerIdInTargetEncLayerIdList( Int nuhLayerId );
 #endif
-#if H_3D
+#if NH_3D_DLT
   Void xDeriveDltArray( TComVPS& vps, TComDLT& dlt );
-#endif
-#if H_3D_DIM_DLT
-  Void  xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt);
+  Void xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt);
 #endif
 
