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 | /** \file CommonDef.h |
---|
37 | \brief Defines constants, macros and tool parameters |
---|
38 | */ |
---|
39 | |
---|
40 | #ifndef __COMMONDEF__ |
---|
41 | #define __COMMONDEF__ |
---|
42 | |
---|
43 | // this pragma can be used for turning off "signed and unsigned mismatch" |
---|
44 | #if _MSC_VER > 1000 |
---|
45 | #pragma warning( disable : 4018 ) |
---|
46 | #endif // _MSC_VER > 1000 |
---|
47 | #include "TypeDef.h" |
---|
48 | #include "TComRom.h" |
---|
49 | |
---|
50 | #include <string> |
---|
51 | #include <assert.h> |
---|
52 | #include <stdlib.h> |
---|
53 | #include <vector> |
---|
54 | |
---|
55 | // ==================================================================================================================== |
---|
56 | // Version information |
---|
57 | // ==================================================================================================================== |
---|
58 | |
---|
59 | #define HM_VERSION "3.0rc2" ///< Current software version |
---|
60 | #define NV_VERSION "0.3" ///< Current software version |
---|
61 | |
---|
62 | // ==================================================================================================================== |
---|
63 | // Platform information |
---|
64 | // ==================================================================================================================== |
---|
65 | |
---|
66 | #ifdef __GNUC__ |
---|
67 | #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ |
---|
68 | #ifdef __IA64__ |
---|
69 | #define NVM_ONARCH "[on 64-bit] " |
---|
70 | #else |
---|
71 | #define NVM_ONARCH "[on 32-bit] " |
---|
72 | #endif |
---|
73 | #endif |
---|
74 | |
---|
75 | #ifdef __INTEL_COMPILER |
---|
76 | #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER |
---|
77 | #elif _MSC_VER |
---|
78 | #define NVM_COMPILEDBY "[VS %d]", _MSC_VER |
---|
79 | #endif |
---|
80 | |
---|
81 | #ifndef NVM_COMPILEDBY |
---|
82 | #define NVM_COMPILEDBY "[Unk-CXX]" |
---|
83 | #endif |
---|
84 | |
---|
85 | #ifdef _WIN32 |
---|
86 | #define NVM_ONOS "[Windows]" |
---|
87 | #elif __linux |
---|
88 | #define NVM_ONOS "[Linux]" |
---|
89 | #elif __CYGWIN__ |
---|
90 | #define NVM_ONOS "[Cygwin]" |
---|
91 | #elif __APPLE__ |
---|
92 | #define NVM_ONOS "[Mac OS X]" |
---|
93 | #else |
---|
94 | #define NVM_ONOS "[Unk-OS]" |
---|
95 | #endif |
---|
96 | |
---|
97 | #define NVM_BITS "[%d bit] ", (sizeof(void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S |
---|
98 | |
---|
99 | #ifndef NULL |
---|
100 | #define NULL 0 |
---|
101 | #endif |
---|
102 | |
---|
103 | |
---|
104 | // ==================================================================================================================== |
---|
105 | // Common constants |
---|
106 | // ==================================================================================================================== |
---|
107 | |
---|
108 | #define _SUMMARY_OUT_ 0 ///< print-out PSNR results of all slices to summary.txt |
---|
109 | #define _SUMMARY_PIC_ 0 ///< print-out PSNR results for each slice type to summary.txt |
---|
110 | |
---|
111 | #define MAX_REF_PIC_NUM 64 |
---|
112 | #define MAX_GOP 64 ///< max. value of hierarchical GOP size |
---|
113 | |
---|
114 | #define MAX_NUM_REF 4 ///< max. value of multiple reference frames |
---|
115 | #if DCM_COMB_LIST |
---|
116 | #define MAX_NUM_REF_LC 8 ///< max. value of combined reference frames |
---|
117 | #endif |
---|
118 | |
---|
119 | #define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer |
---|
120 | #define MAX_UINT64 0xFFFFFFFFFFFFFFFFU |
---|
121 | #define MAX_INT 2147483647 ///< max. value of signed 32-bit integer |
---|
122 | #define MIN_INT (-2147483647-1) // < min. value of signed 32-bit integer |
---|
123 | #define MAX_DOUBLE 1.7e+308 ///< max. value of double-type value |
---|
124 | |
---|
125 | #define MIN_QP 0 |
---|
126 | #define MAX_QP 51 |
---|
127 | |
---|
128 | #define NOT_VALID -1 |
---|
129 | |
---|
130 | #define STD_CAM_PARAMETERS_PRECISION 5 ///< quarter luma sample accuarcy for derived disparities (as default) |
---|
131 | |
---|
132 | #define MAX_INPUT_VIEW_NUM 10 ///< max. number of input view for multiview coding |
---|
133 | |
---|
134 | #if HHI_VSO |
---|
135 | #define MAX_ERREF_VIEW_NUM 15 ///< max. number of virtual external reference views |
---|
136 | #endif |
---|
137 | #define LOG2_DISP_PREC_LUT 2 ///< log2 of disparity precision used in integer disparity LUTs |
---|
138 | |
---|
139 | |
---|
140 | #if ( HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED || POZNAN_MP_USE_DEPTH_MAP_GENERATION) |
---|
141 | #define DEPTH_MAP_GENERATION 1 |
---|
142 | #else |
---|
143 | #define DEPTH_MAP_GENERATION 0 |
---|
144 | #endif |
---|
145 | |
---|
146 | //>>>>> generation and usage of virtual prediction depth maps >>>>> |
---|
147 | #define PDM_ONE_DEPTH_PER_PU 1 // use only a single depth for a prediction unit (in update) |
---|
148 | #define PDM_NO_INTER_UPDATE 1 // no update for inter (but not inter-view) predicted blocks |
---|
149 | #define PDM_MERGE_POS 0 // position of pdm in merge list (0..5) |
---|
150 | #define PDM_AMVP_POS 2 // position of pdm in amvp list (0..3) |
---|
151 | #define PDM_OUTPUT_PRED_DEPTH_MAP 0 // output prediction depth map (for debugging) |
---|
152 | |
---|
153 | #define PDM_INTERNAL_CALC_BIT_DEPTH 31 // bit depth for internal calculations (32 - 1 for signed values) |
---|
154 | #define PDM_BITDEPTH_VIRT_DEPTH 15 // bit depth for virtual depth storage (16 - 1 for signed values) |
---|
155 | #define PDM_LOG2_MAX_ABS_NORMAL_DISPARITY 8 // maximum absolute normal disparity = 256 (for setting accuracy) |
---|
156 | #define PDM_VIRT_DEPTH_PRECISION 4 // must be greater than or equal to 2 (since MVs are given in quarter-pel units) |
---|
157 | |
---|
158 | #define PDM_INTER_CALC_SHIFT ( PDM_INTERNAL_CALC_BIT_DEPTH - PDM_BITDEPTH_VIRT_DEPTH ) // avoids overflow |
---|
159 | #define PDM_LOG4_SCALE_DENOMINATOR ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY + PDM_VIRT_DEPTH_PRECISION ) // accuracy of scaling factor |
---|
160 | #define PDM_OFFSET_SHIFT ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY ) // accuracy of offset |
---|
161 | |
---|
162 | #define PDM_MAX_ABS_VIRT_DEPTH ( ( 1 << PDM_BITDEPTH_VIRT_DEPTH ) - 1 ) |
---|
163 | #define PDM_UNDEFINED_DEPTH ( -( 1 << PDM_BITDEPTH_VIRT_DEPTH ) ) |
---|
164 | |
---|
165 | #define PDM_USE_FOR_IVIEW 1 |
---|
166 | #define PDM_USE_FOR_INTER 2 |
---|
167 | #define PDM_USE_FOR_MERGE 4 |
---|
168 | |
---|
169 | #define PDM_SUBSAMPLING_EXP 2 // subsampling factor is 2^PDM_SUBSAMPLING_EXP |
---|
170 | #define PDM_SUB_SAMP_EXP_X(Pdm) ((Pdm)==1?PDM_SUBSAMPLING_EXP:0) |
---|
171 | #define PDM_SUB_SAMP_EXP_Y(Pdm) ((Pdm)==1?PDM_SUBSAMPLING_EXP:0) |
---|
172 | //<<<<< generation and usage of virtual prediction depth maps <<<<< |
---|
173 | |
---|
174 | #define OUTPUT_RESIDUAL_PICTURES 0 // output residual pictures (for debugging) |
---|
175 | |
---|
176 | #define HHI_MPI_MERGE_POS 0 // position of mvi in merge list (0..5) |
---|
177 | |
---|
178 | // ==================================================================================================================== |
---|
179 | // POZNAN DEFINE SECTION |
---|
180 | // ==================================================================================================================== |
---|
181 | #define POZNAN_OUTPUT_AVAILABLE_MAP 0 // output available map (for debugging) |
---|
182 | #define POZNAN_OUTPUT_SYNTH 0 // output synthesised view (for debugging) |
---|
183 | |
---|
184 | #if POZNAN_DBMP |
---|
185 | #define POZNAN_DBMP_MERGE_POS 0 // position of DBMP candidate in merge list for coding (0..6) - overwrites PDM_MERGE_POS settings, is overwritten by HHI_MPI_MERGE_POS settings!!! |
---|
186 | #endif |
---|
187 | |
---|
188 | // ==================================================================================================================== |
---|
189 | // Macro functions |
---|
190 | // ==================================================================================================================== |
---|
191 | |
---|
192 | #define Max(x, y) ((x)>(y)?(x):(y)) ///< max of (x, y) |
---|
193 | #define Min(x, y) ((x)<(y)?(x):(y)) ///< min of (x, y) |
---|
194 | #define Median(a,b,c) ((a)>(b)?(a)>(c)?(b)>(c)?(b):(c):(a):(b)>(c)?(a)>(c)?(a):(c):(b)) ///< 3-point median |
---|
195 | #define Clip(x) ( Min(g_uiIBDI_MAX, Max( 0, (x)) ) ) ///< clip with bit-depth range |
---|
196 | #define Clip3( MinVal, MaxVal, a) ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) ) ///< general min/max clip |
---|
197 | #define RemoveBitIncrement(x) ( ((x) + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement ) ///< Remove Bit increment |
---|
198 | |
---|
199 | #define SizeOfLUT 256 |
---|
200 | |
---|
201 | #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free |
---|
202 | #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) |
---|
203 | #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 ) |
---|
204 | #define xFree( ptr ) _aligned_free ( ptr ) |
---|
205 | #else |
---|
206 | #define xMalloc( type, len ) malloc ( sizeof(type)*(len) ) |
---|
207 | #define xFree( ptr ) free ( ptr ) |
---|
208 | #endif |
---|
209 | |
---|
210 | #define FATAL_ERROR_0(MESSAGE, EXITCODE) \ |
---|
211 | { \ |
---|
212 | printf(MESSAGE); \ |
---|
213 | exit(EXITCODE); \ |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | // ==================================================================================================================== |
---|
218 | // Coding tool configuration |
---|
219 | // ==================================================================================================================== |
---|
220 | |
---|
221 | // modified LCEC coefficient coding |
---|
222 | #if QC_MOD_LCEC |
---|
223 | #define MAX_TR1 4 |
---|
224 | #endif |
---|
225 | |
---|
226 | // AMVP: advanced motion vector prediction |
---|
227 | #define AMVP_MAX_NUM_CANDS 6 ///< max number of final candidates |
---|
228 | // MERGE |
---|
229 | #if POZNAN_DBMP |
---|
230 | #define MRG_MAX_NUM_CANDS 7 |
---|
231 | #define POZNAN_DBMP_MRG_CAND MRG_MAX_NUM_CANDS-1 // position of DBMP candidate in merge list (0..6) |
---|
232 | #else |
---|
233 | #define MRG_MAX_NUM_CANDS 6 |
---|
234 | #endif |
---|
235 | |
---|
236 | // Reference memory management |
---|
237 | #define DYN_REF_FREE 0 ///< dynamic free of reference memories |
---|
238 | |
---|
239 | // defines for multiview coding |
---|
240 | #define MAX_NUMBER_VIEWS 10 |
---|
241 | |
---|
242 | // Explicit temporal layer QP offset |
---|
243 | #define MAX_TLAYER 10 ///< max number of temporal layer |
---|
244 | #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode |
---|
245 | |
---|
246 | // Fast estimation of generalized B in low-delay mode |
---|
247 | #define GPB_SIMPLE 1 ///< Simple GPB mode |
---|
248 | #if GPB_SIMPLE |
---|
249 | #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction |
---|
250 | #endif |
---|
251 | |
---|
252 | // Fast ME using smoother MV assumption |
---|
253 | #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option |
---|
254 | |
---|
255 | // Adaptive search range depending on POC difference |
---|
256 | #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range |
---|
257 | |
---|
258 | #define ENABLE_IBDI 0 |
---|
259 | |
---|
260 | #define CLIP_TO_709_RANGE 0 |
---|
261 | |
---|
262 | // IBDI range restriction for skipping clip |
---|
263 | #define IBDI_NOCLIP_RANGE 0 ///< restrict max. value after IBDI to skip clip |
---|
264 | |
---|
265 | // Early-skip threshold (encoder) |
---|
266 | #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] |
---|
267 | |
---|
268 | const int g_iShift8x8 = 2; |
---|
269 | const int g_iShift16x16 = 2; |
---|
270 | const int g_iShift32x32 = 2; |
---|
271 | const int g_iShift64x64 = 2; |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | //RENDERER |
---|
276 | #define REN_LUMA_MARGIN ( g_uiMaxCUWidth + 12 ) |
---|
277 | #define REN_VDWEIGHT_PREC 8 |
---|
278 | #define REN_IS_FILLED ( 1 << REN_VDWEIGHT_PREC ) |
---|
279 | #define REN_USED_PEL g_uiIBDI_MAX |
---|
280 | #define REN_UNUSED_PEL 0 |
---|
281 | #define REN_IS_HOLE 0 |
---|
282 | |
---|
283 | /* End of Rounding control */ |
---|
284 | |
---|
285 | enum NalRefIdc |
---|
286 | { |
---|
287 | NAL_REF_IDC_PRIORITY_LOWEST = 0, |
---|
288 | NAL_REF_IDC_PRIORITY_LOW, |
---|
289 | NAL_REF_IDC_PRIORITY_HIGH, |
---|
290 | NAL_REF_IDC_PRIORITY_HIGHEST |
---|
291 | }; |
---|
292 | |
---|
293 | enum NalUnitType |
---|
294 | { |
---|
295 | NAL_UNIT_UNSPECIFIED_0 = 0, |
---|
296 | NAL_UNIT_CODED_SLICE, |
---|
297 | NAL_UNIT_CODED_SLICE_DATAPART_A, |
---|
298 | NAL_UNIT_CODED_SLICE_DATAPART_B, |
---|
299 | #if DCM_DECODING_REFRESH |
---|
300 | NAL_UNIT_CODED_SLICE_CDR, |
---|
301 | #else |
---|
302 | NAL_UNIT_CODED_SLICE_DATAPART_C, |
---|
303 | #endif |
---|
304 | NAL_UNIT_CODED_SLICE_IDR, |
---|
305 | NAL_UNIT_SEI, |
---|
306 | NAL_UNIT_SPS, |
---|
307 | NAL_UNIT_PPS, |
---|
308 | NAL_UNIT_ACCESS_UNIT_DELIMITER, |
---|
309 | NAL_UNIT_END_OF_SEQUENCE, |
---|
310 | NAL_UNIT_END_OF_STREAM, |
---|
311 | NAL_UNIT_FILLER_DATA, |
---|
312 | NAL_UNIT_RESERVED_13, |
---|
313 | NAL_UNIT_RESERVED_14, |
---|
314 | NAL_UNIT_RESERVED_15, |
---|
315 | NAL_UNIT_RESERVED_16, |
---|
316 | NAL_UNIT_RESERVED_17, |
---|
317 | NAL_UNIT_RESERVED_18, |
---|
318 | NAL_UNIT_RESERVED_19, |
---|
319 | NAL_UNIT_RESERVED_20, |
---|
320 | NAL_UNIT_RESERVED_21, |
---|
321 | NAL_UNIT_RESERVED_22, |
---|
322 | NAL_UNIT_RESERVED_23, |
---|
323 | NAL_UNIT_UNSPECIFIED_24, |
---|
324 | NAL_UNIT_UNSPECIFIED_25, |
---|
325 | NAL_UNIT_UNSPECIFIED_26, |
---|
326 | NAL_UNIT_UNSPECIFIED_27, |
---|
327 | NAL_UNIT_UNSPECIFIED_28, |
---|
328 | NAL_UNIT_UNSPECIFIED_29, |
---|
329 | NAL_UNIT_UNSPECIFIED_30, |
---|
330 | NAL_UNIT_UNSPECIFIED_31, |
---|
331 | NAL_UNIT_INVALID, |
---|
332 | }; |
---|
333 | |
---|
334 | typedef _AlfParam ALFParam; |
---|
335 | #if MTK_SAO |
---|
336 | typedef _SaoParam SAOParam; |
---|
337 | #endif |
---|
338 | |
---|
339 | |
---|
340 | class VideoCodecException |
---|
341 | { |
---|
342 | public: |
---|
343 | VideoCodecException() : m_acFile( "unspecified" ), m_uiLine( 0 ) {} |
---|
344 | VideoCodecException( const char *pcFile, UInt uiLine ) : m_acFile( pcFile ), m_uiLine( uiLine ) {} |
---|
345 | |
---|
346 | std::string exceptionFile() const { return m_acFile; } |
---|
347 | UInt exceptionLine() const { return m_uiLine; } |
---|
348 | |
---|
349 | private: |
---|
350 | std::string m_acFile; |
---|
351 | UInt m_uiLine; |
---|
352 | }; |
---|
353 | |
---|
354 | #define RETURN_ERR_ON_EXCEPTION \ |
---|
355 | catch( std::exception &cEx ) \ |
---|
356 | { \ |
---|
357 | std::cerr << "Abnormal program termination: " << cEx.what() << std::endl; \ |
---|
358 | return Err::m_nERR; \ |
---|
359 | } \ |
---|
360 | catch( VideoCodecException &cEx ) \ |
---|
361 | { \ |
---|
362 | std::cerr << std::endl << "VideoCodecExcteption caught at: " << std::endl; \ |
---|
363 | std::cerr << "File: " << cEx.exceptionFile() << std::endl; \ |
---|
364 | std::cerr << "Line: " << cEx.exceptionLine() << std::endl; \ |
---|
365 | return Err::m_nERR; \ |
---|
366 | } \ |
---|
367 | catch( ... ) \ |
---|
368 | { \ |
---|
369 | std::cerr << "Caught unknown exception" << std::endl; \ |
---|
370 | return Err::m_nERR; \ |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | #define TOT( exp ) { if( exp ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
375 | #define TOF( exp ) { if( !(exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
376 | #define TNOK( exp ) { if( Err::m_nOK != (exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
377 | |
---|
378 | #if defined( _DEBUG ) |
---|
379 | |
---|
380 | #define TOT_DBG( exp ) TOT( exp ) |
---|
381 | #define TOF_DBG( exp ) TOF( exp ) |
---|
382 | |
---|
383 | #else |
---|
384 | |
---|
385 | #define TOT_DBG( exp ) ((void)0) |
---|
386 | #define TOF_DBG( exp ) ((void)0) |
---|
387 | |
---|
388 | #endif |
---|
389 | |
---|
390 | typedef int ErrVal; |
---|
391 | |
---|
392 | |
---|
393 | class Err |
---|
394 | { |
---|
395 | public: |
---|
396 | enum |
---|
397 | { |
---|
398 | m_nOK = 0, |
---|
399 | m_nERR = -1, |
---|
400 | m_nEndOfFile = -2, |
---|
401 | m_nEndOfBuffer = -3, |
---|
402 | m_nInvalidParameter = -4, |
---|
403 | m_nDataNotAvailable = -5, |
---|
404 | m_nSizeNotAvailable = -5, |
---|
405 | }; |
---|
406 | }; |
---|
407 | |
---|
408 | |
---|
409 | #define ROF( exp ) \ |
---|
410 | { \ |
---|
411 | if( !( exp ) ) \ |
---|
412 | { \ |
---|
413 | assert( 0 ); \ |
---|
414 | return -1; \ |
---|
415 | } \ |
---|
416 | } |
---|
417 | |
---|
418 | #define ROT( exp ) \ |
---|
419 | { \ |
---|
420 | if( ( exp ) ) \ |
---|
421 | { \ |
---|
422 | assert( 0 ); \ |
---|
423 | return -1; \ |
---|
424 | } \ |
---|
425 | } |
---|
426 | |
---|
427 | #define ROFS( exp ) \ |
---|
428 | { \ |
---|
429 | if( !( exp ) ) \ |
---|
430 | { \ |
---|
431 | return -1; \ |
---|
432 | } \ |
---|
433 | } |
---|
434 | |
---|
435 | #define ROTS( exp ) \ |
---|
436 | { \ |
---|
437 | if( ( exp ) ) \ |
---|
438 | { \ |
---|
439 | return -1; \ |
---|
440 | } \ |
---|
441 | } |
---|
442 | |
---|
443 | #define ROFR( exp, retVal ) \ |
---|
444 | { \ |
---|
445 | if( !( exp ) ) \ |
---|
446 | { \ |
---|
447 | assert( 0 ); \ |
---|
448 | return retVal; \ |
---|
449 | } \ |
---|
450 | } |
---|
451 | |
---|
452 | #define ROTR( exp, retVal ) \ |
---|
453 | { \ |
---|
454 | if( ( exp ) ) \ |
---|
455 | { \ |
---|
456 | assert( 0 ); \ |
---|
457 | return retVal; \ |
---|
458 | } \ |
---|
459 | } |
---|
460 | |
---|
461 | #define ROFRS( exp, retVal ) \ |
---|
462 | { \ |
---|
463 | if( !( exp ) ) \ |
---|
464 | { \ |
---|
465 | return retVal; \ |
---|
466 | } \ |
---|
467 | } |
---|
468 | |
---|
469 | #define ROTRS( exp, retVal ) \ |
---|
470 | { \ |
---|
471 | if( ( exp ) ) \ |
---|
472 | { \ |
---|
473 | return retVal; \ |
---|
474 | } \ |
---|
475 | } |
---|
476 | |
---|
477 | #define ROFV( exp ) \ |
---|
478 | { \ |
---|
479 | if( !( exp ) ) \ |
---|
480 | { \ |
---|
481 | assert( 0 ); \ |
---|
482 | return; \ |
---|
483 | } \ |
---|
484 | } |
---|
485 | |
---|
486 | #define ROTV( exp ) \ |
---|
487 | { \ |
---|
488 | if( ( exp ) ) \ |
---|
489 | { \ |
---|
490 | assert( 0 ); \ |
---|
491 | return; \ |
---|
492 | } \ |
---|
493 | } |
---|
494 | |
---|
495 | #define ROFVS( exp ) \ |
---|
496 | { \ |
---|
497 | if( !( exp ) ) \ |
---|
498 | { \ |
---|
499 | return; \ |
---|
500 | } \ |
---|
501 | } |
---|
502 | |
---|
503 | #define ROTVS( exp ) \ |
---|
504 | { \ |
---|
505 | if( ( exp ) ) \ |
---|
506 | { \ |
---|
507 | return; \ |
---|
508 | } \ |
---|
509 | } |
---|
510 | |
---|
511 | #define RNOK( exp ) \ |
---|
512 | { \ |
---|
513 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
514 | if( 0 != nMSysRetVal ) \ |
---|
515 | { \ |
---|
516 | assert( 0 ); \ |
---|
517 | return nMSysRetVal; \ |
---|
518 | } \ |
---|
519 | } |
---|
520 | |
---|
521 | #define RNOKR( exp, retVal ) \ |
---|
522 | { \ |
---|
523 | if( 0 != ( exp ) ) \ |
---|
524 | { \ |
---|
525 | assert( 0 ); \ |
---|
526 | return retVal; \ |
---|
527 | } \ |
---|
528 | } |
---|
529 | |
---|
530 | #define RNOKS( exp ) \ |
---|
531 | { \ |
---|
532 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
533 | if( 0 != nMSysRetVal ) \ |
---|
534 | { \ |
---|
535 | return nMSysRetVal; \ |
---|
536 | } \ |
---|
537 | } |
---|
538 | |
---|
539 | #define RNOKRS( exp, retVal ) \ |
---|
540 | { \ |
---|
541 | if( 0 != ( exp ) ) \ |
---|
542 | { \ |
---|
543 | return retVal; \ |
---|
544 | } \ |
---|
545 | } |
---|
546 | |
---|
547 | #define RNOKV( exp ) \ |
---|
548 | { \ |
---|
549 | if( 0 != ( exp ) ) \ |
---|
550 | { \ |
---|
551 | assert( 0 ); \ |
---|
552 | return; \ |
---|
553 | } \ |
---|
554 | } |
---|
555 | |
---|
556 | #define RNOKVS( exp ) \ |
---|
557 | { \ |
---|
558 | if( 0 != ( exp ) ) \ |
---|
559 | { \ |
---|
560 | return; \ |
---|
561 | } \ |
---|
562 | } |
---|
563 | |
---|
564 | #define ANOK( exp ) \ |
---|
565 | { \ |
---|
566 | if( 0 != ( exp ) ) \ |
---|
567 | { \ |
---|
568 | assert( 0 ); \ |
---|
569 | } \ |
---|
570 | } |
---|
571 | |
---|
572 | #define AOF( exp ) \ |
---|
573 | { \ |
---|
574 | if( !( exp ) ) \ |
---|
575 | { \ |
---|
576 | assert( 0 ); \ |
---|
577 | } \ |
---|
578 | } |
---|
579 | |
---|
580 | #define AOT( exp ) \ |
---|
581 | { \ |
---|
582 | if( ( exp ) ) \ |
---|
583 | { \ |
---|
584 | assert( 0 ); \ |
---|
585 | } \ |
---|
586 | } |
---|
587 | |
---|
588 | #if defined( _DEBUG ) |
---|
589 | |
---|
590 | #define AOT_DBG( exp ) AOT( exp ) |
---|
591 | #define AOF_DBG( exp ) AOF( exp ) |
---|
592 | |
---|
593 | #else |
---|
594 | |
---|
595 | #define AOT_DBG( exp ) ((void)0) |
---|
596 | #define AOF_DBG( exp ) ((void)0) |
---|
597 | |
---|
598 | #endif |
---|
599 | |
---|
600 | #define DISABLE_DEFAULT_CPYCTOR_AND_ASOP(x) private: x( const x &r ); const x& operator=( const x &r ) |
---|
601 | typedef Int64 PicOrderCnt; |
---|
602 | |
---|
603 | template<class T> |
---|
604 | class AutoDeletePtrVector |
---|
605 | : public std::vector<T*> |
---|
606 | { |
---|
607 | public: |
---|
608 | AutoDeletePtrVector() {} |
---|
609 | |
---|
610 | virtual ~AutoDeletePtrVector() |
---|
611 | { |
---|
612 | while( !std::vector<T*>::empty() ) |
---|
613 | { |
---|
614 | delete std::vector<T*>::back(); |
---|
615 | std::vector<T*>::pop_back(); |
---|
616 | } |
---|
617 | } |
---|
618 | |
---|
619 | DISABLE_DEFAULT_CPYCTOR_AND_ASOP( AutoDeletePtrVector ); |
---|
620 | }; |
---|
621 | |
---|
622 | template<class T> |
---|
623 | __inline T gAbs(const T& x) |
---|
624 | { |
---|
625 | return x < 0 ? -x : x; |
---|
626 | } |
---|
627 | // |
---|
628 | |
---|
629 | template <typename T> |
---|
630 | __inline T gSign(const T& t) |
---|
631 | { |
---|
632 | if( t == 0 ) |
---|
633 | return T(0); |
---|
634 | else |
---|
635 | return (t < 0) ? T(-1) : T(1); |
---|
636 | } |
---|
637 | |
---|
638 | |
---|
639 | |
---|
640 | #if POZNAN_NONLINEAR_DEPTH |
---|
641 | struct TComNonlinearDepthModel // // OS: cannot be stdarray, due to memcpy done on SlicePilot |
---|
642 | { |
---|
643 | Int m_aiPoints[257]; |
---|
644 | Int m_iNum; |
---|
645 | |
---|
646 | Int m_aiX[257]; |
---|
647 | Int m_aiY[257]; |
---|
648 | |
---|
649 | Void Clear() { m_iNum=0; m_aiPoints[0]=0; m_aiPoints[1]=0; }; |
---|
650 | Void Init() |
---|
651 | { |
---|
652 | for (Int k=m_iNum+1; k>=0; --k) |
---|
653 | { |
---|
654 | int q = 255*k/(m_iNum+1); |
---|
655 | m_aiX[k] = q + m_aiPoints[k]; |
---|
656 | m_aiY[k] = q - m_aiPoints[k]; |
---|
657 | } |
---|
658 | }; |
---|
659 | |
---|
660 | Double xInterpolateD(Int *aiX,Int *aiY, Double x, Double dScale) |
---|
661 | { |
---|
662 | Int x1 = 0; |
---|
663 | Int x2 = m_iNum+1; |
---|
664 | |
---|
665 | for (;;) |
---|
666 | { |
---|
667 | if (x1+1>=x2) |
---|
668 | return ((x-aiX[x1])*(aiY[x2]-aiY[x1])/(aiX[x2]-aiX[x1]) + aiY[x1])*dScale; |
---|
669 | Int xm = (x1+x2)>>1; |
---|
670 | if (x >= aiX[xm]) x1 = xm; |
---|
671 | else x2 = xm; |
---|
672 | } |
---|
673 | } |
---|
674 | |
---|
675 | inline Double ForwardD(Double x, Double dScale) { return xInterpolateD(m_aiX, m_aiY, x, dScale); } |
---|
676 | inline Double BackwardD(Double x, Double dScale) { return xInterpolateD(m_aiY, m_aiX, x, dScale); } |
---|
677 | |
---|
678 | Int64 xInterpolateI(Int *aiX,Int *aiY, Int x, Int64 iScale) |
---|
679 | { |
---|
680 | Int x1 = 0; |
---|
681 | Int x2 = m_iNum+1; |
---|
682 | |
---|
683 | for (;;) |
---|
684 | { |
---|
685 | if (x1+1>=x2) |
---|
686 | { |
---|
687 | Int aiXx2x1 = (aiX[x2]-aiX[x1]); |
---|
688 | Int64 res = (x-aiX[x1])*(aiY[x2]-aiY[x1])*iScale; |
---|
689 | if (res>0) return (res + (aiXx2x1>>1) )/aiXx2x1 + aiY[x1]*iScale; |
---|
690 | else return (res - (aiXx2x1>>1) )/aiXx2x1 + aiY[x1]*iScale; |
---|
691 | } |
---|
692 | Int xm = (x1+x2)>>1; |
---|
693 | if (x >= aiX[xm]) x1 = xm; |
---|
694 | else x2 = xm; |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | inline Int64 ForwardI (Int x, Int64 iScale) { return xInterpolateI(m_aiX, m_aiY, x, iScale); } |
---|
699 | inline Int64 BackwardI(Int x, Int64 iScale) { return xInterpolateI(m_aiY, m_aiX, x, iScale); } |
---|
700 | |
---|
701 | }; |
---|
702 | #endif |
---|
703 | |
---|
704 | #endif // end of #ifndef __COMMONDEF__ |
---|
705 | |
---|