summaryrefslogtreecommitdiff
path: root/src/xine-engine/bswap.h
blob: 3415a09b4b07af0090f22a2f8a67e77edc16574e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (C) 2000-2006 the xine project
 *
 * This file is part of xine, a free video player.
 *
 * xine is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * xine 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 */

#ifndef __BSWAP_H__
#define __BSWAP_H__

#include "config.h"

#define always_inline inline 

#include "ffmpeg_bswap.h"

/* These are the Aligned variants */
#define ABE_16(x) (be2me_16(*(uint16_t*)(x)))
#define ABE_32(x) (be2me_32(*(uint32_t*)(x)))
#define ABE_64(x) (be2me_64(*(uint64_t*)(x)))
#define ALE_16(x) (le2me_16(*(uint16_t*)(x)))
#define ALE_32(x) (le2me_32(*(uint32_t*)(x)))
#define ALE_64(x) (le2me_64(*(uint64_t*)(x)))

#define BE_16(x) (((uint16_t)(((uint8_t*)(x))[0]) << 8) | \
                  ((uint16_t)((uint8_t*)(x))[1]))
#define BE_24(x) (((uint32_t)(((uint8_t*)(x))[0]) << 16) | \
                  ((uint32_t)(((uint8_t*)(x))[1]) << 8) | \
                  ((uint32_t)(((uint8_t*)(x))[2])))
#define BE_32(x) (((uint32_t)(((uint8_t*)(x))[0]) << 24) | \
                  ((uint32_t)(((uint8_t*)(x))[1]) << 16) | \
                  ((uint32_t)(((uint8_t*)(x))[2]) << 8) | \
                  ((uint32_t)((uint8_t*)(x))[3]))
#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
                  ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
                  ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \
                  ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \
                  ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \
                  ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \
                  ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \
                  ((uint64_t)((uint8_t*)(x))[7]))

#define LE_16(x) (((uint16_t)(((uint8_t*)(x))[1]) << 8) | \
                  ((uint16_t)((uint8_t*)(x))[0]))
#define LE_24(x) (((uint32_t)(((uint8_t*)(x))[2]) << 16) | \
                  ((uint32_t)(((uint8_t*)(x))[1]) << 8) | \
                  ((uint32_t)(((uint8_t*)(x))[0])))
#define LE_32(x) (((uint32_t)(((uint8_t*)(x))[3]) << 24) | \
                  ((uint32_t)(((uint8_t*)(x))[2]) << 16) | \
                  ((uint32_t)(((uint8_t*)(x))[1]) << 8) | \
                  ((uint32_t)((uint8_t*)(x))[0]))
#define LE_64(x) (((uint64_t)(((uint8_t*)(x))[7]) << 56) | \
                  ((uint64_t)(((uint8_t*)(x))[6]) << 48) | \
                  ((uint64_t)(((uint8_t*)(x))[5]) << 40) | \
                  ((uint64_t)(((uint8_t*)(x))[4]) << 32) | \
                  ((uint64_t)(((uint8_t*)(x))[3]) << 24) | \
                  ((uint64_t)(((uint8_t*)(x))[2]) << 16) | \
                  ((uint64_t)(((uint8_t*)(x))[1]) << 8) | \
                  ((uint64_t)((uint8_t*)(x))[0]))

#ifdef WORDS_BIGENDIAN
#define ME_16(x) BE_16(x)
#define ME_32(x) BE_32(x)
#define ME_64(x) BE_64(x)
#define AME_16(x) ABE_16(x)
#define AME_32(x) ABE_32(x)
#define AME_64(x) ABE_64(x)
#else
#define ME_16(x) LE_16(x)
#define ME_32(x) LE_32(x)
#define ME_64(x) LE_64(x)
#define AME_16(x) ALE_16(x)
#define AME_32(x) ALE_32(x)
#define AME_64(x) ALE_64(x)
#endif

#define BE_FOURCC( ch0, ch1, ch2, ch3 )             \
        ( (uint32_t)(unsigned char)(ch3) |          \
        ( (uint32_t)(unsigned char)(ch2) << 8 ) |   \
        ( (uint32_t)(unsigned char)(ch1) << 16 ) |  \
        ( (uint32_t)(unsigned char)(ch0) << 24 ) )

#define LE_FOURCC( ch0, ch1, ch2, ch3 )             \
        ( (uint32_t)(unsigned char)(ch0) |          \
        ( (uint32_t)(unsigned char)(ch1) << 8 ) |   \
        ( (uint32_t)(unsigned char)(ch2) << 16 ) |  \
        ( (uint32_t)(unsigned char)(ch3) << 24 ) )
        
#ifdef WORDS_BIGENDIAN
#define ME_FOURCC BE_FOURCC
#else
#define ME_FOURCC LE_FOURCC
#endif

#endif