2 libimago - a multi-format image file input/output library.
3 Copyright (C) 2010-2019 John Tsiombikas <nuclear@member.fsf.org>
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.
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.
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/>.
20 int16_t img_read_int16(struct img_io *io)
23 io->read(&v, 2, io->uptr);
27 int16_t img_read_int16_inv(struct img_io *io)
30 io->read(&v, 2, io->uptr);
31 return ((v >> 8) & 0xff) | (v << 8);
34 uint16_t img_read_uint16(struct img_io *io)
37 io->read(&v, 2, io->uptr);
41 uint16_t img_read_uint16_inv(struct img_io *io)
44 io->read(&v, 2, io->uptr);
45 return (v >> 8) | (v << 8);
49 void img_write_int16(struct img_io *io, int16_t val)
51 io->write(&val, 2, io->uptr);
54 void img_write_int16_inv(struct img_io *io, int16_t val)
56 val = ((val >> 8) & 0xff) | (val << 8);
57 io->write(&val, 2, io->uptr);
60 void img_write_uint16(struct img_io *io, uint16_t val)
62 io->write(&val, 2, io->uptr);
65 void img_write_uint16_inv(struct img_io *io, uint16_t val)
67 val = (val >> 8) | (val << 8);
68 io->write(&val, 2, io->uptr);
71 uint32_t img_read_uint32(struct img_io *io)
74 io->read(&v, 4, io->uptr);
78 uint32_t img_read_uint32_inv(struct img_io *io)
81 io->read(&v, 4, io->uptr);
82 return (v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24);