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