No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

81 líneas
2.1 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains replacements for commonly found object types and
  16. * function prototypes that are sometimes missing.
  17. */
  18. /* C99 types */
  19. #if defined HAVE_INTTYPES_H && !defined __KERNEL__
  20. # include <inttypes.h>
  21. #else
  22. typedef signed char int8_t;
  23. typedef signed short int16_t;
  24. typedef signed long int int32_t;
  25. typedef unsigned char uint8_t;
  26. typedef unsigned short uint16_t;
  27. typedef unsigned long int uint32_t;
  28. typedef long int intptr_t;
  29. typedef unsigned long int uintptr_t;
  30. #endif
  31. /* hton16() and hton32() */
  32. #if defined HAVE_HTONS
  33. # if defined __KERNEL__
  34. /* Nothing to do */
  35. # elif defined HAVE_ARPA_INET_H
  36. # include <arpa/inet.h>
  37. # elif defined HAVE_NETINET_IN_H
  38. # include <netinet/in.h>
  39. # endif
  40. # define hton16 htons
  41. # define hton32 htonl
  42. #else
  43. # if defined HAVE_ENDIAN_H
  44. # include <endian.h>
  45. # endif
  46. static inline uint16_t hton16(uint16_t x)
  47. {
  48. /* This is compile-time optimised with at least -O1 or -Os */
  49. #if defined HAVE_ENDIAN_H
  50. if(__BYTE_ORDER == __BIG_ENDIAN)
  51. #else
  52. uint32_t const dummy = 0x12345678;
  53. if(*(uint8_t const *)&dummy == 0x12)
  54. #endif
  55. return x;
  56. else
  57. return (x >> 8) | (x << 8);
  58. }
  59. static inline uint32_t hton32(uint32_t x)
  60. {
  61. /* This is compile-time optimised with at least -O1 or -Os */
  62. #if defined HAVE_ENDIAN_H
  63. if(__BYTE_ORDER == __BIG_ENDIAN)
  64. #else
  65. uint32_t const dummy = 0x12345678;
  66. if(*(uint8_t const *)&dummy == 0x12)
  67. #endif
  68. return x;
  69. else
  70. return (x >> 24) | ((x >> 8) & 0x0000ff00)
  71. | ((x << 8) & 0x00ff0000) | (x << 24);
  72. }
  73. #endif