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