[1238] | 1 | /* The copyright in this software is being made available under the BSD |
---|
[313] | 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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 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" |
---|
[1262] | 40 | #include "TComPic.h" |
---|
[1029] | 41 | #include "TComTU.h" |
---|
[313] | 42 | |
---|
| 43 | //! \ingroup TLibCommon |
---|
| 44 | //! \{ |
---|
| 45 | |
---|
| 46 | // ==================================================================================================================== |
---|
[1029] | 47 | // Tables |
---|
| 48 | // ==================================================================================================================== |
---|
| 49 | |
---|
| 50 | const UChar TComPrediction::m_aucIntraFilter[MAX_NUM_CHANNEL_TYPE][MAX_INTRA_FILTER_DEPTHS] = |
---|
| 51 | { |
---|
| 52 | { // Luma |
---|
| 53 | 10, //4x4 |
---|
| 54 | 7, //8x8 |
---|
| 55 | 1, //16x16 |
---|
| 56 | 0, //32x32 |
---|
| 57 | 10, //64x64 |
---|
| 58 | }, |
---|
| 59 | { // Chroma |
---|
| 60 | 10, //4xn |
---|
| 61 | 7, //8xn |
---|
| 62 | 1, //16xn |
---|
| 63 | 0, //32xn |
---|
| 64 | 10, //64xn |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | // ==================================================================================================================== |
---|
[313] | 70 | // Constructor / destructor / initialize |
---|
| 71 | // ==================================================================================================================== |
---|
| 72 | |
---|
| 73 | TComPrediction::TComPrediction() |
---|
| 74 | : m_pLumaRecBuffer(0) |
---|
| 75 | , m_iLumaRecStride(0) |
---|
| 76 | { |
---|
[1029] | 77 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
| 78 | { |
---|
| 79 | for(UInt buf=0; buf<2; buf++) |
---|
| 80 | { |
---|
| 81 | m_piYuvExt[ch][buf] = NULL; |
---|
| 82 | } |
---|
| 83 | } |
---|
[313] | 84 | } |
---|
| 85 | |
---|
| 86 | TComPrediction::~TComPrediction() |
---|
| 87 | { |
---|
[1029] | 88 | destroy(); |
---|
| 89 | } |
---|
[313] | 90 | |
---|
[1029] | 91 | Void TComPrediction::destroy() |
---|
| 92 | { |
---|
| 93 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
| 94 | { |
---|
| 95 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
| 96 | { |
---|
| 97 | delete [] m_piYuvExt[ch][buf]; |
---|
| 98 | m_piYuvExt[ch][buf] = NULL; |
---|
| 99 | } |
---|
| 100 | } |
---|
[313] | 101 | |
---|
[1029] | 102 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
| 103 | { |
---|
| 104 | m_acYuvPred[i].destroy(); |
---|
| 105 | } |
---|
| 106 | |
---|
[313] | 107 | m_cYuvPredTemp.destroy(); |
---|
| 108 | |
---|
| 109 | if( m_pLumaRecBuffer ) |
---|
| 110 | { |
---|
| 111 | delete [] m_pLumaRecBuffer; |
---|
[1029] | 112 | m_pLumaRecBuffer = 0; |
---|
[313] | 113 | } |
---|
[1029] | 114 | m_iLumaRecStride = 0; |
---|
| 115 | |
---|
| 116 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
[313] | 117 | { |
---|
[1029] | 118 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
[313] | 119 | { |
---|
| 120 | m_filteredBlock[i][j].destroy(); |
---|
| 121 | } |
---|
| 122 | m_filteredBlockTmp[i].destroy(); |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
[1029] | 126 | Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC) |
---|
[313] | 127 | { |
---|
[1029] | 128 | // if it has been initialised before, but the chroma format has changed, release the memory and start again. |
---|
| 129 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] != NULL && m_cYuvPredTemp.getChromaFormat()!=chromaFormatIDC) |
---|
[313] | 130 | { |
---|
[1029] | 131 | destroy(); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet) |
---|
| 135 | { |
---|
| 136 | Int extWidth = MAX_CU_SIZE + 16; |
---|
[313] | 137 | Int extHeight = MAX_CU_SIZE + 1; |
---|
[1029] | 138 | |
---|
| 139 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
[313] | 140 | { |
---|
[1029] | 141 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC); |
---|
| 142 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
[313] | 143 | { |
---|
[1029] | 144 | m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC); |
---|
[313] | 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
[1029] | 148 | m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1); |
---|
| 149 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
| 150 | { |
---|
| 151 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
| 152 | { |
---|
| 153 | m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ]; |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
[313] | 157 | // new structure |
---|
[1029] | 158 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
| 159 | { |
---|
| 160 | m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
| 161 | } |
---|
[313] | 162 | |
---|
[1029] | 163 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
[313] | 164 | } |
---|
| 165 | |
---|
[1029] | 166 | |
---|
[313] | 167 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
| 168 | { |
---|
| 169 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
| 170 | if (!m_pLumaRecBuffer) |
---|
| 171 | { |
---|
| 172 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | // ==================================================================================================================== |
---|
| 178 | // Public member functions |
---|
| 179 | // ==================================================================================================================== |
---|
| 180 | |
---|
| 181 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
[1029] | 182 | //NOTE: Bit-Limit - 25-bit source |
---|
[1307] | 183 | Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
[313] | 184 | { |
---|
| 185 | assert(iWidth > 0 && iHeight > 0); |
---|
| 186 | Int iInd, iSum = 0; |
---|
| 187 | Pel pDcVal; |
---|
| 188 | |
---|
| 189 | if (bAbove) |
---|
| 190 | { |
---|
| 191 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
| 192 | { |
---|
| 193 | iSum += pSrc[iInd-iSrcStride]; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | if (bLeft) |
---|
| 197 | { |
---|
| 198 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
| 199 | { |
---|
| 200 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | if (bAbove && bLeft) |
---|
| 205 | { |
---|
| 206 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
| 207 | } |
---|
| 208 | else if (bAbove) |
---|
| 209 | { |
---|
| 210 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
| 211 | } |
---|
| 212 | else if (bLeft) |
---|
| 213 | { |
---|
| 214 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
| 215 | } |
---|
| 216 | else |
---|
| 217 | { |
---|
| 218 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
| 219 | } |
---|
[1029] | 220 | |
---|
[313] | 221 | return pDcVal; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | // Function for deriving the angular Intra predictions |
---|
| 225 | |
---|
| 226 | /** Function for deriving the simplified angular intra predictions. |
---|
[1260] | 227 | * \param bitDepth bit depth |
---|
| 228 | * \param pSrc pointer to reconstructed sample array |
---|
| 229 | * \param srcStride the stride of the reconstructed sample array |
---|
| 230 | * \param pTrueDst reference to pointer for the prediction sample array |
---|
| 231 | * \param dstStrideTrue the stride of the prediction sample array |
---|
| 232 | * \param uiWidth the width of the block |
---|
| 233 | * \param uiHeight the height of the block |
---|
| 234 | * \param channelType type of pel array (luma/chroma) |
---|
| 235 | * \param format chroma format |
---|
| 236 | * \param dirMode the intra prediction mode index |
---|
| 237 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
| 238 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
| 239 | * \param bEnableEdgeFilters indication whether to enable edge filters |
---|
[313] | 240 | * |
---|
| 241 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
| 242 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
| 243 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
| 244 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
| 245 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
| 246 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
| 247 | * from the extended main reference. |
---|
| 248 | */ |
---|
[1029] | 249 | //NOTE: Bit-Limit - 25-bit source |
---|
| 250 | Void TComPrediction::xPredIntraAng( Int bitDepth, |
---|
| 251 | const Pel* pSrc, Int srcStride, |
---|
| 252 | Pel* pTrueDst, Int dstStrideTrue, |
---|
[1307] | 253 | UInt uiWidth, UInt uiHeight, ChannelType channelType, |
---|
[1029] | 254 | UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable |
---|
| 255 | , const Bool bEnableEdgeFilters |
---|
| 256 | ) |
---|
[313] | 257 | { |
---|
[1029] | 258 | Int width=Int(uiWidth); |
---|
| 259 | Int height=Int(uiHeight); |
---|
[313] | 260 | |
---|
| 261 | // Map the mode index to main prediction direction and angle |
---|
[1029] | 262 | assert( dirMode != PLANAR_IDX ); //no planar |
---|
| 263 | const Bool modeDC = dirMode==DC_IDX; |
---|
[313] | 264 | |
---|
| 265 | // Do the DC prediction |
---|
| 266 | if (modeDC) |
---|
| 267 | { |
---|
[1307] | 268 | const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
[313] | 269 | |
---|
[1029] | 270 | for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue) |
---|
[313] | 271 | { |
---|
[1029] | 272 | for (Int x=0; x<width;) // width is always a multiple of 4. |
---|
[313] | 273 | { |
---|
[1029] | 274 | pTrueDst[x++] = dcval; |
---|
[313] | 275 | } |
---|
| 276 | } |
---|
| 277 | } |
---|
[1029] | 278 | else // Do angular predictions |
---|
| 279 | { |
---|
| 280 | const Bool bIsModeVer = (dirMode >= 18); |
---|
| 281 | const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX); |
---|
| 282 | const Int absAngMode = abs(intraPredAngleMode); |
---|
| 283 | const Int signAng = intraPredAngleMode < 0 ? -1 : 1; |
---|
| 284 | const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT); |
---|
[313] | 285 | |
---|
[1029] | 286 | // Set bitshifts and scale the angle parameter to block size |
---|
| 287 | static const Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
| 288 | static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
| 289 | Int invAngle = invAngTable[absAngMode]; |
---|
| 290 | Int absAng = angTable[absAngMode]; |
---|
| 291 | Int intraPredAngle = signAng * absAng; |
---|
| 292 | |
---|
[313] | 293 | Pel* refMain; |
---|
| 294 | Pel* refSide; |
---|
[1029] | 295 | |
---|
[313] | 296 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
| 297 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
| 298 | |
---|
| 299 | // Initialise the Main and Left reference array. |
---|
| 300 | if (intraPredAngle < 0) |
---|
| 301 | { |
---|
[1029] | 302 | const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1; |
---|
| 303 | const Int refMainOffset = height - 1; |
---|
| 304 | for (Int x=0;x<width+1;x++) |
---|
[313] | 305 | { |
---|
[1029] | 306 | refAbove[x+refMainOffset] = pSrc[x-srcStride-1]; |
---|
[313] | 307 | } |
---|
[1029] | 308 | for (Int y=0;y<height+1;y++) |
---|
[313] | 309 | { |
---|
[1029] | 310 | refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1]; |
---|
[313] | 311 | } |
---|
[1029] | 312 | refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset; |
---|
| 313 | refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset; |
---|
[313] | 314 | |
---|
| 315 | // Extend the Main reference to the left. |
---|
| 316 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
[1029] | 317 | for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--) |
---|
[313] | 318 | { |
---|
| 319 | invAngleSum += invAngle; |
---|
| 320 | refMain[k] = refSide[invAngleSum>>8]; |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | else |
---|
| 324 | { |
---|
[1029] | 325 | for (Int x=0;x<2*width+1;x++) |
---|
[313] | 326 | { |
---|
[1029] | 327 | refAbove[x] = pSrc[x-srcStride-1]; |
---|
[313] | 328 | } |
---|
[1029] | 329 | for (Int y=0;y<2*height+1;y++) |
---|
[313] | 330 | { |
---|
[1029] | 331 | refLeft[y] = pSrc[(y-1)*srcStride-1]; |
---|
[313] | 332 | } |
---|
[1029] | 333 | refMain = bIsModeVer ? refAbove : refLeft ; |
---|
| 334 | refSide = bIsModeVer ? refLeft : refAbove; |
---|
[313] | 335 | } |
---|
| 336 | |
---|
[1029] | 337 | // swap width/height if we are doing a horizontal mode: |
---|
| 338 | Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE]; |
---|
| 339 | const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE; |
---|
| 340 | Pel *pDst = bIsModeVer ? pTrueDst : tempArray; |
---|
| 341 | if (!bIsModeVer) |
---|
[313] | 342 | { |
---|
[1029] | 343 | std::swap(width, height); |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | if (intraPredAngle == 0) // pure vertical or pure horizontal |
---|
| 347 | { |
---|
| 348 | for (Int y=0;y<height;y++) |
---|
[313] | 349 | { |
---|
[1029] | 350 | for (Int x=0;x<width;x++) |
---|
[313] | 351 | { |
---|
[1029] | 352 | pDst[y*dstStride+x] = refMain[x+1]; |
---|
[313] | 353 | } |
---|
| 354 | } |
---|
| 355 | |
---|
[1029] | 356 | if (edgeFilter) |
---|
[313] | 357 | { |
---|
[1029] | 358 | for (Int y=0;y<height;y++) |
---|
[313] | 359 | { |
---|
[1029] | 360 | pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) ); |
---|
[313] | 361 | } |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | else |
---|
| 365 | { |
---|
[1029] | 366 | Pel *pDsty=pDst; |
---|
[313] | 367 | |
---|
[1029] | 368 | for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride) |
---|
[313] | 369 | { |
---|
[1029] | 370 | const Int deltaInt = deltaPos >> 5; |
---|
| 371 | const Int deltaFract = deltaPos & (32 - 1); |
---|
[313] | 372 | |
---|
| 373 | if (deltaFract) |
---|
| 374 | { |
---|
| 375 | // Do linear filtering |
---|
[1029] | 376 | const Pel *pRM=refMain+deltaInt+1; |
---|
| 377 | Int lastRefMainPel=*pRM++; |
---|
| 378 | for (Int x=0;x<width;pRM++,x++) |
---|
[313] | 379 | { |
---|
[1029] | 380 | Int thisRefMainPel=*pRM; |
---|
| 381 | pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 ); |
---|
| 382 | lastRefMainPel=thisRefMainPel; |
---|
[313] | 383 | } |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | // Just copy the integer samples |
---|
[1029] | 388 | for (Int x=0;x<width; x++) |
---|
[313] | 389 | { |
---|
[1029] | 390 | pDsty[x] = refMain[x+deltaInt+1]; |
---|
[313] | 391 | } |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | // Flip the block if this is the horizontal mode |
---|
[1029] | 397 | if (!bIsModeVer) |
---|
[313] | 398 | { |
---|
[1029] | 399 | for (Int y=0; y<height; y++) |
---|
[313] | 400 | { |
---|
[1029] | 401 | for (Int x=0; x<width; x++) |
---|
[313] | 402 | { |
---|
[1029] | 403 | pTrueDst[x*dstStrideTrue] = pDst[x]; |
---|
[313] | 404 | } |
---|
[1029] | 405 | pTrueDst++; |
---|
| 406 | pDst+=dstStride; |
---|
[313] | 407 | } |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | |
---|
[1029] | 412 | Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM ) |
---|
[313] | 413 | { |
---|
[1029] | 414 | const ChannelType channelType = toChannelType(compID); |
---|
| 415 | const TComRectangle &rect = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb); |
---|
| 416 | const Int iWidth = rect.width; |
---|
| 417 | const Int iHeight = rect.height; |
---|
[313] | 418 | |
---|
| 419 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
| 420 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
[1029] | 421 | //assert( iWidth == iHeight ); |
---|
[313] | 422 | |
---|
[1029] | 423 | Pel *pDst = piPred; |
---|
[313] | 424 | |
---|
| 425 | // get starting pixel in block |
---|
[1029] | 426 | const Int sw = (2 * iWidth + 1); |
---|
[313] | 427 | |
---|
[1029] | 428 | if ( bUseLosslessDPCM ) |
---|
[313] | 429 | { |
---|
[1029] | 430 | const Pel *ptrSrc = getPredictorPtr( compID, false ); |
---|
| 431 | // Sample Adaptive intra-Prediction (SAP) |
---|
| 432 | if (uiDirMode==HOR_IDX) |
---|
| 433 | { |
---|
| 434 | // left column filled with reference samples |
---|
| 435 | // remaining columns filled with piOrg data (if available). |
---|
| 436 | for(Int y=0; y<iHeight; y++) |
---|
| 437 | { |
---|
| 438 | piPred[y*uiStride+0] = ptrSrc[(y+1)*sw]; |
---|
| 439 | } |
---|
| 440 | if (piOrg!=0) |
---|
| 441 | { |
---|
| 442 | piPred+=1; // miss off first column |
---|
| 443 | for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
| 444 | { |
---|
| 445 | memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel)); |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | else // VER_IDX |
---|
| 450 | { |
---|
| 451 | // top row filled with reference samples |
---|
| 452 | // remaining rows filled with piOrd data (if available) |
---|
| 453 | for(Int x=0; x<iWidth; x++) |
---|
| 454 | { |
---|
| 455 | piPred[x] = ptrSrc[x+1]; |
---|
| 456 | } |
---|
| 457 | if (piOrg!=0) |
---|
| 458 | { |
---|
| 459 | piPred+=uiStride; // miss off the first row |
---|
| 460 | for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
| 461 | { |
---|
| 462 | memcpy(piPred, piOrg, iWidth*sizeof(Pel)); |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | } |
---|
[313] | 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
[1029] | 469 | const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples ); |
---|
| 470 | |
---|
| 471 | if ( uiDirMode == PLANAR_IDX ) |
---|
[313] | 472 | { |
---|
[1307] | 473 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
[313] | 474 | } |
---|
| 475 | else |
---|
| 476 | { |
---|
[1029] | 477 | // Create the prediction |
---|
| 478 | TComDataCU *const pcCU = rTu.getCU(); |
---|
| 479 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
| 480 | const Bool enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx)); |
---|
| 481 | #if O0043_BEST_EFFORT_DECODING |
---|
[1287] | 482 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getStreamBitDepth(channelType); |
---|
[1029] | 483 | #else |
---|
[1287] | 484 | #if SVC_EXTENSION |
---|
| 485 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getBitDepth(channelType); |
---|
| 486 | #else |
---|
| 487 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType); |
---|
[1029] | 488 | #endif |
---|
[1287] | 489 | #endif |
---|
[1307] | 490 | xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, bAbove, bLeft, enableEdgeFilters ); |
---|
[1029] | 491 | |
---|
| 492 | if(( uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
[313] | 493 | { |
---|
[1029] | 494 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType ); |
---|
[313] | 495 | } |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | } |
---|
| 500 | |
---|
[1260] | 501 | /** Check for identical motion in both motion vector direction of a bi-directional predicted CU |
---|
| 502 | * \returns true, if motion vectors and reference pictures match |
---|
[313] | 503 | */ |
---|
| 504 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
| 505 | { |
---|
| 506 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
| 507 | { |
---|
| 508 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
| 509 | { |
---|
| 510 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
| 511 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
| 512 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
| 513 | { |
---|
| 514 | return true; |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | return false; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
| 522 | { |
---|
| 523 | Int iWidth; |
---|
| 524 | Int iHeight; |
---|
| 525 | UInt uiPartAddr; |
---|
| 526 | |
---|
| 527 | if ( iPartIdx >= 0 ) |
---|
| 528 | { |
---|
| 529 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 530 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
| 531 | { |
---|
| 532 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
| 533 | { |
---|
| 534 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
| 535 | } |
---|
| 536 | else |
---|
| 537 | { |
---|
| 538 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 539 | } |
---|
| 540 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
| 541 | { |
---|
| 542 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | else |
---|
| 546 | { |
---|
| 547 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 548 | { |
---|
| 549 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 550 | } |
---|
| 551 | else |
---|
| 552 | { |
---|
| 553 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | return; |
---|
| 557 | } |
---|
| 558 | |
---|
[713] | 559 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
[313] | 560 | { |
---|
| 561 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 562 | |
---|
| 563 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
| 564 | { |
---|
| 565 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
| 566 | { |
---|
| 567 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
| 568 | } |
---|
| 569 | else |
---|
| 570 | { |
---|
| 571 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 572 | } |
---|
| 573 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
| 574 | { |
---|
| 575 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | else |
---|
| 579 | { |
---|
| 580 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 581 | { |
---|
| 582 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 583 | } |
---|
| 584 | else |
---|
| 585 | { |
---|
| 586 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 587 | } |
---|
| 588 | } |
---|
| 589 | } |
---|
| 590 | return; |
---|
| 591 | } |
---|
| 592 | |
---|
[1029] | 593 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi ) |
---|
[313] | 594 | { |
---|
| 595 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
| 596 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
| 597 | pcCU->clipMv(cMv); |
---|
| 598 | |
---|
[815] | 599 | #if SVC_EXTENSION |
---|
| 600 | if( pcCU->getLayerId() > 0 ) |
---|
| 601 | { |
---|
| 602 | TComPic* refPic = pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx); |
---|
| 603 | |
---|
| 604 | if( refPic->isILR(pcCU->getLayerId()) ) |
---|
| 605 | { |
---|
| 606 | // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, |
---|
| 607 | // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture |
---|
[1057] | 608 | assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerIdx(), refPic->getLayerIdx() ) ); |
---|
[815] | 609 | |
---|
[313] | 610 | #if REF_IDX_ME_ZEROMV |
---|
[815] | 611 | // 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. |
---|
| 612 | assert( cMv.getHor() == 0 && cMv.getVer() == 0 ); |
---|
[313] | 613 | #endif |
---|
[815] | 614 | } |
---|
[313] | 615 | |
---|
[815] | 616 | } |
---|
| 617 | #endif |
---|
| 618 | |
---|
[1287] | 619 | for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++) |
---|
[1246] | 620 | { |
---|
[1287] | 621 | const ComponentID compID=ComponentID(comp); |
---|
| 622 | #if SVC_EXTENSION |
---|
| 623 | xPredInterBlk (compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getBitDepth(toChannelType(compID)) ); |
---|
| 624 | #else |
---|
| 625 | xPredInterBlk (compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) ); |
---|
| 626 | #endif |
---|
[1246] | 627 | } |
---|
[313] | 628 | } |
---|
| 629 | |
---|
[1029] | 630 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred ) |
---|
[313] | 631 | { |
---|
| 632 | TComYuv* pcMbYuv; |
---|
[1029] | 633 | Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1}; |
---|
[313] | 634 | |
---|
[1029] | 635 | for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ ) |
---|
[313] | 636 | { |
---|
[1029] | 637 | RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
| 638 | iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
[313] | 639 | |
---|
[1029] | 640 | if ( iRefIdx[refList] < 0 ) |
---|
[313] | 641 | { |
---|
| 642 | continue; |
---|
| 643 | } |
---|
| 644 | |
---|
[1029] | 645 | assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
[313] | 646 | |
---|
[1029] | 647 | pcMbYuv = &m_acYuvPred[refList]; |
---|
[313] | 648 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
| 649 | { |
---|
| 650 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
| 651 | } |
---|
| 652 | else |
---|
| 653 | { |
---|
[1029] | 654 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
| 655 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
[313] | 656 | { |
---|
| 657 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
| 658 | } |
---|
| 659 | else |
---|
| 660 | { |
---|
| 661 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | |
---|
[1029] | 666 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
[313] | 667 | { |
---|
[1029] | 668 | xWeightedPredictionBi( pcCU, &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 669 | } |
---|
[313] | 670 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
| 671 | { |
---|
[1029] | 672 | xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[313] | 673 | } |
---|
| 674 | else |
---|
| 675 | { |
---|
[1287] | 676 | #if SVC_EXTENSION |
---|
| 677 | xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred, pcCU->getSlice()->getBitDepths() ); |
---|
| 678 | #else |
---|
| 679 | xWeightedAverage( &m_acYuvPred[REF_PIC_LIST_0], &m_acYuvPred[REF_PIC_LIST_1], iRefIdx[REF_PIC_LIST_0], iRefIdx[REF_PIC_LIST_1], uiPartAddr, iWidth, iHeight, pcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() ); |
---|
| 680 | #endif |
---|
[313] | 681 | } |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | /** |
---|
[1029] | 685 | * \brief Generate motion-compensated block |
---|
[313] | 686 | * |
---|
[1305] | 687 | * \param compID Colour component ID |
---|
| 688 | * \param cu Pointer to current CU |
---|
| 689 | * \param refPic Pointer to reference picture |
---|
| 690 | * \param partAddr Address of block within CU |
---|
| 691 | * \param mv Motion vector |
---|
| 692 | * \param width Width of block |
---|
| 693 | * \param height Height of block |
---|
| 694 | * \param dstPic Pointer to destination picture |
---|
| 695 | * \param bi Flag indicating whether bipred is used |
---|
| 696 | * \param bitDepth Bit depth |
---|
[313] | 697 | */ |
---|
[1029] | 698 | |
---|
| 699 | |
---|
[1287] | 700 | Void TComPrediction::xPredInterBlk(const ComponentID compID, TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *dstPic, Bool bi, const Int bitDepth ) |
---|
[313] | 701 | { |
---|
[1029] | 702 | Int refStride = refPic->getStride(compID); |
---|
| 703 | Int dstStride = dstPic->getStride(compID); |
---|
| 704 | Int shiftHor=(2+refPic->getComponentScaleX(compID)); |
---|
| 705 | Int shiftVer=(2+refPic->getComponentScaleY(compID)); |
---|
[313] | 706 | |
---|
[1029] | 707 | Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride; |
---|
[313] | 708 | |
---|
[1029] | 709 | Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset; |
---|
[313] | 710 | |
---|
[1029] | 711 | Pel* dst = dstPic->getAddr( compID, partAddr ); |
---|
[313] | 712 | |
---|
[1029] | 713 | Int xFrac = mv->getHor() & ((1<<shiftHor)-1); |
---|
| 714 | Int yFrac = mv->getVer() & ((1<<shiftVer)-1); |
---|
| 715 | UInt cxWidth = width >> refPic->getComponentScaleX(compID); |
---|
| 716 | UInt cxHeight = height >> refPic->getComponentScaleY(compID); |
---|
| 717 | |
---|
| 718 | const ChromaFormat chFmt = cu->getPic()->getChromaFormat(); |
---|
| 719 | |
---|
[313] | 720 | if ( yFrac == 0 ) |
---|
| 721 | { |
---|
[1287] | 722 | m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth); |
---|
[313] | 723 | } |
---|
| 724 | else if ( xFrac == 0 ) |
---|
| 725 | { |
---|
[1287] | 726 | m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth); |
---|
[313] | 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
[1029] | 730 | Int tmpStride = m_filteredBlockTmp[0].getStride(compID); |
---|
| 731 | Pel* tmp = m_filteredBlockTmp[0].getAddr(compID); |
---|
| 732 | |
---|
| 733 | const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA; |
---|
| 734 | |
---|
[1287] | 735 | m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt, bitDepth); |
---|
| 736 | m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt, bitDepth); |
---|
[313] | 737 | } |
---|
| 738 | } |
---|
| 739 | |
---|
[1287] | 740 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths ) |
---|
[313] | 741 | { |
---|
| 742 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
| 743 | { |
---|
[1287] | 744 | pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths ); |
---|
[313] | 745 | } |
---|
| 746 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
| 747 | { |
---|
[1029] | 748 | pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
[313] | 749 | } |
---|
| 750 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
| 751 | { |
---|
[1029] | 752 | pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
[313] | 753 | } |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | // AMVP |
---|
| 757 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
| 758 | { |
---|
| 759 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
[1029] | 760 | |
---|
[313] | 761 | if( pcAMVPInfo->iN <= 1 ) |
---|
| 762 | { |
---|
| 763 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
| 764 | |
---|
| 765 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 766 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 767 | return; |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
| 771 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
| 772 | return; |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | /** Function for deriving planar intra prediction. |
---|
[1260] | 776 | * \param pSrc pointer to reconstructed sample array |
---|
| 777 | * \param srcStride the stride of the reconstructed sample array |
---|
| 778 | * \param rpDst reference to pointer for the prediction sample array |
---|
| 779 | * \param dstStride the stride of the prediction sample array |
---|
| 780 | * \param width the width of the block |
---|
| 781 | * \param height the height of the block |
---|
| 782 | * \param channelType type of pel array (luma, chroma) |
---|
| 783 | * \param format chroma format |
---|
[313] | 784 | * |
---|
| 785 | * This function derives the prediction samples for planar mode (intra coding). |
---|
| 786 | */ |
---|
[1029] | 787 | //NOTE: Bit-Limit - 24-bit source |
---|
[1307] | 788 | Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
[313] | 789 | { |
---|
[1029] | 790 | assert(width <= height); |
---|
[313] | 791 | |
---|
[442] | 792 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
[1029] | 793 | UInt shift1Dhor = g_aucConvertToBit[ width ] + 2; |
---|
| 794 | UInt shift1Dver = g_aucConvertToBit[ height ] + 2; |
---|
[313] | 795 | |
---|
| 796 | // Get left and above reference column and row |
---|
[1029] | 797 | for(Int k=0;k<width+1;k++) |
---|
[313] | 798 | { |
---|
| 799 | topRow[k] = pSrc[k-srcStride]; |
---|
[1029] | 800 | } |
---|
| 801 | |
---|
| 802 | for (Int k=0; k < height+1; k++) |
---|
| 803 | { |
---|
[313] | 804 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | // Prepare intermediate variables used in interpolation |
---|
[1029] | 808 | Int bottomLeft = leftColumn[height]; |
---|
| 809 | Int topRight = topRow[width]; |
---|
| 810 | |
---|
| 811 | for(Int k=0;k<width;k++) |
---|
[313] | 812 | { |
---|
[1029] | 813 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
| 814 | topRow[k] <<= shift1Dver; |
---|
[313] | 815 | } |
---|
| 816 | |
---|
[1029] | 817 | for(Int k=0;k<height;k++) |
---|
| 818 | { |
---|
| 819 | rightColumn[k] = topRight - leftColumn[k]; |
---|
| 820 | leftColumn[k] <<= shift1Dhor; |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | const UInt topRowShift = 0; |
---|
| 824 | |
---|
[313] | 825 | // Generate prediction signal |
---|
[1029] | 826 | for (Int y=0;y<height;y++) |
---|
[313] | 827 | { |
---|
[1029] | 828 | Int horPred = leftColumn[y] + width; |
---|
| 829 | for (Int x=0;x<width;x++) |
---|
[313] | 830 | { |
---|
[1029] | 831 | horPred += rightColumn[y]; |
---|
| 832 | topRow[x] += bottomRow[x]; |
---|
| 833 | |
---|
| 834 | Int vertPred = ((topRow[x] + topRowShift)>>topRowShift); |
---|
| 835 | rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1); |
---|
[313] | 836 | } |
---|
| 837 | } |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | /** Function for filtering intra DC predictor. |
---|
| 841 | * \param pSrc pointer to reconstructed sample array |
---|
| 842 | * \param iSrcStride the stride of the reconstructed sample array |
---|
[1260] | 843 | * \param pDst reference to pointer for the prediction sample array |
---|
[313] | 844 | * \param iDstStride the stride of the prediction sample array |
---|
| 845 | * \param iWidth the width of the block |
---|
| 846 | * \param iHeight the height of the block |
---|
[1260] | 847 | * \param channelType type of pel array (luma, chroma) |
---|
[313] | 848 | * |
---|
| 849 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
| 850 | */ |
---|
[1029] | 851 | Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType ) |
---|
[313] | 852 | { |
---|
| 853 | Int x, y, iDstStride2, iSrcStride2; |
---|
| 854 | |
---|
[1029] | 855 | if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT)) |
---|
[313] | 856 | { |
---|
[1029] | 857 | //top-left |
---|
| 858 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
[313] | 859 | |
---|
[1029] | 860 | //top row (vertical filter) |
---|
| 861 | for ( x = 1; x < iWidth; x++ ) |
---|
| 862 | { |
---|
| 863 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | //left column (horizontal filter) |
---|
| 867 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
| 868 | { |
---|
| 869 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
| 870 | } |
---|
[313] | 871 | } |
---|
| 872 | |
---|
| 873 | return; |
---|
| 874 | } |
---|
| 875 | |
---|
[1029] | 876 | /* Static member function */ |
---|
| 877 | Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode) |
---|
| 878 | { |
---|
| 879 | return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) && |
---|
| 880 | rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) && |
---|
| 881 | (uiDirMode==HOR_IDX || uiDirMode==VER_IDX); |
---|
| 882 | } |
---|
| 883 | |
---|
[815] | 884 | #if SVC_EXTENSION |
---|
[1287] | 885 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Int refBitDepthLuma, const Int refBitDepthChroma ) |
---|
[944] | 886 | { |
---|
[1287] | 887 | m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, refBitDepthLuma, refBitDepthChroma ); |
---|
[944] | 888 | } |
---|
[815] | 889 | #endif //SVC_EXTENSION |
---|
[313] | 890 | //! \} |
---|