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