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
27 #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | \
28 ((const uint8_t*)(x))[1])
31 #define AV_WB16(p, d) do { \
32 ((uint8_t*)(p))[1] = (d); \
33 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
37 #define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
38 ((const uint8_t*)(x))[0])
41 #define AV_WL16(p, d) do { \
42 ((uint8_t*)(p))[0] = (d); \
43 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
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])
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)
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])
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)
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])
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)
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])
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)
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)
122 # define AV_RN(s, p) AV_RL##s(p)
123 # define AV_WN(s, p, v) AV_WL##s(p, v)
127 # define AV_RN16(p) AV_RN(16, p)
131 # define AV_RN32(p) AV_RN(32, p)
135 # define AV_RN64(p) AV_RN(64, p)
139 # define AV_WN16(p, v) AV_WN(16, p, v)
143 # define AV_WN32(p, v) AV_WN(32, p, v)
147 # define AV_WN64(p, v) AV_WN(64, p, v)
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))
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)
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)
169 # define AV_RB16(p) AV_RB(16, p)
172 # define AV_WB16(p, v) AV_WB(16, p, v)
176 # define AV_RL16(p) AV_RL(16, p)
179 # define AV_WL16(p, v) AV_WL(16, p, v)
183 # define AV_RB32(p) AV_RB(32, p)
186 # define AV_WB32(p, v) AV_WB(32, p, v)
190 # define AV_RL32(p) AV_RL(32, p)
193 # define AV_WL32(p, v) AV_WL(32, p, v)
197 # define AV_RB64(p) AV_RB(64, p)
200 # define AV_WB64(p, v) AV_WB(64, p, v)
204 # define AV_RL64(p) AV_RL(64, p)
207 # define AV_WL64(p, v) AV_WL(64, p, v)
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 */