Description
A QR code is a LV_CANVAS_BUF_SIZE_INDEXED_1BIT canvas, and each pixel of its buffer can be color inverted. I’m asking how to best invert a canvas?
MCU and board type
STM32F205RET (128K SRAM, 512K Flash) in a custom board, with gcc-arm(1), GNU make(1), and STM32 HAL.
LVGL version
7.11.0
What do you want to achieve?
I want to modify a canvas that is being displayed, to have its 1-bit colours inverted.
What have you tried so far?
In the callback of a clickable canvas, I tried lv_obj_set_style_local_image_recolor(3), lv_img_buf_set_palette(3), lv_canvas_set_palette(3), and lv_canvas_set_px(3). All had no effect in the appearance.
I tried modifying the internal image buffer as well:
lv_img_dsc_t * img = lv_canvas_get_img(qrcode);
uint8_t * buf_u8 = (uint8_t *)img->data + 8;
// loop over the buffer and flip the bits (1-bit monochrome)
This kind of works outside the canvas click callback set with:
lv_obj_set_click(qrcanvas, true);
…but it seems to not work inside the callback.
Suspicion
It may be that some of the above tried method work outside of a click event handler, because the object referenced passed to the callback is a copy of the pointer?
I’m not using lv_img_cache_invalidate_src(3), so maybe this would help?
Goal
Pointing a smartphone camera at a LVGL QR code on a small display is error prone. I’m trying to invert the QR code colours on a button key press (to help the phone detect the QR code.)