From 18ebcc74571b5ac983c061573a77e52f53cf40ab Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Mon, 28 Aug 2023 14:29:39 +0200 Subject: [PATCH] Make loading palette colors in TIM images endian agnostic; see #56 --- src/wipeout/image.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wipeout/image.c b/src/wipeout/image.c index 2a8bd5e..99be1f5 100755 --- a/src/wipeout/image.c +++ b/src/wipeout/image.c @@ -59,8 +59,11 @@ image_t *image_load_from_bytes(uint8_t *bytes, bool transparent) { uint16_t palette_y = get_i16_le(bytes, &p); uint16_t palette_colors = get_i16_le(bytes, &p); uint16_t palettes = get_i16_le(bytes, &p); + palette = (uint16_t *)(bytes + p); - p += palette_colors * 2; + for (int i = 0; i < palette_colors; i++) { + palette[i] = get_u16_le(bytes, &p); + } } uint32_t data_size = get_i32_le(bytes, &p); @@ -87,7 +90,7 @@ image_t *image_load_from_bytes(uint8_t *bytes, bool transparent) { if (type == TIM_TYPE_TRUE_COLOR_16_BPP) { for (int i = 0; i < entries; i++) { - image->pixels[pixel_pos++] = tim_16bit_to_rgba(get_i16_le(bytes, &p), transparent); + image->pixels[pixel_pos++] = tim_16bit_to_rgba(get_u16_le(bytes, &p), transparent); } } else if (type == TIM_TYPE_PALETTED_8_BPP) {