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