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 | /* |
---|
16 | * This file contains replacements for commonly found object types and |
---|
17 | * function prototypes that are sometimes missing. |
---|
18 | */ |
---|
19 | |
---|
20 | /* C99 types */ |
---|
21 | #if defined HAVE_INTTYPES_H && !defined __KERNEL__ |
---|
22 | # include <inttypes.h> |
---|
23 | #else |
---|
24 | typedef signed char int8_t; |
---|
25 | typedef signed short int16_t; |
---|
26 | typedef signed long int int32_t; |
---|
27 | |
---|
28 | typedef unsigned char uint8_t; |
---|
29 | typedef unsigned short uint16_t; |
---|
30 | typedef unsigned long int uint32_t; |
---|
31 | |
---|
32 | typedef long int intptr_t; |
---|
33 | typedef unsigned long int uintptr_t; |
---|
34 | #endif |
---|
35 | |
---|
36 | /* hton16() and hton32() */ |
---|
37 | #if defined HAVE_HTONS |
---|
38 | # if defined __KERNEL__ |
---|
39 | /* Nothing to do */ |
---|
40 | # elif defined HAVE_ARPA_INET_H |
---|
41 | # include <arpa/inet.h> |
---|
42 | # elif defined HAVE_NETINET_IN_H |
---|
43 | # include <netinet/in.h> |
---|
44 | # endif |
---|
45 | # define hton16 htons |
---|
46 | # define hton32 htonl |
---|
47 | #else |
---|
48 | # if defined HAVE_ENDIAN_H |
---|
49 | # include <endian.h> |
---|
50 | # endif |
---|
51 | static inline uint16_t hton16(uint16_t x) |
---|
52 | { |
---|
53 | /* This is compile-time optimised with at least -O1 or -Os */ |
---|
54 | #if defined HAVE_ENDIAN_H |
---|
55 | if(__BYTE_ORDER == __BIG_ENDIAN) |
---|
56 | #else |
---|
57 | uint32_t const dummy = 0x12345678; |
---|
58 | if(*(uint8_t const *)&dummy == 0x12) |
---|
59 | #endif |
---|
60 | return x; |
---|
61 | else |
---|
62 | return (x >> 8) | (x << 8); |
---|
63 | } |
---|
64 | |
---|
65 | static inline uint32_t hton32(uint32_t x) |
---|
66 | { |
---|
67 | /* This is compile-time optimised with at least -O1 or -Os */ |
---|
68 | #if defined HAVE_ENDIAN_H |
---|
69 | if(__BYTE_ORDER == __BIG_ENDIAN) |
---|
70 | #else |
---|
71 | uint32_t const dummy = 0x12345678; |
---|
72 | if(*(uint8_t const *)&dummy == 0x12) |
---|
73 | #endif |
---|
74 | return x; |
---|
75 | else |
---|
76 | return (x >> 24) | ((x >> 8) & 0x0000ff00) |
---|
77 | | ((x << 8) & 0x00ff0000) | (x << 24); |
---|
78 | } |
---|
79 | #endif |
---|
80 | |
---|