1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org>
4  *
5  * Authors: Dennis Smit <ds@nerds-incorporated.org>
6  *
7  * $Id:
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _LV_ENDIANESS_H
25 #define _LV_ENDIANESS_H
26 
27 #include <libvisual/lvconfig.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 
33 /**
34  * Macros to convert LE <-> BE
35  * 'I' stands for integer here.
36  */
37 #define VISUAL_ENDIAN_LE_BE_I16(w) (\
38 	(((w) & 0xff00) >> 8) |\
39 	(((w) & 0x00ff) << 8) )
40 
41 #define VISUAL_ENDIAN_LE_BE_I32(w) (\
42 	(((w) & 0x000000ff) << 24) | \
43 	(((w) & 0x0000ff00) << 8) | \
44 	(((w) & 0x00ff0000) >> 8) | \
45 	(((w) & 0xff000000) >> 24) )
46 
47 
48 #if VISUAL_BIG_ENDIAN & VISUAL_LITTLE_ENDIAN
49 #	error determining system endianess.
50 #endif
51 
52 /**
53  * Arch. dependant definitions
54  */
55 
56 #if VISUAL_BIG_ENDIAN
57 #	define VISUAL_ENDIAN_BEI16(x) (x)
58 #	define VISUAL_ENDIAN_BEI32(x) (x)
59 #	define VISUAL_ENDIAN_LEI16(x) VISUAL_ENDIAN_LE_BE_I16(x)
60 #	define VISUAL_ENDIAN_LEI32(x) VISUAL_ENDIAN_LE_BE_I32(x)
61 #endif
62 
63 #if VISUAL_LITTLE_ENDIAN
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 
70 
71 #ifdef __cplusplus
72 }
73 #endif /* __cplusplus */
74 
75 #endif /* _LV_ENDIANESS_H */
76