VLFeat.org

API docs

  • Home
    • Download and Install
    • API docs
    • Matlab docs
    • About VLFeat
  • Tutorials
    • SIFT
    • MSER
    • IKM
    • HIKM
    • AIB
    • Utils
  • Main Page
  • Related Pages
  • Data Structures
  • Files
  • Examples

generic.h

Go to the documentation of this file.
00001 
00006 /* AUTORIGHTS
00007 Copyright 2007 (c) Andrea Vedaldi and Brian Fulkerson
00008 
00009 This file is part of VLFeat, available in the terms of the GNU
00010 General Public License version 2.
00011 */
00012 
00013 #ifndef VL_GENERIC_H
00014 #define VL_GENERIC_H
00015 
00016 #include <stddef.h>
00017 #include <time.h>
00018 #include <assert.h>
00019 
00020 #include "host.h"
00021 
00023 #define VL_VERSION_STRING "0.9.3"
00024 
00028 #define VL_STRINGIFY_(x) # x
00029 
00040 #define VL_STRINGIFY(x) VL_STRINGIFY_(x)
00041 
00051 #define VL_YESNO(x) ((x)?"yes":"no")
00052 
00054 #define VL_LOG_OF_2 0.693147180559945
00055 
00057 #define VL_PI 3.141592653589793
00058 
00065 #define VL_EPSILON_F 1.19209290E-07F
00066 
00072 #define VL_EPSILON_D 2.220446049250313e-16
00073 
00074 /* 
00075    For the code below: An ANSI C compiler takes the two expressions,
00076    LONG_VAR and CHAR_VAR, and implicitly casts them to the type of the
00077    first member of the union. Refer to K&R Second Edition Page 148,
00078    last paragraph.
00079 */
00080 
00082 static union { vl_uint32 raw ; float value ; } 
00083   const vl_nan_f = 
00084     { 0x7FC00000UL } ;
00085 
00087 static union { vl_uint32 raw ; float value ; } 
00088   const vl_infinity_f = 
00089     { 0x7F800000UL } ;
00090 
00092 static union { vl_uint64 raw ; double value ; } 
00093   const vl_nan_d = 
00094 #ifdef VL_COMPILER_MSC
00095     { 0x7FF8000000000000ui64 } ;
00096 #else
00097     { 0x7FF8000000000000ULL } ;
00098 #endif
00099 
00101 static union { vl_uint64 raw ; float value ; } 
00102   const vl_infinity_d = 
00103 #ifdef VL_COMPILER_MSC
00104     { 0x7FF0000000000000ui64 } ;
00105 #else
00106     { 0x7FF0000000000000ULL } ;
00107 #endif
00108 
00110 #define VL_NAN_F (vl_nan_f.value)
00111 
00113 #define VL_INFINITY_F (vl_infinity_f.value)
00114 
00116 #define VL_NAN_D (vl_nan_d.value)
00117 
00119 #define VL_INFINITY_D (vl_infinity_d.value)
00120 
00121 
00126 VL_EXPORT
00127 void vl_set_alloc_func (void *(*malloc_func)  (size_t),
00128                         void *(*realloc_func) (void*,size_t),
00129                         void *(*calloc_func)  (size_t, size_t),
00130                         void  (*free_func)    (void*)) ;
00131 VL_INLINE void *vl_malloc  (size_t n) ;
00132 VL_INLINE void *vl_realloc (void *ptr, size_t n) ;
00133 VL_INLINE void *vl_calloc  (size_t n, size_t size) ;
00134 VL_INLINE void  vl_free    (void* ptr) ;
00135 
00142 VL_EXPORT
00143 void vl_set_printf_func (int(*printf_func)(char const *str, ...)) ;
00144 
00155 #define VL_PRINTF (*vl_printf_func)
00156 
00167 #define VL_PRINT(string) \
00168   ((*vl_printf_func)(string))
00169 
00177 extern VL_EXPORT int vl_err_no ;
00178 
00180 #define VL_ERR_MSG_LEN 1024
00181 
00183 extern VL_EXPORT char vl_err_msg [VL_ERR_MSG_LEN + 1] ;
00184 
00185 #define VL_ERR_OK       0  
00186 #define VL_ERR_OVERFLOW 1  
00187 #define VL_ERR_ALLOC    2  
00188 #define VL_ERR_BAD_ARG  3  
00189 #define VL_ERR_IO       4  
00190 #define VL_ERR_EOF      5  
00191 #define VL_ERR_NO_MORE  5  
00204 #define VL_MIN(x,y) (((x)<(y))?(x):(y))
00205 
00211 #define VL_MAX(x,y) (((x)>(y))?(x):(y))
00212 
00222 #define VL_SHIFT_LEFT(x,n) (((n)>=0)?((x)<<(n)):((x)>>-(n)))
00223 /* @} */
00224 
00226 VL_EXPORT
00227 char const * vl_get_version_string () ;
00228 
00229 VL_EXPORT
00230 void vl_print_info () ;
00231 
00236 VL_EXPORT void vl_tic() ;
00237 VL_EXPORT double vl_toc() ;
00244 VL_INLINE void vl_swap_host_big_endianness_8 (void *dst, void* src) ;
00245 VL_INLINE void vl_swap_host_big_endianness_4 (void *dst, void* src) ;
00246 VL_INLINE void vl_swap_host_big_endianness_2 (void *dst, void* src) ;
00257 VL_INLINE void
00258 vl_swap_host_big_endianness_8 (void *dst, void* src)
00259 {
00260   char *dst_ = (char*) dst ;
00261   char *src_ = (char*) src ;
00262 #if defined(VL_ARCH_BIG_ENDIAN)
00263     dst_ [0] = src_ [0] ;
00264     dst_ [1] = src_ [1] ;
00265     dst_ [2] = src_ [2] ;
00266     dst_ [3] = src_ [3] ;
00267     dst_ [4] = src_ [4] ;
00268     dst_ [5] = src_ [5] ;
00269     dst_ [6] = src_ [6] ;
00270     dst_ [7] = src_ [7] ;
00271 #else 
00272     dst_ [0] = src_ [7] ;
00273     dst_ [1] = src_ [6] ;
00274     dst_ [2] = src_ [5] ;
00275     dst_ [3] = src_ [4] ;
00276     dst_ [4] = src_ [3] ;
00277     dst_ [5] = src_ [2] ;
00278     dst_ [6] = src_ [1] ;
00279     dst_ [7] = src_ [0] ;
00280 #endif
00281 }
00282 
00291 VL_INLINE void
00292 vl_swap_host_big_endianness_4 (void *dst, void* src)
00293 {
00294   char *dst_ = (char*) dst ;
00295   char *src_ = (char*) src ;
00296 #if defined(VL_ARCH_BIG_ENDIAN)
00297     dst_ [0] = src_ [0] ;
00298     dst_ [1] = src_ [1] ;
00299     dst_ [2] = src_ [2] ;
00300     dst_ [3] = src_ [3] ;
00301 #else 
00302     dst_ [0] = src_ [3] ;
00303     dst_ [1] = src_ [2] ;
00304     dst_ [2] = src_ [1] ;
00305     dst_ [3] = src_ [0] ;
00306 #endif
00307 }
00308 
00317 VL_INLINE void
00318 vl_swap_host_big_endianness_2 (void *dst, void* src)
00319 {
00320   char *dst_ = (char*) dst ;
00321   char *src_ = (char*) src ;
00322 #if defined(VL_ARCH_BIG_ENDIAN)
00323     dst_ [0] = src_ [0] ;
00324     dst_ [1] = src_ [1] ;
00325 #else
00326     dst_ [0] = src_ [1] ;
00327     dst_ [1] = src_ [0] ;
00328 #endif
00329 }
00330 
00331 extern VL_EXPORT int   (*vl_printf_func)  (char const * format, ...) ;
00332 extern VL_EXPORT void *(*vl_malloc_func)  (size_t) ;
00333 extern VL_EXPORT void *(*vl_realloc_func) (void*,size_t) ;
00334 extern VL_EXPORT void *(*vl_calloc_func)  (size_t, size_t) ;
00335 extern VL_EXPORT void  (*vl_free_func)    (void*) ;          
00336 
00337 VL_INLINE 
00338 void* vl_malloc (size_t n)
00339 {
00340   return (*vl_malloc_func)(n) ;
00341 }
00342 
00343 VL_INLINE
00344 void* vl_realloc (void* ptr, size_t n)
00345 {
00346   return (*vl_realloc_func)(ptr, n) ;
00347 }
00348 
00349 VL_INLINE
00350 void* vl_calloc (size_t n, size_t size)
00351 {
00352   return (*vl_calloc_func)(n, size) ;
00353 }
00354 
00355 VL_INLINE
00356 void vl_free (void *ptr)
00357 {
00358   (*vl_free_func)(ptr) ;
00359 }
00360 
00361 /* VL_GENERIC_H */
00362 #endif
Copyright © 2008 Andrea Vedaldi and Brian Fulkerson