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

Last change on this file since 101 was 100, checked in by tech, 13 years ago

Adopted modifications:

  • disparity vector generation (A0097)
  • inter-view motion prediction modification (A0049)
  • simplification of disparity vector derivation (A0126)
  • region boundary chain coding (A0070)
  • residual skip intra (A0087)
  • VSO modification (A0033/A0093)

+ Clean ups + Bug fixes

Update of cfg files (A0033 modification 2)

  • Property svn:eol-style set to native
File size: 17.2 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-2011, 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
54using namespace std;
55
56
57#if HHI_VSO_RM_ASSERTIONS
58#define RM_AOT( exp ) AOT ( exp )
59#define RM_AOF( exp ) AOF ( exp )
60#else
61#define RM_AOT( exp ) ((void)0)
62#define RM_AOF( exp ) ((void)0)
63#endif
64
65#define RenModRemoveBitInc( exp ) bBitInc ? ( RemoveBitIncrement( exp ) ) : ( exp )
66
67class TRenSingleModel
68{
69public: 
70#if LGE_VSO_EARLY_SKIP_A0093
71  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip ) = 0;
72#else
73  virtual Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode ) = 0;
74#endif
75
76  // Set Frame dependent data
77  virtual Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride ) = 0;
78  virtual Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference, UInt uiHorOffset ) = 0;
79
80  // Set Data
81#ifdef LGE_VSO_EARLY_SKIP_A0093
82  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel* piOrgData, Int iOrgStride )  = 0;
83#else
84  virtual Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )  = 0;
85#endif
86  virtual Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
87
88  // Get Distortion
89#ifdef LGE_VSO_EARLY_SKIP_A0093
90  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData , Int iOrgStride)=0;
91#else
92  virtual RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
93#endif
94  virtual RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData ) = 0;
95
96  virtual Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset  ) = 0; 
97  virtual Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset  ) = 0;
98  virtual Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset  ) = 0;
99};
100
101template < BlenMod iBM, Bool bBitInc >
102class TRenSingleModelC : public TRenSingleModel
103{
104  struct RenModelInPels
105  {
106    // video
107    Pel aiY[5]    ; // y-value
108#if HHI_VSO_COLOR_PLANES
109    Pel aiU[5]    ; // u-value
110    Pel aiV[5]    ; // v-value
111#endif
112    // depth
113    Pel iD        ; // depth
114
115    // state
116    Bool bOccluded; // Occluded
117  };
118
119  struct RenModelOutPels
120  {
121    // video
122    Pel iYLeft    ; 
123    Pel iYRight   ; 
124    Pel iYBlended ; 
125#if HHI_VSO_COLOR_PLANES
126    Pel iULeft    ; 
127    Pel iURight   ; 
128    Pel iUBlended ; 
129    Pel iVLeft    ; 
130    Pel iVRight   ; 
131    Pel iVBlended ; 
132#endif
133    // depth
134    Pel iDLeft    ;
135    Pel iDRight   ; 
136    Pel iDBlended ; 
137
138    // state
139    Int iFilledLeft ; 
140    Int iFilledRight; 
141
142    // error
143    Int  iError   ;
144
145    // reference
146    Pel iYRef    ; 
147#if HHI_VSO_COLOR_PLANES
148    Pel iURef    ; 
149    Pel iVRef    ; 
150#endif       
151  };
152
153
154
155public:
156  TRenSingleModelC();
157  ~TRenSingleModelC();
158
159  // Create Model
160#if LGE_VSO_EARLY_SKIP_A0093
161  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode, Bool bEarlySkip  );
162#else
163  Void   create    ( Int iMode, Int iWidth, Int iHeight, Int iShiftPrec, Int*** aaaiSubPelShiftTable, Int iHoleMargin, Bool bUseOrgRef, Int iBlendMode );
164#endif
165
166  // Set Frame dependent data
167  Void   setLRView ( Int iViewPos, Pel** apiCurVideoPel, Int* aiCurVideoStride, Pel* piCurDepthPel, Int iCurDepthStride );
168  Void   setup     ( TComPicYuv* pcOrgVideo, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight,  Int** ppiBaseShiftLutRight,  Int iDistToLeft, Bool bKeepReference, UInt uiHorOffset );
169
170#if LGE_VSO_EARLY_SKIP_A0093
171  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel* piOrgData, Int iOrgStride );
172#else
173  Void   setDepth  ( Int iViewPos,                 Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
174#endif
175  Void   setVideo  ( Int iViewPos,     Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
176
177  // Get Distortion
178#ifdef LGE_VSO_EARLY_SKIP_A0093
179  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData , Int iOrgStride);
180#else
181  RMDist getDistDepth  ( Int iViewPos,             Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
182#endif
183  RMDist getDistVideo  ( Int iViewPos, Int iPlane, Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
184
185  Void   getSynthVideo  ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset ); 
186  Void   getSynthDepth  ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset  );
187  Void   getRefVideo    ( Int iViewPos, TComPicYuv* pcPicYuv, UInt uiHorOffset  );
188
189private:
190  // Set and inc Current Row
191  __inline Void   xSetViewRow(  Int iPosY );
192  __inline Void   xIncViewRow();
193
194  /////  Rendering /////
195  // Left to Right
196#ifdef LGE_VSO_EARLY_SKIP_A0093
197                      __inline Bool   xDetectEarlySkipL   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride );
198                      __inline Bool   xDetectEarlySkipR   ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData,Pel* piOrgData, Int iOrgStride );
199  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Bool bFast );
200  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Bool bFast );
201#else
202  template<Bool bSet> __inline RMDist xRenderR            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
203  template<Bool bSet> __inline RMDist xRenderL            ( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData );
204#endif
205                      __inline Void   xInitRenderPartL    ( Int iEndChangePos, Int iLastSPos  );
206  template<Bool bSet> __inline Void   xRenderRangeL       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
207  template<Bool bSet> __inline Void   xRenderShiftedRangeL( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
208  template<Bool bSet> __inline Void   xFillHoleL          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
209  template<Bool bSet> __inline Void   xExtrapolateMarginL ( Int iCurSPos,                Int iCurPos, RMDist& riError );
210                      __inline Int    xRangeLeftL         ( Int iPos );
211                      __inline Int    xRangeRightL        ( Int iPos );
212                      __inline Int    xRoundL             ( Int iPos );
213
214  // Right to Left
215                      __inline Void   xInitRenderPartR    ( Int iStartChangePos, Int iLastSPos );
216  template<Bool bSet> __inline Void   xRenderShiftedRangeR( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
217  template<Bool bSet> __inline Void   xRenderRangeR       ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
218  template<Bool bSet> __inline Void   xFillHoleR          ( Int iCurSPos, Int iLastSPos, Int iCurPos, RMDist& riError );
219  template<Bool bSet> __inline Void   xExtrapolateMarginR ( Int iCurSPos,                Int iCurPos, RMDist& riError );
220                      __inline Int    xRangeLeftR         ( Int iPos );
221                      __inline Int    xRangeRightR        ( Int iPos );
222                      __inline Int    xRoundR             ( Int iPos );
223
224  // Blending
225  template<Bool bSet> __inline Void   xSetShiftedPelBlend ( Int iSourcePos, Int iTargetSPos, Pel iFilled, RMDist& riError );
226
227#if HHI_VSO_COLOR_PLANES
228  __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 );
229  __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 );
230  __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 );
231#else
232  __inline Void   xGetBlendedValue    ( Pel iYL,   Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
233  __inline Void   xGetBlendedValueBM1 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
234  __inline Void   xGetBlendedValueBM2 ( Pel iYL, Pel iYR, Pel iDepthL, Pel iDepthR, Int iFilledL, Int iFilledR, Pel& riY );
235#endif
236  __inline Pel    xBlend              ( Pel pVal1, Pel pVal2, Int iWeightVal2 );
237
238  // General
239  template<Bool bSet> __inline Void xSetShiftedPelL       (Int iSourcePos,                  Int iSubSourcePos, Int iTargetSPos,                   Pel iFilled, RMDist& riError );
240  template<Bool bSet> __inline Void xSetShiftedPelBlendL  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
241  template<Bool bSet> __inline Void xSetShiftedPelNoBlendL(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
242
243  template<Bool bSet> __inline Void xSetShiftedPelR       (Int iSourcePos,                  Int iSubSourcePos, Int iTargetSPos,                   Pel iFilled, RMDist& riError );
244  template<Bool bSet> __inline Void xSetShiftedPelBlendR  (RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
245  template<Bool bSet> __inline Void xSetShiftedPelNoBlendR(RenModelInPels* pcInSample, Int iSubSourcePos, RenModelOutPels* pcOutSample, Pel iFilled, RMDist& riError );
246
247  __inline Int    xShiftNewData      ( Int iPos, Int iPosInNewData );
248  __inline Int    xShift             ( Int iPos );
249  __inline Int    xShift             ( Int iPos, Int iPosInNewData );
250  __inline Int    xGetDist           ( Int iDiffY, Int iDiffU, Int iDiffV );
251  __inline Int    xGetDist           ( Int iDiffY );
252
253  // Utilities
254  __inline Void   xSetPels   ( Pel*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Pel iVal );
255  __inline Void   xSetBools  ( Bool* pbSource    , Int iSourceStride, Int iWidth, Int iHeight, Bool bVal );
256  __inline Void   xSetInts   ( Int*  piPelSource , Int iSourceStride, Int iWidth, Int iHeight, Int iVal );
257
258#if HHI_VSO_COLOR_PLANES
259  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY, Pel RenModelOutPels::*& rpiSrcU, Pel RenModelOutPels::*& rpiSrcV );
260#else 
261  Void            xGetSampleStrTextPtrs ( Int iViewNum, Pel RenModelOutPels::*& rpiSrcY );
262#endif
263  Void            xGetSampleStrDepthPtrs( Int iViewNum, Pel RenModelOutPels::*& rpiSrcD );
264       
265  Void            xSetStructRefView            ();
266  Void            xResetStructError            ();
267  Void            xInitSampleStructs           ();
268  Void            xSetStructSynthViewAsRefView ();
269  Void            xCopy2PicYuv                ( Pel** ppiSrcVideoPel, Int* piStrides, TComPicYuv* rpcPicYuvTarget, UInt uiHorOffset );
270
271
272  template< typename S, typename T> 
273  Void   xCopyFromSampleStruct ( S* ptSource , Int iSourceStride, T S::* ptSourceElement, T* ptTarget, Int iTargetStride, Int iWidth, Int iHeight )
274  {
275    for (Int iPosY = 0; iPosY < m_iHeight; iPosY++)
276    {
277      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
278      {
279        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
280      }
281      ptSource += iSourceStride;
282      ptTarget += iTargetStride;
283    }   
284  } 
285
286  template< typename S, typename T> 
287  Void   xCopyToSampleStruct ( T* ptSource , Int iSourceStride, S* ptTarget, Int iTargetStride, T S::* ptSourceElement, Int iWidth, Int iHeight )
288  {
289    for (Int iPosY = 0; iPosY < m_iHeight; iPosY++)
290    {
291      for (Int iPosX = 0; iPosX < m_iWidth; iPosX++)
292      {
293        ptTarget[iPosX] = ptSource[iPosX].*ptSourceElement;
294      }
295      ptSource += iSourceStride;
296      ptTarget += iTargetStride;
297    }   
298  }   
299
300private:
301
302  // Image sizes
303  Int   m_iWidth;
304  Int   m_iHeight;
305  Int   m_iStride;
306  Int   m_iPad;
307
308  Int   m_iSampledWidth;
309  Int   m_iSampledHeight;
310  Int   m_iSampledStride;
311
312  RenModelInPels* m_pcInputSamples[2];
313  Int                  m_iInputSamplesStride;
314
315  // Base
316  Pel** m_aapiBaseVideoPel     [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
317  Int*  m_aaiBaseVideoStrides  [2]; // Dim1: ViewPosition 0->Left, 1->Right; Dim2: Plane  0-> Y, 1->U, 2->V
318
319  Pel*  m_apiBaseDepthPel      [2]; // Dim1: ViewPosition
320  Int   m_aiBaseDepthStrides   [2]; // Dim1: ViewPosition
321
322
323  // LUT
324  Int** m_appiShiftLut         [2];
325  Int** m_ppiCurLUT;
326  Int** m_aaiSubPelShiftL;
327  Int** m_aaiSubPelShiftR;
328
329  Int*  m_piInvZLUTLeft;
330  Int*  m_piInvZLUTRight;
331
332
333  //// Reference Data  ////
334  TComPicYuv* m_pcPicYuvRef       ;    // Reference PIcYuv
335
336  //// Output Samples
337  RenModelOutPels* m_pcOutputSamples;
338  Int                   m_iOutputSamplesStride;
339
340  Pel*  m_aapiRefVideoPel      [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
341  Int   m_aiRefVideoStrides    [3];    // Dim1: Plane  0-> Y, 1->U, 2->V
342
343  // Rendering State
344  Bool  m_bInOcclusion;                // Currently rendering in occluded area
345  Int   m_iLastOccludedSPos;           // Position of last topmost shifted position
346  Int   m_iLastOccludedSPosFP;         // Position of last topmost shifted position in FullPels
347
348  Int   m_iCurViewPos;                 // Current View Position 0: Left, 1: Right
349  Int   m_iOtherViewPos;               // Other View Position 0: Left, 1: Right
350  Pel*  m_piNewDepthData;              // Pointer to new depth data
351  Int   m_iStartChangePosX;            // Start Position of new data
352  Int   m_iNewDataWidth;               // Width of new data
353  Pel   m_iCurDepth;                   // Current Depth Value
354  Pel   m_iLastDepth;                  // Last Depth Value
355  Pel   m_iThisDepth;                  // Depth value to use for setting
356
357  //// Settings ////
358  // Input
359  Int   m_iMode;                       // 0: Left to Right, 1: Right to Left, 2: Merge
360  Bool  m_bUseOrgRef;
361  Int   m_iShiftPrec;
362  Int   m_iHoleMargin;
363#ifdef LGE_VSO_EARLY_SKIP_A0093
364  Bool  m_bEarlySkip; 
365#endif
366
367  // Derived settings
368  Int   m_iGapTolerance;
369  Int   m_iBlendZThres;
370  Int   m_iBlendDistWeight;
371
372  //// Current Pointers ////
373
374  RenModelInPels*  m_pcInputSamplesRow [2];
375  RenModelOutPels* m_pcOutputSamplesRow;
376
377  //// MISC ////
378  const Int m_iDistShift;                  // Shift in Distortion computation
379
380  //// Early Skip
381#ifdef LGE_VSO_EARLY_SKIP_A0093
382  Bool* m_pbHorSkip;
383#endif
384};
385
386#endif //__TRENSINGLEMODEL__
Note: See TracBrowser for help on using the repository browser.