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.premultiplied = False
|
||||
self.rgb565_dither = False
|
||||
self.nema_gfx = False
|
||||
self.set_data(cf, w, h, data)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
@@ -840,7 +841,8 @@ class LVGLImage:
|
||||
filename: str,
|
||||
cf: ColorFormat = None,
|
||||
background: int = 0x00_00_00,
|
||||
rgb565_dither=False):
|
||||
rgb565_dither=False,
|
||||
nema_gfx=False):
|
||||
"""
|
||||
Create lvgl image from png file.
|
||||
If cf is none, used I1/2/4/8 based on palette size
|
||||
@@ -848,6 +850,7 @@ class LVGLImage:
|
||||
|
||||
self.background = background
|
||||
self.rgb565_dither = rgb565_dither
|
||||
self.nema_gfx = nema_gfx
|
||||
|
||||
if cf is None: # guess cf from filename
|
||||
# split filename string and match with ColorFormat to check
|
||||
@@ -918,6 +921,8 @@ class LVGLImage:
|
||||
# pack data if not in I8 format
|
||||
if cf == ColorFormat.I8:
|
||||
for e in rows:
|
||||
if self.nema_gfx:
|
||||
e = bytearray((x >> 4) | ((x & 0x0F) << 4) for x in e)
|
||||
rawdata += e
|
||||
else:
|
||||
for e in png.pack_rows(rows, cf.bpp):
|
||||
@@ -1262,7 +1267,8 @@ class PNGConverter:
|
||||
premultiply: bool = False,
|
||||
compress: CompressMethod = CompressMethod.NONE,
|
||||
keep_folder=True,
|
||||
rgb565_dither=False) -> None:
|
||||
rgb565_dither=False,
|
||||
nema_gfx=False) -> None:
|
||||
self.files = files
|
||||
self.cf = cf
|
||||
self.ofmt = ofmt
|
||||
@@ -1274,6 +1280,7 @@ class PNGConverter:
|
||||
self.compress = compress
|
||||
self.background = background
|
||||
self.rgb565_dither = rgb565_dither
|
||||
self.nema_gfx = nema_gfx
|
||||
|
||||
def _replace_ext(self, input, ext):
|
||||
if self.keep_folder:
|
||||
@@ -1292,7 +1299,7 @@ class PNGConverter:
|
||||
img = RAWImage().from_file(f, self.cf)
|
||||
img.to_c_array(self._replace_ext(f, ".c"))
|
||||
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)
|
||||
|
||||
if self.premultiply:
|
||||
@@ -1350,6 +1357,8 @@ def main():
|
||||
type=lambda x: int(x, 0),
|
||||
metavar='color',
|
||||
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',
|
||||
'--output',
|
||||
default="./output",
|
||||
@@ -1390,7 +1399,8 @@ def main():
|
||||
premultiply=args.premultiply,
|
||||
compress=compress,
|
||||
keep_folder=False,
|
||||
rgb565_dither=args.rgb565dither)
|
||||
rgb565_dither=args.rgb565dither,
|
||||
nema_gfx=args.nemagfx)
|
||||
output = converter.convert()
|
||||
for f, img in output:
|
||||
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_width(&(layer->buf_area))*lv_color_format_get_size(dst_cf));
|
||||
|
||||
if(!LV_COLOR_FORMAT_IS_INDEXED(src_cf)) {
|
||||
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*/
|
||||
#ifdef NEMA_BLOP_RECOLOR
|
||||
|
||||
Reference in New Issue
Block a user