[5] | 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-2011, 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 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 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
[5] | 35 | |
---|
[2] | 36 | /** \file TComDepthMapGenerator.h |
---|
| 37 | \brief depth map generator class (header) |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | #ifndef __TCOM_DEPTH_MAP_GENERATOR__ |
---|
| 42 | #define __TCOM_DEPTH_MAP_GENERATOR__ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | #include "CommonDef.h" |
---|
| 46 | #include "TComPic.h" |
---|
| 47 | #include "TComPrediction.h" |
---|
| 48 | #include "TComSlice.h" |
---|
| 49 | |
---|
| 50 | |
---|
[5] | 51 | #if DEPTH_MAP_GENERATION |
---|
[77] | 52 | #if VIDYO_VPS_INTEGRATION |
---|
| 53 | class TComVPSAccess // would be better to have a real VPS buffer |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | TComVPSAccess () { clear(); } |
---|
| 57 | ~TComVPSAccess() {} |
---|
[2] | 58 | |
---|
[77] | 59 | Void clear () { ::memset( m_aacVPS, 0x00, sizeof( m_aacVPS ) ); m_uiActiceVPSId = 0;} |
---|
| 60 | Void addVPS ( TComVPS* pcVPS ) { m_aacVPS[ pcVPS->getVPSId() ] = pcVPS; } |
---|
| 61 | TComVPS* getVPS ( UInt uiVPSId ) { return m_aacVPS[ uiVPSId ]; } |
---|
| 62 | TComVPS* getActiveVPS ( ) { return m_aacVPS[ m_uiActiceVPSId ]; } |
---|
| 63 | Void setActiveVPSId ( UInt activeVPSId ) { m_uiActiceVPSId = activeVPSId; } |
---|
| 64 | private: |
---|
| 65 | TComVPS* m_aacVPS[ MAX_NUM_VPS ]; |
---|
| 66 | UInt m_uiActiceVPSId; |
---|
| 67 | }; |
---|
| 68 | #endif |
---|
[5] | 69 | |
---|
[2] | 70 | class TComSPSAccess // would be better to have a real SPS buffer |
---|
| 71 | { |
---|
| 72 | public: |
---|
| 73 | TComSPSAccess () { clear(); } |
---|
| 74 | ~TComSPSAccess() {} |
---|
| 75 | |
---|
| 76 | Void clear () { ::memset( m_aacActiveSPS, 0x00, sizeof( m_aacActiveSPS ) ); } |
---|
| 77 | Void addSPS ( TComSPS* pcSPS ) { m_aacActiveSPS[ pcSPS->isDepth() ? 1 : 0 ][ pcSPS->getViewId() ] = pcSPS; } |
---|
| 78 | TComSPS* getSPS ( UInt uiViewId, |
---|
| 79 | Bool bIsDepth = false ) { return m_aacActiveSPS[ bIsDepth ? 1 : 0 ][ uiViewId ]; } |
---|
| 80 | |
---|
| 81 | UInt getPdm () { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getPredDepthMapGeneration(); } return 0; } |
---|
[443] | 82 | #if H3D_IVRP & !QC_ARP_D0177 |
---|
[2] | 83 | UInt getResPrd () { if( m_aacActiveSPS[0][1] ) { return m_aacActiveSPS[0][1]->getMultiviewResPredMode (); } return 0; } |
---|
[5] | 84 | #endif |
---|
[2] | 85 | |
---|
| 86 | private: |
---|
[56] | 87 | TComSPS* m_aacActiveSPS[ 2 ][ MAX_VIEW_NUM ]; |
---|
[2] | 88 | }; |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | class TComAUPicAccess // would be better to have a real decoded picture buffer |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | TComAUPicAccess () : m_iLastPoc( 0 ), m_uiMaxViewId( 0 ) { clear(); } |
---|
| 96 | ~TComAUPicAccess() {} |
---|
| 97 | |
---|
| 98 | Void clear () { ::memset( m_aacCurrAUPics, 0x00, sizeof( m_aacCurrAUPics ) ); } |
---|
| 99 | Void addPic ( TComPic* pcPic ) { if( m_iLastPoc != pcPic->getPOC() ) |
---|
| 100 | { |
---|
| 101 | clear(); |
---|
| 102 | m_iLastPoc = pcPic->getPOC(); |
---|
| 103 | } |
---|
| 104 | m_aacCurrAUPics[ pcPic->getSPS()->isDepth() ? 1 : 0 ][ pcPic->getSPS()->getViewId() ] = pcPic; |
---|
| 105 | if( pcPic->getSPS()->getViewId() > m_uiMaxViewId ) |
---|
| 106 | { |
---|
| 107 | m_uiMaxViewId = pcPic->getSPS()->getViewId(); |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | TComPic* getPic ( UInt uiViewId, |
---|
| 111 | Bool bIsDepth = false ) { return m_aacCurrAUPics[ bIsDepth ? 1 : 0 ][ uiViewId ]; } |
---|
| 112 | UInt getMaxVId () { return m_uiMaxViewId; } |
---|
| 113 | |
---|
| 114 | private: |
---|
| 115 | Int m_iLastPoc; |
---|
| 116 | UInt m_uiMaxViewId; |
---|
[56] | 117 | TComPic* m_aacCurrAUPics[ 2 ][ MAX_VIEW_NUM ]; |
---|
[2] | 118 | }; |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | class TComDepthMapGenerator |
---|
| 123 | { |
---|
| 124 | public: |
---|
| 125 | TComDepthMapGenerator (); |
---|
| 126 | ~TComDepthMapGenerator(); |
---|
| 127 | |
---|
[21] | 128 | Void create ( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY ); |
---|
[2] | 129 | Void destroy (); |
---|
| 130 | |
---|
[77] | 131 | #if VIDYO_VPS_INTEGRATION |
---|
| 132 | Void init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess ); |
---|
| 133 | #endif |
---|
[2] | 134 | Void init ( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess ); |
---|
| 135 | Void uninit (); |
---|
| 136 | |
---|
| 137 | Void initViewComponent ( TComPic* pcPic ); |
---|
[296] | 138 | #if !H3D_NBDV |
---|
[2] | 139 | Bool predictDepthMap ( TComPic* pcPic ); |
---|
| 140 | Void updateDepthMap ( TComPic* pcPic ); |
---|
| 141 | Void dumpDepthMap ( TComPic* pcPic, char* pFilenameBase ); |
---|
[100] | 142 | #endif |
---|
[2] | 143 | |
---|
[296] | 144 | #if H3D_IVMP |
---|
[2] | 145 | Void covertOrgDepthMap ( TComPic* pcPic ); |
---|
[5] | 146 | #endif |
---|
[2] | 147 | |
---|
| 148 | UInt getBaseViewId ( UInt uiIdx ) { AOF( uiIdx < m_auiBaseIdList.size() ); return m_auiBaseIdList[uiIdx]; } |
---|
[21] | 149 | UInt getSubSampExpX () { return m_uiSubSampExpX; } |
---|
| 150 | UInt getSubSampExpY () { return m_uiSubSampExpY; } |
---|
[2] | 151 | Int getDisparity ( TComPic* pcPic, Int iPosX, Int iPosY, UInt uiRefViewId ); |
---|
[296] | 152 | #if H3D_IVMP |
---|
| 153 | #if H3D_NBDV |
---|
| 154 | Bool getPdmCandidate ( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo, Int* iPdm, Bool bMerge ); |
---|
| 155 | #else |
---|
[2] | 156 | Int getPdmMergeCandidate ( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv ); |
---|
| 157 | Bool getPdmMvPred ( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge ); |
---|
[100] | 158 | #endif |
---|
[2] | 159 | Bool getIViewOrgDepthMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv ); |
---|
[5] | 160 | #endif |
---|
[2] | 161 | |
---|
| 162 | TComPrediction* getPrediction () { return m_pcPrediction; } |
---|
[77] | 163 | #if VIDYO_VPS_INTEGRATION |
---|
| 164 | TComVPSAccess* getVPSAccess () { return m_pcVPSAccess; } |
---|
| 165 | #endif |
---|
[2] | 166 | TComSPSAccess* getSPSAccess () { return m_pcSPSAccess; } |
---|
| 167 | TComAUPicAccess* getAUPicAccess() { return m_pcAUPicAccess; } |
---|
| 168 | |
---|
| 169 | private: |
---|
| 170 | // picture operations |
---|
[296] | 171 | #if !H3D_NBDV |
---|
[2] | 172 | Bool xConvertDepthMapCurr2Ref ( TComPic* pcRef, TComPic* pcCur ); |
---|
| 173 | Bool xConvertDepthMapRef2Curr ( TComPic* pcCur, TComPic* pcRef ); |
---|
| 174 | Bool xPredictDepthMap ( TComPic* pcPic ); |
---|
| 175 | Bool xFillDepthMapHoles ( TComPic* pcPic ); |
---|
[100] | 176 | Void xClearDepthMap ( TComPic* pcPic, Int iVal = PDM_UNDEFINED_DEPTH |
---|
| 177 | #if PDM_REMOVE_DEPENDENCE |
---|
| 178 | , |
---|
| 179 | Int forFirstNonBaseView = 0 |
---|
| 180 | #endif |
---|
| 181 | ); |
---|
[2] | 182 | Void xSetChroma ( TComPicYuv* pcPic, Int iVal ); |
---|
| 183 | |
---|
| 184 | // CU operations |
---|
| 185 | Void xPredictCUDepthMap ( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx ); // CU depth map prediction |
---|
| 186 | Void xIntraPredictCUDepthMap ( TComDataCU* pcCU, TComYuv* pcCUDepthMap ); // CU intra prediction |
---|
| 187 | Void xInterPredictCUDepthMap ( TComDataCU* pcCU, TComYuv* pcCUDepthMap ); // CU inter prediction |
---|
| 188 | |
---|
| 189 | // PU and block operations |
---|
| 190 | Void xIntraPredictBlkDepthMap ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiAbsPartIdx, UInt uiTrDepth ); // block intra prediction |
---|
| 191 | Void xInterPredictPUDepthMap ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ); // PU inter prediction/update |
---|
| 192 | Void xIViewPUDepthMapUpdate ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ); // PU interview update |
---|
| 193 | Void xInterPUDepthMapUpdate ( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ); // PU inter update |
---|
| 194 | Void xInterPUDepthMapPrediction( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ); // PU inter prediction |
---|
| 195 | Bool xGetPredDepth ( TComDataCU* pcCU, UInt uiPartIdx, Int& riPrdDepth, Int* piPosX = 0, Int* piPosY = 0 ); |
---|
[100] | 196 | #endif |
---|
[2] | 197 | // conversion functions |
---|
| 198 | Int xGetVirtDepthFromDisparity( UInt uiBaseId, Int iDisparity ) |
---|
| 199 | { |
---|
| 200 | AOF( uiBaseId < m_uiCurrViewId ); |
---|
| 201 | Int* pPar = m_aaiConvParsDisparity2VirtDepth[ uiBaseId ]; |
---|
| 202 | Int iRes = ( pPar[ 0 ] * iDisparity + pPar[ 1 ] ) >> pPar[ 2 ]; |
---|
| 203 | return iRes; |
---|
| 204 | } |
---|
| 205 | Int xGetDisparityFromVirtDepth( UInt uiBaseId, Int iVirtDepth ) |
---|
| 206 | { |
---|
| 207 | AOF( uiBaseId < m_uiCurrViewId ); |
---|
| 208 | Int* pPar = m_aaiConvParsVirtDepth2Disparity[ uiBaseId ]; |
---|
| 209 | Int iRes = ( pPar[ 0 ] * iVirtDepth + pPar[ 1 ] ) >> pPar[ 2 ]; |
---|
| 210 | return iRes; |
---|
| 211 | } |
---|
| 212 | Int xGetVirtDepthFromOrigDepth( UInt uiViewId, Int iOrigDepth ) |
---|
| 213 | { |
---|
| 214 | AOF( uiViewId <= m_uiCurrViewId ); |
---|
| 215 | Int* pPar = m_aaiConvParsOrigDepth2VirtDepth[ uiViewId ]; |
---|
| 216 | Int iRes = ( pPar[ 0 ] * iOrigDepth + pPar[ 1 ] ) >> pPar[ 2 ]; |
---|
| 217 | return iRes; |
---|
| 218 | } |
---|
| 219 | Int xGetOrigDepthFromVirtDepth( UInt uiViewId, Int iVirtDepth ) |
---|
| 220 | { |
---|
| 221 | AOF( uiViewId <= m_uiCurrViewId ); |
---|
| 222 | Int* pPar = m_aaiConvParsVirtDepth2OrigDepth[ uiViewId ]; |
---|
| 223 | Int iRes = ( pPar[ 0 ] * iVirtDepth + pPar[ 1 ] ) >> pPar[ 2 ]; |
---|
| 224 | return iRes; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | private: |
---|
| 229 | // general parameters |
---|
| 230 | Bool m_bCreated; |
---|
| 231 | Bool m_bInit; |
---|
| 232 | Bool m_bDecoder; |
---|
| 233 | TComPrediction* m_pcPrediction; |
---|
[210] | 234 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 235 | TComVPSAccess* m_pcVPSAccess; |
---|
| 236 | #endif |
---|
[2] | 237 | TComSPSAccess* m_pcSPSAccess; |
---|
| 238 | TComAUPicAccess* m_pcAUPicAccess; |
---|
| 239 | UInt m_uiMaxDepth; |
---|
| 240 | UInt m_uiOrgDepthBitDepth; |
---|
[21] | 241 | UInt m_uiSubSampExpX; |
---|
| 242 | UInt m_uiSubSampExpY; |
---|
[2] | 243 | TComYuv** m_ppcYuv; |
---|
| 244 | TComDataCU** m_ppcCU; |
---|
| 245 | TComPicYuv m_cTmpPic; |
---|
| 246 | |
---|
| 247 | // conversion parameters |
---|
| 248 | UInt m_uiCurrViewId; |
---|
| 249 | Bool m_bPDMAvailable; |
---|
| 250 | std::vector<UInt> m_auiBaseIdList; |
---|
[56] | 251 | Int m_aaiConvParsDisparity2VirtDepth[ MAX_VIEW_NUM ][ 3 ]; // disparity ==> virtual depth (0:scale, 1:add, 2:shift) |
---|
| 252 | Int m_aaiConvParsVirtDepth2Disparity[ MAX_VIEW_NUM ][ 3 ]; // virtual depth ==> disparity (0:scale, 1:add, 2:shift) |
---|
| 253 | Int m_aaiConvParsOrigDepth2VirtDepth[ MAX_VIEW_NUM ][ 3 ]; // original depth ==> virtual depth (0:scale, 1:add, 2:shift) |
---|
| 254 | Int m_aaiConvParsVirtDepth2OrigDepth[ MAX_VIEW_NUM ][ 3 ]; // virtual depth ==> original depth (0:scale, 1:add, 2:shift) |
---|
[2] | 255 | |
---|
| 256 | // temporary arrays |
---|
| 257 | Bool m_aabDepthSet[ MAX_CU_SIZE >> 2 ][ MAX_CU_SIZE >> 2 ]; |
---|
| 258 | Int m_aai4x4Depth[ MAX_CU_SIZE >> 2 ][ MAX_CU_SIZE >> 2 ]; |
---|
| 259 | }; |
---|
| 260 | |
---|
[5] | 261 | |
---|
| 262 | #endif // DEPTH_MAP_GENERATION |
---|
| 263 | |
---|
[2] | 264 | #endif // __TCOM_DEPTH_MAP_GENERATOR__ |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | |
---|