[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 | * |
---|
[1313] | 6 | * Copyright (c) 2010-2015, 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; |
---|
| 72 | |
---|
| 73 | Distortion uiSum = 0; |
---|
| 74 | |
---|
| 75 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
[2] | 76 | { |
---|
[608] | 77 | for (Int n = 0; n < iCols; n++ ) |
---|
[2] | 78 | { |
---|
[1313] | 79 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 80 | |
---|
[608] | 81 | uiSum += abs( piOrg[n] - pred ); |
---|
[2] | 82 | } |
---|
[608] | 83 | piOrg += iStrideOrg; |
---|
| 84 | piCur += iStrideCur; |
---|
[2] | 85 | } |
---|
| 86 | |
---|
[1313] | 87 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 88 | |
---|
[608] | 89 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
[2] | 90 | } |
---|
| 91 | |
---|
[1313] | 92 | |
---|
[2] | 93 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 94 | // SSE |
---|
| 95 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[56] | 96 | /** get weighted SSD cost |
---|
| 97 | * \param pcDtParam |
---|
[1313] | 98 | * \returns Distortion |
---|
[56] | 99 | */ |
---|
[1313] | 100 | Distortion TComRdCostWeightPrediction::xGetSSEw( DistParam* pcDtParam ) |
---|
[2] | 101 | { |
---|
[1313] | 102 | const Pel *piOrg = pcDtParam->pOrg; |
---|
| 103 | const Pel *piCur = pcDtParam->pCur; |
---|
| 104 | const Int iCols = pcDtParam->iCols; |
---|
| 105 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 106 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 107 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
[2] | 108 | |
---|
[1313] | 109 | assert( pcDtParam->iSubShift == 0 ); // NOTE: what is this protecting? |
---|
[2] | 110 | |
---|
[1313] | 111 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
| 112 | const WPScalingParam &wpCur = pcDtParam->wpCur[compIdx]; |
---|
| 113 | const Int w0 = wpCur.w; |
---|
| 114 | const Int offset = wpCur.offset; |
---|
| 115 | const Int shift = wpCur.shift; |
---|
| 116 | const Int round = wpCur.round; |
---|
| 117 | const UInt distortionShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
| 118 | |
---|
| 119 | Distortion sum = 0; |
---|
| 120 | |
---|
| 121 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
[2] | 122 | { |
---|
| 123 | for (Int n = 0; n < iCols; n++ ) |
---|
| 124 | { |
---|
[1313] | 125 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 126 | const Pel residual = piOrg[n] - pred; |
---|
| 127 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
[2] | 128 | } |
---|
| 129 | piOrg += iStrideOrg; |
---|
| 130 | piCur += iStrideCur; |
---|
| 131 | } |
---|
| 132 | |
---|
[1313] | 133 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 134 | |
---|
| 135 | return sum; |
---|
[2] | 136 | } |
---|
| 137 | |
---|
[1313] | 138 | |
---|
[2] | 139 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 140 | // HADAMARD with step (used in fractional search) |
---|
| 141 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[1313] | 142 | //! get weighted Hadamard cost for 2x2 block |
---|
| 143 | Distortion xCalcHADs2x2w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 144 | { |
---|
[1313] | 145 | const Int round = wpCur.round; |
---|
| 146 | const Int shift = wpCur.shift; |
---|
| 147 | const Int offset = wpCur.offset; |
---|
| 148 | const Int w0 = wpCur.w; |
---|
| 149 | |
---|
| 150 | Distortion satd = 0; |
---|
| 151 | TCoeff diff[4]; |
---|
| 152 | TCoeff m[4]; |
---|
| 153 | |
---|
[56] | 154 | Pel pred; |
---|
[2] | 155 | |
---|
[1313] | 156 | pred = ( (w0*piCur[0*iStep ] + round) >> shift ) + offset ; |
---|
[56] | 157 | diff[0] = piOrg[0 ] - pred; |
---|
[1313] | 158 | pred = ( (w0*piCur[1*iStep ] + round) >> shift ) + offset ; |
---|
[56] | 159 | diff[1] = piOrg[1 ] - pred; |
---|
[1313] | 160 | pred = ( (w0*piCur[0*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[56] | 161 | diff[2] = piOrg[iStrideOrg ] - pred; |
---|
[1313] | 162 | pred = ( (w0*piCur[1*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[56] | 163 | diff[3] = piOrg[iStrideOrg + 1] - pred; |
---|
| 164 | |
---|
[2] | 165 | m[0] = diff[0] + diff[2]; |
---|
| 166 | m[1] = diff[1] + diff[3]; |
---|
| 167 | m[2] = diff[0] - diff[2]; |
---|
| 168 | m[3] = diff[1] - diff[3]; |
---|
[1313] | 169 | |
---|
[2] | 170 | satd += abs(m[0] + m[1]); |
---|
| 171 | satd += abs(m[0] - m[1]); |
---|
| 172 | satd += abs(m[2] + m[3]); |
---|
| 173 | satd += abs(m[2] - m[3]); |
---|
[1313] | 174 | |
---|
[2] | 175 | return satd; |
---|
| 176 | } |
---|
| 177 | |
---|
[1313] | 178 | |
---|
| 179 | //! get weighted Hadamard cost for 4x4 block |
---|
| 180 | Distortion xCalcHADs4x4w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 181 | { |
---|
[1313] | 182 | const Int round = wpCur.round; |
---|
| 183 | const Int shift = wpCur.shift; |
---|
| 184 | const Int offset = wpCur.offset; |
---|
| 185 | const Int w0 = wpCur.w; |
---|
[2] | 186 | |
---|
[1313] | 187 | Distortion satd = 0; |
---|
| 188 | TCoeff diff[16]; |
---|
| 189 | TCoeff m[16]; |
---|
| 190 | TCoeff d[16]; |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | for(Int k = 0; k < 16; k+=4 ) |
---|
[2] | 194 | { |
---|
[1313] | 195 | Pel pred; |
---|
| 196 | pred = ( (w0*piCur[0*iStep] + round) >> shift ) + offset ; |
---|
[2] | 197 | diff[k+0] = piOrg[0] - pred; |
---|
[1313] | 198 | pred = ( (w0*piCur[1*iStep] + round) >> shift ) + offset ; |
---|
[2] | 199 | diff[k+1] = piOrg[1] - pred; |
---|
[1313] | 200 | pred = ( (w0*piCur[2*iStep] + round) >> shift ) + offset ; |
---|
[2] | 201 | diff[k+2] = piOrg[2] - pred; |
---|
[1313] | 202 | pred = ( (w0*piCur[3*iStep] + round) >> shift ) + offset ; |
---|
[2] | 203 | diff[k+3] = piOrg[3] - pred; |
---|
| 204 | |
---|
| 205 | piCur += iStrideCur; |
---|
| 206 | piOrg += iStrideOrg; |
---|
| 207 | } |
---|
[1313] | 208 | |
---|
[2] | 209 | /*===== hadamard transform =====*/ |
---|
| 210 | m[ 0] = diff[ 0] + diff[12]; |
---|
| 211 | m[ 1] = diff[ 1] + diff[13]; |
---|
| 212 | m[ 2] = diff[ 2] + diff[14]; |
---|
| 213 | m[ 3] = diff[ 3] + diff[15]; |
---|
| 214 | m[ 4] = diff[ 4] + diff[ 8]; |
---|
| 215 | m[ 5] = diff[ 5] + diff[ 9]; |
---|
| 216 | m[ 6] = diff[ 6] + diff[10]; |
---|
| 217 | m[ 7] = diff[ 7] + diff[11]; |
---|
| 218 | m[ 8] = diff[ 4] - diff[ 8]; |
---|
| 219 | m[ 9] = diff[ 5] - diff[ 9]; |
---|
| 220 | m[10] = diff[ 6] - diff[10]; |
---|
| 221 | m[11] = diff[ 7] - diff[11]; |
---|
| 222 | m[12] = diff[ 0] - diff[12]; |
---|
| 223 | m[13] = diff[ 1] - diff[13]; |
---|
| 224 | m[14] = diff[ 2] - diff[14]; |
---|
| 225 | m[15] = diff[ 3] - diff[15]; |
---|
[1313] | 226 | |
---|
[2] | 227 | d[ 0] = m[ 0] + m[ 4]; |
---|
| 228 | d[ 1] = m[ 1] + m[ 5]; |
---|
| 229 | d[ 2] = m[ 2] + m[ 6]; |
---|
| 230 | d[ 3] = m[ 3] + m[ 7]; |
---|
| 231 | d[ 4] = m[ 8] + m[12]; |
---|
| 232 | d[ 5] = m[ 9] + m[13]; |
---|
| 233 | d[ 6] = m[10] + m[14]; |
---|
| 234 | d[ 7] = m[11] + m[15]; |
---|
| 235 | d[ 8] = m[ 0] - m[ 4]; |
---|
| 236 | d[ 9] = m[ 1] - m[ 5]; |
---|
| 237 | d[10] = m[ 2] - m[ 6]; |
---|
| 238 | d[11] = m[ 3] - m[ 7]; |
---|
| 239 | d[12] = m[12] - m[ 8]; |
---|
| 240 | d[13] = m[13] - m[ 9]; |
---|
| 241 | d[14] = m[14] - m[10]; |
---|
| 242 | d[15] = m[15] - m[11]; |
---|
[1313] | 243 | |
---|
[2] | 244 | m[ 0] = d[ 0] + d[ 3]; |
---|
| 245 | m[ 1] = d[ 1] + d[ 2]; |
---|
| 246 | m[ 2] = d[ 1] - d[ 2]; |
---|
| 247 | m[ 3] = d[ 0] - d[ 3]; |
---|
| 248 | m[ 4] = d[ 4] + d[ 7]; |
---|
| 249 | m[ 5] = d[ 5] + d[ 6]; |
---|
| 250 | m[ 6] = d[ 5] - d[ 6]; |
---|
| 251 | m[ 7] = d[ 4] - d[ 7]; |
---|
| 252 | m[ 8] = d[ 8] + d[11]; |
---|
| 253 | m[ 9] = d[ 9] + d[10]; |
---|
| 254 | m[10] = d[ 9] - d[10]; |
---|
| 255 | m[11] = d[ 8] - d[11]; |
---|
| 256 | m[12] = d[12] + d[15]; |
---|
| 257 | m[13] = d[13] + d[14]; |
---|
| 258 | m[14] = d[13] - d[14]; |
---|
| 259 | m[15] = d[12] - d[15]; |
---|
[1313] | 260 | |
---|
[2] | 261 | d[ 0] = m[ 0] + m[ 1]; |
---|
| 262 | d[ 1] = m[ 0] - m[ 1]; |
---|
| 263 | d[ 2] = m[ 2] + m[ 3]; |
---|
| 264 | d[ 3] = m[ 3] - m[ 2]; |
---|
| 265 | d[ 4] = m[ 4] + m[ 5]; |
---|
| 266 | d[ 5] = m[ 4] - m[ 5]; |
---|
| 267 | d[ 6] = m[ 6] + m[ 7]; |
---|
| 268 | d[ 7] = m[ 7] - m[ 6]; |
---|
| 269 | d[ 8] = m[ 8] + m[ 9]; |
---|
| 270 | d[ 9] = m[ 8] - m[ 9]; |
---|
| 271 | d[10] = m[10] + m[11]; |
---|
| 272 | d[11] = m[11] - m[10]; |
---|
| 273 | d[12] = m[12] + m[13]; |
---|
| 274 | d[13] = m[12] - m[13]; |
---|
| 275 | d[14] = m[14] + m[15]; |
---|
| 276 | d[15] = m[15] - m[14]; |
---|
[1313] | 277 | |
---|
| 278 | for (Int k=0; k<16; ++k) |
---|
[2] | 279 | { |
---|
| 280 | satd += abs(d[k]); |
---|
| 281 | } |
---|
| 282 | satd = ((satd+1)>>1); |
---|
[1313] | 283 | |
---|
[2] | 284 | return satd; |
---|
| 285 | } |
---|
| 286 | |
---|
[1313] | 287 | |
---|
| 288 | //! get weighted Hadamard cost for 8x8 block |
---|
| 289 | Distortion xCalcHADs8x8w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[2] | 290 | { |
---|
[1313] | 291 | Distortion sad=0; |
---|
| 292 | TCoeff diff[64], m1[8][8], m2[8][8], m3[8][8]; |
---|
[2] | 293 | Int iStep2 = iStep<<1; |
---|
| 294 | Int iStep3 = iStep2 + iStep; |
---|
| 295 | Int iStep4 = iStep3 + iStep; |
---|
| 296 | Int iStep5 = iStep4 + iStep; |
---|
| 297 | Int iStep6 = iStep5 + iStep; |
---|
| 298 | Int iStep7 = iStep6 + iStep; |
---|
[1313] | 299 | const Int round = wpCur.round; |
---|
| 300 | const Int shift = wpCur.shift; |
---|
| 301 | const Int offset = wpCur.offset; |
---|
| 302 | const Int w0 = wpCur.w; |
---|
| 303 | |
---|
[2] | 304 | Pel pred; |
---|
| 305 | |
---|
[1313] | 306 | for(Int k = 0; k < 64; k+=8 ) |
---|
[2] | 307 | { |
---|
[1313] | 308 | pred = ( (w0*piCur[ 0] + round) >> shift ) + offset ; |
---|
[2] | 309 | diff[k+0] = piOrg[0] - pred; |
---|
[1313] | 310 | pred = ( (w0*piCur[iStep ] + round) >> shift ) + offset ; |
---|
[2] | 311 | diff[k+1] = piOrg[1] - pred; |
---|
[1313] | 312 | pred = ( (w0*piCur[iStep2] + round) >> shift ) + offset ; |
---|
[2] | 313 | diff[k+2] = piOrg[2] - pred; |
---|
[1313] | 314 | pred = ( (w0*piCur[iStep3] + round) >> shift ) + offset ; |
---|
[2] | 315 | diff[k+3] = piOrg[3] - pred; |
---|
[1313] | 316 | pred = ( (w0*piCur[iStep4] + round) >> shift ) + offset ; |
---|
[2] | 317 | diff[k+4] = piOrg[4] - pred; |
---|
[1313] | 318 | pred = ( (w0*piCur[iStep5] + round) >> shift ) + offset ; |
---|
[2] | 319 | diff[k+5] = piOrg[5] - pred; |
---|
[1313] | 320 | pred = ( (w0*piCur[iStep6] + round) >> shift ) + offset ; |
---|
[2] | 321 | diff[k+6] = piOrg[6] - pred; |
---|
[1313] | 322 | pred = ( (w0*piCur[iStep7] + round) >> shift ) + offset ; |
---|
[2] | 323 | diff[k+7] = piOrg[7] - pred; |
---|
[1313] | 324 | |
---|
[2] | 325 | piCur += iStrideCur; |
---|
| 326 | piOrg += iStrideOrg; |
---|
| 327 | } |
---|
[1313] | 328 | |
---|
[2] | 329 | //horizontal |
---|
[1313] | 330 | for (Int j=0; j < 8; j++) |
---|
[2] | 331 | { |
---|
[1313] | 332 | const Int jj = j << 3; |
---|
[2] | 333 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
| 334 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
| 335 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
| 336 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
| 337 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
| 338 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
| 339 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
| 340 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
[1313] | 341 | |
---|
[2] | 342 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
| 343 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
| 344 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
| 345 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
| 346 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
| 347 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
| 348 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
| 349 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
[1313] | 350 | |
---|
[2] | 351 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
| 352 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
| 353 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
| 354 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
| 355 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
| 356 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
| 357 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
| 358 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
| 359 | } |
---|
[1313] | 360 | |
---|
[2] | 361 | //vertical |
---|
[1313] | 362 | for (Int i=0; i < 8; i++) |
---|
[2] | 363 | { |
---|
| 364 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
| 365 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
| 366 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
| 367 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
| 368 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
| 369 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
| 370 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
| 371 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
[1313] | 372 | |
---|
[2] | 373 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
| 374 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
| 375 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
| 376 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
| 377 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
| 378 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
| 379 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
| 380 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
[1313] | 381 | |
---|
[2] | 382 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
| 383 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
| 384 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
| 385 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
| 386 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
| 387 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
| 388 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
| 389 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
| 390 | } |
---|
[1313] | 391 | |
---|
| 392 | for (Int j=0; j < 8; j++) |
---|
[2] | 393 | { |
---|
[1313] | 394 | for (Int i=0; i < 8; i++) |
---|
[608] | 395 | { |
---|
[2] | 396 | sad += (abs(m2[j][i])); |
---|
[608] | 397 | } |
---|
[2] | 398 | } |
---|
[1313] | 399 | |
---|
[2] | 400 | sad=((sad+2)>>2); |
---|
[1313] | 401 | |
---|
[2] | 402 | return sad; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | |
---|
[1313] | 406 | //! get weighted Hadamard cost |
---|
| 407 | Distortion TComRdCostWeightPrediction::xGetHADsw( DistParam* pcDtParam ) |
---|
[2] | 408 | { |
---|
[1313] | 409 | const Pel *piOrg = pcDtParam->pOrg; |
---|
| 410 | const Pel *piCur = pcDtParam->pCur; |
---|
| 411 | const Int iRows = pcDtParam->iRows; |
---|
| 412 | const Int iCols = pcDtParam->iCols; |
---|
| 413 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
| 414 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
| 415 | const Int iStep = pcDtParam->iStep; |
---|
| 416 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
| 417 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
| 418 | const WPScalingParam wpCur = pcDtParam->wpCur[compIdx]; |
---|
[2] | 419 | |
---|
[1313] | 420 | Distortion uiSum = 0; |
---|
[2] | 421 | |
---|
| 422 | if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) |
---|
| 423 | { |
---|
[1313] | 424 | const Int iOffsetOrg = iStrideOrg<<3; |
---|
| 425 | const Int iOffsetCur = iStrideCur<<3; |
---|
| 426 | for (Int y=0; y<iRows; y+= 8 ) |
---|
[2] | 427 | { |
---|
[1313] | 428 | for (Int x=0; x<iCols; x+= 8 ) |
---|
[2] | 429 | { |
---|
[1313] | 430 | uiSum += xCalcHADs8x8w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 431 | } |
---|
| 432 | piOrg += iOffsetOrg; |
---|
| 433 | piCur += iOffsetCur; |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) |
---|
| 437 | { |
---|
[1313] | 438 | const Int iOffsetOrg = iStrideOrg<<2; |
---|
| 439 | const Int iOffsetCur = iStrideCur<<2; |
---|
| 440 | |
---|
| 441 | for (Int y=0; y<iRows; y+= 4 ) |
---|
[2] | 442 | { |
---|
[1313] | 443 | for (Int x=0; x<iCols; x+= 4 ) |
---|
[2] | 444 | { |
---|
[1313] | 445 | uiSum += xCalcHADs4x4w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 446 | } |
---|
| 447 | piOrg += iOffsetOrg; |
---|
| 448 | piCur += iOffsetCur; |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
[1313] | 453 | for (Int y=0; y<iRows; y+=2 ) |
---|
[2] | 454 | { |
---|
[1313] | 455 | for (Int x=0; x<iCols; x+=2 ) |
---|
[2] | 456 | { |
---|
[1313] | 457 | uiSum += xCalcHADs2x2w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[2] | 458 | } |
---|
| 459 | piOrg += iStrideOrg; |
---|
| 460 | piCur += iStrideCur; |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | |
---|
[608] | 464 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
[2] | 465 | } |
---|