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 | #if H_3D_DIM_DMM |
---|
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 | m_bIsCoarse( false ) |
---|
55 | { |
---|
56 | create( uiWidth, uiHeight ); |
---|
57 | } |
---|
58 | |
---|
59 | TComWedgelet::TComWedgelet( const TComWedgelet &rcWedge ) : m_uhXs ( rcWedge.m_uhXs ), |
---|
60 | m_uhYs ( rcWedge.m_uhYs ), |
---|
61 | m_uhXe ( rcWedge.m_uhXe ), |
---|
62 | m_uhYe ( rcWedge.m_uhYe ), |
---|
63 | m_uhOri ( rcWedge.m_uhOri ), |
---|
64 | m_eWedgeRes( rcWedge.m_eWedgeRes ), |
---|
65 | m_bIsCoarse( rcWedge.m_bIsCoarse ), |
---|
66 | m_uiAng ( rcWedge.m_uiAng ), |
---|
67 | m_uiWidth ( rcWedge.m_uiWidth ), |
---|
68 | m_uiHeight ( rcWedge.m_uiHeight ), |
---|
69 | m_pbPattern( (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ) ) |
---|
70 | #if SHARP_DMM1_I0110 |
---|
71 | ,m_pbScaledPattern( g_wedgePattern ) |
---|
72 | #endif |
---|
73 | { |
---|
74 | ::memcpy( m_pbPattern, rcWedge.m_pbPattern, sizeof(Bool) * (m_uiWidth * m_uiHeight)); |
---|
75 | } |
---|
76 | |
---|
77 | TComWedgelet::~TComWedgelet(void) |
---|
78 | { |
---|
79 | destroy(); |
---|
80 | } |
---|
81 | |
---|
82 | Void TComWedgelet::create( UInt uiWidth, UInt uiHeight ) |
---|
83 | { |
---|
84 | assert( uiWidth > 0 && uiHeight > 0 ); |
---|
85 | |
---|
86 | m_uiWidth = uiWidth; |
---|
87 | m_uiHeight = uiHeight; |
---|
88 | |
---|
89 | m_pbPattern = (Bool*)xMalloc( Bool, (m_uiWidth * m_uiHeight) ); |
---|
90 | #if SHARP_DMM1_I0110 |
---|
91 | m_pbScaledPattern = g_wedgePattern; |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | Void TComWedgelet::destroy() |
---|
96 | { |
---|
97 | if( m_pbPattern ) { xFree( m_pbPattern ); m_pbPattern = NULL; } |
---|
98 | } |
---|
99 | |
---|
100 | Void TComWedgelet::clear() |
---|
101 | { |
---|
102 | ::memset( m_pbPattern, 0, (m_uiWidth * m_uiHeight) * sizeof(Bool) ); |
---|
103 | } |
---|
104 | |
---|
105 | Void TComWedgelet::findClosestAngle() |
---|
106 | { |
---|
107 | UInt uiAng=0,uiOptAng=0; |
---|
108 | UInt uiMinD=MAX_UINT; |
---|
109 | UInt uiTmpD=0; |
---|
110 | Int angTable[9] = {0, 2, 5, 9, 13, 17, 21, 26, 32}; |
---|
111 | |
---|
112 | UChar uhXs = m_uhXs; |
---|
113 | UChar uhYs = m_uhYs; |
---|
114 | UChar uhXe = m_uhXe; |
---|
115 | UChar uhYe = m_uhYe; |
---|
116 | |
---|
117 | for(uiAng=2; uiAng<=34; uiAng++) |
---|
118 | { |
---|
119 | Int iSign = (uiAng<VER_IDX && uiAng>HOR_IDX ) ? -1 : 1; |
---|
120 | Int iVer = uiAng>17 ? 32 : angTable[(uiAng>10) ? (uiAng-10) : (10-uiAng)]; |
---|
121 | Int iHor = uiAng<19 ? 32 : angTable[(uiAng>26) ? (uiAng-26) : (26-uiAng)]; |
---|
122 | |
---|
123 | uiTmpD = abs(iVer*iSign*(uhXs-uhXe) - iHor*(uhYe-uhYs)); |
---|
124 | |
---|
125 | if( uiTmpD < uiMinD ) |
---|
126 | { |
---|
127 | uiMinD = uiTmpD; |
---|
128 | uiOptAng = uiAng; |
---|
129 | } |
---|
130 | } |
---|
131 | m_uiAng = uiOptAng; |
---|
132 | } |
---|
133 | |
---|
134 | Void TComWedgelet::setWedgelet( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UChar uhOri, WedgeResolution eWedgeRes, Bool bIsCoarse ) |
---|
135 | { |
---|
136 | m_uhXs = uhXs; |
---|
137 | m_uhYs = uhYs; |
---|
138 | m_uhXe = uhXe; |
---|
139 | m_uhYe = uhYe; |
---|
140 | m_uhOri = uhOri; |
---|
141 | m_eWedgeRes = eWedgeRes; |
---|
142 | m_bIsCoarse = bIsCoarse; |
---|
143 | |
---|
144 | xGenerateWedgePattern(); |
---|
145 | } |
---|
146 | |
---|
147 | Bool TComWedgelet::checkNotPlain() |
---|
148 | { |
---|
149 | for( UInt k = 1; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
150 | { |
---|
151 | if( m_pbPattern[0] != m_pbPattern[k] ) |
---|
152 | { |
---|
153 | return true; |
---|
154 | } |
---|
155 | } |
---|
156 | return false; |
---|
157 | } |
---|
158 | |
---|
159 | Bool TComWedgelet::checkIdentical( Bool* pbRefPattern ) |
---|
160 | { |
---|
161 | for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
162 | { |
---|
163 | if( m_pbPattern[k] != pbRefPattern[k] ) |
---|
164 | { |
---|
165 | return false; |
---|
166 | } |
---|
167 | } |
---|
168 | return true; |
---|
169 | } |
---|
170 | |
---|
171 | Bool TComWedgelet::checkInvIdentical( Bool* pbRefPattern ) |
---|
172 | { |
---|
173 | for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) |
---|
174 | { |
---|
175 | if( m_pbPattern[k] == pbRefPattern[k] ) |
---|
176 | { |
---|
177 | return false; |
---|
178 | } |
---|
179 | } |
---|
180 | return true; |
---|
181 | } |
---|
182 | |
---|
183 | Void TComWedgelet::xGenerateWedgePattern() |
---|
184 | { |
---|
185 | UInt uiTempBlockSize = 0; |
---|
186 | UChar uhXs = 0, uhYs = 0, uhXe = 0, uhYe = 0; |
---|
187 | switch( m_eWedgeRes ) |
---|
188 | { |
---|
189 | #if !SHARP_DMM1_I0110 |
---|
190 | case( DOUBLE_PEL ): { uiTempBlockSize = m_uiWidth; uhXs = (m_uhXs<<1); uhYs = (m_uhYs<<1); uhXe = (m_uhXe<<1); uhYe = (m_uhYe<<1); } break; |
---|
191 | #endif |
---|
192 | case( FULL_PEL ): { uiTempBlockSize = m_uiWidth; uhXs = m_uhXs; uhYs = m_uhYs; uhXe = m_uhXe; uhYe = m_uhYe; } break; |
---|
193 | case( HALF_PEL ): { uiTempBlockSize = (m_uiWidth<<1); uhXs = m_uhXs; uhYs = m_uhYs; uhXe = m_uhXe; uhYe = m_uhYe; } break; |
---|
194 | } |
---|
195 | |
---|
196 | #if !SHARP_DMM1_I0110 |
---|
197 | if( m_eWedgeRes == DOUBLE_PEL) // adjust line-end for DOUBLE_PEL resolution |
---|
198 | { |
---|
199 | if( m_uhOri == 1 ) { uhXs = uiTempBlockSize-1; } |
---|
200 | if( m_uhOri == 2 ) { uhXe = uiTempBlockSize-1; uhYs = uiTempBlockSize-1; } |
---|
201 | if( m_uhOri == 3 ) { uhYe = uiTempBlockSize-1; } |
---|
202 | if( m_uhOri == 4 ) { uhYe = uiTempBlockSize-1; } |
---|
203 | if( m_uhOri == 5 ) { uhXs = uiTempBlockSize-1; } |
---|
204 | } |
---|
205 | #endif |
---|
206 | |
---|
207 | Bool* pbTempPattern = new Bool[ (uiTempBlockSize * uiTempBlockSize) ]; |
---|
208 | ::memset( pbTempPattern, 0, (uiTempBlockSize * uiTempBlockSize) * sizeof(Bool) ); |
---|
209 | Int iTempStride = uiTempBlockSize; |
---|
210 | |
---|
211 | xDrawEdgeLine( uhXs, uhYs, uhXe, uhYe, pbTempPattern, iTempStride ); |
---|
212 | |
---|
213 | switch( m_uhOri ) |
---|
214 | { |
---|
215 | 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; |
---|
216 | 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; |
---|
217 | 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; |
---|
218 | 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; |
---|
219 | case( 4 ): |
---|
220 | { |
---|
221 | if( (uhXs+uhXe) < uiTempBlockSize ) { for( UInt iY = 0; iY < uiTempBlockSize; iY++ ) { UInt iX = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX++; } } } |
---|
222 | else { for( UInt iY = 0; iY < uiTempBlockSize; iY++ ) { UInt iX = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iX--; } } } |
---|
223 | } |
---|
224 | break; |
---|
225 | case( 5 ): |
---|
226 | { |
---|
227 | if( (uhYs+uhYe) < uiTempBlockSize ) { for( UInt iX = 0; iX < uiTempBlockSize; iX++ ) { UInt iY = 0; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY++; } } } |
---|
228 | else { for( UInt iX = 0; iX < uiTempBlockSize; iX++ ) { UInt iY = uiTempBlockSize-1; while( pbTempPattern[(iY * iTempStride) + iX] == false ) { pbTempPattern[(iY * iTempStride) + iX] = true; iY--; } } } |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | clear(); |
---|
233 | switch( m_eWedgeRes ) |
---|
234 | { |
---|
235 | #if !SHARP_DMM1_I0110 |
---|
236 | case( DOUBLE_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break; |
---|
237 | #endif |
---|
238 | case( FULL_PEL ): { for( UInt k = 0; k < (m_uiWidth * m_uiHeight); k++ ) { m_pbPattern[k] = pbTempPattern[k]; }; } break; |
---|
239 | case( HALF_PEL ): // sub-sampling by factor 2 |
---|
240 | { |
---|
241 | Int iStride = getStride(); |
---|
242 | |
---|
243 | UInt uiOffX, uiOffY; |
---|
244 | switch( m_uhOri ) |
---|
245 | { |
---|
246 | case( 0 ): { uiOffX = 0; uiOffY = 0; } break; |
---|
247 | case( 1 ): { uiOffX = 1; uiOffY = 0; } break; |
---|
248 | case( 2 ): { uiOffX = 1; uiOffY = 1; } break; |
---|
249 | case( 3 ): { uiOffX = 0; uiOffY = 1; } break; |
---|
250 | case( 4 ): |
---|
251 | { |
---|
252 | if( (uhXs+uhXe) < uiTempBlockSize ) { uiOffX = 0; uiOffY = 0; } |
---|
253 | else { uiOffX = 1; uiOffY = 0; } |
---|
254 | } |
---|
255 | break; |
---|
256 | case( 5 ): |
---|
257 | { |
---|
258 | if( (uhYs+uhYe) < uiTempBlockSize ) { uiOffX = 0; uiOffY = 0; } |
---|
259 | else { uiOffX = 0; uiOffY = 1; } |
---|
260 | } |
---|
261 | break; |
---|
262 | default: { uiOffX = 0; uiOffY = 0; } break; |
---|
263 | } |
---|
264 | |
---|
265 | for(Int iY = 0; iY < m_uiHeight; iY++) |
---|
266 | { |
---|
267 | for(Int iX = 0; iX < m_uiWidth; iX++) |
---|
268 | { |
---|
269 | m_pbPattern[(iY * iStride) + iX] = pbTempPattern[(((iY<<1)+uiOffY) * iTempStride) + ((iX<<1)+uiOffX)]; |
---|
270 | } |
---|
271 | } |
---|
272 | } |
---|
273 | break; |
---|
274 | } |
---|
275 | |
---|
276 | if( pbTempPattern ) |
---|
277 | { |
---|
278 | delete [] pbTempPattern; |
---|
279 | pbTempPattern = NULL; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | Void TComWedgelet::xDrawEdgeLine( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, Bool* pbPattern, Int iPatternStride ) |
---|
284 | { |
---|
285 | Int x0 = (Int)uhXs; |
---|
286 | Int y0 = (Int)uhYs; |
---|
287 | Int x1 = (Int)uhXe; |
---|
288 | Int y1 = (Int)uhYe; |
---|
289 | |
---|
290 | // direction independent Bresenham line |
---|
291 | bool steep = (abs(y1 - y0) > abs(x1 - x0)); |
---|
292 | if( steep ) |
---|
293 | { |
---|
294 | std::swap( x0, y0 ); |
---|
295 | std::swap( x1, y1 ); |
---|
296 | } |
---|
297 | |
---|
298 | bool backward = ( x0 > x1 ); |
---|
299 | if( backward ) |
---|
300 | { |
---|
301 | std::swap( x0, x1 ); |
---|
302 | std::swap( y0, y1 ); |
---|
303 | } |
---|
304 | |
---|
305 | Int deltax = x1 - x0; |
---|
306 | Int deltay = abs(y1 - y0); |
---|
307 | Int error = 0; |
---|
308 | Int deltaerr = (deltay<<1); |
---|
309 | |
---|
310 | Int ystep; |
---|
311 | Int y = y0; |
---|
312 | if( y0 < y1 ) ystep = 1; |
---|
313 | else ystep = -1; |
---|
314 | |
---|
315 | for( Int x = x0; x <= x1; x++ ) |
---|
316 | { |
---|
317 | if( steep ) { pbPattern[(x * iPatternStride) + y] = true; } |
---|
318 | else { pbPattern[(y * iPatternStride) + x] = true; } |
---|
319 | |
---|
320 | error += deltaerr; |
---|
321 | if( error >= deltax ) |
---|
322 | { |
---|
323 | y += ystep; |
---|
324 | error = error - (deltax<<1); |
---|
325 | } |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | #if SHARP_DMM1_I0110 |
---|
330 | Bool* TComWedgelet::getScaledPattern(UInt uiDstSize) |
---|
331 | { |
---|
332 | Bool *pbSrcPat = this->getPattern(); |
---|
333 | UInt uiSrcSize = this->getStride(); |
---|
334 | |
---|
335 | Int scale = (g_aucConvertToBit[uiDstSize] - g_aucConvertToBit[uiSrcSize]); |
---|
336 | assert(scale>=0); |
---|
337 | for (Int y=0; y<uiDstSize; y++) |
---|
338 | { |
---|
339 | for (Int x=0; x<uiDstSize; x++) |
---|
340 | { |
---|
341 | Int srcX = x>>scale; |
---|
342 | Int srcY = y>>scale; |
---|
343 | m_pbScaledPattern[y*uiDstSize + x] = pbSrcPat[ srcY*uiSrcSize + srcX ]; |
---|
344 | } |
---|
345 | } |
---|
346 | return m_pbScaledPattern; |
---|
347 | } |
---|
348 | #endif |
---|
349 | |
---|
350 | TComWedgeNode::TComWedgeNode() |
---|
351 | { |
---|
352 | m_uiPatternIdx = DMM_NO_WEDGEINDEX; |
---|
353 | for( UInt uiPos = 0; uiPos < DMM_NUM_WEDGE_REFINES; uiPos++ ) |
---|
354 | { |
---|
355 | m_uiRefineIdx[uiPos] = DMM_NO_WEDGEINDEX; |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | UInt TComWedgeNode::getPatternIdx() |
---|
360 | { |
---|
361 | return m_uiPatternIdx; |
---|
362 | } |
---|
363 | UInt TComWedgeNode::getRefineIdx( UInt uiPos ) |
---|
364 | { |
---|
365 | assert( uiPos < DMM_NUM_WEDGE_REFINES ); |
---|
366 | return m_uiRefineIdx[uiPos]; |
---|
367 | } |
---|
368 | Void TComWedgeNode::setPatternIdx( UInt uiIdx ) |
---|
369 | { |
---|
370 | m_uiPatternIdx = uiIdx; |
---|
371 | } |
---|
372 | Void TComWedgeNode::setRefineIdx( UInt uiIdx, UInt uiPos ) |
---|
373 | { |
---|
374 | assert( uiPos < DMM_NUM_WEDGE_REFINES ); |
---|
375 | m_uiRefineIdx[uiPos] = uiIdx; |
---|
376 | } |
---|
377 | #endif //H_3D_DIM_DMM |
---|