Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00026 #ifndef AVUTIL_BSWAP_H 00027 #define AVUTIL_BSWAP_H 00028 00029 #include <stdint.h> 00030 #include "libavutil/avconfig.h" 00031 #include "attributes.h" 00032 00033 #ifdef HAVE_AV_CONFIG_H 00034 00035 #include "config.h" 00036 00037 #if ARCH_ARM 00038 # include "arm/bswap.h" 00039 #elif ARCH_AVR32 00040 # include "avr32/bswap.h" 00041 #elif ARCH_BFIN 00042 # include "bfin/bswap.h" 00043 #elif ARCH_SH4 00044 # include "sh4/bswap.h" 00045 #elif ARCH_X86 00046 # include "x86/bswap.h" 00047 #endif 00048 00049 #endif /* HAVE_AV_CONFIG_H */ 00050 00051 #define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff)) 00052 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16)) 00053 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32)) 00054 00055 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x) 00056 00057 #ifndef av_bswap16 00058 static av_always_inline av_const uint16_t av_bswap16(uint16_t x) 00059 { 00060 x= (x>>8) | (x<<8); 00061 return x; 00062 } 00063 #endif 00064 00065 #ifndef av_bswap32 00066 static av_always_inline av_const uint32_t av_bswap32(uint32_t x) 00067 { 00068 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); 00069 x= (x>>16) | (x<<16); 00070 return x; 00071 } 00072 #endif 00073 00074 #ifndef av_bswap64 00075 static inline uint64_t av_const av_bswap64(uint64_t x) 00076 { 00077 union { 00078 uint64_t ll; 00079 uint32_t l[2]; 00080 } w, r; 00081 w.ll = x; 00082 r.l[0] = av_bswap32 (w.l[1]); 00083 r.l[1] = av_bswap32 (w.l[0]); 00084 return r.ll; 00085 } 00086 #endif 00087 00088 // be2ne ... big-endian to native-endian 00089 // le2ne ... little-endian to native-endian 00090 00091 #if AV_HAVE_BIGENDIAN 00092 #define av_be2ne16(x) (x) 00093 #define av_be2ne32(x) (x) 00094 #define av_be2ne64(x) (x) 00095 #define av_le2ne16(x) av_bswap16(x) 00096 #define av_le2ne32(x) av_bswap32(x) 00097 #define av_le2ne64(x) av_bswap64(x) 00098 #define AV_BE2NEC(s, x) (x) 00099 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x) 00100 #else 00101 #define av_be2ne16(x) av_bswap16(x) 00102 #define av_be2ne32(x) av_bswap32(x) 00103 #define av_be2ne64(x) av_bswap64(x) 00104 #define av_le2ne16(x) (x) 00105 #define av_le2ne32(x) (x) 00106 #define av_le2ne64(x) (x) 00107 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x) 00108 #define AV_LE2NEC(s, x) (x) 00109 #endif 00110 00111 #define AV_BE2NE16C(x) AV_BE2NEC(16, x) 00112 #define AV_BE2NE32C(x) AV_BE2NEC(32, x) 00113 #define AV_BE2NE64C(x) AV_BE2NEC(64, x) 00114 #define AV_LE2NE16C(x) AV_LE2NEC(16, x) 00115 #define AV_LE2NE32C(x) AV_LE2NEC(32, x) 00116 #define AV_LE2NE64C(x) AV_LE2NEC(64, x) 00117 00118 #endif /* AVUTIL_BSWAP_H */