1 | |
---|
2 | #ifndef __TCOM3DASYMLUT__ |
---|
3 | #define __TCOM3DASYMLUT__ |
---|
4 | |
---|
5 | #include "TypeDef.h" |
---|
6 | |
---|
7 | #if CGS_3D_ASYMLUT |
---|
8 | #include <cassert> |
---|
9 | #include <vector> |
---|
10 | |
---|
11 | typedef struct _SYUVP |
---|
12 | { |
---|
13 | Pel Y , U , V; |
---|
14 | }SYUVP; |
---|
15 | |
---|
16 | typedef struct _SCuboid // vertexes for tetrahedral interpolation |
---|
17 | { |
---|
18 | SYUVP P[4]; // YUV: P0(0,0,0), P1(0,1,0), P3(0,1,1), P7(1,1,1) |
---|
19 | }SCuboid; |
---|
20 | |
---|
21 | class TComPicYuv; |
---|
22 | |
---|
23 | class TCom3DAsymLUT |
---|
24 | { |
---|
25 | public: |
---|
26 | TCom3DAsymLUT(); |
---|
27 | virtual ~TCom3DAsymLUT(); |
---|
28 | |
---|
29 | virtual Void create( Int nMaxOctantDepth, Int nInputBitDepth, Int nInputBitDepthC, Int nOutputBitDepth, Int nOutputBitDepthC, Int nMaxYPartNumLog2, Int nAdaptCThresholdU, Int nAdaptCThresholdV ); |
---|
30 | virtual Void destroy(); |
---|
31 | |
---|
32 | Int getMaxOctantDepth() { return m_nMaxOctantDepth; } |
---|
33 | Int getCurOctantDepth() { return m_nCurOctantDepth; } |
---|
34 | Int getInputBitDepthY() { return m_nInputBitDepthY; } |
---|
35 | Int getOutputBitDepthY() { return m_nOutputBitDepthY; } |
---|
36 | Int getInputBitDepthC() { return m_nInputBitDepthC; } |
---|
37 | Int getOutputBitDepthC() { return m_nOutputBitDepthC; } |
---|
38 | Int getResQuantBit() { return m_nResQuanBit; } |
---|
39 | Void setResQuantBit(Int n) { m_nResQuanBit = n; } |
---|
40 | |
---|
41 | Int getMappingShift() { return m_nMappingShift; } |
---|
42 | Int getDeltaBits() { return m_nDeltaBits; } |
---|
43 | Void setDeltaBits(Int n) { m_nDeltaBits = n; } |
---|
44 | |
---|
45 | Int getMaxYPartNumLog2() { return m_nMaxYPartNumLog2; } |
---|
46 | Int getCurYPartNumLog2() { return m_nCurYPartNumLog2; } |
---|
47 | |
---|
48 | Void addRefLayerId( UInt uiRefLayerId ) |
---|
49 | { |
---|
50 | if( !isRefLayer( uiRefLayerId ) ) |
---|
51 | m_vRefLayerId.push_back( uiRefLayerId ); |
---|
52 | } |
---|
53 | size_t getRefLayerNum() { return m_vRefLayerId.size(); } |
---|
54 | UInt getRefLayerId( UInt n ) { assert( n < m_vRefLayerId.size() ); return m_vRefLayerId[n]; } |
---|
55 | Bool isRefLayer( UInt uiRefLayerId ); |
---|
56 | |
---|
57 | Void setAdaptChromaThresholdU( Int n ) { m_nAdaptCThresholdU = n; } |
---|
58 | Int getAdaptChromaThresholdU() { return m_nAdaptCThresholdU; } |
---|
59 | Void setAdaptChromaThresholdV( Int n ) { m_nAdaptCThresholdV = n; } |
---|
60 | Int getAdaptChromaThresholdV() { return m_nAdaptCThresholdV; } |
---|
61 | |
---|
62 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
63 | Int getMaxYSize() { return 1<<(m_nMaxOctantDepth+m_nMaxYPartNumLog2); } |
---|
64 | Int getMaxCSize() { return 1<<m_nMaxOctantDepth; } |
---|
65 | #endif |
---|
66 | |
---|
67 | Void colorMapping( TComPicYuv * pcPicSrc, TComPicYuv * pcPicDst ); |
---|
68 | Void copy3DAsymLUT( TCom3DAsymLUT * pSrc ); |
---|
69 | |
---|
70 | SYUVP xGetCuboidVertexPredAll( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , SCuboid *** pCurCuboid=NULL ); |
---|
71 | SYUVP getCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx ); |
---|
72 | Void setCuboidVertexResTree( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx , Int deltaY , Int deltaU , Int deltaV ); |
---|
73 | #if R0164_CGS_LUT_BUGFIX_CHECK |
---|
74 | Void xInitCuboids( ); |
---|
75 | Void xCuboidsFilledCheck( Int yIdx , Int uIdx , Int vIdx ); |
---|
76 | Void xCuboidsFilledCheck( Bool bDecode ); |
---|
77 | Void display( Bool bFilled=true ); |
---|
78 | Void xSetExplicit( Int yIdx , Int uIdx , Int vIdx ) { m_pCuboidExplicit[yIdx][uIdx][vIdx] = true ; xSetFilled(yIdx,uIdx,vIdx); } |
---|
79 | Void xSetFilled( Int yIdx , Int uIdx , Int vIdx ) { m_pCuboidFilled[yIdx][uIdx][vIdx] = true ; } |
---|
80 | #endif |
---|
81 | |
---|
82 | private: |
---|
83 | Int m_nMaxOctantDepth; |
---|
84 | Int m_nCurOctantDepth; |
---|
85 | Int m_nInputBitDepthY; |
---|
86 | Int m_nOutputBitDepthY; |
---|
87 | Int m_nInputBitDepthC; |
---|
88 | Int m_nOutputBitDepthC; |
---|
89 | Int m_nDeltaBitDepthC; |
---|
90 | Int m_nDeltaBitDepth; |
---|
91 | Int m_nMaxYPartNumLog2; |
---|
92 | Int m_nCurYPartNumLog2; |
---|
93 | Int m_nMaxPartNumLog2; |
---|
94 | Int m_nYSize; |
---|
95 | Int m_nUSize; |
---|
96 | Int m_nVSize; |
---|
97 | Int m_nYShift2Idx; |
---|
98 | Int m_nUShift2Idx; |
---|
99 | Int m_nVShift2Idx; |
---|
100 | Int m_nMappingShift; |
---|
101 | Int m_nMappingOffset; |
---|
102 | Int m_nResQuanBit; |
---|
103 | Int m_nDeltaBits; |
---|
104 | |
---|
105 | SCuboid *** m_pCuboid; |
---|
106 | const static Int m_nVertexIdxOffset[4][3]; |
---|
107 | std::vector<UInt> m_vRefLayerId; |
---|
108 | |
---|
109 | Int m_nAdaptCThresholdU; |
---|
110 | Int m_nAdaptCThresholdV; |
---|
111 | |
---|
112 | #if R0164_CGS_LUT_BUGFIX_CHECK |
---|
113 | Bool *** m_pCuboidExplicit; |
---|
114 | Bool *** m_pCuboidFilled; |
---|
115 | #endif |
---|
116 | |
---|
117 | protected: |
---|
118 | template <class T> |
---|
119 | Void xAllocate3DArray( T*** &p , Int xSize , Int ySize , Int zSize ); |
---|
120 | template <class T> |
---|
121 | Void xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize ); |
---|
122 | template <class T> |
---|
123 | Void xFree3DArray( T *** &p ); |
---|
124 | |
---|
125 | Void xUpdatePartitioning( Int nCurOctantDepth, Int nCurYPartNumLog2, Int nAdaptCThresholdU, Int nAdaptCThreshodV ); |
---|
126 | SYUVP xGetCuboidVertexPredA( Int yIdx , Int uIdx , Int vIdx , Int nVertexIdx ); |
---|
127 | Pel xMapY( Pel y , Pel u , Pel v ); |
---|
128 | SYUVP xMapUV( Pel y , Pel u , Pel v ); |
---|
129 | Int xGetMaxPartNumLog2() { return m_nMaxPartNumLog2; } |
---|
130 | Int xGetYSize() { return m_nYSize; } |
---|
131 | Int xGetUSize() { return m_nUSize; } |
---|
132 | Int xGetVSize() { return m_nVSize; } |
---|
133 | Int xGetYIdx(Pel y) { return( y >> m_nYShift2Idx ); } |
---|
134 | Int xGetUIdx(Pel u) { return( m_nCurOctantDepth == 1 ? u >= m_nAdaptCThresholdU : u >> m_nUShift2Idx ); } |
---|
135 | Int xGetVIdx(Pel v) { return( m_nCurOctantDepth == 1 ? v >= m_nAdaptCThresholdV : v >> m_nVShift2Idx ); } |
---|
136 | Int xGetNormCoeffOne() { return( 1 << m_nMappingShift ); } |
---|
137 | SCuboid & xGetCuboid( Int yIdx , Int uIdx , Int vIdx ){ return m_pCuboid[yIdx][uIdx][vIdx]; } |
---|
138 | Void xSaveCuboids( SCuboid *** pSrcCuboid ); |
---|
139 | }; |
---|
140 | |
---|
141 | template <class T> |
---|
142 | Void TCom3DAsymLUT::xAllocate3DArray( T *** &p , Int xSize , Int ySize , Int zSize ) |
---|
143 | { |
---|
144 | p = new T**[xSize]; |
---|
145 | p[0] = new T*[xSize*ySize]; |
---|
146 | for( Int x = 1 ; x < xSize ; x++ ) |
---|
147 | { |
---|
148 | p[x] = p[x-1] + ySize; |
---|
149 | } |
---|
150 | p[0][0] = new T[xSize*ySize*zSize]; |
---|
151 | for( Int x = 0 ; x < xSize ; x++ ) |
---|
152 | { |
---|
153 | for( Int y = 0 ; y < ySize ; y++ ) |
---|
154 | { |
---|
155 | p[x][y] = p[0][0] + x * ySize * zSize + y * zSize; |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | template <class T> |
---|
161 | Void TCom3DAsymLUT::xFree3DArray( T *** &p ) |
---|
162 | { |
---|
163 | if( p != NULL ) |
---|
164 | { |
---|
165 | if( p[0] != NULL ) |
---|
166 | { |
---|
167 | if( p[0][0] != NULL ) |
---|
168 | { |
---|
169 | delete [] p[0][0]; |
---|
170 | } |
---|
171 | delete [] p[0]; |
---|
172 | } |
---|
173 | delete [] p; |
---|
174 | p = NULL; |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | template <class T> |
---|
179 | Void TCom3DAsymLUT::xReset3DArray( T*** &p , Int xSize , Int ySize , Int zSize ) |
---|
180 | { |
---|
181 | memset( p[0][0] , 0 , sizeof( T ) * xSize * ySize * zSize ); |
---|
182 | } |
---|
183 | |
---|
184 | #endif |
---|
185 | |
---|
186 | #endif |
---|