Hello again,
I’ve followed the instructions over there:
Simply put, it doesn’t work, absolutely nothing is displayed.
The only difference from the code given there is that I’ve made it in such a way that pictures are loaded in one function, and displayed in another. This code isn’t completely refined and, as you can see, there are a lot of pointers I’m just losing / I know this and I do intend to take care of it once I manage to simply make something work.
You may notice things that seem weird such as the use of decode32 for a picture that’s actually 16 bits, while I multiply (h*w) by 2 (2 x 8 bits = 16, right? ) but I have tried with a 32bit picture and set the size multiplier accordingly (4), and it didn’t work either.
Here is my temporary code:
t_image *png_to_array(char *filename)
{
uint32_t error;
unsigned char *png_data;
size_t png_data_size;
error = lodepng_load_file(&png_data, &png_data_size, filename);
if(error)
{
printf("LOADING IMAGE: ERROR!\n");
printf("error %u: %s\n", error, lodepng_error_text(error));
return NULL;
}
t_image *img = malloc(sizeof(t_image));
error = lodepng_decode32(&img->png_decoded, &img->png_width, &img->png_height, png_data, png_data_size);
if(error)
{
printf("error %u: %s\n", error, lodepng_error_text(error));
return NULL;
}
printf("Creating picture %s, w:%d x h:%d\n", filename, img->png_width, img->png_height);
return img;
}
void display_png(t_image *img)
{
lv_img_dsc_t *png_dsc;
png_dsc = malloc(sizeof(lv_img_dsc_t));
png_dsc->header.always_zero = 0;
png_dsc->header.cf = LV_IMG_CF_TRUE_COLOR;
png_dsc->header.w = img->png_width;
png_dsc->header.h = img->png_height;
png_dsc->data_size = img->png_width * img->png_height * 2;
png_dsc->data = img->png_decoded;
lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img_obj, &png_dsc);
}
For now I just run a line at startup, after initializing everything:
display_png(png_to_array(“file.png”));
The file exists and is a 16 bit png. Transparency does not matter. I can convert it to anything else.
Later on if this works, I would like to load all my pictures into an array of pictures with “png_to_array” and call them with “display_png” whenever I want it.
The use of pointers is mainly just so I’m making sure I don’t lose any variable from a function to another, as for now I’m unsure of how it all works, but later on I want to be able to store them and free them.
What am I doing wrong?