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

Last change on this file since 1265 was 1214, checked in by seregin, 9 years ago

macro cleanup: R0151_CGS_3D_ASYMLUT_IMPROVE

File size: 7.5 KB
Line 
1
2#ifndef __TENC3DASYMLUT__
3#define __TENC3DASYMLUT__
4
5#include "../TLibCommon/TCom3DAsymLUT.h"
6#include "../TLibCommon/TComSlice.h"
7#include "../TLibCommon/CommonDef.h"
8#include "../TLibCommon/TComPic.h"
9#include "TEncCfg.h"
10#if R0179_ENC_OPT_3DLUT_SIZE
11#include "TEncCavlc.h"
12#define MAX_NUM_LUT_SIZES               10   // 4+3+2+1
13#define MAX_Y_SIZE                       4
14#define MAX_C_SIZE                       4
15#endif
16
17#if CGS_3D_ASYMLUT
18
19typedef struct _ColorInfo
20{
21  Double YY , UU , VV;
22  Double Ys , Us , Vs;  // sum of enhancement
23  Double ys , us , vs;  // sum of base
24  Double Yy , Yu , Yv;  // product of enhancement and base
25  Double Uy , Uu , Uv;
26  Double Vy , Vu , Vv;
27  Double yy , yu , yv , uu , uv , vv; // product of base
28  Double N; // number of pixel
29
30public:
31  _ColorInfo & operator += ( const _ColorInfo & rColorInfo )
32  {
33    YY += rColorInfo.YY;
34    UU += rColorInfo.UU;
35    VV += rColorInfo.VV;
36    Ys += rColorInfo.Ys;
37    Us += rColorInfo.Us;
38    Vs += rColorInfo.Vs;
39    ys += rColorInfo.ys;
40    us += rColorInfo.us;
41    vs += rColorInfo.vs;
42    Yy += rColorInfo.Yy;
43    Yu += rColorInfo.Yu;
44    Yv += rColorInfo.Yv;
45    Uy += rColorInfo.Uy;
46    Uu += rColorInfo.Uu;
47    Uv += rColorInfo.Uv;
48    Vy += rColorInfo.Vy;
49    Vu += rColorInfo.Vu;
50    Vv += rColorInfo.Vv;
51    yy += rColorInfo.yy;
52    yu += rColorInfo.yu;
53    yv += rColorInfo.yv;
54    uu += rColorInfo.uu;
55    uv += rColorInfo.uv;
56    vv += rColorInfo.vv;
57    N  += rColorInfo.N; 
58    return *this;
59  }
60
61}SColorInfo;
62
63#if R0179_ENC_OPT_3DLUT_SIZE
64typedef struct _LUTSize
65{
66  Int iYPartNumLog2; 
67  Int iCPartNumLog2; 
68} SLUTSize; 
69#endif
70
71class TEnc3DAsymLUT : public TCom3DAsymLUT
72{
73public:
74  TEnc3DAsymLUT();
75  virtual ~TEnc3DAsymLUT();
76
77  virtual Void  create( Int nMaxOctantDepth , Int nInputBitDepth , Int nInputBitDepthC , Int nOutputBitDepth , Int nOutputBitDepthC , Int nMaxYPartNumLog2 );
78  virtual Void  destroy();
79  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB );
80  Double estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc );
81#if R0179_ENC_OPT_3DLUT_SIZE
82  Double getDistFactor( Int iSliceType, Int iLayer) { return m_dDistFactor[iSliceType][iLayer];}
83  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda );
84  Void   update3DAsymLUTParam( TEnc3DAsymLUT * pSrc );
85#endif
86
87  Void  updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit );
88  Void  setPPSBit(Int n)  { m_nPPSBit = n;  }
89  Int   getPPSBit()       { return m_nPPSBit;}
90  Void  setDsOrigPic(TComPicYuv *pPicYuv) { m_pDsOrigPic = pPicYuv; };
91
92protected:
93  SColorInfo *** m_pColorInfo;
94  SColorInfo *** m_pColorInfoC;
95#if R0179_ENC_OPT_3DLUT_SIZE
96  SColorInfo *** m_pMaxColorInfo;
97  SColorInfo *** m_pMaxColorInfoC;
98#endif
99  TComPicYuv* m_pDsOrigPic;
100  SCuboid *** m_pEncCuboid;
101  SCuboid *** m_pBestEncCuboid;
102  Int         m_nAccuFrameBit;                  // base + enhancement layer
103  Int         m_nAccuFrameCGSBit;
104  Int         m_nPrevFrameCGSPartNumLog2;
105  Double      m_dTotalFrameBit;
106  Int         m_nTotalCGSBit;
107  Int         m_nPPSBit;
108  Int         m_nLUTBitDepth;
109#if R0179_ENC_OPT_3DLUT_SIZE
110
111  Double m_dDistFactor[3][MAX_TLAYER];         
112  Int    m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; 
113  Int    m_nPrevELFrameBit[3][MAX_TLAYER];   
114
115
116  Int   m_nTotalLutSizes;
117  SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES];
118#endif
119  Double m_dSumU;
120  Double m_dSumV;
121  Int    m_nNChroma;
122#if R0179_ENC_OPT_3DLUT_SIZE
123  TComOutputBitstream  *m_pBitstreamRedirect;
124  TEncCavlc *m_pEncCavlc;
125#endif
126
127private:
128  Double  xxDeriveVertexPerColor( 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 ,
129    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
130
131  Void    xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
132  Void    xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
133  Int     xxCoeff2Vertex( 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 ) ); }
134  Void    xxCollectData( TComPic * pCurPic , UInt refLayerIdc );
135
136  Double  xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
137
138  inline Double xxCalEstDist( 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,
139    Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 );
140
141  inline Double xxCalEstDist( 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 );
142
143  inline Double xxCalEstDist( 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 );
144
145#if R0179_ENC_OPT_3DLUT_SIZE
146  Void    xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
147  Void    xxGetAllLutSizes(TComSlice *pSlice);
148  Void    xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC ); 
149  Void    xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
150#endif
151};
152
153Double TEnc3DAsymLUT::xxCalEstDist( 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 ,
154  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 )
155{
156  Double a = 1.0 * ( nP7 - nP3 ) / nLengthY;
157  Double b = 1.0 * ( nP1 - nP0 ) / nLengthUV;
158  Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV;
159  Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY;
160  return( xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) );
161}
162
163Double TEnc3DAsymLUT::xxCalEstDist( 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 ) 
164{
165  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;
166  return( dError );
167};
168
169Double TEnc3DAsymLUT::xxCalEstDist( 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 ) 
170{
171  const Int nOne = xGetNormCoeffOne();
172  Double a = 1.0 * nP0 / nOne;
173  Double b = 1.0 * nP1 / nOne;
174  Double c = 1.0 * nP3 / nOne;
175  Double d = nP7;
176  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;
177  return( dError );
178};
179
180#endif
181
182#endif
Note: See TracBrowser for help on using the repository browser.