[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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, 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" |
---|
| 40 | |
---|
[56] | 41 | //! \ingroup TLibCommon |
---|
| 42 | //! \{ |
---|
| 43 | |
---|
[2] | 44 | // ==================================================================================================================== |
---|
| 45 | // Constructor / destructor / initialize |
---|
| 46 | // ==================================================================================================================== |
---|
| 47 | |
---|
| 48 | TComPrediction::TComPrediction() |
---|
| 49 | : m_pLumaRecBuffer(0) |
---|
[608] | 50 | , m_iLumaRecStride(0) |
---|
[2] | 51 | { |
---|
| 52 | m_piYuvExt = NULL; |
---|
[608] | 53 | #if H_3D_VSP |
---|
| 54 | m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int)); |
---|
| 55 | if (m_pDepthBlock == NULL) |
---|
[296] | 56 | printf("ERROR: UKTGHU, No memory allocated.\n"); |
---|
| 57 | #endif |
---|
[2] | 58 | } |
---|
| 59 | |
---|
| 60 | TComPrediction::~TComPrediction() |
---|
| 61 | { |
---|
[608] | 62 | #if H_3D_VSP |
---|
| 63 | if (m_pDepthBlock != NULL) |
---|
| 64 | free(m_pDepthBlock); |
---|
| 65 | m_cYuvDepthOnVsp.destroy(); |
---|
[296] | 66 | #endif |
---|
[608] | 67 | |
---|
[2] | 68 | delete[] m_piYuvExt; |
---|
| 69 | |
---|
| 70 | m_acYuvPred[0].destroy(); |
---|
| 71 | m_acYuvPred[1].destroy(); |
---|
| 72 | |
---|
| 73 | m_cYuvPredTemp.destroy(); |
---|
[608] | 74 | |
---|
| 75 | #if H_3D_ARP |
---|
[443] | 76 | m_acYuvPredBase[0].destroy(); |
---|
| 77 | m_acYuvPredBase[1].destroy(); |
---|
| 78 | #endif |
---|
[2] | 79 | if( m_pLumaRecBuffer ) |
---|
[56] | 80 | { |
---|
| 81 | delete [] m_pLumaRecBuffer; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | Int i, j; |
---|
| 85 | for (i = 0; i < 4; i++) |
---|
| 86 | { |
---|
| 87 | for (j = 0; j < 4; j++) |
---|
| 88 | { |
---|
| 89 | m_filteredBlock[i][j].destroy(); |
---|
| 90 | } |
---|
| 91 | m_filteredBlockTmp[i].destroy(); |
---|
| 92 | } |
---|
[2] | 93 | } |
---|
| 94 | |
---|
| 95 | Void TComPrediction::initTempBuff() |
---|
| 96 | { |
---|
| 97 | if( m_piYuvExt == NULL ) |
---|
| 98 | { |
---|
[608] | 99 | Int extWidth = MAX_CU_SIZE + 16; |
---|
| 100 | Int extHeight = MAX_CU_SIZE + 1; |
---|
[56] | 101 | Int i, j; |
---|
| 102 | for (i = 0; i < 4; i++) |
---|
| 103 | { |
---|
| 104 | m_filteredBlockTmp[i].create(extWidth, extHeight + 7); |
---|
| 105 | for (j = 0; j < 4; j++) |
---|
| 106 | { |
---|
| 107 | m_filteredBlock[i][j].create(extWidth, extHeight); |
---|
| 108 | } |
---|
| 109 | } |
---|
[608] | 110 | m_iYuvExtHeight = ((MAX_CU_SIZE + 2) << 4); |
---|
| 111 | m_iYuvExtStride = ((MAX_CU_SIZE + 8) << 4); |
---|
[2] | 112 | m_piYuvExt = new Int[ m_iYuvExtStride * m_iYuvExtHeight ]; |
---|
| 113 | |
---|
| 114 | // new structure |
---|
[608] | 115 | m_acYuvPred[0] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
| 116 | m_acYuvPred[1] .create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
[2] | 117 | |
---|
[608] | 118 | m_cYuvPredTemp.create( MAX_CU_SIZE, MAX_CU_SIZE ); |
---|
| 119 | #if H_3D_ARP |
---|
[443] | 120 | m_acYuvPredBase[0] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 121 | m_acYuvPredBase[1] .create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 122 | #endif |
---|
[655] | 123 | #if H_3D_VSP |
---|
[608] | 124 | m_cYuvDepthOnVsp.create( g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 125 | #endif |
---|
[2] | 126 | } |
---|
| 127 | |
---|
[608] | 128 | if (m_iLumaRecStride != (MAX_CU_SIZE>>1) + 1) |
---|
| 129 | { |
---|
| 130 | m_iLumaRecStride = (MAX_CU_SIZE>>1) + 1; |
---|
| 131 | if (!m_pLumaRecBuffer) |
---|
| 132 | { |
---|
| 133 | m_pLumaRecBuffer = new Pel[ m_iLumaRecStride * m_iLumaRecStride ]; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | #if H_3D_IC |
---|
| 137 | m_uiaShift[0] = 0; |
---|
[56] | 138 | for( Int i = 1; i < 64; i++ ) |
---|
| 139 | { |
---|
[608] | 140 | m_uiaShift[i] = ( (1 << 15) + i/2 ) / i; |
---|
| 141 | } |
---|
| 142 | #endif |
---|
[2] | 143 | } |
---|
| 144 | |
---|
| 145 | // ==================================================================================================================== |
---|
| 146 | // Public member functions |
---|
| 147 | // ==================================================================================================================== |
---|
| 148 | |
---|
| 149 | // Function for calculating DC value of the reference samples used in Intra prediction |
---|
| 150 | Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft ) |
---|
| 151 | { |
---|
[608] | 152 | assert(iWidth > 0 && iHeight > 0); |
---|
[2] | 153 | Int iInd, iSum = 0; |
---|
| 154 | Pel pDcVal; |
---|
| 155 | |
---|
| 156 | if (bAbove) |
---|
| 157 | { |
---|
| 158 | for (iInd = 0;iInd < iWidth;iInd++) |
---|
[56] | 159 | { |
---|
[2] | 160 | iSum += pSrc[iInd-iSrcStride]; |
---|
[56] | 161 | } |
---|
[2] | 162 | } |
---|
| 163 | if (bLeft) |
---|
| 164 | { |
---|
| 165 | for (iInd = 0;iInd < iHeight;iInd++) |
---|
[56] | 166 | { |
---|
[2] | 167 | iSum += pSrc[iInd*iSrcStride-1]; |
---|
[56] | 168 | } |
---|
[2] | 169 | } |
---|
| 170 | |
---|
| 171 | if (bAbove && bLeft) |
---|
[56] | 172 | { |
---|
[2] | 173 | pDcVal = (iSum + iWidth) / (iWidth + iHeight); |
---|
[56] | 174 | } |
---|
[2] | 175 | else if (bAbove) |
---|
[56] | 176 | { |
---|
[2] | 177 | pDcVal = (iSum + iWidth/2) / iWidth; |
---|
[56] | 178 | } |
---|
[2] | 179 | else if (bLeft) |
---|
[56] | 180 | { |
---|
[2] | 181 | pDcVal = (iSum + iHeight/2) / iHeight; |
---|
[56] | 182 | } |
---|
[2] | 183 | else |
---|
[56] | 184 | { |
---|
[2] | 185 | pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available |
---|
[56] | 186 | } |
---|
| 187 | |
---|
[2] | 188 | return pDcVal; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | // Function for deriving the angular Intra predictions |
---|
| 192 | |
---|
| 193 | /** Function for deriving the simplified angular intra predictions. |
---|
| 194 | * \param pSrc pointer to reconstructed sample array |
---|
| 195 | * \param srcStride the stride of the reconstructed sample array |
---|
| 196 | * \param rpDst reference to pointer for the prediction sample array |
---|
| 197 | * \param dstStride the stride of the prediction sample array |
---|
| 198 | * \param width the width of the block |
---|
| 199 | * \param height the height of the block |
---|
| 200 | * \param dirMode the intra prediction mode index |
---|
| 201 | * \param blkAboveAvailable boolean indication if the block above is available |
---|
| 202 | * \param blkLeftAvailable boolean indication if the block to the left is available |
---|
| 203 | * |
---|
| 204 | * This function derives the prediction samples for the angular mode based on the prediction direction indicated by |
---|
| 205 | * the prediction mode index. The prediction direction is given by the displacement of the bottom row of the block and |
---|
| 206 | * the reference row above the block in the case of vertical prediction or displacement of the rightmost column |
---|
| 207 | * of the block and reference column left from the block in the case of the horizontal prediction. The displacement |
---|
| 208 | * is signalled at 1/32 pixel accuracy. When projection of the predicted pixel falls inbetween reference samples, |
---|
| 209 | * the predicted value for the pixel is linearly interpolated from the reference samples. All reference samples are taken |
---|
| 210 | * from the extended main reference. |
---|
| 211 | */ |
---|
[608] | 212 | Void TComPrediction::xPredIntraAng(Int bitDepth, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, UInt width, UInt height, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, Bool bFilter ) |
---|
[2] | 213 | { |
---|
| 214 | Int k,l; |
---|
| 215 | Int blkSize = width; |
---|
| 216 | Pel* pDst = rpDst; |
---|
| 217 | |
---|
| 218 | // Map the mode index to main prediction direction and angle |
---|
[56] | 219 | assert( dirMode > 0 ); //no planar |
---|
| 220 | Bool modeDC = dirMode < 2; |
---|
| 221 | Bool modeHor = !modeDC && (dirMode < 18); |
---|
| 222 | Bool modeVer = !modeDC && !modeHor; |
---|
| 223 | Int intraPredAngle = modeVer ? (Int)dirMode - VER_IDX : modeHor ? -((Int)dirMode - HOR_IDX) : 0; |
---|
[2] | 224 | Int absAng = abs(intraPredAngle); |
---|
| 225 | Int signAng = intraPredAngle < 0 ? -1 : 1; |
---|
| 226 | |
---|
| 227 | // Set bitshifts and scale the angle parameter to block size |
---|
| 228 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
| 229 | Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle |
---|
| 230 | Int invAngle = invAngTable[absAng]; |
---|
| 231 | absAng = angTable[absAng]; |
---|
| 232 | intraPredAngle = signAng * absAng; |
---|
| 233 | |
---|
| 234 | // Do the DC prediction |
---|
| 235 | if (modeDC) |
---|
| 236 | { |
---|
| 237 | Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable); |
---|
| 238 | |
---|
| 239 | for (k=0;k<blkSize;k++) |
---|
| 240 | { |
---|
| 241 | for (l=0;l<blkSize;l++) |
---|
| 242 | { |
---|
| 243 | pDst[k*dstStride+l] = dcval; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | // Do angular predictions |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | Pel* refMain; |
---|
| 252 | Pel* refSide; |
---|
| 253 | Pel refAbove[2*MAX_CU_SIZE+1]; |
---|
| 254 | Pel refLeft[2*MAX_CU_SIZE+1]; |
---|
| 255 | |
---|
| 256 | // Initialise the Main and Left reference array. |
---|
| 257 | if (intraPredAngle < 0) |
---|
| 258 | { |
---|
| 259 | for (k=0;k<blkSize+1;k++) |
---|
| 260 | { |
---|
| 261 | refAbove[k+blkSize-1] = pSrc[k-srcStride-1]; |
---|
| 262 | } |
---|
| 263 | for (k=0;k<blkSize+1;k++) |
---|
| 264 | { |
---|
| 265 | refLeft[k+blkSize-1] = pSrc[(k-1)*srcStride-1]; |
---|
| 266 | } |
---|
| 267 | refMain = (modeVer ? refAbove : refLeft) + (blkSize-1); |
---|
| 268 | refSide = (modeVer ? refLeft : refAbove) + (blkSize-1); |
---|
| 269 | |
---|
| 270 | // Extend the Main reference to the left. |
---|
| 271 | Int invAngleSum = 128; // rounding for (shift by 8) |
---|
| 272 | for (k=-1; k>blkSize*intraPredAngle>>5; k--) |
---|
| 273 | { |
---|
| 274 | invAngleSum += invAngle; |
---|
| 275 | refMain[k] = refSide[invAngleSum>>8]; |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
| 280 | for (k=0;k<2*blkSize+1;k++) |
---|
| 281 | { |
---|
| 282 | refAbove[k] = pSrc[k-srcStride-1]; |
---|
| 283 | } |
---|
| 284 | for (k=0;k<2*blkSize+1;k++) |
---|
| 285 | { |
---|
| 286 | refLeft[k] = pSrc[(k-1)*srcStride-1]; |
---|
| 287 | } |
---|
| 288 | refMain = modeVer ? refAbove : refLeft; |
---|
[56] | 289 | refSide = modeVer ? refLeft : refAbove; |
---|
[2] | 290 | } |
---|
| 291 | |
---|
| 292 | if (intraPredAngle == 0) |
---|
| 293 | { |
---|
| 294 | for (k=0;k<blkSize;k++) |
---|
| 295 | { |
---|
| 296 | for (l=0;l<blkSize;l++) |
---|
| 297 | { |
---|
| 298 | pDst[k*dstStride+l] = refMain[l+1]; |
---|
| 299 | } |
---|
| 300 | } |
---|
[56] | 301 | |
---|
| 302 | if ( bFilter ) |
---|
| 303 | { |
---|
| 304 | for (k=0;k<blkSize;k++) |
---|
| 305 | { |
---|
[608] | 306 | pDst[k*dstStride] = Clip3(0, (1<<bitDepth)-1, pDst[k*dstStride] + (( refSide[k+1] - refSide[0] ) >> 1) ); |
---|
[56] | 307 | } |
---|
| 308 | } |
---|
[2] | 309 | } |
---|
| 310 | else |
---|
| 311 | { |
---|
| 312 | Int deltaPos=0; |
---|
| 313 | Int deltaInt; |
---|
| 314 | Int deltaFract; |
---|
| 315 | Int refMainIndex; |
---|
| 316 | |
---|
| 317 | for (k=0;k<blkSize;k++) |
---|
| 318 | { |
---|
| 319 | deltaPos += intraPredAngle; |
---|
| 320 | deltaInt = deltaPos >> 5; |
---|
| 321 | deltaFract = deltaPos & (32 - 1); |
---|
| 322 | |
---|
| 323 | if (deltaFract) |
---|
| 324 | { |
---|
| 325 | // Do linear filtering |
---|
| 326 | for (l=0;l<blkSize;l++) |
---|
| 327 | { |
---|
| 328 | refMainIndex = l+deltaInt+1; |
---|
| 329 | pDst[k*dstStride+l] = (Pel) ( ((32-deltaFract)*refMain[refMainIndex]+deltaFract*refMain[refMainIndex+1]+16) >> 5 ); |
---|
| 330 | } |
---|
| 331 | } |
---|
| 332 | else |
---|
| 333 | { |
---|
| 334 | // Just copy the integer samples |
---|
| 335 | for (l=0;l<blkSize;l++) |
---|
| 336 | { |
---|
| 337 | pDst[k*dstStride+l] = refMain[l+deltaInt+1]; |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | // Flip the block if this is the horizontal mode |
---|
| 344 | if (modeHor) |
---|
| 345 | { |
---|
| 346 | Pel tmp; |
---|
| 347 | for (k=0;k<blkSize-1;k++) |
---|
| 348 | { |
---|
| 349 | for (l=k+1;l<blkSize;l++) |
---|
| 350 | { |
---|
| 351 | tmp = pDst[k*dstStride+l]; |
---|
| 352 | pDst[k*dstStride+l] = pDst[l*dstStride+k]; |
---|
| 353 | pDst[l*dstStride+k] = tmp; |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | |
---|
[608] | 360 | Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
[2] | 361 | { |
---|
| 362 | Pel *pDst = piPred; |
---|
| 363 | Int *ptrSrc; |
---|
| 364 | |
---|
[56] | 365 | assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4 |
---|
| 366 | assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128 |
---|
[2] | 367 | assert( iWidth == iHeight ); |
---|
| 368 | |
---|
[56] | 369 | ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
| 370 | |
---|
| 371 | // get starting pixel in block |
---|
| 372 | Int sw = 2 * iWidth + 1; |
---|
| 373 | |
---|
| 374 | // Create the prediction |
---|
| 375 | if ( uiDirMode == PLANAR_IDX ) |
---|
| 376 | { |
---|
| 377 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
| 378 | } |
---|
| 379 | else |
---|
| 380 | { |
---|
[608] | 381 | if ( (iWidth > 16) || (iHeight > 16) ) |
---|
[56] | 382 | { |
---|
[608] | 383 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
[56] | 384 | } |
---|
[608] | 385 | else |
---|
| 386 | { |
---|
| 387 | xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true ); |
---|
| 388 | |
---|
| 389 | if( (uiDirMode == DC_IDX ) && bAbove && bLeft ) |
---|
| 390 | { |
---|
| 391 | xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight); |
---|
| 392 | } |
---|
| 393 | } |
---|
[56] | 394 | } |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | // Angular chroma |
---|
[608] | 398 | Void TComPrediction::predIntraChromaAng( Int* piSrc, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bAbove, Bool bLeft ) |
---|
[56] | 399 | { |
---|
| 400 | Pel *pDst = piPred; |
---|
| 401 | Int *ptrSrc = piSrc; |
---|
| 402 | |
---|
[2] | 403 | // get starting pixel in block |
---|
[56] | 404 | Int sw = 2 * iWidth + 1; |
---|
[2] | 405 | |
---|
| 406 | if ( uiDirMode == PLANAR_IDX ) |
---|
| 407 | { |
---|
| 408 | xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight ); |
---|
[56] | 409 | } |
---|
| 410 | else |
---|
| 411 | { |
---|
| 412 | // Create the prediction |
---|
[608] | 413 | xPredIntraAng(g_bitDepthC, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false ); |
---|
[56] | 414 | } |
---|
| 415 | } |
---|
| 416 | |
---|
[608] | 417 | #if H_3D_DIM |
---|
| 418 | Void TComPrediction::predIntraLumaDepth( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiIntraMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, Bool bFastEnc ) |
---|
[56] | 419 | { |
---|
[608] | 420 | assert( iWidth == iHeight ); |
---|
| 421 | assert( iWidth >= DIM_MIN_SIZE && iWidth <= DIM_MAX_SIZE ); |
---|
| 422 | assert( isDimMode( uiIntraMode ) ); |
---|
[56] | 423 | |
---|
[608] | 424 | UInt dimType = getDimType ( uiIntraMode ); |
---|
| 425 | Bool dimDeltaDC = isDimDeltaDC( uiIntraMode ); |
---|
| 426 | Bool isDmmMode = (dimType < DMM_NUM_TYPE); |
---|
| 427 | Bool isRbcMode = (dimType == RBC_IDX); |
---|
[100] | 428 | |
---|
[608] | 429 | Bool* biSegPattern = NULL; |
---|
| 430 | UInt patternStride = 0; |
---|
[100] | 431 | |
---|
[608] | 432 | // get partiton |
---|
| 433 | #if H_3D_DIM_DMM |
---|
| 434 | TComWedgelet* dmmSegmentation = NULL; |
---|
| 435 | if( isDmmMode ) |
---|
[100] | 436 | { |
---|
[608] | 437 | switch( dimType ) |
---|
[100] | 438 | { |
---|
[608] | 439 | case( DMM1_IDX ): |
---|
[100] | 440 | { |
---|
[608] | 441 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ) ]); |
---|
| 442 | } break; |
---|
| 443 | case( DMM3_IDX ): |
---|
[100] | 444 | { |
---|
[608] | 445 | UInt uiTabIdx = 0; |
---|
| 446 | if( bFastEnc ) { uiTabIdx = pcCU->getDmmWedgeTabIdx( dimType, uiAbsPartIdx ); } |
---|
| 447 | else |
---|
[100] | 448 | { |
---|
[608] | 449 | uiTabIdx = xPredWedgeFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, pcCU->getDmm3IntraTabIdx( uiAbsPartIdx ) ); |
---|
| 450 | pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dimType, uiAbsPartIdx, (pcCU->getDepth(0) + (pcCU->getPartitionSize(0) == SIZE_2Nx2N ? 0 : 1)) ); |
---|
[100] | 451 | } |
---|
[608] | 452 | dmmSegmentation = &(g_dmmWedgeLists[ g_aucConvertToBit[iWidth] ][ uiTabIdx ]); |
---|
| 453 | } break; |
---|
| 454 | case( DMM4_IDX ): |
---|
[100] | 455 | { |
---|
[608] | 456 | dmmSegmentation = new TComWedgelet( iWidth, iHeight ); |
---|
| 457 | xPredContourFromTex( pcCU, uiAbsPartIdx, iWidth, iHeight, dmmSegmentation ); |
---|
| 458 | } break; |
---|
| 459 | default: assert(0); |
---|
[100] | 460 | } |
---|
[608] | 461 | assert( dmmSegmentation ); |
---|
| 462 | biSegPattern = dmmSegmentation->getPattern(); |
---|
| 463 | patternStride = dmmSegmentation->getStride (); |
---|
[100] | 464 | } |
---|
[608] | 465 | #endif |
---|
| 466 | #if H_3D_DIM_RBC |
---|
| 467 | if( isRbcMode ) |
---|
| 468 | { |
---|
| 469 | biSegPattern = pcCU->getEdgePartition( uiAbsPartIdx ); |
---|
| 470 | patternStride = iWidth; |
---|
| 471 | } |
---|
| 472 | #endif |
---|
[100] | 473 | |
---|
[608] | 474 | // get predicted partition values |
---|
| 475 | assert( biSegPattern ); |
---|
| 476 | Int* piMask = NULL; |
---|
[667] | 477 | #if QC_DIM_DELTADC_UNIFY_F0132 || HHI_DIM_PREDSAMP_FIX_F0171 |
---|
| 478 | piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering |
---|
| 479 | #else |
---|
[608] | 480 | if( isDmmMode ) piMask = pcCU->getPattern()->getAdiOrgBuf( iWidth, iHeight, m_piYuvExt ); // no filtering for DMM |
---|
| 481 | else piMask = pcCU->getPattern()->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt ); |
---|
[667] | 482 | #endif |
---|
[608] | 483 | assert( piMask ); |
---|
| 484 | Int maskStride = 2*iWidth + 1; |
---|
| 485 | Int* ptrSrc = piMask+maskStride+1; |
---|
| 486 | Pel predDC1 = 0; Pel predDC2 = 0; |
---|
| 487 | xPredBiSegDCs( ptrSrc, maskStride, biSegPattern, patternStride, predDC1, predDC2 ); |
---|
| 488 | |
---|
| 489 | // set segment values with deltaDC offsets |
---|
| 490 | Pel segDC1 = 0; |
---|
| 491 | Pel segDC2 = 0; |
---|
| 492 | if( dimDeltaDC ) |
---|
[100] | 493 | { |
---|
[608] | 494 | Pel deltaDC1 = pcCU->getDimDeltaDC( dimType, 0, uiAbsPartIdx ); |
---|
| 495 | Pel deltaDC2 = pcCU->getDimDeltaDC( dimType, 1, uiAbsPartIdx ); |
---|
| 496 | #if H_3D_DIM_DMM |
---|
[667] | 497 | #if QC_DIM_DELTADC_UNIFY_F0132 |
---|
| 498 | if( isDmmMode || isRbcMode) |
---|
| 499 | #else |
---|
[608] | 500 | if( isDmmMode ) |
---|
[667] | 501 | #endif |
---|
[608] | 502 | { |
---|
| 503 | #if H_3D_DIM_DLT |
---|
| 504 | segDC1 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC1 ) + deltaDC1 ); |
---|
| 505 | segDC2 = pcCU->getSlice()->getVPS()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), pcCU->getSlice()->getVPS()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), predDC2 ) + deltaDC2 ); |
---|
| 506 | #else |
---|
| 507 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
| 508 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
| 509 | #endif |
---|
| 510 | } |
---|
| 511 | #endif |
---|
[667] | 512 | #if H_3D_DIM_RBC && !QC_DIM_DELTADC_UNIFY_F0132 |
---|
[608] | 513 | if( isRbcMode ) |
---|
| 514 | { |
---|
| 515 | xDeltaDCQuantScaleUp( pcCU, deltaDC1 ); |
---|
| 516 | xDeltaDCQuantScaleUp( pcCU, deltaDC2 ); |
---|
| 517 | segDC1 = ClipY( predDC1 + deltaDC1 ); |
---|
| 518 | segDC2 = ClipY( predDC2 + deltaDC2 ); |
---|
| 519 | } |
---|
| 520 | #endif |
---|
[100] | 521 | } |
---|
[608] | 522 | else |
---|
[100] | 523 | { |
---|
[608] | 524 | segDC1 = predDC1; |
---|
| 525 | segDC2 = predDC2; |
---|
[100] | 526 | } |
---|
| 527 | |
---|
[608] | 528 | // set prediction signal |
---|
| 529 | Pel* pDst = piPred; |
---|
| 530 | xAssignBiSegDCs( pDst, uiStride, biSegPattern, patternStride, segDC1, segDC2 ); |
---|
[100] | 531 | |
---|
[608] | 532 | #if H_3D_DIM_DMM |
---|
| 533 | if( dimType == DMM4_IDX ) { dmmSegmentation->destroy(); delete dmmSegmentation; } |
---|
| 534 | #endif |
---|
[100] | 535 | } |
---|
[608] | 536 | #endif |
---|
[100] | 537 | |
---|
[608] | 538 | /** Function for checking identical motion. |
---|
| 539 | * \param TComDataCU* pcCU |
---|
| 540 | * \param UInt PartAddr |
---|
| 541 | */ |
---|
| 542 | Bool TComPrediction::xCheckIdenticalMotion ( TComDataCU* pcCU, UInt PartAddr ) |
---|
[100] | 543 | { |
---|
[608] | 544 | if( pcCU->getSlice()->isInterB() && !pcCU->getSlice()->getPPS()->getWPBiPred() ) |
---|
[100] | 545 | { |
---|
[608] | 546 | if( pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr) >= 0 && pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr) >= 0) |
---|
[100] | 547 | { |
---|
[608] | 548 | Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC(); |
---|
| 549 | Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC(); |
---|
| 550 | if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr)) |
---|
[100] | 551 | { |
---|
[608] | 552 | return true; |
---|
[100] | 553 | } |
---|
| 554 | } |
---|
| 555 | } |
---|
[608] | 556 | return false; |
---|
[100] | 557 | } |
---|
| 558 | |
---|
[608] | 559 | |
---|
[56] | 560 | Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx ) |
---|
| 561 | { |
---|
| 562 | Int iWidth; |
---|
| 563 | Int iHeight; |
---|
| 564 | UInt uiPartAddr; |
---|
| 565 | |
---|
| 566 | if ( iPartIdx >= 0 ) |
---|
| 567 | { |
---|
| 568 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
[608] | 569 | #if H_3D_VSP |
---|
[622] | 570 | if ( pcCU->getVSPFlag(uiPartAddr) == 0) |
---|
[56] | 571 | { |
---|
| 572 | #endif |
---|
[608] | 573 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
[56] | 574 | { |
---|
[608] | 575 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
| 576 | { |
---|
| 577 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
| 578 | } |
---|
| 579 | else |
---|
| 580 | { |
---|
| 581 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 582 | } |
---|
| 583 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
| 584 | { |
---|
| 585 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 586 | } |
---|
[56] | 587 | } |
---|
| 588 | else |
---|
| 589 | { |
---|
[608] | 590 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 591 | { |
---|
| 592 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 597 | } |
---|
[56] | 598 | } |
---|
[608] | 599 | #if H_3D_VSP |
---|
[56] | 600 | } |
---|
| 601 | else |
---|
| 602 | { |
---|
[608] | 603 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
[622] | 604 | { |
---|
[608] | 605 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[622] | 606 | } |
---|
[56] | 607 | else |
---|
[622] | 608 | { |
---|
[608] | 609 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
[622] | 610 | } |
---|
[608] | 611 | } |
---|
[296] | 612 | #endif |
---|
[2] | 613 | return; |
---|
| 614 | } |
---|
[56] | 615 | |
---|
| 616 | for ( iPartIdx = 0; iPartIdx < pcCU->getNumPartInter(); iPartIdx++ ) |
---|
| 617 | { |
---|
| 618 | pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight ); |
---|
| 619 | |
---|
[608] | 620 | #if H_3D_VSP |
---|
[622] | 621 | if ( pcCU->getVSPFlag(uiPartAddr) == 0 ) |
---|
[56] | 622 | { |
---|
[189] | 623 | #endif |
---|
[608] | 624 | if ( eRefPicList != REF_PIC_LIST_X ) |
---|
[56] | 625 | { |
---|
[608] | 626 | if( pcCU->getSlice()->getPPS()->getUseWP()) |
---|
| 627 | { |
---|
| 628 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true ); |
---|
| 629 | } |
---|
| 630 | else |
---|
| 631 | { |
---|
| 632 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 633 | } |
---|
| 634 | if ( pcCU->getSlice()->getPPS()->getUseWP() ) |
---|
| 635 | { |
---|
| 636 | xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred ); |
---|
| 637 | } |
---|
[56] | 638 | } |
---|
[608] | 639 | else |
---|
[56] | 640 | { |
---|
[608] | 641 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
| 642 | { |
---|
| 643 | xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
| 644 | } |
---|
| 645 | else |
---|
| 646 | { |
---|
| 647 | xPredInterBi (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
| 648 | } |
---|
[56] | 649 | } |
---|
[608] | 650 | #if H_3D_VSP |
---|
[56] | 651 | } |
---|
| 652 | else |
---|
| 653 | { |
---|
| 654 | if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) ) |
---|
[622] | 655 | { |
---|
[608] | 656 | xPredInterUniVSP( pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred ); |
---|
[622] | 657 | } |
---|
[56] | 658 | else |
---|
[622] | 659 | { |
---|
[608] | 660 | xPredInterBiVSP ( pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred ); |
---|
[622] | 661 | } |
---|
[56] | 662 | } |
---|
[608] | 663 | #endif |
---|
[56] | 664 | } |
---|
| 665 | return; |
---|
| 666 | } |
---|
[2] | 667 | |
---|
[608] | 668 | Void TComPrediction::xPredInterUni ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
[296] | 669 | { |
---|
[608] | 670 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); |
---|
| 671 | TComMv cMv = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
| 672 | pcCU->clipMv(cMv); |
---|
| 673 | #if H_3D_ARP |
---|
| 674 | if( pcCU->getARPW( uiPartAddr ) > 0 |
---|
| 675 | && pcCU->getPartitionSize(uiPartAddr)==SIZE_2Nx2N |
---|
| 676 | && pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()!= pcCU->getSlice()->getPOC() |
---|
| 677 | ) |
---|
[443] | 678 | { |
---|
[608] | 679 | xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, rpcYuvPred, bi ); |
---|
[443] | 680 | } |
---|
[608] | 681 | else |
---|
| 682 | { |
---|
[443] | 683 | #endif |
---|
[608] | 684 | #if H_3D_IC |
---|
| 685 | Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ); |
---|
| 686 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
| 687 | #if H_3D_ARP |
---|
| 688 | , false |
---|
[443] | 689 | #endif |
---|
[608] | 690 | , bICFlag ); |
---|
| 691 | bICFlag = bICFlag && (iWidth > 8); |
---|
| 692 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi |
---|
| 693 | #if H_3D_ARP |
---|
| 694 | , false |
---|
[443] | 695 | #endif |
---|
[608] | 696 | , bICFlag ); |
---|
[443] | 697 | #else |
---|
[608] | 698 | xPredInterLumaBlk ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
| 699 | xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi ); |
---|
[443] | 700 | #endif |
---|
[608] | 701 | #if H_3D_ARP |
---|
[443] | 702 | } |
---|
| 703 | #endif |
---|
| 704 | } |
---|
| 705 | |
---|
[608] | 706 | #if H_3D_VSP |
---|
| 707 | Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi ) |
---|
[56] | 708 | { |
---|
[608] | 709 | // Get depth reference |
---|
[622] | 710 | Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
[655] | 711 | #if H_3D_FCO_VSP_DONBDV_E0163 |
---|
| 712 | TComPic* pRefPicBaseDepth = 0; |
---|
| 713 | Bool bIsCurrDepthCoded = false; |
---|
| 714 | pRefPicBaseDepth = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() ); |
---|
| 715 | if ( pRefPicBaseDepth->getPicYuvRec() != NULL ) |
---|
| 716 | { |
---|
| 717 | bIsCurrDepthCoded = true; |
---|
| 718 | } |
---|
| 719 | else |
---|
| 720 | { |
---|
| 721 | pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx ); |
---|
| 722 | } |
---|
| 723 | #else |
---|
[608] | 724 | TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx ); |
---|
[655] | 725 | #endif |
---|
[608] | 726 | assert(pRefPicBaseDepth != NULL); |
---|
| 727 | TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec(); |
---|
| 728 | assert(pcBaseViewDepthPicYuv != NULL); |
---|
[296] | 729 | |
---|
[608] | 730 | // Get texture reference |
---|
| 731 | Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 732 | assert(iRefIdx >= 0); |
---|
| 733 | TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx ); |
---|
| 734 | TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec(); |
---|
| 735 | assert(pcBaseViewTxtPicYuv != NULL); |
---|
[56] | 736 | |
---|
[608] | 737 | // Initialize LUT according to the reference viewIdx |
---|
| 738 | Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex(); |
---|
| 739 | Int* pShiftLUT = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx ); |
---|
| 740 | assert( txtRefViewIdx < pcCU->getSlice()->getViewIndex() ); |
---|
[100] | 741 | |
---|
[608] | 742 | // Do compensation |
---|
| 743 | TComMv cDv = pcCU->getDvInfo(uiPartAddr).m_acNBDV; |
---|
| 744 | pcCU->clipMv(cDv); |
---|
[296] | 745 | |
---|
[655] | 746 | #if H_3D_FCO_VSP_DONBDV_E0163 |
---|
| 747 | if ( bIsCurrDepthCoded ) |
---|
| 748 | { |
---|
| 749 | cDv.setZero(); |
---|
| 750 | } |
---|
| 751 | #endif |
---|
[608] | 752 | // fetch virtual depth map |
---|
| 753 | pcBaseViewDepthPicYuv->extendPicBorder(); |
---|
| 754 | xGetVirtualDepth( pcCU, pcBaseViewDepthPicYuv, &cDv, uiPartAddr, iWidth, iHeight, &m_cYuvDepthOnVsp ); |
---|
| 755 | // sub-PU based compensation |
---|
| 756 | xPredInterLumaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi ); |
---|
| 757 | xPredInterChromaBlkFromDM ( pcCU, pcBaseViewTxtPicYuv, &m_cYuvDepthOnVsp, pShiftLUT, &cDv, uiPartAddr, iWidth, iHeight, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi ); |
---|
| 758 | } |
---|
[296] | 759 | #endif |
---|
[189] | 760 | |
---|
[608] | 761 | #if H_3D_ARP |
---|
| 762 | Void TComPrediction::xPredInterUniARP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi, TComMvField * pNewMvFiled ) |
---|
| 763 | { |
---|
| 764 | Int iRefIdx = pNewMvFiled ? pNewMvFiled->getRefIdx() : pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 765 | TComMv cMv = pNewMvFiled ? pNewMvFiled->getMv() : pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr ); |
---|
| 766 | Bool bTobeScaled = false; |
---|
| 767 | TComPic* pcPicYuvBaseCol = NULL; |
---|
| 768 | TComPic* pcPicYuvBaseRef = NULL; |
---|
[2] | 769 | |
---|
[608] | 770 | #if H_3D_NBDV |
---|
[443] | 771 | DisInfo cDistparity; |
---|
| 772 | cDistparity.bDV = pcCU->getDvInfo(uiPartAddr).bDV; |
---|
| 773 | if( cDistparity.bDV ) |
---|
| 774 | { |
---|
[608] | 775 | cDistparity.m_acNBDV = pcCU->getDvInfo(0).m_acNBDV; |
---|
[443] | 776 | assert(pcCU->getDvInfo(uiPartAddr).bDV == pcCU->getDvInfo(0).bDV); |
---|
[608] | 777 | cDistparity.m_aVIdxCan = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan; |
---|
[443] | 778 | } |
---|
| 779 | #else |
---|
[608] | 780 | assert(0); // ARP can be applied only when a DV is available |
---|
[443] | 781 | #endif |
---|
| 782 | |
---|
[608] | 783 | UChar dW = cDistparity.bDV ? pcCU->getARPW ( uiPartAddr ) : 0; |
---|
| 784 | |
---|
| 785 | if( cDistparity.bDV ) |
---|
[443] | 786 | { |
---|
[608] | 787 | if( dW > 0 && pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC()!= pcCU->getSlice()->getPOC() ) |
---|
| 788 | { |
---|
[443] | 789 | bTobeScaled = true; |
---|
[608] | 790 | } |
---|
| 791 | |
---|
| 792 | pcPicYuvBaseCol = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getPOC(), cDistparity.m_aVIdxCan ); |
---|
| 793 | pcPicYuvBaseRef = pcCU->getSlice()->getBaseViewRefPic( pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC(), cDistparity.m_aVIdxCan ); |
---|
| 794 | |
---|
| 795 | if( ( !pcPicYuvBaseCol || pcPicYuvBaseCol->getPOC() != pcCU->getSlice()->getPOC() ) || ( !pcPicYuvBaseRef || pcPicYuvBaseRef->getPOC() != pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ) ) |
---|
[443] | 796 | { |
---|
| 797 | dW = 0; |
---|
| 798 | bTobeScaled = false; |
---|
| 799 | } |
---|
| 800 | else |
---|
[608] | 801 | { |
---|
[443] | 802 | assert( pcPicYuvBaseCol->getPOC() == pcCU->getSlice()->getPOC() && pcPicYuvBaseRef->getPOC() == pcCU->getSlice()->getRefPic( eRefPicList, 0 )->getPOC() ); |
---|
[608] | 803 | } |
---|
| 804 | |
---|
[443] | 805 | if(bTobeScaled) |
---|
| 806 | { |
---|
[608] | 807 | Int iCurrPOC = pcCU->getSlice()->getPOC(); |
---|
[443] | 808 | Int iColRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, iRefIdx ); |
---|
| 809 | Int iCurrRefPOC = pcCU->getSlice()->getRefPOC( eRefPicList, 0); |
---|
| 810 | Int iScale = pcCU-> xGetDistScaleFactor(iCurrPOC, iCurrRefPOC, iCurrPOC, iColRefPOC); |
---|
| 811 | if ( iScale != 4096 ) |
---|
[608] | 812 | { |
---|
[443] | 813 | cMv = cMv.scaleMv( iScale ); |
---|
[608] | 814 | } |
---|
[443] | 815 | iRefIdx = 0; |
---|
| 816 | } |
---|
| 817 | } |
---|
[608] | 818 | |
---|
[443] | 819 | pcCU->clipMv(cMv); |
---|
| 820 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(); |
---|
[608] | 821 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
| 822 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi, true ); |
---|
| 823 | |
---|
[443] | 824 | if( dW > 0 ) |
---|
| 825 | { |
---|
[608] | 826 | TComYuv * pYuvB0 = &m_acYuvPredBase[0]; |
---|
[443] | 827 | TComYuv * pYuvB1 = &m_acYuvPredBase[1]; |
---|
[608] | 828 | |
---|
| 829 | TComMv cMVwithDisparity = cMv + cDistparity.m_acNBDV; |
---|
| 830 | pcCU->clipMv(cMVwithDisparity); |
---|
| 831 | |
---|
| 832 | assert ( cDistparity.bDV ); |
---|
| 833 | |
---|
[443] | 834 | pcPicYuvRef = pcPicYuvBaseCol->getPicYuvRec(); |
---|
[608] | 835 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
| 836 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cDistparity.m_acNBDV, iWidth, iHeight, pYuvB0, bi, true ); |
---|
| 837 | |
---|
[443] | 838 | pcPicYuvRef = pcPicYuvBaseRef->getPicYuvRec(); |
---|
[608] | 839 | xPredInterLumaBlk ( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
| 840 | xPredInterChromaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMVwithDisparity, iWidth, iHeight, pYuvB1, bi, true ); |
---|
| 841 | |
---|
| 842 | pYuvB0->subtractARP( pYuvB0 , pYuvB1 , uiPartAddr , iWidth , iHeight ); |
---|
| 843 | |
---|
| 844 | if( 2 == dW ) |
---|
| 845 | { |
---|
| 846 | pYuvB0->multiplyARP( uiPartAddr , iWidth , iHeight , dW ); |
---|
| 847 | } |
---|
| 848 | rpcYuvPred->addARP( rpcYuvPred , pYuvB0 , uiPartAddr , iWidth , iHeight , !bi ); |
---|
[443] | 849 | } |
---|
| 850 | } |
---|
| 851 | #endif |
---|
| 852 | |
---|
[608] | 853 | Void TComPrediction::xPredInterBi ( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
[2] | 854 | { |
---|
[56] | 855 | TComYuv* pcMbYuv; |
---|
| 856 | Int iRefIdx[2] = {-1, -1}; |
---|
| 857 | |
---|
| 858 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
| 859 | { |
---|
| 860 | RefPicList eRefPicList = (iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0); |
---|
| 861 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
| 862 | |
---|
| 863 | if ( iRefIdx[iRefList] < 0 ) |
---|
| 864 | { |
---|
| 865 | continue; |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
| 869 | |
---|
| 870 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
| 871 | if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 ) |
---|
| 872 | { |
---|
[608] | 873 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
[56] | 874 | } |
---|
| 875 | else |
---|
| 876 | { |
---|
[608] | 877 | if ( ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) || |
---|
| 878 | ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) ) |
---|
[56] | 879 | { |
---|
[608] | 880 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, true ); |
---|
[56] | 881 | } |
---|
| 882 | else |
---|
| 883 | { |
---|
[608] | 884 | xPredInterUni ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv ); |
---|
[56] | 885 | } |
---|
| 886 | } |
---|
| 887 | } |
---|
[608] | 888 | |
---|
| 889 | if ( pcCU->getSlice()->getPPS()->getWPBiPred() && pcCU->getSlice()->getSliceType() == B_SLICE ) |
---|
[56] | 890 | { |
---|
| 891 | xWeightedPredictionBi( pcCU, &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
[608] | 892 | } |
---|
[313] | 893 | else if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType() == P_SLICE ) |
---|
| 894 | { |
---|
[608] | 895 | xWeightedPredictionUni( pcCU, &m_acYuvPred[0], uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, rpcYuvPred ); |
---|
[313] | 896 | } |
---|
[56] | 897 | else |
---|
| 898 | { |
---|
[608] | 899 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
[56] | 900 | } |
---|
[2] | 901 | } |
---|
| 902 | |
---|
[608] | 903 | #if H_3D_VSP |
---|
[296] | 904 | |
---|
[608] | 905 | Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred ) |
---|
| 906 | { |
---|
| 907 | TComYuv* pcMbYuv; |
---|
| 908 | Int iRefIdx[2] = {-1, -1}; |
---|
| 909 | Bool bi = (pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0); |
---|
[296] | 910 | |
---|
[608] | 911 | for ( Int iRefList = 0; iRefList < 2; iRefList++ ) |
---|
[2] | 912 | { |
---|
[608] | 913 | RefPicList eRefPicList = RefPicList(iRefList); |
---|
| 914 | iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); |
---|
[56] | 915 | |
---|
[608] | 916 | if ( iRefIdx[iRefList] < 0 ) |
---|
[622] | 917 | { |
---|
[608] | 918 | continue; |
---|
[622] | 919 | } |
---|
[608] | 920 | assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) ); |
---|
[56] | 921 | |
---|
[608] | 922 | pcMbYuv = &m_acYuvPred[iRefList]; |
---|
| 923 | xPredInterUniVSP ( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcMbYuv, bi ); |
---|
[2] | 924 | } |
---|
[296] | 925 | |
---|
[608] | 926 | xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred ); |
---|
| 927 | } |
---|
[296] | 928 | |
---|
| 929 | #endif |
---|
[56] | 930 | |
---|
| 931 | /** |
---|
| 932 | * \brief Generate motion-compensated luma block |
---|
| 933 | * |
---|
| 934 | * \param cu Pointer to current CU |
---|
| 935 | * \param refPic Pointer to reference picture |
---|
| 936 | * \param partAddr Address of block within CU |
---|
| 937 | * \param mv Motion vector |
---|
| 938 | * \param width Width of block |
---|
| 939 | * \param height Height of block |
---|
| 940 | * \param dstPic Pointer to destination picture |
---|
| 941 | * \param bi Flag indicating whether bipred is used |
---|
| 942 | */ |
---|
[608] | 943 | Void TComPrediction::xPredInterLumaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
| 944 | #if H_3D_ARP |
---|
| 945 | , Bool filterType |
---|
[189] | 946 | #endif |
---|
[608] | 947 | #if H_3D_IC |
---|
| 948 | , Bool bICFlag |
---|
| 949 | #endif |
---|
| 950 | ) |
---|
[56] | 951 | { |
---|
| 952 | Int refStride = refPic->getStride(); |
---|
| 953 | Int refOffset = ( mv->getHor() >> 2 ) + ( mv->getVer() >> 2 ) * refStride; |
---|
| 954 | Pel *ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
| 955 | |
---|
| 956 | Int dstStride = dstPic->getStride(); |
---|
| 957 | Pel *dst = dstPic->getLumaAddr( partAddr ); |
---|
| 958 | |
---|
| 959 | Int xFrac = mv->getHor() & 0x3; |
---|
| 960 | Int yFrac = mv->getVer() & 0x3; |
---|
| 961 | |
---|
[608] | 962 | #if H_3D_IC |
---|
| 963 | if( cu->getSlice()->getIsDepth() ) |
---|
| 964 | { |
---|
| 965 | refOffset = mv->getHor() + mv->getVer() * refStride; |
---|
| 966 | ref = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
| 967 | xFrac = 0; |
---|
| 968 | yFrac = 0; |
---|
| 969 | } |
---|
[56] | 970 | #endif |
---|
| 971 | if ( yFrac == 0 ) |
---|
[2] | 972 | { |
---|
[655] | 973 | #if H_3D_IC |
---|
[608] | 974 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi || bICFlag |
---|
| 975 | #else |
---|
| 976 | m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac, !bi |
---|
[443] | 977 | #endif |
---|
[608] | 978 | #if H_3D_ARP |
---|
| 979 | , filterType |
---|
| 980 | #endif |
---|
| 981 | ); |
---|
[2] | 982 | } |
---|
[56] | 983 | else if ( xFrac == 0 ) |
---|
| 984 | { |
---|
[655] | 985 | #if H_3D_IC |
---|
[608] | 986 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag |
---|
| 987 | #else |
---|
| 988 | m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi |
---|
[443] | 989 | #endif |
---|
[608] | 990 | #if H_3D_ARP |
---|
| 991 | , filterType |
---|
| 992 | #endif |
---|
| 993 | ); |
---|
[56] | 994 | } |
---|
| 995 | else |
---|
| 996 | { |
---|
| 997 | Int tmpStride = m_filteredBlockTmp[0].getStride(); |
---|
| 998 | Short *tmp = m_filteredBlockTmp[0].getLumaAddr(); |
---|
| 999 | |
---|
| 1000 | Int filterSize = NTAPS_LUMA; |
---|
| 1001 | Int halfFilterSize = ( filterSize >> 1 ); |
---|
| 1002 | |
---|
[443] | 1003 | m_if.filterHorLuma(ref - (halfFilterSize-1)*refStride, refStride, tmp, tmpStride, width, height+filterSize-1, xFrac, false |
---|
[608] | 1004 | #if H_3D_ARP |
---|
| 1005 | , filterType |
---|
[443] | 1006 | #endif |
---|
[608] | 1007 | ); |
---|
[655] | 1008 | #if H_3D_IC |
---|
[608] | 1009 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi || bICFlag |
---|
| 1010 | #else |
---|
[443] | 1011 | m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height, yFrac, false, !bi |
---|
[608] | 1012 | #endif |
---|
| 1013 | #if H_3D_ARP |
---|
| 1014 | , filterType |
---|
[443] | 1015 | #endif |
---|
[608] | 1016 | ); |
---|
[56] | 1017 | } |
---|
[189] | 1018 | |
---|
[608] | 1019 | #if H_3D_IC |
---|
| 1020 | if( bICFlag ) |
---|
[189] | 1021 | { |
---|
[608] | 1022 | Int a, b, i, j; |
---|
| 1023 | const Int iShift = IC_CONST_SHIFT; |
---|
| 1024 | |
---|
| 1025 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA ); |
---|
[189] | 1026 | |
---|
| 1027 | |
---|
[608] | 1028 | for ( i = 0; i < height; i++ ) |
---|
[189] | 1029 | { |
---|
[608] | 1030 | for ( j = 0; j < width; j++ ) |
---|
[189] | 1031 | { |
---|
[608] | 1032 | dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b ); |
---|
[189] | 1033 | } |
---|
| 1034 | dst += dstStride; |
---|
| 1035 | } |
---|
[655] | 1036 | |
---|
[608] | 1037 | if(bi) |
---|
| 1038 | { |
---|
| 1039 | Pel *dst2 = dstPic->getLumaAddr( partAddr ); |
---|
| 1040 | Int shift = IF_INTERNAL_PREC - g_bitDepthY; |
---|
| 1041 | for (i = 0; i < height; i++) |
---|
| 1042 | { |
---|
| 1043 | for (j = 0; j < width; j++) |
---|
| 1044 | { |
---|
| 1045 | Short val = dst2[j] << shift; |
---|
| 1046 | dst2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
| 1047 | } |
---|
| 1048 | dst2 += dstStride; |
---|
| 1049 | } |
---|
| 1050 | } |
---|
[189] | 1051 | } |
---|
| 1052 | #endif |
---|
[2] | 1053 | } |
---|
| 1054 | |
---|
[56] | 1055 | /** |
---|
| 1056 | * \brief Generate motion-compensated chroma block |
---|
| 1057 | * |
---|
| 1058 | * \param cu Pointer to current CU |
---|
| 1059 | * \param refPic Pointer to reference picture |
---|
| 1060 | * \param partAddr Address of block within CU |
---|
| 1061 | * \param mv Motion vector |
---|
| 1062 | * \param width Width of block |
---|
| 1063 | * \param height Height of block |
---|
| 1064 | * \param dstPic Pointer to destination picture |
---|
| 1065 | * \param bi Flag indicating whether bipred is used |
---|
| 1066 | */ |
---|
[608] | 1067 | Void TComPrediction::xPredInterChromaBlk( TComDataCU *cu, TComPicYuv *refPic, UInt partAddr, TComMv *mv, Int width, Int height, TComYuv *&dstPic, Bool bi |
---|
| 1068 | #if H_3D_ARP |
---|
| 1069 | , Bool filterType |
---|
[189] | 1070 | #endif |
---|
[608] | 1071 | #if H_3D_IC |
---|
| 1072 | , Bool bICFlag |
---|
| 1073 | #endif |
---|
[443] | 1074 | ) |
---|
[2] | 1075 | { |
---|
[56] | 1076 | Int refStride = refPic->getCStride(); |
---|
| 1077 | Int dstStride = dstPic->getCStride(); |
---|
| 1078 | |
---|
| 1079 | Int refOffset = (mv->getHor() >> 3) + (mv->getVer() >> 3) * refStride; |
---|
| 1080 | |
---|
| 1081 | Pel* refCb = refPic->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
| 1082 | Pel* refCr = refPic->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset; |
---|
| 1083 | |
---|
| 1084 | Pel* dstCb = dstPic->getCbAddr( partAddr ); |
---|
| 1085 | Pel* dstCr = dstPic->getCrAddr( partAddr ); |
---|
| 1086 | |
---|
| 1087 | Int xFrac = mv->getHor() & 0x7; |
---|
| 1088 | Int yFrac = mv->getVer() & 0x7; |
---|
| 1089 | UInt cxWidth = width >> 1; |
---|
| 1090 | UInt cxHeight = height >> 1; |
---|
| 1091 | |
---|
| 1092 | Int extStride = m_filteredBlockTmp[0].getStride(); |
---|
| 1093 | Short* extY = m_filteredBlockTmp[0].getLumaAddr(); |
---|
| 1094 | |
---|
| 1095 | Int filterSize = NTAPS_CHROMA; |
---|
| 1096 | |
---|
| 1097 | Int halfFilterSize = (filterSize>>1); |
---|
| 1098 | |
---|
| 1099 | if ( yFrac == 0 ) |
---|
| 1100 | { |
---|
[655] | 1101 | #if H_3D_IC |
---|
[608] | 1102 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
| 1103 | #else |
---|
[443] | 1104 | m_if.filterHorChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
[608] | 1105 | #endif |
---|
| 1106 | #if H_3D_ARP |
---|
| 1107 | , filterType |
---|
| 1108 | #endif |
---|
[443] | 1109 | ); |
---|
[655] | 1110 | #if H_3D_IC |
---|
[608] | 1111 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag |
---|
| 1112 | #else |
---|
[443] | 1113 | m_if.filterHorChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, xFrac, !bi |
---|
[608] | 1114 | #endif |
---|
| 1115 | #if H_3D_ARP |
---|
| 1116 | , filterType |
---|
| 1117 | #endif |
---|
| 1118 | ); |
---|
[56] | 1119 | } |
---|
| 1120 | else if ( xFrac == 0 ) |
---|
| 1121 | { |
---|
[655] | 1122 | #if H_3D_IC |
---|
[608] | 1123 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
| 1124 | #else |
---|
[443] | 1125 | m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
[608] | 1126 | #endif |
---|
| 1127 | #if H_3D_ARP |
---|
| 1128 | , filterType |
---|
| 1129 | #endif |
---|
| 1130 | ); |
---|
[655] | 1131 | #if H_3D_IC |
---|
[608] | 1132 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag |
---|
| 1133 | #else |
---|
[443] | 1134 | m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi |
---|
[608] | 1135 | #endif |
---|
| 1136 | #if H_3D_ARP |
---|
| 1137 | , filterType |
---|
| 1138 | #endif |
---|
| 1139 | ); |
---|
[56] | 1140 | } |
---|
| 1141 | else |
---|
| 1142 | { |
---|
[443] | 1143 | m_if.filterHorChroma(refCb - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
[608] | 1144 | #if H_3D_ARP |
---|
| 1145 | , filterType |
---|
| 1146 | #endif |
---|
| 1147 | ); |
---|
[655] | 1148 | #if H_3D_IC |
---|
[608] | 1149 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
| 1150 | #else |
---|
[443] | 1151 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
[608] | 1152 | #endif |
---|
| 1153 | #if H_3D_ARP |
---|
| 1154 | , filterType |
---|
| 1155 | #endif |
---|
| 1156 | ); |
---|
[56] | 1157 | |
---|
[443] | 1158 | m_if.filterHorChroma(refCr - (halfFilterSize-1)*refStride, refStride, extY, extStride, cxWidth, cxHeight+filterSize-1, xFrac, false |
---|
[608] | 1159 | #if H_3D_ARP |
---|
| 1160 | , filterType |
---|
| 1161 | #endif |
---|
| 1162 | ); |
---|
[655] | 1163 | #if H_3D_IC |
---|
[608] | 1164 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi || bICFlag |
---|
| 1165 | #else |
---|
[443] | 1166 | m_if.filterVerChroma(extY + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight , yFrac, false, !bi |
---|
[608] | 1167 | #endif |
---|
| 1168 | #if H_3D_ARP |
---|
| 1169 | , filterType |
---|
| 1170 | #endif |
---|
| 1171 | ); |
---|
[56] | 1172 | } |
---|
[608] | 1173 | |
---|
| 1174 | #if H_3D_IC |
---|
| 1175 | if( bICFlag ) |
---|
[189] | 1176 | { |
---|
[608] | 1177 | Int a, b, i, j; |
---|
| 1178 | const Int iShift = IC_CONST_SHIFT; |
---|
| 1179 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb |
---|
| 1180 | for ( i = 0; i < cxHeight; i++ ) |
---|
[189] | 1181 | { |
---|
[608] | 1182 | for ( j = 0; j < cxWidth; j++ ) |
---|
[189] | 1183 | { |
---|
[608] | 1184 | dstCb[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b ); |
---|
[189] | 1185 | } |
---|
| 1186 | dstCb += dstStride; |
---|
| 1187 | } |
---|
[608] | 1188 | xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr |
---|
| 1189 | for ( i = 0; i < cxHeight; i++ ) |
---|
[189] | 1190 | { |
---|
[608] | 1191 | for ( j = 0; j < cxWidth; j++ ) |
---|
[189] | 1192 | { |
---|
[608] | 1193 | dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b ); |
---|
[189] | 1194 | } |
---|
| 1195 | dstCr += dstStride; |
---|
| 1196 | } |
---|
[655] | 1197 | |
---|
[608] | 1198 | if(bi) |
---|
[296] | 1199 | { |
---|
[608] | 1200 | Pel* dstCb2 = dstPic->getCbAddr( partAddr ); |
---|
| 1201 | Pel* dstCr2 = dstPic->getCrAddr( partAddr ); |
---|
| 1202 | Int shift = IF_INTERNAL_PREC - g_bitDepthC; |
---|
| 1203 | for (i = 0; i < cxHeight; i++) |
---|
[296] | 1204 | { |
---|
[608] | 1205 | for (j = 0; j < cxWidth; j++) |
---|
[296] | 1206 | { |
---|
[608] | 1207 | Short val = dstCb2[j] << shift; |
---|
| 1208 | dstCb2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
[461] | 1209 | |
---|
[608] | 1210 | val = dstCr2[j] << shift; |
---|
| 1211 | dstCr2[j] = val - (Short)IF_INTERNAL_OFFS; |
---|
[296] | 1212 | } |
---|
[608] | 1213 | dstCb2 += dstStride; |
---|
| 1214 | dstCr2 += dstStride; |
---|
[443] | 1215 | } |
---|
| 1216 | } |
---|
[296] | 1217 | } |
---|
[443] | 1218 | #endif |
---|
[296] | 1219 | } |
---|
| 1220 | |
---|
[608] | 1221 | Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvDst ) |
---|
[2] | 1222 | { |
---|
[56] | 1223 | if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) |
---|
[2] | 1224 | { |
---|
[56] | 1225 | rpcYuvDst->addAvg( pcYuvSrc0, pcYuvSrc1, uiPartIdx, iWidth, iHeight ); |
---|
[2] | 1226 | } |
---|
[56] | 1227 | else if ( iRefIdx0 >= 0 && iRefIdx1 < 0 ) |
---|
[2] | 1228 | { |
---|
[56] | 1229 | pcYuvSrc0->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
[2] | 1230 | } |
---|
[56] | 1231 | else if ( iRefIdx0 < 0 && iRefIdx1 >= 0 ) |
---|
[2] | 1232 | { |
---|
[56] | 1233 | pcYuvSrc1->copyPartToPartYuv( rpcYuvDst, uiPartIdx, iWidth, iHeight ); |
---|
| 1234 | } |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | // AMVP |
---|
[608] | 1238 | Void TComPrediction::getMvPredAMVP( TComDataCU* pcCU, UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, TComMv& rcMvPred ) |
---|
[56] | 1239 | { |
---|
| 1240 | AMVPInfo* pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo(); |
---|
[608] | 1241 | if( pcAMVPInfo->iN <= 1 ) |
---|
[56] | 1242 | { |
---|
| 1243 | rcMvPred = pcAMVPInfo->m_acMvCand[0]; |
---|
| 1244 | |
---|
| 1245 | pcCU->setMVPIdxSubParts( 0, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 1246 | pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr)); |
---|
| 1247 | return; |
---|
| 1248 | } |
---|
| 1249 | |
---|
| 1250 | assert(pcCU->getMVPIdx(eRefPicList,uiPartAddr) >= 0); |
---|
| 1251 | rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; |
---|
| 1252 | return; |
---|
| 1253 | } |
---|
| 1254 | |
---|
| 1255 | /** Function for deriving planar intra prediction. |
---|
| 1256 | * \param pSrc pointer to reconstructed sample array |
---|
| 1257 | * \param srcStride the stride of the reconstructed sample array |
---|
| 1258 | * \param rpDst reference to pointer for the prediction sample array |
---|
| 1259 | * \param dstStride the stride of the prediction sample array |
---|
| 1260 | * \param width the width of the block |
---|
| 1261 | * \param height the height of the block |
---|
| 1262 | * |
---|
| 1263 | * This function derives the prediction samples for planar mode (intra coding). |
---|
| 1264 | */ |
---|
| 1265 | Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height ) |
---|
| 1266 | { |
---|
| 1267 | assert(width == height); |
---|
| 1268 | |
---|
| 1269 | Int k, l, bottomLeft, topRight; |
---|
| 1270 | Int horPred; |
---|
[655] | 1271 | Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE]; |
---|
[56] | 1272 | UInt blkSize = width; |
---|
| 1273 | UInt offset2D = width; |
---|
| 1274 | UInt shift1D = g_aucConvertToBit[ width ] + 2; |
---|
| 1275 | UInt shift2D = shift1D + 1; |
---|
| 1276 | |
---|
| 1277 | // Get left and above reference column and row |
---|
| 1278 | for(k=0;k<blkSize+1;k++) |
---|
| 1279 | { |
---|
| 1280 | topRow[k] = pSrc[k-srcStride]; |
---|
| 1281 | leftColumn[k] = pSrc[k*srcStride-1]; |
---|
| 1282 | } |
---|
| 1283 | |
---|
| 1284 | // Prepare intermediate variables used in interpolation |
---|
| 1285 | bottomLeft = leftColumn[blkSize]; |
---|
| 1286 | topRight = topRow[blkSize]; |
---|
| 1287 | for (k=0;k<blkSize;k++) |
---|
| 1288 | { |
---|
| 1289 | bottomRow[k] = bottomLeft - topRow[k]; |
---|
| 1290 | rightColumn[k] = topRight - leftColumn[k]; |
---|
| 1291 | topRow[k] <<= shift1D; |
---|
| 1292 | leftColumn[k] <<= shift1D; |
---|
| 1293 | } |
---|
| 1294 | |
---|
| 1295 | // Generate prediction signal |
---|
| 1296 | for (k=0;k<blkSize;k++) |
---|
| 1297 | { |
---|
| 1298 | horPred = leftColumn[k] + offset2D; |
---|
| 1299 | for (l=0;l<blkSize;l++) |
---|
[2] | 1300 | { |
---|
[56] | 1301 | horPred += rightColumn[k]; |
---|
| 1302 | topRow[l] += bottomRow[l]; |
---|
| 1303 | rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); |
---|
[2] | 1304 | } |
---|
| 1305 | } |
---|
| 1306 | } |
---|
| 1307 | |
---|
[608] | 1308 | /** Function for filtering intra DC predictor. |
---|
| 1309 | * \param pSrc pointer to reconstructed sample array |
---|
| 1310 | * \param iSrcStride the stride of the reconstructed sample array |
---|
| 1311 | * \param rpDst reference to pointer for the prediction sample array |
---|
| 1312 | * \param iDstStride the stride of the prediction sample array |
---|
| 1313 | * \param iWidth the width of the block |
---|
| 1314 | * \param iHeight the height of the block |
---|
[56] | 1315 | * |
---|
[608] | 1316 | * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). |
---|
[56] | 1317 | */ |
---|
[608] | 1318 | Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight ) |
---|
[56] | 1319 | { |
---|
[608] | 1320 | Pel* pDst = rpDst; |
---|
| 1321 | Int x, y, iDstStride2, iSrcStride2; |
---|
[2] | 1322 | |
---|
[608] | 1323 | // boundary pixels processing |
---|
| 1324 | pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); |
---|
[56] | 1325 | |
---|
[608] | 1326 | for ( x = 1; x < iWidth; x++ ) |
---|
[2] | 1327 | { |
---|
[608] | 1328 | pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); |
---|
[2] | 1329 | } |
---|
| 1330 | |
---|
[608] | 1331 | for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride ) |
---|
[56] | 1332 | { |
---|
[608] | 1333 | pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); |
---|
[56] | 1334 | } |
---|
[2] | 1335 | |
---|
[608] | 1336 | return; |
---|
[2] | 1337 | } |
---|
[608] | 1338 | #if H_3D_IC |
---|
| 1339 | /** Function for deriving the position of first non-zero binary bit of a value |
---|
[56] | 1340 | * \param x input value |
---|
| 1341 | * |
---|
[608] | 1342 | * This function derives the position of first non-zero binary bit of a value |
---|
[56] | 1343 | */ |
---|
| 1344 | Int GetMSB( UInt x ) |
---|
| 1345 | { |
---|
| 1346 | Int iMSB = 0, bits = ( sizeof( Int ) << 3 ), y = 1; |
---|
| 1347 | |
---|
| 1348 | while( x > 1 ) |
---|
| 1349 | { |
---|
| 1350 | bits >>= 1; |
---|
| 1351 | y = x >> bits; |
---|
| 1352 | |
---|
| 1353 | if( y ) |
---|
| 1354 | { |
---|
| 1355 | x = y; |
---|
| 1356 | iMSB += bits; |
---|
| 1357 | } |
---|
| 1358 | } |
---|
| 1359 | |
---|
| 1360 | iMSB+=y; |
---|
| 1361 | |
---|
| 1362 | return iMSB; |
---|
| 1363 | } |
---|
| 1364 | |
---|
| 1365 | |
---|
[608] | 1366 | /** Function for deriving LM illumination compensation. |
---|
[56] | 1367 | */ |
---|
[608] | 1368 | Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType ) |
---|
[56] | 1369 | { |
---|
[608] | 1370 | TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec(); |
---|
| 1371 | Pel *pRec = NULL, *pRef = NULL; |
---|
| 1372 | UInt uiWidth, uiHeight, uiTmpPartIdx; |
---|
| 1373 | Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride(); |
---|
| 1374 | Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride(); |
---|
| 1375 | Int iCUPelX, iCUPelY, iRefX, iRefY, iRefOffset, iHor, iVer; |
---|
[56] | 1376 | |
---|
[608] | 1377 | iCUPelX = pcCU->getCUPelX() + g_auiRasterToPelX[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
| 1378 | iCUPelY = pcCU->getCUPelY() + g_auiRasterToPelY[g_auiZscanToRaster[pcCU->getZorderIdxInCU()]]; |
---|
| 1379 | iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 ); |
---|
| 1380 | iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 ); |
---|
| 1381 | iRefX = iCUPelX + iHor; |
---|
| 1382 | iRefY = iCUPelY + iVer; |
---|
| 1383 | if( eType != TEXT_LUMA ) |
---|
| 1384 | { |
---|
| 1385 | iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 ); |
---|
| 1386 | iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 ); |
---|
| 1387 | } |
---|
| 1388 | uiWidth = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 ) : ( pcCU->getWidth( 0 ) >> 1 ); |
---|
| 1389 | uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 ); |
---|
[56] | 1390 | |
---|
| 1391 | Int i, j, iCountShift = 0; |
---|
| 1392 | |
---|
| 1393 | // LLS parameters estimation --> |
---|
| 1394 | |
---|
| 1395 | Int x = 0, y = 0, xx = 0, xy = 0; |
---|
[608] | 1396 | Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12); |
---|
[56] | 1397 | |
---|
[608] | 1398 | if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelY > 0 && iRefY > 0 ) |
---|
[56] | 1399 | { |
---|
[608] | 1400 | iRefOffset = iHor + iVer * iRefStride - iRefStride; |
---|
| 1401 | if( eType == TEXT_LUMA ) |
---|
[56] | 1402 | { |
---|
[608] | 1403 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1404 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
[56] | 1405 | } |
---|
[608] | 1406 | else if( eType == TEXT_CHROMA_U ) |
---|
[56] | 1407 | { |
---|
[608] | 1408 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1409 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
[56] | 1410 | } |
---|
[608] | 1411 | else |
---|
| 1412 | { |
---|
| 1413 | assert( eType == TEXT_CHROMA_V ); |
---|
| 1414 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1415 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride; |
---|
| 1416 | } |
---|
[56] | 1417 | |
---|
[608] | 1418 | for( j = 0; j < uiWidth; j+=2 ) |
---|
[189] | 1419 | { |
---|
| 1420 | x += pRef[j]; |
---|
| 1421 | y += pRec[j]; |
---|
[608] | 1422 | xx += (pRef[j] * pRef[j])>>precShift; |
---|
| 1423 | xy += (pRef[j] * pRec[j])>>precShift; |
---|
[189] | 1424 | } |
---|
[608] | 1425 | iCountShift += g_aucConvertToBit[ uiWidth ] + 1; |
---|
[189] | 1426 | } |
---|
| 1427 | |
---|
| 1428 | |
---|
[608] | 1429 | if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) && iCUPelX > 0 && iRefX > 0 ) |
---|
[189] | 1430 | { |
---|
[608] | 1431 | iRefOffset = iHor + iVer * iRefStride - 1; |
---|
| 1432 | if( eType == TEXT_LUMA ) |
---|
| 1433 | { |
---|
| 1434 | pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1435 | pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
| 1436 | } |
---|
| 1437 | else if( eType == TEXT_CHROMA_U ) |
---|
| 1438 | { |
---|
| 1439 | pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1440 | pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
| 1441 | } |
---|
| 1442 | else |
---|
| 1443 | { |
---|
| 1444 | assert( eType == TEXT_CHROMA_V ); |
---|
| 1445 | pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset; |
---|
| 1446 | pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1; |
---|
| 1447 | } |
---|
| 1448 | |
---|
| 1449 | for( i = 0; i < uiHeight; i+=2 ) |
---|
[189] | 1450 | { |
---|
| 1451 | x += pRef[0]; |
---|
| 1452 | y += pRec[0]; |
---|
[655] | 1453 | |
---|
[608] | 1454 | xx += (pRef[0] * pRef[0])>>precShift; |
---|
| 1455 | xy += (pRef[0] * pRec[0])>>precShift; |
---|
| 1456 | |
---|
| 1457 | pRef += iRefStride*2; |
---|
| 1458 | pRec += iRecStride*2; |
---|
[189] | 1459 | } |
---|
[608] | 1460 | iCountShift += iCountShift > 0 ? 1 : ( g_aucConvertToBit[ uiWidth ] + 1 ); |
---|
[189] | 1461 | } |
---|
| 1462 | |
---|
[608] | 1463 | xy += xx >> IC_REG_COST_SHIFT; |
---|
| 1464 | xx += xx >> IC_REG_COST_SHIFT; |
---|
| 1465 | Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift); |
---|
| 1466 | Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift); |
---|
| 1467 | const Int iShift = IC_CONST_SHIFT; |
---|
| 1468 | { |
---|
[189] | 1469 | { |
---|
| 1470 | const Int iShiftA2 = 6; |
---|
| 1471 | const Int iAccuracyShift = 15; |
---|
| 1472 | |
---|
| 1473 | Int iScaleShiftA2 = 0; |
---|
| 1474 | Int iScaleShiftA1 = 0; |
---|
| 1475 | Int a1s = a1; |
---|
| 1476 | Int a2s = a2; |
---|
| 1477 | |
---|
[608] | 1478 | a1 = Clip3(0, 2*a2, a1); |
---|
| 1479 | iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2; |
---|
| 1480 | iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF; |
---|
[189] | 1481 | |
---|
| 1482 | if( iScaleShiftA1 < 0 ) |
---|
| 1483 | { |
---|
| 1484 | iScaleShiftA1 = 0; |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | if( iScaleShiftA2 < 0 ) |
---|
| 1488 | { |
---|
| 1489 | iScaleShiftA2 = 0; |
---|
| 1490 | } |
---|
| 1491 | |
---|
| 1492 | Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1; |
---|
| 1493 | |
---|
[608] | 1494 | |
---|
[189] | 1495 | a2s = a2 >> iScaleShiftA2; |
---|
| 1496 | |
---|
| 1497 | a1s = a1 >> iScaleShiftA1; |
---|
| 1498 | |
---|
[608] | 1499 | a = a1s * m_uiaShift[ a2s ]; |
---|
| 1500 | a = a >> iScaleShiftA; |
---|
[189] | 1501 | b = ( y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift; |
---|
| 1502 | } |
---|
| 1503 | } |
---|
| 1504 | } |
---|
[608] | 1505 | #endif |
---|
[189] | 1506 | |
---|
[608] | 1507 | #if H_3D_VSP |
---|
| 1508 | // not fully support iRatioTxtPerDepth* != 1 |
---|
| 1509 | Void TComPrediction::xGetVirtualDepth( TComDataCU *cu, TComPicYuv *picRefDepth, TComMv *mv, UInt partAddr, Int width, Int height, TComYuv *yuvDepth, Int ratioTxtPerDepthX, Int ratioTxtPerDepthY ) |
---|
[189] | 1510 | { |
---|
[608] | 1511 | Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE; |
---|
| 1512 | Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE; |
---|
[189] | 1513 | |
---|
[608] | 1514 | Int refDepStride = picRefDepth->getStride(); |
---|
[189] | 1515 | |
---|
[608] | 1516 | Int refDepOffset = ( (mv->getHor()+2) >> 2 ) + ( (mv->getVer()+2) >> 2 ) * refDepStride; |
---|
| 1517 | Pel *refDepth = picRefDepth->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ); |
---|
[189] | 1518 | |
---|
[608] | 1519 | if( ratioTxtPerDepthX!=1 || ratioTxtPerDepthY!=1 ) |
---|
[189] | 1520 | { |
---|
[608] | 1521 | Int posX, posY; |
---|
| 1522 | refDepth = picRefDepth->getLumaAddr( ); |
---|
| 1523 | cu->getPic()->getPicYuvRec()->getTopLeftSamplePos( cu->getAddr(), cu->getZorderIdxInCU() + partAddr, posX, posY ); // top-left position in texture |
---|
| 1524 | posX /= ratioTxtPerDepthX; // texture position -> depth postion |
---|
| 1525 | posY /= ratioTxtPerDepthY; |
---|
| 1526 | refDepOffset += posX + posY * refDepStride; |
---|
[189] | 1527 | |
---|
[608] | 1528 | width /= ratioTxtPerDepthX; // texture size -> depth size |
---|
| 1529 | height /= ratioTxtPerDepthY; |
---|
[189] | 1530 | } |
---|
| 1531 | |
---|
[608] | 1532 | refDepth += refDepOffset; |
---|
[189] | 1533 | |
---|
[608] | 1534 | Int depStride = yuvDepth->getStride(); |
---|
| 1535 | Pel *depth = yuvDepth->getLumaAddr(); |
---|
[189] | 1536 | |
---|
[608] | 1537 | if( width<8 || height<8 ) |
---|
| 1538 | { // no split |
---|
| 1539 | Int rightOffset = width - 1; |
---|
| 1540 | Int depStrideBlock = depStride * nTxtPerDepthY; |
---|
| 1541 | Pel *refDepthTop = refDepth; |
---|
| 1542 | Pel *refDepthBot = refDepthTop + (height-1)*refDepStride; |
---|
[189] | 1543 | |
---|
[608] | 1544 | Pel maxDepth = refDepthTop[0] > refDepthBot[0] ? refDepthTop[0] : refDepthBot[0]; |
---|
| 1545 | if( maxDepth < refDepthTop[rightOffset] ) { maxDepth = refDepthTop[rightOffset]; } |
---|
| 1546 | if( maxDepth < refDepthBot[rightOffset] ) { maxDepth = refDepthBot[rightOffset]; } |
---|
| 1547 | |
---|
| 1548 | for( Int sY=0; sY<height; sY+=nTxtPerDepthY ) |
---|
| 1549 | { |
---|
| 1550 | for( Int sX=0; sX<width; sX+=nTxtPerDepthX ) |
---|
| 1551 | { |
---|
| 1552 | depth[sX] = maxDepth; |
---|
| 1553 | } |
---|
| 1554 | depth += depStrideBlock; |
---|
| 1555 | } |
---|
[189] | 1556 | } |
---|
| 1557 | else |
---|
[608] | 1558 | { // split to 4x8, or 8x4 |
---|
| 1559 | Int blocksize = 8; |
---|
| 1560 | Int subblocksize = 4; |
---|
| 1561 | Int depStrideBlock = depStride * blocksize; |
---|
| 1562 | Pel *depthTmp = NULL; |
---|
| 1563 | Int depStrideTmp = depStride * nTxtPerDepthY; |
---|
| 1564 | Int offset[4] = { 0, subblocksize-1, subblocksize, blocksize-1 }; |
---|
| 1565 | Pel *refDepthTmp[4] = { NULL, NULL, NULL, NULL }; |
---|
| 1566 | Pel repDepth4x8[2] = {0, 0}; |
---|
| 1567 | Pel repDepth8x4[2] = {0, 0}; |
---|
[189] | 1568 | |
---|
[608] | 1569 | Int refDepStrideBlock = refDepStride * blocksize; |
---|
| 1570 | Int refDepStrideSubBlock = refDepStride * subblocksize; |
---|
| 1571 | |
---|
| 1572 | refDepthTmp[0] = refDepth; |
---|
| 1573 | refDepthTmp[2] = refDepthTmp[0] + refDepStrideSubBlock; |
---|
| 1574 | refDepthTmp[1] = refDepthTmp[2] - refDepStride; |
---|
| 1575 | refDepthTmp[3] = refDepthTmp[1] + refDepStrideSubBlock; |
---|
| 1576 | |
---|
| 1577 | for( Int y=0; y<height; y+=blocksize ) |
---|
[189] | 1578 | { |
---|
[608] | 1579 | for( Int x=0; x<width; x+=blocksize ) |
---|
| 1580 | { |
---|
| 1581 | Bool ULvsBR = false, URvsBL = false; |
---|
[189] | 1582 | |
---|
[608] | 1583 | ULvsBR = refDepthTmp[0][x+offset[0]] < refDepthTmp[3][x+offset[3]]; |
---|
| 1584 | URvsBL = refDepthTmp[0][x+offset[3]] < refDepthTmp[3][x+offset[0]]; |
---|
[189] | 1585 | |
---|
[608] | 1586 | if( ULvsBR ^ URvsBL ) |
---|
| 1587 | { // 4x8 |
---|
| 1588 | repDepth4x8[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[1]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[1]]; |
---|
| 1589 | if( repDepth4x8[0] < refDepthTmp[3][x+offset[0]] ) |
---|
| 1590 | { |
---|
| 1591 | repDepth4x8[0] = refDepthTmp[3][x+offset[0]]; |
---|
| 1592 | } |
---|
| 1593 | if( repDepth4x8[0] < refDepthTmp[3][x+offset[1]] ) |
---|
| 1594 | { |
---|
| 1595 | repDepth4x8[0] = refDepthTmp[3][x+offset[1]]; |
---|
| 1596 | } |
---|
| 1597 | repDepth4x8[1] = refDepthTmp[0][x+offset[2]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[2]] : refDepthTmp[0][x+offset[3]]; |
---|
| 1598 | if( repDepth4x8[1] < refDepthTmp[3][x+offset[2]] ) |
---|
| 1599 | { |
---|
| 1600 | repDepth4x8[1] = refDepthTmp[3][x+offset[2]]; |
---|
| 1601 | } |
---|
| 1602 | if( repDepth4x8[1] < refDepthTmp[3][x+offset[3]] ) |
---|
| 1603 | { |
---|
| 1604 | repDepth4x8[1] = refDepthTmp[3][x+offset[3]]; |
---|
| 1605 | } |
---|
[189] | 1606 | |
---|
[608] | 1607 | depthTmp = &depth[x]; |
---|
| 1608 | for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY ) |
---|
| 1609 | { |
---|
| 1610 | for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX ) |
---|
| 1611 | { |
---|
| 1612 | depthTmp[sX] = repDepth4x8[0]; |
---|
| 1613 | } |
---|
| 1614 | depthTmp += depStrideTmp; |
---|
| 1615 | } |
---|
| 1616 | depthTmp = &depth[x+subblocksize]; |
---|
| 1617 | for( Int sY=0; sY<blocksize; sY+=nTxtPerDepthY ) |
---|
| 1618 | { |
---|
| 1619 | for( Int sX=0; sX<subblocksize; sX+=nTxtPerDepthX ) |
---|
| 1620 | { |
---|
| 1621 | depthTmp[sX] = repDepth4x8[1]; |
---|
| 1622 | } |
---|
| 1623 | depthTmp += depStrideTmp; |
---|
| 1624 | } |
---|
| 1625 | } |
---|
| 1626 | else |
---|
| 1627 | { // 8x4 |
---|
| 1628 | repDepth8x4[0] = refDepthTmp[0][x+offset[0]] > refDepthTmp[0][x+offset[3]] ? refDepthTmp[0][x+offset[0]] : refDepthTmp[0][x+offset[3]]; |
---|
| 1629 | if( repDepth8x4[0] < refDepthTmp[1][x+offset[0]] ) |
---|
| 1630 | { |
---|
| 1631 | repDepth8x4[0] = refDepthTmp[1][x+offset[0]]; |
---|
| 1632 | } |
---|
| 1633 | if( repDepth8x4[0] < refDepthTmp[1][x+offset[3]] ) |
---|
| 1634 | { |
---|
| 1635 | repDepth8x4[0] = refDepthTmp[1][x+offset[3]]; |
---|
| 1636 | } |
---|
| 1637 | repDepth8x4[1] = refDepthTmp[2][x+offset[0]] > refDepthTmp[2][x+offset[3]] ? refDepthTmp[2][x+offset[0]] : refDepthTmp[2][x+offset[3]]; |
---|
| 1638 | if( repDepth8x4[1] < refDepthTmp[3][x+offset[0]] ) |
---|
| 1639 | { |
---|
| 1640 | repDepth8x4[1] = refDepthTmp[3][x+offset[0]]; |
---|
| 1641 | } |
---|
| 1642 | if( repDepth8x4[1] < refDepthTmp[3][x+offset[3]] ) |
---|
| 1643 | { |
---|
| 1644 | repDepth8x4[1] = refDepthTmp[3][x+offset[3]]; |
---|
| 1645 | } |
---|
| 1646 | |
---|
| 1647 | depthTmp = &depth[x]; |
---|
| 1648 | for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY ) |
---|
| 1649 | { |
---|
| 1650 | for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX ) |
---|
| 1651 | { |
---|
| 1652 | depthTmp[sX] = repDepth8x4[0]; |
---|
| 1653 | } |
---|
| 1654 | depthTmp += depStrideTmp; |
---|
| 1655 | } |
---|
| 1656 | for( Int sY=0; sY<subblocksize; sY+=nTxtPerDepthY ) |
---|
| 1657 | { |
---|
| 1658 | for( Int sX=0; sX<blocksize; sX+=nTxtPerDepthX ) |
---|
| 1659 | { |
---|
| 1660 | depthTmp[sX] = repDepth8x4[1]; |
---|
| 1661 | } |
---|
| 1662 | depthTmp += depStrideTmp; |
---|
| 1663 | } |
---|
| 1664 | } |
---|
[189] | 1665 | } |
---|
[608] | 1666 | refDepthTmp[0] += refDepStrideBlock; |
---|
| 1667 | refDepthTmp[1] += refDepStrideBlock; |
---|
| 1668 | refDepthTmp[2] += refDepStrideBlock; |
---|
| 1669 | refDepthTmp[3] += refDepStrideBlock; |
---|
| 1670 | depth += depStrideBlock; |
---|
| 1671 | } |
---|
| 1672 | } |
---|
[189] | 1673 | |
---|
| 1674 | |
---|
[608] | 1675 | } |
---|
| 1676 | |
---|
| 1677 | Void TComPrediction::xPredInterLumaBlkFromDM( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi ) |
---|
| 1678 | { |
---|
| 1679 | Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE; |
---|
| 1680 | Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE; |
---|
| 1681 | |
---|
| 1682 | Int refStride = picRef->getStride(); |
---|
| 1683 | Int dstStride = yuvDst->getStride(); |
---|
| 1684 | Int depStride = yuvDepth->getStride(); |
---|
| 1685 | Int refStrideBlock = refStride * nTxtPerDepthY; |
---|
| 1686 | Int dstStrideBlock = dstStride * nTxtPerDepthY; |
---|
| 1687 | Int depStrideBlock = depStride * nTxtPerDepthY; |
---|
| 1688 | |
---|
| 1689 | Pel *ref = picRef->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ); |
---|
| 1690 | Pel *dst = yuvDst->getLumaAddr(partAddr); |
---|
| 1691 | Pel *depth = yuvDepth->getLumaAddr(); |
---|
| 1692 | |
---|
| 1693 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
| 1694 | #if H_3D_VSP_CONSTRAINED |
---|
| 1695 | //get LUT based horizontal reference range |
---|
| 1696 | Int range = xGetConstrainedSize(width, height); |
---|
| 1697 | |
---|
| 1698 | // The minimum depth value |
---|
| 1699 | Int minRelativePos = MAX_INT; |
---|
| 1700 | Int maxRelativePos = MIN_INT; |
---|
| 1701 | |
---|
| 1702 | Pel* depthTemp, *depthInitial=depth; |
---|
| 1703 | for (Int yTxt = 0; yTxt < height; yTxt++) |
---|
| 1704 | { |
---|
| 1705 | for (Int xTxt = 0; xTxt < width; xTxt++) |
---|
| 1706 | { |
---|
| 1707 | if (depthPosX+xTxt < widthDepth) |
---|
[189] | 1708 | { |
---|
[608] | 1709 | depthTemp = depthInitial + xTxt; |
---|
[189] | 1710 | } |
---|
| 1711 | else |
---|
| 1712 | { |
---|
[608] | 1713 | depthTemp = depthInitial + (widthDepth - depthPosX - 1); |
---|
[189] | 1714 | } |
---|
| 1715 | |
---|
[608] | 1716 | Int disparity = shiftLUT[ *depthTemp ]; // << iShiftPrec; |
---|
| 1717 | Int disparityInt = disparity >> 2; |
---|
[189] | 1718 | |
---|
[608] | 1719 | if( disparity <= 0) |
---|
[189] | 1720 | { |
---|
[608] | 1721 | if (minRelativePos > disparityInt+xTxt) |
---|
| 1722 | { |
---|
| 1723 | minRelativePos = disparityInt+xTxt; |
---|
| 1724 | } |
---|
[189] | 1725 | } |
---|
| 1726 | else |
---|
| 1727 | { |
---|
[608] | 1728 | if (maxRelativePos < disparityInt+xTxt) |
---|
| 1729 | { |
---|
| 1730 | maxRelativePos = disparityInt+xTxt; |
---|
| 1731 | } |
---|
[189] | 1732 | } |
---|
| 1733 | } |
---|
[608] | 1734 | if (depthPosY+yTxt < heightDepth) |
---|
| 1735 | { |
---|
| 1736 | depthInitial = depthInitial + depStride; |
---|
| 1737 | } |
---|
| 1738 | } |
---|
[56] | 1739 | |
---|
[608] | 1740 | Int disparity_tmp = shiftLUT[ *depth ]; // << iShiftPrec; |
---|
| 1741 | if (disparity_tmp <= 0) |
---|
[56] | 1742 | { |
---|
[608] | 1743 | maxRelativePos = minRelativePos + range -1 ; |
---|
[56] | 1744 | } |
---|
[608] | 1745 | else |
---|
[56] | 1746 | { |
---|
[608] | 1747 | minRelativePos = maxRelativePos - range +1 ; |
---|
[56] | 1748 | } |
---|
[608] | 1749 | #endif |
---|
| 1750 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
[56] | 1751 | |
---|
[608] | 1752 | TComMv dv(0, 0); |
---|
[56] | 1753 | |
---|
[608] | 1754 | for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY ) |
---|
| 1755 | { |
---|
| 1756 | for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX ) |
---|
| 1757 | { |
---|
| 1758 | Pel repDepth = depth[ xTxt ]; |
---|
| 1759 | assert( repDepth >= 0 && repDepth <= 255 ); |
---|
| 1760 | |
---|
| 1761 | Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec ?? |
---|
| 1762 | Int xFrac = disparity & 0x3; |
---|
| 1763 | |
---|
| 1764 | dv.setHor( disparity ); |
---|
| 1765 | cu->clipMv( dv ); |
---|
| 1766 | |
---|
| 1767 | Int refOffset = xTxt + (dv.getHor() >> 2); |
---|
| 1768 | |
---|
| 1769 | #if H_3D_VSP_CONSTRAINED |
---|
| 1770 | if(refOffset<minRelativePos || refOffset>maxRelativePos) |
---|
| 1771 | { |
---|
| 1772 | xFrac = 0; |
---|
| 1773 | } |
---|
| 1774 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
[5] | 1775 | #endif |
---|
[608] | 1776 | |
---|
| 1777 | assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 ); |
---|
| 1778 | m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi ); |
---|
| 1779 | } |
---|
| 1780 | ref += refStrideBlock; |
---|
| 1781 | dst += dstStrideBlock; |
---|
| 1782 | depth += depStrideBlock; |
---|
[443] | 1783 | } |
---|
| 1784 | |
---|
| 1785 | } |
---|
[608] | 1786 | |
---|
| 1787 | Void TComPrediction::xPredInterChromaBlkFromDM ( TComDataCU *cu, TComPicYuv *picRef, TComYuv *yuvDepth, Int* shiftLUT, TComMv *mv, UInt partAddr, Int width, Int height, Bool isDepth, TComYuv *&yuvDst, Bool isBi ) |
---|
| 1788 | { |
---|
| 1789 | #if (H_3D_VSP_BLOCKSIZE==1) |
---|
| 1790 | Int nTxtPerDepthX = 1; |
---|
| 1791 | Int nTxtPerDepthY = 1; |
---|
[443] | 1792 | #else |
---|
[608] | 1793 | Int nTxtPerDepthX = H_3D_VSP_BLOCKSIZE >> 1; |
---|
| 1794 | Int nTxtPerDepthY = H_3D_VSP_BLOCKSIZE >> 1; |
---|
| 1795 | #endif |
---|
[2] | 1796 | |
---|
[608] | 1797 | Int refStride = picRef->getCStride(); |
---|
| 1798 | Int dstStride = yuvDst->getCStride(); |
---|
| 1799 | Int depStride = yuvDepth->getStride(); |
---|
| 1800 | Int refStrideBlock = refStride * nTxtPerDepthY; |
---|
| 1801 | Int dstStrideBlock = dstStride * nTxtPerDepthY; |
---|
| 1802 | Int depStrideBlock = depStride * (nTxtPerDepthY<<1); |
---|
[2] | 1803 | |
---|
[608] | 1804 | Pel *refCb = picRef->getCbAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ); |
---|
| 1805 | Pel *refCr = picRef->getCrAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ); |
---|
| 1806 | Pel *dstCb = yuvDst->getCbAddr(partAddr); |
---|
| 1807 | Pel *dstCr = yuvDst->getCrAddr(partAddr); |
---|
| 1808 | Pel *depth = yuvDepth->getLumaAddr(); |
---|
[56] | 1809 | |
---|
[608] | 1810 | #if H_3D_VSP_BLOCKSIZE == 1 |
---|
| 1811 | #if H_3D_VSP_CONSTRAINED |
---|
| 1812 | //get LUT based horizontal reference range |
---|
| 1813 | Int range = xGetConstrainedSize(width, height, false); |
---|
[296] | 1814 | |
---|
[608] | 1815 | // The minimum depth value |
---|
| 1816 | Int minRelativePos = MAX_INT; |
---|
| 1817 | Int maxRelativePos = MIN_INT; |
---|
| 1818 | |
---|
| 1819 | Int depthTmp; |
---|
| 1820 | for (Int yTxt=0; yTxt<height; yTxt++) |
---|
[56] | 1821 | { |
---|
[608] | 1822 | for (Int xTxt=0; xTxt<width; xTxt++) |
---|
[56] | 1823 | { |
---|
[608] | 1824 | depthTmp = m_pDepthBlock[xTxt+yTxt*width]; |
---|
| 1825 | Int disparity = shiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
| 1826 | Int disparityInt = disparity >> 3;//in chroma resolution |
---|
| 1827 | |
---|
| 1828 | if (disparityInt < 0) |
---|
[56] | 1829 | { |
---|
[608] | 1830 | if (minRelativePos > disparityInt+xTxt) |
---|
| 1831 | { |
---|
| 1832 | minRelativePos = disparityInt+xTxt; |
---|
| 1833 | } |
---|
[56] | 1834 | } |
---|
| 1835 | else |
---|
| 1836 | { |
---|
[608] | 1837 | if (maxRelativePos < disparityInt+xTxt) |
---|
| 1838 | { |
---|
| 1839 | maxRelativePos = disparityInt+xTxt; |
---|
| 1840 | } |
---|
[56] | 1841 | } |
---|
| 1842 | } |
---|
| 1843 | } |
---|
| 1844 | |
---|
[608] | 1845 | depthTmp = m_pDepthBlock[0]; |
---|
| 1846 | Int disparity_tmp = shiftLUT[ depthTmp ]; // << iShiftPrec; |
---|
| 1847 | if ( disparity_tmp < 0 ) |
---|
[56] | 1848 | { |
---|
[608] | 1849 | maxRelativePos = minRelativePos + range - 1; |
---|
[56] | 1850 | } |
---|
[608] | 1851 | else |
---|
[56] | 1852 | { |
---|
[608] | 1853 | minRelativePos = maxRelativePos - range + 1; |
---|
[56] | 1854 | } |
---|
[2] | 1855 | |
---|
[608] | 1856 | #endif // H_3D_VSP_CONSTRAINED |
---|
| 1857 | #endif // H_3D_VSP_BLOCKSIZE == 1 |
---|
| 1858 | |
---|
| 1859 | TComMv dv(0, 0); |
---|
| 1860 | // luma size -> chroma size |
---|
| 1861 | height >>= 1; |
---|
| 1862 | width >>= 1; |
---|
| 1863 | |
---|
| 1864 | for ( Int yTxt = 0; yTxt < height; yTxt += nTxtPerDepthY ) |
---|
[5] | 1865 | { |
---|
[608] | 1866 | for ( Int xTxt = 0; xTxt < width; xTxt += nTxtPerDepthX ) |
---|
[5] | 1867 | { |
---|
[608] | 1868 | Pel repDepth = depth[ xTxt<<1 ]; |
---|
| 1869 | assert( repDepth >= 0 && repDepth <= 255 ); |
---|
| 1870 | |
---|
| 1871 | Int disparity = shiftLUT[ repDepth ]; // remove << iShiftPrec; |
---|
| 1872 | Int xFrac = disparity & 0x7; |
---|
| 1873 | |
---|
| 1874 | dv.setHor( disparity ); |
---|
| 1875 | cu->clipMv( dv ); |
---|
| 1876 | |
---|
| 1877 | Int refOffset = xTxt + (dv.getHor() >> 3); |
---|
| 1878 | |
---|
| 1879 | #if H_3D_VSP_CONSTRAINED |
---|
| 1880 | if(refOffset<minRelativePos || refOffset>maxRelativePos) |
---|
[5] | 1881 | { |
---|
[608] | 1882 | xFrac = 0; |
---|
[5] | 1883 | } |
---|
[608] | 1884 | refOffset = Clip3(minRelativePos, maxRelativePos, refOffset); |
---|
| 1885 | #endif |
---|
| 1886 | |
---|
| 1887 | assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 ); |
---|
| 1888 | assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 ); |
---|
| 1889 | |
---|
| 1890 | m_if.filterHorChroma( &refCb[refOffset], refStride, &dstCb[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi ); |
---|
| 1891 | m_if.filterHorChroma( &refCr[refOffset], refStride, &dstCr[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !isBi ); |
---|
[5] | 1892 | } |
---|
[608] | 1893 | refCb += refStrideBlock; |
---|
| 1894 | refCr += refStrideBlock; |
---|
| 1895 | dstCb += dstStrideBlock; |
---|
| 1896 | dstCr += dstStrideBlock; |
---|
| 1897 | depth += depStrideBlock; |
---|
[5] | 1898 | } |
---|
| 1899 | } |
---|
[2] | 1900 | |
---|
[5] | 1901 | |
---|
[608] | 1902 | #if H_3D_VSP_CONSTRAINED |
---|
| 1903 | Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma) |
---|
[56] | 1904 | { |
---|
[608] | 1905 | Int iSize = 0; |
---|
| 1906 | if (bLuma) |
---|
[2] | 1907 | { |
---|
[608] | 1908 | Int iArea = (nPbW+7) * (nPbH+7); |
---|
| 1909 | Int iAlpha = iArea / nPbH - nPbW - 7; |
---|
| 1910 | iSize = iAlpha + nPbW; |
---|
[2] | 1911 | } |
---|
[608] | 1912 | else // chroma |
---|
| 1913 | { |
---|
| 1914 | Int iArea = (nPbW+2) * (nPbH+2); |
---|
| 1915 | Int iAlpha = iArea / nPbH - nPbW - 4; |
---|
| 1916 | iSize = iAlpha + nPbW; |
---|
| 1917 | } |
---|
| 1918 | return iSize; |
---|
[2] | 1919 | } |
---|
[608] | 1920 | #endif // H_3D_VSP_CONSTRAINED |
---|
[2] | 1921 | |
---|
[608] | 1922 | #endif // H_3D_VSP |
---|
| 1923 | |
---|
| 1924 | #if H_3D_DIM |
---|
| 1925 | Void TComPrediction::xPredBiSegDCs( Int* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& predDC1, Pel& predDC2 ) |
---|
[2] | 1926 | { |
---|
[608] | 1927 | Int refDC1, refDC2; |
---|
| 1928 | const Int iTR = ( patternStride - 1 ) - srcStride; |
---|
| 1929 | const Int iTM = ( ( patternStride - 1 ) >> 1 ) - srcStride; |
---|
| 1930 | const Int iLB = ( patternStride - 1 ) * srcStride - 1; |
---|
| 1931 | const Int iLM = ( ( patternStride - 1 ) >> 1 ) * srcStride - 1; |
---|
[2] | 1932 | |
---|
[608] | 1933 | Bool bL = ( biSegPattern[0] != biSegPattern[(patternStride-1)*patternStride] ); |
---|
| 1934 | Bool bT = ( biSegPattern[0] != biSegPattern[(patternStride-1)] ); |
---|
| 1935 | |
---|
| 1936 | if( bL == bT ) |
---|
[56] | 1937 | { |
---|
[608] | 1938 | refDC1 = bL ? ( ptrSrc[iTR] + ptrSrc[iLB] )>>1 : 1<<( g_bitDepthY - 1 ); |
---|
| 1939 | refDC2 = ( ptrSrc[ -1] + ptrSrc[-(Int)srcStride] )>>1; |
---|
[56] | 1940 | } |
---|
| 1941 | else |
---|
| 1942 | { |
---|
[608] | 1943 | refDC1 = bL ? ptrSrc[iLB] : ptrSrc[iTR]; |
---|
| 1944 | refDC2 = bL ? ptrSrc[iTM] : ptrSrc[iLM]; |
---|
[56] | 1945 | } |
---|
| 1946 | |
---|
[608] | 1947 | predDC1 = biSegPattern[0] ? refDC1 : refDC2; |
---|
| 1948 | predDC2 = biSegPattern[0] ? refDC2 : refDC1; |
---|
[2] | 1949 | } |
---|
| 1950 | |
---|
[608] | 1951 | Void TComPrediction::xAssignBiSegDCs( Pel* ptrDst, UInt dstStride, Bool* biSegPattern, Int patternStride, Pel valDC1, Pel valDC2 ) |
---|
[56] | 1952 | { |
---|
[608] | 1953 | if( dstStride == patternStride ) |
---|
| 1954 | { |
---|
| 1955 | for( UInt k = 0; k < (patternStride * patternStride); k++ ) |
---|
| 1956 | { |
---|
| 1957 | if( true == biSegPattern[k] ) { ptrDst[k] = valDC2; } |
---|
| 1958 | else { ptrDst[k] = valDC1; } |
---|
| 1959 | } |
---|
[443] | 1960 | } |
---|
[608] | 1961 | else |
---|
| 1962 | { |
---|
| 1963 | Pel* piTemp = ptrDst; |
---|
| 1964 | for( UInt uiY = 0; uiY < patternStride; uiY++ ) |
---|
| 1965 | { |
---|
| 1966 | for( UInt uiX = 0; uiX < patternStride; uiX++ ) |
---|
| 1967 | { |
---|
| 1968 | if( true == biSegPattern[uiX] ) { piTemp[uiX] = valDC2; } |
---|
| 1969 | else { piTemp[uiX] = valDC1; } |
---|
| 1970 | } |
---|
| 1971 | piTemp += dstStride; |
---|
| 1972 | biSegPattern += patternStride; |
---|
| 1973 | } |
---|
[443] | 1974 | } |
---|
[56] | 1975 | } |
---|
| 1976 | |
---|
[608] | 1977 | #if H_3D_DIM_DMM |
---|
| 1978 | UInt TComPrediction::xPredWedgeFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt intraTabIdx ) |
---|
[56] | 1979 | { |
---|
[608] | 1980 | TComPic* pcPicTex = pcCU->getSlice()->getTexturePic(); |
---|
| 1981 | assert( pcPicTex != NULL ); |
---|
| 1982 | TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr()); |
---|
| 1983 | UInt uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPartIdx; |
---|
| 1984 | Int uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255; |
---|
[56] | 1985 | |
---|
[622] | 1986 | assert( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 ); |
---|
| 1987 | return g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]][uiColTexIntraDir-2].at(intraTabIdx); |
---|
[56] | 1988 | } |
---|
| 1989 | |
---|
[608] | 1990 | Void TComPrediction::xPredContourFromTex( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, TComWedgelet* pcContourWedge ) |
---|
[56] | 1991 | { |
---|
[608] | 1992 | pcContourWedge->clear(); |
---|
[56] | 1993 | |
---|
[608] | 1994 | // get copy of co-located texture luma block |
---|
| 1995 | TComYuv cTempYuv; |
---|
| 1996 | cTempYuv.create( uiWidth, uiHeight ); |
---|
| 1997 | cTempYuv.clear(); |
---|
| 1998 | Pel* piRefBlkY = cTempYuv.getLumaAddr(); |
---|
| 1999 | xCopyTextureLumaBlock( pcCU, uiAbsPartIdx, piRefBlkY, uiWidth, uiHeight ); |
---|
| 2000 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
[56] | 2001 | |
---|
[608] | 2002 | // find contour for texture luma block |
---|
| 2003 | UInt iDC = 0; |
---|
| 2004 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
| 2005 | { |
---|
| 2006 | iDC += piRefBlkY[k]; |
---|
| 2007 | } |
---|
| 2008 | |
---|
[655] | 2009 | Int cuMaxLog2Size = g_aucConvertToBit[g_uiMaxCUWidth]+2; // |
---|
| 2010 | iDC = iDC >> (cuMaxLog2Size - pcCU->getDepth(0))*2; // iDC /= (uiWidth*uiHeight); |
---|
| 2011 | |
---|
[608] | 2012 | piRefBlkY = cTempYuv.getLumaAddr(); |
---|
[56] | 2013 | |
---|
[608] | 2014 | Bool* pabContourPattern = pcContourWedge->getPattern(); |
---|
| 2015 | for( UInt k = 0; k < (uiWidth*uiHeight); k++ ) |
---|
[443] | 2016 | { |
---|
[608] | 2017 | pabContourPattern[k] = (piRefBlkY[k] > iDC) ? true : false; |
---|
[443] | 2018 | } |
---|
[608] | 2019 | |
---|
| 2020 | cTempYuv.destroy(); |
---|
[56] | 2021 | } |
---|
| 2022 | |
---|
[608] | 2023 | |
---|
| 2024 | Void TComPrediction::xCopyTextureLumaBlock( TComDataCU* pcCU, UInt uiAbsPartIdx, Pel* piDestBlockY, UInt uiWidth, UInt uiHeight ) |
---|
[56] | 2025 | { |
---|
[608] | 2026 | TComPicYuv* pcPicYuvRef = pcCU->getSlice()->getTexturePic()->getPicYuvRec(); |
---|
| 2027 | assert( pcPicYuvRef != NULL ); |
---|
| 2028 | Int iRefStride = pcPicYuvRef->getStride(); |
---|
| 2029 | Pel* piRefY = pcPicYuvRef->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() + uiAbsPartIdx ); |
---|
[56] | 2030 | |
---|
[608] | 2031 | for ( Int y = 0; y < uiHeight; y++ ) |
---|
[56] | 2032 | { |
---|
[608] | 2033 | ::memcpy(piDestBlockY, piRefY, sizeof(Pel)*uiWidth); |
---|
| 2034 | piDestBlockY += uiWidth; |
---|
| 2035 | piRefY += iRefStride; |
---|
[56] | 2036 | } |
---|
| 2037 | } |
---|
[655] | 2038 | #endif |
---|
[56] | 2039 | |
---|
[608] | 2040 | #if H_3D_DIM_RBC |
---|
| 2041 | Void TComPrediction::xDeltaDCQuantScaleUp( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
| 2042 | { |
---|
| 2043 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
| 2044 | UInt uiAbs = abs( rDeltaDC ); |
---|
[2] | 2045 | |
---|
[608] | 2046 | Int iQp = pcCU->getQP(0); |
---|
| 2047 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
| 2048 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
| 2049 | |
---|
| 2050 | rDeltaDC = iSign * roftoi( uiAbs * dStepSize ); |
---|
| 2051 | return; |
---|
[2] | 2052 | } |
---|
| 2053 | |
---|
[608] | 2054 | Void TComPrediction::xDeltaDCQuantScaleDown( TComDataCU* pcCU, Pel& rDeltaDC ) |
---|
[2] | 2055 | { |
---|
[608] | 2056 | Int iSign = rDeltaDC < 0 ? -1 : 1; |
---|
| 2057 | UInt uiAbs = abs( rDeltaDC ); |
---|
| 2058 | |
---|
| 2059 | Int iQp = pcCU->getQP(0); |
---|
| 2060 | Double dMax = (Double)( 1<<( g_bitDepthY - 1 ) ); |
---|
| 2061 | Double dStepSize = Clip3( 1.0, dMax, pow( 2.0, iQp/10.0 - 2.0 ) ); |
---|
| 2062 | |
---|
| 2063 | rDeltaDC = iSign * roftoi( uiAbs / dStepSize ); |
---|
| 2064 | return; |
---|
| 2065 | } |
---|
| 2066 | #endif |
---|
| 2067 | #if H_3D_DIM_SDC |
---|
| 2068 | Void TComPrediction::analyzeSegmentsSDC( Pel* pOrig, UInt uiStride, UInt uiSize, Pel* rpSegMeans, UInt uiNumSegments, Bool* pMask, UInt uiMaskStride |
---|
| 2069 | ,UInt uiIntraMode |
---|
| 2070 | ,Bool orgDC |
---|
| 2071 | ) |
---|
| 2072 | { |
---|
| 2073 | Int iSumDepth[2]; |
---|
| 2074 | memset(iSumDepth, 0, sizeof(Int)*2); |
---|
| 2075 | Int iSumPix[2]; |
---|
| 2076 | memset(iSumPix, 0, sizeof(Int)*2); |
---|
| 2077 | |
---|
| 2078 | if (orgDC == false) |
---|
[2] | 2079 | { |
---|
[608] | 2080 | if ( getDimType(uiIntraMode) == DMM1_IDX ) |
---|
| 2081 | { |
---|
| 2082 | UChar ucSegmentLT = pMask[0]; |
---|
| 2083 | UChar ucSegmentRT = pMask[uiSize-1]; |
---|
| 2084 | UChar ucSegmentLB = pMask[uiMaskStride * (uiSize-1)]; |
---|
| 2085 | UChar ucSegmentRB = pMask[uiMaskStride * (uiSize-1) + (uiSize-1)]; |
---|
| 2086 | |
---|
| 2087 | rpSegMeans[ucSegmentLT] = pOrig[0]; |
---|
| 2088 | rpSegMeans[ucSegmentRT] = pOrig[uiSize-1]; |
---|
| 2089 | rpSegMeans[ucSegmentLB] = pOrig[uiStride * (uiSize-1) ]; |
---|
| 2090 | rpSegMeans[ucSegmentRB] = pOrig[uiStride * (uiSize-1) + (uiSize-1) ]; |
---|
| 2091 | } |
---|
| 2092 | else if (uiIntraMode == PLANAR_IDX) |
---|
| 2093 | { |
---|
| 2094 | Pel* pLeftTop = pOrig; |
---|
| 2095 | Pel* pRightTop = pOrig + (uiSize-1); |
---|
| 2096 | Pel* pLeftBottom = (pOrig+ (uiStride*(uiSize-1))); |
---|
| 2097 | Pel* pRightBottom = (pOrig+ (uiStride*(uiSize-1)) + (uiSize-1)); |
---|
| 2098 | |
---|
| 2099 | rpSegMeans[0] = (*pLeftTop + *pRightTop + *pLeftBottom + *pRightBottom + 2)>>2; |
---|
| 2100 | } |
---|
| 2101 | return; |
---|
[2] | 2102 | } |
---|
[608] | 2103 | |
---|
| 2104 | Int subSamplePix; |
---|
| 2105 | if ( uiSize == 64 || uiSize == 32 ) |
---|
[2] | 2106 | { |
---|
[608] | 2107 | subSamplePix = 2; |
---|
[2] | 2108 | } |
---|
[608] | 2109 | else |
---|
[2] | 2110 | { |
---|
[608] | 2111 | subSamplePix = 1; |
---|
[2] | 2112 | } |
---|
[608] | 2113 | for (Int y=0; y<uiSize; y+=subSamplePix) |
---|
[2] | 2114 | { |
---|
[608] | 2115 | for (Int x=0; x<uiSize; x+=subSamplePix) |
---|
| 2116 | { |
---|
| 2117 | UChar ucSegment = pMask?(UChar)pMask[x]:0; |
---|
| 2118 | assert( ucSegment < uiNumSegments ); |
---|
| 2119 | |
---|
| 2120 | iSumDepth[ucSegment] += pOrig[x]; |
---|
| 2121 | iSumPix[ucSegment] += 1; |
---|
| 2122 | } |
---|
| 2123 | |
---|
| 2124 | pOrig += uiStride*subSamplePix; |
---|
| 2125 | pMask += uiMaskStride*subSamplePix; |
---|
[2] | 2126 | } |
---|
[608] | 2127 | |
---|
| 2128 | // compute mean for each segment |
---|
| 2129 | for( UChar ucSeg = 0; ucSeg < uiNumSegments; ucSeg++ ) |
---|
[2] | 2130 | { |
---|
[608] | 2131 | if( iSumPix[ucSeg] > 0 ) |
---|
| 2132 | rpSegMeans[ucSeg] = iSumDepth[ucSeg] / iSumPix[ucSeg]; |
---|
| 2133 | else |
---|
| 2134 | rpSegMeans[ucSeg] = 0; // this happens for zero-segments |
---|
[2] | 2135 | } |
---|
| 2136 | } |
---|
[608] | 2137 | #endif // H_3D_DIM_SDC |
---|
| 2138 | #endif |
---|
[56] | 2139 | //! \} |
---|