• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • 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 FFmpeg.
00005  *
00006  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 "config.h"
00031 #include "common.h"
00032 
00033 #if   ARCH_ARM
00034 #   include "arm/bswap.h"
00035 #elif ARCH_BFIN
00036 #   include "bfin/bswap.h"
00037 #elif ARCH_SH4
00038 #   include "sh4/bswap.h"
00039 #elif ARCH_X86
00040 #   include "x86/bswap.h"
00041 #endif
00042 
00043 #ifndef bswap_16
00044 static av_always_inline av_const uint16_t bswap_16(uint16_t x)
00045 {
00046     x= (x>>8) | (x<<8);
00047     return x;
00048 }
00049 #endif
00050 
00051 #ifndef bswap_32
00052 static av_always_inline av_const uint32_t bswap_32(uint32_t x)
00053 {
00054     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
00055     x= (x>>16) | (x<<16);
00056     return x;
00057 }
00058 #endif
00059 
00060 #ifndef bswap_64
00061 static inline uint64_t av_const bswap_64(uint64_t x)
00062 {
00063 #if 0
00064     x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
00065     x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
00066     return (x>>32) | (x<<32);
00067 #else
00068     union {
00069         uint64_t ll;
00070         uint32_t l[2];
00071     } w, r;
00072     w.ll = x;
00073     r.l[0] = bswap_32 (w.l[1]);
00074     r.l[1] = bswap_32 (w.l[0]);
00075     return r.ll;
00076 #endif
00077 }
00078 #endif
00079 
00080 // be2me ... big-endian to machine-endian
00081 // le2me ... little-endian to machine-endian
00082 
00083 #ifdef WORDS_BIGENDIAN
00084 #define be2me_16(x) (x)
00085 #define be2me_32(x) (x)
00086 #define be2me_64(x) (x)
00087 #define le2me_16(x) bswap_16(x)
00088 #define le2me_32(x) bswap_32(x)
00089 #define le2me_64(x) bswap_64(x)
00090 #else
00091 #define be2me_16(x) bswap_16(x)
00092 #define be2me_32(x) bswap_32(x)
00093 #define be2me_64(x) bswap_64(x)
00094 #define le2me_16(x) (x)
00095 #define le2me_32(x) (x)
00096 #define le2me_64(x) (x)
00097 #endif
00098 
00099 #endif /* AVUTIL_BSWAP_H */

Generated on Tue Nov 4 2014 12:59:24 for ffmpeg by  doxygen 1.7.1