[677] | 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" |
---|
[877] | 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 |
---|
[677] | 16 | |
---|
| 17 | #if Q0048_CGS_3D_ASYMLUT |
---|
| 18 | |
---|
| 19 | typedef 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 | |
---|
| 30 | public: |
---|
| 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 | |
---|
[877] | 63 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 64 | typedef struct _LUTSize |
---|
| 65 | { |
---|
| 66 | Int iYPartNumLog2; |
---|
| 67 | Int iCPartNumLog2; |
---|
| 68 | } SLUTSize; |
---|
| 69 | #endif |
---|
[677] | 70 | |
---|
| 71 | class TEnc3DAsymLUT : public TCom3DAsymLUT |
---|
| 72 | { |
---|
| 73 | public: |
---|
| 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 ); |
---|
[877] | 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 |
---|
[677] | 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 | |
---|
| 92 | protected: |
---|
| 93 | SColorInfo *** m_pColorInfo; |
---|
| 94 | SColorInfo *** m_pColorInfoC; |
---|
[877] | 95 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 96 | SColorInfo *** m_pMaxColorInfo; |
---|
| 97 | SColorInfo *** m_pMaxColorInfoC; |
---|
| 98 | #endif |
---|
[677] | 99 | TComPicYuv* m_pDsOrigPic; |
---|
| 100 | SCuboid *** m_pEncCuboid; |
---|
| 101 | SCuboid *** m_pBestEncCuboid; |
---|
[855] | 102 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[825] | 103 | Int m_nAccuFrameBit; // base + enhancement layer |
---|
| 104 | Int m_nAccuFrameCGSBit; |
---|
| 105 | Int m_nPrevFrameCGSPartNumLog2; |
---|
[855] | 106 | #else |
---|
| 107 | Int m_nPrevFrameBit[3][MAX_TLAYER]; // base + enhancement layer |
---|
| 108 | Int m_nPrevFrameCGSBit[3][MAX_TLAYER]; |
---|
| 109 | Int m_nPrevFrameCGSPartNumLog2[3][MAX_TLAYER]; |
---|
| 110 | Int m_nPrevFrameOverWritePPS[3][MAX_TLAYER]; |
---|
| 111 | #endif |
---|
[677] | 112 | Double m_dTotalFrameBit; |
---|
| 113 | Int m_nTotalCGSBit; |
---|
| 114 | Int m_nPPSBit; |
---|
| 115 | Int m_nLUTBitDepth; |
---|
[877] | 116 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 117 | |
---|
| 118 | Double m_dDistFactor[3][MAX_TLAYER]; |
---|
| 119 | Int m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; |
---|
| 120 | Int m_nPrevELFrameBit[3][MAX_TLAYER]; |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | Int m_nTotalLutSizes; |
---|
| 124 | SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES]; |
---|
| 125 | #endif |
---|
[825] | 126 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 127 | Double m_dSumU; |
---|
| 128 | Double m_dSumV; |
---|
| 129 | Int m_nNChroma; |
---|
| 130 | #endif |
---|
[877] | 131 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 132 | TComOutputBitstream *m_pBitstreamRedirect; |
---|
| 133 | TEncCavlc *m_pEncCavlc; |
---|
| 134 | #endif |
---|
[677] | 135 | |
---|
| 136 | private: |
---|
[825] | 137 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
[677] | 138 | 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 , |
---|
[825] | 139 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ); |
---|
| 140 | #else |
---|
| 141 | 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 , |
---|
[677] | 142 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , |
---|
| 143 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ); |
---|
[825] | 144 | #endif |
---|
[677] | 145 | Void xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB ); |
---|
| 146 | Void xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 ); |
---|
| 147 | 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 ) ); } |
---|
| 148 | Void xxCollectData( TComPic * pCurPic , UInt refLayerIdc ); |
---|
[877] | 149 | |
---|
[677] | 150 | Double xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid ); |
---|
| 151 | 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 , |
---|
| 152 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 ); |
---|
| 153 | 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 , |
---|
| 154 | Double a , Double b , Double c , Double d ); |
---|
[825] | 155 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 156 | 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 , |
---|
| 157 | Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 ); |
---|
| 158 | #endif |
---|
[877] | 159 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 160 | Void xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize ); |
---|
| 161 | Void xxGetAllLutSizes(TComSlice *pSlice); |
---|
| 162 | Void xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src , SColorInfo *** dstC, SColorInfo *** srcC ); |
---|
| 163 | Void xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 ); |
---|
| 164 | #endif |
---|
[677] | 165 | }; |
---|
| 166 | |
---|
| 167 | Double 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 , |
---|
| 168 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 ) |
---|
| 169 | { |
---|
| 170 | Double a = 1.0 * ( nP7 - nP3 ) / nLengthY; |
---|
| 171 | Double b = 1.0 * ( nP1 - nP0 ) / nLengthUV; |
---|
| 172 | Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV; |
---|
| 173 | Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY; |
---|
| 174 | return( xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) ); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | Double 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 , |
---|
| 178 | Double a , Double b , Double c , Double d ) |
---|
| 179 | { |
---|
| 180 | 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; |
---|
| 181 | return( dError ); |
---|
| 182 | }; |
---|
[825] | 183 | |
---|
| 184 | #if R0151_CGS_3D_ASYMLUT_IMPROVE |
---|
| 185 | Double 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 , |
---|
| 186 | Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 ) |
---|
| 187 | { |
---|
| 188 | const Int nOne = xGetNormCoeffOne(); |
---|
| 189 | Double a = 1.0 * nP0 / nOne; |
---|
| 190 | Double b = 1.0 * nP1 / nOne; |
---|
| 191 | Double c = 1.0 * nP3 / nOne; |
---|
| 192 | Double d = nP7; |
---|
| 193 | 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; |
---|
| 194 | return( dError ); |
---|
| 195 | }; |
---|
[677] | 196 | #endif |
---|
| 197 | |
---|
| 198 | #endif |
---|
[825] | 199 | |
---|
| 200 | #endif |
---|