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 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi |
---|
956 | #if H_3D_ARP |
---|
957 | , filterType |
---|
958 | #endif |
---|
959 | ); |
---|
960 | } |
---|
961 | else if ( xFrac == 0 ) |
---|
962 | { |
---|
963 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi |
---|
964 | #if H_3D_ARP |
---|
965 | , filterType |
---|
966 | #endif |
---|
967 | ); |
---|
968 | } |
---|
969 | else |
---|
970 | { |
---|
971 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
972 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
973 | |
---|
974 | Int filterSize = NTAPS_LUMA; |
---|
975 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
976 | |
---|
977 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false |
---|
978 | #if H_3D_ARP |
---|
979 | , filterType |
---|
980 | #endif |
---|
981 | ); |
---|
982 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi |
---|
983 | #if H_3D_ARP |
---|
984 | , filterType |
---|
985 | #endif |
---|
986 | ); |
---|
987 | } |
---|
988 | |
---|
989 | #if H_3D_IC |
---|
990 | if( bICFlag ) |
---|
991 | { |
---|
992 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
993 | Int a, b, i, j; |
---|
994 | const Int iShift = IC_CONST_SHIFT; |
---|
995 | |
---|
996 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA ); |
---|
997 | #else |
---|
998 | Int a, b, iShift, i, j; |
---|
999 | |
---|
1000 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_LUMA ); |
---|
1001 | #endif |
---|
1002 | |
---|
1003 | |
---|
1004 | for ( i = 0; i < height; i++ ) |
---|
1005 | { |
---|
1006 | for ( j = 0; j < width; j++ ) |
---|
1007 | { |
---|
1008 | if( bi ) |
---|
1009 | { |
---|
1010 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
1011 | dst[j] = ( ( a*dst[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1 << iIFshift ) - IF_INTERNAL_OFFS; |
---|
1012 | } |
---|
1013 | else |
---|
1014 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
1015 | } |
---|
1016 | dst += dstStride; |
---|
1017 | } |
---|
1018 | } |
---|
1019 | #endif |
---|
1020 | } |
---|
1021 | |
---|
1022 | /** |
---|
1023 | * \brief Generate motion-compensated chroma block |
---|
1024 | * |
---|
1025 | * \param cu Pointer to current CU |
---|
1026 | * \param refPic Pointer to reference picture |
---|
1027 | * \param partAddr Address of block within CU |
---|
1028 | * \param mv Motion vector |
---|
1029 | * \param width Width of block |
---|
1030 | * \param height Height of block |
---|
1031 | * \param dstPic Pointer to destination picture |
---|
1032 | * \param bi Flag indicating whether bipred is used |
---|
1033 | */ |
---|
1034 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
1035 | #if H_3D_ARP |
---|
1036 | , Bool filterType |
---|
1037 | #endif |
---|
1038 | #if H_3D_IC |
---|
1039 | , Bool bICFlag |
---|
1040 | #endif |
---|
1041 | ) |
---|
1042 | { |
---|
1043 | Int refStride = refPic->getCStride(); |
---|
1044 | Int dstStride = dstPic->getCStride(); |
---|
1045 | |
---|
1046 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
1047 | |
---|
1048 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1049 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1050 | |
---|
1051 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
1052 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
1053 | |
---|
1054 | Int xFrac = mv->getHor() & 0x7; |
---|
1055 | Int yFrac = mv->getVer() & 0x7; |
---|
1056 | UInt cxWidth = width >> 1; |
---|
1057 | UInt cxHeight = height >> 1; |
---|
1058 | |
---|
1059 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
1060 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1061 | |
---|
1062 | Int filterSize = NTAPS_CHROMA; |
---|
1063 | |
---|
1064 | Int halfFilterSize = (filterSize>>1); |
---|
1065 | |
---|
1066 | if ( yFrac == 0 ) |
---|
1067 | { |
---|
1068 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1069 | #if H_3D_ARP |
---|
1070 | , filterType |
---|
1071 | #endif |
---|
1072 | ); |
---|
1073 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
1074 | #if H_3D_ARP |
---|
1075 | , filterType |
---|
1076 | #endif |
---|
1077 | ); |
---|
1078 | } |
---|
1079 | else if ( xFrac == 0 ) |
---|
1080 | { |
---|
1081 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1082 | #if H_3D_ARP |
---|
1083 | , filterType |
---|
1084 | #endif |
---|
1085 | ); |
---|
1086 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
1087 | #if H_3D_ARP |
---|
1088 | , filterType |
---|
1089 | #endif |
---|
1090 | ); |
---|
1091 | } |
---|
1092 | else |
---|
1093 | { |
---|
1094 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1095 | #if H_3D_ARP |
---|
1096 | , filterType |
---|
1097 | #endif |
---|
1098 | ); |
---|
1099 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1100 | #if H_3D_ARP |
---|
1101 | , filterType |
---|
1102 | #endif |
---|
1103 | ); |
---|
1104 | |
---|
1105 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
1106 | #if H_3D_ARP |
---|
1107 | , filterType |
---|
1108 | #endif |
---|
1109 | ); |
---|
1110 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
1111 | #if H_3D_ARP |
---|
1112 | , filterType |
---|
1113 | #endif |
---|
1114 | ); |
---|
1115 | } |
---|
1116 | |
---|
1117 | #if H_3D_IC |
---|
1118 | if( bICFlag ) |
---|
1119 | { |
---|
1120 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1121 | Int a, b, i, j; |
---|
1122 | const Int iShift = IC_CONST_SHIFT; |
---|
1123 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb |
---|
1124 | #else |
---|
1125 | Int a, b, iShift, i, j; |
---|
1126 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_U ); // Cb |
---|
1127 | #endif |
---|
1128 | for ( i = 0; i < cxHeight; i++ ) |
---|
1129 | { |
---|
1130 | for ( j = 0; j < cxWidth; j++ ) |
---|
1131 | { |
---|
1132 | if( bi ) |
---|
1133 | { |
---|
1134 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
1135 | dstCb[j] = ( ( a*dstCb[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS; |
---|
1136 | } |
---|
1137 | else |
---|
1138 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
1139 | } |
---|
1140 | dstCb += dstStride; |
---|
1141 | } |
---|
1142 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1143 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr |
---|
1144 | #else |
---|
1145 | xGetLLSICPrediction( cu, mv, refPic, a, b, iShift, TEXT_CHROMA_V ); // Cr |
---|
1146 | #endif |
---|
1147 | for ( i = 0; i < cxHeight; i++ ) |
---|
1148 | { |
---|
1149 | for ( j = 0; j < cxWidth; j++ ) |
---|
1150 | { |
---|
1151 | if( bi ) |
---|
1152 | { |
---|
1153 | Int iIFshift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
1154 | dstCr[j] = ( ( a*dstCr[j] + a*IF_INTERNAL_OFFS ) >> iShift ) + b*( 1<<iIFshift ) - IF_INTERNAL_OFFS; |
---|
1155 | } |
---|
1156 | else |
---|
1157 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
1158 | } |
---|
1159 | dstCr += dstStride; |
---|
1160 | } |
---|
1161 | } |
---|
1162 | #endif |
---|
1163 | } |
---|
1164 | |
---|
1165 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
1166 | { |
---|
1167 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
1168 | { |
---|
1169 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
1170 | } |
---|
1171 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
1172 | { |
---|
1173 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1174 | } |
---|
1175 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
1176 | { |
---|
1177 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1178 | } |
---|
1179 | } |
---|
1180 | |
---|
1181 | // AMVP |
---|
1182 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
1183 | { |
---|
1184 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
1185 | if( pcAMVPInfo->iN <= 1 ) |
---|
1186 | { |
---|
1187 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
1188 | |
---|
1189 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1190 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1191 | return; |
---|
1192 | } |
---|
1193 | |
---|
1194 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
1195 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
1196 | return; |
---|
1197 | } |
---|
1198 | |
---|
1199 | /** Function for deriving planar intra prediction. |
---|
1200 | * \param pSrc pointer to reconstructed sample array |
---|
1201 | * \param srcStride the stride of the reconstructed sample array |
---|
1202 | * \param rpDst reference to pointer for the prediction sample array |
---|
1203 | * \param dstStride the stride of the prediction sample array |
---|
1204 | * \param width the width of the block |
---|
1205 | * \param height the height of the block |
---|
1206 | * |
---|
1207 | * This function derives the prediction samples for planar mode (intra coding). |
---|
1208 | */ |
---|
1209 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
1210 | { |
---|
1211 | assert(width == height); |
---|
1212 | |
---|
1213 | Int k, l, bottomLeft, topRight; |
---|
1214 | Int horPred; |
---|
1215 | Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
1216 | UInt blkSize = width; |
---|
1217 | UInt offset2D = width; |
---|
1218 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
1219 | UInt shift2D = shift1D + 1; |
---|
1220 | |
---|
1221 | // Get left and above reference column and row |
---|
1222 | for(k=0;k<blkSize+1;k++) |
---|
1223 | { |
---|
1224 | topRow[k] = pSrc[k-srcStride]; |
---|
1225 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
1226 | } |
---|
1227 | |
---|
1228 | // Prepare intermediate variables used in interpolation |
---|
1229 | bottomLeft = leftColumn[blkSize]; |
---|
1230 | topRight = topRow[blkSize]; |
---|
1231 | for (k=0;k<blkSize;k++) |
---|
1232 | { |
---|
1233 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
1234 | rightColumn[k] = topRight - leftColumn[k]; |
---|
1235 | topRow[k] <<= shift1D; |
---|
1236 | leftColumn[k] <<= shift1D; |
---|
1237 | } |
---|
1238 | |
---|
1239 | // Generate prediction signal |
---|
1240 | for (k=0;k<blkSize;k++) |
---|
1241 | { |
---|
1242 | horPred = leftColumn[k] + offset2D; |
---|
1243 | for (l=0;l<blkSize;l++) |
---|
1244 | { |
---|
1245 | horPred += rightColumn[k]; |
---|
1246 | topRow[l] += bottomRow[l]; |
---|
1247 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
1248 | } |
---|
1249 | } |
---|
1250 | } |
---|
1251 | |
---|
1252 | /** Function for filtering intra DC predictor. |
---|
1253 | * \param pSrc pointer to reconstructed sample array |
---|
1254 | * \param iSrcStride the stride of the reconstructed sample array |
---|
1255 | * \param rpDst reference to pointer for the prediction sample array |
---|
1256 | * \param iDstStride the stride of the prediction sample array |
---|
1257 | * \param iWidth the width of the block |
---|
1258 | * \param iHeight the height of the block |
---|
1259 | * |
---|
1260 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
1261 | */ |
---|
1262 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
1263 | { |
---|
1264 | Pel* pDst = rpDst; |
---|
1265 | Int x, y, iDstStride2, iSrcStride2; |
---|
1266 | |
---|
1267 | // boundary pixels processing |
---|
1268 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
1269 | |
---|
1270 | for ( x = 1; x < iWidth; x++ ) |
---|
1271 | { |
---|
1272 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
1273 | } |
---|
1274 | |
---|
1275 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
1276 | { |
---|
1277 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
1278 | } |
---|
1279 | |
---|
1280 | return; |
---|
1281 | } |
---|
1282 | #if H_3D_IC |
---|
1283 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
1284 | * \param x input value |
---|
1285 | * |
---|
1286 | * This function derives the position of first non-zero binary bit of a value |
---|
1287 | */ |
---|
1288 | Int GetMSB( UInt x ) |
---|
1289 | { |
---|
1290 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
1291 | |
---|
1292 | while( x > 1 ) |
---|
1293 | { |
---|
1294 | bits >>= 1; |
---|
1295 | y = x >> bits; |
---|
1296 | |
---|
1297 | if( y ) |
---|
1298 | { |
---|
1299 | x = y; |
---|
1300 | iMSB += bits; |
---|
1301 | } |
---|
1302 | } |
---|
1303 | |
---|
1304 | iMSB+=y; |
---|
1305 | |
---|
1306 | return iMSB; |
---|
1307 | } |
---|
1308 | |
---|
1309 | #if !SHARP_ILLUCOMP_REFINE_E0046 |
---|
1310 | /** Function for counting leading number of zeros/ones |
---|
1311 | * \param x input value |
---|
1312 | \ This function counts leading number of zeros for positive numbers and |
---|
1313 | \ leading number of ones for negative numbers. This can be implemented in |
---|
1314 | \ single instructure cycle on many processors. |
---|
1315 | */ |
---|
1316 | |
---|
1317 | Short CountLeadingZerosOnes (Short x) |
---|
1318 | { |
---|
1319 | Short clz; |
---|
1320 | Short i; |
---|
1321 | |
---|
1322 | if(x == 0) |
---|
1323 | { |
---|
1324 | clz = 0; |
---|
1325 | } |
---|
1326 | else |
---|
1327 | { |
---|
1328 | if (x == -1) |
---|
1329 | { |
---|
1330 | clz = 15; |
---|
1331 | } |
---|
1332 | else |
---|
1333 | { |
---|
1334 | if(x < 0) |
---|
1335 | { |
---|
1336 | x = ~x; |
---|
1337 | } |
---|
1338 | clz = 15; |
---|
1339 | for(i = 0;i < 15;++i) |
---|
1340 | { |
---|
1341 | if(x) |
---|
1342 | { |
---|
1343 | clz --; |
---|
1344 | } |
---|
1345 | x = x >> 1; |
---|
1346 | } |
---|
1347 | } |
---|
1348 | } |
---|
1349 | return clz; |
---|
1350 | } |
---|
1351 | #endif |
---|
1352 | |
---|
1353 | /** Function for deriving LM illumination compensation. |
---|
1354 | */ |
---|
1355 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1356 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType ) |
---|
1357 | #else |
---|
1358 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, TextType eType ) |
---|
1359 | #endif |
---|
1360 | { |
---|
1361 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
1362 | Pel *pRec = NULL, *pRef = NULL; |
---|
1363 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
1364 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
1365 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
1366 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer; |
---|
1367 | |
---|
1368 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
1369 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
1370 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
1371 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
1372 | iRefX = iCUPelX + iHor; |
---|
1373 | iRefY = iCUPelY + iVer; |
---|
1374 | if( eType != TEXT_LUMA ) |
---|
1375 | { |
---|
1376 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
1377 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
1378 | } |
---|
1379 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
1380 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
1381 | |
---|
1382 | Int i, j, iCountShift = 0; |
---|
1383 | |
---|
1384 | // LLS parameters estimation --> |
---|
1385 | |
---|
1386 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
1387 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1388 | Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12); |
---|
1389 | #endif |
---|
1390 | |
---|
1391 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 ) |
---|
1392 | { |
---|
1393 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
1394 | if( eType == TEXT_LUMA ) |
---|
1395 | { |
---|
1396 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1397 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1398 | } |
---|
1399 | else if( eType == TEXT_CHROMA_U ) |
---|
1400 | { |
---|
1401 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1402 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1403 | } |
---|
1404 | else |
---|
1405 | { |
---|
1406 | assert( eType == TEXT_CHROMA_V ); |
---|
1407 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1408 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
1409 | } |
---|
1410 | |
---|
1411 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1412 | for( j = 0; j < uiWidth; j+=2 ) |
---|
1413 | #else |
---|
1414 | for( j = 0; j < uiWidth; j++ ) |
---|
1415 | #endif |
---|
1416 | { |
---|
1417 | x += pRef[j]; |
---|
1418 | y += pRec[j]; |
---|
1419 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1420 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
1421 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
1422 | #else |
---|
1423 | xx += pRef[j] * pRef[j]; |
---|
1424 | xy += pRef[j] * pRec[j]; |
---|
1425 | #endif |
---|
1426 | } |
---|
1427 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1428 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
1429 | #else |
---|
1430 | iCountShift += g_aucConvertToBit[ uiWidth ] + 2; |
---|
1431 | #endif |
---|
1432 | } |
---|
1433 | |
---|
1434 | |
---|
1435 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 ) |
---|
1436 | { |
---|
1437 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
1438 | if( eType == TEXT_LUMA ) |
---|
1439 | { |
---|
1440 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1441 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1442 | } |
---|
1443 | else if( eType == TEXT_CHROMA_U ) |
---|
1444 | { |
---|
1445 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1446 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1447 | } |
---|
1448 | else |
---|
1449 | { |
---|
1450 | assert( eType == TEXT_CHROMA_V ); |
---|
1451 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
1452 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
1453 | } |
---|
1454 | |
---|
1455 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1456 | for( i = 0; i < uiHeight; i+=2 ) |
---|
1457 | #else |
---|
1458 | for( i = 0; i < uiHeight; i++ ) |
---|
1459 | #endif |
---|
1460 | { |
---|
1461 | x += pRef[0]; |
---|
1462 | y += pRec[0]; |
---|
1463 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1464 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
1465 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
1466 | |
---|
1467 | pRef += iRefStride*2; |
---|
1468 | pRec += iRecStride*2; |
---|
1469 | #else |
---|
1470 | xx += pRef[0] * pRef[0]; |
---|
1471 | xy += pRef[0] * pRec[0]; |
---|
1472 | |
---|
1473 | pRef += iRefStride; |
---|
1474 | pRec += iRecStride; |
---|
1475 | #endif |
---|
1476 | } |
---|
1477 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1478 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
1479 | #else |
---|
1480 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 ); |
---|
1481 | #endif |
---|
1482 | } |
---|
1483 | |
---|
1484 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1485 | xy += xx >> IC_REG_COST_SHIFT; |
---|
1486 | xx += xx >> IC_REG_COST_SHIFT; |
---|
1487 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
1488 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
1489 | const Int iShift = IC_CONST_SHIFT; |
---|
1490 | { |
---|
1491 | #else |
---|
1492 | Int iTempShift = ( ( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC ) + g_aucConvertToBit[ uiWidth ] + 3 - 15; |
---|
1493 | |
---|
1494 | if( iTempShift > 0 ) |
---|
1495 | { |
---|
1496 | x = ( x + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1497 | y = ( y + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1498 | xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1499 | xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
1500 | iCountShift -= iTempShift; |
---|
1501 | } |
---|
1502 | |
---|
1503 | iShift = 13; |
---|
1504 | |
---|
1505 | if( iCountShift == 0 ) |
---|
1506 | { |
---|
1507 | a = 1; |
---|
1508 | b = 0; |
---|
1509 | iShift = 0; |
---|
1510 | } |
---|
1511 | else |
---|
1512 | { |
---|
1513 | Int a1 = ( xy << iCountShift ) - y * x; |
---|
1514 | Int a2 = ( xx << iCountShift ) - x * x; |
---|
1515 | #endif |
---|
1516 | { |
---|
1517 | const Int iShiftA2 = 6; |
---|
1518 | #if !SHARP_ILLUCOMP_REFINE_E0046 |
---|
1519 | const Int iShiftA1 = 15; |
---|
1520 | #endif |
---|
1521 | const Int iAccuracyShift = 15; |
---|
1522 | |
---|
1523 | Int iScaleShiftA2 = 0; |
---|
1524 | Int iScaleShiftA1 = 0; |
---|
1525 | Int a1s = a1; |
---|
1526 | Int a2s = a2; |
---|
1527 | |
---|
1528 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1529 | a1 = Clip3(0, 2*a2, a1); |
---|
1530 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
1531 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
1532 | #else |
---|
1533 | iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1; |
---|
1534 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
1535 | #endif |
---|
1536 | |
---|
1537 | if( iScaleShiftA1 < 0 ) |
---|
1538 | { |
---|
1539 | iScaleShiftA1 = 0; |
---|
1540 | } |
---|
1541 | |
---|
1542 | if( iScaleShiftA2 < 0 ) |
---|
1543 | { |
---|
1544 | iScaleShiftA2 = 0; |
---|
1545 | } |
---|
1546 | |
---|
1547 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
1548 | |
---|
1549 | |
---|
1550 | a2s = a2 >> iScaleShiftA2; |
---|
1551 | |
---|
1552 | a1s = a1 >> iScaleShiftA1; |
---|
1553 | |
---|
1554 | #if SHARP_ILLUCOMP_REFINE_E0046 |
---|
1555 | a = a1s * m_uiaShift[ a2s ]; |
---|
1556 | a = a >> iScaleShiftA; |
---|
1557 | #else |
---|
1558 | if (a2s >= 1) |
---|
1559 | { |
---|
1560 | a = a1s * m_uiaShift[ a2s - 1]; |
---|
1561 | } |
---|
1562 | else |
---|
1563 | { |
---|
1564 | a = 0; |
---|
1565 | } |
---|
1566 | |
---|
1567 | if( iScaleShiftA < 0 ) |
---|
1568 | { |
---|
1569 | a = a << -iScaleShiftA; |
---|
1570 | } |
---|
1571 | else |
---|
1572 | { |
---|
1573 | a = a >> iScaleShiftA; |
---|
1574 | } |
---|
1575 | |
---|
1576 | a = Clip3( -( 1 << 15 ), ( 1 << 15 ) - 1, a ); |
---|
1577 | |
---|
1578 | Int minA = -(1 << (6)); |
---|
1579 | Int maxA = (1 << 6) - 1; |
---|
1580 | if( a <= maxA && a >= minA ) |
---|
1581 | { |
---|
1582 | // do nothing |
---|
1583 | } |
---|
1584 | else |
---|
1585 | { |
---|
1586 | Short n = CountLeadingZerosOnes( a ); |
---|
1587 | a = a >> (9-n); |
---|
1588 | iShift -= (9-n); |
---|
1589 | } |
---|
1590 | #endif |
---|
1591 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
1592 | } |
---|
1593 | } |
---|
1594 | } |
---|
1595 | #endif |
---|
1596 | |
---|
1597 | #if H_3D_VSP |
---|
1598 | // Input: |
---|
1599 | // refPic: Ref picture. Full picture, with padding |
---|
1600 | // posX, posY: PU position, texture |
---|
1601 | // sizeX, sizeY: PU size |
---|
1602 | // partAddr: z-order index |
---|
1603 | // dv: disparity vector. derived from neighboring blocks |
---|
1604 | // |
---|
1605 | // Output: dstPic, PU predictor 64x64 |
---|
1606 | Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* dv, UInt partAddr,Int posX, Int posY |
---|
1607 | , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi ) |
---|
1608 | { |
---|
1609 | Int widthLuma; |
---|
1610 | Int heightLuma; |
---|
1611 | |
---|
1612 | if (isDepth) |
---|
1613 | { |
---|
1614 | widthLuma = pPicBaseDepth->getWidth(); |
---|
1615 | heightLuma = pPicBaseDepth->getHeight(); |
---|
1616 | } |
---|
1617 | else |
---|
1618 | { |
---|
1619 | widthLuma = refPic->getWidth(); |
---|
1620 | heightLuma = refPic->getHeight(); |
---|
1621 | } |
---|
1622 | |
---|
1623 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1624 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1625 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1626 | #endif |
---|
1627 | |
---|
1628 | #if H_3D_VSP_CONSTRAINED |
---|
1629 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1630 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1631 | #endif |
---|
1632 | |
---|
1633 | Int nTxtPerDepthX = widthLuma / ( pPicBaseDepth->getWidth() ); // texture pixel # per depth pixel |
---|
1634 | Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() ); |
---|
1635 | |
---|
1636 | Int refStride = refPic->getStride(); |
---|
1637 | Int dstStride = dstPic->getStride(); |
---|
1638 | Int depStride = pPicBaseDepth->getStride(); |
---|
1639 | Int depthPosX = Clip3(0, widthLuma - sizeX, (posX/nTxtPerDepthX) + ((dv->getHor()+2)>>2)); |
---|
1640 | Int depthPosY = Clip3(0, heightLuma- sizeY, (posY/nTxtPerDepthY) + ((dv->getVer()+2)>>2)); |
---|
1641 | Pel *ref = refPic->getLumaAddr() + posX + posY * refStride; |
---|
1642 | Pel *dst = dstPic->getLumaAddr(partAddr); |
---|
1643 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; |
---|
1644 | |
---|
1645 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1646 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1647 | Int dW = sizeX>>1; |
---|
1648 | Int dH = sizeY>>1; |
---|
1649 | #endif |
---|
1650 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1651 | Int dW = sizeX>>2; |
---|
1652 | Int dH = sizeY>>2; |
---|
1653 | #endif |
---|
1654 | { |
---|
1655 | Pel* depthi = depth; |
---|
1656 | for (Int j = 0; j < dH; j++) |
---|
1657 | { |
---|
1658 | for (Int i = 0; i < dW; i++) |
---|
1659 | { |
---|
1660 | Pel* depthTmp; |
---|
1661 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1662 | if (depthPosX + (i<<1) < widthDepth) |
---|
1663 | depthTmp = depthi + (i << 1); |
---|
1664 | else |
---|
1665 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1666 | #endif |
---|
1667 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1668 | if (depthPosX + (i<<2) < widthDepth) |
---|
1669 | depthTmp = depthi + (i << 2); |
---|
1670 | else |
---|
1671 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1672 | #endif |
---|
1673 | Int maxV = 0; |
---|
1674 | for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1)) |
---|
1675 | { |
---|
1676 | Int iX = 0; |
---|
1677 | for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1)) |
---|
1678 | { |
---|
1679 | if (maxV < depthTmp[iX]) |
---|
1680 | maxV = depthTmp[iX]; |
---|
1681 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1682 | if (depthPosX + (i<<1) + blocki < widthDepth - 1) |
---|
1683 | #else // H_3D_VSP_BLOCKSIZE == 4 |
---|
1684 | if (depthPosX + (i<<2) + blocki < widthDepth - 1) |
---|
1685 | #endif |
---|
1686 | iX = (H_3D_VSP_BLOCKSIZE-1); |
---|
1687 | } |
---|
1688 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1689 | if (depthPosY + (j<<1) + blockj < heightDepth - 1) |
---|
1690 | #else // H_3D_VSP_BLOCKSIZE == 4 |
---|
1691 | if (depthPosY + (j<<2) + blockj < heightDepth - 1) |
---|
1692 | #endif |
---|
1693 | depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1); |
---|
1694 | } |
---|
1695 | m_pDepthBlock[i+j*dW] = maxV; |
---|
1696 | } // end of i < dW |
---|
1697 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1698 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1699 | depthi += (depStride << 1); |
---|
1700 | else |
---|
1701 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1702 | #endif |
---|
1703 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1704 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1705 | depthi += (depStride << 2); |
---|
1706 | else |
---|
1707 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1708 | #endif |
---|
1709 | } |
---|
1710 | } |
---|
1711 | #endif // H_3D_VSP_BLOCKSIZE != 1 |
---|
1712 | |
---|
1713 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1714 | #if H_3D_VSP_CONSTRAINED |
---|
1715 | //get LUT based horizontal reference range |
---|
1716 | Int range = xGetConstrainedSize(sizeX, sizeY); |
---|
1717 | |
---|
1718 | // The minimum depth value |
---|
1719 | Int minRelativePos = MAX_INT; |
---|
1720 | Int maxRelativePos = MIN_INT; |
---|
1721 | |
---|
1722 | Pel* depthTemp, *depthInitial=depth; |
---|
1723 | for (Int yTxt = 0; yTxt < sizeY; yTxt++) |
---|
1724 | { |
---|
1725 | for (Int xTxt = 0; xTxt < sizeX; xTxt++) |
---|
1726 | { |
---|
1727 | if (depthPosX+xTxt < widthDepth) |
---|
1728 | depthTemp = depthInitial + xTxt; |
---|
1729 | else |
---|
1730 | depthTemp = depthInitial + (widthDepth - depthPosX - 1); |
---|
1731 | |
---|
1732 | Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec; |
---|
1733 | Int disparityInt = disparity >> 2; |
---|
1734 | |
---|
1735 | if( disparity <= 0) |
---|
1736 | { |
---|
1737 | if (minRelativePos > disparityInt+xTxt) |
---|
1738 | minRelativePos = disparityInt+xTxt; |
---|
1739 | } |
---|
1740 | else |
---|
1741 | { |
---|
1742 | if (maxRelativePos < disparityInt+xTxt) |
---|
1743 | maxRelativePos = disparityInt+xTxt; |
---|
1744 | } |
---|
1745 | } |
---|
1746 | if (depthPosY+yTxt < heightDepth) |
---|
1747 | depthInitial = depthInitial + depStride; |
---|
1748 | } |
---|
1749 | |
---|
1750 | Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec; |
---|
1751 | if (disparity_tmp <= 0) |
---|
1752 | maxRelativePos = minRelativePos + range -1 ; |
---|
1753 | else |
---|
1754 | minRelativePos = maxRelativePos - range +1 ; |
---|
1755 | #endif |
---|
1756 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
1757 | |
---|
1758 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1759 | Int yDepth = 0; |
---|
1760 | #endif |
---|
1761 | for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY ) |
---|
1762 | { |
---|
1763 | for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ ) |
---|
1764 | { |
---|
1765 | Pel repDepth = 0; // to store the depth value used for warping |
---|
1766 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1767 | repDepth = depth[xDepth]; |
---|
1768 | #endif |
---|
1769 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1770 | repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
1771 | #endif |
---|
1772 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1773 | repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW]; |
---|
1774 | #endif |
---|
1775 | |
---|
1776 | assert( repDepth >= 0 && repDepth <= 255 ); |
---|
1777 | Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ?? |
---|
1778 | Int refOffset = xTxt + (disparity >> 2); |
---|
1779 | Int xFrac = disparity & 0x3; |
---|
1780 | #if H_3D_VSP_CONSTRAINED |
---|
1781 | if(refOffset<minRelativePos || refOffset>maxRelativePos) |
---|
1782 | xFrac = 0; |
---|
1783 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
1784 | #endif |
---|
1785 | Int absX = posX + refOffset; |
---|
1786 | |
---|
1787 | if (xFrac == 0) |
---|
1788 | absX = Clip3(0, widthLuma-1, absX); |
---|
1789 | else |
---|
1790 | absX = Clip3(4, widthLuma-5, absX); |
---|
1791 | |
---|
1792 | refOffset = absX - posX; |
---|
1793 | |
---|
1794 | assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 ); |
---|
1795 | m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi ); |
---|
1796 | } |
---|
1797 | ref += refStride*nTxtPerDepthY; |
---|
1798 | dst += dstStride*nTxtPerDepthY; |
---|
1799 | depth += depStride; |
---|
1800 | #if H_3D_VSP_BLOCKSIZE != 1 |
---|
1801 | yDepth++; |
---|
1802 | #endif |
---|
1803 | |
---|
1804 | } |
---|
1805 | } |
---|
1806 | |
---|
1807 | Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*dv, UInt partAddr, Int posX, Int posY |
---|
1808 | , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi) |
---|
1809 | { |
---|
1810 | Int refStride = refPic->getCStride(); |
---|
1811 | Int dstStride = dstPic->getCStride(); |
---|
1812 | Int depStride = pPicBaseDepth->getStride(); |
---|
1813 | |
---|
1814 | Int widthChroma, heightChroma; |
---|
1815 | if( isDepth) |
---|
1816 | { |
---|
1817 | widthChroma = pPicBaseDepth->getWidth()>>1; |
---|
1818 | heightChroma = pPicBaseDepth->getHeight()>>1; |
---|
1819 | } |
---|
1820 | else |
---|
1821 | { |
---|
1822 | widthChroma = refPic->getWidth()>>1; |
---|
1823 | heightChroma = refPic->getHeight()>>1; |
---|
1824 | } |
---|
1825 | |
---|
1826 | // Below is only for Texture chroma component |
---|
1827 | |
---|
1828 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1829 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1830 | |
---|
1831 | Int nTxtPerDepthX, nTxtPerDepthY; // Number of texture samples per one depth sample |
---|
1832 | Int nDepthPerTxtX, nDepthPerTxtY; // Number of depth samples per one texture sample |
---|
1833 | |
---|
1834 | Int depthPosX; // Starting position in depth image |
---|
1835 | Int depthPosY; |
---|
1836 | |
---|
1837 | if ( widthChroma > widthDepth ) |
---|
1838 | { |
---|
1839 | nTxtPerDepthX = widthChroma / widthDepth; |
---|
1840 | nDepthPerTxtX = 1; |
---|
1841 | depthPosX = posX / nTxtPerDepthX + ((dv->getHor()+2)>>2); |
---|
1842 | } |
---|
1843 | else |
---|
1844 | { |
---|
1845 | nTxtPerDepthX = 1; |
---|
1846 | nDepthPerTxtX = widthDepth / widthChroma; |
---|
1847 | depthPosX = posX * nDepthPerTxtX + ((dv->getHor()+2)>>2); |
---|
1848 | } |
---|
1849 | depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX); |
---|
1850 | if ( heightChroma > heightDepth ) |
---|
1851 | { |
---|
1852 | nTxtPerDepthY = heightChroma / heightDepth; |
---|
1853 | nDepthPerTxtY = 1; |
---|
1854 | depthPosY = posY / nTxtPerDepthY + ((dv->getVer()+2)>>2); |
---|
1855 | } |
---|
1856 | else |
---|
1857 | { |
---|
1858 | nTxtPerDepthY = 1; |
---|
1859 | nDepthPerTxtY = heightDepth / heightChroma; |
---|
1860 | depthPosY = posY * nDepthPerTxtY + ((dv->getVer()+2)>>2); |
---|
1861 | } |
---|
1862 | depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY); |
---|
1863 | |
---|
1864 | Pel *refCb = refPic->getCbAddr() + posX + posY * refStride; |
---|
1865 | Pel *refCr = refPic->getCrAddr() + posX + posY * refStride; |
---|
1866 | Pel *dstCb = dstPic->getCbAddr(partAddr); |
---|
1867 | Pel *dstCr = dstPic->getCrAddr(partAddr); |
---|
1868 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; // move the pointer to the current depth pixel position |
---|
1869 | |
---|
1870 | Int refStrideBlock = refStride * nTxtPerDepthY; |
---|
1871 | Int dstStrideBlock = dstStride * nTxtPerDepthY; |
---|
1872 | Int depStrideBlock = depStride * nDepthPerTxtY; |
---|
1873 | |
---|
1874 | if ( widthChroma > widthDepth ) // We assume |
---|
1875 | { |
---|
1876 | assert( heightChroma > heightDepth ); |
---|
1877 | printf("This branch should never been reached.\n"); |
---|
1878 | exit(0); |
---|
1879 | } |
---|
1880 | else |
---|
1881 | { |
---|
1882 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1883 | Int dW = sizeX; |
---|
1884 | Int dH = sizeY; |
---|
1885 | Int sW = 2; // search window size |
---|
1886 | Int sH = 2; |
---|
1887 | #endif |
---|
1888 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1889 | Int dW = sizeX; |
---|
1890 | Int dH = sizeY; |
---|
1891 | Int sW = 2; // search window size |
---|
1892 | Int sH = 2; |
---|
1893 | #endif |
---|
1894 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1895 | Int dW = sizeX>>1; |
---|
1896 | Int dH = sizeY>>1; |
---|
1897 | Int sW = 4; // search window size |
---|
1898 | Int sH = 4; |
---|
1899 | #endif |
---|
1900 | |
---|
1901 | { |
---|
1902 | Pel* depthi = depth; |
---|
1903 | for (Int j = 0; j < dH; j++) |
---|
1904 | { |
---|
1905 | for (Int i = 0; i < dW; i++) |
---|
1906 | { |
---|
1907 | Pel* depthTmp; |
---|
1908 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1909 | depthTmp = depthi + (i << 1); |
---|
1910 | #endif |
---|
1911 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1912 | if (depthPosX + (i<<1) < widthDepth) |
---|
1913 | depthTmp = depthi + (i << 1); |
---|
1914 | else |
---|
1915 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1916 | #endif |
---|
1917 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1918 | if (depthPosX + (i<<2) < widthDepth) |
---|
1919 | depthTmp = depthi + (i << 2); |
---|
1920 | else |
---|
1921 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1922 | #endif |
---|
1923 | Int maxV = 0; |
---|
1924 | for (Int blockj = 0; blockj < sH; blockj+=(sH-1)) |
---|
1925 | { |
---|
1926 | Int iX = 0; |
---|
1927 | for (Int blocki = 0; blocki < sW; blocki+=(sW-1)) |
---|
1928 | { |
---|
1929 | if (maxV < depthTmp[iX]) |
---|
1930 | maxV = depthTmp[iX]; |
---|
1931 | if (depthPosX + i*sW + blocki < widthDepth - 1) |
---|
1932 | iX = (sW-1); |
---|
1933 | } |
---|
1934 | if (depthPosY + j*sH + blockj < heightDepth - 1) |
---|
1935 | depthTmp += depStride * (sH-1); |
---|
1936 | } |
---|
1937 | m_pDepthBlock[i+j*dW] = maxV; |
---|
1938 | } // end of i < dW |
---|
1939 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1940 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1941 | depthi += (depStride << 1); |
---|
1942 | else |
---|
1943 | depthi = depth + (heightDepth-1)*depStride; |
---|
1944 | #endif |
---|
1945 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
1946 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1947 | depthi += (depStride << 1); |
---|
1948 | else |
---|
1949 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1950 | #endif |
---|
1951 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
1952 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1953 | depthi += (depStride << 2); |
---|
1954 | else |
---|
1955 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1956 | #endif |
---|
1957 | } |
---|
1958 | } |
---|
1959 | |
---|
1960 | |
---|
1961 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
1962 | #if H_3D_VSP_CONSTRAINED |
---|
1963 | //get LUT based horizontal reference range |
---|
1964 | Int range = xGetConstrainedSize(sizeX, sizeY, false); |
---|
1965 | |
---|
1966 | // The minimum depth value |
---|
1967 | Int minRelativePos = MAX_INT; |
---|
1968 | Int maxRelativePos = MIN_INT; |
---|
1969 | |
---|
1970 | Int depthTmp; |
---|
1971 | for (Int yTxt=0; yTxt<sizeY; yTxt++) |
---|
1972 | { |
---|
1973 | for (Int xTxt=0; xTxt<sizeX; xTxt++) |
---|
1974 | { |
---|
1975 | depthTmp = m_pDepthBlock[xTxt+yTxt*dW]; |
---|
1976 | Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
1977 | Int disparityInt = disparity >> 3;//in chroma resolution |
---|
1978 | |
---|
1979 | if (disparityInt < 0) |
---|
1980 | { |
---|
1981 | if (minRelativePos > disparityInt+xTxt) |
---|
1982 | minRelativePos = disparityInt+xTxt; |
---|
1983 | } |
---|
1984 | else |
---|
1985 | { |
---|
1986 | if (maxRelativePos < disparityInt+xTxt) |
---|
1987 | maxRelativePos = disparityInt+xTxt; |
---|
1988 | } |
---|
1989 | } |
---|
1990 | } |
---|
1991 | |
---|
1992 | depthTmp = m_pDepthBlock[0]; |
---|
1993 | Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
1994 | if ( disparity_tmp < 0 ) |
---|
1995 | maxRelativePos = minRelativePos + range - 1; |
---|
1996 | else |
---|
1997 | minRelativePos = maxRelativePos - range + 1; |
---|
1998 | |
---|
1999 | #endif // H_3D_VSP_CONSTRAINED |
---|
2000 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
2001 | |
---|
2002 | // (sizeX, sizeY) is Chroma block size |
---|
2003 | for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY ) |
---|
2004 | { |
---|
2005 | for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX ) |
---|
2006 | { |
---|
2007 | Pel repDepth = 0; // to store the depth value used for warping |
---|
2008 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
2009 | repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW]; |
---|
2010 | #endif |
---|
2011 | #if H_3D_VSP_BLOCKSIZE == 2 |
---|
2012 | repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW]; |
---|
2013 | #endif |
---|
2014 | #if H_3D_VSP_BLOCKSIZE == 4 |
---|
2015 | repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
2016 | #endif |
---|
2017 | |
---|
2018 | // calculate the offset in the reference picture |
---|
2019 | Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec; |
---|
2020 | Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image |
---|
2021 | Int xFrac = disparity & 0x7; |
---|
2022 | #if H_3D_VSP_CONSTRAINED |
---|
2023 | if(refOffset < minRelativePos || refOffset > maxRelativePos) |
---|
2024 | xFrac = 0; |
---|
2025 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
2026 | #endif |
---|
2027 | Int absX = posX + refOffset; |
---|
2028 | |
---|
2029 | if (xFrac == 0) |
---|
2030 | absX = Clip3(0, widthChroma-1, absX); |
---|
2031 | else |
---|
2032 | absX = Clip3(4, widthChroma-5, absX); |
---|
2033 | |
---|
2034 | refOffset = absX - posX; |
---|
2035 | |
---|
2036 | assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 ); |
---|
2037 | assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 ); |
---|
2038 | m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi); |
---|
2039 | m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi); |
---|
2040 | } |
---|
2041 | refCb += refStrideBlock; |
---|
2042 | refCr += refStrideBlock; |
---|
2043 | dstCb += dstStrideBlock; |
---|
2044 | dstCr += dstStrideBlock; |
---|
2045 | depth += depStrideBlock; |
---|
2046 | } |
---|
2047 | } |
---|
2048 | |
---|
2049 | } |
---|
2050 | |
---|
2051 | #if H_3D_VSP_CONSTRAINED |
---|
2052 | Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma) |
---|
2053 | { |
---|
2054 | Int iSize = 0; |
---|
2055 | if (bLuma) |
---|
2056 | { |
---|
2057 | Int iArea = (nPbW+7) * (nPbH+7); |
---|
2058 | Int iAlpha = iArea / nPbH - nPbW - 7; |
---|
2059 | iSize = iAlpha + nPbW; |
---|
2060 | } |
---|
2061 | else // chroma |
---|
2062 | { |
---|
2063 | Int iArea = (nPbW+2) * (nPbH+2); |
---|
2064 | Int iAlpha = iArea / nPbH - nPbW - 4; |
---|
2065 | iSize = iAlpha + nPbW; |
---|
2066 | } |
---|
2067 | return iSize; |
---|
2068 | } |
---|
2069 | #endif // H_3D_VSP_CONSTRAINED |
---|
2070 | |
---|
2071 | #endif // H_3D_VSP |
---|
2072 | |
---|
2073 | #if H_3D_DIM |
---|
2074 | Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
2075 | { |
---|
2076 | Int refDC1, refDC2; |
---|
2077 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
2078 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
2079 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
2080 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
2081 | |
---|
2082 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
2083 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
2084 | |
---|
2085 | if( bL == bT ) |
---|
2086 | { |
---|
2087 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 ); |
---|
2088 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
2089 | } |
---|
2090 | else |
---|
2091 | { |
---|
2092 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
2093 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
2094 | } |
---|
2095 | |
---|
2096 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
2097 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
2098 | } |
---|
2099 | |
---|
2100 | Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
2101 | { |
---|
2102 | if( dstStride == patternStride ) |
---|
2103 | { |
---|
2104 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
2105 | { |
---|
2106 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
2107 | else { ptrDst[k] = valDC1; } |
---|
2108 | } |
---|
2109 | } |
---|
2110 | else |
---|
2111 | { |
---|
2112 | Pel* piTemp = ptrDst; |
---|
2113 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
2114 | { |
---|
2115 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
2116 | { |
---|
2117 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
2118 | else { piTemp[uiX] = valDC1; } |
---|
2119 | } |
---|
2120 | piTemp += dstStride; |
---|
2121 | biSegPattern += patternStride; |
---|
2122 | } |
---|
2123 | } |
---|
2124 | } |
---|
2125 | |
---|
2126 | #if H_3D_DIM_DMM |
---|
2127 | UInt TComPrediction::xPredWedgeFromIntra( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd ) |
---|
2128 | { |
---|
2129 | UInt uiThisBlockSize = uiWidth; |
---|
2130 | |
---|
2131 | TComDataCU* pcTempCU; |
---|
2132 | UInt uiTempPartIdx; |
---|
2133 | // 1st: try continue above wedgelet |
---|
2134 | pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2135 | if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) ) |
---|
2136 | { |
---|
2137 | UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ); |
---|
2138 | if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType ) |
---|
2139 | { |
---|
2140 | // get offset between current and reference block |
---|
2141 | UInt uiOffsetX = 0, uiOffsetY = 0; |
---|
2142 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
2143 | |
---|
2144 | // get reference wedgelet |
---|
2145 | WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])]; |
---|
2146 | TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) ); |
---|
2147 | |
---|
2148 | // find wedgelet, if direction is suitable for continue wedge |
---|
2149 | if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) ) |
---|
2150 | { |
---|
2151 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2152 | pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd ); |
---|
2153 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2154 | } |
---|
2155 | } |
---|
2156 | } |
---|
2157 | |
---|
2158 | // 2nd: try continue left wedglelet |
---|
2159 | pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2160 | if( pcTempCU && isDimMode( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ) ) |
---|
2161 | { |
---|
2162 | UInt dimType = getDimType( pcTempCU->getLumaIntraDir( uiTempPartIdx ) ); |
---|
2163 | if( DMM1_IDX == dimType || DMM2_IDX == dimType || DMM3_IDX == dimType ) |
---|
2164 | { |
---|
2165 | // get offset between current and reference block |
---|
2166 | UInt uiOffsetX = 0, uiOffsetY = 0; |
---|
2167 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
2168 | |
---|
2169 | // get reference wedgelet |
---|
2170 | WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[(pcTempCU->getWidth( uiTempPartIdx )>>((pcTempCU->getPartitionSize( uiTempPartIdx ) == SIZE_NxN) ? 1 : 0))])]; |
---|
2171 | TComWedgelet* pcRefWedgelet = &(pacWedgeList->at( pcTempCU->getDmmWedgeTabIdx( dimType, uiTempPartIdx ) ) ); |
---|
2172 | |
---|
2173 | // find wedgelet, if direction is suitable for continue wedge |
---|
2174 | if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) ) |
---|
2175 | { |
---|
2176 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2177 | pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd ); |
---|
2178 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2179 | } |
---|
2180 | } |
---|
2181 | } |
---|
2182 | |
---|
2183 | // 3rd: (default) make wedglet from intra dir and max slope point |
---|
2184 | Int iSlopeX = 0, iSlopeY = 0; |
---|
2185 | UInt uiStartPosX = 0, uiStartPosY = 0; |
---|
2186 | if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) ) |
---|
2187 | { |
---|
2188 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
2189 | xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd ); |
---|
2190 | return xGetWedgePatternIdx( uiThisBlockSize, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
2191 | } |
---|
2192 | |
---|
2193 | return 0; |
---|
2194 | } |
---|
2195 | |
---|
2196 | UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx ) |
---|
2197 | { |
---|
2198 | TComPic* pcPicTex = pcCU->getSlice()->getTexturePic(); |
---|
2199 | assert( pcPicTex != NULL ); |
---|
2200 | TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr()); |
---|
2201 | UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
2202 | Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; |
---|
2203 | |
---|
2204 | if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) { return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); } |
---|
2205 | else { return g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])].at(intraTabIdx).getPatternIdx(); } |
---|
2206 | } |
---|
2207 | |
---|
2208 | Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
2209 | { |
---|
2210 | pcContourWedge->clear(); |
---|
2211 | |
---|
2212 | // get copy of co-located texture luma block |
---|
2213 | TComYuv cTempYuv; |
---|
2214 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2215 | cTempYuv.clear(); |
---|
2216 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2217 | xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2218 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2219 | |
---|
2220 | // find contour for texture luma block |
---|
2221 | UInt iDC = 0; |
---|
2222 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2223 | { |
---|
2224 | iDC += piRefBlkY[k]; |
---|
2225 | } |
---|
2226 | iDC /= (uiWidth*uiHeight); |
---|
2227 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2228 | |
---|
2229 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
2230 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2231 | { |
---|
2232 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2233 | } |
---|
2234 | |
---|
2235 | cTempYuv.destroy(); |
---|
2236 | } |
---|
2237 | |
---|
2238 | |
---|
2239 | Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
2240 | { |
---|
2241 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2242 | assert( pcPicYuvRef != NULL ); |
---|
2243 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
2244 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2245 | |
---|
2246 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
2247 | { |
---|
2248 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
2249 | piDestBlockY += uiWidth; |
---|
2250 | piRefY += iRefStride; |
---|
2251 | } |
---|
2252 | } |
---|
2253 | |
---|
2254 | Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY ) |
---|
2255 | { |
---|
2256 | ruiOffsetX = 0; |
---|
2257 | ruiOffsetY = 0; |
---|
2258 | |
---|
2259 | // get offset between current and above/left block |
---|
2260 | UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2261 | UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
2262 | |
---|
2263 | UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart(); |
---|
2264 | UInt uiMaxDepthRefCU = 0; |
---|
2265 | while( uiNumPartInRefCU > 1 ) |
---|
2266 | { |
---|
2267 | uiNumPartInRefCU >>= 2; |
---|
2268 | uiMaxDepthRefCU++; |
---|
2269 | } |
---|
2270 | |
---|
2271 | UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1); |
---|
2272 | UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2; |
---|
2273 | UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts; |
---|
2274 | |
---|
2275 | UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
2276 | UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
2277 | |
---|
2278 | if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); } |
---|
2279 | if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); } |
---|
2280 | } |
---|
2281 | |
---|
2282 | Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY ) |
---|
2283 | { |
---|
2284 | riSlopeX = 0, riSlopeY = 0, ruiStartPosX = 0, ruiStartPosY = 0; |
---|
2285 | |
---|
2286 | // 1st step: get wedge start point (max. slope) |
---|
2287 | Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt ); |
---|
2288 | Int iSourceStride = ( uiBlockSize<<1 ) + 1; |
---|
2289 | |
---|
2290 | UInt uiSlopeMaxAbove = 0, uiPosSlopeMaxAbove = 0; |
---|
2291 | for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ ) |
---|
2292 | { |
---|
2293 | if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove ) |
---|
2294 | { |
---|
2295 | uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] ); |
---|
2296 | uiPosSlopeMaxAbove = uiPosHor; |
---|
2297 | } |
---|
2298 | } |
---|
2299 | |
---|
2300 | UInt uiSlopeMaxLeft = 0, uiPosSlopeMaxLeft = 0; |
---|
2301 | for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ ) |
---|
2302 | { |
---|
2303 | if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft ) |
---|
2304 | { |
---|
2305 | uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ); |
---|
2306 | uiPosSlopeMaxLeft = uiPosVer; |
---|
2307 | } |
---|
2308 | } |
---|
2309 | |
---|
2310 | if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) |
---|
2311 | { |
---|
2312 | return false; |
---|
2313 | } |
---|
2314 | |
---|
2315 | ruiStartPosX = ( uiSlopeMaxAbove > uiSlopeMaxLeft ) ? uiPosSlopeMaxAbove : 0; |
---|
2316 | ruiStartPosY = ( uiSlopeMaxLeft >= uiSlopeMaxAbove ) ? uiPosSlopeMaxLeft : 0; |
---|
2317 | |
---|
2318 | // 2nd step: derive wedge direction |
---|
2319 | Int uiPreds[3] = {-1, -1, -1}; |
---|
2320 | Int iMode = -1; |
---|
2321 | Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); |
---|
2322 | |
---|
2323 | UInt uiDirMode = 0; |
---|
2324 | if( iMode >= 0 ) { iPredNum = iMode; } |
---|
2325 | if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; } |
---|
2326 | if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; } |
---|
2327 | |
---|
2328 | if( uiDirMode < 2 ) { return false; } // no planar & DC |
---|
2329 | |
---|
2330 | Bool modeHor = (uiDirMode < 18); |
---|
2331 | Bool modeVer = !modeHor; |
---|
2332 | Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0; |
---|
2333 | Int absAng = abs(intraPredAngle); |
---|
2334 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
2335 | Int angTable[9] = {0,2,5,9,13,17,21,26,32}; |
---|
2336 | absAng = angTable[absAng]; |
---|
2337 | intraPredAngle = signAng * absAng; |
---|
2338 | |
---|
2339 | // 3rd step: set slope for direction |
---|
2340 | if( modeHor ) |
---|
2341 | { |
---|
2342 | riSlopeX = ( intraPredAngle > 0 ) ? -32 : 32; |
---|
2343 | riSlopeY = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle; |
---|
2344 | } |
---|
2345 | else if( modeVer ) |
---|
2346 | { |
---|
2347 | riSlopeX = ( intraPredAngle > 0 ) ? intraPredAngle : -intraPredAngle; |
---|
2348 | riSlopeY = ( intraPredAngle > 0 ) ? -32 : 32; |
---|
2349 | } |
---|
2350 | |
---|
2351 | return true; |
---|
2352 | } |
---|
2353 | |
---|
2354 | 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 ) |
---|
2355 | { |
---|
2356 | ruhXs = 0; |
---|
2357 | ruhYs = 0; |
---|
2358 | ruhXe = 0; |
---|
2359 | ruhYe = 0; |
---|
2360 | |
---|
2361 | // scaling of start pos and block size to wedge resolution |
---|
2362 | UInt uiScaledStartPosX = 0; |
---|
2363 | UInt uiScaledStartPosY = 0; |
---|
2364 | UInt uiScaledBlockSize = 0; |
---|
2365 | WedgeResolution eWedgeRes = g_dmmWedgeResolution[(UInt)g_aucConvertToBit[uiBlockSize]]; |
---|
2366 | switch( eWedgeRes ) |
---|
2367 | { |
---|
2368 | case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; } |
---|
2369 | case( FULL_PEL ): { uiScaledStartPosX = uiPMSPosX; uiScaledStartPosY = uiPMSPosY; uiScaledBlockSize = uiBlockSize; break; } |
---|
2370 | case( HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; } |
---|
2371 | } |
---|
2372 | Int iMaxPos = (Int)uiScaledBlockSize - 1; |
---|
2373 | |
---|
2374 | // case above |
---|
2375 | if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 ) |
---|
2376 | { |
---|
2377 | ruhXs = (UChar)uiScaledStartPosX; |
---|
2378 | ruhYs = 0; |
---|
2379 | |
---|
2380 | if( iDeltaY == 0 ) |
---|
2381 | { |
---|
2382 | if( iDeltaX < 0 ) |
---|
2383 | { |
---|
2384 | ruhXe = 0; |
---|
2385 | ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
2386 | return; |
---|
2387 | } |
---|
2388 | else |
---|
2389 | { |
---|
2390 | ruhXe = (UChar)iMaxPos; |
---|
2391 | ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
2392 | std::swap( ruhXs, ruhXe ); |
---|
2393 | std::swap( ruhYs, ruhYe ); |
---|
2394 | return; |
---|
2395 | } |
---|
2396 | } |
---|
2397 | |
---|
2398 | // regular case |
---|
2399 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
2400 | |
---|
2401 | if( iVirtualEndX < 0 ) |
---|
2402 | { |
---|
2403 | Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd; |
---|
2404 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2405 | { |
---|
2406 | ruhXe = 0; |
---|
2407 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2408 | return; |
---|
2409 | } |
---|
2410 | else |
---|
2411 | { |
---|
2412 | ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos ); |
---|
2413 | ruhYe = (UChar)iMaxPos; |
---|
2414 | return; |
---|
2415 | } |
---|
2416 | } |
---|
2417 | else if( iVirtualEndX > iMaxPos ) |
---|
2418 | { |
---|
2419 | Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
2420 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2421 | { |
---|
2422 | ruhXe = (UChar)iMaxPos; |
---|
2423 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2424 | std::swap( ruhXs, ruhXe ); |
---|
2425 | std::swap( ruhYs, ruhYe ); |
---|
2426 | return; |
---|
2427 | } |
---|
2428 | else |
---|
2429 | { |
---|
2430 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2431 | ruhYe = (UChar)iMaxPos; |
---|
2432 | return; |
---|
2433 | } |
---|
2434 | } |
---|
2435 | else |
---|
2436 | { |
---|
2437 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
2438 | if( iXe < 0 ) |
---|
2439 | { |
---|
2440 | ruhXe = 0; |
---|
2441 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
2442 | return; |
---|
2443 | } |
---|
2444 | else if( iXe > iMaxPos ) |
---|
2445 | { |
---|
2446 | ruhXe = (UChar)iMaxPos; |
---|
2447 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2448 | std::swap( ruhXs, ruhXe ); |
---|
2449 | std::swap( ruhYs, ruhYe ); |
---|
2450 | return; |
---|
2451 | } |
---|
2452 | else |
---|
2453 | { |
---|
2454 | ruhXe = (UChar)iXe; |
---|
2455 | ruhYe = (UChar)iMaxPos; |
---|
2456 | return; |
---|
2457 | } |
---|
2458 | } |
---|
2459 | } |
---|
2460 | |
---|
2461 | // case left |
---|
2462 | if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 ) |
---|
2463 | { |
---|
2464 | ruhXs = 0; |
---|
2465 | ruhYs = (UChar)uiScaledStartPosY; |
---|
2466 | |
---|
2467 | if( iDeltaX == 0 ) |
---|
2468 | { |
---|
2469 | if( iDeltaY < 0 ) |
---|
2470 | { |
---|
2471 | ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
2472 | ruhYe = 0; |
---|
2473 | std::swap( ruhXs, ruhXe ); |
---|
2474 | std::swap( ruhYs, ruhYe ); |
---|
2475 | return; |
---|
2476 | } |
---|
2477 | else |
---|
2478 | { |
---|
2479 | ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
2480 | ruhYe = (UChar)iMaxPos; |
---|
2481 | return; |
---|
2482 | } |
---|
2483 | } |
---|
2484 | |
---|
2485 | // regular case |
---|
2486 | Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) ); |
---|
2487 | |
---|
2488 | if( iVirtualEndY < 0 ) |
---|
2489 | { |
---|
2490 | Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd; |
---|
2491 | if( iXe < (Int)uiScaledBlockSize ) |
---|
2492 | { |
---|
2493 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
2494 | ruhYe = 0; |
---|
2495 | std::swap( ruhXs, ruhXe ); |
---|
2496 | std::swap( ruhYs, ruhYe ); |
---|
2497 | return; |
---|
2498 | } |
---|
2499 | else |
---|
2500 | { |
---|
2501 | ruhXe = (UChar)iMaxPos; |
---|
2502 | ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos ); |
---|
2503 | std::swap( ruhXs, ruhXe ); |
---|
2504 | std::swap( ruhYs, ruhYe ); |
---|
2505 | return; |
---|
2506 | } |
---|
2507 | } |
---|
2508 | else if( iVirtualEndY > (uiScaledBlockSize-1) ) |
---|
2509 | { |
---|
2510 | Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd; |
---|
2511 | if( iXe < (Int)uiScaledBlockSize ) |
---|
2512 | { |
---|
2513 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
2514 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2515 | return; |
---|
2516 | } |
---|
2517 | else |
---|
2518 | { |
---|
2519 | ruhXe = (UChar)iMaxPos; |
---|
2520 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2521 | std::swap( ruhXs, ruhXe ); |
---|
2522 | std::swap( ruhYs, ruhYe ); |
---|
2523 | return; |
---|
2524 | } |
---|
2525 | } |
---|
2526 | else |
---|
2527 | { |
---|
2528 | Int iYe = iVirtualEndY - iDeltaEnd; |
---|
2529 | if( iYe < 0 ) |
---|
2530 | { |
---|
2531 | ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 ); |
---|
2532 | ruhYe = 0; |
---|
2533 | std::swap( ruhXs, ruhXe ); |
---|
2534 | std::swap( ruhYs, ruhYe ); |
---|
2535 | return; |
---|
2536 | } |
---|
2537 | else if( iYe > iMaxPos ) |
---|
2538 | { |
---|
2539 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2540 | ruhYe = (UChar)iMaxPos; |
---|
2541 | return; |
---|
2542 | } |
---|
2543 | else |
---|
2544 | { |
---|
2545 | ruhXe = (UChar)iMaxPos; |
---|
2546 | ruhYe = (UChar)iYe; |
---|
2547 | std::swap( ruhXs, ruhXe ); |
---|
2548 | std::swap( ruhYs, ruhYe ); |
---|
2549 | return; |
---|
2550 | } |
---|
2551 | } |
---|
2552 | } |
---|
2553 | |
---|
2554 | // case origin |
---|
2555 | if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 ) |
---|
2556 | { |
---|
2557 | if( iDeltaX*iDeltaY < 0 ) |
---|
2558 | { |
---|
2559 | return; |
---|
2560 | } |
---|
2561 | |
---|
2562 | ruhXs = 0; |
---|
2563 | ruhYs = 0; |
---|
2564 | |
---|
2565 | if( iDeltaY == 0 ) |
---|
2566 | { |
---|
2567 | ruhXe = (UChar)iMaxPos; |
---|
2568 | ruhYe = 0; |
---|
2569 | std::swap( ruhXs, ruhXe ); |
---|
2570 | std::swap( ruhYs, ruhYe ); |
---|
2571 | return; |
---|
2572 | } |
---|
2573 | |
---|
2574 | if( iDeltaX == 0 ) |
---|
2575 | { |
---|
2576 | ruhXe = 0; |
---|
2577 | ruhYe = (UChar)iMaxPos; |
---|
2578 | return; |
---|
2579 | } |
---|
2580 | |
---|
2581 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
2582 | |
---|
2583 | if( iVirtualEndX > iMaxPos ) |
---|
2584 | { |
---|
2585 | Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
2586 | if( iYe < (Int)uiScaledBlockSize ) |
---|
2587 | { |
---|
2588 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
2589 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
2590 | std::swap( ruhXs, ruhXe ); |
---|
2591 | std::swap( ruhYs, ruhYe ); |
---|
2592 | return; |
---|
2593 | } |
---|
2594 | else |
---|
2595 | { |
---|
2596 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
2597 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2598 | return; |
---|
2599 | } |
---|
2600 | } |
---|
2601 | else |
---|
2602 | { |
---|
2603 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
2604 | if( iXe < 0 ) |
---|
2605 | { |
---|
2606 | ruhXe = 0; |
---|
2607 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
2608 | return; |
---|
2609 | } |
---|
2610 | else if( iXe > iMaxPos ) |
---|
2611 | { |
---|
2612 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
2613 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
2614 | std::swap( ruhXs, ruhXe ); |
---|
2615 | std::swap( ruhYs, ruhYe ); |
---|
2616 | return; |
---|
2617 | } |
---|
2618 | else |
---|
2619 | { |
---|
2620 | ruhXe = (UChar)iXe; |
---|
2621 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
2622 | return; |
---|
2623 | } |
---|
2624 | } |
---|
2625 | } |
---|
2626 | } |
---|
2627 | |
---|
2628 | UInt TComPrediction::xGetWedgePatternIdx( UInt uiBlockSize, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe ) |
---|
2629 | { |
---|
2630 | WedgeRefList* pcWedgeRefList = &g_dmmWedgeRefLists[(g_aucConvertToBit[uiBlockSize])]; |
---|
2631 | for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ ) |
---|
2632 | { |
---|
2633 | TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx)); |
---|
2634 | if( pcTestWedgeRef->getStartX() == uhXs && pcTestWedgeRef->getStartY() == uhYs && pcTestWedgeRef->getEndX() == uhXe && pcTestWedgeRef->getEndY() == uhYe ) |
---|
2635 | { |
---|
2636 | return pcTestWedgeRef->getRefIdx(); |
---|
2637 | } |
---|
2638 | } |
---|
2639 | return 0; |
---|
2640 | } |
---|
2641 | #endif |
---|
2642 | #if H_3D_DIM_RBC |
---|
2643 | Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
2644 | { |
---|
2645 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
2646 | UInt uiAbs = abs( rDeltaDC ); |
---|
2647 | |
---|
2648 | Int iQp = pcCU->getQP(0); |
---|
2649 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
2650 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
2651 | |
---|
2652 | rDeltaDC = iSign * roftoi( uiAbs * dStepSize ); |
---|
2653 | return; |
---|
2654 | } |
---|
2655 | |
---|
2656 | Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
2657 | { |
---|
2658 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
2659 | UInt uiAbs = abs( rDeltaDC ); |
---|
2660 | |
---|
2661 | Int iQp = pcCU->getQP(0); |
---|
2662 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
2663 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
2664 | |
---|
2665 | rDeltaDC = iSign * roftoi( uiAbs / dStepSize ); |
---|
2666 | return; |
---|
2667 | } |
---|
2668 | #endif |
---|
2669 | #if H_3D_DIM_SDC |
---|
2670 | Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride ) |
---|
2671 | { |
---|
2672 | Int iSumDepth[2]; |
---|
2673 | memset(iSumDepth, 0, sizeof(Int)*2); |
---|
2674 | Int iSumPix[2]; |
---|
2675 | memset(iSumPix, 0, sizeof(Int)*2); |
---|
2676 | |
---|
2677 | Int subSamplePix; |
---|
2678 | if ( uiSize == 64 || uiSize == 32 ) |
---|
2679 | { |
---|
2680 | subSamplePix = 2; |
---|
2681 | } |
---|
2682 | else |
---|
2683 | { |
---|
2684 | subSamplePix = 1; |
---|
2685 | } |
---|
2686 | for (Int y=0; y<uiSize; y+=subSamplePix) |
---|
2687 | { |
---|
2688 | for (Int x=0; x<uiSize; x+=subSamplePix) |
---|
2689 | { |
---|
2690 | UChar ucSegment = pMask?(UChar)pMask[x]:0; |
---|
2691 | assert( ucSegment < uiNumSegments ); |
---|
2692 | |
---|
2693 | iSumDepth[ucSegment] += pOrig[x]; |
---|
2694 | iSumPix[ucSegment] += 1; |
---|
2695 | } |
---|
2696 | |
---|
2697 | pOrig += uiStride*subSamplePix; |
---|
2698 | pMask += uiMaskStride*subSamplePix; |
---|
2699 | } |
---|
2700 | |
---|
2701 | // compute mean for each segment |
---|
2702 | for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ ) |
---|
2703 | { |
---|
2704 | if( iSumPix[ucSeg] > 0 ) |
---|
2705 | rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg]; |
---|
2706 | else |
---|
2707 | rpSegMeans[ucSeg] = 0; // this happens for zero-segments |
---|
2708 | } |
---|
2709 | } |
---|
2710 | #endif // H_3D_DIM_SDC |
---|
2711 | #endif |
---|
2712 | //! \} |
---|