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