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