[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[1313] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1412] | 6 | * Copyright (c) 2010-2017, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TComRdCostWeightPrediction.cpp |
---|
| 35 | \brief RD cost computation class with Weighted-Prediction |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <math.h> |
---|
| 39 | #include <assert.h> |
---|
| 40 | #include "TComRdCost.h" |
---|
| 41 | #include "TComRdCostWeightPrediction.h" |
---|
| 42 | |
---|
[1313] | 43 | static Distortion xCalcHADs2x2w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
| 44 | static Distortion xCalcHADs4x4w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
| 45 | static Distortion xCalcHADs8x8w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); |
---|
[2] | 46 | |
---|
| 47 | |
---|
| 48 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 49 | // SAD |
---|
| 50 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[56] | 51 | /** get weighted SAD cost |
---|
| 52 | * \param pcDtParam |
---|
[1313] | 53 | * \returns Distortion |
---|
[56] | 54 | */ |
---|
[1313] | 55 | Distortion TComRdCostWeightPrediction::xGetSADw( DistParam* pcDtParam ) |
---|
[2] | 56 | { |
---|
[1313] | 57 | const Pel *piOrg = pcDtParam->pOrg; |
---|
| 58 | const Pel *piCur = pcDtParam->pCur; |
---|
| 59 | const Int iCols = pcDtParam->iCols; |
---|
| 60 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 61 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 62 | const ComponentID compID = pcDtParam->compIdx; |
---|
[2] | 63 | |
---|
[1313] | 64 | assert(compID<MAX_NUM_COMPONENT); |
---|
| 65 | |
---|
| 66 | const WPScalingParam &wpCur = pcDtParam->wpCur[compID]; |
---|
| 67 | |
---|
| 68 | const Int w0 = wpCur.w; |
---|
| 69 | const Int offset = wpCur.offset; |
---|
| 70 | const Int shift = wpCur.shift; |
---|
| 71 | const Int round = wpCur.round; |
---|
[1386] | 72 | const Int distortionShift = DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
[1313] | 73 | |
---|
| 74 | Distortion uiSum = 0; |
---|
| 75 | |
---|
[1386] | 76 | // Default weight |
---|
| 77 | if (w0 == 1 << shift) |
---|
| 78 | { |
---|
| 79 | // no offset |
---|
| 80 | if (offset == 0) |
---|
| 81 | { |
---|
| 82 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 83 | { |
---|
| 84 | for (Int n = 0; n < iCols; n++ ) |
---|
| 85 | { |
---|
| 86 | uiSum += abs( piOrg[n] - piCur[n] ); |
---|
| 87 | } |
---|
| 88 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 89 | { |
---|
| 90 | return uiSum >> distortionShift; |
---|
| 91 | } |
---|
| 92 | piOrg += iStrideOrg; |
---|
| 93 | piCur += iStrideCur; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | // Lets not clip for the bipredictive case since clipping should be done after |
---|
| 99 | // combining both elements. Unfortunately the code uses the suboptimal "subtraction" |
---|
| 100 | // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal). |
---|
| 101 | if (pcDtParam->bIsBiPred) |
---|
| 102 | { |
---|
| 103 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 104 | { |
---|
| 105 | for (Int n = 0; n < iCols; n++ ) |
---|
| 106 | { |
---|
| 107 | uiSum += abs( piOrg[n] - (piCur[n] + offset) ); |
---|
| 108 | } |
---|
| 109 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 110 | { |
---|
| 111 | return uiSum >> distortionShift; |
---|
| 112 | } |
---|
[1313] | 113 | |
---|
[1386] | 114 | piOrg += iStrideOrg; |
---|
| 115 | piCur += iStrideCur; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
| 121 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 122 | { |
---|
| 123 | for (Int n = 0; n < iCols; n++ ) |
---|
| 124 | { |
---|
| 125 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (piCur[n] + offset)) ; |
---|
| 126 | |
---|
| 127 | uiSum += abs( piOrg[n] - pred ); |
---|
| 128 | } |
---|
| 129 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 130 | { |
---|
| 131 | return uiSum >> distortionShift; |
---|
| 132 | } |
---|
| 133 | piOrg += iStrideOrg; |
---|
| 134 | piCur += iStrideCur; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
| 141 | // Lets not clip for the bipredictive case since clipping should be done after |
---|
| 142 | // combining both elements. Unfortunately the code uses the suboptimal "subtraction" |
---|
| 143 | // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal). |
---|
| 144 | if (pcDtParam->bIsBiPred) |
---|
| 145 | { |
---|
| 146 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 147 | { |
---|
| 148 | for (Int n = 0; n < iCols; n++ ) |
---|
| 149 | { |
---|
| 150 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 151 | uiSum += abs( piOrg[n] - pred ); |
---|
| 152 | } |
---|
| 153 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 154 | { |
---|
| 155 | return uiSum >> distortionShift; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | piOrg += iStrideOrg; |
---|
| 159 | piCur += iStrideCur; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | else |
---|
| 163 | { |
---|
| 164 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
| 165 | |
---|
| 166 | if (offset == 0) |
---|
| 167 | { |
---|
| 168 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 169 | { |
---|
| 170 | for (Int n = 0; n < iCols; n++ ) |
---|
| 171 | { |
---|
| 172 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ))) ; |
---|
| 173 | |
---|
| 174 | uiSum += abs( piOrg[n] - pred ); |
---|
| 175 | } |
---|
| 176 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 177 | { |
---|
| 178 | return uiSum >> distortionShift; |
---|
| 179 | } |
---|
| 180 | piOrg += iStrideOrg; |
---|
| 181 | piCur += iStrideCur; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
| 186 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
| 187 | { |
---|
| 188 | for (Int n = 0; n < iCols; n++ ) |
---|
| 189 | { |
---|
| 190 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ; |
---|
| 191 | |
---|
| 192 | uiSum += abs( piOrg[n] - pred ); |
---|
| 193 | } |
---|
| 194 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
| 195 | { |
---|
| 196 | return uiSum >> distortionShift; |
---|
| 197 | } |
---|
| 198 | piOrg += iStrideOrg; |
---|
| 199 | piCur += iStrideCur; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | //pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 205 | |
---|
| 206 | return uiSum >> distortionShift; |
---|
[2] | 207 | } |
---|
| 208 | |
---|
[1313] | 209 | |
---|
[2] | 210 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 211 | // SSE |
---|
| 212 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[56] | 213 | /** get weighted SSD cost |
---|
| 214 | * \param pcDtParam |
---|
[1313] | 215 | * \returns Distortion |
---|
[56] | 216 | */ |
---|
[1313] | 217 | Distortion TComRdCostWeightPrediction::xGetSSEw( DistParam* pcDtParam ) |
---|
[2] | 218 | { |
---|
[1313] | 219 | const Pel *piOrg = pcDtParam->pOrg; |
---|
| 220 | const Pel *piCur = pcDtParam->pCur; |
---|
| 221 | const Int iCols = pcDtParam->iCols; |
---|
| 222 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 223 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 224 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
[2] | 225 | |
---|
[1313] | 226 | assert( pcDtParam->iSubShift == 0 ); // NOTE: what is this protecting? |
---|
[2] | 227 | |
---|
[1313] | 228 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
| 229 | const WPScalingParam &wpCur = pcDtParam->wpCur[compIdx]; |
---|
| 230 | const Int w0 = wpCur.w; |
---|
| 231 | const Int offset = wpCur.offset; |
---|
| 232 | const Int shift = wpCur.shift; |
---|
| 233 | const Int round = wpCur.round; |
---|
| 234 | const UInt distortionShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
| 235 | |
---|
| 236 | Distortion sum = 0; |
---|
| 237 | |
---|
[1386] | 238 | if (pcDtParam->bIsBiPred) |
---|
| 239 | { |
---|
| 240 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
| 241 | { |
---|
| 242 | for (Int n = 0; n < iCols; n++ ) |
---|
| 243 | { |
---|
| 244 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 245 | const Pel residual = piOrg[n] - pred; |
---|
| 246 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
| 247 | } |
---|
| 248 | piOrg += iStrideOrg; |
---|
| 249 | piCur += iStrideCur; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | else |
---|
| 253 | { |
---|
| 254 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
[1313] | 255 | |
---|
[1386] | 256 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
| 257 | { |
---|
| 258 | for (Int n = 0; n < iCols; n++ ) |
---|
| 259 | { |
---|
| 260 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ; |
---|
| 261 | const Pel residual = piOrg[n] - pred; |
---|
| 262 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
| 263 | } |
---|
| 264 | piOrg += iStrideOrg; |
---|
| 265 | piCur += iStrideCur; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | //pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 270 | |
---|
[1313] | 271 | return sum; |
---|
[2] | 272 | } |
---|
| 273 | |
---|
[1313] | 274 | |
---|
[2] | 275 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 276 | // HADAMARD with step (used in fractional search) |
---|
| 277 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[1313] | 278 | //! get weighted Hadamard cost for 2x2 block |
---|
| 279 | Distortion xCalcHADs2x2w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 280 | { |
---|
[1313] | 281 | const Int round = wpCur.round; |
---|
| 282 | const Int shift = wpCur.shift; |
---|
| 283 | const Int offset = wpCur.offset; |
---|
| 284 | const Int w0 = wpCur.w; |
---|
| 285 | |
---|
| 286 | Distortion satd = 0; |
---|
| 287 | TCoeff diff[4]; |
---|
| 288 | TCoeff m[4]; |
---|
| 289 | |
---|
[56] | 290 | Pel pred; |
---|
[2] | 291 | |
---|
[1313] | 292 | pred = ( (w0*piCur[0*iStep ] + round) >> shift ) + offset ; |
---|
[56] | 293 | diff[0] = piOrg[0 ] - pred; |
---|
[1313] | 294 | pred = ( (w0*piCur[1*iStep ] + round) >> shift ) + offset ; |
---|
[56] | 295 | diff[1] = piOrg[1 ] - pred; |
---|
[1313] | 296 | pred = ( (w0*piCur[0*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[56] | 297 | diff[2] = piOrg[iStrideOrg ] - pred; |
---|
[1313] | 298 | pred = ( (w0*piCur[1*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[56] | 299 | diff[3] = piOrg[iStrideOrg + 1] - pred; |
---|
| 300 | |
---|
[2] | 301 | m[0] = diff[0] + diff[2]; |
---|
| 302 | m[1] = diff[1] + diff[3]; |
---|
| 303 | m[2] = diff[0] - diff[2]; |
---|
| 304 | m[3] = diff[1] - diff[3]; |
---|
[1313] | 305 | |
---|
[2] | 306 | satd += abs(m[0] + m[1]); |
---|
| 307 | satd += abs(m[0] - m[1]); |
---|
| 308 | satd += abs(m[2] + m[3]); |
---|
| 309 | satd += abs(m[2] - m[3]); |
---|
[1313] | 310 | |
---|
[2] | 311 | return satd; |
---|
| 312 | } |
---|
| 313 | |
---|
[1313] | 314 | |
---|
| 315 | //! get weighted Hadamard cost for 4x4 block |
---|
| 316 | Distortion xCalcHADs4x4w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 317 | { |
---|
[1313] | 318 | const Int round = wpCur.round; |
---|
| 319 | const Int shift = wpCur.shift; |
---|
| 320 | const Int offset = wpCur.offset; |
---|
| 321 | const Int w0 = wpCur.w; |
---|
[2] | 322 | |
---|
[1313] | 323 | Distortion satd = 0; |
---|
| 324 | TCoeff diff[16]; |
---|
| 325 | TCoeff m[16]; |
---|
| 326 | TCoeff d[16]; |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | for(Int k = 0; k < 16; k+=4 ) |
---|
[2] | 330 | { |
---|
[1313] | 331 | Pel pred; |
---|
| 332 | pred = ( (w0*piCur[0*iStep] + round) >> shift ) + offset ; |
---|
[2] | 333 | diff[k+0] = piOrg[0] - pred; |
---|
[1313] | 334 | pred = ( (w0*piCur[1*iStep] + round) >> shift ) + offset ; |
---|
[2] | 335 | diff[k+1] = piOrg[1] - pred; |
---|
[1313] | 336 | pred = ( (w0*piCur[2*iStep] + round) >> shift ) + offset ; |
---|
[2] | 337 | diff[k+2] = piOrg[2] - pred; |
---|
[1313] | 338 | pred = ( (w0*piCur[3*iStep] + round) >> shift ) + offset ; |
---|
[2] | 339 | diff[k+3] = piOrg[3] - pred; |
---|
| 340 | |
---|
| 341 | piCur += iStrideCur; |
---|
| 342 | piOrg += iStrideOrg; |
---|
| 343 | } |
---|
[1313] | 344 | |
---|
[2] | 345 | /*===== hadamard transform =====*/ |
---|
| 346 | m[ 0] = diff[ 0] + diff[12]; |
---|
| 347 | m[ 1] = diff[ 1] + diff[13]; |
---|
| 348 | m[ 2] = diff[ 2] + diff[14]; |
---|
| 349 | m[ 3] = diff[ 3] + diff[15]; |
---|
| 350 | m[ 4] = diff[ 4] + diff[ 8]; |
---|
| 351 | m[ 5] = diff[ 5] + diff[ 9]; |
---|
| 352 | m[ 6] = diff[ 6] + diff[10]; |
---|
| 353 | m[ 7] = diff[ 7] + diff[11]; |
---|
| 354 | m[ 8] = diff[ 4] - diff[ 8]; |
---|
| 355 | m[ 9] = diff[ 5] - diff[ 9]; |
---|
| 356 | m[10] = diff[ 6] - diff[10]; |
---|
| 357 | m[11] = diff[ 7] - diff[11]; |
---|
| 358 | m[12] = diff[ 0] - diff[12]; |
---|
| 359 | m[13] = diff[ 1] - diff[13]; |
---|
| 360 | m[14] = diff[ 2] - diff[14]; |
---|
| 361 | m[15] = diff[ 3] - diff[15]; |
---|
[1313] | 362 | |
---|
[2] | 363 | d[ 0] = m[ 0] + m[ 4]; |
---|
| 364 | d[ 1] = m[ 1] + m[ 5]; |
---|
| 365 | d[ 2] = m[ 2] + m[ 6]; |
---|
| 366 | d[ 3] = m[ 3] + m[ 7]; |
---|
| 367 | d[ 4] = m[ 8] + m[12]; |
---|
| 368 | d[ 5] = m[ 9] + m[13]; |
---|
| 369 | d[ 6] = m[10] + m[14]; |
---|
| 370 | d[ 7] = m[11] + m[15]; |
---|
| 371 | d[ 8] = m[ 0] - m[ 4]; |
---|
| 372 | d[ 9] = m[ 1] - m[ 5]; |
---|
| 373 | d[10] = m[ 2] - m[ 6]; |
---|
| 374 | d[11] = m[ 3] - m[ 7]; |
---|
| 375 | d[12] = m[12] - m[ 8]; |
---|
| 376 | d[13] = m[13] - m[ 9]; |
---|
| 377 | d[14] = m[14] - m[10]; |
---|
| 378 | d[15] = m[15] - m[11]; |
---|
[1313] | 379 | |
---|
[2] | 380 | m[ 0] = d[ 0] + d[ 3]; |
---|
| 381 | m[ 1] = d[ 1] + d[ 2]; |
---|
| 382 | m[ 2] = d[ 1] - d[ 2]; |
---|
| 383 | m[ 3] = d[ 0] - d[ 3]; |
---|
| 384 | m[ 4] = d[ 4] + d[ 7]; |
---|
| 385 | m[ 5] = d[ 5] + d[ 6]; |
---|
| 386 | m[ 6] = d[ 5] - d[ 6]; |
---|
| 387 | m[ 7] = d[ 4] - d[ 7]; |
---|
| 388 | m[ 8] = d[ 8] + d[11]; |
---|
| 389 | m[ 9] = d[ 9] + d[10]; |
---|
| 390 | m[10] = d[ 9] - d[10]; |
---|
| 391 | m[11] = d[ 8] - d[11]; |
---|
| 392 | m[12] = d[12] + d[15]; |
---|
| 393 | m[13] = d[13] + d[14]; |
---|
| 394 | m[14] = d[13] - d[14]; |
---|
| 395 | m[15] = d[12] - d[15]; |
---|
[1313] | 396 | |
---|
[2] | 397 | d[ 0] = m[ 0] + m[ 1]; |
---|
| 398 | d[ 1] = m[ 0] - m[ 1]; |
---|
| 399 | d[ 2] = m[ 2] + m[ 3]; |
---|
| 400 | d[ 3] = m[ 3] - m[ 2]; |
---|
| 401 | d[ 4] = m[ 4] + m[ 5]; |
---|
| 402 | d[ 5] = m[ 4] - m[ 5]; |
---|
| 403 | d[ 6] = m[ 6] + m[ 7]; |
---|
| 404 | d[ 7] = m[ 7] - m[ 6]; |
---|
| 405 | d[ 8] = m[ 8] + m[ 9]; |
---|
| 406 | d[ 9] = m[ 8] - m[ 9]; |
---|
| 407 | d[10] = m[10] + m[11]; |
---|
| 408 | d[11] = m[11] - m[10]; |
---|
| 409 | d[12] = m[12] + m[13]; |
---|
| 410 | d[13] = m[12] - m[13]; |
---|
| 411 | d[14] = m[14] + m[15]; |
---|
| 412 | d[15] = m[15] - m[14]; |
---|
[1313] | 413 | |
---|
| 414 | for (Int k=0; k<16; ++k) |
---|
[2] | 415 | { |
---|
| 416 | satd += abs(d[k]); |
---|
| 417 | } |
---|
| 418 | satd = ((satd+1)>>1); |
---|
[1313] | 419 | |
---|
[2] | 420 | return satd; |
---|
| 421 | } |
---|
| 422 | |
---|
[1313] | 423 | |
---|
| 424 | //! get weighted Hadamard cost for 8x8 block |
---|
| 425 | Distortion xCalcHADs8x8w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 426 | { |
---|
[1313] | 427 | Distortion sad=0; |
---|
| 428 | TCoeff diff[64], m1[8][8], m2[8][8], m3[8][8]; |
---|
[2] | 429 | Int iStep2 = iStep<<1; |
---|
| 430 | Int iStep3 = iStep2 + iStep; |
---|
| 431 | Int iStep4 = iStep3 + iStep; |
---|
| 432 | Int iStep5 = iStep4 + iStep; |
---|
| 433 | Int iStep6 = iStep5 + iStep; |
---|
| 434 | Int iStep7 = iStep6 + iStep; |
---|
[1313] | 435 | const Int round = wpCur.round; |
---|
| 436 | const Int shift = wpCur.shift; |
---|
| 437 | const Int offset = wpCur.offset; |
---|
| 438 | const Int w0 = wpCur.w; |
---|
| 439 | |
---|
[2] | 440 | Pel pred; |
---|
| 441 | |
---|
[1313] | 442 | for(Int k = 0; k < 64; k+=8 ) |
---|
[2] | 443 | { |
---|
[1313] | 444 | pred = ( (w0*piCur[ 0] + round) >> shift ) + offset ; |
---|
[2] | 445 | diff[k+0] = piOrg[0] - pred; |
---|
[1313] | 446 | pred = ( (w0*piCur[iStep ] + round) >> shift ) + offset ; |
---|
[2] | 447 | diff[k+1] = piOrg[1] - pred; |
---|
[1313] | 448 | pred = ( (w0*piCur[iStep2] + round) >> shift ) + offset ; |
---|
[2] | 449 | diff[k+2] = piOrg[2] - pred; |
---|
[1313] | 450 | pred = ( (w0*piCur[iStep3] + round) >> shift ) + offset ; |
---|
[2] | 451 | diff[k+3] = piOrg[3] - pred; |
---|
[1313] | 452 | pred = ( (w0*piCur[iStep4] + round) >> shift ) + offset ; |
---|
[2] | 453 | diff[k+4] = piOrg[4] - pred; |
---|
[1313] | 454 | pred = ( (w0*piCur[iStep5] + round) >> shift ) + offset ; |
---|
[2] | 455 | diff[k+5] = piOrg[5] - pred; |
---|
[1313] | 456 | pred = ( (w0*piCur[iStep6] + round) >> shift ) + offset ; |
---|
[2] | 457 | diff[k+6] = piOrg[6] - pred; |
---|
[1313] | 458 | pred = ( (w0*piCur[iStep7] + round) >> shift ) + offset ; |
---|
[2] | 459 | diff[k+7] = piOrg[7] - pred; |
---|
[1313] | 460 | |
---|
[2] | 461 | piCur += iStrideCur; |
---|
| 462 | piOrg += iStrideOrg; |
---|
| 463 | } |
---|
[1313] | 464 | |
---|
[2] | 465 | //horizontal |
---|
[1313] | 466 | for (Int j=0; j < 8; j++) |
---|
[2] | 467 | { |
---|
[1313] | 468 | const Int jj = j << 3; |
---|
[2] | 469 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 470 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 471 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 472 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 473 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 474 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 475 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 476 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
[1313] | 477 | |
---|
[2] | 478 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 479 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 480 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 481 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 482 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 483 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 484 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 485 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
[1313] | 486 | |
---|
[2] | 487 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 488 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 489 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 490 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 491 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 492 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 493 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 494 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 495 | } |
---|
[1313] | 496 | |
---|
[2] | 497 | //vertical |
---|
[1313] | 498 | for (Int i=0; i < 8; i++) |
---|
[2] | 499 | { |
---|
| 500 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 501 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 502 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 503 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 504 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 505 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 506 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 507 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
[1313] | 508 | |
---|
[2] | 509 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 510 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 511 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 512 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 513 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 514 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 515 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 516 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
[1313] | 517 | |
---|
[2] | 518 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 519 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 520 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 521 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 522 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 523 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 524 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 525 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 526 | } |
---|
[1313] | 527 | |
---|
| 528 | for (Int j=0; j < 8; j++) |
---|
[2] | 529 | { |
---|
[1313] | 530 | for (Int i=0; i < 8; i++) |
---|
[608] | 531 | { |
---|
[2] | 532 | sad += (abs(m2[j][i])); |
---|
[608] | 533 | } |
---|
[2] | 534 | } |
---|
[1313] | 535 | |
---|
[2] | 536 | sad=((sad+2)>>2); |
---|
[1313] | 537 | |
---|
[2] | 538 | return sad; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | |
---|
[1313] | 542 | //! get weighted Hadamard cost |
---|
| 543 | Distortion TComRdCostWeightPrediction::xGetHADsw( DistParam* pcDtParam ) |
---|
[2] | 544 | { |
---|
[1313] | 545 | const Pel *piOrg = pcDtParam->pOrg; |
---|
| 546 | const Pel *piCur = pcDtParam->pCur; |
---|
| 547 | const Int iRows = pcDtParam->iRows; |
---|
| 548 | const Int iCols = pcDtParam->iCols; |
---|
| 549 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 550 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 551 | const Int iStep = pcDtParam->iStep; |
---|
| 552 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
| 553 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
[1386] | 554 | const WPScalingParam &wpCur = pcDtParam->wpCur[compIdx]; |
---|
[2] | 555 | |
---|
[1313] | 556 | Distortion uiSum = 0; |
---|
[2] | 557 | |
---|
| 558 | if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) |
---|
| 559 | { |
---|
[1313] | 560 | const Int iOffsetOrg = iStrideOrg<<3; |
---|
| 561 | const Int iOffsetCur = iStrideCur<<3; |
---|
| 562 | for (Int y=0; y<iRows; y+= 8 ) |
---|
[2] | 563 | { |
---|
[1313] | 564 | for (Int x=0; x<iCols; x+= 8 ) |
---|
[2] | 565 | { |
---|
[1313] | 566 | uiSum += xCalcHADs8x8w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 567 | } |
---|
| 568 | piOrg += iOffsetOrg; |
---|
| 569 | piCur += iOffsetCur; |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) |
---|
| 573 | { |
---|
[1313] | 574 | const Int iOffsetOrg = iStrideOrg<<2; |
---|
| 575 | const Int iOffsetCur = iStrideCur<<2; |
---|
| 576 | |
---|
| 577 | for (Int y=0; y<iRows; y+= 4 ) |
---|
[2] | 578 | { |
---|
[1313] | 579 | for (Int x=0; x<iCols; x+= 4 ) |
---|
[2] | 580 | { |
---|
[1313] | 581 | uiSum += xCalcHADs4x4w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 582 | } |
---|
| 583 | piOrg += iOffsetOrg; |
---|
| 584 | piCur += iOffsetCur; |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | else |
---|
| 588 | { |
---|
[1313] | 589 | for (Int y=0; y<iRows; y+=2 ) |
---|
[2] | 590 | { |
---|
[1313] | 591 | for (Int x=0; x<iCols; x+=2 ) |
---|
[2] | 592 | { |
---|
[1313] | 593 | uiSum += xCalcHADs2x2w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 594 | } |
---|
| 595 | piOrg += iStrideOrg; |
---|
| 596 | piCur += iStrideCur; |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | |
---|
[608] | 600 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
[2] | 601 | } |
---|