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