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