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