1 | |
---|
2 | |
---|
3 | /** \file TComResidualGenerator.cpp |
---|
4 | \brief residual picture generator class |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | #include "CommonDef.h" |
---|
10 | #include "TComResidualGenerator.h" |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | TComResidualGenerator::TComResidualGenerator() |
---|
15 | { |
---|
16 | m_bCreated = false; |
---|
17 | m_bInit = false; |
---|
18 | m_bDecoder = false; |
---|
19 | m_pcTrQuant = 0; |
---|
20 | m_pcDepthMapGenerator = 0; |
---|
21 | m_pcSPSAccess = 0; |
---|
22 | m_pcAUPicAccess = 0; |
---|
23 | m_uiMaxDepth = 0; |
---|
24 | m_uiOrgDepthBitDepth = 0; |
---|
25 | m_ppcYuvTmp = 0; |
---|
26 | m_ppcYuv = 0; |
---|
27 | m_ppcCU = 0; |
---|
28 | } |
---|
29 | |
---|
30 | TComResidualGenerator::~TComResidualGenerator() |
---|
31 | { |
---|
32 | destroy (); |
---|
33 | uninit (); |
---|
34 | } |
---|
35 | |
---|
36 | Void |
---|
37 | TComResidualGenerator::create( Bool bDecoder, UInt uiPicWidth, UInt uiPicHeight, UInt uiMaxCUDepth, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiOrgBitDepth ) |
---|
38 | { |
---|
39 | destroy(); |
---|
40 | m_bDecoder = bDecoder; |
---|
41 | m_uiMaxDepth = uiMaxCUDepth; |
---|
42 | m_uiOrgDepthBitDepth = uiOrgBitDepth; |
---|
43 | m_ppcYuvTmp = new TComYuv* [ NUM_TMP_YUV_BUFFERS ]; |
---|
44 | m_ppcYuv = new TComYuv* [ m_uiMaxDepth ]; |
---|
45 | m_ppcCU = new TComDataCU* [ m_uiMaxDepth ]; |
---|
46 | for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ ) |
---|
47 | { |
---|
48 | m_ppcYuvTmp[uiIdx] = new TComYuv; m_ppcYuvTmp[uiIdx]->create( uiMaxCUWidth, uiMaxCUHeight ); |
---|
49 | } |
---|
50 | for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ ) |
---|
51 | { |
---|
52 | UInt uiNumPart = 1 << ( ( m_uiMaxDepth - uiDepth ) << 1 ); |
---|
53 | UInt uiWidth = uiMaxCUWidth >> uiDepth; |
---|
54 | UInt uiHeight = uiMaxCUHeight >> uiDepth; |
---|
55 | |
---|
56 | m_ppcYuv[ uiDepth ] = new TComYuv; m_ppcYuv[ uiDepth ]->create( uiWidth, uiHeight ); |
---|
57 | m_ppcCU [ uiDepth ] = new TComDataCU; m_ppcCU [ uiDepth ]->create( uiNumPart, uiWidth, uiHeight, true ); |
---|
58 | } |
---|
59 | m_cTmpPic.create( uiPicWidth, uiPicHeight, uiMaxCUWidth, uiMaxCUHeight, uiMaxCUDepth ); |
---|
60 | m_bCreated = true; |
---|
61 | } |
---|
62 | |
---|
63 | Void |
---|
64 | TComResidualGenerator::destroy() |
---|
65 | { |
---|
66 | if( m_bCreated ) |
---|
67 | { |
---|
68 | m_bCreated = false; |
---|
69 | for( UInt uiIdx = 0; uiIdx < NUM_TMP_YUV_BUFFERS; uiIdx++ ) |
---|
70 | { |
---|
71 | m_ppcYuvTmp[uiIdx]->destroy(); delete m_ppcYuvTmp[uiIdx]; m_ppcYuvTmp[uiIdx] = 0; |
---|
72 | } |
---|
73 | for( UInt uiDepth = 0; uiDepth < m_uiMaxDepth; uiDepth++ ) |
---|
74 | { |
---|
75 | m_ppcYuv[ uiDepth ]->destroy(); delete m_ppcYuv[ uiDepth ]; m_ppcYuv[ uiDepth ] = 0; |
---|
76 | m_ppcCU [ uiDepth ]->destroy(); delete m_ppcCU [ uiDepth ]; m_ppcCU [ uiDepth ] = 0; |
---|
77 | } |
---|
78 | delete [] m_ppcYuvTmp; m_ppcYuvTmp = 0; |
---|
79 | delete [] m_ppcYuv; m_ppcYuv = 0; |
---|
80 | delete [] m_ppcCU; m_ppcCU = 0; |
---|
81 | m_cTmpPic.destroy(); |
---|
82 | m_uiMaxDepth = 0; |
---|
83 | m_uiOrgDepthBitDepth = 0; |
---|
84 | m_bDecoder = false; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | Void |
---|
89 | TComResidualGenerator::init( TComTrQuant* pcTrQuant, TComDepthMapGenerator* pcDepthMapGenerator ) |
---|
90 | { |
---|
91 | AOF( pcTrQuant ); |
---|
92 | AOF( pcDepthMapGenerator ); |
---|
93 | AOF( pcDepthMapGenerator->getSPSAccess () ); |
---|
94 | AOF( pcDepthMapGenerator->getAUPicAccess() ); |
---|
95 | uninit(); |
---|
96 | m_pcTrQuant = pcTrQuant; |
---|
97 | m_pcDepthMapGenerator = pcDepthMapGenerator; |
---|
98 | m_pcSPSAccess = pcDepthMapGenerator->getSPSAccess (); |
---|
99 | m_pcAUPicAccess = pcDepthMapGenerator->getAUPicAccess(); |
---|
100 | m_bInit = true; |
---|
101 | } |
---|
102 | |
---|
103 | Void |
---|
104 | TComResidualGenerator::uninit() |
---|
105 | { |
---|
106 | if( m_bInit ) |
---|
107 | { |
---|
108 | m_bInit = false; |
---|
109 | m_pcTrQuant = 0; |
---|
110 | m_pcDepthMapGenerator = 0; |
---|
111 | m_pcSPSAccess = 0; |
---|
112 | m_pcAUPicAccess = 0; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | Void |
---|
119 | TComResidualGenerator::initViewComponent( TComPic* pcPic ) |
---|
120 | { |
---|
121 | AOF ( m_bCreated && m_bInit ); |
---|
122 | AOF ( pcPic ); |
---|
123 | |
---|
124 | // set pointer in SPS |
---|
125 | pcPic->getSPS()->setResidualGenerator( this ); |
---|
126 | ROFVS( pcPic->getSPS()->getMultiviewResPredMode() ); |
---|
127 | |
---|
128 | #if OUTPUT_RESIDUAL_PICTURES |
---|
129 | // dump reconstructed residual picture for first AU |
---|
130 | if( pcPic->getPOC() == 0 ) |
---|
131 | { |
---|
132 | AOF( pcPic->getSPS()->getViewId() ); |
---|
133 | UInt uiBaseViewId = pcPic->getSPS()->getViewId() - 1; |
---|
134 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseViewId ); |
---|
135 | AOF( pcBasePic ); |
---|
136 | Char acFilenameBase[1024]; |
---|
137 | ::sprintf( acFilenameBase, "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) ); |
---|
138 | xDumpResidual( pcBasePic, acFilenameBase ); |
---|
139 | } |
---|
140 | #endif |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | Void |
---|
146 | TComResidualGenerator::setRecResidualPic( TComPic* pcPic ) |
---|
147 | { |
---|
148 | AOF ( m_bCreated && m_bInit ); |
---|
149 | AOF ( pcPic ); |
---|
150 | |
---|
151 | if( pcPic->getPOC() == 0 ) |
---|
152 | { |
---|
153 | if( pcPic->getSPS()->getViewId() == 0 || m_pcSPSAccess->getResPrd() != 0 ) |
---|
154 | { |
---|
155 | // set residual picture |
---|
156 | AOT( pcPic->getResidual() ); |
---|
157 | if( !pcPic->getResidual() ) |
---|
158 | { |
---|
159 | pcPic->addResidualBuffer(); |
---|
160 | } |
---|
161 | xSetRecResidualPic( pcPic ); |
---|
162 | } |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | if( m_pcSPSAccess->getResPrd() != 0 && pcPic->getSPS()->getViewId() < m_pcAUPicAccess->getMaxVId() ) |
---|
167 | { |
---|
168 | // set residual picture |
---|
169 | AOT( pcPic->getResidual() ); |
---|
170 | if( !pcPic->getResidual() ) |
---|
171 | { |
---|
172 | pcPic->addResidualBuffer(); |
---|
173 | } |
---|
174 | xSetRecResidualPic( pcPic ); |
---|
175 | |
---|
176 | #if OUTPUT_RESIDUAL_PICTURES |
---|
177 | // dump reconstructed residual picture |
---|
178 | Char acFilenameBase[1024]; |
---|
179 | ::sprintf( acFilenameBase, "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) ); |
---|
180 | xDumpResidual( pcPic, acFilenameBase ); |
---|
181 | #endif |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | Bool |
---|
188 | TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv ) |
---|
189 | { |
---|
190 | AOF( pcCU ); |
---|
191 | UInt uiPartAddr; |
---|
192 | Int iBlkWidth, iBlkHeight, iXPos, iYPos; |
---|
193 | AOT( uiPUIdx ); |
---|
194 | uiPartAddr = 0; |
---|
195 | iBlkWidth = pcCU->getWidth ( 0 ); |
---|
196 | iBlkHeight = pcCU->getHeight ( 0 ); |
---|
197 | pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iXPos, iYPos ); |
---|
198 | return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv ); |
---|
199 | } |
---|
200 | |
---|
201 | Bool |
---|
202 | TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv ) |
---|
203 | { |
---|
204 | UInt uiBaseViewId = m_pcDepthMapGenerator->getBaseViewId( 0 ); |
---|
205 | |
---|
206 | if( !pcYuv ) |
---|
207 | { |
---|
208 | pcYuv = m_ppcYuvTmp[1]; |
---|
209 | } |
---|
210 | xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv ); |
---|
211 | return xIsNonZero( pcYuv, uiBlkWidth, uiBlkHeight ); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | Void |
---|
217 | TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic ) |
---|
218 | { |
---|
219 | AOF( pcPic ); |
---|
220 | AOF( pcPic->getResidual() ); |
---|
221 | for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ ) |
---|
222 | { |
---|
223 | TComDataCU* pcCU = pcPic->getCU( uiCUAddr ); |
---|
224 | xSetRecResidualCU( pcCU, 0, 0 ); |
---|
225 | } |
---|
226 | pcPic->getResidual()->setBorderExtension( false ); |
---|
227 | pcPic->getResidual()->extendPicBorder (); |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | Void |
---|
232 | TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx ) |
---|
233 | { |
---|
234 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
235 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
236 | UInt uiRPelX = uiLPelX + ( g_uiMaxCUWidth >> uiDepth ) - 1; |
---|
237 | UInt uiBPelY = uiTPelY + ( g_uiMaxCUHeight >> uiDepth ) - 1; |
---|
238 | Bool bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getWidth() || uiBPelY >= pcCU->getSlice()->getSPS()->getHeight() ); |
---|
239 | Bool bSplit = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary ); |
---|
240 | if( bSplit ) |
---|
241 | { |
---|
242 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2; |
---|
243 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts ) |
---|
244 | { |
---|
245 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
246 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
247 | Bool bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getWidth() && uiTPelY < pcCU->getSlice()->getSPS()->getHeight() ); |
---|
248 | if( bInside ) |
---|
249 | { |
---|
250 | xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx ); |
---|
251 | } |
---|
252 | } |
---|
253 | return; |
---|
254 | } |
---|
255 | |
---|
256 | //--- set sub-CU and sub-residual --- |
---|
257 | TComDataCU* pcSubCU = m_ppcCU [ uiDepth ]; |
---|
258 | TComYuv* pcSubRes = m_ppcYuv[ uiDepth ]; |
---|
259 | TComPicYuv* pcPicRes = pcCU->getPic()->getResidual(); |
---|
260 | UInt uiCUAddr = pcCU->getAddr(); |
---|
261 | pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth ); |
---|
262 | |
---|
263 | //--- set residual --- |
---|
264 | switch( pcSubCU->getPredictionMode( 0 ) ) |
---|
265 | { |
---|
266 | case MODE_INTRA: |
---|
267 | xSetRecResidualIntraCU( pcSubCU, pcSubRes ); |
---|
268 | break; |
---|
269 | case MODE_SKIP: |
---|
270 | case MODE_INTER: |
---|
271 | xSetRecResidualInterCU( pcSubCU, pcSubRes ); |
---|
272 | break; |
---|
273 | default: |
---|
274 | AOT( true ); |
---|
275 | break; |
---|
276 | } |
---|
277 | |
---|
278 | //--- copy sub-residual --- |
---|
279 | pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx ); |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | Void |
---|
284 | TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual ) |
---|
285 | { |
---|
286 | //===== set residual to zero for entire CU ===== |
---|
287 | xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) ); |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | Void |
---|
292 | TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual ) |
---|
293 | { |
---|
294 | //===== reconstruct residual from coded transform coefficient levels ===== |
---|
295 | xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) ); |
---|
296 | // luma |
---|
297 | UInt uiWidth = pcCU->getWidth ( 0 ); |
---|
298 | UInt uiHeight = pcCU->getHeight ( 0 ); |
---|
299 | TCoeff* piCoeff = pcCU->getCoeffY (); |
---|
300 | Pel* pRes = pcCUResidual->getLumaAddr(); |
---|
301 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
302 | pcCU->convertTransIdx ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode ); |
---|
303 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA ); |
---|
304 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff ); |
---|
305 | // chroma Cb |
---|
306 | uiWidth >>= 1; |
---|
307 | uiHeight >>= 1; |
---|
308 | piCoeff = pcCU->getCoeffCb(); |
---|
309 | pRes = pcCUResidual->getCbAddr(); |
---|
310 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA ); |
---|
311 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff ); |
---|
312 | // chroma Cr |
---|
313 | piCoeff = pcCU->getCoeffCr(); |
---|
314 | pRes = pcCUResidual->getCrAddr(); |
---|
315 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff ); |
---|
316 | |
---|
317 | if( pcCU->getResPredFlag( 0 ) ) |
---|
318 | { |
---|
319 | AOF( pcCU->getResPredAvail( 0 ) ); |
---|
320 | Bool bOK = pcCU->getResidualSamples( 0, m_ppcYuvTmp[0] ); |
---|
321 | AOF( bOK ); |
---|
322 | pcCUResidual->add( m_ppcYuvTmp[0], pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) ); |
---|
323 | } |
---|
324 | |
---|
325 | //===== clear inter-view predicted parts ===== |
---|
326 | for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ ) |
---|
327 | { |
---|
328 | xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx ); |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | |
---|
333 | Void |
---|
334 | TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx ) |
---|
335 | { |
---|
336 | UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId(); |
---|
337 | if( uiCurrViewId ) |
---|
338 | { |
---|
339 | Int iWidth; |
---|
340 | Int iHeight; |
---|
341 | UInt uiAbsPartIdx; |
---|
342 | pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
343 | TComCUMvField* aiCurrMvField[2] = { pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getCUMvField( REF_PIC_LIST_1 ) }; |
---|
344 | Int aiCurrRefIdx [2] = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) }; |
---|
345 | Bool abCurrIntView[2] = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId, |
---|
346 | aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId }; |
---|
347 | Bool bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] ); |
---|
348 | if( bUsesInterViewPrd ) |
---|
349 | { //===== set resiudal to zero ===== |
---|
350 | xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight ); |
---|
351 | } |
---|
352 | } |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | Void |
---|
357 | TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) |
---|
358 | { |
---|
359 | // luma |
---|
360 | Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx ); |
---|
361 | Int iStrideY = pcCUResidual->getStride (); |
---|
362 | for( UInt uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY ) |
---|
363 | { |
---|
364 | ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) ); |
---|
365 | } |
---|
366 | // chroma |
---|
367 | uiWidth >>= 1; |
---|
368 | uiHeight >>= 1; |
---|
369 | Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx ); |
---|
370 | Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx ); |
---|
371 | Int iStrideC = pcCUResidual->getCStride(); |
---|
372 | for( UInt uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC ) |
---|
373 | { |
---|
374 | ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) ); |
---|
375 | ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) ); |
---|
376 | } |
---|
377 | } |
---|
378 | |
---|
379 | |
---|
380 | |
---|
381 | Void |
---|
382 | TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv ) |
---|
383 | { |
---|
384 | //===== set and check some basic variables ===== |
---|
385 | AOF( pcYuv ); |
---|
386 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseViewId ); |
---|
387 | AOF( pcPic ); |
---|
388 | AOF( pcBasePic ); |
---|
389 | TComPicYuv* pcBaseRes = pcBasePic->getResidual (); |
---|
390 | TComPicYuv* pcPdmMap = pcPic ->getPredDepthMap(); |
---|
391 | AOF( pcBaseRes ); |
---|
392 | AOF( pcPdmMap ); |
---|
393 | UInt uiPicWidth = pcBaseRes->getWidth (); |
---|
394 | UInt uiPicHeight = pcBaseRes->getHeight(); |
---|
395 | AOT( uiXPos + uiBlkWidth > uiPicWidth ); |
---|
396 | AOT( uiYPos + uiBlkHeight > uiPicHeight ); |
---|
397 | |
---|
398 | //===== get disparity ===== |
---|
399 | Int iMidPosX = Int( uiXPos + ( ( uiBlkWidth - 1 ) >> 1 ) ); |
---|
400 | Int iMidPosY = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ); |
---|
401 | Int iDisparity = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId ); |
---|
402 | |
---|
403 | //===== compensate luma ===== |
---|
404 | Int iYWidth = Int( uiBlkWidth ); |
---|
405 | Int iYHeight = Int( uiBlkHeight ); |
---|
406 | Int iYWeight1 = ( iDisparity & 3 ); |
---|
407 | Int iYWeight0 = 4 - iYWeight1; |
---|
408 | Int iYRefPosX0 = Int( uiXPos ) + ( iDisparity >> 2 ); |
---|
409 | Int iYRefPosX1 = iYRefPosX0 + 1; |
---|
410 | Int iYMaxPosX = Int( uiPicWidth ) - 1; |
---|
411 | Int iSrcStrideY = pcBaseRes->getStride (); |
---|
412 | Int iDesStrideY = pcYuv ->getStride (); |
---|
413 | Pel* pSrcSamplesY= pcBaseRes->getLumaAddr ( 0 ) + uiYPos * iSrcStrideY; |
---|
414 | Pel* pDesSamplesY= pcYuv ->getLumaAddr (); |
---|
415 | for( Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY += iSrcStrideY, pDesSamplesY += iDesStrideY ) |
---|
416 | { |
---|
417 | for( Int iX = 0; iX < iYWidth; iX++ ) |
---|
418 | { |
---|
419 | Int iXPic0 = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) ); |
---|
420 | Int iXPic1 = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) ); |
---|
421 | pDesSamplesY[iX] = ( iYWeight0 * pSrcSamplesY[iXPic0] + iYWeight1 * pSrcSamplesY[iXPic1] + 2 ) >> 2; |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | //===== compensate chroma ===== |
---|
426 | Int iCWidth = Int( uiBlkWidth >> 1 ); |
---|
427 | Int iCHeight = Int( uiBlkHeight >> 1 ); |
---|
428 | Int iCWeight1 = ( iDisparity & 7 ); |
---|
429 | Int iCWeight0 = 8 - iCWeight1; |
---|
430 | Int iCRefPosX0 = Int( uiXPos >> 1 ) + ( iDisparity >> 3 ); |
---|
431 | Int iCRefPosX1 = iCRefPosX0 + 1; |
---|
432 | Int iCMaxPosX = Int( uiPicWidth >> 1 ) - 1; |
---|
433 | Int iSrcStrideC = pcBaseRes->getCStride(); |
---|
434 | Int iDesStrideC = pcYuv ->getCStride(); |
---|
435 | Pel* pSrcSamplesU= pcBaseRes->getCbAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC; |
---|
436 | Pel* pSrcSamplesV= pcBaseRes->getCrAddr ( 0 ) + ( uiYPos >> 1 ) * iSrcStrideC; |
---|
437 | Pel* pDesSamplesU= pcYuv ->getCbAddr (); |
---|
438 | Pel* pDesSamplesV= pcYuv ->getCrAddr (); |
---|
439 | for( Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU += iSrcStrideC, pDesSamplesU += iDesStrideC, |
---|
440 | pSrcSamplesV += iSrcStrideC, pDesSamplesV += iDesStrideC ) |
---|
441 | { |
---|
442 | for( Int iX = 0; iX < iCWidth; iX++ ) |
---|
443 | { |
---|
444 | Int iXPic0 = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) ); |
---|
445 | Int iXPic1 = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) ); |
---|
446 | pDesSamplesU[iX] = ( iCWeight0 * pSrcSamplesU[iXPic0] + iCWeight1 * pSrcSamplesU[iXPic1] + 4 ) >> 3; |
---|
447 | pDesSamplesV[iX] = ( iCWeight0 * pSrcSamplesV[iXPic0] + iCWeight1 * pSrcSamplesV[iXPic1] + 4 ) >> 3; |
---|
448 | } |
---|
449 | } |
---|
450 | } |
---|
451 | |
---|
452 | |
---|
453 | Bool |
---|
454 | TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight ) |
---|
455 | { |
---|
456 | AOF( pcYuv ); |
---|
457 | //===== check luma ===== |
---|
458 | Int iYWidth = Int( uiBlkWidth ); |
---|
459 | Int iYHeight = Int( uiBlkHeight ); |
---|
460 | Int iStrideY = pcYuv->getStride (); |
---|
461 | Pel* pSamplesY = pcYuv->getLumaAddr (); |
---|
462 | for( Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY ) |
---|
463 | { |
---|
464 | for( Int iX = 0; iX < iYWidth; iX++ ) |
---|
465 | { |
---|
466 | ROTRS( pSamplesY[iX], true ); |
---|
467 | } |
---|
468 | } |
---|
469 | //===== compensate chroma ===== |
---|
470 | Int iCWidth = Int( uiBlkWidth >> 1 ); |
---|
471 | Int iCHeight = Int( uiBlkHeight >> 1 ); |
---|
472 | Int iStrideC = pcYuv->getCStride(); |
---|
473 | Pel* pSamplesU = pcYuv->getCbAddr (); |
---|
474 | Pel* pSamplesV = pcYuv->getCrAddr (); |
---|
475 | for( Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC ) |
---|
476 | { |
---|
477 | for( Int iX = 0; iX < iCWidth; iX++ ) |
---|
478 | { |
---|
479 | ROTRS( pSamplesU[iX], true ); |
---|
480 | ROTRS( pSamplesV[iX], true ); |
---|
481 | } |
---|
482 | } |
---|
483 | return false; |
---|
484 | } |
---|
485 | |
---|
486 | |
---|
487 | |
---|
488 | Void |
---|
489 | TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase ) |
---|
490 | { |
---|
491 | AOF( m_bCreated && m_bInit ); |
---|
492 | AOF( pcPic ); |
---|
493 | AOF( pFilenameBase ); |
---|
494 | AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement ); |
---|
495 | |
---|
496 | // convert to output format (just clip high absolute values, since they are very unlikely) |
---|
497 | Int iMin = 0; |
---|
498 | Int iMax = ( 1 << m_uiOrgDepthBitDepth ) - 1; |
---|
499 | Int iMid = ( 1 << m_uiOrgDepthBitDepth ) >> 1; |
---|
500 | UInt uiViewId = pcPic ->getSPS ()->getViewId(); |
---|
501 | TComPicYuv* pcPicYuv = pcPic ->getResidual (); |
---|
502 | // luma |
---|
503 | Int iWidth = pcPicYuv->getWidth (); |
---|
504 | Int iHeight = pcPicYuv->getHeight (); |
---|
505 | Int iSrcStride = pcPicYuv->getStride (); |
---|
506 | Int iDstStride = m_cTmpPic.getStride (); |
---|
507 | Pel* pSrcSamples = pcPicYuv->getLumaAddr ( 0 ); |
---|
508 | Pel* pDstSamples = m_cTmpPic.getLumaAddr ( 0 ); |
---|
509 | AOF( m_cTmpPic.getWidth () == iWidth ); |
---|
510 | AOF( m_cTmpPic.getHeight() == iHeight ); |
---|
511 | for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride ) |
---|
512 | { |
---|
513 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
514 | { |
---|
515 | pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) ); |
---|
516 | } |
---|
517 | } |
---|
518 | // chroma |
---|
519 | iWidth >>= 1; |
---|
520 | iHeight >>= 1; |
---|
521 | iSrcStride = pcPicYuv->getCStride(); |
---|
522 | iDstStride = m_cTmpPic.getCStride(); |
---|
523 | Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 ); |
---|
524 | Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 ); |
---|
525 | Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 ); |
---|
526 | Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 ); |
---|
527 | for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride ) |
---|
528 | { |
---|
529 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
530 | { |
---|
531 | pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) ); |
---|
532 | pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) ); |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | // output |
---|
537 | Char acFilename[1024]; |
---|
538 | ::sprintf ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId ); |
---|
539 | m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 ) ); |
---|
540 | } |
---|
541 | |
---|
542 | |
---|
543 | |
---|