[1297] | 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 | */ |
---|
[677] | 33 | |
---|
[1297] | 34 | /** \file TEnc3DAsymLUT.cpp |
---|
| 35 | \brief TEnc3DAsymLUT encoder class header |
---|
| 36 | */ |
---|
| 37 | |
---|
[677] | 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" |
---|
[877] | 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 |
---|
[677] | 52 | |
---|
[1212] | 53 | #if CGS_3D_ASYMLUT |
---|
[677] | 54 | |
---|
| 55 | typedef 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 | |
---|
| 66 | public: |
---|
| 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 | |
---|
[877] | 99 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 100 | typedef struct _LUTSize |
---|
| 101 | { |
---|
| 102 | Int iYPartNumLog2; |
---|
| 103 | Int iCPartNumLog2; |
---|
| 104 | } SLUTSize; |
---|
| 105 | #endif |
---|
[677] | 106 | |
---|
| 107 | class TEnc3DAsymLUT : public TCom3DAsymLUT |
---|
| 108 | { |
---|
| 109 | public: |
---|
| 110 | TEnc3DAsymLUT(); |
---|
| 111 | virtual ~TEnc3DAsymLUT(); |
---|
| 112 | |
---|
| 113 | virtual 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 ); |
---|
[877] | 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 |
---|
[677] | 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 | |
---|
| 128 | protected: |
---|
| 129 | SColorInfo *** m_pColorInfo; |
---|
| 130 | SColorInfo *** m_pColorInfoC; |
---|
[877] | 131 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 132 | SColorInfo *** m_pMaxColorInfo; |
---|
| 133 | SColorInfo *** m_pMaxColorInfoC; |
---|
| 134 | #endif |
---|
[677] | 135 | TComPicYuv* m_pDsOrigPic; |
---|
| 136 | SCuboid *** m_pEncCuboid; |
---|
| 137 | SCuboid *** m_pBestEncCuboid; |
---|
[1214] | 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; |
---|
[877] | 145 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 146 | |
---|
| 147 | Double m_dDistFactor[3][MAX_TLAYER]; |
---|
| 148 | Int m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE]; |
---|
| 149 | Int m_nPrevELFrameBit[3][MAX_TLAYER]; |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | Int m_nTotalLutSizes; |
---|
| 153 | SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES]; |
---|
| 154 | #endif |
---|
[825] | 155 | Double m_dSumU; |
---|
| 156 | Double m_dSumV; |
---|
| 157 | Int m_nNChroma; |
---|
[877] | 158 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 159 | TComOutputBitstream *m_pBitstreamRedirect; |
---|
| 160 | TEncCavlc *m_pEncCavlc; |
---|
| 161 | #endif |
---|
[677] | 162 | |
---|
| 163 | private: |
---|
| 164 | 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] | 165 | Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit ); |
---|
[1214] | 166 | |
---|
[677] | 167 | Void xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB ); |
---|
| 168 | Void xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 ); |
---|
| 169 | 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 ) ); } |
---|
| 170 | Void xxCollectData( TComPic * pCurPic , UInt refLayerIdc ); |
---|
[877] | 171 | |
---|
[677] | 172 | Double xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid ); |
---|
[1214] | 173 | |
---|
| 174 | 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, |
---|
| 175 | Int y0, Int u0, Int v0, Int nLengthY, Int nLengthUV, Pel nP0, Pel nP1, Pel nP3, Pel nP7 ); |
---|
| 176 | |
---|
| 177 | 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 ); |
---|
| 178 | |
---|
| 179 | 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 ); |
---|
| 180 | |
---|
[877] | 181 | #if R0179_ENC_OPT_3DLUT_SIZE |
---|
| 182 | Void xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize ); |
---|
| 183 | Void xxGetAllLutSizes(TComSlice *pSlice); |
---|
| 184 | Void xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src , SColorInfo *** dstC, SColorInfo *** srcC ); |
---|
| 185 | Void xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 ); |
---|
| 186 | #endif |
---|
[677] | 187 | }; |
---|
| 188 | |
---|
| 189 | 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 , |
---|
| 190 | Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV , Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 ) |
---|
| 191 | { |
---|
| 192 | Double a = 1.0 * ( nP7 - nP3 ) / nLengthY; |
---|
| 193 | Double b = 1.0 * ( nP1 - nP0 ) / nLengthUV; |
---|
| 194 | Double c = 1.0 * ( nP3 - nP1 ) / nLengthUV; |
---|
| 195 | Double d = ( ( nP0 * nLengthUV + u0 * nP0 + ( v0 - u0 ) * nP1 - v0 * nP3 ) * nLengthY + y0 * nLengthUV * ( nP3 - nP7 ) ) / nLengthUV / nLengthY; |
---|
| 196 | return( xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , d ) ); |
---|
| 197 | } |
---|
| 198 | |
---|
[1214] | 199 | 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, Double a, Double b, Double c, Double d ) |
---|
[677] | 200 | { |
---|
| 201 | 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; |
---|
| 202 | return( dError ); |
---|
| 203 | }; |
---|
[825] | 204 | |
---|
[1214] | 205 | 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, Pel nP0, Pel nP1, Pel nP3, Pel nP7 ) |
---|
[825] | 206 | { |
---|
| 207 | const Int nOne = xGetNormCoeffOne(); |
---|
| 208 | Double a = 1.0 * nP0 / nOne; |
---|
| 209 | Double b = 1.0 * nP1 / nOne; |
---|
| 210 | Double c = 1.0 * nP3 / nOne; |
---|
| 211 | Double d = nP7; |
---|
| 212 | 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; |
---|
| 213 | return( dError ); |
---|
| 214 | }; |
---|
[677] | 215 | |
---|
| 216 | #endif |
---|
[825] | 217 | |
---|
| 218 | #endif |
---|