diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-02 22:31:43 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-02 22:31:43 +0100 |
commit | 7f22298b791771be8eff356ef6203582ebda3c3d (patch) | |
tree | 5df08e37192af45dddcf1b6d6d3f51893663a933 | |
parent | liblss16_optimise: check if it is preferrable to assign an unused colour index 0 (diff) | |
download | liblss16-7f22298b791771be8eff356ef6203582ebda3c3d.tar.gz liblss16-7f22298b791771be8eff356ef6203582ebda3c3d.tar.bz2 liblss16-7f22298b791771be8eff356ef6203582ebda3c3d.tar.xz |
m
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r-- | liblss16_optimise.c | 9 |
1 files changed, 7 insertions, 2 deletions
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; |