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