Index: branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg
===================================================================
--- branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg	(revision 30)
+++ branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_2view+depth.cfg	(revision 41)
@@ -115,8 +115,11 @@
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
 MVI                       : 1                                      # motion parameter inheritance
-DepthPower                : -1                                     # nonlinear depth representation
+NonlinearDepth            : 1                                      # nonlinear depth representation
+NonlinearDepthModel       : 12 21 26 27 23 15                      # nonlinear depth representation model
 
 #========== view synthesis optimization (VSO) ==========
 VSOConfig                 : [cx0 B(cc1) I(s0.5)][cx1 B(oo0) I(s0.5)]
                                                                    # VSO configuration string
-
+#========== flexible coding order (FlexCO) ==========
+3DVFlexOrder              : 0
+3DVCodingOrder            : T0D0D1D2T1T2
Index: branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg
===================================================================
--- branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg	(revision 30)
+++ branches/0.3-poznan-univ/CommonTestConditionsCfgs/baseCfg_3view+depth.cfg	(revision 41)
@@ -119,10 +119,13 @@
 VSO                       : 1                                      # use of view synthesis optimization for depth coding
 MVI                       : 1                                      # motion parameter inheritance
-DepthPower                : -1                                     # nonlinear depth representation
+NonlinearDepth            : 1                                      # nonlinear depth representation
+NonlinearDepthModel       : 12 21 26 27 23 15                      # nonlinear depth representation model
 
 #========== view synthesis optimization (VSO) ==========
 VSOConfig                 : [cx0 B(cc1) I(s0.5)][cx1 B(oo0) B(oo2) I(s0.5 s1.5)][cx2 B(cc1) I(s1.5)]
                                                                    # VSO configuration string
+#========== flexible coding order (FlexCO) ==========
+3DVFlexOrder              : 0
+3DVCodingOrder            : T0D0D1D2T1T2
 
 
-
Index: branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.cpp	(revision 41)
@@ -877,22 +877,16 @@
       radShiftParams[ uiSourceView][ uiTargetView ][ 1 ] = dOffset;
 
+      for( UInt uiDepthValue = 0; uiDepthValue < SizeOfLUT; uiDepthValue++ )
+      {
+        // real-valued look-up tables
 #if POZNAN_NONLINEAR_DEPTH
-      TComNonlinearDepthBackward cNonlinearDepthBwd(m_fDepthPower, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0);
+        Double  dShiftLuma;
+        if(m_bUseNonlinearDepth)
+          dShiftLuma      = ( m_cNonlinearDepthModel.BackwardD((Double)uiDepthValue, dScale) + dOffset ) * Double( 1 << m_iLog2Precision );
+        else
+          dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+#else
+        Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
 #endif
-
-      for( UInt uiDepthValue = 0; uiDepthValue < SizeOfLUT; uiDepthValue++ )
-      {
-        Double  dDepthValue = (Double)uiDepthValue;
-        Int64   iDepthValue = (Int64)uiDepthValue;
-#if POZNAN_NONLINEAR_DEPTH
-        dDepthValue = cNonlinearDepthBwd(dDepthValue);
-        iDepthValue = (Int64)(dDepthValue+0.5);
-#endif
-#if POZNAN_LUT_INCREASED_PRECISION
-        dDepthValue /= (1<<g_uiBitIncrement);
-#endif
-        // real-valued look-up tables
-
-        Double  dShiftLuma      = ( dDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
         Double  dShiftChroma    = dShiftLuma / 2;
         radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
@@ -900,7 +894,13 @@
 
         // integer-valued look-up tables
-        Int64   iTempScale      = iDepthValue * iScale;
-#if POZNAN_LUT_INCREASED_PRECISION
-        iTempScale >>= g_uiBitIncrement;
+#if POZNAN_NONLINEAR_DEPTH
+        Int64   iTempScale;
+        if(m_bUseNonlinearDepth)
+          iTempScale      = (Int64)m_cNonlinearDepthModel.BackwardI(uiDepthValue, iScale);
+        else
+          iTempScale      = (Int64)uiDepthValue * iScale;
+
+#else
+        Int64   iTempScale      = (Int64)uiDepthValue * iScale;
 #endif
         Int64   iTestScale      = ( iTempScale + iOffset       );   // for checking accuracy of camera parameters
@@ -1254,5 +1254,5 @@
                       Int    iLog2Precision
 #if POZNAN_NONLINEAR_DEPTH
-                      ,Float fDepthPower
+                      ,TComNonlinearDepthModel* pcNonlinearDepthModel
 #endif
                       )
@@ -1266,5 +1266,7 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  m_fDepthPower             = fDepthPower;
+  m_bUseNonlinearDepth = (pcNonlinearDepthModel != NULL) ? true : false;
+  if(pcNonlinearDepthModel != NULL)
+    m_cNonlinearDepthModel    = *pcNonlinearDepthModel;
 #endif
 
Index: branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.h
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.h	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppCommon/TAppComCamPara.h	(revision 41)
@@ -105,5 +105,6 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  Float               m_fDepthPower;
+  TComNonlinearDepthModel m_cNonlinearDepthModel;
+  Bool                m_bUseNonlinearDepth;
 #endif
 
@@ -166,5 +167,5 @@
                 Int     iLog2Precision 
 #if POZNAN_NONLINEAR_DEPTH
-                ,Float  fDepthPower
+                ,TComNonlinearDepthModel* pcNonlinearDepthModel
 #endif
                 );
@@ -178,5 +179,5 @@
                 Int     iLog2Precision
 #if POZNAN_NONLINEAR_DEPTH
-                ,Float  fDepthPower
+                ,TComNonlinearDepthModel* pcNonlinearDepthModel
 #endif
               );
Index: branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp	(revision 41)
@@ -138,4 +138,10 @@
   NalUnitType eNalUnitType;
 
+#if FLEX_CODING_ORDER
+  Int iDepthViewIdx = 0;
+  Bool bCountDepthViewIdx = false;		// a flag which avoid repeating assign a value to iDepthViewIdx   
+  Bool bNewPictureType =true;
+  Bool bFirstDepth = false;
+#endif
   
   while ( !bEos )
@@ -148,10 +154,19 @@
       if( bIsDepth )
       {
+#if FLEX_CODING_ORDER
+        if (!bFirstSliceDecoded) m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx] ,bNewPictureType);
+        m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
+#else
         if (!bFirstSliceDecoded) m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
         m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
+#endif
       }
       else
       {
+#if FLEX_CODING_ORDER
+        if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType);
+#else
         if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
+#endif
         m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
       }
@@ -168,8 +183,57 @@
     Bool bNewPicture;
     if( bIsDepth )
+#if FLEX_CODING_ORDER
+      bNewPicture = m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx], bNewPictureType);
+#else
       bNewPicture = m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
+#endif
     else
+#if FLEX_CODING_ORDER
+      bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType );
+#else
       bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
+#endif
     bFirstSliceDecoded   = true;
+
+#if FLEX_CODING_ORDER
+    if (eNalUnitType == NAL_UNIT_SPS)
+    {
+#if POZNAN_SYNTH
+      if(cComSPS.getViewId()==0 && !cComSPS.isDepth()) // it should be called at first view at the begining of the stream
+        initRenderer(cComSPS);
+#endif
+      if( cComSPS.isDepth() && (m_bUsingDepth==false) )  // expected not using depth, but bitstream are using depth
+      {                                                     // know from sps
+        assert( cComSPS.getViewId() == 0 && iDepthViewIdx == 0 && !bIsDepth );
+        startUsingDepth() ;
+      }
+      if (cComSPS.isDepth())
+      {
+        if (cComSPS.getViewId() >= m_acTVideoIOYuvDepthReconFileList.size())
+        {
+          assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
+          increaseNumberOfViews(cComSPS.getViewId()+1);
+        }
+  			
+        m_acTDecDepthTopList[cComSPS.getViewId()]->setSPS(cComSPS);
+      }
+      else 
+      {
+        if (cComSPS.getViewId() >= m_acTVideoIOYuvReconFileList.size())
+        {
+          assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
+          increaseNumberOfViews(cComSPS.getViewId()+1);
+        }
+        m_acTDecTopList[cComSPS.getViewId()]->setSPS(cComSPS);
+      }
+      bEos = m_cTVideoIOBitstreamFile.readBits( pcBitstream );
+      assert( !bEos);
+      if( cComSPS.isDepth() )
+        m_acTDecDepthTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
+      else
+        m_acTDecTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
+      assert( eNalUnitType == NAL_UNIT_PPS );
+    }
+#else
 
     if( eNalUnitType == NAL_UNIT_SPS )
@@ -204,9 +268,14 @@
       assert( eNalUnitType == NAL_UNIT_PPS );
     }
+#endif
     assert( eNalUnitType != NAL_UNIT_SEI ); // not yet supported for MVC
     if (bNewPicture)
     {
       if( bIsDepth )
+#if FLEX_CODING_ORDER
+        m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
+#else
         m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
+#endif
       else
         m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
@@ -214,20 +283,42 @@
       m_cTVideoIOBitstreamFile.setFileLocation( lLocation );
       bFirstSliceDecoded = false;
-
-      if( m_bUsingDepth && !bIsDepth )
-      {
-        bIsDepth = true;
+#if FLEX_CODING_ORDER
+      if (m_bUsingDepth)
+      {
+        bIsDepth = bNewPictureType;	  
+
+      }
+      if (bCountDepthViewIdx == false )
+      {
+        bCountDepthViewIdx = true;
+        if (bIsDepth == true)
+        {
+          bFirstDepth = true;
+          bCountDepthViewIdx = true;
+        }
+        if (!bFirstDepth && !bIsDepth)
+        {
+          iViewIdx++;
+          bCountDepthViewIdx = false;
+        }
+
       }
       else
       {
-        bIsDepth = false;
-        if( iViewIdx<m_acTDecTopList.size()-1)
-        {
-          iViewIdx++ ;
+        if (bIsDepth)
+        {
+          iDepthViewIdx++;
         }
         else
         {
+          iViewIdx ++;
+        }
+
+        if (iViewIdx >= m_acTDecTopList.size() || iDepthViewIdx >= m_acTDecDepthTopList.size())
+        {
+          bFirstDepth = false;
           iViewIdx = 0;
-
+          iDepthViewIdx = 0;
+          bCountDepthViewIdx = false;
           // end of access unit: delete extra pic buffers
           Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
@@ -260,4 +351,53 @@
         }
       }
+	  
+#else
+
+      if( m_bUsingDepth && !bIsDepth )
+      {
+        bIsDepth = true;
+      }
+      else
+      {
+        bIsDepth = false;
+        if( iViewIdx<m_acTDecTopList.size()-1)
+        {
+          iViewIdx++ ;
+        }
+        else
+        {
+          iViewIdx = 0;
+
+          // end of access unit: delete extra pic buffers
+          Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
+          for( Int iVId = 0; iVId < iNumViews; iVId++ )
+          {
+            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
+            {
+              m_acTDecTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
+            }
+            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
+            {
+              m_acTDecDepthTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
+            }
+          }
+
+#if AMVP_BUFFERCOMPRESS
+          // compress motion for entire access unit
+          for( Int iVId = 0; iVId < iNumViews; iVId++ )
+          {
+            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
+            {
+              m_acTDecTopList[iVId]->compressMotion( (Int)uiPOC );
+            }
+            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
+            {
+              m_acTDecDepthTopList[iVId]->compressMotion( (Int)uiPOC );
+            }
+          }
+#endif
+        }
+      }
+#endif
     }
 #else
@@ -434,16 +574,19 @@
 #if POZNAN_NONLINEAR_DEPTH
           TComSPS* pcSPS = pcPic->getSlice(0)->getSPS();
-          TComPicYuv cPicPower;
-
-          //pcPic->getPicYuvRec()
-          cPicPower.create(pcSPS->getWidth(), pcSPS->getHeight(), pcSPS->getMaxCUWidth(), pcSPS->getMaxCUHeight(), pcSPS->getMaxCUDepth() ); 
-
-          pcPic->getPicYuvRec()->nonlinearDepthBackward(&cPicPower, pcSPS->getDepthPower());
-
-          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write(&cPicPower, pcSPS->getPad());
-          cPicPower.destroy();		  
-#else
+          if( pcSPS->getUseNonlinearDepth() )
+          {
+            TComPicYuv cPicNonlinearDepth;
+
+            //pcPic->getPicYuvRec()
+            cPicNonlinearDepth.create(pcSPS->getWidth(), pcSPS->getHeight(), pcSPS->getMaxCUWidth(), pcSPS->getMaxCUHeight(), pcSPS->getMaxCUDepth() ); 
+
+            pcPic->getPicYuvRec()->nonlinearDepthBackward(&cPicNonlinearDepth, pcSPS->getNonlinearDepthModel());
+
+            m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write(&cPicNonlinearDepth, pcSPS->getPad());
+            cPicNonlinearDepth.destroy();		  
+          }
+          else
+#endif
           m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() );
-#endif
         }
 
@@ -536,5 +679,10 @@
       m_acTDecDepthTopList.back()->create() ;
       m_acTDecDepthTopList.back()->init( this, false );
+#if FLEX_CODING_ORDER
+      Int iNumofgen = (Int)m_acTDecDepthTopList.size();
+      m_acTDecDepthTopList.back()->setViewIdx(iNumofgen-1); //Oweczka ??
+#else
       m_acTDecDepthTopList.back()->setViewIdx((Int)m_acTDecTopList.size()-1);
+#endif
       m_acTDecDepthTopList.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
       m_acTDecDepthTopList.back()->setToDepth( true );
@@ -560,4 +708,14 @@
 TComPic* TAppDecTop::getPicFromView( Int iViewIdx, Int iPoc, bool bIsDepth )
 {
+#if FLEX_CODING_ORDER //Owieczka ?? flaga Jakuba
+  if( bIsDepth && ((Int)(m_acTDecDepthTopList.size() - 1) < iViewIdx))
+  {
+    return NULL;
+  }
+  if(!bIsDepth && ((Int)(     m_acTDecTopList.size() - 1) < iViewIdx)) 
+  {
+    return NULL;
+  }
+#endif
   TComList<TComPic*>* apcListPic = (bIsDepth ? m_acTDecDepthTopList[iViewIdx] : m_acTDecTopList[iViewIdx])->getListPic();
   TComPic* pcRefPic = NULL;
Index: branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 41)
@@ -110,4 +110,11 @@
     free (m_pchBitstreamFile) ;
 
+#if FLEX_CODING_ORDER
+  if (m_pchMVCJointCodingOrder != NULL)
+  {
+    free(m_pchMVCJointCodingOrder) ;
+  }
+#endif
+
   for(Int i = 0; i< m_pchDepthReconFileList.size(); i++ )
   {
@@ -153,4 +160,9 @@
   string cfg_ReconFile;
   string cfg_dQPFile;
+
+#if FLEX_CODING_ORDER
+  string cfg_JointCodingOrdering;
+#endif
+
   po::Options opts;
   opts.addOptions()
@@ -191,4 +203,8 @@
   ("NumberOfViews",         m_iNumberOfViews,    0, "Number of views")
 
+#if FLEX_CODING_ORDER
+  ("3DVFlexOrder",          m_b3DVFlexOrder,   false, "flexible coding order flag" )
+  ("3DVCodingOrder",		cfg_JointCodingOrdering,  string(""), "The coding order for joint texture-depth coding")
+#endif
 
   /* Unit definition parameters */
@@ -367,5 +383,9 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-  ("DepthPower,-dpow",    m_fDepthPower,      (Double)1.0, "Depth power value (for non-linear processing)")
+  ("NonlinearDepth",           m_bUseNonlinearDepth,    true, "usage of non-linear depth representation")    
+  ("NonlinearDepthModel",      m_aiNonlinearDepthModel, std::vector<Int>(0,0), "Nodes for definition of non-linear depth representation")    
+#if POZNAN_NONLINEAR_DEPTH_THRESHOLD
+  ("NonlinearDepthThreshold",  m_iNonlinearDepthThreshold, 100, "Threshold for usage of Nonlinear depth representation")    
+#endif
 #endif
 
@@ -398,4 +418,36 @@
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
+
+#if FLEX_CODING_ORDER && HHI_VSO
+  m_pchMVCJointCodingOrder	= cfg_JointCodingOrdering.empty()?NULL:strdup(cfg_JointCodingOrdering.c_str());
+  // If flexible order is enabled and if depth comes before the texture for a view, disable VSO
+  Bool depthComesFirst = false;
+  if ( m_b3DVFlexOrder )
+  {
+    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
+    {
+      for ( Int ii=1; ii<12; ii+=2 )
+      {
+        Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
+        if ( iViewIdxCfg == iViewIdx )
+        {
+          if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
+          {
+            depthComesFirst = true;
+            break;
+          }
+          else
+          {
+            assert(m_pchMVCJointCodingOrder[ii-1]=='T');
+          }
+        }
+      }
+    }
+  }
+  if (depthComesFirst)
+  {
+    m_bUseVSO = false;		
+  }
+#endif
 
 
@@ -458,18 +510,44 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-if (m_fDepthPower<=0) 
-  {
-    Float fDepthQP = m_adQP[ m_adQP.size()  < 2 ? 0 : 1];
-    m_fDepthPower = (fDepthQP-30) *0.25/20.0 + 1.25;
-    if (m_fDepthPower<=1.0) m_fDepthPower = 1.0;
-    // QP = 30 = 1.25
-    // QP = 50 = 1.5
-    if (m_fDepthPower>=1.66) m_fDepthPower = 1.66;
-  };
-
-#if POZNAN_NONLINEAR_DEPTH_SEND_AS_BYTE
-  m_fDepthPower = dequantizeDepthPower(quantizeDepthPower((Float)m_fDepthPower));
-#endif
-
+#if POZNAN_NONLINEAR_DEPTH_THRESHOLD
+  if(m_bUseNonlinearDepth && m_iNonlinearDepthThreshold>0)
+  {
+    FILE *base_depth_file;
+    unsigned char *depth_buf;
+    int histogram[256];
+    int i, size;
+    float weighted_avg;
+    base_depth_file = fopen(m_pchDepthInputFileList[0], "rb");
+    if (base_depth_file)
+    {
+      size = m_iSourceWidth*m_iSourceHeight;
+      depth_buf = (unsigned char *)malloc(size);
+      fread(depth_buf, 1, size, base_depth_file);
+      fclose(base_depth_file);
+      memset(histogram, 0, sizeof(histogram));
+      for (i=0; i<size;++i) histogram[depth_buf[i]]++;
+      weighted_avg = 0;
+      for (i=0; i<256; ++i) weighted_avg += i*histogram[i];
+      weighted_avg /= size;
+
+      if (weighted_avg<m_iNonlinearDepthThreshold)
+      {
+        m_bUseNonlinearDepth = 0;
+        printf ("\nWeighted average of depth histogram:%f < %d, turning NonlinearDepthRepresentation OFF\n", weighted_avg, m_iNonlinearDepthThreshold);
+      }
+    }
+  }
+#endif
+
+  if(m_bUseNonlinearDepth)
+  {
+    m_cNonlinearDepthModel.m_iNum = (Int)m_aiNonlinearDepthModel.size();
+    m_cNonlinearDepthModel.m_aiPoints[0]=0;
+    for (int i=0; i<m_cNonlinearDepthModel.m_iNum; ++i)
+      m_cNonlinearDepthModel.m_aiPoints[i+1] = m_aiNonlinearDepthModel[i];
+
+    m_cNonlinearDepthModel.m_aiPoints[m_cNonlinearDepthModel.m_iNum+1]=0;
+    m_cNonlinearDepthModel.Init();
+  }
 #endif
 
@@ -555,5 +633,5 @@
                                       LOG2_DISP_PREC_LUT 
 #if POZNAN_NONLINEAR_DEPTH                                      
-                                      ,m_fDepthPower
+                                      ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
 #endif
                                       );
@@ -572,5 +650,5 @@
                                       LOG2_DISP_PREC_LUT 
 #if POZNAN_NONLINEAR_DEPTH                                      
-                                      ,m_fDepthPower
+                                      ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
 #endif                                      
                                       );
@@ -589,5 +667,5 @@
     LOG2_DISP_PREC_LUT 
 #if POZNAN_NONLINEAR_DEPTH                                      
-    ,m_fDepthPower
+    ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
 #endif    
     );
@@ -605,5 +683,5 @@
     LOG2_DISP_PREC_LUT 
 #if POZNAN_NONLINEAR_DEPTH                                      
-    ,m_fDepthPower
+    ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
 #endif    
     );
@@ -1064,5 +1142,5 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-  printf("DepthPower:%f ", m_fDepthPower);
+  printf("NLDR:%d ", m_bUseNonlinearDepth ? 1 : 0);
 #endif
   printf("\n");
Index: branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.h	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.h	(revision 41)
@@ -81,4 +81,9 @@
   Bool      m_bUsingDepthMaps ;
 
+#if FLEX_CODING_ORDER
+  char*		m_pchMVCJointCodingOrder;		///<  texture-depth coding order
+  Bool		m_b3DVFlexOrder;		///<  flexible coding order flag
+#endif
+
 
   // coding structure
@@ -290,5 +295,8 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  Double    m_fDepthPower;									  ///< Depth power value
+  std::vector<Int>            m_aiNonlinearDepthModel;
+  TComNonlinearDepthModel     m_cNonlinearDepthModel;
+  Int                         m_iNonlinearDepthThreshold;
+  Bool                        m_bUseNonlinearDepth;
 #endif
 
Index: branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp	(revision 41)
@@ -142,5 +142,6 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-    m_acTEncTopList[iViewIdx]->setDepthPower                   ( (Float)m_fDepthPower );
+    m_acTEncTopList[iViewIdx]->setNonlinearDepthModel         ( m_cNonlinearDepthModel );
+    m_acTEncTopList[iViewIdx]->setUseNonlinearDepth           ( m_bUseNonlinearDepth );
 #endif
 
@@ -256,4 +257,27 @@
     for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
     {
+#if FLEX_CODING_ORDER
+      // Detect whether depth comes before than texture for this view
+      Bool isDepthFirst = false;
+      if ( m_b3DVFlexOrder )
+      {
+        for ( Int ii=1; ii<12; ii+=2 )
+        {
+          Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
+          if ( iViewIdxCfg == iViewIdx )
+          {
+            if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
+            {
+              isDepthFirst = true;
+            }
+            else
+            {
+              assert(m_pchMVCJointCodingOrder[ii-1]=='T');
+            }
+            break;
+          }
+        }
+      }
+#endif
       m_iDepthFrameRcvdVector.push_back(0) ;
       m_acTEncDepthTopList.push_back(new TEncTop);
@@ -375,4 +399,7 @@
       m_acTEncDepthTopList[iViewIdx]->setUseDMM( m_bUseDMM );
 #endif
+#if FLEX_CODING_ORDER && HHI_DMM_PRED_TEX
+      m_acTEncDepthTopList[iViewIdx]->setUseDMM34( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseDMM );
+#endif
 #if CONSTRAINED_INTRA_PRED
       m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
@@ -401,5 +428,9 @@
 #endif
 #if HHI_MPI
+#if FLEX_CODING_ORDER
+      m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
+#else
       m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
+#endif
 #endif
 #if POZNAN_DBMP
@@ -407,8 +438,9 @@
 #endif
 #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
-	    m_acTEncDepthTopList[iViewIdx]->setUseCUSkip                      ( m_uiUseCUSkip );
+	    m_acTEncDepthTopList[iViewIdx]->setUseCUSkip                   ( m_uiUseCUSkip );
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-      m_acTEncDepthTopList[iViewIdx]->setDepthPower                   ( (Float)m_fDepthPower );
+      m_acTEncDepthTopList[iViewIdx]->setNonlinearDepthModel         ( m_cNonlinearDepthModel );
+      m_acTEncDepthTopList[iViewIdx]->setUseNonlinearDepth           ( m_bUseNonlinearDepth );
 #endif
 
@@ -690,5 +722,6 @@
           m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcPdmDepthOrg, m_aiPad, m_bUsingDepthMaps );
 #if POZNAN_NONLINEAR_DEPTH
-		      pcPdmDepthOrg->nonlinearDepthForward(pcPdmDepthOrg, m_fDepthPower);		  
+          if( m_bUseNonlinearDepth )
+            pcPdmDepthOrg->nonlinearDepthForward(pcPdmDepthOrg, m_cNonlinearDepthModel);		  
 #endif
         }
@@ -714,5 +747,6 @@
           m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad  ) ;
 #if POZNAN_NONLINEAR_DEPTH
-		      pcDepthPicYuvOrg->nonlinearDepthForward(pcDepthPicYuvOrg, m_fDepthPower);		  
+          if( m_bUseNonlinearDepth )
+            pcDepthPicYuvOrg->nonlinearDepthForward(pcDepthPicYuvOrg, m_cNonlinearDepthModel);		  
 #endif
           bDepthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
@@ -744,4 +778,71 @@
 #endif
 
+#if FLEX_CODING_ORDER
+    if (m_b3DVFlexOrder)
+    {
+      Int i=0;
+      Int iViewIdx = 0;
+      bool bThisViewContinueReadingPics = false;
+      bool bThisViewContinueReadingDepthPics = false;
+      Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
+      for(Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )     // Start encoding
+      {
+        if (m_pchMVCJointCodingOrder[i]=='T')
+        {
+          i++;
+          assert(isdigit(m_pchMVCJointCodingOrder[i]));
+          iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+          bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
+#if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
+          // If no depth picture reconstruction for current view and current POC is available sythesize one
+          Int   iCurrPoc         = m_acTEncTopList[ 0 ]->getNextFrameId();
+          Bool  bCurrPicDepthRec = getPicFromView( iViewIdx, iCurrPoc, true ) != NULL && getPicFromView( iViewIdx, iCurrPoc, true )->getReconMark();
+          if(m_bUseTexDqpAccordingToDepth && !bCurrPicDepthRec)
+          {
+            xStoreDepthSynthPicsInBuffer(iViewIdx);
+          }
+#endif
+          m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
+          bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
+          bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
+
+          if(pcBitstream->getNumberOfWrittenBits()!=0)
+          {
+            m_cTVideoIOBitsFile.writeBits( pcBitstream );
+          }
+          pcBitstream->resetBits(); //GT: also done later in ....
+          pcBitstream->rewindStreamPacket( );
+          // write bistream to file if necessary
+          xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
+          i++;
+        }
+        else if ( m_pchMVCJointCodingOrder[i] == 'D')
+        {
+          i++;
+          if( m_bUsingDepthMaps )
+          {
+            assert(isdigit(m_pchMVCJointCodingOrder[i]));
+            iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
+            bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
+            m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
+            bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
+
+            bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
+            if(pcBitstream->getNumberOfWrittenBits()!=0)
+            {
+              m_cTVideoIOBitsFile.writeBits( pcBitstream );
+            }
+            pcBitstream->resetBits();
+            pcBitstream->rewindStreamPacket( );
+            // write bistream to file if necessary
+            xWriteOutput( iViewIdx, true );
+            i++;
+          }
+        }
+      }
+    }
+    else
+    {
+#endif
     //GT: Encode
     for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )     // Start encoding
@@ -755,5 +856,12 @@
             //*
 #if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
+#if FLEX_CODING_ORDER
+      // If no depth picture reconstruction for current view and current POC is available sythesize one
+      Int   iCurrPoc         = m_acTEncTopList[ 0 ]->getNextFrameId();
+      Bool  bCurrPicDepthRec = getPicFromView( iViewIdx, iCurrPoc, true ) != NULL && getPicFromView( iViewIdx, iCurrPoc, true )->getReconMark();
+      if(m_bUseTexDqpAccordingToDepth && !bCurrPicDepthRec)
+#else
       if(m_bUseTexDqpAccordingToDepth)
+#endif
       {
         xStoreDepthSynthPicsInBuffer(iViewIdx);
@@ -798,5 +906,7 @@
       }
     }
-
+#if FLEX_CODING_ORDER
+    }
+#endif
     // delete extra picture buffers
     if( bCurrPocCoded )
@@ -1004,5 +1114,5 @@
     riNextPocToDump++;
 #if POZNAN_NONLINEAR_DEPTH
-    if(isDepth)
+    if(isDepth && m_bUseNonlinearDepth)
     {
       TComPicYuv *pcPicOrg = i->second;
@@ -1011,5 +1121,5 @@
       pcPicPow->create( pcPicOrg->getWidth(), pcPicOrg->getHeight(), pcPicOrg->getMaxCuWidth(), pcPicOrg->getMaxCuHeight(), pcPicOrg->getMaxCuDepth() );
       //cPicPower.create(pcSPS->getWidth(), pcSPS->getHeight(), pcSPS->getMaxCUWidth(), pcSPS->getMaxCUHeight(), pcSPS->getMaxCUDepth() ); 
-      pcPicOrg->nonlinearDepthBackward(pcPicPow, m_fDepthPower);		
+      pcPicOrg->nonlinearDepthBackward(pcPicPow, m_cNonlinearDepthModel);		
       rpcTVideoIOYuvReconFile->write( pcPicPow, m_aiPad );
 // to do destroy pcPicow
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/CommonDef.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/CommonDef.h	(revision 41)
@@ -144,10 +144,4 @@
 #endif
 
-#if POZNAN_NONLINEAR_DEPTH
-#define POZNAN_LUT_INCREASED_PRECISION 0 // 1 //to do
-#else
-#define POZNAN_LUT_INCREASED_PRECISION 0
-#endif
-
 //>>>>> generation and usage of virtual prediction depth maps >>>>>
 #define PDM_ONE_DEPTH_PER_PU              1         // use only a single depth for a prediction unit (in update)
@@ -192,19 +186,4 @@
 #endif
 
-#if POZNAN_NONLINEAR_DEPTH
-inline UChar quantizeDepthPower(Float fDepthPower)
-{
-  Int r = (Int) ( (fDepthPower-1.0f)*128.0f + 0.5f);
-  if (r<=0) return 0;
-  if (r>255) r=255;  
-  return r;
-};
-
-inline Float dequantizeDepthPower(Int iDepthQuant)
-{
-  return iDepthQuant/128.0f + 1.0f;  
-};
-#endif
-
 // ====================================================================================================================
 // Macro functions
@@ -218,11 +197,5 @@
 #define RemoveBitIncrement(x)       ( ((x) + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement )     ///< Remove Bit increment
 
-#if POZNAN_LUT_INCREASED_PRECISION
-#define RemoveBitIncrementLUT(x)       (x)     ///< Remove Bit increment
-#define SizeOfLUT                      (256 << g_uiBitIncrement)  
-#else
 #define SizeOfLUT                      256
-#define RemoveBitIncrementLUT(x)       ( ((x) + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement )     ///< Remove Bit increment
-#endif
 
 #define DATA_ALIGN                  1                                                                 ///< use 32-bit aligned malloc/free
@@ -665,4 +638,68 @@
 
 
+#if POZNAN_NONLINEAR_DEPTH
+struct TComNonlinearDepthModel // // OS: cannot be stdarray, due to memcpy done on SlicePilot
+{
+  Int m_aiPoints[257];
+  Int m_iNum;
+
+  Int m_aiX[257];
+  Int m_aiY[257];
+
+  Void Clear() { m_iNum=0; m_aiPoints[0]=0; m_aiPoints[1]=0; };
+  Void Init() 
+  { 
+    for (Int k=m_iNum+1; k>=0; --k)
+    {
+      int q = 255*k/(m_iNum+1);
+      m_aiX[k] = q + m_aiPoints[k];
+      m_aiY[k] = q - m_aiPoints[k];
+    }
+  };
+
+  Double xInterpolateD(Int *aiX,Int *aiY, Double x, Double dScale)
+  {
+    Int x1 = 0;
+    Int x2 = m_iNum+1;
+
+    for (;;)
+    {
+      if (x1+1>=x2)
+        return ((x-aiX[x1])*(aiY[x2]-aiY[x1])/(aiX[x2]-aiX[x1]) + aiY[x1])*dScale;
+      Int xm = (x1+x2)>>1;
+      if (x >= aiX[xm]) x1 = xm;
+      else              x2 = xm;
+    }
+  }
+
+  inline Double ForwardD(Double x,  Double dScale) { return xInterpolateD(m_aiX, m_aiY, x, dScale); }
+  inline Double BackwardD(Double x, Double dScale) { return xInterpolateD(m_aiY, m_aiX, x, dScale); }
+
+  Int64 xInterpolateI(Int *aiX,Int *aiY, Int x, Int64 iScale)
+  {
+    Int x1 = 0;
+    Int x2 = m_iNum+1;
+
+    for (;;)
+    {
+      if (x1+1>=x2)
+      {         
+        Int aiXx2x1 = (aiX[x2]-aiX[x1]);
+        Int64 res = (x-aiX[x1])*(aiY[x2]-aiY[x1])*iScale;
+        if (res>0) return (res + (aiXx2x1>>1) )/aiXx2x1 + aiY[x1]*iScale;
+        else       return (res - (aiXx2x1>>1) )/aiXx2x1 + aiY[x1]*iScale; 
+      }
+      Int xm = (x1+x2)>>1;
+      if (x >= aiX[xm]) x1 = xm;
+      else              x2 = xm;
+    }
+  }
+
+  inline Int64  ForwardI (Int x, Int64 iScale) { return xInterpolateI(m_aiX, m_aiY, x, iScale); }
+  inline Int64  BackwardI(Int x, Int64 iScale) { return xInterpolateI(m_aiY, m_aiX, x, iScale); }
+
+};
+#endif
+
 #endif // end of #ifndef  __COMMONDEF__
 
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComDataCU.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComDataCU.cpp	(revision 41)
@@ -5004,12 +5004,12 @@
     exit(333);
   }
-  Float fVal = (Float)((255 - (uiBlockMax >> g_uiBitIncrement)) >> 4);
+  Double fVal = (Double)((255 - (uiBlockMax >> g_uiBitIncrement)) >> 4); //Owieczka ?? ToDo Convert Double to Int
   fVal = (fVal * fVal);
 #if POZNAN_TEXTURE_TU_DELTA_QP_PARAM_IN_CFG_FOR_ENC
-  fVal = (Float)( fVal + getPic()->getTexDqpAccordingToDepthOffset() * 32); // add offset, if offset is negative than objects in front will have smaller QP than originaly - quality in front will be increased and in bacground will be decreased
-  fVal = (Float)( fVal * getPic()->getTexDqpAccordingToDepthMul()); // 
+  fVal = (Double)( fVal + getPic()->getTexDqpAccordingToDepthOffset() * 32); // add offset, if offset is negative than objects in front will have smaller QP than originaly - quality in front will be increased and in bacground will be decreased
+  fVal = (Double)( fVal * getPic()->getTexDqpAccordingToDepthMul()); // 
 #else 
-  fVal = (Float)( fVal + POZNAN_TEXTURE_TU_DELTA_QP_OFFSET * 32); // add offset, if offset is negative objects in front will have smaller QP than in original approach - quality in front will be increased and in bacground will be decreased
-  fVal = (Float)( fVal * POZNAN_TEXTURE_TU_DELTA_QP_MUL); // 
+  fVal = (Double)( fVal + POZNAN_TEXTURE_TU_DELTA_QP_OFFSET * 32); // add offset, if offset is negative objects in front will have smaller QP than in original approach - quality in front will be increased and in bacground will be decreased
+  fVal = (Double)( fVal * POZNAN_TEXTURE_TU_DELTA_QP_MUL); // 
 #endif
   return (Int)fVal >> 5;
@@ -5034,5 +5034,18 @@
    UInt iCuAddr = getAddr();
    //TComPic * pcDepthPic = getPic()->getDepthPic();
+#if FLEX_CODING_ORDER
+   TComPicYuv * pcDepthPicYUV = NULL;
+   // if depth map reconstruction picture is available use it Use synthesis picture otherwise.
+   if(getPic()->getSlice(0)->getDepthPic() != NULL && getPic()->getSlice(0)->getDepthPic()->getReconMark())
+   {
+     pcDepthPicYUV = getPic()->getSlice(0)->getDepthPic()->getPicYuvRec();
+   }
+   else
+   {
+      pcDepthPicYUV = getPic()->getPicYuvSynthDepth();
+   }
+#else
    TComPicYuv * pcDepthPicYUV = getPic()->getPicYuvSynthDepth();
+#endif
    if(pcDepthPicYUV /*pcDepthPic*/ == NULL)
    {
@@ -5055,6 +5068,6 @@
    }
 #if POZNAN_NONLINEAR_DEPTH
-   TComNonlinearDepthBackward cNonlinearDepthBwd(getSlice()->getSPS()->getDepthPower(), g_uiBitIncrement, g_uiBitIncrement); 
-   uiDepthLumaTransformBlockMax = (Pel)( cNonlinearDepthBwd(uiDepthLumaTransformBlockMax) + 0.5);
+   if( getSlice()->getSPS()->getUseNonlinearDepth() )
+    uiDepthLumaTransformBlockMax = (Pel)( getSlice()->getSPS()->getNonlinearDepthModel().BackwardI(RemoveBitIncrement(uiDepthLumaTransformBlockMax), 1<<g_uiBitIncrement ) ) ;
 #endif
    Int iDeltaQP = CuQpIncrementFunction(uiDepthLumaTransformBlockMax);
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.cpp	(revision 41)
@@ -44,4 +44,9 @@
 	//m_pcCameraData = NULL;
 	m_aiBaseViewShiftLUT = NULL;
+#if POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+  m_ppiTempMvPtCorrX = NULL;
+  m_ppiTempMvPtCorrY = NULL;
+  m_ppiTempMvPtCorrZ = NULL;
+#endif
 #endif
 
@@ -96,22 +101,4 @@
 #endif
 
-/*
-	m_ppiMvPtCorrX = new Short*[m_uiHeight];
-	m_ppiMvPtCorrY = new Short*[m_uiHeight];
-	m_ppiMvPtCorrZ = new Short*[m_uiHeight];
-	m_ppiMvPtCorrRefViewIdx = new Short*[m_uiHeight];
-	m_pppcRefCU = new TComDataCU**[m_uiHeight];
-	m_ppuicRefPartAddr = new UShort*[m_uiHeight];	
-	for(Int i=0;i<m_uiHeight;i++)
-	{
-		m_ppiMvPtCorrX[i] = new Short[m_uiWidth];
-		m_ppiMvPtCorrY[i] = new Short[m_uiWidth];
-		m_ppiMvPtCorrZ[i] = new Short[m_uiWidth];
-		m_ppiMvPtCorrRefViewIdx[i] = new Short[m_uiWidth];
-		m_pppcRefCU[i] = new TComDataCU*[m_uiWidth];
-		m_ppuicRefPartAddr[i]  = new UShort[m_uiWidth];
-	}
-//*/
-///*
 	Short* piPtr;
 	UShort* puiPtr;
@@ -141,5 +128,19 @@
 	puiPtr = (UShort*)malloc(sizeof(UShort)*m_uiHeight*m_uiWidth);
 	for(UInt i=0,addr=0;i<m_uiHeight;i++,addr+=m_uiWidth) m_ppuicRefPartAddr[i] = &(puiPtr[addr]);
-//*/
+
+#if !POZNAN_MP_USE_DEPTH_MAP_GENERATION && POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+	m_ppiTempMvPtCorrX = (Short**)malloc(sizeof(Short*)*m_uiHeight);
+	piPtr = (Short*)malloc(sizeof(Short)*m_uiHeight*m_uiWidth);
+	for(UInt i=0,addr=0;i<m_uiHeight;i++,addr+=m_uiWidth) m_ppiTempMvPtCorrX[i] = &(piPtr[addr]);
+
+	m_ppiTempMvPtCorrY = (Short**)malloc(sizeof(Short*)*m_uiHeight);
+	piPtr = (Short*)malloc(sizeof(Short)*m_uiHeight*m_uiWidth);
+	for(UInt i=0,addr=0;i<m_uiHeight;i++,addr+=m_uiWidth) m_ppiTempMvPtCorrY[i] = &(piPtr[addr]);
+
+	m_ppiTempMvPtCorrZ = (Short**)malloc(sizeof(Short*)*m_uiHeight);
+	piPtr = (Short*)malloc(sizeof(Short)*m_uiHeight*m_uiWidth);
+	for(UInt i=0,addr=0;i<m_uiHeight;i++,addr+=m_uiWidth) m_ppiTempMvPtCorrZ[i] = &(piPtr[addr]);
+#endif
+
 #if POZNAN_DBMP & !POZNAN_DBMP_COMPRESS_ME_DATA
 	m_ppiL0RefPOC.clear();
@@ -303,4 +304,34 @@
 	}
 
+#if !POZNAN_MP_USE_DEPTH_MAP_GENERATION && POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+	if(m_ppiTempMvPtCorrX!=NULL)
+	{
+		//for(Int i=0;i<m_uiHeight;i++) delete [] m_ppiTempMvPtCorrX[i];
+		//delete [] m_ppiTempMvPtCorrX;
+		free(m_ppiTempMvPtCorrX[0]);
+		free(m_ppiTempMvPtCorrX);
+		m_ppiTempMvPtCorrX = NULL;
+	}
+
+	if(m_ppiTempMvPtCorrY!=NULL)
+	{
+		//for(Int i=0;i<m_uiHeight;i++) delete [] m_ppiTempMvPtCorrY[i];
+		//delete [] m_ppiTempMvPtCorrY;
+		free(m_ppiTempMvPtCorrY[0]);
+		free(m_ppiTempMvPtCorrY);
+		m_ppiTempMvPtCorrY = NULL;
+	}
+
+	if(m_ppiTempMvPtCorrZ!=NULL)
+	{
+		//for(Int i=0;i<m_uiHeight;i++) delete [] m_ppiTempMvPtCorrZ[i];
+		//delete [] m_ppiTempMvPtCorrZ;
+		free(m_ppiTempMvPtCorrZ[0]);
+		free(m_ppiTempMvPtCorrZ);
+		m_ppiTempMvPtCorrZ = NULL;
+	}
+
+#endif
+
 #if POZNAN_DBMP & !POZNAN_DBMP_COMPRESS_ME_DATA
 	PUT_MP_ARRAY_TYPE** ppiTemp;
@@ -439,4 +470,20 @@
 }
 
+#if !POZNAN_MP_USE_DEPTH_MAP_GENERATION && POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+Void TComMP::clearTemp()
+{
+	if(!isInit()) return;
+
+	for(Int i=0;i<m_uiHeight;i++)
+		for(Int j=0;j<m_uiWidth;j++)
+		{
+			m_ppiTempMvPtCorrX[i][j] = TComMP::OCCLUSION;
+			m_ppiTempMvPtCorrY[i][j] = TComMP::OCCLUSION;
+			//m_ppiTempMvPtCorrZ[i][j] = 0x7FFF; //Depth
+			m_ppiTempMvPtCorrZ[i][j] = TComMP::OCCLUSION; //Disparity
+		}
+}
+#endif
+
 Bool TComMP::isInit()
 {
@@ -498,4 +545,7 @@
 	//Bool bIsLeft;
 	Int  iDepth;
+#if POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+	Int iSrcX, iSrcY;
+#endif	
 #endif	
 
@@ -547,4 +597,113 @@
 	}
 #else
+
+#if POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+	//pcDepthPic = GetPicFromList(m_pcDepthRefPicsList, uiPOC, uiViewId);
+	if(pcPic->getSlice(0)->getDepthPic()!=NULL && pcPic->getSlice(0)->getDepthPic()->getReconMark())
+		pcDepthPic = pcPic->getSlice(0)->getDepthPic();
+	else
+		pcDepthPic = NULL;
+
+	if(pcDepthPic!=NULL)
+	{
+	  pDepth = pcDepthPic->getPicYuvRec()->getLumaAddr();
+	  iStride = pcDepthPic->getPicYuvRec()->getStride();
+
+	  for( UInt uiIdx = 0; uiIdx < uiViewId; uiIdx++ )
+	  //for( UInt uiIdx = uiViewId-1; uiIdx >= uiViewId; uiIdx-- )
+	  {
+	    uiRefViewId = uiIdx;
+
+		pcRefPic = GetPicFromList(m_pcRefPicsList, uiPOC, uiRefViewId);
+		assert(pcRefPic!=NULL);//test
+		if(pcRefPic==NULL) return false; //No ref pic with current POC and RefView found in ref list!!!
+
+		if(!pcRefPic->getSlice(0)->isIntra()) bIsRefNoISliceAvailable = true;
+		else bIsAnchorPicture = true;
+
+		//ppiShiftLUTLeft = m_pcCameraData->getBaseViewShiftLUTI()[uiViewId][uiRefViewId];
+		ppiShiftLUTLeft = m_aiBaseViewShiftLUT[uiViewId][uiRefViewId];
+
+		clearTemp();
+
+		for(iCurY=0; iCurY<(Int)m_uiHeight; iCurY++)
+			for(iCurX=0; iCurX<(Int)m_uiWidth; iCurX++)
+			{
+				//Check if point already has its reference:
+				if(m_ppiMvPtCorrX[iCurY][iCurX]!=TComMP::OCCLUSION && m_ppiMvPtCorrY[iCurY][iCurX]!=TComMP::OCCLUSION) continue;
+
+				iDepth = pDepth[ iCurX + iCurY * iStride ];
+				iDepth = RemoveBitIncrement(iDepth);
+				assert( iDepth >= 0 && iDepth <= 256 );					
+				
+				//if(bIsLeft) iDisparity = ppiShiftLUTLeft[0][iDepth];
+				//else iDisparity = -ppiShiftLUTLeft[0][iDepth];
+				iDisparity = ppiShiftLUTLeft[0][iDepth]; //!!!
+
+				iRefX = iCurX - ( ( iDisparity + 2 ) >> 2 );
+				iRefY = iCurY;
+
+				if(iRefX>=0 && iRefX<m_uiWidth && iRefY>=0 && iRefY<m_uiHeight)
+				{
+					iSrcX = m_ppiTempMvPtCorrX[iRefY][iRefX];
+					iSrcY = m_ppiTempMvPtCorrY[iRefY][iRefX];
+
+					if(iSrcX==TComMP::OCCLUSION || iSrcY==TComMP::OCCLUSION)
+					{
+						m_ppiMvPtCorrRefViewIdx[iCurY][iCurX] = (Short)uiRefViewId;
+						m_ppiMvPtCorrX[iCurY][iCurX] = (Short)iRefX;
+						m_ppiMvPtCorrY[iCurY][iCurX] = (Short)iRefY;
+
+						m_ppiMvPtCorrZ[iCurY][iCurX] = (Short)iDepth;
+						//m_ppiMvPtCorrZ[iCurY][iCurX] = (Short)iDisparity;						
+
+						pcRefCU = pcRefPic->getCU((UInt)(iRefY/pcRefPic->getSlice(0)->getSPS()->getMaxCUHeight()*pcRefPic->getFrameWidthInCU() + iRefX/pcRefPic->getSlice(0)->getSPS()->getMaxCUWidth()));
+
+						m_pppcRefCU[iCurY][iCurX] = pcRefCU;
+						m_ppuicRefPartAddr[iCurY][iCurX] = (UShort)g_auiRasterToZscan[(iRefY-pcRefCU->getCUPelY())/pcRefPic->getMinCUHeight()*pcRefPic->getNumPartInWidth()+(iRefX-pcRefCU->getCUPelX())/pcRefPic->getMinCUWidth()];
+
+						m_ppiTempMvPtCorrX[iRefY][iRefX] = iCurX;
+						m_ppiTempMvPtCorrY[iRefY][iRefX] = iCurY;
+						m_ppiTempMvPtCorrZ[iRefY][iRefX] = (Short)iDepth;
+						//m_ppiTempMvPtCorrZ[iRefY][iRefX] = (Short)iDisparity;
+					}
+					else if((Short)iDepth>m_ppiTempMvPtCorrZ[iRefY][iRefX]) //Point assigned earlier to this location is occluded
+					//else if((Short)iDisparity>m_ppiTempMvPtCorrZ[iRefY][iRefX]) //Point assigned earlier to this location is occluded
+					{
+						m_ppiMvPtCorrRefViewIdx[iCurY][iCurX] = (Short)uiRefViewId;
+						m_ppiMvPtCorrX[iCurY][iCurX] = (Short)iRefX;
+						m_ppiMvPtCorrY[iCurY][iCurX] = (Short)iRefY;
+
+						m_ppiMvPtCorrZ[iCurY][iCurX] = (Short)iDepth;
+						//m_ppiMvPtCorrZ[iCurY][iCurX] = (Short)iDisparity;						
+
+						pcRefCU = pcRefPic->getCU((UInt)(iRefY/pcRefPic->getSlice(0)->getSPS()->getMaxCUHeight()*pcRefPic->getFrameWidthInCU() + iRefX/pcRefPic->getSlice(0)->getSPS()->getMaxCUWidth()));
+
+						m_pppcRefCU[iCurY][iCurX] = pcRefCU;
+						m_ppuicRefPartAddr[iCurY][iCurX] = (UShort)g_auiRasterToZscan[(iRefY-pcRefCU->getCUPelY())/pcRefPic->getMinCUHeight()*pcRefPic->getNumPartInWidth()+(iRefX-pcRefCU->getCUPelX())/pcRefPic->getMinCUWidth()];
+
+						m_ppiTempMvPtCorrX[iRefY][iRefX] = iCurX;
+						m_ppiTempMvPtCorrY[iRefY][iRefX] = iCurY;
+						m_ppiTempMvPtCorrZ[iRefY][iRefX] = (Short)iDepth;
+						//m_ppiTempMvPtCorrZ[iRefY][iRefX] = (Short)iDisparity;
+						
+						//Mark point assigned earlier to this location as occluded:
+						m_ppiMvPtCorrRefViewIdx[iSrcY][iSrcX] = TComMP::OCCLUSION;
+						m_ppiMvPtCorrX[iSrcY][iSrcX] = TComMP::OCCLUSION;
+						m_ppiMvPtCorrY[iSrcY][iSrcX] = TComMP::OCCLUSION;
+
+						//m_ppiMvPtCorrZ[iSrcY][iSrcX] = 0x7FFF;
+						m_ppiMvPtCorrZ[iSrcY][iSrcX] = TComMP::OCCLUSION;						
+
+						m_pppcRefCU[iSrcY][iSrcX] = NULL;
+						m_ppuicRefPartAddr[iSrcY][iSrcX] = 0;						
+					}
+				}
+			}
+	  }
+	}
+	else
+#endif
+	{
 	iSynthViewIdx = uiViewId;
 
@@ -605,4 +764,5 @@
 			}
 	}
+      }
 #endif
 
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComMP.h	(revision 41)
@@ -69,4 +69,10 @@
   Short** m_ppiMvPtCorrZ;
   Short** m_ppiMvPtCorrRefViewIdx;
+
+#if !POZNAN_MP_USE_DEPTH_MAP_GENERATION && POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+  Short** m_ppiTempMvPtCorrX;
+  Short** m_ppiTempMvPtCorrY;
+  Short** m_ppiTempMvPtCorrZ;
+#endif
 
   TComDataCU*** m_pppcRefCU; //XY array of pointers to reference CU for each point of picture
@@ -117,4 +123,7 @@
   //Void			init(UInt uiHeight, UInt uiWidth, TAppComCamPara* pcCameraData);
   Void			init(UInt uiHeight, UInt uiWidth, Int**** aiBaseViewShiftLUT);
+#if POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE
+  Void			clearTemp();
+#endif
 #endif
   Void			uninit();
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 41)
@@ -457,8 +457,11 @@
 }
 #if POZNAN_NONLINEAR_DEPTH
-Void TComPicYuv::nonlinearDepthForward(TComPicYuv *pcPicDst, Float p)
-{
-  Int		x,y;
-  TComNonlinearDepthForward cNonlinearDepthFwd(p, g_uiBitIncrement, g_uiBitIncrement);
+Void TComPicYuv::nonlinearDepthForward(TComPicYuv *pcPicDst, TComNonlinearDepthModel &rcNonlinearDepthModel)
+{
+  Int		x,y,i;
+  Int   LUT[256];
+
+  for (i=0; i<256; ++i)
+    LUT[i] = (Int)rcNonlinearDepthModel.ForwardI(i, 1<<g_uiBitIncrement);
 
   // Luma
@@ -469,5 +472,5 @@
     for(x=0; x<m_iPicWidth; x++)
     {
-      pPelDst[x] = (Pel)( cNonlinearDepthFwd(pPelSrc[x]) + 0.5);
+      pPelDst[x] = LUT[RemoveBitIncrement(pPelSrc[x])];
     }
     pPelDst += pcPicDst->getStride();
@@ -478,8 +481,12 @@
   copyToPicCr(pcPicDst);
 }
-Void TComPicYuv::nonlinearDepthBackward(TComPicYuv *pcPicDst, Float p)
-{
-  Int		x,y;
-  TComNonlinearDepthBackward cNonlinearDepthBwd(p, g_uiBitIncrement, g_uiBitIncrement);
+
+Void TComPicYuv::nonlinearDepthBackward(TComPicYuv *pcPicDst, TComNonlinearDepthModel &rcNonlinearDepthModel)
+{
+  Int   x,y,i;
+  Int   LUT[256];
+
+  for (i=255; i>=0; --i)
+    LUT[i] = (Int)rcNonlinearDepthModel.BackwardI(i, 1<<g_uiBitIncrement ); // +0.5;
 
   // Luma
@@ -490,5 +497,5 @@
     for(x=0; x<m_iPicWidth; x++)
     {
-      pPelDst[x] = (Pel)( cNonlinearDepthBwd(pPelSrc[x]) + 0.5);
+      pPelDst[x] = LUT[RemoveBitIncrement(pPelSrc[x])];
     }
     pPelDst += pcPicDst->getStride();
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPicYuv.h	(revision 41)
@@ -44,54 +44,4 @@
 #include "CommonDef.h"
 
-#if POZNAN_NONLINEAR_DEPTH
-
-#include <math.h>
-
-class TComNonlinearDepthForward // OLGIERD - Z-NL-Power conversion
-{
-private:
-  Double m_fMul;
-  Float m_fPower;
-
-public:
-
-  TComNonlinearDepthForward(Float fPower, Int iInputBitIncrement, Int iOutputBitIncrement)
-  {
-    m_fPower = fPower;
-    Double fPostMul = (1<<(8+iOutputBitIncrement))-1; // OLGIERD ToDo - should be or not?
-    Double fPreMul  = 1.0/((1<<(8+iInputBitIncrement))-1);
-    m_fMul = fPostMul*pow(fPreMul,(Double)fPower);
-  };
-
-  inline Double operator() (Double Value)
-  {    
-    if (Value<0) return -pow( -Value,(Double)m_fPower)*m_fMul;
-    return pow(Value,(Double)m_fPower)*m_fMul;
-  };
-};
-
-class TComNonlinearDepthBackward // OLGIERD - Z-NL-Power conversion
-{
-private:
-  Double m_fMul;
-  Float m_fPower;
-
-public:
-
-  TComNonlinearDepthBackward(Float fPower, Int iInputBitIncrement, Int iOutputBitIncrement) 
-  {     
-    m_fPower = fPower = 1.0/fPower;
-    Double fPostMul = (1<<(8+iOutputBitIncrement))-1; // OLGIERD ToDo - should be or not?
-    Double fPreMul  = 1.0/((1<<(8+iInputBitIncrement))-1);
-    m_fMul = fPostMul*pow(fPreMul,(Double)fPower);
-  };
-
-  inline Double operator() (Double Value)
-  {    
-    if (Value<0) return -pow( -Value,(Double)m_fPower)*m_fMul;
-    return pow(Value,(Double)m_fPower)*m_fMul;
-  };
-};
-#endif
 // ====================================================================================================================
 // Class definition
@@ -226,6 +176,6 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  Void nonlinearDepthForward(TComPicYuv *pcPicDst, Float p);
-  Void nonlinearDepthBackward(TComPicYuv *pcPicDst, Float p);
+  Void nonlinearDepthForward(TComPicYuv *pcPicDst, TComNonlinearDepthModel &rcNonlinearDepthModel);
+  Void nonlinearDepthBackward(TComPicYuv *pcPicDst, TComNonlinearDepthModel &rcNonlinearDepthModel);
 #endif
 };// END CLASS DEFINITION TComPicYuv
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp	(revision 41)
@@ -1639,4 +1639,9 @@
   TComMv	  mv0_2nd,mv1_2nd;
 
+#if DEPTH_MAP_GENERATION
+  Int		  ref_frame0_idx_1st, ref_frame1_idx_1st;
+  TComMv	  mv0_1st,mv1_1st;
+#endif
+
   Pel* piDstCb;
   Pel* piDstCr;
@@ -1684,4 +1689,11 @@
       iWidth  >>= uiSubSampExpX;
       iHeight >>= uiSubSampExpY;
+
+      //save orginal motion field of CU (it will be overwritten during the motion compensation)
+      ref_frame0_idx_1st = pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiPartAddr);
+      mv0_1st = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( uiPartAddr );
+
+      ref_frame1_idx_1st = pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiPartAddr);
+      mv1_1st = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( uiPartAddr );
     }
 #endif
@@ -1804,9 +1816,9 @@
 
 	//set motion data representing CU with DBMP 
+	PartSize ePartSize = pcCU->getPartitionSize( uiPartAddr ); //PartSize ePartSize = pcCU->getPartitionSize( 0 );
 #if DEPTH_MAP_GENERATION
 	if( !bPrdDepthMap )
 #endif
 	{
-		PartSize ePartSize = pcCU->getPartitionSize( uiPartAddr ); //PartSize ePartSize = pcCU->getPartitionSize( 0 );
 #if POZNAN_DBMP_CALC_PRED_DATA
 		pcMP->xCalcDBMPPredData(uiPointCnt, ref_frame0_idx, mv0, ref_frame1_idx, mv1);
@@ -1819,4 +1831,12 @@
 #endif
 	}
+
+#if DEPTH_MAP_GENERATION
+	if( bPrdDepthMap )
+	{
+		pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( mv0_1st, ref_frame0_idx_1st, ePartSize, uiPartAddr, iPartIdx, 0 );
+		pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( mv1_1st, ref_frame1_idx_1st, ePartSize, uiPartAddr, iPartIdx, 0 );
+	}
+#endif
 
 	if ( iPartIdxOrg >= 0 ) break;
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp	(revision 41)
@@ -85,4 +85,5 @@
   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
   m_pcTexturePic = NULL;
+  m_pcDepthPic = NULL; 
 #ifdef WEIGHT_PRED
   resetWpScaling(m_weightPredTable);
@@ -113,4 +114,5 @@
   ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
   m_pcTexturePic = NULL;
+  m_pcDepthPic = NULL; 
   
   initEqualRef();
@@ -703,4 +705,7 @@
   m_bUseDMM = false;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  m_bUseDMM34 = false;
+#endif
 }
 
@@ -747,5 +752,5 @@
   }
 #if POZNAN_NONLINEAR_DEPTH
-  m_fDepthPower = 1.0;
+  m_cNonlinearDepthModel.Clear();
 #endif
 #if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
@@ -768,5 +773,5 @@
   ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) );
 #if POZNAN_NONLINEAR_DEPTH
-  m_fDepthPower = 1.0;
+  m_cNonlinearDepthModel.Clear();
 #endif
 }
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h	(revision 41)
@@ -139,4 +139,7 @@
   Bool  m_bUseDMM;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool  m_bUseDMM34;
+#endif
 
 #if DEPTH_MAP_GENERATION
@@ -169,5 +172,6 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  Float  m_fDepthPower;
+  TComNonlinearDepthModel m_cNonlinearDepthModel;   
+  Bool  m_bUseNonlinearDepth;
 #endif
 
@@ -258,5 +262,8 @@
   Void setUseDMM( Bool b ) { m_bUseDMM = b;    }
 #endif
-
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool getUseDMM34()         { return m_bUseDMM34; }
+  Void setUseDMM34( Bool b ) { m_bUseDMM34 = b;    }
+#endif
 
 #if DCM_COMB_LIST
@@ -295,5 +302,5 @@
   Void setUseSAO                  (Bool bVal)  {m_bUseSAO = bVal;}
 #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU //todo fix SAO
-  Bool getUseSAO     ()         { return (getViewId()>0)?false:m_bUseSAO;}
+  Bool getUseSAO     ()           { return (getUseCUSkip() && getViewId()>0)?false:m_bUseSAO;}
 #else
   Bool getUseSAO                  ()           {return m_bUseSAO;}
@@ -354,8 +361,8 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-  inline Void    setDepthPower(Float p)   {m_fDepthPower = p;}
-  inline Float	 getDepthPower()          {return m_fDepthPower;}
-#else
-  inline Float	 getDepthPower()          {return 1.0f;}
+  inline Void                            setNonlinearDepthModel( TComNonlinearDepthModel &rp ){ m_cNonlinearDepthModel = rp; }
+  inline TComNonlinearDepthModel&        getNonlinearDepthModel()                             { return m_cNonlinearDepthModel; }
+  Bool                    getUseNonlinearDepth()                                              { return m_bUseNonlinearDepth; }
+  Void                    setUseNonlinearDepth( Bool bVal )                                   { m_bUseNonlinearDepth = bVal; }
 #endif
 #if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
@@ -459,4 +466,5 @@
   Int         m_iDepth;
   TComPic*    m_pcTexturePic;
+  TComPic*    m_pcDepthPic;
 
   // referenced slice?
@@ -664,5 +672,7 @@
 
   Void setTexturePic( TComPic *pcTexturePic ) { m_pcTexturePic = pcTexturePic; }
+  Void setDepthPic  ( TComPic *pcDepthPic   ) { m_pcDepthPic   = pcDepthPic;   }
   TComPic *getTexturePic() const { return m_pcTexturePic; }
+  TComPic *getDepthPic()   const { return m_pcDepthPic; }
 
 #ifdef WEIGHT_PRED
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h	(revision 41)
@@ -40,6 +40,7 @@
 
 
-
-#define SONY_COLPIC_AVAILABILITY  		  1
+#define FLEX_CODING_ORDER               1
+
+#define SONY_COLPIC_AVAILABILITY        1
 
 //>>>>> HHI 3DV tools >>>>>
@@ -83,6 +84,6 @@
 #define POZNAN_CU_SKIP_PSNR         1 //Poznan Cu Skip Display psnr of the codded CUs only
 
-#define POZNAN_NONLINEAR_DEPTH              1	 /// Non-linear depth processing (Maciej Kurc)
-#define POZNAN_NONLINEAR_DEPTH_SEND_AS_BYTE 1	 /// Send DepthPower as byte instead of float
+#define POZNAN_NONLINEAR_DEPTH              1	 /// Non-linear depth processing
+#define POZNAN_NONLINEAR_DEPTH_THRESHOLD    1  /// Non-linear depth thrasholding
 
 #if POZNAN_SYNTH 
@@ -106,4 +107,8 @@
 										                                                        //			POZNAN_MP_USE_DEPTH_MAP_GENERATION=1 - use DEPTH_MAP_GENERATION, 
 										                                                        //			POZNAN_MP_USE_DEPTH_MAP_GENERATION=0 - use reconstructed depth maps from neighboring views
+
+#if !POZNAN_MP_USE_DEPTH_MAP_GENERATION 
+#define POZNAN_MP_USE_CURRENT_VIEW_DEPTH_MAP_IF_AVAILABLE 1 // Depth-Based Multiview Prediction of CU parameters will use depth picture of current view if this picture is available, otherwise reference view depth is utilized
+#endif
 
 #define POZNAN_MP_FILL                             1    // Depth-Based Multiview Prediction of CU parameters with fill option for occluded areas
@@ -407,5 +412,4 @@
 typedef       unsigned long       ULong;
 typedef       double              Double;
-typedef       float               Float;
 
 // ====================================================================================================================
Index: branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 41)
@@ -238,10 +238,8 @@
 #endif
 #if POZNAN_DBMP
-	  xReadFlag( uiCode );
-	  pcSPS->setDBMP  ( uiCode );
+  xReadFlag( uiCode ); pcSPS->setDBMP  ( uiCode );
 #endif
 #if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
-	  xReadFlag( uiCode );
-	  pcSPS->setUseCUSkip ( uiCode );
+  xReadFlag( uiCode ); pcSPS->setUseCUSkip ( uiCode );
 #endif
   xReadFlag( uiCode ); // SPS base view flag
@@ -279,15 +277,22 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-#if POZNAN_NONLINEAR_DEPTH_SEND_AS_BYTE
-      uiCode = 0;
-      xReadCode(8, uiCode);
-      pcSPS->setDepthPower(dequantizeDepthPower(uiCode));
-#else
-      uiCode = 0;
-      xReadCode(sizeof(float)*8, uiCode); // We do not send seign
-      //uiCode &= ~0x80000000;
-      pcSPS->setDepthPower(*((float*)&uiCode));  
-#endif
-      printf("\nfDepthPower = %f", pcSPS->getDepthPower());
+      xReadFlag( uiCode );
+      pcSPS->setUseNonlinearDepth( uiCode ? true : false );
+      pcSPS->getNonlinearDepthModel().Clear();
+      if( uiCode )
+      {
+        uiCode = 0; //Owieczka Necessary??
+        xReadUvlc( uiCode ); 
+        int num = pcSPS->getNonlinearDepthModel().m_iNum = uiCode;
+        for (int i=1; i<=num; ++i)
+        {
+          uiCode = 0;
+          xReadUvlc( uiCode ); 
+          pcSPS->getNonlinearDepthModel().m_aiPoints[i] = uiCode;      
+        }
+        pcSPS->getNonlinearDepthModel().m_aiPoints[0] = 0;
+        pcSPS->getNonlinearDepthModel().m_aiPoints[num+1] = 0;
+        pcSPS->getNonlinearDepthModel().Init();
+      }
 #endif
     }
Index: branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp	(revision 41)
@@ -90,5 +90,6 @@
   m_uiMaxViewId             = 0;
 #if POZNAN_NONLINEAR_DEPTH
-  m_fDepthPower             = 1.0;
+  m_cNonlinearDepthModel.Clear();
+  m_bUseNonlinearDepth      = false;
 #endif
 }
@@ -140,22 +141,18 @@
   Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
 
+
+  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
+  {
+
+    // real-valued look-up tables
 #if POZNAN_NONLINEAR_DEPTH
-  TComNonlinearDepthBackward cNonlinearDepthBwd(m_fDepthPower, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0, (POZNAN_LUT_INCREASED_PRECISION) ? g_uiBitIncrement : 0);
-#endif
-
-  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
-  {
-    Double  dDepthValue = (Double)uiDepthValue;
-    Int64   iDepthValue = (Int64)uiDepthValue;
-#if POZNAN_NONLINEAR_DEPTH
-    dDepthValue = cNonlinearDepthBwd(dDepthValue);
-    iDepthValue = (Int64)(dDepthValue+0.5);
-#endif
-#if POZNAN_LUT_INCREASED_PRECISION
-    dDepthValue /= (1<<g_uiBitIncrement);
-#endif
-
-    // real-valued look-up tables
-    Double  dShiftLuma      = ( dDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+    Double  dShiftLuma;
+    if( m_bUseNonlinearDepth )
+      dShiftLuma      = ( m_cNonlinearDepthModel.BackwardD( (Double)uiDepthValue, dScale) + dOffset ) * Double( 1 << m_iLog2Precision );
+    else
+      dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+#else
+    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
+#endif
     Double  dShiftChroma    = dShiftLuma / 2;
     radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
@@ -163,7 +160,12 @@
 
     // integer-valued look-up tables
-    Int64   iTempScale      = iDepthValue * iScale;
-#if POZNAN_LUT_INCREASED_PRECISION
-    iTempScale >>= g_uiBitIncrement;
+#if POZNAN_NONLINEAR_DEPTH
+    Int64   iTempScale;
+    if( m_bUseNonlinearDepth )
+      iTempScale      = (Int64)m_cNonlinearDepthModel.BackwardI(uiDepthValue, iScale);
+    else
+      iTempScale      = (Int64)uiDepthValue * iScale;
+#else
+    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
 #endif
     Int64   iTestScale      = ( iTempScale + iOffset       );   // for checking accuracy of camera parameters
@@ -233,5 +235,6 @@
   {
 #if POZNAN_NONLINEAR_DEPTH
-    m_fDepthPower = pcSlice->getSPS()->getDepthPower();
+    m_bUseNonlinearDepth = pcSlice->getSPS()->getUseNonlinearDepth();
+    m_cNonlinearDepthModel = pcSlice->getSPS()->getNonlinearDepthModel();    
 #endif
     return;
@@ -240,5 +243,6 @@
   {
 #if POZNAN_NONLINEAR_DEPTH
-    pcSlice->getSPS()->setDepthPower(m_fDepthPower); // OLGIERD: ToDo - QP-Tex should not use getDepthPower() from texture SPS.
+    pcSlice->getSPS()->setUseNonlinearDepth(m_bUseNonlinearDepth);
+    pcSlice->getSPS()->setNonlinearDepthModel(m_cNonlinearDepthModel); // OLGIERD: ToDo - QP-Tex should not use getDepthPower() from texture SPS.
 #endif
   }
@@ -684,5 +688,9 @@
 
 #if DCM_SKIP_DECODING_FRAMES
+#if FLEX_CODING_ORDER
+Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay, Bool& bNewPictureType)
+#else
 Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay)
+#endif
 #else
 Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS )
@@ -712,4 +720,7 @@
       TComSPS cTempSPS;
       m_cEntropyDecoder.decodeSPS( &cTempSPS );
+#if FLEX_CODING_ORDER
+      m_cNewSPS = cTempSPS;
+#endif
 
       if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
@@ -724,6 +735,6 @@
         if(!cTempSPS.isDepth() && cTempSPS.getViewId())
         {
-          Float fDepthPower = getDecTop()->getPicFromView( 0, pcPic->getPOC(), true )->getSPS()->getDepthPower();
-          cTempSPS.setDepthPower(fDepthPower);
+          cTempSPS.setUseNonlinearDepth(getDecTop()->getPicFromView( 0, pcPic->getPOC(), true )->getSPS()->getUseNonlinearDepth());
+          cTempSPS.setNonlinearDepthModel(getDecTop()->getPicFromView( 0, pcPic->getPOC(), true )->getSPS()->getNonlinearDepthModel());
         }
 #endif
@@ -802,4 +813,7 @@
       {
         m_uiPrevPOC = m_apcSlicePilot->getPOC();
+#if FLEX_CODING_ORDER
+        bNewPictureType = m_cNewSPS.isDepth();
+#endif
         return true;
       }
@@ -887,8 +901,23 @@
         // Set reference list
         std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
-        TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
+        TComPic * const pcTexturePic = ( m_cSPS.isDepth()) ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
+        TComPic * const pcDepthPic   = (!m_cSPS.isDepth()) ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), true  ) : NULL; 
+#if FLEX_CODING_ORDER
+        if (pcTexturePic != NULL)
+        {
+          assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
+          pcSlice->setTexturePic( pcTexturePic );
+        }
+        if (pcDepthPic != NULL)
+        {
+          assert(   m_cSPS.isDepth() || pcDepthPic != NULL );
+          pcSlice->setDepthPic( pcDepthPic );
+        }
+#else
         assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
         pcSlice->setTexturePic( pcTexturePic );
+        pcSlice->setDepthPic( pcDepthPic );
         pcSlice->setViewIdx( pcPic->getViewIdx() );
+#endif
 #if SONY_COLPIC_AVAILABILITY
         pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
@@ -949,5 +978,10 @@
       //*
 #if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
+#if FLEX_CODING_ORDER
+      Bool bHaveReconDepth = (pcSlice->getDepthPic() != NULL) && (pcSlice->getDepthPic()->getReconMark());
+      if(!getIsDepth() && pcSlice->getSPS()->getUseTexDqpAccordingToDepth() && !bHaveReconDepth )
+#else
       if(!getIsDepth() && pcSlice->getSPS()->getUseTexDqpAccordingToDepth())
+#endif
       {
         getDecTop()->storeDepthSynthPicsInBuffer(pcSlice->getViewIdx(),pcSlice->getSPS()->getViewOrderIdx(),pcSlice->getPOC());
Index: branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.h	(revision 41)
@@ -121,5 +121,6 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-  Float               m_fDepthPower;
+  TComNonlinearDepthModel m_cNonlinearDepthModel; 
+  Bool m_bUseNonlinearDepth;
 #endif
 
@@ -205,4 +206,7 @@
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
   TComSPS                 m_cSPS;
+#if FLEX_CODING_ORDER
+  TComSPS                 m_cNewSPS;
+#endif
   TComPPS                 m_cPPS;
   TComSlice*              m_apcSlicePilot;
@@ -265,5 +269,9 @@
   Void  init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance = true );
 #if DCM_SKIP_DECODING_FRAMES
+#if FLEX_CODING_ORDER
+  Bool  decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame, Int& iPOCLastDisplay, Bool& bNewPictureType);
+#else
   Bool  decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame, Int& iPOCLastDisplay);
+#endif
 #else
   Void  decode ( Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS );
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 41)
@@ -348,14 +348,16 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-      // Depth power coefficient
-#if POZNAN_NONLINEAR_DEPTH_SEND_AS_BYTE
-      UInt  uiCode = quantizeDepthPower(pcSPS->getDepthPower());  
-      xWriteCode(uiCode, 8); 
-#else
-      float fCode  = pcSPS->getDepthPower();
-      UInt  uiCode = *((UInt*)&fCode);
-      //uiCode &= ~0x80000000;
-      xWriteCode(uiCode, sizeof(float)*8); // we do not send sign?;
-#endif
+      if( pcSPS->getUseNonlinearDepth() )
+      {
+        xWriteFlag( 1 ); //Nonlinear Depth Representation
+        // Nonlinear Depth Model coefficient
+        xWriteUvlc(pcSPS->getNonlinearDepthModel().m_iNum);
+        for (int i=1; i<=pcSPS->getNonlinearDepthModel().m_iNum; ++i)
+          xWriteUvlc(pcSPS->getNonlinearDepthModel().m_aiPoints[i]);
+      }
+      else
+      {
+        xWriteFlag( 0 ); // Don't use Nonlinear Depth Representation
+      }
 #endif
     }
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h	(revision 41)
@@ -159,4 +159,7 @@
   Bool m_bUseDMM;
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Bool m_bUseDMM34;
+#endif
 #if HHI_MPI
   Bool m_bUseMVI;
@@ -232,5 +235,6 @@
 #endif
 #if POZNAN_NONLINEAR_DEPTH
-  Float 	m_fDepthPower;
+  TComNonlinearDepthModel  m_cNonlinearDepthModel;
+  Bool        m_bUseNonlinearDepth;
 #endif
 
@@ -335,8 +339,9 @@
 
 #if POZNAN_NONLINEAR_DEPTH
-  inline Float   getDepthPower()               { return m_fDepthPower; }
-  inline Void    setDepthPower(Float p)        { m_fDepthPower = p; }
-#else
- inline Float    getDepthPower()               { return 1.0f; }
+  inline TComNonlinearDepthModel&   getNonlinearDepthModel()                                    { return m_cNonlinearDepthModel; }
+  inline Void                       setNonlinearDepthModel( TComNonlinearDepthModel &rp )       { m_cNonlinearDepthModel = rp; }
+
+  Void                              setUseNonlinearDepth  ( Bool bVal )                         { m_bUseNonlinearDepth = bVal; }
+  bool                              getUseNonlinearDepth  ()                                    { return m_bUseNonlinearDepth; }
 #endif
 
@@ -457,5 +462,8 @@
   Bool getUseDMM()        { return m_bUseDMM; }
 #endif
-
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  Void setUseDMM34( Bool b) { m_bUseDMM34 = b;    }
+  Bool getUseDMM34()        { return m_bUseDMM34; }
+#endif
 #if LM_CHROMA
   Bool getUseLMChroma                       ()      { return m_bUseLMChroma;        }
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 41)
@@ -175,7 +175,10 @@
 // GT FIX
   std::vector<TComPic*> apcSpatRefPics = m_pcEncTop->getEncTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_pcEncTop->isDepthCoder() );
-  TComPic * const pcTexturePic = m_pcEncTop->isDepthCoder() ? m_pcEncTop->getEncTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
+  TComPic * const pcTexturePic = ( m_pcEncTop->isDepthCoder()) ? m_pcEncTop->getEncTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
+  TComPic * const pcDepthPic   = (!m_pcEncTop->isDepthCoder()) ? m_pcEncTop->getEncTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), true  ) : NULL; 
   assert( ! m_pcEncTop->isDepthCoder() || pcTexturePic != NULL );
+  assert(   m_pcEncTop->isDepthCoder() || pcDepthPic   != NULL );
   pcSlice->setTexturePic( pcTexturePic );
+  pcSlice->setDepthPic  ( pcDepthPic   );
 
   pcSlice->setRefPicListFromGOPSTring( rcListPic, apcSpatRefPics );
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 41)
@@ -1178,4 +1178,11 @@
 #endif
 #if HHI_DMM_PRED_TEX
+#if FLEX_CODING_ORDER
+    if ( !pcCU->getSlice()->getSPS()->getUseDMM34() )
+    {
+      assert( uiDir != DMM_WEDGE_PREDTEX_D_IDX );
+      assert( uiDir != DMM_CONTOUR_PREDTEX_D_IDX );
+    }
+#endif
     if( uiDir == DMM_WEDGE_PREDTEX_D_IDX )     { xCodeWedgePredTexDeltaInfo  ( pcCU, uiAbsPartIdx ); }
     if( uiDir == DMM_CONTOUR_PREDTEX_D_IDX )   { xCodeContourPredTexDeltaInfo( pcCU, uiAbsPartIdx ); }
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 41)
@@ -1934,4 +1934,8 @@
 #endif
 #if HHI_DMM_PRED_TEX
+#if FLEX_CODING_ORDER
+      if ( pcCU->getSlice()->getSPS()->getUseDMM34() )
+      {
+#endif
       TComYuv cTempYuv; cTempYuv.create( uiWidth, uiHeight ); cTempYuv.clear();
       Pel* piTempY      = cTempYuv.getLumaAddr();
@@ -1968,4 +1972,7 @@
 
       cTempYuv.destroy();
+#if FLEX_CODING_ORDER
+      }
+#endif
 #endif
     }
@@ -1996,5 +2003,9 @@
 #else
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+      if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getUseDMM34() ) )
+#else
       if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
+#endif
         continue;
 #endif
@@ -2084,5 +2095,9 @@
 #else
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+      if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight, pcCU->getSlice()->getSPS()->getUseDMM34() ) )
+#else
       if( m_pcEncCfg->isDepthCoder() && !predIntraLumaDMMAvailable( uiOrgMode, uiWidth, uiHeight ) )
+#endif
         continue;
 #endif
@@ -2727,5 +2742,9 @@
 }
 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+Bool TEncSearch::predIntraLumaDMMAvailable( UInt uiMode, UInt uiWidth, UInt uiHeight, Bool bDMMAvailable34 )
+#else
 Bool TEncSearch::predIntraLumaDMMAvailable( UInt uiMode, UInt uiWidth, UInt uiHeight )
+#endif
 {
   if( uiMode <= MAX_MODE_ID_INTRA_DIR ) return true;
@@ -2755,4 +2774,10 @@
       bDMMAvailable = false;
     }
+#if FLEX_CODING_ORDER
+    if ( !bDMMAvailable34 )
+    {
+      bDMMAvailable = false;
+    }
+#endif
   }
 
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.h	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSearch.h	(revision 41)
@@ -210,5 +210,10 @@
   Bool predIntraLumaDMMAvailable( UInt         uiMode, 
                                   UInt         uiWidth, 
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+                                  UInt         uiHeight, 
+                                  Bool         bDMMAvailable34 );
+#else
                                   UInt         uiHeight );
+#endif
 #endif
 #if HHI_DMM_WEDGE_INTRA
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp	(revision 41)
@@ -304,6 +304,9 @@
 
   bool bSomethingCoded = false ;
-
+#if FLEX_CODING_ORDER  
+  if (TEncTop::m_bPicWaitingForCoding )
+#else
   if (m_bPicWaitingForCoding )
+#endif
   {
     std::map<Int, TComPic*>::iterator cIter = m_acInputPicMap.find( (Int)m_cSeqIter.getPoc() );
@@ -659,7 +662,8 @@
 #endif
 
-#if POZNAN_NONLINEAR_DEPTH
-  m_cSPS.setDepthPower  ( m_fDepthPower );
-  // OLGIERD: ToDo - QP-Tex should not use getDepthPower() from texture SPS.
+#if POZNAN_NONLINEAR_DEPTH 
+  m_cSPS.setNonlinearDepthModel  ( m_cNonlinearDepthModel );
+  m_cSPS.setUseNonlinearDepth    ( m_bUseNonlinearDepth );
+  // OLGIERD: ToDo - QP-Tex should not use getNonlinearDepthModel() from texture SPS.
 #endif
 
Index: branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenSingleModel.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenSingleModel.cpp	(revision 41)
@@ -448,5 +448,5 @@
       m_iLastOccludedSPosFP = xRangeLeftL( m_iLastOccludedSPos );
       xExtrapolateMarginL  ( iCurSPos, iEndChangePos, iError );
-      iMinChangedSPos       = Min( iMinChangedSPos, (iEndChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iEndChangePos], m_piNewDepthData[iPosXinNewData] )) ]);
+      iMinChangedSPos       = Min( iMinChangedSPos, (iEndChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iEndChangePos], m_piNewDepthData[iPosXinNewData] )) ]);
       iLastSPos             = iCurSPos;
       m_iLastDepth          = m_iCurDepth;
@@ -466,5 +466,5 @@
     {
       // Get minimal changed sample position
-      iMinChangedSPos = Min( iMinChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iCurPosX], m_piNewDepthData[iPosXinNewData] )) ]);
+      iMinChangedSPos = Min( iMinChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iCurPosX], m_piNewDepthData[iPosXinNewData] )) ]);
       Int iCurSPos    = xShiftNewData(iCurPosX,iPosXinNewData);
       m_iCurDepth     = m_piNewDepthData[iPosXinNewData];
@@ -541,5 +541,5 @@
       m_iLastOccludedSPosFP = xRangeRightR( m_iLastOccludedSPos );
       xExtrapolateMarginR     ( iCurSPos, iStartChangePos, iError );
-      iMaxChangedSPos       = Max( iMaxChangedSPos, (iStartChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iStartChangePos], m_piNewDepthData[iPosXinNewData] )) ]);
+      iMaxChangedSPos       = Max( iMaxChangedSPos, (iStartChangePos << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iStartChangePos], m_piNewDepthData[iPosXinNewData] )) ]);
       iLastSPos             = iCurSPos;
       m_iLastDepth          = m_iCurDepth;
@@ -559,5 +559,5 @@
     {
       // Get minimal changed sample position
-      iMaxChangedSPos = Max( iMaxChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iCurPosX], m_piNewDepthData[iPosXinNewData] )) ]);
+      iMaxChangedSPos = Max( iMaxChangedSPos, (iCurPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( Max(m_apiBaseDepthPelRow[m_iCurViewPos][iCurPosX], m_piNewDepthData[iPosXinNewData] )) ]);
       Int iCurSPos    = xShiftNewData(iCurPosX,iPosXinNewData);
       m_iCurDepth     = m_piNewDepthData[iPosXinNewData];
@@ -948,5 +948,5 @@
   AOF( iPosInNewData < m_iNewDataWidth );
 
-  return (iPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( m_piNewDepthData[iPosInNewData] )];
+  return (iPosX << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( m_piNewDepthData[iPosInNewData] )];
 }
 
@@ -956,5 +956,5 @@
  AOT( iPosX <        0);
  AOF( iPosX < m_iWidth);
- return (iPosX  << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrementLUT( m_apiBaseDepthPelRow[m_iCurViewPos][iPosX] )];
+ return (iPosX  << m_iShiftPrec) - m_ppiCurLUT[0][ RemoveBitIncrement( m_apiBaseDepthPelRow[m_iCurViewPos][iPosX] )];
 }
 
@@ -1149,6 +1149,6 @@
       m_aapiSynthVideoPelRow                                   [1][2][iTargetSPos]  ,
 #endif
-      m_piInvZLUTLeft [RemoveBitIncrementLUT(m_iThisDepth)                            ],
-      m_piInvZLUTRight[RemoveBitIncrementLUT(m_apiSynthDepthPelRow[1]   [iTargetSPos])],
+      m_piInvZLUTLeft [RemoveBitIncrement(m_iThisDepth)                            ],
+      m_piInvZLUTRight[RemoveBitIncrement(m_apiSynthDepthPelRow[1]   [iTargetSPos])],
       iFilled,
       m_apiFilledRow                                           [1]   [iTargetSPos]  ,
@@ -1171,6 +1171,6 @@
       m_aapiBaseVideoPelRow                                    [1][2][iSourcePos ],
 #endif
-      m_piInvZLUTLeft [RemoveBitIncrementLUT(m_apiSynthDepthPelRow[0]   [iTargetSPos])],
-      m_piInvZLUTRight[RemoveBitIncrementLUT(m_iThisDepth)                            ],
+      m_piInvZLUTLeft [RemoveBitIncrement(m_apiSynthDepthPelRow[0]   [iTargetSPos])],
+      m_piInvZLUTRight[RemoveBitIncrement(m_iThisDepth)                            ],
       m_apiFilledRow                                           [0]   [iTargetSPos],
       iFilled                                                                     ,
Index: branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenTop.cpp	(revision 30)
+++ branches/0.3-poznan-univ/source/Lib/TLibRenderer/TRenTop.cpp	(revision 41)
@@ -498,5 +498,5 @@
 
       // compute disparity and shift
-      iShiftedPos  = ( iPosX << m_iRelShiftLUTPrec ) - m_aiShiftLUTCur[RemoveBitIncrementLUT( pcDepthData[iPosX])];
+      iShiftedPos  = ( iPosX << m_iRelShiftLUTPrec ) - m_aiShiftLUTCur[RemoveBitIncrement( pcDepthData[iPosX])];
 
       if (iPosX == 0)
@@ -652,6 +652,6 @@
 
         // compute disparity and shift
-        assert( RemoveBitIncrementLUT(pcDepthData[iPosX]) >= 0 && RemoveBitIncrementLUT(pcDepthData[iPosX]) <= SizeOfLUT );
-        dPrevShiftedPos  = (Double) iPosX - m_adShiftLUTCur[ RemoveBitIncrementLUT(pcDepthData[iPosX])];
+        assert( RemoveBitIncrement(pcDepthData[iPosX]) >= 0 && RemoveBitIncrement(pcDepthData[iPosX]) <= SizeOfLUT );
+        dPrevShiftedPos  = (Double) iPosX - m_adShiftLUTCur[ RemoveBitIncrement(pcDepthData[iPosX])];
 
         if (iPosX == 0)
@@ -833,6 +833,6 @@
     for(Int iPosX = 0; iPosX < iWidth; iPosX++)
     {
-      assert( RemoveBitIncrementLUT(pcDepthData[iPosX]) >= 0 && RemoveBitIncrementLUT(pcDepthData[iPosX]) <= SizeOfLUT );
-      Int iShiftedPos = iPosX - m_aiShiftLUTCur[ RemoveBitIncrementLUT(pcDepthData[iPosX])] ;
+      assert( RemoveBitIncrement(pcDepthData[iPosX]) >= 0 && RemoveBitIncrement(pcDepthData[iPosX]) <= SizeOfLUT );
+      Int iShiftedPos = iPosX - m_aiShiftLUTCur[ RemoveBitIncrement(pcDepthData[iPosX])] ;
       if (iShiftedPos < iWidth && iShiftedPos >= 0)
       {
@@ -908,5 +908,5 @@
     for(Int iPosX = 0; iPosX < iOutputWidth; iPosX ++)
     {
-      Int iBackShiftedPos = (iPosX << m_iRelShiftLUTPrec) - m_aiShiftLUTCur[ RemoveBitIncrementLUT( pcDepthData[iPosX] )];
+      Int iBackShiftedPos = (iPosX << m_iRelShiftLUTPrec) - m_aiShiftLUTCur[ RemoveBitIncrement( pcDepthData[iPosX] )];
       if( ( pcFilledData[iPosX] == REN_IS_FILLED )  && (iBackShiftedPos >= 0 ) && ( iBackShiftedPos < iInputWidth ) )
       {
@@ -981,5 +981,5 @@
     {
       // compute disparity and shift
-      iShiftedPos  =  iPosX - m_aiShiftLUTCur[RemoveBitIncrementLUT(pcDepthData[iPosX])];
+      iShiftedPos  =  iPosX - m_aiShiftLUTCur[RemoveBitIncrement(pcDepthData[iPosX])];
 
       if ( iPosX == 0 )
@@ -1866,5 +1866,5 @@
         if      (  (pcFilledRightData[uiXPos] != REN_IS_HOLE ) && ( pcFilledLeftData[uiXPos] != REN_IS_HOLE) )
         {
-          Int iDepthDifference  = m_piInvZLUTLeft[RemoveBitIncrementLUT(pcLeftDepthData[uiXPos])] - m_piInvZLUTRight[RemoveBitIncrementLUT(pcRightDepthData[uiXPos])];
+          Int iDepthDifference  = m_piInvZLUTLeft[RemoveBitIncrement(pcLeftDepthData[uiXPos])] - m_piInvZLUTRight[RemoveBitIncrement(pcRightDepthData[uiXPos])];
 
           if ( abs ( iDepthDifference ) <= m_iBlendZThres )
@@ -1895,5 +1895,5 @@
         else if ( (pcFilledRightData[uiXPos] == REN_IS_HOLE) && (pcFilledLeftData[uiXPos] == REN_IS_HOLE))
         {
-          pcOutputData[uiXPos] = m_piInvZLUTLeft[RemoveBitIncrementLUT( pcLeftDepthData[uiXPos])]  < m_piInvZLUTRight[RemoveBitIncrementLUT(pcRightDepthData[uiXPos])] ? pcLeftVideoData[uiXPos] : pcRightVideoData[uiXPos];
+          pcOutputData[uiXPos] = m_piInvZLUTLeft[RemoveBitIncrement( pcLeftDepthData[uiXPos])]  < m_piInvZLUTRight[RemoveBitIncrement(pcRightDepthData[uiXPos])] ? pcLeftVideoData[uiXPos] : pcRightVideoData[uiXPos];
         }
         else
