• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavutil/bswap.h

Go to the documentation of this file.
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     return AV_BSWAP32C(x);
00069 }
00070 #endif
00071 
00072 #ifndef av_bswap64
00073 static inline uint64_t av_const av_bswap64(uint64_t x)
00074 {
00075     return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
00076 }
00077 #endif
00078 
00079 // be2ne ... big-endian to native-endian
00080 // le2ne ... little-endian to native-endian
00081 
00082 #if AV_HAVE_BIGENDIAN
00083 #define av_be2ne16(x) (x)
00084 #define av_be2ne32(x) (x)
00085 #define av_be2ne64(x) (x)
00086 #define av_le2ne16(x) av_bswap16(x)
00087 #define av_le2ne32(x) av_bswap32(x)
00088 #define av_le2ne64(x) av_bswap64(x)
00089 #define AV_BE2NEC(s, x) (x)
00090 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
00091 #else
00092 #define av_be2ne16(x) av_bswap16(x)
00093 #define av_be2ne32(x) av_bswap32(x)
00094 #define av_be2ne64(x) av_bswap64(x)
00095 #define av_le2ne16(x) (x)
00096 #define av_le2ne32(x) (x)
00097 #define av_le2ne64(x) (x)
00098 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
00099 #define AV_LE2NEC(s, x) (x)
00100 #endif
00101 
00102 #define AV_BE2NE16C(x) AV_BE2NEC(16, x)
00103 #define AV_BE2NE32C(x) AV_BE2NEC(32, x)
00104 #define AV_BE2NE64C(x) AV_BE2NEC(64, x)
00105 #define AV_LE2NE16C(x) AV_LE2NEC(16, x)
00106 #define AV_LE2NE32C(x) AV_LE2NEC(32, x)
00107 #define AV_LE2NE64C(x) AV_LE2NEC(64, x)
00108 
00109 #endif /* AVUTIL_BSWAP_H */
Generated on Thu Jan 24 2013 17:08:56 for Libav by doxygen 1.7.1