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