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 );
