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:
parent
8baabf358b
commit
63ac1cec9b
@ -872,9 +872,19 @@ class LVGLImage:
|
||||
def _png_to_indexed(self, cf: ColorFormat, filename: str):
|
||||
# convert to palette mode
|
||||
auto_cf = cf is None
|
||||
reader = png.Reader(
|
||||
bytes=PngQuant(256 if auto_cf else cf.ncolors).convert(filename))
|
||||
w, h, rows, _ = reader.read()
|
||||
|
||||
# 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user