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-2015, ITU/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 ITU/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 | /** \file TComPrediction.cpp |
---|
35 | \brief prediction class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <memory.h> |
---|
39 | #include "TComPrediction.h" |
---|
40 | |
---|
41 | //! \ingroup TLibCommon |
---|
42 | //! \{ |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / initialize |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | TComPrediction::TComPrediction() |
---|
49 | : m_pLumaRecBuffer(0) |
---|
50 | , m_iLumaRecStride(0) |
---|
51 | { |
---|
52 | m_piYuvExt = NULL; |
---|
53 | #if H_3D_VSP |
---|
54 | m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int)); |
---|
55 | if (m_pDepthBlock == NULL) |
---|
56 | { |
---|
57 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
58 | } |
---|
59 | #endif |
---|
60 | } |
---|
61 | |
---|
62 | TComPrediction::~TComPrediction() |
---|
63 | { |
---|
64 | #if H_3D_VSP |
---|
65 | if (m_pDepthBlock != NULL) |
---|
66 | { |
---|
67 | free(m_pDepthBlock); |
---|
68 | } |
---|
69 | m_cYuvDepthOnVsp.destroy(); |
---|
70 | #endif |
---|
71 | |
---|
72 | delete[] m_piYuvExt; |
---|
73 | |
---|
74 | m_acYuvPred[0].destroy(); |
---|
75 | m_acYuvPred[1].destroy(); |
---|
76 | |
---|
77 | m_cYuvPredTemp.destroy(); |
---|
78 | |
---|
79 | #if H_3D_ARP |
---|
80 | m_acYuvPredBase[0].destroy(); |
---|
81 | m_acYuvPredBase[1].destroy(); |
---|
82 | #endif |
---|
83 | if( m_pLumaRecBuffer ) |
---|
84 | { |
---|
85 | delete [] m_pLumaRecBuffer; |
---|
86 | } |
---|
87 | |
---|
88 | Int i, j; |
---|
89 | for (i = 0; i < 4; i++) |
---|
90 | { |
---|
91 | for (j = 0; j < 4; j++) |
---|
92 | { |
---|
93 | m_filteredBlock[i][j].destroy(); |
---|
94 | } |
---|
95 | m_filteredBlockTmp[i].destroy(); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | Void TComPrediction::initTempBuff() |
---|
100 | { |
---|
101 | if( m_piYuvExt == NULL ) |
---|
102 | { |
---|
103 | Int extWidth = MAX_CU_SIZE + 16; |
---|
104 | Int extHeight = MAX_CU_SIZE + 1; |
---|
105 | Int i, j; |
---|
106 | for (i = 0; i < 4; i++) |
---|
107 | { |
---|
108 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7); |
---|
109 | for (j = 0; j < 4; j++) |
---|
110 | { |
---|
111 | m_filteredBlock[i][j].create(extWidth, extHeight); |
---|
112 | } |
---|
113 | } |
---|
114 | m_iYuvExtHeight = ((MAX_CU_SIZE + 2) << 4); |
---|
115 | m_iYuvExtStride = ((MAX_CU_SIZE + 8) << 4); |
---|
116 | m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ]; |
---|
117 | |
---|
118 | // new structure |
---|
119 | m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
120 | m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
121 | |
---|
122 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
123 | #if H_3D_ARP |
---|
124 | m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
125 | m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
126 | #endif |
---|
127 | #if H_3D_VSP |
---|
128 | m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
129 | #endif |
---|
130 | } |
---|
131 | |
---|
132 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
133 | { |
---|
134 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
135 | if (!m_pLumaRecBuffer) |
---|
136 | { |
---|
137 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
138 | } |
---|
139 | } |
---|
140 | #if H_3D_IC |
---|
141 | m_uiaShift[0] = 0; |
---|
142 | for( Int i = 1; i < 64; i++ ) |
---|
143 | { |
---|
144 | m_uiaShift[i] = ( (1 << 15) + i/2 ) / i; |
---|
145 | } |
---|
146 | #endif |
---|
147 | } |
---|
148 | |
---|
149 | // ==================================================================================================================== |
---|
150 | // Public member functions |
---|
151 | // ==================================================================================================================== |
---|
152 | |
---|
153 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
154 | Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
155 | { |
---|
156 | assert(iWidth > 0 && iHeight > 0); |
---|
157 | Int iInd, iSum = 0; |
---|
158 | Pel pDcVal; |
---|
159 | |
---|
160 | if (bAbove) |
---|
161 | { |
---|
162 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
163 | { |
---|
164 | iSum += pSrc[iInd-iSrcStride]; |
---|
165 | } |
---|
166 | } |
---|
167 | if (bLeft) |
---|
168 | { |
---|
169 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
170 | { |
---|
171 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | if (bAbove && bLeft) |
---|
176 | { |
---|
177 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
178 | } |
---|
179 | else if (bAbove) |
---|
180 | { |
---|
181 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
182 | } |
---|
183 | else if (bLeft) |
---|
184 | { |
---|
185 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
190 | } |
---|
191 | |
---|
192 | return pDcVal; |
---|
193 | } |
---|
194 | |
---|
195 | // Function for deriving the angular Intra predictions |
---|
196 | |
---|
197 | /** Function for deriving the simplified angular intra predictions. |
---|
198 | * \param pSrc pointer to reconstructed sample array |
---|
199 | * \param srcStride the stride of the reconstructed sample array |
---|
200 | * \param rpDst reference to pointer for the prediction sample array |
---|
201 | * \param dstStride the stride of the prediction sample array |
---|
202 | * \param width the width of the block |
---|
203 | * \param height the height of the block |
---|
204 | * \param dirMode the intra prediction mode index |
---|
205 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
206 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
207 | * |
---|
208 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
209 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
210 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
211 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
212 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
213 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
214 | * from the extended main reference. |
---|
215 | */ |
---|
216 | Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter ) |
---|
217 | { |
---|
218 | Int k,l; |
---|
219 | Int blkSize = width; |
---|
220 | Pel* pDst = rpDst; |
---|
221 | |
---|
222 | // Map the mode index to main prediction direction and angle |
---|
223 | assert( dirMode > 0 ); //no planar |
---|
224 | Bool modeDC = dirMode < 2; |
---|
225 | Bool modeHor = !modeDC && (dirMode < 18); |
---|
226 | Bool modeVer = !modeDC && !modeHor; |
---|
227 | Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0; |
---|
228 | Int absAng = abs(intraPredAngle); |
---|
229 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
230 | |
---|
231 | // Set bitshifts and scale the angle parameter to block size |
---|
232 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
233 | Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
234 | Int invAngle = invAngTable[absAng]; |
---|
235 | absAng = angTable[absAng]; |
---|
236 | intraPredAngle = signAng * absAng; |
---|
237 | |
---|
238 | // Do the DC prediction |
---|
239 | if (modeDC) |
---|
240 | { |
---|
241 | Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
242 | |
---|
243 | for (k=0;k<blkSize;k++) |
---|
244 | { |
---|
245 | for (l=0;l<blkSize;l++) |
---|
246 | { |
---|
247 | pDst[k*dstStride+l] = dcval; |
---|
248 | } |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | // Do angular predictions |
---|
253 | else |
---|
254 | { |
---|
255 | Pel* refMain; |
---|
256 | Pel* refSide; |
---|
257 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
258 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
259 | |
---|
260 | // Initialise the Main and Left reference array. |
---|
261 | if (intraPredAngle < 0) |
---|
262 | { |
---|
263 | for (k=0;k<blkSize+1;k++) |
---|
264 | { |
---|
265 | refAbove[k+blkSize-1] = pSrc[k-srcStride-1]; |
---|
266 | } |
---|
267 | for (k=0;k<blkSize+1;k++) |
---|
268 | { |
---|
269 | refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1]; |
---|
270 | } |
---|
271 | refMain = (modeVer ? refAbove : refLeft) + (blkSize-1); |
---|
272 | refSide = (modeVer ? refLeft : refAbove) + (blkSize-1); |
---|
273 | |
---|
274 | // Extend the Main reference to the left. |
---|
275 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
276 | for (k=-1; k>blkSize*intraPredAngle>>5; k--) |
---|
277 | { |
---|
278 | invAngleSum += invAngle; |
---|
279 | refMain[k] = refSide[invAngleSum>>8]; |
---|
280 | } |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | for (k=0;k<2*blkSize+1;k++) |
---|
285 | { |
---|
286 | refAbove[k] = pSrc[k-srcStride-1]; |
---|
287 | } |
---|
288 | for (k=0;k<2*blkSize+1;k++) |
---|
289 | { |
---|
290 | refLeft[k] = pSrc[(k-1)*srcStride-1]; |
---|
291 | } |
---|
292 | refMain = modeVer ? refAbove : refLeft; |
---|
293 | refSide = modeVer ? refLeft : refAbove; |
---|
294 | } |
---|
295 | |
---|
296 | if (intraPredAngle == 0) |
---|
297 | { |
---|
298 | for (k=0;k<blkSize;k++) |
---|
299 | { |
---|
300 | for (l=0;l<blkSize;l++) |
---|
301 | { |
---|
302 | pDst[k*dstStride+l] = refMain[l+1]; |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | if ( bFilter ) |
---|
307 | { |
---|
308 | for (k=0;k<blkSize;k++) |
---|
309 | { |
---|
310 | pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) ); |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | else |
---|
315 | { |
---|
316 | Int deltaPos=0; |
---|
317 | Int deltaInt; |
---|
318 | Int deltaFract; |
---|
319 | Int refMainIndex; |
---|
320 | |
---|
321 | for (k=0;k<blkSize;k++) |
---|
322 | { |
---|
323 | deltaPos += intraPredAngle; |
---|
324 | deltaInt = deltaPos >> 5; |
---|
325 | deltaFract = deltaPos & (32 - 1); |
---|
326 | |
---|
327 | if (deltaFract) |
---|
328 | { |
---|
329 | // Do linear filtering |
---|
330 | for (l=0;l<blkSize;l++) |
---|
331 | { |
---|
332 | refMainIndex = l+deltaInt+1; |
---|
333 | pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 ); |
---|
334 | } |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | // Just copy the integer samples |
---|
339 | for (l=0;l<blkSize;l++) |
---|
340 | { |
---|
341 | pDst[k*dstStride+l] = refMain[l+deltaInt+1]; |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | // Flip the block if this is the horizontal mode |
---|
348 | if (modeHor) |
---|
349 | { |
---|
350 | Pel tmp; |
---|
351 | for (k=0;k<blkSize-1;k++) |
---|
352 | { |
---|
353 | for (l=k+1;l<blkSize;l++) |
---|
354 | { |
---|
355 | tmp = pDst[k*dstStride+l]; |
---|
356 | pDst[k*dstStride+l] = pDst[l*dstStride+k]; |
---|
357 | pDst[l*dstStride+k] = tmp; |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
365 | { |
---|
366 | Pel *pDst = piPred; |
---|
367 | Int *ptrSrc; |
---|
368 | |
---|
369 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
370 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
371 | assert( iWidth == iHeight ); |
---|
372 | |
---|
373 | ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
374 | |
---|
375 | // get starting pixel in block |
---|
376 | Int sw = 2 * iWidth + 1; |
---|
377 | |
---|
378 | // Create the prediction |
---|
379 | if ( uiDirMode == PLANAR_IDX ) |
---|
380 | { |
---|
381 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
382 | } |
---|
383 | else |
---|
384 | { |
---|
385 | if ( (iWidth > 16) || (iHeight > 16) ) |
---|
386 | { |
---|
387 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
388 | } |
---|
389 | else |
---|
390 | { |
---|
391 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true ); |
---|
392 | |
---|
393 | if( (uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
394 | { |
---|
395 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight); |
---|
396 | } |
---|
397 | } |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | // Angular chroma |
---|
402 | Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
403 | { |
---|
404 | Pel *pDst = piPred; |
---|
405 | Int *ptrSrc = piSrc; |
---|
406 | |
---|
407 | // get starting pixel in block |
---|
408 | Int sw = 2 * iWidth + 1; |
---|
409 | |
---|
410 | if ( uiDirMode == PLANAR_IDX ) |
---|
411 | { |
---|
412 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
413 | } |
---|
414 | else |
---|
415 | { |
---|
416 | // Create the prediction |
---|
417 | xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
418 | } |
---|
419 | } |
---|
420 | |
---|
421 | #if H_3D_DIM |
---|
422 | Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc, TComWedgelet* dmm4Segmentation ) |
---|
423 | { |
---|
424 | assert( iWidth == iHeight ); |
---|
425 | assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE ); |
---|
426 | assert( isDimMode( uiIntraMode ) ); |
---|
427 | |
---|
428 | UInt dimType = getDimType ( uiIntraMode ); |
---|
429 | Bool isDmmMode = (dimType < DMM_NUM_TYPE); |
---|
430 | |
---|
431 | Bool* biSegPattern = NULL; |
---|
432 | UInt patternStride = 0; |
---|
433 | |
---|
434 | // get partiton |
---|
435 | #if H_3D_DIM_DMM |
---|
436 | TComWedgelet* dmmSegmentation = NULL; |
---|
437 | if( isDmmMode ) |
---|
438 | { |
---|
439 | switch( dimType ) |
---|
440 | { |
---|
441 | case( DMM1_IDX ): |
---|
442 | { |
---|
443 | dmmSegmentation = pcCU->isDMM1UpscaleMode((UInt)iWidth) ? |
---|
444 | &(g_dmmWedgeLists[ g_aucConvertToBit[pcCU->getDMM1BasePatternWidth((UInt)iWidth)] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]) : |
---|
445 | &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]); |
---|
446 | } break; |
---|
447 | case( DMM4_IDX ): |
---|
448 | { |
---|
449 | if( dmm4Segmentation == NULL ) |
---|
450 | { |
---|
451 | dmmSegmentation = new TComWedgelet( iWidth, iHeight ); |
---|
452 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation ); |
---|
453 | } |
---|
454 | else |
---|
455 | { |
---|
456 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation ); |
---|
457 | dmmSegmentation = dmm4Segmentation; |
---|
458 | } |
---|
459 | } break; |
---|
460 | default: assert(0); |
---|
461 | } |
---|
462 | assert( dmmSegmentation ); |
---|
463 | if( dimType == DMM1_IDX && pcCU->isDMM1UpscaleMode((UInt)iWidth) ) |
---|
464 | { |
---|
465 | biSegPattern = dmmSegmentation->getScaledPattern((UInt)iWidth); |
---|
466 | patternStride = iWidth; |
---|
467 | } |
---|
468 | else |
---|
469 | { |
---|
470 | biSegPattern = dmmSegmentation->getPattern(); |
---|
471 | patternStride = dmmSegmentation->getStride (); |
---|
472 | } |
---|
473 | } |
---|
474 | #endif |
---|
475 | |
---|
476 | // get predicted partition values |
---|
477 | assert( biSegPattern ); |
---|
478 | Int* piMask = NULL; |
---|
479 | piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering |
---|
480 | assert( piMask ); |
---|
481 | Int maskStride = 2*iWidth + 1; |
---|
482 | Int* ptrSrc = piMask+maskStride+1; |
---|
483 | Pel predDC1 = 0; Pel predDC2 = 0; |
---|
484 | xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
485 | |
---|
486 | // set segment values with deltaDC offsets |
---|
487 | Pel segDC1 = 0; |
---|
488 | Pel segDC2 = 0; |
---|
489 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
490 | { |
---|
491 | Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx ); |
---|
492 | Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx ); |
---|
493 | #if H_3D_DIM_DMM |
---|
494 | if( isDmmMode ) |
---|
495 | { |
---|
496 | #if H_3D_DIM_DLT |
---|
497 | segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
498 | segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
499 | #else |
---|
500 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
501 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
502 | #endif |
---|
503 | } |
---|
504 | #endif |
---|
505 | } |
---|
506 | else |
---|
507 | { |
---|
508 | segDC1 = predDC1; |
---|
509 | segDC2 = predDC2; |
---|
510 | } |
---|
511 | |
---|
512 | // set prediction signal |
---|
513 | Pel* pDst = piPred; |
---|
514 | xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
515 | pcCU->setDmmPredictor(segDC1, 0); |
---|
516 | pcCU->setDmmPredictor(segDC2, 1); |
---|
517 | |
---|
518 | #if H_3D_DIM_DMM |
---|
519 | if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) |
---|
520 | { |
---|
521 | dmmSegmentation->destroy(); |
---|
522 | delete dmmSegmentation; |
---|
523 | } |
---|
524 | #endif |
---|
525 | } |
---|
526 | #endif |
---|
527 | |
---|
528 | /** Function for checking identical motion. |
---|
529 | * \param TComDataCU* pcCU |
---|
530 | * \param UInt PartAddr |
---|
531 | */ |
---|
532 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
533 | { |
---|
534 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
535 | { |
---|
536 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
537 | { |
---|
538 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
539 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
540 | #if H_3D_ARP |
---|
541 | if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
542 | #else |
---|
543 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
544 | #endif |
---|
545 | { |
---|
546 | return true; |
---|
547 | } |
---|
548 | } |
---|
549 | } |
---|
550 | return false; |
---|
551 | } |
---|
552 | |
---|
553 | #if H_3D_SPIVMP |
---|
554 | Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr ) |
---|
555 | { |
---|
556 | for (Int i = 0; i < iNumSP; i++) |
---|
557 | { |
---|
558 | uiMergedSPW[i] = iSPWidth; |
---|
559 | uiMergedSPH[i] = iSPHeight; |
---|
560 | pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]); |
---|
561 | } |
---|
562 | if( pcCU->getARPW( uiPartAddr ) != 0 ) |
---|
563 | { |
---|
564 | return; |
---|
565 | } |
---|
566 | |
---|
567 | // horizontal sub-PU merge |
---|
568 | for (Int i=0; i<iNumSP; i++) |
---|
569 | { |
---|
570 | if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
571 | { |
---|
572 | continue; |
---|
573 | } |
---|
574 | for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++) |
---|
575 | { |
---|
576 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j])) |
---|
577 | { |
---|
578 | uiMergedSPW[i] += iSPWidth; |
---|
579 | uiMergedSPW[j] = uiMergedSPH[j] = 0; |
---|
580 | } |
---|
581 | else |
---|
582 | { |
---|
583 | break; |
---|
584 | } |
---|
585 | } |
---|
586 | } |
---|
587 | //vertical sub-PU merge |
---|
588 | for (Int i=0; i<iNumSP-iNumSPInOneLine; i++) |
---|
589 | { |
---|
590 | if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
591 | { |
---|
592 | continue; |
---|
593 | } |
---|
594 | for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine) |
---|
595 | { |
---|
596 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j]) |
---|
597 | { |
---|
598 | uiMergedSPH[i] += iSPHeight; |
---|
599 | uiMergedSPH[j] = uiMergedSPW[j] = 0; |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | break; |
---|
604 | } |
---|
605 | } |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 ) |
---|
610 | { |
---|
611 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1)) |
---|
612 | { |
---|
613 | return false; |
---|
614 | } |
---|
615 | if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1)) |
---|
616 | { |
---|
617 | return false; |
---|
618 | } |
---|
619 | |
---|
620 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0) |
---|
621 | { |
---|
622 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1)) |
---|
623 | { |
---|
624 | return false; |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0) |
---|
629 | { |
---|
630 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1)) |
---|
631 | { |
---|
632 | return false; |
---|
633 | } |
---|
634 | } |
---|
635 | return true; |
---|
636 | } |
---|
637 | #endif |
---|
638 | |
---|
639 | #if H_3D_DBBP |
---|
640 | PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU) |
---|
641 | { |
---|
642 | // find virtual partitioning for this CU based on depth block |
---|
643 | // segmentation of texture block --> mask IDs |
---|
644 | Pel* pDepthBlockStart = pDepthPels; |
---|
645 | |
---|
646 | // first compute average of depth block for thresholding |
---|
647 | Int iSumDepth = 0; |
---|
648 | Int iSubSample = 4; |
---|
649 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(); |
---|
650 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); |
---|
651 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
652 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
653 | { |
---|
654 | cDv.setVer(0); |
---|
655 | } |
---|
656 | Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2); |
---|
657 | Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2); |
---|
658 | |
---|
659 | UInt t=0; |
---|
660 | |
---|
661 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
662 | { |
---|
663 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
664 | { |
---|
665 | if (iBlkX+x>iPictureWidth) |
---|
666 | { |
---|
667 | Int depthPel = pDepthPels[t]; |
---|
668 | iSumDepth += depthPel; |
---|
669 | } |
---|
670 | else |
---|
671 | { |
---|
672 | Int depthPel = pDepthPels[x]; |
---|
673 | t=x; |
---|
674 | iSumDepth += depthPel; |
---|
675 | } |
---|
676 | } |
---|
677 | |
---|
678 | // next row |
---|
679 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
680 | { |
---|
681 | pDepthPels += uiDepthStride*iSubSample; |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample]; // respect sub-sampling factor |
---|
686 | Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiSize*uiSize); |
---|
687 | |
---|
688 | // start again for segmentation |
---|
689 | pDepthPels = pDepthBlockStart; |
---|
690 | |
---|
691 | // start mapping process |
---|
692 | Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option |
---|
693 | PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN}; |
---|
694 | |
---|
695 | UInt uiHalfSize = uiSize>>1; |
---|
696 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
697 | { |
---|
698 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
699 | { |
---|
700 | Int depthPel = 0; |
---|
701 | if (iBlkX+x>iPictureWidth) |
---|
702 | { |
---|
703 | depthPel = pDepthPels[t]; |
---|
704 | } |
---|
705 | else |
---|
706 | { |
---|
707 | depthPel = pDepthPels[x]; |
---|
708 | t=x; |
---|
709 | } |
---|
710 | |
---|
711 | // decide which segment this pixel belongs to |
---|
712 | Int ucSegment = (Int)(depthPel>iMean); |
---|
713 | |
---|
714 | // Matched Filter to find optimal (conventional) partitioning |
---|
715 | |
---|
716 | // SIZE_Nx2N |
---|
717 | if(x<uiHalfSize) // left |
---|
718 | { |
---|
719 | matchedPartSum[0][ucSegment]++; |
---|
720 | } |
---|
721 | else // right |
---|
722 | { |
---|
723 | matchedPartSum[0][1-ucSegment]++; |
---|
724 | } |
---|
725 | |
---|
726 | // SIZE_2NxN |
---|
727 | if(y<uiHalfSize) // top |
---|
728 | { |
---|
729 | matchedPartSum[1][ucSegment]++; |
---|
730 | } |
---|
731 | else // bottom |
---|
732 | { |
---|
733 | matchedPartSum[1][1-ucSegment]++; |
---|
734 | } |
---|
735 | } |
---|
736 | |
---|
737 | // next row |
---|
738 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
739 | { |
---|
740 | pDepthPels += uiDepthStride*iSubSample; |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | PartSize matchedPartSize = SIZE_NONE; |
---|
745 | |
---|
746 | Int iMaxMatchSum = 0; |
---|
747 | for(Int p=0; p<2; p++) // loop over partition |
---|
748 | { |
---|
749 | for( Int b=0; b<=1; b++ ) // loop over boolean options |
---|
750 | { |
---|
751 | if(matchedPartSum[p][b] > iMaxMatchSum) |
---|
752 | { |
---|
753 | iMaxMatchSum = matchedPartSum[p][b]; |
---|
754 | matchedPartSize = virtualPartSizes[p]; |
---|
755 | } |
---|
756 | } |
---|
757 | } |
---|
758 | |
---|
759 | AOF( matchedPartSize != SIZE_NONE ); |
---|
760 | |
---|
761 | return matchedPartSize; |
---|
762 | } |
---|
763 | |
---|
764 | Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU) |
---|
765 | { |
---|
766 | // segmentation of texture block --> mask IDs |
---|
767 | Pel* pDepthBlockStart = pDepthPels; |
---|
768 | |
---|
769 | // first compute average of depth block for thresholding |
---|
770 | Int iSumDepth = 0; |
---|
771 | Int uiMinDepth = MAX_INT; |
---|
772 | Int uiMaxDepth = 0; |
---|
773 | uiMinDepth = pDepthPels[ 0 ]; |
---|
774 | uiMaxDepth = pDepthPels[ 0 ]; |
---|
775 | iSumDepth = pDepthPels[ 0 ]; |
---|
776 | |
---|
777 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(); |
---|
778 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(); |
---|
779 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
780 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
781 | { |
---|
782 | cDv.setVer(0); |
---|
783 | } |
---|
784 | Int iBlkX = ( pcCU->getAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getHor()+2)>>2); |
---|
785 | Int iBlkY = ( pcCU->getAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCU() ] ]+ ((cDv.getVer()+2)>>2); |
---|
786 | if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
787 | { |
---|
788 | iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ]; |
---|
789 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
790 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
791 | } |
---|
792 | else |
---|
793 | { |
---|
794 | iSumDepth += pDepthPels[ uiWidth - 1 ]; |
---|
795 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
796 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
797 | } |
---|
798 | if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
799 | { |
---|
800 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]; |
---|
801 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
802 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
803 | } |
---|
804 | else |
---|
805 | { |
---|
806 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ]; |
---|
807 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
808 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
809 | } |
---|
810 | if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
811 | { |
---|
812 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
813 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
814 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
815 | } |
---|
816 | else if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
817 | { |
---|
818 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]; |
---|
819 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
820 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
821 | } |
---|
822 | else if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
823 | { |
---|
824 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
825 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
826 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
827 | } |
---|
828 | else |
---|
829 | { |
---|
830 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]; |
---|
831 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
832 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
833 | } |
---|
834 | |
---|
835 | // don't generate mask for blocks with small depth range (encoder decision) |
---|
836 | if( uiMaxDepth - uiMinDepth < 10 ) |
---|
837 | { |
---|
838 | return false; |
---|
839 | } |
---|
840 | |
---|
841 | AOF(uiWidth==uiHeight); |
---|
842 | Int iMean = iSumDepth >> 2; |
---|
843 | |
---|
844 | // start again for segmentation |
---|
845 | pDepthPels = pDepthBlockStart; |
---|
846 | |
---|
847 | Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0 |
---|
848 | |
---|
849 | // generate mask |
---|
850 | UInt t=0; |
---|
851 | UInt uiSumPix[2] = {0,0}; |
---|
852 | for (Int y=0; y<uiHeight; y++) |
---|
853 | { |
---|
854 | for (Int x=0; x<uiHeight; x++) |
---|
855 | { |
---|
856 | Int depthPel = 0; |
---|
857 | if (iBlkX+x>iPictureWidth) |
---|
858 | { |
---|
859 | depthPel = pDepthPels[t]; |
---|
860 | } |
---|
861 | else |
---|
862 | { |
---|
863 | depthPel = pDepthPels[x]; |
---|
864 | t=x; |
---|
865 | } |
---|
866 | |
---|
867 | // decide which segment this pixel belongs to |
---|
868 | Int ucSegment = (Int)(depthPel>iMean); |
---|
869 | |
---|
870 | if( bInvertMask ) |
---|
871 | { |
---|
872 | ucSegment = 1-ucSegment; |
---|
873 | } |
---|
874 | |
---|
875 | // count pixels for each segment |
---|
876 | uiSumPix[ucSegment]++; |
---|
877 | |
---|
878 | // set mask value |
---|
879 | pMask[x] = (Bool)ucSegment; |
---|
880 | } |
---|
881 | |
---|
882 | // next row |
---|
883 | if (!(iBlkY+y+1>iPictureHeight)) |
---|
884 | pDepthPels += uiDepthStride; |
---|
885 | pMask += MAX_CU_SIZE; |
---|
886 | } |
---|
887 | |
---|
888 | // don't generate valid mask for tiny segments (encoder decision) |
---|
889 | // each segment needs to cover at least 1/8th of block |
---|
890 | UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3; |
---|
891 | if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) ) |
---|
892 | { |
---|
893 | return false; |
---|
894 | } |
---|
895 | |
---|
896 | // all good |
---|
897 | return true; |
---|
898 | } |
---|
899 | |
---|
900 | Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize ) |
---|
901 | { |
---|
902 | Pel* piSrc[2] = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)}; |
---|
903 | UInt uiSrcStride = pInYuv[0]->getStride(); |
---|
904 | Pel* piDst = pOutYuv->getLumaAddr(uiPartAddr); |
---|
905 | UInt uiDstStride = pOutYuv->getStride(); |
---|
906 | |
---|
907 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
908 | Pel* tmpTar = 0; |
---|
909 | tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight); |
---|
910 | |
---|
911 | // backup pointer |
---|
912 | Bool* pMaskStart = pMask; |
---|
913 | |
---|
914 | // combine luma first |
---|
915 | for (Int y=0; y<uiHeight; y++) |
---|
916 | { |
---|
917 | for (Int x=0; x<uiWidth; x++) |
---|
918 | { |
---|
919 | UChar ucSegment = (UChar)pMask[x]; |
---|
920 | AOF( ucSegment < 2 ); |
---|
921 | |
---|
922 | // filtering |
---|
923 | tmpTar[y*uiWidth+x] = piSrc[ucSegment][x]; |
---|
924 | } |
---|
925 | |
---|
926 | piSrc[0] += uiSrcStride; |
---|
927 | piSrc[1] += uiSrcStride; |
---|
928 | pMask += uiMaskStride; |
---|
929 | } |
---|
930 | |
---|
931 | if (partSize == SIZE_Nx2N) |
---|
932 | { |
---|
933 | for (Int y=0; y<uiHeight; y++) |
---|
934 | { |
---|
935 | for (Int x=0; x<uiWidth; x++) |
---|
936 | { |
---|
937 | Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1]; |
---|
938 | Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1]; |
---|
939 | |
---|
940 | Pel left, right; |
---|
941 | left = (x==0) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1]; |
---|
942 | right = (x==uiWidth-1) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1]; |
---|
943 | |
---|
944 | piDst[x] = (l!=r) ? ClipY( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 )) : tmpTar[y*uiWidth+x]; |
---|
945 | } |
---|
946 | piDst += uiDstStride; |
---|
947 | } |
---|
948 | } |
---|
949 | else // SIZE_2NxN |
---|
950 | { |
---|
951 | for (Int y=0; y<uiHeight; y++) |
---|
952 | { |
---|
953 | for (Int x=0; x<uiWidth; x++) |
---|
954 | { |
---|
955 | Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x]; |
---|
956 | Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x]; |
---|
957 | |
---|
958 | Pel top, bottom; |
---|
959 | top = (y==0) ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x]; |
---|
960 | bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x]; |
---|
961 | |
---|
962 | piDst[x] = (t!=b) ? ClipY( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 )) : tmpTar[y*uiWidth+x]; |
---|
963 | } |
---|
964 | piDst += uiDstStride; |
---|
965 | } |
---|
966 | } |
---|
967 | |
---|
968 | if ( tmpTar ) |
---|
969 | { |
---|
970 | xFree(tmpTar); |
---|
971 | tmpTar = NULL; |
---|
972 | } |
---|
973 | |
---|
974 | // now combine chroma |
---|
975 | Pel* piSrcU[2] = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) }; |
---|
976 | Pel* piSrcV[2] = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) }; |
---|
977 | UInt uiSrcStrideC = pInYuv[0]->getCStride(); |
---|
978 | Pel* piDstU = pOutYuv->getCbAddr(uiPartAddr); |
---|
979 | Pel* piDstV = pOutYuv->getCrAddr(uiPartAddr); |
---|
980 | UInt uiDstStrideC = pOutYuv->getCStride(); |
---|
981 | UInt uiWidthC = uiWidth >> 1; |
---|
982 | UInt uiHeightC = uiHeight >> 1; |
---|
983 | Pel filSrcU = 0, filSrcV = 0; |
---|
984 | Pel* tmpTarU = 0, *tmpTarV = 0; |
---|
985 | tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
986 | tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
987 | pMask = pMaskStart; |
---|
988 | |
---|
989 | for (Int y=0; y<uiHeightC; y++) |
---|
990 | { |
---|
991 | for (Int x=0; x<uiWidthC; x++) |
---|
992 | { |
---|
993 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
994 | AOF( ucSegment < 2 ); |
---|
995 | |
---|
996 | // filtering |
---|
997 | tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x]; |
---|
998 | tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x]; |
---|
999 | } |
---|
1000 | |
---|
1001 | piSrcU[0] += uiSrcStrideC; |
---|
1002 | piSrcU[1] += uiSrcStrideC; |
---|
1003 | piSrcV[0] += uiSrcStrideC; |
---|
1004 | piSrcV[1] += uiSrcStrideC; |
---|
1005 | pMask += 2*uiMaskStride; |
---|
1006 | } |
---|
1007 | |
---|
1008 | if (partSize == SIZE_Nx2N) |
---|
1009 | { |
---|
1010 | for (Int y=0; y<uiHeightC; y++) |
---|
1011 | { |
---|
1012 | for (Int x=0; x<uiWidthC; x++) |
---|
1013 | { |
---|
1014 | Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2]; |
---|
1015 | Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2]; |
---|
1016 | |
---|
1017 | Pel leftU, rightU; |
---|
1018 | leftU = (x==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1]; |
---|
1019 | rightU = (x==uiWidthC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1]; |
---|
1020 | Pel leftV, rightV; |
---|
1021 | leftV = (x==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1]; |
---|
1022 | rightV = (x==uiWidthC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1]; |
---|
1023 | |
---|
1024 | if (l!=r) |
---|
1025 | { |
---|
1026 | filSrcU = ClipC( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 )); |
---|
1027 | filSrcV = ClipC( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 )); |
---|
1028 | } |
---|
1029 | else |
---|
1030 | { |
---|
1031 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
1032 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
1033 | } |
---|
1034 | piDstU[x] = filSrcU; |
---|
1035 | piDstV[x] = filSrcV; |
---|
1036 | } |
---|
1037 | piDstU += uiDstStrideC; |
---|
1038 | piDstV += uiDstStrideC; |
---|
1039 | } |
---|
1040 | } |
---|
1041 | else |
---|
1042 | { |
---|
1043 | for (Int y=0; y<uiHeightC; y++) |
---|
1044 | { |
---|
1045 | for (Int x=0; x<uiWidthC; x++) |
---|
1046 | { |
---|
1047 | Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2]; |
---|
1048 | Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2]; |
---|
1049 | |
---|
1050 | Pel topU, bottomU; |
---|
1051 | topU = (y==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x]; |
---|
1052 | bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x]; |
---|
1053 | Pel topV, bottomV; |
---|
1054 | topV = (y==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x]; |
---|
1055 | bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x]; |
---|
1056 | |
---|
1057 | if (t!=b) |
---|
1058 | { |
---|
1059 | filSrcU = ClipC( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 )); |
---|
1060 | filSrcV = ClipC( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 )); |
---|
1061 | } |
---|
1062 | else |
---|
1063 | { |
---|
1064 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
1065 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
1066 | } |
---|
1067 | piDstU[x] = filSrcU; |
---|
1068 | piDstV[x] = filSrcV; |
---|
1069 | } |
---|
1070 | piDstU += uiDstStrideC; |
---|
1071 | piDstV += uiDstStrideC; |
---|
1072 | } |
---|
1073 | } |
---|
1074 | |
---|
1075 | if( tmpTarU ) |
---|
1076 | { |
---|
1077 | xFree(tmpTarU); |
---|
1078 | tmpTarU = NULL; |
---|
1079 | } |
---|
1080 | if ( tmpTarV ) |
---|
1081 | { |
---|
1082 | xFree(tmpTarV); |
---|
1083 | tmpTarV = NULL; |
---|
1084 | } |
---|
1085 | } |
---|
1086 | #endif |
---|
1087 | |
---|
1088 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
1089 | { |
---|
1090 | Int iWidth; |
---|
1091 | Int iHeight; |
---|
1092 | UInt uiPartAddr; |
---|
1093 | |
---|
1094 | if ( iPartIdx >= 0 ) |
---|
1095 | { |
---|
1096 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
1097 | #if H_3D_VSP |
---|
1098 | if ( pcCU->getVSPFlag(uiPartAddr) == 0) |
---|
1099 | { |
---|
1100 | #endif |
---|
1101 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
1102 | { |
---|
1103 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1104 | { |
---|
1105 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
1106 | } |
---|
1107 | else |
---|
1108 | { |
---|
1109 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1110 | } |
---|
1111 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
1112 | { |
---|
1113 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1114 | } |
---|
1115 | } |
---|
1116 | else |
---|
1117 | { |
---|
1118 | #if H_3D_SPIVMP |
---|
1119 | if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1120 | { |
---|
1121 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1122 | |
---|
1123 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1124 | |
---|
1125 | UInt uiW[256], uiH[256]; |
---|
1126 | UInt uiSPAddr[256]; |
---|
1127 | |
---|
1128 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1129 | |
---|
1130 | //MC |
---|
1131 | for (Int i = 0; i < iNumSP; i++) |
---|
1132 | { |
---|
1133 | if (uiW[i]==0 || uiH[i]==0) |
---|
1134 | { |
---|
1135 | continue; |
---|
1136 | } |
---|
1137 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1138 | { |
---|
1139 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1140 | } |
---|
1141 | else |
---|
1142 | { |
---|
1143 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1144 | } |
---|
1145 | } |
---|
1146 | } |
---|
1147 | else |
---|
1148 | { |
---|
1149 | #endif |
---|
1150 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1151 | { |
---|
1152 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1153 | } |
---|
1154 | else |
---|
1155 | { |
---|
1156 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1157 | } |
---|
1158 | #if H_3D_SPIVMP |
---|
1159 | } |
---|
1160 | #endif |
---|
1161 | } |
---|
1162 | #if H_3D_VSP |
---|
1163 | } |
---|
1164 | else |
---|
1165 | { |
---|
1166 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1167 | { |
---|
1168 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1169 | } |
---|
1170 | else |
---|
1171 | { |
---|
1172 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1173 | } |
---|
1174 | } |
---|
1175 | #endif |
---|
1176 | return; |
---|
1177 | } |
---|
1178 | |
---|
1179 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
1180 | { |
---|
1181 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
1182 | |
---|
1183 | #if H_3D_VSP |
---|
1184 | if ( pcCU->getVSPFlag(uiPartAddr) == 0 ) |
---|
1185 | { |
---|
1186 | #endif |
---|
1187 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
1188 | { |
---|
1189 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1190 | { |
---|
1191 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
1192 | } |
---|
1193 | else |
---|
1194 | { |
---|
1195 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1196 | } |
---|
1197 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
1198 | { |
---|
1199 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1200 | } |
---|
1201 | } |
---|
1202 | else |
---|
1203 | { |
---|
1204 | #if H_3D_SPIVMP |
---|
1205 | if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1206 | { |
---|
1207 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1208 | |
---|
1209 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1210 | |
---|
1211 | UInt uiW[256], uiH[256]; |
---|
1212 | UInt uiSPAddr[256]; |
---|
1213 | |
---|
1214 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1215 | //MC |
---|
1216 | for (Int i = 0; i < iNumSP; i++) |
---|
1217 | { |
---|
1218 | if (uiW[i]==0 || uiH[i]==0) |
---|
1219 | { |
---|
1220 | continue; |
---|
1221 | } |
---|
1222 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1223 | { |
---|
1224 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1225 | } |
---|
1226 | else |
---|
1227 | { |
---|
1228 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1229 | } |
---|
1230 | } |
---|
1231 | } |
---|
1232 | else |
---|
1233 | { |
---|
1234 | #endif |
---|
1235 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1236 | { |
---|
1237 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1238 | } |
---|
1239 | else |
---|
1240 | { |
---|
1241 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1242 | } |
---|
1243 | #if H_3D_SPIVMP |
---|
1244 | } |
---|
1245 | #endif |
---|
1246 | } |
---|
1247 | #if H_3D_VSP |
---|
1248 | } |
---|
1249 | else |
---|
1250 | { |
---|
1251 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1252 | { |
---|
1253 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1254 | } |
---|
1255 | else |
---|
1256 | { |
---|
1257 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1258 | } |
---|
1259 | } |
---|
1260 | #endif |
---|
1261 | } |
---|
1262 | return; |
---|
1263 | } |
---|
1264 | |
---|
1265 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
1266 | { |
---|
1267 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
1268 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1269 | pcCU->clipMv(cMv); |
---|
1270 | #if H_MV |
---|
1271 | pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx ); |
---|
1272 | #endif |
---|
1273 | #if H_3D_ARP |
---|
1274 | if(pcCU->getARPW( uiPartAddr ) > 0 && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC()) |
---|
1275 | { |
---|
1276 | xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi ); |
---|
1277 | } |
---|
1278 | else |
---|
1279 | { |
---|
1280 | if( pcCU->getARPW( uiPartAddr ) > 0 |
---|
1281 | && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N |
---|
1282 | && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() |
---|
1283 | ) |
---|
1284 | { |
---|
1285 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi ); |
---|
1286 | } |
---|
1287 | else |
---|
1288 | { |
---|
1289 | #endif |
---|
1290 | #if H_3D_IC |
---|
1291 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ); |
---|
1292 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1293 | #if H_3D_ARP |
---|
1294 | , false |
---|
1295 | #endif |
---|
1296 | , bICFlag ); |
---|
1297 | bICFlag = bICFlag && (iWidth > 8); |
---|
1298 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1299 | #if H_3D_ARP |
---|
1300 | , false |
---|
1301 | #endif |
---|
1302 | , bICFlag ); |
---|
1303 | #else |
---|
1304 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1305 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1306 | #endif |
---|
1307 | #if H_3D_ARP |
---|
1308 | } |
---|
1309 | } |
---|
1310 | #endif |
---|
1311 | } |
---|
1312 | |
---|
1313 | #if H_3D_VSP |
---|
1314 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
1315 | { |
---|
1316 | Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1; |
---|
1317 | |
---|
1318 | Int widthSubPU, heightSubPU; |
---|
1319 | if (vspSize) |
---|
1320 | { |
---|
1321 | widthSubPU = 8; |
---|
1322 | heightSubPU = 4; |
---|
1323 | } |
---|
1324 | else |
---|
1325 | { |
---|
1326 | widthSubPU = 4; |
---|
1327 | heightSubPU = 8; |
---|
1328 | } |
---|
1329 | xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU ); |
---|
1330 | } |
---|
1331 | |
---|
1332 | Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU ) |
---|
1333 | { |
---|
1334 | UInt numPartsInLine = pcCU->getPic()->getNumPartInWidth(); |
---|
1335 | UInt horiNumPartsInSubPU = widthSubPU >> 2; |
---|
1336 | UInt vertNumPartsInSubPU = (heightSubPU >> 2) * numPartsInLine; |
---|
1337 | |
---|
1338 | UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ]; |
---|
1339 | |
---|
1340 | for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU ) |
---|
1341 | { |
---|
1342 | UInt partAddrRasterSubPU = partAddrRasterLine; |
---|
1343 | for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU ) |
---|
1344 | { |
---|
1345 | UInt partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ]; |
---|
1346 | Int refIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU ); assert (refIdx >= 0); |
---|
1347 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU ); |
---|
1348 | pcCU->clipMv(cMv); |
---|
1349 | |
---|
1350 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1351 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1352 | |
---|
1353 | } |
---|
1354 | } |
---|
1355 | } |
---|
1356 | |
---|
1357 | #endif |
---|
1358 | |
---|
1359 | #if H_3D_ARP |
---|
1360 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1361 | { |
---|
1362 | Int iRefIdx = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1363 | TComMv cMv = pNewMvFiled ? pNewMvFiled->getMv() : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1364 | Bool bTobeScaled = false; |
---|
1365 | TComPic* pcPicYuvBaseCol = NULL; |
---|
1366 | TComPic* pcPicYuvBaseRef = NULL; |
---|
1367 | |
---|
1368 | #if H_3D_NBDV |
---|
1369 | DisInfo cDistparity; |
---|
1370 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
1371 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
1372 | #else |
---|
1373 | assert(0); // ARP can be applied only when a DV is available |
---|
1374 | #endif |
---|
1375 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
1376 | |
---|
1377 | { |
---|
1378 | Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList); |
---|
1379 | if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() ) |
---|
1380 | { |
---|
1381 | bTobeScaled = true; |
---|
1382 | } |
---|
1383 | |
---|
1384 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1385 | |
---|
1386 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1387 | |
---|
1388 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan)) |
---|
1389 | { |
---|
1390 | dW = 0; |
---|
1391 | bTobeScaled = false; |
---|
1392 | } |
---|
1393 | else |
---|
1394 | { |
---|
1395 | assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() ); |
---|
1396 | } |
---|
1397 | |
---|
1398 | if(bTobeScaled) |
---|
1399 | { |
---|
1400 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
1401 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
1402 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, 0); |
---|
1403 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
1404 | if ( iScale != 4096 ) |
---|
1405 | { |
---|
1406 | cMv = cMv.scaleMv( iScale ); |
---|
1407 | } |
---|
1408 | iRefIdx = 0; |
---|
1409 | } |
---|
1410 | } |
---|
1411 | |
---|
1412 | pcCU->clipMv(cMv); |
---|
1413 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
1414 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true ); |
---|
1415 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), true ); |
---|
1416 | |
---|
1417 | if( dW > 0 ) |
---|
1418 | { |
---|
1419 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
1420 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
1421 | |
---|
1422 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
1423 | pcCU->clipMv(cMVwithDisparity); |
---|
1424 | if (iWidth <= 8) |
---|
1425 | { |
---|
1426 | pYuvB0->clear(); pYuvB1->clear(); |
---|
1427 | } |
---|
1428 | TComMv cNBDV = cDistparity.m_acNBDV; |
---|
1429 | pcCU->clipMv( cNBDV ); |
---|
1430 | |
---|
1431 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1432 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true ); |
---|
1433 | if (iWidth > 8) |
---|
1434 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, true ); |
---|
1435 | |
---|
1436 | pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec(); |
---|
1437 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true ); |
---|
1438 | |
---|
1439 | if (iWidth > 8) |
---|
1440 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, true ); |
---|
1441 | |
---|
1442 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
1443 | |
---|
1444 | if( 2 == dW ) |
---|
1445 | { |
---|
1446 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1447 | } |
---|
1448 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1449 | } |
---|
1450 | } |
---|
1451 | |
---|
1452 | Bool TComPrediction::xCheckBiInterviewARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eBaseRefPicList, TComPic*& pcPicYuvCurrTRef, TComMv& cBaseTMV, Int& iCurrTRefPoc ) |
---|
1453 | { |
---|
1454 | Int iRefIdx = pcCU->getCUMvField( eBaseRefPicList )->getRefIdx( uiPartAddr ); |
---|
1455 | TComMv cDMv = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr ); |
---|
1456 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); |
---|
1457 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1458 | Int uiLCUAddr,uiAbsPartAddr; |
---|
1459 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
1460 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
1461 | |
---|
1462 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
1463 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
1464 | pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
1465 | TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr ); |
---|
1466 | |
---|
1467 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
1468 | pcPicYuvCurrTRef = NULL; |
---|
1469 | |
---|
1470 | //If there is available motion in base reference list, use it |
---|
1471 | if(!pColCU->isIntra(uiAbsPartAddr)) |
---|
1472 | { |
---|
1473 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1); iList ++) |
---|
1474 | { |
---|
1475 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
1476 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
1477 | if( iRef != -1) |
---|
1478 | { |
---|
1479 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
1480 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
1481 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1482 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
1483 | |
---|
1484 | if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC) |
---|
1485 | { |
---|
1486 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
1487 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1488 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1489 | if(pcPicYuvBaseTRef) |
---|
1490 | { |
---|
1491 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
1492 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
1493 | if ( iScale != 4096 ) |
---|
1494 | { |
---|
1495 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1496 | } |
---|
1497 | iCurrTRefPoc = iTargetPOC; |
---|
1498 | return true; |
---|
1499 | } |
---|
1500 | } |
---|
1501 | } |
---|
1502 | } |
---|
1503 | } |
---|
1504 | |
---|
1505 | //If there is no available motion in base reference list, use ( 0, 0 ) |
---|
1506 | if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 ) |
---|
1507 | { |
---|
1508 | cBaseTMV.set( 0, 0 ); |
---|
1509 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList, pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) ); |
---|
1510 | iCurrTRefPoc = pcPicYuvCurrTRef->getPOC(); |
---|
1511 | return true; |
---|
1512 | } |
---|
1513 | |
---|
1514 | return false; |
---|
1515 | } |
---|
1516 | |
---|
1517 | Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1518 | { |
---|
1519 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1520 | TComMv cDMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1521 | TComMv cTempDMv = cDMv; |
---|
1522 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
1523 | |
---|
1524 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
1525 | TComPic* pcPicYuvCurrTRef = NULL; |
---|
1526 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
1527 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1528 | Bool bTMVAvai = false; |
---|
1529 | TComMv cBaseTMV; |
---|
1530 | if( pNewMvFiled ) |
---|
1531 | { |
---|
1532 | iRefIdx = pNewMvFiled->getRefIdx(); |
---|
1533 | cDMv = pNewMvFiled->getMv(); |
---|
1534 | } |
---|
1535 | pcCU->clipMv(cTempDMv); |
---|
1536 | |
---|
1537 | assert(dW > 0); |
---|
1538 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex())) |
---|
1539 | { |
---|
1540 | dW = 0; |
---|
1541 | } |
---|
1542 | Int uiLCUAddr,uiAbsPartAddr; |
---|
1543 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
1544 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
1545 | |
---|
1546 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
1547 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
1548 | pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
1549 | TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr ); |
---|
1550 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() ) |
---|
1551 | { |
---|
1552 | RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
1553 | Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr ); |
---|
1554 | //The other prediction direction is temporal ARP |
---|
1555 | if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ) |
---|
1556 | { |
---|
1557 | bTMVAvai = true; |
---|
1558 | pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx ); |
---|
1559 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
1560 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1561 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList ); |
---|
1562 | |
---|
1563 | if( iCurrRef >= 0 ) |
---|
1564 | { |
---|
1565 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); |
---|
1566 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1567 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1568 | if( pcPicYuvBaseTRef ) |
---|
1569 | { |
---|
1570 | cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr ); |
---|
1571 | Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC ); |
---|
1572 | if ( iScale != 4096 ) |
---|
1573 | { |
---|
1574 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1575 | } |
---|
1576 | } |
---|
1577 | else |
---|
1578 | { |
---|
1579 | dW = 0; |
---|
1580 | } |
---|
1581 | } |
---|
1582 | else |
---|
1583 | { |
---|
1584 | dW = 0; |
---|
1585 | } |
---|
1586 | } |
---|
1587 | |
---|
1588 | //Both prediction directions are inter-view ARP |
---|
1589 | if ( iOtherRefIdx >= 0 && !bTMVAvai ) |
---|
1590 | { |
---|
1591 | RefPicList eBaseList = REF_PIC_LIST_0; |
---|
1592 | Int iCurrTRefPoc; |
---|
1593 | bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ); |
---|
1594 | |
---|
1595 | if ( bTMVAvai ) |
---|
1596 | { |
---|
1597 | if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) ) |
---|
1598 | { |
---|
1599 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc, pcPicYuvBaseCol->getViewIndex() ); |
---|
1600 | if ( pcPicYuvBaseTRef == NULL ) |
---|
1601 | { |
---|
1602 | dW = 0; |
---|
1603 | } |
---|
1604 | } |
---|
1605 | else |
---|
1606 | { |
---|
1607 | dW = 0; |
---|
1608 | } |
---|
1609 | } |
---|
1610 | } |
---|
1611 | } |
---|
1612 | |
---|
1613 | if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai ) |
---|
1614 | { |
---|
1615 | TComMvField puMVField; |
---|
1616 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++) |
---|
1617 | { |
---|
1618 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
1619 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
1620 | if( iRef != -1) |
---|
1621 | { |
---|
1622 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
1623 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
1624 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1625 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
1626 | if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC) |
---|
1627 | { |
---|
1628 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
1629 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1630 | { |
---|
1631 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1632 | if(pcPicYuvBaseTRef) |
---|
1633 | { |
---|
1634 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
1635 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
1636 | if ( iScale != 4096 ) |
---|
1637 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1638 | bTMVAvai = true; |
---|
1639 | break; |
---|
1640 | } |
---|
1641 | } |
---|
1642 | } |
---|
1643 | } |
---|
1644 | } |
---|
1645 | } |
---|
1646 | if (bTMVAvai == false) |
---|
1647 | { |
---|
1648 | bTMVAvai = true; |
---|
1649 | cBaseTMV.set(0, 0); |
---|
1650 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1651 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic (eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1652 | } |
---|
1653 | |
---|
1654 | xPredInterLumaBlk ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), bTMVAvai); |
---|
1655 | xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), bTMVAvai); |
---|
1656 | |
---|
1657 | if( dW > 0 && bTMVAvai ) |
---|
1658 | { |
---|
1659 | TComYuv* pYuvCurrTRef = &m_acYuvPredBase[0]; |
---|
1660 | TComYuv* pYuvBaseTRef = &m_acYuvPredBase[1]; |
---|
1661 | TComPicYuv* pcYuvCurrTref = pcPicYuvCurrTRef->getPicYuvRec(); |
---|
1662 | TComPicYuv* pcYuvBaseTref = pcPicYuvBaseTRef->getPicYuvRec(); |
---|
1663 | TComMv cTempMv = cDMv + cBaseTMV; |
---|
1664 | |
---|
1665 | pcCU->clipMv(cBaseTMV); |
---|
1666 | pcCU->clipMv(cTempMv); |
---|
1667 | |
---|
1668 | if (iWidth <= 8) |
---|
1669 | { |
---|
1670 | pYuvCurrTRef->clear(); pYuvBaseTRef->clear(); |
---|
1671 | } |
---|
1672 | xPredInterLumaBlk ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, true); |
---|
1673 | |
---|
1674 | if (iWidth > 8) |
---|
1675 | xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, true); |
---|
1676 | |
---|
1677 | xPredInterLumaBlk ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, true); |
---|
1678 | |
---|
1679 | if (iWidth > 8) |
---|
1680 | xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, true); |
---|
1681 | |
---|
1682 | pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); |
---|
1683 | if(dW == 2) |
---|
1684 | { |
---|
1685 | pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1686 | } |
---|
1687 | rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1688 | } |
---|
1689 | } |
---|
1690 | #endif |
---|
1691 | |
---|
1692 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
1693 | { |
---|
1694 | TComYuv* pcMbYuv; |
---|
1695 | Int iRefIdx[2] = {-1, -1}; |
---|
1696 | |
---|
1697 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1698 | { |
---|
1699 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
1700 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1701 | |
---|
1702 | if ( iRefIdx[iRefList] < 0 ) |
---|
1703 | { |
---|
1704 | continue; |
---|
1705 | } |
---|
1706 | |
---|
1707 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1708 | |
---|
1709 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1710 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
1711 | { |
---|
1712 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1713 | } |
---|
1714 | else |
---|
1715 | { |
---|
1716 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
1717 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
1718 | { |
---|
1719 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1720 | } |
---|
1721 | else |
---|
1722 | { |
---|
1723 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
1724 | } |
---|
1725 | } |
---|
1726 | } |
---|
1727 | |
---|
1728 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
1729 | { |
---|
1730 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1731 | } |
---|
1732 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
1733 | { |
---|
1734 | xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); |
---|
1735 | } |
---|
1736 | else |
---|
1737 | { |
---|
1738 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1739 | } |
---|
1740 | } |
---|
1741 | |
---|
1742 | #if H_3D_VSP |
---|
1743 | |
---|
1744 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
1745 | { |
---|
1746 | TComYuv* pcMbYuv; |
---|
1747 | Int iRefIdx[2] = {-1, -1}; |
---|
1748 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
1749 | |
---|
1750 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1751 | { |
---|
1752 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
1753 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1754 | |
---|
1755 | if ( iRefIdx[iRefList] < 0 ) |
---|
1756 | { |
---|
1757 | continue; |
---|
1758 | } |
---|
1759 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1760 | |
---|
1761 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1762 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
1763 | } |
---|
1764 | |
---|
1765 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1766 | } |
---|
1767 | |
---|
1768 | #endif |
---|
1769 | |
---|
1770 | /** |
---|
1771 | * \brief Generate motion-compensated luma block |
---|
1772 | * |
---|
1773 | * \param cu Pointer to current CU |
---|
1774 | * \param refPic Pointer to reference picture |
---|
1775 | * \param partAddr Address of block within CU |
---|
1776 | * \param mv Motion vector |
---|
1777 | * \param width Width of block |
---|
1778 | * \param height Height of block |
---|
1779 | * \param dstPic Pointer to destination picture |
---|
1780 | * \param bi Flag indicating whether bipred is used |
---|
1781 | */ |
---|
1782 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1783 | #if H_3D_ARP |
---|
1784 | , Bool filterType |
---|
1785 | #endif |
---|
1786 | #if H_3D_IC |
---|
1787 | , Bool bICFlag |
---|
1788 | #endif |
---|
1789 | ) |
---|
1790 | { |
---|
1791 | Int refStride = refPic->getStride(); |
---|
1792 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
1793 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1794 | |
---|
1795 | Int dstStride = dstPic->getStride(); |
---|
1796 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
1797 | |
---|
1798 | Int xFrac = mv->getHor() & 0x3; |
---|
1799 | Int yFrac = mv->getVer() & 0x3; |
---|
1800 | |
---|
1801 | #if H_3D_IC |
---|
1802 | if( cu->getSlice()->getIsDepth() ) |
---|
1803 | { |
---|
1804 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
1805 | ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1806 | xFrac = 0; |
---|
1807 | yFrac = 0; |
---|
1808 | } |
---|
1809 | #endif |
---|
1810 | if ( yFrac == 0 ) |
---|
1811 | { |
---|
1812 | #if H_3D_IC |
---|
1813 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi || bICFlag |
---|
1814 | #else |
---|
1815 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi |
---|
1816 | #endif |
---|
1817 | #if H_3D_ARP |
---|
1818 | , filterType |
---|
1819 | #endif |
---|
1820 | ); |
---|
1821 | } |
---|
1822 | else if ( xFrac == 0 ) |
---|
1823 | { |
---|
1824 | #if H_3D_IC |
---|
1825 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag |
---|
1826 | #else |
---|
1827 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi |
---|
1828 | #endif |
---|
1829 | #if H_3D_ARP |
---|
1830 | , filterType |
---|
1831 | #endif |
---|
1832 | ); |
---|
1833 | } |
---|
1834 | else |
---|
1835 | { |
---|
1836 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
1837 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1838 | |
---|
1839 | Int filterSize = NTAPS_LUMA; |
---|
1840 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
1841 | |
---|
1842 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false |
---|
1843 | #if H_3D_ARP |
---|
1844 | , filterType |
---|
1845 | #endif |
---|
1846 | ); |
---|
1847 | #if H_3D_IC |
---|
1848 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi || bICFlag |
---|
1849 | #else |
---|
1850 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi |
---|
1851 | #endif |
---|
1852 | #if H_3D_ARP |
---|
1853 | , filterType |
---|
1854 | #endif |
---|
1855 | ); |
---|
1856 | } |
---|
1857 | |
---|
1858 | #if H_3D_IC |
---|
1859 | if( bICFlag ) |
---|
1860 | { |
---|
1861 | Int a, b, i, j; |
---|
1862 | const Int iShift = IC_CONST_SHIFT; |
---|
1863 | |
---|
1864 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA ); |
---|
1865 | |
---|
1866 | |
---|
1867 | for ( i = 0; i < height; i++ ) |
---|
1868 | { |
---|
1869 | for ( j = 0; j < width; j++ ) |
---|
1870 | { |
---|
1871 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
1872 | } |
---|
1873 | dst += dstStride; |
---|
1874 | } |
---|
1875 | |
---|
1876 | if(bi) |
---|
1877 | { |
---|
1878 | Pel *dst2 = dstPic->getLumaAddr( partAddr ); |
---|
1879 | Int shift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
1880 | for (i = 0; i < height; i++) |
---|
1881 | { |
---|
1882 | for (j = 0; j < width; j++) |
---|
1883 | { |
---|
1884 | Short val = dst2[j] << shift; |
---|
1885 | dst2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
1886 | } |
---|
1887 | dst2 += dstStride; |
---|
1888 | } |
---|
1889 | } |
---|
1890 | } |
---|
1891 | #endif |
---|
1892 | } |
---|
1893 | |
---|
1894 | /** |
---|
1895 | * \brief Generate motion-compensated chroma block |
---|
1896 | * |
---|
1897 | * \param cu Pointer to current CU |
---|
1898 | * \param refPic Pointer to reference picture |
---|
1899 | * \param partAddr Address of block within CU |
---|
1900 | * \param mv Motion vector |
---|
1901 | * \param width Width of block |
---|
1902 | * \param height Height of block |
---|
1903 | * \param dstPic Pointer to destination picture |
---|
1904 | * \param bi Flag indicating whether bipred is used |
---|
1905 | */ |
---|
1906 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1907 | #if H_3D_ARP |
---|
1908 | , Bool filterType |
---|
1909 | #endif |
---|
1910 | #if H_3D_IC |
---|
1911 | , Bool bICFlag |
---|
1912 | #endif |
---|
1913 | ) |
---|
1914 | { |
---|
1915 | Int refStride = refPic->getCStride(); |
---|
1916 | Int dstStride = dstPic->getCStride(); |
---|
1917 | |
---|
1918 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
1919 | |
---|
1920 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1921 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1922 | |
---|
1923 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
1924 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
1925 | |
---|
1926 | Int xFrac = mv->getHor() & 0x7; |
---|
1927 | Int yFrac = mv->getVer() & 0x7; |
---|
1928 | UInt cxWidth = width >> 1; |
---|
1929 | UInt cxHeight = height >> 1; |
---|
1930 | |
---|
1931 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
1932 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1933 | |
---|
1934 | Int filterSize = NTAPS_CHROMA; |
---|
1935 | |
---|
1936 | Int halfFilterSize = (filterSize>>1); |
---|
1937 | |
---|
1938 | if ( yFrac == 0 ) |
---|
1939 | { |
---|
1940 | #if H_3D_IC |
---|
1941 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1942 | #else |
---|
1943 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1944 | #endif |
---|
1945 | #if H_3D_ARP |
---|
1946 | , filterType |
---|
1947 | #endif |
---|
1948 | ); |
---|
1949 | #if H_3D_IC |
---|
1950 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1951 | #else |
---|
1952 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1953 | #endif |
---|
1954 | #if H_3D_ARP |
---|
1955 | , filterType |
---|
1956 | #endif |
---|
1957 | ); |
---|
1958 | } |
---|
1959 | else if ( xFrac == 0 ) |
---|
1960 | { |
---|
1961 | #if H_3D_IC |
---|
1962 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1963 | #else |
---|
1964 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1965 | #endif |
---|
1966 | #if H_3D_ARP |
---|
1967 | , filterType |
---|
1968 | #endif |
---|
1969 | ); |
---|
1970 | #if H_3D_IC |
---|
1971 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1972 | #else |
---|
1973 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1974 | #endif |
---|
1975 | #if H_3D_ARP |
---|
1976 | , filterType |
---|
1977 | #endif |
---|
1978 | ); |
---|
1979 | } |
---|
1980 | else |
---|
1981 | { |
---|
1982 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1983 | #if H_3D_ARP |
---|
1984 | , filterType |
---|
1985 | #endif |
---|
1986 | ); |
---|
1987 | #if H_3D_IC |
---|
1988 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
1989 | #else |
---|
1990 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1991 | #endif |
---|
1992 | #if H_3D_ARP |
---|
1993 | , filterType |
---|
1994 | #endif |
---|
1995 | ); |
---|
1996 | |
---|
1997 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1998 | #if H_3D_ARP |
---|
1999 | , filterType |
---|
2000 | #endif |
---|
2001 | ); |
---|
2002 | #if H_3D_IC |
---|
2003 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
2004 | #else |
---|
2005 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
2006 | #endif |
---|
2007 | #if H_3D_ARP |
---|
2008 | , filterType |
---|
2009 | #endif |
---|
2010 | ); |
---|
2011 | } |
---|
2012 | |
---|
2013 | #if H_3D_IC |
---|
2014 | if( bICFlag ) |
---|
2015 | { |
---|
2016 | Int a, b, i, j; |
---|
2017 | const Int iShift = IC_CONST_SHIFT; |
---|
2018 | |
---|
2019 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb |
---|
2020 | for ( i = 0; i < cxHeight; i++ ) |
---|
2021 | { |
---|
2022 | for ( j = 0; j < cxWidth; j++ ) |
---|
2023 | { |
---|
2024 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
2025 | } |
---|
2026 | dstCb += dstStride; |
---|
2027 | } |
---|
2028 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr |
---|
2029 | for ( i = 0; i < cxHeight; i++ ) |
---|
2030 | { |
---|
2031 | for ( j = 0; j < cxWidth; j++ ) |
---|
2032 | { |
---|
2033 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
2034 | } |
---|
2035 | dstCr += dstStride; |
---|
2036 | } |
---|
2037 | |
---|
2038 | if(bi) |
---|
2039 | { |
---|
2040 | Pel* dstCb2 = dstPic->getCbAddr( partAddr ); |
---|
2041 | Pel* dstCr2 = dstPic->getCrAddr( partAddr ); |
---|
2042 | Int shift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
2043 | for (i = 0; i < cxHeight; i++) |
---|
2044 | { |
---|
2045 | for (j = 0; j < cxWidth; j++) |
---|
2046 | { |
---|
2047 | Short val = dstCb2[j] << shift; |
---|
2048 | dstCb2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
2049 | |
---|
2050 | val = dstCr2[j] << shift; |
---|
2051 | dstCr2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
2052 | } |
---|
2053 | dstCb2 += dstStride; |
---|
2054 | dstCr2 += dstStride; |
---|
2055 | } |
---|
2056 | } |
---|
2057 | } |
---|
2058 | #endif |
---|
2059 | } |
---|
2060 | |
---|
2061 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
2062 | { |
---|
2063 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
2064 | { |
---|
2065 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
2066 | } |
---|
2067 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
2068 | { |
---|
2069 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
2070 | } |
---|
2071 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
2072 | { |
---|
2073 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
2074 | } |
---|
2075 | } |
---|
2076 | |
---|
2077 | // AMVP |
---|
2078 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
2079 | { |
---|
2080 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
2081 | if( pcAMVPInfo->iN <= 1 ) |
---|
2082 | { |
---|
2083 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
2084 | |
---|
2085 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
2086 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
2087 | return; |
---|
2088 | } |
---|
2089 | |
---|
2090 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
2091 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
2092 | return; |
---|
2093 | } |
---|
2094 | |
---|
2095 | /** Function for deriving planar intra prediction. |
---|
2096 | * \param pSrc pointer to reconstructed sample array |
---|
2097 | * \param srcStride the stride of the reconstructed sample array |
---|
2098 | * \param rpDst reference to pointer for the prediction sample array |
---|
2099 | * \param dstStride the stride of the prediction sample array |
---|
2100 | * \param width the width of the block |
---|
2101 | * \param height the height of the block |
---|
2102 | * |
---|
2103 | * This function derives the prediction samples for planar mode (intra coding). |
---|
2104 | */ |
---|
2105 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
2106 | { |
---|
2107 | assert(width == height); |
---|
2108 | |
---|
2109 | Int k, l, bottomLeft, topRight; |
---|
2110 | Int horPred; |
---|
2111 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
2112 | UInt blkSize = width; |
---|
2113 | UInt offset2D = width; |
---|
2114 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
2115 | UInt shift2D = shift1D + 1; |
---|
2116 | |
---|
2117 | // Get left and above reference column and row |
---|
2118 | for(k=0;k<blkSize+1;k++) |
---|
2119 | { |
---|
2120 | topRow[k] = pSrc[k-srcStride]; |
---|
2121 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
2122 | } |
---|
2123 | |
---|
2124 | // Prepare intermediate variables used in interpolation |
---|
2125 | bottomLeft = leftColumn[blkSize]; |
---|
2126 | topRight = topRow[blkSize]; |
---|
2127 | for (k=0;k<blkSize;k++) |
---|
2128 | { |
---|
2129 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
2130 | rightColumn[k] = topRight - leftColumn[k]; |
---|
2131 | topRow[k] <<= shift1D; |
---|
2132 | leftColumn[k] <<= shift1D; |
---|
2133 | } |
---|
2134 | |
---|
2135 | // Generate prediction signal |
---|
2136 | for (k=0;k<blkSize;k++) |
---|
2137 | { |
---|
2138 | horPred = leftColumn[k] + offset2D; |
---|
2139 | for (l=0;l<blkSize;l++) |
---|
2140 | { |
---|
2141 | horPred += rightColumn[k]; |
---|
2142 | topRow[l] += bottomRow[l]; |
---|
2143 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
2144 | } |
---|
2145 | } |
---|
2146 | } |
---|
2147 | |
---|
2148 | /** Function for filtering intra DC predictor. |
---|
2149 | * \param pSrc pointer to reconstructed sample array |
---|
2150 | * \param iSrcStride the stride of the reconstructed sample array |
---|
2151 | * \param rpDst reference to pointer for the prediction sample array |
---|
2152 | * \param iDstStride the stride of the prediction sample array |
---|
2153 | * \param iWidth the width of the block |
---|
2154 | * \param iHeight the height of the block |
---|
2155 | * |
---|
2156 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
2157 | */ |
---|
2158 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
2159 | { |
---|
2160 | Pel* pDst = rpDst; |
---|
2161 | Int x, y, iDstStride2, iSrcStride2; |
---|
2162 | |
---|
2163 | // boundary pixels processing |
---|
2164 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
2165 | |
---|
2166 | for ( x = 1; x < iWidth; x++ ) |
---|
2167 | { |
---|
2168 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
2169 | } |
---|
2170 | |
---|
2171 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
2172 | { |
---|
2173 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
2174 | } |
---|
2175 | |
---|
2176 | return; |
---|
2177 | } |
---|
2178 | #if H_3D_IC |
---|
2179 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
2180 | * \param x input value |
---|
2181 | * |
---|
2182 | * This function derives the position of first non-zero binary bit of a value |
---|
2183 | */ |
---|
2184 | Int GetMSB( UInt x ) |
---|
2185 | { |
---|
2186 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
2187 | |
---|
2188 | while( x > 1 ) |
---|
2189 | { |
---|
2190 | bits >>= 1; |
---|
2191 | y = x >> bits; |
---|
2192 | |
---|
2193 | if( y ) |
---|
2194 | { |
---|
2195 | x = y; |
---|
2196 | iMSB += bits; |
---|
2197 | } |
---|
2198 | } |
---|
2199 | |
---|
2200 | iMSB+=y; |
---|
2201 | |
---|
2202 | return iMSB; |
---|
2203 | } |
---|
2204 | |
---|
2205 | |
---|
2206 | /** Function for deriving LM illumination compensation. |
---|
2207 | */ |
---|
2208 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType ) |
---|
2209 | { |
---|
2210 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
2211 | Pel *pRec = NULL, *pRef = NULL; |
---|
2212 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
2213 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
2214 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
2215 | Int iRefOffset, iHor, iVer; |
---|
2216 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
2217 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
2218 | if( eType != TEXT_LUMA ) |
---|
2219 | { |
---|
2220 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
2221 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
2222 | } |
---|
2223 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
2224 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
2225 | |
---|
2226 | Int i, j, iCountShift = 0; |
---|
2227 | |
---|
2228 | // LLS parameters estimation --> |
---|
2229 | |
---|
2230 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2231 | Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12); |
---|
2232 | |
---|
2233 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) ) |
---|
2234 | { |
---|
2235 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
2236 | if( eType == TEXT_LUMA ) |
---|
2237 | { |
---|
2238 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2239 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2240 | } |
---|
2241 | else if( eType == TEXT_CHROMA_U ) |
---|
2242 | { |
---|
2243 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2244 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2245 | } |
---|
2246 | else |
---|
2247 | { |
---|
2248 | assert( eType == TEXT_CHROMA_V ); |
---|
2249 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2250 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2251 | } |
---|
2252 | |
---|
2253 | for( j = 0; j < uiWidth; j+=2 ) |
---|
2254 | { |
---|
2255 | x += pRef[j]; |
---|
2256 | y += pRec[j]; |
---|
2257 | if ( eType == TEXT_LUMA ) |
---|
2258 | { |
---|
2259 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
2260 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
2261 | } |
---|
2262 | } |
---|
2263 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
2264 | } |
---|
2265 | |
---|
2266 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) ) |
---|
2267 | { |
---|
2268 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
2269 | if( eType == TEXT_LUMA ) |
---|
2270 | { |
---|
2271 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2272 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2273 | } |
---|
2274 | else if( eType == TEXT_CHROMA_U ) |
---|
2275 | { |
---|
2276 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2277 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2278 | } |
---|
2279 | else |
---|
2280 | { |
---|
2281 | assert( eType == TEXT_CHROMA_V ); |
---|
2282 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2283 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2284 | } |
---|
2285 | |
---|
2286 | for( i = 0; i < uiHeight; i+=2 ) |
---|
2287 | { |
---|
2288 | x += pRef[0]; |
---|
2289 | y += pRec[0]; |
---|
2290 | if ( eType == TEXT_LUMA ) |
---|
2291 | { |
---|
2292 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
2293 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
2294 | } |
---|
2295 | pRef += iRefStride*2; |
---|
2296 | pRec += iRecStride*2; |
---|
2297 | } |
---|
2298 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
2299 | } |
---|
2300 | |
---|
2301 | if( iCountShift == 0 ) |
---|
2302 | { |
---|
2303 | a = ( 1 << IC_CONST_SHIFT ); |
---|
2304 | b = 0; |
---|
2305 | return; |
---|
2306 | } |
---|
2307 | |
---|
2308 | if ( eType != TEXT_LUMA ) |
---|
2309 | { |
---|
2310 | a = 32; |
---|
2311 | b = ( y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2312 | } |
---|
2313 | else |
---|
2314 | { |
---|
2315 | xy += xx >> IC_REG_COST_SHIFT; |
---|
2316 | xx += xx >> IC_REG_COST_SHIFT; |
---|
2317 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
2318 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
2319 | const Int iShift = IC_CONST_SHIFT; |
---|
2320 | { |
---|
2321 | { |
---|
2322 | const Int iShiftA2 = 6; |
---|
2323 | const Int iAccuracyShift = 15; |
---|
2324 | |
---|
2325 | Int iScaleShiftA2 = 0; |
---|
2326 | Int iScaleShiftA1 = 0; |
---|
2327 | Int a1s = a1; |
---|
2328 | Int a2s = a2; |
---|
2329 | |
---|
2330 | a1 = Clip3(0, 2*a2, a1); |
---|
2331 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2332 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
2333 | |
---|
2334 | if( iScaleShiftA1 < 0 ) |
---|
2335 | { |
---|
2336 | iScaleShiftA1 = 0; |
---|
2337 | } |
---|
2338 | |
---|
2339 | if( iScaleShiftA2 < 0 ) |
---|
2340 | { |
---|
2341 | iScaleShiftA2 = 0; |
---|
2342 | } |
---|
2343 | |
---|
2344 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2345 | |
---|
2346 | |
---|
2347 | a2s = a2 >> iScaleShiftA2; |
---|
2348 | |
---|
2349 | a1s = a1 >> iScaleShiftA1; |
---|
2350 | |
---|
2351 | a = a1s * m_uiaShift[ a2s ]; |
---|
2352 | a = a >> iScaleShiftA; |
---|
2353 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2354 | } |
---|
2355 | } |
---|
2356 | } |
---|
2357 | } |
---|
2358 | #endif |
---|
2359 | |
---|
2360 | #if H_3D_DIM |
---|
2361 | Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
2362 | { |
---|
2363 | Int refDC1, refDC2; |
---|
2364 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
2365 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
2366 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
2367 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
2368 | |
---|
2369 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
2370 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
2371 | |
---|
2372 | if( bL == bT ) |
---|
2373 | { |
---|
2374 | const Int iTRR = ( patternStride * 2 - 1 ) - srcStride; |
---|
2375 | const Int iLBB = ( patternStride * 2 - 1 ) * srcStride - 1; |
---|
2376 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]); |
---|
2377 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
2378 | } |
---|
2379 | else |
---|
2380 | { |
---|
2381 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
2382 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
2383 | } |
---|
2384 | |
---|
2385 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
2386 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
2387 | } |
---|
2388 | |
---|
2389 | Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
2390 | { |
---|
2391 | if( dstStride == patternStride ) |
---|
2392 | { |
---|
2393 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
2394 | { |
---|
2395 | if( true == biSegPattern[k] ) |
---|
2396 | { |
---|
2397 | ptrDst[k] = valDC2; |
---|
2398 | } |
---|
2399 | else |
---|
2400 | { |
---|
2401 | ptrDst[k] = valDC1; |
---|
2402 | } |
---|
2403 | } |
---|
2404 | } |
---|
2405 | else |
---|
2406 | { |
---|
2407 | Pel* piTemp = ptrDst; |
---|
2408 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
2409 | { |
---|
2410 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
2411 | { |
---|
2412 | if( true == biSegPattern[uiX] ) |
---|
2413 | { |
---|
2414 | piTemp[uiX] = valDC2; |
---|
2415 | } |
---|
2416 | else |
---|
2417 | { |
---|
2418 | piTemp[uiX] = valDC1; |
---|
2419 | } |
---|
2420 | } |
---|
2421 | piTemp += dstStride; |
---|
2422 | biSegPattern += patternStride; |
---|
2423 | } |
---|
2424 | } |
---|
2425 | } |
---|
2426 | |
---|
2427 | #if H_3D_DIM_DMM |
---|
2428 | |
---|
2429 | Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
2430 | { |
---|
2431 | pcContourWedge->clear(); |
---|
2432 | |
---|
2433 | // get copy of co-located texture luma block |
---|
2434 | TComYuv cTempYuv; |
---|
2435 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2436 | cTempYuv.clear(); |
---|
2437 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2438 | xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2439 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2440 | |
---|
2441 | // find contour for texture luma block |
---|
2442 | UInt iDC = 0; |
---|
2443 | |
---|
2444 | iDC = piRefBlkY[ 0 ]; |
---|
2445 | iDC += piRefBlkY[ uiWidth - 1 ]; |
---|
2446 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ]; |
---|
2447 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ]; |
---|
2448 | iDC = iDC >> 2; |
---|
2449 | |
---|
2450 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2451 | |
---|
2452 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
2453 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2454 | { |
---|
2455 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2456 | } |
---|
2457 | |
---|
2458 | cTempYuv.destroy(); |
---|
2459 | } |
---|
2460 | |
---|
2461 | |
---|
2462 | Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
2463 | { |
---|
2464 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2465 | assert( pcPicYuvRef != NULL ); |
---|
2466 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
2467 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2468 | |
---|
2469 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
2470 | { |
---|
2471 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
2472 | piDestBlockY += uiWidth; |
---|
2473 | piRefY += iRefStride; |
---|
2474 | } |
---|
2475 | } |
---|
2476 | #endif |
---|
2477 | |
---|
2478 | |
---|
2479 | #if H_3D_DIM_SDC |
---|
2480 | Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride |
---|
2481 | ,UInt uiIntraMode |
---|
2482 | ,Bool orgDC |
---|
2483 | ) |
---|
2484 | { |
---|
2485 | Int iSumDepth[2]; |
---|
2486 | memset(iSumDepth, 0, sizeof(Int)*2); |
---|
2487 | Int iSumPix[2]; |
---|
2488 | memset(iSumPix, 0, sizeof(Int)*2); |
---|
2489 | |
---|
2490 | for( Int i = 0; i < uiNumSegments; i++ ) |
---|
2491 | { |
---|
2492 | rpSegMeans[i] = 0; |
---|
2493 | } |
---|
2494 | |
---|
2495 | if ( !orgDC ) |
---|
2496 | { |
---|
2497 | Pel* pLeftTop = pOrig; |
---|
2498 | Pel* pRightTop = pOrig + (uiSize-1); |
---|
2499 | Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1))); |
---|
2500 | Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1)); |
---|
2501 | |
---|
2502 | rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; |
---|
2503 | return; |
---|
2504 | } |
---|
2505 | |
---|
2506 | Int subSamplePix; |
---|
2507 | if ( uiSize == 64 || uiSize == 32 ) |
---|
2508 | { |
---|
2509 | subSamplePix = 2; |
---|
2510 | } |
---|
2511 | else |
---|
2512 | { |
---|
2513 | subSamplePix = 1; |
---|
2514 | } |
---|
2515 | |
---|
2516 | for (Int y=0; y<uiSize; y+=subSamplePix) |
---|
2517 | { |
---|
2518 | for (Int x=0; x<uiSize; x+=subSamplePix) |
---|
2519 | { |
---|
2520 | UChar ucSegment = pMask?(UChar)pMask[x]:0; |
---|
2521 | assert( ucSegment < uiNumSegments ); |
---|
2522 | |
---|
2523 | iSumDepth[ucSegment] += pOrig[x]; |
---|
2524 | iSumPix[ucSegment] += 1; |
---|
2525 | } |
---|
2526 | |
---|
2527 | pOrig += uiStride*subSamplePix; |
---|
2528 | pMask += uiMaskStride*subSamplePix; |
---|
2529 | } |
---|
2530 | |
---|
2531 | // compute mean for each segment |
---|
2532 | for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ ) |
---|
2533 | { |
---|
2534 | if( iSumPix[ucSeg] > 0 ) |
---|
2535 | { |
---|
2536 | rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg]; |
---|
2537 | } |
---|
2538 | else |
---|
2539 | { |
---|
2540 | rpSegMeans[ucSeg] = 0; // this happens for zero-segments |
---|
2541 | } |
---|
2542 | } |
---|
2543 | } |
---|
2544 | #endif // H_3D_DIM_SDC |
---|
2545 | #endif |
---|
2546 | //! \} |
---|