[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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, 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 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 | |
---|
[1029] | 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 ); |
---|
[313] | 46 | |
---|
| 47 | |
---|
| 48 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 49 | // SAD |
---|
| 50 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 51 | /** get weighted SAD cost |
---|
| 52 | * \param pcDtParam |
---|
[1029] | 53 | * \returns Distortion |
---|
[313] | 54 | */ |
---|
[1029] | 55 | Distortion TComRdCostWeightPrediction::xGetSADw( DistParam* pcDtParam ) |
---|
[313] | 56 | { |
---|
[1029] | 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; |
---|
[313] | 63 | |
---|
[1029] | 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-- ) |
---|
[313] | 76 | { |
---|
| 77 | for (Int n = 0; n < iCols; n++ ) |
---|
| 78 | { |
---|
[1029] | 79 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 80 | |
---|
[313] | 81 | uiSum += abs( piOrg[n] - pred ); |
---|
| 82 | } |
---|
| 83 | piOrg += iStrideOrg; |
---|
| 84 | piCur += iStrideCur; |
---|
| 85 | } |
---|
| 86 | |
---|
[1029] | 87 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 88 | |
---|
[313] | 89 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 90 | } |
---|
| 91 | |
---|
[1029] | 92 | |
---|
[313] | 93 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 94 | // SSE |
---|
| 95 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 96 | /** get weighted SSD cost |
---|
| 97 | * \param pcDtParam |
---|
[1029] | 98 | * \returns Distortion |
---|
[313] | 99 | */ |
---|
[1029] | 100 | Distortion TComRdCostWeightPrediction::xGetSSEw( DistParam* pcDtParam ) |
---|
[313] | 101 | { |
---|
[1029] | 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; |
---|
[313] | 108 | |
---|
[1029] | 109 | assert( pcDtParam->iSubShift == 0 ); // NOTE: what is this protecting? |
---|
[313] | 110 | |
---|
[1029] | 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-- ) |
---|
[313] | 122 | { |
---|
| 123 | for (Int n = 0; n < iCols; n++ ) |
---|
| 124 | { |
---|
[1029] | 125 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
| 126 | const Pel residual = piOrg[n] - pred; |
---|
| 127 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
[313] | 128 | } |
---|
| 129 | piOrg += iStrideOrg; |
---|
| 130 | piCur += iStrideCur; |
---|
| 131 | } |
---|
| 132 | |
---|
[1029] | 133 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
| 134 | |
---|
| 135 | return sum; |
---|
[313] | 136 | } |
---|
| 137 | |
---|
[1029] | 138 | |
---|
[313] | 139 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 140 | // HADAMARD with step (used in fractional search) |
---|
| 141 | // -------------------------------------------------------------------------------------------------------------------- |
---|
[1258] | 142 | //! get weighted Hadamard cost for 2x2 block |
---|
[1029] | 143 | Distortion xCalcHADs2x2w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[313] | 144 | { |
---|
[1029] | 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 | |
---|
[313] | 154 | Pel pred; |
---|
| 155 | |
---|
[1029] | 156 | pred = ( (w0*piCur[0*iStep ] + round) >> shift ) + offset ; |
---|
[313] | 157 | diff[0] = piOrg[0 ] - pred; |
---|
[1029] | 158 | pred = ( (w0*piCur[1*iStep ] + round) >> shift ) + offset ; |
---|
[313] | 159 | diff[1] = piOrg[1 ] - pred; |
---|
[1029] | 160 | pred = ( (w0*piCur[0*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[313] | 161 | diff[2] = piOrg[iStrideOrg ] - pred; |
---|
[1029] | 162 | pred = ( (w0*piCur[1*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
[313] | 163 | diff[3] = piOrg[iStrideOrg + 1] - pred; |
---|
| 164 | |
---|
| 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]; |
---|
[1029] | 169 | |
---|
[313] | 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]); |
---|
[1029] | 174 | |
---|
[313] | 175 | return satd; |
---|
| 176 | } |
---|
| 177 | |
---|
[1029] | 178 | |
---|
[1258] | 179 | //! get weighted Hadamard cost for 4x4 block |
---|
[1029] | 180 | Distortion xCalcHADs4x4w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[313] | 181 | { |
---|
[1029] | 182 | const Int round = wpCur.round; |
---|
| 183 | const Int shift = wpCur.shift; |
---|
| 184 | const Int offset = wpCur.offset; |
---|
| 185 | const Int w0 = wpCur.w; |
---|
[313] | 186 | |
---|
[1029] | 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 ) |
---|
[313] | 194 | { |
---|
[1029] | 195 | Pel pred; |
---|
| 196 | pred = ( (w0*piCur[0*iStep] + round) >> shift ) + offset ; |
---|
[313] | 197 | diff[k+0] = piOrg[0] - pred; |
---|
[1029] | 198 | pred = ( (w0*piCur[1*iStep] + round) >> shift ) + offset ; |
---|
[313] | 199 | diff[k+1] = piOrg[1] - pred; |
---|
[1029] | 200 | pred = ( (w0*piCur[2*iStep] + round) >> shift ) + offset ; |
---|
[313] | 201 | diff[k+2] = piOrg[2] - pred; |
---|
[1029] | 202 | pred = ( (w0*piCur[3*iStep] + round) >> shift ) + offset ; |
---|
[313] | 203 | diff[k+3] = piOrg[3] - pred; |
---|
| 204 | |
---|
| 205 | piCur += iStrideCur; |
---|
| 206 | piOrg += iStrideOrg; |
---|
| 207 | } |
---|
[1029] | 208 | |
---|
[313] | 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]; |
---|
[1029] | 226 | |
---|
[313] | 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]; |
---|
[1029] | 243 | |
---|
[313] | 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]; |
---|
[1029] | 260 | |
---|
[313] | 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]; |
---|
[1029] | 277 | |
---|
| 278 | for (Int k=0; k<16; ++k) |
---|
[313] | 279 | { |
---|
| 280 | satd += abs(d[k]); |
---|
| 281 | } |
---|
| 282 | satd = ((satd+1)>>1); |
---|
[1029] | 283 | |
---|
[313] | 284 | return satd; |
---|
| 285 | } |
---|
| 286 | |
---|
[1029] | 287 | |
---|
[1258] | 288 | //! get weighted Hadamard cost for 8x8 block |
---|
[1029] | 289 | Distortion xCalcHADs8x8w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
[313] | 290 | { |
---|
[1029] | 291 | Distortion sad=0; |
---|
| 292 | TCoeff diff[64], m1[8][8], m2[8][8], m3[8][8]; |
---|
[313] | 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; |
---|
[1029] | 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 | |
---|
[313] | 304 | Pel pred; |
---|
| 305 | |
---|
[1029] | 306 | for(Int k = 0; k < 64; k+=8 ) |
---|
[313] | 307 | { |
---|
[1029] | 308 | pred = ( (w0*piCur[ 0] + round) >> shift ) + offset ; |
---|
[313] | 309 | diff[k+0] = piOrg[0] - pred; |
---|
[1029] | 310 | pred = ( (w0*piCur[iStep ] + round) >> shift ) + offset ; |
---|
[313] | 311 | diff[k+1] = piOrg[1] - pred; |
---|
[1029] | 312 | pred = ( (w0*piCur[iStep2] + round) >> shift ) + offset ; |
---|
[313] | 313 | diff[k+2] = piOrg[2] - pred; |
---|
[1029] | 314 | pred = ( (w0*piCur[iStep3] + round) >> shift ) + offset ; |
---|
[313] | 315 | diff[k+3] = piOrg[3] - pred; |
---|
[1029] | 316 | pred = ( (w0*piCur[iStep4] + round) >> shift ) + offset ; |
---|
[313] | 317 | diff[k+4] = piOrg[4] - pred; |
---|
[1029] | 318 | pred = ( (w0*piCur[iStep5] + round) >> shift ) + offset ; |
---|
[313] | 319 | diff[k+5] = piOrg[5] - pred; |
---|
[1029] | 320 | pred = ( (w0*piCur[iStep6] + round) >> shift ) + offset ; |
---|
[313] | 321 | diff[k+6] = piOrg[6] - pred; |
---|
[1029] | 322 | pred = ( (w0*piCur[iStep7] + round) >> shift ) + offset ; |
---|
[313] | 323 | diff[k+7] = piOrg[7] - pred; |
---|
[1029] | 324 | |
---|
[313] | 325 | piCur += iStrideCur; |
---|
| 326 | piOrg += iStrideOrg; |
---|
| 327 | } |
---|
[1029] | 328 | |
---|
[313] | 329 | //horizontal |
---|
[1029] | 330 | for (Int j=0; j < 8; j++) |
---|
[313] | 331 | { |
---|
[1029] | 332 | const Int jj = j << 3; |
---|
[313] | 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]; |
---|
[1029] | 341 | |
---|
[313] | 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]; |
---|
[1029] | 350 | |
---|
[313] | 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 | } |
---|
[1029] | 360 | |
---|
[313] | 361 | //vertical |
---|
[1029] | 362 | for (Int i=0; i < 8; i++) |
---|
[313] | 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]; |
---|
[1029] | 372 | |
---|
[313] | 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]; |
---|
[1029] | 381 | |
---|
[313] | 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 | } |
---|
[1029] | 391 | |
---|
| 392 | for (Int j=0; j < 8; j++) |
---|
[313] | 393 | { |
---|
[1029] | 394 | for (Int i=0; i < 8; i++) |
---|
[313] | 395 | { |
---|
| 396 | sad += (abs(m2[j][i])); |
---|
| 397 | } |
---|
| 398 | } |
---|
[1029] | 399 | |
---|
[313] | 400 | sad=((sad+2)>>2); |
---|
[1029] | 401 | |
---|
[313] | 402 | return sad; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | |
---|
[1258] | 406 | //! get weighted Hadamard cost |
---|
[1029] | 407 | Distortion TComRdCostWeightPrediction::xGetHADsw( DistParam* pcDtParam ) |
---|
[313] | 408 | { |
---|
[1029] | 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]; |
---|
[313] | 419 | |
---|
[1029] | 420 | Distortion uiSum = 0; |
---|
[313] | 421 | |
---|
| 422 | if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) |
---|
| 423 | { |
---|
[1029] | 424 | const Int iOffsetOrg = iStrideOrg<<3; |
---|
| 425 | const Int iOffsetCur = iStrideCur<<3; |
---|
| 426 | for (Int y=0; y<iRows; y+= 8 ) |
---|
[313] | 427 | { |
---|
[1029] | 428 | for (Int x=0; x<iCols; x+= 8 ) |
---|
[313] | 429 | { |
---|
[1029] | 430 | uiSum += xCalcHADs8x8w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[313] | 431 | } |
---|
| 432 | piOrg += iOffsetOrg; |
---|
| 433 | piCur += iOffsetCur; |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) |
---|
| 437 | { |
---|
[1029] | 438 | const Int iOffsetOrg = iStrideOrg<<2; |
---|
| 439 | const Int iOffsetCur = iStrideCur<<2; |
---|
| 440 | |
---|
| 441 | for (Int y=0; y<iRows; y+= 4 ) |
---|
[313] | 442 | { |
---|
[1029] | 443 | for (Int x=0; x<iCols; x+= 4 ) |
---|
[313] | 444 | { |
---|
[1029] | 445 | uiSum += xCalcHADs4x4w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[313] | 446 | } |
---|
| 447 | piOrg += iOffsetOrg; |
---|
| 448 | piCur += iOffsetCur; |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
[1029] | 453 | for (Int y=0; y<iRows; y+=2 ) |
---|
[313] | 454 | { |
---|
[1029] | 455 | for (Int x=0; x<iCols; x+=2 ) |
---|
[313] | 456 | { |
---|
[1029] | 457 | uiSum += xCalcHADs2x2w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
[313] | 458 | } |
---|
| 459 | piOrg += iStrideOrg; |
---|
| 460 | piCur += iStrideCur; |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
| 465 | } |
---|