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