diff options
-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; |