libvisual  0.5.0
lv_bits.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Dennis Smit <ds@nerds-incorporated.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as
10  * published by the Free Software Foundation; either version 2.1
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
23 #ifndef _LV_ENDIANESS_H
24 #define _LV_ENDIANESS_H
25 
26 #include <libvisual/lvconfig.h>
27 #include <libvisual/lv_defines.h>
28 
29 LV_BEGIN_DECLS
30 
35 #define VISUAL_ENDIAN_LE_BE_I16(w) (\
36  (((w) & 0xff00) >> 8) |\
37  (((w) & 0x00ff) << 8) )
38 
39 #define VISUAL_ENDIAN_LE_BE_I32(w) (\
40  (((w) & 0x000000ff) << 24) | \
41  (((w) & 0x0000ff00) << 8) | \
42  (((w) & 0x00ff0000) >> 8) | \
43  (((w) & 0xff000000) >> 24) )
44 
45 
46 #if ! ((VISUAL_BIG_ENDIAN) | (VISUAL_LITTLE_ENDIAN))
47 # error determining system endianess. (none set)
48 #endif
49 
50 #if ((VISUAL_BIG_ENDIAN == 1) & (VISUAL_LITTLE_ENDIAN == 1))
51 # error determing system endianess (both set?)
52 #endif
53 
58 #if VISUAL_BIG_ENDIAN == 1
59 # define VISUAL_ENDIAN_BEI16(x) (x)
60 # define VISUAL_ENDIAN_BEI32(x) (x)
61 # define VISUAL_ENDIAN_LEI16(x) VISUAL_ENDIAN_LE_BE_I16(x)
62 # define VISUAL_ENDIAN_LEI32(x) VISUAL_ENDIAN_LE_BE_I32(x)
63 #else
64 # define VISUAL_ENDIAN_LEI16(x) (x)
65 # define VISUAL_ENDIAN_LEI32(x) (x)
66 # define VISUAL_ENDIAN_BEI16(x) VISUAL_ENDIAN_LE_BE_I16(x)
67 # define VISUAL_ENDIAN_BEI32(x) VISUAL_ENDIAN_LE_BE_I32(x)
68 #endif
69 
74 #define VISUAL_ALIGNED(x, y) (!(((intptr_t) x) & (y - 1)))
75 
76 LV_END_DECLS
77 
78 #endif /* _LV_ENDIANESS_H */