source: 3DVCSoftware/trunk/source/Lib/TLibRenderer/TRenModel.cpp @ 1397

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

Merged HTM-16.0-dev1@1395.

  • Property svn:eol-style set to native
File size: 32.4 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#include "TRenImage.h"
35#include "TRenFilter.h"
36#include "TRenModel.h"
37
38#if NH_3D_VSO
39///////////  TRENMODEL //////////////////////
40TRenModel::TRenModel()
41{
42  m_iPad               = PICYUV_PAD;
43  m_iWidth             = -1;
44  m_iHeight            = -1;
45  m_iUsedHeight        = -1; 
46  m_iNumOfBaseViews    = -1;
47  m_iSampledWidth      = -1;
48  m_iShiftPrec         =  0;
49  m_iHoleMargin        =  1;
50  m_uiHorOff           = -1;
51#if H_3D_VSO_EARLY_SKIP
52  m_bEarlySkip         = false; 
53#endif
54
55  // Current Error Type ///
56  m_iCurrentView       = -1;
57  m_iCurrentContent    = -1;
58  m_iCurrentPlane      = -1;
59
60  // Array of Models used to determine the Current Error ///
61  m_iNumOfCurRenModels = -1;
62  m_apcCurRenModels    = NULL;
63  m_aiCurPosInModels   = NULL;
64
65  // Array of Models ///
66  m_iNumOfRenModels    = -1;
67  m_apcRenModels       = NULL;
68
69  // Mapping from View number to models ///
70  m_aiNumOfModelsForDepthView = NULL;
71  m_aapcRenModelForDepthView  = NULL;
72  m_aaePosInModelForDepthView = NULL;
73
74  m_aiNumOfModelsForVideoView = NULL;
75  m_aapcRenModelForVideoView  = NULL;
76  m_aaePosInModelForVideoView = NULL;
77  m_aaeBaseViewPosInModel     = NULL;
78
79  // Data
80  m_aapiCurVideoPel      = NULL;
81  m_aaiCurVideoStrides   = NULL;
82  m_apiCurDepthPel       = NULL;
83  m_aiCurDepthStrides    = NULL;
84
85  m_aapiOrgVideoPel      = NULL;
86  m_aaiOrgVideoStrides   = NULL;
87  m_apiOrgDepthPel       = NULL;
88  m_aiOrgDepthStrides    = NULL;
89
90  m_aaaiSubPelShiftLut[0]= NULL;
91  m_aaaiSubPelShiftLut[1]= NULL;
92
93  /// Current Setup data ///
94  m_abSetupVideoFromOrgForView = NULL;
95  m_abSetupDepthFromOrgForView = NULL;
96}
97
98TRenModel::~TRenModel()
99{
100  if ( m_apcRenModels )
101  {
102    for (Int iNumModel = 0; iNumModel < m_iNumOfRenModels; iNumModel++)
103    {
104      if ( m_apcRenModels[iNumModel] ) delete m_apcRenModels[iNumModel];
105    }
106
107    delete[] m_apcRenModels;
108  }
109
110  for (Int iViewNum = 0; iViewNum < m_iNumOfBaseViews; iViewNum++)
111  {
112    if ( m_aapcRenModelForDepthView && m_aapcRenModelForDepthView [iViewNum] )
113    {
114      delete[]   m_aapcRenModelForDepthView [iViewNum];
115    }
116
117    if ( m_aaePosInModelForDepthView && m_aaePosInModelForDepthView[iViewNum] )
118    {
119      delete[]   m_aaePosInModelForDepthView[iViewNum];
120    }
121
122    if ( m_aapcRenModelForVideoView && m_aapcRenModelForVideoView[iViewNum] )
123    {
124      delete[]   m_aapcRenModelForVideoView[iViewNum];
125    }
126
127    if ( m_aaePosInModelForVideoView && m_aaePosInModelForVideoView[iViewNum] )
128    {
129      delete[]   m_aaePosInModelForVideoView[iViewNum];
130    }
131
132    if ( m_aaeBaseViewPosInModel && m_aaeBaseViewPosInModel[iViewNum] )
133    {
134      delete[]   m_aaeBaseViewPosInModel[iViewNum];
135    }
136
137    if ( m_aapiCurVideoPel && m_aapiCurVideoPel    [iViewNum] )
138    {
139      delete[] ( m_aapiCurVideoPel    [iViewNum][0] - m_iPad * m_aaiCurVideoStrides[iViewNum][0] - m_iPad );
140      delete[] ( m_aapiCurVideoPel    [iViewNum][1] - m_iPad * m_aaiCurVideoStrides[iViewNum][1] - m_iPad );
141      delete[] ( m_aapiCurVideoPel    [iViewNum][2] - m_iPad * m_aaiCurVideoStrides[iViewNum][2] - m_iPad );
142      delete[]   m_aapiCurVideoPel    [iViewNum];
143    }
144
145    if ( m_aaiCurVideoStrides && m_aaiCurVideoStrides [iViewNum] )
146    {
147      delete[]   m_aaiCurVideoStrides [iViewNum];
148    }
149
150    if ( m_apiCurDepthPel )
151    {
152      delete[] ( m_apiCurDepthPel     [iViewNum]    - m_iPad * m_aiCurDepthStrides [iViewNum]    - m_iPad );
153    }
154
155    if ( m_aapiOrgVideoPel && m_aapiOrgVideoPel    [iViewNum] )
156    {
157      delete[] ( m_aapiOrgVideoPel    [iViewNum][0] - m_iPad * m_aaiOrgVideoStrides[iViewNum][0] - m_iPad );
158      delete[] ( m_aapiOrgVideoPel    [iViewNum][1] - m_iPad * m_aaiOrgVideoStrides[iViewNum][1] - m_iPad );
159      delete[] ( m_aapiOrgVideoPel    [iViewNum][2] - m_iPad * m_aaiOrgVideoStrides[iViewNum][2] - m_iPad );
160      delete[]   m_aapiOrgVideoPel    [iViewNum];
161    }
162
163    if ( m_aaiOrgVideoStrides && m_aaiOrgVideoStrides [iViewNum] )
164    {
165      delete[]   m_aaiOrgVideoStrides [iViewNum];
166    }
167
168    if ( m_apiOrgDepthPel && m_apiOrgDepthPel     [iViewNum ] )
169    {
170      delete[] ( m_apiOrgDepthPel     [iViewNum]    - m_iPad * m_aiOrgDepthStrides [iViewNum]    - m_iPad );
171    }
172  }
173
174  if(m_aiNumOfModelsForDepthView) delete[] m_aiNumOfModelsForDepthView;
175  if(m_aapcRenModelForDepthView ) delete[] m_aapcRenModelForDepthView ;
176  if(m_aaePosInModelForDepthView) delete[] m_aaePosInModelForDepthView;
177
178  if(m_aiNumOfModelsForVideoView) delete[] m_aiNumOfModelsForVideoView;
179  if(m_aapcRenModelForVideoView ) delete[] m_aapcRenModelForVideoView ;
180  if(m_aaePosInModelForVideoView) delete[] m_aaePosInModelForVideoView;
181
182
183  if(m_aaeBaseViewPosInModel    ) delete[] m_aaeBaseViewPosInModel    ;
184  if(m_aapiCurVideoPel          ) delete[] m_aapiCurVideoPel          ;
185  if(m_aaiCurVideoStrides       ) delete[] m_aaiCurVideoStrides       ;
186
187  if(m_abSetupVideoFromOrgForView) delete[] m_abSetupVideoFromOrgForView;
188  if(m_abSetupDepthFromOrgForView) delete[] m_abSetupDepthFromOrgForView;
189
190  if(m_aapiOrgVideoPel          ) delete[] m_aapiOrgVideoPel          ;
191  if(m_aaiOrgVideoStrides       ) delete[] m_aaiOrgVideoStrides       ;
192
193  if(m_apiOrgDepthPel           ) delete[] m_apiOrgDepthPel           ;
194  if(m_aiOrgDepthStrides        ) delete[] m_aiOrgDepthStrides        ;
195
196  if(m_apiCurDepthPel           ) delete[] m_apiCurDepthPel           ;
197  if(m_aiCurDepthStrides        ) delete[] m_aiCurDepthStrides        ;
198
199  Int iNumEntries = (1 << ( m_iShiftPrec + 1) ) + 1 ;
200
201  for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
202  {
203    if ( m_aaaiSubPelShiftLut[0] && m_aaaiSubPelShiftLut[0][uiEntry] )
204      delete[] m_aaaiSubPelShiftLut[0][uiEntry];
205
206    if ( m_aaaiSubPelShiftLut[1] && m_aaaiSubPelShiftLut[1][uiEntry] )
207      delete[] m_aaaiSubPelShiftLut[1][uiEntry];
208  }
209
210  if( m_aaaiSubPelShiftLut[0] ) delete[] m_aaaiSubPelShiftLut[0];
211  if( m_aaaiSubPelShiftLut[1] ) delete[] m_aaaiSubPelShiftLut[1];
212}
213
214
215
216Void
217#if H_3D_VSO_EARLY_SKIP
218TRenModel::create( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin, Bool bLimOutput, Bool bEarlySkip )
219#else
220TRenModel::create( Int iNumOfBaseViews, Int iNumOfModels, Int iWidth, Int iHeight, Int iShiftPrec, Int iHoleMargin, Bool bLimOutput )
221#endif
222{
223  m_bLimOutput          = bLimOutput; 
224
225  m_iNumOfBaseViews     = iNumOfBaseViews;
226  m_iNumOfRenModels     = iNumOfModels;
227  m_iWidth              = iWidth;
228  m_iHeight             = iHeight;
229  m_iShiftPrec          = iShiftPrec;
230  m_iHoleMargin         = iHoleMargin;
231#if H_3D_VSO_EARLY_SKIP
232  m_bEarlySkip          = bEarlySkip; 
233#endif
234
235
236// LUTs for sub pel shifting
237  Int iNumEntries = (1 << ( m_iShiftPrec + 1) ) + 1 ;
238  m_aaaiSubPelShiftLut[0] = new Int*[ iNumEntries ];
239  m_aaaiSubPelShiftLut[1] = new Int*[ iNumEntries ];
240  for (UInt uiEntry = 0; uiEntry < iNumEntries; uiEntry++)
241  {
242    m_aaaiSubPelShiftLut[0][uiEntry] = new Int[ iNumEntries ];
243    m_aaaiSubPelShiftLut[1][uiEntry] = new Int[ iNumEntries ];
244  }
245
246  TRenFilter<REN_BIT_DEPTH>::setSubPelShiftLUT( m_iShiftPrec, m_aaaiSubPelShiftLut[0], 0 );
247  TRenFilter<REN_BIT_DEPTH>::setSubPelShiftLUT( m_iShiftPrec, m_aaaiSubPelShiftLut[1], 0 );
248
249  m_iSampledWidth       = iWidth << m_iShiftPrec;
250
251
252  m_aapiCurVideoPel     = new Pel**     [m_iNumOfBaseViews];
253  m_aaiCurVideoStrides  = new Int*      [m_iNumOfBaseViews];
254  m_apiCurDepthPel      = new Pel*      [m_iNumOfBaseViews];
255  m_aiCurDepthStrides   = new Int       [m_iNumOfBaseViews];
256
257  m_aapiOrgVideoPel     = new Pel**     [m_iNumOfBaseViews];
258  m_aaiOrgVideoStrides  = new Int*      [m_iNumOfBaseViews];
259
260  m_apiOrgDepthPel      = new Pel*      [m_iNumOfBaseViews];
261  m_aiOrgDepthStrides   = new Int       [m_iNumOfBaseViews];
262
263  m_abSetupVideoFromOrgForView = new Bool[m_iNumOfBaseViews];
264  m_abSetupDepthFromOrgForView = new Bool[m_iNumOfBaseViews];
265
266  m_iNumOfCurRenModels   = 0;
267  m_apcCurRenModels      = NULL;
268  m_aiCurPosInModels     = NULL;
269
270  m_apcRenModels         = new TRenSingleModel*       [m_iNumOfRenModels];
271
272  m_aiNumOfModelsForDepthView = new Int               [m_iNumOfBaseViews];
273  m_aapcRenModelForDepthView  = new TRenSingleModel** [m_iNumOfBaseViews];
274  m_aaePosInModelForDepthView = new Int*              [m_iNumOfBaseViews];
275
276  m_aiNumOfModelsForVideoView = new Int               [m_iNumOfBaseViews];
277  m_aapcRenModelForVideoView  = new TRenSingleModel** [m_iNumOfBaseViews];
278  m_aaePosInModelForVideoView = new Int*              [m_iNumOfBaseViews];
279  m_aaeBaseViewPosInModel     = new Int*              [m_iNumOfBaseViews];
280
281
282  for (Int iModelNum = 0; iModelNum < m_iNumOfRenModels; iModelNum++)
283  {
284    m_apcRenModels         [iModelNum] = NULL;
285  }
286
287  for (Int iViewNum = 0; iViewNum < m_iNumOfBaseViews; iViewNum++ )
288  {
289    m_aiNumOfModelsForDepthView[ iViewNum ] = 0;
290    m_aiNumOfModelsForVideoView[ iViewNum ] = 0;
291
292    m_aapcRenModelForDepthView [iViewNum] = new TRenSingleModel*[m_iNumOfRenModels];
293    m_aapcRenModelForVideoView [iViewNum] = new TRenSingleModel*[m_iNumOfRenModels];
294
295    m_aaePosInModelForDepthView[iViewNum] = new Int             [m_iNumOfRenModels];
296    m_aaePosInModelForVideoView[iViewNum] = new Int             [m_iNumOfRenModels];
297    m_aaeBaseViewPosInModel    [iViewNum] = new Int             [m_iNumOfRenModels];
298
299    for (Int iModelNum = 0; iModelNum< m_iNumOfRenModels; iModelNum++)
300    {
301      m_aapcRenModelForDepthView [iViewNum] [iModelNum] = NULL;
302      m_aapcRenModelForVideoView [iViewNum] [iModelNum] = NULL;
303      m_aaePosInModelForDepthView[iViewNum] [iModelNum] = VIEWPOS_INVALID;
304      m_aaePosInModelForVideoView[iViewNum] [iModelNum] = VIEWPOS_INVALID;
305      m_aaeBaseViewPosInModel    [iViewNum] [iModelNum] = VIEWPOS_INVALID;
306    };
307
308    m_aaiCurVideoStrides  [iViewNum]     =  new Int[3];
309    m_aaiCurVideoStrides  [iViewNum][0]  =  m_iSampledWidth + (m_iPad << 1);
310    m_aaiCurVideoStrides  [iViewNum][1]  =  m_iSampledWidth + (m_iPad << 1);
311    m_aaiCurVideoStrides  [iViewNum][2]  =  m_iSampledWidth + (m_iPad << 1);
312
313    m_aapiCurVideoPel     [iViewNum]     = new Pel*[3];
314    m_aapiCurVideoPel     [iViewNum][0]  = new Pel [ m_aaiCurVideoStrides[iViewNum][0] * ( m_iHeight  + (m_iPad << 1) )];
315    m_aapiCurVideoPel     [iViewNum][1]  = new Pel [ m_aaiCurVideoStrides[iViewNum][1] * ( m_iHeight  + (m_iPad << 1) )];
316    m_aapiCurVideoPel     [iViewNum][2]  = new Pel [ m_aaiCurVideoStrides[iViewNum][2] * ( m_iHeight  + (m_iPad << 1) )];
317
318    m_aapiCurVideoPel     [iViewNum][0] += m_aaiCurVideoStrides[iViewNum][0] * m_iPad + m_iPad;
319    m_aapiCurVideoPel     [iViewNum][1] += m_aaiCurVideoStrides[iViewNum][1] * m_iPad + m_iPad;
320    m_aapiCurVideoPel     [iViewNum][2] += m_aaiCurVideoStrides[iViewNum][2] * m_iPad + m_iPad;
321
322    m_aiCurDepthStrides   [iViewNum]     = m_iWidth + (m_iPad << 1);
323    m_apiCurDepthPel      [iViewNum]     = new Pel[ m_aiCurDepthStrides[iViewNum] * ( m_iHeight  + (m_iPad << 1) ) ];
324    m_apiCurDepthPel      [iViewNum]    += m_aiCurDepthStrides[iViewNum] * m_iPad + m_iPad;
325
326    m_aaiOrgVideoStrides  [iViewNum]    =  new Int[3];
327    m_aaiOrgVideoStrides  [iViewNum][0] = m_iSampledWidth + (m_iPad << 1);
328    m_aaiOrgVideoStrides  [iViewNum][1] = m_iSampledWidth + (m_iPad << 1);
329    m_aaiOrgVideoStrides  [iViewNum][2] = m_iSampledWidth + (m_iPad << 1);
330
331    m_aapiOrgVideoPel     [iViewNum]     = new Pel*[3];
332    m_aapiOrgVideoPel     [iViewNum][0]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][0] * ( m_iHeight  + (m_iPad << 1) )];
333    m_aapiOrgVideoPel     [iViewNum][1]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][1] * ( m_iHeight  + (m_iPad << 1) )];
334    m_aapiOrgVideoPel     [iViewNum][2]  = new Pel [ m_aaiOrgVideoStrides[iViewNum][2] * ( m_iHeight  + (m_iPad << 1) )];
335
336    m_aapiOrgVideoPel     [iViewNum][0] += m_aaiOrgVideoStrides[iViewNum][0] * m_iPad + m_iPad;
337    m_aapiOrgVideoPel     [iViewNum][1] += m_aaiOrgVideoStrides[iViewNum][1] * m_iPad + m_iPad;
338    m_aapiOrgVideoPel     [iViewNum][2] += m_aaiOrgVideoStrides[iViewNum][2] * m_iPad + m_iPad;
339
340    m_aiOrgDepthStrides   [iViewNum]     = m_iWidth + (m_iPad << 1);
341    m_apiOrgDepthPel      [iViewNum]     = new Pel[ m_aiOrgDepthStrides[iViewNum] * ( m_iHeight  + (m_iPad << 1) ) ];
342    m_apiOrgDepthPel      [iViewNum]    += m_aiOrgDepthStrides[iViewNum] * m_iPad + m_iPad;
343
344    m_abSetupVideoFromOrgForView[iViewNum] = false;
345    m_abSetupDepthFromOrgForView[iViewNum] = false;
346  }
347}
348
349Void
350TRenModel::createSingleModel( Int iBaseViewNum, Int iContent, Int iModelNum, Int iLeftViewNum, Int iRightViewNum, Bool bUseOrgRef, Int iBlendMode )
351{
352  Int iMode = ( (iLeftViewNum != -1) && ( iRightViewNum != -1 ) ) ? 2 : ( iLeftViewNum != -1 ? 0 : ( iRightViewNum != -1  ? 1 : -1 ) );
353
354  AOT( iMode == -1);
355  AOT( iModelNum < 0 || iModelNum > m_iNumOfRenModels ); 
356  AOT( iLeftViewNum  < -1 || iLeftViewNum  > m_iNumOfBaseViews );
357  AOT( iRightViewNum < -1 || iRightViewNum > m_iNumOfBaseViews );
358  AOT( iBaseViewNum  < -1 || iBaseViewNum  > m_iNumOfBaseViews );
359  AOT( iBaseViewNum != -1 && iBaseViewNum != iLeftViewNum && iBaseViewNum != iRightViewNum );
360  AOT( iContent      < -1 || iContent > 1 );
361  AOT( iBlendMode < -1 || iBlendMode > 2 ); 
362
363  Bool bBitInc = ( REN_BIT_DEPTH != ENC_INTERNAL_BIT_DEPTH );
364
365  AOT( m_apcRenModels[iModelNum] );
366
367  if ( bBitInc )
368  { 
369    if ( iMode != 2 ) 
370    { // No Blending
371      m_apcRenModels[iModelNum]   = new TRenSingleModelC<BLEND_NONE, true>; 
372    }
373    else
374    {
375      switch ( iBlendMode )
376      {
377      case BLEND_AVRG: // average
378        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_AVRG, true>;       
379        break;
380      case BLEND_LEFT: // left  view is main view
381        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_LEFT, true>;       
382        break;
383      case BLEND_RIGHT: // right view is main view
384        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_RIGHT, true>;       
385        break;
386      default: 
387        AOT(true);
388        break;
389      }   
390    }
391  }
392  else
393  {
394    if ( iMode != 2 ) 
395    { // No Blending
396      m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_NONE, false>; 
397    }
398    else
399    {
400      switch ( iBlendMode )
401      {
402      case BLEND_AVRG: // average
403        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_AVRG, false>;       
404        break;
405      case BLEND_LEFT: // left  view is main view
406        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_LEFT, false>;       
407        break;
408      case BLEND_RIGHT: // right view is main view
409        m_apcRenModels[iModelNum] = new TRenSingleModelC<BLEND_RIGHT, false>;       
410        break;
411      default: 
412        AOT(true);
413        break;
414      }   
415    }
416  }
417
418
419#if H_3D_VSO_EARLY_SKIP
420#if RM_INIT_FIX
421  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, ( iMode != 2 )  ? BLEND_NONE : iBlendMode , m_bLimOutput, m_bEarlySkip );
422#else
423  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, iBlendMode, m_bLimOutput, m_bEarlySkip );
424#endif
425
426#else
427
428#if RM_INIT_FIX
429  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, ( iMode != 2 )  ? BLEND_NONE : iBlendMode, m_bLimOutput );
430#else
431  m_apcRenModels[iModelNum]->create( iMode ,m_iWidth, m_iHeight, m_iShiftPrec, m_aaaiSubPelShiftLut, m_iHoleMargin,  bUseOrgRef, iBlendMode, m_bLimOutput );
432#endif
433#endif
434
435  if ( iLeftViewNum != -1 )
436  {
437    xSetLRViewAndAddModel( iModelNum, iLeftViewNum, iContent,  VIEWPOS_LEFT,  (iBaseViewNum == -1  || iBaseViewNum == iLeftViewNum   ) );
438  }
439
440  if ( iRightViewNum != -1)
441  {
442    xSetLRViewAndAddModel( iModelNum, iRightViewNum, iContent, VIEWPOS_RIGHT, (iBaseViewNum == -1  || iBaseViewNum == iRightViewNum  ) );
443  }
444}
445
446Void
447TRenModel::setBaseView( Int iViewNum, TComPicYuv* pcPicYuvVideoData, TComPicYuv* pcPicYuvDepthData, TComPicYuv* pcPicYuvOrgVideoData, TComPicYuv* pcPicYuvOrgDepthData )
448{
449  AOT( iViewNum < 0 || iViewNum > m_iNumOfBaseViews );
450  AOF( pcPicYuvVideoData->getHeight( COMPONENT_Y ) >= m_iUsedHeight + m_uiHorOff && pcPicYuvVideoData->getWidth( COMPONENT_Y ) == m_iWidth );
451  AOF( pcPicYuvDepthData->getHeight( COMPONENT_Y ) >= m_iUsedHeight + m_uiHorOff && pcPicYuvDepthData->getWidth( COMPONENT_Y ) == m_iWidth );
452 
453  AOF( pcPicYuvVideoData   ->getChromaFormat() == CHROMA_420 );
454 
455  pcPicYuvVideoData->extendPicBorder();
456
457  TRenFilter<REN_BIT_DEPTH>::sampleHorUp   ( m_iShiftPrec, pcPicYuvVideoData->getAddr( COMPONENT_Y  ) +  m_uiHorOff        * pcPicYuvVideoData->getStride( COMPONENT_Y ) , pcPicYuvVideoData->getStride( COMPONENT_Y  ) , m_iWidth,      m_iUsedHeight,      m_aapiCurVideoPel[ iViewNum ][0], m_aaiCurVideoStrides[iViewNum][0] );
458  TRenFilter<REN_BIT_DEPTH>::sampleCUpHorUp( m_iShiftPrec, pcPicYuvVideoData->getAddr( COMPONENT_Cb ) + (m_uiHorOff >> 1 ) * pcPicYuvVideoData->getStride( COMPONENT_Cb) , pcPicYuvVideoData->getStride( COMPONENT_Cb ), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiCurVideoPel[ iViewNum ][1], m_aaiCurVideoStrides[iViewNum][1] );
459  TRenFilter<REN_BIT_DEPTH>::sampleCUpHorUp( m_iShiftPrec, pcPicYuvVideoData->getAddr( COMPONENT_Cr ) + (m_uiHorOff >> 1 ) * pcPicYuvVideoData->getStride( COMPONENT_Cr) , pcPicYuvVideoData->getStride( COMPONENT_Cr ), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiCurVideoPel[ iViewNum ][2], m_aaiCurVideoStrides[iViewNum][2] );
460  TRenFilter<REN_BIT_DEPTH>::copy          (               pcPicYuvDepthData->getAddr( COMPONENT_Y  ) +  m_uiHorOff        * pcPicYuvDepthData->getStride( COMPONENT_Y ) , pcPicYuvDepthData->getStride( COMPONENT_Y  ),  m_iWidth,      m_iUsedHeight,      m_apiCurDepthPel [ iViewNum],     m_aiCurDepthStrides [iViewNum]    );
461
462  // Used for rendering reference pic from original video data
463  m_abSetupVideoFromOrgForView[iViewNum] = (pcPicYuvOrgVideoData != NULL);
464  m_abSetupDepthFromOrgForView[iViewNum] = (pcPicYuvOrgDepthData != NULL);
465
466  if ( m_abSetupVideoFromOrgForView[iViewNum] )
467  {
468    AOF( pcPicYuvOrgVideoData->getChromaFormat() == CHROMA_420 );
469    AOF( pcPicYuvOrgVideoData->getHeight( COMPONENT_Y ) >= m_iUsedHeight + m_uiHorOff && pcPicYuvOrgVideoData->getWidth( COMPONENT_Y) == m_iWidth );   
470    pcPicYuvOrgVideoData->extendPicBorder();
471    TRenFilter<REN_BIT_DEPTH>::sampleHorUp   ( m_iShiftPrec, pcPicYuvOrgVideoData->getAddr( COMPONENT_Y  ) +  m_uiHorOff          * pcPicYuvOrgVideoData->getStride( COMPONENT_Y  ), pcPicYuvOrgVideoData->getStride( COMPONENT_Y  ) , m_iWidth,      m_iUsedHeight,      m_aapiOrgVideoPel[ iViewNum ][0], m_aaiOrgVideoStrides[iViewNum][0] );
472    TRenFilter<REN_BIT_DEPTH>::sampleCUpHorUp( m_iShiftPrec, pcPicYuvOrgVideoData->getAddr( COMPONENT_Cb )   + (m_uiHorOff >> 1 ) * pcPicYuvOrgVideoData->getStride( COMPONENT_Cb ), pcPicYuvOrgVideoData->getStride( COMPONENT_Cb ), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiOrgVideoPel[ iViewNum ][1], m_aaiOrgVideoStrides[iViewNum][1] );
473    TRenFilter<REN_BIT_DEPTH>::sampleCUpHorUp( m_iShiftPrec, pcPicYuvOrgVideoData->getAddr( COMPONENT_Cr )   + (m_uiHorOff >> 1 ) * pcPicYuvOrgVideoData->getStride( COMPONENT_Cr ), pcPicYuvOrgVideoData->getStride( COMPONENT_Cr ), m_iWidth >> 1, m_iUsedHeight >> 1, m_aapiOrgVideoPel[ iViewNum ][2], m_aaiOrgVideoStrides[iViewNum][2] );
474  }
475
476  if ( m_abSetupDepthFromOrgForView[iViewNum] )
477  {   
478    AOF( pcPicYuvOrgDepthData->getHeight( COMPONENT_Y ) >= m_iUsedHeight + m_uiHorOff && pcPicYuvOrgDepthData->getWidth( COMPONENT_Y ) == m_iWidth );
479    TRenFilter<REN_BIT_DEPTH>::copy          (               pcPicYuvOrgDepthData->getAddr( COMPONENT_Y ) +  m_uiHorOff        * pcPicYuvOrgDepthData->getStride( COMPONENT_Y) , pcPicYuvOrgDepthData->getStride( COMPONENT_Y),  m_iWidth,     m_iUsedHeight,      m_apiOrgDepthPel [ iViewNum],     m_aiOrgDepthStrides [iViewNum]    );
480  }
481}
482
483Void
484TRenModel::setSingleModel( Int iModelNum, Int** ppiShiftLutLeft, Int** ppiBaseShiftLutLeft, Int** ppiShiftLutRight, Int** ppiBaseShiftLutRight, Int iDistToLeft, TComPicYuv* pcPicYuvRefView, Int iEncViewSIdx)
485{
486  AOT( iModelNum < 0 || iModelNum > m_iNumOfRenModels );
487
488  m_apcRenModels[iModelNum]->setupPart( m_uiHorOff, m_iUsedHeight );
489
490  // Switch model  to original data for setup if given to render reference
491  Bool bAnyRefFromOrg = false;
492  for (Int iBaseViewIdx = 0; iBaseViewIdx < m_iNumOfBaseViews; iBaseViewIdx++ )
493  {
494    Bool bSetupFromOrgVideo = m_abSetupVideoFromOrgForView[iBaseViewIdx];
495    Bool bSetupFromOrgDepth = m_abSetupDepthFromOrgForView[iBaseViewIdx];
496    bAnyRefFromOrg          = bAnyRefFromOrg || bSetupFromOrgVideo || bSetupFromOrgDepth;
497
498    if ( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum] != VIEWPOS_INVALID )
499    {
500      m_apcRenModels[iModelNum]->setLRView( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum],
501        ( bSetupFromOrgVideo ? m_aapiOrgVideoPel   : m_aapiCurVideoPel   ) [iBaseViewIdx],
502        ( bSetupFromOrgVideo ? m_aaiOrgVideoStrides: m_aaiCurVideoStrides) [iBaseViewIdx],
503        ( bSetupFromOrgDepth ? m_apiOrgDepthPel    : m_apiCurDepthPel    ) [iBaseViewIdx],
504        ( bSetupFromOrgDepth ? m_aiOrgDepthStrides : m_aiCurDepthStrides ) [iBaseViewIdx] );
505    }
506  }
507
508  // Render
509#if !RM_FIX_SETUP
510  m_apcRenModels[iModelNum]->setupLutAndRef(  pcPicYuvRefView, ppiShiftLutLeft, ppiBaseShiftLutLeft, ppiShiftLutRight, ppiBaseShiftLutRight, iDistToLeft, bAnyRefFromOrg );
511
512  // Setup with actual data 
513    for (Int iBaseViewIdx = 0; iBaseViewIdx < m_iNumOfBaseViews; iBaseViewIdx++ )
514    {
515      if ( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum] != VIEWPOS_INVALID )
516      {
517        m_apcRenModels[iModelNum]->setLRView(
518          m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum],
519          m_aapiCurVideoPel      [iBaseViewIdx],
520          m_aaiCurVideoStrides   [iBaseViewIdx],
521          m_apiCurDepthPel       [iBaseViewIdx],
522          m_aiCurDepthStrides    [iBaseViewIdx]
523        );
524      }
525    }
526  // Render initial state
527  AOT( m_bLimOutput && m_aaeBaseViewPosInModel[ iEncViewSIdx ][iModelNum] == VIEWPOS_INVALID );
528  m_apcRenModels[iModelNum]->setupInitialState( m_bLimOutput ? m_aaeBaseViewPosInModel[ iEncViewSIdx ][iModelNum] : VIEWPOS_INVALID ); 
529
530#else
531  m_apcRenModels[iModelNum]->setupLut(  ppiShiftLutLeft, ppiBaseShiftLutLeft, ppiShiftLutRight, ppiBaseShiftLutRight, iDistToLeft );
532 
533  // Copy yuv to reference if given.
534  AOT( pcPicYuvRefView != NULL && bAnyRefFromOrg );
535 
536  if (pcPicYuvRefView )
537  {
538    m_apcRenModels[iModelNum]->setupRefView( pcPicYuvRefView );
539  }
540
541  m_apcRenModels[iModelNum]->renderAll( ); 
542
543  // pcPicYuvRefView != NULL &&  bAnyRefFromOrg --> invalid combination
544  // pcPicYuvRefView != NULL && !bAnyRefFromOrg --> distortion correct; reference view correct; current view correct
545  // pcPicYuvRefView == NULL &&  bAnyRefFromOrg --> distortion TBD    ; reference view TBD    ; current view TBD
546  // pcPicYuvRefView == NULL && !bAnyRefFromOrg --> distortion TBD    ; reference view TBD    ; current view correct
547
548  if ( pcPicYuvRefView == NULL )
549  {
550    // Update reference view
551    m_apcRenModels[iModelNum]->setStructSynthViewAsRefView(); 
552
553    // pcPicYuvRefView != NULL &&  bAnyRefFromOrg --> invalid combination
554    // pcPicYuvRefView != NULL && !bAnyRefFromOrg --> distortion correct; reference view correct; current view correct
555    // pcPicYuvRefView == NULL &&  bAnyRefFromOrg --> distortion TBD    ; reference view correct; current view TBD
556    // pcPicYuvRefView == NULL && !bAnyRefFromOrg --> distortion TBD    ; reference view correct; current view correct
557
558    if ( bAnyRefFromOrg )
559    {   
560      // Update current view and distortion
561      for (Int iBaseViewIdx = 0; iBaseViewIdx < m_iNumOfBaseViews; iBaseViewIdx++ )
562      {
563        if ( m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum] != VIEWPOS_INVALID )
564        {
565          m_apcRenModels[iModelNum]->setLRView(
566            m_aaeBaseViewPosInModel[iBaseViewIdx][iModelNum],
567            m_aapiCurVideoPel      [iBaseViewIdx],
568            m_aaiCurVideoStrides   [iBaseViewIdx],
569            m_apiCurDepthPel       [iBaseViewIdx],
570            m_aiCurDepthStrides    [iBaseViewIdx]
571          );
572        }
573      }
574      m_apcRenModels[iModelNum]->renderAll( );
575    }
576    else
577    {
578      // Update to distortion
579      m_apcRenModels[iModelNum]->resetStructError();
580    }
581  }     
582
583  if ( m_bLimOutput )
584  {
585    AOT( m_aaeBaseViewPosInModel[ iEncViewSIdx ][iModelNum] == VIEWPOS_INVALID );
586    Int curViewPosInModel = m_aaeBaseViewPosInModel[ iEncViewSIdx ][iModelNum];   
587    m_apcRenModels[iModelNum]->setLimOutStruct( (curViewPosInModel == VIEWPOS_RIGHT)  ? VIEWPOS_LEFT : VIEWPOS_RIGHT );
588  } 
589#endif
590}
591
592Void
593TRenModel::setErrorMode( Int iView, Int iContent, int iPlane )
594{
595  AOT(iView > m_iNumOfBaseViews || iView < 0);
596  AOT(iContent != 0  &&  iContent != 1);
597  AOT(iPlane < 0     || iPlane > 3);
598
599  m_iCurrentView    = iView;
600  m_iCurrentContent = iContent;
601  m_iCurrentPlane   = iPlane;
602
603  if ( iContent == 1 )
604  {
605    m_iNumOfCurRenModels  = m_aiNumOfModelsForDepthView[iView];
606    m_apcCurRenModels     = m_aapcRenModelForDepthView [iView];
607    m_aiCurPosInModels    = m_aaePosInModelForDepthView[iView];
608  }
609  else
610  {
611    m_iNumOfCurRenModels  = m_aiNumOfModelsForVideoView[iView];
612    m_apcCurRenModels     = m_aapcRenModelForVideoView [iView];
613    m_aiCurPosInModels    = m_aaePosInModelForVideoView[iView];
614  }
615}
616
617
618Void
619TRenModel::setupPart ( UInt uiHorOff, Int iUsedHeight )
620{
621//  AOT( iUsedHeight > m_iHeight );     
622  m_uiHorOff    = uiHorOff; 
623  m_iUsedHeight = iUsedHeight; 
624}
625
626#if H_3D_VSO_EARLY_SKIP
627RMDist
628TRenModel::getDist( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData, Pel * piOrgData, Int iOrgStride)
629#else
630RMDist
631TRenModel::getDist( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, Pel* piNewData )
632#endif
633{
634  iStartPosY -= m_uiHorOff; 
635
636  AOT( iWidth  + iStartPosX > m_iWidth  );
637  AOT( iHeight + iStartPosY > m_iUsedHeight );
638
639  AOT( iStartPosX < 0);
640  AOT( iStartPosY < 0);
641  AOT( iWidth     < 0);
642  AOT( iHeight    < 0);
643
644  RMDist iDist = 0;
645
646  for (Int iModelNum = 0; iModelNum < m_iNumOfCurRenModels; iModelNum++ )
647  {
648    if (m_iCurrentContent == 1)
649    {
650#if H_3D_VSO_EARLY_SKIP
651      iDist +=  m_apcCurRenModels[iModelNum]->getDistDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride,  piNewData , piOrgData, iOrgStride);
652#else
653      iDist +=  m_apcCurRenModels[iModelNum]->getDistDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride,  piNewData );
654#endif
655    }
656    else
657    {
658      iDist +=  m_apcCurRenModels[iModelNum]->getDistVideo  ( m_aiCurPosInModels[iModelNum], m_iCurrentPlane ,iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData );
659    }
660  }
661  return m_iNumOfCurRenModels > 0 ? ( iDist + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels : 0;
662}
663
664Void
665TRenModel::setData( Int iStartPosX, Int iStartPosY, Int iWidth, Int iHeight, Int iStride, const Pel* piNewData )
666{
667  iStartPosY -= m_uiHorOff; 
668
669  iWidth  = min(iWidth , m_iWidth  - iStartPosX );
670  iHeight = min(iHeight, m_iUsedHeight - iStartPosY );
671
672  AOT( iStartPosX < 0);
673  AOT( iStartPosY < 0);
674  AOT( iWidth     < 0);
675  AOT( iHeight    < 0);
676
677  for (Int iModelNum = 0; iModelNum < m_iNumOfCurRenModels; iModelNum++ )
678  {
679    if (m_iCurrentContent == 1)
680    {
681#if H_3D_VSO_EARLY_SKIP
682      Int iTargetStride = m_aiCurDepthStrides[ m_iCurrentView ];
683      m_apcCurRenModels[iModelNum]->setDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData,m_apiCurDepthPel[ m_iCurrentView ] + iStartPosY * iTargetStride + iStartPosX ,iTargetStride );
684#else
685      m_apcCurRenModels[iModelNum]->setDepth  ( m_aiCurPosInModels[iModelNum], iStartPosX, iStartPosY, iWidth, iHeight, iStride, piNewData );
686#endif
687    }
688    else
689    {
690      m_apcCurRenModels[iModelNum]->setVideo  ( m_aiCurPosInModels[iModelNum], m_iCurrentPlane ,iStartPosX, iStartPosY,  iWidth,  iHeight,  iStride, piNewData );
691    }
692  }
693
694#if H_3D_VSO_EARLY_SKIP
695  if (m_iCurrentContent == 1)
696  {
697    Int iTargetStride = m_aiCurDepthStrides[ m_iCurrentView ];
698    TRenFilter<REN_BIT_DEPTH>::copy( piNewData, iStride, iWidth, iHeight,  m_apiCurDepthPel[ m_iCurrentView ] + iStartPosY * iTargetStride + iStartPosX, iTargetStride );
699  }
700#endif
701}
702
703Void
704TRenModel::getSynthVideo( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuv )
705{
706  m_apcRenModels[iModelNum]->getSynthVideo(iViewNum, pcPicYuv );
707}
708
709Void
710TRenModel::getSynthDepth( Int iModelNum, Int iViewNum, TComPicYuv* pcPicYuv )
711{
712  m_apcRenModels[iModelNum]->getSynthDepth(iViewNum, pcPicYuv );
713}
714
715Void
716TRenModel::getTotalSSE( Int64& riSSEY, Int64& riSSEU, Int64& riSSEV )
717{
718  TComPicYuv cPicYuvSynth;
719  cPicYuvSynth.create( m_iWidth, m_iUsedHeight, CHROMA_420, 1, 1, 1, true);
720
721  TComPicYuv cPicYuvTempRef;
722  cPicYuvTempRef.create( m_iWidth, m_iUsedHeight, CHROMA_420, 1, 1, 1, true);
723
724  Int64 iSSEY = 0;
725  Int64 iSSEU = 0;
726  Int64 iSSEV = 0;
727
728  for (Int iCurModel = 0; iCurModel < m_iNumOfCurRenModels; iCurModel++)
729  {
730    m_apcCurRenModels[iCurModel]->getSynthVideo( m_aiCurPosInModels[iCurModel], &cPicYuvSynth );   
731    m_apcCurRenModels[iCurModel]->getRefVideo  ( m_aiCurPosInModels[iCurModel], &cPicYuvTempRef   );
732
733    iSSEY += TRenFilter<REN_BIT_DEPTH>::SSE( cPicYuvSynth.getAddr(  COMPONENT_Y ), cPicYuvSynth.getStride( COMPONENT_Y  ),  m_iWidth,      m_iUsedHeight    , cPicYuvTempRef.getAddr( COMPONENT_Y  ), cPicYuvTempRef.getStride( COMPONENT_Y  ), true  );
734    iSSEU += TRenFilter<REN_BIT_DEPTH>::SSE( cPicYuvSynth.getAddr( COMPONENT_Cb ), cPicYuvSynth.getStride( COMPONENT_Cb ), m_iWidth >> 1, m_iUsedHeight >> 1, cPicYuvTempRef.getAddr( COMPONENT_Cb ), cPicYuvTempRef.getStride( COMPONENT_Cb ), false );
735    iSSEV += TRenFilter<REN_BIT_DEPTH>::SSE( cPicYuvSynth.getAddr( COMPONENT_Cr ), cPicYuvSynth.getStride( COMPONENT_Cr ), m_iWidth >> 1, m_iUsedHeight >> 1, cPicYuvTempRef.getAddr( COMPONENT_Cr ), cPicYuvTempRef.getStride( COMPONENT_Cr ), false );
736  }
737
738  riSSEY = ( iSSEY + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
739  riSSEU = ( iSSEU + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
740  riSSEV = ( iSSEV + (m_iNumOfCurRenModels >> 1) ) / m_iNumOfCurRenModels;
741
742  cPicYuvTempRef.destroy();
743  cPicYuvSynth  .destroy();
744}
745
746Void
747TRenModel::xSetLRViewAndAddModel( Int iModelNum, Int iBaseViewNum, Int iContent, Int iViewPos, Bool bAdd )
748{
749  AOF(iViewPos == VIEWPOS_LEFT  || iViewPos == VIEWPOS_RIGHT);
750  AOF(iContent == -1 || iContent == 0 || iContent == 1);
751  AOT( iBaseViewNum  < 0 || iBaseViewNum  > m_iNumOfBaseViews );
752  AOT( m_aaeBaseViewPosInModel[iBaseViewNum][iModelNum] != VIEWPOS_INVALID );
753  m_aaeBaseViewPosInModel[iBaseViewNum][iModelNum] = iViewPos;
754
755  if (bAdd)
756  {
757    if (iContent == 0 || iContent == -1 )
758    {
759      Int iNewModelIdxForView = m_aiNumOfModelsForVideoView[iBaseViewNum]++;
760      m_aapcRenModelForVideoView [ iBaseViewNum ][ iNewModelIdxForView ] = m_apcRenModels[iModelNum];
761      m_aaePosInModelForVideoView[ iBaseViewNum ][ iNewModelIdxForView ] = iViewPos;
762    }
763
764    if (iContent == 1 || iContent == -1 )
765    {
766      Int iNewModelIdxForView = m_aiNumOfModelsForDepthView[iBaseViewNum]++;
767      m_aapcRenModelForDepthView [ iBaseViewNum ][ iNewModelIdxForView ] = m_apcRenModels[iModelNum];
768      m_aaePosInModelForDepthView[ iBaseViewNum ][ iNewModelIdxForView ] = iViewPos;
769    }
770  }
771}
772#endif // NH_3D
Note: See TracBrowser for help on using the repository browser.