Home | History | Annotate | Download | only in base
      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 (at) intel.com>
     19  */
     20 
     21 #ifndef XCAM_DEFS_H
     22 #define XCAM_DEFS_H
     23 
     24 #ifndef XCAM_LOG_ERROR
     25 #define XCAM_LOG_ERROR(format, ...)    \
     26     xcam_print_log ("XCAM ERROR %s:%d: " format "\n", __FILE__, __LINE__, ## __VA_ARGS__)
     27 #endif
     28 
     29 #ifndef XCAM_LOG_WARNING
     30 #define XCAM_LOG_WARNING(format, ...)   \
     31     xcam_print_log ("XCAM WARNING %s:%d: " format "\n", __FILE__, __LINE__, ## __VA_ARGS__)
     32 #endif
     33 
     34 #ifndef XCAM_LOG_INFO
     35 #define XCAM_LOG_INFO(format, ...)   \
     36     xcam_print_log ("XCAM INFO %s:%d: " format "\n", __FILE__, __LINE__, ## __VA_ARGS__)
     37 #endif
     38 
     39 #ifdef DEBUG
     40 #ifndef XCAM_LOG_DEBUG
     41 #define XCAM_LOG_DEBUG(format, ...)   \
     42       xcam_print_log ("XCAM DEBUG %s:%d: " format "\n", __FILE__, __LINE__, ## __VA_ARGS__)
     43 #endif
     44 #else
     45 #define XCAM_LOG_DEBUG(...)
     46 #endif
     47 
     48 #define XCAM_ASSERT(exp)  assert(exp)
     49 
     50 #ifdef  __cplusplus
     51 #define XCAM_BEGIN_DECLARE  extern "C" {
     52 #define XCAM_END_DECLARE    }
     53 #else
     54 #define XCAM_BEGIN_DECLARE
     55 #define XCAM_END_DECLARE
     56 #endif
     57 
     58 #ifndef __user
     59 #define __user
     60 #endif
     61 
     62 #define XCAM_UNUSED(variable) (void)(variable)
     63 
     64 #define XCAM_CONSTRUCTOR(obj, TYPE, ...) new (&obj) TYPE(## __VA_ARGS__)
     65 #define XCAM_DESTRUCTOR(obj, TYPE) (obj).~TYPE()
     66 
     67 #define XCAM_MAX(a, b)  ((a) > (b) ? (a) : (b))
     68 #define XCAM_MIN(a, b)  ((a) < (b) ? (a) : (b))
     69 #define XCAM_CLAMP(v, min, max)   \
     70     (((v) < (min)) ? (min) : (((v) > (max)) ? (max) : (v)))
     71 
     72 #define XCAM_FAIL_RETURN(LEVEL, exp, ret, msg, ...)         \
     73     if (!(exp)) {                                           \
     74         XCAM_LOG_##LEVEL (msg, ## __VA_ARGS__);             \
     75         return (ret);                                       \
     76     }
     77 
     78 #define XCAM_DEAD_COPY(ClassObj)                \
     79         ClassObj (const ClassObj&);             \
     80         ClassObj & operator= (const ClassObj&)  \
     81 
     82 
     83 #define XCAM_STR(str)  ((str) ? (str) : "null")
     84 #define XCAM_BOOL2STR(value)  ((value) ? "true" : "false")
     85 
     86 #define XCAM_DOUBLE_EQUAL(a, b, tolerance)  \
     87     (((a) >= ((b) - (tolerance))) && ((a) <= ((b) + (tolerance))))
     88 
     89 #define XCAM_DOUBLE_EQUAL_AROUND(a, b)  \
     90     XCAM_DOUBLE_EQUAL((a), (b), 0.000001)
     91 
     92 #define XCAM_GAMMA_TABLE_SIZE 256
     93 #define XCAM_MAX_STR_SIZE 4096
     94 #undef XCAM_CL_MAX_STR_SIZE
     95 #define XCAM_CL_MAX_STR_SIZE 1024
     96 
     97 #define XCAM_TIMESPEC_2_USEC(timespec) ((timespec).tv_sec*1000000LL + (timespec).tv_nsec/1000)
     98 #define XCAM_TIMEVAL_2_USEC(timeval) ((timeval).tv_sec*1000000LL + (timeval).tv_usec)
     99 
    100 #define XCAM_TIMESTAMP_2_SECONDS(t) ((t)/1000000)
    101 #define XCAM_SECONDS_2_TIMESTAMP(t) ((t)*1000000)
    102 
    103 #define XCAM_TIMESTAMP_FORMAT "%02d:%02d:%02d.%03d"
    104 
    105 #define XCAM_TIMESTAMP_ARGS(t)                \
    106     (int32_t)(XCAM_TIMESTAMP_2_SECONDS(t)/3600),       \
    107     (int32_t)((XCAM_TIMESTAMP_2_SECONDS(t)%3600)/60),  \
    108     (int32_t)(XCAM_TIMESTAMP_2_SECONDS(t)%60),         \
    109     (int32_t)(((t)/1000)%1000)
    110 
    111 // align must be a interger of power 2
    112 #define XCAM_ALIGN_UP(value, align) (((value)+((align)-1))&(~((align)-1)))
    113 #define XCAM_ALIGN_DOWN(value, align) ((value)&(~((align)-1)))
    114 #define XCAM_ALIGN_AROUND(value, align) (((value)+(align)/2)/(align)*(align))
    115 
    116 #ifdef _LP64
    117 #define PRIuS "zu"
    118 #else
    119 #define PRIuS "u"
    120 #endif
    121 
    122 #define PI 3.1415926f
    123 #define degree2radian(degree) ((degree) * PI / 180.0f)
    124 
    125 #endif //XCAM_DEFS_H
    126