summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Johnson <leif@ambient.2y.net>2003-11-16 21:47:16 +0000
committerLeif Johnson <leif@ambient.2y.net>2003-11-16 21:47:16 +0000
commit70ac550707d2b3049836750e523404aa6460e915 (patch)
tree444f2e24538ea18053ea996c4aca7ba0e33751a6
parentfe6b374d2d4a57c4d472f999ba4a41cb49c6826a (diff)
downloadgst-plugins-bad-70ac550707d2b3049836750e523404aa6460e915.tar.gz
gst-plugins-bad-70ac550707d2b3049836750e523404aa6460e915.tar.bz2
gst-plugins-bad-70ac550707d2b3049836750e523404aa6460e915.zip
+ adding endianness conversion macros for floats
Original commit message from CVS: + adding endianness conversion macros for floats
-rw-r--r--gst-libs/gst/floatcast/floatcast.h56
1 files changed, 55 insertions, 1 deletions
diff --git a/gst-libs/gst/floatcast/floatcast.h b/gst-libs/gst/floatcast/floatcast.h
index 0d5809f1..99577d91 100644
--- a/gst-libs/gst/floatcast/floatcast.h
+++ b/gst-libs/gst/floatcast/floatcast.h
@@ -21,6 +21,15 @@
#ifndef __FLOATCAST_H__
#define __FLOATCAST_H__
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <glib/gtypes.h>
+
+G_BEGIN_DECLS
+
#if (HAVE_LRINT && HAVE_LRINTF)
/* These defines enable functionality introduced with the 1999 ISO C
@@ -40,7 +49,7 @@
#define gst_cast_float(x) ((gint)lrintf(x))
#define gst_cast_double(x) ((gint)lrint(x))
-
+
#else
/* use a standard c cast, but do rounding correctly */
#define gst_cast_float(x) ((x)>=0?(gint)((x)+0.5):(gint)((x)-0.5))
@@ -48,5 +57,50 @@
#endif
+inline static gfloat
+GFLOAT_SWAP_LE_BE(gfloat in)
+{
+ gint32 swap;
+ gfloat out;
+ memcpy(&swap, &in, 4);
+ swap = GUINT32_SWAP_LE_BE_CONSTANT (swap);
+ memcpy(&out, &swap, 4);
+ return out;
+}
+
+inline static gdouble
+GDOUBLE_SWAP_LE_BE(gdouble in)
+{
+ gint64 swap;
+ gdouble out;
+ memcpy(&swap, &in, 8);
+ swap = GUINT64_SWAP_LE_BE_CONSTANT (swap);
+ memcpy(&out, &swap, 8);
+ return out;
+}
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GFLOAT_TO_LE(val) ((gfloat) (val))
+#define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
+#define GDOUBLE_TO_LE(val) ((gdouble) (val))
+#define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
+
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
+#define GFLOAT_TO_BE(val) ((gfloat) (val))
+#define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
+#define GDOUBLE_TO_BE(val) ((gdouble) (val))
+
+#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+#error unknown ENDIAN type
+#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+
+#define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
+#define GFLOAT_FROM_BE(val) (GDOUBLE_TO_BE (val))
+#define GDOUBLE_FROM_LE(val) (GFLOAT_TO_LE (val))
+#define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
+
+G_END_DECLS
+
#endif /* __FLOATCAST_H__ */