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