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