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 | #if !HS_DMM_SIGNALLING_I0120 |
---|
426 | Bool dimDeltaDC = isDimDeltaDC( uiIntraMode ); |
---|
427 | #endif |
---|
428 | Bool isDmmMode = (dimType < DMM_NUM_TYPE); |
---|
429 | |
---|
430 | Bool* biSegPattern = NULL; |
---|
431 | UInt patternStride = 0; |
---|
432 | |
---|
433 | // get partiton |
---|
434 | #if H_3D_DIM_DMM |
---|
435 | TComWedgelet* dmmSegmentation = NULL; |
---|
436 | if( isDmmMode ) |
---|
437 | { |
---|
438 | switch( dimType ) |
---|
439 | { |
---|
440 | case( DMM1_IDX ): |
---|
441 | { |
---|
442 | #if SHARP_DMM1_I0110 |
---|
443 | dmmSegmentation = pcCU->isDMM1UpscaleMode((UInt)iWidth) ? |
---|
444 | &(g_dmmWedgeLists[ g_aucConvertToBit[pcCU->getDMM1BasePatternWidth((UInt)iWidth)] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]) : |
---|
445 | &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]); |
---|
446 | #else |
---|
447 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]); |
---|
448 | #endif |
---|
449 | } break; |
---|
450 | case( DMM4_IDX ): |
---|
451 | { |
---|
452 | if( dmm4Segmentation == NULL ) |
---|
453 | { |
---|
454 | dmmSegmentation = new TComWedgelet( iWidth, iHeight ); |
---|
455 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation ); |
---|
456 | } |
---|
457 | else |
---|
458 | { |
---|
459 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmm4Segmentation ); |
---|
460 | dmmSegmentation = dmm4Segmentation; |
---|
461 | } |
---|
462 | } break; |
---|
463 | default: assert(0); |
---|
464 | } |
---|
465 | assert( dmmSegmentation ); |
---|
466 | #if SHARP_DMM1_I0110 |
---|
467 | if( dimType == DMM1_IDX && pcCU->isDMM1UpscaleMode((UInt)iWidth) ) |
---|
468 | { |
---|
469 | biSegPattern = dmmSegmentation->getScaledPattern((UInt)iWidth); |
---|
470 | patternStride = iWidth; |
---|
471 | } |
---|
472 | else |
---|
473 | { |
---|
474 | biSegPattern = dmmSegmentation->getPattern(); |
---|
475 | patternStride = dmmSegmentation->getStride (); |
---|
476 | } |
---|
477 | #else |
---|
478 | biSegPattern = dmmSegmentation->getPattern(); |
---|
479 | patternStride = dmmSegmentation->getStride (); |
---|
480 | #endif |
---|
481 | } |
---|
482 | #endif |
---|
483 | |
---|
484 | // get predicted partition values |
---|
485 | assert( biSegPattern ); |
---|
486 | Int* piMask = NULL; |
---|
487 | piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering |
---|
488 | assert( piMask ); |
---|
489 | Int maskStride = 2*iWidth + 1; |
---|
490 | Int* ptrSrc = piMask+maskStride+1; |
---|
491 | Pel predDC1 = 0; Pel predDC2 = 0; |
---|
492 | xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
493 | |
---|
494 | // set segment values with deltaDC offsets |
---|
495 | Pel segDC1 = 0; |
---|
496 | Pel segDC2 = 0; |
---|
497 | #if HS_DMM_SIGNALLING_I0120 |
---|
498 | if( !pcCU->getSDCFlag( uiAbsPartIdx ) ) |
---|
499 | #else |
---|
500 | if( dimDeltaDC ) |
---|
501 | #endif |
---|
502 | { |
---|
503 | Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx ); |
---|
504 | Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx ); |
---|
505 | #if H_3D_DIM_DMM |
---|
506 | if( isDmmMode ) |
---|
507 | { |
---|
508 | #if H_3D_DIM_DLT |
---|
509 | segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
510 | segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
511 | #else |
---|
512 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
513 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
514 | #endif |
---|
515 | } |
---|
516 | #endif |
---|
517 | } |
---|
518 | else |
---|
519 | { |
---|
520 | segDC1 = predDC1; |
---|
521 | segDC2 = predDC2; |
---|
522 | } |
---|
523 | |
---|
524 | // set prediction signal |
---|
525 | Pel* pDst = piPred; |
---|
526 | xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
527 | pcCU->setDmmPredictor(segDC1, 0); |
---|
528 | pcCU->setDmmPredictor(segDC2, 1); |
---|
529 | |
---|
530 | #if H_3D_DIM_DMM |
---|
531 | if( dimType == DMM4_IDX && dmm4Segmentation == NULL ) { dmmSegmentation->destroy(); delete dmmSegmentation; } |
---|
532 | #endif |
---|
533 | } |
---|
534 | #endif |
---|
535 | |
---|
536 | /** Function for checking identical motion. |
---|
537 | * \param TComDataCU* pcCU |
---|
538 | * \param UInt PartAddr |
---|
539 | */ |
---|
540 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
541 | { |
---|
542 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
543 | { |
---|
544 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
545 | { |
---|
546 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
547 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
548 | #if H_3D_ARP |
---|
549 | if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
550 | #else |
---|
551 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
552 | #endif |
---|
553 | { |
---|
554 | return true; |
---|
555 | } |
---|
556 | } |
---|
557 | } |
---|
558 | return false; |
---|
559 | } |
---|
560 | |
---|
561 | #if H_3D_SPIVMP |
---|
562 | Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr ) |
---|
563 | { |
---|
564 | for (Int i = 0; i < iNumSP; i++) |
---|
565 | { |
---|
566 | uiMergedSPW[i] = iSPWidth; |
---|
567 | uiMergedSPH[i] = iSPHeight; |
---|
568 | pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]); |
---|
569 | } |
---|
570 | // horizontal sub-PU merge |
---|
571 | for (Int i=0; i<iNumSP; i++) |
---|
572 | { |
---|
573 | if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
574 | { |
---|
575 | continue; |
---|
576 | } |
---|
577 | for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++) |
---|
578 | { |
---|
579 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j])) |
---|
580 | { |
---|
581 | uiMergedSPW[i] += iSPWidth; |
---|
582 | uiMergedSPW[j] = uiMergedSPH[j] = 0; |
---|
583 | } |
---|
584 | else |
---|
585 | { |
---|
586 | break; |
---|
587 | } |
---|
588 | } |
---|
589 | } |
---|
590 | //vertical sub-PU merge |
---|
591 | for (Int i=0; i<iNumSP-iNumSPInOneLine; i++) |
---|
592 | { |
---|
593 | if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
594 | { |
---|
595 | continue; |
---|
596 | } |
---|
597 | for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine) |
---|
598 | { |
---|
599 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j]) |
---|
600 | { |
---|
601 | uiMergedSPH[i] += iSPHeight; |
---|
602 | uiMergedSPH[j] = uiMergedSPW[j] = 0; |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | break; |
---|
607 | } |
---|
608 | } |
---|
609 | } |
---|
610 | } |
---|
611 | |
---|
612 | Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 ) |
---|
613 | { |
---|
614 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1)) |
---|
615 | { |
---|
616 | return false; |
---|
617 | } |
---|
618 | if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1)) |
---|
619 | { |
---|
620 | return false; |
---|
621 | } |
---|
622 | |
---|
623 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0) |
---|
624 | { |
---|
625 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1)) |
---|
626 | { |
---|
627 | return false; |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0) |
---|
632 | { |
---|
633 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1)) |
---|
634 | { |
---|
635 | return false; |
---|
636 | } |
---|
637 | } |
---|
638 | return true; |
---|
639 | } |
---|
640 | #endif |
---|
641 | |
---|
642 | #if H_3D_DBBP |
---|
643 | PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize) |
---|
644 | { |
---|
645 | // find virtual partitioning for this CU based on depth block |
---|
646 | // segmentation of texture block --> mask IDs |
---|
647 | Pel* pDepthBlockStart = pDepthPels; |
---|
648 | |
---|
649 | // first compute average of depth block for thresholding |
---|
650 | Int iSumDepth = 0; |
---|
651 | Int iSubSample = 4; |
---|
652 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
653 | { |
---|
654 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
655 | { |
---|
656 | Int depthPel = pDepthPels[x]; |
---|
657 | |
---|
658 | iSumDepth += depthPel; |
---|
659 | } |
---|
660 | |
---|
661 | // next row |
---|
662 | pDepthPels += uiDepthStride*iSubSample; |
---|
663 | } |
---|
664 | |
---|
665 | Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample]; // respect sub-sampling factor |
---|
666 | Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiSize*uiSize); |
---|
667 | |
---|
668 | // start again for segmentation |
---|
669 | pDepthPels = pDepthBlockStart; |
---|
670 | |
---|
671 | // start mapping process |
---|
672 | Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option |
---|
673 | PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN}; |
---|
674 | |
---|
675 | UInt uiHalfSize = uiSize>>1; |
---|
676 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
677 | { |
---|
678 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
679 | { |
---|
680 | Int depthPel = pDepthPels[x]; |
---|
681 | |
---|
682 | // decide which segment this pixel belongs to |
---|
683 | Int ucSegment = (Int)(depthPel>iMean); |
---|
684 | |
---|
685 | // Matched Filter to find optimal (conventional) partitioning |
---|
686 | |
---|
687 | // SIZE_Nx2N |
---|
688 | if(x<uiHalfSize) // left |
---|
689 | { |
---|
690 | matchedPartSum[0][ucSegment]++; |
---|
691 | } |
---|
692 | else // right |
---|
693 | { |
---|
694 | matchedPartSum[0][1-ucSegment]++; |
---|
695 | } |
---|
696 | |
---|
697 | // SIZE_2NxN |
---|
698 | if(y<uiHalfSize) // top |
---|
699 | { |
---|
700 | matchedPartSum[1][ucSegment]++; |
---|
701 | } |
---|
702 | else // bottom |
---|
703 | { |
---|
704 | matchedPartSum[1][1-ucSegment]++; |
---|
705 | } |
---|
706 | } |
---|
707 | |
---|
708 | // next row |
---|
709 | pDepthPels += uiDepthStride*iSubSample; |
---|
710 | } |
---|
711 | |
---|
712 | PartSize matchedPartSize = SIZE_NONE; |
---|
713 | |
---|
714 | Int iMaxMatchSum = 0; |
---|
715 | for(Int p=0; p<2; p++) // loop over partition |
---|
716 | { |
---|
717 | for( Int b=0; b<=1; b++ ) // loop over boolean options |
---|
718 | { |
---|
719 | if(matchedPartSum[p][b] > iMaxMatchSum) |
---|
720 | { |
---|
721 | iMaxMatchSum = matchedPartSum[p][b]; |
---|
722 | matchedPartSize = virtualPartSizes[p]; |
---|
723 | } |
---|
724 | } |
---|
725 | } |
---|
726 | |
---|
727 | AOF( matchedPartSize != SIZE_NONE ); |
---|
728 | |
---|
729 | return matchedPartSize; |
---|
730 | } |
---|
731 | |
---|
732 | Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask ) |
---|
733 | { |
---|
734 | // segmentation of texture block --> mask IDs |
---|
735 | Pel* pDepthBlockStart = pDepthPels; |
---|
736 | |
---|
737 | // first compute average of depth block for thresholding |
---|
738 | Int iSumDepth = 0; |
---|
739 | Int uiMinDepth = MAX_INT; |
---|
740 | Int uiMaxDepth = 0; |
---|
741 | for (Int y=0; y<uiHeight; y++) |
---|
742 | { |
---|
743 | for (Int x=0; x<uiWidth; x++) |
---|
744 | { |
---|
745 | Int depthPel = pDepthPels[x]; |
---|
746 | iSumDepth += depthPel; |
---|
747 | |
---|
748 | if( depthPel > uiMaxDepth ) |
---|
749 | { |
---|
750 | uiMaxDepth = depthPel; |
---|
751 | } |
---|
752 | if( depthPel < uiMinDepth ) |
---|
753 | { |
---|
754 | uiMinDepth = depthPel; |
---|
755 | } |
---|
756 | } |
---|
757 | |
---|
758 | // next row |
---|
759 | pDepthPels += uiDepthStride; |
---|
760 | } |
---|
761 | |
---|
762 | // don't generate mask for blocks with small depth range (encoder decision) |
---|
763 | if( uiMaxDepth - uiMinDepth < 10 ) |
---|
764 | { |
---|
765 | return false; |
---|
766 | } |
---|
767 | |
---|
768 | AOF(uiWidth==uiHeight); |
---|
769 | Int iSizeInBits = g_aucConvertToBit[uiWidth]+2; |
---|
770 | Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiWidth*uiHeight); |
---|
771 | |
---|
772 | // start again for segmentation |
---|
773 | pDepthPels = pDepthBlockStart; |
---|
774 | |
---|
775 | Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0 |
---|
776 | |
---|
777 | // generate mask |
---|
778 | UInt uiSumPix[2] = {0,0}; |
---|
779 | for (Int y=0; y<uiHeight; y++) |
---|
780 | { |
---|
781 | for (Int x=0; x<uiHeight; x++) |
---|
782 | { |
---|
783 | Int depthPel = pDepthPels[x]; |
---|
784 | |
---|
785 | // decide which segment this pixel belongs to |
---|
786 | Int ucSegment = (Int)(depthPel>iMean); |
---|
787 | |
---|
788 | if( bInvertMask ) |
---|
789 | { |
---|
790 | ucSegment = 1-ucSegment; |
---|
791 | } |
---|
792 | |
---|
793 | // count pixels for each segment |
---|
794 | uiSumPix[ucSegment]++; |
---|
795 | |
---|
796 | // set mask value |
---|
797 | pMask[x] = (Bool)ucSegment; |
---|
798 | } |
---|
799 | |
---|
800 | // next row |
---|
801 | pDepthPels += uiDepthStride; |
---|
802 | pMask += MAX_CU_SIZE; |
---|
803 | } |
---|
804 | |
---|
805 | // don't generate valid mask for tiny segments (encoder decision) |
---|
806 | // each segment needs to cover at least 1/8th of block |
---|
807 | UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3; |
---|
808 | if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) ) |
---|
809 | { |
---|
810 | return false; |
---|
811 | } |
---|
812 | |
---|
813 | // all good |
---|
814 | return true; |
---|
815 | } |
---|
816 | |
---|
817 | Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr ) |
---|
818 | { |
---|
819 | Pel* piSrc[2] = {pInYuv[0]->getLumaAddr(uiPartAddr), pInYuv[1]->getLumaAddr(uiPartAddr)}; |
---|
820 | UInt uiSrcStride = pInYuv[0]->getStride(); |
---|
821 | Pel* piDst = pOutYuv->getLumaAddr(uiPartAddr); |
---|
822 | UInt uiDstStride = pOutYuv->getStride(); |
---|
823 | |
---|
824 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
825 | Pel filSrc = 0; |
---|
826 | Pel* tmpTar = 0; |
---|
827 | tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight); |
---|
828 | |
---|
829 | // backup pointer |
---|
830 | Bool* pMaskStart = pMask; |
---|
831 | |
---|
832 | // combine luma first |
---|
833 | for (Int y=0; y<uiHeight; y++) |
---|
834 | { |
---|
835 | for (Int x=0; x<uiWidth; x++) |
---|
836 | { |
---|
837 | UChar ucSegment = (UChar)pMask[x]; |
---|
838 | AOF( ucSegment < 2 ); |
---|
839 | |
---|
840 | // filtering |
---|
841 | tmpTar[y*uiWidth+x] = piSrc[ucSegment][x]; |
---|
842 | } |
---|
843 | |
---|
844 | piSrc[0] += uiSrcStride; |
---|
845 | piSrc[1] += uiSrcStride; |
---|
846 | pMask += uiMaskStride; |
---|
847 | } |
---|
848 | |
---|
849 | for (Int y=0; y<uiHeight; y++) |
---|
850 | { |
---|
851 | for (Int x=0; x<uiWidth; x++) |
---|
852 | { |
---|
853 | Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x]; |
---|
854 | Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1]; |
---|
855 | Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x]; |
---|
856 | Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1]; |
---|
857 | Bool c =pMaskStart[y*uiMaskStride+x]; |
---|
858 | |
---|
859 | Pel left, right, top, bottom; |
---|
860 | left = (x==0) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1]; |
---|
861 | right = (x==uiWidth-1) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1]; |
---|
862 | top = (y==0) ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x]; |
---|
863 | bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x]; |
---|
864 | |
---|
865 | if(!((l&&r&&c) || (!l&&!r&&!c))) |
---|
866 | { |
---|
867 | filSrc = Clip3( Pel( 0 ), Pel( 255 ), Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 )); |
---|
868 | } |
---|
869 | else |
---|
870 | { |
---|
871 | filSrc = tmpTar[y*uiWidth+x]; |
---|
872 | } |
---|
873 | |
---|
874 | if(!((t&&b&&c) || (!t&&!b&&!c))) |
---|
875 | { |
---|
876 | filSrc = Clip3( Pel( 0 ), Pel( 255 ), Pel(( top + (filSrc << 1) + bottom ) >> 2 )); |
---|
877 | } |
---|
878 | piDst[x] = filSrc; |
---|
879 | } |
---|
880 | piDst += uiDstStride; |
---|
881 | } |
---|
882 | if ( tmpTar ) { xFree(tmpTar); tmpTar = NULL; } |
---|
883 | |
---|
884 | // now combine chroma |
---|
885 | Pel* piSrcU[2] = { pInYuv[0]->getCbAddr(uiPartAddr), pInYuv[1]->getCbAddr(uiPartAddr) }; |
---|
886 | Pel* piSrcV[2] = { pInYuv[0]->getCrAddr(uiPartAddr), pInYuv[1]->getCrAddr(uiPartAddr) }; |
---|
887 | UInt uiSrcStrideC = pInYuv[0]->getCStride(); |
---|
888 | Pel* piDstU = pOutYuv->getCbAddr(uiPartAddr); |
---|
889 | Pel* piDstV = pOutYuv->getCrAddr(uiPartAddr); |
---|
890 | UInt uiDstStrideC = pOutYuv->getCStride(); |
---|
891 | UInt uiWidthC = uiWidth >> 1; |
---|
892 | UInt uiHeightC = uiHeight >> 1; |
---|
893 | Pel filSrcU = 0, filSrcV = 0; |
---|
894 | Pel* tmpTarU = 0, *tmpTarV = 0; |
---|
895 | tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
896 | tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
897 | pMask = pMaskStart; |
---|
898 | |
---|
899 | for (Int y=0; y<uiHeightC; y++) |
---|
900 | { |
---|
901 | for (Int x=0; x<uiWidthC; x++) |
---|
902 | { |
---|
903 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
904 | AOF( ucSegment < 2 ); |
---|
905 | |
---|
906 | // filtering |
---|
907 | tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x]; |
---|
908 | tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x]; |
---|
909 | } |
---|
910 | |
---|
911 | piSrcU[0] += uiSrcStrideC; |
---|
912 | piSrcU[1] += uiSrcStrideC; |
---|
913 | piSrcV[0] += uiSrcStrideC; |
---|
914 | piSrcV[1] += uiSrcStrideC; |
---|
915 | pMask += 2*uiMaskStride; |
---|
916 | } |
---|
917 | |
---|
918 | for (Int y=0; y<uiHeightC; y++) |
---|
919 | { |
---|
920 | for (Int x=0; x<uiWidthC; x++) |
---|
921 | { |
---|
922 | Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2]; |
---|
923 | Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2]; |
---|
924 | Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2]; |
---|
925 | Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2]; |
---|
926 | Bool c =pMaskStart[y*2*uiMaskStride+x*2]; |
---|
927 | |
---|
928 | Pel leftU, rightU, topU, bottomU; |
---|
929 | leftU = (x==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1]; |
---|
930 | rightU = (x==uiWidthC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1]; |
---|
931 | topU = (y==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x]; |
---|
932 | bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x]; |
---|
933 | |
---|
934 | Pel leftV, rightV, topV, bottomV; |
---|
935 | leftV = (x==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1]; |
---|
936 | rightV = (x==uiWidthC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1]; |
---|
937 | topV = (y==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x]; |
---|
938 | bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x]; |
---|
939 | |
---|
940 | if(!((l&&r&&c) || (!l&&!r&&!c))) |
---|
941 | { |
---|
942 | filSrcU = Clip3( Pel( 0 ), Pel( 255 ), Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 )); |
---|
943 | filSrcV = Clip3( Pel( 0 ), Pel( 255 ), Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 )); |
---|
944 | } |
---|
945 | else |
---|
946 | { |
---|
947 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
948 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
949 | } |
---|
950 | |
---|
951 | if(!((t&&b&&c) || (!t&&!b&&!c))) |
---|
952 | { |
---|
953 | filSrcU = Clip3( Pel( 0 ), Pel( 255 ), Pel(( topU + (filSrcU << 1) + bottomU ) >> 2 )); |
---|
954 | filSrcV = Clip3( Pel( 0 ), Pel( 255 ), Pel(( topV + (filSrcV << 1) + bottomV ) >> 2 )); |
---|
955 | } |
---|
956 | |
---|
957 | piDstU[x] = filSrcU; |
---|
958 | piDstV[x] = filSrcV; |
---|
959 | } |
---|
960 | piDstU += uiDstStrideC; |
---|
961 | piDstV += uiDstStrideC; |
---|
962 | } |
---|
963 | if ( tmpTarU ) { xFree(tmpTarU); tmpTarU = NULL; } |
---|
964 | if ( tmpTarV ) { xFree(tmpTarV); tmpTarV = NULL; } |
---|
965 | } |
---|
966 | #endif |
---|
967 | |
---|
968 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
969 | { |
---|
970 | Int iWidth; |
---|
971 | Int iHeight; |
---|
972 | UInt uiPartAddr; |
---|
973 | |
---|
974 | if ( iPartIdx >= 0 ) |
---|
975 | { |
---|
976 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
977 | #if H_3D_VSP |
---|
978 | if ( pcCU->getVSPFlag(uiPartAddr) == 0) |
---|
979 | { |
---|
980 | #endif |
---|
981 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
982 | { |
---|
983 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
984 | { |
---|
985 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
986 | } |
---|
987 | else |
---|
988 | { |
---|
989 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
990 | } |
---|
991 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
992 | { |
---|
993 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
994 | } |
---|
995 | } |
---|
996 | else |
---|
997 | { |
---|
998 | #if H_3D_SPIVMP |
---|
999 | if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1000 | { |
---|
1001 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1002 | |
---|
1003 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1004 | |
---|
1005 | UInt uiW[256], uiH[256]; |
---|
1006 | UInt uiSPAddr[256]; |
---|
1007 | |
---|
1008 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1009 | |
---|
1010 | //MC |
---|
1011 | for (Int i = 0; i < iNumSP; i++) |
---|
1012 | { |
---|
1013 | if (uiW[i]==0 || uiH[i]==0) |
---|
1014 | { |
---|
1015 | continue; |
---|
1016 | } |
---|
1017 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1018 | { |
---|
1019 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1020 | } |
---|
1021 | else |
---|
1022 | { |
---|
1023 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1024 | } |
---|
1025 | } |
---|
1026 | } |
---|
1027 | else |
---|
1028 | { |
---|
1029 | #endif |
---|
1030 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1031 | { |
---|
1032 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1033 | } |
---|
1034 | else |
---|
1035 | { |
---|
1036 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1037 | } |
---|
1038 | #if H_3D_SPIVMP |
---|
1039 | } |
---|
1040 | #endif |
---|
1041 | } |
---|
1042 | #if H_3D_VSP |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1047 | { |
---|
1048 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1049 | } |
---|
1050 | else |
---|
1051 | { |
---|
1052 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1053 | } |
---|
1054 | } |
---|
1055 | #endif |
---|
1056 | return; |
---|
1057 | } |
---|
1058 | |
---|
1059 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
1060 | { |
---|
1061 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
1062 | |
---|
1063 | #if H_3D_VSP |
---|
1064 | if ( pcCU->getVSPFlag(uiPartAddr) == 0 ) |
---|
1065 | { |
---|
1066 | #endif |
---|
1067 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
1068 | { |
---|
1069 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1070 | { |
---|
1071 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
1072 | } |
---|
1073 | else |
---|
1074 | { |
---|
1075 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1076 | } |
---|
1077 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
1078 | { |
---|
1079 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
1080 | } |
---|
1081 | } |
---|
1082 | else |
---|
1083 | { |
---|
1084 | #if H_3D_SPIVMP |
---|
1085 | if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
1086 | { |
---|
1087 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
1088 | |
---|
1089 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
1090 | |
---|
1091 | UInt uiW[256], uiH[256]; |
---|
1092 | UInt uiSPAddr[256]; |
---|
1093 | |
---|
1094 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
1095 | //MC |
---|
1096 | for (Int i = 0; i < iNumSP; i++) |
---|
1097 | { |
---|
1098 | if (uiW[i]==0 || uiH[i]==0) |
---|
1099 | { |
---|
1100 | continue; |
---|
1101 | } |
---|
1102 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
1103 | { |
---|
1104 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
1105 | } |
---|
1106 | else |
---|
1107 | { |
---|
1108 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
1109 | } |
---|
1110 | } |
---|
1111 | } |
---|
1112 | else |
---|
1113 | { |
---|
1114 | #endif |
---|
1115 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1116 | { |
---|
1117 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1118 | } |
---|
1119 | else |
---|
1120 | { |
---|
1121 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1122 | } |
---|
1123 | #if H_3D_SPIVMP |
---|
1124 | } |
---|
1125 | #endif |
---|
1126 | } |
---|
1127 | #if H_3D_VSP |
---|
1128 | } |
---|
1129 | else |
---|
1130 | { |
---|
1131 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1132 | { |
---|
1133 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
1134 | } |
---|
1135 | else |
---|
1136 | { |
---|
1137 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
1138 | } |
---|
1139 | } |
---|
1140 | #endif |
---|
1141 | } |
---|
1142 | return; |
---|
1143 | } |
---|
1144 | |
---|
1145 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
1146 | { |
---|
1147 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
1148 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1149 | pcCU->clipMv(cMv); |
---|
1150 | |
---|
1151 | #if H_3D_DDD |
---|
1152 | if( pcCU->getUseDDD( uiPartAddr ) ) |
---|
1153 | { |
---|
1154 | assert( pcCU->getSPIVMPFlag( uiPartAddr ) == 0 ); |
---|
1155 | assert( pcCU->getSlice()->getViewIndex() != 0 ); |
---|
1156 | |
---|
1157 | Int dstStride = rpcYuvPred->getStride(); |
---|
1158 | Int dstStrideC = rpcYuvPred->getCStride(); |
---|
1159 | Pel *dst = rpcYuvPred->getLumaAddr( uiPartAddr ); |
---|
1160 | Pel *dstU = rpcYuvPred->getCbAddr( uiPartAddr ); |
---|
1161 | Pel *dstV = rpcYuvPred->getCrAddr( uiPartAddr ); |
---|
1162 | |
---|
1163 | Int iWidthC = iWidth >> 1; |
---|
1164 | Int iHeightC = iHeight >> 1; |
---|
1165 | Int DefaultC = 1 << ( g_bitDepthY - 1); |
---|
1166 | for ( Int i = 0; i < iHeight; i++) |
---|
1167 | { |
---|
1168 | for ( Int j = 0; j < iWidth ; j++) |
---|
1169 | { |
---|
1170 | dst[j] = pcCU->getDDDepth( uiPartAddr ); |
---|
1171 | } |
---|
1172 | dst += dstStride; |
---|
1173 | } |
---|
1174 | for ( Int i = 0; i < iHeightC; i++) |
---|
1175 | { |
---|
1176 | for ( Int j = 0; j < iWidthC; j++) |
---|
1177 | { |
---|
1178 | dstU[j] = dstV[j] = DefaultC; |
---|
1179 | } |
---|
1180 | dstU += dstStrideC; |
---|
1181 | dstV += dstStrideC; |
---|
1182 | } |
---|
1183 | |
---|
1184 | //return; |
---|
1185 | } else |
---|
1186 | #endif |
---|
1187 | #if H_3D_ARP |
---|
1188 | if(pcCU->getARPW( uiPartAddr ) > 0 && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC()) |
---|
1189 | { |
---|
1190 | xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , rpcYuvPred , bi ); |
---|
1191 | } |
---|
1192 | else |
---|
1193 | { |
---|
1194 | if( pcCU->getARPW( uiPartAddr ) > 0 |
---|
1195 | && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N |
---|
1196 | && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() |
---|
1197 | ) |
---|
1198 | { |
---|
1199 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi ); |
---|
1200 | } |
---|
1201 | else |
---|
1202 | { |
---|
1203 | #endif |
---|
1204 | #if H_3D_IC |
---|
1205 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ); |
---|
1206 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1207 | #if H_3D_ARP |
---|
1208 | , false |
---|
1209 | #endif |
---|
1210 | , bICFlag ); |
---|
1211 | bICFlag = bICFlag && (iWidth > 8); |
---|
1212 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
1213 | #if H_3D_ARP |
---|
1214 | , false |
---|
1215 | #endif |
---|
1216 | , bICFlag ); |
---|
1217 | #else |
---|
1218 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1219 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1220 | #endif |
---|
1221 | #if H_3D_ARP |
---|
1222 | } |
---|
1223 | } |
---|
1224 | #endif |
---|
1225 | } |
---|
1226 | |
---|
1227 | #if H_3D_VSP |
---|
1228 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
1229 | { |
---|
1230 | Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1; |
---|
1231 | |
---|
1232 | Int widthSubPU, heightSubPU; |
---|
1233 | if (vspSize) |
---|
1234 | { |
---|
1235 | widthSubPU = 8; |
---|
1236 | heightSubPU = 4; |
---|
1237 | } |
---|
1238 | else |
---|
1239 | { |
---|
1240 | widthSubPU = 4; |
---|
1241 | heightSubPU = 8; |
---|
1242 | } |
---|
1243 | xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU ); |
---|
1244 | } |
---|
1245 | |
---|
1246 | Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU ) |
---|
1247 | { |
---|
1248 | UInt numPartsInLine = pcCU->getPic()->getNumPartInWidth(); |
---|
1249 | UInt horiNumPartsInSubPU = widthSubPU >> 2; |
---|
1250 | UInt vertNumPartsInSubPU = (heightSubPU >> 2) * numPartsInLine; |
---|
1251 | |
---|
1252 | UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ]; |
---|
1253 | |
---|
1254 | for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU ) |
---|
1255 | { |
---|
1256 | UInt partAddrRasterSubPU = partAddrRasterLine; |
---|
1257 | for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU ) |
---|
1258 | { |
---|
1259 | UInt partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ]; |
---|
1260 | Int refIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU ); assert (refIdx >= 0); |
---|
1261 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU ); |
---|
1262 | pcCU->clipMv(cMv); |
---|
1263 | |
---|
1264 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1265 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi ); |
---|
1266 | |
---|
1267 | } |
---|
1268 | } |
---|
1269 | } |
---|
1270 | |
---|
1271 | #endif |
---|
1272 | |
---|
1273 | #if H_3D_ARP |
---|
1274 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1275 | { |
---|
1276 | Int iRefIdx = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1277 | TComMv cMv = pNewMvFiled ? pNewMvFiled->getMv() : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1278 | Bool bTobeScaled = false; |
---|
1279 | TComPic* pcPicYuvBaseCol = NULL; |
---|
1280 | TComPic* pcPicYuvBaseRef = NULL; |
---|
1281 | |
---|
1282 | #if H_3D_NBDV |
---|
1283 | DisInfo cDistparity; |
---|
1284 | cDistparity.bDV = pcCU->getDvInfo(uiPartAddr).bDV; |
---|
1285 | if( cDistparity.bDV ) |
---|
1286 | { |
---|
1287 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
1288 | assert(pcCU->getDvInfo(uiPartAddr).bDV == pcCU->getDvInfo(0).bDV); |
---|
1289 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
1290 | } |
---|
1291 | #else |
---|
1292 | assert(0); // ARP can be applied only when a DV is available |
---|
1293 | #endif |
---|
1294 | |
---|
1295 | UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0; |
---|
1296 | |
---|
1297 | if( cDistparity.bDV ) |
---|
1298 | { |
---|
1299 | Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList); |
---|
1300 | if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() ) |
---|
1301 | { |
---|
1302 | bTobeScaled = true; |
---|
1303 | } |
---|
1304 | |
---|
1305 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1306 | |
---|
1307 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
1308 | |
---|
1309 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan)) |
---|
1310 | { |
---|
1311 | dW = 0; |
---|
1312 | bTobeScaled = false; |
---|
1313 | } |
---|
1314 | else |
---|
1315 | { |
---|
1316 | assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC() ); |
---|
1317 | } |
---|
1318 | |
---|
1319 | if(bTobeScaled) |
---|
1320 | { |
---|
1321 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
1322 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
1323 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, 0); |
---|
1324 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
1325 | if ( iScale != 4096 ) |
---|
1326 | { |
---|
1327 | cMv = cMv.scaleMv( iScale ); |
---|
1328 | } |
---|
1329 | iRefIdx = 0; |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | pcCU->clipMv(cMv); |
---|
1334 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
1335 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
1336 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
1337 | |
---|
1338 | if( dW > 0 ) |
---|
1339 | { |
---|
1340 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
1341 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
1342 | |
---|
1343 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
1344 | pcCU->clipMv(cMVwithDisparity); |
---|
1345 | |
---|
1346 | assert ( cDistparity.bDV ); |
---|
1347 | |
---|
1348 | #if NTT_BUG_FIX_TK54 |
---|
1349 | TComMv cNBDV = cDistparity.m_acNBDV; |
---|
1350 | pcCU->clipMv( cNBDV ); |
---|
1351 | |
---|
1352 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1353 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
1354 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
1355 | #else |
---|
1356 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1357 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
1358 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
1359 | #endif |
---|
1360 | |
---|
1361 | pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec(); |
---|
1362 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
1363 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
1364 | |
---|
1365 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
1366 | |
---|
1367 | if( 2 == dW ) |
---|
1368 | { |
---|
1369 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1370 | } |
---|
1371 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1372 | } |
---|
1373 | } |
---|
1374 | Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
1375 | { |
---|
1376 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1377 | TComMv cDMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1378 | TComMv cTempDMv = cDMv; |
---|
1379 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
1380 | |
---|
1381 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
1382 | TComPic* pcPicYuvCurrTRef = NULL; |
---|
1383 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
1384 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
1385 | Bool bTMVAvai = false; |
---|
1386 | TComMv cBaseTMV; |
---|
1387 | if( pNewMvFiled ) |
---|
1388 | { |
---|
1389 | iRefIdx = pNewMvFiled->getRefIdx(); |
---|
1390 | cDMv = pNewMvFiled->getMv(); |
---|
1391 | } |
---|
1392 | pcCU->clipMv(cTempDMv); |
---|
1393 | |
---|
1394 | assert(dW > 0); |
---|
1395 | if (!pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, pcPicYuvBaseCol->getViewIndex())) |
---|
1396 | { |
---|
1397 | dW = 0; |
---|
1398 | } |
---|
1399 | Int uiLCUAddr,uiAbsPartAddr; |
---|
1400 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
1401 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
1402 | |
---|
1403 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
1404 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
1405 | pcYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
1406 | TComDataCU *pColCU = pcPicYuvBaseCol->getCU( uiLCUAddr ); |
---|
1407 | |
---|
1408 | if(!pColCU->isIntra(uiAbsPartAddr)) |
---|
1409 | { |
---|
1410 | TComMvField puMVField; |
---|
1411 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++) |
---|
1412 | { |
---|
1413 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
1414 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
1415 | if( iRef != -1) |
---|
1416 | { |
---|
1417 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
1418 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
1419 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
1420 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
1421 | if( iCurrRef >= 0) |
---|
1422 | { |
---|
1423 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
1424 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
1425 | { |
---|
1426 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
1427 | if(pcPicYuvBaseTRef) |
---|
1428 | { |
---|
1429 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
1430 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
1431 | if ( iScale != 4096 ) |
---|
1432 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
1433 | bTMVAvai = true; |
---|
1434 | break; |
---|
1435 | } |
---|
1436 | } |
---|
1437 | } |
---|
1438 | } |
---|
1439 | } |
---|
1440 | } |
---|
1441 | if (bTMVAvai == false) |
---|
1442 | { |
---|
1443 | bTMVAvai = true; |
---|
1444 | cBaseTMV.set(0, 0); |
---|
1445 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1446 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic (eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
1447 | } |
---|
1448 | |
---|
1449 | xPredInterLumaBlk ( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi, bTMVAvai); |
---|
1450 | xPredInterChromaBlk( pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi, bTMVAvai); |
---|
1451 | |
---|
1452 | if( dW > 0 && bTMVAvai ) |
---|
1453 | { |
---|
1454 | TComYuv* pYuvCurrTRef = &m_acYuvPredBase[0]; |
---|
1455 | TComYuv* pYuvBaseTRef = &m_acYuvPredBase[1]; |
---|
1456 | TComPicYuv* pcYuvCurrTref = pcPicYuvCurrTRef->getPicYuvRec(); |
---|
1457 | TComPicYuv* pcYuvBaseTref = pcPicYuvBaseTRef->getPicYuvRec(); |
---|
1458 | TComMv cTempMv = cDMv + cBaseTMV; |
---|
1459 | |
---|
1460 | pcCU->clipMv(cBaseTMV); |
---|
1461 | pcCU->clipMv(cTempMv); |
---|
1462 | |
---|
1463 | xPredInterLumaBlk ( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi, true); |
---|
1464 | xPredInterChromaBlk( pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, bi, true); |
---|
1465 | xPredInterLumaBlk ( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, bi, true); |
---|
1466 | xPredInterChromaBlk( pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, bi, true); |
---|
1467 | |
---|
1468 | pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); |
---|
1469 | if(dW == 2) |
---|
1470 | { |
---|
1471 | pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
1472 | } |
---|
1473 | rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi ); |
---|
1474 | } |
---|
1475 | } |
---|
1476 | |
---|
1477 | #endif |
---|
1478 | |
---|
1479 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
1480 | { |
---|
1481 | TComYuv* pcMbYuv; |
---|
1482 | Int iRefIdx[2] = {-1, -1}; |
---|
1483 | |
---|
1484 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1485 | { |
---|
1486 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
1487 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1488 | |
---|
1489 | if ( iRefIdx[iRefList] < 0 ) |
---|
1490 | { |
---|
1491 | continue; |
---|
1492 | } |
---|
1493 | |
---|
1494 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1495 | |
---|
1496 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1497 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
1498 | { |
---|
1499 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1500 | } |
---|
1501 | else |
---|
1502 | { |
---|
1503 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
1504 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
1505 | { |
---|
1506 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
1507 | } |
---|
1508 | else |
---|
1509 | { |
---|
1510 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
1511 | } |
---|
1512 | } |
---|
1513 | } |
---|
1514 | |
---|
1515 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
1516 | { |
---|
1517 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1518 | } |
---|
1519 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
1520 | { |
---|
1521 | xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); |
---|
1522 | } |
---|
1523 | else |
---|
1524 | { |
---|
1525 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1526 | } |
---|
1527 | } |
---|
1528 | |
---|
1529 | #if H_3D_VSP |
---|
1530 | |
---|
1531 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
1532 | { |
---|
1533 | TComYuv* pcMbYuv; |
---|
1534 | Int iRefIdx[2] = {-1, -1}; |
---|
1535 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
1536 | |
---|
1537 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1538 | { |
---|
1539 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
1540 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1541 | |
---|
1542 | if ( iRefIdx[iRefList] < 0 ) |
---|
1543 | { |
---|
1544 | continue; |
---|
1545 | } |
---|
1546 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1547 | |
---|
1548 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1549 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
1550 | } |
---|
1551 | |
---|
1552 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1553 | } |
---|
1554 | |
---|
1555 | #endif |
---|
1556 | |
---|
1557 | /** |
---|
1558 | * \brief Generate motion-compensated luma block |
---|
1559 | * |
---|
1560 | * \param cu Pointer to current CU |
---|
1561 | * \param refPic Pointer to reference picture |
---|
1562 | * \param partAddr Address of block within CU |
---|
1563 | * \param mv Motion vector |
---|
1564 | * \param width Width of block |
---|
1565 | * \param height Height of block |
---|
1566 | * \param dstPic Pointer to destination picture |
---|
1567 | * \param bi Flag indicating whether bipred is used |
---|
1568 | */ |
---|
1569 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1570 | #if H_3D_ARP |
---|
1571 | , Bool filterType |
---|
1572 | #endif |
---|
1573 | #if H_3D_IC |
---|
1574 | , Bool bICFlag |
---|
1575 | #endif |
---|
1576 | ) |
---|
1577 | { |
---|
1578 | Int refStride = refPic->getStride(); |
---|
1579 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
1580 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1581 | |
---|
1582 | Int dstStride = dstPic->getStride(); |
---|
1583 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
1584 | |
---|
1585 | Int xFrac = mv->getHor() & 0x3; |
---|
1586 | Int yFrac = mv->getVer() & 0x3; |
---|
1587 | |
---|
1588 | #if H_3D_IC |
---|
1589 | if( cu->getSlice()->getIsDepth() ) |
---|
1590 | { |
---|
1591 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
1592 | ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1593 | xFrac = 0; |
---|
1594 | yFrac = 0; |
---|
1595 | } |
---|
1596 | #endif |
---|
1597 | if ( yFrac == 0 ) |
---|
1598 | { |
---|
1599 | #if H_3D_IC |
---|
1600 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi || bICFlag |
---|
1601 | #else |
---|
1602 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi |
---|
1603 | #endif |
---|
1604 | #if H_3D_ARP |
---|
1605 | , filterType |
---|
1606 | #endif |
---|
1607 | ); |
---|
1608 | } |
---|
1609 | else if ( xFrac == 0 ) |
---|
1610 | { |
---|
1611 | #if H_3D_IC |
---|
1612 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag |
---|
1613 | #else |
---|
1614 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi |
---|
1615 | #endif |
---|
1616 | #if H_3D_ARP |
---|
1617 | , filterType |
---|
1618 | #endif |
---|
1619 | ); |
---|
1620 | } |
---|
1621 | else |
---|
1622 | { |
---|
1623 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
1624 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1625 | |
---|
1626 | Int filterSize = NTAPS_LUMA; |
---|
1627 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
1628 | |
---|
1629 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false |
---|
1630 | #if H_3D_ARP |
---|
1631 | , filterType |
---|
1632 | #endif |
---|
1633 | ); |
---|
1634 | #if H_3D_IC |
---|
1635 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi || bICFlag |
---|
1636 | #else |
---|
1637 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi |
---|
1638 | #endif |
---|
1639 | #if H_3D_ARP |
---|
1640 | , filterType |
---|
1641 | #endif |
---|
1642 | ); |
---|
1643 | } |
---|
1644 | |
---|
1645 | #if H_3D_IC |
---|
1646 | if( bICFlag ) |
---|
1647 | { |
---|
1648 | Int a, b, i, j; |
---|
1649 | const Int iShift = IC_CONST_SHIFT; |
---|
1650 | |
---|
1651 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA ); |
---|
1652 | |
---|
1653 | |
---|
1654 | for ( i = 0; i < height; i++ ) |
---|
1655 | { |
---|
1656 | for ( j = 0; j < width; j++ ) |
---|
1657 | { |
---|
1658 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
1659 | } |
---|
1660 | dst += dstStride; |
---|
1661 | } |
---|
1662 | |
---|
1663 | if(bi) |
---|
1664 | { |
---|
1665 | Pel *dst2 = dstPic->getLumaAddr( partAddr ); |
---|
1666 | Int shift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
1667 | for (i = 0; i < height; i++) |
---|
1668 | { |
---|
1669 | for (j = 0; j < width; j++) |
---|
1670 | { |
---|
1671 | Short val = dst2[j] << shift; |
---|
1672 | dst2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
1673 | } |
---|
1674 | dst2 += dstStride; |
---|
1675 | } |
---|
1676 | } |
---|
1677 | } |
---|
1678 | #endif |
---|
1679 | } |
---|
1680 | |
---|
1681 | /** |
---|
1682 | * \brief Generate motion-compensated chroma block |
---|
1683 | * |
---|
1684 | * \param cu Pointer to current CU |
---|
1685 | * \param refPic Pointer to reference picture |
---|
1686 | * \param partAddr Address of block within CU |
---|
1687 | * \param mv Motion vector |
---|
1688 | * \param width Width of block |
---|
1689 | * \param height Height of block |
---|
1690 | * \param dstPic Pointer to destination picture |
---|
1691 | * \param bi Flag indicating whether bipred is used |
---|
1692 | */ |
---|
1693 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1694 | #if H_3D_ARP |
---|
1695 | , Bool filterType |
---|
1696 | #endif |
---|
1697 | #if H_3D_IC |
---|
1698 | , Bool bICFlag |
---|
1699 | #endif |
---|
1700 | ) |
---|
1701 | { |
---|
1702 | Int refStride = refPic->getCStride(); |
---|
1703 | Int dstStride = dstPic->getCStride(); |
---|
1704 | |
---|
1705 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
1706 | |
---|
1707 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1708 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1709 | |
---|
1710 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
1711 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
1712 | |
---|
1713 | Int xFrac = mv->getHor() & 0x7; |
---|
1714 | Int yFrac = mv->getVer() & 0x7; |
---|
1715 | UInt cxWidth = width >> 1; |
---|
1716 | UInt cxHeight = height >> 1; |
---|
1717 | |
---|
1718 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
1719 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1720 | |
---|
1721 | Int filterSize = NTAPS_CHROMA; |
---|
1722 | |
---|
1723 | Int halfFilterSize = (filterSize>>1); |
---|
1724 | |
---|
1725 | if ( yFrac == 0 ) |
---|
1726 | { |
---|
1727 | #if H_3D_IC |
---|
1728 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1729 | #else |
---|
1730 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1731 | #endif |
---|
1732 | #if H_3D_ARP |
---|
1733 | , filterType |
---|
1734 | #endif |
---|
1735 | ); |
---|
1736 | #if H_3D_IC |
---|
1737 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
1738 | #else |
---|
1739 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1740 | #endif |
---|
1741 | #if H_3D_ARP |
---|
1742 | , filterType |
---|
1743 | #endif |
---|
1744 | ); |
---|
1745 | } |
---|
1746 | else if ( xFrac == 0 ) |
---|
1747 | { |
---|
1748 | #if H_3D_IC |
---|
1749 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1750 | #else |
---|
1751 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1752 | #endif |
---|
1753 | #if H_3D_ARP |
---|
1754 | , filterType |
---|
1755 | #endif |
---|
1756 | ); |
---|
1757 | #if H_3D_IC |
---|
1758 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
1759 | #else |
---|
1760 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1761 | #endif |
---|
1762 | #if H_3D_ARP |
---|
1763 | , filterType |
---|
1764 | #endif |
---|
1765 | ); |
---|
1766 | } |
---|
1767 | else |
---|
1768 | { |
---|
1769 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1770 | #if H_3D_ARP |
---|
1771 | , filterType |
---|
1772 | #endif |
---|
1773 | ); |
---|
1774 | #if H_3D_IC |
---|
1775 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
1776 | #else |
---|
1777 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1778 | #endif |
---|
1779 | #if H_3D_ARP |
---|
1780 | , filterType |
---|
1781 | #endif |
---|
1782 | ); |
---|
1783 | |
---|
1784 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1785 | #if H_3D_ARP |
---|
1786 | , filterType |
---|
1787 | #endif |
---|
1788 | ); |
---|
1789 | #if H_3D_IC |
---|
1790 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
1791 | #else |
---|
1792 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1793 | #endif |
---|
1794 | #if H_3D_ARP |
---|
1795 | , filterType |
---|
1796 | #endif |
---|
1797 | ); |
---|
1798 | } |
---|
1799 | |
---|
1800 | #if H_3D_IC |
---|
1801 | if( bICFlag ) |
---|
1802 | { |
---|
1803 | Int a, b, i, j; |
---|
1804 | const Int iShift = IC_CONST_SHIFT; |
---|
1805 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb |
---|
1806 | for ( i = 0; i < cxHeight; i++ ) |
---|
1807 | { |
---|
1808 | for ( j = 0; j < cxWidth; j++ ) |
---|
1809 | { |
---|
1810 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
1811 | } |
---|
1812 | dstCb += dstStride; |
---|
1813 | } |
---|
1814 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr |
---|
1815 | for ( i = 0; i < cxHeight; i++ ) |
---|
1816 | { |
---|
1817 | for ( j = 0; j < cxWidth; j++ ) |
---|
1818 | { |
---|
1819 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
1820 | } |
---|
1821 | dstCr += dstStride; |
---|
1822 | } |
---|
1823 | |
---|
1824 | if(bi) |
---|
1825 | { |
---|
1826 | Pel* dstCb2 = dstPic->getCbAddr( partAddr ); |
---|
1827 | Pel* dstCr2 = dstPic->getCrAddr( partAddr ); |
---|
1828 | Int shift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
1829 | for (i = 0; i < cxHeight; i++) |
---|
1830 | { |
---|
1831 | for (j = 0; j < cxWidth; j++) |
---|
1832 | { |
---|
1833 | Short val = dstCb2[j] << shift; |
---|
1834 | dstCb2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
1835 | |
---|
1836 | val = dstCr2[j] << shift; |
---|
1837 | dstCr2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
1838 | } |
---|
1839 | dstCb2 += dstStride; |
---|
1840 | dstCr2 += dstStride; |
---|
1841 | } |
---|
1842 | } |
---|
1843 | } |
---|
1844 | #endif |
---|
1845 | } |
---|
1846 | |
---|
1847 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
1848 | { |
---|
1849 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
1850 | { |
---|
1851 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
1852 | } |
---|
1853 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
1854 | { |
---|
1855 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1856 | } |
---|
1857 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
1858 | { |
---|
1859 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1860 | } |
---|
1861 | } |
---|
1862 | |
---|
1863 | // AMVP |
---|
1864 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
1865 | { |
---|
1866 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
1867 | if( pcAMVPInfo->iN <= 1 ) |
---|
1868 | { |
---|
1869 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
1870 | |
---|
1871 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1872 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1873 | return; |
---|
1874 | } |
---|
1875 | |
---|
1876 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
1877 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
1878 | return; |
---|
1879 | } |
---|
1880 | |
---|
1881 | /** Function for deriving planar intra prediction. |
---|
1882 | * \param pSrc pointer to reconstructed sample array |
---|
1883 | * \param srcStride the stride of the reconstructed sample array |
---|
1884 | * \param rpDst reference to pointer for the prediction sample array |
---|
1885 | * \param dstStride the stride of the prediction sample array |
---|
1886 | * \param width the width of the block |
---|
1887 | * \param height the height of the block |
---|
1888 | * |
---|
1889 | * This function derives the prediction samples for planar mode (intra coding). |
---|
1890 | */ |
---|
1891 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
1892 | { |
---|
1893 | assert(width == height); |
---|
1894 | |
---|
1895 | Int k, l, bottomLeft, topRight; |
---|
1896 | Int horPred; |
---|
1897 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
1898 | UInt blkSize = width; |
---|
1899 | UInt offset2D = width; |
---|
1900 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
1901 | UInt shift2D = shift1D + 1; |
---|
1902 | |
---|
1903 | // Get left and above reference column and row |
---|
1904 | for(k=0;k<blkSize+1;k++) |
---|
1905 | { |
---|
1906 | topRow[k] = pSrc[k-srcStride]; |
---|
1907 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
1908 | } |
---|
1909 | |
---|
1910 | // Prepare intermediate variables used in interpolation |
---|
1911 | bottomLeft = leftColumn[blkSize]; |
---|
1912 | topRight = topRow[blkSize]; |
---|
1913 | for (k=0;k<blkSize;k++) |
---|
1914 | { |
---|
1915 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
1916 | rightColumn[k] = topRight - leftColumn[k]; |
---|
1917 | topRow[k] <<= shift1D; |
---|
1918 | leftColumn[k] <<= shift1D; |
---|
1919 | } |
---|
1920 | |
---|
1921 | // Generate prediction signal |
---|
1922 | for (k=0;k<blkSize;k++) |
---|
1923 | { |
---|
1924 | horPred = leftColumn[k] + offset2D; |
---|
1925 | for (l=0;l<blkSize;l++) |
---|
1926 | { |
---|
1927 | horPred += rightColumn[k]; |
---|
1928 | topRow[l] += bottomRow[l]; |
---|
1929 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
1930 | } |
---|
1931 | } |
---|
1932 | } |
---|
1933 | |
---|
1934 | /** Function for filtering intra DC predictor. |
---|
1935 | * \param pSrc pointer to reconstructed sample array |
---|
1936 | * \param iSrcStride the stride of the reconstructed sample array |
---|
1937 | * \param rpDst reference to pointer for the prediction sample array |
---|
1938 | * \param iDstStride the stride of the prediction sample array |
---|
1939 | * \param iWidth the width of the block |
---|
1940 | * \param iHeight the height of the block |
---|
1941 | * |
---|
1942 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
1943 | */ |
---|
1944 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
1945 | { |
---|
1946 | Pel* pDst = rpDst; |
---|
1947 | Int x, y, iDstStride2, iSrcStride2; |
---|
1948 | |
---|
1949 | // boundary pixels processing |
---|
1950 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
1951 | |
---|
1952 | for ( x = 1; x < iWidth; x++ ) |
---|
1953 | { |
---|
1954 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
1955 | } |
---|
1956 | |
---|
1957 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
1958 | { |
---|
1959 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
1960 | } |
---|
1961 | |
---|
1962 | return; |
---|
1963 | } |
---|
1964 | #if H_3D_IC |
---|
1965 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
1966 | * \param x input value |
---|
1967 | * |
---|
1968 | * This function derives the position of first non-zero binary bit of a value |
---|
1969 | */ |
---|
1970 | Int GetMSB( UInt x ) |
---|
1971 | { |
---|
1972 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
1973 | |
---|
1974 | while( x > 1 ) |
---|
1975 | { |
---|
1976 | bits >>= 1; |
---|
1977 | y = x >> bits; |
---|
1978 | |
---|
1979 | if( y ) |
---|
1980 | { |
---|
1981 | x = y; |
---|
1982 | iMSB += bits; |
---|
1983 | } |
---|
1984 | } |
---|
1985 | |
---|
1986 | iMSB+=y; |
---|
1987 | |
---|
1988 | return iMSB; |
---|
1989 | } |
---|
1990 | |
---|
1991 | |
---|
1992 | /** Function for deriving LM illumination compensation. |
---|
1993 | */ |
---|
1994 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType ) |
---|
1995 | { |
---|
1996 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
1997 | Pel *pRec = NULL, *pRef = NULL; |
---|
1998 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
1999 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
2000 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
2001 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer; |
---|
2002 | |
---|
2003 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2004 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2005 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
2006 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
2007 | iRefX = iCUPelX + iHor; |
---|
2008 | iRefY = iCUPelY + iVer; |
---|
2009 | if( eType != TEXT_LUMA ) |
---|
2010 | { |
---|
2011 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
2012 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
2013 | } |
---|
2014 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
2015 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
2016 | |
---|
2017 | Int i, j, iCountShift = 0; |
---|
2018 | |
---|
2019 | // LLS parameters estimation --> |
---|
2020 | |
---|
2021 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2022 | Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12); |
---|
2023 | |
---|
2024 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 ) |
---|
2025 | { |
---|
2026 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
2027 | if( eType == TEXT_LUMA ) |
---|
2028 | { |
---|
2029 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2030 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2031 | } |
---|
2032 | else if( eType == TEXT_CHROMA_U ) |
---|
2033 | { |
---|
2034 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2035 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2036 | } |
---|
2037 | else |
---|
2038 | { |
---|
2039 | assert( eType == TEXT_CHROMA_V ); |
---|
2040 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2041 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2042 | } |
---|
2043 | |
---|
2044 | for( j = 0; j < uiWidth; j+=2 ) |
---|
2045 | { |
---|
2046 | x += pRef[j]; |
---|
2047 | y += pRec[j]; |
---|
2048 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
2049 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
2050 | } |
---|
2051 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
2052 | } |
---|
2053 | |
---|
2054 | |
---|
2055 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 ) |
---|
2056 | { |
---|
2057 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
2058 | if( eType == TEXT_LUMA ) |
---|
2059 | { |
---|
2060 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2061 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2062 | } |
---|
2063 | else if( eType == TEXT_CHROMA_U ) |
---|
2064 | { |
---|
2065 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2066 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2067 | } |
---|
2068 | else |
---|
2069 | { |
---|
2070 | assert( eType == TEXT_CHROMA_V ); |
---|
2071 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2072 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2073 | } |
---|
2074 | |
---|
2075 | for( i = 0; i < uiHeight; i+=2 ) |
---|
2076 | { |
---|
2077 | x += pRef[0]; |
---|
2078 | y += pRec[0]; |
---|
2079 | |
---|
2080 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
2081 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
2082 | |
---|
2083 | pRef += iRefStride*2; |
---|
2084 | pRec += iRecStride*2; |
---|
2085 | } |
---|
2086 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
2087 | } |
---|
2088 | |
---|
2089 | xy += xx >> IC_REG_COST_SHIFT; |
---|
2090 | xx += xx >> IC_REG_COST_SHIFT; |
---|
2091 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
2092 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
2093 | const Int iShift = IC_CONST_SHIFT; |
---|
2094 | { |
---|
2095 | { |
---|
2096 | const Int iShiftA2 = 6; |
---|
2097 | const Int iAccuracyShift = 15; |
---|
2098 | |
---|
2099 | Int iScaleShiftA2 = 0; |
---|
2100 | Int iScaleShiftA1 = 0; |
---|
2101 | Int a1s = a1; |
---|
2102 | Int a2s = a2; |
---|
2103 | |
---|
2104 | a1 = Clip3(0, 2*a2, a1); |
---|
2105 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2106 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
2107 | |
---|
2108 | if( iScaleShiftA1 < 0 ) |
---|
2109 | { |
---|
2110 | iScaleShiftA1 = 0; |
---|
2111 | } |
---|
2112 | |
---|
2113 | if( iScaleShiftA2 < 0 ) |
---|
2114 | { |
---|
2115 | iScaleShiftA2 = 0; |
---|
2116 | } |
---|
2117 | |
---|
2118 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2119 | |
---|
2120 | |
---|
2121 | a2s = a2 >> iScaleShiftA2; |
---|
2122 | |
---|
2123 | a1s = a1 >> iScaleShiftA1; |
---|
2124 | |
---|
2125 | a = a1s * m_uiaShift[ a2s ]; |
---|
2126 | a = a >> iScaleShiftA; |
---|
2127 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2128 | } |
---|
2129 | } |
---|
2130 | } |
---|
2131 | #endif |
---|
2132 | |
---|
2133 | #if H_3D_DIM |
---|
2134 | Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
2135 | { |
---|
2136 | Int refDC1, refDC2; |
---|
2137 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
2138 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
2139 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
2140 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
2141 | |
---|
2142 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
2143 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
2144 | |
---|
2145 | if( bL == bT ) |
---|
2146 | { |
---|
2147 | const Int iTRR = ( patternStride * 2 - 1 ) - srcStride; |
---|
2148 | const Int iLBB = ( patternStride * 2 - 1 ) * srcStride - 1; |
---|
2149 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]); |
---|
2150 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
2151 | } |
---|
2152 | else |
---|
2153 | { |
---|
2154 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
2155 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
2156 | } |
---|
2157 | |
---|
2158 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
2159 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
2160 | } |
---|
2161 | |
---|
2162 | Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
2163 | { |
---|
2164 | if( dstStride == patternStride ) |
---|
2165 | { |
---|
2166 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
2167 | { |
---|
2168 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
2169 | else { ptrDst[k] = valDC1; } |
---|
2170 | } |
---|
2171 | } |
---|
2172 | else |
---|
2173 | { |
---|
2174 | Pel* piTemp = ptrDst; |
---|
2175 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
2176 | { |
---|
2177 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
2178 | { |
---|
2179 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
2180 | else { piTemp[uiX] = valDC1; } |
---|
2181 | } |
---|
2182 | piTemp += dstStride; |
---|
2183 | biSegPattern += patternStride; |
---|
2184 | } |
---|
2185 | } |
---|
2186 | } |
---|
2187 | |
---|
2188 | #if H_3D_DIM_DMM |
---|
2189 | |
---|
2190 | Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
2191 | { |
---|
2192 | pcContourWedge->clear(); |
---|
2193 | |
---|
2194 | // get copy of co-located texture luma block |
---|
2195 | TComYuv cTempYuv; |
---|
2196 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2197 | cTempYuv.clear(); |
---|
2198 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2199 | xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2200 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2201 | |
---|
2202 | // find contour for texture luma block |
---|
2203 | UInt iDC = 0; |
---|
2204 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2205 | { |
---|
2206 | iDC += piRefBlkY[k]; |
---|
2207 | } |
---|
2208 | |
---|
2209 | Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2; // |
---|
2210 | iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2; // iDC /= (uiWidth*uiHeight); |
---|
2211 | |
---|
2212 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2213 | |
---|
2214 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
2215 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2216 | { |
---|
2217 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2218 | } |
---|
2219 | |
---|
2220 | cTempYuv.destroy(); |
---|
2221 | } |
---|
2222 | |
---|
2223 | |
---|
2224 | Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
2225 | { |
---|
2226 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2227 | assert( pcPicYuvRef != NULL ); |
---|
2228 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
2229 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2230 | |
---|
2231 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
2232 | { |
---|
2233 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
2234 | piDestBlockY += uiWidth; |
---|
2235 | piRefY += iRefStride; |
---|
2236 | } |
---|
2237 | } |
---|
2238 | #endif |
---|
2239 | |
---|
2240 | |
---|
2241 | #if H_3D_DIM_SDC |
---|
2242 | Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride |
---|
2243 | ,UInt uiIntraMode |
---|
2244 | ,Bool orgDC |
---|
2245 | ) |
---|
2246 | { |
---|
2247 | Int iSumDepth[2]; |
---|
2248 | memset(iSumDepth, 0, sizeof(Int)*2); |
---|
2249 | Int iSumPix[2]; |
---|
2250 | memset(iSumPix, 0, sizeof(Int)*2); |
---|
2251 | for( Int i = 0; i < uiNumSegments; i++ ) |
---|
2252 | { |
---|
2253 | rpSegMeans[i] = 0; |
---|
2254 | } |
---|
2255 | if (orgDC == false) |
---|
2256 | { |
---|
2257 | Pel* pLeftTop = pOrig; |
---|
2258 | Pel* pRightTop = pOrig + (uiSize-1); |
---|
2259 | Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1))); |
---|
2260 | Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1)); |
---|
2261 | |
---|
2262 | rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; |
---|
2263 | return; |
---|
2264 | } |
---|
2265 | |
---|
2266 | Int subSamplePix; |
---|
2267 | if ( uiSize == 64 || uiSize == 32 ) |
---|
2268 | { |
---|
2269 | subSamplePix = 2; |
---|
2270 | } |
---|
2271 | else |
---|
2272 | { |
---|
2273 | subSamplePix = 1; |
---|
2274 | } |
---|
2275 | for (Int y=0; y<uiSize; y+=subSamplePix) |
---|
2276 | { |
---|
2277 | for (Int x=0; x<uiSize; x+=subSamplePix) |
---|
2278 | { |
---|
2279 | UChar ucSegment = pMask?(UChar)pMask[x]:0; |
---|
2280 | assert( ucSegment < uiNumSegments ); |
---|
2281 | |
---|
2282 | iSumDepth[ucSegment] += pOrig[x]; |
---|
2283 | iSumPix[ucSegment] += 1; |
---|
2284 | } |
---|
2285 | |
---|
2286 | pOrig += uiStride*subSamplePix; |
---|
2287 | pMask += uiMaskStride*subSamplePix; |
---|
2288 | } |
---|
2289 | |
---|
2290 | // compute mean for each segment |
---|
2291 | for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ ) |
---|
2292 | { |
---|
2293 | if( iSumPix[ucSeg] > 0 ) |
---|
2294 | rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg]; |
---|
2295 | else |
---|
2296 | rpSegMeans[ucSeg] = 0; // this happens for zero-segments |
---|
2297 | } |
---|
2298 | } |
---|
2299 | #endif // H_3D_DIM_SDC |
---|
2300 | #endif |
---|
2301 | //! \} |
---|