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