contrib: add a test image to show how zoom modes work
[libam7xxx.git] / src / serialize.c
1 /* am7xxx - communication with AM7xxx based USB Pico Projectors and DPFs
2  *
3  * Copyright (C) 2012  Antonio Ospite <ospite@studenti.unina.it>
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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <string.h>
20
21 #ifdef __MINGW32__
22 #define le32toh(x) (x)
23 #define htole32(x) (x)
24 #else
25 #include <endian.h>
26 #endif
27
28 #include "serialize.h"
29
30 uint8_t get_8(uint8_t **bufferp)
31 {
32         uint8_t tmp;
33
34         tmp = *bufferp[0];
35         *bufferp += 1;
36
37         return tmp;
38 }
39
40 uint32_t get_le32(uint8_t **bufferp)
41 {
42         uint32_t tmp;
43
44         memcpy(&tmp, *bufferp, sizeof (tmp));
45         *bufferp += sizeof (tmp);
46
47         return le32toh(tmp);
48 }
49
50 uint8_t *put_8(uint8_t value, uint8_t **bufferp)
51 {
52         *bufferp[0] = value;
53         *bufferp += 1;
54
55         return *bufferp;
56 }
57
58 uint8_t *put_le32(uint32_t value, uint8_t **bufferp)
59 {
60         uint32_t tmp;
61
62         tmp = htole32(value);
63         memcpy(*bufferp, &tmp, sizeof (tmp));
64         *bufferp += sizeof (tmp);
65
66         return *bufferp;
67 }