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