I found it out.
For some reason png and jpg expect the buffer as BGR (and not RGB). I do not understand why, but it is what it is
I wrote a small function converting RGB to BGR and then saving the new buffer.
void convertRGBtoBGR(uint8_t* buffer, uint32_t width, uint32_t height) {
uint32_t totalPixels = width * height;
for (uint32_t i = 0; i < totalPixels; ++i) {
uint32_t index = i * 3;
uint8_t r = buffer[index]; // R
uint8_t g = buffer[index + 1]; // G
uint8_t b = buffer[index + 2]; // B
buffer[index] = b; // B
buffer[index + 1] = g; // G
buffer[index + 2] = r; // R
}
}
I am calling it like this:
lv_draw_buf_t *buff = lv_screenshot_take(lv_disp_get_default(), LV_COLOR_FORMAT_RGB888);
save_as_bmp_file(buff->data, buff->header.w, buff->header.h, 24, "A:/Users/ph/Downloads/test.bmp");
convertRGBtoBGR(buff->data, buff->header.w, buff->header.h);
save_as_png_file(buff->data, buff->header.w, buff->header.h, 24, "A:/Users/ph/Downloads/test.png");
tje_encode_to_file("A:/Users/ph/Downloads/test.jpg", buff->header.w, buff->header.h, 3, buff->data);
Thanks for your help!