[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.cpp |
---|
| 37 | \brief depth map generator class |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | #include "CommonDef.h" |
---|
| 43 | #include "TComDepthMapGenerator.h" |
---|
| 44 | |
---|
| 45 | |
---|
[5] | 46 | #if DEPTH_MAP_GENERATION |
---|
[2] | 47 | |
---|
[5] | 48 | |
---|
[2] | 49 | TComDepthMapGenerator::TComDepthMapGenerator() |
---|
| 50 | { |
---|
| 51 | m_bCreated = false; |
---|
| 52 | m_bInit = false; |
---|
| 53 | m_bDecoder = false; |
---|
| 54 | m_pcPrediction = 0; |
---|
| 55 | m_pcSPSAccess = 0; |
---|
| 56 | m_pcAUPicAccess = 0; |
---|
| 57 | m_uiMaxDepth = 0; |
---|
| 58 | m_uiOrgDepthBitDepth = 0; |
---|
[21] | 59 | m_uiSubSampExpX = 0; |
---|
| 60 | m_uiSubSampExpY = 0; |
---|
[2] | 61 | m_ppcYuv = 0; |
---|
| 62 | m_ppcCU = 0; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | TComDepthMapGenerator::~TComDepthMapGenerator() |
---|
| 66 | { |
---|
| 67 | destroy (); |
---|
| 68 | uninit (); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | Void |
---|
[21] | 72 | TComDepthMapGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth, UInt uiSubSampExpX, UInt uiSubSampExpY ) |
---|
[2] | 73 | { |
---|
| 74 | destroy(); |
---|
| 75 | m_bDecoder = bDecoder; |
---|
| 76 | m_uiMaxDepth = uiMaxCUDepth; |
---|
| 77 | m_uiOrgDepthBitDepth = uiOrgBitDepth; |
---|
[21] | 78 | m_uiSubSampExpX = uiSubSampExpX; |
---|
| 79 | m_uiSubSampExpY = uiSubSampExpY; |
---|
[100] | 80 | #if !QC_MULTI_DIS_CAN |
---|
[2] | 81 | m_ppcYuv = new TComYuv* [ m_uiMaxDepth ]; |
---|
| 82 | m_ppcCU = new TComDataCU* [ m_uiMaxDepth ]; |
---|
| 83 | for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ ) |
---|
| 84 | { |
---|
| 85 | UInt uiNumPart = 1 << ( ( m_uiMaxDepth - uiDepth ) << 1 ); |
---|
| 86 | UInt uiWidth = uiMaxCUWidth >> uiDepth; |
---|
| 87 | UInt uiHeight = uiMaxCUHeight >> uiDepth; |
---|
| 88 | |
---|
[21] | 89 | m_ppcYuv[ uiDepth ] = new TComYuv; m_ppcYuv[ uiDepth ]->create( uiWidth >> m_uiSubSampExpX, uiHeight >> m_uiSubSampExpY ); |
---|
[56] | 90 | m_ppcCU [ uiDepth ] = new TComDataCU; m_ppcCU [ uiDepth ]->create( uiNumPart, uiWidth, uiHeight, true, uiMaxCUWidth >> (uiMaxCUDepth - 1) ); |
---|
[2] | 91 | } |
---|
[21] | 92 | m_cTmpPic.create( uiPicWidth >> m_uiSubSampExpX, uiPicHeight >> m_uiSubSampExpY, uiMaxCUWidth >> m_uiSubSampExpX, uiMaxCUHeight >> m_uiSubSampExpY, uiMaxCUDepth ); |
---|
[2] | 93 | xSetChroma( &m_cTmpPic, ( 1 << uiOrgBitDepth ) >> 1 ); |
---|
[100] | 94 | #endif |
---|
[2] | 95 | m_bCreated = true; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | Void |
---|
| 99 | TComDepthMapGenerator::destroy() |
---|
| 100 | { |
---|
| 101 | if( m_bCreated ) |
---|
| 102 | { |
---|
| 103 | m_bCreated = false; |
---|
[100] | 104 | #if !QC_MULTI_DIS_CAN |
---|
[2] | 105 | for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ ) |
---|
| 106 | { |
---|
[56] | 107 | if( m_ppcYuv[ uiDepth ] ) |
---|
| 108 | { |
---|
| 109 | m_ppcYuv[ uiDepth ]->destroy(); delete m_ppcYuv[ uiDepth ]; m_ppcYuv[ uiDepth ] = 0; |
---|
| 110 | } |
---|
| 111 | if( m_ppcCU [ uiDepth ] ) |
---|
| 112 | { |
---|
| 113 | m_ppcCU [ uiDepth ]->destroy(); delete m_ppcCU [ uiDepth ]; m_ppcCU [ uiDepth ] = 0; |
---|
| 114 | } |
---|
[2] | 115 | } |
---|
| 116 | delete [] m_ppcYuv; m_ppcYuv = 0; |
---|
| 117 | delete [] m_ppcCU; m_ppcCU = 0; |
---|
| 118 | m_cTmpPic.destroy(); |
---|
[100] | 119 | #endif |
---|
[2] | 120 | m_uiMaxDepth = 0; |
---|
| 121 | m_uiOrgDepthBitDepth = 0; |
---|
[21] | 122 | m_uiSubSampExpX = 0; |
---|
| 123 | m_uiSubSampExpY = 0; |
---|
[2] | 124 | m_bDecoder = false; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
[77] | 128 | #if VIDYO_VPS_INTEGRATION |
---|
[2] | 129 | Void |
---|
[77] | 130 | TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess ) |
---|
| 131 | #else |
---|
| 132 | Void |
---|
[2] | 133 | TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess ) |
---|
[77] | 134 | #endif |
---|
[2] | 135 | { |
---|
| 136 | AOF( pcPrediction ); |
---|
| 137 | AOF( pcSPSAccess ); |
---|
| 138 | AOF( pcAUPicAccess ); |
---|
| 139 | uninit(); |
---|
| 140 | m_pcPrediction = pcPrediction; |
---|
[77] | 141 | #if VIDYO_VPS_INTEGRATION |
---|
| 142 | m_pcVPSAccess = pcVPSAccess; |
---|
| 143 | #endif |
---|
[2] | 144 | m_pcSPSAccess = pcSPSAccess; |
---|
| 145 | m_pcAUPicAccess = pcAUPicAccess; |
---|
| 146 | m_bInit = true; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | Void |
---|
| 150 | TComDepthMapGenerator::uninit() |
---|
| 151 | { |
---|
| 152 | if( m_bInit ) |
---|
| 153 | { |
---|
| 154 | m_bInit = false; |
---|
| 155 | m_pcPrediction = 0; |
---|
| 156 | m_pcSPSAccess = 0; |
---|
| 157 | m_pcAUPicAccess = 0; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | Void |
---|
| 162 | TComDepthMapGenerator::initViewComponent( TComPic* pcPic ) |
---|
| 163 | { |
---|
| 164 | AOF ( m_bCreated && m_bInit ); |
---|
| 165 | AOF ( pcPic ); |
---|
| 166 | AOT ( pcPic->getSPS()->getViewId() && !pcPic->getSPS()->isDepth() && pcPic->getPOC() && pcPic->getSPS()->getPredDepthMapGeneration() != m_pcSPSAccess->getPdm() ); |
---|
| 167 | m_bPDMAvailable = false; |
---|
| 168 | m_uiCurrViewId = pcPic->getSPS()->getViewId(); |
---|
[100] | 169 | #if PDM_REMOVE_DEPENDENCE |
---|
| 170 | pcPic->setStoredPDMforV2(0); |
---|
| 171 | #endif |
---|
[2] | 172 | // update SPS list and AU pic list and set depth map generator in SPS |
---|
[77] | 173 | #if VIDYO_VPS_INTEGRATION |
---|
| 174 | m_pcVPSAccess ->addVPS( pcPic->getVPS() ); |
---|
| 175 | #endif |
---|
[2] | 176 | m_pcSPSAccess ->addSPS( pcPic->getSPS() ); |
---|
| 177 | m_pcAUPicAccess->addPic( pcPic ); |
---|
| 178 | pcPic->getSPS()->setDepthMapGenerator( this ); |
---|
| 179 | |
---|
| 180 | // check whether we have depth data or don't use pred depth prediction |
---|
| 181 | ROFVS( pcPic->getSPS()->getViewId() ); |
---|
| 182 | ROTVS( pcPic->getSPS()->isDepth () ); |
---|
| 183 | ROFVS( m_pcSPSAccess->getPdm () ); |
---|
| 184 | |
---|
| 185 | // set basic SPS parameters |
---|
| 186 | const Int iDisparityDir = 1; // 1 or -1, depending on the usage of disparity vectors |
---|
| 187 | TComSPS* pcSPS = pcPic->getSPS (); |
---|
| 188 | Int iVOI = pcSPS->getViewOrderIdx (); |
---|
| 189 | UInt uiPdmPrec = pcSPS->getPdmPrecision (); |
---|
| 190 | UInt uiCamPrec = pcSPS->getCamParPrecision (); |
---|
| 191 | Bool bInSlice = pcSPS->hasCamParInSliceHeader (); |
---|
| 192 | Int iScaleVOI01 = ( 1 << ( uiPdmPrec + PDM_INTER_CALC_SHIFT + PDM_VIRT_DEPTH_PRECISION - 2 ) ); |
---|
| 193 | |
---|
| 194 | // check availability of base views and set base id list |
---|
| 195 | std::vector<Int> aiAbsDeltaVOI; |
---|
| 196 | for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ ) |
---|
| 197 | { |
---|
| 198 | TComSPS* pcBaseSPS = m_pcSPSAccess ->getSPS( uiBaseId ); |
---|
| 199 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 200 | AOF( pcBaseSPS != 0 && pcBasePic != 0 ); |
---|
| 201 | Int iDeltaVOI = iVOI - pcBaseSPS->getViewOrderIdx(); |
---|
| 202 | Int iAbsDeltaVOI = ( iDeltaVOI < 0 ? -iDeltaVOI : iDeltaVOI ); |
---|
| 203 | AOT( iAbsDeltaVOI == 0 ); |
---|
| 204 | aiAbsDeltaVOI.push_back( iAbsDeltaVOI ); |
---|
| 205 | } |
---|
| 206 | m_auiBaseIdList.clear(); |
---|
| 207 | while( (UInt)m_auiBaseIdList.size() < m_uiCurrViewId ) |
---|
| 208 | { |
---|
| 209 | Int iMinAbsDelta = MAX_INT; |
---|
[56] | 210 | UInt uiNextBaseId = MAX_VIEW_NUM; |
---|
[2] | 211 | for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ ) |
---|
| 212 | { |
---|
| 213 | if( aiAbsDeltaVOI[ uiBaseId ] > 0 && aiAbsDeltaVOI[ uiBaseId ] <= iMinAbsDelta ) |
---|
| 214 | { |
---|
| 215 | iMinAbsDelta = aiAbsDeltaVOI[ uiBaseId ]; |
---|
| 216 | uiNextBaseId = uiBaseId; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | m_auiBaseIdList.push_back( uiNextBaseId ); |
---|
| 220 | aiAbsDeltaVOI[ uiNextBaseId ] = 0; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | // check availability of prediction depth map |
---|
| 224 | if( m_uiCurrViewId ) |
---|
| 225 | { |
---|
[100] | 226 | #if PDM_REMOVE_DEPENDENCE |
---|
| 227 | UInt uiBaseVId = m_auiBaseIdList[0]; |
---|
| 228 | #else |
---|
[2] | 229 | Bool bCheckVId1 = ( m_uiCurrViewId > 1 && m_auiBaseIdList[0] == 0 ); |
---|
| 230 | UInt uiBaseVId = ( bCheckVId1 ? 1 : m_auiBaseIdList[0] ); |
---|
[100] | 231 | #endif |
---|
[2] | 232 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseVId ); |
---|
| 233 | SliceType eSliceType = pcBasePic->getCurrSlice()->getSliceType(); |
---|
| 234 | Bool bNoRAPdm = ( pcPic->getSPS()->getPredDepthMapGeneration() == 1 ); |
---|
| 235 | m_bPDMAvailable = ( eSliceType != I_SLICE || !bNoRAPdm ); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | // update disparity depth conversion parameters |
---|
| 239 | for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ ) |
---|
| 240 | { |
---|
| 241 | TComSPS* pcBaseSPS = m_pcSPSAccess->getSPS( uiBaseId ); |
---|
| 242 | Int iBaseVOI = pcBaseSPS->getViewOrderIdx(); |
---|
| 243 | |
---|
| 244 | // disparity -> virtual depth |
---|
| 245 | Int iVNominator = ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) + pcSPS->getPdmScaleNomDelta()[ uiBaseId ]; |
---|
| 246 | Int iVDiv = iVOI - iBaseVOI; |
---|
| 247 | Int iVAdd = ( iVDiv > 0 ? iVDiv / 2 : -iVDiv / 2 ); |
---|
| 248 | Int iVScalePred = ( iScaleVOI01 + iVAdd ) / iVDiv; |
---|
| 249 | Int iVShift = PDM_INTER_CALC_SHIFT; |
---|
| 250 | Int iVScale = Int( ( (Int64)iVNominator * (Int64)iVScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR ); |
---|
| 251 | Int iVOffset = pcSPS->getPdmOffset()[ uiBaseId ] << PDM_OFFSET_SHIFT; |
---|
| 252 | m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 0 ] = iDisparityDir * iVScale; |
---|
| 253 | m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 1 ] = iDisparityDir * iVOffset + ( ( 1 << iVShift ) >> 1 ); |
---|
| 254 | m_aaiConvParsDisparity2VirtDepth[ uiBaseId ][ 2 ] = iVShift; |
---|
| 255 | |
---|
| 256 | // virtual depth -> disparity |
---|
| 257 | Int iVInvAdd = ( iVScale > 0 ? iVScale / 2 : -iVScale / 2 ); |
---|
| 258 | Int iVInvScale = Int( ( ( Int64( 1 ) << ( iVShift << 1 ) ) + iVInvAdd ) / Int64( iVScale ) ); |
---|
| 259 | Int iVInvOffset = Int( ( ( Int64( -iVOffset ) << iVShift ) + iVInvAdd ) / Int64( iVScale ) ); |
---|
| 260 | m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 0 ] = iDisparityDir * iVInvScale; |
---|
| 261 | m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 1 ] = iDisparityDir * iVInvOffset + ( ( 1 << iVShift ) >> 1 ); |
---|
| 262 | m_aaiConvParsVirtDepth2Disparity[ uiBaseId ][ 2 ] = iVShift; |
---|
| 263 | |
---|
| 264 | // coded depth -> virtual depth |
---|
| 265 | Int iCScale = ( bInSlice ? pcPic->getCurrSlice()->getCodedScale () : pcSPS->getCodedScale () )[ uiBaseId ]; |
---|
| 266 | Int iCOffset = ( bInSlice ? pcPic->getCurrSlice()->getCodedOffset() : pcSPS->getCodedOffset() )[ uiBaseId ] << m_uiOrgDepthBitDepth; |
---|
| 267 | Int iCShift = m_uiOrgDepthBitDepth + uiCamPrec + 1 - 2; |
---|
| 268 | Int iCVShift = PDM_INTER_CALC_SHIFT; |
---|
| 269 | Int iTmpShift = iVShift + iCShift - iCVShift; AOF( iTmpShift >= 0 ) |
---|
| 270 | Int iCVScale = Int( ( Int64( iVScale ) * Int64( iCScale ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift ); |
---|
| 271 | Int iCVOffset = Int( ( Int64( iVScale ) * Int64( iCOffset ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift ); |
---|
| 272 | iTmpShift = iVShift - iCVShift; AOF( iTmpShift >= 0 ) |
---|
| 273 | iCVOffset += ( iVOffset + ( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift; |
---|
| 274 | m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 0 ] = iCVScale; |
---|
| 275 | m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 1 ] = iCVOffset + ( ( 1 << iCVShift ) >> 1 ); |
---|
| 276 | m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ][ 2 ] = iCVShift; |
---|
| 277 | |
---|
| 278 | // virtual depth -> coded depth |
---|
| 279 | Int iCVAdd = ( iCVScale > 0 ? iCVScale / 2 : -iCVScale / 2 ); |
---|
| 280 | Int iCVInvScale = Int( ( ( Int64( 1 ) << ( iCVShift << 1 ) ) + iCVAdd ) / Int64( iCVScale ) ); |
---|
| 281 | Int iCVInvOffset= Int( ( ( Int64( -iCVOffset ) << iCVShift ) + iCVAdd ) / Int64( iCVScale ) ); |
---|
| 282 | m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 0 ] = iCVInvScale; |
---|
| 283 | m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 1 ] = iCVInvOffset + ( ( 1 << iCVShift ) >> 1 ); |
---|
| 284 | m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ][ 2 ] = iCVShift; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | if( m_uiCurrViewId > 0 ) |
---|
| 288 | { |
---|
| 289 | UInt uiBaseId = 0; |
---|
| 290 | UInt uiBaseVOI = 0; // per definition |
---|
| 291 | Int iVNominator = ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) + pcSPS->getPdmScaleNomDelta()[ uiBaseId ]; |
---|
| 292 | Int iVDiv = iVOI - uiBaseVOI; |
---|
| 293 | Int iVAdd = ( iVDiv > 0 ? iVDiv / 2 : -iVDiv / 2 ); |
---|
| 294 | Int iVScalePred = ( iScaleVOI01 + iVAdd ) / iVDiv; |
---|
| 295 | Int iVShift = PDM_INTER_CALC_SHIFT; |
---|
| 296 | Int iVScale = Int( ( (Int64)iVNominator * (Int64)iVScalePred + (Int64)( ( 1 << PDM_LOG4_SCALE_DENOMINATOR ) >> 1 ) ) >> PDM_LOG4_SCALE_DENOMINATOR ); |
---|
| 297 | Int iVOffset = pcSPS->getPdmOffset()[ uiBaseId ] << PDM_OFFSET_SHIFT; |
---|
| 298 | |
---|
| 299 | // coded depth -> virtual depth (current view) |
---|
| 300 | Int iCScale = ( bInSlice ? pcPic->getCurrSlice()->getInvCodedScale () : pcSPS->getInvCodedScale () )[ uiBaseId ]; |
---|
| 301 | Int iCOffset = ( bInSlice ? pcPic->getCurrSlice()->getInvCodedOffset() : pcSPS->getInvCodedOffset() )[ uiBaseId ] << m_uiOrgDepthBitDepth; |
---|
| 302 | Int iCShift = m_uiOrgDepthBitDepth + uiCamPrec + 1 - 2; |
---|
| 303 | Int iCVShift = PDM_INTER_CALC_SHIFT; |
---|
| 304 | Int iTmpShift = iVShift + iCShift - iCVShift; AOF( iTmpShift >= 0 ) |
---|
| 305 | Int iCVScale = Int( ( Int64( -iVScale ) * Int64( iCScale ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift ); |
---|
| 306 | Int iCVOffset = Int( ( Int64( -iVScale ) * Int64( iCOffset ) + Int64( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift ); |
---|
| 307 | iTmpShift = iVShift - iCVShift; AOF( iTmpShift >= 0 ) |
---|
| 308 | iCVOffset += ( iVOffset + ( ( 1 << iTmpShift ) >> 1 ) ) >> iTmpShift; |
---|
| 309 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 0 ] = iCVScale; |
---|
| 310 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 1 ] = iCVOffset + ( ( 1 << iCVShift ) >> 1 ); |
---|
| 311 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 2 ] = iCVShift; |
---|
| 312 | |
---|
| 313 | // virtual depth -> coded depth |
---|
| 314 | Int iCVAdd = ( iCVScale > 0 ? iCVScale / 2 : -iCVScale / 2 ); |
---|
| 315 | Int iCVInvScale = Int( ( ( Int64( 1 ) << ( iCVShift << 1 ) ) + iCVAdd ) / Int64( iCVScale ) ); |
---|
| 316 | Int iCVInvOffset= Int( ( ( Int64( -iCVOffset ) << iCVShift ) + iCVAdd ) / Int64( iCVScale ) ); |
---|
| 317 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 0 ] = iCVInvScale; |
---|
| 318 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 1 ] = iCVInvOffset + ( ( 1 << iCVShift ) >> 1 ); |
---|
| 319 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 2 ] = iCVShift; |
---|
| 320 | } |
---|
| 321 | else if( pcPic->getPOC() == 0 ) |
---|
| 322 | { // set dummy values |
---|
| 323 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 0 ] = 0; |
---|
| 324 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 1 ] = 0; |
---|
| 325 | m_aaiConvParsOrigDepth2VirtDepth[ m_uiCurrViewId ][ 2 ] = 0; |
---|
| 326 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 0 ] = 0; |
---|
| 327 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 1 ] = 0; |
---|
| 328 | m_aaiConvParsVirtDepth2OrigDepth[ m_uiCurrViewId ][ 2 ] = 0; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | #if 0 // print out for debugging |
---|
| 333 | if( m_uiCurrViewId ) |
---|
| 334 | { |
---|
| 335 | printf( "\n\ninit slice of view %d (VOI=%2d):\n===============================\n", m_uiCurrViewId, iVOI ); |
---|
| 336 | { |
---|
| 337 | printf( "\n disparity -> virtual depth:\n" ); |
---|
| 338 | for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ ) |
---|
| 339 | { |
---|
| 340 | Int* pP = m_aaiConvParsDisparity2VirtDepth[ uiBaseId ]; |
---|
| 341 | Double dF = 1.0 / Double( 1 << pP[ 2 ] ); |
---|
| 342 | Double dA = dF * Double( pP[ 0 ] ); |
---|
| 343 | Double dB = dF * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) ); |
---|
| 344 | printf( " BId=%d: a = %10.4lf b = %10.4lf\n", uiBaseId, dA, dB ); |
---|
| 345 | } |
---|
| 346 | printf( "\n virtual depth -> disparity:\n" ); |
---|
| 347 | for( UInt uiBaseId = 0; uiBaseId < m_uiCurrViewId; uiBaseId++ ) |
---|
| 348 | { |
---|
| 349 | Int* pP = m_aaiConvParsVirtDepth2Disparity[ uiBaseId ]; |
---|
| 350 | Double dF = 1.0 / Double( 1 << pP[ 2 ] ); |
---|
| 351 | Double dA = dF * Double( pP[ 0 ] ); |
---|
| 352 | Double dB = dF * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) ); |
---|
| 353 | printf( " BId=%d: a = %10.4lf b = %10.4lf\n", uiBaseId, dA, dB ); |
---|
| 354 | } |
---|
| 355 | printf( "\n original depth -> virtual depth:\n" ); |
---|
| 356 | for( UInt uiBaseId = 0; uiBaseId <= m_uiCurrViewId; uiBaseId++ ) |
---|
| 357 | { |
---|
| 358 | Int* pP = m_aaiConvParsOrigDepth2VirtDepth[ uiBaseId ]; |
---|
| 359 | Double dF = 1.0 / Double( 1 << pP[ 2 ] ); |
---|
| 360 | Double dA = dF * Double( pP[ 0 ] ); |
---|
| 361 | Double dB = dF * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) ); |
---|
| 362 | printf( " VId=%d: a = %10.4lf b = %10.4lf\n", uiBaseId, dA, dB ); |
---|
| 363 | } |
---|
| 364 | printf( "\n virtual depth -> original depth:\n" ); |
---|
| 365 | for( UInt uiBaseId = 0; uiBaseId <= m_uiCurrViewId; uiBaseId++ ) |
---|
| 366 | { |
---|
| 367 | Int* pP = m_aaiConvParsVirtDepth2OrigDepth[ uiBaseId ]; |
---|
| 368 | Double dF = 1.0 / Double( 1 << pP[ 2 ] ); |
---|
| 369 | Double dA = dF * Double( pP[ 0 ] ); |
---|
| 370 | Double dB = dF * Double( pP[ 1 ] - ( ( 1 << pP[ 2 ] ) >> 1 ) ); |
---|
| 371 | printf( " VId=%d: a = %10.4lf b = %10.4lf\n", uiBaseId, dA, dB ); |
---|
| 372 | } |
---|
| 373 | printf( "\n" ); |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | #endif |
---|
| 377 | } |
---|
| 378 | |
---|
[100] | 379 | #if !QC_MULTI_DIS_CAN |
---|
[2] | 380 | Bool |
---|
| 381 | TComDepthMapGenerator::predictDepthMap( TComPic* pcPic ) |
---|
| 382 | { |
---|
| 383 | AOF ( m_bCreated && m_bInit ); |
---|
| 384 | AOF ( pcPic ); |
---|
| 385 | ROTRS( pcPic->getSPS()->isDepth(), true ); |
---|
| 386 | ROFRS( m_pcSPSAccess->getPdm(), true ); |
---|
| 387 | AOF ( pcPic->getPredDepthMap() ); |
---|
| 388 | AOF ( pcPic->getSPS()->getViewId() == m_uiCurrViewId ); |
---|
| 389 | |
---|
| 390 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 391 | Char acFilenameBase[1024]; |
---|
| 392 | ::sprintf( acFilenameBase, "PDM_%s_Prd", ( m_bDecoder ? "Dec" : "Enc" ) ); |
---|
| 393 | #endif |
---|
| 394 | |
---|
| 395 | Bool bUndefined = true; |
---|
| 396 | if( m_uiCurrViewId ) |
---|
| 397 | { |
---|
| 398 | AOF( m_auiBaseIdList.size() ); |
---|
| 399 | UInt uiBaseId = m_auiBaseIdList[ 0 ]; |
---|
| 400 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 401 | AOF( pcBasePic ); |
---|
| 402 | |
---|
| 403 | if( m_uiCurrViewId == 1 ) |
---|
| 404 | { |
---|
| 405 | if( pcBasePic->getPOC() == 0 ) |
---|
| 406 | { |
---|
[21] | 407 | pcBasePic->removePrdDepthMapBuffer(); |
---|
| 408 | pcBasePic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_pcSPSAccess->getPdm()), PDM_SUB_SAMP_EXP_Y(m_pcSPSAccess->getPdm()) ); |
---|
[2] | 409 | xClearDepthMap( pcBasePic ); |
---|
[100] | 410 | #if PDM_REMOVE_DEPENDENCE |
---|
| 411 | xClearDepthMap( pcBasePic, PDM_UNDEFINED_DEPTH, 1 ); |
---|
| 412 | #endif |
---|
[2] | 413 | } |
---|
| 414 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 415 | dumpDepthMap( pcBasePic, acFilenameBase ); |
---|
| 416 | #endif |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | Bool bLoadDepth = ( m_pcSPSAccess->getPdm() == 2 ); |
---|
| 420 | if( m_pcSPSAccess->getPdm() > 2 ) |
---|
| 421 | { |
---|
| 422 | bLoadDepth = ( pcBasePic->getCurrSlice()->getSliceType() == I_SLICE ); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | if( bLoadDepth) |
---|
| 426 | { // load coded depth of base view |
---|
| 427 | TComPic* pcBaseDepth = m_pcAUPicAccess->getPic( uiBaseId, true ); |
---|
| 428 | AOF( pcBaseDepth ); |
---|
| 429 | AOF( pcBaseDepth->getPicYuvRec() ); |
---|
| 430 | AOF( pcBaseDepth->getPicYuvRec()->getWidth () == pcBasePic->getPredDepthMap()->getWidth () ); |
---|
| 431 | AOF( pcBaseDepth->getPicYuvRec()->getHeight() == pcBasePic->getPredDepthMap()->getHeight() ); |
---|
| 432 | Int iWidth = pcBasePic ->getPredDepthMap()->getWidth (); |
---|
| 433 | Int iHeight = pcBasePic ->getPredDepthMap()->getHeight (); |
---|
| 434 | Int iDesStride = pcBasePic ->getPredDepthMap()->getStride (); |
---|
| 435 | Int iSrcStride = pcBaseDepth->getPicYuvRec ()->getStride (); |
---|
| 436 | Pel* pDesSamples = pcBasePic ->getPredDepthMap()->getLumaAddr ( 0 ); |
---|
| 437 | Pel* pSrcSamples = pcBaseDepth->getPicYuvRec ()->getLumaAddr ( 0 ); |
---|
| 438 | for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDesSamples += iDesStride ) |
---|
| 439 | { |
---|
| 440 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 441 | { |
---|
| 442 | pDesSamples[ iX ] = xGetVirtDepthFromOrigDepth( uiBaseId, pSrcSamples[ iX ] ); |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | // convert depth of base view to current view |
---|
| 448 | bUndefined = xConvertDepthMapRef2Curr( pcPic, pcBasePic ); |
---|
| 449 | |
---|
| 450 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 451 | dumpDepthMap( pcPic, acFilenameBase ); |
---|
| 452 | #endif |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | { |
---|
| 456 | xClearDepthMap( pcPic ); |
---|
[100] | 457 | #if PDM_REMOVE_DEPENDENCE |
---|
| 458 | xClearDepthMap( pcPic, PDM_UNDEFINED_DEPTH, 1 ); |
---|
| 459 | #endif |
---|
[2] | 460 | } |
---|
| 461 | return bUndefined; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | |
---|
| 465 | Void |
---|
| 466 | TComDepthMapGenerator::updateDepthMap( TComPic* pcPic ) |
---|
| 467 | { |
---|
| 468 | AOF ( m_bCreated && m_bInit ); |
---|
| 469 | AOF ( pcPic ); |
---|
| 470 | ROTVS( pcPic->getSPS()->isDepth() ); |
---|
| 471 | ROFVS( m_pcSPSAccess->getPdm() == 1 || m_pcSPSAccess->getPdm() == 3 ); |
---|
| 472 | AOF ( pcPic->getPredDepthMap() ); |
---|
| 473 | AOF ( pcPic->getSPS()->getViewId() == m_uiCurrViewId ); |
---|
| 474 | |
---|
| 475 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 476 | Char acFilenameBase[1024]; |
---|
| 477 | ::sprintf( acFilenameBase, "PDM_%s_Upd", ( m_bDecoder ? "Dec" : "Enc" ) ); |
---|
| 478 | #endif |
---|
| 479 | |
---|
| 480 | // predict depth map using current coding symbols |
---|
[100] | 481 | #if PDM_REMOVE_DEPENDENCE |
---|
| 482 | pcPic->setStoredPDMforV2(0); |
---|
[2] | 483 | xPredictDepthMap( pcPic ); |
---|
[100] | 484 | if(m_uiCurrViewId==0) |
---|
| 485 | { |
---|
| 486 | pcPic->setStoredPDMforV2(1); |
---|
| 487 | xPredictDepthMap( pcPic ); |
---|
| 488 | pcPic->setStoredPDMforV2(0); |
---|
| 489 | } |
---|
| 490 | #else |
---|
| 491 | xPredictDepthMap( pcPic ); |
---|
[2] | 492 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 493 | if( m_uiCurrViewId ) |
---|
| 494 | { |
---|
| 495 | dumpDepthMap( pcPic, acFilenameBase ); |
---|
| 496 | } |
---|
| 497 | #endif |
---|
[100] | 498 | #endif |
---|
[2] | 499 | |
---|
| 500 | // generate base depth map |
---|
| 501 | if( m_uiCurrViewId == 1 ) |
---|
| 502 | { |
---|
| 503 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( 0 ); |
---|
| 504 | AOF( pcBasePic ); |
---|
| 505 | xConvertDepthMapCurr2Ref( pcBasePic, pcPic ); |
---|
| 506 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 507 | dumpDepthMap( pcBasePic, acFilenameBase ); |
---|
| 508 | #endif |
---|
| 509 | } |
---|
[100] | 510 | #if PDM_REMOVE_DEPENDENCE |
---|
| 511 | if( m_uiCurrViewId == 2 ) |
---|
| 512 | { |
---|
| 513 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( 0 ); |
---|
| 514 | AOF( pcBasePic ); |
---|
| 515 | xConvertDepthMapCurr2Ref( pcBasePic, pcPic ); |
---|
| 516 | #if PDM_OUTPUT_PRED_DEPTH_MAP |
---|
| 517 | dumpDepthMap( pcBasePic, acFilenameBase ); |
---|
| 518 | #endif |
---|
| 519 | } |
---|
| 520 | #endif |
---|
[2] | 521 | } |
---|
| 522 | |
---|
| 523 | |
---|
| 524 | Void |
---|
| 525 | TComDepthMapGenerator::dumpDepthMap( TComPic* pcPic, char* pFilenameBase ) |
---|
| 526 | { |
---|
| 527 | AOF( m_bCreated && m_bInit ); |
---|
| 528 | AOF( pcPic ); |
---|
| 529 | AOF( pFilenameBase ); |
---|
| 530 | AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement ); |
---|
| 531 | AOF( pcPic->getSPS()->getViewId() <= m_uiCurrViewId ); |
---|
| 532 | |
---|
| 533 | // convert to output format |
---|
| 534 | Int iMax = ( 1 << m_uiOrgDepthBitDepth ) - 1; |
---|
| 535 | UInt uiViewId = pcPic->getSPS()->getViewId(); |
---|
| 536 | TComPicYuv* pcPicYuv = pcPic->getPredDepthMap(); |
---|
| 537 | Int iWidth = pcPicYuv->getWidth (); |
---|
| 538 | Int iHeight = pcPicYuv->getHeight (); |
---|
| 539 | Int iSrcStride = pcPicYuv->getStride (); |
---|
| 540 | Int iDstStride = m_cTmpPic.getStride (); |
---|
[100] | 541 | #if PDM_REMOVE_DEPENDENCE |
---|
| 542 | if(pcPic->getStoredPDMforV2()) |
---|
| 543 | pcPicYuv = pcPic->getPredDepthMapTemp(); |
---|
| 544 | #endif |
---|
[2] | 545 | Pel* pSrcSamples = pcPicYuv->getLumaAddr ( 0 ); |
---|
| 546 | Pel* pDstSamples = m_cTmpPic.getLumaAddr ( 0 ); |
---|
| 547 | Int iMidOrgDpth = ( 1 << m_uiOrgDepthBitDepth ) >> 1; |
---|
| 548 | AOF( m_cTmpPic.getWidth () == iWidth ); |
---|
| 549 | AOF( m_cTmpPic.getHeight() == iHeight ); |
---|
| 550 | for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride ) |
---|
| 551 | { |
---|
| 552 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 553 | { |
---|
| 554 | Int iOrgDepth = ( pSrcSamples[ iX ] != PDM_UNDEFINED_DEPTH ? xGetOrigDepthFromVirtDepth( uiViewId, pSrcSamples[ iX ] ) : iMidOrgDpth ); |
---|
| 555 | pDstSamples[ iX ] = Max( 0, Min( iMax, iOrgDepth ) ); |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | // output |
---|
| 560 | Char acFilename[1024]; |
---|
| 561 | ::sprintf ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId ); |
---|
| 562 | m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 ) ); |
---|
| 563 | } |
---|
[100] | 564 | #endif |
---|
[2] | 565 | |
---|
[5] | 566 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
[2] | 567 | Void |
---|
| 568 | TComDepthMapGenerator::covertOrgDepthMap( TComPic* pcPic ) |
---|
| 569 | { |
---|
| 570 | AOF ( m_bCreated && m_bInit ); |
---|
| 571 | AOF ( pcPic ); |
---|
| 572 | ROFVS( pcPic->getOrgDepthMap() ); |
---|
[56] | 573 | AOF ( pcPic->getViewId() ); |
---|
[2] | 574 | |
---|
[56] | 575 | UInt uiBaseId = pcPic->getViewId(); |
---|
[2] | 576 | Int iWidth = pcPic->getOrgDepthMap()->getWidth (); |
---|
| 577 | Int iHeight = pcPic->getOrgDepthMap()->getHeight (); |
---|
| 578 | Int iStride = pcPic->getOrgDepthMap()->getStride (); |
---|
| 579 | Pel* pSamples = pcPic->getOrgDepthMap()->getLumaAddr ( 0 ); |
---|
| 580 | for( Int iY = 0; iY < iHeight; iY++, pSamples += iStride ) |
---|
| 581 | { |
---|
| 582 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 583 | { |
---|
| 584 | pSamples[ iX ] = xGetVirtDepthFromOrigDepth( uiBaseId, pSamples[ iX ] ); |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | } |
---|
[5] | 588 | #endif |
---|
[2] | 589 | |
---|
| 590 | Int |
---|
| 591 | TComDepthMapGenerator::getDisparity( TComPic* pcPic, Int iPosX, Int iPosY, UInt uiRefViewId ) |
---|
| 592 | { |
---|
| 593 | AOF( pcPic ); |
---|
| 594 | AOF( pcPic->getPredDepthMap() ); |
---|
| 595 | AOF( iPosX >= 0 && iPosX < pcPic->getPredDepthMap()->getWidth () ); |
---|
| 596 | AOF( iPosY >= 0 && iPosY < pcPic->getPredDepthMap()->getHeight() ); |
---|
| 597 | Pel* piPdmMap = pcPic->getPredDepthMap()->getLumaAddr( 0 ); |
---|
| 598 | Int iStride = pcPic->getPredDepthMap()->getStride (); |
---|
| 599 | Int iPrdDepth = piPdmMap[ iPosX + iPosY * iStride ]; |
---|
| 600 | Int iDisparity = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth ); |
---|
| 601 | return iDisparity; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | |
---|
| 605 | |
---|
[5] | 606 | #if HHI_INTER_VIEW_MOTION_PRED |
---|
[100] | 607 | #if QC_MULTI_DIS_CAN |
---|
[2] | 608 | Int |
---|
[100] | 609 | TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo ) |
---|
| 610 | #else |
---|
| 611 | Int |
---|
[2] | 612 | TComDepthMapGenerator::getPdmMergeCandidate( TComDataCU* pcCU, UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv ) |
---|
[100] | 613 | #endif |
---|
[2] | 614 | { |
---|
[100] | 615 | #if MTK_INTERVIEW_MERGE_A0049 |
---|
| 616 | AOF ( m_bCreated && m_bInit ); |
---|
| 617 | |
---|
| 618 | #if !QC_MULTI_DIS_CAN |
---|
| 619 | ROFRS( m_bPDMAvailable, 0 ); |
---|
| 620 | #endif |
---|
| 621 | |
---|
| 622 | TComSlice* pcSlice = pcCU->getSlice (); |
---|
| 623 | TComSPS* pcSPS = pcSlice->getSPS(); |
---|
| 624 | AOF ( pcSPS->getViewId() == m_uiCurrViewId ); |
---|
| 625 | Bool bPdmMerge = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ); |
---|
| 626 | ROTRS( !bPdmMerge, 0 ); |
---|
| 627 | |
---|
| 628 | Bool abPdmAvailable[2] = {false,false}; |
---|
| 629 | |
---|
| 630 | Int iValid = 0; |
---|
| 631 | Int iViewId = 0; |
---|
| 632 | for( UInt uiBId = 0; uiBId < m_uiCurrViewId && iValid==0; uiBId++ ) |
---|
| 633 | { |
---|
| 634 | UInt uiBaseId = m_auiBaseIdList[ uiBId ]; |
---|
| 635 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 636 | for( Int iRefListId = 0; iRefListId < 2 && iValid==0; iRefListId++ ) |
---|
| 637 | { |
---|
| 638 | RefPicList eRefPicListTest = RefPicList( iRefListId ); |
---|
| 639 | Int iNumRefPics = pcSlice->getNumRefIdx( eRefPicListTest ) ; |
---|
| 640 | for( Int iRefIndex = 0; iRefIndex < iNumRefPics; iRefIndex++ ) |
---|
| 641 | { |
---|
| 642 | if(pcBasePic->getPOC() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getPOC() |
---|
| 643 | && pcBasePic->getViewId() == pcSlice->getRefPic( eRefPicListTest, iRefIndex )->getViewId()) |
---|
| 644 | { |
---|
| 645 | iValid=1; |
---|
| 646 | iViewId = uiBaseId; |
---|
| 647 | break; |
---|
| 648 | } |
---|
| 649 | } |
---|
| 650 | } |
---|
| 651 | } |
---|
| 652 | if (iValid == 0) |
---|
| 653 | return 0; |
---|
| 654 | |
---|
| 655 | //--- get base CU/PU and check prediction mode --- |
---|
| 656 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( iViewId ); |
---|
| 657 | TComPicYuv* pcBaseRec = pcBasePic->getPicYuvRec (); |
---|
| 658 | |
---|
| 659 | #if QC_MULTI_DIS_CAN |
---|
| 660 | Int iCurrPosX, iCurrPosY; |
---|
| 661 | UInt uiPartAddr; |
---|
| 662 | Int iWidth; |
---|
| 663 | Int iHeight; |
---|
| 664 | |
---|
| 665 | pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 666 | pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY ); |
---|
| 667 | iCurrPosX += ( ( iWidth - 1 ) >> 1 ); |
---|
| 668 | iCurrPosY += ( ( iHeight - 1 ) >> 1 ); |
---|
| 669 | |
---|
| 670 | Int iBasePosX = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) ); |
---|
| 671 | Int iBasePosY = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); |
---|
| 672 | Int iBaseCUAddr; |
---|
| 673 | Int iBaseAbsPartIdx; |
---|
| 674 | pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx ); |
---|
| 675 | #else |
---|
| 676 | Int iPrdDepth, iCurrPosX, iCurrPosY; |
---|
| 677 | Bool bAvailable = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY ); |
---|
| 678 | AOF( bAvailable ); |
---|
| 679 | TComPicYuv* pcBasePdm = pcBasePic->getPredDepthMap(); |
---|
| 680 | Int iDisparity = xGetDisparityFromVirtDepth( iViewId, iPrdDepth ); |
---|
| 681 | Int iShiftX = m_uiSubSampExpX + 2; |
---|
| 682 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
| 683 | Int iBasePosX = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) ); |
---|
| 684 | Int iBasePosY = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY ); |
---|
| 685 | Int iBaseCUAddr; |
---|
| 686 | Int iBaseAbsPartIdx; |
---|
| 687 | pcBaseRec->getCUAddrAndPartIdx( iBasePosX<< m_uiSubSampExpX , iBasePosY<< m_uiSubSampExpY , iBaseCUAddr, iBaseAbsPartIdx ); |
---|
| 688 | #endif |
---|
| 689 | |
---|
| 690 | TComDataCU* pcBaseCU = pcBasePic->getCU( iBaseCUAddr ); |
---|
| 691 | |
---|
| 692 | if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_INTER || pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) == MODE_SKIP ) |
---|
| 693 | { |
---|
| 694 | for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ ) |
---|
| 695 | { |
---|
| 696 | RefPicList eBaseRefPicList = RefPicList( uiBaseRefListId ); |
---|
| 697 | TComMvField cBaseMvField; |
---|
| 698 | pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField ); |
---|
| 699 | Int iBaseRefIdx = cBaseMvField.getRefIdx(); |
---|
| 700 | |
---|
| 701 | if (iBaseRefIdx >= 0) |
---|
| 702 | { |
---|
| 703 | Int iBaseRefPOC = pcBaseCU->getSlice()->getRefPOC(eBaseRefPicList, iBaseRefIdx); |
---|
| 704 | if (iBaseRefPOC != pcSlice->getPOC()) |
---|
| 705 | { |
---|
| 706 | for (Int iPdmRefIdx = 0; iPdmRefIdx < pcSlice->getNumRefIdx( eBaseRefPicList ); iPdmRefIdx++) |
---|
| 707 | { |
---|
| 708 | if (iBaseRefPOC == pcSlice->getRefPOC(eBaseRefPicList, iPdmRefIdx)) |
---|
| 709 | { |
---|
| 710 | abPdmAvailable[ uiBaseRefListId ] = true; |
---|
| 711 | paiPdmRefIdx [ uiBaseRefListId ] = iPdmRefIdx; |
---|
| 712 | TComMv cMv(cBaseMvField.getHor(), cBaseMvField.getVer()); |
---|
| 713 | #if LGE_DVMCP |
---|
| 714 | cMv.m_bDvMcp = true; |
---|
| 715 | cMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor(); |
---|
| 716 | #endif |
---|
| 717 | pcCU->clipMv( cMv ); |
---|
| 718 | pacPdmMv [ uiBaseRefListId ] = cMv; |
---|
| 719 | break; |
---|
| 720 | } |
---|
| 721 | } |
---|
| 722 | } |
---|
| 723 | } |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | Int iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ); |
---|
| 727 | |
---|
| 728 | if (iPdmInterDir == 0) |
---|
| 729 | { |
---|
| 730 | for( Int iRefListId = 0; iRefListId < 2 ; iRefListId++ ) |
---|
| 731 | { |
---|
| 732 | RefPicList eRefPicList = RefPicList( iRefListId ); |
---|
| 733 | Int iNumRefPics = pcSlice->getNumRefIdx( eRefPicList ); |
---|
| 734 | for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ ) |
---|
| 735 | { |
---|
| 736 | if( pcSlice->getRefPOC( eRefPicList, iPdmRefIdx ) == pcSlice->getPOC()) |
---|
| 737 | { |
---|
| 738 | abPdmAvailable[ iRefListId ] = true; |
---|
| 739 | paiPdmRefIdx [ iRefListId ] = iPdmRefIdx; |
---|
| 740 | #if QC_MULTI_DIS_CAN |
---|
| 741 | TComMv cMv = pDInfo->m_acMvCand[0]; |
---|
| 742 | cMv.setVer(0); |
---|
| 743 | #else |
---|
| 744 | TComMv cMv(iDisparity, 0); |
---|
| 745 | #endif |
---|
| 746 | pcCU->clipMv( cMv ); |
---|
| 747 | pacPdmMv [ iRefListId ] = cMv; |
---|
| 748 | break; |
---|
| 749 | } |
---|
| 750 | } |
---|
| 751 | } |
---|
| 752 | iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ) ; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | return iPdmInterDir; |
---|
| 756 | |
---|
| 757 | #else |
---|
[2] | 758 | Int iMaxNumInterPics = 1; |
---|
| 759 | Int iMaxNumAllPics = 2; |
---|
| 760 | |
---|
| 761 | // inter-only |
---|
| 762 | Bool abPdmAvailable[2] = {false,false}; |
---|
| 763 | for( Int iRefListId = 0; iRefListId < 2; iRefListId++ ) |
---|
| 764 | { |
---|
| 765 | RefPicList eRefPicList = RefPicList( iRefListId ); |
---|
| 766 | Int iNumRefPics = pcCU->getSlice()->getNumRefIdx( eRefPicList ); |
---|
| 767 | TComMv cMv; |
---|
| 768 | for( Int iPdmRefIdx = 0, iInterPics = 0; iPdmRefIdx < iNumRefPics && iInterPics < iMaxNumInterPics; iPdmRefIdx++ ) |
---|
| 769 | { |
---|
| 770 | if( pcCU->getSlice()->getRefPOC( eRefPicList, iPdmRefIdx ) != pcCU->getSlice()->getPOC() ) |
---|
| 771 | { |
---|
[100] | 772 | #if QC_MULTI_DIS_CAN |
---|
| 773 | if( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) ) |
---|
| 774 | #else |
---|
[2] | 775 | if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) ) |
---|
[100] | 776 | #endif |
---|
[2] | 777 | { |
---|
| 778 | pcCU->clipMv( cMv ); |
---|
| 779 | abPdmAvailable[ iRefListId ] = true; |
---|
| 780 | paiPdmRefIdx [ iRefListId ] = iPdmRefIdx; |
---|
| 781 | pacPdmMv [ iRefListId ] = cMv; |
---|
| 782 | break; |
---|
| 783 | } |
---|
| 784 | iInterPics++; |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | } |
---|
| 788 | Int iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ); |
---|
| 789 | if( 0==iPdmInterDir ) |
---|
| 790 | { // check all, including inter view references |
---|
| 791 | for( Int iRefListId = 0; iRefListId < 2; iRefListId++ ) |
---|
| 792 | { |
---|
| 793 | RefPicList eRefPicList = RefPicList( iRefListId ); |
---|
| 794 | Int iNumRefPics = Min( iMaxNumAllPics, pcCU->getSlice()->getNumRefIdx( eRefPicList ) ); |
---|
| 795 | TComMv cMv; |
---|
| 796 | for( Int iPdmRefIdx = 0; iPdmRefIdx < iNumRefPics; iPdmRefIdx++ ) |
---|
| 797 | { |
---|
[100] | 798 | #if QC_MULTI_DIS_CAN |
---|
| 799 | if ( getDisCanPdmMvPred (pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, pDInfo, true ) ) |
---|
| 800 | #else |
---|
[2] | 801 | if( getPdmMvPred( pcCU, uiPartIdx, eRefPicList, iPdmRefIdx, cMv, true ) ) |
---|
[100] | 802 | #endif |
---|
[2] | 803 | { |
---|
| 804 | pcCU->clipMv( cMv ); |
---|
| 805 | abPdmAvailable[ iRefListId ] = true; |
---|
| 806 | paiPdmRefIdx [ iRefListId ] = iPdmRefIdx; |
---|
| 807 | pacPdmMv [ iRefListId ] = cMv; |
---|
| 808 | break; |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | iPdmInterDir = ( abPdmAvailable[0] ? 1 : 0 ) + ( abPdmAvailable[1] ? 2 : 0 ); |
---|
| 813 | } |
---|
| 814 | return iPdmInterDir; |
---|
[100] | 815 | #endif |
---|
[2] | 816 | } |
---|
| 817 | |
---|
[100] | 818 | #if QC_MULTI_DIS_CAN |
---|
| 819 | Bool |
---|
| 820 | TComDepthMapGenerator::getDisCanPdmMvPred ( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge ) |
---|
| 821 | { |
---|
| 822 | #if LGE_DVMCP |
---|
| 823 | rcMv.m_bDvMcp = false; |
---|
| 824 | #endif |
---|
| 825 | AOF ( m_bCreated && m_bInit ); |
---|
| 826 | AOF ( iRefIdx >= 0 ); |
---|
| 827 | AOF ( pcCU ); |
---|
| 828 | //ROFRS( m_bPDMAvailable, false ); |
---|
| 829 | TComSlice* pcSlice = pcCU->getSlice (); |
---|
| 830 | TComSPS* pcSPS = pcSlice->getSPS(); |
---|
| 831 | AOF ( pcSPS->getViewId() == m_uiCurrViewId ); |
---|
| 832 | TComPic* pcRefPic = pcSlice->getRefPic( eRefPicList, iRefIdx ); |
---|
| 833 | UInt uiRefViewId = pcRefPic->getSPS()->getViewId(); |
---|
| 834 | Int iRefPoc = pcRefPic->getPOC(); |
---|
| 835 | Bool bInterview = ( uiRefViewId < m_uiCurrViewId ); |
---|
| 836 | AOT( bInterview && iRefPoc != pcSlice->getPOC() ); |
---|
| 837 | AOT( !bInterview && iRefPoc == pcSlice->getPOC() ); |
---|
| 838 | Bool bPdmIView = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW ); |
---|
| 839 | Bool bPdmInter = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER ); |
---|
| 840 | Bool bPdmMerge = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ); |
---|
| 841 | ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false ); |
---|
| 842 | ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false ); |
---|
| 843 | ROTRS( bMerge && !bPdmMerge, false ); |
---|
| 844 | Int iCurrPosX, iCurrPosY; |
---|
| 845 | TComMv cDisMv; |
---|
[2] | 846 | |
---|
[100] | 847 | if( bInterview ) |
---|
| 848 | { |
---|
| 849 | rcMv = pDInfo->m_acMvCand[0]; |
---|
| 850 | rcMv.setVer(0); |
---|
| 851 | return true; |
---|
| 852 | } |
---|
| 853 | for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ ) |
---|
| 854 | { |
---|
| 855 | UInt uiBaseId = uiBId; //m_auiBaseIdList[ uiBId ]; |
---|
| 856 | |
---|
| 857 | if (m_uiCurrViewId >1 && uiBaseId ==1 ) |
---|
| 858 | continue; |
---|
| 859 | |
---|
| 860 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 861 | TComPicYuv* pcBaseRec = pcBasePic->getPicYuvRec (); |
---|
| 862 | UInt uiPartAddr; |
---|
| 863 | Int iWidth; |
---|
| 864 | Int iHeight; |
---|
| 865 | |
---|
| 866 | pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 867 | pcBaseRec->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY ); |
---|
| 868 | iCurrPosX += ( ( iWidth - 1 ) >> 1 ); |
---|
| 869 | iCurrPosY += ( ( iHeight - 1 ) >> 1 ); |
---|
| 870 | Int iBasePosX = Clip3( 0, pcBaseRec->getWidth () - 1, iCurrPosX + ( (pDInfo->m_acMvCand[0].getHor() + 2 ) >> 2 ) ); |
---|
| 871 | Int iBasePosY = Clip3( 0, pcBaseRec->getHeight() - 1, iCurrPosY + ( (pDInfo->m_acMvCand[0].getVer() + 2 ) >> 2 )); |
---|
| 872 | Int iBaseCUAddr; |
---|
| 873 | Int iBaseAbsPartIdx; |
---|
| 874 | pcBaseRec->getCUAddrAndPartIdx( iBasePosX , iBasePosY , iBaseCUAddr, iBaseAbsPartIdx ); |
---|
| 875 | TComDataCU* pcBaseCU = pcBasePic->getCU( iBaseCUAddr ); |
---|
| 876 | if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP ) |
---|
| 877 | { |
---|
| 878 | continue; |
---|
| 879 | } |
---|
| 880 | for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ ) |
---|
| 881 | { |
---|
| 882 | RefPicList eBaseRefPicList = RefPicList( uiBaseRefListId ); |
---|
| 883 | TComMvField cBaseMvField; |
---|
| 884 | pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField ); |
---|
| 885 | Int iBaseRefIdx = cBaseMvField.getRefIdx(); |
---|
| 886 | Int iBaseRefPoc = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) ); |
---|
| 887 | if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc ) |
---|
| 888 | { |
---|
| 889 | rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() ); |
---|
| 890 | #if LGE_DVMCP |
---|
| 891 | // save disparity vector when a merge candidate for IVMP is set as DV-MCP |
---|
| 892 | if( bMerge ) |
---|
| 893 | { |
---|
| 894 | rcMv.m_bDvMcp = true; |
---|
| 895 | rcMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor(); |
---|
| 896 | } |
---|
| 897 | else { // AMVP ? |
---|
| 898 | rcMv.m_bDvMcp = false; |
---|
| 899 | } |
---|
| 900 | #endif |
---|
| 901 | return true; |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | return false; |
---|
| 906 | } |
---|
| 907 | #else |
---|
[2] | 908 | Bool |
---|
| 909 | TComDepthMapGenerator::getPdmMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, Bool bMerge ) |
---|
| 910 | { |
---|
| 911 | AOF ( m_bCreated && m_bInit ); |
---|
| 912 | AOF ( iRefIdx >= 0 ); |
---|
| 913 | AOF ( pcCU ); |
---|
| 914 | ROFRS( m_bPDMAvailable, false ); |
---|
| 915 | |
---|
| 916 | TComSlice* pcSlice = pcCU->getSlice (); |
---|
| 917 | TComPic* pcPic = pcCU->getPic (); |
---|
| 918 | TComSPS* pcSPS = pcSlice->getSPS(); |
---|
| 919 | AOF ( pcPic->getPredDepthMap() ); |
---|
| 920 | AOF ( pcSPS->getViewId() == m_uiCurrViewId ); |
---|
| 921 | |
---|
| 922 | TComPic* pcRefPic = pcSlice->getRefPic( eRefPicList, iRefIdx ); |
---|
| 923 | UInt uiRefViewId = pcRefPic->getSPS()->getViewId(); |
---|
| 924 | Int iRefPoc = pcRefPic->getPOC(); |
---|
| 925 | Bool bInterview = ( uiRefViewId < m_uiCurrViewId ); |
---|
| 926 | AOT( bInterview && iRefPoc != pcSlice->getPOC() ); |
---|
| 927 | AOT( !bInterview && iRefPoc == pcSlice->getPOC() ); |
---|
| 928 | |
---|
| 929 | Bool bPdmIView = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_IVIEW ) == PDM_USE_FOR_IVIEW ); |
---|
| 930 | Bool bPdmInter = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_INTER ) == PDM_USE_FOR_INTER ); |
---|
| 931 | Bool bPdmMerge = ( ( pcSPS->getMultiviewMvPredMode() & PDM_USE_FOR_MERGE ) == PDM_USE_FOR_MERGE ); |
---|
| 932 | ROTRS( ( bInterview && !bMerge ) && !bPdmIView, false ); |
---|
| 933 | ROTRS( (!bInterview && !bMerge ) && !bPdmInter, false ); |
---|
| 934 | ROTRS( bMerge && !bPdmMerge, false ); |
---|
| 935 | |
---|
| 936 | //===== get predicted depth for middle position of current PU ===== |
---|
| 937 | Int iPrdDepth, iCurrPosX, iCurrPosY; |
---|
| 938 | Bool bAvailable = xGetPredDepth( pcCU, uiPartIdx, iPrdDepth, &iCurrPosX, &iCurrPosY ); |
---|
| 939 | AOF( bAvailable ); |
---|
| 940 | |
---|
| 941 | //===== inter-view motion vector prediction ===== |
---|
| 942 | if( bInterview ) |
---|
| 943 | { |
---|
| 944 | Int iDisparity = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth ); |
---|
| 945 | rcMv.set ( iDisparity, 0 ); |
---|
| 946 | return true; |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | //===== inter motion vector prediction ===== |
---|
| 950 | for( UInt uiBId = 0; uiBId < m_uiCurrViewId; uiBId++ ) |
---|
| 951 | { |
---|
| 952 | //--- get base CU/PU and check prediction mode --- |
---|
| 953 | UInt uiBaseId = m_auiBaseIdList[ uiBId ]; |
---|
[100] | 954 | #if PDM_REMOVE_DEPENDENCE |
---|
| 955 | if( uiBaseId != 0) |
---|
| 956 | continue; |
---|
| 957 | #endif |
---|
[2] | 958 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 959 | TComPicYuv* pcBasePdm = pcBasePic->getPredDepthMap(); |
---|
| 960 | TComPicYuv* pcBaseRec = pcBasePic->getPicYuvRec (); |
---|
| 961 | Int iDisparity = xGetDisparityFromVirtDepth( uiBaseId, iPrdDepth ); |
---|
[21] | 962 | Int iShiftX = m_uiSubSampExpX + 2; |
---|
| 963 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
| 964 | Int iBasePosX = Clip3( 0, pcBasePdm->getWidth () - 1, iCurrPosX + ( ( iDisparity + iAddX ) >> iShiftX ) ); |
---|
[2] | 965 | Int iBasePosY = Clip3( 0, pcBasePdm->getHeight() - 1, iCurrPosY ); |
---|
| 966 | Int iBaseCUAddr; |
---|
| 967 | Int iBaseAbsPartIdx; |
---|
[21] | 968 | pcBaseRec->getCUAddrAndPartIdx( iBasePosX << m_uiSubSampExpX, iBasePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx ); |
---|
[2] | 969 | TComDataCU* pcBaseCU = pcBasePic->getCU( iBaseCUAddr ); |
---|
| 970 | if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP ) |
---|
| 971 | { |
---|
| 972 | continue; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | for( UInt uiBaseRefListId = 0; uiBaseRefListId < 2; uiBaseRefListId++ ) |
---|
| 976 | { |
---|
| 977 | RefPicList eBaseRefPicList = RefPicList( uiBaseRefListId ); |
---|
| 978 | TComMvField cBaseMvField; |
---|
| 979 | pcBaseCU->getMvField( pcBaseCU, iBaseAbsPartIdx, eBaseRefPicList, cBaseMvField ); |
---|
| 980 | Int iBaseRefIdx = cBaseMvField.getRefIdx(); |
---|
| 981 | Int iBaseRefPoc = ( iBaseRefIdx >= 0 ? pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, iBaseRefIdx )->getPOC() : -(1<<30) ); |
---|
| 982 | if( iBaseRefIdx >= 0 && iBaseRefPoc == iRefPoc ) |
---|
| 983 | { |
---|
| 984 | rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() ); |
---|
| 985 | return true; |
---|
| 986 | } |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | return false; |
---|
| 990 | } |
---|
[100] | 991 | #endif |
---|
[2] | 992 | |
---|
| 993 | |
---|
| 994 | Bool // first version |
---|
| 995 | TComDepthMapGenerator::getIViewOrgDepthMvPred( TComDataCU* pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv ) |
---|
| 996 | { |
---|
| 997 | AOF ( m_bCreated && m_bInit ); |
---|
| 998 | AOF ( iRefIdx >= 0 ); |
---|
| 999 | AOF ( pcCU ); |
---|
| 1000 | |
---|
| 1001 | TComSlice* pcSlice = pcCU->getSlice (); |
---|
| 1002 | TComPic* pcPic = pcCU->getPic (); |
---|
| 1003 | TComSPS* pcSPS = pcSlice->getSPS(); |
---|
| 1004 | AOF ( pcSPS->getViewId() == m_uiCurrViewId ); |
---|
| 1005 | ROFRS( pcPic->getOrgDepthMap(), false ); |
---|
| 1006 | |
---|
| 1007 | TComPic* pcRefPic = pcSlice->getRefPic( eRefPicList, iRefIdx ); |
---|
| 1008 | UInt uiRefViewId = pcRefPic->getSPS()->getViewId(); |
---|
| 1009 | Int iRefPoc = pcRefPic->getPOC(); |
---|
| 1010 | ROFRS( uiRefViewId < m_uiCurrViewId, false ); |
---|
| 1011 | AOF ( iRefPoc == pcSlice->getPOC() ); |
---|
| 1012 | |
---|
| 1013 | //===== get predicted depth for middle position of current PU (first version) ===== |
---|
| 1014 | UInt uiPartAddr; |
---|
| 1015 | Int iWidth; |
---|
| 1016 | Int iHeight; |
---|
| 1017 | pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 1018 | TComPicYuv* pcOrgDepthMap = pcPic->getOrgDepthMap(); |
---|
| 1019 | Pel* piOrgDepthMap = pcOrgDepthMap->getLumaAddr ( 0 ); |
---|
| 1020 | Int iCurrStride = pcOrgDepthMap->getStride (); |
---|
| 1021 | Int iCurrPosX; |
---|
| 1022 | Int iCurrPosY; |
---|
| 1023 | pcOrgDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY ); |
---|
| 1024 | iCurrPosX += ( iWidth - 1 ) >> 1; |
---|
| 1025 | iCurrPosY += ( iHeight - 1 ) >> 1; |
---|
| 1026 | Int iPrdDepth = piOrgDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ]; |
---|
| 1027 | |
---|
| 1028 | //===== get disparity vector ===== |
---|
| 1029 | Int iDisparity = xGetDisparityFromVirtDepth( uiRefViewId, iPrdDepth ); |
---|
| 1030 | rcMv.set ( iDisparity, 0 ); |
---|
| 1031 | return true; |
---|
| 1032 | } |
---|
[5] | 1033 | #endif |
---|
[2] | 1034 | |
---|
| 1035 | |
---|
| 1036 | |
---|
| 1037 | |
---|
| 1038 | |
---|
[100] | 1039 | #if !QC_MULTI_DIS_CAN |
---|
[2] | 1040 | /*=======================================================* |
---|
| 1041 | *===== =====* |
---|
| 1042 | *===== p i c t u r e o p e r a t i o n s =====* |
---|
| 1043 | *===== =====* |
---|
| 1044 | *=======================================================*/ |
---|
| 1045 | |
---|
| 1046 | Bool |
---|
| 1047 | TComDepthMapGenerator::xConvertDepthMapCurr2Ref( TComPic* pcRef, TComPic* pcCur ) |
---|
| 1048 | { |
---|
| 1049 | AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId ); |
---|
| 1050 | AOF( pcCur->getSPS()->getViewId() > pcRef->getSPS()->getViewId() ); |
---|
| 1051 | AOF( pcCur->getPredDepthMap() ); |
---|
| 1052 | AOF( pcRef->getPredDepthMap() ); |
---|
| 1053 | AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () ); |
---|
| 1054 | AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() ); |
---|
[100] | 1055 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1056 | if( pcCur->getViewId() == 1) |
---|
| 1057 | xClearDepthMap( pcRef ); |
---|
| 1058 | else if (pcCur->getViewId() == 2) |
---|
| 1059 | xClearDepthMap( pcRef, PDM_UNDEFINED_DEPTH, 1 ); |
---|
| 1060 | #else |
---|
[2] | 1061 | xClearDepthMap( pcRef ); |
---|
[100] | 1062 | #endif |
---|
[2] | 1063 | TComPicYuv* pcCurDepthMap = pcCur->getPredDepthMap (); |
---|
| 1064 | TComPicYuv* pcRefDepthMap = pcRef->getPredDepthMap (); |
---|
| 1065 | Int iWidth = pcCurDepthMap->getWidth (); |
---|
| 1066 | Int iHeight = pcCurDepthMap->getHeight (); |
---|
| 1067 | Int iCurStride = pcCurDepthMap->getStride (); |
---|
| 1068 | Int iRefStride = pcRefDepthMap->getStride (); |
---|
| 1069 | Pel* pCurSamples = pcCurDepthMap->getLumaAddr( 0 ); |
---|
| 1070 | Pel* pRefSamples = pcRefDepthMap->getLumaAddr( 0 ); |
---|
[56] | 1071 | Int iRefViewIdx = pcRef->getViewId(); |
---|
[100] | 1072 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1073 | if( pcCur->getViewId() == 2) |
---|
| 1074 | { |
---|
| 1075 | pcRefDepthMap = pcRef->getPredDepthMapTemp(); |
---|
| 1076 | pRefSamples = pcRefDepthMap->getLumaAddr( 0 ); |
---|
| 1077 | } |
---|
| 1078 | #endif |
---|
[21] | 1079 | Int iShiftX = m_uiSubSampExpX + 2; |
---|
| 1080 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
[2] | 1081 | for( Int iY = 0; iY < iHeight; iY++, pCurSamples += iCurStride, pRefSamples += iRefStride ) |
---|
| 1082 | { |
---|
| 1083 | for( Int iXCur = 0; iXCur < iWidth; iXCur++ ) |
---|
| 1084 | { |
---|
| 1085 | Int iDepth = pCurSamples[ iXCur ]; |
---|
| 1086 | Int iDisp = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth ); |
---|
[21] | 1087 | Int iXRef = iXCur + ( ( iDisp + iAddX ) >> iShiftX ); |
---|
[2] | 1088 | if( iXRef >= 0 && iXRef < iWidth && iDepth > pRefSamples[ iXRef ] ) |
---|
| 1089 | { |
---|
| 1090 | pRefSamples[ iXRef ] = iDepth; |
---|
| 1091 | } |
---|
| 1092 | } |
---|
| 1093 | } |
---|
| 1094 | Bool bUndefined = xFillDepthMapHoles( pcRef ); |
---|
| 1095 | pcRefDepthMap->setBorderExtension( false ); |
---|
| 1096 | pcRefDepthMap->extendPicBorder (); |
---|
| 1097 | return bUndefined; |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | |
---|
| 1101 | Bool |
---|
| 1102 | TComDepthMapGenerator::xConvertDepthMapRef2Curr( TComPic* pcCur, TComPic* pcRef ) |
---|
| 1103 | { |
---|
| 1104 | AOF( pcCur->getSPS()->getViewId() == m_uiCurrViewId ); |
---|
| 1105 | AOF( pcCur->getSPS()->getViewId() > pcRef->getSPS()->getViewId() ); |
---|
| 1106 | AOF( pcCur->getPredDepthMap() ); |
---|
[100] | 1107 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1108 | if(pcCur->getViewId() == 1) |
---|
| 1109 | { |
---|
| 1110 | AOF( pcRef->getPredDepthMap() ); |
---|
| 1111 | }else |
---|
| 1112 | { |
---|
| 1113 | AOF( pcRef->getPredDepthMapTemp() ); |
---|
| 1114 | } |
---|
| 1115 | #else |
---|
[2] | 1116 | AOF( pcRef->getPredDepthMap() ); |
---|
[100] | 1117 | #endif |
---|
[2] | 1118 | AOF( pcRef->getPredDepthMap()->getWidth () == pcCur->getPredDepthMap()->getWidth () ); |
---|
| 1119 | AOF( pcRef->getPredDepthMap()->getHeight() == pcCur->getPredDepthMap()->getHeight() ); |
---|
| 1120 | |
---|
| 1121 | xClearDepthMap( pcCur ); |
---|
| 1122 | TComPicYuv* pcRefDepthMap = pcRef->getPredDepthMap (); |
---|
[100] | 1123 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1124 | if(pcCur->getViewId() == 2) |
---|
| 1125 | pcRefDepthMap = pcRef->getPredDepthMapTemp (); |
---|
| 1126 | #endif |
---|
[2] | 1127 | TComPicYuv* pcCurDepthMap = pcCur->getPredDepthMap (); |
---|
| 1128 | Int iWidth = pcRefDepthMap->getWidth (); |
---|
| 1129 | Int iHeight = pcRefDepthMap->getHeight (); |
---|
| 1130 | Int iRefStride = pcRefDepthMap->getStride (); |
---|
| 1131 | Int iCurStride = pcCurDepthMap->getStride (); |
---|
| 1132 | Pel* pRefSamples = pcRefDepthMap->getLumaAddr( 0 ); |
---|
| 1133 | Pel* pCurSamples = pcCurDepthMap->getLumaAddr( 0 ); |
---|
[56] | 1134 | Int iRefViewIdx = pcRef->getViewId(); |
---|
[21] | 1135 | Int iShiftX = m_uiSubSampExpX + 2; |
---|
| 1136 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
[2] | 1137 | for( Int iY = 0; iY < iHeight; iY++, pRefSamples += iRefStride, pCurSamples += iCurStride ) |
---|
| 1138 | { |
---|
| 1139 | for( Int iXRef = 0; iXRef < iWidth; iXRef++ ) |
---|
| 1140 | { |
---|
| 1141 | Int iDepth = pRefSamples[ iXRef ]; |
---|
| 1142 | Int iDisp = xGetDisparityFromVirtDepth( iRefViewIdx, iDepth ); |
---|
[21] | 1143 | Int iXCur = iXRef - ( ( iDisp + iAddX ) >> iShiftX ); |
---|
[2] | 1144 | if( iXCur >= 0 && iXCur < iWidth && iDepth > pCurSamples[ iXCur ] ) |
---|
| 1145 | { |
---|
| 1146 | pCurSamples[ iXCur ] = iDepth; |
---|
| 1147 | } |
---|
| 1148 | } |
---|
| 1149 | } |
---|
| 1150 | Bool bUndefined = xFillDepthMapHoles( pcCur ); |
---|
| 1151 | pcCurDepthMap->setBorderExtension( false ); |
---|
| 1152 | pcCurDepthMap->extendPicBorder (); |
---|
| 1153 | return bUndefined; |
---|
| 1154 | } |
---|
| 1155 | |
---|
| 1156 | |
---|
| 1157 | Bool |
---|
| 1158 | TComDepthMapGenerator::xPredictDepthMap( TComPic* pcPic ) |
---|
| 1159 | { |
---|
| 1160 | for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ ) |
---|
| 1161 | { |
---|
| 1162 | TComDataCU* pcCU = pcPic->getCU( uiCUAddr ); |
---|
| 1163 | xPredictCUDepthMap( pcCU, 0, 0 ); |
---|
| 1164 | } |
---|
| 1165 | Bool bUndefined = xFillDepthMapHoles( pcPic ); |
---|
[100] | 1166 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1167 | if(pcPic->getStoredPDMforV2() == 1){ |
---|
| 1168 | pcPic->getPredDepthMapTemp()->setBorderExtension( false ); |
---|
| 1169 | pcPic->getPredDepthMapTemp()->extendPicBorder (); |
---|
| 1170 | }else{ |
---|
| 1171 | #endif |
---|
[2] | 1172 | pcPic->getPredDepthMap()->setBorderExtension( false ); |
---|
| 1173 | pcPic->getPredDepthMap()->extendPicBorder (); |
---|
[100] | 1174 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1175 | } |
---|
| 1176 | #endif |
---|
[2] | 1177 | return bUndefined; |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | |
---|
| 1181 | Bool |
---|
| 1182 | TComDepthMapGenerator::xFillDepthMapHoles( TComPic* pcPic ) |
---|
| 1183 | { |
---|
| 1184 | Bool bUndefined = false; |
---|
| 1185 | TComPicYuv* pcDepthMap = pcPic->getPredDepthMap (); |
---|
[100] | 1186 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1187 | if(pcPic->getViewId()==0 && pcPic->getStoredPDMforV2()==1) |
---|
| 1188 | pcDepthMap = pcPic->getPredDepthMapTemp (); |
---|
| 1189 | #endif |
---|
[2] | 1190 | Int iWidth = pcDepthMap->getWidth (); |
---|
| 1191 | Int iHeight = pcDepthMap->getHeight (); |
---|
| 1192 | Int iStride = pcDepthMap->getStride (); |
---|
| 1193 | Pel* pDMSamples = pcDepthMap->getLumaAddr ( 0 ); |
---|
| 1194 | // horizontal |
---|
| 1195 | for( Int iY = 0; iY < iHeight && !bUndefined; iY++, pDMSamples += iStride ) |
---|
| 1196 | { |
---|
| 1197 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 1198 | { |
---|
| 1199 | if( pDMSamples[ iX ] == PDM_UNDEFINED_DEPTH ) |
---|
| 1200 | { |
---|
| 1201 | Int iE; |
---|
| 1202 | for( iE = iX + 1; iE < iWidth; iE++ ) |
---|
| 1203 | { |
---|
| 1204 | if( pDMSamples[ iE ] != PDM_UNDEFINED_DEPTH ) |
---|
| 1205 | { |
---|
| 1206 | break; |
---|
| 1207 | } |
---|
| 1208 | } |
---|
| 1209 | if( iX > 0 || iE < iWidth ) |
---|
| 1210 | { |
---|
| 1211 | Int iDepth; |
---|
| 1212 | if ( iX > 0 && iE < iWidth ) iDepth = ( pDMSamples[ iX-1 ] < pDMSamples[ iE ] ? pDMSamples[ iX-1 ] : pDMSamples[ iE ] ); |
---|
| 1213 | else if( iX > 0 ) iDepth = pDMSamples[ iX-1 ]; |
---|
| 1214 | else /*( iE < iWidth )*/ iDepth = pDMSamples[ iE ]; |
---|
| 1215 | for( Int iZ = iX; iZ < iE; iZ++ ) |
---|
| 1216 | { |
---|
| 1217 | pDMSamples[ iZ ] = iDepth; |
---|
| 1218 | } |
---|
| 1219 | } |
---|
| 1220 | else |
---|
| 1221 | { |
---|
| 1222 | bUndefined = true; |
---|
[100] | 1223 | break; |
---|
[2] | 1224 | } |
---|
| 1225 | iX = iE - 1; |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | } |
---|
| 1229 | |
---|
| 1230 | if( bUndefined && m_uiCurrViewId ) |
---|
| 1231 | { |
---|
| 1232 | pDMSamples = pcDepthMap->getLumaAddr( 0 ); |
---|
| 1233 | Int iMiddleOrgDpth = ( 1 << m_uiOrgDepthBitDepth ) >> 1; |
---|
| 1234 | Int iMiddleDepth = xGetVirtDepthFromOrigDepth( m_uiCurrViewId, iMiddleOrgDpth ); |
---|
| 1235 | for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride ) |
---|
| 1236 | { |
---|
| 1237 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 1238 | { |
---|
| 1239 | pDMSamples[ iX ] = iMiddleDepth; |
---|
| 1240 | } |
---|
| 1241 | } |
---|
| 1242 | } |
---|
| 1243 | return bUndefined; |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | |
---|
| 1247 | Void |
---|
[100] | 1248 | TComDepthMapGenerator::xClearDepthMap( TComPic* pcPic, Int iVal |
---|
| 1249 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1250 | , |
---|
| 1251 | Int forFirstNonBaseView |
---|
| 1252 | #endif |
---|
| 1253 | ) |
---|
[2] | 1254 | { |
---|
| 1255 | TComPicYuv* pcDepthMap = pcPic->getPredDepthMap (); |
---|
| 1256 | Int iWidth = pcDepthMap->getWidth (); |
---|
| 1257 | Int iHeight = pcDepthMap->getHeight (); |
---|
| 1258 | Int iStride = pcDepthMap->getStride (); |
---|
| 1259 | Pel* pDMSamples = pcDepthMap->getLumaAddr ( 0 ); |
---|
[100] | 1260 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1261 | if( forFirstNonBaseView == 1) |
---|
| 1262 | { |
---|
| 1263 | pcDepthMap = pcPic->getPredDepthMapTemp (); |
---|
| 1264 | pDMSamples = pcDepthMap->getLumaAddr ( 0 ); |
---|
| 1265 | } |
---|
| 1266 | #endif |
---|
[2] | 1267 | for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride ) |
---|
| 1268 | { |
---|
| 1269 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 1270 | { |
---|
| 1271 | pDMSamples[ iX ] = iVal; |
---|
| 1272 | } |
---|
| 1273 | } |
---|
| 1274 | pcDepthMap->setBorderExtension( false ); |
---|
| 1275 | pcDepthMap->extendPicBorder (); |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | Void |
---|
| 1279 | TComDepthMapGenerator::xSetChroma( TComPicYuv* pcPic, Int iVal ) |
---|
| 1280 | { |
---|
| 1281 | Int iWidth = pcPic->getWidth () >> 1; |
---|
| 1282 | Int iHeight = pcPic->getHeight () >> 1; |
---|
| 1283 | Int iStride = pcPic->getCStride (); |
---|
| 1284 | Pel* pCbSamples = pcPic->getCbAddr ( 0 ); |
---|
| 1285 | Pel* pCrSamples = pcPic->getCrAddr ( 0 ); |
---|
| 1286 | for( Int iY = 0; iY < iHeight; iY++, pCbSamples += iStride, pCrSamples += iStride ) |
---|
| 1287 | { |
---|
| 1288 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
| 1289 | { |
---|
| 1290 | pCbSamples[ iX ] = pCrSamples[ iX ] = iVal; |
---|
| 1291 | } |
---|
| 1292 | } |
---|
| 1293 | } |
---|
| 1294 | |
---|
| 1295 | |
---|
| 1296 | |
---|
| 1297 | |
---|
| 1298 | |
---|
| 1299 | |
---|
| 1300 | |
---|
| 1301 | /*===============================================* |
---|
| 1302 | *===== =====* |
---|
| 1303 | *===== C U p r e d i c t i o n s =====* |
---|
| 1304 | *===== =====* |
---|
| 1305 | *===============================================*/ |
---|
| 1306 | |
---|
| 1307 | Void |
---|
| 1308 | TComDepthMapGenerator::xPredictCUDepthMap( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx ) |
---|
| 1309 | { |
---|
| 1310 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
| 1311 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
| 1312 | UInt uiRPelX = uiLPelX + ( g_uiMaxCUWidth >> uiDepth ) - 1; |
---|
| 1313 | UInt uiBPelY = uiTPelY + ( g_uiMaxCUHeight >> uiDepth ) - 1; |
---|
[56] | 1314 | Bool bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
[2] | 1315 | Bool bSplit = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary ); |
---|
| 1316 | if( bSplit ) |
---|
| 1317 | { |
---|
| 1318 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2; |
---|
| 1319 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts ) |
---|
| 1320 | { |
---|
| 1321 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
| 1322 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
[56] | 1323 | Bool bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
[2] | 1324 | if( bInside ) |
---|
| 1325 | { |
---|
| 1326 | xPredictCUDepthMap( pcCU, uiDepth + 1, uiAbsPartIdx ); |
---|
| 1327 | } |
---|
| 1328 | } |
---|
| 1329 | return; |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | //--- set sub-CU and sub-depth-map --- |
---|
| 1333 | TComDataCU* pcSubCU = m_ppcCU [ uiDepth ]; |
---|
| 1334 | TComYuv* pcSubDM = m_ppcYuv[ uiDepth ]; |
---|
| 1335 | TComPicYuv* pcPicDM = pcCU->getPic()->getPredDepthMap(); |
---|
[100] | 1336 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1337 | if( pcCU->getPic()->getStoredPDMforV2() == 1) |
---|
| 1338 | pcPicDM = pcCU->getPic()->getPredDepthMapTemp(); |
---|
| 1339 | #endif |
---|
[2] | 1340 | UInt uiCUAddr = pcCU->getAddr(); |
---|
| 1341 | pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth ); |
---|
| 1342 | |
---|
| 1343 | //--- update depth map --- |
---|
| 1344 | switch( pcSubCU->getPredictionMode( 0 ) ) |
---|
| 1345 | { |
---|
| 1346 | case MODE_INTRA: |
---|
| 1347 | xIntraPredictCUDepthMap( pcSubCU, pcSubDM ); |
---|
| 1348 | break; |
---|
| 1349 | case MODE_SKIP: |
---|
| 1350 | case MODE_INTER: |
---|
| 1351 | xInterPredictCUDepthMap( pcSubCU, pcSubDM ); |
---|
| 1352 | break; |
---|
| 1353 | default: |
---|
| 1354 | AOT( true ); |
---|
| 1355 | break; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | //--- copy sub-depth-map --- |
---|
| 1359 | pcSubDM->copyToPicYuv( pcPicDM, uiCUAddr, uiAbsPartIdx ); |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | |
---|
| 1363 | Void |
---|
| 1364 | TComDepthMapGenerator::xIntraPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap ) |
---|
| 1365 | { |
---|
| 1366 | UInt uiInitTrDepth = ( pcCU->getPartitionSize( 0 ) == SIZE_2Nx2N ? 0 : 1 ); |
---|
| 1367 | UInt uiNumPart = pcCU->getNumPartInter (); |
---|
| 1368 | UInt uiNumQParts = pcCU->getTotalNumPart () >> 2; |
---|
| 1369 | for( UInt uiPU = 0; uiPU < uiNumPart; uiPU++ ) |
---|
| 1370 | { |
---|
| 1371 | xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiPU * uiNumQParts, uiInitTrDepth ); |
---|
| 1372 | } |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | |
---|
| 1376 | Void |
---|
| 1377 | TComDepthMapGenerator::xInterPredictCUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap ) |
---|
| 1378 | { |
---|
| 1379 | for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ ) |
---|
| 1380 | { |
---|
| 1381 | xInterPredictPUDepthMap( pcCU, pcCUDepthMap, uiPartIdx ); |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | |
---|
| 1385 | |
---|
| 1386 | |
---|
| 1387 | |
---|
| 1388 | |
---|
| 1389 | |
---|
| 1390 | |
---|
| 1391 | /*=====================================================================* |
---|
| 1392 | *===== =====* |
---|
| 1393 | *===== P U - a n d B l o c k p r e d i c t i o n s =====* |
---|
| 1394 | *===== =====* |
---|
| 1395 | *=====================================================================*/ |
---|
| 1396 | |
---|
| 1397 | Void |
---|
| 1398 | TComDepthMapGenerator::xIntraPredictBlkDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiAbsPartIdx, UInt uiTrDepth ) |
---|
| 1399 | { |
---|
| 1400 | UInt uiFullDepth = pcCU->getDepth( 0 ) + uiTrDepth; |
---|
| 1401 | UInt uiTrMode = pcCU->getTransformIdx( uiAbsPartIdx ); |
---|
| 1402 | if( uiTrMode == uiTrDepth ) |
---|
| 1403 | { |
---|
[21] | 1404 | UInt uiWidth = pcCU->getWidth ( 0 ) >> ( uiTrDepth + m_uiSubSampExpX ); |
---|
| 1405 | UInt uiHeight = pcCU->getHeight( 0 ) >> ( uiTrDepth + m_uiSubSampExpY ); |
---|
[2] | 1406 | UInt uiStride = pcCUDepthMap->getStride (); |
---|
[21] | 1407 | UInt uiBlkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX; |
---|
| 1408 | UInt uiBlkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY; |
---|
| 1409 | Pel* pDepthMap = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX; |
---|
[2] | 1410 | UInt uiLumaPredMode = pcCU->getLumaIntraDir ( uiAbsPartIdx ); |
---|
| 1411 | Bool bAboveAvail = false; |
---|
| 1412 | Bool bLeftAvail = false; |
---|
| 1413 | pcCU->getPattern()->initPattern ( pcCU, uiTrDepth, uiAbsPartIdx, true ); |
---|
| 1414 | pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, |
---|
| 1415 | m_pcPrediction->getPredicBuf (), |
---|
| 1416 | m_pcPrediction->getPredicBufWidth (), |
---|
| 1417 | m_pcPrediction->getPredicBufHeight (), |
---|
[56] | 1418 | bAboveAvail, bLeftAvail, false, true, m_uiSubSampExpX, m_uiSubSampExpY ); |
---|
[2] | 1419 | m_pcPrediction->predIntraDepthAng ( pcCU->getPattern(), uiLumaPredMode, pDepthMap, uiStride, uiWidth, uiHeight ); // could be replaced with directional intra prediction |
---|
| 1420 | // using "predIntraLumaAng", but note: |
---|
| 1421 | // - need to take care of neighbours with undefined depth |
---|
| 1422 | // - special case for wedgelet mode (if available in normal views) |
---|
| 1423 | // copy to picture array (for next intra prediction block) |
---|
| 1424 | UInt uiZOrderIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
| 1425 | Pel* pPicDepthMap = pcCU->getPic()->getPredDepthMap()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx ); |
---|
[100] | 1426 | #if PDM_REMOVE_DEPENDENCE |
---|
| 1427 | if(pcCU->getPic()->getStoredPDMforV2()==1) |
---|
| 1428 | pPicDepthMap = pcCU->getPic()->getPredDepthMapTemp()->getLumaAddr( pcCU->getAddr(), uiZOrderIdx ); |
---|
| 1429 | #endif |
---|
[2] | 1430 | Int iPicStride = pcCU->getPic()->getPredDepthMap()->getStride (); |
---|
| 1431 | for( UInt uiY = 0; uiY < uiHeight; uiY++, pDepthMap += uiStride, pPicDepthMap += iPicStride ) |
---|
| 1432 | { |
---|
| 1433 | for( UInt uiX = 0; uiX < uiWidth; uiX++ ) |
---|
| 1434 | { |
---|
| 1435 | pPicDepthMap[ uiX ] = pDepthMap[ uiX ]; |
---|
| 1436 | } |
---|
| 1437 | } |
---|
| 1438 | } |
---|
| 1439 | else |
---|
| 1440 | { |
---|
| 1441 | UInt uiNumQPart = pcCU->getPic()->getNumPartInCU() >> ( ( uiFullDepth + 1 ) << 1 ); |
---|
| 1442 | for( UInt uiPart = 0; uiPart < 4; uiPart++ ) |
---|
| 1443 | { |
---|
| 1444 | xIntraPredictBlkDepthMap( pcCU, pcCUDepthMap, uiAbsPartIdx + uiPart * uiNumQPart, uiTrDepth + 1 ); |
---|
| 1445 | } |
---|
| 1446 | } |
---|
| 1447 | } |
---|
| 1448 | |
---|
| 1449 | |
---|
| 1450 | Void |
---|
| 1451 | TComDepthMapGenerator::xInterPredictPUDepthMap( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ) |
---|
| 1452 | { |
---|
| 1453 | if ( pcCU->getSlice()->getSPS()->getViewId() ) |
---|
| 1454 | { |
---|
| 1455 | AOF( m_uiCurrViewId == pcCU->getSlice()->getSPS()->getViewId() ); |
---|
| 1456 | // check for interview prediction |
---|
| 1457 | Int iWidth; |
---|
| 1458 | Int iHeight; |
---|
| 1459 | UInt uiAbsPartIdx; |
---|
| 1460 | pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
| 1461 | TComCUMvField* aiCurrMvField[2] = { pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getCUMvField( REF_PIC_LIST_1 ) }; |
---|
| 1462 | Int aiCurrRefIdx [2] = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) }; |
---|
| 1463 | Bool abCurrIntView[2] = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != m_uiCurrViewId, |
---|
| 1464 | aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != m_uiCurrViewId }; |
---|
| 1465 | Bool bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] ); |
---|
| 1466 | if( bUsesInterViewPrd ) |
---|
| 1467 | { |
---|
| 1468 | xIViewPUDepthMapUpdate ( pcCU, pcCUDepthMap, uiPartIdx ); |
---|
| 1469 | } |
---|
| 1470 | else |
---|
| 1471 | { |
---|
| 1472 | #if PDM_NO_INTER_UPDATE |
---|
| 1473 | xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx ); |
---|
| 1474 | #else |
---|
| 1475 | xInterPUDepthMapUpdate ( pcCU, pcCUDepthMap, uiPartIdx ); |
---|
| 1476 | #endif |
---|
| 1477 | } |
---|
| 1478 | } |
---|
| 1479 | else |
---|
| 1480 | { |
---|
| 1481 | xInterPUDepthMapPrediction( pcCU, pcCUDepthMap, uiPartIdx ); |
---|
| 1482 | } |
---|
| 1483 | } |
---|
| 1484 | |
---|
| 1485 | |
---|
| 1486 | Void |
---|
| 1487 | TComDepthMapGenerator::xIViewPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ) |
---|
| 1488 | { |
---|
| 1489 | // get width, height, and part address |
---|
| 1490 | Int iWidth; |
---|
| 1491 | Int iHeight; |
---|
| 1492 | UInt uiAbsPartIdx; |
---|
| 1493 | pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
[21] | 1494 | iWidth >>= m_uiSubSampExpX; |
---|
| 1495 | iHeight >>= m_uiSubSampExpY; |
---|
[2] | 1496 | |
---|
| 1497 | // get depth values |
---|
| 1498 | Int iDepthValue = PDM_UNDEFINED_DEPTH; |
---|
| 1499 | Int aiPrdDepth[2] = { PDM_UNDEFINED_DEPTH, PDM_UNDEFINED_DEPTH }; |
---|
| 1500 | for( Int iRefListId = 0; iRefListId < 2; iRefListId++ ) |
---|
| 1501 | { |
---|
| 1502 | RefPicList eRefPicList = RefPicList( iRefListId ); |
---|
| 1503 | TComCUMvField* pcCUMvField = pcCU->getCUMvField( eRefPicList ); |
---|
| 1504 | Int iRefIdx = pcCUMvField->getRefIdx( uiAbsPartIdx ); |
---|
[56] | 1505 | UInt uiBaseId = ( iRefIdx >= 0 ? pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getSPS()->getViewId() : MAX_VIEW_NUM ); |
---|
[2] | 1506 | Bool bInterview = ( iRefIdx >= 0 && uiBaseId < m_uiCurrViewId ); |
---|
| 1507 | if( bInterview ) |
---|
| 1508 | { |
---|
| 1509 | Int iMvX = pcCUMvField->getMv( uiAbsPartIdx ).getHor(); |
---|
| 1510 | aiPrdDepth[ iRefListId ] = xGetVirtDepthFromDisparity( uiBaseId, iMvX ); |
---|
| 1511 | } |
---|
| 1512 | } |
---|
| 1513 | if( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH && aiPrdDepth[ 1 ] != PDM_UNDEFINED_DEPTH ) |
---|
| 1514 | { |
---|
[21] | 1515 | iDepthValue = ( aiPrdDepth[ 0 ] + aiPrdDepth[ 1 ] + 1 ) >> 1; |
---|
[2] | 1516 | } |
---|
| 1517 | else |
---|
| 1518 | { |
---|
| 1519 | iDepthValue = ( aiPrdDepth[ 0 ] != PDM_UNDEFINED_DEPTH ? aiPrdDepth[ 0 ] : aiPrdDepth[ 1 ] ); |
---|
| 1520 | AOT( iDepthValue == PDM_UNDEFINED_DEPTH ); |
---|
| 1521 | } |
---|
| 1522 | iDepthValue = Max( 0, Min( PDM_MAX_ABS_VIRT_DEPTH, iDepthValue ) ); |
---|
| 1523 | |
---|
| 1524 | // set depth map for PU |
---|
[21] | 1525 | UInt uiBlkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX; |
---|
| 1526 | UInt uiBlkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY; |
---|
| 1527 | Pel* pDMSamples = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX; |
---|
[2] | 1528 | Int iStride = pcCUDepthMap->getStride (); |
---|
| 1529 | for( Int iY = 0; iY < iHeight; iY++, pDMSamples += iStride ) |
---|
| 1530 | { |
---|
| 1531 | for( Int iX = 0; iX < iWidth; iX++) |
---|
| 1532 | { |
---|
| 1533 | pDMSamples[ iX ] = (Pel)iDepthValue; |
---|
| 1534 | } |
---|
| 1535 | } |
---|
| 1536 | } |
---|
| 1537 | |
---|
| 1538 | |
---|
| 1539 | Void |
---|
| 1540 | TComDepthMapGenerator::xInterPUDepthMapUpdate( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ) |
---|
| 1541 | { |
---|
| 1542 | const Int iMaxAbsDeltaMvY = 8 << 2; |
---|
| 1543 | |
---|
| 1544 | //===== determine block parameters for current access unit and current view ===== |
---|
| 1545 | Int iWidth; |
---|
| 1546 | Int iHeight; |
---|
| 1547 | UInt uiAbsPartIdx; |
---|
| 1548 | pcCU->getPartIndexAndSize ( uiPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
| 1549 | UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId(); |
---|
| 1550 | Int iNum4x4BlksY = iHeight >> 2; |
---|
| 1551 | Int iNum4x4BlksX = iWidth >> 2; |
---|
[21] | 1552 | iWidth >>= m_uiSubSampExpX; |
---|
| 1553 | iHeight >>= m_uiSubSampExpY; |
---|
| 1554 | |
---|
[2] | 1555 | TComPicYuv* pcCurrDepthMap = pcCU->getPic()->getPredDepthMap(); |
---|
| 1556 | Pel* piCurrDepthMap = pcCurrDepthMap->getLumaAddr(); |
---|
| 1557 | Int iCurrStride = pcCurrDepthMap->getStride(); |
---|
| 1558 | TComCUMvField* aiCurrMvField[2] = { pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getCUMvField( REF_PIC_LIST_1 ) }; |
---|
| 1559 | Int aiCurrRefIdx [2] = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) }; |
---|
| 1560 | Int iMinCurrListId = ( aiCurrRefIdx [0] < 0 ? 1 : 0 ); |
---|
| 1561 | Int iMaxCurrListId = ( aiCurrRefIdx [1] < 0 ? 0 : 1 ); |
---|
| 1562 | Int iCurrPUPosX; |
---|
| 1563 | Int iCurrPUPosY; |
---|
| 1564 | pcCurrDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx, iCurrPUPosX, iCurrPUPosY ); |
---|
| 1565 | AOT( uiCurrViewId != m_uiCurrViewId ); |
---|
| 1566 | AOT( iMinCurrListId > iMaxCurrListId ); |
---|
| 1567 | AOT( aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId ); |
---|
| 1568 | AOT( aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId ); |
---|
| 1569 | |
---|
| 1570 | //===== determine parameters for current access unit and base view ===== |
---|
| 1571 | AOF( m_auiBaseIdList.size() ); |
---|
| 1572 | UInt uiBaseId = m_auiBaseIdList[ 0 ]; |
---|
| 1573 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseId ); |
---|
| 1574 | AOF( pcBasePic ); |
---|
| 1575 | TComPicYuv* pcBaseDepthMap = pcBasePic->getPredDepthMap(); |
---|
| 1576 | TComPicYuv* pcBaseRecPic = pcBasePic->getPicYuvRec (); |
---|
| 1577 | Pel* piBaseDepthMap = pcBaseDepthMap->getLumaAddr(); |
---|
| 1578 | Int iBaseStride = pcBaseDepthMap->getStride(); |
---|
[21] | 1579 | Int iShiftX = m_uiSubSampExpX + 2; |
---|
| 1580 | Int iShiftY = m_uiSubSampExpY + 2; |
---|
| 1581 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
| 1582 | Int iAddY = ( 1 << iShiftY ) >> 1; |
---|
[2] | 1583 | |
---|
| 1584 | //===== initialize 4x4 block arrays ===== |
---|
| 1585 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1586 | { |
---|
| 1587 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1588 | { |
---|
| 1589 | m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = false; |
---|
| 1590 | m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = PDM_UNDEFINED_DEPTH; |
---|
| 1591 | } |
---|
| 1592 | } |
---|
| 1593 | Int iNum4x4Set = 0; |
---|
| 1594 | |
---|
| 1595 | //===== determine depth based on 4x4 blocks ===== |
---|
| 1596 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1597 | { |
---|
| 1598 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1599 | { |
---|
| 1600 | // position parameters |
---|
[21] | 1601 | Int iCurrBlkPosX = iCurrPUPosX + ( ( i4x4BlkX << 2 ) >> m_uiSubSampExpX ); |
---|
| 1602 | Int iCurrBlkPosY = iCurrPUPosY + ( ( i4x4BlkY << 2 ) >> m_uiSubSampExpY ); |
---|
| 1603 | Int iCurrSamplePosX = iCurrBlkPosX + ( 1 >> m_uiSubSampExpX ); |
---|
| 1604 | Int iCurrSamplePosY = iCurrBlkPosY + ( 1 >> m_uiSubSampExpY ); |
---|
[2] | 1605 | Int iCurrPredDepth = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ]; |
---|
| 1606 | Int iCurrPredDisp = xGetDisparityFromVirtDepth( uiBaseId, iCurrPredDepth ); |
---|
[21] | 1607 | Int iBaseSamplePosX = iCurrSamplePosX + ( ( iCurrPredDisp + iAddX ) >> iShiftX ); |
---|
[2] | 1608 | Int iBaseSamplePosY = iCurrSamplePosY; |
---|
| 1609 | iBaseSamplePosX = Clip3( 0, pcBaseDepthMap->getWidth () - 1, iBaseSamplePosX ); |
---|
| 1610 | iBaseSamplePosY = Clip3( 0, pcBaseDepthMap->getHeight() - 1, iBaseSamplePosY ); |
---|
| 1611 | |
---|
| 1612 | // check for occlusion |
---|
| 1613 | if( piBaseDepthMap[ iBaseSamplePosY * iBaseStride + iBaseSamplePosX ] != iCurrPredDepth ) |
---|
| 1614 | { |
---|
| 1615 | continue; |
---|
| 1616 | } |
---|
| 1617 | |
---|
| 1618 | // determine base motion data and check prediction mode |
---|
| 1619 | Int iBaseCUAddr; |
---|
| 1620 | Int iBaseAbsPartIdx; |
---|
[21] | 1621 | pcBaseRecPic->getCUAddrAndPartIdx( iBaseSamplePosX << m_uiSubSampExpX, iBaseSamplePosY << m_uiSubSampExpY, iBaseCUAddr, iBaseAbsPartIdx ); |
---|
[2] | 1622 | TComDataCU* pcBaseCU = pcBasePic->getCU( iBaseCUAddr ); |
---|
| 1623 | if( pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_INTER && pcBaseCU->getPredictionMode( iBaseAbsPartIdx ) != MODE_SKIP ) |
---|
| 1624 | { |
---|
| 1625 | continue; |
---|
| 1626 | } |
---|
| 1627 | |
---|
| 1628 | // check whether base was inter-view predicted |
---|
| 1629 | TComCUMvField* aiBaseMvField[2] = { pcBaseCU->getCUMvField( REF_PIC_LIST_0 ), pcBaseCU->getCUMvField( REF_PIC_LIST_1 ) }; |
---|
| 1630 | Int aiBaseRefIdx [2] = { aiBaseMvField[0]->getRefIdx( iBaseAbsPartIdx ), aiBaseMvField[1]->getRefIdx( iBaseAbsPartIdx ) }; |
---|
| 1631 | Bool abBaseIntView[2] = { aiBaseRefIdx[0] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiBaseRefIdx[0] )->getSPS()->getViewId() != uiBaseId, |
---|
| 1632 | aiBaseRefIdx[1] >= 0 && pcBaseCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiBaseRefIdx[1] )->getSPS()->getViewId() != uiBaseId }; |
---|
| 1633 | if( abBaseIntView[0] || abBaseIntView[1] ) |
---|
| 1634 | { // current depth is reliable |
---|
| 1635 | m_aai4x4Depth[i4x4BlkY][i4x4BlkX] = iCurrPredDepth; |
---|
| 1636 | m_aabDepthSet[i4x4BlkY][i4x4BlkX] = true; |
---|
| 1637 | iNum4x4Set++; |
---|
| 1638 | continue; |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | // determine depth candidates using an approximate 4-point relationship (if appropriate) |
---|
| 1642 | std::vector<Int> aiDepthCand; |
---|
| 1643 | Int iMinBaseListId = ( aiBaseRefIdx [0] < 0 ? 1 : 0 ); |
---|
| 1644 | Int iMaxBaseListId = ( aiBaseRefIdx [1] < 0 ? 0 : 1 ); |
---|
| 1645 | AOT( iMinBaseListId > iMaxBaseListId ); |
---|
| 1646 | for( Int iCurrRefListId = iMinCurrListId; iCurrRefListId <= iMaxCurrListId; iCurrRefListId++ ) |
---|
| 1647 | { |
---|
| 1648 | RefPicList eCurrRefPicList = RefPicList( iCurrRefListId ); |
---|
| 1649 | Int iCurrRefPoc = pcCU->getSlice()->getRefPOC( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] ); |
---|
| 1650 | TComPic* pcCurrRefPic = pcCU->getSlice()->getRefPic( eCurrRefPicList, aiCurrRefIdx[ iCurrRefListId ] ); |
---|
| 1651 | TComPicYuv* pcCurrRefDMap = pcCurrRefPic->getPredDepthMap(); |
---|
| 1652 | Pel* piCurrRefDMap = pcCurrRefDMap->getLumaAddr(); |
---|
| 1653 | Int iCurrRefStride = pcCurrRefDMap->getStride(); |
---|
[56] | 1654 | TComMv rcCurrMv = aiCurrMvField[ iCurrRefListId ]->getMv( uiAbsPartIdx ); |
---|
[21] | 1655 | Int iCurrRefSamplePosX = iCurrSamplePosX + ( ( rcCurrMv.getHor() + iAddX ) >> iShiftX ); |
---|
| 1656 | Int iCurrRefSamplePosY = iCurrSamplePosY + ( ( rcCurrMv.getVer() + iAddY ) >> iShiftY ); |
---|
[2] | 1657 | Int iCurrRefSamplePosXC = Clip3( 0, pcCurrRefDMap->getWidth () - 1, iCurrRefSamplePosX ); |
---|
| 1658 | Int iCurrRefSamplePosYC = Clip3( 0, pcCurrRefDMap->getHeight() - 1, iCurrRefSamplePosY ); |
---|
| 1659 | Int iCurrRefDepth = piCurrRefDMap[ iCurrRefSamplePosYC * iCurrRefStride + iCurrRefSamplePosXC ]; |
---|
| 1660 | |
---|
| 1661 | for( Int iBaseRefListId = iMinBaseListId; iBaseRefListId <= iMaxBaseListId; iBaseRefListId++ ) |
---|
| 1662 | { |
---|
| 1663 | RefPicList eBaseRefPicList = RefPicList( iBaseRefListId ); |
---|
| 1664 | Int iBaseRefPoc = pcBaseCU->getSlice()->getRefPOC( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] ); |
---|
| 1665 | |
---|
| 1666 | if( iCurrRefPoc == iBaseRefPoc ) |
---|
| 1667 | { |
---|
| 1668 | // location and depth for path currView/currAU -> currView/refAU -> baseView/refAU |
---|
| 1669 | Int iCurrRefDisp = xGetDisparityFromVirtDepth( uiBaseId, iCurrRefDepth ); |
---|
[21] | 1670 | Int iBaseRefSamplePosX = iCurrRefSamplePosX + ( ( iCurrRefDisp + iAddX ) >> iShiftX ); |
---|
[2] | 1671 | Int iBaseRefSamplePosY = iCurrRefSamplePosY; |
---|
| 1672 | TComPic* pcBaseRefPic = pcBaseCU->getSlice()->getRefPic( eBaseRefPicList, aiBaseRefIdx[ iBaseRefListId ] ); |
---|
| 1673 | TComPicYuv* pcBaseRefDMap = pcBaseRefPic->getPredDepthMap(); |
---|
| 1674 | Pel* piBaseRefDMap = pcBaseRefDMap->getLumaAddr(); |
---|
| 1675 | Int iBaseRefStride = pcBaseRefDMap->getStride(); |
---|
| 1676 | iBaseRefSamplePosX = Clip3( 0, pcBaseRefDMap->getWidth () - 1, iBaseRefSamplePosX ); |
---|
| 1677 | iBaseRefSamplePosY = Clip3( 0, pcBaseRefDMap->getHeight() - 1, iBaseRefSamplePosY ); |
---|
| 1678 | Int iBaseRefDepth = piBaseRefDMap[ iBaseRefSamplePosY * iBaseRefStride + iBaseRefSamplePosX ]; |
---|
| 1679 | |
---|
| 1680 | // location and depth for path currView/currAU ->baseView/currAU -> baseView/refAU |
---|
[56] | 1681 | TComMv rcBaseMv = aiBaseMvField[ iBaseRefListId ]->getMv( iBaseAbsPartIdx ); |
---|
[2] | 1682 | Int iAbsDeltaMvY = ( rcBaseMv.getAbsVer() > rcCurrMv.getVer() ? rcBaseMv.getAbsVer() - rcCurrMv.getVer() : rcCurrMv.getVer() - rcBaseMv.getAbsVer() ); |
---|
| 1683 | |
---|
| 1684 | // check reliability (occlusion in reference access unit / vertical motion vector difference) |
---|
| 1685 | if( iBaseRefDepth != iCurrRefDepth || iAbsDeltaMvY > iMaxAbsDeltaMvY ) |
---|
| 1686 | { |
---|
| 1687 | continue; |
---|
| 1688 | } |
---|
| 1689 | |
---|
| 1690 | // determine new depth |
---|
| 1691 | Int iCurrCandDisp = iCurrRefDisp + rcCurrMv.getHor() - rcBaseMv.getHor(); |
---|
| 1692 | Int iCurrCandDepth = xGetVirtDepthFromDisparity( uiBaseId, iCurrCandDisp ); |
---|
| 1693 | aiDepthCand.push_back( iCurrCandDepth ); |
---|
| 1694 | } // iCurrRefPoc == iBaseRefPoc |
---|
| 1695 | } // iBaseRefListId |
---|
| 1696 | } // iCurrRefListId |
---|
| 1697 | |
---|
| 1698 | // set depth for 4x4 block |
---|
| 1699 | if( aiDepthCand.size() ) |
---|
| 1700 | { // get depth with minimum change (probably most reliable) |
---|
| 1701 | Int iMinAbsDepthChange = (1<<30); |
---|
| 1702 | Int iDepthForMinChange = (1<<30); |
---|
| 1703 | for( UInt uiCandId = 0; uiCandId < (UInt)aiDepthCand.size(); uiCandId++ ) |
---|
| 1704 | { |
---|
| 1705 | Int iAbsDeltaDepth = ( aiDepthCand[uiCandId] > iCurrPredDepth ? aiDepthCand[uiCandId] > iCurrPredDepth : iCurrPredDepth - aiDepthCand[uiCandId] ); |
---|
| 1706 | if( iAbsDeltaDepth < iMinAbsDepthChange ) |
---|
| 1707 | { |
---|
| 1708 | iMinAbsDepthChange = iAbsDeltaDepth; |
---|
| 1709 | iDepthForMinChange = aiDepthCand[uiCandId]; |
---|
| 1710 | } |
---|
| 1711 | } |
---|
| 1712 | m_aai4x4Depth[i4x4BlkY][i4x4BlkX] = Min( Max( 0, iDepthForMinChange ), PDM_MAX_ABS_VIRT_DEPTH ); |
---|
| 1713 | m_aabDepthSet[i4x4BlkY][i4x4BlkX] = true; |
---|
| 1714 | iNum4x4Set++; |
---|
| 1715 | } |
---|
| 1716 | } // i4x4BlkX |
---|
| 1717 | } // i4x4BlkY |
---|
| 1718 | |
---|
| 1719 | //===== fall back (take original depth for 4x4 blocks) ==== |
---|
| 1720 | if( iNum4x4Set < Max( 1, ( iNum4x4BlksY * iNum4x4BlksX ) >> 2 ) ) |
---|
| 1721 | { |
---|
| 1722 | iNum4x4Set = 0; |
---|
| 1723 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1724 | { |
---|
| 1725 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1726 | { |
---|
[21] | 1727 | Int iCurrSamplePosX = iCurrPUPosX + ( ( ( i4x4BlkX << 2 ) + 1 ) >> m_uiSubSampExpX ); |
---|
| 1728 | Int iCurrSamplePosY = iCurrPUPosY + ( ( ( i4x4BlkY << 2 ) + 1 ) >> m_uiSubSampExpY ); |
---|
[2] | 1729 | m_aai4x4Depth[i4x4BlkY][i4x4BlkX] = piCurrDepthMap[ iCurrSamplePosY * iCurrStride + iCurrSamplePosX ]; |
---|
| 1730 | m_aabDepthSet[i4x4BlkY][i4x4BlkX] = true; |
---|
| 1731 | iNum4x4Set++; |
---|
| 1732 | } |
---|
| 1733 | } |
---|
| 1734 | } |
---|
| 1735 | |
---|
| 1736 | #if PDM_ONE_DEPTH_PER_PU |
---|
| 1737 | //===== set average in 4x4 depth array ===== |
---|
| 1738 | Int iSum = 0; |
---|
| 1739 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1740 | { |
---|
| 1741 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1742 | { |
---|
| 1743 | if( m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] ) |
---|
| 1744 | { |
---|
| 1745 | iSum += m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ]; |
---|
| 1746 | } |
---|
| 1747 | } |
---|
| 1748 | } |
---|
| 1749 | Int iDepth = ( iSum + ( iNum4x4Set >> 1 ) ) / iNum4x4Set; |
---|
| 1750 | iNum4x4Set = iNum4x4BlksY * iNum4x4BlksX; |
---|
| 1751 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1752 | { |
---|
| 1753 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1754 | { |
---|
| 1755 | m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = iDepth; |
---|
| 1756 | m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true; |
---|
| 1757 | } |
---|
| 1758 | } |
---|
| 1759 | #endif |
---|
| 1760 | |
---|
| 1761 | //===== complete depth arrays ===== |
---|
| 1762 | while( iNum4x4BlksY * iNum4x4BlksX - iNum4x4Set ) |
---|
| 1763 | { |
---|
| 1764 | for( Int i4x4BlkY = 0; i4x4BlkY < iNum4x4BlksY; i4x4BlkY++ ) |
---|
| 1765 | { |
---|
| 1766 | for( Int i4x4BlkX = 0; i4x4BlkX < iNum4x4BlksX; i4x4BlkX++ ) |
---|
| 1767 | { |
---|
| 1768 | if( !m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] ) |
---|
| 1769 | { // could also use minimum of neighbours (occlusions) |
---|
| 1770 | Int iNumNeighbours = 0; |
---|
| 1771 | Int iSumNeighbours = 0; |
---|
| 1772 | if( i4x4BlkY > 0 && m_aabDepthSet[ i4x4BlkY-1 ][ i4x4BlkX ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY-1 ][ i4x4BlkX ]; iNumNeighbours++; } |
---|
| 1773 | if( i4x4BlkY < iNum4x4BlksY-1 && m_aabDepthSet[ i4x4BlkY+1 ][ i4x4BlkX ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY+1 ][ i4x4BlkX ]; iNumNeighbours++; } |
---|
| 1774 | if( i4x4BlkX > 0 && m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX-1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX-1 ]; iNumNeighbours++; } |
---|
| 1775 | if( i4x4BlkX < iNum4x4BlksX-1 && m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX+1 ] ) { iSumNeighbours += m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX+1 ]; iNumNeighbours++; } |
---|
| 1776 | if( iNumNeighbours ) |
---|
| 1777 | { |
---|
| 1778 | m_aai4x4Depth[ i4x4BlkY ][ i4x4BlkX ] = ( iSumNeighbours + ( iNumNeighbours >> 1 ) ) / iNumNeighbours; |
---|
| 1779 | m_aabDepthSet[ i4x4BlkY ][ i4x4BlkX ] = true; |
---|
| 1780 | iNum4x4Set++; |
---|
| 1781 | } |
---|
| 1782 | } |
---|
| 1783 | } |
---|
| 1784 | } |
---|
| 1785 | } |
---|
| 1786 | |
---|
| 1787 | //===== set depth values ===== |
---|
[21] | 1788 | UInt uiBlkX = g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpX; |
---|
| 1789 | UInt uiBlkY = g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ] >> m_uiSubSampExpY; |
---|
| 1790 | Pel* piDepthMap = pcCUDepthMap->getLumaAddr() + uiBlkY * pcCUDepthMap->getStride() + uiBlkX; |
---|
[2] | 1791 | Int iCUStride = pcCUDepthMap->getStride (); |
---|
| 1792 | for( Int iRow = 0; iRow < iHeight; iRow++, piDepthMap += iCUStride ) |
---|
| 1793 | { |
---|
| 1794 | for( Int iCol = 0; iCol < iWidth; iCol++ ) |
---|
| 1795 | { |
---|
[21] | 1796 | piDepthMap[ iCol ] = m_aai4x4Depth[ (iRow << m_uiSubSampExpY) >> 2 ][ (iCol << m_uiSubSampExpX) >> 2 ]; |
---|
[2] | 1797 | } |
---|
| 1798 | } |
---|
| 1799 | } |
---|
| 1800 | |
---|
| 1801 | |
---|
| 1802 | Void |
---|
| 1803 | TComDepthMapGenerator::xInterPUDepthMapPrediction( TComDataCU* pcCU, TComYuv* pcCUDepthMap, UInt uiPartIdx ) |
---|
| 1804 | { |
---|
[21] | 1805 | m_pcPrediction->motionCompensation( pcCU, pcCUDepthMap, REF_PIC_LIST_X, (Int)uiPartIdx, true, m_uiSubSampExpX, m_uiSubSampExpY ); |
---|
[2] | 1806 | } |
---|
| 1807 | |
---|
| 1808 | |
---|
| 1809 | Bool |
---|
| 1810 | TComDepthMapGenerator::xGetPredDepth( TComDataCU* pcCU, UInt uiPartIdx, Int& riPrdDepth, Int* piPosX, Int* piPosY ) |
---|
| 1811 | { |
---|
| 1812 | AOF ( m_bCreated && m_bInit ); |
---|
| 1813 | AOF ( pcCU ); |
---|
| 1814 | ROFRS( m_bPDMAvailable, false ); |
---|
| 1815 | |
---|
| 1816 | TComSlice* pcSlice = pcCU->getSlice (); |
---|
| 1817 | TComPic* pcPic = pcCU->getPic (); |
---|
| 1818 | TComSPS* pcSPS = pcSlice->getSPS(); |
---|
| 1819 | AOF ( pcPic->getPredDepthMap() ); |
---|
| 1820 | AOF ( pcSPS->getViewId() == m_uiCurrViewId ); |
---|
| 1821 | |
---|
| 1822 | //===== get predicted depth and disprity for middle position of current PU ===== |
---|
| 1823 | UInt uiPartAddr; |
---|
| 1824 | Int iWidth; |
---|
| 1825 | Int iHeight; |
---|
| 1826 | pcCU->getPartIndexAndSize( uiPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 1827 | TComPicYuv* pcPredDepthMap = pcPic->getPredDepthMap(); |
---|
| 1828 | Pel* piPredDepthMap = pcPredDepthMap->getLumaAddr ( 0 ); |
---|
| 1829 | Int iCurrStride = pcPredDepthMap->getStride (); |
---|
| 1830 | Int iCurrPosX; |
---|
| 1831 | Int iCurrPosY; |
---|
| 1832 | pcPredDepthMap->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iCurrPosX, iCurrPosY ); |
---|
[77] | 1833 | #if SAIT_IMPROV_MOTION_PRED_M24829 // max disparity within PU |
---|
| 1834 | Int DiWidth = iCurrPosX+(iWidth >> m_uiSubSampExpX); |
---|
| 1835 | Int DiHeight = iCurrPosY+(iHeight >> m_uiSubSampExpY); |
---|
| 1836 | Int maxDepth = MIN_INT; |
---|
| 1837 | |
---|
| 1838 | for(Int y=iCurrPosY; y<DiHeight ;y++) |
---|
| 1839 | { |
---|
| 1840 | for(Int x=iCurrPosX; x<DiWidth; x++) |
---|
| 1841 | { |
---|
| 1842 | if(piPredDepthMap[ x + y * iCurrStride ] > maxDepth) |
---|
| 1843 | { |
---|
| 1844 | maxDepth = piPredDepthMap[ x + y * iCurrStride ]; |
---|
| 1845 | } |
---|
| 1846 | } |
---|
| 1847 | } |
---|
[21] | 1848 | iCurrPosX += ( ( iWidth >> m_uiSubSampExpX ) - 1 ) >> 1; |
---|
| 1849 | iCurrPosY += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1; |
---|
[77] | 1850 | riPrdDepth = maxDepth; |
---|
| 1851 | #else |
---|
| 1852 | iCurrPosX += ( ( iWidth >> m_uiSubSampExpX ) - 1 ) >> 1; |
---|
| 1853 | iCurrPosY += ( ( iHeight >> m_uiSubSampExpY ) - 1 ) >> 1; |
---|
[2] | 1854 | riPrdDepth = piPredDepthMap[ iCurrPosX + iCurrPosY * iCurrStride ]; |
---|
[77] | 1855 | #endif |
---|
[2] | 1856 | if( piPosX ) |
---|
| 1857 | { |
---|
| 1858 | *piPosX = iCurrPosX; |
---|
| 1859 | } |
---|
| 1860 | if( piPosY ) |
---|
| 1861 | { |
---|
| 1862 | *piPosY = iCurrPosY; |
---|
| 1863 | } |
---|
| 1864 | return true; |
---|
| 1865 | } |
---|
[100] | 1866 | #endif |
---|
[2] | 1867 | |
---|
[5] | 1868 | #endif // DEPTH_MAP_GENERATION |
---|
| 1869 | |
---|