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