Index: branches/0.3-poznan-univ/build/linux/common/makefile.base
===================================================================
--- branches/0.3-poznan-univ/build/linux/common/makefile.base	(revision 47)
+++ branches/0.3-poznan-univ/build/linux/common/makefile.base	(revision 48)
@@ -47,5 +47,5 @@
 # default cpp flags for all configurations
 #CPPFLAGS          = -Wall -fPIC $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS)
-CPPFLAGS          = -fPIC $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS) -Wall -Wshadow -Wno-sign-compare
+CPPFLAGS          = -fPIC $(DEFS) -I$(CURDIR)/$(INC_DIR) $(USER_INC_DIRS) -Wall -Wshadow -Wno-sign-compare -Werror
 
 ########## 
Index: branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/App/TAppDecoder/TAppDecTop.cpp	(revision 48)
@@ -739,6 +739,4 @@
 Void TAppDecTop::storeSynthPicsInBuffer(Int iCoddedViewIdx,Int iCoddedViewOrderIdx, Int iCurPoc, Bool bDepth)
 {
-  Int  iLeftViewIdx  = -1;
-  Int  iRightViewIdx = -1;
   Int  iNearestViewIdx = -1;
   Bool bRenderFromLeft;
@@ -830,6 +828,4 @@
 Void TAppDecTop::storeDepthSynthPicsInBuffer(Int iCoddedViewIdx,Int iCoddedViewOrderIdx, Int iCurPoc)
 {
-  Int  iLeftViewIdx  = -1;
-  Int  iRightViewIdx = -1;
   Int  iNearestViewIdx = -1;
   Bool bRenderFromLeft;
Index: branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 48)
@@ -523,16 +523,19 @@
       size = m_iSourceWidth*m_iSourceHeight;
       depth_buf = (unsigned char *)malloc(size);
-      fread(depth_buf, 1, size, base_depth_file);
+      size_t read = 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)
+      if(read)
       {
-        m_bUseNonlinearDepth = 0;
-        printf ("\nWeighted average of depth histogram:%f < %d, turning NonlinearDepthRepresentation OFF\n", weighted_avg, m_iNonlinearDepthThreshold);
+        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);
+        }
       }
     }
@@ -542,6 +545,19 @@
   if(m_bUseNonlinearDepth)
   {
+     if((Int)m_aiNonlinearDepthModel.size()== 0)
+     {
+       m_aiNonlinearDepthModel.push_back(10);
+       m_aiNonlinearDepthModel.push_back(19);
+       m_aiNonlinearDepthModel.push_back(24);
+       m_aiNonlinearDepthModel.push_back(27);
+       m_aiNonlinearDepthModel.push_back(26);
+       m_aiNonlinearDepthModel.push_back(22);
+       m_aiNonlinearDepthModel.push_back(13);
+     }
+    //10,19,24,27,26,22,13
     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];
Index: branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncTop.cpp	(revision 48)
@@ -150,4 +150,7 @@
 #endif
 
+#if BITSTREAM_EXTRACTION
+    m_acTEncTopList[iViewIdx]->setLayerId                      ( ( (UInt)iViewIdx ) << 1 );
+#endif
     m_acTEncTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
     m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
@@ -359,11 +362,21 @@
 #endif
 
+#if BITSTREAM_EXTRACTION
+      m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( ( ( (UInt)iViewIdx ) << 1 ) + 1 );
+#endif
       m_acTEncDepthTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
       m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
       m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
+#if FLEX_CODING_ORDER
+      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
+      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
+      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
+      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
+#else
       m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
       m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
       m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
       m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
+#endif
 #if DEPTH_MAP_GENERATION
       m_acTEncDepthTopList[iViewIdx]->setPredDepthMapGeneration       ( 0 );
@@ -794,7 +807,13 @@
           iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
           bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
+#if POZNAN_SYNTH
+          if( m_uiUseCUSkip )
+          {
+            xStoreSynthPicsInBuffer(iViewIdx,false);
+          }
+#endif
 #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();
+          //Int   iCurrPoc2         = m_acTEncTopList[ 0 ]->getNextFrameId();
           Bool  bCurrPicDepthRec = getPicFromView( iViewIdx, iCurrPoc, true ) != NULL && getPicFromView( iViewIdx, iCurrPoc, true )->getReconMark();
           if(m_bUseTexDqpAccordingToDepth && !bCurrPicDepthRec)
@@ -825,4 +844,10 @@
             iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
             bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
+#if POZNAN_SYNTH
+            if( m_uiUseCUSkip )
+            {
+              xStoreSynthPicsInBuffer(iViewIdx,true);
+            }
+#endif
             m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
             bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
@@ -858,5 +883,5 @@
 #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();
+      //Int   iCurrPoc         = m_acTEncTopList[ 0 ]->getNextFrameId();
       Bool  bCurrPicDepthRec = getPicFromView( iViewIdx, iCurrPoc, true ) != NULL && getPicFromView( iViewIdx, iCurrPoc, true )->getReconMark();
       if(m_bUseTexDqpAccordingToDepth && !bCurrPicDepthRec)
@@ -1390,5 +1415,4 @@
   }
   
-  Int iNumberOfReferenceViews = 0;
   Int  iNearestViewIdx = -1;
   Bool bRenderFromLeft;
@@ -1477,6 +1501,4 @@
 Void TAppEncTop::xStoreDepthSynthPicsInBuffer(Int iCoddedViewIdx)
 {
-  Int  iLeftViewIdx  = -1;
-  Int  iRightViewIdx = -1;
   Int  iNearestViewIdx = -1;
   Bool bRenderFromLeft;
Index: branches/0.3-poznan-univ/source/App/TAppRenderer/TAppRendererTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/App/TAppRenderer/TAppRendererTop.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/App/TAppRenderer/TAppRendererTop.cpp	(revision 48)
@@ -308,6 +308,6 @@
             else
             {
-              Int iDistLeft  = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx ]  );
-              Int iDistRight = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iRightBaseViewIdx]  );
+              //Int iDistLeft  = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iLeftBaseViewIdx ]  );
+              //Int iDistRight = abs( m_cCameraData.getBaseId2SortedId()[0] - m_cCameraData.getBaseId2SortedId() [iRightBaseViewIdx]  );
 
               Int iFillViewIdx = (0!=iLeftBaseViewIdx)? iLeftBaseViewIdx: iRightBaseViewIdx;
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/SEI.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/SEI.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/SEI.h	(revision 48)
@@ -41,4 +41,9 @@
 class SEI
 {
+#if BITSTREAM_EXTRACTION
+protected:
+  UInt m_uiLayerId;
+#endif
+
 public:
   enum PayloadType {
@@ -51,4 +56,9 @@
   
   virtual PayloadType payloadType() const = 0;
+
+#if BITSTREAM_EXTRACTION
+  Void      setLayerId              ( UInt u )       { m_uiLayerId = u; }
+  UInt      getLayerId              ()         const { return m_uiLayerId; }
+#endif
 };
 
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 48)
@@ -419,5 +419,5 @@
   UInt uiPartP;
   TComDataCU* pcCUP;
-  UInt uiBs;
+  UInt uiBs = 0;
   
 #if MTK_NONCROSS_INLOOP_FILTER
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPic.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPic.cpp	(revision 48)
@@ -490,5 +490,4 @@
   
   Int x, y;
-  Bool bAvailable = true;
   Pel* pAvail  = getPicYuvAvail()->getLumaAddr ( iCuAddr, uiAbsZorderIdx );
   Int CUHeight = g_uiMaxCUHeight >> uiPartDepth; //rpcCU->getHeight(uiAbsZorderIdx);
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComPrediction.cpp	(revision 48)
@@ -1640,5 +1640,5 @@
 
 #if DEPTH_MAP_GENERATION
-  Int		  ref_frame0_idx_1st, ref_frame1_idx_1st;
+  Int		  ref_frame0_idx_1st = 0, ref_frame1_idx_1st = 0;
   TComMv	  mv0_1st,mv1_1st;
 #endif
@@ -1648,6 +1648,6 @@
   Pel aiUTab[MAX_CU_SIZE];
   Pel aiVTab[MAX_CU_SIZE];
-  Pel iULast;
-  Pel iVLast;
+  Pel iULast = 0;
+  Pel iVLast = 0;
   Pel iTemp;
 
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.cpp	(revision 48)
@@ -737,6 +737,11 @@
 }
 
+#if FLEXCO_CAMPARAM_IN_DEPTH
+Void
+TComSPS::initMultiviewSPS( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset , Bool bDepth)
+#else
 Void
 TComSPS::initMultiviewSPS( UInt uiViewId, Int iViewOrderIdx, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset )
+#endif
 {
   AOT( uiViewId == 0 && iViewOrderIdx != 0 );
@@ -746,5 +751,9 @@
   m_uiViewId              = uiViewId;
   m_iViewOrderIdx         = iViewOrderIdx;
+#if FLEXCO_CAMPARAM_IN_DEPTH
+  m_bDepth                = bDepth;
+#else
   m_bDepth                = false;
+#endif
   m_uiCamParPrecision     = ( m_uiViewId ? uiCamParPrecision : 0 );
   m_bCamParInSliceHeader  = ( m_uiViewId ? bCamParSlice  : false );
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TComSlice.h	(revision 48)
@@ -221,5 +221,9 @@
   Int* getPad         ( )        { return m_aiPad; }
 
+#if FLEX_CODING_ORDER 
+  Void        initMultiviewSPS      ( UInt uiViewId, Int iViewOrderIdx = 0, UInt uiCamParPrecision = 0, Bool bCamParSlice = false, Int** aaiScale = 0, Int** aaiOffset = 0, Bool bDepth = false );
+#else
   Void        initMultiviewSPS      ( UInt uiViewId, Int iViewOrderIdx = 0, UInt uiCamParPrecision = 0, Bool bCamParSlice = false, Int** aaiScale = 0, Int** aaiOffset = 0 );
+#endif
   Void        initMultiviewSPSDepth ( UInt uiViewId, Int iViewOrderIdx );
 
Index: branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibCommon/TypeDef.h	(revision 48)
@@ -44,4 +44,6 @@
 #define FLEX_CODING_ORDER               1
 
+#define FLEXCO_CAMPARAM_IN_DEPTH        FLEX_CODING_ORDER // encode pamera parameters in depth SPS
+
 #define SONY_COLPIC_AVAILABILITY        1
 
Index: branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 48)
@@ -255,10 +255,4 @@
   xReadFlag( uiCode ); pcSPS->setUseSAO       ( uiCode ? true : false );
 #endif
-#if POZNAN_DBMP
-  xReadFlag( uiCode ); pcSPS->setDBMP  ( uiCode );
-#endif
-#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
-  xReadFlag( uiCode ); pcSPS->setUseCUSkip ( uiCode );
-#endif
   xReadFlag( uiCode ); // SPS base view flag
   if( uiCode )
@@ -271,15 +265,57 @@
     pcSPS->setMultiviewResPredMode  ( 0 );
 #endif
+#if POZNAN_DBMP
+    pcSPS->setDBMP  ( false );
+#endif
+#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
+    pcSPS->setUseCUSkip ( false );
+#endif
   }
   else
   {
+#if POZNAN_DBMP
+    xReadFlag( uiCode ); pcSPS->setDBMP  ( uiCode );
+#endif
+#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
+    xReadFlag( uiCode ); pcSPS->setUseCUSkip ( uiCode );
+#endif
     xReadFlag  ( uiCode ); // depth flag
     if( uiCode )
     {
-      xReadUvlc( uiCode ); // view id
+      UInt  uiViewId;
+#if FLEXCO_CAMPARAM_IN_DEPTH
+      UInt  uiCamParPrecision;
+      Int   iVOI;
+      Bool  bCamParSlice;
+      xReadUvlc( uiViewId ); 
+      xReadSvlc( iVOI );
+      if (uiViewId == 0)
+      {
+        pcSPS->initMultiviewSPSDepth    ( uiViewId, iVOI );
+      }
+      else
+      {
+        xReadUvlc( uiCamParPrecision );
+        xReadFlag( uiCode );    bCamParSlice = ( uiCode == 1 );
+        if( !bCamParSlice )
+        {
+          //uiViewId++;
+          for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
+          {
+            xReadSvlc( iCode );   m_aaiTempScale [ uiBaseId ][ uiViewId ] = iCode;
+            xReadSvlc( iCode );   m_aaiTempOffset[ uiBaseId ][ uiViewId ] = iCode;
+            xReadSvlc( iCode );   m_aaiTempScale [ uiViewId ][ uiBaseId ] = iCode - m_aaiTempScale [ uiBaseId ][ uiViewId ];
+            xReadSvlc( iCode );   m_aaiTempOffset[ uiViewId ][ uiBaseId ] = iCode - m_aaiTempOffset[ uiBaseId ][ uiViewId ];
+          }
+        }
+        pcSPS->initMultiviewSPS( uiViewId, iVOI, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset, true);
+      }
+#else
+      xReadUvlc( uiViewId ); // view id
       xReadSvlc(  iCode ); // view order index
-      pcSPS->initMultiviewSPSDepth    ( uiCode, iCode );
+      pcSPS->initMultiviewSPSDepth    ( uiViewId, iCode );
+#endif
 #if DEPTH_MAP_GENERATION
-      pcSPS->setPredDepthMapGeneration( uiCode, true );
+      pcSPS->setPredDepthMapGeneration( uiViewId, true );
 #endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -2729,15 +2765,18 @@
 #endif
 #if POZNAN_DBMP
-	if(bDBMPAvailable)
-	{
-	  if(uiIdx==POZNAN_DBMP_MERGE_POS) uiModIdx = POZNAN_DBMP_MRG_CAND;
-	  else if(uiIdx>POZNAN_DBMP_MERGE_POS) uiModIdx = uiIdx--;
-	  else uiModIdx = uiIdx;
-	}
-	else uiModIdx = uiIdx;
-	if( pcCU->getNeighbourCandIdx( uiModIdx, uiAbsPartIdx ) != uiModIdx + 1 )
-	{
-	  ruiMergeIndex++;
-	}
+    {
+      if(bDBMPAvailable)
+      {
+        if(uiIdx==POZNAN_DBMP_MERGE_POS) uiModIdx = POZNAN_DBMP_MRG_CAND;
+        else if(uiIdx>POZNAN_DBMP_MERGE_POS) uiModIdx = uiIdx--;
+        else uiModIdx = uiIdx;
+      }
+      else uiModIdx = uiIdx;
+
+      if( pcCU->getNeighbourCandIdx( uiModIdx, uiAbsPartIdx ) != uiModIdx + 1 )
+      {
+	ruiMergeIndex++;
+      }
+    }
 #else
     if( pcCU->getNeighbourCandIdx( uiIdx, uiAbsPartIdx ) != uiIdx + 1 )
Index: branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp	(revision 48)
@@ -169,5 +169,4 @@
     Int64   iTempScale      = (Int64)uiDepthValue * iScale;
 #endif
-    Int64   iTestScale      = ( iTempScale + iOffset       );   // for checking accuracy of camera parameters
     Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
     Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
@@ -232,4 +231,5 @@
 
   AOF( pcSlice->getSPS()->getViewId() < MAX_NUMBER_VIEWS );
+
   if ( pcSlice->getSPS()->isDepth  () )
   {
@@ -238,7 +238,11 @@
     m_cNonlinearDepthModel = pcSlice->getSPS()->getNonlinearDepthModel();    
 #endif
+#if !FLEX_CODING_ORDER //Owieczka
     return;
-  }
+#endif
+  }
+#if !FLEX_CODING_ORDER //Owieczka
   else
+#endif
   {
 #if POZNAN_NONLINEAR_DEPTH
@@ -251,6 +255,8 @@
   Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
   AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
+#if !FLEX_CODING_ORDER //Owieczka  
   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
   AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
+#endif
   AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
   if ( !bFirstSliceInView )
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 48)
@@ -39,4 +39,5 @@
 
 #include "TEncCavlc.h"
+#include "../TLibCommon/SEI.h"
 #include "SEIwrite.h"
 
@@ -228,5 +229,9 @@
 void TEncCavlc::codeSEI(const SEI& sei)
 {
+#if BITSTREAM_EXTRACTION
+  codeNALUnitHeader( NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST, 0, sei.getLayerId() );
+#else
   codeNALUnitHeader(NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST);
+#endif
   writeSEImessage(*m_pcBitIf, sei);
 }
@@ -235,5 +240,9 @@
 {
   // uiFirstByte
+#if BITSTREAM_EXTRACTION
+  codeNALUnitHeader( NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST, 0, pcPPS->getLayerId() );
+#else
   codeNALUnitHeader( NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST );
+#endif
 
   xWriteUvlc( pcPPS->getPPSId() );
@@ -249,4 +258,16 @@
 }
 
+#if BITSTREAM_EXTRACTION
+Void TEncCavlc::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, UInt uiLayerId )
+{
+  // uiFirstByte
+  xWriteCode( 0, 1);                    // forbidden_zero_flag
+  xWriteCode( eNalRefIdc==0 ? 0:1, 1);  // nal_ref_flag
+  xWriteCode( eNalUnitType, 6);         // nal_unit_type
+
+  xWriteCode( TemporalId, 3);           // temporal_id
+  xWriteCode( uiLayerId+1, 5);          // layer_id_plus1
+}
+#else
 Void TEncCavlc::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, Bool bOutputFlag )
 {
@@ -263,9 +284,14 @@
   }
 }
+#endif
 
 Void TEncCavlc::codeSPS( TComSPS* pcSPS )
 {
   // uiFirstByte
+#if BITSTREAM_EXTRACTION
+  codeNALUnitHeader( NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST, 0, pcSPS->getLayerId() );
+#else
   codeNALUnitHeader( NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST );
+#endif
 
   // Structure
@@ -326,4 +352,7 @@
   xWriteFlag( pcSPS->getUseSAO() ? 1 : 0);
 #endif
+  if( pcSPS->getViewId() || pcSPS->isDepth() )
+  {
+    xWriteFlag( 0 ); // inverse of RBSP stop bit (for backwards compatible extension)
 #if POZNAN_DBMP
 	  xWriteFlag( pcSPS->getDBMP() );
@@ -332,8 +361,4 @@
 	  xWriteFlag( pcSPS->getUseCUSkip() );
 #endif
-
-  if( pcSPS->getViewId() || pcSPS->isDepth() )
-  {
-    xWriteFlag( 0 ); // inverse of RBSP stop bit (for backwards compatible extension)
     if( pcSPS->isDepth() )
     {
@@ -341,4 +366,21 @@
       xWriteUvlc( pcSPS->getViewId() );
       xWriteSvlc( pcSPS->getViewOrderIdx() );
+#if FLEXCO_CAMPARAM_IN_DEPTH
+      if ( pcSPS->getViewId() != 0) 
+      {
+        xWriteUvlc( pcSPS->getCamParPrecision() );
+        xWriteFlag( pcSPS->hasCamParInSliceHeader() ? 1 : 0 );
+        if( !pcSPS->hasCamParInSliceHeader() )
+        {
+          for( UInt uiId = 0; uiId < pcSPS->getViewId(); uiId++ )
+          {
+            xWriteSvlc( pcSPS->getCodedScale    ()[ uiId ] );
+            xWriteSvlc( pcSPS->getCodedOffset   ()[ uiId ] );
+            xWriteSvlc( pcSPS->getInvCodedScale ()[ uiId ] + pcSPS->getCodedScale ()[ uiId ] );
+            xWriteSvlc( pcSPS->getInvCodedOffset()[ uiId ] + pcSPS->getCodedOffset()[ uiId ] );
+          }
+        }
+      }
+#endif
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
       xWriteFlag( pcSPS->getUseDMM() ? 1 : 0 );
@@ -408,7 +450,15 @@
   // here someone can add an appropriated NalRefIdc type
 #if DCM_DECODING_REFRESH
+#if BITSTREAM_EXTRACTION
+  codeNALUnitHeader (pcSlice->getNalUnitType(), NAL_REF_IDC_PRIORITY_HIGHEST, 1, pcSlice->getLayerId());
+#else
   codeNALUnitHeader (pcSlice->getNalUnitType(), NAL_REF_IDC_PRIORITY_HIGHEST, 1, true);
+#endif
+#else
+#if BITSTREAM_EXTRACTION
+  codeNALUnitHeader (NAL_UNIT_CODED_SLICE, NAL_REF_IDC_PRIORITY_HIGHEST, 0, pcSlice->getLayerId());
 #else
   codeNALUnitHeader (NAL_UNIT_CODED_SLICE, NAL_REF_IDC_PRIORITY_HIGHEST);
+#endif
 #endif
 
@@ -784,13 +834,13 @@
     {
 #if POZNAN_DBMP
-	  if(bDBMPAvailable)
-	  {
-		  if(uiIdx==POZNAN_DBMP_MERGE_POS) uiModIdx = POZNAN_DBMP_MRG_CAND;
-		  else if(uiIdx>POZNAN_DBMP_MERGE_POS) uiModIdx = uiIdx--;
-		  else uiModIdx = uiIdx;
-	  }
-	  else uiModIdx = uiIdx;
-	  if( pcCU->getNeighbourCandIdx( uiModIdx, uiAbsPartIdx ) == uiModIdx + 1 )
-	  {
+	    if(bDBMPAvailable)
+	    {
+		    if(uiIdx==POZNAN_DBMP_MERGE_POS) uiModIdx = POZNAN_DBMP_MRG_CAND;
+		    else if(uiIdx>POZNAN_DBMP_MERGE_POS) uiModIdx = uiIdx--;
+		    else uiModIdx = uiIdx;
+	    }
+	    else uiModIdx = uiIdx;
+	    if( pcCU->getNeighbourCandIdx( uiModIdx, uiAbsPartIdx ) == uiModIdx + 1 )
+	    {
         uiNumCand++;
       }
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCavlc.h	(revision 48)
@@ -206,5 +206,9 @@
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
   
+#if BITSTREAM_EXTRACTION
+  Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, UInt uiLayerId = 0 );
+#else
   Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, Bool bOutputFlag = true );
+#endif
   
   Void  codeSPS                 ( TComSPS* pcSPS );
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncCfg.h	(revision 48)
@@ -187,4 +187,7 @@
   //std::vector<int>  m_aiLayerQPOffset;
 
+#if BITSTREAM_EXTRACTION
+  UInt        m_uiLayerId;
+#endif
   UInt        m_uiViewId;
   Int         m_iViewOrderIdx;
@@ -257,4 +260,8 @@
   Void      setRateGOPSize                  ( Int   i )      { m_iRateGOPSize = i; }
 
+#if BITSTREAM_EXTRACTION
+  Void      setLayerId                      ( UInt  u )      { m_uiLayerId              = u; }
+  UInt      getLayerId                      ( )              { return m_uiLayerId; }
+#endif
   Void      setViewId                       ( UInt  u )      { m_uiViewId               = u; }
   Void      setViewOrderIdx                 ( Int   i )      { m_iViewOrderIdx          = i; }
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncEntropy.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncEntropy.h	(revision 48)
@@ -72,5 +72,9 @@
   virtual UInt  getCoeffCost          ()                = 0;
   
+#if BITSTREAM_EXTRACTION
+  virtual Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, UInt uiLayerId = 0 ) = 0;
+#else
   virtual Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, Bool bOutputFlag = true ) = 0;
+#endif
 
   virtual Void  codeSPS                 ( TComSPS* pcSPS )                                      = 0;
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 48)
@@ -658,4 +658,7 @@
         seiBs.create(1024);
         /* write the SEI messages */
+#if BITSTREAM_EXTRACTION
+        sei_recon_picture_digest.setLayerId( pcSlice->getLayerId() );
+#endif
         m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
         m_pcEntropyCoder->setBitstream(&seiBs);
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 48)
@@ -177,5 +177,9 @@
 }
 
+#if BITSTREAM_EXTRACTION
+Void TEncSbac::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, UInt uiLayerId )
+#else
 Void TEncSbac::codeNALUnitHeader( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId, Bool bOutputFlag )
+#endif
 {
   assert (0);
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.h	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSbac.h	(revision 48)
@@ -89,5 +89,9 @@
   //--SBAC RD
   
+#if BITSTREAM_EXTRACTION
+  Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, UInt uiLayerId = 0 );
+#else
   Void  codeNALUnitHeader       ( NalUnitType eNalUnitType, NalRefIdc eNalRefIdc, UInt TemporalId = 0, Bool bOutputFlag = true );
+#endif
 
   Void  codeSPS                 ( TComSPS* pcSPS     );
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 48)
@@ -149,4 +149,7 @@
   rpcSlice->initSlice();
   rpcSlice->setPOC( pcPic->getPOC() );
+#if BITSTREAM_EXTRACTION
+  rpcSlice->setLayerId( m_pcCfg->getLayerId() );
+#endif
 #if SONY_COLPIC_AVAILABILITY
   rpcSlice->setViewOrderIdx(m_pcCfg->getViewOrderIdx());
Index: branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp	(revision 47)
+++ branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp	(revision 48)
@@ -576,7 +576,16 @@
   m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
 
+#if BITSTREAM_EXTRACTION
+  m_cSPS.setLayerId( m_uiLayerId );
+#endif
+
   if( m_bIsDepth )
   {
+#if FLEXCO_CAMPARAM_IN_DEPTH
+    //m_cSPS.initMultiviewSPSDepth    ( m_uiViewId, m_iViewOrderIdx );
+    m_cSPS.initMultiviewSPS         ( m_uiViewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset, true );
+#else
     m_cSPS.initMultiviewSPSDepth    ( m_uiViewId, m_iViewOrderIdx );
+#endif
 #if DEPTH_MAP_GENERATION
     m_cSPS.setPredDepthMapGeneration( m_uiViewId, true );
@@ -654,4 +663,7 @@
   m_cSPS.setUseDMM( m_bUseDMM );
 #endif
+#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
+  m_cSPS.setUseDMM34( m_bUseDMM34 );
+#endif
 #if HHI_MPI
   m_cSPS.setUseMVI( m_bUseMVI );
@@ -678,4 +690,8 @@
 Void TEncTop::xInitPPS()
 {
+#if BITSTREAM_EXTRACTION
+  m_cPPS.setLayerId( m_uiLayerId );
+#endif
+
   m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
   m_cPPS.setPPSId( ( m_uiViewId << 1 ) + ( m_bIsDepth ? 1 : 0 ) );
