1 /* 2 * xcam_defs.h - macros defines 3 * 4 * Copyright (c) 2014-2015 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan@intel.com> 19 */ 20 21 #ifndef XCAM_DEFS_H 22 #define XCAM_DEFS_H 23 24 #include <assert.h> 25 26 #if defined(__linux__) 27 #include "unistd.h" 28 #endif 29 //#include "xcam_log.h" 30 31 #define XCAM_ASSERT(exp) assert(exp) 32 33 #ifdef __cplusplus 34 #define XCAM_BEGIN_DECLARE extern "C" { 35 #define XCAM_END_DECLARE } 36 #else 37 #define XCAM_BEGIN_DECLARE 38 #define XCAM_END_DECLARE 39 #endif 40 41 #ifndef __user 42 #define __user 43 #endif 44 45 #define XCAM_UNUSED(variable) (void)(variable) 46 47 #define XCAM_CONSTRUCTOR(obj, TYPE, ...) new (&obj) TYPE(## __VA_ARGS__) 48 #define XCAM_DESTRUCTOR(obj, TYPE) (obj).~TYPE() 49 50 #define XCAM_MAX(a, b) ((a) > (b) ? (a) : (b)) 51 #define XCAM_MIN(a, b) ((a) < (b) ? (a) : (b)) 52 #define XCAM_CLAMP(v, min, max) \ 53 (((v) < (min)) ? (min) : (((v) > (max)) ? (max) : (v))) 54 55 #define XCAM_FAIL_RETURN(LEVEL, exp, ret, msg, ...) \ 56 if (!(exp)) { \ 57 XCAM_LOG_##LEVEL (msg, ## __VA_ARGS__); \ 58 return (ret); \ 59 } 60 61 #define XCAM_DEAD_COPY(ClassObj) \ 62 ClassObj (const ClassObj&); \ 63 ClassObj & operator= (const ClassObj&) \ 64 65 66 #define XCAM_STR(str) ((str) ? (str) : "null") 67 #define XCAM_BOOL2STR(value) ((value) ? "true" : "false") 68 69 #define XCAM_DOUBLE_EQUAL(a, b, tolerance) \ 70 (((a) >= ((b) - (tolerance))) && ((a) <= ((b) + (tolerance)))) 71 72 #define XCAM_DOUBLE_EQUAL_AROUND(a, b) \ 73 XCAM_DOUBLE_EQUAL((a), (b), 0.000001) 74 75 #define XCAM_GAMMA_TABLE_SIZE 256 76 #define XCAM_MAX_STR_SIZE 4096 77 #undef XCAM_CL_MAX_STR_SIZE 78 #define XCAM_CL_MAX_STR_SIZE 1024 79 80 #define XCAM_TIMESPEC_2_USEC(timespec) ((timespec).tv_sec*1000000LL + (timespec).tv_nsec/1000) 81 #define XCAM_TIMEVAL_2_USEC(timeval) ((timeval).tv_sec*1000000LL + (timeval).tv_usec) 82 83 #define XCAM_TIMESTAMP_2_SECONDS(t) ((t)/1000000) 84 #define XCAM_SECONDS_2_TIMESTAMP(t) ((t)*1000000) 85 86 #define XCAM_TIMESTAMP_FORMAT "%02d:%02d:%02d.%03d" 87 88 #define XCAM_TIMESTAMP_ARGS(t) \ 89 (int32_t)(XCAM_TIMESTAMP_2_SECONDS(t)/3600), \ 90 (int32_t)((XCAM_TIMESTAMP_2_SECONDS(t)%3600)/60), \ 91 (int32_t)(XCAM_TIMESTAMP_2_SECONDS(t)%60), \ 92 (int32_t)(((t)/1000)%1000) 93 94 // align must be a interger of power 2 95 #define XCAM_ALIGN_UP(value, align) (((value)+((align)-1))&(~((align)-1))) 96 #define XCAM_ALIGN_DOWN(value, align) ((value)&(~((align)-1))) 97 #define XCAM_ALIGN_AROUND(value, align) (((value)+(align)/2)/(align)*(align)) 98 99 #ifdef _LP64 100 #define PRIuS "zu" 101 #else 102 #define PRIuS "u" 103 #endif 104 105 #define PI 3.1415926f 106 #define degree2radian(degree) ((degree) * PI / 180.0f) 107 108 #endif //XCAM_DEFS_H 109