fix(nema): fix indexed image error (#7744)
This commit is contained in:
@@ -498,6 +498,7 @@ class LVGLImage:
|
|||||||
self.stride = 0 # default no valid stride value
|
self.stride = 0 # default no valid stride value
|
||||||
self.premultiplied = False
|
self.premultiplied = False
|
||||||
self.rgb565_dither = False
|
self.rgb565_dither = False
|
||||||
|
self.nema_gfx = False
|
||||||
self.set_data(cf, w, h, data)
|
self.set_data(cf, w, h, data)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@@ -840,7 +841,8 @@ class LVGLImage:
|
|||||||
filename: str,
|
filename: str,
|
||||||
cf: ColorFormat = None,
|
cf: ColorFormat = None,
|
||||||
background: int = 0x00_00_00,
|
background: int = 0x00_00_00,
|
||||||
rgb565_dither=False):
|
rgb565_dither=False,
|
||||||
|
nema_gfx=False):
|
||||||
"""
|
"""
|
||||||
Create lvgl image from png file.
|
Create lvgl image from png file.
|
||||||
If cf is none, used I1/2/4/8 based on palette size
|
If cf is none, used I1/2/4/8 based on palette size
|
||||||
@@ -848,6 +850,7 @@ class LVGLImage:
|
|||||||
|
|
||||||
self.background = background
|
self.background = background
|
||||||
self.rgb565_dither = rgb565_dither
|
self.rgb565_dither = rgb565_dither
|
||||||
|
self.nema_gfx = nema_gfx
|
||||||
|
|
||||||
if cf is None: # guess cf from filename
|
if cf is None: # guess cf from filename
|
||||||
# split filename string and match with ColorFormat to check
|
# split filename string and match with ColorFormat to check
|
||||||
@@ -881,7 +884,7 @@ class LVGLImage:
|
|||||||
w, h, rows, metadata = reader.read()
|
w, h, rows, metadata = reader.read()
|
||||||
|
|
||||||
# to preserve original palette data only convert the image if needed. For this
|
# 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
|
# 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:
|
if not 'palette' in metadata or not auto_cf and len(metadata['palette']) != 2 ** cf.bpp:
|
||||||
# reread and convert file
|
# reread and convert file
|
||||||
reader = png.Reader(
|
reader = png.Reader(
|
||||||
@@ -918,6 +921,8 @@ class LVGLImage:
|
|||||||
# pack data if not in I8 format
|
# pack data if not in I8 format
|
||||||
if cf == ColorFormat.I8:
|
if cf == ColorFormat.I8:
|
||||||
for e in rows:
|
for e in rows:
|
||||||
|
if self.nema_gfx:
|
||||||
|
e = bytearray((x >> 4) | ((x & 0x0F) << 4) for x in e)
|
||||||
rawdata += e
|
rawdata += e
|
||||||
else:
|
else:
|
||||||
for e in png.pack_rows(rows, cf.bpp):
|
for e in png.pack_rows(rows, cf.bpp):
|
||||||
@@ -1262,7 +1267,8 @@ class PNGConverter:
|
|||||||
premultiply: bool = False,
|
premultiply: bool = False,
|
||||||
compress: CompressMethod = CompressMethod.NONE,
|
compress: CompressMethod = CompressMethod.NONE,
|
||||||
keep_folder=True,
|
keep_folder=True,
|
||||||
rgb565_dither=False) -> None:
|
rgb565_dither=False,
|
||||||
|
nema_gfx=False) -> None:
|
||||||
self.files = files
|
self.files = files
|
||||||
self.cf = cf
|
self.cf = cf
|
||||||
self.ofmt = ofmt
|
self.ofmt = ofmt
|
||||||
@@ -1274,6 +1280,7 @@ class PNGConverter:
|
|||||||
self.compress = compress
|
self.compress = compress
|
||||||
self.background = background
|
self.background = background
|
||||||
self.rgb565_dither = rgb565_dither
|
self.rgb565_dither = rgb565_dither
|
||||||
|
self.nema_gfx = nema_gfx
|
||||||
|
|
||||||
def _replace_ext(self, input, ext):
|
def _replace_ext(self, input, ext):
|
||||||
if self.keep_folder:
|
if self.keep_folder:
|
||||||
@@ -1292,7 +1299,7 @@ class PNGConverter:
|
|||||||
img = RAWImage().from_file(f, self.cf)
|
img = RAWImage().from_file(f, self.cf)
|
||||||
img.to_c_array(self._replace_ext(f, ".c"))
|
img.to_c_array(self._replace_ext(f, ".c"))
|
||||||
else:
|
else:
|
||||||
img = LVGLImage().from_png(f, self.cf, background=self.background, rgb565_dither=self.rgb565_dither)
|
img = LVGLImage().from_png(f, self.cf, background=self.background, rgb565_dither=self.rgb565_dither, nema_gfx=self.nema_gfx)
|
||||||
img.adjust_stride(align=self.align)
|
img.adjust_stride(align=self.align)
|
||||||
|
|
||||||
if self.premultiply:
|
if self.premultiply:
|
||||||
@@ -1350,6 +1357,8 @@ def main():
|
|||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
metavar='color',
|
metavar='color',
|
||||||
nargs='?')
|
nargs='?')
|
||||||
|
parser.add_argument('--nemagfx', action='store_true',
|
||||||
|
help="export color palette for I8 images in a format compatible with NEMA accelerator", default=False)
|
||||||
parser.add_argument('-o',
|
parser.add_argument('-o',
|
||||||
'--output',
|
'--output',
|
||||||
default="./output",
|
default="./output",
|
||||||
@@ -1390,7 +1399,8 @@ def main():
|
|||||||
premultiply=args.premultiply,
|
premultiply=args.premultiply,
|
||||||
compress=compress,
|
compress=compress,
|
||||||
keep_folder=False,
|
keep_folder=False,
|
||||||
rgb565_dither=args.rgb565dither)
|
rgb565_dither=args.rgb565dither,
|
||||||
|
nema_gfx=args.nemagfx)
|
||||||
output = converter.convert()
|
output = converter.convert()
|
||||||
for f, img in output:
|
for f, img in output:
|
||||||
logging.info(f"len: {img.data_len} for {path.basename(f)} ")
|
logging.info(f"len: {img.data_len} for {path.basename(f)} ")
|
||||||
|
|||||||
@@ -152,8 +152,15 @@ static void _draw_nema_gfx_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * d
|
|||||||
lv_area_get_height(&(layer->buf_area)), dst_nema_cf,
|
lv_area_get_height(&(layer->buf_area)), dst_nema_cf,
|
||||||
lv_area_get_width(&(layer->buf_area))*lv_color_format_get_size(dst_cf));
|
lv_area_get_width(&(layer->buf_area))*lv_color_format_get_size(dst_cf));
|
||||||
|
|
||||||
nema_bind_src_tex((uintptr_t)(src_buf), tex_w, tex_h, src_nema_cf, src_stride,
|
if(!LV_COLOR_FORMAT_IS_INDEXED(src_cf)) {
|
||||||
dsc->antialias ? NEMA_FILTER_BL : NEMA_FILTER_PS);
|
nema_bind_src_tex((uintptr_t)(src_buf), tex_w, tex_h, src_nema_cf, src_stride,
|
||||||
|
dsc->antialias ? NEMA_FILTER_BL : NEMA_FILTER_PS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nema_bind_lut_tex((uintptr_t)((uint8_t *)src_buf + LV_COLOR_INDEXED_PALETTE_SIZE(src_cf) * 4), tex_w, tex_h,
|
||||||
|
src_nema_cf, src_stride, NEMA_FILTER_PS, (uintptr_t)(src_buf), NEMA_BGRA8888);
|
||||||
|
blending_mode |= NEMA_BLOP_LUT;
|
||||||
|
}
|
||||||
|
|
||||||
/*Guard for previous NemaGFX Version*/
|
/*Guard for previous NemaGFX Version*/
|
||||||
#ifdef NEMA_BLOP_RECOLOR
|
#ifdef NEMA_BLOP_RECOLOR
|
||||||
|
|||||||
Reference in New Issue
Block a user