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-2011, 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 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 | |
---|
35 | |
---|
36 | |
---|
37 | // Include files |
---|
38 | #include "CommonDef.h" |
---|
39 | #include "TComYuv.h" |
---|
40 | #include "TComWedgelet.h" |
---|
41 | |
---|
42 | #include <stdlib.h> |
---|
43 | #include <memory.h> |
---|
44 | |
---|
45 | using namespace std; |
---|
46 | |
---|
47 | |
---|
48 | TComWedgelet::TComWedgelet( UInt uiWidth, UInt uiHeight ) : m_uhXs ( 0 ), |
---|
49 | m_uhYs ( 0 ), |
---|
50 | m_uhXe ( 0 ), |
---|
51 | m_uhYe ( 0 ), |
---|
52 | m_uhOri ( 0 ), |
---|
53 | m_eWedgeRes( FULL_PEL ) |
---|
54 | { |
---|
55 | create( uiWidth, uiHeight ); |
---|
56 | } |
---|
57 | |
---|
58 | TComWedgelet::TComWedgelet( const TComWedgelet &rcWedge ) : m_uhXs ( rcWedge.m_uhXs ), |
---|
59 | m_uhYs ( rcWedge.m_uhYs ), |
---|
60 | m_uhXe ( rcWedge.m_uhXe ), |
---|
61 | m_uhYe ( rcWedge.m_uhYe ), |
---|
62 | m_uhOri ( rcWedge.m_uhOri ), |
---|
63 | m_eWedgeRes( rcWedge.m_eWedgeRes ), |
---|
64 | m_uiWidth ( rcWedge.m_uiWidth ), |
---|
65 | m_uiHeight ( rcWedge.m_uiHeight ), |
---|
66 | m_pbPattern( (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ) ) |
---|
67 | { |
---|
68 | ::memcpy( m_pbPattern, rcWedge.m_pbPattern, sizeof(Bool) * (m_uiWidth * m_uiHeight)); |
---|
69 | } |
---|
70 | |
---|
71 | TComWedgelet::~TComWedgelet(void) |
---|
72 | { |
---|
73 | destroy(); |
---|
74 | } |
---|
75 | |
---|
76 | Void TComWedgelet::create( UInt uiWidth, UInt uiHeight ) |
---|
77 | { |
---|
78 | assert( uiWidth > 0 && uiHeight > 0 ); |
---|
79 | |
---|
80 | m_uiWidth = uiWidth; |
---|
81 | m_uiHeight = uiHeight; |
---|
82 | |
---|
83 | m_pbPattern = (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ); |
---|
84 | } |
---|
85 | |
---|
86 | Void TComWedgelet::destroy() |
---|
87 | { |
---|
88 | if( m_pbPattern ) { xFree( m_pbPattern ); m_pbPattern = NULL; } |
---|
89 | } |
---|
90 | |
---|
91 | Void TComWedgelet::clear() |
---|
92 | { |
---|
93 | ::memset( m_pbPattern, 0, (m_uiWidth * m_uiHeight) * sizeof(Bool) ); |
---|
94 | } |
---|
95 | |
---|
96 | Void TComWedgelet::setWedgelet( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UChar uhOri, WedgeResolution eWedgeRes ) |
---|
97 | { |
---|
98 | m_uhXs = uhXs; |
---|
99 | m_uhYs = uhYs; |
---|
100 | m_uhXe = uhXe; |
---|
101 | m_uhYe = uhYe; |
---|
102 | m_uhOri = uhOri; |
---|
103 | m_eWedgeRes = eWedgeRes; |
---|
104 | |
---|
105 | xGenerateWedgePattern(); |
---|
106 | } |
---|
107 | |
---|
108 | Bool TComWedgelet::checkNotPlain() |
---|
109 | { |
---|
110 | for( UInt k = 1; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
111 | { |
---|
112 | if( m_pbPattern[0] != m_pbPattern[k] ) |
---|
113 | { |
---|
114 | return true; |
---|
115 | } |
---|
116 | } |
---|
117 | return false; |
---|
118 | } |
---|
119 | |
---|
120 | Bool TComWedgelet::checkIdentical( Bool* pbRefPattern ) |
---|
121 | { |
---|
122 | for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
123 | { |
---|
124 | if( m_pbPattern[k] != pbRefPattern[k] ) |
---|
125 | { |
---|
126 | return false; |
---|
127 | } |
---|
128 | } |
---|
129 | return true; |
---|
130 | } |
---|
131 | |
---|
132 | Bool TComWedgelet::checkInvIdentical( Bool* pbRefPattern ) |
---|
133 | { |
---|
134 | for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
135 | { |
---|
136 | if( m_pbPattern[k] == pbRefPattern[k] ) |
---|
137 | { |
---|
138 | return false; |
---|
139 | } |
---|
140 | } |
---|
141 | return true; |
---|
142 | } |
---|
143 | |
---|
144 | #if HHI_DMM_WEDGE_INTRA |
---|
145 | Bool TComWedgelet::checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset ) |
---|
146 | { |
---|
147 | WedgeResolution eContDWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiPredDirBlockSize]]; |
---|
148 | UInt uiContDStartEndMax = 0; |
---|
149 | UInt uiContDStartEndOffset = 0; |
---|
150 | switch( eContDWedgeRes ) |
---|
151 | { |
---|
152 | case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; } |
---|
153 | case( FULL_PEL ): { uiContDStartEndMax = uiPredDirBlockSize; uiContDStartEndOffset = uiPredDirBlockOffset; break; } |
---|
154 | case( HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; } |
---|
155 | } |
---|
156 | |
---|
157 | if( m_uhOri == 2 || m_uhOri == 3 || m_uhOri == 4 ) |
---|
158 | { |
---|
159 | UInt uiThisStartEndMax = 0; |
---|
160 | switch( m_eWedgeRes ) |
---|
161 | { |
---|
162 | case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiWidth>>1); break; } |
---|
163 | case( FULL_PEL ): { uiThisStartEndMax = m_uiWidth; break; } |
---|
164 | case( HALF_PEL ): { uiThisStartEndMax = (m_uiWidth<<1); break; } |
---|
165 | } |
---|
166 | |
---|
167 | UChar uhStartX = m_uhXs; |
---|
168 | UChar uhStartY = m_uhYs; |
---|
169 | UChar uhEndX = m_uhXe; |
---|
170 | UChar uhEndY = m_uhYe; |
---|
171 | |
---|
172 | if( 2 == m_uhOri ) |
---|
173 | { |
---|
174 | std::swap( uhStartX, uhEndX ); |
---|
175 | std::swap( uhStartY, uhEndY ); |
---|
176 | } |
---|
177 | |
---|
178 | UInt uiScaledEndX = (UInt)uhEndX; |
---|
179 | Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes; |
---|
180 | if( iDeltaRes > 0 ) { uiScaledEndX <<= iDeltaRes; } |
---|
181 | if( iDeltaRes < 0 ) { uiScaledEndX >>= -iDeltaRes; } |
---|
182 | |
---|
183 | if( ((UInt)uhEndY == (uiThisStartEndMax-1)) && ((uiScaledEndX-uiContDStartEndOffset) > 0 && (uiScaledEndX-uiContDStartEndOffset) < (uiContDStartEndMax-1)) ) |
---|
184 | { |
---|
185 | return true; |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | return false; |
---|
190 | } |
---|
191 | |
---|
192 | Bool TComWedgelet::checkPredDirLeftPossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset ) |
---|
193 | { |
---|
194 | WedgeResolution eContDWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiPredDirBlockSize]]; |
---|
195 | UInt uiContDStartEndMax = 0; |
---|
196 | UInt uiContDStartEndOffset = 0; |
---|
197 | switch( eContDWedgeRes ) |
---|
198 | { |
---|
199 | case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; } |
---|
200 | case( FULL_PEL ): { uiContDStartEndMax = uiPredDirBlockSize; uiContDStartEndOffset = uiPredDirBlockOffset; break; } |
---|
201 | case( HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; } |
---|
202 | } |
---|
203 | |
---|
204 | if( m_uhOri == 1 || m_uhOri == 2 || m_uhOri == 5 ) |
---|
205 | { |
---|
206 | UInt uiThisStartEndMax = 0; |
---|
207 | switch( m_eWedgeRes ) |
---|
208 | { |
---|
209 | case( DOUBLE_PEL ): { uiThisStartEndMax = (m_uiHeight>>1); break; } |
---|
210 | case( FULL_PEL ): { uiThisStartEndMax = m_uiHeight; break; } |
---|
211 | case( HALF_PEL ): { uiThisStartEndMax = (m_uiHeight<<1); break; } |
---|
212 | } |
---|
213 | |
---|
214 | UChar uhStartX = m_uhXs; |
---|
215 | UChar uhStartY = m_uhYs; |
---|
216 | UChar uhEndX = m_uhXe; |
---|
217 | UChar uhEndY = m_uhYe; |
---|
218 | |
---|
219 | if( 1 == m_uhOri || 5 == m_uhOri ) |
---|
220 | { |
---|
221 | std::swap( uhStartX, uhEndX ); |
---|
222 | std::swap( uhStartY, uhEndY ); |
---|
223 | } |
---|
224 | |
---|
225 | UInt uiScaledEndY = (UInt)uhEndY; |
---|
226 | Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes; |
---|
227 | if( iDeltaRes > 0 ) { uiScaledEndY <<= iDeltaRes; } |
---|
228 | if( iDeltaRes < 0 ) { uiScaledEndY >>= -iDeltaRes; } |
---|
229 | |
---|
230 | if( ((UInt)uhEndX == (uiThisStartEndMax-1)) && ((uiScaledEndY-uiContDStartEndOffset) > 0 && (uiScaledEndY-uiContDStartEndOffset) < (uiContDStartEndMax-1)) ) |
---|
231 | { |
---|
232 | return true; |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | return false; |
---|
237 | } |
---|
238 | |
---|
239 | Void TComWedgelet::getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd ) |
---|
240 | { |
---|
241 | ruhXs = 0; |
---|
242 | ruhYs = 0; |
---|
243 | ruhXe = 0; |
---|
244 | ruhYe = 0; |
---|
245 | |
---|
246 | // get start/end of reference (=this) wedgelet |
---|
247 | UInt uiRefStartX = (UInt)getStartX(); |
---|
248 | UInt uiRefStartY = (UInt)getStartY(); |
---|
249 | UInt uiRefEndX = (UInt)getEndX(); |
---|
250 | UInt uiRefEndY = (UInt)getEndY(); |
---|
251 | |
---|
252 | WedgeResolution eContDWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiPredDirBlockSize]]; |
---|
253 | UInt uiContDStartEndMax = 0; |
---|
254 | UInt uiContDStartEndOffset = 0; |
---|
255 | switch( eContDWedgeRes ) |
---|
256 | { |
---|
257 | case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; } |
---|
258 | case( FULL_PEL ): { uiContDStartEndMax = uiPredDirBlockSize; uiContDStartEndOffset = uiPredDirBlockOffset; break; } |
---|
259 | case( HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; } |
---|
260 | } |
---|
261 | Int iContDMaxPos = (Int)uiContDStartEndMax - 1; |
---|
262 | |
---|
263 | // swap if start/end if line orientation is not from top to bottom |
---|
264 | if( 2 == (UInt)getOri() ) |
---|
265 | { |
---|
266 | std::swap( uiRefStartX, uiRefEndX ); |
---|
267 | std::swap( uiRefStartY, uiRefEndY ); |
---|
268 | } |
---|
269 | |
---|
270 | // calc slopes |
---|
271 | Int iA_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX; |
---|
272 | Int iA_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY; |
---|
273 | |
---|
274 | // get aligned end x value of ref wedge |
---|
275 | UInt uiScaledRefEndX = uiRefEndX; |
---|
276 | Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes; |
---|
277 | if( iDeltaRes > 0 ) { uiScaledRefEndX <<= iDeltaRes; } |
---|
278 | if( iDeltaRes < 0 ) { uiScaledRefEndX >>= -iDeltaRes; } |
---|
279 | |
---|
280 | assert( uiScaledRefEndX >= uiContDStartEndOffset ); |
---|
281 | Int iAlignedRefEndX = (Int)uiScaledRefEndX - (Int)uiContDStartEndOffset; |
---|
282 | |
---|
283 | // special for straight vertical wedge |
---|
284 | if( iA_DeltaX == 0 ) |
---|
285 | { |
---|
286 | ruhXs = (UChar)iAlignedRefEndX; |
---|
287 | ruhYs = 0; |
---|
288 | |
---|
289 | Int iXe = iAlignedRefEndX + iDeltaEnd; |
---|
290 | if( iXe < 0 ) |
---|
291 | { |
---|
292 | ruhXe = 0; |
---|
293 | ruhYe = (UChar)min( max( (iContDMaxPos + iXe), 0 ), iContDMaxPos ); |
---|
294 | |
---|
295 | return; |
---|
296 | } |
---|
297 | else if( iXe > iContDMaxPos ) |
---|
298 | { |
---|
299 | ruhXe = (UChar)iContDMaxPos; |
---|
300 | ruhYe = (UChar)min( max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 ), iContDMaxPos ); |
---|
301 | |
---|
302 | std::swap( ruhXs, ruhXe ); |
---|
303 | std::swap( ruhYs, ruhYe ); |
---|
304 | return; |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | ruhXe = (UChar)iXe; |
---|
309 | ruhYe = (UChar)iContDMaxPos; |
---|
310 | |
---|
311 | return; |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | // special for straight horizontal short bottom line |
---|
316 | if( iA_DeltaY == 0 ) |
---|
317 | { |
---|
318 | switch( (UInt)getOri() ) |
---|
319 | { |
---|
320 | case( 2 ): |
---|
321 | { |
---|
322 | ruhXs = (UChar)(iAlignedRefEndX-1); |
---|
323 | ruhYs = 0; |
---|
324 | ruhXe = 0; |
---|
325 | ruhYe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos ); |
---|
326 | |
---|
327 | return; |
---|
328 | } |
---|
329 | case( 3 ): |
---|
330 | { |
---|
331 | ruhXs = (UChar)(iAlignedRefEndX+1); |
---|
332 | ruhYs = 0; |
---|
333 | ruhXe = (UChar)iContDMaxPos; |
---|
334 | ruhYe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos ); |
---|
335 | |
---|
336 | std::swap( ruhXs, ruhXe ); |
---|
337 | std::swap( ruhYs, ruhYe ); |
---|
338 | return; |
---|
339 | } |
---|
340 | default: |
---|
341 | { |
---|
342 | assert( 0 ); |
---|
343 | return; |
---|
344 | } |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | // set start point depending on slope |
---|
349 | if( abs( iA_DeltaX ) >= abs( iA_DeltaY ) ) { if( iA_DeltaX < 0 ) { ruhXs = (UChar)(iAlignedRefEndX-1); ruhYs = 0; } |
---|
350 | if( iA_DeltaX > 0 ) { ruhXs = (UChar)(iAlignedRefEndX+1); ruhYs = 0; } } |
---|
351 | else { ruhXs = (UChar)(iAlignedRefEndX); ruhYs = 0; } |
---|
352 | |
---|
353 | // calc end point and determine orientation |
---|
354 | Int iVirtualEndX = (Int)ruhXs + roftoi( (Double)iContDMaxPos * ((Double)iA_DeltaX / (Double)iA_DeltaY) ); |
---|
355 | |
---|
356 | if( iVirtualEndX < 0 ) |
---|
357 | { |
---|
358 | Int iYe = roftoi( (Double)(0 - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) + iDeltaEnd; |
---|
359 | if( iYe < (Int)uiContDStartEndMax ) |
---|
360 | { |
---|
361 | ruhXe = 0; |
---|
362 | ruhYe = (UChar)max( iYe, 0 ); |
---|
363 | |
---|
364 | return; |
---|
365 | } |
---|
366 | else |
---|
367 | { |
---|
368 | ruhXe = (UChar)min( (iYe - iContDMaxPos), iContDMaxPos ); |
---|
369 | ruhYe = (UChar)iContDMaxPos; |
---|
370 | |
---|
371 | return; |
---|
372 | } |
---|
373 | } |
---|
374 | else if( iVirtualEndX > iContDMaxPos ) |
---|
375 | { |
---|
376 | Int iYe = roftoi( (Double)(iContDMaxPos - (Int)ruhXs) * ((Double)iA_DeltaY / (Double)iA_DeltaX) ) - iDeltaEnd; |
---|
377 | if( iYe < (Int)uiContDStartEndMax ) |
---|
378 | { |
---|
379 | ruhXe = (UChar)iContDMaxPos; |
---|
380 | ruhYe = (UChar)max( iYe, 0 ); |
---|
381 | |
---|
382 | std::swap( ruhXs, ruhXe ); |
---|
383 | std::swap( ruhYs, ruhYe ); |
---|
384 | return; |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 ); |
---|
389 | ruhYe = (UChar)iContDMaxPos; |
---|
390 | |
---|
391 | return; |
---|
392 | } |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | Int iXe = iVirtualEndX + iDeltaEnd; |
---|
397 | if( iXe < 0 ) |
---|
398 | { |
---|
399 | ruhXe = 0; |
---|
400 | ruhYe = (UChar)max( (iContDMaxPos + iXe), 0 ); |
---|
401 | |
---|
402 | return; |
---|
403 | } |
---|
404 | else if( iXe > iContDMaxPos ) |
---|
405 | { |
---|
406 | ruhXe = (UChar)iContDMaxPos; |
---|
407 | ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 ); |
---|
408 | |
---|
409 | std::swap( ruhXs, ruhXe ); |
---|
410 | std::swap( ruhYs, ruhYe ); |
---|
411 | return; |
---|
412 | } |
---|
413 | else |
---|
414 | { |
---|
415 | ruhXe = (UChar)iXe; |
---|
416 | ruhYe = (UChar)iContDMaxPos; |
---|
417 | |
---|
418 | return; |
---|
419 | } |
---|
420 | } |
---|
421 | } |
---|
422 | |
---|
423 | Void TComWedgelet::getPredDirStartEndLeft( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd ) |
---|
424 | { |
---|
425 | ruhXs = 0; |
---|
426 | ruhYs = 0; |
---|
427 | ruhXe = 0; |
---|
428 | ruhYe = 0; |
---|
429 | |
---|
430 | // get start/end of reference (=this) wedgelet |
---|
431 | UInt uiRefStartX = (UInt)getStartX(); |
---|
432 | UInt uiRefStartY = (UInt)getStartY(); |
---|
433 | UInt uiRefEndX = (UInt)getEndX(); |
---|
434 | UInt uiRefEndY = (UInt)getEndY(); |
---|
435 | |
---|
436 | WedgeResolution eContDWedgeRes = g_aeWedgeResolutionList[(UInt)g_aucConvertToBit[uiPredDirBlockSize]]; |
---|
437 | UInt uiContDStartEndMax = 0; |
---|
438 | UInt uiContDStartEndOffset = 0; |
---|
439 | switch( eContDWedgeRes ) |
---|
440 | { |
---|
441 | case( DOUBLE_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize>>1); uiContDStartEndOffset = (uiPredDirBlockOffset>>1); break; } |
---|
442 | case( FULL_PEL ): { uiContDStartEndMax = uiPredDirBlockSize; uiContDStartEndOffset = uiPredDirBlockOffset; break; } |
---|
443 | case( HALF_PEL ): { uiContDStartEndMax = (uiPredDirBlockSize<<1); uiContDStartEndOffset = (uiPredDirBlockOffset<<1); break; } |
---|
444 | } |
---|
445 | Int iContDMaxPos = (Int)uiContDStartEndMax - 1; |
---|
446 | |
---|
447 | // swap if start/end if line orientation is not from left to right |
---|
448 | if( 1 == (UInt)getOri() || 5 == (UInt)getOri() ) |
---|
449 | { |
---|
450 | std::swap( uiRefStartX, uiRefEndX ); |
---|
451 | std::swap( uiRefStartY, uiRefEndY ); |
---|
452 | } |
---|
453 | |
---|
454 | Int iL_DeltaX = (Int)uiRefEndX - (Int)uiRefStartX; |
---|
455 | Int iL_DeltaY = (Int)uiRefEndY - (Int)uiRefStartY; |
---|
456 | |
---|
457 | UInt uiScaledRefEndY = uiRefEndY; |
---|
458 | Int iDeltaRes = (Int)eContDWedgeRes - (Int)m_eWedgeRes; |
---|
459 | if( iDeltaRes > 0 ) { uiScaledRefEndY <<= iDeltaRes; } |
---|
460 | if( iDeltaRes < 0 ) { uiScaledRefEndY >>= -iDeltaRes; } |
---|
461 | |
---|
462 | assert( uiScaledRefEndY >= uiContDStartEndOffset ); |
---|
463 | Int iAlignedRefEndY = (Int)uiScaledRefEndY - (Int)uiContDStartEndOffset; |
---|
464 | |
---|
465 | // special for straight horizontal wedge |
---|
466 | if( iL_DeltaY == 0 ) |
---|
467 | { |
---|
468 | ruhXs = 0; |
---|
469 | ruhYs = (UChar)iAlignedRefEndY; |
---|
470 | |
---|
471 | Int iYe = iAlignedRefEndY - iDeltaEnd; |
---|
472 | if( iYe < 0 ) |
---|
473 | { |
---|
474 | ruhXe = (UChar)min( max( (iContDMaxPos + iYe), 0 ), iContDMaxPos ); |
---|
475 | ruhYe = 0; |
---|
476 | |
---|
477 | std::swap( ruhXs, ruhXe ); |
---|
478 | std::swap( ruhYs, ruhYe ); |
---|
479 | return; |
---|
480 | } |
---|
481 | else if( iYe > iContDMaxPos ) |
---|
482 | { |
---|
483 | ruhXe = (UChar)min( max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 ), iContDMaxPos ); |
---|
484 | ruhYe = (UChar)iContDMaxPos; |
---|
485 | |
---|
486 | return; |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | ruhXe = (UChar)iContDMaxPos; |
---|
491 | ruhYe = (UChar)iYe; |
---|
492 | |
---|
493 | std::swap( ruhXs, ruhXe ); |
---|
494 | std::swap( ruhYs, ruhYe ); |
---|
495 | return; |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | // special for straight vertical short right line |
---|
500 | if( iL_DeltaX == 0 ) |
---|
501 | { |
---|
502 | switch( (UInt)getOri() ) |
---|
503 | { |
---|
504 | case( 1 ): |
---|
505 | { |
---|
506 | ruhXs = 0; |
---|
507 | ruhYs = (UChar)(iAlignedRefEndY+1); |
---|
508 | ruhXe = (UChar)min( max( iDeltaEnd, 0 ), iContDMaxPos ); |
---|
509 | ruhYe = (UChar)iContDMaxPos; |
---|
510 | |
---|
511 | return; |
---|
512 | } |
---|
513 | case( 2 ): |
---|
514 | { |
---|
515 | ruhXs = 0; |
---|
516 | ruhYs = (UChar)(iAlignedRefEndY-1); |
---|
517 | ruhXe = (UChar)min( max( -iDeltaEnd, 0 ), iContDMaxPos ); |
---|
518 | ruhYe = 0; |
---|
519 | |
---|
520 | std::swap( ruhXs, ruhXe ); |
---|
521 | std::swap( ruhYs, ruhYe ); |
---|
522 | return; |
---|
523 | } |
---|
524 | default: |
---|
525 | { |
---|
526 | assert( 0 ); |
---|
527 | return; |
---|
528 | } |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | // set start point depending on slope |
---|
533 | if( abs( iL_DeltaY ) >= abs( iL_DeltaX ) ) { if( iL_DeltaY < 0 ) { ruhYs = (UChar)(iAlignedRefEndY-1); ruhXs = 0; } |
---|
534 | if( iL_DeltaY > 0 ) { ruhYs = (UChar)(iAlignedRefEndY+1); ruhXs = 0; } } |
---|
535 | else { ruhYs = (UChar)(iAlignedRefEndY); ruhXs = 0; } |
---|
536 | |
---|
537 | // calc end point and determine orientation |
---|
538 | Int iVirtualEndY = (Int)ruhYs + roftoi( (Double)iContDMaxPos * ((Double)iL_DeltaY / (Double)iL_DeltaX) ); |
---|
539 | |
---|
540 | if( iVirtualEndY < 0 ) |
---|
541 | { |
---|
542 | Int iXe = roftoi( (Double)(0 - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) - iDeltaEnd; |
---|
543 | if( iXe < (Int)uiContDStartEndMax ) |
---|
544 | { |
---|
545 | ruhXe = (UChar)max( iXe, 0 ); |
---|
546 | ruhYe = 0; |
---|
547 | |
---|
548 | std::swap( ruhXs, ruhXe ); |
---|
549 | std::swap( ruhYs, ruhYe ); |
---|
550 | return; |
---|
551 | } |
---|
552 | else |
---|
553 | { |
---|
554 | ruhXe = (UChar)iContDMaxPos; |
---|
555 | ruhYe = (UChar)min( (iXe - iContDMaxPos), iContDMaxPos ); |
---|
556 | |
---|
557 | std::swap( ruhXs, ruhXe ); |
---|
558 | std::swap( ruhYs, ruhYe ); |
---|
559 | return; |
---|
560 | } |
---|
561 | } |
---|
562 | else if( iVirtualEndY > iContDMaxPos ) |
---|
563 | { |
---|
564 | Int iXe = roftoi( (Double)(iContDMaxPos - (Int)ruhYs ) * ((Double)iL_DeltaX / (Double)iL_DeltaY) ) + iDeltaEnd; |
---|
565 | if( iXe < (Int)uiContDStartEndMax ) |
---|
566 | { |
---|
567 | ruhXe = (UChar)max( iXe, 0 ); |
---|
568 | ruhYe = (UChar)iContDMaxPos; |
---|
569 | |
---|
570 | return; |
---|
571 | } |
---|
572 | else |
---|
573 | { |
---|
574 | ruhXe = (UChar)iContDMaxPos; |
---|
575 | ruhYe = (UChar)max( (iContDMaxPos - (iXe - iContDMaxPos)), 0 ); |
---|
576 | |
---|
577 | std::swap( ruhXs, ruhXe ); |
---|
578 | std::swap( ruhYs, ruhYe ); |
---|
579 | return; |
---|
580 | } |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | Int iYe = iVirtualEndY - iDeltaEnd; |
---|
585 | if( iYe < 0 ) |
---|
586 | { |
---|
587 | ruhXe = (UChar)max( (iContDMaxPos + iYe), 0 ); |
---|
588 | ruhYe = 0; |
---|
589 | |
---|
590 | std::swap( ruhXs, ruhXe ); |
---|
591 | std::swap( ruhYs, ruhYe ); |
---|
592 | return; |
---|
593 | } |
---|
594 | else if( iYe > iContDMaxPos ) |
---|
595 | { |
---|
596 | ruhXe = (UChar)max( (iContDMaxPos - (iYe - iContDMaxPos)), 0 ); |
---|
597 | ruhYe = (UChar)iContDMaxPos; |
---|
598 | |
---|
599 | return; |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | ruhXe = (UChar)iContDMaxPos; |
---|
604 | ruhYe = (UChar)iYe; |
---|
605 | |
---|
606 | std::swap( ruhXs, ruhXe ); |
---|
607 | std::swap( ruhYs, ruhYe ); |
---|
608 | return; |
---|
609 | } |
---|
610 | } |
---|
611 | } |
---|
612 | #endif |
---|
613 | |
---|
614 | Void TComWedgelet::xGenerateWedgePattern() |
---|
615 | { |
---|
616 | UInt uiTempBlockSize = 0; |
---|
617 | UChar uhXs = 0, uhYs = 0, uhXe = 0, uhYe = 0; |
---|
618 | switch( m_eWedgeRes ) |
---|
619 | { |
---|
620 | case( DOUBLE_PEL ): { uiTempBlockSize = m_uiWidth; uhXs = (m_uhXs<<1); uhYs = (m_uhYs<<1); uhXe = (m_uhXe<<1); uhYe = (m_uhYe<<1); } break; |
---|
621 | case( FULL_PEL ): { uiTempBlockSize = m_uiWidth; uhXs = m_uhXs; uhYs = m_uhYs; uhXe = m_uhXe; uhYe = m_uhYe; } break; |
---|
622 | case( HALF_PEL ): { uiTempBlockSize = (m_uiWidth<<1); uhXs = m_uhXs; uhYs = m_uhYs; uhXe = m_uhXe; uhYe = m_uhYe; } break; |
---|
623 | } |
---|
624 | |
---|
625 | if( m_eWedgeRes == DOUBLE_PEL) // fix for line-end problem with DOUBLE_PEL resolution |
---|
626 | { |
---|
627 | if( m_uhOri == 1 ) { uhXs = uiTempBlockSize-1; } |
---|
628 | if( m_uhOri == 2 ) { uhXe = uiTempBlockSize-1; uhYs = uiTempBlockSize-1; } |
---|
629 | if( m_uhOri == 3 ) { uhYe = uiTempBlockSize-1; } |
---|
630 | if( m_uhOri == 4 ) { uhYe = uiTempBlockSize-1; } |
---|
631 | if( m_uhOri == 5 ) { uhXs = uiTempBlockSize-1; } |
---|
632 | } |
---|
633 | |
---|
634 | Bool* pbTempPattern = new Bool[ (uiTempBlockSize * uiTempBlockSize) ]; |
---|
635 | ::memset( pbTempPattern, 0, (uiTempBlockSize * uiTempBlockSize) * sizeof(Bool) ); |
---|
636 | Int iTempStride = uiTempBlockSize; |
---|
637 | |
---|
638 | xDrawEdgeLine( uhXs, uhYs, uhXe, uhYe, pbTempPattern, iTempStride ); |
---|
639 | |
---|
640 | switch( m_uhOri ) |
---|
641 | { |
---|
642 | case( 0 ): { for( UInt iX = 0; iX < uhXs; iX++ ) { UInt iY = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY++; } } } break; |
---|
643 | case( 1 ): { for( UInt iY = 0; iY < uhYs; iY++ ) { UInt iX = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX--; } } } break; |
---|
644 | case( 2 ): { for( UInt iX = uiTempBlockSize-1; iX > uhXs; iX-- ) { UInt iY = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY--; } } } break; |
---|
645 | case( 3 ): { for( UInt iY = uiTempBlockSize-1; iY > uhYs; iY-- ) { UInt iX = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX++; } } } break; |
---|
646 | case( 4 ): { for( UInt iY = 0; iY < uiTempBlockSize; iY++ ) { UInt iX = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX++; } } } break; |
---|
647 | case( 5 ): { for( UInt iX = 0; iX < uiTempBlockSize; iX++ ) { UInt iY = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY++; } } } break; |
---|
648 | } |
---|
649 | |
---|
650 | clear(); |
---|
651 | switch( m_eWedgeRes ) |
---|
652 | { |
---|
653 | case( DOUBLE_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break; |
---|
654 | case( FULL_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break; |
---|
655 | case( HALF_PEL ): // sub-sampling by factor 2 |
---|
656 | { |
---|
657 | Int iStride = getStride(); |
---|
658 | |
---|
659 | UInt uiOffX, uiOffY; |
---|
660 | switch( m_uhOri ) |
---|
661 | { |
---|
662 | case( 0 ): { uiOffX = 0; uiOffY = 0; } break; |
---|
663 | case( 1 ): { uiOffX = 1; uiOffY = 0; } break; |
---|
664 | case( 2 ): { uiOffX = 1; uiOffY = 1; } break; |
---|
665 | case( 3 ): { uiOffX = 0; uiOffY = 1; } break; |
---|
666 | case( 4 ): { uiOffX = 0; uiOffY = 0; } break; |
---|
667 | case( 5 ): { uiOffX = 0; uiOffY = 0; } break; |
---|
668 | default: { uiOffX = 0; uiOffY = 0; } break; |
---|
669 | } |
---|
670 | |
---|
671 | for(Int iY = 0; iY < m_uiHeight; iY++) |
---|
672 | { |
---|
673 | for(Int iX = 0; iX < m_uiWidth; iX++) |
---|
674 | { |
---|
675 | m_pbPattern[(iY * iStride) + iX] = pbTempPattern[(((iY<<1)+uiOffY) * iTempStride) + ((iX<<1)+uiOffX)]; |
---|
676 | } |
---|
677 | } |
---|
678 | } |
---|
679 | break; |
---|
680 | } |
---|
681 | |
---|
682 | if( pbTempPattern ) |
---|
683 | { |
---|
684 | delete [] pbTempPattern; |
---|
685 | pbTempPattern = NULL; |
---|
686 | } |
---|
687 | } |
---|
688 | |
---|
689 | Void TComWedgelet::xDrawEdgeLine( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, Bool* pbPattern, Int iPatternStride ) |
---|
690 | { |
---|
691 | Int x0 = (Int)uhXs; |
---|
692 | Int y0 = (Int)uhYs; |
---|
693 | Int x1 = (Int)uhXe; |
---|
694 | Int y1 = (Int)uhYe; |
---|
695 | |
---|
696 | // direction independent Bresenham line |
---|
697 | bool steep = (abs(y1 - y0) > abs(x1 - x0)); |
---|
698 | if( steep ) |
---|
699 | { |
---|
700 | std::swap( x0, y0 ); |
---|
701 | std::swap( x1, y1 ); |
---|
702 | } |
---|
703 | |
---|
704 | bool backward = ( x0 > x1 ); |
---|
705 | if( backward ) |
---|
706 | { |
---|
707 | std::swap( x0, x1 ); |
---|
708 | std::swap( y0, y1 ); |
---|
709 | } |
---|
710 | |
---|
711 | Int deltax = x1 - x0; |
---|
712 | Int deltay = abs(y1 - y0); |
---|
713 | double error = 0.0; |
---|
714 | double deltaerr = (double)deltay / (double)deltax; |
---|
715 | |
---|
716 | Int ystep; |
---|
717 | Int y = y0; |
---|
718 | if( y0 < y1 ) ystep = 1; |
---|
719 | else ystep = -1; |
---|
720 | |
---|
721 | for( Int x = x0; x <= x1; x++ ) |
---|
722 | { |
---|
723 | if( steep ) { pbPattern[(x * iPatternStride) + y] = true; } |
---|
724 | else { pbPattern[(y * iPatternStride) + x] = true; } |
---|
725 | |
---|
726 | error += deltaerr; |
---|
727 | if( error >= 0.5) |
---|
728 | { |
---|
729 | y += ystep; |
---|
730 | error = error - 1.0; |
---|
731 | } |
---|
732 | } |
---|
733 | } |
---|
734 | |
---|
735 | #if HHI_DMM_PRED_TEX |
---|
736 | TComWedgeDist::TComWedgeDist() |
---|
737 | { |
---|
738 | init(); |
---|
739 | } |
---|
740 | |
---|
741 | TComWedgeDist::~TComWedgeDist() |
---|
742 | { |
---|
743 | } |
---|
744 | |
---|
745 | Void TComWedgeDist::init() |
---|
746 | { |
---|
747 | m_afpDistortFunc[0] = TComWedgeDist::xGetSAD4; |
---|
748 | m_afpDistortFunc[1] = TComWedgeDist::xGetSAD8; |
---|
749 | m_afpDistortFunc[2] = TComWedgeDist::xGetSAD16; |
---|
750 | m_afpDistortFunc[3] = TComWedgeDist::xGetSAD32; |
---|
751 | |
---|
752 | m_afpDistortFunc[4] = TComWedgeDist::xGetSSE4; |
---|
753 | m_afpDistortFunc[5] = TComWedgeDist::xGetSSE8; |
---|
754 | m_afpDistortFunc[6] = TComWedgeDist::xGetSSE16; |
---|
755 | m_afpDistortFunc[7] = TComWedgeDist::xGetSSE32; |
---|
756 | } |
---|
757 | |
---|
758 | UInt TComWedgeDist::xGetSAD4( WedgeDistParam* pcDtParam ) |
---|
759 | { |
---|
760 | Pel* piOrg = pcDtParam->pOrg; |
---|
761 | Pel* piCur = pcDtParam->pCur; |
---|
762 | Int iRows = pcDtParam->iRows; |
---|
763 | Int iSubShift = pcDtParam->iSubShift; |
---|
764 | Int iSubStep = ( 1 << iSubShift ); |
---|
765 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
766 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
767 | |
---|
768 | UInt uiSum = 0; |
---|
769 | |
---|
770 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
771 | { |
---|
772 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
773 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
774 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
775 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
776 | |
---|
777 | piOrg += iStrideOrg; |
---|
778 | piCur += iStrideCur; |
---|
779 | } |
---|
780 | |
---|
781 | uiSum <<= iSubShift; |
---|
782 | return ( uiSum >> g_uiBitIncrement ); |
---|
783 | } |
---|
784 | |
---|
785 | UInt TComWedgeDist::xGetSAD8( WedgeDistParam* pcDtParam ) |
---|
786 | { |
---|
787 | Pel* piOrg = pcDtParam->pOrg; |
---|
788 | Pel* piCur = pcDtParam->pCur; |
---|
789 | Int iRows = pcDtParam->iRows; |
---|
790 | Int iSubShift = pcDtParam->iSubShift; |
---|
791 | Int iSubStep = ( 1 << iSubShift ); |
---|
792 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
793 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
794 | |
---|
795 | UInt uiSum = 0; |
---|
796 | |
---|
797 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
798 | { |
---|
799 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
800 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
801 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
802 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
803 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
804 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
805 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
806 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
807 | |
---|
808 | piOrg += iStrideOrg; |
---|
809 | piCur += iStrideCur; |
---|
810 | } |
---|
811 | |
---|
812 | uiSum <<= iSubShift; |
---|
813 | return ( uiSum >> g_uiBitIncrement ); |
---|
814 | } |
---|
815 | |
---|
816 | UInt TComWedgeDist::xGetSAD16( WedgeDistParam* pcDtParam ) |
---|
817 | { |
---|
818 | Pel* piOrg = pcDtParam->pOrg; |
---|
819 | Pel* piCur = pcDtParam->pCur; |
---|
820 | Int iRows = pcDtParam->iRows; |
---|
821 | Int iSubShift = pcDtParam->iSubShift; |
---|
822 | Int iSubStep = ( 1 << iSubShift ); |
---|
823 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
824 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
825 | |
---|
826 | UInt uiSum = 0; |
---|
827 | |
---|
828 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
829 | { |
---|
830 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
831 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
832 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
833 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
834 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
835 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
836 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
837 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
838 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
839 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
840 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
841 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
842 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
843 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
844 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
845 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
846 | |
---|
847 | piOrg += iStrideOrg; |
---|
848 | piCur += iStrideCur; |
---|
849 | } |
---|
850 | |
---|
851 | uiSum <<= iSubShift; |
---|
852 | return ( uiSum >> g_uiBitIncrement ); |
---|
853 | } |
---|
854 | |
---|
855 | UInt TComWedgeDist::xGetSAD32( WedgeDistParam* pcDtParam ) |
---|
856 | { |
---|
857 | Pel* piOrg = pcDtParam->pOrg; |
---|
858 | Pel* piCur = pcDtParam->pCur; |
---|
859 | Int iRows = pcDtParam->iRows; |
---|
860 | Int iSubShift = pcDtParam->iSubShift; |
---|
861 | Int iSubStep = ( 1 << iSubShift ); |
---|
862 | Int iStrideCur = pcDtParam->iStrideCur*iSubStep; |
---|
863 | Int iStrideOrg = pcDtParam->iStrideOrg*iSubStep; |
---|
864 | |
---|
865 | UInt uiSum = 0; |
---|
866 | |
---|
867 | for( ; iRows != 0; iRows-=iSubStep ) |
---|
868 | { |
---|
869 | uiSum += abs( piOrg[0] - piCur[0] ); |
---|
870 | uiSum += abs( piOrg[1] - piCur[1] ); |
---|
871 | uiSum += abs( piOrg[2] - piCur[2] ); |
---|
872 | uiSum += abs( piOrg[3] - piCur[3] ); |
---|
873 | uiSum += abs( piOrg[4] - piCur[4] ); |
---|
874 | uiSum += abs( piOrg[5] - piCur[5] ); |
---|
875 | uiSum += abs( piOrg[6] - piCur[6] ); |
---|
876 | uiSum += abs( piOrg[7] - piCur[7] ); |
---|
877 | uiSum += abs( piOrg[8] - piCur[8] ); |
---|
878 | uiSum += abs( piOrg[9] - piCur[9] ); |
---|
879 | uiSum += abs( piOrg[10] - piCur[10] ); |
---|
880 | uiSum += abs( piOrg[11] - piCur[11] ); |
---|
881 | uiSum += abs( piOrg[12] - piCur[12] ); |
---|
882 | uiSum += abs( piOrg[13] - piCur[13] ); |
---|
883 | uiSum += abs( piOrg[14] - piCur[14] ); |
---|
884 | uiSum += abs( piOrg[15] - piCur[15] ); |
---|
885 | uiSum += abs( piOrg[16] - piCur[16] ); |
---|
886 | uiSum += abs( piOrg[17] - piCur[17] ); |
---|
887 | uiSum += abs( piOrg[18] - piCur[18] ); |
---|
888 | uiSum += abs( piOrg[19] - piCur[19] ); |
---|
889 | uiSum += abs( piOrg[20] - piCur[20] ); |
---|
890 | uiSum += abs( piOrg[21] - piCur[21] ); |
---|
891 | uiSum += abs( piOrg[22] - piCur[22] ); |
---|
892 | uiSum += abs( piOrg[23] - piCur[23] ); |
---|
893 | uiSum += abs( piOrg[24] - piCur[24] ); |
---|
894 | uiSum += abs( piOrg[25] - piCur[25] ); |
---|
895 | uiSum += abs( piOrg[26] - piCur[26] ); |
---|
896 | uiSum += abs( piOrg[27] - piCur[27] ); |
---|
897 | uiSum += abs( piOrg[28] - piCur[28] ); |
---|
898 | uiSum += abs( piOrg[29] - piCur[29] ); |
---|
899 | uiSum += abs( piOrg[30] - piCur[30] ); |
---|
900 | uiSum += abs( piOrg[31] - piCur[31] ); |
---|
901 | |
---|
902 | piOrg += iStrideOrg; |
---|
903 | piCur += iStrideCur; |
---|
904 | } |
---|
905 | |
---|
906 | uiSum <<= iSubShift; |
---|
907 | return ( uiSum >> g_uiBitIncrement ); |
---|
908 | } |
---|
909 | |
---|
910 | UInt TComWedgeDist::xGetSSE4( WedgeDistParam* pcDtParam ) |
---|
911 | { |
---|
912 | Pel* piOrg = pcDtParam->pOrg; |
---|
913 | Pel* piCur = pcDtParam->pCur; |
---|
914 | Int iRows = pcDtParam->iRows; |
---|
915 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
916 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
917 | |
---|
918 | UInt uiSum = 0; |
---|
919 | UInt uiShift = g_uiBitIncrement<<1; |
---|
920 | |
---|
921 | Int iTemp; |
---|
922 | |
---|
923 | for( ; iRows != 0; iRows-- ) |
---|
924 | { |
---|
925 | |
---|
926 | iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
927 | iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
928 | iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
929 | iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
930 | |
---|
931 | piOrg += iStrideOrg; |
---|
932 | piCur += iStrideCur; |
---|
933 | } |
---|
934 | |
---|
935 | return ( uiSum ); |
---|
936 | } |
---|
937 | |
---|
938 | UInt TComWedgeDist::xGetSSE8( WedgeDistParam* pcDtParam ) |
---|
939 | { |
---|
940 | Pel* piOrg = pcDtParam->pOrg; |
---|
941 | Pel* piCur = pcDtParam->pCur; |
---|
942 | Int iRows = pcDtParam->iRows; |
---|
943 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
944 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
945 | |
---|
946 | UInt uiSum = 0; |
---|
947 | UInt uiShift = g_uiBitIncrement<<1; |
---|
948 | |
---|
949 | Int iTemp; |
---|
950 | |
---|
951 | for( ; iRows != 0; iRows-- ) |
---|
952 | { |
---|
953 | iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
954 | iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
955 | iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
956 | iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
957 | iTemp = piOrg[4] - piCur[4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
958 | iTemp = piOrg[5] - piCur[5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
959 | iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
960 | iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
961 | |
---|
962 | piOrg += iStrideOrg; |
---|
963 | piCur += iStrideCur; |
---|
964 | } |
---|
965 | |
---|
966 | return ( uiSum ); |
---|
967 | } |
---|
968 | |
---|
969 | UInt TComWedgeDist::xGetSSE16( WedgeDistParam* pcDtParam ) |
---|
970 | { |
---|
971 | Pel* piOrg = pcDtParam->pOrg; |
---|
972 | Pel* piCur = pcDtParam->pCur; |
---|
973 | Int iRows = pcDtParam->iRows; |
---|
974 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
975 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
976 | |
---|
977 | UInt uiSum = 0; |
---|
978 | UInt uiShift = g_uiBitIncrement<<1; |
---|
979 | |
---|
980 | Int iTemp; |
---|
981 | |
---|
982 | for( ; iRows != 0; iRows-- ) |
---|
983 | { |
---|
984 | |
---|
985 | iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
986 | iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
987 | iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
988 | iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
989 | iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
990 | iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
991 | iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
992 | iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
993 | iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
994 | iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
995 | iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
996 | iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
997 | iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
998 | iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
999 | iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1000 | iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1001 | |
---|
1002 | piOrg += iStrideOrg; |
---|
1003 | piCur += iStrideCur; |
---|
1004 | } |
---|
1005 | |
---|
1006 | return ( uiSum ); |
---|
1007 | } |
---|
1008 | |
---|
1009 | UInt TComWedgeDist::xGetSSE32( WedgeDistParam* pcDtParam ) |
---|
1010 | { |
---|
1011 | Pel* piOrg = pcDtParam->pOrg; |
---|
1012 | Pel* piCur = pcDtParam->pCur; |
---|
1013 | Int iRows = pcDtParam->iRows; |
---|
1014 | Int iStrideOrg = pcDtParam->iStrideOrg; |
---|
1015 | Int iStrideCur = pcDtParam->iStrideCur; |
---|
1016 | |
---|
1017 | UInt uiSum = 0; |
---|
1018 | UInt uiShift = g_uiBitIncrement<<1; |
---|
1019 | Int iTemp; |
---|
1020 | |
---|
1021 | for( ; iRows != 0; iRows-- ) |
---|
1022 | { |
---|
1023 | |
---|
1024 | iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1025 | iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1026 | iTemp = piOrg[ 2] - piCur[ 2]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1027 | iTemp = piOrg[ 3] - piCur[ 3]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1028 | iTemp = piOrg[ 4] - piCur[ 4]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1029 | iTemp = piOrg[ 5] - piCur[ 5]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1030 | iTemp = piOrg[ 6] - piCur[ 6]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1031 | iTemp = piOrg[ 7] - piCur[ 7]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1032 | iTemp = piOrg[ 8] - piCur[ 8]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1033 | iTemp = piOrg[ 9] - piCur[ 9]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1034 | iTemp = piOrg[10] - piCur[10]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1035 | iTemp = piOrg[11] - piCur[11]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1036 | iTemp = piOrg[12] - piCur[12]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1037 | iTemp = piOrg[13] - piCur[13]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1038 | iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1039 | iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1040 | iTemp = piOrg[16] - piCur[16]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1041 | iTemp = piOrg[17] - piCur[17]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1042 | iTemp = piOrg[18] - piCur[18]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1043 | iTemp = piOrg[19] - piCur[19]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1044 | iTemp = piOrg[20] - piCur[20]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1045 | iTemp = piOrg[21] - piCur[21]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1046 | iTemp = piOrg[22] - piCur[22]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1047 | iTemp = piOrg[23] - piCur[23]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1048 | iTemp = piOrg[24] - piCur[24]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1049 | iTemp = piOrg[25] - piCur[25]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1050 | iTemp = piOrg[26] - piCur[26]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1051 | iTemp = piOrg[27] - piCur[27]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1052 | iTemp = piOrg[28] - piCur[28]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1053 | iTemp = piOrg[29] - piCur[29]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1054 | iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1055 | iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift; |
---|
1056 | |
---|
1057 | piOrg += iStrideOrg; |
---|
1058 | piCur += iStrideCur; |
---|
1059 | } |
---|
1060 | |
---|
1061 | return ( uiSum ); |
---|
1062 | } |
---|
1063 | |
---|
1064 | Void TComWedgeDist::setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist, WedgeDistParam& rcDistParam ) |
---|
1065 | { |
---|
1066 | // set Block Width / Height |
---|
1067 | rcDistParam.iCols = uiBlkWidth; |
---|
1068 | rcDistParam.iRows = uiBlkHeight; |
---|
1069 | rcDistParam.DistFunc = m_afpDistortFunc[eWDist + g_aucConvertToBit[ rcDistParam.iCols ] ]; |
---|
1070 | |
---|
1071 | // initialize |
---|
1072 | rcDistParam.iSubShift = 0; |
---|
1073 | } |
---|
1074 | |
---|
1075 | UInt TComWedgeDist::getDistPart( Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, WedgeDist eWDist ) |
---|
1076 | { |
---|
1077 | WedgeDistParam cDtParam; |
---|
1078 | setDistParam( uiBlkWidth, uiBlkHeight, eWDist, cDtParam ); |
---|
1079 | cDtParam.pOrg = piOrg; |
---|
1080 | cDtParam.pCur = piCur; |
---|
1081 | cDtParam.iStrideOrg = iOrgStride; |
---|
1082 | cDtParam.iStrideCur = iCurStride; |
---|
1083 | cDtParam.iStep = 1; |
---|
1084 | |
---|
1085 | return cDtParam.DistFunc( &cDtParam ); |
---|
1086 | } |
---|
1087 | #endif |
---|