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