From 2797f74c842f829503afea713a0a557aed46f6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 5 Oct 2010 14:16:19 +0100 Subject: [PATCH] gst: add math-compat.h header Add minimal math-compath.h header where we can define fallback versions for miscellaneous math functions that aren't always available, so we don't have to duplicate this in plugins. The header is not included by default, so needs to be included explicitly for now. https://bugzilla.gnome.org/show_bug.cgi?id=630802 --- docs/gst/Makefile.am | 1 + gst/Makefile.am | 3 +- gst/math-compat.h | 82 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 gst/math-compat.h diff --git a/docs/gst/Makefile.am b/docs/gst/Makefile.am index d92ea2ab5b..d4da1c4646 100644 --- a/docs/gst/Makefile.am +++ b/docs/gst/Makefile.am @@ -73,6 +73,7 @@ IGNORE_HFILES= \ \ grammar.tab.h \ grammar.tab.pre.h \ + math-compat.h \ types.h gst-universe.svg: gst-universe.dot diff --git a/gst/Makefile.am b/gst/Makefile.am index b85dd756c2..c65dd3ad0f 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -196,7 +196,8 @@ gst_headers = \ gstparse.h \ gstxml.h -libgstreamer_@GST_MAJORMINOR@include_HEADERS = $(gst_headers) +libgstreamer_@GST_MAJORMINOR@include_HEADERS = $(gst_headers) math-compat.h + nodist_libgstreamer_@GST_MAJORMINOR@include_HEADERS = \ $(built_header_configure) $(built_header_make) diff --git a/gst/math-compat.h b/gst/math-compat.h new file mode 100644 index 0000000000..02a2b52844 --- /dev/null +++ b/gst/math-compat.h @@ -0,0 +1,82 @@ +/* GStreamer + * Copyright (C) 2010 Tim-Philipp Müller + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_MATH_COMPAT_H__ +#define __GST_MATH_COMPAT_H__ + +/* This header is not included automatically via gst/gst.h, you need to + * include it explicitly if you need it. */ + +#define _USE_MATH_DEFINES /* so MSVC defines M_PI etc. */ +#include + +#include + +G_BEGIN_DECLS + +/* http://en.wikipedia.org/wiki/Math.h */ + +#define __GST_MATH_COMPAT_NEED_RINT +#define __GST_MATH_COMPAT_NEED_RINTF + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#undef __GST_MATH_COMPAT_NEED_RINT +#undef __GST_MATH_COMPAT_NEED_RINTF +#endif + +#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +#undef __GST_MATH_COMPAT_NEED_RINT +#undef __GST_MATH_COMPAT_NEED_RINTF +#endif + +#ifndef M_PI +#define M_PI G_PI +#endif + +#ifndef M_PI_2 +#define M_PI_2 G_PI_2 +#endif + +#ifndef M_PI_4 +#define M_PI_4 G_PI_4 +#endif + +static inline double +__gst_math_compat_rint (double x) +{ + return floor (x + 0.5); +} + +static inline float +__gst_math_compat_rintf (float x) +{ + return floorf (x + 0.5); +} + +#if defined (__GST_MATH_COMPAT_NEED_RINT) && !defined (rint) +#define rint(x) __gst_math_compat_rint(x) +#endif + +#if defined (__GST_MATH_COMPAT_NEED_RINTF) && !defined (rintf) +#define rintf(x) __gst_math_compat_rintf(x) +#endif + +G_END_DECLS + +#endif /* __GST_MATH_COMPAT_H__ */