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-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TComPrediction.cpp |
---|
35 | \brief prediction class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <memory.h> |
---|
39 | #include "TComPrediction.h" |
---|
40 | |
---|
41 | //! \ingroup TLibCommon |
---|
42 | //! \{ |
---|
43 | |
---|
44 | // ==================================================================================================================== |
---|
45 | // Constructor / destructor / initialize |
---|
46 | // ==================================================================================================================== |
---|
47 | |
---|
48 | TComPrediction::TComPrediction() |
---|
49 | : m_pLumaRecBuffer(0) |
---|
50 | , m_iLumaRecStride(0) |
---|
51 | { |
---|
52 | m_piYuvExt = NULL; |
---|
53 | } |
---|
54 | |
---|
55 | TComPrediction::~TComPrediction() |
---|
56 | { |
---|
57 | |
---|
58 | delete[] m_piYuvExt; |
---|
59 | |
---|
60 | m_acYuvPred[0].destroy(); |
---|
61 | m_acYuvPred[1].destroy(); |
---|
62 | |
---|
63 | m_cYuvPredTemp.destroy(); |
---|
64 | |
---|
65 | if( m_pLumaRecBuffer ) |
---|
66 | { |
---|
67 | delete [] m_pLumaRecBuffer; |
---|
68 | } |
---|
69 | |
---|
70 | Int i, j; |
---|
71 | for (i = 0; i < 4; i++) |
---|
72 | { |
---|
73 | for (j = 0; j < 4; j++) |
---|
74 | { |
---|
75 | m_filteredBlock[i][j].destroy(); |
---|
76 | } |
---|
77 | m_filteredBlockTmp[i].destroy(); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | Void TComPrediction::initTempBuff() |
---|
82 | { |
---|
83 | if( m_piYuvExt == NULL ) |
---|
84 | { |
---|
85 | Int extWidth = MAX_CU_SIZE + 16; |
---|
86 | Int extHeight = MAX_CU_SIZE + 1; |
---|
87 | Int i, j; |
---|
88 | for (i = 0; i < 4; i++) |
---|
89 | { |
---|
90 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7); |
---|
91 | for (j = 0; j < 4; j++) |
---|
92 | { |
---|
93 | m_filteredBlock[i][j].create(extWidth, extHeight); |
---|
94 | } |
---|
95 | } |
---|
96 | m_iYuvExtHeight = ((MAX_CU_SIZE + 2) << 4); |
---|
97 | m_iYuvExtStride = ((MAX_CU_SIZE + 8) << 4); |
---|
98 | m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ]; |
---|
99 | |
---|
100 | // new structure |
---|
101 | m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
102 | m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
103 | |
---|
104 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
105 | } |
---|
106 | |
---|
107 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
108 | { |
---|
109 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
110 | if (!m_pLumaRecBuffer) |
---|
111 | { |
---|
112 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // ==================================================================================================================== |
---|
118 | // Public member functions |
---|
119 | // ==================================================================================================================== |
---|
120 | |
---|
121 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
122 | Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
123 | { |
---|
124 | assert(iWidth > 0 && iHeight > 0); |
---|
125 | Int iInd, iSum = 0; |
---|
126 | Pel pDcVal; |
---|
127 | |
---|
128 | if (bAbove) |
---|
129 | { |
---|
130 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
131 | { |
---|
132 | iSum += pSrc[iInd-iSrcStride]; |
---|
133 | } |
---|
134 | } |
---|
135 | if (bLeft) |
---|
136 | { |
---|
137 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
138 | { |
---|
139 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | if (bAbove && bLeft) |
---|
144 | { |
---|
145 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
146 | } |
---|
147 | else if (bAbove) |
---|
148 | { |
---|
149 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
150 | } |
---|
151 | else if (bLeft) |
---|
152 | { |
---|
153 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
158 | } |
---|
159 | |
---|
160 | return pDcVal; |
---|
161 | } |
---|
162 | |
---|
163 | // Function for deriving the angular Intra predictions |
---|
164 | |
---|
165 | /** Function for deriving the simplified angular intra predictions. |
---|
166 | * \param pSrc pointer to reconstructed sample array |
---|
167 | * \param srcStride the stride of the reconstructed sample array |
---|
168 | * \param rpDst reference to pointer for the prediction sample array |
---|
169 | * \param dstStride the stride of the prediction sample array |
---|
170 | * \param width the width of the block |
---|
171 | * \param height the height of the block |
---|
172 | * \param dirMode the intra prediction mode index |
---|
173 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
174 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
175 | * |
---|
176 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
177 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
178 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
179 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
180 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
181 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
182 | * from the extended main reference. |
---|
183 | */ |
---|
184 | Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter ) |
---|
185 | { |
---|
186 | Int k,l; |
---|
187 | Int blkSize = width; |
---|
188 | Pel* pDst = rpDst; |
---|
189 | |
---|
190 | // Map the mode index to main prediction direction and angle |
---|
191 | assert( dirMode > 0 ); //no planar |
---|
192 | Bool modeDC = dirMode < 2; |
---|
193 | Bool modeHor = !modeDC && (dirMode < 18); |
---|
194 | Bool modeVer = !modeDC && !modeHor; |
---|
195 | Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0; |
---|
196 | Int absAng = abs(intraPredAngle); |
---|
197 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
198 | |
---|
199 | // Set bitshifts and scale the angle parameter to block size |
---|
200 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
201 | Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
202 | Int invAngle = invAngTable[absAng]; |
---|
203 | absAng = angTable[absAng]; |
---|
204 | intraPredAngle = signAng * absAng; |
---|
205 | |
---|
206 | // Do the DC prediction |
---|
207 | if (modeDC) |
---|
208 | { |
---|
209 | Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
210 | |
---|
211 | for (k=0;k<blkSize;k++) |
---|
212 | { |
---|
213 | for (l=0;l<blkSize;l++) |
---|
214 | { |
---|
215 | pDst[k*dstStride+l] = dcval; |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | // Do angular predictions |
---|
221 | else |
---|
222 | { |
---|
223 | Pel* refMain; |
---|
224 | Pel* refSide; |
---|
225 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
226 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
227 | |
---|
228 | // Initialise the Main and Left reference array. |
---|
229 | if (intraPredAngle < 0) |
---|
230 | { |
---|
231 | for (k=0;k<blkSize+1;k++) |
---|
232 | { |
---|
233 | refAbove[k+blkSize-1] = pSrc[k-srcStride-1]; |
---|
234 | } |
---|
235 | for (k=0;k<blkSize+1;k++) |
---|
236 | { |
---|
237 | refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1]; |
---|
238 | } |
---|
239 | refMain = (modeVer ? refAbove : refLeft) + (blkSize-1); |
---|
240 | refSide = (modeVer ? refLeft : refAbove) + (blkSize-1); |
---|
241 | |
---|
242 | // Extend the Main reference to the left. |
---|
243 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
244 | for (k=-1; k>blkSize*intraPredAngle>>5; k--) |
---|
245 | { |
---|
246 | invAngleSum += invAngle; |
---|
247 | refMain[k] = refSide[invAngleSum>>8]; |
---|
248 | } |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | for (k=0;k<2*blkSize+1;k++) |
---|
253 | { |
---|
254 | refAbove[k] = pSrc[k-srcStride-1]; |
---|
255 | } |
---|
256 | for (k=0;k<2*blkSize+1;k++) |
---|
257 | { |
---|
258 | refLeft[k] = pSrc[(k-1)*srcStride-1]; |
---|
259 | } |
---|
260 | refMain = modeVer ? refAbove : refLeft; |
---|
261 | refSide = modeVer ? refLeft : refAbove; |
---|
262 | } |
---|
263 | |
---|
264 | if (intraPredAngle == 0) |
---|
265 | { |
---|
266 | for (k=0;k<blkSize;k++) |
---|
267 | { |
---|
268 | for (l=0;l<blkSize;l++) |
---|
269 | { |
---|
270 | pDst[k*dstStride+l] = refMain[l+1]; |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | if ( bFilter ) |
---|
275 | { |
---|
276 | for (k=0;k<blkSize;k++) |
---|
277 | { |
---|
278 | pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) ); |
---|
279 | } |
---|
280 | } |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | Int deltaPos=0; |
---|
285 | Int deltaInt; |
---|
286 | Int deltaFract; |
---|
287 | Int refMainIndex; |
---|
288 | |
---|
289 | for (k=0;k<blkSize;k++) |
---|
290 | { |
---|
291 | deltaPos += intraPredAngle; |
---|
292 | deltaInt = deltaPos >> 5; |
---|
293 | deltaFract = deltaPos & (32 - 1); |
---|
294 | |
---|
295 | if (deltaFract) |
---|
296 | { |
---|
297 | // Do linear filtering |
---|
298 | for (l=0;l<blkSize;l++) |
---|
299 | { |
---|
300 | refMainIndex = l+deltaInt+1; |
---|
301 | pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 ); |
---|
302 | } |
---|
303 | } |
---|
304 | else |
---|
305 | { |
---|
306 | // Just copy the integer samples |
---|
307 | for (l=0;l<blkSize;l++) |
---|
308 | { |
---|
309 | pDst[k*dstStride+l] = refMain[l+deltaInt+1]; |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | // Flip the block if this is the horizontal mode |
---|
316 | if (modeHor) |
---|
317 | { |
---|
318 | Pel tmp; |
---|
319 | for (k=0;k<blkSize-1;k++) |
---|
320 | { |
---|
321 | for (l=k+1;l<blkSize;l++) |
---|
322 | { |
---|
323 | tmp = pDst[k*dstStride+l]; |
---|
324 | pDst[k*dstStride+l] = pDst[l*dstStride+k]; |
---|
325 | pDst[l*dstStride+k] = tmp; |
---|
326 | } |
---|
327 | } |
---|
328 | } |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
333 | { |
---|
334 | Pel *pDst = piPred; |
---|
335 | Int *ptrSrc; |
---|
336 | |
---|
337 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
338 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
339 | assert( iWidth == iHeight ); |
---|
340 | |
---|
341 | ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
342 | |
---|
343 | // get starting pixel in block |
---|
344 | Int sw = 2 * iWidth + 1; |
---|
345 | |
---|
346 | // Create the prediction |
---|
347 | if ( uiDirMode == PLANAR_IDX ) |
---|
348 | { |
---|
349 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | if ( (iWidth > 16) || (iHeight > 16) ) |
---|
354 | { |
---|
355 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true ); |
---|
360 | |
---|
361 | if( (uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
362 | { |
---|
363 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight); |
---|
364 | } |
---|
365 | } |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | // Angular chroma |
---|
370 | Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
371 | { |
---|
372 | Pel *pDst = piPred; |
---|
373 | Int *ptrSrc = piSrc; |
---|
374 | |
---|
375 | // get starting pixel in block |
---|
376 | Int sw = 2 * iWidth + 1; |
---|
377 | |
---|
378 | if ( uiDirMode == PLANAR_IDX ) |
---|
379 | { |
---|
380 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
381 | } |
---|
382 | else |
---|
383 | { |
---|
384 | // Create the prediction |
---|
385 | xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | /** Function for checking identical motion. |
---|
390 | * \param TComDataCU* pcCU |
---|
391 | * \param UInt PartAddr |
---|
392 | */ |
---|
393 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
394 | { |
---|
395 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
396 | { |
---|
397 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
398 | { |
---|
399 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
400 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
401 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
402 | { |
---|
403 | return true; |
---|
404 | } |
---|
405 | } |
---|
406 | } |
---|
407 | return false; |
---|
408 | } |
---|
409 | |
---|
410 | |
---|
411 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
412 | { |
---|
413 | Int iWidth; |
---|
414 | Int iHeight; |
---|
415 | UInt uiPartAddr; |
---|
416 | |
---|
417 | if ( iPartIdx >= 0 ) |
---|
418 | { |
---|
419 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
420 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
421 | { |
---|
422 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
423 | { |
---|
424 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
429 | } |
---|
430 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
431 | { |
---|
432 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
433 | } |
---|
434 | } |
---|
435 | else |
---|
436 | { |
---|
437 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
438 | { |
---|
439 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
440 | } |
---|
441 | else |
---|
442 | { |
---|
443 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
444 | } |
---|
445 | } |
---|
446 | return; |
---|
447 | } |
---|
448 | |
---|
449 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
450 | { |
---|
451 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
452 | |
---|
453 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
454 | { |
---|
455 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
456 | { |
---|
457 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
458 | } |
---|
459 | else |
---|
460 | { |
---|
461 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
462 | } |
---|
463 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
464 | { |
---|
465 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
466 | } |
---|
467 | } |
---|
468 | else |
---|
469 | { |
---|
470 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
471 | { |
---|
472 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
473 | } |
---|
474 | else |
---|
475 | { |
---|
476 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | return; |
---|
481 | } |
---|
482 | |
---|
483 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
484 | { |
---|
485 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
486 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
487 | pcCU->clipMv(cMv); |
---|
488 | |
---|
489 | #if SVC_EXTENSION |
---|
490 | if( pcCU->getLayerId() > 0 ) |
---|
491 | { |
---|
492 | TComPic* refPic = pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx); |
---|
493 | |
---|
494 | if( refPic->isILR(pcCU->getLayerId()) ) |
---|
495 | { |
---|
496 | // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, |
---|
497 | // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture |
---|
498 | assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), refPic->getLayerId() ) ); |
---|
499 | |
---|
500 | #if REF_IDX_ME_ZEROMV |
---|
501 | // It is a requirement of bitstream conformance that the variables mvLX[ 0 ] and mvLX[ 1 ] shall be equal to 0 if the value of refIdxLX corresponds to an inter-layer reference picture. |
---|
502 | assert( cMv.getHor() == 0 && cMv.getVer() == 0 ); |
---|
503 | #endif |
---|
504 | } |
---|
505 | |
---|
506 | } |
---|
507 | #endif |
---|
508 | |
---|
509 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
510 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
511 | } |
---|
512 | |
---|
513 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
514 | { |
---|
515 | TComYuv* pcMbYuv; |
---|
516 | Int iRefIdx[2] = {-1, -1}; |
---|
517 | |
---|
518 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
519 | { |
---|
520 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
521 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
522 | |
---|
523 | if ( iRefIdx[iRefList] < 0 ) |
---|
524 | { |
---|
525 | continue; |
---|
526 | } |
---|
527 | |
---|
528 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
529 | |
---|
530 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
531 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
532 | { |
---|
533 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
538 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
539 | { |
---|
540 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
545 | } |
---|
546 | } |
---|
547 | } |
---|
548 | |
---|
549 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
550 | { |
---|
551 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
552 | } |
---|
553 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
554 | { |
---|
555 | xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); |
---|
556 | } |
---|
557 | else |
---|
558 | { |
---|
559 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
560 | } |
---|
561 | } |
---|
562 | |
---|
563 | /** |
---|
564 | * \brief Generate motion-compensated luma block |
---|
565 | * |
---|
566 | * \param cu Pointer to current CU |
---|
567 | * \param refPic Pointer to reference picture |
---|
568 | * \param partAddr Address of block within CU |
---|
569 | * \param mv Motion vector |
---|
570 | * \param width Width of block |
---|
571 | * \param height Height of block |
---|
572 | * \param dstPic Pointer to destination picture |
---|
573 | * \param bi Flag indicating whether bipred is used |
---|
574 | */ |
---|
575 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi ) |
---|
576 | { |
---|
577 | Int refStride = refPic->getStride(); |
---|
578 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
579 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
580 | |
---|
581 | Int dstStride = dstPic->getStride(); |
---|
582 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
583 | |
---|
584 | Int xFrac = mv->getHor() & 0x3; |
---|
585 | Int yFrac = mv->getVer() & 0x3; |
---|
586 | |
---|
587 | if ( yFrac == 0 ) |
---|
588 | { |
---|
589 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi ); |
---|
590 | } |
---|
591 | else if ( xFrac == 0 ) |
---|
592 | { |
---|
593 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi ); |
---|
594 | } |
---|
595 | else |
---|
596 | { |
---|
597 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
598 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
599 | |
---|
600 | Int filterSize = NTAPS_LUMA; |
---|
601 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
602 | |
---|
603 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false ); |
---|
604 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi); |
---|
605 | } |
---|
606 | } |
---|
607 | |
---|
608 | /** |
---|
609 | * \brief Generate motion-compensated chroma block |
---|
610 | * |
---|
611 | * \param cu Pointer to current CU |
---|
612 | * \param refPic Pointer to reference picture |
---|
613 | * \param partAddr Address of block within CU |
---|
614 | * \param mv Motion vector |
---|
615 | * \param width Width of block |
---|
616 | * \param height Height of block |
---|
617 | * \param dstPic Pointer to destination picture |
---|
618 | * \param bi Flag indicating whether bipred is used |
---|
619 | */ |
---|
620 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi ) |
---|
621 | { |
---|
622 | Int refStride = refPic->getCStride(); |
---|
623 | Int dstStride = dstPic->getCStride(); |
---|
624 | |
---|
625 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
626 | |
---|
627 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
628 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
629 | |
---|
630 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
631 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
632 | |
---|
633 | Int xFrac = mv->getHor() & 0x7; |
---|
634 | Int yFrac = mv->getVer() & 0x7; |
---|
635 | UInt cxWidth = width >> 1; |
---|
636 | UInt cxHeight = height >> 1; |
---|
637 | |
---|
638 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
639 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
640 | |
---|
641 | Int filterSize = NTAPS_CHROMA; |
---|
642 | |
---|
643 | Int halfFilterSize = (filterSize>>1); |
---|
644 | |
---|
645 | if ( yFrac == 0 ) |
---|
646 | { |
---|
647 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi); |
---|
648 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi); |
---|
649 | } |
---|
650 | else if ( xFrac == 0 ) |
---|
651 | { |
---|
652 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi); |
---|
653 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi); |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false); |
---|
658 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi); |
---|
659 | |
---|
660 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false); |
---|
661 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi); |
---|
662 | } |
---|
663 | } |
---|
664 | |
---|
665 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
666 | { |
---|
667 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
668 | { |
---|
669 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
670 | } |
---|
671 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
672 | { |
---|
673 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
674 | } |
---|
675 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
676 | { |
---|
677 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
678 | } |
---|
679 | } |
---|
680 | |
---|
681 | // AMVP |
---|
682 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
683 | { |
---|
684 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
685 | if( pcAMVPInfo->iN <= 1 ) |
---|
686 | { |
---|
687 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
688 | |
---|
689 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
690 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
691 | return; |
---|
692 | } |
---|
693 | |
---|
694 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
695 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
696 | return; |
---|
697 | } |
---|
698 | |
---|
699 | /** Function for deriving planar intra prediction. |
---|
700 | * \param pSrc pointer to reconstructed sample array |
---|
701 | * \param srcStride the stride of the reconstructed sample array |
---|
702 | * \param rpDst reference to pointer for the prediction sample array |
---|
703 | * \param dstStride the stride of the prediction sample array |
---|
704 | * \param width the width of the block |
---|
705 | * \param height the height of the block |
---|
706 | * |
---|
707 | * This function derives the prediction samples for planar mode (intra coding). |
---|
708 | */ |
---|
709 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
710 | { |
---|
711 | assert(width == height); |
---|
712 | |
---|
713 | Int k, l, bottomLeft, topRight; |
---|
714 | Int horPred; |
---|
715 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
716 | UInt blkSize = width; |
---|
717 | UInt offset2D = width; |
---|
718 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
719 | UInt shift2D = shift1D + 1; |
---|
720 | |
---|
721 | // Get left and above reference column and row |
---|
722 | for(k=0;k<blkSize+1;k++) |
---|
723 | { |
---|
724 | topRow[k] = pSrc[k-srcStride]; |
---|
725 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
726 | } |
---|
727 | |
---|
728 | // Prepare intermediate variables used in interpolation |
---|
729 | bottomLeft = leftColumn[blkSize]; |
---|
730 | topRight = topRow[blkSize]; |
---|
731 | for (k=0;k<blkSize;k++) |
---|
732 | { |
---|
733 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
734 | rightColumn[k] = topRight - leftColumn[k]; |
---|
735 | topRow[k] <<= shift1D; |
---|
736 | leftColumn[k] <<= shift1D; |
---|
737 | } |
---|
738 | |
---|
739 | // Generate prediction signal |
---|
740 | for (k=0;k<blkSize;k++) |
---|
741 | { |
---|
742 | horPred = leftColumn[k] + offset2D; |
---|
743 | for (l=0;l<blkSize;l++) |
---|
744 | { |
---|
745 | horPred += rightColumn[k]; |
---|
746 | topRow[l] += bottomRow[l]; |
---|
747 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
748 | } |
---|
749 | } |
---|
750 | } |
---|
751 | |
---|
752 | /** Function for filtering intra DC predictor. |
---|
753 | * \param pSrc pointer to reconstructed sample array |
---|
754 | * \param iSrcStride the stride of the reconstructed sample array |
---|
755 | * \param rpDst reference to pointer for the prediction sample array |
---|
756 | * \param iDstStride the stride of the prediction sample array |
---|
757 | * \param iWidth the width of the block |
---|
758 | * \param iHeight the height of the block |
---|
759 | * |
---|
760 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
761 | */ |
---|
762 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
763 | { |
---|
764 | Pel* pDst = rpDst; |
---|
765 | Int x, y, iDstStride2, iSrcStride2; |
---|
766 | |
---|
767 | // boundary pixels processing |
---|
768 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
769 | |
---|
770 | for ( x = 1; x < iWidth; x++ ) |
---|
771 | { |
---|
772 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
773 | } |
---|
774 | |
---|
775 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
776 | { |
---|
777 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
778 | } |
---|
779 | |
---|
780 | return; |
---|
781 | } |
---|
782 | |
---|
783 | #if SVC_EXTENSION |
---|
784 | #if O0215_PHASE_ALIGNMENT |
---|
785 | #if O0194_JOINT_US_BITSHIFT |
---|
786 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag ) |
---|
787 | { |
---|
788 | m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, phaseAlignFlag ); |
---|
789 | } |
---|
790 | #else |
---|
791 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag ) |
---|
792 | { |
---|
793 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag ); |
---|
794 | } |
---|
795 | #endif |
---|
796 | #else |
---|
797 | #if O0194_JOINT_US_BITSHIFT |
---|
798 | #if REF_REGION_OFFSET |
---|
799 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow ) |
---|
800 | { |
---|
801 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, altRefWindow ); |
---|
802 | } |
---|
803 | #else |
---|
804 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window) |
---|
805 | { |
---|
806 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window); |
---|
807 | } |
---|
808 | #endif |
---|
809 | #else |
---|
810 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window) |
---|
811 | { |
---|
812 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window); |
---|
813 | } |
---|
814 | #endif |
---|
815 | #endif |
---|
816 | #endif //SVC_EXTENSION |
---|
817 | //! \} |
---|