1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(scripts): fix image conversion was scrambling palette data (#7367)

Co-authored-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
blkhawk 2024-12-02 03:56:24 +01:00 committed by GitHub
parent 8baabf358b
commit 63ac1cec9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -872,9 +872,19 @@ class LVGLImage:
def _png_to_indexed(self, cf: ColorFormat, filename: str):
# convert to palette mode
auto_cf = cf is None
# read the image data to get the metadata
reader = png.Reader(filename=filename)
w, h, rows, metadata = reader.read()
# to preserve original palette data only convert the image if needed. For this
# check if image has a palette and the requested palette size equals the existing one
if not 'palette' in metadata or not auto_cf and len(metadata['palette']) != 2 ** cf.bpp:
# reread and convert file
reader = png.Reader(
bytes=PngQuant(256 if auto_cf else cf.ncolors).convert(filename))
w, h, rows, _ = reader.read()
palette = reader.palette(alpha="force") # always return alpha
palette_len = len(palette)