From 6dae13007eba3206442b67d1167a46a2c2c85d6f Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 23 Dec 2021 21:14:12 +0100 Subject: [PATCH] fxconv: "fix" palette remap with non-continous "P" image Just take the holes and save less space --- fxconv/fxconv.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fxconv/fxconv.py b/fxconv/fxconv.py index bd07e25..ac433be 100644 --- a/fxconv/fxconv.py +++ b/fxconv/fxconv.py @@ -1005,10 +1005,16 @@ def r5g6b5(img, color_count=0, trim_palette=False, palette_base=0, alpha=None): # Format for the first palette is a list of N triplets where N is the # number of used opaque colors; obviously N <= palette_max_size - palette1 = img.getpalette()[:3*len(img.getcolors())] + # Note: sometimes colors are not numbered 0..N-1, so we take the max + # value rather than len(img.getcolors()); we don't try to remap indices + pixels = img.load() + N = 1 + max(pixels[x,y] + for y in range(img.height) + for x in range(img.width)) + palette1 = img.getpalette()[:3*N] palette1 = list(zip(palette1[::3], palette1[1::3], palette1[2::3])) - - pixels = img.load() + else: + pixels = img.load() #--- # Alpha encoding