source: 3DVCSoftware/trunk/source/Lib/TLibRenderer/TRenSingleModel.h @ 1313

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

  • Property svn:eol-style set to native
File size: 18.1 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35#ifndef __TRENSINGLEMODEL__
36#define __TRENSINGLEMODEL__
37
38#include "TRenImage.h"
39#include "../TLibCommon/CommonDef.h"
40#include "../TLibCommon/TComPicYuv.h"
41#include "../TLibCommon/TypeDef.h"
42#include "../TAppCommon/TAppComCamPara.h"
43
44
45#include <math.h>
46#include <errno.h>
47#include <iostream>
48
49#include <string>
50#include <cstdio>
51#include <cstring>
52
53#if NH_3D_VSO
54using namespace std;
55
56#if H_3D_VSO_RM_ASSERTIONS
57#define RM_AOT( exp ) AOT ( exp )
58#define RM_AOF( exp ) AOF ( exp )
59#else
60#define RM_AOT( exp ) ((void)0)
61#define RM_AOF( exp ) ((void)0)
62#endif
63
64#define RenModRemoveBitInc( exp ) bBitInc ? ( RemoveBitIncrement( exp ) ) : ( exp )
65
66class TRenSingleModel
67{
68public: 
69
70  virtual ~TRenSingleModel() { } 
71#if H_3D_VSO_EARLY_SKIP
72  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip ) = 0;
73#else
74  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode ) = 0;
75#endif
76
77  // Set Frame dependent data
78  virtual Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride ) = 0;
79  virtual Void   setupPart ( UInt uiHorOffset,       Int iUsedHeight ) = 0;
80  virtual Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference ) = 0;
81
82  // Set Data
83#if H_3D_VSO_EARLY_SKIP
84  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel* piOrgData, Int iOrgStride )  = 0;
85#else
86  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData )  = 0;
87#endif
88  virtual Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData ) = 0;
89
90  // Get Distortion
91#if H_3D_VSO_EARLY_SKIP
92  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel * piOrgData , Int iOrgStride)=0;
93#else
94  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData ) = 0;
95#endif
96  virtual RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData ) = 0;
97
98  virtual Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0; 
99  virtual Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0;
100  virtual Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv ) = 0;
101};
102
103template < BlenMod iBM, Bool bBitInc >
104class TRenSingleModelC : public TRenSingleModel
105{
106  struct RenModelInPels
107  {
108    // video
109    Pel aiY[5]    ; // y-value
110#if H_3D_VSO_COLOR_PLANES
111    Pel aiU[5]    ; // u-value
112    Pel aiV[5]    ; // v-value
113#endif
114    // depth
115    Pel iD        ; // depth
116
117    // state
118    Bool bOccluded; // Occluded
119  };
120
121  struct RenModelOutPels
122  {
123    // video
124    Pel iYLeft    ; 
125    Pel iYRight   ; 
126    Pel iYBlended ; 
127#if H_3D_VSO_COLOR_PLANES
128    Pel iULeft    ; 
129    Pel iURight   ; 
130    Pel iUBlended ; 
131    Pel iVLeft    ; 
132    Pel iVRight   ; 
133    Pel iVBlended ; 
134#endif
135    // depth
136    Pel iDLeft    ;
137    Pel iDRight   ; 
138    Pel iDBlended ; 
139
140    // state
141    Int iFilledLeft ; 
142    Int iFilledRight; 
143
144    // error
145    Int  iError   ;
146
147    // reference
148    Pel iYRef    ; 
149#if H_3D_VSO_COLOR_PLANES
150    Pel iURef    ; 
151    Pel iVRef    ; 
152#endif       
153  };
154
155
156
157public:
158  TRenSingleModelC();
159  ~TRenSingleModelC();
160
161  // Create Model
162#if H_3D_VSO_EARLY_SKIP
163  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip  );
164#else
165  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode );
166#endif
167
168  // Set Frame dependent data
169  Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride );
170  Void   setupPart ( UInt uiHorOffset,       Int uiUsedHeight );
171  Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference );
172
173#if H_3D_VSO_EARLY_SKIP
174  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel* piOrgData, Int iOrgStride );
175#else                                                                                                                   
176  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
177#endif                                                                                                                   
178  Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
179                                                                                                                         
180  // Get Distortion                                                                                                     
181#if H_3D_VSO_EARLY_SKIP                                                                                                 
182  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel * piOrgData , Int iOrgStride);
183#else                                                                                                                   
184  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
185#endif                                                                                                                   
186  RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
187
188  Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv ); 
189  Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv );
190  Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv );
191
192private:
193  // Set and inc Current Row
194  __inline Void   xSetViewRow(  Int iPosY );
195  __inline Void   xIncViewRow();
196
197  /////  Rendering /////
198  // Left to Right
199#if H_3D_VSO_EARLY_SKIP
200                      __inline Bool   xDetectEarlySkipL   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel* piOrgData, Int iOrgStride );
201                      __inline Bool   xDetectEarlySkipR   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, const Pel* piOrgData, Int iOrgStride );
202  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, Bool bFast );
203  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData, Bool bFast );
204#else
205  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
206  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData );
207#endif
208                      __inline Void   xInitRenderPartL    ( Int iEndChangePos, Int iLastSPos  );
209  template<Bool bSet> __inline Void   xRenderRangeL       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
210  template<Bool bSet> __inline Void   xRenderShiftedRangeL( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
211  template<Bool bSet> __inline Void   xFillHoleL          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
212  template<Bool bSet> __inline Void   xExtrapolateMarginL ( Int iCurSPos,                Int iCurPos, RMDist& riError );
213                      __inline Int    xRangeLeftL         ( Int iPos );
214                      __inline Int    xRangeRightL        ( Int iPos );
215                      __inline Int    xRoundL             ( Int iPos );
216
217  // Right to Left
218                      __inline Void   xInitRenderPartR    ( Int iStartChangePos, Int iLastSPos );
219  template<Bool bSet> __inline Void   xRenderShiftedRangeR( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
220  template<Bool bSet> __inline Void   xRenderRangeR       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
221  template<Bool bSet> __inline Void   xFillHoleR          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
222  template<Bool bSet> __inline Void   xExtrapolateMarginR ( Int iCurSPos,                Int iCurPos, RMDist& riError );
223                      __inline Int    xRangeLeftR         ( Int iPos );
224                      __inline Int    xRangeRightR        ( Int iPos );
225                      __inline Int    xRoundR             ( Int iPos );
226
227  // Blending
228  template<Bool bSet> __inline Void   xSetShiftedPelBlend ( Int iSourcePos, Int iTargetSPos, Pel iFilled, RMDist& riError );
229
230#if H_3D_VSO_COLOR_PLANES
231  __inline Void   xGetBlendedValue    ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
232  __inline Void   xGetBlendedValueBM1 ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
233  __inline Void   xGetBlendedValueBM2 ( Pel iYL, Pel iYR, Pel iUL, Pel iUR, Pel iVL, Pel iVR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY, Pel& riU, Pel&riV );
234#else
235  __inline Void   xGetBlendedValue    ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
236  __inline Void   xGetBlendedValueBM1 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
237  __inline Void   xGetBlendedValueBM2 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
238#endif
239  __inline Pel    xBlend              ( Pel pVal1, Pel pVal2, Int iWeightVal2 );
240
241  // General
242  template<Bool bSet> __inline Void xSetShiftedPelL       (Int iSourcePos,             Int iSubSourcePos, Int iTargetSPos,              Pel iFilled, RMDist& riError );
243  template<Bool bSet> __inline Void xSetShiftedPelBlendL  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
244  template<Bool bSet> __inline Void xSetShiftedPelNoBlendL(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
245
246  template<Bool bSet> __inline Void xSetShiftedPelR       (Int iSourcePos,             Int iSubSourcePos, Int iTargetSPos,              Pel iFilled, RMDist& riError );
247  template<Bool bSet> __inline Void xSetShiftedPelBlendR  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
248  template<Bool bSet> __inline Void xSetShiftedPelNoBlendR(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
249
250  __inline Int    xShiftNewData      ( Int iPos, Int iPosInNewData );
251  __inline Int    xShift             ( Int iPos );
252  __inline Int    xShift             ( Int iPos, Int iPosInNewData );
253  __inline Int    xGetDist           ( Int iDiffY, Int iDiffU, Int iDiffV );
254  __inline Int    xGetDist           ( Int iDiffY );
255
256  // Utilities
257  __inline Void   xSetPels   ( Pel*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Pel iVal );
258  __inline Void   xSetBools  ( Bool* pbSource    , Int iSourceStride, Int iWidth, Int iHeight, Bool bVal );
259  __inline Void   xSetInts   ( Int*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Int iVal );
260
261#if H_3D_VSO_COLOR_PLANES
262  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY, Pel RenModelOutPels::*& rpiSrcU, Pel RenModelOutPels::*& rpiSrcV );
263#else 
264  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY );
265#endif
266  Void            xGetSampleStrDepthPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcD );
267       
268  Void            xSetStructRefView            ();
269  Void            xResetStructError            ();
270  Void            xInitSampleStructs           ();
271  Void            xSetStructSynthViewAsRefView ();
272  Void            xCopy2PicYuv                ( Pel** ppiSrcVideoPel, Int* piStrides, TComPicYuv* rpcPicYuvTarget );
273
274  template< typename S, typename T> 
275  Void   xCopyFromSampleStruct ( S* ptSource , Int iSourceStride, T S::* ptSourceElement, T* ptTarget, Int iTargetStride, Int iWidth, Int iHeight )
276  {
277    AOT( iWidth != m_iWidth ); 
278    for (Int iPosY = 0; iPosY < iHeight; iPosY++)
279    {
280      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
281      {
282        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
283      }
284      ptSource += iSourceStride;
285      ptTarget += iTargetStride;
286    }   
287  } 
288
289  template< typename S, typename T> 
290  Void   xCopyToSampleStruct ( T* ptSource , Int iSourceStride, S* ptTarget, Int iTargetStride, T S::* ptSourceElement, Int iWidth, Int iHeight )
291  {
292    AOT( iWidth != m_iWidth ); 
293    for (Int iPosY = 0; iPosY < iHeight; iPosY++)
294    {
295      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
296      {
297        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
298      }
299      ptSource += iSourceStride;
300      ptTarget += iTargetStride;
301    }   
302  }   
303
304private:
305
306  // Image sizes
307  Int   m_iWidth;
308  Int   m_iHeight;
309  Int   m_iStride;
310  Int   m_iPad;
311  Int   m_iUsedHeight;
312  Int   m_iHorOffset; 
313
314  Int   m_iSampledWidth;
315  Int   m_iSampledStride;
316
317  RenModelInPels* m_pcInputSamples[2];
318  Int             m_iInputSamplesStride;
319
320  // Base
321  Pel** m_aapiBaseVideoPel     [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
322  Int*  m_aaiBaseVideoStrides  [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
323
324  Pel*  m_apiBaseDepthPel      [2]; // Dim1: ViewPosition
325  Int   m_aiBaseDepthStrides   [2]; // Dim1: ViewPosition
326
327
328  // LUT
329  Int** m_appiShiftLut         [2];
330  Int** m_ppiCurLUT;
331  Int** m_aaiSubPelShiftL;
332  Int** m_aaiSubPelShiftR;
333
334  Int*  m_piInvZLUTLeft;
335  Int*  m_piInvZLUTRight;
336
337
338  //// Reference Data  ////
339  TComPicYuv* m_pcPicYuvRef       ;    // Reference PIcYuv
340
341  //// Output Samples
342  RenModelOutPels* m_pcOutputSamples;
343  Int                   m_iOutputSamplesStride;
344
345  Pel*  m_aapiRefVideoPel      [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
346  Int   m_aiRefVideoStrides    [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
347
348  // Rendering State
349  Bool  m_bInOcclusion;                // Currently rendering in occluded area
350  Int   m_iLastOccludedSPos;           // Position of last topmost shifted position
351  Int   m_iLastOccludedSPosFP;         // Position of last topmost shifted position in FullPels
352
353  Int   m_iCurViewPos;                 // Current View Position 0: Left, 1: Right
354  Int   m_iOtherViewPos;               // Other View Position 0: Left, 1: Right
355  const Pel*  m_piNewDepthData;              // Pointer to new depth data
356  Int   m_iStartChangePosX;            // Start Position of new data
357  Int   m_iNewDataWidth;               // Width of new data
358  Pel   m_iCurDepth;                   // Current Depth Value
359  Pel   m_iLastDepth;                  // Last Depth Value
360  Pel   m_iThisDepth;                  // Depth value to use for setting
361
362  //// Settings ////
363  // Input
364  Int   m_iMode;                       // 0: Left to Right, 1: Right to Left, 2: Merge
365  Bool  m_bUseOrgRef;
366  Int   m_iShiftPrec;
367  Int   m_iHoleMargin;
368#if H_3D_VSO_EARLY_SKIP
369  Bool  m_bEarlySkip; 
370#endif
371
372  // Derived settings
373  Int   m_iGapTolerance;
374  Int   m_iBlendZThres;
375  Int   m_iBlendDistWeight;
376
377  //// Current Pointers ////
378
379  RenModelInPels*  m_pcInputSamplesRow [2];
380  RenModelOutPels* m_pcOutputSamplesRow;
381
382  //// MISC ////
383  const Int m_iDistShift;                  // Shift in Distortion computation
384
385  //// Early Skip
386#if H_3D_VSO_EARLY_SKIP
387  Bool* m_pbHorSkip;
388#endif
389};
390
391#endif // NH_3D
392#endif //__TRENSINGLEMODEL__
393
394
Note: See TracBrowser for help on using the repository browser.