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