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