How to change single pixels in a monochrome Canvas (LVGL v6)

Description

I find myself facing the same problem I had a couple of years ago (How to change single pixels in a monochrome Canvas). I found a solution for that but it doesn’t seem to work in version 6 of the library (which I need to use for reasons that are not relevant).

What MCU/Processor/Board and compiler are you using?

For now I’m working on the SDL simulator.

What LVGL version are you using?

6

What do you want to achieve?

Changing single pixels on a canvas.

What have you tried so far?

The solution proposed here: How to change single pixels in a monochrome Canvas.
It works in version 7 but not in version 6.

Code to reproduce

The following code with LV_COLOR_DEPTH set as 1. The display is 128x64 pixels.

    static lv_color_t buffer[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(48, 48)];
    lv_obj_t *        canvas = lv_canvas_create(lv_scr_act(), NULL);
    lv_canvas_set_buffer(canvas, buffer, 48, 48, LV_IMG_CF_INDEXED_1BIT);
    lv_color_t black;
    black.full = 0;
    lv_color_t white;
    white.full = 1;
    lv_canvas_set_palette(canvas, 0, LV_COLOR_WHITE);
    lv_canvas_set_palette(canvas, 1, LV_COLOR_BLACK);
    lv_canvas_set_px(canvas, 1, 1, black);
    lv_canvas_set_px(canvas, 2, 2, white);
    lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0)

I’m going to add some more information for clarity.
What I actually need to achieve is the ability to display bitmap images stored as byte arrays directly in a monochrome display (i.e. with 1 bit per pixel representation).
Using the default LVGL image representation would be a huge waste of memory (1 byte per pixel minimum, so 8 times what I actually need), thus I was circumventing this limitation by manually setting pixels in a canvas.

As this doesn’t seem to work I’ve resorted to implement a custom variant on the image widget that adheres to the byte array representation I’m using. It works perfectly and it’s probably better (performance wise) than the canvas. My originae issue still stands - though it’s now just for personal interest.