Skip to content

Commit 213a8f6

Browse files
committed
implementing endianness check on mlx_color struct
1 parent 42e62ac commit 213a8f6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

includes/mlx.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <contact@kbz8.me> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
9-
/* Updated: 2024/12/16 23:11:59 by maldavid ### ########.fr */
9+
/* Updated: 2024/12/17 00:15:34 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -48,10 +48,17 @@ typedef union mlx_color
4848
{
4949
struct
5050
{
51-
uint8_t a;
52-
uint8_t b;
53-
uint8_t g;
54-
uint8_t r;
51+
#if MLX_ENDIAN_ORDER == MLX_LITTLE_ENDIAN
52+
uint8_t a;
53+
uint8_t b;
54+
uint8_t g;
55+
uint8_t r;
56+
#else
57+
uint8_t r;
58+
uint8_t g;
59+
uint8_t b;
60+
uint8_t a;
61+
#endif
5562
};
5663
uint32_t rgba;
5764
} mlx_color;

includes/mlx_profile.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
9-
/* Updated: 2024/12/16 16:16:07 by maldavid ### ########.fr */
9+
/* Updated: 2024/12/17 00:14:47 by maldavid ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -142,6 +142,10 @@
142142
#endif
143143
#endif
144144

145+
#define MLX_LITTLE_ENDIAN 0x41424344UL
146+
#define MLX_BIG_ENDIAN 0x44434241UL
147+
#define MLX_ENDIAN_ORDER ('ABCD')
148+
145149
#include <stdint.h>
146150

147151
#define MLX_MAKE_VERSION(major, minor, patch) ((((uint32_t)(major)) << 22U) | (((uint32_t)(minor)) << 12U) | ((uint32_t)(patch)))

0 commit comments

Comments
 (0)