a563ce7eedd59e0a224587a4864fc3f666102a82
4 * Created on: Feb 23, 2011
7 * This file is part of vid.stab video stabilization library
9 * vid.stab is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License,
11 * as published by the Free Software Foundation; either version 2, or
12 * (at your option) any later version.
14 * vid.stab is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Make; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifndef VIDSTABDEFINES_H_
27 #define VIDSTABDEFINES_H_
33 #define likely(x) __builtin_expect(!!(x), 1)
34 #define unlikely(x) __builtin_expect(!!(x), 0)
37 #define unlikely(x) (x)
40 #define VS_MAX(a, b) (((a) > (b)) ?(a) :(b))
41 #define VS_MIN(a, b) (((a) < (b)) ?(a) :(b))
42 /* clamp x between a and b */
43 #define VS_CLAMP(x, a, b) VS_MIN(VS_MAX((a), (x)), (b))
47 /// pixel in single layer image
48 #define PIXEL(img, linesize, x, y, w, h, def) \
49 (((x) < 0 || (y) < 0 || (x) >= (w) || (y) >= (h)) ? (def) : img[(x) + (y) * (linesize)])
50 /// pixel in single layer image without rangecheck
51 #define PIX(img, linesize, x, y) (img[(x) + (y) * (linesize)])
52 /// pixel in N-channel image. channel in {0..N-1}
53 #define PIXELN(img, linesize, x, y, w, h, N, channel, def) \
54 (((x) < 0 || (y) < 0 || (x) >= (w) || (y) >= (h)) ? (def) : img[((x) + (y) * (linesize))*(N) + (channel)])
55 /// pixel in N-channel image without rangecheck. channel in {0..N-1}
56 #define PIXN(img, linesize, x, y, N, channel) (img[((x) + (y) * (linesize))*(N) + (channel)])
58 /**** Configurable memory and logging functions. Defined in libvidstab.c ****/
60 typedef void* (*vs_malloc_t
) (size_t size
);
61 typedef void* (*vs_realloc_t
) (void* ptr
, size_t size
);
62 typedef void (*vs_free_t
) (void* ptr
);
63 typedef void* (*vs_zalloc_t
) (size_t size
);
65 typedef int (*vs_log_t
) (int type
, const char* tag
, const char* format
, ...);
67 typedef char* (*vs_strdup_t
) (const char* s
);
69 extern vs_log_t vs_log
;
71 extern vs_malloc_t vs_malloc
;
72 extern vs_realloc_t vs_realloc
;
73 extern vs_free_t vs_free
;
74 extern vs_zalloc_t vs_zalloc
;
76 extern vs_strdup_t vs_strdup
;
78 extern int VS_ERROR_TYPE
;
79 extern int VS_WARN_TYPE
;
80 extern int VS_INFO_TYPE
;
81 extern int VS_MSG_TYPE
;
86 #define vs_log_error(tag, format, args...) \
87 vs_log(VS_ERROR_TYPE, tag, format , ## args)
88 #define vs_log_warn(tag, format, args...) \
89 vs_log(VS_WARN_TYPE, tag, format , ## args)
90 #define vs_log_info(tag, format, args...) \
91 vs_log(VS_INFO_TYPE, tag, format , ## args)
92 #define vs_log_msg(tag, format, args...) \
93 vs_log(VS_MSG_TYPE, tag, format , ## args)
95 #endif /* VIDSTABDEFINES_H_ */