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