source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h @ 1499

Last change on this file since 1499 was 1487, checked in by fujitsu, 9 years ago

Added support of scalable range extension profiles. Also corrected few issues such as the confWindow wrong initialization. Code is controlled by the macro SCALABLE_REXT.

File size: 11.0 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 ITU/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/** \file     TEnc3DAsymLUT.cpp
35    \brief    TEnc3DAsymLUT encoder class header
36*/
37
38#ifndef __TENC3DASYMLUT__
39#define __TENC3DASYMLUT__
40
41#include "../TLibCommon/TCom3DAsymLUT.h"
42#include "../TLibCommon/TComSlice.h"
43#include "../TLibCommon/CommonDef.h"
44#include "../TLibCommon/TComPic.h"
45#include "TEncCfg.h"
46#if R0179_ENC_OPT_3DLUT_SIZE
47#include "TEncCavlc.h"
48#define MAX_NUM_LUT_SIZES               10   // 4+3+2+1
49#define MAX_Y_SIZE                       4
50#define MAX_C_SIZE                       4
51#endif
52
53#if CGS_3D_ASYMLUT
54
55typedef struct _ColorInfo
56{
57  Double YY , UU , VV;
58  Double Ys , Us , Vs;  // sum of enhancement
59  Double ys , us , vs;  // sum of base
60  Double Yy , Yu , Yv;  // product of enhancement and base
61  Double Uy , Uu , Uv;
62  Double Vy , Vu , Vv;
63  Double yy , yu , yv , uu , uv , vv; // product of base
64  Double N; // number of pixel
65
66public:
67  _ColorInfo & operator += ( const _ColorInfo & rColorInfo )
68  {
69    YY += rColorInfo.YY;
70    UU += rColorInfo.UU;
71    VV += rColorInfo.VV;
72    Ys += rColorInfo.Ys;
73    Us += rColorInfo.Us;
74    Vs += rColorInfo.Vs;
75    ys += rColorInfo.ys;
76    us += rColorInfo.us;
77    vs += rColorInfo.vs;
78    Yy += rColorInfo.Yy;
79    Yu += rColorInfo.Yu;
80    Yv += rColorInfo.Yv;
81    Uy += rColorInfo.Uy;
82    Uu += rColorInfo.Uu;
83    Uv += rColorInfo.Uv;
84    Vy += rColorInfo.Vy;
85    Vu += rColorInfo.Vu;
86    Vv += rColorInfo.Vv;
87    yy += rColorInfo.yy;
88    yu += rColorInfo.yu;
89    yv += rColorInfo.yv;
90    uu += rColorInfo.uu;
91    uv += rColorInfo.uv;
92    vv += rColorInfo.vv;
93    N  += rColorInfo.N; 
94    return *this;
95  }
96
97}SColorInfo;
98
99#if R0179_ENC_OPT_3DLUT_SIZE
100typedef struct _LUTSize
101{
102  Int iYPartNumLog2; 
103  Int iCPartNumLog2; 
104} SLUTSize; 
105#endif
106
107class TEnc3DAsymLUT : public TCom3DAsymLUT
108{
109public:
110  TEnc3DAsymLUT();
111  virtual ~TEnc3DAsymLUT();
112
113  Void create( Int nMaxOctantDepth, Int nInputBitDepth, Int nInputBitDepthC, Int nOutputBitDepth, Int nOutputBitDepthC, Int nMaxYPartNumLog2 );
114  virtual Void destroy();
115  Double derive3DAsymLUT( TComSlice * pSlice, TComPic * pCurPic, UInt refLayerIdc, TEncCfg * pCfg, Bool bSignalPPS, Bool bElRapSliceTypeB );
116  Double estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc );
117#if R0179_ENC_OPT_3DLUT_SIZE
118  Double getDistFactor( Int iSliceType, Int iLayer) { return m_dDistFactor[iSliceType][iLayer];}
119  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda );
120  Void   update3DAsymLUTParam( TEnc3DAsymLUT * pSrc );
121#endif
122
123  Void  updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit );
124  Void  setPPSBit(Int n)  { m_nPPSBit = n;  }
125  Int   getPPSBit()       { return m_nPPSBit;}
126  Void  setDsOrigPic(TComPicYuv *pPicYuv) { m_pDsOrigPic = pPicYuv; };
127
128protected:
129  SColorInfo *** m_pColorInfo;
130  SColorInfo *** m_pColorInfoC;
131#if R0179_ENC_OPT_3DLUT_SIZE
132  SColorInfo *** m_pMaxColorInfo;
133  SColorInfo *** m_pMaxColorInfoC;
134#endif
135  TComPicYuv* m_pDsOrigPic;
136  SCuboid *** m_pEncCuboid;
137  SCuboid *** m_pBestEncCuboid;
138  Int         m_nAccuFrameBit;                  // base + enhancement layer
139  Int         m_nAccuFrameCGSBit;
140  Int         m_nPrevFrameCGSPartNumLog2;
141  Double      m_dTotalFrameBit;
142  Int         m_nTotalCGSBit;
143  Int         m_nPPSBit;
144  Int         m_nLUTBitDepth;
145#if R0179_ENC_OPT_3DLUT_SIZE
146  Double      m_dDistFactor[3][MAX_TLAYER];         
147  Int         m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; 
148  Int         m_nPrevELFrameBit[3][MAX_TLAYER];   
149
150
151  Int         m_nTotalLutSizes;
152  SLUTSize    m_sLutSizes[MAX_NUM_LUT_SIZES];
153#endif
154  Double      m_dSumU;
155  Double      m_dSumV;
156  Int         m_nNChroma;
157#if R0179_ENC_OPT_3DLUT_SIZE
158  TComOutputBitstream  *m_pBitstreamRedirect;
159  TEncCavlc  *m_pEncCavlc;
160#endif
161
162private:
163  Double  xDeriveVertexPerColor( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, 
164                                 Pel & rP0, Pel & rP1, Pel & rP3, Pel & rP7, Int nResQuantBit );
165
166  Void    xDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
167  Void    xMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
168  Int     xCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
169  Void    xCollectData( TComPic * pCurPic , UInt refLayerIdc );
170
171  Double  xDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
172
173  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY,
174                             Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
175
176  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d );
177#if SCALABLE_REXT
178/*
179former xCalEstDist(Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Pel, Pel, Pel, Pel)
180replaced by this fucntion because behaving differently than other xCalEstDist and was conflicting with xCalEstDist when RExt__HIGH_BIT_DEPTH_SUPPORT = 1
181*/
182  inline Double xCalEstPelDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
183#else
184  inline Double xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
185#endif
186#if R0179_ENC_OPT_3DLUT_SIZE
187  Void    xConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
188  Void    xGetAllLutSizes(TComSlice *pSlice);
189  Void    xCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC ); 
190  Void    xAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
191#endif
192};
193
194Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY,
195                                   Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 )
196{
197  Double a = 1.0 * ( nP7 - nP3 ) / nLengthY;
198  Double b = 1.0 * ( nP1 - nP0 ) / nLengthUV;
199  Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV;
200  Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY;
201  return( xCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) );
202}
203
204Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Double a, Double b, Double c, Double d ) 
205{
206  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
207  return( dError );
208};
209
210
211#if SCALABLE_REXT
212/*
213former xCalEstDist(Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Double, Pel, Pel, Pel, Pel)
214replaced by this fucntion because behaving differently than other xCalEstDist and was conflicting with xCalEstDist when RExt__HIGH_BIT_DEPTH_SUPPORT = 1
215*/
216Double TEnc3DAsymLUT::xCalEstPelDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 ) 
217{
218  const Int nOne = xGetNormCoeffOne();
219  Double a = 1.0 * nP0 / nOne;
220  Double b = 1.0 * nP1 / nOne;
221  Double c = 1.0 * nP3 / nOne;
222  Double d = nP7;
223  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
224  return( dError );
225};
226#else
227Double TEnc3DAsymLUT::xCalEstDist( Double N, Double Ys, Double Yy, Double Yu, Double Yv, Double ys, Double us, Double vs, Double yy, Double yu, Double yv, Double uu, Double uv, Double vv, Double YY, Pel nP0, Pel nP1, Pel nP3, Pel nP7 ) 
228{
229  const Int nOne = xGetNormCoeffOne();
230  Double a = 1.0 * nP0 / nOne;
231  Double b = 1.0 * nP1 / nOne;
232  Double c = 1.0 * nP3 / nOne;
233  Double d = nP7;
234  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
235  return( dError );
236};
237#endif
238
239#endif
240
241#endif
Note: See TracBrowser for help on using the repository browser.