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