gst_plugins_base/gst-libs/gst/floatcast/floatcast.h
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    38 
    38 
    39 #ifndef __FLOATCAST_H__
    39 #ifndef __FLOATCAST_H__
    40 #define __FLOATCAST_H__
    40 #define __FLOATCAST_H__
    41 
    41 
    42 #include <string.h>
    42 #include <string.h>
    43 #include <glib.h>
    43 #include <glib/gtypes.h>
       
    44 #include <glib/gutils.h>  /* to make sure inline is defined properly */
    44 
    45 
    45 #if defined (_MSC_VER) && !defined (inline)
    46 #if defined (_MSC_VER) && !defined (inline)
    46 #define inline __inline
    47 #define inline __inline
    47 #endif
    48 #endif
    48 
    49 
    94         #define gst_cast_float(x)       ((gint)floor((x)+0.5))
    95         #define gst_cast_float(x)       ((gint)floor((x)+0.5))
    95         #define gst_cast_double(x)      ((gint)floor((x)+0.5))
    96         #define gst_cast_double(x)      ((gint)floor((x)+0.5))
    96 
    97 
    97 #endif
    98 #endif
    98 
    99 
       
   100 /* FIXME 0.11: don't use GLib namespace (GDOUBLE_SWAP_LE_BE, GFLOAT_TO_LE,
       
   101  * GFLOAT_TO_BE, GDOUBLE_TO_LE, GDOUBLE_TO_BE) */
       
   102 
       
   103 /**
       
   104  * GFLOAT_SWAP_LE_BE:
       
   105  * @in: input value
       
   106  *
       
   107  * Swap byte order of a 32-bit floating point value (float).
       
   108  */
       
   109 inline static gfloat
       
   110 GFLOAT_SWAP_LE_BE(gfloat in)
       
   111 {
       
   112   union
       
   113   {
       
   114     guint32 i;
       
   115     gfloat f;
       
   116   } u;
       
   117 
       
   118   u.f = in;
       
   119   u.i = GUINT32_SWAP_LE_BE (u.i);
       
   120   return u.f;
       
   121 }
       
   122 
       
   123 /**
       
   124  * GDOUBLE_SWAP_LE_BE:
       
   125  * @in: input value
       
   126  *
       
   127  * Swap byte order of a 64-bit floating point value (double).
       
   128  */
       
   129 inline static gdouble
       
   130 GDOUBLE_SWAP_LE_BE(gdouble in)
       
   131 {
       
   132   union
       
   133   {
       
   134     guint64 i;
       
   135     gdouble d;
       
   136   } u;
       
   137 
       
   138   u.d = in;
       
   139   u.i = GUINT64_SWAP_LE_BE (u.i);
       
   140   return u.d;
       
   141 }
       
   142 
       
   143 /**
       
   144  * GDOUBLE_TO_LE:
       
   145  * @val: value
       
   146  *
       
   147  * Convert 64-bit floating point value (double) from native byte order into
       
   148  * little endian byte order.
       
   149  */
       
   150 /**
       
   151  * GDOUBLE_TO_BE:
       
   152  * @val: value
       
   153  *
       
   154  * Convert 64-bit floating point value (double) from native byte order into
       
   155  * big endian byte order.
       
   156  */
       
   157 /**
       
   158  * GDOUBLE_FROM_LE:
       
   159  * @val: value
       
   160  *
       
   161  * Convert 64-bit floating point value (double) from little endian byte order
       
   162  * into native byte order.
       
   163  */
       
   164 /**
       
   165  * GDOUBLE_FROM_BE:
       
   166  * @val: value
       
   167  *
       
   168  * Convert 64-bit floating point value (double) from big endian byte order
       
   169  * into native byte order.
       
   170  */
       
   171 
       
   172 /**
       
   173  * GFLOAT_TO_LE:
       
   174  * @val: value
       
   175  *
       
   176  * Convert 32-bit floating point value (float) from native byte order into
       
   177  * little endian byte order.
       
   178  */
       
   179 /**
       
   180  * GFLOAT_TO_BE:
       
   181  * @val: value
       
   182  *
       
   183  * Convert 32-bit floating point value (float) from native byte order into
       
   184  * big endian byte order.
       
   185  */
       
   186 /**
       
   187  * GFLOAT_FROM_LE:
       
   188  * @val: value
       
   189  *
       
   190  * Convert 32-bit floating point value (float) from little endian byte order
       
   191  * into native byte order.
       
   192  */
       
   193 /**
       
   194  * GFLOAT_FROM_BE:
       
   195  * @val: value
       
   196  *
       
   197  * Convert 32-bit floating point value (float) from big endian byte order
       
   198  * into native byte order.
       
   199  */
       
   200 
       
   201 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
       
   202 #define GFLOAT_TO_LE(val)    ((gfloat) (val))
       
   203 #define GFLOAT_TO_BE(val)    (GFLOAT_SWAP_LE_BE (val))
       
   204 #define GDOUBLE_TO_LE(val)   ((gdouble) (val))
       
   205 #define GDOUBLE_TO_BE(val)   (GDOUBLE_SWAP_LE_BE (val))
       
   206 
       
   207 #elif G_BYTE_ORDER == G_BIG_ENDIAN
       
   208 #define GFLOAT_TO_LE(val)    (GFLOAT_SWAP_LE_BE (val))
       
   209 #define GFLOAT_TO_BE(val)    ((gfloat) (val))
       
   210 #define GDOUBLE_TO_LE(val)   (GDOUBLE_SWAP_LE_BE (val))
       
   211 #define GDOUBLE_TO_BE(val)   ((gdouble) (val))
       
   212 
       
   213 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
       
   214 #error unknown ENDIAN type
       
   215 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
       
   216 
       
   217 #define GFLOAT_FROM_LE(val)  (GFLOAT_TO_LE (val))
       
   218 #define GFLOAT_FROM_BE(val)  (GFLOAT_TO_BE (val))
       
   219 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
       
   220 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
       
   221 
    99 G_END_DECLS
   222 G_END_DECLS
   100 
   223 
   101 #endif /* __FLOATCAST_H__ */
   224 #endif /* __FLOATCAST_H__ */
   102 
   225