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 H3D_IVRP |
---|
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 H3D_IVRP |
---|
187 | if (pcPic->getSPS()->getViewId() != 0) |
---|
188 | { |
---|
189 | return; |
---|
190 | } |
---|
191 | #endif |
---|
192 | |
---|
193 | if( pcPic->getPOC() == 0 ) |
---|
194 | { |
---|
195 | if( pcPic->getSPS()->getViewId() == 0 || m_pcSPSAccess->getResPrd() != 0 ) |
---|
196 | { |
---|
197 | // set residual picture |
---|
198 | AOT( pcPic->getResidual() ); |
---|
199 | if( !pcPic->getResidual() ) |
---|
200 | { |
---|
201 | pcPic->addResidualBuffer(); |
---|
202 | } |
---|
203 | xSetRecResidualPic( pcPic ); |
---|
204 | } |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | if( m_pcSPSAccess->getResPrd() != 0 && pcPic->getSPS()->getViewId() < m_pcAUPicAccess->getMaxVId() ) |
---|
209 | { |
---|
210 | // set residual picture |
---|
211 | AOT( pcPic->getResidual() ); |
---|
212 | if( !pcPic->getResidual() ) |
---|
213 | { |
---|
214 | pcPic->addResidualBuffer(); |
---|
215 | } |
---|
216 | xSetRecResidualPic( pcPic ); |
---|
217 | |
---|
218 | #if OUTPUT_RESIDUAL_PICTURES |
---|
219 | // dump reconstructed residual picture |
---|
220 | Char acFilenameBase[1024]; |
---|
221 | ::sprintf( acFilenameBase, "RecResidual_%s", ( m_bDecoder ? "Dec" : "Enc" ) ); |
---|
222 | xDumpResidual( pcPic, acFilenameBase ); |
---|
223 | #endif |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | #if H3D_NBDV |
---|
229 | Bool |
---|
230 | TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, TComMv iDisp, Bool bRecon ) |
---|
231 | #else |
---|
232 | Bool |
---|
233 | TComResidualGenerator::getResidualSamples( TComDataCU* pcCU, UInt uiPUIdx, TComYuv* pcYuv, Bool bRecon ) |
---|
234 | #endif //H3D_NBDV |
---|
235 | { |
---|
236 | AOF( pcCU ); |
---|
237 | UInt uiPartAddr; |
---|
238 | Int iBlkWidth, iBlkHeight, iXPos, iYPos; |
---|
239 | AOT( uiPUIdx ); |
---|
240 | uiPartAddr = 0; |
---|
241 | iBlkWidth = pcCU->getWidth ( 0 ); |
---|
242 | iBlkHeight = pcCU->getHeight ( 0 ); |
---|
243 | pcCU->getPic()->getPicYuvRec()->getTopLeftSamplePos( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr, iXPos, iYPos ); |
---|
244 | #if H3D_NBDV |
---|
245 | return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, iDisp, bRecon); |
---|
246 | #else |
---|
247 | return getResidualSamples( pcCU->getPic(), (UInt)iXPos, (UInt)iYPos, (UInt)iBlkWidth, (UInt)iBlkHeight, pcYuv, bRecon); |
---|
248 | #endif // H3D_NBDV |
---|
249 | } |
---|
250 | |
---|
251 | #if H3D_NBDV |
---|
252 | Bool |
---|
253 | TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp, Bool bRecon) |
---|
254 | #else |
---|
255 | Bool |
---|
256 | TComResidualGenerator::getResidualSamples( TComPic* pcPic, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, Bool bRecon) |
---|
257 | #endif |
---|
258 | { |
---|
259 | UInt uiBaseViewId = 0; |
---|
260 | if( !pcYuv ) |
---|
261 | { |
---|
262 | pcYuv = m_ppcYuvTmp[1]; |
---|
263 | } |
---|
264 | UInt uiXPosInRefView = uiXPos , uiYPosInRefView = uiYPos; |
---|
265 | #if H3D_NBDV |
---|
266 | xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, iDisp, &uiXPosInRefView , &uiYPosInRefView , bRecon ); |
---|
267 | #else |
---|
268 | xSetPredResidualBlock( pcPic, uiBaseViewId, uiXPos, uiYPos, uiBlkWidth, uiBlkHeight, pcYuv, &uiXPosInRefView , &uiYPosInRefView , bRecon ); |
---|
269 | #endif |
---|
270 | return true; |
---|
271 | } |
---|
272 | |
---|
273 | Bool TComResidualGenerator::xIsNonZeroByCBF( UInt uiBaseViewId , UInt uiXPos , UInt uiYPos, UInt uiBlkWidth , UInt uiBlkHeight ) |
---|
274 | { |
---|
275 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseViewId ); |
---|
276 | const Int nMaxPicX = pcBasePic->getSPS()->getPicWidthInLumaSamples() - 1; |
---|
277 | const Int nMaxPicY = pcBasePic->getSPS()->getPicHeightInLumaSamples() - 1; |
---|
278 | for( UInt y = 0 ; y < uiBlkHeight ; y +=4 ) |
---|
279 | { |
---|
280 | for( UInt x = 0 ; x <= uiBlkWidth ; x += 4 ) |
---|
281 | { // to cover both the mapped CU and the 1-pixel-right-shifted mapped CU |
---|
282 | Int iCuAddr = 0, iAbsZorderIdx = 0; |
---|
283 | pcBasePic->getPicYuvRec()->getCUAddrAndPartIdx( Min( uiXPos + x , nMaxPicX ) , Min( uiYPos + y , nMaxPicY ) , iCuAddr , iAbsZorderIdx ); |
---|
284 | TComDataCU *pCUInRefView = pcBasePic->getCU( iCuAddr ); |
---|
285 | if( pCUInRefView->isIntra( iAbsZorderIdx ) ) |
---|
286 | // no inter-view residual pred from a intra CU |
---|
287 | continue; |
---|
288 | UInt uiTempTrDepth = pCUInRefView->getTransformIdx( iAbsZorderIdx ); |
---|
289 | if( pCUInRefView->getCbf( iAbsZorderIdx , TEXT_LUMA , uiTempTrDepth ) |
---|
290 | || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_U , uiTempTrDepth ) |
---|
291 | || pCUInRefView->getCbf( iAbsZorderIdx , TEXT_CHROMA_V , uiTempTrDepth ) ) |
---|
292 | return( true ); |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | return( false ); |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | Void |
---|
302 | TComResidualGenerator::xSetRecResidualPic( TComPic* pcPic ) |
---|
303 | { |
---|
304 | AOF( pcPic ); |
---|
305 | AOF( pcPic->getResidual() ); |
---|
306 | for( UInt uiCUAddr = 0; uiCUAddr < pcPic->getPicSym()->getNumberOfCUsInFrame(); uiCUAddr++ ) |
---|
307 | { |
---|
308 | TComDataCU* pcCU = pcPic->getCU( uiCUAddr ); |
---|
309 | xSetRecResidualCU( pcCU, 0, 0 ); |
---|
310 | } |
---|
311 | pcPic->getResidual()->setBorderExtension( false ); |
---|
312 | pcPic->getResidual()->extendPicBorder (); |
---|
313 | } |
---|
314 | |
---|
315 | |
---|
316 | Void |
---|
317 | TComResidualGenerator::xSetRecResidualCU( TComDataCU* pcCU, UInt uiDepth, UInt uiAbsPartIdx ) |
---|
318 | { |
---|
319 | UInt uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
320 | UInt uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
321 | UInt uiRPelX = uiLPelX + ( g_uiMaxCUWidth >> uiDepth ) - 1; |
---|
322 | UInt uiBPelY = uiTPelY + ( g_uiMaxCUHeight >> uiDepth ) - 1; |
---|
323 | Bool bBoundary = ( uiRPelX >= pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() || uiBPelY >= pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
324 | Bool bSplit = ( ( uiDepth < pcCU->getDepth( uiAbsPartIdx ) && uiDepth < ( g_uiMaxCUDepth - g_uiAddCUDepth ) ) || bBoundary ); |
---|
325 | if( bSplit ) |
---|
326 | { |
---|
327 | UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> ( uiDepth << 1 ) ) >> 2; |
---|
328 | for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx += uiQNumParts ) |
---|
329 | { |
---|
330 | uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
331 | uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
332 | Bool bInside = ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() && uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); |
---|
333 | if( bInside ) |
---|
334 | { |
---|
335 | xSetRecResidualCU( pcCU, uiDepth + 1, uiAbsPartIdx ); |
---|
336 | } |
---|
337 | } |
---|
338 | return; |
---|
339 | } |
---|
340 | |
---|
341 | //--- set sub-CU and sub-residual --- |
---|
342 | TComDataCU* pcSubCU = m_ppcCU [ uiDepth ]; |
---|
343 | TComYuv* pcSubRes = m_ppcYuv[ uiDepth ]; |
---|
344 | TComPicYuv* pcPicRes = pcCU->getPic()->getResidual(); |
---|
345 | UInt uiCUAddr = pcCU->getAddr(); |
---|
346 | pcSubCU->copySubCU( pcCU, uiAbsPartIdx, uiDepth ); |
---|
347 | |
---|
348 | //--- set residual --- |
---|
349 | switch( pcSubCU->getPredictionMode( 0 ) ) |
---|
350 | { |
---|
351 | case MODE_INTRA: |
---|
352 | xSetRecResidualIntraCU( pcSubCU, pcSubRes ); |
---|
353 | break; |
---|
354 | case MODE_SKIP: |
---|
355 | case MODE_INTER: |
---|
356 | xSetRecResidualInterCU( pcSubCU, pcSubRes ); |
---|
357 | break; |
---|
358 | default: |
---|
359 | AOT( true ); |
---|
360 | break; |
---|
361 | } |
---|
362 | |
---|
363 | //--- copy sub-residual --- |
---|
364 | pcSubRes->copyToPicYuv( pcPicRes, uiCUAddr, uiAbsPartIdx ); |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | Void |
---|
369 | TComResidualGenerator::xSetRecResidualIntraCU( TComDataCU* pcCU, TComYuv* pcCUResidual ) |
---|
370 | { |
---|
371 | //===== set residual to zero for entire CU ===== |
---|
372 | xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) ); |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | Void |
---|
377 | TComResidualGenerator::xSetRecResidualInterCU( TComDataCU* pcCU, TComYuv* pcCUResidual ) |
---|
378 | { |
---|
379 | //===== reconstruct residual from coded transform coefficient levels ===== |
---|
380 | xClearResidual( pcCUResidual, 0, pcCU->getWidth( 0 ), pcCU->getHeight( 0 ) ); |
---|
381 | // luma |
---|
382 | UInt uiWidth = pcCU->getWidth ( 0 ); |
---|
383 | UInt uiHeight = pcCU->getHeight ( 0 ); |
---|
384 | TCoeff* piCoeff = pcCU->getCoeffY (); |
---|
385 | Pel* pRes = pcCUResidual->getLumaAddr(); |
---|
386 | UInt uiLumaTrMode, uiChromaTrMode; |
---|
387 | pcCU->convertTransIdx ( 0, pcCU->getTransformIdx( 0 ), uiLumaTrMode, uiChromaTrMode ); |
---|
388 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 ); |
---|
389 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_LUMA, pRes, 0, pcCUResidual->getStride(), uiWidth, uiHeight, uiLumaTrMode, 0, piCoeff ); |
---|
390 | // chroma Cb |
---|
391 | uiWidth >>= 1; |
---|
392 | uiHeight >>= 1; |
---|
393 | piCoeff = pcCU->getCoeffCb(); |
---|
394 | pRes = pcCUResidual->getCbAddr(); |
---|
395 | m_pcTrQuant->setQPforQuant ( pcCU->getQP( 0 ), !pcCU->getSlice()->getDepth(), pcCU->getSlice()->getSliceType(), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), pcCU->getSlice()->getPPS()->getChromaQpOffset() ); |
---|
396 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_U, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff ); |
---|
397 | // chroma Cr |
---|
398 | piCoeff = pcCU->getCoeffCr(); |
---|
399 | pRes = pcCUResidual->getCrAddr(); |
---|
400 | m_pcTrQuant->invRecurTransformNxN ( pcCU, 0, TEXT_CHROMA_V, pRes, 0, pcCUResidual->getCStride(), uiWidth, uiHeight, uiChromaTrMode, 0, piCoeff ); |
---|
401 | |
---|
402 | //===== clear inter-view predicted parts ===== |
---|
403 | for( UInt uiPartIdx = 0; uiPartIdx < pcCU->getNumPartInter(); uiPartIdx++ ) |
---|
404 | { |
---|
405 | xClearIntViewResidual( pcCU, pcCUResidual, uiPartIdx ); |
---|
406 | } |
---|
407 | } |
---|
408 | |
---|
409 | |
---|
410 | Void |
---|
411 | TComResidualGenerator::xClearIntViewResidual( TComDataCU* pcCU, TComYuv* pcCUResidual, UInt uiPartIdx ) |
---|
412 | { |
---|
413 | UInt uiCurrViewId = pcCU->getSlice()->getSPS()->getViewId(); |
---|
414 | if( uiCurrViewId ) |
---|
415 | { |
---|
416 | Int iWidth; |
---|
417 | Int iHeight; |
---|
418 | UInt uiAbsPartIdx; |
---|
419 | pcCU->getPartIndexAndSize( uiPartIdx, uiAbsPartIdx, iWidth, iHeight ); |
---|
420 | TComCUMvField* aiCurrMvField[2] = { pcCU->getCUMvField( REF_PIC_LIST_0 ), pcCU->getCUMvField( REF_PIC_LIST_1 ) }; |
---|
421 | Int aiCurrRefIdx [2] = { aiCurrMvField[0]->getRefIdx( uiAbsPartIdx ), aiCurrMvField[1]->getRefIdx( uiAbsPartIdx ) }; |
---|
422 | Bool abCurrIntView[2] = { aiCurrRefIdx[0] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_0, aiCurrRefIdx[0] )->getSPS()->getViewId() != uiCurrViewId, |
---|
423 | aiCurrRefIdx[1] >= 0 && pcCU->getSlice()->getRefPic( REF_PIC_LIST_1, aiCurrRefIdx[1] )->getSPS()->getViewId() != uiCurrViewId }; |
---|
424 | Bool bUsesInterViewPrd = ( abCurrIntView[0] || abCurrIntView[1] ); |
---|
425 | if( bUsesInterViewPrd ) |
---|
426 | { //===== set resiudal to zero ===== |
---|
427 | xClearResidual( pcCUResidual, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight ); |
---|
428 | } |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | |
---|
433 | Void |
---|
434 | TComResidualGenerator::xClearResidual( TComYuv* pcCUResidual, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) |
---|
435 | { |
---|
436 | // luma |
---|
437 | Pel* pSamplesY = pcCUResidual->getLumaAddr( uiAbsPartIdx ); |
---|
438 | Int iStrideY = pcCUResidual->getStride (); |
---|
439 | for( UInt uiY = 0; uiY < uiHeight; uiY++, pSamplesY += iStrideY ) |
---|
440 | { |
---|
441 | ::memset( pSamplesY, 0x00, uiWidth * sizeof( Pel ) ); |
---|
442 | } |
---|
443 | // chroma |
---|
444 | uiWidth >>= 1; |
---|
445 | uiHeight >>= 1; |
---|
446 | Pel* pSamplesU = pcCUResidual->getCbAddr ( uiAbsPartIdx ); |
---|
447 | Pel* pSamplesV = pcCUResidual->getCrAddr ( uiAbsPartIdx ); |
---|
448 | Int iStrideC = pcCUResidual->getCStride(); |
---|
449 | for( UInt uiY = 0; uiY < uiHeight; uiY++, pSamplesU += iStrideC, pSamplesV += iStrideC ) |
---|
450 | { |
---|
451 | ::memset( pSamplesU, 0x00, uiWidth * sizeof( Pel ) ); |
---|
452 | ::memset( pSamplesV, 0x00, uiWidth * sizeof( Pel ) ); |
---|
453 | } |
---|
454 | } |
---|
455 | |
---|
456 | |
---|
457 | #if H3D_NBDV |
---|
458 | Void |
---|
459 | TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv, TComMv iDisp |
---|
460 | ,UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon ) |
---|
461 | #else // H3D_NBDV |
---|
462 | Void |
---|
463 | TComResidualGenerator::xSetPredResidualBlock( TComPic* pcPic, UInt uiBaseViewId, UInt uiXPos, UInt uiYPos, UInt uiBlkWidth, UInt uiBlkHeight, TComYuv* pcYuv |
---|
464 | , UInt * puiXPosInRefView , UInt * puiYPosInRefView , Bool bRecon ) |
---|
465 | #endif // H3D_NBDV |
---|
466 | { |
---|
467 | //===== set and check some basic variables ===== |
---|
468 | AOF( pcYuv ); |
---|
469 | TComPic* pcBasePic = m_pcAUPicAccess->getPic( uiBaseViewId ); |
---|
470 | AOF( pcPic ); |
---|
471 | AOF( pcBasePic ); |
---|
472 | TComPicYuv* pcBaseRes = pcBasePic->getResidual (); |
---|
473 | TComPicYuv* pcPdmMap = pcPic ->getPredDepthMap(); |
---|
474 | AOF( pcBaseRes ); |
---|
475 | AOF( pcPdmMap ); |
---|
476 | UInt uiPicWidth = pcBaseRes->getWidth (); |
---|
477 | UInt uiPicHeight = pcBaseRes->getHeight(); |
---|
478 | AOT( uiXPos + uiBlkWidth > uiPicWidth ); |
---|
479 | AOT( uiYPos + uiBlkHeight > uiPicHeight ); |
---|
480 | |
---|
481 | //===== get disparity ===== |
---|
482 | #if H3D_NBDV |
---|
483 | Int iDisparity_y = iDisp.getVer(); |
---|
484 | Int iDisparity = iDisp.getHor(); |
---|
485 | #else //H3D_NBDV |
---|
486 | Int iMidPosX = Int( uiXPos + ( ( uiBlkWidth - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpX(); |
---|
487 | Int iMidPosY = Int( uiYPos + ( ( uiBlkHeight - 1 ) >> 1 ) ) >> m_pcDepthMapGenerator->getSubSampExpY(); |
---|
488 | Int iDisparity = m_pcDepthMapGenerator->getDisparity( pcPic, iMidPosX, iMidPosY, uiBaseViewId ); |
---|
489 | #endif //H3D_NBDV |
---|
490 | //===== compensate luma ===== |
---|
491 | Int iYWidth = Int( uiBlkWidth ); |
---|
492 | Int iYHeight = Int( uiBlkHeight ); |
---|
493 | Int iYWeight1 = ( iDisparity & 3 ); |
---|
494 | Int iYWeight0 = 4 - iYWeight1; |
---|
495 | Int iYRefPosX0 = Int( uiXPos ) + ( iDisparity >> 2 ); |
---|
496 | Int iYRefPosX1 = iYRefPosX0 + 1; |
---|
497 | Int iYMaxPosY = Int( uiPicHeight ) - 1; |
---|
498 | Int iYWeight3 = ( iDisparity_y & 3 ); |
---|
499 | Int iYWeight2 = 4 - iYWeight3; |
---|
500 | Int iYRefPosY0 = Max( 0, Min( iYMaxPosY, Int( uiYPos ) + ( iDisparity_y >> 2 )) ); |
---|
501 | Int iYRefPosY1 = Max( 0, Min( iYMaxPosY, iYRefPosY0 + 1 )); |
---|
502 | Int iYMaxPosX = Int( uiPicWidth ) - 1; |
---|
503 | Int iSrcStrideY = pcBaseRes->getStride (); |
---|
504 | Int iDesStrideY = pcYuv ->getStride (); |
---|
505 | Pel* pSrcSamplesY0= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY0 * iSrcStrideY; |
---|
506 | Pel* pSrcSamplesY1= pcBaseRes->getLumaAddr ( 0 ) + iYRefPosY1 * iSrcStrideY; |
---|
507 | Pel* pDesSamplesY= pcYuv ->getLumaAddr (); |
---|
508 | |
---|
509 | |
---|
510 | if( puiXPosInRefView != NULL ) |
---|
511 | *puiXPosInRefView = Max( 0, Min( iYMaxPosX, iYRefPosX0 ) ); |
---|
512 | if( puiYPosInRefView != NULL ) |
---|
513 | *puiYPosInRefView = uiYPos; |
---|
514 | if( bRecon == false ) |
---|
515 | return; |
---|
516 | |
---|
517 | for( Int iY = 0; iY < iYHeight; iY++, pSrcSamplesY0 += iSrcStrideY, pSrcSamplesY1 += iSrcStrideY, pDesSamplesY += iDesStrideY ) |
---|
518 | { |
---|
519 | for( Int iX = 0; iX < iYWidth; iX++ ) |
---|
520 | { |
---|
521 | Int iXPic0 = Max( 0, Min( iYMaxPosX, iYRefPosX0 + iX ) ); |
---|
522 | Int iXPic1 = Max( 0, Min( iYMaxPosX, iYRefPosX1 + iX ) ); |
---|
523 | Pel Temp1,Temp2; |
---|
524 | Temp1 =( iYWeight0 * pSrcSamplesY0[iXPic0] + iYWeight1 * pSrcSamplesY0[iXPic1] + 2 ) >> 2; |
---|
525 | Temp2 =( iYWeight0 * pSrcSamplesY1[iXPic0] + iYWeight1 * pSrcSamplesY1[iXPic1] + 2 ) >> 2; |
---|
526 | pDesSamplesY[iX] = ( iYWeight2 * Temp1 + iYWeight3 * Temp2 + 2 ) >> 2; |
---|
527 | } |
---|
528 | } |
---|
529 | |
---|
530 | //===== compensate chroma ===== |
---|
531 | Int iCWidth = Int( uiBlkWidth >> 1 ); |
---|
532 | Int iCHeight = Int( uiBlkHeight >> 1 ); |
---|
533 | Int iCWeight1 = ( iDisparity & 7 ); |
---|
534 | Int iCWeight0 = 8 - iCWeight1; |
---|
535 | Int iCRefPosX0 = Int( uiXPos >> 1 ) + ( iDisparity >> 3 ); |
---|
536 | Int iCRefPosX1 = iCRefPosX0 + 1; |
---|
537 | Int iCMaxPosY = Int( uiPicHeight >> 1 ) - 1; |
---|
538 | Int iCWeight3 = ( iDisparity_y & 7 ); |
---|
539 | Int iCWeight2 = 8 - iCWeight3; |
---|
540 | Int iCRefPosY0 = Max( 0, Min( iCMaxPosY, Int( uiYPos >> 1 ) + ( iDisparity_y >> 3 )) ); |
---|
541 | Int iCRefPosY1 = Max( 0, Min( iCMaxPosY, iCRefPosY0 + 1 )); |
---|
542 | Int iCMaxPosX = Int( uiPicWidth >> 1 ) - 1; |
---|
543 | Int iSrcStrideC = pcBaseRes->getCStride(); |
---|
544 | Int iDesStrideC = pcYuv ->getCStride(); |
---|
545 | |
---|
546 | Pel* pSrcSamplesU0= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY0 * iSrcStrideC; |
---|
547 | Pel* pSrcSamplesU1= pcBaseRes->getCbAddr ( 0 ) + iCRefPosY1 * iSrcStrideC; |
---|
548 | Pel* pSrcSamplesV0= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY0 * iSrcStrideC; |
---|
549 | Pel* pSrcSamplesV1= pcBaseRes->getCrAddr ( 0 ) + iCRefPosY1 * iSrcStrideC; |
---|
550 | Pel* pDesSamplesU= pcYuv ->getCbAddr (); |
---|
551 | Pel* pDesSamplesV= pcYuv ->getCrAddr (); |
---|
552 | for( Int iY = 0; iY < iCHeight; iY++, pSrcSamplesU0 += iSrcStrideC, pSrcSamplesU1 += iSrcStrideC, pDesSamplesU += iDesStrideC, |
---|
553 | pSrcSamplesV0 += iSrcStrideC, pSrcSamplesV1 += iSrcStrideC, pDesSamplesV += iDesStrideC ) |
---|
554 | { |
---|
555 | for( Int iX = 0; iX < iCWidth; iX++ ) |
---|
556 | { |
---|
557 | Int iXPic0 = Max( 0, Min( iCMaxPosX, iCRefPosX0 + iX ) ); |
---|
558 | Int iXPic1 = Max( 0, Min( iCMaxPosX, iCRefPosX1 + iX ) ); |
---|
559 | Pel Temp1,Temp2; |
---|
560 | Temp1 =( iCWeight0 * pSrcSamplesU0[iXPic0] + iCWeight1 * pSrcSamplesU0[iXPic1] + 4 ) >> 3; |
---|
561 | Temp2 =( iCWeight0 * pSrcSamplesU1[iXPic0] + iCWeight1 * pSrcSamplesU1[iXPic1] + 4 ) >> 3; |
---|
562 | pDesSamplesU[iX] = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3; |
---|
563 | Temp1 =( iCWeight0 * pSrcSamplesV0[iXPic0] + iCWeight1 * pSrcSamplesV0[iXPic1] + 4 ) >> 3; |
---|
564 | Temp2 =( iCWeight0 * pSrcSamplesV1[iXPic0] + iCWeight1 * pSrcSamplesV1[iXPic1] + 4 ) >> 3; |
---|
565 | pDesSamplesV[iX] = ( iCWeight2 * Temp1 + iCWeight3 * Temp2 + 4 ) >> 3; |
---|
566 | } |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | |
---|
571 | Bool |
---|
572 | TComResidualGenerator::xIsNonZero( TComYuv* pcYuv, UInt uiBlkWidth, UInt uiBlkHeight ) |
---|
573 | { |
---|
574 | AOF( pcYuv ); |
---|
575 | //===== check luma ===== |
---|
576 | Int iYWidth = Int( uiBlkWidth ); |
---|
577 | Int iYHeight = Int( uiBlkHeight ); |
---|
578 | Int iStrideY = pcYuv->getStride (); |
---|
579 | Pel* pSamplesY = pcYuv->getLumaAddr (); |
---|
580 | for( Int iY = 0; iY < iYHeight; iY++, pSamplesY += iStrideY ) |
---|
581 | { |
---|
582 | for( Int iX = 0; iX < iYWidth; iX++ ) |
---|
583 | { |
---|
584 | ROTRS( pSamplesY[iX], true ); |
---|
585 | } |
---|
586 | } |
---|
587 | //===== compensate chroma ===== |
---|
588 | Int iCWidth = Int( uiBlkWidth >> 1 ); |
---|
589 | Int iCHeight = Int( uiBlkHeight >> 1 ); |
---|
590 | Int iStrideC = pcYuv->getCStride(); |
---|
591 | Pel* pSamplesU = pcYuv->getCbAddr (); |
---|
592 | Pel* pSamplesV = pcYuv->getCrAddr (); |
---|
593 | for( Int iY = 0; iY < iCHeight; iY++, pSamplesU += iStrideC, pSamplesV += iStrideC ) |
---|
594 | { |
---|
595 | for( Int iX = 0; iX < iCWidth; iX++ ) |
---|
596 | { |
---|
597 | ROTRS( pSamplesU[iX], true ); |
---|
598 | ROTRS( pSamplesV[iX], true ); |
---|
599 | } |
---|
600 | } |
---|
601 | return false; |
---|
602 | } |
---|
603 | |
---|
604 | |
---|
605 | |
---|
606 | Void |
---|
607 | TComResidualGenerator::xDumpResidual( TComPic* pcPic, char* pFilenameBase ) |
---|
608 | { |
---|
609 | AOF( m_bCreated && m_bInit ); |
---|
610 | AOF( pcPic ); |
---|
611 | AOF( pFilenameBase ); |
---|
612 | AOF( m_uiOrgDepthBitDepth == 8 + g_uiBitIncrement ); |
---|
613 | |
---|
614 | // convert to output format (just clip high absolute values, since they are very unlikely) |
---|
615 | Int iMin = 0; |
---|
616 | Int iMax = ( 1 << m_uiOrgDepthBitDepth ) - 1; |
---|
617 | Int iMid = ( 1 << m_uiOrgDepthBitDepth ) >> 1; |
---|
618 | UInt uiViewId = pcPic ->getSPS ()->getViewId(); |
---|
619 | TComPicYuv* pcPicYuv = pcPic ->getResidual (); |
---|
620 | // luma |
---|
621 | Int iWidth = pcPicYuv->getWidth (); |
---|
622 | Int iHeight = pcPicYuv->getHeight (); |
---|
623 | Int iSrcStride = pcPicYuv->getStride (); |
---|
624 | Int iDstStride = m_cTmpPic.getStride (); |
---|
625 | Pel* pSrcSamples = pcPicYuv->getLumaAddr ( 0 ); |
---|
626 | Pel* pDstSamples = m_cTmpPic.getLumaAddr ( 0 ); |
---|
627 | AOF( m_cTmpPic.getWidth () == iWidth ); |
---|
628 | AOF( m_cTmpPic.getHeight() == iHeight ); |
---|
629 | for( Int iY = 0; iY < iHeight; iY++, pSrcSamples += iSrcStride, pDstSamples += iDstStride ) |
---|
630 | { |
---|
631 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
632 | { |
---|
633 | pDstSamples[ iX ] = Max( iMin, Min( iMax, iMid + pSrcSamples[ iX ] ) ); |
---|
634 | } |
---|
635 | } |
---|
636 | // chroma |
---|
637 | iWidth >>= 1; |
---|
638 | iHeight >>= 1; |
---|
639 | iSrcStride = pcPicYuv->getCStride(); |
---|
640 | iDstStride = m_cTmpPic.getCStride(); |
---|
641 | Pel* pSrcCb = pcPicYuv->getCbAddr ( 0 ); |
---|
642 | Pel* pSrcCr = pcPicYuv->getCrAddr ( 0 ); |
---|
643 | Pel* pDstCb = m_cTmpPic.getCbAddr ( 0 ); |
---|
644 | Pel* pDstCr = m_cTmpPic.getCrAddr ( 0 ); |
---|
645 | for( Int iY = 0; iY < iHeight; iY++, pSrcCb += iSrcStride, pSrcCr += iSrcStride, pDstCb += iDstStride, pDstCr += iDstStride ) |
---|
646 | { |
---|
647 | for( Int iX = 0; iX < iWidth; iX++ ) |
---|
648 | { |
---|
649 | pDstCb[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCb[ iX ] ) ); |
---|
650 | pDstCr[ iX ] = Max( iMin, Min( iMax, iMid + pSrcCr[ iX ] ) ); |
---|
651 | } |
---|
652 | } |
---|
653 | |
---|
654 | // output |
---|
655 | Char acFilename[1024]; |
---|
656 | ::sprintf ( acFilename, "%s_V%d.yuv", pFilenameBase, uiViewId ); |
---|
657 | m_cTmpPic.dump( acFilename, ( pcPic->getPOC() != 0 ) ); |
---|
658 | } |
---|
659 | |
---|
660 | |
---|
661 | #endif // H3D_IVRP |
---|
662 | |
---|