def open_png(decoder, dsc): img_dsc = lv.img_dsc_t.__cast__(dsc.src) png_data = img_dsc.data png_size = img_dsc.data_size png_decoded = png.C_Pointer() png_width = png.C_Pointer() png_height = png.C_Pointer() error = png.decode32(png_decoded, png_width, png_height, png_data, png_size) if error: return None # LV_IMG_DECODER_OPEN_FAIL img_size = png_width.int_val * png_height.int_val * lv.color_t.__SIZE__ img_data = png_decoded.ptr_val # Convert png RGBA-big-endian format to lvgl ARGB-little-endian # Eventually - this means swapping red and blue. # More info on https://forum.lvgl.io/t/png-decoding-why-red-and-blue-are-swapped/72 img_view = img_data.__dereference__(img_size) for i in range(0, img_size, lv.color_t.__SIZE__): ch = lv.color_t.__cast__(img_view[i:i]).ch ch.red, ch.blue = ch.blue, ch.red dsc.img_data = img_data return lv.RES.OK
def open_png(decoder, dsc): img_dsc = lv.img_dsc_t.cast(dsc.src) png_data = img_dsc.data png_size = img_dsc.data_size png_decoded = png.C_Pointer() png_width = png.C_Pointer() png_height = png.C_Pointer() error = png.decode32(png_decoded, png_width, png_height, png_data, png_size) if error: raise lodepng_error(error) img_size = png_width.int_val * png_height.int_val * 4 img_data = png_decoded.ptr_val img_view = img_data.__dereference__(img_size) if COLOR_SIZE == 4: convert_rgba8888_to_bgra8888(img_view) elif COLOR_SIZE == 2: if COLOR_IS_SWAPPED: convert_rgba8888_to_swapped_bgra5658(img_view) else: convert_rgba8888_to_bgra5658(img_view) else: raise lodepng_error("Error: Color mode not supported yet!") dsc.img_data = img_data return lv.RES.OK
def open_png(decoder, dsc): # Read and parse PNG file img_dsc = lv.img_dsc_t.cast(dsc.src) png_data = img_dsc.data png_size = img_dsc.data_size png_decoded = png.C_Pointer() png_width = png.C_Pointer() png_height = png.C_Pointer() error = png.decode32(png_decoded, png_width, png_height, png_data, png_size) if error: raise lodepng_error(error) img_size = png_width.int_val * png_height.int_val * 4 img_data = png_decoded.ptr_val img_view = img_data.__dereference__(img_size) lv_h.rgba8888_to_5658(img_view) dsc.img_data = img_data return lv.RES.OK
def open_png(decoder, dsc): img_dsc = lv.img_dsc_t.cast(dsc.src) png_data = img_dsc.data png_size = img_dsc.data_size png_decoded = png.C_Pointer() png_width = png.C_Pointer() png_height = png.C_Pointer() error = png.decode32(png_decoded, png_width, png_height, png_data, png_size) if error: raise lodepng_error(error) img_size = png_width.int_val * png_height.int_val * lv.color_t.SIZE img_data = png_decoded.ptr_val img_view = img_data.__dereference__(img_size) convert_rgba_to_argb(img_view, img_size) dsc.img_data = img_data return lv.RES.OK