[FFmpeg-devel] [PATCHv2 1/2] avutil/common: add FFABSDIFF macro

Ganesh Ajjanagadde gajjanagadde at gmail.com
Mon Aug 24 00:11:34 CEST 2015


FFABSDIFF(a,b) expands to effectively abs((int)a-(int)b).
Note that this is not safe in general as it makes assumptions on the widths.
This macro is useful across at least 3 places in the codebase,
and is therefore placed in avutil/common.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavutil/common.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/common.h b/libavutil/common.h
index 3e62b6d..ad27405 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -59,6 +59,7 @@
 #define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b))
 #define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b))
 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
+#define FFABSDIFF(a,b) (abs((int)(a)-(int)(b))) /* assume no overflow */
 #define FFSIGN(a) ((a) > 0 ? 1 : -1)
 
 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
-- 
2.5.0



More information about the ffmpeg-devel mailing list