Initial 800x480 cabbiev2 port, based on 480x800x16 one
[kugel-rb.git] / apps / codecs / lib / ffmpeg_intreadwrite.h
blob24f03292e8a72026601e31ae57178719ed4f479a
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 AVUTIL_INTREADWRITE_H
20 #define AVUTIL_INTREADWRITE_H
22 #include <stdint.h>
24 * Arch-specific headers can provide any combination of
25 * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
26 * Preprocessor symbols must be defined, even if these are implemented
27 * as inline functions.
31 * Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
33 #define HAVE_BIGENDIAN 0
34 #if HAVE_BIGENDIAN
36 # if defined(AV_RN16) && !defined(AV_RB16)
37 # define AV_RB16(p) AV_RN16(p)
38 # elif !defined(AV_RN16) && defined(AV_RB16)
39 # define AV_RN16(p) AV_RB16(p)
40 # endif
42 # if defined(AV_WN16) && !defined(AV_WB16)
43 # define AV_WB16(p, v) AV_WN16(p, v)
44 # elif !defined(AV_WN16) && defined(AV_WB16)
45 # define AV_WN16(p, v) AV_WB16(p, v)
46 # endif
48 # if defined(AV_RN24) && !defined(AV_RB24)
49 # define AV_RB24(p) AV_RN24(p)
50 # elif !defined(AV_RN24) && defined(AV_RB24)
51 # define AV_RN24(p) AV_RB24(p)
52 # endif
54 # if defined(AV_WN24) && !defined(AV_WB24)
55 # define AV_WB24(p, v) AV_WN24(p, v)
56 # elif !defined(AV_WN24) && defined(AV_WB24)
57 # define AV_WN24(p, v) AV_WB24(p, v)
58 # endif
60 # if defined(AV_RN32) && !defined(AV_RB32)
61 # define AV_RB32(p) AV_RN32(p)
62 # elif !defined(AV_RN32) && defined(AV_RB32)
63 # define AV_RN32(p) AV_RB32(p)
64 # endif
66 # if defined(AV_WN32) && !defined(AV_WB32)
67 # define AV_WB32(p, v) AV_WN32(p, v)
68 # elif !defined(AV_WN32) && defined(AV_WB32)
69 # define AV_WN32(p, v) AV_WB32(p, v)
70 # endif
72 # if defined(AV_RN64) && !defined(AV_RB64)
73 # define AV_RB64(p) AV_RN64(p)
74 # elif !defined(AV_RN64) && defined(AV_RB64)
75 # define AV_RN64(p) AV_RB64(p)
76 # endif
78 # if defined(AV_WN64) && !defined(AV_WB64)
79 # define AV_WB64(p, v) AV_WN64(p, v)
80 # elif !defined(AV_WN64) && defined(AV_WB64)
81 # define AV_WN64(p, v) AV_WB64(p, v)
82 # endif
84 #else /* HAVE_BIGENDIAN */
86 # if defined(AV_RN16) && !defined(AV_RL16)
87 # define AV_RL16(p) AV_RN16(p)
88 # elif !defined(AV_RN16) && defined(AV_RL16)
89 # define AV_RN16(p) AV_RL16(p)
90 # endif
92 # if defined(AV_WN16) && !defined(AV_WL16)
93 # define AV_WL16(p, v) AV_WN16(p, v)
94 # elif !defined(AV_WN16) && defined(AV_WL16)
95 # define AV_WN16(p, v) AV_WL16(p, v)
96 # endif
98 # if defined(AV_RN24) && !defined(AV_RL24)
99 # define AV_RL24(p) AV_RN24(p)
100 # elif !defined(AV_RN24) && defined(AV_RL24)
101 # define AV_RN24(p) AV_RL24(p)
102 # endif
104 # if defined(AV_WN24) && !defined(AV_WL24)
105 # define AV_WL24(p, v) AV_WN24(p, v)
106 # elif !defined(AV_WN24) && defined(AV_WL24)
107 # define AV_WN24(p, v) AV_WL24(p, v)
108 # endif
110 # if defined(AV_RN32) && !defined(AV_RL32)
111 # define AV_RL32(p) AV_RN32(p)
112 # elif !defined(AV_RN32) && defined(AV_RL32)
113 # define AV_RN32(p) AV_RL32(p)
114 # endif
116 # if defined(AV_WN32) && !defined(AV_WL32)
117 # define AV_WL32(p, v) AV_WN32(p, v)
118 # elif !defined(AV_WN32) && defined(AV_WL32)
119 # define AV_WN32(p, v) AV_WL32(p, v)
120 # endif
122 # if defined(AV_RN64) && !defined(AV_RL64)
123 # define AV_RL64(p) AV_RN64(p)
124 # elif !defined(AV_RN64) && defined(AV_RL64)
125 # define AV_RN64(p) AV_RL64(p)
126 # endif
128 # if defined(AV_WN64) && !defined(AV_WL64)
129 # define AV_WL64(p, v) AV_WN64(p, v)
130 # elif !defined(AV_WN64) && defined(AV_WL64)
131 # define AV_WN64(p, v) AV_WL64(p, v)
132 # endif
134 #endif /* !HAVE_BIGENDIAN */
136 #define HAVE_ATTRIBUTE_PACKED 0
137 #define HAVE_FAST_UNALIGNED 0
139 * Define AV_[RW]N helper macros to simplify definitions not provided
140 * by per-arch headers.
143 #if HAVE_ATTRIBUTE_PACKED
145 union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
146 union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
147 union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
149 # define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
150 # define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
152 #elif defined(__DECC)
154 # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
155 # define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
157 #elif HAVE_FAST_UNALIGNED
159 # define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
160 # define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
162 #else
164 #ifndef AV_RB16
165 # define AV_RB16(x) \
166 ((((const uint8_t*)(x))[0] << 8) | \
167 ((const uint8_t*)(x))[1])
168 #endif
169 #ifndef AV_WB16
170 # define AV_WB16(p, d) do { \
171 ((uint8_t*)(p))[1] = (d); \
172 ((uint8_t*)(p))[0] = (d)>>8; \
173 } while(0)
174 #endif
176 #ifndef AV_RL16
177 # define AV_RL16(x) \
178 ((((const uint8_t*)(x))[1] << 8) | \
179 ((const uint8_t*)(x))[0])
180 #endif
181 #ifndef AV_WL16
182 # define AV_WL16(p, d) do { \
183 ((uint8_t*)(p))[0] = (d); \
184 ((uint8_t*)(p))[1] = (d)>>8; \
185 } while(0)
186 #endif
188 #ifndef AV_RB32
189 /* Coldfire and ARMv6 and above support unaligned long reads */
190 #if defined CPU_COLDFIRE || (defined CPU_ARM && ARM_ARCH >= 6)
191 #define AV_RB32(x) (htobe32(*(const uint32_t*)(x)))
192 #else
193 # define AV_RB32(x) \
194 ((((const uint8_t*)(x))[0] << 24) | \
195 (((const uint8_t*)(x))[1] << 16) | \
196 (((const uint8_t*)(x))[2] << 8) | \
197 ((const uint8_t*)(x))[3])
198 #endif
199 #endif
200 #ifndef AV_WB32
201 # define AV_WB32(p, d) do { \
202 ((uint8_t*)(p))[3] = (d); \
203 ((uint8_t*)(p))[2] = (d)>>8; \
204 ((uint8_t*)(p))[1] = (d)>>16; \
205 ((uint8_t*)(p))[0] = (d)>>24; \
206 } while(0)
207 #endif
209 #ifndef AV_RL32
210 # define AV_RL32(x) \
211 ((((const uint8_t*)(x))[3] << 24) | \
212 (((const uint8_t*)(x))[2] << 16) | \
213 (((const uint8_t*)(x))[1] << 8) | \
214 ((const uint8_t*)(x))[0])
215 #endif
216 #ifndef AV_WL32
217 # define AV_WL32(p, d) do { \
218 ((uint8_t*)(p))[0] = (d); \
219 ((uint8_t*)(p))[1] = (d)>>8; \
220 ((uint8_t*)(p))[2] = (d)>>16; \
221 ((uint8_t*)(p))[3] = (d)>>24; \
222 } while(0)
223 #endif
225 #ifndef AV_RB64
226 # define AV_RB64(x) \
227 (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
228 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
229 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
230 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
231 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
232 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
233 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
234 (uint64_t)((const uint8_t*)(x))[7])
235 #endif
236 #ifndef AV_WB64
237 # define AV_WB64(p, d) do { \
238 ((uint8_t*)(p))[7] = (d); \
239 ((uint8_t*)(p))[6] = (d)>>8; \
240 ((uint8_t*)(p))[5] = (d)>>16; \
241 ((uint8_t*)(p))[4] = (d)>>24; \
242 ((uint8_t*)(p))[3] = (d)>>32; \
243 ((uint8_t*)(p))[2] = (d)>>40; \
244 ((uint8_t*)(p))[1] = (d)>>48; \
245 ((uint8_t*)(p))[0] = (d)>>56; \
246 } while(0)
247 #endif
249 #ifndef AV_RL64
250 # define AV_RL64(x) \
251 (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
252 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
253 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
254 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
255 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
256 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
257 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
258 (uint64_t)((const uint8_t*)(x))[0])
259 #endif
260 #ifndef AV_WL64
261 # define AV_WL64(p, d) do { \
262 ((uint8_t*)(p))[0] = (d); \
263 ((uint8_t*)(p))[1] = (d)>>8; \
264 ((uint8_t*)(p))[2] = (d)>>16; \
265 ((uint8_t*)(p))[3] = (d)>>24; \
266 ((uint8_t*)(p))[4] = (d)>>32; \
267 ((uint8_t*)(p))[5] = (d)>>40; \
268 ((uint8_t*)(p))[6] = (d)>>48; \
269 ((uint8_t*)(p))[7] = (d)>>56; \
270 } while(0)
271 #endif
273 #if HAVE_BIGENDIAN
274 # define AV_RN(s, p) AV_RB##s(p)
275 # define AV_WN(s, p, v) AV_WB##s(p, v)
276 #else
277 # define AV_RN(s, p) AV_RL##s(p)
278 # define AV_WN(s, p, v) AV_WL##s(p, v)
279 #endif
281 #endif /* HAVE_FAST_UNALIGNED */
283 #ifndef AV_RN16
284 # define AV_RN16(p) AV_RN(16, p)
285 #endif
287 #ifndef AV_RN32
288 # define AV_RN32(p) AV_RN(32, p)
289 #endif
291 #ifndef AV_RN64
292 # define AV_RN64(p) AV_RN(64, p)
293 #endif
295 #ifndef AV_WN16
296 # define AV_WN16(p, v) AV_WN(16, p, v)
297 #endif
299 #ifndef AV_WN32
300 # define AV_WN32(p, v) AV_WN(32, p, v)
301 #endif
303 #ifndef AV_WN64
304 # define AV_WN64(p, v) AV_WN(64, p, v)
305 #endif
307 #if HAVE_BIGENDIAN
308 # define AV_RB(s, p) AV_RN##s(p)
309 # define AV_WB(s, p, v) AV_WN##s(p, v)
310 # define AV_RL(s, p) bswap_##s(AV_RN##s(p))
311 # define AV_WL(s, p, v) AV_WN##s(p, bswap_##s(v))
312 #else
313 # define AV_RB(s, p) bswap_##s(AV_RN##s(p))
314 # define AV_WB(s, p, v) AV_WN##s(p, bswap_##s(v))
315 # define AV_RL(s, p) AV_RN##s(p)
316 # define AV_WL(s, p, v) AV_WN##s(p, v)
317 #endif
319 #define AV_RB8(x) (((const uint8_t*)(x))[0])
320 #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
322 #define AV_RL8(x) AV_RB8(x)
323 #define AV_WL8(p, d) AV_WB8(p, d)
325 #ifndef AV_RB16
326 # define AV_RB16(p) AV_RB(16, p)
327 #endif
328 #ifndef AV_WB16
329 # define AV_WB16(p, v) AV_WB(16, p, v)
330 #endif
332 #ifndef AV_RL16
333 # define AV_RL16(p) AV_RL(16, p)
334 #endif
335 #ifndef AV_WL16
336 # define AV_WL16(p, v) AV_WL(16, p, v)
337 #endif
339 #ifndef AV_RB32
340 # define AV_RB32(p) AV_RB(32, p)
341 #endif
342 #ifndef AV_WB32
343 # define AV_WB32(p, v) AV_WB(32, p, v)
344 #endif
346 #ifndef AV_RL32
347 # define AV_RL32(p) AV_RL(32, p)
348 #endif
349 #ifndef AV_WL32
350 # define AV_WL32(p, v) AV_WL(32, p, v)
351 #endif
353 #ifndef AV_RB64
354 # define AV_RB64(p) AV_RB(64, p)
355 #endif
356 #ifndef AV_WB64
357 # define AV_WB64(p, v) AV_WB(64, p, v)
358 #endif
360 #ifndef AV_RL64
361 # define AV_RL64(p) AV_RL(64, p)
362 #endif
363 #ifndef AV_WL64
364 # define AV_WL64(p, v) AV_WL(64, p, v)
365 #endif
367 #ifndef AV_RB24
368 # define AV_RB24(x) \
369 ((((const uint8_t*)(x))[0] << 16) | \
370 (((const uint8_t*)(x))[1] << 8) | \
371 ((const uint8_t*)(x))[2])
372 #endif
373 #ifndef AV_WB24
374 # define AV_WB24(p, d) do { \
375 ((uint8_t*)(p))[2] = (d); \
376 ((uint8_t*)(p))[1] = (d)>>8; \
377 ((uint8_t*)(p))[0] = (d)>>16; \
378 } while(0)
379 #endif
381 #ifndef AV_RL24
382 # define AV_RL24(x) \
383 ((((const uint8_t*)(x))[2] << 16) | \
384 (((const uint8_t*)(x))[1] << 8) | \
385 ((const uint8_t*)(x))[0])
386 #endif
387 #ifndef AV_WL24
388 # define AV_WL24(p, d) do { \
389 ((uint8_t*)(p))[0] = (d); \
390 ((uint8_t*)(p))[1] = (d)>>8; \
391 ((uint8_t*)(p))[2] = (d)>>16; \
392 } while(0)
393 #endif
396 * The AV_[RW]NA macros access naturally aligned data
397 * in a type-safe way.
400 #define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s)
401 #define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
403 #ifndef AV_RN16A
404 # define AV_RN16A(p) AV_RNA(16, p)
405 #endif
407 #ifndef AV_RN32A
408 # define AV_RN32A(p) AV_RNA(32, p)
409 #endif
411 #ifndef AV_RN64A
412 # define AV_RN64A(p) AV_RNA(64, p)
413 #endif
415 #ifndef AV_WN16A
416 # define AV_WN16A(p, v) AV_WNA(16, p, v)
417 #endif
419 #ifndef AV_WN32A
420 # define AV_WN32A(p, v) AV_WNA(32, p, v)
421 #endif
423 #ifndef AV_WN64A
424 # define AV_WN64A(p, v) AV_WNA(64, p, v)
425 #endif
427 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
428 * naturally aligned. They may be implemented using MMX,
429 * so emms_c() must be called before using any float code
430 * afterwards.
433 #define AV_COPY(n, d, s) \
434 (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
436 #ifndef AV_COPY16
437 # define AV_COPY16(d, s) AV_COPY(16, d, s)
438 #endif
440 #ifndef AV_COPY32
441 # define AV_COPY32(d, s) AV_COPY(32, d, s)
442 #endif
444 #ifndef AV_COPY64
445 # define AV_COPY64(d, s) AV_COPY(64, d, s)
446 #endif
448 #ifndef AV_COPY128
449 # define AV_COPY128(d, s) \
450 do { \
451 AV_COPY64(d, s); \
452 AV_COPY64((char*)(d)+8, (char*)(s)+8); \
453 } while(0)
454 #endif
456 #define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
458 #ifndef AV_SWAP64
459 # define AV_SWAP64(a, b) AV_SWAP(64, a, b)
460 #endif
462 #define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
464 #ifndef AV_ZERO16
465 # define AV_ZERO16(d) AV_ZERO(16, d)
466 #endif
468 #ifndef AV_ZERO32
469 # define AV_ZERO32(d) AV_ZERO(32, d)
470 #endif
472 #ifndef AV_ZERO64
473 # define AV_ZERO64(d) AV_ZERO(64, d)
474 #endif
476 #ifndef AV_ZERO128
477 # define AV_ZERO128(d) \
478 do { \
479 AV_ZERO64(d); \
480 AV_ZERO64((char*)(d)+8); \
481 } while(0)
482 #endif
484 #endif /* AVUTIL_INTREADWRITE_H */