vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / ffmpeg_files / intreadwrite.h
blobff4e917e4623d9efc3448bc2f41c337d805f5bd4
1 /*
2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef MP_AVUTIL_INTREADWRITE_H
20 #define MP_AVUTIL_INTREADWRITE_H
22 #include <stdint.h>
23 #include "config.h"
24 #include "bswap.h"
26 #ifndef AV_RB16
27 #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | \
28 ((const uint8_t*)(x))[1])
29 #endif
30 #ifndef AV_WB16
31 #define AV_WB16(p, d) do { \
32 ((uint8_t*)(p))[1] = (d); \
33 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
34 #endif
36 #ifndef AV_RL16
37 #define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
38 ((const uint8_t*)(x))[0])
39 #endif
40 #ifndef AV_WL16
41 #define AV_WL16(p, d) do { \
42 ((uint8_t*)(p))[0] = (d); \
43 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
44 #endif
46 #ifndef AV_RB32
47 #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
48 (((const uint8_t*)(x))[1] << 16) | \
49 (((const uint8_t*)(x))[2] << 8) | \
50 ((const uint8_t*)(x))[3])
51 #endif
52 #ifndef AV_WB32
53 #define AV_WB32(p, d) do { \
54 ((uint8_t*)(p))[3] = (d); \
55 ((uint8_t*)(p))[2] = (d)>>8; \
56 ((uint8_t*)(p))[1] = (d)>>16; \
57 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
58 #endif
60 #ifndef AV_RL32
61 #define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
62 (((const uint8_t*)(x))[2] << 16) | \
63 (((const uint8_t*)(x))[1] << 8) | \
64 ((const uint8_t*)(x))[0])
65 #endif
66 #ifndef AV_WL32
67 #define AV_WL32(p, d) do { \
68 ((uint8_t*)(p))[0] = (d); \
69 ((uint8_t*)(p))[1] = (d)>>8; \
70 ((uint8_t*)(p))[2] = (d)>>16; \
71 ((uint8_t*)(p))[3] = (d)>>24; } while(0)
72 #endif
74 #ifndef AV_RB64
75 #define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
76 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
77 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
78 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
79 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
80 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
81 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
82 (uint64_t)((const uint8_t*)(x))[7])
83 #endif
84 #ifndef AV_WB64
85 #define AV_WB64(p, d) do { \
86 ((uint8_t*)(p))[7] = (d); \
87 ((uint8_t*)(p))[6] = (d)>>8; \
88 ((uint8_t*)(p))[5] = (d)>>16; \
89 ((uint8_t*)(p))[4] = (d)>>24; \
90 ((uint8_t*)(p))[3] = (d)>>32; \
91 ((uint8_t*)(p))[2] = (d)>>40; \
92 ((uint8_t*)(p))[1] = (d)>>48; \
93 ((uint8_t*)(p))[0] = (d)>>56; } while(0)
94 #endif
96 #ifndef AV_RL64
97 #define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
98 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
99 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
100 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
101 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
102 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
103 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
104 (uint64_t)((const uint8_t*)(x))[0])
105 #endif
106 #ifndef AV_WL64
107 #define AV_WL64(p, d) do { \
108 ((uint8_t*)(p))[0] = (d); \
109 ((uint8_t*)(p))[1] = (d)>>8; \
110 ((uint8_t*)(p))[2] = (d)>>16; \
111 ((uint8_t*)(p))[3] = (d)>>24; \
112 ((uint8_t*)(p))[4] = (d)>>32; \
113 ((uint8_t*)(p))[5] = (d)>>40; \
114 ((uint8_t*)(p))[6] = (d)>>48; \
115 ((uint8_t*)(p))[7] = (d)>>56; } while(0)
116 #endif
118 #ifdef WORDS_BIGENDIAN
119 # define AV_RN(s, p) AV_RB##s(p)
120 # define AV_WN(s, p, v) AV_WB##s(p, v)
121 #else
122 # define AV_RN(s, p) AV_RL##s(p)
123 # define AV_WN(s, p, v) AV_WL##s(p, v)
124 #endif
126 #ifndef AV_RN16
127 # define AV_RN16(p) AV_RN(16, p)
128 #endif
130 #ifndef AV_RN32
131 # define AV_RN32(p) AV_RN(32, p)
132 #endif
134 #ifndef AV_RN64
135 # define AV_RN64(p) AV_RN(64, p)
136 #endif
138 #ifndef AV_WN16
139 # define AV_WN16(p, v) AV_WN(16, p, v)
140 #endif
142 #ifndef AV_WN32
143 # define AV_WN32(p, v) AV_WN(32, p, v)
144 #endif
146 #ifndef AV_WN64
147 # define AV_WN64(p, v) AV_WN(64, p, v)
148 #endif
150 #ifdef WORDS_BIGENDIAN
151 # define AV_RB(s, p) AV_RN(s, p)
152 # define AV_WB(s, p, v) AV_WN(s, p, v)
153 # define AV_RL(s, p) bswap_##s(AV_RN(s, p))
154 # define AV_WL(s, p, v) AV_WN(s, p, bswap_##s(v))
155 #else
156 # define AV_RB(s, p) bswap_##s(AV_RN(s, p))
157 # define AV_WB(s, p, v) AV_WN(s, p, bswap_##s(v))
158 # define AV_RL(s, p) AV_RN(s, p)
159 # define AV_WL(s, p, v) AV_WN(s, p, v)
160 #endif
162 #define AV_RB8(x) (((const uint8_t*)(x))[0])
163 #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
165 #define AV_RL8(x) AV_RB8(x)
166 #define AV_WL8(p, d) AV_WB8(p, d)
168 #ifndef AV_RB16
169 # define AV_RB16(p) AV_RB(16, p)
170 #endif
171 #ifndef AV_WB16
172 # define AV_WB16(p, v) AV_WB(16, p, v)
173 #endif
175 #ifndef AV_RL16
176 # define AV_RL16(p) AV_RL(16, p)
177 #endif
178 #ifndef AV_WL16
179 # define AV_WL16(p, v) AV_WL(16, p, v)
180 #endif
182 #ifndef AV_RB32
183 # define AV_RB32(p) AV_RB(32, p)
184 #endif
185 #ifndef AV_WB32
186 # define AV_WB32(p, v) AV_WB(32, p, v)
187 #endif
189 #ifndef AV_RL32
190 # define AV_RL32(p) AV_RL(32, p)
191 #endif
192 #ifndef AV_WL32
193 # define AV_WL32(p, v) AV_WL(32, p, v)
194 #endif
196 #ifndef AV_RB64
197 # define AV_RB64(p) AV_RB(64, p)
198 #endif
199 #ifndef AV_WB64
200 # define AV_WB64(p, v) AV_WB(64, p, v)
201 #endif
203 #ifndef AV_RL64
204 # define AV_RL64(p) AV_RL(64, p)
205 #endif
206 #ifndef AV_WL64
207 # define AV_WL64(p, v) AV_WL(64, p, v)
208 #endif
210 #define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
211 (((const uint8_t*)(x))[1] << 8) | \
212 ((const uint8_t*)(x))[2])
213 #define AV_WB24(p, d) do { \
214 ((uint8_t*)(p))[2] = (d); \
215 ((uint8_t*)(p))[1] = (d)>>8; \
216 ((uint8_t*)(p))[0] = (d)>>16; } while(0)
218 #define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
219 (((const uint8_t*)(x))[1] << 8) | \
220 ((const uint8_t*)(x))[0])
221 #define AV_WL24(p, d) do { \
222 ((uint8_t*)(p))[0] = (d); \
223 ((uint8_t*)(p))[1] = (d)>>8; \
224 ((uint8_t*)(p))[2] = (d)>>16; } while(0)
226 #endif /* AVUTIL_INTREADWRITE_H */