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