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