sfendian.h
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:2k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. /*
  2. ** Copyright (C) 1999-2000 Erik de Castro Lopo <erikd@zip.com.au>
  3. **  
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU Lesser General Public License as published by
  6. ** the Free Software Foundation; either version 2.1 of the License, or
  7. ** (at your option) any later version.
  8. ** 
  9. ** This program 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
  12. ** GNU Lesser General Public License for more details.
  13. ** 
  14. ** You should have received a copy of the GNU Lesser General Public License
  15. ** along with this program; if not, write to the Free Software 
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "config.h"
  19. #if HAVE_ENDIAN_H
  20. /* This is the best way to do it. Unfortunately Sparc Solaris (and
  21. ** possibly others) don't have <endian.h>
  22. */
  23. #include <endian.h>
  24. #if (__BYTE_ORDER == __LITTLE_ENDIAN)
  25. #define CPU_IS_LITTLE_ENDIAN 1
  26. #define CPU_IS_BIG_ENDIAN 0
  27. #elif (__BYTE_ORDER == __BIG_ENDIAN)
  28. #define CPU_IS_LITTLE_ENDIAN 0
  29. #define CPU_IS_BIG_ENDIAN 1
  30. #else
  31. #error "A bit confused about endian-ness! Have <endian.h> but not __BYTEORDER."
  32. #endif
  33. #else
  34. /* If we don't have <endian.h> use the guess based on target processor
  35. ** from the autoconf process.
  36. */
  37. #if GUESS_LITTLE_ENDIAN
  38. #define CPU_IS_LITTLE_ENDIAN 1
  39. #define CPU_IS_BIG_ENDIAN 0
  40. #elif GUESS_BIG_ENDIAN
  41. #define CPU_IS_LITTLE_ENDIAN 0
  42. #define CPU_IS_BIG_ENDIAN 1
  43. #else
  44. #error "Endian guess seems incorrect."
  45. #endif
  46. #endif
  47. #define ENDSWAP_SHORT(x) ((((x)>>8)&0xFF)|(((x)&0xFF)<<8))
  48. #define ENDSWAP_INT(x) ((((x)>>24)&0xFF)|(((x)>>8)&0xFF00)|(((x)&0xFF00)<<8)|(((x)&0xFF)<<24))
  49. #if (CPU_IS_LITTLE_ENDIAN == 1)
  50. #define H2LE_SHORT(x) (x)
  51. #define H2LE_INT(x) (x)
  52. #define LE2H_SHORT(x) (x)
  53. #define LE2H_INT(x) (x)
  54. #define BE2H_INT(x) ENDSWAP_INT(x)
  55. #define BE2H_SHORT(x) ENDSWAP_SHORT(x)
  56. #define H2BE_INT(x) ENDSWAP_INT(x)
  57. #define H2BE_SHORT(x) ENDSWAP_SHORT(x)
  58. #elif (CPU_IS_BIG_ENDIAN == 1)
  59. #define H2LE_SHORT(x) ENDSWAP_SHORT(x)
  60. #define H2LE_INT(x) ENDSWAP_INT(x)
  61. #define LE2H_SHORT(x) ENDSWAP_SHORT(x)
  62. #define LE2H_INT(x) ENDSWAP_INT(x)
  63. #define BE2H_INT(x) (x)
  64. #define BE2H_SHORT(x) (x)
  65. #define H2BE_INT(x) (x)
  66. #define H2BE_SHORT(x) (x)
  67. #else
  68. #error "Cannot determine endian-ness of processor."
  69. #endif