[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1313] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1313] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TComPrediction.cpp |
---|
| 35 | \brief prediction class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <memory.h> |
---|
| 39 | #include "TComPrediction.h" |
---|
[1313] | 40 | #include "TComPic.h" |
---|
| 41 | #include "TComTU.h" |
---|
[2] | 42 | |
---|
[56] | 43 | //! \ingroup TLibCommon |
---|
| 44 | //! \{ |
---|
| 45 | |
---|
[2] | 46 | // ==================================================================================================================== |
---|
[1313] | 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 | // ==================================================================================================================== |
---|
[2] | 70 | // Constructor / destructor / initialize |
---|
| 71 | // ==================================================================================================================== |
---|
| 72 | |
---|
| 73 | TComPrediction::TComPrediction() |
---|
| 74 | : m_pLumaRecBuffer(0) |
---|
[608] | 75 | , m_iLumaRecStride(0) |
---|
[2] | 76 | { |
---|
[1313] | 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 | } |
---|
| 84 | #if NH_3D_VSP |
---|
| 85 | m_pDepthBlock = (Int*) malloc(MAX_NUM_PART_IDXS_IN_CTU_WIDTH*MAX_NUM_PART_IDXS_IN_CTU_WIDTH*sizeof(Int)); |
---|
[608] | 86 | if (m_pDepthBlock == NULL) |
---|
[1196] | 87 | { |
---|
[296] | 88 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
[1196] | 89 | } |
---|
[296] | 90 | #endif |
---|
[1313] | 91 | |
---|
[2] | 92 | } |
---|
| 93 | |
---|
| 94 | TComPrediction::~TComPrediction() |
---|
| 95 | { |
---|
[1313] | 96 | #if NH_3D_VSP |
---|
[608] | 97 | if (m_pDepthBlock != NULL) |
---|
[1196] | 98 | { |
---|
| 99 | free(m_pDepthBlock); |
---|
| 100 | } |
---|
[608] | 101 | m_cYuvDepthOnVsp.destroy(); |
---|
[296] | 102 | #endif |
---|
[608] | 103 | |
---|
[1313] | 104 | destroy(); |
---|
| 105 | } |
---|
[2] | 106 | |
---|
[1313] | 107 | Void TComPrediction::destroy() |
---|
| 108 | { |
---|
| 109 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
| 110 | { |
---|
| 111 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
| 112 | { |
---|
| 113 | delete [] m_piYuvExt[ch][buf]; |
---|
| 114 | m_piYuvExt[ch][buf] = NULL; |
---|
| 115 | } |
---|
| 116 | } |
---|
[2] | 117 | |
---|
[1313] | 118 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
| 119 | { |
---|
| 120 | m_acYuvPred[i].destroy(); |
---|
| 121 | } |
---|
| 122 | |
---|
[2] | 123 | m_cYuvPredTemp.destroy(); |
---|
[608] | 124 | |
---|
[1313] | 125 | #if NH_3D_ARP |
---|
[443] | 126 | m_acYuvPredBase[0].destroy(); |
---|
| 127 | m_acYuvPredBase[1].destroy(); |
---|
| 128 | #endif |
---|
[2] | 129 | if( m_pLumaRecBuffer ) |
---|
[56] | 130 | { |
---|
| 131 | delete [] m_pLumaRecBuffer; |
---|
[1313] | 132 | m_pLumaRecBuffer = 0; |
---|
[56] | 133 | } |
---|
[1313] | 134 | m_iLumaRecStride = 0; |
---|
| 135 | |
---|
| 136 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
[56] | 137 | { |
---|
[1313] | 138 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
[56] | 139 | { |
---|
| 140 | m_filteredBlock[i][j].destroy(); |
---|
| 141 | } |
---|
| 142 | m_filteredBlockTmp[i].destroy(); |
---|
| 143 | } |
---|
[2] | 144 | } |
---|
| 145 | |
---|
[1313] | 146 | Void TComPrediction::initTempBuff(ChromaFormat chromaFormatIDC) |
---|
[2] | 147 | { |
---|
[1313] | 148 | // if it has been initialised before, but the chroma format has changed, release the memory and start again. |
---|
| 149 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] != NULL && m_cYuvPredTemp.getChromaFormat()!=chromaFormatIDC) |
---|
[2] | 150 | { |
---|
[1313] | 151 | destroy(); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | if( m_piYuvExt[COMPONENT_Y][PRED_BUF_UNFILTERED] == NULL ) // check if first is null (in which case, nothing initialised yet) |
---|
| 155 | { |
---|
| 156 | Int extWidth = MAX_CU_SIZE + 16; |
---|
[608] | 157 | Int extHeight = MAX_CU_SIZE + 1; |
---|
[1313] | 158 | |
---|
| 159 | for (UInt i = 0; i < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; i++) |
---|
[56] | 160 | { |
---|
[1313] | 161 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7, chromaFormatIDC); |
---|
| 162 | for (UInt j = 0; j < LUMA_INTERPOLATION_FILTER_SUB_SAMPLE_POSITIONS; j++) |
---|
[56] | 163 | { |
---|
[1313] | 164 | m_filteredBlock[i][j].create(extWidth, extHeight, chromaFormatIDC); |
---|
[56] | 165 | } |
---|
| 166 | } |
---|
[2] | 167 | |
---|
[1313] | 168 | m_iYuvExtSize = (MAX_CU_SIZE*2+1) * (MAX_CU_SIZE*2+1); |
---|
| 169 | for(UInt ch=0; ch<MAX_NUM_COMPONENT; ch++) |
---|
| 170 | { |
---|
| 171 | for(UInt buf=0; buf<NUM_PRED_BUF; buf++) |
---|
| 172 | { |
---|
| 173 | m_piYuvExt[ch][buf] = new Pel[ m_iYuvExtSize ]; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
[2] | 177 | // new structure |
---|
[1313] | 178 | for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++) |
---|
| 179 | { |
---|
| 180 | m_acYuvPred[i] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
| 181 | } |
---|
[2] | 182 | |
---|
[1313] | 183 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
| 184 | #if NH_3D_ARP |
---|
| 185 | m_acYuvPredBase[0] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
| 186 | m_acYuvPredBase[1] .create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
[443] | 187 | #endif |
---|
[1313] | 188 | #if NH_3D_VSP |
---|
| 189 | m_cYuvDepthOnVsp.create( MAX_CU_SIZE, MAX_CU_SIZE, chromaFormatIDC ); |
---|
[608] | 190 | #endif |
---|
[1313] | 191 | |
---|
[2] | 192 | } |
---|
| 193 | |
---|
[1313] | 194 | |
---|
[608] | 195 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
| 196 | { |
---|
| 197 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
| 198 | if (!m_pLumaRecBuffer) |
---|
| 199 | { |
---|
| 200 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
| 201 | } |
---|
| 202 | } |
---|
[1313] | 203 | #if NH_3D_IC |
---|
[608] | 204 | m_uiaShift[0] = 0; |
---|
[56] | 205 | for( Int i = 1; i < 64; i++ ) |
---|
| 206 | { |
---|
[608] | 207 | m_uiaShift[i] = ( (1 << 15) + i/2 ) / i; |
---|
| 208 | } |
---|
| 209 | #endif |
---|
[2] | 210 | } |
---|
| 211 | |
---|
| 212 | // ==================================================================================================================== |
---|
| 213 | // Public member functions |
---|
| 214 | // ==================================================================================================================== |
---|
| 215 | |
---|
| 216 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
[1313] | 217 | //NOTE: Bit-Limit - 25-bit source |
---|
| 218 | Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight) |
---|
[2] | 219 | { |
---|
[608] | 220 | assert(iWidth > 0 && iHeight > 0); |
---|
[2] | 221 | Int iInd, iSum = 0; |
---|
| 222 | Pel pDcVal; |
---|
| 223 | |
---|
[1313] | 224 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
[2] | 225 | { |
---|
[1313] | 226 | iSum += pSrc[iInd-iSrcStride]; |
---|
[2] | 227 | } |
---|
[1313] | 228 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
[2] | 229 | { |
---|
[1313] | 230 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
[2] | 231 | } |
---|
| 232 | |
---|
[1313] | 233 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
| 234 | |
---|
[2] | 235 | return pDcVal; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | // Function for deriving the angular Intra predictions |
---|
| 239 | |
---|
| 240 | /** Function for deriving the simplified angular intra predictions. |
---|
[1313] | 241 | * \param bitDepth bit depth |
---|
| 242 | * \param pSrc pointer to reconstructed sample array |
---|
| 243 | * \param srcStride the stride of the reconstructed sample array |
---|
| 244 | * \param pTrueDst reference to pointer for the prediction sample array |
---|
| 245 | * \param dstStrideTrue the stride of the prediction sample array |
---|
| 246 | * \param uiWidth the width of the block |
---|
| 247 | * \param uiHeight the height of the block |
---|
| 248 | * \param channelType type of pel array (luma/chroma) |
---|
| 249 | * \param format chroma format |
---|
| 250 | * \param dirMode the intra prediction mode index |
---|
| 251 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
| 252 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
| 253 | * \param bEnableEdgeFilters indication whether to enable edge filters |
---|
[2] | 254 | * |
---|
| 255 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
| 256 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
| 257 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
| 258 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
| 259 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
| 260 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
| 261 | * from the extended main reference. |
---|
| 262 | */ |
---|
[1313] | 263 | //NOTE: Bit-Limit - 25-bit source |
---|
| 264 | Void TComPrediction::xPredIntraAng( Int bitDepth, |
---|
| 265 | const Pel* pSrc, Int srcStride, |
---|
| 266 | Pel* pTrueDst, Int dstStrideTrue, |
---|
| 267 | UInt uiWidth, UInt uiHeight, ChannelType channelType, |
---|
| 268 | UInt dirMode, const Bool bEnableEdgeFilters |
---|
| 269 | ) |
---|
[2] | 270 | { |
---|
[1313] | 271 | Int width=Int(uiWidth); |
---|
| 272 | Int height=Int(uiHeight); |
---|
[2] | 273 | |
---|
| 274 | // Map the mode index to main prediction direction and angle |
---|
[1313] | 275 | assert( dirMode != PLANAR_IDX ); //no planar |
---|
| 276 | const Bool modeDC = dirMode==DC_IDX; |
---|
[2] | 277 | |
---|
| 278 | // Do the DC prediction |
---|
| 279 | if (modeDC) |
---|
| 280 | { |
---|
[1313] | 281 | const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height); |
---|
[2] | 282 | |
---|
[1313] | 283 | for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue) |
---|
[2] | 284 | { |
---|
[1313] | 285 | for (Int x=0; x<width;) // width is always a multiple of 4. |
---|
[2] | 286 | { |
---|
[1313] | 287 | pTrueDst[x++] = dcval; |
---|
[2] | 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
[1313] | 291 | else // Do angular predictions |
---|
| 292 | { |
---|
| 293 | const Bool bIsModeVer = (dirMode >= 18); |
---|
| 294 | const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX); |
---|
| 295 | const Int absAngMode = abs(intraPredAngleMode); |
---|
| 296 | const Int signAng = intraPredAngleMode < 0 ? -1 : 1; |
---|
| 297 | const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT); |
---|
[2] | 298 | |
---|
[1313] | 299 | // Set bitshifts and scale the angle parameter to block size |
---|
| 300 | static const Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
| 301 | static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
| 302 | Int invAngle = invAngTable[absAngMode]; |
---|
| 303 | Int absAng = angTable[absAngMode]; |
---|
| 304 | Int intraPredAngle = signAng * absAng; |
---|
| 305 | |
---|
[2] | 306 | Pel* refMain; |
---|
| 307 | Pel* refSide; |
---|
[1313] | 308 | |
---|
[2] | 309 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
| 310 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
| 311 | |
---|
[1313] | 312 | // Initialize the Main and Left reference array. |
---|
[2] | 313 | if (intraPredAngle < 0) |
---|
| 314 | { |
---|
[1313] | 315 | const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1; |
---|
| 316 | const Int refMainOffset = height - 1; |
---|
| 317 | for (Int x=0;x<width+1;x++) |
---|
[2] | 318 | { |
---|
[1313] | 319 | refAbove[x+refMainOffset] = pSrc[x-srcStride-1]; |
---|
[2] | 320 | } |
---|
[1313] | 321 | for (Int y=0;y<height+1;y++) |
---|
[2] | 322 | { |
---|
[1313] | 323 | refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1]; |
---|
[2] | 324 | } |
---|
[1313] | 325 | refMain = (bIsModeVer ? refAbove : refLeft) + refMainOffset; |
---|
| 326 | refSide = (bIsModeVer ? refLeft : refAbove) + refMainOffset; |
---|
[2] | 327 | |
---|
| 328 | // Extend the Main reference to the left. |
---|
| 329 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
[1313] | 330 | for (Int k=-1; k>(refMainOffsetPreScale+1)*intraPredAngle>>5; k--) |
---|
[2] | 331 | { |
---|
| 332 | invAngleSum += invAngle; |
---|
| 333 | refMain[k] = refSide[invAngleSum>>8]; |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
[1313] | 338 | for (Int x=0;x<2*width+1;x++) |
---|
[2] | 339 | { |
---|
[1313] | 340 | refAbove[x] = pSrc[x-srcStride-1]; |
---|
[2] | 341 | } |
---|
[1313] | 342 | for (Int y=0;y<2*height+1;y++) |
---|
[2] | 343 | { |
---|
[1313] | 344 | refLeft[y] = pSrc[(y-1)*srcStride-1]; |
---|
[2] | 345 | } |
---|
[1313] | 346 | refMain = bIsModeVer ? refAbove : refLeft ; |
---|
| 347 | refSide = bIsModeVer ? refLeft : refAbove; |
---|
[2] | 348 | } |
---|
| 349 | |
---|
[1313] | 350 | // swap width/height if we are doing a horizontal mode: |
---|
| 351 | Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE]; |
---|
| 352 | const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE; |
---|
| 353 | Pel *pDst = bIsModeVer ? pTrueDst : tempArray; |
---|
| 354 | if (!bIsModeVer) |
---|
[2] | 355 | { |
---|
[1313] | 356 | std::swap(width, height); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | if (intraPredAngle == 0) // pure vertical or pure horizontal |
---|
| 360 | { |
---|
| 361 | for (Int y=0;y<height;y++) |
---|
[2] | 362 | { |
---|
[1313] | 363 | for (Int x=0;x<width;x++) |
---|
[2] | 364 | { |
---|
[1313] | 365 | pDst[y*dstStride+x] = refMain[x+1]; |
---|
[2] | 366 | } |
---|
| 367 | } |
---|
[56] | 368 | |
---|
[1313] | 369 | if (edgeFilter) |
---|
[56] | 370 | { |
---|
[1313] | 371 | for (Int y=0;y<height;y++) |
---|
[56] | 372 | { |
---|
[1313] | 373 | pDst[y*dstStride] = Clip3 (0, ((1 << bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) >> 1) ); |
---|
[56] | 374 | } |
---|
| 375 | } |
---|
[2] | 376 | } |
---|
| 377 | else |
---|
| 378 | { |
---|
[1313] | 379 | Pel *pDsty=pDst; |
---|
[2] | 380 | |
---|
[1313] | 381 | for (Int y=0, deltaPos=intraPredAngle; y<height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride) |
---|
[2] | 382 | { |
---|
[1313] | 383 | const Int deltaInt = deltaPos >> 5; |
---|
| 384 | const Int deltaFract = deltaPos & (32 - 1); |
---|
[2] | 385 | |
---|
| 386 | if (deltaFract) |
---|
| 387 | { |
---|
| 388 | // Do linear filtering |
---|
[1313] | 389 | const Pel *pRM=refMain+deltaInt+1; |
---|
| 390 | Int lastRefMainPel=*pRM++; |
---|
| 391 | for (Int x=0;x<width;pRM++,x++) |
---|
[2] | 392 | { |
---|
[1313] | 393 | Int thisRefMainPel=*pRM; |
---|
| 394 | pDsty[x+0] = (Pel) ( ((32-deltaFract)*lastRefMainPel + deltaFract*thisRefMainPel +16) >> 5 ); |
---|
| 395 | lastRefMainPel=thisRefMainPel; |
---|
[2] | 396 | } |
---|
| 397 | } |
---|
| 398 | else |
---|
| 399 | { |
---|
| 400 | // Just copy the integer samples |
---|
[1313] | 401 | for (Int x=0;x<width; x++) |
---|
[2] | 402 | { |
---|
[1313] | 403 | pDsty[x] = refMain[x+deltaInt+1]; |
---|
[2] | 404 | } |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | // Flip the block if this is the horizontal mode |
---|
[1313] | 410 | if (!bIsModeVer) |
---|
[2] | 411 | { |
---|
[1313] | 412 | for (Int y=0; y<height; y++) |
---|
[2] | 413 | { |
---|
[1313] | 414 | for (Int x=0; x<width; x++) |
---|
[2] | 415 | { |
---|
[1313] | 416 | pTrueDst[x*dstStrideTrue] = pDst[x]; |
---|
[2] | 417 | } |
---|
[1313] | 418 | pTrueDst++; |
---|
| 419 | pDst+=dstStride; |
---|
[2] | 420 | } |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
[1313] | 425 | Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM ) |
---|
[2] | 426 | { |
---|
[1313] | 427 | const ChannelType channelType = toChannelType(compID); |
---|
| 428 | const TComRectangle &rect = rTu.getRect(isLuma(compID) ? COMPONENT_Y : COMPONENT_Cb); |
---|
| 429 | const Int iWidth = rect.width; |
---|
| 430 | const Int iHeight = rect.height; |
---|
[2] | 431 | |
---|
[56] | 432 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
| 433 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
[1313] | 434 | //assert( iWidth == iHeight ); |
---|
[2] | 435 | |
---|
[1313] | 436 | Pel *pDst = piPred; |
---|
[56] | 437 | |
---|
| 438 | // get starting pixel in block |
---|
[1313] | 439 | const Int sw = (2 * iWidth + 1); |
---|
[56] | 440 | |
---|
[1313] | 441 | if ( bUseLosslessDPCM ) |
---|
[56] | 442 | { |
---|
[1313] | 443 | const Pel *ptrSrc = getPredictorPtr( compID, false ); |
---|
| 444 | // Sample Adaptive intra-Prediction (SAP) |
---|
| 445 | if (uiDirMode==HOR_IDX) |
---|
| 446 | { |
---|
| 447 | // left column filled with reference samples |
---|
| 448 | // remaining columns filled with piOrg data (if available). |
---|
| 449 | for(Int y=0; y<iHeight; y++) |
---|
| 450 | { |
---|
| 451 | piPred[y*uiStride+0] = ptrSrc[(y+1)*sw]; |
---|
| 452 | } |
---|
| 453 | if (piOrg!=0) |
---|
| 454 | { |
---|
| 455 | piPred+=1; // miss off first column |
---|
| 456 | for(Int y=0; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
| 457 | { |
---|
| 458 | memcpy(piPred, piOrg, (iWidth-1)*sizeof(Pel)); |
---|
| 459 | } |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | else // VER_IDX |
---|
| 463 | { |
---|
| 464 | // top row filled with reference samples |
---|
| 465 | // remaining rows filled with piOrd data (if available) |
---|
| 466 | for(Int x=0; x<iWidth; x++) |
---|
| 467 | { |
---|
| 468 | piPred[x] = ptrSrc[x+1]; |
---|
| 469 | } |
---|
| 470 | if (piOrg!=0) |
---|
| 471 | { |
---|
| 472 | piPred+=uiStride; // miss off the first row |
---|
| 473 | for(Int y=1; y<iHeight; y++, piPred+=uiStride, piOrg+=uiOrgStride) |
---|
| 474 | { |
---|
| 475 | memcpy(piPred, piOrg, iWidth*sizeof(Pel)); |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | } |
---|
[56] | 479 | } |
---|
| 480 | else |
---|
| 481 | { |
---|
[1313] | 482 | const Pel *ptrSrc = getPredictorPtr( compID, bUseFilteredPredSamples ); |
---|
| 483 | |
---|
| 484 | if ( uiDirMode == PLANAR_IDX ) |
---|
[56] | 485 | { |
---|
[1313] | 486 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
[56] | 487 | } |
---|
[608] | 488 | else |
---|
| 489 | { |
---|
[1313] | 490 | // Create the prediction |
---|
| 491 | TComDataCU *const pcCU = rTu.getCU(); |
---|
| 492 | const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU(); |
---|
| 493 | const Bool enableEdgeFilters = !(pcCU->isRDPCMEnabled(uiAbsPartIdx) && pcCU->getCUTransquantBypass(uiAbsPartIdx)); |
---|
| 494 | #if O0043_BEST_EFFORT_DECODING |
---|
| 495 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getStreamBitDepth(channelType); |
---|
| 496 | #else |
---|
| 497 | const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType); |
---|
| 498 | #endif |
---|
| 499 | xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, enableEdgeFilters ); |
---|
[608] | 500 | |
---|
[1313] | 501 | if( uiDirMode == DC_IDX ) |
---|
[608] | 502 | { |
---|
[1313] | 503 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType ); |
---|
[608] | 504 | } |
---|
| 505 | } |
---|
[56] | 506 | } |
---|
| 507 | |
---|
| 508 | } |
---|
| 509 | |
---|
[1313] | 510 | #if NH_3D_DMM |
---|
| 511 | Void TComPrediction::predIntraLumaDmm( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight ) |
---|
[56] | 512 | { |
---|
[608] | 513 | assert( iWidth == iHeight ); |
---|
[1313] | 514 | assert( iWidth >= DMM_MIN_SIZE && iWidth <= DMM_MAX_SIZE ); |
---|
| 515 | #if NH_3D_SDC_INTRA |
---|
| 516 | assert( !pcCU->getSDCFlag( uiAbsPartIdx ) ); |
---|
| 517 | #endif |
---|
[56] | 518 | |
---|
[1313] | 519 | // get partition |
---|
| 520 | Bool* biSegPattern = new Bool[ (UInt)(iWidth*iHeight) ]; |
---|
| 521 | UInt patternStride = (UInt)iWidth; |
---|
| 522 | switch( dmmType ) |
---|
[100] | 523 | { |
---|
[1313] | 524 | case( DMM1_IDX ): { (getWedgeListScaled( (UInt)iWidth )->at( pcCU->getDmm1WedgeTabIdx( uiAbsPartIdx ) )).getPatternScaledCopy( (UInt)iWidth, biSegPattern ); } break; |
---|
| 525 | case( DMM4_IDX ): { predContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern ); } break; |
---|
| 526 | default: assert(0); |
---|
[100] | 527 | } |
---|
| 528 | |
---|
[608] | 529 | // get predicted partition values |
---|
[1313] | 530 | Pel predDC1 = 0, predDC2 = 0; |
---|
| 531 | predBiSegDCs( pcCU, uiAbsPartIdx, iWidth, iHeight, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
[608] | 532 | |
---|
| 533 | // set segment values with deltaDC offsets |
---|
[1313] | 534 | Pel segDC1 = 0, segDC2 = 0; |
---|
| 535 | Pel deltaDC1 = pcCU->getDmmDeltaDC( dmmType, 0, uiAbsPartIdx ); |
---|
| 536 | Pel deltaDC2 = pcCU->getDmmDeltaDC( dmmType, 1, uiAbsPartIdx ); |
---|
| 537 | #if NH_3D_DLT |
---|
| 538 | segDC1 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
| 539 | segDC2 = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
[758] | 540 | #else |
---|
[1313] | 541 | segDC1 = ClipBD( predDC1 + deltaDC1, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
| 542 | segDC2 = ClipBD( predDC2 + deltaDC2, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
[608] | 543 | #endif |
---|
[100] | 544 | |
---|
[608] | 545 | // set prediction signal |
---|
| 546 | Pel* pDst = piPred; |
---|
[1313] | 547 | assignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
| 548 | |
---|
| 549 | delete[] biSegPattern; |
---|
[100] | 550 | } |
---|
[608] | 551 | #endif |
---|
[100] | 552 | |
---|
[1313] | 553 | /** Check for identical motion in both motion vector direction of a bi-directional predicted CU |
---|
| 554 | * \returns true, if motion vectors and reference pictures match |
---|
[608] | 555 | */ |
---|
| 556 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
[100] | 557 | { |
---|
[608] | 558 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
[100] | 559 | { |
---|
[608] | 560 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
[100] | 561 | { |
---|
[608] | 562 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
| 563 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
[1321] | 564 | #if NH_MV_FIX_TICKET_106 |
---|
| 565 | #if NH_MV |
---|
| 566 | Int layerIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getLayerId(); |
---|
| 567 | Int layerIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getLayerId(); |
---|
[1313] | 568 | #if NH_3D_ARP |
---|
[1321] | 569 | if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
| 570 | #else |
---|
| 571 | if(RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
| 572 | #endif |
---|
| 573 | #else |
---|
| 574 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
| 575 | #endif |
---|
| 576 | #else |
---|
| 577 | #if NH_3D_ARP |
---|
[950] | 578 | if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
| 579 | #else |
---|
[608] | 580 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
[950] | 581 | #endif |
---|
[1321] | 582 | #endif |
---|
[100] | 583 | { |
---|
[608] | 584 | return true; |
---|
[100] | 585 | } |
---|
| 586 | } |
---|
| 587 | } |
---|
[608] | 588 | return false; |
---|
[100] | 589 | } |
---|
| 590 | |
---|
[1313] | 591 | #if NH_3D_SPIVMP |
---|
[724] | 592 | Void TComPrediction::xGetSubPUAddrAndMerge(TComDataCU* pcCU, UInt uiPartAddr, Int iSPWidth, Int iSPHeight, Int iNumSPInOneLine, Int iNumSP, UInt* uiMergedSPW, UInt* uiMergedSPH, UInt* uiSPAddr ) |
---|
| 593 | { |
---|
| 594 | for (Int i = 0; i < iNumSP; i++) |
---|
| 595 | { |
---|
| 596 | uiMergedSPW[i] = iSPWidth; |
---|
| 597 | uiMergedSPH[i] = iSPHeight; |
---|
| 598 | pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]); |
---|
| 599 | } |
---|
[1321] | 600 | #if NH_3D_ARP |
---|
[1039] | 601 | if( pcCU->getARPW( uiPartAddr ) != 0 ) |
---|
| 602 | { |
---|
| 603 | return; |
---|
| 604 | } |
---|
[1313] | 605 | #endif |
---|
[1084] | 606 | |
---|
[724] | 607 | // horizontal sub-PU merge |
---|
| 608 | for (Int i=0; i<iNumSP; i++) |
---|
| 609 | { |
---|
| 610 | if (i % iNumSPInOneLine == iNumSPInOneLine - 1 || uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
| 611 | { |
---|
| 612 | continue; |
---|
| 613 | } |
---|
| 614 | for (Int j=i+1; j<i+iNumSPInOneLine-i%iNumSPInOneLine; j++) |
---|
| 615 | { |
---|
| 616 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j])) |
---|
| 617 | { |
---|
| 618 | uiMergedSPW[i] += iSPWidth; |
---|
| 619 | uiMergedSPW[j] = uiMergedSPH[j] = 0; |
---|
| 620 | } |
---|
| 621 | else |
---|
| 622 | { |
---|
| 623 | break; |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | //vertical sub-PU merge |
---|
| 628 | for (Int i=0; i<iNumSP-iNumSPInOneLine; i++) |
---|
| 629 | { |
---|
| 630 | if (uiMergedSPW[i]==0 || uiMergedSPH[i]==0) |
---|
| 631 | { |
---|
| 632 | continue; |
---|
| 633 | } |
---|
| 634 | for (Int j=i+iNumSPInOneLine; j<iNumSP; j+=iNumSPInOneLine) |
---|
| 635 | { |
---|
| 636 | if (xCheckTwoSPMotion(pcCU, uiSPAddr[i], uiSPAddr[j]) && uiMergedSPW[i]==uiMergedSPW[j]) |
---|
| 637 | { |
---|
| 638 | uiMergedSPH[i] += iSPHeight; |
---|
| 639 | uiMergedSPH[j] = uiMergedSPW[j] = 0; |
---|
| 640 | } |
---|
| 641 | else |
---|
| 642 | { |
---|
| 643 | break; |
---|
| 644 | } |
---|
| 645 | } |
---|
| 646 | } |
---|
| 647 | } |
---|
[608] | 648 | |
---|
[724] | 649 | Bool TComPrediction::xCheckTwoSPMotion ( TComDataCU* pcCU, UInt PartAddr0, UInt PartAddr1 ) |
---|
| 650 | { |
---|
| 651 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr1)) |
---|
| 652 | { |
---|
| 653 | return false; |
---|
| 654 | } |
---|
| 655 | if( pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr1)) |
---|
| 656 | { |
---|
| 657 | return false; |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr0) >= 0) |
---|
| 661 | { |
---|
| 662 | if (pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr1)) |
---|
| 663 | { |
---|
| 664 | return false; |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr0) >= 0) |
---|
| 669 | { |
---|
| 670 | if (pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr0) != pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr1)) |
---|
| 671 | { |
---|
| 672 | return false; |
---|
| 673 | } |
---|
| 674 | } |
---|
| 675 | return true; |
---|
| 676 | } |
---|
| 677 | #endif |
---|
| 678 | |
---|
[1313] | 679 | #if NH_3D_DBBP |
---|
[1179] | 680 | PartSize TComPrediction::getPartitionSizeFromDepth(Pel* pDepthPels, UInt uiDepthStride, UInt uiSize, TComDataCU*& pcCU) |
---|
[833] | 681 | { |
---|
[1313] | 682 | const TComSPS* sps = pcCU->getSlice()->getSPS(); |
---|
| 683 | UInt uiMaxCUWidth = sps->getMaxCUWidth(); |
---|
| 684 | UInt uiMaxCUHeight = sps->getMaxCUHeight(); |
---|
| 685 | |
---|
[833] | 686 | // find virtual partitioning for this CU based on depth block |
---|
| 687 | // segmentation of texture block --> mask IDs |
---|
| 688 | Pel* pDepthBlockStart = pDepthPels; |
---|
[1196] | 689 | |
---|
[833] | 690 | // first compute average of depth block for thresholding |
---|
| 691 | Int iSumDepth = 0; |
---|
| 692 | Int iSubSample = 4; |
---|
[1313] | 693 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y); |
---|
| 694 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y); |
---|
[1179] | 695 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
| 696 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
| 697 | { |
---|
| 698 | cDv.setVer(0); |
---|
| 699 | } |
---|
[1313] | 700 | Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2); |
---|
| 701 | Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2); |
---|
[1196] | 702 | |
---|
[1179] | 703 | UInt t=0; |
---|
| 704 | |
---|
[833] | 705 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
[1196] | 706 | { |
---|
[1179] | 707 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
[1196] | 708 | { |
---|
| 709 | if (iBlkX+x>iPictureWidth) |
---|
| 710 | { |
---|
| 711 | Int depthPel = pDepthPels[t]; |
---|
| 712 | iSumDepth += depthPel; |
---|
| 713 | } |
---|
| 714 | else |
---|
| 715 | { |
---|
| 716 | Int depthPel = pDepthPels[x]; |
---|
| 717 | t=x; |
---|
| 718 | iSumDepth += depthPel; |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | |
---|
[1179] | 722 | // next row |
---|
| 723 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
[833] | 724 | { |
---|
[1196] | 725 | pDepthPels += uiDepthStride*iSubSample; |
---|
[833] | 726 | } |
---|
| 727 | } |
---|
[1196] | 728 | |
---|
[833] | 729 | Int iSizeInBits = g_aucConvertToBit[uiSize] - g_aucConvertToBit[iSubSample]; // respect sub-sampling factor |
---|
| 730 | Int iMean = iSumDepth >> iSizeInBits*2; // iMean /= (uiSize*uiSize); |
---|
[1196] | 731 | |
---|
[833] | 732 | // start again for segmentation |
---|
| 733 | pDepthPels = pDepthBlockStart; |
---|
[1196] | 734 | |
---|
[833] | 735 | // start mapping process |
---|
[950] | 736 | Int matchedPartSum[2][2] = {{0,0},{0,0}}; // counter for each part size and boolean option |
---|
| 737 | PartSize virtualPartSizes[2] = { SIZE_Nx2N, SIZE_2NxN}; |
---|
[1196] | 738 | |
---|
[833] | 739 | UInt uiHalfSize = uiSize>>1; |
---|
| 740 | for (Int y=0; y<uiSize; y+=iSubSample) |
---|
| 741 | { |
---|
| 742 | for (Int x=0; x<uiSize; x+=iSubSample) |
---|
| 743 | { |
---|
[1179] | 744 | Int depthPel = 0; |
---|
[1196] | 745 | if (iBlkX+x>iPictureWidth) |
---|
| 746 | { |
---|
| 747 | depthPel = pDepthPels[t]; |
---|
| 748 | } |
---|
| 749 | else |
---|
| 750 | { |
---|
| 751 | depthPel = pDepthPels[x]; |
---|
| 752 | t=x; |
---|
| 753 | } |
---|
| 754 | |
---|
[833] | 755 | // decide which segment this pixel belongs to |
---|
| 756 | Int ucSegment = (Int)(depthPel>iMean); |
---|
[1196] | 757 | |
---|
[833] | 758 | // Matched Filter to find optimal (conventional) partitioning |
---|
[1196] | 759 | |
---|
[833] | 760 | // SIZE_Nx2N |
---|
| 761 | if(x<uiHalfSize) // left |
---|
| 762 | { |
---|
| 763 | matchedPartSum[0][ucSegment]++; |
---|
| 764 | } |
---|
| 765 | else // right |
---|
| 766 | { |
---|
| 767 | matchedPartSum[0][1-ucSegment]++; |
---|
| 768 | } |
---|
[1196] | 769 | |
---|
[833] | 770 | // SIZE_2NxN |
---|
| 771 | if(y<uiHalfSize) // top |
---|
| 772 | { |
---|
| 773 | matchedPartSum[1][ucSegment]++; |
---|
| 774 | } |
---|
| 775 | else // bottom |
---|
| 776 | { |
---|
| 777 | matchedPartSum[1][1-ucSegment]++; |
---|
| 778 | } |
---|
| 779 | } |
---|
[1196] | 780 | |
---|
[833] | 781 | // next row |
---|
[1179] | 782 | if (!(iBlkY+y+4>iPictureHeight)) |
---|
[1196] | 783 | { |
---|
| 784 | pDepthPels += uiDepthStride*iSubSample; |
---|
| 785 | } |
---|
[833] | 786 | } |
---|
[1196] | 787 | |
---|
[1313] | 788 | PartSize matchedPartSize = NUMBER_OF_PART_SIZES; |
---|
[1196] | 789 | |
---|
[833] | 790 | Int iMaxMatchSum = 0; |
---|
[950] | 791 | for(Int p=0; p<2; p++) // loop over partition |
---|
[833] | 792 | { |
---|
| 793 | for( Int b=0; b<=1; b++ ) // loop over boolean options |
---|
| 794 | { |
---|
| 795 | if(matchedPartSum[p][b] > iMaxMatchSum) |
---|
| 796 | { |
---|
| 797 | iMaxMatchSum = matchedPartSum[p][b]; |
---|
| 798 | matchedPartSize = virtualPartSizes[p]; |
---|
| 799 | } |
---|
| 800 | } |
---|
| 801 | } |
---|
[1196] | 802 | |
---|
[1313] | 803 | AOF( matchedPartSize != NUMBER_OF_PART_SIZES ); |
---|
[1196] | 804 | |
---|
[833] | 805 | return matchedPartSize; |
---|
| 806 | } |
---|
| 807 | |
---|
[1179] | 808 | Bool TComPrediction::getSegmentMaskFromDepth( Pel* pDepthPels, UInt uiDepthStride, UInt uiWidth, UInt uiHeight, Bool* pMask, TComDataCU*& pcCU) |
---|
[833] | 809 | { |
---|
[1313] | 810 | const TComSPS* sps = pcCU->getSlice()->getSPS(); |
---|
| 811 | UInt uiMaxCUWidth = sps->getMaxCUWidth(); |
---|
| 812 | UInt uiMaxCUHeight = sps->getMaxCUHeight(); |
---|
| 813 | |
---|
[833] | 814 | // segmentation of texture block --> mask IDs |
---|
| 815 | Pel* pDepthBlockStart = pDepthPels; |
---|
[1179] | 816 | |
---|
[833] | 817 | // first compute average of depth block for thresholding |
---|
| 818 | Int iSumDepth = 0; |
---|
| 819 | Int uiMinDepth = MAX_INT; |
---|
| 820 | Int uiMaxDepth = 0; |
---|
[1179] | 821 | uiMinDepth = pDepthPels[ 0 ]; |
---|
| 822 | uiMaxDepth = pDepthPels[ 0 ]; |
---|
[1039] | 823 | iSumDepth = pDepthPels[ 0 ]; |
---|
[1196] | 824 | |
---|
[1313] | 825 | Int iPictureWidth = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getWidth(COMPONENT_Y); |
---|
| 826 | Int iPictureHeight = pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getPicYuvRec()->getHeight(COMPONENT_Y); |
---|
[1179] | 827 | TComMv cDv = pcCU->getSlice()->getDepthRefinementFlag( ) ? pcCU->getDvInfo(0).m_acDoNBDV : pcCU->getDvInfo(0).m_acNBDV; |
---|
| 828 | if( pcCU->getSlice()->getDepthRefinementFlag( ) ) |
---|
| 829 | { |
---|
| 830 | cDv.setVer(0); |
---|
| 831 | } |
---|
[1313] | 832 | Int iBlkX = ( pcCU->getCtuRsAddr() % pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUWidth + g_auiRasterToPelX[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getHor()+2)>>2); |
---|
| 833 | Int iBlkY = ( pcCU->getCtuRsAddr() / pcCU->getSlice()->getIvPic (true, pcCU->getDvInfo(0).m_aVIdxCan)->getFrameWidthInCtus() ) * uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ pcCU->getZorderIdxInCtu() ] ]+ ((cDv.getVer()+2)>>2); |
---|
[1179] | 834 | if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
| 835 | { |
---|
| 836 | iSumDepth += pDepthPels[ iPictureWidth - iBlkX - 1 ]; |
---|
| 837 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
| 838 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ iPictureWidth - iBlkX - 1 ]); |
---|
| 839 | } |
---|
| 840 | else |
---|
| 841 | { |
---|
| 842 | iSumDepth += pDepthPels[ uiWidth - 1 ]; |
---|
| 843 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
| 844 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiWidth - 1 ]); |
---|
| 845 | } |
---|
| 846 | if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
| 847 | { |
---|
| 848 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]; |
---|
| 849 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
| 850 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) ]); |
---|
| 851 | } |
---|
| 852 | else |
---|
| 853 | { |
---|
| 854 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) ]; |
---|
| 855 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
| 856 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) ]); |
---|
| 857 | } |
---|
| 858 | if (iBlkY>(Int)(iPictureHeight - uiHeight) && iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
| 859 | { |
---|
| 860 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
| 861 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
| 862 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
| 863 | } |
---|
| 864 | else if (iBlkY>(Int)(iPictureHeight - uiHeight)) |
---|
| 865 | { |
---|
| 866 | iSumDepth += pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]; |
---|
| 867 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
| 868 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (iPictureHeight - iBlkY - 1) + uiWidth - 1 ]); |
---|
| 869 | } |
---|
| 870 | else if (iBlkX>(Int)(iPictureWidth - uiWidth)) |
---|
| 871 | { |
---|
| 872 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]; |
---|
| 873 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
| 874 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + iPictureWidth - iBlkX - 1 ]); |
---|
| 875 | } |
---|
| 876 | else |
---|
| 877 | { |
---|
| 878 | iSumDepth += pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]; |
---|
| 879 | uiMinDepth = std::min( uiMinDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
| 880 | uiMaxDepth = std::max( uiMaxDepth, (Int)pDepthPels[ uiDepthStride * (uiHeight - 1) + uiWidth - 1 ]); |
---|
| 881 | } |
---|
[1039] | 882 | |
---|
[833] | 883 | // don't generate mask for blocks with small depth range (encoder decision) |
---|
| 884 | if( uiMaxDepth - uiMinDepth < 10 ) |
---|
| 885 | { |
---|
| 886 | return false; |
---|
| 887 | } |
---|
[1179] | 888 | |
---|
[833] | 889 | AOF(uiWidth==uiHeight); |
---|
[1039] | 890 | Int iMean = iSumDepth >> 2; |
---|
[1179] | 891 | |
---|
[833] | 892 | // start again for segmentation |
---|
| 893 | pDepthPels = pDepthBlockStart; |
---|
[1179] | 894 | |
---|
[833] | 895 | Bool bInvertMask = pDepthPels[0]>iMean; // top-left segment needs to be mapped to partIdx 0 |
---|
[1179] | 896 | |
---|
[833] | 897 | // generate mask |
---|
[1196] | 898 | UInt t=0; |
---|
[833] | 899 | UInt uiSumPix[2] = {0,0}; |
---|
| 900 | for (Int y=0; y<uiHeight; y++) |
---|
| 901 | { |
---|
| 902 | for (Int x=0; x<uiHeight; x++) |
---|
| 903 | { |
---|
[1179] | 904 | Int depthPel = 0; |
---|
| 905 | if (iBlkX+x>iPictureWidth) |
---|
| 906 | { |
---|
| 907 | depthPel = pDepthPels[t]; |
---|
| 908 | } |
---|
| 909 | else |
---|
| 910 | { |
---|
| 911 | depthPel = pDepthPels[x]; |
---|
| 912 | t=x; |
---|
| 913 | } |
---|
| 914 | |
---|
[833] | 915 | // decide which segment this pixel belongs to |
---|
| 916 | Int ucSegment = (Int)(depthPel>iMean); |
---|
[1179] | 917 | |
---|
[833] | 918 | if( bInvertMask ) |
---|
| 919 | { |
---|
| 920 | ucSegment = 1-ucSegment; |
---|
| 921 | } |
---|
[1179] | 922 | |
---|
[833] | 923 | // count pixels for each segment |
---|
| 924 | uiSumPix[ucSegment]++; |
---|
[1179] | 925 | |
---|
[833] | 926 | // set mask value |
---|
| 927 | pMask[x] = (Bool)ucSegment; |
---|
| 928 | } |
---|
[1179] | 929 | |
---|
[833] | 930 | // next row |
---|
[1179] | 931 | if (!(iBlkY+y+1>iPictureHeight)) |
---|
| 932 | pDepthPels += uiDepthStride; |
---|
[833] | 933 | pMask += MAX_CU_SIZE; |
---|
| 934 | } |
---|
[1179] | 935 | |
---|
[833] | 936 | // don't generate valid mask for tiny segments (encoder decision) |
---|
| 937 | // each segment needs to cover at least 1/8th of block |
---|
| 938 | UInt uiMinPixPerSegment = (uiWidth*uiHeight) >> 3; |
---|
| 939 | if( !( uiSumPix[0] > uiMinPixPerSegment && uiSumPix[1] > uiMinPixPerSegment ) ) |
---|
| 940 | { |
---|
| 941 | return false; |
---|
| 942 | } |
---|
[1179] | 943 | |
---|
[833] | 944 | // all good |
---|
| 945 | return true; |
---|
| 946 | } |
---|
| 947 | |
---|
[1313] | 948 | Void TComPrediction::combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize, Int bitDepthY ) |
---|
[833] | 949 | { |
---|
[1313] | 950 | Pel* piSrc[2] = {pInYuv[0]->getAddr(COMPONENT_Y, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Y, uiPartAddr)}; |
---|
| 951 | UInt uiSrcStride = pInYuv[0]->getStride(COMPONENT_Y); |
---|
| 952 | Pel* piDst = pOutYuv->getAddr(COMPONENT_Y, uiPartAddr); |
---|
| 953 | UInt uiDstStride = pOutYuv->getStride(COMPONENT_Y); |
---|
[833] | 954 | |
---|
| 955 | UInt uiMaskStride= MAX_CU_SIZE; |
---|
[950] | 956 | Pel* tmpTar = 0; |
---|
| 957 | tmpTar = (Pel *)xMalloc(Pel, uiWidth*uiHeight); |
---|
[833] | 958 | |
---|
| 959 | // backup pointer |
---|
| 960 | Bool* pMaskStart = pMask; |
---|
| 961 | |
---|
| 962 | // combine luma first |
---|
| 963 | for (Int y=0; y<uiHeight; y++) |
---|
| 964 | { |
---|
| 965 | for (Int x=0; x<uiWidth; x++) |
---|
| 966 | { |
---|
| 967 | UChar ucSegment = (UChar)pMask[x]; |
---|
| 968 | AOF( ucSegment < 2 ); |
---|
| 969 | |
---|
| 970 | // filtering |
---|
[950] | 971 | tmpTar[y*uiWidth+x] = piSrc[ucSegment][x]; |
---|
[833] | 972 | } |
---|
| 973 | |
---|
| 974 | piSrc[0] += uiSrcStride; |
---|
| 975 | piSrc[1] += uiSrcStride; |
---|
| 976 | pMask += uiMaskStride; |
---|
| 977 | } |
---|
| 978 | |
---|
[1039] | 979 | if (partSize == SIZE_Nx2N) |
---|
| 980 | { |
---|
| 981 | for (Int y=0; y<uiHeight; y++) |
---|
| 982 | { |
---|
| 983 | for (Int x=0; x<uiWidth; x++) |
---|
| 984 | { |
---|
| 985 | Bool l = (x==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x-1]; |
---|
| 986 | Bool r = (x==uiWidth-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[y*uiMaskStride+x+1]; |
---|
| 987 | |
---|
| 988 | Pel left, right; |
---|
| 989 | left = (x==0) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x-1]; |
---|
| 990 | right = (x==uiWidth-1) ? tmpTar[y*uiWidth+x] : tmpTar[y*uiWidth+x+1]; |
---|
| 991 | |
---|
[1313] | 992 | piDst[x] = (l!=r) ? ClipBD( Pel(( left + (tmpTar[y*uiWidth+x] << 1) + right ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x]; |
---|
[1039] | 993 | } |
---|
| 994 | piDst += uiDstStride; |
---|
| 995 | } |
---|
| 996 | } |
---|
| 997 | else // SIZE_2NxN |
---|
| 998 | { |
---|
| 999 | for (Int y=0; y<uiHeight; y++) |
---|
| 1000 | { |
---|
| 1001 | for (Int x=0; x<uiWidth; x++) |
---|
| 1002 | { |
---|
| 1003 | Bool t = (y==0)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y-1)*uiMaskStride+x]; |
---|
| 1004 | Bool b = (y==uiHeight-1)?pMaskStart[y*uiMaskStride+x]:pMaskStart[(y+1)*uiMaskStride+x]; |
---|
| 1005 | |
---|
| 1006 | Pel top, bottom; |
---|
| 1007 | top = (y==0) ? tmpTar[y*uiWidth+x] : tmpTar[(y-1)*uiWidth+x]; |
---|
| 1008 | bottom = (y==uiHeight-1) ? tmpTar[y*uiWidth+x] : tmpTar[(y+1)*uiWidth+x]; |
---|
| 1009 | |
---|
[1313] | 1010 | piDst[x] = (t!=b) ? ClipBD( Pel(( top + (tmpTar[y*uiWidth+x] << 1) + bottom ) >> 2 ), bitDepthY) : tmpTar[y*uiWidth+x]; |
---|
[1039] | 1011 | } |
---|
| 1012 | piDst += uiDstStride; |
---|
| 1013 | } |
---|
| 1014 | } |
---|
[950] | 1015 | |
---|
[1196] | 1016 | if ( tmpTar ) |
---|
| 1017 | { |
---|
| 1018 | xFree(tmpTar); |
---|
| 1019 | tmpTar = NULL; |
---|
| 1020 | } |
---|
[950] | 1021 | |
---|
[833] | 1022 | // now combine chroma |
---|
[1313] | 1023 | Pel* piSrcU[2] = { pInYuv[0]->getAddr(COMPONENT_Cb, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cb, uiPartAddr) }; |
---|
| 1024 | Pel* piSrcV[2] = { pInYuv[0]->getAddr(COMPONENT_Cr, uiPartAddr), pInYuv[1]->getAddr(COMPONENT_Cr, uiPartAddr) }; |
---|
| 1025 | UInt uiSrcStrideC = pInYuv[0]->getStride(COMPONENT_Cb); |
---|
| 1026 | Pel* piDstU = pOutYuv->getAddr(COMPONENT_Cb, uiPartAddr); |
---|
| 1027 | Pel* piDstV = pOutYuv->getAddr(COMPONENT_Cr, uiPartAddr); |
---|
| 1028 | UInt uiDstStrideC = pOutYuv->getStride(COMPONENT_Cb); |
---|
[833] | 1029 | UInt uiWidthC = uiWidth >> 1; |
---|
| 1030 | UInt uiHeightC = uiHeight >> 1; |
---|
[950] | 1031 | Pel filSrcU = 0, filSrcV = 0; |
---|
| 1032 | Pel* tmpTarU = 0, *tmpTarV = 0; |
---|
| 1033 | tmpTarU = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
| 1034 | tmpTarV = (Pel *)xMalloc(Pel, uiWidthC*uiHeightC); |
---|
[833] | 1035 | pMask = pMaskStart; |
---|
| 1036 | |
---|
| 1037 | for (Int y=0; y<uiHeightC; y++) |
---|
| 1038 | { |
---|
| 1039 | for (Int x=0; x<uiWidthC; x++) |
---|
| 1040 | { |
---|
| 1041 | UChar ucSegment = (UChar)pMask[x*2]; |
---|
| 1042 | AOF( ucSegment < 2 ); |
---|
| 1043 | |
---|
| 1044 | // filtering |
---|
[950] | 1045 | tmpTarU[y*uiWidthC+x] = piSrcU[ucSegment][x]; |
---|
| 1046 | tmpTarV[y*uiWidthC+x] = piSrcV[ucSegment][x]; |
---|
[833] | 1047 | } |
---|
| 1048 | |
---|
| 1049 | piSrcU[0] += uiSrcStrideC; |
---|
| 1050 | piSrcU[1] += uiSrcStrideC; |
---|
| 1051 | piSrcV[0] += uiSrcStrideC; |
---|
| 1052 | piSrcV[1] += uiSrcStrideC; |
---|
| 1053 | pMask += 2*uiMaskStride; |
---|
| 1054 | } |
---|
[950] | 1055 | |
---|
[1039] | 1056 | if (partSize == SIZE_Nx2N) |
---|
| 1057 | { |
---|
| 1058 | for (Int y=0; y<uiHeightC; y++) |
---|
| 1059 | { |
---|
| 1060 | for (Int x=0; x<uiWidthC; x++) |
---|
| 1061 | { |
---|
| 1062 | Bool l = (x==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x-1)*2]; |
---|
| 1063 | Bool r = (x==uiWidthC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[y*2*uiMaskStride+(x+1)*2]; |
---|
| 1064 | |
---|
| 1065 | Pel leftU, rightU; |
---|
| 1066 | leftU = (x==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x-1]; |
---|
| 1067 | rightU = (x==uiWidthC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[y*uiWidthC+x+1]; |
---|
| 1068 | Pel leftV, rightV; |
---|
| 1069 | leftV = (x==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x-1]; |
---|
| 1070 | rightV = (x==uiWidthC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[y*uiWidthC+x+1]; |
---|
| 1071 | |
---|
| 1072 | if (l!=r) |
---|
| 1073 | { |
---|
[1313] | 1074 | filSrcU = ClipBD( Pel(( leftU + (tmpTarU[y*uiWidthC+x] << 1) + rightU ) >> 2 ), bitDepthY); |
---|
| 1075 | filSrcV = ClipBD( Pel(( leftV + (tmpTarV[y*uiWidthC+x] << 1) + rightV ) >> 2 ), bitDepthY); |
---|
[1039] | 1076 | } |
---|
| 1077 | else |
---|
| 1078 | { |
---|
| 1079 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
| 1080 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
| 1081 | } |
---|
| 1082 | piDstU[x] = filSrcU; |
---|
| 1083 | piDstV[x] = filSrcV; |
---|
| 1084 | } |
---|
| 1085 | piDstU += uiDstStrideC; |
---|
| 1086 | piDstV += uiDstStrideC; |
---|
| 1087 | } |
---|
| 1088 | } |
---|
| 1089 | else |
---|
| 1090 | { |
---|
| 1091 | for (Int y=0; y<uiHeightC; y++) |
---|
| 1092 | { |
---|
| 1093 | for (Int x=0; x<uiWidthC; x++) |
---|
| 1094 | { |
---|
| 1095 | Bool t = (y==0)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y-1)*2*uiMaskStride+x*2]; |
---|
| 1096 | Bool b = (y==uiHeightC-1)?pMaskStart[y*2*uiMaskStride+x*2]:pMaskStart[(y+1)*2*uiMaskStride+x*2]; |
---|
| 1097 | |
---|
| 1098 | Pel topU, bottomU; |
---|
| 1099 | topU = (y==0) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y-1)*uiWidthC+x]; |
---|
| 1100 | bottomU = (y==uiHeightC-1) ? tmpTarU[y*uiWidthC+x] : tmpTarU[(y+1)*uiWidthC+x]; |
---|
| 1101 | Pel topV, bottomV; |
---|
| 1102 | topV = (y==0) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y-1)*uiWidthC+x]; |
---|
| 1103 | bottomV = (y==uiHeightC-1) ? tmpTarV[y*uiWidthC+x] : tmpTarV[(y+1)*uiWidthC+x]; |
---|
| 1104 | |
---|
| 1105 | if (t!=b) |
---|
| 1106 | { |
---|
[1313] | 1107 | filSrcU = ClipBD( Pel(( topU + (tmpTarU[y*uiWidthC+x] << 1) + bottomU ) >> 2 ), bitDepthY); |
---|
| 1108 | filSrcV = ClipBD( Pel(( topV + (tmpTarV[y*uiWidthC+x] << 1) + bottomV ) >> 2 ), bitDepthY); |
---|
[1039] | 1109 | } |
---|
| 1110 | else |
---|
| 1111 | { |
---|
| 1112 | filSrcU = tmpTarU[y*uiWidthC+x]; |
---|
| 1113 | filSrcV = tmpTarV[y*uiWidthC+x]; |
---|
| 1114 | } |
---|
| 1115 | piDstU[x] = filSrcU; |
---|
| 1116 | piDstV[x] = filSrcV; |
---|
| 1117 | } |
---|
| 1118 | piDstU += uiDstStrideC; |
---|
| 1119 | piDstV += uiDstStrideC; |
---|
| 1120 | } |
---|
| 1121 | } |
---|
[950] | 1122 | |
---|
[1196] | 1123 | if( tmpTarU ) |
---|
| 1124 | { |
---|
| 1125 | xFree(tmpTarU); |
---|
| 1126 | tmpTarU = NULL; |
---|
| 1127 | } |
---|
| 1128 | if ( tmpTarV ) |
---|
| 1129 | { |
---|
| 1130 | xFree(tmpTarV); |
---|
| 1131 | tmpTarV = NULL; |
---|
| 1132 | } |
---|
[833] | 1133 | } |
---|
| 1134 | #endif |
---|
| 1135 | |
---|
[56] | 1136 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
| 1137 | { |
---|
| 1138 | Int iWidth; |
---|
| 1139 | Int iHeight; |
---|
| 1140 | UInt uiPartAddr; |
---|
| 1141 | |
---|
| 1142 | if ( iPartIdx >= 0 ) |
---|
| 1143 | { |
---|
| 1144 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
[1313] | 1145 | #if NH_3D_VSP |
---|
[622] | 1146 | if ( pcCU->getVSPFlag(uiPartAddr) == 0) |
---|
[56] | 1147 | { |
---|
| 1148 | #endif |
---|
[608] | 1149 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
[56] | 1150 | { |
---|
[608] | 1151 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
| 1152 | { |
---|
| 1153 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
| 1154 | } |
---|
| 1155 | else |
---|
| 1156 | { |
---|
| 1157 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 1158 | } |
---|
| 1159 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
| 1160 | { |
---|
| 1161 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 1162 | } |
---|
[56] | 1163 | } |
---|
| 1164 | else |
---|
| 1165 | { |
---|
[1313] | 1166 | #if NH_3D_SPIVMP |
---|
[724] | 1167 | if ( pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
[608] | 1168 | { |
---|
[724] | 1169 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
| 1170 | |
---|
| 1171 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
| 1172 | |
---|
| 1173 | UInt uiW[256], uiH[256]; |
---|
| 1174 | UInt uiSPAddr[256]; |
---|
| 1175 | |
---|
| 1176 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
| 1177 | |
---|
| 1178 | //MC |
---|
| 1179 | for (Int i = 0; i < iNumSP; i++) |
---|
| 1180 | { |
---|
| 1181 | if (uiW[i]==0 || uiH[i]==0) |
---|
| 1182 | { |
---|
| 1183 | continue; |
---|
| 1184 | } |
---|
| 1185 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
| 1186 | { |
---|
| 1187 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
| 1188 | } |
---|
| 1189 | else |
---|
| 1190 | { |
---|
| 1191 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
| 1192 | } |
---|
| 1193 | } |
---|
[608] | 1194 | } |
---|
| 1195 | else |
---|
| 1196 | { |
---|
[724] | 1197 | #endif |
---|
| 1198 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 1199 | { |
---|
| 1200 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 1201 | } |
---|
| 1202 | else |
---|
| 1203 | { |
---|
| 1204 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 1205 | } |
---|
[1313] | 1206 | #if NH_3D_SPIVMP |
---|
[608] | 1207 | } |
---|
[724] | 1208 | #endif |
---|
[56] | 1209 | } |
---|
[1313] | 1210 | #if NH_3D_VSP |
---|
[56] | 1211 | } |
---|
| 1212 | else |
---|
| 1213 | { |
---|
[608] | 1214 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
[622] | 1215 | { |
---|
[608] | 1216 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[622] | 1217 | } |
---|
[56] | 1218 | else |
---|
[622] | 1219 | { |
---|
[608] | 1220 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
[622] | 1221 | } |
---|
[608] | 1222 | } |
---|
[296] | 1223 | #endif |
---|
[2] | 1224 | return; |
---|
| 1225 | } |
---|
[56] | 1226 | |
---|
[964] | 1227 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartitions(); iPartIdx++ ) |
---|
[56] | 1228 | { |
---|
| 1229 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 1230 | |
---|
[1313] | 1231 | #if NH_3D_VSP |
---|
[622] | 1232 | if ( pcCU->getVSPFlag(uiPartAddr) == 0 ) |
---|
[56] | 1233 | { |
---|
[189] | 1234 | #endif |
---|
[1313] | 1235 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
| 1236 | { |
---|
| 1237 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
[56] | 1238 | { |
---|
[1313] | 1239 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
[56] | 1240 | } |
---|
[608] | 1241 | else |
---|
[56] | 1242 | { |
---|
[1313] | 1243 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 1244 | } |
---|
| 1245 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
[724] | 1246 | { |
---|
[1313] | 1247 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 1248 | } |
---|
| 1249 | } |
---|
| 1250 | else |
---|
| 1251 | { |
---|
| 1252 | #if NH_3D_SPIVMP |
---|
| 1253 | if (pcCU->getSPIVMPFlag(uiPartAddr)!=0) |
---|
| 1254 | { |
---|
[724] | 1255 | Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; |
---|
| 1256 | |
---|
| 1257 | pcCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); |
---|
| 1258 | |
---|
| 1259 | UInt uiW[256], uiH[256]; |
---|
| 1260 | UInt uiSPAddr[256]; |
---|
| 1261 | |
---|
| 1262 | xGetSubPUAddrAndMerge(pcCU, uiPartAddr, iSPWidth, iSPHeight, iNumSPInOneLine, iNumSP, uiW, uiH, uiSPAddr); |
---|
| 1263 | //MC |
---|
| 1264 | for (Int i = 0; i < iNumSP; i++) |
---|
| 1265 | { |
---|
| 1266 | if (uiW[i]==0 || uiH[i]==0) |
---|
| 1267 | { |
---|
| 1268 | continue; |
---|
| 1269 | } |
---|
| 1270 | if( xCheckIdenticalMotion( pcCU, uiSPAddr[i] )) |
---|
| 1271 | { |
---|
| 1272 | xPredInterUni (pcCU, uiSPAddr[i], uiW[i], uiH[i], REF_PIC_LIST_0, pcYuvPred ); |
---|
| 1273 | } |
---|
| 1274 | else |
---|
| 1275 | { |
---|
| 1276 | xPredInterBi (pcCU, uiSPAddr[i], uiW[i], uiH[i], pcYuvPred); |
---|
| 1277 | } |
---|
| 1278 | } |
---|
| 1279 | } |
---|
| 1280 | else |
---|
| 1281 | { |
---|
| 1282 | #endif |
---|
[608] | 1283 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 1284 | { |
---|
| 1285 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 1286 | } |
---|
| 1287 | else |
---|
| 1288 | { |
---|
| 1289 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 1290 | } |
---|
[1313] | 1291 | #if NH_3D_SPIVMP |
---|
| 1292 | } |
---|
[724] | 1293 | #endif |
---|
[56] | 1294 | } |
---|
[1313] | 1295 | #if NH_3D_VSP |
---|
| 1296 | } |
---|
[56] | 1297 | else |
---|
| 1298 | { |
---|
| 1299 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
[622] | 1300 | { |
---|
[608] | 1301 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[622] | 1302 | } |
---|
[56] | 1303 | else |
---|
[622] | 1304 | { |
---|
[608] | 1305 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
[622] | 1306 | } |
---|
[56] | 1307 | } |
---|
[608] | 1308 | #endif |
---|
[56] | 1309 | } |
---|
| 1310 | return; |
---|
| 1311 | } |
---|
[2] | 1312 | |
---|
[1313] | 1313 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv* pcYuvPred, Bool bi ) |
---|
[296] | 1314 | { |
---|
[608] | 1315 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
| 1316 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
| 1317 | pcCU->clipMv(cMv); |
---|
[1321] | 1318 | |
---|
| 1319 | #if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC |
---|
| 1320 | if ( g_traceMotionInfoBeforUniPred ) |
---|
| 1321 | { |
---|
| 1322 | std::cout << "RefPic POC : " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC() << std::endl; |
---|
| 1323 | std::cout << "RefPic Layer Id: " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getLayerId() << std::endl; |
---|
| 1324 | std::cout << "RefIdx : " << iRefIdx << std::endl; |
---|
| 1325 | std::cout << "RefPIcList : " << eRefPicList << std::endl; |
---|
| 1326 | } |
---|
| 1327 | #endif |
---|
| 1328 | |
---|
[1313] | 1329 | #if NH_MV |
---|
[1196] | 1330 | pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx ); |
---|
[1179] | 1331 | #endif |
---|
[1313] | 1332 | #if NH_3D_ARP |
---|
| 1333 | if( pcCU->getARPW( uiPartAddr ) > 0 ) |
---|
[724] | 1334 | { |
---|
[1313] | 1335 | if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC() ) |
---|
[1321] | 1336 | { |
---|
[1313] | 1337 | xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , pcYuvPred , bi ); |
---|
[1321] | 1338 | } |
---|
| 1339 | else |
---|
| 1340 | { |
---|
| 1341 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, bi ); |
---|
| 1342 | } |
---|
[724] | 1343 | } |
---|
| 1344 | else |
---|
[443] | 1345 | { |
---|
[1321] | 1346 | #endif |
---|
| 1347 | |
---|
| 1348 | for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++) |
---|
[773] | 1349 | { |
---|
[1321] | 1350 | const ComponentID compID=ComponentID(comp); |
---|
[1313] | 1351 | #if NH_3D_IC |
---|
[1321] | 1352 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) ); |
---|
[1313] | 1353 | xPredInterBlk(compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) |
---|
| 1354 | #if NH_3D_ARP |
---|
[773] | 1355 | , false |
---|
[443] | 1356 | #endif |
---|
[773] | 1357 | , bICFlag ); |
---|
[443] | 1358 | #else |
---|
[1321] | 1359 | xPredInterBlk (compID, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) ); |
---|
[443] | 1360 | #endif |
---|
[1321] | 1361 | } |
---|
[1313] | 1362 | #if NH_3D_ARP |
---|
| 1363 | } |
---|
[443] | 1364 | #endif |
---|
| 1365 | } |
---|
| 1366 | |
---|
[1313] | 1367 | #if NH_3D_VSP |
---|
[608] | 1368 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
[56] | 1369 | { |
---|
[833] | 1370 | Int vspSize = pcCU->getVSPFlag( uiPartAddr ) >> 1; |
---|
| 1371 | |
---|
| 1372 | Int widthSubPU, heightSubPU; |
---|
| 1373 | if (vspSize) |
---|
| 1374 | { |
---|
| 1375 | widthSubPU = 8; |
---|
| 1376 | heightSubPU = 4; |
---|
| 1377 | } |
---|
| 1378 | else |
---|
| 1379 | { |
---|
| 1380 | widthSubPU = 4; |
---|
| 1381 | heightSubPU = 8; |
---|
| 1382 | } |
---|
| 1383 | xPredInterUniSubPU( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi, widthSubPU, heightSubPU ); |
---|
[608] | 1384 | } |
---|
[833] | 1385 | |
---|
| 1386 | Void TComPrediction::xPredInterUniSubPU( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, Int widthSubPU, Int heightSubPU ) |
---|
| 1387 | { |
---|
[1313] | 1388 | UInt numPartsInLine = pcCU->getPic()->getNumPartInCtuWidth(); |
---|
[833] | 1389 | UInt horiNumPartsInSubPU = widthSubPU >> 2; |
---|
| 1390 | UInt vertNumPartsInSubPU = (heightSubPU >> 2) * numPartsInLine; |
---|
| 1391 | |
---|
| 1392 | UInt partAddrRasterLine = g_auiZscanToRaster[ uiPartAddr ]; |
---|
| 1393 | |
---|
| 1394 | for( Int posY=0; posY<iHeight; posY+=heightSubPU, partAddrRasterLine+=vertNumPartsInSubPU ) |
---|
| 1395 | { |
---|
| 1396 | UInt partAddrRasterSubPU = partAddrRasterLine; |
---|
| 1397 | for( Int posX=0; posX<iWidth; posX+=widthSubPU, partAddrRasterSubPU+=horiNumPartsInSubPU ) |
---|
| 1398 | { |
---|
| 1399 | UInt partAddrSubPU = g_auiRasterToZscan[ partAddrRasterSubPU ]; |
---|
| 1400 | Int refIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( partAddrSubPU ); assert (refIdx >= 0); |
---|
| 1401 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( partAddrSubPU ); |
---|
| 1402 | pcCU->clipMv(cMv); |
---|
| 1403 | |
---|
[1313] | 1404 | xPredInterBlk( COMPONENT_Y, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA) ); |
---|
| 1405 | xPredInterBlk( COMPONENT_Cb, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) ); |
---|
| 1406 | xPredInterBlk( COMPONENT_Cr, pcCU, pcCU->getSlice()->getRefPic( eRefPicList, refIdx )->getPicYuvRec(), partAddrSubPU, &cMv, widthSubPU, heightSubPU, rpcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA) ); |
---|
[833] | 1407 | } |
---|
| 1408 | } |
---|
| 1409 | } |
---|
[296] | 1410 | #endif |
---|
[189] | 1411 | |
---|
[1313] | 1412 | #if NH_3D_ARP |
---|
| 1413 | //temporal ARP |
---|
| 1414 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
[608] | 1415 | { |
---|
[1313] | 1416 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 1417 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
[608] | 1418 | Bool bTobeScaled = false; |
---|
| 1419 | TComPic* pcPicYuvBaseCol = NULL; |
---|
| 1420 | TComPic* pcPicYuvBaseRef = NULL; |
---|
[2] | 1421 | |
---|
[1313] | 1422 | #if NH_3D_NBDV |
---|
[443] | 1423 | DisInfo cDistparity; |
---|
[1179] | 1424 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
| 1425 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
| 1426 | #else |
---|
[608] | 1427 | assert(0); // ARP can be applied only when a DV is available |
---|
[443] | 1428 | #endif |
---|
[1179] | 1429 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
[608] | 1430 | |
---|
[724] | 1431 | Int arpRefIdx = pcCU->getSlice()->getFirstTRefIdx(eRefPicList); |
---|
[1313] | 1432 | if (arpRefIdx < 0 || !pcCU->getSlice()->getArpRefPicAvailable( eRefPicList, cDistparity.m_aVIdxCan)) |
---|
[608] | 1433 | { |
---|
[443] | 1434 | dW = 0; |
---|
| 1435 | bTobeScaled = false; |
---|
| 1436 | } |
---|
| 1437 | else |
---|
[608] | 1438 | { |
---|
[1313] | 1439 | if( arpRefIdx != iRefIdx ) |
---|
| 1440 | { |
---|
| 1441 | bTobeScaled = true; |
---|
[608] | 1442 | } |
---|
[1313] | 1443 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
| 1444 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, arpRefIdx )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
| 1445 | } |
---|
[608] | 1446 | |
---|
[443] | 1447 | if(bTobeScaled) |
---|
| 1448 | { |
---|
[608] | 1449 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
[443] | 1450 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
[1313] | 1451 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, arpRefIdx ); |
---|
[443] | 1452 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
| 1453 | if ( iScale != 4096 ) |
---|
[608] | 1454 | { |
---|
[443] | 1455 | cMv = cMv.scaleMv( iScale ); |
---|
[608] | 1456 | } |
---|
[1313] | 1457 | iRefIdx = arpRefIdx; |
---|
[443] | 1458 | } |
---|
[608] | 1459 | |
---|
[443] | 1460 | pcCU->clipMv(cMv); |
---|
| 1461 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
[1084] | 1462 | |
---|
[1313] | 1463 | for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++) |
---|
| 1464 | { |
---|
| 1465 | const ComponentID compID=ComponentID(comp); |
---|
| 1466 | xPredInterBlk ( compID, pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); |
---|
| 1467 | } |
---|
| 1468 | |
---|
[443] | 1469 | if( dW > 0 ) |
---|
| 1470 | { |
---|
[608] | 1471 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
[443] | 1472 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
[608] | 1473 | |
---|
| 1474 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
| 1475 | pcCU->clipMv(cMVwithDisparity); |
---|
[1039] | 1476 | if (iWidth <= 8) |
---|
| 1477 | { |
---|
| 1478 | pYuvB0->clear(); pYuvB1->clear(); |
---|
| 1479 | } |
---|
[950] | 1480 | TComMv cNBDV = cDistparity.m_acNBDV; |
---|
| 1481 | pcCU->clipMv( cNBDV ); |
---|
| 1482 | |
---|
[1313] | 1483 | TComPicYuv* pcPicYuvBaseColRec = pcPicYuvBaseCol->getPicYuvRec(); |
---|
| 1484 | TComPicYuv* pcPicYuvBaseRefRec = pcPicYuvBaseRef->getPicYuvRec(); |
---|
[608] | 1485 | |
---|
[1313] | 1486 | UInt uiCompNum = ( iWidth > 8 ) ? 3: 1; |
---|
| 1487 | for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++) |
---|
| 1488 | { |
---|
| 1489 | const ComponentID compID=ComponentID(comp); |
---|
| 1490 | xPredInterBlk ( compID, pcCU, pcPicYuvBaseColRec, uiPartAddr, &cNBDV, iWidth, iHeight, pYuvB0, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); |
---|
| 1491 | xPredInterBlk ( compID, pcCU, pcPicYuvBaseRefRec, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); |
---|
| 1492 | } |
---|
[1084] | 1493 | |
---|
[608] | 1494 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
| 1495 | |
---|
| 1496 | if( 2 == dW ) |
---|
| 1497 | { |
---|
| 1498 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
| 1499 | } |
---|
[1313] | 1500 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() ); |
---|
[443] | 1501 | } |
---|
| 1502 | } |
---|
[1039] | 1503 | |
---|
| 1504 | Bool TComPrediction::xCheckBiInterviewARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eBaseRefPicList, TComPic*& pcPicYuvCurrTRef, TComMv& cBaseTMV, Int& iCurrTRefPoc ) |
---|
| 1505 | { |
---|
| 1506 | Int iRefIdx = pcCU->getCUMvField( eBaseRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 1507 | TComMv cDMv = pcCU->getCUMvField( eBaseRefPicList )->getMv( uiPartAddr ); |
---|
| 1508 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eBaseRefPicList, iRefIdx ); |
---|
| 1509 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
| 1510 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
| 1511 | |
---|
| 1512 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
| 1513 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
| 1514 | |
---|
[1313] | 1515 | Int uiLCUAddr,uiAbsPartAddr; |
---|
| 1516 | pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
| 1517 | TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr ); |
---|
| 1518 | |
---|
[1039] | 1519 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
| 1520 | pcPicYuvCurrTRef = NULL; |
---|
| 1521 | |
---|
| 1522 | //If there is available motion in base reference list, use it |
---|
| 1523 | if(!pColCU->isIntra(uiAbsPartAddr)) |
---|
| 1524 | { |
---|
| 1525 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1); iList ++) |
---|
| 1526 | { |
---|
| 1527 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
| 1528 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
| 1529 | if( iRef != -1) |
---|
| 1530 | { |
---|
| 1531 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
| 1532 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
| 1533 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
| 1534 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
[1084] | 1535 | |
---|
[1039] | 1536 | if( iCurrRef >= 0 && iCurrPOC != iCurrRefPOC) |
---|
| 1537 | { |
---|
| 1538 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
| 1539 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
| 1540 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
| 1541 | if(pcPicYuvBaseTRef) |
---|
| 1542 | { |
---|
| 1543 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
| 1544 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
| 1545 | if ( iScale != 4096 ) |
---|
| 1546 | { |
---|
| 1547 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
| 1548 | } |
---|
| 1549 | iCurrTRefPoc = iTargetPOC; |
---|
| 1550 | return true; |
---|
| 1551 | } |
---|
| 1552 | } |
---|
| 1553 | } |
---|
| 1554 | } |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | //If there is no available motion in base reference list, use ( 0, 0 ) |
---|
| 1558 | if( pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) >= 0 ) |
---|
| 1559 | { |
---|
| 1560 | cBaseTMV.set( 0, 0 ); |
---|
| 1561 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eBaseRefPicList, pcCU->getSlice()->getFirstTRefIdx( eBaseRefPicList ) ); |
---|
| 1562 | iCurrTRefPoc = pcPicYuvCurrTRef->getPOC(); |
---|
| 1563 | return true; |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | return false; |
---|
| 1567 | } |
---|
| 1568 | |
---|
[1313] | 1569 | //inter-view ARP |
---|
| 1570 | Void TComPrediction::xPredInterUniARPviewRef( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
[724] | 1571 | { |
---|
| 1572 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 1573 | TComMv cDMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
| 1574 | TComMv cTempDMv = cDMv; |
---|
| 1575 | UChar dW = pcCU->getARPW ( uiPartAddr ); |
---|
| 1576 | |
---|
| 1577 | TComPic* pcPicYuvBaseTRef = NULL; |
---|
| 1578 | TComPic* pcPicYuvCurrTRef = NULL; |
---|
| 1579 | TComPic* pcPicYuvBaseCol = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
| 1580 | TComPicYuv* pcYuvBaseCol = pcPicYuvBaseCol->getPicYuvRec(); |
---|
| 1581 | Bool bTMVAvai = false; |
---|
| 1582 | TComMv cBaseTMV; |
---|
[1313] | 1583 | |
---|
[724] | 1584 | pcCU->clipMv(cTempDMv); |
---|
| 1585 | |
---|
| 1586 | Int irefPUX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[uiPartAddr]] + iWidth/2 + ((cDMv.getHor() + 2)>>2); |
---|
| 1587 | Int irefPUY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[uiPartAddr]] + iHeight/2 + ((cDMv.getVer() + 2)>>2); |
---|
[443] | 1588 | |
---|
[724] | 1589 | irefPUX = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()-> getPicWidthInLumaSamples()-1, irefPUX); |
---|
| 1590 | irefPUY = (Int)Clip3<Int>(0, pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples()-1, irefPUY); |
---|
[1313] | 1591 | |
---|
| 1592 | Int uiLCUAddr,uiAbsPartAddr; |
---|
| 1593 | pcPicYuvBaseCol->getCUAddrAndPartIdx( irefPUX, irefPUY, uiLCUAddr, uiAbsPartAddr); |
---|
| 1594 | TComDataCU *pColCU = pcPicYuvBaseCol->getCtu( uiLCUAddr ); |
---|
[1039] | 1595 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getIsDepth() ) |
---|
| 1596 | { |
---|
| 1597 | RefPicList eOtherRefList = ( eRefPicList == REF_PIC_LIST_0 ) ? REF_PIC_LIST_1 : REF_PIC_LIST_0; |
---|
| 1598 | Int iOtherRefIdx = pcCU->getCUMvField( eOtherRefList )->getRefIdx( uiPartAddr ); |
---|
| 1599 | //The other prediction direction is temporal ARP |
---|
| 1600 | if( iOtherRefIdx >= 0 && pcCU->getSlice()->getViewIndex() == pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ) |
---|
| 1601 | { |
---|
| 1602 | bTMVAvai = true; |
---|
| 1603 | pcPicYuvBaseTRef = pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx ); |
---|
| 1604 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
| 1605 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
| 1606 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx( eOtherRefList ); |
---|
| 1607 | |
---|
| 1608 | if( iCurrRef >= 0 ) |
---|
| 1609 | { |
---|
| 1610 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic( eOtherRefList,iCurrRef ); |
---|
| 1611 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
| 1612 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
| 1613 | if( pcPicYuvBaseTRef ) |
---|
| 1614 | { |
---|
| 1615 | cBaseTMV = pcCU->getCUMvField( eOtherRefList )->getMv( uiPartAddr ); |
---|
| 1616 | Int iScale = pcCU-> xGetDistScaleFactor( iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC ); |
---|
| 1617 | if ( iScale != 4096 ) |
---|
| 1618 | { |
---|
| 1619 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
| 1620 | } |
---|
| 1621 | } |
---|
| 1622 | else |
---|
| 1623 | { |
---|
| 1624 | dW = 0; |
---|
| 1625 | } |
---|
| 1626 | } |
---|
| 1627 | else |
---|
| 1628 | { |
---|
| 1629 | dW = 0; |
---|
| 1630 | } |
---|
| 1631 | } |
---|
[724] | 1632 | |
---|
[1039] | 1633 | //Both prediction directions are inter-view ARP |
---|
| 1634 | if ( iOtherRefIdx >= 0 && !bTMVAvai ) |
---|
| 1635 | { |
---|
| 1636 | RefPicList eBaseList = REF_PIC_LIST_0; |
---|
| 1637 | Int iCurrTRefPoc; |
---|
| 1638 | bTMVAvai = ( eBaseList != eRefPicList ) && ( pcCU->getSlice()->getViewIndex() != pcCU->getSlice()->getRefPic( eOtherRefList, iOtherRefIdx )->getViewIndex() ); |
---|
| 1639 | |
---|
| 1640 | if ( bTMVAvai ) |
---|
| 1641 | { |
---|
| 1642 | if( xCheckBiInterviewARP( pcCU, uiPartAddr, iWidth, iHeight, eBaseList, pcPicYuvCurrTRef, cBaseTMV, iCurrTRefPoc ) ) |
---|
| 1643 | { |
---|
| 1644 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic( iCurrTRefPoc, pcPicYuvBaseCol->getViewIndex() ); |
---|
| 1645 | if ( pcPicYuvBaseTRef == NULL ) |
---|
| 1646 | { |
---|
| 1647 | dW = 0; |
---|
| 1648 | } |
---|
| 1649 | } |
---|
| 1650 | else |
---|
| 1651 | { |
---|
| 1652 | dW = 0; |
---|
| 1653 | } |
---|
| 1654 | } |
---|
| 1655 | } |
---|
| 1656 | } |
---|
| 1657 | |
---|
| 1658 | if( !pColCU->isIntra( uiAbsPartAddr ) && !bTMVAvai ) |
---|
[724] | 1659 | { |
---|
| 1660 | TComMvField puMVField; |
---|
| 1661 | for(Int iList = 0; iList < (pColCU->getSlice()->isInterB() ? 2: 1) && !bTMVAvai; iList ++) |
---|
| 1662 | { |
---|
| 1663 | RefPicList eRefPicListCurr = RefPicList(iList); |
---|
| 1664 | Int iRef = pColCU->getCUMvField(eRefPicListCurr)->getRefIdx(uiAbsPartAddr); |
---|
[1313] | 1665 | if( iRef != -1 && pcCU->getSlice()->getArpRefPicAvailable( eRefPicListCurr, pcPicYuvBaseCol->getViewIndex())) |
---|
[724] | 1666 | { |
---|
| 1667 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicListCurr, iRef); |
---|
| 1668 | Int iCurrPOC = pColCU->getSlice()->getPOC(); |
---|
| 1669 | Int iCurrRefPOC = pcPicYuvBaseTRef->getPOC(); |
---|
| 1670 | Int iCurrRef = pcCU->getSlice()->getFirstTRefIdx(eRefPicListCurr); |
---|
[1039] | 1671 | if (iCurrRef >= 0 && iCurrRefPOC != iCurrPOC) |
---|
[724] | 1672 | { |
---|
| 1673 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic(eRefPicListCurr,iCurrRef); |
---|
| 1674 | Int iTargetPOC = pcPicYuvCurrTRef->getPOC(); |
---|
| 1675 | { |
---|
| 1676 | pcPicYuvBaseTRef = pcCU->getSlice()->getBaseViewRefPic(iTargetPOC, pcPicYuvBaseCol->getViewIndex() ); |
---|
| 1677 | if(pcPicYuvBaseTRef) |
---|
| 1678 | { |
---|
| 1679 | cBaseTMV = pColCU->getCUMvField(eRefPicListCurr)->getMv(uiAbsPartAddr); |
---|
| 1680 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iTargetPOC, iCurrPOC, iCurrRefPOC); |
---|
| 1681 | if ( iScale != 4096 ) |
---|
| 1682 | cBaseTMV = cBaseTMV.scaleMv( iScale ); |
---|
| 1683 | bTMVAvai = true; |
---|
| 1684 | break; |
---|
| 1685 | } |
---|
| 1686 | } |
---|
| 1687 | } |
---|
| 1688 | } |
---|
| 1689 | } |
---|
| 1690 | } |
---|
| 1691 | if (bTMVAvai == false) |
---|
| 1692 | { |
---|
| 1693 | bTMVAvai = true; |
---|
| 1694 | cBaseTMV.set(0, 0); |
---|
| 1695 | pcPicYuvBaseTRef = pColCU->getSlice()->getRefPic(eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
| 1696 | pcPicYuvCurrTRef = pcCU->getSlice()->getRefPic (eRefPicList, pcCU->getSlice()->getFirstTRefIdx(eRefPicList)); |
---|
| 1697 | } |
---|
[1084] | 1698 | |
---|
[1313] | 1699 | for (UInt comp=COMPONENT_Y; comp< rpcYuvPred->getNumberValidComponents(); comp++) |
---|
| 1700 | { |
---|
| 1701 | const ComponentID compID=ComponentID(comp); |
---|
| 1702 | xPredInterBlk ( compID, pcCU, pcYuvBaseCol, uiPartAddr, &cTempDMv, iWidth, iHeight, rpcYuvPred, bi || ( dW > 0 && bTMVAvai ), pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), bTMVAvai ); |
---|
| 1703 | } |
---|
[1084] | 1704 | |
---|
[1313] | 1705 | if( dW > 0 ) |
---|
[724] | 1706 | { |
---|
[1313] | 1707 | assert ( bTMVAvai ); |
---|
[724] | 1708 | TComYuv* pYuvCurrTRef = &m_acYuvPredBase[0]; |
---|
| 1709 | TComYuv* pYuvBaseTRef = &m_acYuvPredBase[1]; |
---|
| 1710 | TComPicYuv* pcYuvCurrTref = pcPicYuvCurrTRef->getPicYuvRec(); |
---|
| 1711 | TComPicYuv* pcYuvBaseTref = pcPicYuvBaseTRef->getPicYuvRec(); |
---|
| 1712 | TComMv cTempMv = cDMv + cBaseTMV; |
---|
| 1713 | |
---|
| 1714 | pcCU->clipMv(cBaseTMV); |
---|
| 1715 | pcCU->clipMv(cTempMv); |
---|
[1084] | 1716 | |
---|
[1039] | 1717 | if (iWidth <= 8) |
---|
| 1718 | { |
---|
| 1719 | pYuvCurrTRef->clear(); pYuvBaseTRef->clear(); |
---|
| 1720 | } |
---|
[1084] | 1721 | |
---|
[1313] | 1722 | UInt uiCompNum = ( iWidth > 8 ) ? 3: 1; |
---|
| 1723 | for (UInt comp=COMPONENT_Y; comp< uiCompNum; comp++) |
---|
| 1724 | { |
---|
| 1725 | const ComponentID compID=ComponentID(comp); |
---|
| 1726 | xPredInterBlk ( compID, pcCU, pcYuvCurrTref, uiPartAddr, &cBaseTMV, iWidth, iHeight, pYuvCurrTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); |
---|
| 1727 | xPredInterBlk ( compID, pcCU, pcYuvBaseTref, uiPartAddr, &cTempMv, iWidth, iHeight, pYuvBaseTRef, true, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)), true ); |
---|
| 1728 | } |
---|
[1084] | 1729 | |
---|
[724] | 1730 | pYuvCurrTRef->subtractARP( pYuvCurrTRef , pYuvBaseTRef , uiPartAddr , iWidth , iHeight ); |
---|
| 1731 | if(dW == 2) |
---|
| 1732 | { |
---|
| 1733 | pYuvCurrTRef->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
| 1734 | } |
---|
[1313] | 1735 | rpcYuvPred->addARP( rpcYuvPred , pYuvCurrTRef , uiPartAddr , iWidth , iHeight , !bi, pcCU->getSlice()->getSPS()->getBitDepths() ); |
---|
[724] | 1736 | } |
---|
| 1737 | } |
---|
| 1738 | #endif |
---|
| 1739 | |
---|
[1313] | 1740 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv* pcYuvPred ) |
---|
[2] | 1741 | { |
---|
[56] | 1742 | TComYuv* pcMbYuv; |
---|
[1313] | 1743 | Int iRefIdx[NUM_REF_PIC_LIST_01] = {-1, -1}; |
---|
[56] | 1744 | |
---|
[1313] | 1745 | for ( UInt refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ ) |
---|
[56] | 1746 | { |
---|
[1313] | 1747 | RefPicList eRefPicList = (refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
| 1748 | iRefIdx[refList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
[56] | 1749 | |
---|
[1313] | 1750 | if ( iRefIdx[refList] < 0 ) |
---|
[56] | 1751 | { |
---|
| 1752 | continue; |
---|
| 1753 | } |
---|
| 1754 | |
---|
[1313] | 1755 | assert( iRefIdx[refList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
[56] | 1756 | |
---|
[1313] | 1757 | pcMbYuv = &m_acYuvPred[refList]; |
---|
[56] | 1758 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
| 1759 | { |
---|
[608] | 1760 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
[56] | 1761 | } |
---|
| 1762 | else |
---|
| 1763 | { |
---|
[1313] | 1764 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
| 1765 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
[56] | 1766 | { |
---|
[608] | 1767 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
[56] | 1768 | } |
---|
| 1769 | else |
---|
| 1770 | { |
---|
[608] | 1771 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
[56] | 1772 | } |
---|
| 1773 | } |
---|
| 1774 | } |
---|
[608] | 1775 | |
---|
[1313] | 1776 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
[56] | 1777 | { |
---|
[1313] | 1778 | 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 ); |
---|
| 1779 | } |
---|
[313] | 1780 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
| 1781 | { |
---|
[1313] | 1782 | xWeightedPredictionUni( pcCU, &m_acYuvPred[REF_PIC_LIST_0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[313] | 1783 | } |
---|
[56] | 1784 | else |
---|
| 1785 | { |
---|
[1313] | 1786 | 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() ); |
---|
[56] | 1787 | } |
---|
[2] | 1788 | } |
---|
| 1789 | |
---|
[1313] | 1790 | #if NH_3D_VSP |
---|
[608] | 1791 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
| 1792 | { |
---|
| 1793 | TComYuv* pcMbYuv; |
---|
| 1794 | Int iRefIdx[2] = {-1, -1}; |
---|
| 1795 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
[296] | 1796 | |
---|
[608] | 1797 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
[2] | 1798 | { |
---|
[608] | 1799 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
| 1800 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
[56] | 1801 | |
---|
[608] | 1802 | if ( iRefIdx[iRefList] < 0 ) |
---|
[622] | 1803 | { |
---|
[608] | 1804 | continue; |
---|
[622] | 1805 | } |
---|
[608] | 1806 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
[56] | 1807 | |
---|
[608] | 1808 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
| 1809 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
[2] | 1810 | } |
---|
[296] | 1811 | |
---|
[1313] | 1812 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred, pcCU->getSlice()->getSPS()->getBitDepths() ); |
---|
[608] | 1813 | } |
---|
[296] | 1814 | #endif |
---|
[56] | 1815 | |
---|
| 1816 | /** |
---|
[1313] | 1817 | * \brief Generate motion-compensated block |
---|
[56] | 1818 | * |
---|
[1313] | 1819 | * \param compID Colour component ID |
---|
| 1820 | * \param cu Pointer to current CU |
---|
| 1821 | * \param refPic Pointer to reference picture |
---|
| 1822 | * \param partAddr Address of block within CU |
---|
| 1823 | * \param mv Motion vector |
---|
| 1824 | * \param width Width of block |
---|
| 1825 | * \param height Height of block |
---|
| 1826 | * \param dstPic Pointer to destination picture |
---|
| 1827 | * \param bi Flag indicating whether bipred is used |
---|
| 1828 | * \param bitDepth Bit depth |
---|
[56] | 1829 | */ |
---|
[1313] | 1830 | |
---|
| 1831 | |
---|
| 1832 | 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 |
---|
| 1833 | #if NH_3D_ARP |
---|
[608] | 1834 | , Bool filterType |
---|
[189] | 1835 | #endif |
---|
[1313] | 1836 | #if NH_3D_IC |
---|
[608] | 1837 | , Bool bICFlag |
---|
| 1838 | #endif |
---|
[1313] | 1839 | ) |
---|
[56] | 1840 | { |
---|
[1321] | 1841 | #if NH_MV |
---|
| 1842 | assert( refPic->getBorderExtension() ); |
---|
| 1843 | #endif |
---|
[1313] | 1844 | Int refStride = refPic->getStride(compID); |
---|
| 1845 | Int dstStride = dstPic->getStride(compID); |
---|
| 1846 | Int shiftHor=(2+refPic->getComponentScaleX(compID)); |
---|
| 1847 | Int shiftVer=(2+refPic->getComponentScaleY(compID)); |
---|
[56] | 1848 | |
---|
[1313] | 1849 | Int refOffset = (mv->getHor() >> shiftHor) + (mv->getVer() >> shiftVer) * refStride; |
---|
| 1850 | |
---|
| 1851 | Pel* ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset; |
---|
| 1852 | |
---|
| 1853 | Pel* dst = dstPic->getAddr( compID, partAddr ); |
---|
| 1854 | |
---|
| 1855 | Int xFrac = mv->getHor() & ((1<<shiftHor)-1); |
---|
| 1856 | Int yFrac = mv->getVer() & ((1<<shiftVer)-1); |
---|
| 1857 | |
---|
| 1858 | #if NH_3D_INTEGER_MV_DEPTH |
---|
[608] | 1859 | if( cu->getSlice()->getIsDepth() ) |
---|
| 1860 | { |
---|
| 1861 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
[1313] | 1862 | ref = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset; |
---|
[608] | 1863 | xFrac = 0; |
---|
| 1864 | yFrac = 0; |
---|
| 1865 | } |
---|
[56] | 1866 | #endif |
---|
[1313] | 1867 | |
---|
| 1868 | UInt cxWidth = width >> refPic->getComponentScaleX(compID); |
---|
| 1869 | UInt cxHeight = height >> refPic->getComponentScaleY(compID); |
---|
| 1870 | |
---|
| 1871 | const ChromaFormat chFmt = cu->getPic()->getChromaFormat(); |
---|
| 1872 | |
---|
[56] | 1873 | if ( yFrac == 0 ) |
---|
[2] | 1874 | { |
---|
[1313] | 1875 | #if NH_3D_IC |
---|
| 1876 | m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag, chFmt, bitDepth |
---|
[608] | 1877 | #else |
---|
[1313] | 1878 | m_if.filterHor(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth |
---|
[443] | 1879 | #endif |
---|
[1313] | 1880 | #if NH_3D_ARP |
---|
[608] | 1881 | , filterType |
---|
[1313] | 1882 | #endif |
---|
| 1883 | ); |
---|
[2] | 1884 | } |
---|
[56] | 1885 | else if ( xFrac == 0 ) |
---|
| 1886 | { |
---|
[1313] | 1887 | #if NH_3D_IC |
---|
| 1888 | m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag, chFmt, bitDepth |
---|
[608] | 1889 | #else |
---|
[1313] | 1890 | m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth |
---|
[443] | 1891 | #endif |
---|
[1313] | 1892 | #if NH_3D_ARP |
---|
[608] | 1893 | , filterType |
---|
| 1894 | #endif |
---|
[1313] | 1895 | ); |
---|
[56] | 1896 | } |
---|
| 1897 | else |
---|
| 1898 | { |
---|
[1313] | 1899 | Int tmpStride = m_filteredBlockTmp[0].getStride(compID); |
---|
| 1900 | Pel* tmp = m_filteredBlockTmp[0].getAddr(compID); |
---|
[56] | 1901 | |
---|
[1313] | 1902 | const Int vFilterSize = isLuma(compID) ? NTAPS_LUMA : NTAPS_CHROMA; |
---|
[56] | 1903 | |
---|
[1313] | 1904 | m_if.filterHor(compID, ref - ((vFilterSize>>1) -1)*refStride, refStride, tmp, tmpStride, cxWidth, cxHeight+vFilterSize-1, xFrac, false, chFmt, bitDepth |
---|
| 1905 | #if NH_3D_ARP |
---|
[608] | 1906 | , filterType |
---|
[443] | 1907 | #endif |
---|
[1313] | 1908 | ); |
---|
| 1909 | #if NH_3D_IC |
---|
| 1910 | m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi || bICFlag, chFmt, bitDepth |
---|
[608] | 1911 | #else |
---|
[1313] | 1912 | m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight, yFrac, false, !bi, chFmt, bitDepth |
---|
[608] | 1913 | #endif |
---|
[1313] | 1914 | #if NH_3D_ARP |
---|
[608] | 1915 | , filterType |
---|
[443] | 1916 | #endif |
---|
[1313] | 1917 | ); |
---|
[56] | 1918 | } |
---|
[189] | 1919 | |
---|
[1313] | 1920 | #if NH_3D_IC |
---|
[608] | 1921 | if( bICFlag ) |
---|
[189] | 1922 | { |
---|
[608] | 1923 | Int a, b, i, j; |
---|
| 1924 | const Int iShift = IC_CONST_SHIFT; |
---|
[1313] | 1925 | Pel *dst2 = dst; |
---|
[608] | 1926 | |
---|
[1313] | 1927 | xGetLLSICPrediction( compID, cu, mv, refPic, a, b, bitDepth ); |
---|
[189] | 1928 | |
---|
[608] | 1929 | for ( i = 0; i < cxHeight; i++ ) |
---|
[189] | 1930 | { |
---|
[608] | 1931 | for ( j = 0; j < cxWidth; j++ ) |
---|
[189] | 1932 | { |
---|
[1313] | 1933 | dst[j] = Clip3( 0, ( 1 << bitDepth ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
[189] | 1934 | } |
---|
[1313] | 1935 | dst += dstStride; |
---|
[189] | 1936 | } |
---|
[655] | 1937 | |
---|
[608] | 1938 | if(bi) |
---|
[296] | 1939 | { |
---|
[1313] | 1940 | Int shift = IF_INTERNAL_PREC - bitDepth; |
---|
[608] | 1941 | for (i = 0; i < cxHeight; i++) |
---|
[296] | 1942 | { |
---|
[608] | 1943 | for (j = 0; j < cxWidth; j++) |
---|
[296] | 1944 | { |
---|
[1313] | 1945 | Pel val = dst2[j] << shift; |
---|
| 1946 | dst2[j] = val - (Pel)IF_INTERNAL_OFFS; |
---|
[296] | 1947 | } |
---|
[1313] | 1948 | dst2 += dstStride; |
---|
[443] | 1949 | } |
---|
| 1950 | } |
---|
[296] | 1951 | } |
---|
[443] | 1952 | #endif |
---|
[1313] | 1953 | |
---|
[296] | 1954 | } |
---|
| 1955 | |
---|
[1313] | 1956 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths |
---|
| 1957 | ) |
---|
[2] | 1958 | { |
---|
[56] | 1959 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
[2] | 1960 | { |
---|
[1313] | 1961 | pcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight, clipBitDepths ); |
---|
[2] | 1962 | } |
---|
[56] | 1963 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
[2] | 1964 | { |
---|
[1313] | 1965 | pcYuvSrc0->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
[2] | 1966 | } |
---|
[56] | 1967 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
[2] | 1968 | { |
---|
[1313] | 1969 | pcYuvSrc1->copyPartToPartYuv( pcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
[56] | 1970 | } |
---|
| 1971 | } |
---|
| 1972 | |
---|
| 1973 | // AMVP |
---|
[608] | 1974 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
[56] | 1975 | { |
---|
| 1976 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
[1313] | 1977 | |
---|
[608] | 1978 | if( pcAMVPInfo->iN <= 1 ) |
---|
[56] | 1979 | { |
---|
| 1980 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
| 1981 | |
---|
| 1982 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 1983 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 1984 | return; |
---|
| 1985 | } |
---|
| 1986 | |
---|
| 1987 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
| 1988 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
| 1989 | return; |
---|
| 1990 | } |
---|
| 1991 | |
---|
| 1992 | /** Function for deriving planar intra prediction. |
---|
[1313] | 1993 | * \param pSrc pointer to reconstructed sample array |
---|
| 1994 | * \param srcStride the stride of the reconstructed sample array |
---|
| 1995 | * \param rpDst reference to pointer for the prediction sample array |
---|
| 1996 | * \param dstStride the stride of the prediction sample array |
---|
| 1997 | * \param width the width of the block |
---|
| 1998 | * \param height the height of the block |
---|
| 1999 | * \param channelType type of pel array (luma, chroma) |
---|
| 2000 | * \param format chroma format |
---|
[56] | 2001 | * |
---|
| 2002 | * This function derives the prediction samples for planar mode (intra coding). |
---|
| 2003 | */ |
---|
[1313] | 2004 | //NOTE: Bit-Limit - 24-bit source |
---|
| 2005 | Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
[56] | 2006 | { |
---|
[1313] | 2007 | assert(width <= height); |
---|
[56] | 2008 | |
---|
[655] | 2009 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
[1313] | 2010 | UInt shift1Dhor = g_aucConvertToBit[ width ] + 2; |
---|
| 2011 | UInt shift1Dver = g_aucConvertToBit[ height ] + 2; |
---|
[56] | 2012 | |
---|
| 2013 | // Get left and above reference column and row |
---|
[1313] | 2014 | for(Int k=0;k<width+1;k++) |
---|
[56] | 2015 | { |
---|
| 2016 | topRow[k] = pSrc[k-srcStride]; |
---|
[1313] | 2017 | } |
---|
| 2018 | |
---|
| 2019 | for (Int k=0; k < height+1; k++) |
---|
| 2020 | { |
---|
[56] | 2021 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
| 2022 | } |
---|
| 2023 | |
---|
| 2024 | // Prepare intermediate variables used in interpolation |
---|
[1313] | 2025 | Int bottomLeft = leftColumn[height]; |
---|
| 2026 | Int topRight = topRow[width]; |
---|
| 2027 | |
---|
| 2028 | for(Int k=0;k<width;k++) |
---|
[56] | 2029 | { |
---|
[1313] | 2030 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
| 2031 | topRow[k] <<= shift1Dver; |
---|
[56] | 2032 | } |
---|
| 2033 | |
---|
[1313] | 2034 | for(Int k=0;k<height;k++) |
---|
| 2035 | { |
---|
| 2036 | rightColumn[k] = topRight - leftColumn[k]; |
---|
| 2037 | leftColumn[k] <<= shift1Dhor; |
---|
| 2038 | } |
---|
| 2039 | |
---|
| 2040 | const UInt topRowShift = 0; |
---|
| 2041 | |
---|
[56] | 2042 | // Generate prediction signal |
---|
[1313] | 2043 | for (Int y=0;y<height;y++) |
---|
[56] | 2044 | { |
---|
[1313] | 2045 | Int horPred = leftColumn[y] + width; |
---|
| 2046 | for (Int x=0;x<width;x++) |
---|
[2] | 2047 | { |
---|
[1313] | 2048 | horPred += rightColumn[y]; |
---|
| 2049 | topRow[x] += bottomRow[x]; |
---|
| 2050 | |
---|
| 2051 | Int vertPred = ((topRow[x] + topRowShift)>>topRowShift); |
---|
| 2052 | rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1); |
---|
[2] | 2053 | } |
---|
| 2054 | } |
---|
| 2055 | } |
---|
| 2056 | |
---|
[608] | 2057 | /** Function for filtering intra DC predictor. |
---|
| 2058 | * \param pSrc pointer to reconstructed sample array |
---|
| 2059 | * \param iSrcStride the stride of the reconstructed sample array |
---|
[1313] | 2060 | * \param pDst reference to pointer for the prediction sample array |
---|
[608] | 2061 | * \param iDstStride the stride of the prediction sample array |
---|
| 2062 | * \param iWidth the width of the block |
---|
| 2063 | * \param iHeight the height of the block |
---|
[1313] | 2064 | * \param channelType type of pel array (luma, chroma) |
---|
[56] | 2065 | * |
---|
[608] | 2066 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
[56] | 2067 | */ |
---|
[1313] | 2068 | Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType ) |
---|
[56] | 2069 | { |
---|
[608] | 2070 | Int x, y, iDstStride2, iSrcStride2; |
---|
[2] | 2071 | |
---|
[1313] | 2072 | if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT)) |
---|
[2] | 2073 | { |
---|
[1313] | 2074 | //top-left |
---|
| 2075 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
[2] | 2076 | |
---|
[1313] | 2077 | //top row (vertical filter) |
---|
| 2078 | for ( x = 1; x < iWidth; x++ ) |
---|
| 2079 | { |
---|
| 2080 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
| 2081 | } |
---|
| 2082 | |
---|
| 2083 | //left column (horizontal filter) |
---|
| 2084 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
| 2085 | { |
---|
| 2086 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
| 2087 | } |
---|
[56] | 2088 | } |
---|
[2] | 2089 | |
---|
[608] | 2090 | return; |
---|
[2] | 2091 | } |
---|
[1313] | 2092 | |
---|
| 2093 | /* Static member function */ |
---|
| 2094 | Bool TComPrediction::UseDPCMForFirstPassIntraEstimation(TComTU &rTu, const UInt uiDirMode) |
---|
| 2095 | { |
---|
| 2096 | return (rTu.getCU()->isRDPCMEnabled(rTu.GetAbsPartIdxTU()) ) && |
---|
| 2097 | rTu.getCU()->getCUTransquantBypass(rTu.GetAbsPartIdxTU()) && |
---|
| 2098 | (uiDirMode==HOR_IDX || uiDirMode==VER_IDX); |
---|
| 2099 | } |
---|
| 2100 | #if NH_3D_IC |
---|
[608] | 2101 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
[56] | 2102 | * \param x input value |
---|
| 2103 | * |
---|
[608] | 2104 | * This function derives the position of first non-zero binary bit of a value |
---|
[56] | 2105 | */ |
---|
| 2106 | Int GetMSB( UInt x ) |
---|
| 2107 | { |
---|
| 2108 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
| 2109 | |
---|
| 2110 | while( x > 1 ) |
---|
| 2111 | { |
---|
| 2112 | bits >>= 1; |
---|
| 2113 | y = x >> bits; |
---|
| 2114 | |
---|
| 2115 | if( y ) |
---|
| 2116 | { |
---|
| 2117 | x = y; |
---|
| 2118 | iMSB += bits; |
---|
| 2119 | } |
---|
| 2120 | } |
---|
| 2121 | |
---|
| 2122 | iMSB+=y; |
---|
| 2123 | |
---|
| 2124 | return iMSB; |
---|
| 2125 | } |
---|
| 2126 | |
---|
| 2127 | |
---|
[608] | 2128 | /** Function for deriving LM illumination compensation. |
---|
[56] | 2129 | */ |
---|
[1313] | 2130 | Void TComPrediction::xGetLLSICPrediction( const ComponentID compID, TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, const Int bitDepth ) |
---|
[56] | 2131 | { |
---|
[608] | 2132 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
| 2133 | Pel *pRec = NULL, *pRef = NULL; |
---|
| 2134 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
[1313] | 2135 | Int iRecStride = pRecPic->getStride(compID); |
---|
| 2136 | Int iRefStride = pRefPic->getStride(compID); |
---|
[1039] | 2137 | Int iRefOffset, iHor, iVer; |
---|
[608] | 2138 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
| 2139 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
[1313] | 2140 | if( !isLuma(compID) ) |
---|
[608] | 2141 | { |
---|
| 2142 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
| 2143 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
| 2144 | } |
---|
[1313] | 2145 | uiWidth = pcCU->getWidth( 0 ) >> pRefPic->getComponentScaleX(compID); |
---|
| 2146 | uiHeight = pcCU->getHeight( 0 ) >> pRefPic->getComponentScaleY(compID); |
---|
[56] | 2147 | |
---|
| 2148 | Int i, j, iCountShift = 0; |
---|
| 2149 | |
---|
[1313] | 2150 | // LLS parameters estimation |
---|
[56] | 2151 | |
---|
| 2152 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
[1313] | 2153 | Int precShift = std::max(0, bitDepth - 12); |
---|
[56] | 2154 | |
---|
[1313] | 2155 | UInt partAddr = 0; |
---|
| 2156 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) ) |
---|
[56] | 2157 | { |
---|
[608] | 2158 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
[1313] | 2159 | pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset; |
---|
| 2160 | pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - iRecStride; |
---|
[608] | 2161 | for( j = 0; j < uiWidth; j+=2 ) |
---|
[189] | 2162 | { |
---|
| 2163 | x += pRef[j]; |
---|
| 2164 | y += pRec[j]; |
---|
[1313] | 2165 | if( isLuma(compID) ) |
---|
[1124] | 2166 | { |
---|
| 2167 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
| 2168 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
| 2169 | } |
---|
[189] | 2170 | } |
---|
[608] | 2171 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
[189] | 2172 | } |
---|
| 2173 | |
---|
[1313] | 2174 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) ) |
---|
[189] | 2175 | { |
---|
[608] | 2176 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
[1313] | 2177 | pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset; |
---|
| 2178 | pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - 1; |
---|
[608] | 2179 | for( i = 0; i < uiHeight; i+=2 ) |
---|
[189] | 2180 | { |
---|
| 2181 | x += pRef[0]; |
---|
| 2182 | y += pRec[0]; |
---|
[1313] | 2183 | if( isLuma(compID) ) |
---|
[1124] | 2184 | { |
---|
| 2185 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
| 2186 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
| 2187 | } |
---|
[608] | 2188 | pRef += iRefStride*2; |
---|
| 2189 | pRec += iRecStride*2; |
---|
[189] | 2190 | } |
---|
[608] | 2191 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
[189] | 2192 | } |
---|
| 2193 | |
---|
[1039] | 2194 | if( iCountShift == 0 ) |
---|
| 2195 | { |
---|
| 2196 | a = ( 1 << IC_CONST_SHIFT ); |
---|
| 2197 | b = 0; |
---|
| 2198 | return; |
---|
| 2199 | } |
---|
| 2200 | |
---|
[1313] | 2201 | if( !isLuma(compID) ) |
---|
[1124] | 2202 | { |
---|
[1313] | 2203 | a = ( 1 << IC_CONST_SHIFT ); |
---|
[1124] | 2204 | b = ( y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
| 2205 | } |
---|
| 2206 | else |
---|
| 2207 | { |
---|
[608] | 2208 | xy += xx >> IC_REG_COST_SHIFT; |
---|
| 2209 | xx += xx >> IC_REG_COST_SHIFT; |
---|
| 2210 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
| 2211 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
| 2212 | const Int iShift = IC_CONST_SHIFT; |
---|
[189] | 2213 | const Int iShiftA2 = 6; |
---|
| 2214 | const Int iAccuracyShift = 15; |
---|
| 2215 | |
---|
| 2216 | Int iScaleShiftA2 = 0; |
---|
| 2217 | Int iScaleShiftA1 = 0; |
---|
[1313] | 2218 | Int a1s; |
---|
| 2219 | Int a2s; |
---|
[189] | 2220 | |
---|
[608] | 2221 | a1 = Clip3(0, 2*a2, a1); |
---|
| 2222 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
| 2223 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
[189] | 2224 | |
---|
| 2225 | if( iScaleShiftA1 < 0 ) |
---|
| 2226 | { |
---|
| 2227 | iScaleShiftA1 = 0; |
---|
| 2228 | } |
---|
| 2229 | |
---|
| 2230 | if( iScaleShiftA2 < 0 ) |
---|
| 2231 | { |
---|
| 2232 | iScaleShiftA2 = 0; |
---|
| 2233 | } |
---|
| 2234 | |
---|
| 2235 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
| 2236 | |
---|
[608] | 2237 | |
---|
[189] | 2238 | a2s = a2 >> iScaleShiftA2; |
---|
| 2239 | |
---|
| 2240 | a1s = a1 >> iScaleShiftA1; |
---|
| 2241 | |
---|
[608] | 2242 | a = a1s * m_uiaShift[ a2s ]; |
---|
| 2243 | a = a >> iScaleShiftA; |
---|
[189] | 2244 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
| 2245 | } |
---|
| 2246 | } |
---|
[1313] | 2247 | #endif |
---|
| 2248 | |
---|
| 2249 | #if NH_3D_SDC_INTRA |
---|
| 2250 | Void TComPrediction::predConstantSDC( Pel* ptrSrc, UInt srcStride, UInt uiSize, Pel& predDC ) |
---|
| 2251 | { |
---|
| 2252 | Pel* pLeftTop = ptrSrc; |
---|
| 2253 | Pel* pRightTop = ptrSrc + (uiSize-1); |
---|
| 2254 | Pel* pLeftBottom = (ptrSrc+ (srcStride*(uiSize-1)) ); |
---|
| 2255 | Pel* pRightBottom = (ptrSrc+ (srcStride*(uiSize-1)) + (uiSize-1)); |
---|
| 2256 | predDC = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; |
---|
| 2257 | } |
---|
| 2258 | #endif // NH_3D_SDC_INTRA |
---|
| 2259 | |
---|
| 2260 | #if NH_3D_DMM |
---|
| 2261 | Void TComPrediction::predContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* segPattern ) |
---|
| 2262 | { |
---|
| 2263 | // get copy of co-located texture luma block |
---|
| 2264 | TComYuv cTempYuv; |
---|
| 2265 | cTempYuv.create( uiWidth, uiHeight, CHROMA_400 ); |
---|
| 2266 | cTempYuv.clear(); |
---|
| 2267 | Pel* piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
| 2268 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
| 2269 | assert( pcPicYuvRef != NULL ); |
---|
| 2270 | Int iRefStride = pcPicYuvRef->getStride( COMPONENT_Y ); |
---|
| 2271 | Pel* piRefY = pcPicYuvRef->getAddr ( COMPONENT_Y, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + uiAbsPartIdx ); |
---|
| 2272 | |
---|
| 2273 | for( Int y = 0; y < uiHeight; y++ ) |
---|
| 2274 | { |
---|
| 2275 | ::memcpy(piRefBlkY, piRefY, sizeof(Pel)*uiWidth); |
---|
| 2276 | piRefBlkY += uiWidth; |
---|
| 2277 | piRefY += iRefStride; |
---|
[1124] | 2278 | } |
---|
[1313] | 2279 | |
---|
| 2280 | |
---|
| 2281 | // find contour for texture luma block |
---|
| 2282 | piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
| 2283 | UInt iDC = 0; |
---|
| 2284 | iDC = piRefBlkY[ 0 ]; |
---|
| 2285 | iDC += piRefBlkY[ uiWidth - 1 ]; |
---|
| 2286 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) ]; |
---|
| 2287 | iDC += piRefBlkY[ uiWidth * (uiHeight - 1) + uiWidth - 1 ]; |
---|
| 2288 | iDC = iDC >> 2; |
---|
| 2289 | |
---|
| 2290 | piRefBlkY = cTempYuv.getAddr( COMPONENT_Y ); |
---|
| 2291 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
| 2292 | { |
---|
| 2293 | segPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
| 2294 | } |
---|
| 2295 | |
---|
| 2296 | cTempYuv.destroy(); |
---|
[189] | 2297 | } |
---|
| 2298 | |
---|
[1313] | 2299 | Void TComPrediction::predBiSegDCs( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
[2] | 2300 | { |
---|
[1313] | 2301 | assert( biSegPattern ); |
---|
| 2302 | const Pel *piMask = getPredictorPtr( COMPONENT_Y, false ); |
---|
| 2303 | assert( piMask ); |
---|
| 2304 | Int srcStride = 2*uiWidth + 1; |
---|
| 2305 | const Pel *ptrSrc = piMask+srcStride+1; |
---|
| 2306 | |
---|
[608] | 2307 | Int refDC1, refDC2; |
---|
| 2308 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
| 2309 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
| 2310 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
| 2311 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
[2] | 2312 | |
---|
[608] | 2313 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
| 2314 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
| 2315 | |
---|
| 2316 | if( bL == bT ) |
---|
[56] | 2317 | { |
---|
[833] | 2318 | const Int iTRR = ( patternStride * 2 - 1 ) - srcStride; |
---|
| 2319 | const Int iLBB = ( patternStride * 2 - 1 ) * srcStride - 1; |
---|
| 2320 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : (abs(ptrSrc[iTRR] - ptrSrc[-(Int)srcStride]) > abs(ptrSrc[iLBB] - ptrSrc[ -1]) ? ptrSrc[iTRR] : ptrSrc[iLBB]); |
---|
[608] | 2321 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
[56] | 2322 | } |
---|
| 2323 | else |
---|
| 2324 | { |
---|
[608] | 2325 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
| 2326 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
[56] | 2327 | } |
---|
| 2328 | |
---|
[608] | 2329 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
| 2330 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
[2] | 2331 | } |
---|
| 2332 | |
---|
[1313] | 2333 | Void TComPrediction::assignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
[56] | 2334 | { |
---|
[1313] | 2335 | assert( biSegPattern ); |
---|
[608] | 2336 | if( dstStride == patternStride ) |
---|
| 2337 | { |
---|
| 2338 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
| 2339 | { |
---|
[1313] | 2340 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
| 2341 | else { ptrDst[k] = valDC1; } |
---|
[608] | 2342 | } |
---|
[443] | 2343 | } |
---|
[608] | 2344 | else |
---|
| 2345 | { |
---|
| 2346 | Pel* piTemp = ptrDst; |
---|
| 2347 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
| 2348 | { |
---|
| 2349 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
| 2350 | { |
---|
[1313] | 2351 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
| 2352 | else { piTemp[uiX] = valDC1; } |
---|
[608] | 2353 | } |
---|
| 2354 | piTemp += dstStride; |
---|
| 2355 | biSegPattern += patternStride; |
---|
| 2356 | } |
---|
[443] | 2357 | } |
---|
[56] | 2358 | } |
---|
[655] | 2359 | #endif |
---|
[56] | 2360 | //! \} |
---|