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