prepare for the DOS port
[retroray] / libs / imago / src / byteord.h
1 /*
2 libimago - a multi-format image file input/output library.
3 Copyright (C) 2010-2017 John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef IMAGO_BYTEORD_H_
19 #define IMAGO_BYTEORD_H_
20
21 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199900) || \
22         (defined(_MSC_VER) && _MSC_VER >= 1600) || \
23         (defined(__WATCOMC__) && __WATCOMC__ >= 1200)
24 #include <stdint.h>
25 #else
26 #include <sys/types.h>
27 #endif
28
29 #if defined(__DOS__) && defined(__WATCOMC__) && __WATCOMC__ < 1200
30 typedef signed char int8_t;
31 typedef unsigned char uint8_t;
32 typedef short int16_t;
33 typedef unsigned short uint16_t;
34 typedef long int32_t;
35 typedef unsigned long uint32_t;
36 typedef long intptr_t;
37 typedef unsigned long uintptr_t;
38 #endif
39
40 #if defined(_MSC_VER) && (_MSC_VER < 1600)
41 typedef signed __int8 int8_t;
42 typedef unsigned __int8 uint8_t;
43 typedef __int16 int16_t;
44 typedef unsigned __int16 uint16_t;
45 typedef __int32 int32_t;
46 typedef unsigned __int32 uint32_t;
47 typedef long intptr_t;
48 typedef unsigned long uintptr_t;
49 #endif
50
51 #include "imago2.h"
52
53 #if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
54     (defined(__alpha__) || defined(__alpha)) || \
55      defined(__arm__) || \
56     (defined(__mips__) && defined(__MIPSEL__)) || \
57      defined(__SYMBIAN32__) || \
58      defined(__x86_64__) || \
59      defined(__LITTLE_ENDIAN__)
60 /* little endian */
61 #define IMAGO_LITTLE_ENDIAN
62
63 #define img_read_int16_le(f)            img_read_int16(f)
64 #define img_write_int16_le(f, v)        img_write_int16(f, v)
65 #define img_read_int16_be(f)            img_read_int16_inv(f)
66 #define img_write_int16_be(f, v)        img_write_int16_inv(f, v)
67 #define img_read_uint16_le(f)           img_read_uint16(f)
68 #define img_write_uint16_le(f, v)       img_write_uint16(f, v)
69 #define img_read_uint16_be(f)           img_read_uint16_inv(f)
70 #define img_write_uint16_be(f, v)       img_write_uint16_inv(f, v)
71
72 #define img_read_uint32_be(f)           img_read_uint32_inv(f)
73 #else
74 /* big endian */
75 #define IMAGO_BIG_ENDIAN
76
77 #define img_read_int16_le(f)            img_read_int16_inv(f)
78 #define img_write_int16_le(f, v)        img_write_int16_inv(f, v)
79 #define img_read_int16_be(f)            img_read_int16(f)
80 #define img_write_int16_be(f, v)        img_write_int16(f, v)
81 #define img_read_uint16_le(f)           img_read_uint16_inv(f)
82 #define img_write_uint16_le(f, v)       img_write_uint16_inv(f, v)
83 #define img_read_uint16_be(f)           img_read_uint16(f)
84 #define img_write_uint16_be(f, v)       img_write_uint16(f, v)
85
86 #define img_read_uint32_be(f)           img_read_uint32(f)
87 #endif  /* endian check */
88
89 int16_t img_read_int16(struct img_io *io);
90 int16_t img_read_int16_inv(struct img_io *io);
91 uint16_t img_read_uint16(struct img_io *io);
92 uint16_t img_read_uint16_inv(struct img_io *io);
93
94 void img_write_int16(struct img_io *io, int16_t val);
95 void img_write_int16_inv(struct img_io *io, int16_t val);
96 void img_write_uint16(struct img_io *io, uint16_t val);
97 void img_write_uint16_inv(struct img_io *io, uint16_t val);
98
99 uint32_t img_read_uint32(struct img_io *io);
100 uint32_t img_read_uint32_inv(struct img_io *io);
101
102
103 #endif  /* IMAGO_BYTEORD_H_ */