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-2015, 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 | const Int distortionShift = DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
73 | |
---|
74 | Distortion uiSum = 0; |
---|
75 | |
---|
76 | #if !U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING |
---|
77 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
78 | { |
---|
79 | for (Int n = 0; n < iCols; n++ ) |
---|
80 | { |
---|
81 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
82 | |
---|
83 | uiSum += abs( piOrg[n] - pred ); |
---|
84 | } |
---|
85 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
86 | { |
---|
87 | return uiSum >> distortionShift; |
---|
88 | } |
---|
89 | piOrg += iStrideOrg; |
---|
90 | piCur += iStrideCur; |
---|
91 | } |
---|
92 | |
---|
93 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
94 | #else |
---|
95 | // Default weight |
---|
96 | if (w0 == 1 << shift) |
---|
97 | { |
---|
98 | // no offset |
---|
99 | if (offset == 0) |
---|
100 | { |
---|
101 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
102 | { |
---|
103 | for (Int n = 0; n < iCols; n++ ) |
---|
104 | { |
---|
105 | uiSum += abs( piOrg[n] - piCur[n] ); |
---|
106 | } |
---|
107 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
108 | { |
---|
109 | return uiSum >> distortionShift; |
---|
110 | } |
---|
111 | piOrg += iStrideOrg; |
---|
112 | piCur += iStrideCur; |
---|
113 | } |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | // Lets not clip for the bipredictive case since clipping should be done after |
---|
118 | // combining both elements. Unfortunately the code uses the suboptimal "subtraction" |
---|
119 | // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal). |
---|
120 | if (pcDtParam->bIsBiPred) |
---|
121 | { |
---|
122 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
123 | { |
---|
124 | for (Int n = 0; n < iCols; n++ ) |
---|
125 | { |
---|
126 | uiSum += abs( piOrg[n] - (piCur[n] + offset) ); |
---|
127 | } |
---|
128 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
129 | { |
---|
130 | return uiSum >> distortionShift; |
---|
131 | } |
---|
132 | |
---|
133 | piOrg += iStrideOrg; |
---|
134 | piCur += iStrideCur; |
---|
135 | } |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
140 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
141 | { |
---|
142 | for (Int n = 0; n < iCols; n++ ) |
---|
143 | { |
---|
144 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (piCur[n] + offset)) ; |
---|
145 | |
---|
146 | uiSum += abs( piOrg[n] - pred ); |
---|
147 | } |
---|
148 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
149 | { |
---|
150 | return uiSum >> distortionShift; |
---|
151 | } |
---|
152 | piOrg += iStrideOrg; |
---|
153 | piCur += iStrideCur; |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | // Lets not clip for the bipredictive case since clipping should be done after |
---|
161 | // combining both elements. Unfortunately the code uses the suboptimal "subtraction" |
---|
162 | // method, which is faster but introduces the clipping issue (therefore Bipred is suboptimal). |
---|
163 | if (pcDtParam->bIsBiPred) |
---|
164 | { |
---|
165 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
166 | { |
---|
167 | for (Int n = 0; n < iCols; n++ ) |
---|
168 | { |
---|
169 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
170 | uiSum += abs( piOrg[n] - pred ); |
---|
171 | } |
---|
172 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
173 | { |
---|
174 | return uiSum >> distortionShift; |
---|
175 | } |
---|
176 | |
---|
177 | piOrg += iStrideOrg; |
---|
178 | piCur += iStrideCur; |
---|
179 | } |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
184 | |
---|
185 | if (offset == 0) |
---|
186 | { |
---|
187 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
188 | { |
---|
189 | for (Int n = 0; n < iCols; n++ ) |
---|
190 | { |
---|
191 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ))) ; |
---|
192 | |
---|
193 | uiSum += abs( piOrg[n] - pred ); |
---|
194 | } |
---|
195 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
196 | { |
---|
197 | return uiSum >> distortionShift; |
---|
198 | } |
---|
199 | piOrg += iStrideOrg; |
---|
200 | piCur += iStrideCur; |
---|
201 | } |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | for(Int iRows = pcDtParam->iRows; iRows != 0; iRows-- ) |
---|
206 | { |
---|
207 | for (Int n = 0; n < iCols; n++ ) |
---|
208 | { |
---|
209 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ; |
---|
210 | |
---|
211 | uiSum += abs( piOrg[n] - pred ); |
---|
212 | } |
---|
213 | if (pcDtParam->m_maximumDistortionForEarlyExit < ( uiSum >> distortionShift)) |
---|
214 | { |
---|
215 | return uiSum >> distortionShift; |
---|
216 | } |
---|
217 | piOrg += iStrideOrg; |
---|
218 | piCur += iStrideCur; |
---|
219 | } |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | //pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
224 | #endif |
---|
225 | |
---|
226 | return uiSum >> distortionShift; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | // -------------------------------------------------------------------------------------------------------------------- |
---|
231 | // SSE |
---|
232 | // -------------------------------------------------------------------------------------------------------------------- |
---|
233 | /** get weighted SSD cost |
---|
234 | * \param pcDtParam |
---|
235 | * \returns Distortion |
---|
236 | */ |
---|
237 | Distortion TComRdCostWeightPrediction::xGetSSEw( DistParam* pcDtParam ) |
---|
238 | { |
---|
239 | const Pel *piOrg = pcDtParam->pOrg; |
---|
240 | const Pel *piCur = pcDtParam->pCur; |
---|
241 | const Int iCols = pcDtParam->iCols; |
---|
242 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
243 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
244 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
245 | |
---|
246 | assert( pcDtParam->iSubShift == 0 ); // NOTE: what is this protecting? |
---|
247 | |
---|
248 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
249 | const WPScalingParam &wpCur = pcDtParam->wpCur[compIdx]; |
---|
250 | const Int w0 = wpCur.w; |
---|
251 | const Int offset = wpCur.offset; |
---|
252 | const Int shift = wpCur.shift; |
---|
253 | const Int round = wpCur.round; |
---|
254 | const UInt distortionShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1); |
---|
255 | |
---|
256 | Distortion sum = 0; |
---|
257 | |
---|
258 | #if !U0040_MODIFIED_WEIGHTEDPREDICTION_WITH_BIPRED_AND_CLIPPING |
---|
259 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
260 | { |
---|
261 | for (Int n = 0; n < iCols; n++ ) |
---|
262 | { |
---|
263 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
264 | const Pel residual = piOrg[n] - pred; |
---|
265 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
266 | } |
---|
267 | piOrg += iStrideOrg; |
---|
268 | piCur += iStrideCur; |
---|
269 | } |
---|
270 | |
---|
271 | pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
272 | #else |
---|
273 | if (pcDtParam->bIsBiPred) |
---|
274 | { |
---|
275 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
276 | { |
---|
277 | for (Int n = 0; n < iCols; n++ ) |
---|
278 | { |
---|
279 | const Pel pred = ( (w0*piCur[n] + round) >> shift ) + offset ; |
---|
280 | const Pel residual = piOrg[n] - pred; |
---|
281 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
282 | } |
---|
283 | piOrg += iStrideOrg; |
---|
284 | piCur += iStrideCur; |
---|
285 | } |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | const Pel iMaxValue = (Pel) ((1 << pcDtParam->bitDepth) - 1); |
---|
290 | |
---|
291 | for(Int iRows = pcDtParam->iRows ; iRows != 0; iRows-- ) |
---|
292 | { |
---|
293 | for (Int n = 0; n < iCols; n++ ) |
---|
294 | { |
---|
295 | const Pel pred = Clip3((Pel) 0, iMaxValue, (Pel) (( (w0*piCur[n] + round) >> shift ) + offset)) ; |
---|
296 | const Pel residual = piOrg[n] - pred; |
---|
297 | sum += ( Distortion(residual) * Distortion(residual) ) >> distortionShift; |
---|
298 | } |
---|
299 | piOrg += iStrideOrg; |
---|
300 | piCur += iStrideCur; |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | //pcDtParam->compIdx = MAX_NUM_COMPONENT; // reset for DEBUG (assert test) |
---|
305 | #endif |
---|
306 | |
---|
307 | return sum; |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | // -------------------------------------------------------------------------------------------------------------------- |
---|
312 | // HADAMARD with step (used in fractional search) |
---|
313 | // -------------------------------------------------------------------------------------------------------------------- |
---|
314 | //! get weighted Hadamard cost for 2x2 block |
---|
315 | Distortion xCalcHADs2x2w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
316 | { |
---|
317 | const Int round = wpCur.round; |
---|
318 | const Int shift = wpCur.shift; |
---|
319 | const Int offset = wpCur.offset; |
---|
320 | const Int w0 = wpCur.w; |
---|
321 | |
---|
322 | Distortion satd = 0; |
---|
323 | TCoeff diff[4]; |
---|
324 | TCoeff m[4]; |
---|
325 | |
---|
326 | Pel pred; |
---|
327 | |
---|
328 | pred = ( (w0*piCur[0*iStep ] + round) >> shift ) + offset ; |
---|
329 | diff[0] = piOrg[0 ] - pred; |
---|
330 | pred = ( (w0*piCur[1*iStep ] + round) >> shift ) + offset ; |
---|
331 | diff[1] = piOrg[1 ] - pred; |
---|
332 | pred = ( (w0*piCur[0*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
333 | diff[2] = piOrg[iStrideOrg ] - pred; |
---|
334 | pred = ( (w0*piCur[1*iStep + iStrideCur] + round) >> shift ) + offset ; |
---|
335 | diff[3] = piOrg[iStrideOrg + 1] - pred; |
---|
336 | |
---|
337 | m[0] = diff[0] + diff[2]; |
---|
338 | m[1] = diff[1] + diff[3]; |
---|
339 | m[2] = diff[0] - diff[2]; |
---|
340 | m[3] = diff[1] - diff[3]; |
---|
341 | |
---|
342 | satd += abs(m[0] + m[1]); |
---|
343 | satd += abs(m[0] - m[1]); |
---|
344 | satd += abs(m[2] + m[3]); |
---|
345 | satd += abs(m[2] - m[3]); |
---|
346 | |
---|
347 | return satd; |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | //! get weighted Hadamard cost for 4x4 block |
---|
352 | Distortion xCalcHADs4x4w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
353 | { |
---|
354 | const Int round = wpCur.round; |
---|
355 | const Int shift = wpCur.shift; |
---|
356 | const Int offset = wpCur.offset; |
---|
357 | const Int w0 = wpCur.w; |
---|
358 | |
---|
359 | Distortion satd = 0; |
---|
360 | TCoeff diff[16]; |
---|
361 | TCoeff m[16]; |
---|
362 | TCoeff d[16]; |
---|
363 | |
---|
364 | |
---|
365 | for(Int k = 0; k < 16; k+=4 ) |
---|
366 | { |
---|
367 | Pel pred; |
---|
368 | pred = ( (w0*piCur[0*iStep] + round) >> shift ) + offset ; |
---|
369 | diff[k+0] = piOrg[0] - pred; |
---|
370 | pred = ( (w0*piCur[1*iStep] + round) >> shift ) + offset ; |
---|
371 | diff[k+1] = piOrg[1] - pred; |
---|
372 | pred = ( (w0*piCur[2*iStep] + round) >> shift ) + offset ; |
---|
373 | diff[k+2] = piOrg[2] - pred; |
---|
374 | pred = ( (w0*piCur[3*iStep] + round) >> shift ) + offset ; |
---|
375 | diff[k+3] = piOrg[3] - pred; |
---|
376 | |
---|
377 | piCur += iStrideCur; |
---|
378 | piOrg += iStrideOrg; |
---|
379 | } |
---|
380 | |
---|
381 | /*===== hadamard transform =====*/ |
---|
382 | m[ 0] = diff[ 0] + diff[12]; |
---|
383 | m[ 1] = diff[ 1] + diff[13]; |
---|
384 | m[ 2] = diff[ 2] + diff[14]; |
---|
385 | m[ 3] = diff[ 3] + diff[15]; |
---|
386 | m[ 4] = diff[ 4] + diff[ 8]; |
---|
387 | m[ 5] = diff[ 5] + diff[ 9]; |
---|
388 | m[ 6] = diff[ 6] + diff[10]; |
---|
389 | m[ 7] = diff[ 7] + diff[11]; |
---|
390 | m[ 8] = diff[ 4] - diff[ 8]; |
---|
391 | m[ 9] = diff[ 5] - diff[ 9]; |
---|
392 | m[10] = diff[ 6] - diff[10]; |
---|
393 | m[11] = diff[ 7] - diff[11]; |
---|
394 | m[12] = diff[ 0] - diff[12]; |
---|
395 | m[13] = diff[ 1] - diff[13]; |
---|
396 | m[14] = diff[ 2] - diff[14]; |
---|
397 | m[15] = diff[ 3] - diff[15]; |
---|
398 | |
---|
399 | d[ 0] = m[ 0] + m[ 4]; |
---|
400 | d[ 1] = m[ 1] + m[ 5]; |
---|
401 | d[ 2] = m[ 2] + m[ 6]; |
---|
402 | d[ 3] = m[ 3] + m[ 7]; |
---|
403 | d[ 4] = m[ 8] + m[12]; |
---|
404 | d[ 5] = m[ 9] + m[13]; |
---|
405 | d[ 6] = m[10] + m[14]; |
---|
406 | d[ 7] = m[11] + m[15]; |
---|
407 | d[ 8] = m[ 0] - m[ 4]; |
---|
408 | d[ 9] = m[ 1] - m[ 5]; |
---|
409 | d[10] = m[ 2] - m[ 6]; |
---|
410 | d[11] = m[ 3] - m[ 7]; |
---|
411 | d[12] = m[12] - m[ 8]; |
---|
412 | d[13] = m[13] - m[ 9]; |
---|
413 | d[14] = m[14] - m[10]; |
---|
414 | d[15] = m[15] - m[11]; |
---|
415 | |
---|
416 | m[ 0] = d[ 0] + d[ 3]; |
---|
417 | m[ 1] = d[ 1] + d[ 2]; |
---|
418 | m[ 2] = d[ 1] - d[ 2]; |
---|
419 | m[ 3] = d[ 0] - d[ 3]; |
---|
420 | m[ 4] = d[ 4] + d[ 7]; |
---|
421 | m[ 5] = d[ 5] + d[ 6]; |
---|
422 | m[ 6] = d[ 5] - d[ 6]; |
---|
423 | m[ 7] = d[ 4] - d[ 7]; |
---|
424 | m[ 8] = d[ 8] + d[11]; |
---|
425 | m[ 9] = d[ 9] + d[10]; |
---|
426 | m[10] = d[ 9] - d[10]; |
---|
427 | m[11] = d[ 8] - d[11]; |
---|
428 | m[12] = d[12] + d[15]; |
---|
429 | m[13] = d[13] + d[14]; |
---|
430 | m[14] = d[13] - d[14]; |
---|
431 | m[15] = d[12] - d[15]; |
---|
432 | |
---|
433 | d[ 0] = m[ 0] + m[ 1]; |
---|
434 | d[ 1] = m[ 0] - m[ 1]; |
---|
435 | d[ 2] = m[ 2] + m[ 3]; |
---|
436 | d[ 3] = m[ 3] - m[ 2]; |
---|
437 | d[ 4] = m[ 4] + m[ 5]; |
---|
438 | d[ 5] = m[ 4] - m[ 5]; |
---|
439 | d[ 6] = m[ 6] + m[ 7]; |
---|
440 | d[ 7] = m[ 7] - m[ 6]; |
---|
441 | d[ 8] = m[ 8] + m[ 9]; |
---|
442 | d[ 9] = m[ 8] - m[ 9]; |
---|
443 | d[10] = m[10] + m[11]; |
---|
444 | d[11] = m[11] - m[10]; |
---|
445 | d[12] = m[12] + m[13]; |
---|
446 | d[13] = m[12] - m[13]; |
---|
447 | d[14] = m[14] + m[15]; |
---|
448 | d[15] = m[15] - m[14]; |
---|
449 | |
---|
450 | for (Int k=0; k<16; ++k) |
---|
451 | { |
---|
452 | satd += abs(d[k]); |
---|
453 | } |
---|
454 | satd = ((satd+1)>>1); |
---|
455 | |
---|
456 | return satd; |
---|
457 | } |
---|
458 | |
---|
459 | |
---|
460 | //! get weighted Hadamard cost for 8x8 block |
---|
461 | Distortion xCalcHADs8x8w( const WPScalingParam &wpCur, const Pel *piOrg, const Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep ) |
---|
462 | { |
---|
463 | Distortion sad=0; |
---|
464 | TCoeff diff[64], m1[8][8], m2[8][8], m3[8][8]; |
---|
465 | Int iStep2 = iStep<<1; |
---|
466 | Int iStep3 = iStep2 + iStep; |
---|
467 | Int iStep4 = iStep3 + iStep; |
---|
468 | Int iStep5 = iStep4 + iStep; |
---|
469 | Int iStep6 = iStep5 + iStep; |
---|
470 | Int iStep7 = iStep6 + iStep; |
---|
471 | const Int round = wpCur.round; |
---|
472 | const Int shift = wpCur.shift; |
---|
473 | const Int offset = wpCur.offset; |
---|
474 | const Int w0 = wpCur.w; |
---|
475 | |
---|
476 | Pel pred; |
---|
477 | |
---|
478 | for(Int k = 0; k < 64; k+=8 ) |
---|
479 | { |
---|
480 | pred = ( (w0*piCur[ 0] + round) >> shift ) + offset ; |
---|
481 | diff[k+0] = piOrg[0] - pred; |
---|
482 | pred = ( (w0*piCur[iStep ] + round) >> shift ) + offset ; |
---|
483 | diff[k+1] = piOrg[1] - pred; |
---|
484 | pred = ( (w0*piCur[iStep2] + round) >> shift ) + offset ; |
---|
485 | diff[k+2] = piOrg[2] - pred; |
---|
486 | pred = ( (w0*piCur[iStep3] + round) >> shift ) + offset ; |
---|
487 | diff[k+3] = piOrg[3] - pred; |
---|
488 | pred = ( (w0*piCur[iStep4] + round) >> shift ) + offset ; |
---|
489 | diff[k+4] = piOrg[4] - pred; |
---|
490 | pred = ( (w0*piCur[iStep5] + round) >> shift ) + offset ; |
---|
491 | diff[k+5] = piOrg[5] - pred; |
---|
492 | pred = ( (w0*piCur[iStep6] + round) >> shift ) + offset ; |
---|
493 | diff[k+6] = piOrg[6] - pred; |
---|
494 | pred = ( (w0*piCur[iStep7] + round) >> shift ) + offset ; |
---|
495 | diff[k+7] = piOrg[7] - pred; |
---|
496 | |
---|
497 | piCur += iStrideCur; |
---|
498 | piOrg += iStrideOrg; |
---|
499 | } |
---|
500 | |
---|
501 | //horizontal |
---|
502 | for (Int j=0; j < 8; j++) |
---|
503 | { |
---|
504 | const Int jj = j << 3; |
---|
505 | m2[j][0] = diff[jj ] + diff[jj+4]; |
---|
506 | m2[j][1] = diff[jj+1] + diff[jj+5]; |
---|
507 | m2[j][2] = diff[jj+2] + diff[jj+6]; |
---|
508 | m2[j][3] = diff[jj+3] + diff[jj+7]; |
---|
509 | m2[j][4] = diff[jj ] - diff[jj+4]; |
---|
510 | m2[j][5] = diff[jj+1] - diff[jj+5]; |
---|
511 | m2[j][6] = diff[jj+2] - diff[jj+6]; |
---|
512 | m2[j][7] = diff[jj+3] - diff[jj+7]; |
---|
513 | |
---|
514 | m1[j][0] = m2[j][0] + m2[j][2]; |
---|
515 | m1[j][1] = m2[j][1] + m2[j][3]; |
---|
516 | m1[j][2] = m2[j][0] - m2[j][2]; |
---|
517 | m1[j][3] = m2[j][1] - m2[j][3]; |
---|
518 | m1[j][4] = m2[j][4] + m2[j][6]; |
---|
519 | m1[j][5] = m2[j][5] + m2[j][7]; |
---|
520 | m1[j][6] = m2[j][4] - m2[j][6]; |
---|
521 | m1[j][7] = m2[j][5] - m2[j][7]; |
---|
522 | |
---|
523 | m2[j][0] = m1[j][0] + m1[j][1]; |
---|
524 | m2[j][1] = m1[j][0] - m1[j][1]; |
---|
525 | m2[j][2] = m1[j][2] + m1[j][3]; |
---|
526 | m2[j][3] = m1[j][2] - m1[j][3]; |
---|
527 | m2[j][4] = m1[j][4] + m1[j][5]; |
---|
528 | m2[j][5] = m1[j][4] - m1[j][5]; |
---|
529 | m2[j][6] = m1[j][6] + m1[j][7]; |
---|
530 | m2[j][7] = m1[j][6] - m1[j][7]; |
---|
531 | } |
---|
532 | |
---|
533 | //vertical |
---|
534 | for (Int i=0; i < 8; i++) |
---|
535 | { |
---|
536 | m3[0][i] = m2[0][i] + m2[4][i]; |
---|
537 | m3[1][i] = m2[1][i] + m2[5][i]; |
---|
538 | m3[2][i] = m2[2][i] + m2[6][i]; |
---|
539 | m3[3][i] = m2[3][i] + m2[7][i]; |
---|
540 | m3[4][i] = m2[0][i] - m2[4][i]; |
---|
541 | m3[5][i] = m2[1][i] - m2[5][i]; |
---|
542 | m3[6][i] = m2[2][i] - m2[6][i]; |
---|
543 | m3[7][i] = m2[3][i] - m2[7][i]; |
---|
544 | |
---|
545 | m1[0][i] = m3[0][i] + m3[2][i]; |
---|
546 | m1[1][i] = m3[1][i] + m3[3][i]; |
---|
547 | m1[2][i] = m3[0][i] - m3[2][i]; |
---|
548 | m1[3][i] = m3[1][i] - m3[3][i]; |
---|
549 | m1[4][i] = m3[4][i] + m3[6][i]; |
---|
550 | m1[5][i] = m3[5][i] + m3[7][i]; |
---|
551 | m1[6][i] = m3[4][i] - m3[6][i]; |
---|
552 | m1[7][i] = m3[5][i] - m3[7][i]; |
---|
553 | |
---|
554 | m2[0][i] = m1[0][i] + m1[1][i]; |
---|
555 | m2[1][i] = m1[0][i] - m1[1][i]; |
---|
556 | m2[2][i] = m1[2][i] + m1[3][i]; |
---|
557 | m2[3][i] = m1[2][i] - m1[3][i]; |
---|
558 | m2[4][i] = m1[4][i] + m1[5][i]; |
---|
559 | m2[5][i] = m1[4][i] - m1[5][i]; |
---|
560 | m2[6][i] = m1[6][i] + m1[7][i]; |
---|
561 | m2[7][i] = m1[6][i] - m1[7][i]; |
---|
562 | } |
---|
563 | |
---|
564 | for (Int j=0; j < 8; j++) |
---|
565 | { |
---|
566 | for (Int i=0; i < 8; i++) |
---|
567 | { |
---|
568 | sad += (abs(m2[j][i])); |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | sad=((sad+2)>>2); |
---|
573 | |
---|
574 | return sad; |
---|
575 | } |
---|
576 | |
---|
577 | |
---|
578 | //! get weighted Hadamard cost |
---|
579 | Distortion TComRdCostWeightPrediction::xGetHADsw( DistParam* pcDtParam ) |
---|
580 | { |
---|
581 | const Pel *piOrg = pcDtParam->pOrg; |
---|
582 | const Pel *piCur = pcDtParam->pCur; |
---|
583 | const Int iRows = pcDtParam->iRows; |
---|
584 | const Int iCols = pcDtParam->iCols; |
---|
585 | const Int iStrideCur = pcDtParam->iStrideCur; |
---|
586 | const Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
587 | const Int iStep = pcDtParam->iStep; |
---|
588 | const ComponentID compIdx = pcDtParam->compIdx; |
---|
589 | assert(compIdx<MAX_NUM_COMPONENT); |
---|
590 | const WPScalingParam &wpCur = pcDtParam->wpCur[compIdx]; |
---|
591 | |
---|
592 | Distortion uiSum = 0; |
---|
593 | |
---|
594 | if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) |
---|
595 | { |
---|
596 | const Int iOffsetOrg = iStrideOrg<<3; |
---|
597 | const Int iOffsetCur = iStrideCur<<3; |
---|
598 | for (Int y=0; y<iRows; y+= 8 ) |
---|
599 | { |
---|
600 | for (Int x=0; x<iCols; x+= 8 ) |
---|
601 | { |
---|
602 | uiSum += xCalcHADs8x8w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
603 | } |
---|
604 | piOrg += iOffsetOrg; |
---|
605 | piCur += iOffsetCur; |
---|
606 | } |
---|
607 | } |
---|
608 | else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) |
---|
609 | { |
---|
610 | const Int iOffsetOrg = iStrideOrg<<2; |
---|
611 | const Int iOffsetCur = iStrideCur<<2; |
---|
612 | |
---|
613 | for (Int y=0; y<iRows; y+= 4 ) |
---|
614 | { |
---|
615 | for (Int x=0; x<iCols; x+= 4 ) |
---|
616 | { |
---|
617 | uiSum += xCalcHADs4x4w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
618 | } |
---|
619 | piOrg += iOffsetOrg; |
---|
620 | piCur += iOffsetCur; |
---|
621 | } |
---|
622 | } |
---|
623 | else |
---|
624 | { |
---|
625 | for (Int y=0; y<iRows; y+=2 ) |
---|
626 | { |
---|
627 | for (Int x=0; x<iCols; x+=2 ) |
---|
628 | { |
---|
629 | uiSum += xCalcHADs2x2w( wpCur, &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep ); |
---|
630 | } |
---|
631 | piOrg += iStrideOrg; |
---|
632 | piCur += iStrideCur; |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8); |
---|
637 | } |
---|