GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_get_set_bytes.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2025 Cyril Hrubis <metan@ucw.cz>
4 */
5
10#ifndef CORE_GP_GET_SET_BYTES_H
11#define CORE_GP_GET_SET_BYTES_H
12
13#include <core/gp_byte_order.h>
14
20#define GP_SWAP_BYTES2(v) ( \
21 (((v) & 0xff00)>>8) | \
22 (((v) & 0x00ff)<<8) \
23)
24
30#define GP_SWAP_BYTES3(v) ( \
31 ((v) & 0x00ff00) | \
32 (((v) & 0x0000ff)<<16) | \
33 (((v) & 0xff0000)>>16) \
34)
35
41#define GP_SWAP_BYTES4(v) ( \
42 (((v) & 0xff000000)>>24) | \
43 (((v) & 0x00ff0000)>>8) | \
44 (((v) & 0x0000ff00)<<8) | \
45 (((v) & 0x000000ff)<<24) \
46)
47
55#define GP_GET_BYTES1(src) (*((uint8_t *)(src)))
56
65#define GP_SET_BYTES1(dst, byte) *((uint8_t *)(dst)) = (byte)
66
74#if __BYTE_ORDER == __LITTLE_ENDIAN
75# define GP_GET_BYTES2_LE(src) (*((uint16_t *)(src)))
76#else
77# define GP_GET_BYTES2_LE(src) GP_SWAP_BYTES2(*((uint16_t *)(src)))
78#endif
79
87#if __BYTE_ORDER == __LITTLE_ENDIAN
88# define GP_SET_BYTES2_LE(dst, bytes) *((uint16_t *)(dst)) = (bytes)
89#else
90# define GP_SET_BYTES2_LE(dst, bytes) *((uint16_t *)(dst)) = GP_SWAP_BYTES2(bytes)
91#endif
92
100#if __BYTE_ORDER == __BIG_ENDIAN
101# define GP_GET_BYTES2_BE(src) (*((uint16_t *)(src)))
102#else
103# define GP_GET_BYTES2_BE(src) GP_SWAP_BYTES2(*((uint16_t *)(src)))
104#endif
105
113#if __BYTE_ORDER == __BIG_ENDIAN
114# define GP_SET_BYTES2_BE(dst, bytes) *((uint16_t *)(dst)) = (bytes)
115#else
116# define GP_SET_BYTES2_BE(dst, bytes) *((uint16_t *)(dst)) = GP_SWAP_BYTES2(bytes)
117#endif
118
126#if __BYTE_ORDER == __BIG_ENDIAN
127# define GP_GET_BYTES4_BE(src) *((uint32_t *)src)
128#else
129# define GP_GET_BYTES4_BE(src) GP_SWAP_BYTES4(*((uint16_t *)(src)))
130#endif
131
139#if __BYTE_ORDER == __BIG_ENDIAN
140# define GP_SET_BYTES4_BE(dst, bytes) *((uint32_t *)(dst)) = (bytes)
141#else
142# define GP_SET_BYTES4_BE(dst, bytes) *((uint32_t *)(dst)) = GP_SWAP_BYTES4(bytes)
143#endif
144
152#if __BYTE_ORDER == __LITTLE_ENDIAN
153# define GP_GET_BYTES4_LE(src) *((uint32_t *)src)
154#else
155# define GP_GET_BYTES4_LE(src) GP_SWAP_BYTES4(*((uint16_t *)(src)))
156#endif
157
165#if __BYTE_ORDER == __LITTLE_ENDIAN
166# define GP_SET_BYTES4_LE(dst, bytes) *((uint32_t *)(dst)) = (bytes)
167#else
168# define GP_SET_BYTES4_LE(dst, bytes) *((uint32_t *)(dst)) = GP_SWAP_BYTES4(bytes)
169#endif
170
171#endif /* CORE_GP_GET_SET_BYTES_H */
A byte order (endians) defintions.