| 1 | /* The copyright in this software is beinOMg 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 | #include "TComTU.h" |
|---|
| 41 | |
|---|
| 42 | //! \ingroup TLibCommon |
|---|
| 43 | //! \{ |
|---|
| 44 | |
|---|
| 45 | // ==================================================================================================================== |
|---|
| 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 | // ==================================================================================================================== |
|---|
| 69 | // Constructor / destructor / initialize |
|---|
| 70 | // ==================================================================================================================== |
|---|
| 71 | |
|---|
| 72 | TComPrediction::TComPrediction() |
|---|
| 73 | : m_pLumaRecBuffer(0) |
|---|
| 74 | , m_iLumaRecStride(0) |
|---|
| 75 | { |
|---|
| 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 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | TComPrediction::~TComPrediction() |
|---|
| 86 | { |
|---|
| 87 | destroy(); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 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 | } |
|---|
| 100 | |
|---|
| 101 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
|---|
| 102 | { |
|---|
| 103 | m_acYuvPred[i].destroy(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | m_cYuvPredTemp.destroy(); |
|---|
| 107 | |
|---|
| 108 | if( m_pLumaRecBuffer ) |
|---|
| 109 | { |
|---|
| 110 | delete [] m_pLumaRecBuffer; |
|---|
| 111 | m_pLumaRecBuffer = 0; |
|---|
| 112 | } |
|---|
| 113 | m_iLumaRecStride = 0; |
|---|
| 114 | |
|---|
| 115 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
|---|
| 116 | { |
|---|
| 117 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
|---|
| 118 | { |
|---|
| 119 | m_filteredBlock[i][j].destroy(); |
|---|
| 120 | } |
|---|
| 121 | m_filteredBlockTmp[i].destroy(); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC) |
|---|
| 126 | { |
|---|
| 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) |
|---|
| 129 | { |
|---|
| 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; |
|---|
| 136 | Int extHeight = MAX_CU_SIZE + 1; |
|---|
| 137 | |
|---|
| 138 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
|---|
| 139 | { |
|---|
| 140 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC); |
|---|
| 141 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
|---|
| 142 | { |
|---|
| 143 | m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 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 | |
|---|
| 156 | // new structure |
|---|
| 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 | } |
|---|
| 161 | |
|---|
| 162 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 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 |
|---|
| 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 ) |
|---|
| 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 | } |
|---|
| 219 | |
|---|
| 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 | */ |
|---|
| 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 | ) |
|---|
| 252 | { |
|---|
| 253 | Int width=Int(uiWidth); |
|---|
| 254 | Int height=Int(uiHeight); |
|---|
| 255 | |
|---|
| 256 | // Map the mode index to main prediction direction and angle |
|---|
| 257 | assert( dirMode != PLANAR_IDX ); //no planar |
|---|
| 258 | const Bool modeDC = dirMode==DC_IDX; |
|---|
| 259 | |
|---|
| 260 | // Do the DC prediction |
|---|
| 261 | if (modeDC) |
|---|
| 262 | { |
|---|
| 263 | const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, channelType, format, blkAboveAvailable, blkLeftAvailable); |
|---|
| 264 | |
|---|
| 265 | for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue) |
|---|
| 266 | { |
|---|
| 267 | for (Int x=0; x<width;) // width is always a multiple of 4. |
|---|
| 268 | { |
|---|
| 269 | pTrueDst[x++] = dcval; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 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); |
|---|
| 280 | |
|---|
| 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 | |
|---|
| 288 | Pel* refMain; |
|---|
| 289 | Pel* refSide; |
|---|
| 290 | |
|---|
| 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 | { |
|---|
| 297 | const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1; |
|---|
| 298 | const Int refMainOffset = height - 1; |
|---|
| 299 | for (Int x=0;x<width+1;x++) |
|---|
| 300 | { |
|---|
| 301 | refAbove[x+refMainOffset] = pSrc[x-srcStride-1]; |
|---|
| 302 | } |
|---|
| 303 | for (Int y=0;y<height+1;y++) |
|---|
| 304 | { |
|---|
| 305 | refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1]; |
|---|
| 306 | } |
|---|
| 307 | refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset; |
|---|
| 308 | refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset; |
|---|
| 309 | |
|---|
| 310 | // Extend the Main reference to the left. |
|---|
| 311 | Int invAngleSum = 128; // rounding for (shift by 8) |
|---|
| 312 | for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--) |
|---|
| 313 | { |
|---|
| 314 | invAngleSum += invAngle; |
|---|
| 315 | refMain[k] = refSide[invAngleSum>>8]; |
|---|
| 316 | } |
|---|
| 317 | } |
|---|
| 318 | else |
|---|
| 319 | { |
|---|
| 320 | for (Int x=0;x<2*width+1;x++) |
|---|
| 321 | { |
|---|
| 322 | refAbove[x] = pSrc[x-srcStride-1]; |
|---|
| 323 | } |
|---|
| 324 | for (Int y=0;y<2*height+1;y++) |
|---|
| 325 | { |
|---|
| 326 | refLeft[y] = pSrc[(y-1)*srcStride-1]; |
|---|
| 327 | } |
|---|
| 328 | refMain = bIsModeVer ? refAbove : refLeft ; |
|---|
| 329 | refSide = bIsModeVer ? refLeft : refAbove; |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 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) |
|---|
| 337 | { |
|---|
| 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++) |
|---|
| 344 | { |
|---|
| 345 | for (Int x=0;x<width;x++) |
|---|
| 346 | { |
|---|
| 347 | pDst[y*dstStride+x] = refMain[x+1]; |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | if (edgeFilter) |
|---|
| 352 | { |
|---|
| 353 | for (Int y=0;y<height;y++) |
|---|
| 354 | { |
|---|
| 355 | pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) ); |
|---|
| 356 | } |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | else |
|---|
| 360 | { |
|---|
| 361 | Pel *pDsty=pDst; |
|---|
| 362 | |
|---|
| 363 | for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride) |
|---|
| 364 | { |
|---|
| 365 | const Int deltaInt = deltaPos >> 5; |
|---|
| 366 | const Int deltaFract = deltaPos & (32 - 1); |
|---|
| 367 | |
|---|
| 368 | if (deltaFract) |
|---|
| 369 | { |
|---|
| 370 | // Do linear filtering |
|---|
| 371 | const Pel *pRM=refMain+deltaInt+1; |
|---|
| 372 | Int lastRefMainPel=*pRM++; |
|---|
| 373 | for (Int x=0;x<width;pRM++,x++) |
|---|
| 374 | { |
|---|
| 375 | Int thisRefMainPel=*pRM; |
|---|
| 376 | pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 ); |
|---|
| 377 | lastRefMainPel=thisRefMainPel; |
|---|
| 378 | } |
|---|
| 379 | } |
|---|
| 380 | else |
|---|
| 381 | { |
|---|
| 382 | // Just copy the integer samples |
|---|
| 383 | for (Int x=0;x<width; x++) |
|---|
| 384 | { |
|---|
| 385 | pDsty[x] = refMain[x+deltaInt+1]; |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | // Flip the block if this is the horizontal mode |
|---|
| 392 | if (!bIsModeVer) |
|---|
| 393 | { |
|---|
| 394 | for (Int y=0; y<height; y++) |
|---|
| 395 | { |
|---|
| 396 | for (Int x=0; x<width; x++) |
|---|
| 397 | { |
|---|
| 398 | pTrueDst[x*dstStrideTrue] = pDst[x]; |
|---|
| 399 | } |
|---|
| 400 | pTrueDst++; |
|---|
| 401 | pDst+=dstStride; |
|---|
| 402 | } |
|---|
| 403 | } |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 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 ) |
|---|
| 408 | { |
|---|
| 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; |
|---|
| 414 | |
|---|
| 415 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
|---|
| 416 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
|---|
| 417 | //assert( iWidth == iHeight ); |
|---|
| 418 | |
|---|
| 419 | Pel *pDst = piPred; |
|---|
| 420 | |
|---|
| 421 | // get starting pixel in block |
|---|
| 422 | const Int sw = (2 * iWidth + 1); |
|---|
| 423 | |
|---|
| 424 | if ( bUseLosslessDPCM ) |
|---|
| 425 | { |
|---|
| 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 | } |
|---|
| 462 | } |
|---|
| 463 | else |
|---|
| 464 | { |
|---|
| 465 | const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples ); |
|---|
| 466 | |
|---|
| 467 | if ( uiDirMode == PLANAR_IDX ) |
|---|
| 468 | { |
|---|
| 469 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, format ); |
|---|
| 470 | } |
|---|
| 471 | else |
|---|
| 472 | { |
|---|
| 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)); |
|---|
| 477 | |
|---|
| 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 ) |
|---|
| 485 | { |
|---|
| 486 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType ); |
|---|
| 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 | |
|---|
| 552 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
|---|
| 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 | |
|---|
| 586 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi ) |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 603 | #if REF_IDX_ME_ZEROMV |
|---|
| 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 ); |
|---|
| 606 | #endif |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | } |
|---|
| 610 | #endif |
|---|
| 611 | |
|---|
| 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 ); |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred ) |
|---|
| 617 | { |
|---|
| 618 | TComYuv* pcMbYuv; |
|---|
| 619 | Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1}; |
|---|
| 620 | |
|---|
| 621 | for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ ) |
|---|
| 622 | { |
|---|
| 623 | RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
|---|
| 624 | iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
|---|
| 625 | |
|---|
| 626 | if ( iRefIdx[refList] < 0 ) |
|---|
| 627 | { |
|---|
| 628 | continue; |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
|---|
| 632 | |
|---|
| 633 | pcMbYuv = &m_acYuvPred[refList]; |
|---|
| 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 | { |
|---|
| 640 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
|---|
| 641 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
|---|
| 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 | |
|---|
| 652 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
|---|
| 653 | { |
|---|
| 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 | } |
|---|
| 656 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
|---|
| 657 | { |
|---|
| 658 | xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
|---|
| 659 | } |
|---|
| 660 | else |
|---|
| 661 | { |
|---|
| 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 ); |
|---|
| 663 | } |
|---|
| 664 | } |
|---|
| 665 | |
|---|
| 666 | /** |
|---|
| 667 | * \brief Generate motion-compensated block |
|---|
| 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 | */ |
|---|
| 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 ) |
|---|
| 681 | { |
|---|
| 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)); |
|---|
| 686 | |
|---|
| 687 | Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride; |
|---|
| 688 | |
|---|
| 689 | Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset; |
|---|
| 690 | |
|---|
| 691 | Pel* dst = dstPic->getAddr( compID, partAddr ); |
|---|
| 692 | |
|---|
| 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 | |
|---|
| 700 | if ( yFrac == 0 ) |
|---|
| 701 | { |
|---|
| 702 | m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt); |
|---|
| 703 | } |
|---|
| 704 | else if ( xFrac == 0 ) |
|---|
| 705 | { |
|---|
| 706 | m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt); |
|---|
| 707 | } |
|---|
| 708 | else |
|---|
| 709 | { |
|---|
| 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); |
|---|
| 717 | } |
|---|
| 718 | } |
|---|
| 719 | |
|---|
| 720 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst ) |
|---|
| 721 | { |
|---|
| 722 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
|---|
| 723 | { |
|---|
| 724 | pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
|---|
| 725 | } |
|---|
| 726 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
|---|
| 727 | { |
|---|
| 728 | pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
|---|
| 729 | } |
|---|
| 730 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
|---|
| 731 | { |
|---|
| 732 | pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
|---|
| 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(); |
|---|
| 740 | |
|---|
| 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 | */ |
|---|
| 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 ) |
|---|
| 767 | { |
|---|
| 768 | assert(width <= height); |
|---|
| 769 | |
|---|
| 770 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
|---|
| 771 | UInt shift1Dhor = g_aucConvertToBit[ width ] + 2; |
|---|
| 772 | UInt shift1Dver = g_aucConvertToBit[ height ] + 2; |
|---|
| 773 | |
|---|
| 774 | // Get left and above reference column and row |
|---|
| 775 | for(Int k=0;k<width+1;k++) |
|---|
| 776 | { |
|---|
| 777 | topRow[k] = pSrc[k-srcStride]; |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | for (Int k=0; k < height+1; k++) |
|---|
| 781 | { |
|---|
| 782 | leftColumn[k] = pSrc[k*srcStride-1]; |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | // Prepare intermediate variables used in interpolation |
|---|
| 786 | Int bottomLeft = leftColumn[height]; |
|---|
| 787 | Int topRight = topRow[width]; |
|---|
| 788 | |
|---|
| 789 | for(Int k=0;k<width;k++) |
|---|
| 790 | { |
|---|
| 791 | bottomRow[k] = bottomLeft - topRow[k]; |
|---|
| 792 | topRow[k] <<= shift1Dver; |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 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 | |
|---|
| 803 | // Generate prediction signal |
|---|
| 804 | for (Int y=0;y<height;y++) |
|---|
| 805 | { |
|---|
| 806 | Int horPred = leftColumn[y] + width; |
|---|
| 807 | for (Int x=0;x<width;x++) |
|---|
| 808 | { |
|---|
| 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); |
|---|
| 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 | */ |
|---|
| 828 | Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType ) |
|---|
| 829 | { |
|---|
| 830 | Int x, y, iDstStride2, iSrcStride2; |
|---|
| 831 | |
|---|
| 832 | if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT)) |
|---|
| 833 | { |
|---|
| 834 | //top-left |
|---|
| 835 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
|---|
| 836 | |
|---|
| 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 | } |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | return; |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 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 | |
|---|
| 861 | #if SVC_EXTENSION |
|---|
| 862 | #if O0215_PHASE_ALIGNMENT_REMOVAL |
|---|
| 863 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic ) |
|---|
| 864 | { |
|---|
| 865 | m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic ); |
|---|
| 866 | } |
|---|
| 867 | #else |
|---|
| 868 | #if O0215_PHASE_ALIGNMENT |
|---|
| 869 | #if O0194_JOINT_US_BITSHIFT |
|---|
| 870 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, Bool phaseAlignFlag ) |
|---|
| 871 | { |
|---|
| 872 | m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, phaseAlignFlag ); |
|---|
| 873 | } |
|---|
| 874 | #else |
|---|
| 875 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag ) |
|---|
| 876 | { |
|---|
| 877 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag ); |
|---|
| 878 | } |
|---|
| 879 | #endif |
|---|
| 880 | #else |
|---|
| 881 | #if O0194_JOINT_US_BITSHIFT |
|---|
| 882 | #if REF_REGION_OFFSET |
|---|
| 883 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, const Window altRefWindow ) |
|---|
| 884 | { |
|---|
| 885 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, altRefWindow ); |
|---|
| 886 | } |
|---|
| 887 | #else |
|---|
| 888 | Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window) |
|---|
| 889 | { |
|---|
| 890 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window); |
|---|
| 891 | } |
|---|
| 892 | #endif |
|---|
| 893 | #else |
|---|
| 894 | Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window) |
|---|
| 895 | { |
|---|
| 896 | m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window); |
|---|
| 897 | } |
|---|
| 898 | #endif |
|---|
| 899 | #endif |
|---|
| 900 | #endif |
|---|
| 901 | #endif //SVC_EXTENSION |
|---|
| 902 | //! \} |
|---|