1
0

mpeg4ip_byteswap.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Copyright (C) 2000, 2001 Billy Biggs <[email protected]>,
  3. * Han Hjort <[email protected]>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef BSWAP_H_INCLUDED
  20. #define BSWAP_H_INCLUDED
  21. #ifdef _WIN32
  22. #include <config.h>
  23. #endif
  24. #if defined(WORDS_BIGENDIAN)
  25. /* All bigendian systems are fine, just ignore the swaps. */
  26. #define B2N_16(x) (x)
  27. #define B2N_32(x) (x)
  28. #define B2N_64(x) (x)
  29. #else
  30. #if defined(__linux__)
  31. #include <byteswap.h>
  32. #define B2N_16(x) x = bswap_16(x)
  33. #define B2N_32(x) x = bswap_32(x)
  34. #define B2N_64(x) x = bswap_64(x)
  35. #elif defined(__NetBSD__)
  36. #include <sys/endian.h>
  37. #define B2N_16(x) BE16TOH(x)
  38. #define B2N_32(x) BE32TOH(x)
  39. #define B2N_64(x) BE64TOH(x)
  40. #elif defined(__OpenBSD__)
  41. #include <sys/endian.h>
  42. #define B2N_16(x) x = swap16(x)
  43. #define B2N_32(x) x = swap32(x)
  44. #define B2N_64(x) x = swap64(x)
  45. /* This is a slow but portable implementation, it has multiple evaluation
  46. * problems so beware.
  47. * FreeBSD and Solaris don't have <byteswap.h> or any other such
  48. * functionality!
  49. */
  50. #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(_WIN32)
  51. #define B2N_16(x) \
  52. x = ((((x) & 0xff00) >> 8) | \
  53. (((x) & 0x00ff) << 8))
  54. #define B2N_32(x) \
  55. x = ((((x) & 0xff000000) >> 24) | \
  56. (((x) & 0x00ff0000) >> 8) | \
  57. (((x) & 0x0000ff00) << 8) | \
  58. (((x) & 0x000000ff) << 24))
  59. #define B2N_64(x) \
  60. x = ((((x) & 0xff00000000000000) >> 56) | \
  61. (((x) & 0x00ff000000000000) >> 40) | \
  62. (((x) & 0x0000ff0000000000) >> 24) | \
  63. (((x) & 0x000000ff00000000) >> 8) | \
  64. (((x) & 0x00000000ff000000) << 8) | \
  65. (((x) & 0x0000000000ff0000) << 24) | \
  66. (((x) & 0x000000000000ff00) << 40) | \
  67. (((x) & 0x00000000000000ff) << 56))
  68. #else
  69. /* If there isn't a header provided with your system with this functionality
  70. * add the relevant || define( ) to the portable implementation above.
  71. */
  72. #error "You need to add endian swap macros for you're system"
  73. #endif
  74. #endif /* WORDS_BIGENDIAN */
  75. #endif /* BSWAP_H_INCLUDED */