[313] | 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 |
---|
[494] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[593] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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 TComRdCost.cpp |
---|
| 35 | \brief RD cost computation class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <math.h> |
---|
| 39 | #include <assert.h> |
---|
| 40 | #include "TComRom.h" |
---|
| 41 | #include "TComRdCost.h" |
---|
| 42 | |
---|
| 43 | //! \ingroup TLibCommon |
---|
| 44 | //! \{ |
---|
| 45 | |
---|
| 46 | TComRdCost::TComRdCost() |
---|
| 47 | { |
---|
| 48 | init(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | TComRdCost::~TComRdCost() |
---|
| 52 | { |
---|
| 53 | #if !FIX203 |
---|
| 54 | xUninit(); |
---|
| 55 | #endif |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // Calculate RD functions |
---|
| 59 | Double TComRdCost::calcRdCost( UInt uiBits, UInt uiDistortion, Bool bFlag, DFunc eDFunc ) |
---|
| 60 | { |
---|
| 61 | Double dRdCost = 0.0; |
---|
| 62 | Double dLambda = 0.0; |
---|
[494] | 63 | |
---|
[313] | 64 | switch ( eDFunc ) |
---|
| 65 | { |
---|
| 66 | case DF_SSE: |
---|
| 67 | assert(0); |
---|
| 68 | break; |
---|
| 69 | case DF_SAD: |
---|
| 70 | dLambda = (Double)m_uiLambdaMotionSAD; |
---|
| 71 | break; |
---|
| 72 | case DF_DEFAULT: |
---|
| 73 | dLambda = m_dLambda; |
---|
| 74 | break; |
---|
| 75 | case DF_SSE_FRAME: |
---|
| 76 | dLambda = m_dFrameLambda; |
---|
| 77 | break; |
---|
| 78 | default: |
---|
| 79 | assert (0); |
---|
| 80 | break; |
---|
| 81 | } |
---|
[494] | 82 | |
---|
[313] | 83 | if (bFlag) |
---|
| 84 | { |
---|
| 85 | // Intra8x8, Intra4x4 Block only... |
---|
| 86 | #if SEQUENCE_LEVEL_LOSSLESS |
---|
| 87 | dRdCost = (Double)(uiBits); |
---|
| 88 | #else |
---|
| 89 | dRdCost = (((Double)uiDistortion) + ((Double)uiBits * dLambda)); |
---|
| 90 | #endif |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | if (eDFunc == DF_SAD) |
---|
| 95 | { |
---|
| 96 | dRdCost = ((Double)uiDistortion + (Double)((Int)(uiBits * dLambda+.5)>>16)); |
---|
| 97 | dRdCost = (Double)(UInt)floor(dRdCost); |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | #if SEQUENCE_LEVEL_LOSSLESS |
---|
| 102 | dRdCost = (Double)(uiBits); |
---|
| 103 | #else |
---|
| 104 | dRdCost = ((Double)uiDistortion + (Double)((Int)(uiBits * dLambda+.5))); |
---|
| 105 | dRdCost = (Double)(UInt)floor(dRdCost); |
---|
| 106 | #endif |
---|
| 107 | } |
---|
| 108 | } |
---|
[494] | 109 | |
---|
[313] | 110 | return dRdCost; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | Double TComRdCost::calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag, DFunc eDFunc ) |
---|
| 114 | { |
---|
| 115 | Double dRdCost = 0.0; |
---|
| 116 | Double dLambda = 0.0; |
---|
[494] | 117 | |
---|
[313] | 118 | switch ( eDFunc ) |
---|
| 119 | { |
---|
| 120 | case DF_SSE: |
---|
| 121 | assert(0); |
---|
| 122 | break; |
---|
| 123 | case DF_SAD: |
---|
| 124 | dLambda = (Double)m_uiLambdaMotionSAD; |
---|
| 125 | break; |
---|
| 126 | case DF_DEFAULT: |
---|
| 127 | dLambda = m_dLambda; |
---|
| 128 | break; |
---|
| 129 | case DF_SSE_FRAME: |
---|
| 130 | dLambda = m_dFrameLambda; |
---|
| 131 | break; |
---|
| 132 | default: |
---|
| 133 | assert (0); |
---|
| 134 | break; |
---|
| 135 | } |
---|
[494] | 136 | |
---|
[313] | 137 | if (bFlag) |
---|
| 138 | { |
---|
| 139 | // Intra8x8, Intra4x4 Block only... |
---|
| 140 | #if SEQUENCE_LEVEL_LOSSLESS |
---|
| 141 | dRdCost = (Double)(uiBits); |
---|
| 142 | #else |
---|
| 143 | dRdCost = (((Double)(Int64)uiDistortion) + ((Double)(Int64)uiBits * dLambda)); |
---|
| 144 | #endif |
---|
| 145 | } |
---|
| 146 | else |
---|
| 147 | { |
---|
| 148 | if (eDFunc == DF_SAD) |
---|
| 149 | { |
---|
| 150 | dRdCost = ((Double)(Int64)uiDistortion + (Double)((Int)((Int64)uiBits * dLambda+.5)>>16)); |
---|
| 151 | dRdCost = (Double)(UInt)floor(dRdCost); |
---|
| 152 | } |
---|
| 153 | else |
---|
| 154 | { |
---|
| 155 | #if SEQUENCE_LEVEL_LOSSLESS |
---|
| 156 | dRdCost = (Double)(uiBits); |
---|
| 157 | #else |
---|
| 158 | dRdCost = ((Double)(Int64)uiDistortion + (Double)((Int)((Int64)uiBits * dLambda+.5))); |
---|
| 159 | dRdCost = (Double)(UInt)floor(dRdCost); |
---|
| 160 | #endif |
---|
| 161 | } |
---|
| 162 | } |
---|
[494] | 163 | |
---|
[313] | 164 | return dRdCost; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | Void TComRdCost::setLambda( Double dLambda ) |
---|
| 168 | { |
---|
| 169 | m_dLambda = dLambda; |
---|
| 170 | m_sqrtLambda = sqrt(m_dLambda); |
---|
| 171 | m_uiLambdaMotionSAD = (UInt)floor(65536.0 * m_sqrtLambda); |
---|
| 172 | m_uiLambdaMotionSSE = (UInt)floor(65536.0 * m_dLambda ); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | // Initalize Function Pointer by [eDFunc] |
---|
| 177 | Void TComRdCost::init() |
---|
| 178 | { |
---|
| 179 | m_afpDistortFunc[0] = NULL; // for DF_DEFAULT |
---|
[494] | 180 | |
---|
[313] | 181 | m_afpDistortFunc[1] = TComRdCost::xGetSSE; |
---|
| 182 | m_afpDistortFunc[2] = TComRdCost::xGetSSE4; |
---|
| 183 | m_afpDistortFunc[3] = TComRdCost::xGetSSE8; |
---|
| 184 | m_afpDistortFunc[4] = TComRdCost::xGetSSE16; |
---|
| 185 | m_afpDistortFunc[5] = TComRdCost::xGetSSE32; |
---|
| 186 | m_afpDistortFunc[6] = TComRdCost::xGetSSE64; |
---|
| 187 | m_afpDistortFunc[7] = TComRdCost::xGetSSE16N; |
---|
[494] | 188 | |
---|
[313] | 189 | m_afpDistortFunc[8] = TComRdCost::xGetSAD; |
---|
| 190 | m_afpDistortFunc[9] = TComRdCost::xGetSAD4; |
---|
| 191 | m_afpDistortFunc[10] = TComRdCost::xGetSAD8; |
---|
| 192 | m_afpDistortFunc[11] = TComRdCost::xGetSAD16; |
---|
| 193 | m_afpDistortFunc[12] = TComRdCost::xGetSAD32; |
---|
| 194 | m_afpDistortFunc[13] = TComRdCost::xGetSAD64; |
---|
| 195 | m_afpDistortFunc[14] = TComRdCost::xGetSAD16N; |
---|
[494] | 196 | |
---|
[313] | 197 | m_afpDistortFunc[15] = TComRdCost::xGetSAD; |
---|
| 198 | m_afpDistortFunc[16] = TComRdCost::xGetSAD4; |
---|
| 199 | m_afpDistortFunc[17] = TComRdCost::xGetSAD8; |
---|
| 200 | m_afpDistortFunc[18] = TComRdCost::xGetSAD16; |
---|
| 201 | m_afpDistortFunc[19] = TComRdCost::xGetSAD32; |
---|
| 202 | m_afpDistortFunc[20] = TComRdCost::xGetSAD64; |
---|
| 203 | m_afpDistortFunc[21] = TComRdCost::xGetSAD16N; |
---|
[494] | 204 | |
---|
[313] | 205 | #if AMP_SAD |
---|
| 206 | m_afpDistortFunc[43] = TComRdCost::xGetSAD12; |
---|
| 207 | m_afpDistortFunc[44] = TComRdCost::xGetSAD24; |
---|
| 208 | m_afpDistortFunc[45] = TComRdCost::xGetSAD48; |
---|
| 209 | |
---|
| 210 | m_afpDistortFunc[46] = TComRdCost::xGetSAD12; |
---|
| 211 | m_afpDistortFunc[47] = TComRdCost::xGetSAD24; |
---|
| 212 | m_afpDistortFunc[48] = TComRdCost::xGetSAD48; |
---|
| 213 | #endif |
---|
| 214 | m_afpDistortFunc[22] = TComRdCost::xGetHADs; |
---|
| 215 | m_afpDistortFunc[23] = TComRdCost::xGetHADs; |
---|
| 216 | m_afpDistortFunc[24] = TComRdCost::xGetHADs; |
---|
| 217 | m_afpDistortFunc[25] = TComRdCost::xGetHADs; |
---|
| 218 | m_afpDistortFunc[26] = TComRdCost::xGetHADs; |
---|
| 219 | m_afpDistortFunc[27] = TComRdCost::xGetHADs; |
---|
| 220 | m_afpDistortFunc[28] = TComRdCost::xGetHADs; |
---|
[494] | 221 | |
---|
[313] | 222 | #if !FIX203 |
---|
| 223 | m_puiComponentCostOriginP = NULL; |
---|
| 224 | m_puiComponentCost = NULL; |
---|
| 225 | m_puiVerCost = NULL; |
---|
| 226 | m_puiHorCost = NULL; |
---|
| 227 | #endif |
---|
| 228 | m_uiCost = 0; |
---|
| 229 | m_iCostScale = 0; |
---|
| 230 | #if !FIX203 |
---|
| 231 | m_iSearchLimit = 0xdeaddead; |
---|
| 232 | #endif |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | #if !FIX203 |
---|
| 236 | Void TComRdCost::initRateDistortionModel( Int iSubPelSearchLimit ) |
---|
| 237 | { |
---|
| 238 | // make it larger |
---|
| 239 | iSubPelSearchLimit += 4; |
---|
| 240 | iSubPelSearchLimit *= 8; |
---|
[494] | 241 | |
---|
[313] | 242 | if( m_iSearchLimit != iSubPelSearchLimit ) |
---|
| 243 | { |
---|
| 244 | xUninit(); |
---|
[494] | 245 | |
---|
[313] | 246 | m_iSearchLimit = iSubPelSearchLimit; |
---|
[494] | 247 | |
---|
[313] | 248 | m_puiComponentCostOriginP = new UInt[ 4 * iSubPelSearchLimit ]; |
---|
| 249 | iSubPelSearchLimit *= 2; |
---|
[494] | 250 | |
---|
[313] | 251 | m_puiComponentCost = m_puiComponentCostOriginP + iSubPelSearchLimit; |
---|
[494] | 252 | |
---|
[313] | 253 | for( Int n = -iSubPelSearchLimit; n < iSubPelSearchLimit; n++) |
---|
| 254 | { |
---|
| 255 | m_puiComponentCost[n] = xGetComponentBits( n ); |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | Void TComRdCost::xUninit() |
---|
| 261 | { |
---|
| 262 | if( NULL != m_puiComponentCostOriginP ) |
---|
| 263 | { |
---|
| 264 | delete [] m_puiComponentCostOriginP; |
---|
| 265 | m_puiComponentCostOriginP = NULL; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | #endif |
---|
| 269 | |
---|
| 270 | UInt TComRdCost::xGetComponentBits( Int iVal ) |
---|
| 271 | { |
---|
| 272 | UInt uiLength = 1; |
---|
| 273 | UInt uiTemp = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1); |
---|
[494] | 274 | |
---|
[313] | 275 | assert ( uiTemp ); |
---|
[494] | 276 | |
---|
[313] | 277 | while ( 1 != uiTemp ) |
---|
| 278 | { |
---|
| 279 | uiTemp >>= 1; |
---|
| 280 | uiLength += 2; |
---|
| 281 | } |
---|
[494] | 282 | |
---|
[313] | 283 | return uiLength; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | Void TComRdCost::setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam ) |
---|
| 287 | { |
---|
| 288 | // set Block Width / Height |
---|
| 289 | rcDistParam.iCols = uiBlkWidth; |
---|
| 290 | rcDistParam.iRows = uiBlkHeight; |
---|
| 291 | rcDistParam.DistFunc = m_afpDistortFunc[eDFunc + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ]; |
---|
[494] | 292 | |
---|
[313] | 293 | // initialize |
---|
| 294 | rcDistParam.iSubShift = 0; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | // Setting the Distortion Parameter for Inter (ME) |
---|
| 298 | Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ) |
---|
| 299 | { |
---|
| 300 | // set Original & Curr Pointer / Stride |
---|
| 301 | rcDistParam.pOrg = pcPatternKey->getROIY(); |
---|
| 302 | rcDistParam.pCur = piRefY; |
---|
[494] | 303 | |
---|
[313] | 304 | rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride(); |
---|
| 305 | rcDistParam.iStrideCur = iRefStride; |
---|
[494] | 306 | |
---|
[313] | 307 | // set Block Width / Height |
---|
| 308 | rcDistParam.iCols = pcPatternKey->getROIYWidth(); |
---|
| 309 | rcDistParam.iRows = pcPatternKey->getROIYHeight(); |
---|
| 310 | rcDistParam.DistFunc = m_afpDistortFunc[DF_SAD + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ]; |
---|
[494] | 311 | |
---|
[313] | 312 | #if AMP_SAD |
---|
| 313 | if (rcDistParam.iCols == 12) |
---|
| 314 | { |
---|
| 315 | rcDistParam.DistFunc = m_afpDistortFunc[43 ]; |
---|
| 316 | } |
---|
| 317 | else if (rcDistParam.iCols == 24) |
---|
| 318 | { |
---|
| 319 | rcDistParam.DistFunc = m_afpDistortFunc[44 ]; |
---|
| 320 | } |
---|
| 321 | else if (rcDistParam.iCols == 48) |
---|
| 322 | { |
---|
| 323 | rcDistParam.DistFunc = m_afpDistortFunc[45 ]; |
---|
| 324 | } |
---|
| 325 | #endif |
---|
| 326 | |
---|
| 327 | // initialize |
---|
| 328 | rcDistParam.iSubShift = 0; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | // Setting the Distortion Parameter for Inter (subpel ME with step) |
---|
| 332 | Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME ) |
---|
| 333 | { |
---|
[494] | 334 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
| 335 | // Bug fix: The correct bit depth has not been used for weighted cost calculation |
---|
| 336 | rcDistParam.bitDepth = g_bitDepthY; |
---|
| 337 | #endif |
---|
[313] | 338 | // set Original & Curr Pointer / Stride |
---|
| 339 | rcDistParam.pOrg = pcPatternKey->getROIY(); |
---|
| 340 | rcDistParam.pCur = piRefY; |
---|
[494] | 341 | |
---|
[313] | 342 | rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride(); |
---|
| 343 | rcDistParam.iStrideCur = iRefStride * iStep; |
---|
[494] | 344 | |
---|
[313] | 345 | // set Step for interpolated buffer |
---|
| 346 | rcDistParam.iStep = iStep; |
---|
[494] | 347 | |
---|
[313] | 348 | // set Block Width / Height |
---|
| 349 | rcDistParam.iCols = pcPatternKey->getROIYWidth(); |
---|
| 350 | rcDistParam.iRows = pcPatternKey->getROIYHeight(); |
---|
[494] | 351 | |
---|
[313] | 352 | // set distortion function |
---|
| 353 | if ( !bHADME ) |
---|
| 354 | { |
---|
| 355 | rcDistParam.DistFunc = m_afpDistortFunc[DF_SADS + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ]; |
---|
| 356 | #if AMP_SAD |
---|
| 357 | if (rcDistParam.iCols == 12) |
---|
| 358 | { |
---|
| 359 | rcDistParam.DistFunc = m_afpDistortFunc[46 ]; |
---|
| 360 | } |
---|
| 361 | else if (rcDistParam.iCols == 24) |
---|
| 362 | { |
---|
| 363 | rcDistParam.DistFunc = m_afpDistortFunc[47 ]; |
---|
| 364 | } |
---|
| 365 | else if (rcDistParam.iCols == 48) |
---|
| 366 | { |
---|
| 367 | rcDistParam.DistFunc = m_afpDistortFunc[48 ]; |
---|
| 368 | } |
---|
| 369 | #endif |
---|
| 370 | } |
---|
| 371 | else |
---|
| 372 | { |
---|
| 373 | rcDistParam.DistFunc = m_afpDistortFunc[DF_HADS + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ]; |
---|
| 374 | } |
---|
[494] | 375 | |
---|
[313] | 376 | // initialize |
---|
| 377 | rcDistParam.iSubShift = 0; |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | Void |
---|
| 381 | TComRdCost::setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard ) |
---|
| 382 | { |
---|
| 383 | rcDP.pOrg = p1; |
---|
| 384 | rcDP.pCur = p2; |
---|
| 385 | rcDP.iStrideOrg = iStride1; |
---|
| 386 | rcDP.iStrideCur = iStride2; |
---|
| 387 | rcDP.iCols = iWidth; |
---|
| 388 | rcDP.iRows = iHeight; |
---|
| 389 | rcDP.iStep = 1; |
---|
| 390 | rcDP.iSubShift = 0; |
---|
| 391 | rcDP.bitDepth = bitDepth; |
---|
| 392 | rcDP.DistFunc = m_afpDistortFunc[ ( bHadamard ? DF_HADS : DF_SADS ) + g_aucConvertToBit[ iWidth ] + 1 ]; |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | UInt TComRdCost::calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight ) |
---|
| 396 | { |
---|
| 397 | UInt uiSum = 0; |
---|
| 398 | Int x, y; |
---|
[494] | 399 | |
---|
[313] | 400 | if ( ( (iWidth % 8) == 0 ) && ( (iHeight % 8) == 0 ) ) |
---|
| 401 | { |
---|
| 402 | for ( y=0; y<iHeight; y+= 8 ) |
---|
| 403 | { |
---|
| 404 | for ( x=0; x<iWidth; x+= 8 ) |
---|
| 405 | { |
---|
| 406 | uiSum += xCalcHADs8x8( &pi0[x], &pi1[x], iStride0, iStride1, 1 ); |
---|
| 407 | } |
---|
| 408 | pi0 += iStride0*8; |
---|
| 409 | pi1 += iStride1*8; |
---|
| 410 | } |
---|
| 411 | } |
---|
[593] | 412 | else |
---|
[313] | 413 | { |
---|
[593] | 414 | assert(iWidth % 4 == 0 && iHeight % 4 == 0); |
---|
| 415 | |
---|
[313] | 416 | for ( y=0; y<iHeight; y+= 4 ) |
---|
| 417 | { |
---|
| 418 | for ( x=0; x<iWidth; x+= 4 ) |
---|
| 419 | { |
---|
| 420 | uiSum += xCalcHADs4x4( &pi0[x], &pi1[x], iStride0, iStride1, 1 ); |
---|
| 421 | } |
---|
| 422 | pi0 += iStride0*4; |
---|
| 423 | pi1 += iStride1*4; |
---|
| 424 | } |
---|
| 425 | } |
---|
[494] | 426 | |
---|
[313] | 427 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); |
---|
| 428 | |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText, DFunc eDFunc) |
---|
| 432 | { |
---|
| 433 | DistParam cDtParam; |
---|
| 434 | setDistParam( uiBlkWidth, uiBlkHeight, eDFunc, cDtParam ); |
---|
| 435 | cDtParam.pOrg = piOrg; |
---|
| 436 | cDtParam.pCur = piCur; |
---|
| 437 | cDtParam.iStrideOrg = iOrgStride; |
---|
| 438 | cDtParam.iStrideCur = iCurStride; |
---|
| 439 | cDtParam.iStep = 1; |
---|
| 440 | |
---|
| 441 | cDtParam.bApplyWeight = false; |
---|
| 442 | cDtParam.uiComp = 255; // just for assert: to be sure it was set before use, since only values 0,1 or 2 are allowed. |
---|
| 443 | cDtParam.bitDepth = bitDepth; |
---|
| 444 | |
---|
| 445 | if (eText == TEXT_CHROMA_U) |
---|
| 446 | { |
---|
| 447 | return ((Int) (m_cbDistortionWeight * cDtParam.DistFunc( &cDtParam ))); |
---|
| 448 | } |
---|
| 449 | else if (eText == TEXT_CHROMA_V) |
---|
| 450 | { |
---|
| 451 | return ((Int) (m_crDistortionWeight * cDtParam.DistFunc( &cDtParam ))); |
---|
| 452 | } |
---|
| 453 | else |
---|
| 454 | { |
---|
| 455 | return cDtParam.DistFunc( &cDtParam ); |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | // ==================================================================================================================== |
---|
| 460 | // Distortion functions |
---|
| 461 | // ==================================================================================================================== |
---|
| 462 | |
---|
| 463 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 464 | // SAD |
---|
| 465 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 466 | |
---|
| 467 | UInt TComRdCost::xGetSAD( DistParam* pcDtParam ) |
---|
| 468 | { |
---|
| 469 | if ( pcDtParam->bApplyWeight ) |
---|
| 470 | { |
---|
| 471 | return xGetSADw( pcDtParam ); |
---|
| 472 | } |
---|
| 473 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 474 | Pel* piCur = pcDtParam->pCur; |
---|
| 475 | Int iRows = pcDtParam->iRows; |
---|
| 476 | Int iCols = pcDtParam->iCols; |
---|
| 477 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 478 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
[494] | 479 | |
---|
[313] | 480 | UInt uiSum = 0; |
---|
[494] | 481 | |
---|
[313] | 482 | for( ; iRows != 0; iRows-- ) |
---|
| 483 | { |
---|
| 484 | for (Int n = 0; n < iCols; n++ ) |
---|
| 485 | { |
---|
| 486 | uiSum += abs( piOrg[n] - piCur[n] ); |
---|
| 487 | } |
---|
| 488 | piOrg += iStrideOrg; |
---|
| 489 | piCur += iStrideCur; |
---|
| 490 | } |
---|
[494] | 491 | |
---|
[313] | 492 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | UInt TComRdCost::xGetSAD4( DistParam* pcDtParam ) |
---|
| 496 | { |
---|
[494] | 497 | if ( pcDtParam->bApplyWeight ) |
---|
[313] | 498 | { |
---|
| 499 | return xGetSADw( pcDtParam ); |
---|
| 500 | } |
---|
| 501 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 502 | Pel* piCur = pcDtParam->pCur; |
---|
| 503 | Int iRows = pcDtParam->iRows; |
---|
| 504 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 505 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 506 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 507 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 508 | |
---|
[313] | 509 | UInt uiSum = 0; |
---|
[494] | 510 | |
---|
[313] | 511 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 512 | { |
---|
| 513 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 514 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 515 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 516 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
[494] | 517 | |
---|
[313] | 518 | piOrg += iStrideOrg; |
---|
| 519 | piCur += iStrideCur; |
---|
| 520 | } |
---|
[494] | 521 | |
---|
[313] | 522 | uiSum <<= iSubShift; |
---|
| 523 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | UInt TComRdCost::xGetSAD8( DistParam* pcDtParam ) |
---|
| 527 | { |
---|
| 528 | if ( pcDtParam->bApplyWeight ) |
---|
| 529 | { |
---|
| 530 | return xGetSADw( pcDtParam ); |
---|
| 531 | } |
---|
| 532 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 533 | Pel* piCur = pcDtParam->pCur; |
---|
| 534 | Int iRows = pcDtParam->iRows; |
---|
| 535 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 536 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 537 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 538 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 539 | |
---|
[313] | 540 | UInt uiSum = 0; |
---|
[494] | 541 | |
---|
[313] | 542 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 543 | { |
---|
| 544 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 545 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 546 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 547 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 548 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 549 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 550 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 551 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
[494] | 552 | |
---|
[313] | 553 | piOrg += iStrideOrg; |
---|
| 554 | piCur += iStrideCur; |
---|
| 555 | } |
---|
[494] | 556 | |
---|
[313] | 557 | uiSum <<= iSubShift; |
---|
| 558 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | UInt TComRdCost::xGetSAD16( DistParam* pcDtParam ) |
---|
| 562 | { |
---|
| 563 | if ( pcDtParam->bApplyWeight ) |
---|
| 564 | { |
---|
| 565 | return xGetSADw( pcDtParam ); |
---|
| 566 | } |
---|
| 567 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 568 | Pel* piCur = pcDtParam->pCur; |
---|
| 569 | Int iRows = pcDtParam->iRows; |
---|
| 570 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 571 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 572 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 573 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 574 | |
---|
[313] | 575 | UInt uiSum = 0; |
---|
[494] | 576 | |
---|
[313] | 577 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 578 | { |
---|
| 579 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 580 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 581 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 582 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 583 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 584 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 585 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 586 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 587 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 588 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 589 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 590 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
| 591 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
| 592 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
| 593 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
| 594 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
[494] | 595 | |
---|
[313] | 596 | piOrg += iStrideOrg; |
---|
| 597 | piCur += iStrideCur; |
---|
| 598 | } |
---|
[494] | 599 | |
---|
[313] | 600 | uiSum <<= iSubShift; |
---|
| 601 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | #if AMP_SAD |
---|
| 605 | UInt TComRdCost::xGetSAD12( DistParam* pcDtParam ) |
---|
| 606 | { |
---|
| 607 | if ( pcDtParam->bApplyWeight ) |
---|
| 608 | { |
---|
| 609 | return xGetSADw( pcDtParam ); |
---|
| 610 | } |
---|
| 611 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 612 | Pel* piCur = pcDtParam->pCur; |
---|
| 613 | Int iRows = pcDtParam->iRows; |
---|
| 614 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 615 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 616 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 617 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 618 | |
---|
[313] | 619 | UInt uiSum = 0; |
---|
[494] | 620 | |
---|
[313] | 621 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 622 | { |
---|
| 623 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 624 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 625 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 626 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 627 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 628 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 629 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 630 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 631 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 632 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 633 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 634 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
[494] | 635 | |
---|
[313] | 636 | piOrg += iStrideOrg; |
---|
| 637 | piCur += iStrideCur; |
---|
| 638 | } |
---|
[494] | 639 | |
---|
[313] | 640 | uiSum <<= iSubShift; |
---|
| 641 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 642 | } |
---|
| 643 | #endif |
---|
| 644 | |
---|
| 645 | UInt TComRdCost::xGetSAD16N( DistParam* pcDtParam ) |
---|
| 646 | { |
---|
| 647 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 648 | Pel* piCur = pcDtParam->pCur; |
---|
| 649 | Int iRows = pcDtParam->iRows; |
---|
| 650 | Int iCols = pcDtParam->iCols; |
---|
| 651 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 652 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 653 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 654 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 655 | |
---|
[313] | 656 | UInt uiSum = 0; |
---|
[494] | 657 | |
---|
[313] | 658 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 659 | { |
---|
| 660 | for (Int n = 0; n < iCols; n+=16 ) |
---|
| 661 | { |
---|
| 662 | uiSum += abs( piOrg[n+ 0] - piCur[n+ 0] ); |
---|
| 663 | uiSum += abs( piOrg[n+ 1] - piCur[n+ 1] ); |
---|
| 664 | uiSum += abs( piOrg[n+ 2] - piCur[n+ 2] ); |
---|
| 665 | uiSum += abs( piOrg[n+ 3] - piCur[n+ 3] ); |
---|
| 666 | uiSum += abs( piOrg[n+ 4] - piCur[n+ 4] ); |
---|
| 667 | uiSum += abs( piOrg[n+ 5] - piCur[n+ 5] ); |
---|
| 668 | uiSum += abs( piOrg[n+ 6] - piCur[n+ 6] ); |
---|
| 669 | uiSum += abs( piOrg[n+ 7] - piCur[n+ 7] ); |
---|
| 670 | uiSum += abs( piOrg[n+ 8] - piCur[n+ 8] ); |
---|
| 671 | uiSum += abs( piOrg[n+ 9] - piCur[n+ 9] ); |
---|
| 672 | uiSum += abs( piOrg[n+10] - piCur[n+10] ); |
---|
| 673 | uiSum += abs( piOrg[n+11] - piCur[n+11] ); |
---|
| 674 | uiSum += abs( piOrg[n+12] - piCur[n+12] ); |
---|
| 675 | uiSum += abs( piOrg[n+13] - piCur[n+13] ); |
---|
| 676 | uiSum += abs( piOrg[n+14] - piCur[n+14] ); |
---|
| 677 | uiSum += abs( piOrg[n+15] - piCur[n+15] ); |
---|
| 678 | } |
---|
| 679 | piOrg += iStrideOrg; |
---|
| 680 | piCur += iStrideCur; |
---|
| 681 | } |
---|
[494] | 682 | |
---|
[313] | 683 | uiSum <<= iSubShift; |
---|
| 684 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | UInt TComRdCost::xGetSAD32( DistParam* pcDtParam ) |
---|
| 688 | { |
---|
| 689 | if ( pcDtParam->bApplyWeight ) |
---|
| 690 | { |
---|
| 691 | return xGetSADw( pcDtParam ); |
---|
| 692 | } |
---|
| 693 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 694 | Pel* piCur = pcDtParam->pCur; |
---|
| 695 | Int iRows = pcDtParam->iRows; |
---|
| 696 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 697 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 698 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 699 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 700 | |
---|
[313] | 701 | UInt uiSum = 0; |
---|
[494] | 702 | |
---|
[313] | 703 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 704 | { |
---|
| 705 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 706 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 707 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 708 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 709 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 710 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 711 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 712 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 713 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 714 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 715 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 716 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
| 717 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
| 718 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
| 719 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
| 720 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
| 721 | uiSum += abs( piOrg[16] - piCur[16] ); |
---|
| 722 | uiSum += abs( piOrg[17] - piCur[17] ); |
---|
| 723 | uiSum += abs( piOrg[18] - piCur[18] ); |
---|
| 724 | uiSum += abs( piOrg[19] - piCur[19] ); |
---|
| 725 | uiSum += abs( piOrg[20] - piCur[20] ); |
---|
| 726 | uiSum += abs( piOrg[21] - piCur[21] ); |
---|
| 727 | uiSum += abs( piOrg[22] - piCur[22] ); |
---|
| 728 | uiSum += abs( piOrg[23] - piCur[23] ); |
---|
| 729 | uiSum += abs( piOrg[24] - piCur[24] ); |
---|
| 730 | uiSum += abs( piOrg[25] - piCur[25] ); |
---|
| 731 | uiSum += abs( piOrg[26] - piCur[26] ); |
---|
| 732 | uiSum += abs( piOrg[27] - piCur[27] ); |
---|
| 733 | uiSum += abs( piOrg[28] - piCur[28] ); |
---|
| 734 | uiSum += abs( piOrg[29] - piCur[29] ); |
---|
| 735 | uiSum += abs( piOrg[30] - piCur[30] ); |
---|
| 736 | uiSum += abs( piOrg[31] - piCur[31] ); |
---|
[494] | 737 | |
---|
[313] | 738 | piOrg += iStrideOrg; |
---|
| 739 | piCur += iStrideCur; |
---|
| 740 | } |
---|
[494] | 741 | |
---|
[313] | 742 | uiSum <<= iSubShift; |
---|
| 743 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | #if AMP_SAD |
---|
| 747 | UInt TComRdCost::xGetSAD24( DistParam* pcDtParam ) |
---|
| 748 | { |
---|
| 749 | if ( pcDtParam->bApplyWeight ) |
---|
| 750 | { |
---|
| 751 | return xGetSADw( pcDtParam ); |
---|
| 752 | } |
---|
| 753 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 754 | Pel* piCur = pcDtParam->pCur; |
---|
| 755 | Int iRows = pcDtParam->iRows; |
---|
| 756 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 757 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 758 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 759 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 760 | |
---|
[313] | 761 | UInt uiSum = 0; |
---|
[494] | 762 | |
---|
[313] | 763 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 764 | { |
---|
| 765 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 766 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 767 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 768 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 769 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 770 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 771 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 772 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 773 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 774 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 775 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 776 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
| 777 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
| 778 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
| 779 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
| 780 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
| 781 | uiSum += abs( piOrg[16] - piCur[16] ); |
---|
| 782 | uiSum += abs( piOrg[17] - piCur[17] ); |
---|
| 783 | uiSum += abs( piOrg[18] - piCur[18] ); |
---|
| 784 | uiSum += abs( piOrg[19] - piCur[19] ); |
---|
| 785 | uiSum += abs( piOrg[20] - piCur[20] ); |
---|
| 786 | uiSum += abs( piOrg[21] - piCur[21] ); |
---|
| 787 | uiSum += abs( piOrg[22] - piCur[22] ); |
---|
| 788 | uiSum += abs( piOrg[23] - piCur[23] ); |
---|
[494] | 789 | |
---|
[313] | 790 | piOrg += iStrideOrg; |
---|
| 791 | piCur += iStrideCur; |
---|
| 792 | } |
---|
[494] | 793 | |
---|
[313] | 794 | uiSum <<= iSubShift; |
---|
| 795 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | #endif |
---|
| 799 | |
---|
| 800 | UInt TComRdCost::xGetSAD64( DistParam* pcDtParam ) |
---|
| 801 | { |
---|
| 802 | if ( pcDtParam->bApplyWeight ) |
---|
| 803 | { |
---|
| 804 | return xGetSADw( pcDtParam ); |
---|
| 805 | } |
---|
| 806 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 807 | Pel* piCur = pcDtParam->pCur; |
---|
| 808 | Int iRows = pcDtParam->iRows; |
---|
| 809 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 810 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 811 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 812 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 813 | |
---|
[313] | 814 | UInt uiSum = 0; |
---|
[494] | 815 | |
---|
[313] | 816 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 817 | { |
---|
| 818 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 819 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 820 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 821 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 822 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 823 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 824 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 825 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 826 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 827 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 828 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 829 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
| 830 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
| 831 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
| 832 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
| 833 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
| 834 | uiSum += abs( piOrg[16] - piCur[16] ); |
---|
| 835 | uiSum += abs( piOrg[17] - piCur[17] ); |
---|
| 836 | uiSum += abs( piOrg[18] - piCur[18] ); |
---|
| 837 | uiSum += abs( piOrg[19] - piCur[19] ); |
---|
| 838 | uiSum += abs( piOrg[20] - piCur[20] ); |
---|
| 839 | uiSum += abs( piOrg[21] - piCur[21] ); |
---|
| 840 | uiSum += abs( piOrg[22] - piCur[22] ); |
---|
| 841 | uiSum += abs( piOrg[23] - piCur[23] ); |
---|
| 842 | uiSum += abs( piOrg[24] - piCur[24] ); |
---|
| 843 | uiSum += abs( piOrg[25] - piCur[25] ); |
---|
| 844 | uiSum += abs( piOrg[26] - piCur[26] ); |
---|
| 845 | uiSum += abs( piOrg[27] - piCur[27] ); |
---|
| 846 | uiSum += abs( piOrg[28] - piCur[28] ); |
---|
| 847 | uiSum += abs( piOrg[29] - piCur[29] ); |
---|
| 848 | uiSum += abs( piOrg[30] - piCur[30] ); |
---|
| 849 | uiSum += abs( piOrg[31] - piCur[31] ); |
---|
| 850 | uiSum += abs( piOrg[32] - piCur[32] ); |
---|
| 851 | uiSum += abs( piOrg[33] - piCur[33] ); |
---|
| 852 | uiSum += abs( piOrg[34] - piCur[34] ); |
---|
| 853 | uiSum += abs( piOrg[35] - piCur[35] ); |
---|
| 854 | uiSum += abs( piOrg[36] - piCur[36] ); |
---|
| 855 | uiSum += abs( piOrg[37] - piCur[37] ); |
---|
| 856 | uiSum += abs( piOrg[38] - piCur[38] ); |
---|
| 857 | uiSum += abs( piOrg[39] - piCur[39] ); |
---|
| 858 | uiSum += abs( piOrg[40] - piCur[40] ); |
---|
| 859 | uiSum += abs( piOrg[41] - piCur[41] ); |
---|
| 860 | uiSum += abs( piOrg[42] - piCur[42] ); |
---|
| 861 | uiSum += abs( piOrg[43] - piCur[43] ); |
---|
| 862 | uiSum += abs( piOrg[44] - piCur[44] ); |
---|
| 863 | uiSum += abs( piOrg[45] - piCur[45] ); |
---|
| 864 | uiSum += abs( piOrg[46] - piCur[46] ); |
---|
| 865 | uiSum += abs( piOrg[47] - piCur[47] ); |
---|
| 866 | uiSum += abs( piOrg[48] - piCur[48] ); |
---|
| 867 | uiSum += abs( piOrg[49] - piCur[49] ); |
---|
| 868 | uiSum += abs( piOrg[50] - piCur[50] ); |
---|
| 869 | uiSum += abs( piOrg[51] - piCur[51] ); |
---|
| 870 | uiSum += abs( piOrg[52] - piCur[52] ); |
---|
| 871 | uiSum += abs( piOrg[53] - piCur[53] ); |
---|
| 872 | uiSum += abs( piOrg[54] - piCur[54] ); |
---|
| 873 | uiSum += abs( piOrg[55] - piCur[55] ); |
---|
| 874 | uiSum += abs( piOrg[56] - piCur[56] ); |
---|
| 875 | uiSum += abs( piOrg[57] - piCur[57] ); |
---|
| 876 | uiSum += abs( piOrg[58] - piCur[58] ); |
---|
| 877 | uiSum += abs( piOrg[59] - piCur[59] ); |
---|
| 878 | uiSum += abs( piOrg[60] - piCur[60] ); |
---|
| 879 | uiSum += abs( piOrg[61] - piCur[61] ); |
---|
| 880 | uiSum += abs( piOrg[62] - piCur[62] ); |
---|
| 881 | uiSum += abs( piOrg[63] - piCur[63] ); |
---|
[494] | 882 | |
---|
[313] | 883 | piOrg += iStrideOrg; |
---|
| 884 | piCur += iStrideCur; |
---|
| 885 | } |
---|
[494] | 886 | |
---|
[313] | 887 | uiSum <<= iSubShift; |
---|
| 888 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | #if AMP_SAD |
---|
| 892 | UInt TComRdCost::xGetSAD48( DistParam* pcDtParam ) |
---|
| 893 | { |
---|
| 894 | if ( pcDtParam->bApplyWeight ) |
---|
| 895 | { |
---|
| 896 | return xGetSADw( pcDtParam ); |
---|
| 897 | } |
---|
| 898 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 899 | Pel* piCur = pcDtParam->pCur; |
---|
| 900 | Int iRows = pcDtParam->iRows; |
---|
| 901 | Int iSubShift = pcDtParam->iSubShift; |
---|
| 902 | Int iSubStep = ( 1 << iSubShift ); |
---|
| 903 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
| 904 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
[494] | 905 | |
---|
[313] | 906 | UInt uiSum = 0; |
---|
[494] | 907 | |
---|
[313] | 908 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
| 909 | { |
---|
| 910 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
| 911 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
| 912 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
| 913 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
| 914 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
| 915 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
| 916 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
| 917 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
| 918 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
| 919 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
| 920 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
| 921 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
| 922 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
| 923 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
| 924 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
| 925 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
| 926 | uiSum += abs( piOrg[16] - piCur[16] ); |
---|
| 927 | uiSum += abs( piOrg[17] - piCur[17] ); |
---|
| 928 | uiSum += abs( piOrg[18] - piCur[18] ); |
---|
| 929 | uiSum += abs( piOrg[19] - piCur[19] ); |
---|
| 930 | uiSum += abs( piOrg[20] - piCur[20] ); |
---|
| 931 | uiSum += abs( piOrg[21] - piCur[21] ); |
---|
| 932 | uiSum += abs( piOrg[22] - piCur[22] ); |
---|
| 933 | uiSum += abs( piOrg[23] - piCur[23] ); |
---|
| 934 | uiSum += abs( piOrg[24] - piCur[24] ); |
---|
| 935 | uiSum += abs( piOrg[25] - piCur[25] ); |
---|
| 936 | uiSum += abs( piOrg[26] - piCur[26] ); |
---|
| 937 | uiSum += abs( piOrg[27] - piCur[27] ); |
---|
| 938 | uiSum += abs( piOrg[28] - piCur[28] ); |
---|
| 939 | uiSum += abs( piOrg[29] - piCur[29] ); |
---|
| 940 | uiSum += abs( piOrg[30] - piCur[30] ); |
---|
| 941 | uiSum += abs( piOrg[31] - piCur[31] ); |
---|
| 942 | uiSum += abs( piOrg[32] - piCur[32] ); |
---|
| 943 | uiSum += abs( piOrg[33] - piCur[33] ); |
---|
| 944 | uiSum += abs( piOrg[34] - piCur[34] ); |
---|
| 945 | uiSum += abs( piOrg[35] - piCur[35] ); |
---|
| 946 | uiSum += abs( piOrg[36] - piCur[36] ); |
---|
| 947 | uiSum += abs( piOrg[37] - piCur[37] ); |
---|
| 948 | uiSum += abs( piOrg[38] - piCur[38] ); |
---|
| 949 | uiSum += abs( piOrg[39] - piCur[39] ); |
---|
| 950 | uiSum += abs( piOrg[40] - piCur[40] ); |
---|
| 951 | uiSum += abs( piOrg[41] - piCur[41] ); |
---|
| 952 | uiSum += abs( piOrg[42] - piCur[42] ); |
---|
| 953 | uiSum += abs( piOrg[43] - piCur[43] ); |
---|
| 954 | uiSum += abs( piOrg[44] - piCur[44] ); |
---|
| 955 | uiSum += abs( piOrg[45] - piCur[45] ); |
---|
| 956 | uiSum += abs( piOrg[46] - piCur[46] ); |
---|
| 957 | uiSum += abs( piOrg[47] - piCur[47] ); |
---|
[494] | 958 | |
---|
[313] | 959 | piOrg += iStrideOrg; |
---|
| 960 | piCur += iStrideCur; |
---|
| 961 | } |
---|
[494] | 962 | |
---|
[313] | 963 | uiSum <<= iSubShift; |
---|
| 964 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 965 | } |
---|
| 966 | #endif |
---|
| 967 | |
---|
| 968 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 969 | // SSE |
---|
| 970 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 971 | |
---|
| 972 | UInt TComRdCost::xGetSSE( DistParam* pcDtParam ) |
---|
| 973 | { |
---|
| 974 | if ( pcDtParam->bApplyWeight ) |
---|
| 975 | { |
---|
| 976 | return xGetSSEw( pcDtParam ); |
---|
| 977 | } |
---|
| 978 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 979 | Pel* piCur = pcDtParam->pCur; |
---|
| 980 | Int iRows = pcDtParam->iRows; |
---|
| 981 | Int iCols = pcDtParam->iCols; |
---|
| 982 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 983 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 984 | |
---|
[313] | 985 | UInt uiSum = 0; |
---|
| 986 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
[494] | 987 | |
---|
[313] | 988 | Int iTemp; |
---|
[494] | 989 | |
---|
[313] | 990 | for( ; iRows != 0; iRows-- ) |
---|
| 991 | { |
---|
| 992 | for (Int n = 0; n < iCols; n++ ) |
---|
| 993 | { |
---|
| 994 | iTemp = piOrg[n ] - piCur[n ]; |
---|
| 995 | uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 996 | } |
---|
| 997 | piOrg += iStrideOrg; |
---|
| 998 | piCur += iStrideCur; |
---|
| 999 | } |
---|
[494] | 1000 | |
---|
[313] | 1001 | return ( uiSum ); |
---|
| 1002 | } |
---|
| 1003 | |
---|
| 1004 | UInt TComRdCost::xGetSSE4( DistParam* pcDtParam ) |
---|
| 1005 | { |
---|
| 1006 | if ( pcDtParam->bApplyWeight ) |
---|
| 1007 | { |
---|
| 1008 | assert( pcDtParam->iCols == 4 ); |
---|
| 1009 | return xGetSSEw( pcDtParam ); |
---|
| 1010 | } |
---|
| 1011 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1012 | Pel* piCur = pcDtParam->pCur; |
---|
| 1013 | Int iRows = pcDtParam->iRows; |
---|
| 1014 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1015 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1016 | |
---|
[313] | 1017 | UInt uiSum = 0; |
---|
| 1018 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
[494] | 1019 | |
---|
[313] | 1020 | Int iTemp; |
---|
[494] | 1021 | |
---|
[313] | 1022 | for( ; iRows != 0; iRows-- ) |
---|
| 1023 | { |
---|
[494] | 1024 | |
---|
[313] | 1025 | iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1026 | iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1027 | iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1028 | iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1029 | |
---|
[313] | 1030 | piOrg += iStrideOrg; |
---|
| 1031 | piCur += iStrideCur; |
---|
| 1032 | } |
---|
[494] | 1033 | |
---|
[313] | 1034 | return ( uiSum ); |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | UInt TComRdCost::xGetSSE8( DistParam* pcDtParam ) |
---|
| 1038 | { |
---|
| 1039 | if ( pcDtParam->bApplyWeight ) |
---|
| 1040 | { |
---|
| 1041 | assert( pcDtParam->iCols == 8 ); |
---|
| 1042 | return xGetSSEw( pcDtParam ); |
---|
| 1043 | } |
---|
| 1044 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1045 | Pel* piCur = pcDtParam->pCur; |
---|
| 1046 | Int iRows = pcDtParam->iRows; |
---|
| 1047 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1048 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1049 | |
---|
[313] | 1050 | UInt uiSum = 0; |
---|
| 1051 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
[494] | 1052 | |
---|
[313] | 1053 | Int iTemp; |
---|
[494] | 1054 | |
---|
[313] | 1055 | for( ; iRows != 0; iRows-- ) |
---|
| 1056 | { |
---|
| 1057 | iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1058 | iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1059 | iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1060 | iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1061 | iTemp = piOrg[4] - piCur[4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1062 | iTemp = piOrg[5] - piCur[5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1063 | iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1064 | iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1065 | |
---|
[313] | 1066 | piOrg += iStrideOrg; |
---|
| 1067 | piCur += iStrideCur; |
---|
| 1068 | } |
---|
[494] | 1069 | |
---|
[313] | 1070 | return ( uiSum ); |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | UInt TComRdCost::xGetSSE16( DistParam* pcDtParam ) |
---|
| 1074 | { |
---|
| 1075 | if ( pcDtParam->bApplyWeight ) |
---|
| 1076 | { |
---|
| 1077 | assert( pcDtParam->iCols == 16 ); |
---|
| 1078 | return xGetSSEw( pcDtParam ); |
---|
| 1079 | } |
---|
| 1080 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1081 | Pel* piCur = pcDtParam->pCur; |
---|
| 1082 | Int iRows = pcDtParam->iRows; |
---|
| 1083 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1084 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1085 | |
---|
[313] | 1086 | UInt uiSum = 0; |
---|
| 1087 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
[494] | 1088 | |
---|
[313] | 1089 | Int iTemp; |
---|
[494] | 1090 | |
---|
[313] | 1091 | for( ; iRows != 0; iRows-- ) |
---|
| 1092 | { |
---|
[494] | 1093 | |
---|
[313] | 1094 | iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1095 | iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1096 | iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1097 | iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1098 | iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1099 | iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1100 | iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1101 | iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1102 | iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1103 | iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1104 | iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1105 | iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1106 | iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1107 | iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1108 | iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1109 | iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1110 | |
---|
[313] | 1111 | piOrg += iStrideOrg; |
---|
| 1112 | piCur += iStrideCur; |
---|
| 1113 | } |
---|
[494] | 1114 | |
---|
[313] | 1115 | return ( uiSum ); |
---|
| 1116 | } |
---|
| 1117 | |
---|
| 1118 | UInt TComRdCost::xGetSSE16N( DistParam* pcDtParam ) |
---|
| 1119 | { |
---|
| 1120 | if ( pcDtParam->bApplyWeight ) |
---|
| 1121 | { |
---|
| 1122 | return xGetSSEw( pcDtParam ); |
---|
| 1123 | } |
---|
| 1124 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1125 | Pel* piCur = pcDtParam->pCur; |
---|
| 1126 | Int iRows = pcDtParam->iRows; |
---|
| 1127 | Int iCols = pcDtParam->iCols; |
---|
| 1128 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1129 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1130 | |
---|
[313] | 1131 | UInt uiSum = 0; |
---|
| 1132 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
| 1133 | Int iTemp; |
---|
[494] | 1134 | |
---|
[313] | 1135 | for( ; iRows != 0; iRows-- ) |
---|
| 1136 | { |
---|
| 1137 | for (Int n = 0; n < iCols; n+=16 ) |
---|
| 1138 | { |
---|
[494] | 1139 | |
---|
[313] | 1140 | iTemp = piOrg[n+ 0] - piCur[n+ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1141 | iTemp = piOrg[n+ 1] - piCur[n+ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1142 | iTemp = piOrg[n+ 2] - piCur[n+ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1143 | iTemp = piOrg[n+ 3] - piCur[n+ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1144 | iTemp = piOrg[n+ 4] - piCur[n+ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1145 | iTemp = piOrg[n+ 5] - piCur[n+ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1146 | iTemp = piOrg[n+ 6] - piCur[n+ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1147 | iTemp = piOrg[n+ 7] - piCur[n+ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1148 | iTemp = piOrg[n+ 8] - piCur[n+ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1149 | iTemp = piOrg[n+ 9] - piCur[n+ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1150 | iTemp = piOrg[n+10] - piCur[n+10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1151 | iTemp = piOrg[n+11] - piCur[n+11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1152 | iTemp = piOrg[n+12] - piCur[n+12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1153 | iTemp = piOrg[n+13] - piCur[n+13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1154 | iTemp = piOrg[n+14] - piCur[n+14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1155 | iTemp = piOrg[n+15] - piCur[n+15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1156 | |
---|
[313] | 1157 | } |
---|
| 1158 | piOrg += iStrideOrg; |
---|
| 1159 | piCur += iStrideCur; |
---|
| 1160 | } |
---|
[494] | 1161 | |
---|
[313] | 1162 | return ( uiSum ); |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | UInt TComRdCost::xGetSSE32( DistParam* pcDtParam ) |
---|
| 1166 | { |
---|
| 1167 | if ( pcDtParam->bApplyWeight ) |
---|
| 1168 | { |
---|
| 1169 | assert( pcDtParam->iCols == 32 ); |
---|
| 1170 | return xGetSSEw( pcDtParam ); |
---|
| 1171 | } |
---|
| 1172 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1173 | Pel* piCur = pcDtParam->pCur; |
---|
| 1174 | Int iRows = pcDtParam->iRows; |
---|
| 1175 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1176 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1177 | |
---|
[313] | 1178 | UInt uiSum = 0; |
---|
| 1179 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
| 1180 | Int iTemp; |
---|
[494] | 1181 | |
---|
[313] | 1182 | for( ; iRows != 0; iRows-- ) |
---|
| 1183 | { |
---|
[494] | 1184 | |
---|
[313] | 1185 | iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1186 | iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1187 | iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1188 | iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1189 | iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1190 | iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1191 | iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1192 | iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1193 | iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1194 | iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1195 | iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1196 | iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1197 | iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1198 | iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1199 | iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1200 | iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1201 | iTemp = piOrg[16] - piCur[16]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1202 | iTemp = piOrg[17] - piCur[17]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1203 | iTemp = piOrg[18] - piCur[18]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1204 | iTemp = piOrg[19] - piCur[19]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1205 | iTemp = piOrg[20] - piCur[20]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1206 | iTemp = piOrg[21] - piCur[21]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1207 | iTemp = piOrg[22] - piCur[22]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1208 | iTemp = piOrg[23] - piCur[23]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1209 | iTemp = piOrg[24] - piCur[24]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1210 | iTemp = piOrg[25] - piCur[25]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1211 | iTemp = piOrg[26] - piCur[26]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1212 | iTemp = piOrg[27] - piCur[27]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1213 | iTemp = piOrg[28] - piCur[28]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1214 | iTemp = piOrg[29] - piCur[29]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1215 | iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1216 | iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1217 | |
---|
[313] | 1218 | piOrg += iStrideOrg; |
---|
| 1219 | piCur += iStrideCur; |
---|
| 1220 | } |
---|
[494] | 1221 | |
---|
[313] | 1222 | return ( uiSum ); |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | UInt TComRdCost::xGetSSE64( DistParam* pcDtParam ) |
---|
| 1226 | { |
---|
| 1227 | if ( pcDtParam->bApplyWeight ) |
---|
| 1228 | { |
---|
| 1229 | assert( pcDtParam->iCols == 64 ); |
---|
| 1230 | return xGetSSEw( pcDtParam ); |
---|
| 1231 | } |
---|
| 1232 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1233 | Pel* piCur = pcDtParam->pCur; |
---|
| 1234 | Int iRows = pcDtParam->iRows; |
---|
| 1235 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1236 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
[494] | 1237 | |
---|
[313] | 1238 | UInt uiSum = 0; |
---|
| 1239 | UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
| 1240 | Int iTemp; |
---|
[494] | 1241 | |
---|
[313] | 1242 | for( ; iRows != 0; iRows-- ) |
---|
| 1243 | { |
---|
| 1244 | iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1245 | iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1246 | iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1247 | iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1248 | iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1249 | iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1250 | iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1251 | iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1252 | iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1253 | iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1254 | iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1255 | iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1256 | iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1257 | iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1258 | iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1259 | iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1260 | iTemp = piOrg[16] - piCur[16]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1261 | iTemp = piOrg[17] - piCur[17]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1262 | iTemp = piOrg[18] - piCur[18]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1263 | iTemp = piOrg[19] - piCur[19]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1264 | iTemp = piOrg[20] - piCur[20]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1265 | iTemp = piOrg[21] - piCur[21]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1266 | iTemp = piOrg[22] - piCur[22]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1267 | iTemp = piOrg[23] - piCur[23]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1268 | iTemp = piOrg[24] - piCur[24]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1269 | iTemp = piOrg[25] - piCur[25]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1270 | iTemp = piOrg[26] - piCur[26]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1271 | iTemp = piOrg[27] - piCur[27]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1272 | iTemp = piOrg[28] - piCur[28]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1273 | iTemp = piOrg[29] - piCur[29]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1274 | iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1275 | iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1276 | iTemp = piOrg[32] - piCur[32]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1277 | iTemp = piOrg[33] - piCur[33]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1278 | iTemp = piOrg[34] - piCur[34]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1279 | iTemp = piOrg[35] - piCur[35]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1280 | iTemp = piOrg[36] - piCur[36]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1281 | iTemp = piOrg[37] - piCur[37]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1282 | iTemp = piOrg[38] - piCur[38]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1283 | iTemp = piOrg[39] - piCur[39]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1284 | iTemp = piOrg[40] - piCur[40]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1285 | iTemp = piOrg[41] - piCur[41]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1286 | iTemp = piOrg[42] - piCur[42]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1287 | iTemp = piOrg[43] - piCur[43]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1288 | iTemp = piOrg[44] - piCur[44]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1289 | iTemp = piOrg[45] - piCur[45]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1290 | iTemp = piOrg[46] - piCur[46]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1291 | iTemp = piOrg[47] - piCur[47]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1292 | iTemp = piOrg[48] - piCur[48]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1293 | iTemp = piOrg[49] - piCur[49]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1294 | iTemp = piOrg[50] - piCur[50]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1295 | iTemp = piOrg[51] - piCur[51]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1296 | iTemp = piOrg[52] - piCur[52]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1297 | iTemp = piOrg[53] - piCur[53]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1298 | iTemp = piOrg[54] - piCur[54]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1299 | iTemp = piOrg[55] - piCur[55]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1300 | iTemp = piOrg[56] - piCur[56]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1301 | iTemp = piOrg[57] - piCur[57]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1302 | iTemp = piOrg[58] - piCur[58]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1303 | iTemp = piOrg[59] - piCur[59]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1304 | iTemp = piOrg[60] - piCur[60]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1305 | iTemp = piOrg[61] - piCur[61]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1306 | iTemp = piOrg[62] - piCur[62]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
| 1307 | iTemp = piOrg[63] - piCur[63]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
[494] | 1308 | |
---|
[313] | 1309 | piOrg += iStrideOrg; |
---|
| 1310 | piCur += iStrideCur; |
---|
| 1311 | } |
---|
[494] | 1312 | |
---|
[313] | 1313 | return ( uiSum ); |
---|
| 1314 | } |
---|
| 1315 | |
---|
| 1316 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 1317 | // HADAMARD with step (used in fractional search) |
---|
| 1318 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 1319 | |
---|
| 1320 | UInt TComRdCost::xCalcHADs2x2( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
| 1321 | { |
---|
| 1322 | Int satd = 0, diff[4], m[4]; |
---|
| 1323 | assert( iStep == 1 ); |
---|
| 1324 | diff[0] = piOrg[0 ] - piCur[0]; |
---|
| 1325 | diff[1] = piOrg[1 ] - piCur[1]; |
---|
| 1326 | diff[2] = piOrg[iStrideOrg ] - piCur[0 + iStrideCur]; |
---|
| 1327 | diff[3] = piOrg[iStrideOrg + 1] - piCur[1 + iStrideCur]; |
---|
| 1328 | m[0] = diff[0] + diff[2]; |
---|
| 1329 | m[1] = diff[1] + diff[3]; |
---|
| 1330 | m[2] = diff[0] - diff[2]; |
---|
| 1331 | m[3] = diff[1] - diff[3]; |
---|
[494] | 1332 | |
---|
[313] | 1333 | satd += abs(m[0] + m[1]); |
---|
| 1334 | satd += abs(m[0] - m[1]); |
---|
| 1335 | satd += abs(m[2] + m[3]); |
---|
| 1336 | satd += abs(m[2] - m[3]); |
---|
[494] | 1337 | |
---|
[313] | 1338 | return satd; |
---|
| 1339 | } |
---|
| 1340 | |
---|
| 1341 | UInt TComRdCost::xCalcHADs4x4( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
| 1342 | { |
---|
| 1343 | Int k, satd = 0, diff[16], m[16], d[16]; |
---|
[494] | 1344 | |
---|
[313] | 1345 | assert( iStep == 1 ); |
---|
| 1346 | for( k = 0; k < 16; k+=4 ) |
---|
| 1347 | { |
---|
| 1348 | diff[k+0] = piOrg[0] - piCur[0]; |
---|
| 1349 | diff[k+1] = piOrg[1] - piCur[1]; |
---|
| 1350 | diff[k+2] = piOrg[2] - piCur[2]; |
---|
| 1351 | diff[k+3] = piOrg[3] - piCur[3]; |
---|
[494] | 1352 | |
---|
[313] | 1353 | piCur += iStrideCur; |
---|
| 1354 | piOrg += iStrideOrg; |
---|
| 1355 | } |
---|
[494] | 1356 | |
---|
[313] | 1357 | /*===== hadamard transform =====*/ |
---|
| 1358 | m[ 0] = diff[ 0] + diff[12]; |
---|
| 1359 | m[ 1] = diff[ 1] + diff[13]; |
---|
| 1360 | m[ 2] = diff[ 2] + diff[14]; |
---|
| 1361 | m[ 3] = diff[ 3] + diff[15]; |
---|
| 1362 | m[ 4] = diff[ 4] + diff[ 8]; |
---|
| 1363 | m[ 5] = diff[ 5] + diff[ 9]; |
---|
| 1364 | m[ 6] = diff[ 6] + diff[10]; |
---|
| 1365 | m[ 7] = diff[ 7] + diff[11]; |
---|
| 1366 | m[ 8] = diff[ 4] - diff[ 8]; |
---|
| 1367 | m[ 9] = diff[ 5] - diff[ 9]; |
---|
| 1368 | m[10] = diff[ 6] - diff[10]; |
---|
| 1369 | m[11] = diff[ 7] - diff[11]; |
---|
| 1370 | m[12] = diff[ 0] - diff[12]; |
---|
| 1371 | m[13] = diff[ 1] - diff[13]; |
---|
| 1372 | m[14] = diff[ 2] - diff[14]; |
---|
| 1373 | m[15] = diff[ 3] - diff[15]; |
---|
[494] | 1374 | |
---|
[313] | 1375 | d[ 0] = m[ 0] + m[ 4]; |
---|
| 1376 | d[ 1] = m[ 1] + m[ 5]; |
---|
| 1377 | d[ 2] = m[ 2] + m[ 6]; |
---|
| 1378 | d[ 3] = m[ 3] + m[ 7]; |
---|
| 1379 | d[ 4] = m[ 8] + m[12]; |
---|
| 1380 | d[ 5] = m[ 9] + m[13]; |
---|
| 1381 | d[ 6] = m[10] + m[14]; |
---|
| 1382 | d[ 7] = m[11] + m[15]; |
---|
| 1383 | d[ 8] = m[ 0] - m[ 4]; |
---|
| 1384 | d[ 9] = m[ 1] - m[ 5]; |
---|
| 1385 | d[10] = m[ 2] - m[ 6]; |
---|
| 1386 | d[11] = m[ 3] - m[ 7]; |
---|
| 1387 | d[12] = m[12] - m[ 8]; |
---|
| 1388 | d[13] = m[13] - m[ 9]; |
---|
| 1389 | d[14] = m[14] - m[10]; |
---|
| 1390 | d[15] = m[15] - m[11]; |
---|
[494] | 1391 | |
---|
[313] | 1392 | m[ 0] = d[ 0] + d[ 3]; |
---|
| 1393 | m[ 1] = d[ 1] + d[ 2]; |
---|
| 1394 | m[ 2] = d[ 1] - d[ 2]; |
---|
| 1395 | m[ 3] = d[ 0] - d[ 3]; |
---|
| 1396 | m[ 4] = d[ 4] + d[ 7]; |
---|
| 1397 | m[ 5] = d[ 5] + d[ 6]; |
---|
| 1398 | m[ 6] = d[ 5] - d[ 6]; |
---|
| 1399 | m[ 7] = d[ 4] - d[ 7]; |
---|
| 1400 | m[ 8] = d[ 8] + d[11]; |
---|
| 1401 | m[ 9] = d[ 9] + d[10]; |
---|
| 1402 | m[10] = d[ 9] - d[10]; |
---|
| 1403 | m[11] = d[ 8] - d[11]; |
---|
| 1404 | m[12] = d[12] + d[15]; |
---|
| 1405 | m[13] = d[13] + d[14]; |
---|
| 1406 | m[14] = d[13] - d[14]; |
---|
| 1407 | m[15] = d[12] - d[15]; |
---|
[494] | 1408 | |
---|
[313] | 1409 | d[ 0] = m[ 0] + m[ 1]; |
---|
| 1410 | d[ 1] = m[ 0] - m[ 1]; |
---|
| 1411 | d[ 2] = m[ 2] + m[ 3]; |
---|
| 1412 | d[ 3] = m[ 3] - m[ 2]; |
---|
| 1413 | d[ 4] = m[ 4] + m[ 5]; |
---|
| 1414 | d[ 5] = m[ 4] - m[ 5]; |
---|
| 1415 | d[ 6] = m[ 6] + m[ 7]; |
---|
| 1416 | d[ 7] = m[ 7] - m[ 6]; |
---|
| 1417 | d[ 8] = m[ 8] + m[ 9]; |
---|
| 1418 | d[ 9] = m[ 8] - m[ 9]; |
---|
| 1419 | d[10] = m[10] + m[11]; |
---|
| 1420 | d[11] = m[11] - m[10]; |
---|
| 1421 | d[12] = m[12] + m[13]; |
---|
| 1422 | d[13] = m[12] - m[13]; |
---|
| 1423 | d[14] = m[14] + m[15]; |
---|
| 1424 | d[15] = m[15] - m[14]; |
---|
[494] | 1425 | |
---|
[313] | 1426 | for (k=0; k<16; ++k) |
---|
| 1427 | { |
---|
| 1428 | satd += abs(d[k]); |
---|
| 1429 | } |
---|
| 1430 | satd = ((satd+1)>>1); |
---|
[494] | 1431 | |
---|
[313] | 1432 | return satd; |
---|
| 1433 | } |
---|
| 1434 | |
---|
| 1435 | UInt TComRdCost::xCalcHADs8x8( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
| 1436 | { |
---|
| 1437 | Int k, i, j, jj, sad=0; |
---|
| 1438 | Int diff[64], m1[8][8], m2[8][8], m3[8][8]; |
---|
| 1439 | assert( iStep == 1 ); |
---|
| 1440 | for( k = 0; k < 64; k += 8 ) |
---|
| 1441 | { |
---|
| 1442 | diff[k+0] = piOrg[0] - piCur[0]; |
---|
| 1443 | diff[k+1] = piOrg[1] - piCur[1]; |
---|
| 1444 | diff[k+2] = piOrg[2] - piCur[2]; |
---|
| 1445 | diff[k+3] = piOrg[3] - piCur[3]; |
---|
| 1446 | diff[k+4] = piOrg[4] - piCur[4]; |
---|
| 1447 | diff[k+5] = piOrg[5] - piCur[5]; |
---|
| 1448 | diff[k+6] = piOrg[6] - piCur[6]; |
---|
| 1449 | diff[k+7] = piOrg[7] - piCur[7]; |
---|
[494] | 1450 | |
---|
[313] | 1451 | piCur += iStrideCur; |
---|
| 1452 | piOrg += iStrideOrg; |
---|
| 1453 | } |
---|
[494] | 1454 | |
---|
[313] | 1455 | //horizontal |
---|
| 1456 | for (j=0; j < 8; j++) |
---|
| 1457 | { |
---|
| 1458 | jj = j << 3; |
---|
| 1459 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 1460 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 1461 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 1462 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 1463 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 1464 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 1465 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 1466 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
[494] | 1467 | |
---|
[313] | 1468 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 1469 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 1470 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 1471 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 1472 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 1473 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 1474 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 1475 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
[494] | 1476 | |
---|
[313] | 1477 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 1478 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 1479 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 1480 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 1481 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 1482 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 1483 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 1484 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 1485 | } |
---|
[494] | 1486 | |
---|
[313] | 1487 | //vertical |
---|
| 1488 | for (i=0; i < 8; i++) |
---|
| 1489 | { |
---|
| 1490 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 1491 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 1492 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 1493 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 1494 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 1495 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 1496 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 1497 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
[494] | 1498 | |
---|
[313] | 1499 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 1500 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 1501 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 1502 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 1503 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 1504 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 1505 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 1506 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
[494] | 1507 | |
---|
[313] | 1508 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 1509 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 1510 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 1511 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 1512 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 1513 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 1514 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 1515 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 1516 | } |
---|
[494] | 1517 | |
---|
[313] | 1518 | for (i = 0; i < 8; i++) |
---|
| 1519 | { |
---|
| 1520 | for (j = 0; j < 8; j++) |
---|
| 1521 | { |
---|
| 1522 | sad += abs(m2[i][j]); |
---|
| 1523 | } |
---|
| 1524 | } |
---|
[494] | 1525 | |
---|
[313] | 1526 | sad=((sad+2)>>2); |
---|
[494] | 1527 | |
---|
[313] | 1528 | return sad; |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | UInt TComRdCost::xGetHADs4( DistParam* pcDtParam ) |
---|
| 1532 | { |
---|
| 1533 | if ( pcDtParam->bApplyWeight ) |
---|
| 1534 | { |
---|
| 1535 | return xGetHADs4w( pcDtParam ); |
---|
| 1536 | } |
---|
| 1537 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1538 | Pel* piCur = pcDtParam->pCur; |
---|
| 1539 | Int iRows = pcDtParam->iRows; |
---|
| 1540 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 1541 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1542 | Int iStep = pcDtParam->iStep; |
---|
| 1543 | Int y; |
---|
| 1544 | Int iOffsetOrg = iStrideOrg<<2; |
---|
| 1545 | Int iOffsetCur = iStrideCur<<2; |
---|
[494] | 1546 | |
---|
[313] | 1547 | UInt uiSum = 0; |
---|
[494] | 1548 | |
---|
[313] | 1549 | for ( y=0; y<iRows; y+= 4 ) |
---|
| 1550 | { |
---|
| 1551 | uiSum += xCalcHADs4x4( piOrg, piCur, iStrideOrg, iStrideCur, iStep ); |
---|
| 1552 | piOrg += iOffsetOrg; |
---|
| 1553 | piCur += iOffsetCur; |
---|
| 1554 | } |
---|
[494] | 1555 | |
---|
[313] | 1556 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | UInt TComRdCost::xGetHADs8( DistParam* pcDtParam ) |
---|
| 1560 | { |
---|
| 1561 | if ( pcDtParam->bApplyWeight ) |
---|
| 1562 | { |
---|
| 1563 | return xGetHADs8w( pcDtParam ); |
---|
| 1564 | } |
---|
| 1565 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1566 | Pel* piCur = pcDtParam->pCur; |
---|
| 1567 | Int iRows = pcDtParam->iRows; |
---|
| 1568 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 1569 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1570 | Int iStep = pcDtParam->iStep; |
---|
| 1571 | Int y; |
---|
[494] | 1572 | |
---|
[313] | 1573 | UInt uiSum = 0; |
---|
[494] | 1574 | |
---|
[313] | 1575 | if ( iRows == 4 ) |
---|
| 1576 | { |
---|
| 1577 | uiSum += xCalcHADs4x4( piOrg+0, piCur , iStrideOrg, iStrideCur, iStep ); |
---|
| 1578 | uiSum += xCalcHADs4x4( piOrg+4, piCur+4*iStep, iStrideOrg, iStrideCur, iStep ); |
---|
| 1579 | } |
---|
| 1580 | else |
---|
| 1581 | { |
---|
| 1582 | Int iOffsetOrg = iStrideOrg<<3; |
---|
| 1583 | Int iOffsetCur = iStrideCur<<3; |
---|
| 1584 | for ( y=0; y<iRows; y+= 8 ) |
---|
| 1585 | { |
---|
| 1586 | uiSum += xCalcHADs8x8( piOrg, piCur, iStrideOrg, iStrideCur, iStep ); |
---|
| 1587 | piOrg += iOffsetOrg; |
---|
| 1588 | piCur += iOffsetCur; |
---|
| 1589 | } |
---|
| 1590 | } |
---|
[494] | 1591 | |
---|
[313] | 1592 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | UInt TComRdCost::xGetHADs( DistParam* pcDtParam ) |
---|
| 1596 | { |
---|
| 1597 | if ( pcDtParam->bApplyWeight ) |
---|
| 1598 | { |
---|
| 1599 | return xGetHADsw( pcDtParam ); |
---|
| 1600 | } |
---|
| 1601 | Pel* piOrg = pcDtParam->pOrg; |
---|
| 1602 | Pel* piCur = pcDtParam->pCur; |
---|
| 1603 | Int iRows = pcDtParam->iRows; |
---|
| 1604 | Int iCols = pcDtParam->iCols; |
---|
| 1605 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 1606 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 1607 | Int iStep = pcDtParam->iStep; |
---|
[494] | 1608 | |
---|
[313] | 1609 | Int x, y; |
---|
[494] | 1610 | |
---|
[313] | 1611 | UInt uiSum = 0; |
---|
[494] | 1612 | |
---|
[313] | 1613 | if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) |
---|
| 1614 | { |
---|
| 1615 | Int iOffsetOrg = iStrideOrg<<3; |
---|
| 1616 | Int iOffsetCur = iStrideCur<<3; |
---|
| 1617 | for ( y=0; y<iRows; y+= 8 ) |
---|
| 1618 | { |
---|
| 1619 | for ( x=0; x<iCols; x+= 8 ) |
---|
| 1620 | { |
---|
| 1621 | uiSum += xCalcHADs8x8( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
| 1622 | } |
---|
| 1623 | piOrg += iOffsetOrg; |
---|
| 1624 | piCur += iOffsetCur; |
---|
| 1625 | } |
---|
| 1626 | } |
---|
| 1627 | else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) |
---|
| 1628 | { |
---|
| 1629 | Int iOffsetOrg = iStrideOrg<<2; |
---|
| 1630 | Int iOffsetCur = iStrideCur<<2; |
---|
[494] | 1631 | |
---|
[313] | 1632 | for ( y=0; y<iRows; y+= 4 ) |
---|
| 1633 | { |
---|
| 1634 | for ( x=0; x<iCols; x+= 4 ) |
---|
| 1635 | { |
---|
| 1636 | uiSum += xCalcHADs4x4( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
| 1637 | } |
---|
| 1638 | piOrg += iOffsetOrg; |
---|
| 1639 | piCur += iOffsetCur; |
---|
| 1640 | } |
---|
| 1641 | } |
---|
| 1642 | else if( ( iRows % 2 == 0) && (iCols % 2 == 0) ) |
---|
| 1643 | { |
---|
| 1644 | Int iOffsetOrg = iStrideOrg<<1; |
---|
| 1645 | Int iOffsetCur = iStrideCur<<1; |
---|
| 1646 | for ( y=0; y<iRows; y+=2 ) |
---|
| 1647 | { |
---|
| 1648 | for ( x=0; x<iCols; x+=2 ) |
---|
| 1649 | { |
---|
| 1650 | uiSum += xCalcHADs2x2( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
| 1651 | } |
---|
| 1652 | piOrg += iOffsetOrg; |
---|
| 1653 | piCur += iOffsetCur; |
---|
| 1654 | } |
---|
| 1655 | } |
---|
| 1656 | else |
---|
| 1657 | { |
---|
| 1658 | assert(false); |
---|
| 1659 | } |
---|
[494] | 1660 | |
---|
[313] | 1661 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 1662 | } |
---|
| 1663 | |
---|
| 1664 | //! \} |
---|