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-2012, 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 | #if LGE_EDGE_INTRA_A0070 |
---|
49 | #define MAX_DISTANCE_EDGEINTRA 255 |
---|
50 | #endif |
---|
51 | |
---|
52 | TComPrediction::TComPrediction() |
---|
53 | : m_pLumaRecBuffer(0) |
---|
54 | { |
---|
55 | m_piYuvExt = NULL; |
---|
56 | #if MERL_VSP_C0152 |
---|
57 | m_pDepth = (Int*) malloc(64*64*sizeof(Int)); // TODO: Use a smart way to determine the size of the array |
---|
58 | if (m_pDepth == NULL) |
---|
59 | { |
---|
60 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
61 | } |
---|
62 | #endif |
---|
63 | } |
---|
64 | |
---|
65 | TComPrediction::~TComPrediction() |
---|
66 | { |
---|
67 | |
---|
68 | #if MERL_VSP_C0152 |
---|
69 | if (m_pDepth != NULL) |
---|
70 | { |
---|
71 | free(m_pDepth); |
---|
72 | } |
---|
73 | #endif |
---|
74 | delete[] m_piYuvExt; |
---|
75 | |
---|
76 | m_acYuvPred[0].destroy(); |
---|
77 | m_acYuvPred[1].destroy(); |
---|
78 | |
---|
79 | m_cYuvPredTemp.destroy(); |
---|
80 | |
---|
81 | if( m_pLumaRecBuffer ) |
---|
82 | { |
---|
83 | delete [] m_pLumaRecBuffer; |
---|
84 | } |
---|
85 | |
---|
86 | Int i, j; |
---|
87 | for (i = 0; i < 4; i++) |
---|
88 | { |
---|
89 | for (j = 0; j < 4; j++) |
---|
90 | { |
---|
91 | m_filteredBlock[i][j].destroy(); |
---|
92 | } |
---|
93 | m_filteredBlockTmp[i].destroy(); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | Void TComPrediction::initTempBuff() |
---|
98 | { |
---|
99 | if( m_piYuvExt == NULL ) |
---|
100 | { |
---|
101 | Int extWidth = g_uiMaxCUWidth + 16; |
---|
102 | Int extHeight = g_uiMaxCUHeight + 1; |
---|
103 | Int i, j; |
---|
104 | for (i = 0; i < 4; i++) |
---|
105 | { |
---|
106 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7); |
---|
107 | for (j = 0; j < 4; j++) |
---|
108 | { |
---|
109 | m_filteredBlock[i][j].create(extWidth, extHeight); |
---|
110 | } |
---|
111 | } |
---|
112 | m_iYuvExtHeight = ((g_uiMaxCUHeight + 2) << 4); |
---|
113 | m_iYuvExtStride = ((g_uiMaxCUWidth + 8) << 4); |
---|
114 | m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ]; |
---|
115 | |
---|
116 | // new structure |
---|
117 | m_acYuvPred[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
118 | m_acYuvPred[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
119 | |
---|
120 | m_cYuvPredTemp.create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
121 | } |
---|
122 | |
---|
123 | m_iLumaRecStride = (g_uiMaxCUWidth>>1) + 1; |
---|
124 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
125 | |
---|
126 | for( Int i = 1; i < 64; i++ ) |
---|
127 | { |
---|
128 | m_uiaShift[i-1] = ( (1 << 15) + i/2 ) / i; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | // ==================================================================================================================== |
---|
133 | // Public member functions |
---|
134 | // ==================================================================================================================== |
---|
135 | |
---|
136 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
137 | Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
138 | { |
---|
139 | Int iInd, iSum = 0; |
---|
140 | Pel pDcVal; |
---|
141 | |
---|
142 | if (bAbove) |
---|
143 | { |
---|
144 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
145 | { |
---|
146 | iSum += pSrc[iInd-iSrcStride]; |
---|
147 | } |
---|
148 | } |
---|
149 | if (bLeft) |
---|
150 | { |
---|
151 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
152 | { |
---|
153 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | if (bAbove && bLeft) |
---|
158 | { |
---|
159 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
160 | } |
---|
161 | else if (bAbove) |
---|
162 | { |
---|
163 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
164 | } |
---|
165 | else if (bLeft) |
---|
166 | { |
---|
167 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
172 | } |
---|
173 | |
---|
174 | return pDcVal; |
---|
175 | } |
---|
176 | |
---|
177 | // Function for deriving the angular Intra predictions |
---|
178 | |
---|
179 | /** Function for deriving the simplified angular intra predictions. |
---|
180 | * \param pSrc pointer to reconstructed sample array |
---|
181 | * \param srcStride the stride of the reconstructed sample array |
---|
182 | * \param rpDst reference to pointer for the prediction sample array |
---|
183 | * \param dstStride the stride of the prediction sample array |
---|
184 | * \param width the width of the block |
---|
185 | * \param height the height of the block |
---|
186 | * \param dirMode the intra prediction mode index |
---|
187 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
188 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
189 | * |
---|
190 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
191 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
192 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
193 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
194 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
195 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
196 | * from the extended main reference. |
---|
197 | */ |
---|
198 | Void TComPrediction::xPredIntraAng( Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter ) |
---|
199 | { |
---|
200 | Int k,l; |
---|
201 | Int blkSize = width; |
---|
202 | Pel* pDst = rpDst; |
---|
203 | |
---|
204 | // Map the mode index to main prediction direction and angle |
---|
205 | #if LOGI_INTRA_NAME_3MPM |
---|
206 | assert( dirMode > 0 ); //no planar |
---|
207 | Bool modeDC = dirMode < 2; |
---|
208 | Bool modeHor = !modeDC && (dirMode < 18); |
---|
209 | Bool modeVer = !modeDC && !modeHor; |
---|
210 | Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0; |
---|
211 | #else |
---|
212 | Bool modeDC = dirMode == 0; |
---|
213 | Bool modeVer = !modeDC && (dirMode < 18); |
---|
214 | Bool modeHor = !modeDC && !modeVer; |
---|
215 | Int intraPredAngle = modeVer ? dirMode - 9 : modeHor ? dirMode - 25 : 0; |
---|
216 | #endif |
---|
217 | Int absAng = abs(intraPredAngle); |
---|
218 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
219 | |
---|
220 | // Set bitshifts and scale the angle parameter to block size |
---|
221 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
222 | Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
223 | Int invAngle = invAngTable[absAng]; |
---|
224 | absAng = angTable[absAng]; |
---|
225 | intraPredAngle = signAng * absAng; |
---|
226 | |
---|
227 | // Do the DC prediction |
---|
228 | if (modeDC) |
---|
229 | { |
---|
230 | Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
231 | |
---|
232 | for (k=0;k<blkSize;k++) |
---|
233 | { |
---|
234 | for (l=0;l<blkSize;l++) |
---|
235 | { |
---|
236 | pDst[k*dstStride+l] = dcval; |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | // Do angular predictions |
---|
242 | else |
---|
243 | { |
---|
244 | Pel* refMain; |
---|
245 | Pel* refSide; |
---|
246 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
247 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
248 | |
---|
249 | // Initialise the Main and Left reference array. |
---|
250 | if (intraPredAngle < 0) |
---|
251 | { |
---|
252 | for (k=0;k<blkSize+1;k++) |
---|
253 | { |
---|
254 | refAbove[k+blkSize-1] = pSrc[k-srcStride-1]; |
---|
255 | } |
---|
256 | for (k=0;k<blkSize+1;k++) |
---|
257 | { |
---|
258 | refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1]; |
---|
259 | } |
---|
260 | refMain = (modeVer ? refAbove : refLeft) + (blkSize-1); |
---|
261 | refSide = (modeVer ? refLeft : refAbove) + (blkSize-1); |
---|
262 | |
---|
263 | // Extend the Main reference to the left. |
---|
264 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
265 | for (k=-1; k>blkSize*intraPredAngle>>5; k--) |
---|
266 | { |
---|
267 | invAngleSum += invAngle; |
---|
268 | refMain[k] = refSide[invAngleSum>>8]; |
---|
269 | } |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | for (k=0;k<2*blkSize+1;k++) |
---|
274 | { |
---|
275 | refAbove[k] = pSrc[k-srcStride-1]; |
---|
276 | } |
---|
277 | for (k=0;k<2*blkSize+1;k++) |
---|
278 | { |
---|
279 | refLeft[k] = pSrc[(k-1)*srcStride-1]; |
---|
280 | } |
---|
281 | refMain = modeVer ? refAbove : refLeft; |
---|
282 | refSide = modeVer ? refLeft : refAbove; |
---|
283 | } |
---|
284 | |
---|
285 | if (intraPredAngle == 0) |
---|
286 | { |
---|
287 | for (k=0;k<blkSize;k++) |
---|
288 | { |
---|
289 | for (l=0;l<blkSize;l++) |
---|
290 | { |
---|
291 | pDst[k*dstStride+l] = refMain[l+1]; |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | if ( bFilter ) |
---|
296 | { |
---|
297 | for (k=0;k<blkSize;k++) |
---|
298 | { |
---|
299 | #if REMOVE_DIV_OPERATION |
---|
300 | pDst[k*dstStride] = Clip ( pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) ); |
---|
301 | #else |
---|
302 | pDst[k*dstStride] = Clip ( pDst[k*dstStride] + ( refSide[k+1] - refSide[0] ) / 2 ); |
---|
303 | #endif |
---|
304 | } |
---|
305 | } |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | Int deltaPos=0; |
---|
310 | Int deltaInt; |
---|
311 | Int deltaFract; |
---|
312 | Int refMainIndex; |
---|
313 | |
---|
314 | for (k=0;k<blkSize;k++) |
---|
315 | { |
---|
316 | deltaPos += intraPredAngle; |
---|
317 | deltaInt = deltaPos >> 5; |
---|
318 | deltaFract = deltaPos & (32 - 1); |
---|
319 | |
---|
320 | if (deltaFract) |
---|
321 | { |
---|
322 | // Do linear filtering |
---|
323 | for (l=0;l<blkSize;l++) |
---|
324 | { |
---|
325 | refMainIndex = l+deltaInt+1; |
---|
326 | pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 ); |
---|
327 | } |
---|
328 | } |
---|
329 | else |
---|
330 | { |
---|
331 | // Just copy the integer samples |
---|
332 | for (l=0;l<blkSize;l++) |
---|
333 | { |
---|
334 | pDst[k*dstStride+l] = refMain[l+deltaInt+1]; |
---|
335 | } |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | // Flip the block if this is the horizontal mode |
---|
341 | if (modeHor) |
---|
342 | { |
---|
343 | Pel tmp; |
---|
344 | for (k=0;k<blkSize-1;k++) |
---|
345 | { |
---|
346 | for (l=k+1;l<blkSize;l++) |
---|
347 | { |
---|
348 | tmp = pDst[k*dstStride+l]; |
---|
349 | pDst[k*dstStride+l] = pDst[l*dstStride+k]; |
---|
350 | pDst[l*dstStride+k] = tmp; |
---|
351 | } |
---|
352 | } |
---|
353 | } |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, TComDataCU* pcCU, Bool bAbove, Bool bLeft ) |
---|
358 | { |
---|
359 | Pel *pDst = piPred; |
---|
360 | Int *ptrSrc; |
---|
361 | |
---|
362 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
363 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
364 | assert( iWidth == iHeight ); |
---|
365 | |
---|
366 | ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
367 | |
---|
368 | // get starting pixel in block |
---|
369 | Int sw = 2 * iWidth + 1; |
---|
370 | |
---|
371 | // Create the prediction |
---|
372 | if ( uiDirMode == PLANAR_IDX ) |
---|
373 | { |
---|
374 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
375 | } |
---|
376 | else |
---|
377 | { |
---|
378 | #if LOGI_INTRA_NAME_3MPM |
---|
379 | xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true ); |
---|
380 | #else |
---|
381 | xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, g_aucAngIntraModeOrder[ uiDirMode ], bAbove, bLeft, true ); |
---|
382 | #endif |
---|
383 | |
---|
384 | if( (uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
385 | { |
---|
386 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight); |
---|
387 | } |
---|
388 | } |
---|
389 | } |
---|
390 | |
---|
391 | // Angular chroma |
---|
392 | Void TComPrediction::predIntraChromaAng( TComPattern* pcTComPattern, Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, TComDataCU* pcCU, Bool bAbove, Bool bLeft ) |
---|
393 | { |
---|
394 | Pel *pDst = piPred; |
---|
395 | Int *ptrSrc = piSrc; |
---|
396 | |
---|
397 | // get starting pixel in block |
---|
398 | Int sw = 2 * iWidth + 1; |
---|
399 | |
---|
400 | if ( uiDirMode == PLANAR_IDX ) |
---|
401 | { |
---|
402 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
403 | } |
---|
404 | else |
---|
405 | { |
---|
406 | // Create the prediction |
---|
407 | #if LOGI_INTRA_NAME_3MPM |
---|
408 | xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
409 | #else |
---|
410 | xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, g_aucAngIntraModeOrder[ uiDirMode ], bAbove, bLeft, false ); |
---|
411 | #endif |
---|
412 | } |
---|
413 | } |
---|
414 | |
---|
415 | /** Function for checking identical motion. |
---|
416 | * \param TComDataCU* pcCU |
---|
417 | * \param UInt PartAddr |
---|
418 | */ |
---|
419 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
420 | { |
---|
421 | if( pcCU->getSlice()->isInterB() && pcCU->getSlice()->getPPS()->getWPBiPredIdc() == 0 ) |
---|
422 | { |
---|
423 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
424 | { |
---|
425 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
426 | Int RefViewIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getViewId(); |
---|
427 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
428 | Int RefViewIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getViewId(); |
---|
429 | if(RefPOCL0 == RefPOCL1 && RefViewIdL0 == RefViewIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
430 | { |
---|
431 | return true; |
---|
432 | } |
---|
433 | } |
---|
434 | } |
---|
435 | return false; |
---|
436 | } |
---|
437 | |
---|
438 | #if LGE_EDGE_INTRA_A0070 |
---|
439 | Void TComPrediction::predIntraLumaEdge ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta ) |
---|
440 | { |
---|
441 | Pel *piDst = piPred; |
---|
442 | Int *piSrc; |
---|
443 | Int iSrcStride = ( iWidth<<1 ) + 1; |
---|
444 | Int iDstStride = uiStride; |
---|
445 | |
---|
446 | piSrc = pcTComPattern->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
447 | |
---|
448 | xPredIntraEdge ( pcCU, uiAbsPartIdx, iWidth, iHeight, piSrc, iSrcStride, piDst, iDstStride |
---|
449 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
450 | , bDelta |
---|
451 | #endif |
---|
452 | ); |
---|
453 | } |
---|
454 | |
---|
455 | Pel TComPrediction::xGetNearestNeighbor( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion ) |
---|
456 | { |
---|
457 | Bool bLeft = (x < y) ? true : false; |
---|
458 | Bool bFound = false; |
---|
459 | Int iFoundX = -1, iFoundY = -1; |
---|
460 | Int cResult = 0; |
---|
461 | |
---|
462 | UChar* piTopDistance = new UChar[iWidth]; |
---|
463 | UChar* piLeftDistance = new UChar[iHeight]; |
---|
464 | |
---|
465 | for( Int i = 0; i < iWidth; i++ ) |
---|
466 | { |
---|
467 | int Abs = x > i ? x - i : i - x; |
---|
468 | piTopDistance[ i ] = y + Abs; |
---|
469 | |
---|
470 | Abs = y > i ? y - i : i - y; |
---|
471 | piLeftDistance[ i ] = x + Abs; |
---|
472 | } |
---|
473 | |
---|
474 | for( Int dist = 0; dist < MAX_DISTANCE_EDGEINTRA && !bFound; dist++ ) |
---|
475 | { |
---|
476 | if( !bLeft ) |
---|
477 | { |
---|
478 | for( Int i = 0; i < iWidth; i++ ) |
---|
479 | { |
---|
480 | if( piTopDistance[ i ] == dist ) |
---|
481 | { |
---|
482 | if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] ) |
---|
483 | { |
---|
484 | iFoundX = i; |
---|
485 | iFoundY = 0; |
---|
486 | bFound = true; |
---|
487 | } |
---|
488 | } |
---|
489 | } |
---|
490 | for( Int i = 0; i < iHeight; i++ ) |
---|
491 | { |
---|
492 | if( piLeftDistance[ i ] == dist ) |
---|
493 | { |
---|
494 | if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] ) |
---|
495 | { |
---|
496 | iFoundX = 0; |
---|
497 | iFoundY = i; |
---|
498 | bFound = true; |
---|
499 | } |
---|
500 | } |
---|
501 | } |
---|
502 | } |
---|
503 | else |
---|
504 | { |
---|
505 | for( Int i = 0; i < iHeight; i++ ) |
---|
506 | { |
---|
507 | if( piLeftDistance[ i ] == dist ) |
---|
508 | { |
---|
509 | if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] ) |
---|
510 | { |
---|
511 | iFoundX = 0; |
---|
512 | iFoundY = i; |
---|
513 | bFound = true; |
---|
514 | } |
---|
515 | } |
---|
516 | } |
---|
517 | for( Int i = 0; i < iWidth; i++ ) |
---|
518 | { |
---|
519 | if( piTopDistance[ i ] == dist ) |
---|
520 | { |
---|
521 | if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] ) |
---|
522 | { |
---|
523 | iFoundX = i; |
---|
524 | iFoundY = 0; |
---|
525 | bFound = true; |
---|
526 | } |
---|
527 | } |
---|
528 | } |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | if( iFoundY == 0 ) |
---|
533 | { |
---|
534 | cResult = pSrc[ iFoundX + 1 ]; |
---|
535 | } |
---|
536 | else // iFoundX == 0 |
---|
537 | { |
---|
538 | cResult = pSrc[ (iFoundY + 1) * srcStride ]; |
---|
539 | } |
---|
540 | |
---|
541 | delete[] piTopDistance; piTopDistance = NULL; |
---|
542 | delete[] piLeftDistance; piLeftDistance = NULL; |
---|
543 | |
---|
544 | assert( bFound ); |
---|
545 | |
---|
546 | return cResult; |
---|
547 | } |
---|
548 | |
---|
549 | Void TComPrediction::xPredIntraEdge( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta ) |
---|
550 | { |
---|
551 | Pel* pDst = rpDst; |
---|
552 | Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx ); |
---|
553 | |
---|
554 | // Do prediction |
---|
555 | { |
---|
556 | //UInt uiSum0 = 0, uiSum1 = 0; |
---|
557 | Int iSum0 = 0, iSum1 = 0; |
---|
558 | //UInt uiMean0, uiMean1; |
---|
559 | Int iMean0, iMean1; |
---|
560 | //UInt uiCount0 = 0, uiCount1 = 0; |
---|
561 | Int iCount0 = 0, iCount1 = 0; |
---|
562 | for( UInt ui = 0; ui < iWidth; ui++ ) |
---|
563 | { |
---|
564 | if( pbRegion[ ui ] == false ) |
---|
565 | { |
---|
566 | iSum0 += (pSrc[ ui + 1 ]); |
---|
567 | iCount0++; |
---|
568 | } |
---|
569 | else |
---|
570 | { |
---|
571 | iSum1 += (pSrc[ ui + 1 ]); |
---|
572 | iCount1++; |
---|
573 | } |
---|
574 | } |
---|
575 | for( UInt ui = 0; ui < iHeight; ui++ ) // (0,0) recount (to avoid division) |
---|
576 | { |
---|
577 | if( pbRegion[ ui * iWidth ] == false ) |
---|
578 | { |
---|
579 | iSum0 += (pSrc[ (ui + 1) * srcStride ]); |
---|
580 | iCount0++; |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | iSum1 += (pSrc[ (ui + 1) * srcStride ]); |
---|
585 | iCount1++; |
---|
586 | } |
---|
587 | } |
---|
588 | if( iCount0 == 0 ) |
---|
589 | assert(false); |
---|
590 | if( iCount1 == 0 ) |
---|
591 | assert(false); |
---|
592 | iMean0 = iSum0 / iCount0; // TODO : integer op. |
---|
593 | iMean1 = iSum1 / iCount1; |
---|
594 | #if LGE_EDGE_INTRA_DELTA_DC |
---|
595 | if( bDelta ) |
---|
596 | { |
---|
597 | Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx ); |
---|
598 | Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx ); |
---|
599 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC0 ); |
---|
600 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 ); |
---|
601 | iMean0 = Clip( iMean0 + iDeltaDC0 ); |
---|
602 | iMean1 = Clip( iMean1 + iDeltaDC1 ); |
---|
603 | } |
---|
604 | #endif |
---|
605 | for( UInt ui = 0; ui < iHeight; ui++ ) |
---|
606 | { |
---|
607 | for( UInt uii = 0; uii < iWidth; uii++ ) |
---|
608 | { |
---|
609 | if( pbRegion[ uii + ui * iWidth ] == false ) |
---|
610 | pDst[ uii + ui * dstStride ] = iMean0; |
---|
611 | else |
---|
612 | pDst[ uii + ui * dstStride ] = iMean1; |
---|
613 | } |
---|
614 | } |
---|
615 | } |
---|
616 | } |
---|
617 | #endif |
---|
618 | |
---|
619 | #if DEPTH_MAP_GENERATION |
---|
620 | Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY ) |
---|
621 | #else |
---|
622 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
623 | #endif |
---|
624 | { |
---|
625 | Int iWidth; |
---|
626 | Int iHeight; |
---|
627 | UInt uiPartAddr; |
---|
628 | |
---|
629 | if ( iPartIdx >= 0 ) |
---|
630 | { |
---|
631 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
632 | |
---|
633 | #if DEPTH_MAP_GENERATION |
---|
634 | if( bPrdDepthMap ) |
---|
635 | { |
---|
636 | iWidth >>= uiSubSampExpX; |
---|
637 | iHeight >>= uiSubSampExpY; |
---|
638 | } |
---|
639 | #endif |
---|
640 | |
---|
641 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
642 | { |
---|
643 | #if LGE_ILLUCOMP_B0045 |
---|
644 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
645 | #else |
---|
646 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
647 | #endif |
---|
648 | { |
---|
649 | #if DEPTH_MAP_GENERATION |
---|
650 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
651 | #else |
---|
652 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true ); |
---|
653 | #endif |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | #if DEPTH_MAP_GENERATION |
---|
658 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
659 | #else |
---|
660 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
661 | #endif |
---|
662 | } |
---|
663 | #if LGE_ILLUCOMP_B0045 |
---|
664 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr) ) |
---|
665 | #else |
---|
666 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
667 | #endif |
---|
668 | { |
---|
669 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx ); |
---|
670 | } |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | #if DEPTH_MAP_GENERATION |
---|
675 | if( xCheckIdenticalMotion( pcCU, uiPartAddr ) && !bPrdDepthMap ) |
---|
676 | #else |
---|
677 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
678 | #endif |
---|
679 | { |
---|
680 | #if DEPTH_MAP_GENERATION |
---|
681 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
682 | #else |
---|
683 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false ); |
---|
684 | #endif |
---|
685 | } |
---|
686 | else |
---|
687 | { |
---|
688 | #if DEPTH_MAP_GENERATION |
---|
689 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap ); |
---|
690 | #else |
---|
691 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx ); |
---|
692 | #endif |
---|
693 | } |
---|
694 | } |
---|
695 | return; |
---|
696 | } |
---|
697 | |
---|
698 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ ) |
---|
699 | { |
---|
700 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
701 | |
---|
702 | #if DEPTH_MAP_GENERATION |
---|
703 | if( bPrdDepthMap ) |
---|
704 | { |
---|
705 | iWidth >>= uiSubSampExpX; |
---|
706 | iHeight >>= uiSubSampExpY; |
---|
707 | } |
---|
708 | #endif |
---|
709 | |
---|
710 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
711 | { |
---|
712 | #if LGE_ILLUCOMP_B0045 |
---|
713 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
714 | #else |
---|
715 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
716 | #endif |
---|
717 | { |
---|
718 | #if DEPTH_MAP_GENERATION |
---|
719 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
720 | #else |
---|
721 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true ); |
---|
722 | #endif |
---|
723 | } |
---|
724 | else |
---|
725 | { |
---|
726 | #if DEPTH_MAP_GENERATION |
---|
727 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
728 | #else |
---|
729 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
730 | #endif |
---|
731 | } |
---|
732 | #if DEPTH_MAP_GENERATION |
---|
733 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
734 | #else |
---|
735 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
736 | #endif |
---|
737 | #if LGE_ILLUCOMP_B0045 |
---|
738 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
739 | #else |
---|
740 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
741 | #endif |
---|
742 | { |
---|
743 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx ); |
---|
744 | } |
---|
745 | } |
---|
746 | else |
---|
747 | { |
---|
748 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
749 | { |
---|
750 | #if DEPTH_MAP_GENERATION |
---|
751 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
752 | #else |
---|
753 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false ); |
---|
754 | #endif |
---|
755 | } |
---|
756 | else |
---|
757 | { |
---|
758 | #if DEPTH_MAP_GENERATION |
---|
759 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap ); |
---|
760 | #else |
---|
761 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx ); |
---|
762 | #endif |
---|
763 | } |
---|
764 | } |
---|
765 | } |
---|
766 | return; |
---|
767 | } |
---|
768 | |
---|
769 | |
---|
770 | |
---|
771 | #if DEPTH_MAP_GENERATION |
---|
772 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi ) |
---|
773 | #else |
---|
774 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi ) |
---|
775 | #endif |
---|
776 | { |
---|
777 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
778 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
779 | pcCU->clipMv(cMv); |
---|
780 | |
---|
781 | #if DEPTH_MAP_GENERATION |
---|
782 | if( bPrdDepthMap ) |
---|
783 | { |
---|
784 | UInt uiRShift = 0; |
---|
785 | #if PDM_REMOVE_DEPENDENCE |
---|
786 | if( pcCU->getPic()->getStoredPDMforV2() == 1 ) |
---|
787 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMapTemp(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 ); |
---|
788 | else |
---|
789 | #endif |
---|
790 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 ); |
---|
791 | |
---|
792 | return; |
---|
793 | } |
---|
794 | #endif |
---|
795 | |
---|
796 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
797 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
798 | { |
---|
799 | UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 ); |
---|
800 | UInt uiOffset = bi ? IF_INTERNAL_OFFS : 0; |
---|
801 | #if DEPTH_MAP_GENERATION |
---|
802 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, 0, 0, rpcYuvPred, uiRShift, uiOffset ); |
---|
803 | #else |
---|
804 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, uiOffset ); |
---|
805 | #endif |
---|
806 | } |
---|
807 | else |
---|
808 | { |
---|
809 | #endif |
---|
810 | #if LGE_ILLUCOMP_B0045 |
---|
811 | Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId()); |
---|
812 | |
---|
813 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag); |
---|
814 | #else |
---|
815 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
816 | #endif |
---|
817 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
818 | } |
---|
819 | #endif |
---|
820 | #if LGE_ILLUCOMP_B0045 |
---|
821 | Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId()); |
---|
822 | |
---|
823 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag ); |
---|
824 | #else |
---|
825 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
826 | #endif |
---|
827 | } |
---|
828 | |
---|
829 | |
---|
830 | #if DEPTH_MAP_GENERATION |
---|
831 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap ) |
---|
832 | #else |
---|
833 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred, Int iPartIdx ) |
---|
834 | #endif |
---|
835 | { |
---|
836 | TComYuv* pcMbYuv; |
---|
837 | Int iRefIdx[2] = {-1, -1}; |
---|
838 | |
---|
839 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
840 | { |
---|
841 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
842 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
843 | |
---|
844 | if ( iRefIdx[iRefList] < 0 ) |
---|
845 | { |
---|
846 | continue; |
---|
847 | } |
---|
848 | |
---|
849 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
850 | |
---|
851 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
852 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
853 | { |
---|
854 | #if DEPTH_MAP_GENERATION |
---|
855 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
856 | #else |
---|
857 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true ); |
---|
858 | #endif |
---|
859 | } |
---|
860 | else |
---|
861 | { |
---|
862 | if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() ) |
---|
863 | { |
---|
864 | #if DEPTH_MAP_GENERATION |
---|
865 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
866 | #else |
---|
867 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true ); |
---|
868 | #endif |
---|
869 | } |
---|
870 | else |
---|
871 | { |
---|
872 | #if DEPTH_MAP_GENERATION |
---|
873 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
874 | #else |
---|
875 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, false ); |
---|
876 | #endif |
---|
877 | } |
---|
878 | } |
---|
879 | } |
---|
880 | |
---|
881 | if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() ) |
---|
882 | { |
---|
883 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
884 | } |
---|
885 | else |
---|
886 | { |
---|
887 | #if DEPTH_MAP_GENERATION |
---|
888 | if ( bPrdDepthMap ) |
---|
889 | { |
---|
890 | xWeightedAveragePdm( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, uiSubSampExpX, uiSubSampExpY ); |
---|
891 | } |
---|
892 | else |
---|
893 | { |
---|
894 | xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
895 | } |
---|
896 | #else |
---|
897 | xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
898 | #endif |
---|
899 | } |
---|
900 | } |
---|
901 | |
---|
902 | #if MERL_VSP_C0152 |
---|
903 | #if DEPTH_MAP_GENERATION |
---|
904 | Void TComPrediction::motionCompensationBWVSP( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY ) |
---|
905 | #else |
---|
906 | Void TComPrediction::motionCompensationBWVSP ( TComDataCU* pcCU, TComYuv* pcYuvPred, UInt uiAbsPartIdx, RefPicList eRefPicList, Int iPartIdx ) |
---|
907 | #endif |
---|
908 | { |
---|
909 | Int iWidth; |
---|
910 | Int iHeight; |
---|
911 | UInt uiPartAddr; |
---|
912 | |
---|
913 | if ( iPartIdx >= 0 ) |
---|
914 | { |
---|
915 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
916 | |
---|
917 | #if DEPTH_MAP_GENERATION |
---|
918 | if( bPrdDepthMap ) |
---|
919 | { |
---|
920 | iWidth >>= uiSubSampExpX; |
---|
921 | iHeight >>= uiSubSampExpY; |
---|
922 | } |
---|
923 | #endif |
---|
924 | |
---|
925 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
926 | { |
---|
927 | #if LGE_ILLUCOMP_B0045 |
---|
928 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
929 | #else |
---|
930 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
931 | #endif |
---|
932 | { |
---|
933 | #if DEPTH_MAP_GENERATION |
---|
934 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
935 | #else |
---|
936 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true ); |
---|
937 | #endif |
---|
938 | } |
---|
939 | else |
---|
940 | { |
---|
941 | #if DEPTH_MAP_GENERATION |
---|
942 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
943 | #else |
---|
944 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
945 | #endif |
---|
946 | } |
---|
947 | #if LGE_ILLUCOMP_B0045 |
---|
948 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
949 | #else |
---|
950 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
951 | #endif |
---|
952 | { |
---|
953 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx ); |
---|
954 | } |
---|
955 | } |
---|
956 | else |
---|
957 | { |
---|
958 | #if DEPTH_MAP_GENERATION |
---|
959 | if( xCheckIdenticalMotion( pcCU, uiPartAddr ) && !bPrdDepthMap ) |
---|
960 | #else |
---|
961 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
962 | #endif |
---|
963 | { |
---|
964 | #if DEPTH_MAP_GENERATION |
---|
965 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
966 | #else |
---|
967 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false ); |
---|
968 | #endif |
---|
969 | } |
---|
970 | else |
---|
971 | { |
---|
972 | #if DEPTH_MAP_GENERATION |
---|
973 | xPredInterBiBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap ); |
---|
974 | #else |
---|
975 | xPredInterBiBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, pcYuvPred, iPartIdx ); |
---|
976 | #endif |
---|
977 | } |
---|
978 | } |
---|
979 | return; |
---|
980 | } |
---|
981 | |
---|
982 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ ) |
---|
983 | { |
---|
984 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
985 | |
---|
986 | #if DEPTH_MAP_GENERATION |
---|
987 | if( bPrdDepthMap ) |
---|
988 | { |
---|
989 | iWidth >>= uiSubSampExpX; |
---|
990 | iHeight >>= uiSubSampExpY; |
---|
991 | } |
---|
992 | #endif |
---|
993 | |
---|
994 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
995 | { |
---|
996 | #if LGE_ILLUCOMP_B0045 |
---|
997 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
998 | #else |
---|
999 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1000 | #endif |
---|
1001 | { |
---|
1002 | #if DEPTH_MAP_GENERATION |
---|
1003 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr , iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
1004 | #else |
---|
1005 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, true ); |
---|
1006 | #endif |
---|
1007 | } |
---|
1008 | else |
---|
1009 | { |
---|
1010 | #if DEPTH_MAP_GENERATION |
---|
1011 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
1012 | #else |
---|
1013 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
1014 | #endif |
---|
1015 | } |
---|
1016 | #if DEPTH_MAP_GENERATION |
---|
1017 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
1018 | #else |
---|
1019 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx, false ); |
---|
1020 | #endif |
---|
1021 | #if LGE_ILLUCOMP_B0045 |
---|
1022 | if( pcCU->getSlice()->getPPS()->getUseWP() && !pcCU->getICFlag(uiPartAddr)) |
---|
1023 | #else |
---|
1024 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
1025 | #endif |
---|
1026 | { |
---|
1027 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, iPartIdx ); |
---|
1028 | } |
---|
1029 | } |
---|
1030 | else |
---|
1031 | { |
---|
1032 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
1033 | { |
---|
1034 | #if DEPTH_MAP_GENERATION |
---|
1035 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
1036 | #else |
---|
1037 | xPredInterUniBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred, iPartIdx, false ); |
---|
1038 | #endif |
---|
1039 | } |
---|
1040 | else |
---|
1041 | { |
---|
1042 | #if DEPTH_MAP_GENERATION |
---|
1043 | xPredInterBiBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, pcYuvPred, iPartIdx, bPrdDepthMap ); |
---|
1044 | #else |
---|
1045 | xPredInterBiBWVSP (pcCU, uiPartAddr, uiAbsPartIdx+uiPartAddr, iWidth, iHeight, pcYuvPred, iPartIdx ); |
---|
1046 | #endif |
---|
1047 | } |
---|
1048 | } |
---|
1049 | } |
---|
1050 | |
---|
1051 | return; |
---|
1052 | } |
---|
1053 | |
---|
1054 | |
---|
1055 | // Output: rpcYuvPred |
---|
1056 | #if DEPTH_MAP_GENERATION |
---|
1057 | Void TComPrediction::xPredInterUniBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY, Bool bi ) |
---|
1058 | #else |
---|
1059 | Void TComPrediction::xPredInterUniBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bi ) |
---|
1060 | #endif |
---|
1061 | { |
---|
1062 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1063 | Int vspIdx = pcCU->getVSPIndex(uiPartAddr); |
---|
1064 | if (vspIdx != 0) |
---|
1065 | { |
---|
1066 | if (iRefIdx >= 0) |
---|
1067 | { |
---|
1068 | printf("vspIdx = %d, iRefIdx = %d\n", vspIdx, iRefIdx); |
---|
1069 | } |
---|
1070 | assert (iRefIdx < 0); // assert (iRefIdx == NOT_VALID); |
---|
1071 | } |
---|
1072 | else |
---|
1073 | { |
---|
1074 | assert (iRefIdx >= 0); |
---|
1075 | } |
---|
1076 | |
---|
1077 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
1078 | pcCU->clipMv(cMv); |
---|
1079 | |
---|
1080 | #if DEPTH_MAP_GENERATION |
---|
1081 | if( bPrdDepthMap ) |
---|
1082 | { |
---|
1083 | UInt uiRShift = 0; |
---|
1084 | #if PDM_REMOVE_DEPENDENCE |
---|
1085 | if( pcCU->getPic()->getStoredPDMforV2() == 1 ) |
---|
1086 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMapTemp(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 ); |
---|
1087 | else |
---|
1088 | #endif |
---|
1089 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPredDepthMap(), uiPartAddr, &cMv, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY, rpcYuvPred, uiRShift, 0 ); |
---|
1090 | |
---|
1091 | return; |
---|
1092 | } |
---|
1093 | #endif |
---|
1094 | |
---|
1095 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
1096 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
1097 | { |
---|
1098 | if (vspIdx != 0) |
---|
1099 | { // depth, vsp |
---|
1100 | // get depth estimator here |
---|
1101 | TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth(); |
---|
1102 | TComPicYuv* pcBaseViewDepthPicYuv = NULL; |
---|
1103 | if (vspIdx < 4) // spatial |
---|
1104 | { |
---|
1105 | pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec(); |
---|
1106 | } |
---|
1107 | Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
1108 | Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
1109 | Int* pShiftLUT; |
---|
1110 | Int iShiftPrec; |
---|
1111 | pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec); |
---|
1112 | //using disparity to find the depth block of the base view as the depth block estimator of the current block |
---|
1113 | //using depth block estimator and base view texture to get Backward warping |
---|
1114 | xPredInterLumaBlkFromDM ( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX, iBlkY, iWidth, iHeight, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred ); |
---|
1115 | xPredInterChromaBlkFromDM( pcBaseViewDepthPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred ); |
---|
1116 | } |
---|
1117 | else |
---|
1118 | { // depth, non-vsp |
---|
1119 | UInt uiRShift = ( bi ? 14-g_uiBitDepth-g_uiBitIncrement : 0 ); |
---|
1120 | UInt uiOffset = bi ? IF_INTERNAL_OFFS : 0; |
---|
1121 | #if DEPTH_MAP_GENERATION |
---|
1122 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, 0, 0, rpcYuvPred, uiRShift, uiOffset ); |
---|
1123 | #else |
---|
1124 | xPredInterPrdDepthMap( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, uiRShift, uiOffset ); |
---|
1125 | #endif |
---|
1126 | |
---|
1127 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1128 | } |
---|
1129 | } |
---|
1130 | else // texture |
---|
1131 | { |
---|
1132 | #endif |
---|
1133 | if ( vspIdx != 0 && !pcCU->getSlice()->getSPS()->isDepth()) |
---|
1134 | { // texture, vsp |
---|
1135 | TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPicBaseTxt(); |
---|
1136 | TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec(); |
---|
1137 | TComPicYuv* pcBaseViewDepthPicYuv = NULL; |
---|
1138 | if (vspIdx < 4) // spatial |
---|
1139 | { |
---|
1140 | TComPic* pRefPicBaseDepth = pcCU->getSlice()->getRefPicBaseDepth(); |
---|
1141 | pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec(); |
---|
1142 | } |
---|
1143 | Int iBlkX = ( pcCU->getAddr() % pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
1144 | Int iBlkY = ( pcCU->getAddr() / pRefPicBaseTxt->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ]; |
---|
1145 | Int* pShiftLUT; |
---|
1146 | Int iShiftPrec; |
---|
1147 | pcCU->getSlice()->getBWVSPLUTParam(pShiftLUT, iShiftPrec); |
---|
1148 | |
---|
1149 | //using disparity to find the depth block of the base view as the depth block estimator of the current block |
---|
1150 | //using depth block estimator and base view texture to get Backward warping |
---|
1151 | xPredInterLumaBlkFromDM ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX, iBlkY, iWidth, iHeight, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred ); |
---|
1152 | xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, iShiftPrec, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getSPS()->isDepth(), vspIdx, rpcYuvPred ); |
---|
1153 | } |
---|
1154 | else |
---|
1155 | { // texture, non-vsp |
---|
1156 | #if LGE_ILLUCOMP_B0045 |
---|
1157 | Bool bICFlag = pcCU->getICFlag(uiPartAddr) && (pcCU->getSlice()->getRefViewId( eRefPicList, iRefIdx ) != pcCU->getSlice()->getViewId()); |
---|
1158 | |
---|
1159 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag); |
---|
1160 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, bICFlag ); |
---|
1161 | #else |
---|
1162 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1163 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
1164 | #endif |
---|
1165 | } |
---|
1166 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
1167 | } |
---|
1168 | #endif |
---|
1169 | } |
---|
1170 | |
---|
1171 | |
---|
1172 | #if DEPTH_MAP_GENERATION |
---|
1173 | Void TComPrediction::xPredInterBiBWVSP ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuvPred, Int iPartIdx, Bool bPrdDepthMap ) |
---|
1174 | #else |
---|
1175 | Void TComPrediction::xPredInterBiSDM ( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred, Int iPartIdx ) |
---|
1176 | #endif |
---|
1177 | { |
---|
1178 | TComYuv* pcMbYuv; |
---|
1179 | Int iRefIdx[2] = {-1, -1}; |
---|
1180 | |
---|
1181 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
1182 | { |
---|
1183 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
1184 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
1185 | #if MERL_VSP_C0152 |
---|
1186 | if(!pcCU->getVSPIndex(uiPartAddr)) |
---|
1187 | { |
---|
1188 | if ( iRefIdx[iRefList] < 0 ) |
---|
1189 | { |
---|
1190 | continue; |
---|
1191 | } |
---|
1192 | } |
---|
1193 | else |
---|
1194 | { |
---|
1195 | if ( iRefList== REF_PIC_LIST_1 && iRefIdx[iRefList] < 0 ) // iRefIdx[iRefList] ==NOT_VALID |
---|
1196 | { |
---|
1197 | continue; |
---|
1198 | } |
---|
1199 | } |
---|
1200 | #else |
---|
1201 | if ( iRefIdx[iRefList] < 0 ) |
---|
1202 | { |
---|
1203 | continue; |
---|
1204 | } |
---|
1205 | #endif |
---|
1206 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
1207 | |
---|
1208 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
1209 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
1210 | { |
---|
1211 | #if DEPTH_MAP_GENERATION |
---|
1212 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
1213 | #else |
---|
1214 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true ); |
---|
1215 | #endif |
---|
1216 | } |
---|
1217 | else |
---|
1218 | { |
---|
1219 | if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() ) |
---|
1220 | { |
---|
1221 | #if DEPTH_MAP_GENERATION |
---|
1222 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, true ); |
---|
1223 | #else |
---|
1224 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, true ); |
---|
1225 | #endif |
---|
1226 | } |
---|
1227 | else |
---|
1228 | { |
---|
1229 | #if DEPTH_MAP_GENERATION |
---|
1230 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, bPrdDepthMap, uiSubSampExpX, uiSubSampExpY, false ); |
---|
1231 | #else |
---|
1232 | xPredInterUniBWVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, iPartIdx, false ); |
---|
1233 | #endif |
---|
1234 | } |
---|
1235 | } |
---|
1236 | } |
---|
1237 | |
---|
1238 | if ( pcCU->getSlice()->getPPS()->getWPBiPredIdc() ) |
---|
1239 | { |
---|
1240 | #if MERL_VSP_C0152 |
---|
1241 | if(pcCU->getVSPIndex(uiPartAddr)) |
---|
1242 | m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight ); |
---|
1243 | else |
---|
1244 | #endif |
---|
1245 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1246 | } |
---|
1247 | else |
---|
1248 | { |
---|
1249 | #if DEPTH_MAP_GENERATION |
---|
1250 | if ( bPrdDepthMap ) |
---|
1251 | { |
---|
1252 | xWeightedAveragePdm( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, uiSubSampExpX, uiSubSampExpY ); |
---|
1253 | } |
---|
1254 | else |
---|
1255 | { |
---|
1256 | #if MERL_VSP_C0152 |
---|
1257 | if(pcCU->getVSPIndex(uiPartAddr)) |
---|
1258 | m_acYuvPred[0].copyPartToPartYuv( rpcYuvPred, uiPartAddr, iWidth, iHeight ); |
---|
1259 | else |
---|
1260 | #endif |
---|
1261 | xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1262 | } |
---|
1263 | #else |
---|
1264 | xWeightedAverage( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
1265 | #endif |
---|
1266 | } |
---|
1267 | } |
---|
1268 | #endif |
---|
1269 | |
---|
1270 | Void |
---|
1271 | #if DEPTH_MAP_GENERATION |
---|
1272 | TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, UInt uiSubSampExpX, UInt uiSubSampExpY, TComYuv*& rpcYuv, UInt uiRShift, UInt uiOffset ) |
---|
1273 | #else |
---|
1274 | TComPrediction::xPredInterPrdDepthMap( TComDataCU* pcCU, TComPicYuv* pcPicYuvRef, UInt uiPartAddr, TComMv* pcMv, Int iWidth, Int iHeight, TComYuv*& rpcYuv, UInt uiRShift, UInt uiOffset ) |
---|
1275 | #endif |
---|
1276 | { |
---|
1277 | #if DEPTH_MAP_GENERATION |
---|
1278 | Int iShiftX = 2 + uiSubSampExpX; |
---|
1279 | Int iShiftY = 2 + uiSubSampExpY; |
---|
1280 | Int iAddX = ( 1 << iShiftX ) >> 1; |
---|
1281 | Int iAddY = ( 1 << iShiftY ) >> 1; |
---|
1282 | Int iHor = ( pcMv->getHor() + iAddX ) >> iShiftX; |
---|
1283 | Int iVer = ( pcMv->getVer() + iAddY ) >> iShiftY; |
---|
1284 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
1285 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
1286 | { |
---|
1287 | iHor = pcMv->getHor(); |
---|
1288 | iVer = pcMv->getVer(); |
---|
1289 | } |
---|
1290 | #endif |
---|
1291 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
1292 | Int iDstStride = rpcYuv->getStride(); |
---|
1293 | Int iRefOffset = iHor + iVer * iRefStride; |
---|
1294 | #else |
---|
1295 | Int iFPelMask = ~3; |
---|
1296 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
1297 | Int iDstStride = rpcYuv->getStride(); |
---|
1298 | Int iHor = ( pcMv->getHor() + 2 ) & iFPelMask; |
---|
1299 | Int iVer = ( pcMv->getVer() + 2 ) & iFPelMask; |
---|
1300 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
1301 | if( pcCU->getSlice()->getSPS()->isDepth() ) |
---|
1302 | { |
---|
1303 | iHor = pcMv->getHor() * 4; |
---|
1304 | iVer = pcMv->getVer() * 4; |
---|
1305 | } |
---|
1306 | #endif |
---|
1307 | #if !QC_MVHEVC_B0046 |
---|
1308 | Int ixFrac = iHor & 0x3; |
---|
1309 | Int iyFrac = iVer & 0x3; |
---|
1310 | #endif |
---|
1311 | Int iRefOffset = ( iHor >> 2 ) + ( iVer >> 2 ) * iRefStride; |
---|
1312 | #endif |
---|
1313 | |
---|
1314 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiPartAddr ) + iRefOffset; |
---|
1315 | Pel* piDstY = rpcYuv->getLumaAddr( uiPartAddr ); |
---|
1316 | |
---|
1317 | for( Int y = 0; y < iHeight; y++, piDstY += iDstStride, piRefY += iRefStride ) |
---|
1318 | { |
---|
1319 | for( Int x = 0; x < iWidth; x++ ) |
---|
1320 | { |
---|
1321 | piDstY[ x ] = ( piRefY[ x ] << uiRShift ) - uiOffset; |
---|
1322 | } |
---|
1323 | } |
---|
1324 | } |
---|
1325 | |
---|
1326 | |
---|
1327 | /** |
---|
1328 | * \brief Generate motion-compensated luma block |
---|
1329 | * |
---|
1330 | * \param cu Pointer to current CU |
---|
1331 | * \param refPic Pointer to reference picture |
---|
1332 | * \param partAddr Address of block within CU |
---|
1333 | * \param mv Motion vector |
---|
1334 | * \param width Width of block |
---|
1335 | * \param height Height of block |
---|
1336 | * \param dstPic Pointer to destination picture |
---|
1337 | * \param bi Flag indicating whether bipred is used |
---|
1338 | */ |
---|
1339 | #if LGE_ILLUCOMP_B0045 |
---|
1340 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag) |
---|
1341 | #else |
---|
1342 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi ) |
---|
1343 | #endif |
---|
1344 | { |
---|
1345 | Int refStride = refPic->getStride(); |
---|
1346 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
1347 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1348 | |
---|
1349 | Int dstStride = dstPic->getStride(); |
---|
1350 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
1351 | |
---|
1352 | Int xFrac = mv->getHor() & 0x3; |
---|
1353 | Int yFrac = mv->getVer() & 0x3; |
---|
1354 | |
---|
1355 | #if HHI_FULL_PEL_DEPTH_MAP_MV_ACC |
---|
1356 | assert( ! cu->getSlice()->getIsDepth() || ( xFrac == 0 && yFrac == 0 ) ); |
---|
1357 | #endif |
---|
1358 | |
---|
1359 | if ( yFrac == 0 ) |
---|
1360 | { |
---|
1361 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi ); |
---|
1362 | } |
---|
1363 | else if ( xFrac == 0 ) |
---|
1364 | { |
---|
1365 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi ); |
---|
1366 | } |
---|
1367 | else |
---|
1368 | { |
---|
1369 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
1370 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1371 | |
---|
1372 | Int filterSize = NTAPS_LUMA; |
---|
1373 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
1374 | |
---|
1375 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false ); |
---|
1376 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi); |
---|
1377 | } |
---|
1378 | |
---|
1379 | #if LGE_ILLUCOMP_B0045 |
---|
1380 | if(bICFlag) |
---|
1381 | { |
---|
1382 | Int a, b, iShift, i, j; |
---|
1383 | |
---|
1384 | xGetLLSICPrediction(cu, mv, refPic, a, b, iShift); |
---|
1385 | |
---|
1386 | for (i = 0; i < height; i++) |
---|
1387 | { |
---|
1388 | for (j = 0; j < width; j++) |
---|
1389 | { |
---|
1390 | if(bi) |
---|
1391 | { |
---|
1392 | Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement ); |
---|
1393 | dst[j] = ( (a*dst[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS; |
---|
1394 | } |
---|
1395 | else |
---|
1396 | dst[j] = Clip( ( (a*dst[j]) >> iShift ) + b ); |
---|
1397 | } |
---|
1398 | dst += dstStride; |
---|
1399 | } |
---|
1400 | } |
---|
1401 | #endif |
---|
1402 | } |
---|
1403 | |
---|
1404 | /** |
---|
1405 | * \brief Generate motion-compensated chroma block |
---|
1406 | * |
---|
1407 | * \param cu Pointer to current CU |
---|
1408 | * \param refPic Pointer to reference picture |
---|
1409 | * \param partAddr Address of block within CU |
---|
1410 | * \param mv Motion vector |
---|
1411 | * \param width Width of block |
---|
1412 | * \param height Height of block |
---|
1413 | * \param dstPic Pointer to destination picture |
---|
1414 | * \param bi Flag indicating whether bipred is used |
---|
1415 | */ |
---|
1416 | #if LGE_ILLUCOMP_B0045 |
---|
1417 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi, Bool bICFlag ) |
---|
1418 | #else |
---|
1419 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi ) |
---|
1420 | #endif |
---|
1421 | { |
---|
1422 | Int refStride = refPic->getCStride(); |
---|
1423 | Int dstStride = dstPic->getCStride(); |
---|
1424 | |
---|
1425 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
1426 | |
---|
1427 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1428 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
1429 | |
---|
1430 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
1431 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
1432 | |
---|
1433 | Int xFrac = mv->getHor() & 0x7; |
---|
1434 | Int yFrac = mv->getVer() & 0x7; |
---|
1435 | UInt cxWidth = width >> 1; |
---|
1436 | UInt cxHeight = height >> 1; |
---|
1437 | |
---|
1438 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
1439 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
1440 | |
---|
1441 | Int filterSize = NTAPS_CHROMA; |
---|
1442 | |
---|
1443 | Int halfFilterSize = (filterSize>>1); |
---|
1444 | |
---|
1445 | if ( yFrac == 0 ) |
---|
1446 | { |
---|
1447 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi); |
---|
1448 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi); |
---|
1449 | } |
---|
1450 | else if ( xFrac == 0 ) |
---|
1451 | { |
---|
1452 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi); |
---|
1453 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi); |
---|
1454 | } |
---|
1455 | else |
---|
1456 | { |
---|
1457 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false); |
---|
1458 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi); |
---|
1459 | |
---|
1460 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false); |
---|
1461 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi); |
---|
1462 | } |
---|
1463 | #if LGE_ILLUCOMP_B0045 |
---|
1464 | if(bICFlag) |
---|
1465 | { |
---|
1466 | Int a, b, iShift, i, j; |
---|
1467 | xGetLLSICPredictionChroma(cu, mv, refPic, a, b, iShift, 0); // Cb |
---|
1468 | for (i = 0; i < cxHeight; i++) |
---|
1469 | { |
---|
1470 | for (j = 0; j < cxWidth; j++) |
---|
1471 | { |
---|
1472 | if(bi) |
---|
1473 | { |
---|
1474 | Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement ); |
---|
1475 | dstCb[j] = ( (a*dstCb[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS; |
---|
1476 | } |
---|
1477 | else |
---|
1478 | dstCb[j] = Clip3(0, 255, ((a*dstCb[j])>>iShift)+b); |
---|
1479 | } |
---|
1480 | dstCb += dstStride; |
---|
1481 | } |
---|
1482 | |
---|
1483 | xGetLLSICPredictionChroma(cu, mv, refPic, a, b, iShift, 1); // Cr |
---|
1484 | for (i = 0; i < cxHeight; i++) |
---|
1485 | { |
---|
1486 | for (j = 0; j < cxWidth; j++) |
---|
1487 | { |
---|
1488 | if(bi) |
---|
1489 | { |
---|
1490 | Int iIFshift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement ); |
---|
1491 | dstCr[j] = ( (a*dstCr[j]+a*IF_INTERNAL_OFFS) >> iShift ) + b*(1<<iIFshift) - IF_INTERNAL_OFFS; |
---|
1492 | } |
---|
1493 | else |
---|
1494 | dstCr[j] = Clip3(0, 255, ((a*dstCr[j])>>iShift)+b); |
---|
1495 | } |
---|
1496 | dstCr += dstStride; |
---|
1497 | } |
---|
1498 | } |
---|
1499 | #endif |
---|
1500 | } |
---|
1501 | |
---|
1502 | #if MERL_VSP_C0152 |
---|
1503 | // Input: |
---|
1504 | // refPic: Ref picture. Full picture, with padding |
---|
1505 | // posX, posY: PU position, texture |
---|
1506 | // size_x, size_y: PU size |
---|
1507 | // partAddr: z-order index |
---|
1508 | // mv: disparity vector. derived from neighboring blocks |
---|
1509 | // |
---|
1510 | // Output: dstPic, PU predictor 64x64 |
---|
1511 | Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv* mv, UInt partAddr,Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx |
---|
1512 | , TComYuv *&dstPic ) |
---|
1513 | { |
---|
1514 | Int widthLuma; |
---|
1515 | Int heightLuma; |
---|
1516 | |
---|
1517 | if (isDepth) |
---|
1518 | { |
---|
1519 | widthLuma = pPicBaseDepth->getWidth(); |
---|
1520 | heightLuma = pPicBaseDepth->getHeight(); |
---|
1521 | } |
---|
1522 | else |
---|
1523 | { |
---|
1524 | widthLuma = refPic->getWidth(); |
---|
1525 | heightLuma = refPic->getHeight(); |
---|
1526 | } |
---|
1527 | |
---|
1528 | #if MERL_VSP_BLOCKSIZE_C0152 != 1 |
---|
1529 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1530 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1531 | #endif |
---|
1532 | |
---|
1533 | Int nTxtPerDepthX = widthLuma / ( pPicBaseDepth->getWidth() ); // texture pixel # per depth pixel |
---|
1534 | Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() ); |
---|
1535 | |
---|
1536 | Int refStride = refPic->getStride(); |
---|
1537 | Int dstStride = dstPic->getStride(); |
---|
1538 | Int depStride = pPicBaseDepth->getStride(); |
---|
1539 | |
---|
1540 | Int depthPosX = Clip3(0, widthLuma - size_x - 1, (posX/nTxtPerDepthX) + (mv->getHor()>>2)); |
---|
1541 | Int depthPosY = Clip3(0, heightLuma- size_y - 1, (posY/nTxtPerDepthY) + (mv->getVer()>>2)); |
---|
1542 | |
---|
1543 | Pel *ref = refPic->getLumaAddr() + posX + posY * refStride; |
---|
1544 | Pel *dst = dstPic->getLumaAddr(partAddr); |
---|
1545 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; |
---|
1546 | |
---|
1547 | #if MERL_VSP_BLOCKSIZE_C0152 != 1 |
---|
1548 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1549 | Int dW = size_x>>1; |
---|
1550 | Int dH = size_y>>1; |
---|
1551 | #endif |
---|
1552 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1553 | Int dW = size_x>>2; |
---|
1554 | Int dH = size_y>>2; |
---|
1555 | #endif |
---|
1556 | { |
---|
1557 | Pel* depthi = depth; |
---|
1558 | for (Int j = 0; j < dH; j++) |
---|
1559 | { |
---|
1560 | for (Int i = 0; i < dW; i++) |
---|
1561 | { |
---|
1562 | Pel* depthTmp; |
---|
1563 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1564 | if (depthPosX + (i<<1) < widthDepth) |
---|
1565 | depthTmp = depthi + (i << 1); |
---|
1566 | else |
---|
1567 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1568 | #endif |
---|
1569 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1570 | if (depthPosX + (i<<2) < widthDepth) |
---|
1571 | depthTmp = depthi + (i << 2); |
---|
1572 | else |
---|
1573 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1574 | #endif |
---|
1575 | Int maxV = 0; |
---|
1576 | for (Int blockj = 0; blockj < MERL_VSP_BLOCKSIZE_C0152; blockj++) |
---|
1577 | { |
---|
1578 | Int iX = 0; |
---|
1579 | for (Int blocki = 0; blocki < MERL_VSP_BLOCKSIZE_C0152; blocki++) |
---|
1580 | { |
---|
1581 | if (maxV < depthTmp[iX]) |
---|
1582 | maxV = depthTmp[iX]; |
---|
1583 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1584 | if (depthPosX + (i<<1) + blocki < widthDepth - 1) |
---|
1585 | #else // MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1586 | if (depthPosX + (i<<2) + blocki < widthDepth - 1) |
---|
1587 | #endif |
---|
1588 | iX++; |
---|
1589 | } |
---|
1590 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1591 | if (depthPosY + (j<<1) + blockj < heightDepth - 1) |
---|
1592 | #else // MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1593 | if (depthPosY + (j<<2) + blockj < heightDepth - 1) |
---|
1594 | #endif |
---|
1595 | depthTmp += depStride; |
---|
1596 | } |
---|
1597 | m_pDepth[i+j*dW] = maxV; |
---|
1598 | } // end of i < dW |
---|
1599 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1600 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1601 | depthi += (depStride << 1); |
---|
1602 | else |
---|
1603 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1604 | #endif |
---|
1605 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1606 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1607 | depthi += (depStride << 2); |
---|
1608 | else |
---|
1609 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1610 | #endif |
---|
1611 | } |
---|
1612 | } |
---|
1613 | #endif |
---|
1614 | |
---|
1615 | #if MERL_VSP_BLOCKSIZE_C0152 != 1 |
---|
1616 | Int yDepth = 0; |
---|
1617 | #endif |
---|
1618 | for ( Int yTxt = 0; yTxt < size_y; yTxt += nTxtPerDepthY ) |
---|
1619 | { |
---|
1620 | for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth++ ) |
---|
1621 | { |
---|
1622 | Pel rep_depth = 0; // to store the depth value used for warping |
---|
1623 | #if MERL_VSP_BLOCKSIZE_C0152 == 1 |
---|
1624 | rep_depth = depth[xDepth]; |
---|
1625 | #endif |
---|
1626 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1627 | rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
1628 | #endif |
---|
1629 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1630 | rep_depth = m_pDepth[(xTxt>>2) + (yTxt>>2)*dW]; |
---|
1631 | #endif |
---|
1632 | |
---|
1633 | assert( rep_depth >= 0 && rep_depth <= 255 ); |
---|
1634 | Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec; |
---|
1635 | Int refOffset = xTxt + (disparity >> 2); |
---|
1636 | Int xFrac = disparity & 0x3; |
---|
1637 | Int absX = posX + refOffset; |
---|
1638 | |
---|
1639 | if (xFrac == 0) |
---|
1640 | absX = Clip3(0, widthLuma-1, absX); |
---|
1641 | else |
---|
1642 | absX = Clip3(4, widthLuma-5, absX); |
---|
1643 | |
---|
1644 | refOffset = absX - posX; |
---|
1645 | |
---|
1646 | assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 ); |
---|
1647 | m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true ); |
---|
1648 | } |
---|
1649 | ref += refStride*nTxtPerDepthY; |
---|
1650 | dst += dstStride*nTxtPerDepthY; |
---|
1651 | depth += depStride; |
---|
1652 | #if MERL_VSP_BLOCKSIZE_C0152 != 1 |
---|
1653 | yDepth++; |
---|
1654 | #endif |
---|
1655 | } |
---|
1656 | } |
---|
1657 | |
---|
1658 | Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, Int iShiftPrec, TComMv*mv, UInt partAddr, Int posX, Int posY, Int size_x, Int size_y, Bool isDepth, Int vspIdx |
---|
1659 | , TComYuv *&dstPic ) |
---|
1660 | { |
---|
1661 | Int refStride = refPic->getCStride(); |
---|
1662 | Int dstStride = dstPic->getCStride(); |
---|
1663 | Int depStride = pPicBaseDepth->getStride(); |
---|
1664 | |
---|
1665 | Int widthChroma, heightChroma; |
---|
1666 | if( isDepth) |
---|
1667 | { |
---|
1668 | widthChroma = pPicBaseDepth->getWidth()>>1; |
---|
1669 | heightChroma = pPicBaseDepth->getHeight()>>1; |
---|
1670 | } |
---|
1671 | else |
---|
1672 | { |
---|
1673 | widthChroma = refPic->getWidth()>>1; |
---|
1674 | heightChroma = refPic->getHeight()>>1; |
---|
1675 | } |
---|
1676 | |
---|
1677 | // Below is only for Texture chroma component |
---|
1678 | |
---|
1679 | Int widthDepth = pPicBaseDepth->getWidth(); |
---|
1680 | Int heightDepth = pPicBaseDepth->getHeight(); |
---|
1681 | |
---|
1682 | Int nTxtPerDepthX, nTxtPerDepthY; // Number of texture samples per one depth sample |
---|
1683 | Int nDepthPerTxtX, nDepthPerTxtY; // Number of depth samples per one texture sample |
---|
1684 | |
---|
1685 | Int depthPosX; // Starting position in depth image |
---|
1686 | Int depthPosY; |
---|
1687 | |
---|
1688 | if ( widthChroma > widthDepth ) |
---|
1689 | { |
---|
1690 | nTxtPerDepthX = widthChroma / widthDepth; |
---|
1691 | nDepthPerTxtX = 1; |
---|
1692 | depthPosX = posX / nTxtPerDepthX + (mv->getHor()>>2); //mv denotes the disparity for VSP |
---|
1693 | } |
---|
1694 | else |
---|
1695 | { |
---|
1696 | nTxtPerDepthX = 1; |
---|
1697 | nDepthPerTxtX = widthDepth / widthChroma; |
---|
1698 | depthPosX = posX * nDepthPerTxtX + (mv->getHor()>>2); //mv denotes the disparity for VSP |
---|
1699 | } |
---|
1700 | depthPosX = Clip3(0, widthDepth - (size_x<<1) - 1, depthPosX); |
---|
1701 | |
---|
1702 | if ( heightChroma > heightDepth ) |
---|
1703 | { |
---|
1704 | nTxtPerDepthY = heightChroma / heightDepth; |
---|
1705 | nDepthPerTxtY = 1; |
---|
1706 | depthPosY = posY / nTxtPerDepthY + (mv->getVer()>>2); //mv denotes the disparity for VSP |
---|
1707 | } |
---|
1708 | else |
---|
1709 | { |
---|
1710 | nTxtPerDepthY = 1; |
---|
1711 | nDepthPerTxtY = heightDepth / heightChroma; |
---|
1712 | depthPosY = posY * nDepthPerTxtY + (mv->getVer()>>2); //mv denotes the disparity for VSP |
---|
1713 | } |
---|
1714 | depthPosY = Clip3(0, heightDepth - (size_y<<1) - 1, depthPosY); |
---|
1715 | |
---|
1716 | Pel *refCb = refPic->getCbAddr() + posX + posY * refStride; |
---|
1717 | Pel *refCr = refPic->getCrAddr() + posX + posY * refStride; |
---|
1718 | Pel *dstCb = dstPic->getCbAddr(partAddr); |
---|
1719 | Pel *dstCr = dstPic->getCrAddr(partAddr); |
---|
1720 | Pel *depth = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride; // move the pointer to the current depth pixel position |
---|
1721 | |
---|
1722 | Int refStrideBlock = refStride * nTxtPerDepthY; |
---|
1723 | Int dstStrideBlock = dstStride * nTxtPerDepthY; |
---|
1724 | Int depStrideBlock = depStride * nDepthPerTxtY; |
---|
1725 | |
---|
1726 | if (isDepth) |
---|
1727 | { |
---|
1728 | // DT: Since the call for this function is redundant, .. |
---|
1729 | for (Int y = 0; y < size_y; y++) |
---|
1730 | { |
---|
1731 | for (Int x = 0; x < size_x; x++) |
---|
1732 | { |
---|
1733 | dstCb[x] = 128; |
---|
1734 | dstCr[x] = 128; |
---|
1735 | } |
---|
1736 | dstCb += dstStride; |
---|
1737 | dstCr += dstStride; |
---|
1738 | } |
---|
1739 | return; |
---|
1740 | } |
---|
1741 | |
---|
1742 | if ( widthChroma > widthDepth ) // We assume |
---|
1743 | { |
---|
1744 | assert( heightChroma > heightDepth ); |
---|
1745 | printf("This branch should never been reached.\n"); |
---|
1746 | exit(0); |
---|
1747 | } |
---|
1748 | else |
---|
1749 | { |
---|
1750 | #if MERL_VSP_BLOCKSIZE_C0152 == 1 |
---|
1751 | Int dW = size_x; |
---|
1752 | Int dH = size_y; |
---|
1753 | Int sW = 2; // search window size |
---|
1754 | Int sH = 2; |
---|
1755 | #endif |
---|
1756 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1757 | Int dW = size_x; |
---|
1758 | Int dH = size_y; |
---|
1759 | Int sW = 2; // search window size |
---|
1760 | Int sH = 2; |
---|
1761 | #endif |
---|
1762 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1763 | Int dW = size_x>>1; |
---|
1764 | Int dH = size_y>>1; |
---|
1765 | Int sW = 4; // search window size |
---|
1766 | Int sH = 4; |
---|
1767 | #endif |
---|
1768 | |
---|
1769 | { |
---|
1770 | Pel* depthi = depth; |
---|
1771 | for (Int j = 0; j < dH; j++) |
---|
1772 | { |
---|
1773 | for (Int i = 0; i < dW; i++) |
---|
1774 | { |
---|
1775 | Pel* depthTmp; |
---|
1776 | #if MERL_VSP_BLOCKSIZE_C0152 == 1 |
---|
1777 | depthTmp = depthi + (i << 1); |
---|
1778 | #endif |
---|
1779 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1780 | if (depthPosX + (i<<1) < widthDepth) |
---|
1781 | depthTmp = depthi + (i << 1); |
---|
1782 | else |
---|
1783 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1784 | #endif |
---|
1785 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1786 | if (depthPosX + (i<<2) < widthDepth) |
---|
1787 | depthTmp = depthi + (i << 2); |
---|
1788 | else |
---|
1789 | depthTmp = depthi + (widthDepth - depthPosX - 1); |
---|
1790 | #endif |
---|
1791 | Int maxV = 0; |
---|
1792 | for (Int blockj = 0; blockj < sH; blockj++) |
---|
1793 | { |
---|
1794 | Int iX = 0; |
---|
1795 | for (Int blocki = 0; blocki < sW; blocki++) |
---|
1796 | { |
---|
1797 | if (maxV < depthTmp[iX]) |
---|
1798 | maxV = depthTmp[iX]; |
---|
1799 | if (depthPosX + i*sW + blocki < widthDepth - 1) |
---|
1800 | iX++; |
---|
1801 | } |
---|
1802 | if (depthPosY + j*sH + blockj < heightDepth - 1) |
---|
1803 | depthTmp += depStride; |
---|
1804 | } |
---|
1805 | m_pDepth[i+j*dW] = maxV; |
---|
1806 | } // end of i < dW |
---|
1807 | #if MERL_VSP_BLOCKSIZE_C0152 == 1 |
---|
1808 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1809 | depthi += (depStride << 1); |
---|
1810 | else |
---|
1811 | depthi = depth + (heightDepth-1)*depStride; |
---|
1812 | #endif |
---|
1813 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1814 | if (depthPosY + ((j+1)<<1) < heightDepth) |
---|
1815 | depthi += (depStride << 1); |
---|
1816 | else |
---|
1817 | depthi = depth + (heightDepth-depthPosY-1)*depStride; |
---|
1818 | #endif |
---|
1819 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1820 | if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1 |
---|
1821 | depthi += (depStride << 2); |
---|
1822 | else |
---|
1823 | depthi = depth + (heightDepth-depthPosY-1)*depStride; // the last line |
---|
1824 | #endif |
---|
1825 | } |
---|
1826 | } |
---|
1827 | |
---|
1828 | |
---|
1829 | // (size_x, size_y) is Chroma block size |
---|
1830 | for ( Int yTxt = 0, yDepth = 0; yTxt < size_y; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY ) |
---|
1831 | { |
---|
1832 | for ( Int xTxt = 0, xDepth = 0; xTxt < size_x; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX ) |
---|
1833 | { |
---|
1834 | Pel rep_depth = 0; // to store the depth value used for warping |
---|
1835 | #if MERL_VSP_BLOCKSIZE_C0152 == 1 |
---|
1836 | rep_depth = m_pDepth[(xTxt) + (yTxt)*dW]; |
---|
1837 | #endif |
---|
1838 | #if MERL_VSP_BLOCKSIZE_C0152 == 2 |
---|
1839 | rep_depth = m_pDepth[(xTxt) + (yTxt)*dW]; |
---|
1840 | #endif |
---|
1841 | #if MERL_VSP_BLOCKSIZE_C0152 == 4 |
---|
1842 | rep_depth = m_pDepth[(xTxt>>1) + (yTxt>>1)*dW]; |
---|
1843 | #endif |
---|
1844 | |
---|
1845 | // calculate the offset in the reference picture |
---|
1846 | Int disparity = pShiftLUT[ rep_depth ] << iShiftPrec; |
---|
1847 | Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image |
---|
1848 | Int xFrac = disparity & 0x7; |
---|
1849 | Int absX = posX + refOffset; |
---|
1850 | |
---|
1851 | if (xFrac == 0) |
---|
1852 | absX = Clip3(0, widthChroma-1, absX); |
---|
1853 | else |
---|
1854 | absX = Clip3(4, widthChroma-5, absX); |
---|
1855 | |
---|
1856 | refOffset = absX - posX; |
---|
1857 | |
---|
1858 | assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 ); |
---|
1859 | assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 ); |
---|
1860 | m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true); |
---|
1861 | m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, true); |
---|
1862 | } |
---|
1863 | refCb += refStrideBlock; |
---|
1864 | refCr += refStrideBlock; |
---|
1865 | dstCb += dstStrideBlock; |
---|
1866 | dstCr += dstStrideBlock; |
---|
1867 | depth += depStrideBlock; |
---|
1868 | } |
---|
1869 | } |
---|
1870 | } |
---|
1871 | |
---|
1872 | #endif // MERL_VSP_C0152 |
---|
1873 | |
---|
1874 | #if DEPTH_MAP_GENERATION |
---|
1875 | Void TComPrediction::xWeightedAveragePdm( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst, UInt uiSubSampExpX, UInt uiSubSampExpY ) |
---|
1876 | { |
---|
1877 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
1878 | { |
---|
1879 | rpcYuvDst->addAvgPdm( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY ); |
---|
1880 | } |
---|
1881 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
1882 | { |
---|
1883 | pcYuvSrc0->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY ); |
---|
1884 | } |
---|
1885 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
1886 | { |
---|
1887 | pcYuvSrc1->copyPartToPartYuvPdm( rpcYuvDst, uiPartIdx, iWidth, iHeight, uiSubSampExpX, uiSubSampExpY ); |
---|
1888 | } |
---|
1889 | else |
---|
1890 | { |
---|
1891 | assert (0); |
---|
1892 | } |
---|
1893 | } |
---|
1894 | #endif |
---|
1895 | |
---|
1896 | Void TComPrediction::xWeightedAverage( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
1897 | { |
---|
1898 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
1899 | { |
---|
1900 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
1901 | } |
---|
1902 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
1903 | { |
---|
1904 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1905 | } |
---|
1906 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
1907 | { |
---|
1908 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
1909 | } |
---|
1910 | } |
---|
1911 | |
---|
1912 | // AMVP |
---|
1913 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred ) |
---|
1914 | { |
---|
1915 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
1916 | |
---|
1917 | if( pcCU->getAMVPMode(uiPartAddr) == AM_NONE || (pcAMVPInfo->iN <= 1 && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL) ) |
---|
1918 | { |
---|
1919 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
1920 | |
---|
1921 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1922 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
1923 | return; |
---|
1924 | } |
---|
1925 | |
---|
1926 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
1927 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
1928 | return; |
---|
1929 | } |
---|
1930 | |
---|
1931 | /** Function for deriving planar intra prediction. |
---|
1932 | * \param pSrc pointer to reconstructed sample array |
---|
1933 | * \param srcStride the stride of the reconstructed sample array |
---|
1934 | * \param rpDst reference to pointer for the prediction sample array |
---|
1935 | * \param dstStride the stride of the prediction sample array |
---|
1936 | * \param width the width of the block |
---|
1937 | * \param height the height of the block |
---|
1938 | * |
---|
1939 | * This function derives the prediction samples for planar mode (intra coding). |
---|
1940 | */ |
---|
1941 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
1942 | { |
---|
1943 | assert(width == height); |
---|
1944 | |
---|
1945 | Int k, l, bottomLeft, topRight; |
---|
1946 | Int horPred; |
---|
1947 | Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
1948 | UInt blkSize = width; |
---|
1949 | UInt offset2D = width; |
---|
1950 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
1951 | UInt shift2D = shift1D + 1; |
---|
1952 | |
---|
1953 | // Get left and above reference column and row |
---|
1954 | for(k=0;k<blkSize+1;k++) |
---|
1955 | { |
---|
1956 | topRow[k] = pSrc[k-srcStride]; |
---|
1957 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
1958 | } |
---|
1959 | |
---|
1960 | // Prepare intermediate variables used in interpolation |
---|
1961 | bottomLeft = leftColumn[blkSize]; |
---|
1962 | topRight = topRow[blkSize]; |
---|
1963 | for (k=0;k<blkSize;k++) |
---|
1964 | { |
---|
1965 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
1966 | rightColumn[k] = topRight - leftColumn[k]; |
---|
1967 | topRow[k] <<= shift1D; |
---|
1968 | leftColumn[k] <<= shift1D; |
---|
1969 | } |
---|
1970 | |
---|
1971 | // Generate prediction signal |
---|
1972 | for (k=0;k<blkSize;k++) |
---|
1973 | { |
---|
1974 | horPred = leftColumn[k] + offset2D; |
---|
1975 | for (l=0;l<blkSize;l++) |
---|
1976 | { |
---|
1977 | horPred += rightColumn[k]; |
---|
1978 | topRow[l] += bottomRow[l]; |
---|
1979 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
1980 | } |
---|
1981 | } |
---|
1982 | } |
---|
1983 | |
---|
1984 | /** Function for deriving chroma LM intra prediction. |
---|
1985 | * \param pcPattern pointer to neighbouring pixel access pattern |
---|
1986 | * \param piSrc pointer to reconstructed chroma sample array |
---|
1987 | * \param pPred pointer for the prediction sample array |
---|
1988 | * \param uiPredStride the stride of the prediction sample array |
---|
1989 | * \param uiCWidth the width of the chroma block |
---|
1990 | * \param uiCHeight the height of the chroma block |
---|
1991 | * \param uiChromaId boolean indication of chroma component |
---|
1992 | * |
---|
1993 | * This function derives the prediction samples for chroma LM mode (chroma intra coding) |
---|
1994 | */ |
---|
1995 | Void TComPrediction::predLMIntraChroma( TComPattern* pcPattern, Int* piSrc, Pel* pPred, UInt uiPredStride, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId ) |
---|
1996 | { |
---|
1997 | UInt uiWidth = 2 * uiCWidth; |
---|
1998 | |
---|
1999 | xGetLLSPrediction( pcPattern, piSrc+uiWidth+2, uiWidth+1, pPred, uiPredStride, uiCWidth, uiCHeight, 1 ); |
---|
2000 | } |
---|
2001 | |
---|
2002 | /** Function for deriving downsampled luma sample of current chroma block and its above, left causal pixel |
---|
2003 | * \param pcPattern pointer to neighbouring pixel access pattern |
---|
2004 | * \param uiCWidth the width of the chroma block |
---|
2005 | * \param uiCHeight the height of the chroma block |
---|
2006 | * |
---|
2007 | * This function derives downsampled luma sample of current chroma block and its above, left causal pixel |
---|
2008 | */ |
---|
2009 | Void TComPrediction::getLumaRecPixels( TComPattern* pcPattern, UInt uiCWidth, UInt uiCHeight ) |
---|
2010 | { |
---|
2011 | UInt uiWidth = 2 * uiCWidth; |
---|
2012 | UInt uiHeight = 2 * uiCHeight; |
---|
2013 | |
---|
2014 | Pel* pRecSrc = pcPattern->getROIY(); |
---|
2015 | Pel* pDst0 = m_pLumaRecBuffer + m_iLumaRecStride + 1; |
---|
2016 | |
---|
2017 | Int iRecSrcStride = pcPattern->getPatternLStride(); |
---|
2018 | Int iRecSrcStride2 = iRecSrcStride << 1; |
---|
2019 | Int iDstStride = m_iLumaRecStride; |
---|
2020 | Int iSrcStride = ( max( uiWidth, uiHeight ) << 1 ) + 1; |
---|
2021 | |
---|
2022 | Int* ptrSrc = pcPattern->getAdiOrgBuf( uiWidth, uiHeight, m_piYuvExt ); |
---|
2023 | |
---|
2024 | // initial pointers |
---|
2025 | Pel* pDst = pDst0 - 1 - iDstStride; |
---|
2026 | Int* piSrc = ptrSrc; |
---|
2027 | |
---|
2028 | // top left corner downsampled from ADI buffer |
---|
2029 | // don't need this point |
---|
2030 | |
---|
2031 | // top row downsampled from ADI buffer |
---|
2032 | pDst++; |
---|
2033 | piSrc ++; |
---|
2034 | for (Int i = 0; i < uiCWidth; i++) |
---|
2035 | { |
---|
2036 | pDst[i] = ((piSrc[2*i] * 2 ) + piSrc[2*i - 1] + piSrc[2*i + 1] + 2) >> 2; |
---|
2037 | } |
---|
2038 | |
---|
2039 | // left column downsampled from ADI buffer |
---|
2040 | pDst = pDst0 - 1; |
---|
2041 | piSrc = ptrSrc + iSrcStride; |
---|
2042 | for (Int j = 0; j < uiCHeight; j++) |
---|
2043 | { |
---|
2044 | pDst[0] = ( piSrc[0] + piSrc[iSrcStride] ) >> 1; |
---|
2045 | piSrc += iSrcStride << 1; |
---|
2046 | pDst += iDstStride; |
---|
2047 | } |
---|
2048 | |
---|
2049 | // inner part from reconstructed picture buffer |
---|
2050 | for( Int j = 0; j < uiCHeight; j++ ) |
---|
2051 | { |
---|
2052 | for (Int i = 0; i < uiCWidth; i++) |
---|
2053 | { |
---|
2054 | pDst0[i] = (pRecSrc[2*i] + pRecSrc[2*i + iRecSrcStride]) >> 1; |
---|
2055 | } |
---|
2056 | |
---|
2057 | pDst0 += iDstStride; |
---|
2058 | pRecSrc += iRecSrcStride2; |
---|
2059 | } |
---|
2060 | } |
---|
2061 | |
---|
2062 | /** Function for deriving the positon of first non-zero binary bit of a value |
---|
2063 | * \param x input value |
---|
2064 | * |
---|
2065 | * This function derives the positon of first non-zero binary bit of a value |
---|
2066 | */ |
---|
2067 | Int GetMSB( UInt x ) |
---|
2068 | { |
---|
2069 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
2070 | |
---|
2071 | while( x > 1 ) |
---|
2072 | { |
---|
2073 | bits >>= 1; |
---|
2074 | y = x >> bits; |
---|
2075 | |
---|
2076 | if( y ) |
---|
2077 | { |
---|
2078 | x = y; |
---|
2079 | iMSB += bits; |
---|
2080 | } |
---|
2081 | } |
---|
2082 | |
---|
2083 | iMSB+=y; |
---|
2084 | |
---|
2085 | return iMSB; |
---|
2086 | } |
---|
2087 | |
---|
2088 | /** Function for counting leading number of zeros/ones |
---|
2089 | * \param x input value |
---|
2090 | \ This function counts leading number of zeros for positive numbers and |
---|
2091 | \ leading number of ones for negative numbers. This can be implemented in |
---|
2092 | \ single instructure cycle on many processors. |
---|
2093 | */ |
---|
2094 | |
---|
2095 | Short CountLeadingZerosOnes (Short x) |
---|
2096 | { |
---|
2097 | Short clz; |
---|
2098 | Short i; |
---|
2099 | |
---|
2100 | if(x == 0) |
---|
2101 | { |
---|
2102 | clz = 0; |
---|
2103 | } |
---|
2104 | else |
---|
2105 | { |
---|
2106 | if (x == -1) |
---|
2107 | { |
---|
2108 | clz = 15; |
---|
2109 | } |
---|
2110 | else |
---|
2111 | { |
---|
2112 | if(x < 0) |
---|
2113 | { |
---|
2114 | x = ~x; |
---|
2115 | } |
---|
2116 | clz = 15; |
---|
2117 | for(i = 0;i < 15;++i) |
---|
2118 | { |
---|
2119 | if(x) |
---|
2120 | { |
---|
2121 | clz --; |
---|
2122 | } |
---|
2123 | x = x >> 1; |
---|
2124 | } |
---|
2125 | } |
---|
2126 | } |
---|
2127 | return clz; |
---|
2128 | } |
---|
2129 | |
---|
2130 | /** Function for deriving LM intra prediction. |
---|
2131 | * \param pcPattern pointer to neighbouring pixel access pattern |
---|
2132 | * \param pSrc0 pointer to reconstructed chroma sample array |
---|
2133 | * \param iSrcStride the stride of reconstructed chroma sample array |
---|
2134 | * \param pDst0 reference to pointer for the prediction sample array |
---|
2135 | * \param iDstStride the stride of the prediction sample array |
---|
2136 | * \param uiWidth the width of the chroma block |
---|
2137 | * \param uiHeight the height of the chroma block |
---|
2138 | * \param uiExt0 line number of neiggboirng pixels for calculating LM model parameter, default value is 1 |
---|
2139 | * |
---|
2140 | * This function derives the prediction samples for chroma LM mode (chroma intra coding) |
---|
2141 | */ |
---|
2142 | Void TComPrediction::xGetLLSPrediction( TComPattern* pcPattern, Int* pSrc0, Int iSrcStride, Pel* pDst0, Int iDstStride, UInt uiWidth, UInt uiHeight, UInt uiExt0 ) |
---|
2143 | { |
---|
2144 | |
---|
2145 | Pel *pDst, *pLuma; |
---|
2146 | Int *pSrc; |
---|
2147 | |
---|
2148 | Int iLumaStride = m_iLumaRecStride; |
---|
2149 | Pel* pLuma0 = m_pLumaRecBuffer + uiExt0 * iLumaStride + uiExt0; |
---|
2150 | |
---|
2151 | Int i, j, iCountShift = 0; |
---|
2152 | |
---|
2153 | UInt uiExt = uiExt0; |
---|
2154 | |
---|
2155 | // LLS parameters estimation --> |
---|
2156 | |
---|
2157 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2158 | |
---|
2159 | pSrc = pSrc0 - iSrcStride; |
---|
2160 | pLuma = pLuma0 - iLumaStride; |
---|
2161 | |
---|
2162 | for( j = 0; j < uiWidth; j++ ) |
---|
2163 | { |
---|
2164 | x += pLuma[j]; |
---|
2165 | y += pSrc[j]; |
---|
2166 | xx += pLuma[j] * pLuma[j]; |
---|
2167 | xy += pLuma[j] * pSrc[j]; |
---|
2168 | } |
---|
2169 | iCountShift += g_aucConvertToBit[ uiWidth ] + 2; |
---|
2170 | |
---|
2171 | pSrc = pSrc0 - uiExt; |
---|
2172 | pLuma = pLuma0 - uiExt; |
---|
2173 | |
---|
2174 | for( i = 0; i < uiHeight; i++ ) |
---|
2175 | { |
---|
2176 | x += pLuma[0]; |
---|
2177 | y += pSrc[0]; |
---|
2178 | xx += pLuma[0] * pLuma[0]; |
---|
2179 | xy += pLuma[0] * pSrc[0]; |
---|
2180 | |
---|
2181 | pSrc += iSrcStride; |
---|
2182 | pLuma += iLumaStride; |
---|
2183 | } |
---|
2184 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 ); |
---|
2185 | |
---|
2186 | Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15; |
---|
2187 | |
---|
2188 | if(iTempShift > 0) |
---|
2189 | { |
---|
2190 | x = ( x + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2191 | y = ( y + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2192 | xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2193 | xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2194 | iCountShift -= iTempShift; |
---|
2195 | } |
---|
2196 | |
---|
2197 | Int a, b, iShift = 13; |
---|
2198 | |
---|
2199 | if( iCountShift == 0 ) |
---|
2200 | { |
---|
2201 | a = 0; |
---|
2202 | b = 1 << (g_uiBitDepth + g_uiBitIncrement - 1); |
---|
2203 | iShift = 0; |
---|
2204 | } |
---|
2205 | else |
---|
2206 | { |
---|
2207 | Int a1 = ( xy << iCountShift ) - y * x; |
---|
2208 | Int a2 = ( xx << iCountShift ) - x * x; |
---|
2209 | |
---|
2210 | { |
---|
2211 | const Int iShiftA2 = 6; |
---|
2212 | const Int iShiftA1 = 15; |
---|
2213 | const Int iAccuracyShift = 15; |
---|
2214 | |
---|
2215 | Int iScaleShiftA2 = 0; |
---|
2216 | Int iScaleShiftA1 = 0; |
---|
2217 | Int a1s = a1; |
---|
2218 | Int a2s = a2; |
---|
2219 | |
---|
2220 | iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1; |
---|
2221 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2222 | |
---|
2223 | if( iScaleShiftA1 < 0 ) |
---|
2224 | { |
---|
2225 | iScaleShiftA1 = 0; |
---|
2226 | } |
---|
2227 | |
---|
2228 | if( iScaleShiftA2 < 0 ) |
---|
2229 | { |
---|
2230 | iScaleShiftA2 = 0; |
---|
2231 | } |
---|
2232 | |
---|
2233 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2234 | |
---|
2235 | a2s = a2 >> iScaleShiftA2; |
---|
2236 | |
---|
2237 | a1s = a1 >> iScaleShiftA1; |
---|
2238 | |
---|
2239 | if (a2s >= 1) |
---|
2240 | { |
---|
2241 | a = a1s * m_uiaShift[ a2s - 1]; |
---|
2242 | } |
---|
2243 | else |
---|
2244 | { |
---|
2245 | a = 0; |
---|
2246 | } |
---|
2247 | |
---|
2248 | if( iScaleShiftA < 0 ) |
---|
2249 | { |
---|
2250 | a = a << -iScaleShiftA; |
---|
2251 | } |
---|
2252 | else |
---|
2253 | { |
---|
2254 | a = a >> iScaleShiftA; |
---|
2255 | } |
---|
2256 | |
---|
2257 | a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a); |
---|
2258 | |
---|
2259 | Int minA = -(1 << (6)); |
---|
2260 | Int maxA = (1 << 6) - 1; |
---|
2261 | if( a <= maxA && a >= minA ) |
---|
2262 | { |
---|
2263 | // do nothing |
---|
2264 | } |
---|
2265 | else |
---|
2266 | { |
---|
2267 | Short n = CountLeadingZerosOnes(a); |
---|
2268 | a = a >> (9-n); |
---|
2269 | iShift -= (9-n); |
---|
2270 | } |
---|
2271 | |
---|
2272 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2273 | } |
---|
2274 | } |
---|
2275 | |
---|
2276 | // <-- end of LLS parameters estimation |
---|
2277 | |
---|
2278 | // get prediction --> |
---|
2279 | uiExt = uiExt0; |
---|
2280 | pLuma = pLuma0; |
---|
2281 | pDst = pDst0; |
---|
2282 | |
---|
2283 | for( i = 0; i < uiHeight; i++ ) |
---|
2284 | { |
---|
2285 | for( j = 0; j < uiWidth; j++ ) |
---|
2286 | { |
---|
2287 | pDst[j] = Clip( ( ( a * pLuma[j] ) >> iShift ) + b ); |
---|
2288 | } |
---|
2289 | |
---|
2290 | pDst += iDstStride; |
---|
2291 | pLuma += iLumaStride; |
---|
2292 | } |
---|
2293 | // <-- end of get prediction |
---|
2294 | |
---|
2295 | } |
---|
2296 | |
---|
2297 | |
---|
2298 | #if LGE_ILLUCOMP_B0045 |
---|
2299 | /** Function for deriving LM illumination compensation. |
---|
2300 | */ |
---|
2301 | Void TComPrediction::xGetLLSICPrediction(TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift) |
---|
2302 | { |
---|
2303 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
2304 | Pel *pRec, *pRef; |
---|
2305 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
2306 | Int iRecStride = pRecPic->getStride(), iRefStride = pRefPic->getStride(); |
---|
2307 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset; |
---|
2308 | |
---|
2309 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2310 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2311 | iRefX = iCUPelX + (pMv->getHor() >> 2); |
---|
2312 | iRefY = iCUPelY + (pMv->getVer() >> 2); |
---|
2313 | uiWidth = pcCU->getWidth(0); |
---|
2314 | uiHeight = pcCU->getHeight(0); |
---|
2315 | |
---|
2316 | Int i, j, iCountShift = 0; |
---|
2317 | |
---|
2318 | // LLS parameters estimation --> |
---|
2319 | |
---|
2320 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2321 | |
---|
2322 | if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0) |
---|
2323 | { |
---|
2324 | iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - iRefStride; |
---|
2325 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2326 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2327 | |
---|
2328 | for( j = 0; j < uiWidth; j++ ) |
---|
2329 | { |
---|
2330 | x += pRef[j]; |
---|
2331 | y += pRec[j]; |
---|
2332 | xx += pRef[j] * pRef[j]; |
---|
2333 | xy += pRef[j] * pRec[j]; |
---|
2334 | } |
---|
2335 | iCountShift += g_aucConvertToBit[ uiWidth ] + 2; |
---|
2336 | } |
---|
2337 | |
---|
2338 | |
---|
2339 | if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0) |
---|
2340 | { |
---|
2341 | iRefOffset = ( pMv->getHor() >> 2 ) + ( pMv->getVer() >> 2 ) * iRefStride - 1; |
---|
2342 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2343 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2344 | |
---|
2345 | for( i = 0; i < uiHeight; i++ ) |
---|
2346 | { |
---|
2347 | x += pRef[0]; |
---|
2348 | y += pRec[0]; |
---|
2349 | xx += pRef[0] * pRef[0]; |
---|
2350 | xy += pRef[0] * pRec[0]; |
---|
2351 | |
---|
2352 | pRef += iRefStride; |
---|
2353 | pRec += iRecStride; |
---|
2354 | } |
---|
2355 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 ); |
---|
2356 | } |
---|
2357 | |
---|
2358 | Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15; |
---|
2359 | |
---|
2360 | if(iTempShift > 0) |
---|
2361 | { |
---|
2362 | x = ( x + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2363 | y = ( y + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2364 | xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2365 | xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2366 | iCountShift -= iTempShift; |
---|
2367 | } |
---|
2368 | |
---|
2369 | iShift = 13; |
---|
2370 | |
---|
2371 | if( iCountShift == 0 ) |
---|
2372 | { |
---|
2373 | a = 1; |
---|
2374 | b = 0; |
---|
2375 | iShift = 0; |
---|
2376 | } |
---|
2377 | else |
---|
2378 | { |
---|
2379 | Int a1 = ( xy << iCountShift ) - y * x; |
---|
2380 | Int a2 = ( xx << iCountShift ) - x * x; |
---|
2381 | |
---|
2382 | { |
---|
2383 | const Int iShiftA2 = 6; |
---|
2384 | const Int iShiftA1 = 15; |
---|
2385 | const Int iAccuracyShift = 15; |
---|
2386 | |
---|
2387 | Int iScaleShiftA2 = 0; |
---|
2388 | Int iScaleShiftA1 = 0; |
---|
2389 | Int a1s = a1; |
---|
2390 | Int a2s = a2; |
---|
2391 | |
---|
2392 | iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1; |
---|
2393 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2394 | |
---|
2395 | if( iScaleShiftA1 < 0 ) |
---|
2396 | { |
---|
2397 | iScaleShiftA1 = 0; |
---|
2398 | } |
---|
2399 | |
---|
2400 | if( iScaleShiftA2 < 0 ) |
---|
2401 | { |
---|
2402 | iScaleShiftA2 = 0; |
---|
2403 | } |
---|
2404 | |
---|
2405 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2406 | |
---|
2407 | a2s = a2 >> iScaleShiftA2; |
---|
2408 | |
---|
2409 | a1s = a1 >> iScaleShiftA1; |
---|
2410 | |
---|
2411 | if (a2s >= 1) |
---|
2412 | { |
---|
2413 | a = a1s * m_uiaShift[ a2s - 1]; |
---|
2414 | } |
---|
2415 | else |
---|
2416 | { |
---|
2417 | a = 0; |
---|
2418 | } |
---|
2419 | |
---|
2420 | if( iScaleShiftA < 0 ) |
---|
2421 | { |
---|
2422 | a = a << -iScaleShiftA; |
---|
2423 | } |
---|
2424 | else |
---|
2425 | { |
---|
2426 | a = a >> iScaleShiftA; |
---|
2427 | } |
---|
2428 | |
---|
2429 | a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a); |
---|
2430 | |
---|
2431 | Int minA = -(1 << (6)); |
---|
2432 | Int maxA = (1 << 6) - 1; |
---|
2433 | if( a <= maxA && a >= minA ) |
---|
2434 | { |
---|
2435 | // do nothing |
---|
2436 | } |
---|
2437 | else |
---|
2438 | { |
---|
2439 | Short n = CountLeadingZerosOnes(a); |
---|
2440 | a = a >> (9-n); |
---|
2441 | iShift -= (9-n); |
---|
2442 | } |
---|
2443 | |
---|
2444 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2445 | } |
---|
2446 | } |
---|
2447 | } |
---|
2448 | |
---|
2449 | Void TComPrediction::xGetLLSICPredictionChroma(TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, Int &iShift, Int iChromaId) |
---|
2450 | { |
---|
2451 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
2452 | Pel *pRec = NULL, *pRef = NULL; |
---|
2453 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
2454 | Int iRecStride = pRecPic->getCStride(), iRefStride = pRefPic->getCStride(); |
---|
2455 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset; |
---|
2456 | |
---|
2457 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2458 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
2459 | iRefX = iCUPelX + (pMv->getHor() >> 3); |
---|
2460 | iRefY = iCUPelY + (pMv->getVer() >> 3); |
---|
2461 | uiWidth = pcCU->getWidth(0) >> 1; |
---|
2462 | uiHeight = pcCU->getHeight(0) >> 1; |
---|
2463 | |
---|
2464 | Int i, j, iCountShift = 0; |
---|
2465 | |
---|
2466 | // LLS parameters estimation --> |
---|
2467 | |
---|
2468 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
2469 | |
---|
2470 | if(pcCU->getPUAbove(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelY > 0 && iRefY > 0) |
---|
2471 | { |
---|
2472 | iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - iRefStride; |
---|
2473 | if (iChromaId == 0) // Cb |
---|
2474 | { |
---|
2475 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2476 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2477 | } |
---|
2478 | else if (iChromaId == 1) // Cr |
---|
2479 | { |
---|
2480 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2481 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
2482 | } |
---|
2483 | |
---|
2484 | for( j = 0; j < uiWidth; j++ ) |
---|
2485 | { |
---|
2486 | x += pRef[j]; |
---|
2487 | y += pRec[j]; |
---|
2488 | xx += pRef[j] * pRef[j]; |
---|
2489 | xy += pRef[j] * pRec[j]; |
---|
2490 | } |
---|
2491 | iCountShift += g_aucConvertToBit[ uiWidth ] + 2; |
---|
2492 | } |
---|
2493 | |
---|
2494 | |
---|
2495 | if(pcCU->getPULeft(uiTmpPartIdx, pcCU->getZorderIdxInCU()) && iCUPelX > 0 && iRefX > 0) |
---|
2496 | { |
---|
2497 | iRefOffset = ( pMv->getHor() >> 3 ) + ( pMv->getVer() >> 3 ) * iRefStride - 1; |
---|
2498 | if (iChromaId == 0) // Cb |
---|
2499 | { |
---|
2500 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2501 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2502 | } |
---|
2503 | else if (iChromaId == 1) // Cr |
---|
2504 | { |
---|
2505 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
2506 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
2507 | } |
---|
2508 | |
---|
2509 | for( i = 0; i < uiHeight; i++ ) |
---|
2510 | { |
---|
2511 | x += pRef[0]; |
---|
2512 | y += pRec[0]; |
---|
2513 | xx += pRef[0] * pRef[0]; |
---|
2514 | xy += pRef[0] * pRec[0]; |
---|
2515 | |
---|
2516 | pRef += iRefStride; |
---|
2517 | pRec += iRecStride; |
---|
2518 | } |
---|
2519 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 2 ); |
---|
2520 | } |
---|
2521 | |
---|
2522 | Int iTempShift = ( g_uiBitDepth + g_uiBitIncrement ) + g_aucConvertToBit[ uiWidth ] + 3 - 15; |
---|
2523 | |
---|
2524 | if(iTempShift > 0) |
---|
2525 | { |
---|
2526 | x = ( x + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2527 | y = ( y + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2528 | xx = ( xx + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2529 | xy = ( xy + ( 1 << ( iTempShift - 1 ) ) ) >> iTempShift; |
---|
2530 | iCountShift -= iTempShift; |
---|
2531 | } |
---|
2532 | |
---|
2533 | iShift = 13; |
---|
2534 | |
---|
2535 | if( iCountShift == 0 ) |
---|
2536 | { |
---|
2537 | a = 1; |
---|
2538 | b = 0; |
---|
2539 | iShift = 0; |
---|
2540 | } |
---|
2541 | else |
---|
2542 | { |
---|
2543 | Int a1 = ( xy << iCountShift ) - y * x; |
---|
2544 | Int a2 = ( xx << iCountShift ) - x * x; |
---|
2545 | |
---|
2546 | { |
---|
2547 | const Int iShiftA2 = 6; |
---|
2548 | const Int iShiftA1 = 15; |
---|
2549 | const Int iAccuracyShift = 15; |
---|
2550 | |
---|
2551 | Int iScaleShiftA2 = 0; |
---|
2552 | Int iScaleShiftA1 = 0; |
---|
2553 | Int a1s = a1; |
---|
2554 | Int a2s = a2; |
---|
2555 | |
---|
2556 | iScaleShiftA1 = GetMSB( abs( a1 ) ) - iShiftA1; |
---|
2557 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
2558 | |
---|
2559 | if( iScaleShiftA1 < 0 ) |
---|
2560 | { |
---|
2561 | iScaleShiftA1 = 0; |
---|
2562 | } |
---|
2563 | |
---|
2564 | if( iScaleShiftA2 < 0 ) |
---|
2565 | { |
---|
2566 | iScaleShiftA2 = 0; |
---|
2567 | } |
---|
2568 | |
---|
2569 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
2570 | |
---|
2571 | a2s = a2 >> iScaleShiftA2; |
---|
2572 | |
---|
2573 | a1s = a1 >> iScaleShiftA1; |
---|
2574 | |
---|
2575 | if (a2s >= 1) |
---|
2576 | { |
---|
2577 | a = a1s * m_uiaShift[ a2s - 1]; |
---|
2578 | } |
---|
2579 | else |
---|
2580 | { |
---|
2581 | a = 0; |
---|
2582 | } |
---|
2583 | |
---|
2584 | if( iScaleShiftA < 0 ) |
---|
2585 | { |
---|
2586 | a = a << -iScaleShiftA; |
---|
2587 | } |
---|
2588 | else |
---|
2589 | { |
---|
2590 | a = a >> iScaleShiftA; |
---|
2591 | } |
---|
2592 | |
---|
2593 | a = Clip3(-( 1 << 15 ), ( 1 << 15 ) - 1, a); |
---|
2594 | |
---|
2595 | Int minA = -(1 << (6)); |
---|
2596 | Int maxA = (1 << 6) - 1; |
---|
2597 | if( a <= maxA && a >= minA ) |
---|
2598 | { |
---|
2599 | // do nothing |
---|
2600 | } |
---|
2601 | else |
---|
2602 | { |
---|
2603 | Short n = CountLeadingZerosOnes(a); |
---|
2604 | a = a >> (9-n); |
---|
2605 | iShift -= (9-n); |
---|
2606 | } |
---|
2607 | |
---|
2608 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
2609 | } |
---|
2610 | } |
---|
2611 | } |
---|
2612 | #endif |
---|
2613 | /** Function for filtering intra DC predictor. |
---|
2614 | * \param pSrc pointer to reconstructed sample array |
---|
2615 | * \param iSrcStride the stride of the reconstructed sample array |
---|
2616 | * \param rpDst reference to pointer for the prediction sample array |
---|
2617 | * \param iDstStride the stride of the prediction sample array |
---|
2618 | * \param iWidth the width of the block |
---|
2619 | * \param iHeight the height of the block |
---|
2620 | * |
---|
2621 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
2622 | */ |
---|
2623 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
2624 | { |
---|
2625 | Pel* pDst = rpDst; |
---|
2626 | Int x, y, iDstStride2, iSrcStride2; |
---|
2627 | |
---|
2628 | // boundary pixels processing |
---|
2629 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
2630 | |
---|
2631 | for ( x = 1; x < iWidth; x++ ) |
---|
2632 | { |
---|
2633 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
2634 | } |
---|
2635 | |
---|
2636 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
2637 | { |
---|
2638 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
2639 | } |
---|
2640 | |
---|
2641 | return; |
---|
2642 | } |
---|
2643 | |
---|
2644 | #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX |
---|
2645 | Void TComPrediction::predIntraLumaDMM( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder ) |
---|
2646 | { |
---|
2647 | #if HHI_DMM_WEDGE_INTRA |
---|
2648 | if( uiMode == DMM_WEDGE_FULL_IDX ) { xPredIntraWedgeFull ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgeFullTabIdx ( uiAbsPartIdx ) ); } |
---|
2649 | if( uiMode == DMM_WEDGE_FULL_D_IDX ) { xPredIntraWedgeFull ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getWedgeFullTabIdx( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC1( uiAbsPartIdx ), pcCU->getWedgeFullDeltaDC2( uiAbsPartIdx ) ); } |
---|
2650 | if( uiMode == DMM_WEDGE_PREDDIR_IDX ) { xPredIntraWedgeDir ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false, pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ) ); } |
---|
2651 | if( uiMode == DMM_WEDGE_PREDDIR_D_IDX ) { xPredIntraWedgeDir ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getWedgePredDirDeltaEnd( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredDirDeltaDC2( uiAbsPartIdx ) ); } |
---|
2652 | #endif |
---|
2653 | #if HHI_DMM_PRED_TEX |
---|
2654 | if( uiMode == DMM_WEDGE_PREDTEX_IDX ) { xPredIntraWedgeTex ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); } |
---|
2655 | if( uiMode == DMM_WEDGE_PREDTEX_D_IDX ) { xPredIntraWedgeTex ( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getWedgePredTexDeltaDC1( uiAbsPartIdx ), pcCU->getWedgePredTexDeltaDC2( uiAbsPartIdx ) ); } |
---|
2656 | if( uiMode == DMM_CONTOUR_PREDTEX_IDX ) { xPredIntraContourTex( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, false ); } |
---|
2657 | if( uiMode == DMM_CONTOUR_PREDTEX_D_IDX ) { xPredIntraContourTex( pcCU, uiAbsPartIdx, piPred, uiStride, iWidth, iHeight, bAbove, bLeft, bEncoder, true, pcCU->getContourPredTexDeltaDC1( uiAbsPartIdx ), pcCU->getContourPredTexDeltaDC2( uiAbsPartIdx ) ); } |
---|
2658 | #endif |
---|
2659 | } |
---|
2660 | |
---|
2661 | Void TComPrediction::getWedgePredDCs( TComWedgelet* pcWedgelet, Int* piMask, Int iMaskStride, Int& riPredDC1, Int& riPredDC2, Bool bAbove, Bool bLeft ) |
---|
2662 | { |
---|
2663 | riPredDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); //pred val, if no neighbors are available |
---|
2664 | riPredDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); |
---|
2665 | |
---|
2666 | if( !bAbove && !bLeft ) { return; } |
---|
2667 | |
---|
2668 | UInt uiNumSmpDC1 = 0, uiNumSmpDC2 = 0; |
---|
2669 | Int iPredDC1 = 0, iPredDC2 = 0; |
---|
2670 | |
---|
2671 | Bool* pabWedgePattern = pcWedgelet->getPattern(); |
---|
2672 | UInt uiWedgeStride = pcWedgelet->getStride(); |
---|
2673 | |
---|
2674 | if( bAbove ) |
---|
2675 | { |
---|
2676 | for( Int k = 0; k < pcWedgelet->getWidth(); k++ ) |
---|
2677 | { |
---|
2678 | if( true == pabWedgePattern[k] ) |
---|
2679 | { |
---|
2680 | iPredDC2 += piMask[k-iMaskStride]; |
---|
2681 | uiNumSmpDC2++; |
---|
2682 | } |
---|
2683 | else |
---|
2684 | { |
---|
2685 | iPredDC1 += piMask[k-iMaskStride]; |
---|
2686 | uiNumSmpDC1++; |
---|
2687 | } |
---|
2688 | } |
---|
2689 | } |
---|
2690 | if( bLeft ) |
---|
2691 | { |
---|
2692 | for( Int k = 0; k < pcWedgelet->getHeight(); k++ ) |
---|
2693 | { |
---|
2694 | if( true == pabWedgePattern[k*uiWedgeStride] ) |
---|
2695 | { |
---|
2696 | iPredDC2 += piMask[k*iMaskStride-1]; |
---|
2697 | uiNumSmpDC2++; |
---|
2698 | } |
---|
2699 | else |
---|
2700 | { |
---|
2701 | iPredDC1 += piMask[k*iMaskStride-1]; |
---|
2702 | uiNumSmpDC1++; |
---|
2703 | } |
---|
2704 | } |
---|
2705 | } |
---|
2706 | |
---|
2707 | if( uiNumSmpDC1 > 0 ) |
---|
2708 | { |
---|
2709 | iPredDC1 /= uiNumSmpDC1; |
---|
2710 | riPredDC1 = iPredDC1; |
---|
2711 | } |
---|
2712 | if( uiNumSmpDC2 > 0 ) |
---|
2713 | { |
---|
2714 | iPredDC2 /= uiNumSmpDC2; |
---|
2715 | riPredDC2 = iPredDC2; |
---|
2716 | } |
---|
2717 | } |
---|
2718 | |
---|
2719 | Void TComPrediction::calcWedgeDCs( TComWedgelet* pcWedgelet, Pel* piOrig, UInt uiStride, Int& riDC1, Int& riDC2 ) |
---|
2720 | { |
---|
2721 | UInt uiDC1 = 0; |
---|
2722 | UInt uiDC2 = 0; |
---|
2723 | UInt uiNumPixDC1 = 0, uiNumPixDC2 = 0; |
---|
2724 | Bool* pabWedgePattern = pcWedgelet->getPattern(); |
---|
2725 | if( uiStride == pcWedgelet->getStride() ) |
---|
2726 | { |
---|
2727 | for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ ) |
---|
2728 | { |
---|
2729 | if( true == pabWedgePattern[k] ) |
---|
2730 | { |
---|
2731 | uiDC2 += piOrig[k]; |
---|
2732 | uiNumPixDC2++; |
---|
2733 | } |
---|
2734 | else |
---|
2735 | { |
---|
2736 | uiDC1 += piOrig[k]; |
---|
2737 | uiNumPixDC1++; |
---|
2738 | } |
---|
2739 | } |
---|
2740 | } |
---|
2741 | else |
---|
2742 | { |
---|
2743 | Pel* piTemp = piOrig; |
---|
2744 | UInt uiWedgeStride = pcWedgelet->getStride(); |
---|
2745 | for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ ) |
---|
2746 | { |
---|
2747 | for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ ) |
---|
2748 | { |
---|
2749 | if( true == pabWedgePattern[uiX] ) |
---|
2750 | { |
---|
2751 | uiDC2 += piTemp[uiX]; |
---|
2752 | uiNumPixDC2++; |
---|
2753 | } |
---|
2754 | else |
---|
2755 | { |
---|
2756 | uiDC1 += piTemp[uiX]; |
---|
2757 | uiNumPixDC1++; |
---|
2758 | } |
---|
2759 | } |
---|
2760 | piTemp += uiStride; |
---|
2761 | pabWedgePattern += uiWedgeStride; |
---|
2762 | } |
---|
2763 | } |
---|
2764 | |
---|
2765 | if( uiNumPixDC1 > 0 ) { riDC1 = uiDC1 / uiNumPixDC1; } |
---|
2766 | else { riDC1 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); } |
---|
2767 | |
---|
2768 | if( uiNumPixDC2 > 0 ) { riDC2 = uiDC2 / uiNumPixDC2; } |
---|
2769 | else { riDC2 = ( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); } |
---|
2770 | } |
---|
2771 | |
---|
2772 | Void TComPrediction::assignWedgeDCs2Pred( TComWedgelet* pcWedgelet, Pel* piPred, UInt uiStride, Int iDC1, Int iDC2 ) |
---|
2773 | { |
---|
2774 | Bool* pabWedgePattern = pcWedgelet->getPattern(); |
---|
2775 | |
---|
2776 | if( uiStride == pcWedgelet->getStride() ) |
---|
2777 | { |
---|
2778 | for( UInt k = 0; k < (pcWedgelet->getWidth() * pcWedgelet->getHeight()); k++ ) |
---|
2779 | { |
---|
2780 | if( true == pabWedgePattern[k] ) |
---|
2781 | { |
---|
2782 | piPred[k] = iDC2; |
---|
2783 | } |
---|
2784 | else |
---|
2785 | { |
---|
2786 | piPred[k] = iDC1; |
---|
2787 | } |
---|
2788 | } |
---|
2789 | } |
---|
2790 | else |
---|
2791 | { |
---|
2792 | Pel* piTemp = piPred; |
---|
2793 | UInt uiWedgeStride = pcWedgelet->getStride(); |
---|
2794 | for( UInt uiY = 0; uiY < pcWedgelet->getHeight(); uiY++ ) |
---|
2795 | { |
---|
2796 | for( UInt uiX = 0; uiX < pcWedgelet->getWidth(); uiX++ ) |
---|
2797 | { |
---|
2798 | if( true == pabWedgePattern[uiX] ) |
---|
2799 | { |
---|
2800 | piTemp[uiX] = iDC2; |
---|
2801 | } |
---|
2802 | else |
---|
2803 | { |
---|
2804 | piTemp[uiX] = iDC1; |
---|
2805 | } |
---|
2806 | } |
---|
2807 | piTemp += uiStride; |
---|
2808 | pabWedgePattern += uiWedgeStride; |
---|
2809 | } |
---|
2810 | } |
---|
2811 | } |
---|
2812 | |
---|
2813 | Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Int& riDeltaDC ) |
---|
2814 | { |
---|
2815 | Int iSign = riDeltaDC < 0 ? -1 : 1; |
---|
2816 | UInt uiAbs = abs( riDeltaDC ); |
---|
2817 | |
---|
2818 | Int iQp = pcCU->getQP(0); |
---|
2819 | Double dMax = (Double)( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); |
---|
2820 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 + g_iDeltaDCsQuantOffset ) ); |
---|
2821 | |
---|
2822 | riDeltaDC = iSign * roftoi( uiAbs * dStepSize ); |
---|
2823 | return; |
---|
2824 | } |
---|
2825 | |
---|
2826 | Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU* pcCU, Int& riDeltaDC ) |
---|
2827 | { |
---|
2828 | Int iSign = riDeltaDC < 0 ? -1 : 1; |
---|
2829 | UInt uiAbs = abs( riDeltaDC ); |
---|
2830 | |
---|
2831 | Int iQp = pcCU->getQP(0); |
---|
2832 | Double dMax = (Double)( 1<<( g_uiBitDepth + g_uiBitIncrement - 1) ); |
---|
2833 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 + g_iDeltaDCsQuantOffset ) ); |
---|
2834 | |
---|
2835 | riDeltaDC = iSign * roftoi( uiAbs / dStepSize ); |
---|
2836 | return; |
---|
2837 | } |
---|
2838 | #endif |
---|
2839 | |
---|
2840 | #if HHI_DMM_PRED_TEX |
---|
2841 | Void TComPrediction::getBestContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
2842 | { |
---|
2843 | pcContourWedge->clear(); |
---|
2844 | |
---|
2845 | // get copy of co-located texture luma block |
---|
2846 | TComYuv cTempYuv; |
---|
2847 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2848 | cTempYuv.clear(); |
---|
2849 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2850 | copyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2851 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2852 | |
---|
2853 | // find contour for texture luma block |
---|
2854 | UInt iDC = 0; |
---|
2855 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2856 | { |
---|
2857 | iDC += piRefBlkY[k]; |
---|
2858 | } |
---|
2859 | iDC /= (uiWidth*uiHeight); |
---|
2860 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2861 | |
---|
2862 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
2863 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
2864 | { |
---|
2865 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
2866 | } |
---|
2867 | |
---|
2868 | cTempYuv.destroy(); |
---|
2869 | } |
---|
2870 | |
---|
2871 | UInt TComPrediction::getBestWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight ) |
---|
2872 | { |
---|
2873 | assert( uiWidth >= DMM_WEDGEMODEL_MIN_SIZE && uiWidth <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
2874 | |
---|
2875 | // get copy of co-located texture luma block |
---|
2876 | TComYuv cTempYuv; |
---|
2877 | cTempYuv.create( uiWidth, uiHeight ); |
---|
2878 | cTempYuv.clear(); |
---|
2879 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2880 | |
---|
2881 | copyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
2882 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
2883 | |
---|
2884 | // local pred buffer |
---|
2885 | TComYuv cPredYuv; |
---|
2886 | cPredYuv.create( uiWidth, uiHeight ); |
---|
2887 | cPredYuv.clear(); |
---|
2888 | Pel* piPred = cPredYuv.getLumaAddr(); |
---|
2889 | |
---|
2890 | UInt uiPredStride = cPredYuv.getStride(); |
---|
2891 | |
---|
2892 | // wedge search |
---|
2893 | TComWedgeDist cWedgeDist; |
---|
2894 | UInt uiBestDist = MAX_UINT; |
---|
2895 | UInt uiBestTabIdx = 0; |
---|
2896 | Int iDC1 = 0; |
---|
2897 | Int iDC2 = 0; |
---|
2898 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiWidth])]; |
---|
2899 | |
---|
2900 | #if HHIQC_DMMFASTSEARCH_B0039 |
---|
2901 | TComPic* pcPicTex = pcCU->getSlice()->getTexturePic(); |
---|
2902 | TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr()); |
---|
2903 | UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
2904 | Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; |
---|
2905 | |
---|
2906 | std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]]; |
---|
2907 | if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ) |
---|
2908 | { |
---|
2909 | std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2]; |
---|
2910 | for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ ) |
---|
2911 | { |
---|
2912 | UInt uiIdx = pauiWdgLst->at(uiIdxW); |
---|
2913 | calcWedgeDCs ( &(pacWedgeList->at(uiIdx)), piRefBlkY, uiWidth, iDC1, iDC2 ); |
---|
2914 | assignWedgeDCs2Pred( &(pacWedgeList->at(uiIdx)), piPred, uiPredStride, iDC1, iDC2 ); |
---|
2915 | |
---|
2916 | UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD ); |
---|
2917 | |
---|
2918 | if( uiActDist < uiBestDist || uiBestDist == MAX_UINT ) |
---|
2919 | { |
---|
2920 | uiBestDist = uiActDist; |
---|
2921 | uiBestTabIdx = uiIdx; |
---|
2922 | } |
---|
2923 | } |
---|
2924 | } |
---|
2925 | else |
---|
2926 | { |
---|
2927 | WedgeNodeList* pacWedgeNodeList = &g_aacWedgeNodeLists[(g_aucConvertToBit[uiWidth])]; |
---|
2928 | UInt uiBestNodeDist = MAX_UINT; |
---|
2929 | UInt uiBestNodeId = 0; |
---|
2930 | for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ ) |
---|
2931 | { |
---|
2932 | calcWedgeDCs ( &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())), piRefBlkY, uiWidth, iDC1, iDC2 ); |
---|
2933 | assignWedgeDCs2Pred( &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx())), piPred, uiPredStride, iDC1, iDC2 ); |
---|
2934 | |
---|
2935 | UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD ); |
---|
2936 | |
---|
2937 | if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT ) |
---|
2938 | { |
---|
2939 | uiBestNodeDist = uiActDist; |
---|
2940 | uiBestNodeId = uiNodeId; |
---|
2941 | } |
---|
2942 | } |
---|
2943 | |
---|
2944 | // refinement |
---|
2945 | uiBestDist = uiBestNodeDist; |
---|
2946 | uiBestTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx(); |
---|
2947 | for( UInt uiRefId = 0; uiRefId < NUM_WEDGE_REFINES; uiRefId++ ) |
---|
2948 | { |
---|
2949 | if( pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ) != NO_IDX ) |
---|
2950 | { |
---|
2951 | calcWedgeDCs ( &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ))), piRefBlkY, uiWidth, iDC1, iDC2 ); |
---|
2952 | assignWedgeDCs2Pred( &(pacWedgeList->at(pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ))), piPred, uiPredStride, iDC1, iDC2 ); |
---|
2953 | |
---|
2954 | UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD ); |
---|
2955 | |
---|
2956 | if( uiActDist < uiBestDist || uiBestDist == MAX_UINT ) |
---|
2957 | { |
---|
2958 | uiBestDist = uiActDist; |
---|
2959 | uiBestTabIdx = pacWedgeNodeList->at(uiBestNodeId).getRefineIdx( uiRefId ); |
---|
2960 | } |
---|
2961 | } |
---|
2962 | } |
---|
2963 | } |
---|
2964 | #else |
---|
2965 | for( UInt uiIdx = 0; uiIdx < pacWedgeList->size(); uiIdx++ ) |
---|
2966 | { |
---|
2967 | calcWedgeDCs ( &(pacWedgeList->at(uiIdx)), piRefBlkY, uiWidth, iDC1, iDC2 ); |
---|
2968 | assignWedgeDCs2Pred( &(pacWedgeList->at(uiIdx)), piPred, uiPredStride, iDC1, iDC2 ); |
---|
2969 | |
---|
2970 | UInt uiActDist = cWedgeDist.getDistPart( piPred, uiPredStride, piRefBlkY, uiWidth, uiWidth, uiHeight, WedgeDist_SAD ); |
---|
2971 | |
---|
2972 | if( uiActDist < uiBestDist || uiBestDist == MAX_UINT ) |
---|
2973 | { |
---|
2974 | uiBestDist = uiActDist; |
---|
2975 | uiBestTabIdx = uiIdx; |
---|
2976 | } |
---|
2977 | } |
---|
2978 | #endif |
---|
2979 | |
---|
2980 | cPredYuv.destroy(); |
---|
2981 | cTempYuv.destroy(); |
---|
2982 | return uiBestTabIdx; |
---|
2983 | } |
---|
2984 | |
---|
2985 | Void TComPrediction::copyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
2986 | { |
---|
2987 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
2988 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
2989 | Pel* piRefY; |
---|
2990 | |
---|
2991 | piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
2992 | |
---|
2993 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
2994 | { |
---|
2995 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
2996 | // ::memset(piDestBlockY, 128, sizeof(Pel)*uiWidth); |
---|
2997 | piDestBlockY += uiWidth; |
---|
2998 | piRefY += iRefStride; |
---|
2999 | } |
---|
3000 | } |
---|
3001 | |
---|
3002 | Void TComPrediction::xPredIntraWedgeTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 ) |
---|
3003 | { |
---|
3004 | assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
3005 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])]; |
---|
3006 | |
---|
3007 | // get wedge pattern |
---|
3008 | UInt uiTextureWedgeTabIdx = 0; |
---|
3009 | if( bEncoder ) |
---|
3010 | { |
---|
3011 | // encoder: load stored wedge pattern from CU |
---|
3012 | uiTextureWedgeTabIdx = pcCU->getWedgePredTexTabIdx( uiAbsPartIdx ); |
---|
3013 | } |
---|
3014 | else |
---|
3015 | { |
---|
3016 | // decoder: get and store wedge pattern in CU |
---|
3017 | uiTextureWedgeTabIdx = getBestWedgeFromTex( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight ); |
---|
3018 | |
---|
3019 | UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1); |
---|
3020 | pcCU->setWedgePredTexTabIdxSubParts( uiTextureWedgeTabIdx, uiAbsPartIdx, uiDepth ); |
---|
3021 | } |
---|
3022 | TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTextureWedgeTabIdx)); |
---|
3023 | |
---|
3024 | // get wedge pred DCs |
---|
3025 | Int iPredDC1 = 0; |
---|
3026 | Int iPredDC2 = 0; |
---|
3027 | Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); |
---|
3028 | Int iMaskStride = ( iWidth<<1 ) + 1; |
---|
3029 | piMask += iMaskStride+1; |
---|
3030 | getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft ); |
---|
3031 | |
---|
3032 | if( bDelta ) |
---|
3033 | { |
---|
3034 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 ); |
---|
3035 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 ); |
---|
3036 | } |
---|
3037 | |
---|
3038 | // assign wedge pred DCs to prediction |
---|
3039 | if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); } |
---|
3040 | else { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 ); } |
---|
3041 | } |
---|
3042 | |
---|
3043 | Void TComPrediction::xPredIntraContourTex( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iDeltaDC1, Int iDeltaDC2 ) |
---|
3044 | { |
---|
3045 | // get contour pattern |
---|
3046 | TComWedgelet* pcContourWedge = new TComWedgelet( iWidth, iHeight ); |
---|
3047 | getBestContourFromTex( pcCU, uiAbsPartIdx, (UInt)iWidth, (UInt)iHeight, pcContourWedge ); |
---|
3048 | |
---|
3049 | // get wedge pred DCs |
---|
3050 | Int iPredDC1 = 0; |
---|
3051 | Int iPredDC2 = 0; |
---|
3052 | Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); |
---|
3053 | Int iMaskStride = ( iWidth<<1 ) + 1; |
---|
3054 | piMask += iMaskStride+1; |
---|
3055 | getWedgePredDCs( pcContourWedge, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft ); |
---|
3056 | |
---|
3057 | if( bDelta ) |
---|
3058 | { |
---|
3059 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 ); |
---|
3060 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 ); |
---|
3061 | } |
---|
3062 | |
---|
3063 | // assign wedge pred DCs to prediction |
---|
3064 | if( bDelta ) { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, Clip ( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); } |
---|
3065 | else { assignWedgeDCs2Pred( pcContourWedge, piPred, uiStride, iPredDC1, iPredDC2 ); } |
---|
3066 | |
---|
3067 | pcContourWedge->destroy(); |
---|
3068 | delete pcContourWedge; |
---|
3069 | } |
---|
3070 | #endif |
---|
3071 | |
---|
3072 | #if HHI_DMM_WEDGE_INTRA |
---|
3073 | UInt TComPrediction::getBestContinueWedge( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Int iDeltaEnd ) |
---|
3074 | { |
---|
3075 | UInt uiThisBlockSize = uiWidth; |
---|
3076 | assert( uiThisBlockSize >= DMM_WEDGEMODEL_MIN_SIZE && uiThisBlockSize <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
3077 | WedgeRefList* pacContDWedgeRefList = &g_aacWedgeRefLists[(g_aucConvertToBit[uiThisBlockSize])]; |
---|
3078 | |
---|
3079 | UInt uiPredDirWedgeTabIdx = 0; |
---|
3080 | TComDataCU* pcTempCU; |
---|
3081 | UInt uiTempPartIdx; |
---|
3082 | // 1st: try continue above wedgelet |
---|
3083 | pcTempCU = pcCU->getPUAbove( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
3084 | if( pcTempCU ) |
---|
3085 | { |
---|
3086 | UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx ); |
---|
3087 | if( DMM_WEDGE_FULL_IDX == uhLumaIntraDir || |
---|
3088 | DMM_WEDGE_FULL_D_IDX == uhLumaIntraDir || |
---|
3089 | DMM_WEDGE_PREDDIR_IDX == uhLumaIntraDir || |
---|
3090 | DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir |
---|
3091 | #if HHI_DMM_PRED_TEX |
---|
3092 | || |
---|
3093 | DMM_WEDGE_PREDTEX_IDX == uhLumaIntraDir || |
---|
3094 | DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir |
---|
3095 | #endif |
---|
3096 | ) |
---|
3097 | { |
---|
3098 | UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )]; |
---|
3099 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])]; |
---|
3100 | |
---|
3101 | // get offset between current and reference block |
---|
3102 | UInt uiOffsetX = 0; |
---|
3103 | UInt uiOffsetY = 0; |
---|
3104 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
3105 | |
---|
3106 | // get reference wedgelet |
---|
3107 | UInt uiRefWedgeTabIdx = 0; |
---|
3108 | switch( uhLumaIntraDir ) |
---|
3109 | { |
---|
3110 | case( DMM_WEDGE_FULL_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx ( uiTempPartIdx ); } break; |
---|
3111 | case( DMM_WEDGE_FULL_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx ( uiTempPartIdx ); } break; |
---|
3112 | case( DMM_WEDGE_PREDDIR_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break; |
---|
3113 | case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break; |
---|
3114 | #if HHI_DMM_PRED_TEX |
---|
3115 | case( DMM_WEDGE_PREDTEX_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break; |
---|
3116 | case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break; |
---|
3117 | #endif |
---|
3118 | default: { assert( 0 ); return uiPredDirWedgeTabIdx; } |
---|
3119 | } |
---|
3120 | TComWedgelet* pcRefWedgelet; |
---|
3121 | pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx )); |
---|
3122 | |
---|
3123 | // find reference wedgelet, if direction is suitable for continue wedge |
---|
3124 | if( pcRefWedgelet->checkPredDirAbovePossible( uiThisBlockSize, uiOffsetX ) ) |
---|
3125 | { |
---|
3126 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
3127 | pcRefWedgelet->getPredDirStartEndAbove( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetX, iDeltaEnd ); |
---|
3128 | getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
3129 | return uiPredDirWedgeTabIdx; |
---|
3130 | } |
---|
3131 | } |
---|
3132 | } |
---|
3133 | |
---|
3134 | // 2nd: try continue left wedglelet |
---|
3135 | pcTempCU = pcCU->getPULeft( uiTempPartIdx, pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
3136 | if( pcTempCU ) |
---|
3137 | { |
---|
3138 | UChar uhLumaIntraDir = pcTempCU->getLumaIntraDir( uiTempPartIdx ); |
---|
3139 | if( DMM_WEDGE_FULL_IDX == uhLumaIntraDir || |
---|
3140 | DMM_WEDGE_FULL_D_IDX == uhLumaIntraDir || |
---|
3141 | DMM_WEDGE_PREDDIR_IDX == uhLumaIntraDir || |
---|
3142 | DMM_WEDGE_PREDDIR_D_IDX == uhLumaIntraDir |
---|
3143 | #if HHI_DMM_PRED_TEX |
---|
3144 | || |
---|
3145 | DMM_WEDGE_PREDTEX_IDX == uhLumaIntraDir || |
---|
3146 | DMM_WEDGE_PREDTEX_D_IDX == uhLumaIntraDir |
---|
3147 | #endif |
---|
3148 | ) |
---|
3149 | { |
---|
3150 | UInt uiRefWedgeSize = (UInt)g_aucIntraSizeIdxToWedgeSize[pcTempCU->getIntraSizeIdx( uiTempPartIdx )]; |
---|
3151 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[uiRefWedgeSize])]; |
---|
3152 | |
---|
3153 | // get offset between current and reference block |
---|
3154 | UInt uiOffsetX = 0; |
---|
3155 | UInt uiOffsetY = 0; |
---|
3156 | xGetBlockOffset( pcCU, uiAbsPartIdx, pcTempCU, uiTempPartIdx, uiOffsetX, uiOffsetY ); |
---|
3157 | |
---|
3158 | // get reference wedgelet |
---|
3159 | UInt uiRefWedgeTabIdx = 0; |
---|
3160 | switch( uhLumaIntraDir ) |
---|
3161 | { |
---|
3162 | case( DMM_WEDGE_FULL_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx ( uiTempPartIdx ); } break; |
---|
3163 | case( DMM_WEDGE_FULL_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgeFullTabIdx ( uiTempPartIdx ); } break; |
---|
3164 | case( DMM_WEDGE_PREDDIR_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break; |
---|
3165 | case( DMM_WEDGE_PREDDIR_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredDirTabIdx( uiTempPartIdx ); } break; |
---|
3166 | #if HHI_DMM_PRED_TEX |
---|
3167 | case( DMM_WEDGE_PREDTEX_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break; |
---|
3168 | case( DMM_WEDGE_PREDTEX_D_IDX ): { uiRefWedgeTabIdx = pcTempCU->getWedgePredTexTabIdx( uiTempPartIdx ); } break; |
---|
3169 | #endif |
---|
3170 | default: { assert( 0 ); return uiPredDirWedgeTabIdx; } |
---|
3171 | } |
---|
3172 | TComWedgelet* pcRefWedgelet; |
---|
3173 | pcRefWedgelet = &(pacWedgeList->at( uiRefWedgeTabIdx )); |
---|
3174 | |
---|
3175 | // find reference wedgelet, if direction is suitable for continue wedge |
---|
3176 | if( pcRefWedgelet->checkPredDirLeftPossible( uiThisBlockSize, uiOffsetY ) ) |
---|
3177 | { |
---|
3178 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
3179 | pcRefWedgelet->getPredDirStartEndLeft( uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, uiThisBlockSize, uiOffsetY, iDeltaEnd ); |
---|
3180 | getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
3181 | return uiPredDirWedgeTabIdx; |
---|
3182 | } |
---|
3183 | } |
---|
3184 | } |
---|
3185 | |
---|
3186 | // 3rd: (default) make wedglet from intra dir and max slope point |
---|
3187 | Int iSlopeX = 0; |
---|
3188 | Int iSlopeY = 0; |
---|
3189 | UInt uiStartPosX = 0; |
---|
3190 | UInt uiStartPosY = 0; |
---|
3191 | if( xGetWedgeIntraDirPredData( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY ) ) |
---|
3192 | { |
---|
3193 | UChar uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye; |
---|
3194 | xGetWedgeIntraDirStartEnd( pcCU, uiAbsPartIdx, uiThisBlockSize, iSlopeX, iSlopeY, uiStartPosX, uiStartPosY, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye, iDeltaEnd ); |
---|
3195 | getWedgePatternIdx( pacContDWedgeRefList, uiPredDirWedgeTabIdx, uhContD_Xs, uhContD_Ys, uhContD_Xe, uhContD_Ye ); |
---|
3196 | return uiPredDirWedgeTabIdx; |
---|
3197 | } |
---|
3198 | |
---|
3199 | return uiPredDirWedgeTabIdx; |
---|
3200 | } |
---|
3201 | |
---|
3202 | Bool TComPrediction::getWedgePatternIdx( WedgeRefList* pcWedgeRefList, UInt& ruiTabIdx, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe ) |
---|
3203 | { |
---|
3204 | ruiTabIdx = 0; |
---|
3205 | |
---|
3206 | for( UInt uiIdx = 0; uiIdx < pcWedgeRefList->size(); uiIdx++ ) |
---|
3207 | { |
---|
3208 | TComWedgeRef* pcTestWedgeRef = &(pcWedgeRefList->at(uiIdx)); |
---|
3209 | |
---|
3210 | if( pcTestWedgeRef->getStartX() == uhXs && |
---|
3211 | pcTestWedgeRef->getStartY() == uhYs && |
---|
3212 | pcTestWedgeRef->getEndX() == uhXe && |
---|
3213 | pcTestWedgeRef->getEndY() == uhYe ) |
---|
3214 | { |
---|
3215 | ruiTabIdx = pcTestWedgeRef->getRefIdx(); |
---|
3216 | return true; |
---|
3217 | } |
---|
3218 | } |
---|
3219 | |
---|
3220 | return false; |
---|
3221 | } |
---|
3222 | |
---|
3223 | Void TComPrediction::xPredIntraWedgeFull( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, UInt uiTabIdx, Int iDeltaDC1, Int iDeltaDC2 ) |
---|
3224 | { |
---|
3225 | assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
3226 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])]; |
---|
3227 | TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiTabIdx)); |
---|
3228 | |
---|
3229 | // get wedge pred DCs |
---|
3230 | Int iPredDC1 = 0; |
---|
3231 | Int iPredDC2 = 0; |
---|
3232 | |
---|
3233 | Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); |
---|
3234 | Int iMaskStride = ( iWidth<<1 ) + 1; |
---|
3235 | piMask += iMaskStride+1; |
---|
3236 | getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft ); |
---|
3237 | |
---|
3238 | if( bDelta ) |
---|
3239 | { |
---|
3240 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 ); |
---|
3241 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 ); |
---|
3242 | } |
---|
3243 | |
---|
3244 | // assign wedge pred DCs to prediction |
---|
3245 | if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); } |
---|
3246 | else { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 ); } |
---|
3247 | } |
---|
3248 | |
---|
3249 | Void TComPrediction::xPredIntraWedgeDir( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft, Bool bEncoder, Bool bDelta, Int iWedgeDeltaEnd, Int iDeltaDC1, Int iDeltaDC2 ) |
---|
3250 | { |
---|
3251 | assert( iWidth >= DMM_WEDGEMODEL_MIN_SIZE && iWidth <= DMM_WEDGEMODEL_MAX_SIZE ); |
---|
3252 | WedgeList* pacWedgeList = &g_aacWedgeLists[(g_aucConvertToBit[iWidth])]; |
---|
3253 | |
---|
3254 | // get wedge pattern |
---|
3255 | UInt uiDirWedgeTabIdx = 0; |
---|
3256 | if( bEncoder ) |
---|
3257 | { |
---|
3258 | // encoder: load stored wedge pattern from CU |
---|
3259 | uiDirWedgeTabIdx = pcCU->getWedgePredDirTabIdx( uiAbsPartIdx ); |
---|
3260 | } |
---|
3261 | else |
---|
3262 | { |
---|
3263 | uiDirWedgeTabIdx = getBestContinueWedge( pcCU, uiAbsPartIdx, iWidth, iHeight, iWedgeDeltaEnd ); |
---|
3264 | |
---|
3265 | UInt uiDepth = (pcCU->getDepth(0)) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1); |
---|
3266 | pcCU->setWedgePredDirTabIdxSubParts( uiDirWedgeTabIdx, uiAbsPartIdx, uiDepth ); |
---|
3267 | } |
---|
3268 | TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiDirWedgeTabIdx)); |
---|
3269 | |
---|
3270 | // get wedge pred DCs |
---|
3271 | Int iPredDC1 = 0; |
---|
3272 | Int iPredDC2 = 0; |
---|
3273 | |
---|
3274 | Int* piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); |
---|
3275 | Int iMaskStride = ( iWidth<<1 ) + 1; |
---|
3276 | piMask += iMaskStride+1; |
---|
3277 | getWedgePredDCs( pcWedgelet, piMask, iMaskStride, iPredDC1, iPredDC2, bAbove, bLeft ); |
---|
3278 | |
---|
3279 | if( bDelta ) |
---|
3280 | { |
---|
3281 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 ); |
---|
3282 | xDeltaDCQuantScaleUp( pcCU, iDeltaDC2 ); |
---|
3283 | } |
---|
3284 | |
---|
3285 | // assign wedge pred DCs to prediction |
---|
3286 | if( bDelta ) { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, Clip( iPredDC1+iDeltaDC1 ), Clip( iPredDC2+iDeltaDC2 ) ); } |
---|
3287 | else { assignWedgeDCs2Pred( pcWedgelet, piPred, uiStride, iPredDC1, iPredDC2 ); } |
---|
3288 | } |
---|
3289 | |
---|
3290 | Void TComPrediction::xGetBlockOffset( TComDataCU* pcCU, UInt uiAbsPartIdx, TComDataCU* pcRefCU, UInt uiRefAbsPartIdx, UInt& ruiOffsetX, UInt& ruiOffsetY ) |
---|
3291 | { |
---|
3292 | ruiOffsetX = 0; |
---|
3293 | ruiOffsetY = 0; |
---|
3294 | |
---|
3295 | // get offset between current and above/left block |
---|
3296 | UInt uiThisOriginX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
3297 | UInt uiThisOriginY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; |
---|
3298 | |
---|
3299 | UInt uiNumPartInRefCU = pcRefCU->getTotalNumPart(); |
---|
3300 | UInt uiMaxDepthRefCU = 0; |
---|
3301 | while( uiNumPartInRefCU > 1 ) |
---|
3302 | { |
---|
3303 | uiNumPartInRefCU >>= 2; |
---|
3304 | uiMaxDepthRefCU++; |
---|
3305 | } |
---|
3306 | |
---|
3307 | UInt uiDepthRefPU = (pcRefCU->getDepth(uiRefAbsPartIdx)) + (pcRefCU->getPartitionSize(uiRefAbsPartIdx) == SIZE_2Nx2N ? 0 : 1); |
---|
3308 | UInt uiShifts = (uiMaxDepthRefCU - uiDepthRefPU)*2; |
---|
3309 | UInt uiRefBlockOriginPartIdx = (uiRefAbsPartIdx>>uiShifts)<<uiShifts; |
---|
3310 | |
---|
3311 | UInt uiRefOriginX = pcRefCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
3312 | UInt uiRefOriginY = pcRefCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiRefBlockOriginPartIdx] ]; |
---|
3313 | |
---|
3314 | if( (uiThisOriginX - uiRefOriginX) > 0 ) { ruiOffsetX = (UInt)(uiThisOriginX - uiRefOriginX); } |
---|
3315 | if( (uiThisOriginY - uiRefOriginY) > 0 ) { ruiOffsetY = (UInt)(uiThisOriginY - uiRefOriginY); } |
---|
3316 | } |
---|
3317 | |
---|
3318 | Bool TComPrediction::xGetWedgeIntraDirPredData( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiBlockSize, Int& riSlopeX, Int& riSlopeY, UInt& ruiStartPosX, UInt& ruiStartPosY ) |
---|
3319 | { |
---|
3320 | riSlopeX = 0; |
---|
3321 | riSlopeY = 0; |
---|
3322 | ruiStartPosX = 0; |
---|
3323 | ruiStartPosY = 0; |
---|
3324 | |
---|
3325 | // 1st step: get wedge start point (max. slope) |
---|
3326 | Int* piSource = pcCU->getPattern()->getAdiOrgBuf( uiBlockSize, uiBlockSize, m_piYuvExt ); |
---|
3327 | Int iSourceStride = ( uiBlockSize<<1 ) + 1; |
---|
3328 | |
---|
3329 | UInt uiSlopeMaxAbove = 0; |
---|
3330 | UInt uiPosSlopeMaxAbove = 0; |
---|
3331 | for( UInt uiPosHor = 0; uiPosHor < (uiBlockSize-1); uiPosHor++ ) |
---|
3332 | { |
---|
3333 | if( abs( piSource[uiPosHor+1] - piSource[uiPosHor] ) > uiSlopeMaxAbove ) |
---|
3334 | { |
---|
3335 | uiSlopeMaxAbove = abs( piSource[uiPosHor+1] - piSource[uiPosHor] ); |
---|
3336 | uiPosSlopeMaxAbove = uiPosHor; |
---|
3337 | } |
---|
3338 | } |
---|
3339 | |
---|
3340 | UInt uiSlopeMaxLeft = 0; |
---|
3341 | UInt uiPosSlopeMaxLeft = 0; |
---|
3342 | for( UInt uiPosVer = 0; uiPosVer < (uiBlockSize-1); uiPosVer++ ) |
---|
3343 | { |
---|
3344 | if( abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ) > uiSlopeMaxLeft ) |
---|
3345 | { |
---|
3346 | uiSlopeMaxLeft = abs( piSource[(uiPosVer+1)*iSourceStride] - piSource[uiPosVer*iSourceStride] ); |
---|
3347 | uiPosSlopeMaxLeft = uiPosVer; |
---|
3348 | } |
---|
3349 | } |
---|
3350 | |
---|
3351 | if( uiSlopeMaxAbove == 0 && uiSlopeMaxLeft == 0 ) |
---|
3352 | { |
---|
3353 | return false; |
---|
3354 | } |
---|
3355 | |
---|
3356 | if( uiSlopeMaxAbove > uiSlopeMaxLeft ) |
---|
3357 | { |
---|
3358 | ruiStartPosX = uiPosSlopeMaxAbove; |
---|
3359 | ruiStartPosY = 0; |
---|
3360 | } |
---|
3361 | else |
---|
3362 | { |
---|
3363 | ruiStartPosX = 0; |
---|
3364 | ruiStartPosY = uiPosSlopeMaxLeft; |
---|
3365 | } |
---|
3366 | |
---|
3367 | // 2nd step: derive wedge direction |
---|
3368 | #if LOGI_INTRA_NAME_3MPM |
---|
3369 | Int uiPreds[3] = {-1, -1, -1}; |
---|
3370 | #else |
---|
3371 | Int uiPreds[2] = {-1, -1}; |
---|
3372 | #endif |
---|
3373 | Int iMode = -1; |
---|
3374 | Int iPredNum = pcCU->getIntraDirLumaPredictor( uiAbsPartIdx, uiPreds, &iMode ); |
---|
3375 | |
---|
3376 | UInt uiDirMode = 0; |
---|
3377 | #if LOGI_INTRA_NAME_3MPM |
---|
3378 | if( iMode >= 0 ) { iPredNum = iMode; } |
---|
3379 | if( iPredNum == 1 ) { uiDirMode = uiPreds[0]; } |
---|
3380 | if( iPredNum == 2 ) { uiDirMode = uiPreds[1]; } |
---|
3381 | |
---|
3382 | if( uiDirMode < 2 ) { return false; } // no planar & DC |
---|
3383 | |
---|
3384 | Bool modeHor = (uiDirMode < 18); |
---|
3385 | Bool modeVer = !modeHor; |
---|
3386 | Int intraPredAngle = modeVer ? (Int)uiDirMode - VER_IDX : modeHor ? -((Int)uiDirMode - HOR_IDX) : 0; |
---|
3387 | #else |
---|
3388 | if( iPredNum == 1 ) { uiDirMode = g_aucAngIntraModeOrder[uiPreds[0]]; } |
---|
3389 | if( iPredNum == 2 ) { uiDirMode = g_aucAngIntraModeOrder[uiPreds[1]]; } |
---|
3390 | |
---|
3391 | if( uiDirMode == 0 ) { return false; } // no DC |
---|
3392 | |
---|
3393 | Bool modeVer = (uiDirMode < 18); |
---|
3394 | Bool modeHor = !modeVer; |
---|
3395 | Int intraPredAngle = modeVer ? uiDirMode - 9 : modeHor ? uiDirMode - 25 : 0; |
---|
3396 | #endif |
---|
3397 | Int absAng = abs(intraPredAngle); |
---|
3398 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
3399 | Int angTable[9] = {0,2,5,9,13,17,21,26,32}; |
---|
3400 | absAng = angTable[absAng]; |
---|
3401 | intraPredAngle = signAng * absAng; |
---|
3402 | |
---|
3403 | // 3rd step: set slope for direction |
---|
3404 | if( modeHor ) |
---|
3405 | { |
---|
3406 | if( intraPredAngle > 0 ) |
---|
3407 | { |
---|
3408 | riSlopeX = -32; |
---|
3409 | riSlopeY = intraPredAngle; |
---|
3410 | } |
---|
3411 | else |
---|
3412 | { |
---|
3413 | riSlopeX = 32; |
---|
3414 | riSlopeY = -intraPredAngle; |
---|
3415 | } |
---|
3416 | } |
---|
3417 | else if( modeVer ) |
---|
3418 | { |
---|
3419 | if( intraPredAngle > 0 ) |
---|
3420 | { |
---|
3421 | riSlopeX = intraPredAngle; |
---|
3422 | riSlopeY = -32; |
---|
3423 | } |
---|
3424 | else |
---|
3425 | { |
---|
3426 | riSlopeX = -intraPredAngle; |
---|
3427 | riSlopeY = 32; |
---|
3428 | } |
---|
3429 | } |
---|
3430 | |
---|
3431 | return true; |
---|
3432 | } |
---|
3433 | |
---|
3434 | 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 ) |
---|
3435 | { |
---|
3436 | ruhXs = 0; |
---|
3437 | ruhYs = 0; |
---|
3438 | ruhXe = 0; |
---|
3439 | ruhYe = 0; |
---|
3440 | |
---|
3441 | // scaling of start pos and block size to wedge resolution |
---|
3442 | UInt uiScaledStartPosX = 0; |
---|
3443 | UInt uiScaledStartPosY = 0; |
---|
3444 | UInt uiScaledBlockSize = 0; |
---|
3445 | WedgeResolution eWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiBlockSize]]; |
---|
3446 | switch( eWedgeRes ) |
---|
3447 | { |
---|
3448 | case( DOUBLE_PEL ): { uiScaledStartPosX = (uiPMSPosX>>1); uiScaledStartPosY = (uiPMSPosY>>1); uiScaledBlockSize = (uiBlockSize>>1); break; } |
---|
3449 | case( FULL_PEL ): { uiScaledStartPosX = uiPMSPosX; uiScaledStartPosY = uiPMSPosY; uiScaledBlockSize = uiBlockSize; break; } |
---|
3450 | case( HALF_PEL ): { uiScaledStartPosX = (uiPMSPosX<<1); uiScaledStartPosY = (uiPMSPosY<<1); uiScaledBlockSize = (uiBlockSize<<1); break; } |
---|
3451 | } |
---|
3452 | Int iMaxPos = (Int)uiScaledBlockSize - 1; |
---|
3453 | |
---|
3454 | // case above |
---|
3455 | if( uiScaledStartPosX > 0 && uiScaledStartPosY == 0 ) |
---|
3456 | { |
---|
3457 | ruhXs = (UChar)uiScaledStartPosX; |
---|
3458 | ruhYs = 0; |
---|
3459 | |
---|
3460 | if( iDeltaY == 0 ) |
---|
3461 | { |
---|
3462 | if( iDeltaX < 0 ) |
---|
3463 | { |
---|
3464 | ruhXe = 0; |
---|
3465 | ruhYe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
3466 | return; |
---|
3467 | } |
---|
3468 | else |
---|
3469 | { |
---|
3470 | ruhXe = (UChar)iMaxPos; |
---|
3471 | ruhYe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
3472 | std::swap( ruhXs, ruhXe ); |
---|
3473 | std::swap( ruhYs, ruhYe ); |
---|
3474 | return; |
---|
3475 | } |
---|
3476 | } |
---|
3477 | |
---|
3478 | // regular case |
---|
3479 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
3480 | |
---|
3481 | if( iVirtualEndX < 0 ) |
---|
3482 | { |
---|
3483 | Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) + iDeltaEnd; |
---|
3484 | if( iYe < (Int)uiScaledBlockSize ) |
---|
3485 | { |
---|
3486 | ruhXe = 0; |
---|
3487 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
3488 | return; |
---|
3489 | } |
---|
3490 | else |
---|
3491 | { |
---|
3492 | ruhXe = (UChar)std::min( (iYe - iMaxPos), iMaxPos ); |
---|
3493 | ruhYe = (UChar)iMaxPos; |
---|
3494 | return; |
---|
3495 | } |
---|
3496 | } |
---|
3497 | else if( iVirtualEndX > iMaxPos ) |
---|
3498 | { |
---|
3499 | Int iYe = roftoi( (Double)(iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
3500 | if( iYe < (Int)uiScaledBlockSize ) |
---|
3501 | { |
---|
3502 | ruhXe = (UChar)iMaxPos; |
---|
3503 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
3504 | std::swap( ruhXs, ruhXe ); |
---|
3505 | std::swap( ruhYs, ruhYe ); |
---|
3506 | return; |
---|
3507 | } |
---|
3508 | else |
---|
3509 | { |
---|
3510 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
3511 | ruhYe = (UChar)iMaxPos; |
---|
3512 | return; |
---|
3513 | } |
---|
3514 | } |
---|
3515 | else |
---|
3516 | { |
---|
3517 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
3518 | if( iXe < 0 ) |
---|
3519 | { |
---|
3520 | ruhXe = 0; |
---|
3521 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
3522 | return; |
---|
3523 | } |
---|
3524 | else if( iXe > iMaxPos ) |
---|
3525 | { |
---|
3526 | ruhXe = (UChar)iMaxPos; |
---|
3527 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
3528 | std::swap( ruhXs, ruhXe ); |
---|
3529 | std::swap( ruhYs, ruhYe ); |
---|
3530 | return; |
---|
3531 | } |
---|
3532 | else |
---|
3533 | { |
---|
3534 | ruhXe = (UChar)iXe; |
---|
3535 | ruhYe = (UChar)iMaxPos; |
---|
3536 | return; |
---|
3537 | } |
---|
3538 | } |
---|
3539 | } |
---|
3540 | |
---|
3541 | // case left |
---|
3542 | if( uiScaledStartPosY > 0 && uiScaledStartPosX == 0 ) |
---|
3543 | { |
---|
3544 | ruhXs = 0; |
---|
3545 | ruhYs = (UChar)uiScaledStartPosY; |
---|
3546 | |
---|
3547 | if( iDeltaX == 0 ) |
---|
3548 | { |
---|
3549 | if( iDeltaY < 0 ) |
---|
3550 | { |
---|
3551 | ruhXe = (UChar)std::min( std::max( -iDeltaEnd, 0 ), iMaxPos ); |
---|
3552 | ruhYe = 0; |
---|
3553 | std::swap( ruhXs, ruhXe ); |
---|
3554 | std::swap( ruhYs, ruhYe ); |
---|
3555 | return; |
---|
3556 | } |
---|
3557 | else |
---|
3558 | { |
---|
3559 | ruhXe = (UChar)std::min( std::max( iDeltaEnd, 0 ), iMaxPos ); |
---|
3560 | ruhYe = (UChar)iMaxPos; |
---|
3561 | return; |
---|
3562 | } |
---|
3563 | } |
---|
3564 | |
---|
3565 | // regular case |
---|
3566 | Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iMaxPos * ((Double)iDeltaY / (Double)iDeltaX) ); |
---|
3567 | |
---|
3568 | if( iVirtualEndY < 0 ) |
---|
3569 | { |
---|
3570 | Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) - iDeltaEnd; |
---|
3571 | if( iXe < (Int)uiScaledBlockSize ) |
---|
3572 | { |
---|
3573 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
3574 | ruhYe = 0; |
---|
3575 | std::swap( ruhXs, ruhXe ); |
---|
3576 | std::swap( ruhYs, ruhYe ); |
---|
3577 | return; |
---|
3578 | } |
---|
3579 | else |
---|
3580 | { |
---|
3581 | ruhXe = (UChar)iMaxPos; |
---|
3582 | ruhYe = (UChar)std::min( (iXe - iMaxPos), iMaxPos ); |
---|
3583 | std::swap( ruhXs, ruhXe ); |
---|
3584 | std::swap( ruhYs, ruhYe ); |
---|
3585 | return; |
---|
3586 | } |
---|
3587 | } |
---|
3588 | else if( iVirtualEndY > (uiScaledBlockSize-1) ) |
---|
3589 | { |
---|
3590 | Int iXe = roftoi( (Double)((Int)(uiScaledBlockSize-1) - (Int)ruhYs ) * ((Double)iDeltaX / (Double)iDeltaY) ) + iDeltaEnd; |
---|
3591 | if( iXe < (Int)uiScaledBlockSize ) |
---|
3592 | { |
---|
3593 | ruhXe = (UChar)std::max( iXe, 0 ); |
---|
3594 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
3595 | return; |
---|
3596 | } |
---|
3597 | else |
---|
3598 | { |
---|
3599 | ruhXe = (UChar)iMaxPos; |
---|
3600 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
3601 | std::swap( ruhXs, ruhXe ); |
---|
3602 | std::swap( ruhYs, ruhYe ); |
---|
3603 | return; |
---|
3604 | } |
---|
3605 | } |
---|
3606 | else |
---|
3607 | { |
---|
3608 | Int iYe = iVirtualEndY - iDeltaEnd; |
---|
3609 | if( iYe < 0 ) |
---|
3610 | { |
---|
3611 | ruhXe = (UChar)std::max( (iMaxPos + iYe), 0 ); |
---|
3612 | ruhYe = 0; |
---|
3613 | std::swap( ruhXs, ruhXe ); |
---|
3614 | std::swap( ruhYs, ruhYe ); |
---|
3615 | return; |
---|
3616 | } |
---|
3617 | else if( iYe > iMaxPos ) |
---|
3618 | { |
---|
3619 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
3620 | ruhYe = (UChar)iMaxPos; |
---|
3621 | return; |
---|
3622 | } |
---|
3623 | else |
---|
3624 | { |
---|
3625 | ruhXe = (UChar)iMaxPos; |
---|
3626 | ruhYe = (UChar)iYe; |
---|
3627 | std::swap( ruhXs, ruhXe ); |
---|
3628 | std::swap( ruhYs, ruhYe ); |
---|
3629 | return; |
---|
3630 | } |
---|
3631 | } |
---|
3632 | } |
---|
3633 | |
---|
3634 | // case origin |
---|
3635 | if( uiScaledStartPosX == 0 && uiScaledStartPosY == 0 ) |
---|
3636 | { |
---|
3637 | if( iDeltaX*iDeltaY < 0 ) |
---|
3638 | { |
---|
3639 | return; |
---|
3640 | } |
---|
3641 | |
---|
3642 | ruhXs = 0; |
---|
3643 | ruhYs = 0; |
---|
3644 | |
---|
3645 | if( iDeltaY == 0 ) |
---|
3646 | { |
---|
3647 | ruhXe = (UChar)iMaxPos; |
---|
3648 | ruhYe = 0; |
---|
3649 | std::swap( ruhXs, ruhXe ); |
---|
3650 | std::swap( ruhYs, ruhYe ); |
---|
3651 | return; |
---|
3652 | } |
---|
3653 | |
---|
3654 | if( iDeltaX == 0 ) |
---|
3655 | { |
---|
3656 | ruhXe = 0; |
---|
3657 | ruhYe = (UChar)iMaxPos; |
---|
3658 | return; |
---|
3659 | } |
---|
3660 | |
---|
3661 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iMaxPos * ((Double)iDeltaX / (Double)iDeltaY) ); |
---|
3662 | |
---|
3663 | if( iVirtualEndX > iMaxPos ) |
---|
3664 | { |
---|
3665 | Int iYe = roftoi( (Double)((Int)iMaxPos - (Int)ruhXs) * ((Double)iDeltaY / (Double)iDeltaX) ) - iDeltaEnd; |
---|
3666 | if( iYe < (Int)uiScaledBlockSize ) |
---|
3667 | { |
---|
3668 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
3669 | ruhYe = (UChar)std::max( iYe, 0 ); |
---|
3670 | std::swap( ruhXs, ruhXe ); |
---|
3671 | std::swap( ruhYs, ruhYe ); |
---|
3672 | return; |
---|
3673 | } |
---|
3674 | else |
---|
3675 | { |
---|
3676 | ruhXe = (UChar)std::max( (iMaxPos - (iYe - iMaxPos)), 0 ); |
---|
3677 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
3678 | return; |
---|
3679 | } |
---|
3680 | } |
---|
3681 | else |
---|
3682 | { |
---|
3683 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
3684 | if( iXe < 0 ) |
---|
3685 | { |
---|
3686 | ruhXe = 0; |
---|
3687 | ruhYe = (UChar)std::max( (iMaxPos + iXe), 0 ); |
---|
3688 | return; |
---|
3689 | } |
---|
3690 | else if( iXe > iMaxPos ) |
---|
3691 | { |
---|
3692 | ruhXe = (UChar)(uiScaledBlockSize-1); |
---|
3693 | ruhYe = (UChar)std::max( (iMaxPos - (iXe - iMaxPos)), 0 ); |
---|
3694 | std::swap( ruhXs, ruhXe ); |
---|
3695 | std::swap( ruhYs, ruhYe ); |
---|
3696 | return; |
---|
3697 | } |
---|
3698 | else |
---|
3699 | { |
---|
3700 | ruhXe = (UChar)iXe; |
---|
3701 | ruhYe = (UChar)(uiScaledBlockSize-1); |
---|
3702 | return; |
---|
3703 | } |
---|
3704 | } |
---|
3705 | } |
---|
3706 | } |
---|
3707 | #endif |
---|
3708 | |
---|
3709 | Void |
---|
3710 | TComPrediction::predIntraDepthAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight ) |
---|
3711 | { |
---|
3712 | Pel* pDst = piPred; |
---|
3713 | Int* ptrSrc = pcTComPattern->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); |
---|
3714 | Int sw = ( iWidth<<1 ) + 1; |
---|
3715 | #if !LOGI_INTRA_NAME_3MPM |
---|
3716 | uiDirMode = g_aucAngIntraModeOrder[ uiDirMode ]; |
---|
3717 | #endif |
---|
3718 | xPredIntraAngDepth( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode ); |
---|
3719 | } |
---|
3720 | |
---|
3721 | Int |
---|
3722 | TComPrediction::xGetDCDepth( Int* pSrc, Int iDelta, Int iBlkSize ) |
---|
3723 | { |
---|
3724 | Int iDC = PDM_UNDEFINED_DEPTH; |
---|
3725 | Int iSum = 0; |
---|
3726 | Int iNum = 0; |
---|
3727 | for( Int k = 0; k < iBlkSize; k++, pSrc += iDelta ) |
---|
3728 | { |
---|
3729 | if( *pSrc != PDM_UNDEFINED_DEPTH ) |
---|
3730 | { |
---|
3731 | iSum += *pSrc; |
---|
3732 | iNum ++; |
---|
3733 | } |
---|
3734 | } |
---|
3735 | if( iNum ) |
---|
3736 | { |
---|
3737 | iDC = ( iSum + ( iNum >> 1 ) ) / iNum; |
---|
3738 | } |
---|
3739 | return iDC; |
---|
3740 | } |
---|
3741 | |
---|
3742 | Int |
---|
3743 | TComPrediction::xGetDCValDepth( Int iVal1, Int iVal2, Int iVal3, Int iVal4 ) |
---|
3744 | { |
---|
3745 | if ( iVal1 != PDM_UNDEFINED_DEPTH ) return iVal1; |
---|
3746 | else if( iVal2 != PDM_UNDEFINED_DEPTH ) return iVal2; |
---|
3747 | else if( iVal3 != PDM_UNDEFINED_DEPTH ) return iVal3; |
---|
3748 | return iVal4; |
---|
3749 | } |
---|
3750 | |
---|
3751 | Void |
---|
3752 | TComPrediction::xPredIntraAngDepth( Int* pSrc, Int srcStride, Pel* pDst, Int dstStride, UInt width, UInt height, UInt dirMode ) |
---|
3753 | { |
---|
3754 | AOF( width == height ); |
---|
3755 | Int blkSize = width; |
---|
3756 | Int iDCAbove = xGetDCDepth( pSrc - srcStride, 1, blkSize ); |
---|
3757 | Int iDCAboveRight = xGetDCDepth( pSrc - srcStride + blkSize, 1, blkSize ); |
---|
3758 | Int iDCLeft = xGetDCDepth( pSrc - 1, srcStride, blkSize ); |
---|
3759 | Int iDCBelowLeft = xGetDCDepth( pSrc - 1 + blkSize * srcStride, srcStride, blkSize ); |
---|
3760 | Int iWgt, iDC1, iDC2; |
---|
3761 | if( dirMode < 2 ) // 1..2 |
---|
3762 | { |
---|
3763 | iDC1 = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft, iDCBelowLeft ); |
---|
3764 | iDC2 = xGetDCValDepth( iDCLeft, iDCBelowLeft, iDCAbove, iDCAboveRight ); |
---|
3765 | iWgt = 8; |
---|
3766 | } |
---|
3767 | else if( dirMode < 11 ) // 3..10 |
---|
3768 | { |
---|
3769 | iDC1 = xGetDCValDepth( iDCLeft, iDCBelowLeft, iDCAbove, iDCAboveRight ); |
---|
3770 | iDC2 = xGetDCValDepth( iDCBelowLeft, iDCLeft, iDCAbove, iDCAboveRight ); |
---|
3771 | iWgt = 6 + dirMode; |
---|
3772 | } |
---|
3773 | else if( dirMode < 27 ) // 11..26 |
---|
3774 | { |
---|
3775 | iDC1 = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft, iDCBelowLeft ); |
---|
3776 | iDC2 = xGetDCValDepth( iDCLeft, iDCBelowLeft, iDCAbove, iDCAboveRight ); |
---|
3777 | iWgt = dirMode - 10; |
---|
3778 | } |
---|
3779 | else if( dirMode < 35 ) // 27..34 |
---|
3780 | { |
---|
3781 | iDC1 = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft, iDCBelowLeft ); |
---|
3782 | iDC2 = xGetDCValDepth( iDCAboveRight, iDCAbove, iDCLeft, iDCBelowLeft ); |
---|
3783 | iWgt = 42 - dirMode; |
---|
3784 | } |
---|
3785 | else // (wedgelet -> use simple DC prediction |
---|
3786 | { |
---|
3787 | iDC1 = xGetDCValDepth( iDCAbove, iDCAboveRight, iDCLeft, iDCBelowLeft ); |
---|
3788 | iDC2 = xGetDCValDepth( iDCLeft, iDCBelowLeft, iDCAbove, iDCAboveRight ); |
---|
3789 | iWgt = 8; |
---|
3790 | } |
---|
3791 | Int iWgt2 = 16 - iWgt; |
---|
3792 | Int iDCVal = ( iWgt * iDC1 + iWgt2 * iDC2 + 8 ) >> 4; |
---|
3793 | |
---|
3794 | // set depth |
---|
3795 | for( Int iY = 0; iY < blkSize; iY++, pDst += dstStride ) |
---|
3796 | { |
---|
3797 | for( Int iX = 0; iX < blkSize; iX++ ) |
---|
3798 | { |
---|
3799 | pDst[ iX ] = iDCVal; |
---|
3800 | } |
---|
3801 | } |
---|
3802 | } |
---|
3803 | |
---|
3804 | //! \} |
---|