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 | #if ( HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED || POZNAN_MP_USE_DEPTH_MAP_GENERATION) |
---|
140 | #define DEPTH_MAP_GENERATION 1 |
---|
141 | #else |
---|
142 | #define DEPTH_MAP_GENERATION 0 |
---|
143 | #endif |
---|
144 | |
---|
145 | //>>>>> generation and usage of virtual prediction depth maps >>>>> |
---|
146 | #define PDM_DEPTH_MAP_MCP_FILTER 2 // 0: standard filter, 1:bilinear, 2:nearest neighbour |
---|
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 0 // 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 | //<<<<< generation and usage of virtual prediction depth maps <<<<< |
---|
169 | |
---|
170 | #define OUTPUT_RESIDUAL_PICTURES 0 // output residual pictures (for debugging) |
---|
171 | |
---|
172 | #define HHI_MPI_MERGE_POS 0 // position of mvi in merge list (0..5) |
---|
173 | |
---|
174 | // ==================================================================================================================== |
---|
175 | // POZNAN DEFINE SECTION |
---|
176 | // ==================================================================================================================== |
---|
177 | #define POZNAN_OUTPUT_AVAILABLE_MAP 0 // output available map (for debugging) |
---|
178 | #define POZNAN_OUTPUT_SYNTH 0 // output synthesised view (for debugging) |
---|
179 | |
---|
180 | #if POZNAN_NONLINEAR_DEPTH |
---|
181 | #define POZNAN_LUT_INCREASED_PRECISION 0 // 1 |
---|
182 | #else |
---|
183 | #define POZNAN_LUT_INCREASED_PRECISION 0 |
---|
184 | #endif |
---|
185 | |
---|
186 | #if POZNAN_NONLINEAR_DEPTH |
---|
187 | inline UChar quantizeDepthPower(Float fDepthPower) |
---|
188 | { |
---|
189 | Int r = (Int) ( (fDepthPower-1.0f)*128.0f + 0.5f); |
---|
190 | if (r<=0) return 0; |
---|
191 | if (r>255) r=255; |
---|
192 | return r; |
---|
193 | }; |
---|
194 | |
---|
195 | inline Float dequantizeDepthPower(Int iDepthQuant) |
---|
196 | { |
---|
197 | return iDepthQuant/128.0f + 1.0f; |
---|
198 | }; |
---|
199 | #endif |
---|
200 | |
---|
201 | #if POZNAN_EIVD |
---|
202 | #define POZNAN_EIVD_MERGE_POS 0 // position of EIVD candidate in merge list for coding (0..6) - overwrites PDM_MERGE_POS settings, is overwritten by HHI_MPI_MERGE_POS settings!!! |
---|
203 | #endif |
---|
204 | |
---|
205 | // ==================================================================================================================== |
---|
206 | // Macro functions |
---|
207 | // ==================================================================================================================== |
---|
208 | |
---|
209 | #define Max(x, y) ((x)>(y)?(x):(y)) ///< max of (x, y) |
---|
210 | #define Min(x, y) ((x)<(y)?(x):(y)) ///< min of (x, y) |
---|
211 | #define Median(a,b,c) ((a)>(b)?(a)>(c)?(b)>(c)?(b):(c):(a):(b)>(c)?(a)>(c)?(a):(c):(b)) ///< 3-point median |
---|
212 | #define Clip(x) ( Min(g_uiIBDI_MAX, Max( 0, (x)) ) ) ///< clip with bit-depth range |
---|
213 | #define Clip3( MinVal, MaxVal, a) ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) ) ///< general min/max clip |
---|
214 | #define RemoveBitIncrement(x) ( ((x) + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement ) ///< Remove Bit increment |
---|
215 | |
---|
216 | #if POZNAN_LUT_INCREASED_PRECISION |
---|
217 | #define RemoveBitIncrementLUT(x) (x) ///< Remove Bit increment |
---|
218 | #define SizeOfLUT (256 << g_uiBitIncrement) |
---|
219 | #else |
---|
220 | #define SizeOfLUT 256 |
---|
221 | #define RemoveBitIncrementLUT(x) ( ((x) + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement ) ///< Remove Bit increment |
---|
222 | #endif |
---|
223 | |
---|
224 | #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free |
---|
225 | #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) |
---|
226 | #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 ) |
---|
227 | #define xFree( ptr ) _aligned_free ( ptr ) |
---|
228 | #else |
---|
229 | #define xMalloc( type, len ) malloc ( sizeof(type)*(len) ) |
---|
230 | #define xFree( ptr ) free ( ptr ) |
---|
231 | #endif |
---|
232 | |
---|
233 | #define FATAL_ERROR_0(MESSAGE, EXITCODE) \ |
---|
234 | { \ |
---|
235 | printf(MESSAGE); \ |
---|
236 | exit(EXITCODE); \ |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | // ==================================================================================================================== |
---|
241 | // Coding tool configuration |
---|
242 | // ==================================================================================================================== |
---|
243 | |
---|
244 | // modified LCEC coefficient coding |
---|
245 | #if QC_MOD_LCEC |
---|
246 | #define MAX_TR1 4 |
---|
247 | #endif |
---|
248 | |
---|
249 | // AMVP: advanced motion vector prediction |
---|
250 | #define AMVP_MAX_NUM_CANDS 6 ///< max number of final candidates |
---|
251 | // MERGE |
---|
252 | #if POZNAN_EIVD |
---|
253 | #define MRG_MAX_NUM_CANDS 7 |
---|
254 | #define POZNAN_EIVD_MRG_CAND MRG_MAX_NUM_CANDS-1 // position of EIVD candidate in merge list (0..6) |
---|
255 | #else |
---|
256 | #define MRG_MAX_NUM_CANDS 6 |
---|
257 | #endif |
---|
258 | |
---|
259 | // Reference memory management |
---|
260 | #define DYN_REF_FREE 0 ///< dynamic free of reference memories |
---|
261 | |
---|
262 | // defines for multiview coding |
---|
263 | #define MAX_NUMBER_VIEWS 10 |
---|
264 | |
---|
265 | // Explicit temporal layer QP offset |
---|
266 | #define MAX_TLAYER 10 ///< max number of temporal layer |
---|
267 | #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode |
---|
268 | |
---|
269 | // Fast estimation of generalized B in low-delay mode |
---|
270 | #define GPB_SIMPLE 1 ///< Simple GPB mode |
---|
271 | #if GPB_SIMPLE |
---|
272 | #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction |
---|
273 | #endif |
---|
274 | |
---|
275 | // Fast ME using smoother MV assumption |
---|
276 | #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option |
---|
277 | |
---|
278 | // Adaptive search range depending on POC difference |
---|
279 | #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range |
---|
280 | |
---|
281 | #define ENABLE_IBDI 0 |
---|
282 | |
---|
283 | #define CLIP_TO_709_RANGE 0 |
---|
284 | |
---|
285 | // IBDI range restriction for skipping clip |
---|
286 | #define IBDI_NOCLIP_RANGE 0 ///< restrict max. value after IBDI to skip clip |
---|
287 | |
---|
288 | // Early-skip threshold (encoder) |
---|
289 | #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] |
---|
290 | |
---|
291 | const int g_iShift8x8 = 2; |
---|
292 | const int g_iShift16x16 = 2; |
---|
293 | const int g_iShift32x32 = 2; |
---|
294 | const int g_iShift64x64 = 2; |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | //RENDERER |
---|
299 | #define REN_LUMA_MARGIN ( g_uiMaxCUWidth + 12 ) |
---|
300 | #define REN_VDWEIGHT_PREC 8 |
---|
301 | #define REN_IS_FILLED ( 1 << REN_VDWEIGHT_PREC ) |
---|
302 | #define REN_USED_PEL g_uiIBDI_MAX |
---|
303 | #define REN_UNUSED_PEL 0 |
---|
304 | #define REN_IS_HOLE 0 |
---|
305 | |
---|
306 | /* End of Rounding control */ |
---|
307 | |
---|
308 | enum NalRefIdc |
---|
309 | { |
---|
310 | NAL_REF_IDC_PRIORITY_LOWEST = 0, |
---|
311 | NAL_REF_IDC_PRIORITY_LOW, |
---|
312 | NAL_REF_IDC_PRIORITY_HIGH, |
---|
313 | NAL_REF_IDC_PRIORITY_HIGHEST |
---|
314 | }; |
---|
315 | |
---|
316 | enum NalUnitType |
---|
317 | { |
---|
318 | NAL_UNIT_UNSPECIFIED_0 = 0, |
---|
319 | NAL_UNIT_CODED_SLICE, |
---|
320 | NAL_UNIT_CODED_SLICE_DATAPART_A, |
---|
321 | NAL_UNIT_CODED_SLICE_DATAPART_B, |
---|
322 | #if DCM_DECODING_REFRESH |
---|
323 | NAL_UNIT_CODED_SLICE_CDR, |
---|
324 | #else |
---|
325 | NAL_UNIT_CODED_SLICE_DATAPART_C, |
---|
326 | #endif |
---|
327 | NAL_UNIT_CODED_SLICE_IDR, |
---|
328 | NAL_UNIT_SEI, |
---|
329 | NAL_UNIT_SPS, |
---|
330 | NAL_UNIT_PPS, |
---|
331 | NAL_UNIT_ACCESS_UNIT_DELIMITER, |
---|
332 | NAL_UNIT_END_OF_SEQUENCE, |
---|
333 | NAL_UNIT_END_OF_STREAM, |
---|
334 | NAL_UNIT_FILLER_DATA, |
---|
335 | NAL_UNIT_RESERVED_13, |
---|
336 | NAL_UNIT_RESERVED_14, |
---|
337 | NAL_UNIT_RESERVED_15, |
---|
338 | NAL_UNIT_RESERVED_16, |
---|
339 | NAL_UNIT_RESERVED_17, |
---|
340 | NAL_UNIT_RESERVED_18, |
---|
341 | NAL_UNIT_RESERVED_19, |
---|
342 | NAL_UNIT_RESERVED_20, |
---|
343 | NAL_UNIT_RESERVED_21, |
---|
344 | NAL_UNIT_RESERVED_22, |
---|
345 | NAL_UNIT_RESERVED_23, |
---|
346 | NAL_UNIT_UNSPECIFIED_24, |
---|
347 | NAL_UNIT_UNSPECIFIED_25, |
---|
348 | NAL_UNIT_UNSPECIFIED_26, |
---|
349 | NAL_UNIT_UNSPECIFIED_27, |
---|
350 | NAL_UNIT_UNSPECIFIED_28, |
---|
351 | NAL_UNIT_UNSPECIFIED_29, |
---|
352 | NAL_UNIT_UNSPECIFIED_30, |
---|
353 | NAL_UNIT_UNSPECIFIED_31, |
---|
354 | NAL_UNIT_INVALID, |
---|
355 | }; |
---|
356 | |
---|
357 | typedef _AlfParam ALFParam; |
---|
358 | #if MTK_SAO |
---|
359 | typedef _SaoParam SAOParam; |
---|
360 | #endif |
---|
361 | |
---|
362 | |
---|
363 | class VideoCodecException |
---|
364 | { |
---|
365 | public: |
---|
366 | VideoCodecException() : m_acFile( "unspecified" ), m_uiLine( 0 ) {} |
---|
367 | VideoCodecException( const char *pcFile, UInt uiLine ) : m_acFile( pcFile ), m_uiLine( uiLine ) {} |
---|
368 | |
---|
369 | std::string exceptionFile() const { return m_acFile; } |
---|
370 | UInt exceptionLine() const { return m_uiLine; } |
---|
371 | |
---|
372 | private: |
---|
373 | std::string m_acFile; |
---|
374 | UInt m_uiLine; |
---|
375 | }; |
---|
376 | |
---|
377 | #define RETURN_ERR_ON_EXCEPTION \ |
---|
378 | catch( std::exception &cEx ) \ |
---|
379 | { \ |
---|
380 | std::cerr << "Abnormal program termination: " << cEx.what() << std::endl; \ |
---|
381 | return Err::m_nERR; \ |
---|
382 | } \ |
---|
383 | catch( VideoCodecException &cEx ) \ |
---|
384 | { \ |
---|
385 | std::cerr << std::endl << "VideoCodecExcteption caught at: " << std::endl; \ |
---|
386 | std::cerr << "File: " << cEx.exceptionFile() << std::endl; \ |
---|
387 | std::cerr << "Line: " << cEx.exceptionLine() << std::endl; \ |
---|
388 | return Err::m_nERR; \ |
---|
389 | } \ |
---|
390 | catch( ... ) \ |
---|
391 | { \ |
---|
392 | std::cerr << "Caught unknown exception" << std::endl; \ |
---|
393 | return Err::m_nERR; \ |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | #define TOT( exp ) { if( exp ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
398 | #define TOF( exp ) { if( !(exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
399 | #define TNOK( exp ) { if( Err::m_nOK != (exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
400 | |
---|
401 | #if defined( _DEBUG ) |
---|
402 | |
---|
403 | #define TOT_DBG( exp ) TOT( exp ) |
---|
404 | #define TOF_DBG( exp ) TOF( exp ) |
---|
405 | |
---|
406 | #else |
---|
407 | |
---|
408 | #define TOT_DBG( exp ) ((void)0) |
---|
409 | #define TOF_DBG( exp ) ((void)0) |
---|
410 | |
---|
411 | #endif |
---|
412 | |
---|
413 | typedef int ErrVal; |
---|
414 | |
---|
415 | |
---|
416 | class Err |
---|
417 | { |
---|
418 | public: |
---|
419 | enum |
---|
420 | { |
---|
421 | m_nOK = 0, |
---|
422 | m_nERR = -1, |
---|
423 | m_nEndOfFile = -2, |
---|
424 | m_nEndOfBuffer = -3, |
---|
425 | m_nInvalidParameter = -4, |
---|
426 | m_nDataNotAvailable = -5, |
---|
427 | m_nSizeNotAvailable = -5, |
---|
428 | }; |
---|
429 | }; |
---|
430 | |
---|
431 | |
---|
432 | #define ROF( exp ) \ |
---|
433 | { \ |
---|
434 | if( !( exp ) ) \ |
---|
435 | { \ |
---|
436 | assert( 0 ); \ |
---|
437 | return -1; \ |
---|
438 | } \ |
---|
439 | } |
---|
440 | |
---|
441 | #define ROT( exp ) \ |
---|
442 | { \ |
---|
443 | if( ( exp ) ) \ |
---|
444 | { \ |
---|
445 | assert( 0 ); \ |
---|
446 | return -1; \ |
---|
447 | } \ |
---|
448 | } |
---|
449 | |
---|
450 | #define ROFS( exp ) \ |
---|
451 | { \ |
---|
452 | if( !( exp ) ) \ |
---|
453 | { \ |
---|
454 | return -1; \ |
---|
455 | } \ |
---|
456 | } |
---|
457 | |
---|
458 | #define ROTS( exp ) \ |
---|
459 | { \ |
---|
460 | if( ( exp ) ) \ |
---|
461 | { \ |
---|
462 | return -1; \ |
---|
463 | } \ |
---|
464 | } |
---|
465 | |
---|
466 | #define ROFR( exp, retVal ) \ |
---|
467 | { \ |
---|
468 | if( !( exp ) ) \ |
---|
469 | { \ |
---|
470 | assert( 0 ); \ |
---|
471 | return retVal; \ |
---|
472 | } \ |
---|
473 | } |
---|
474 | |
---|
475 | #define ROTR( exp, retVal ) \ |
---|
476 | { \ |
---|
477 | if( ( exp ) ) \ |
---|
478 | { \ |
---|
479 | assert( 0 ); \ |
---|
480 | return retVal; \ |
---|
481 | } \ |
---|
482 | } |
---|
483 | |
---|
484 | #define ROFRS( exp, retVal ) \ |
---|
485 | { \ |
---|
486 | if( !( exp ) ) \ |
---|
487 | { \ |
---|
488 | return retVal; \ |
---|
489 | } \ |
---|
490 | } |
---|
491 | |
---|
492 | #define ROTRS( exp, retVal ) \ |
---|
493 | { \ |
---|
494 | if( ( exp ) ) \ |
---|
495 | { \ |
---|
496 | return retVal; \ |
---|
497 | } \ |
---|
498 | } |
---|
499 | |
---|
500 | #define ROFV( exp ) \ |
---|
501 | { \ |
---|
502 | if( !( exp ) ) \ |
---|
503 | { \ |
---|
504 | assert( 0 ); \ |
---|
505 | return; \ |
---|
506 | } \ |
---|
507 | } |
---|
508 | |
---|
509 | #define ROTV( exp ) \ |
---|
510 | { \ |
---|
511 | if( ( exp ) ) \ |
---|
512 | { \ |
---|
513 | assert( 0 ); \ |
---|
514 | return; \ |
---|
515 | } \ |
---|
516 | } |
---|
517 | |
---|
518 | #define ROFVS( exp ) \ |
---|
519 | { \ |
---|
520 | if( !( exp ) ) \ |
---|
521 | { \ |
---|
522 | return; \ |
---|
523 | } \ |
---|
524 | } |
---|
525 | |
---|
526 | #define ROTVS( exp ) \ |
---|
527 | { \ |
---|
528 | if( ( exp ) ) \ |
---|
529 | { \ |
---|
530 | return; \ |
---|
531 | } \ |
---|
532 | } |
---|
533 | |
---|
534 | #define RNOK( exp ) \ |
---|
535 | { \ |
---|
536 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
537 | if( 0 != nMSysRetVal ) \ |
---|
538 | { \ |
---|
539 | assert( 0 ); \ |
---|
540 | return nMSysRetVal; \ |
---|
541 | } \ |
---|
542 | } |
---|
543 | |
---|
544 | #define RNOKR( exp, retVal ) \ |
---|
545 | { \ |
---|
546 | if( 0 != ( exp ) ) \ |
---|
547 | { \ |
---|
548 | assert( 0 ); \ |
---|
549 | return retVal; \ |
---|
550 | } \ |
---|
551 | } |
---|
552 | |
---|
553 | #define RNOKS( exp ) \ |
---|
554 | { \ |
---|
555 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
556 | if( 0 != nMSysRetVal ) \ |
---|
557 | { \ |
---|
558 | return nMSysRetVal; \ |
---|
559 | } \ |
---|
560 | } |
---|
561 | |
---|
562 | #define RNOKRS( exp, retVal ) \ |
---|
563 | { \ |
---|
564 | if( 0 != ( exp ) ) \ |
---|
565 | { \ |
---|
566 | return retVal; \ |
---|
567 | } \ |
---|
568 | } |
---|
569 | |
---|
570 | #define RNOKV( exp ) \ |
---|
571 | { \ |
---|
572 | if( 0 != ( exp ) ) \ |
---|
573 | { \ |
---|
574 | assert( 0 ); \ |
---|
575 | return; \ |
---|
576 | } \ |
---|
577 | } |
---|
578 | |
---|
579 | #define RNOKVS( exp ) \ |
---|
580 | { \ |
---|
581 | if( 0 != ( exp ) ) \ |
---|
582 | { \ |
---|
583 | return; \ |
---|
584 | } \ |
---|
585 | } |
---|
586 | |
---|
587 | #define ANOK( exp ) \ |
---|
588 | { \ |
---|
589 | if( 0 != ( exp ) ) \ |
---|
590 | { \ |
---|
591 | assert( 0 ); \ |
---|
592 | } \ |
---|
593 | } |
---|
594 | |
---|
595 | #define AOF( exp ) \ |
---|
596 | { \ |
---|
597 | if( !( exp ) ) \ |
---|
598 | { \ |
---|
599 | assert( 0 ); \ |
---|
600 | } \ |
---|
601 | } |
---|
602 | |
---|
603 | #define AOT( exp ) \ |
---|
604 | { \ |
---|
605 | if( ( exp ) ) \ |
---|
606 | { \ |
---|
607 | assert( 0 ); \ |
---|
608 | } \ |
---|
609 | } |
---|
610 | |
---|
611 | #if defined( _DEBUG ) |
---|
612 | |
---|
613 | #define AOT_DBG( exp ) AOT( exp ) |
---|
614 | #define AOF_DBG( exp ) AOF( exp ) |
---|
615 | |
---|
616 | #else |
---|
617 | |
---|
618 | #define AOT_DBG( exp ) ((void)0) |
---|
619 | #define AOF_DBG( exp ) ((void)0) |
---|
620 | |
---|
621 | #endif |
---|
622 | |
---|
623 | #define DISABLE_DEFAULT_CPYCTOR_AND_ASOP(x) private: x( const x &r ); const x& operator=( const x &r ) |
---|
624 | typedef Int64 PicOrderCnt; |
---|
625 | |
---|
626 | template<class T> |
---|
627 | class AutoDeletePtrVector |
---|
628 | : public std::vector<T*> |
---|
629 | { |
---|
630 | public: |
---|
631 | AutoDeletePtrVector() {} |
---|
632 | |
---|
633 | virtual ~AutoDeletePtrVector() |
---|
634 | { |
---|
635 | while( !std::vector<T*>::empty() ) |
---|
636 | { |
---|
637 | delete std::vector<T*>::back(); |
---|
638 | std::vector<T*>::pop_back(); |
---|
639 | } |
---|
640 | } |
---|
641 | |
---|
642 | DISABLE_DEFAULT_CPYCTOR_AND_ASOP( AutoDeletePtrVector ); |
---|
643 | }; |
---|
644 | |
---|
645 | template<class T> |
---|
646 | __inline T gAbs(const T& x) |
---|
647 | { |
---|
648 | return x < 0 ? -x : x; |
---|
649 | } |
---|
650 | // |
---|
651 | |
---|
652 | template <typename T> |
---|
653 | __inline T gSign(const T& t) |
---|
654 | { |
---|
655 | if( t == 0 ) |
---|
656 | return T(0); |
---|
657 | else |
---|
658 | return (t < 0) ? T(-1) : T(1); |
---|
659 | } |
---|
660 | |
---|
661 | |
---|
662 | |
---|
663 | #endif // end of #ifndef __COMMONDEF__ |
---|
664 | |
---|