From 7f22298b791771be8eff356ef6203582ebda3c3d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 2 Mar 2025 22:31:43 +0100 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- liblss16_optimise.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'liblss16_optimise.c') diff --git a/liblss16_optimise.c b/liblss16_optimise.c index 7cb3b5d..83d0c21 100644 --- a/liblss16_optimise.c +++ b/liblss16_optimise.c @@ -6,7 +6,7 @@ void liblss16_optimise(struct liblss16_header *header, uint8_t *pixels) { - uint8_t remap[16], unmap[16], ncolours, colour, preferred; + uint8_t remap[16], unmap[16], ncolours, colour, preferred, dummy = 0; unsigned x, y, count, width; size_t p, n; int32_t zero[16], nonzero[16]; @@ -52,7 +52,7 @@ liblss16_optimise(struct liblss16_header *header, uint8_t *pixels) least = zero[0] - nonzero[0]; preferred = 0U; if (ncolours < 16U) - ncolours++; + dummy = ncolours++; for (x = 1U; x < (unsigned)ncolours; x++) { zero_penalty = zero[x] - nonzero[x]; if (zero_penalty < least) { @@ -70,6 +70,11 @@ liblss16_optimise(struct liblss16_header *header, uint8_t *pixels) t8 = remap[preferred]; remap[preferred] = remap[0]; remap[0] = t8; + if (preferred == dummy) { + header->colour_map[0].r = header->colour_map[1].r; + header->colour_map[0].g = header->colour_map[1].r; + header->colour_map[0].b = header->colour_map[1].r; + } } n = p; -- cgit v1.2.3-70-g09d2