lvgl / lv_lib_png

PNG decoder for LVGL
MIT License
67 stars 26 forks source link

PNG test on lv_port_stm32f429_disco #16

Open WiktorBAbove opened 3 years ago

WiktorBAbove commented 3 years ago

Hello Im trying to load the basic example on a stm32f429 discovery board. Im not doing anything unusual,

    lv_init();
    tft_init();
    lv_png_init();
    .
    .
    .

    LV_IMG_DECLARE(png_decoder_test);
    lv_obj_t * imgpng = lv_img_create(lv_scr_act(), NULL);
    lv_img_set_src(imgpng, &png_decoder_test);
    lv_obj_align(imgpng, NULL, LV_ALIGN_CENTER, 0, 0);

The only thing I get on the screen is:

No
data

I just have one image, but I've #define LV_IMG_CACHE_DEF_SIZE 2 Is there anything else I need to think about? Im using "7faf20592598e7f891cf2aceca32bbe6ff5fc36c"

kisvegabor commented 3 years ago

Probably you are out of memory.

I've added a smaller png_decoder_test image. Does it work with that?

WiktorBAbove commented 3 years ago

That worked well! I have tried to convert myown png to 50x50 like png_decoder_test.

const lv_img_dsc_t png_decoder_test = {
  .header.always_zero = 0,
  .header.w = 50,
  .header.h = 50,
  .data_size = 5158,
  .header.cf = LV_IMG_CF_RAW_ALPHA,
  .data = png_decoder_test_map,
};

and mine is:

const lv_img_dsc_t testtubeslab2 = {
  .header.always_zero = 0,
  .header.w = 50,
  .header.h = 50,
  .data_size = 3727,
  .header.cf = LV_IMG_CF_RAW_ALPHA,
  .data = testtubeslab2_map,
};

It is smaller in size however it is showing just a bold text PNG on the screen. I converted it by: php ../lv_utils/img_conv_core.php "name=testtubeslab2&img=./png/testtubeslab2.png&format=c_array&cf=raw_alpha" I am using php7.4-gd and php7.4-cli if that matters? Am i missing something crucial for it to work?

kisvegabor commented 3 years ago

Could you send the PNG image you used?

WiktorBAbove commented 3 years ago

I think i figured out what was wrong!

  1. resized the original with windows10's builtin converter (powertoys)
  2. resized with imagick (convert) What I got was interesting: 1) 3071bytes 2) 3727bytes

Both files can be opened and viewed. However the current decoder cant handle an image that is resized with Imagick. convert orig.png -resize 50x50 resized.png

Now I've actually managed to combine, a transparent PNG together with a 320x240 transparent GIF animation, without graphical issues.

I suppose we can close this issue, thank you for quick response! and your work!

embeddedt commented 3 years ago

I'd be curious to know if the same issue happens when converting the PNG to LVGL format using the experimental JS converter. There are many variants of PNG and the PHP converter tends to fail on several of them.

WiktorBAbove commented 3 years ago

@embeddedt: Since you mentioned it, I have done the same test, but with the experimental "JS converter". It seems to work even though i converted it with Imagick with some extra bytes. What is missing is the correct image-description of size,h and w in the generated C-file which I needed to update, or else "no bueno" Other than that; maybe a 80char width would be more estethicaly appealing.

embeddedt commented 3 years ago

What is missing is the correct image-description of size,h and w in the generated C-file which I needed to update, or else "no bueno"

Are you referring to the struct generated at the end of the file? That is using the dimension data provided by the browser, which should match the dimensions of the PNG file. If it's not matching, please provide the PNG file so I have something to replicate the issue with.

WiktorBAbove commented 3 years ago

So i tried: https://blog.lvgl.io/assets/png_converter/png_decoder_test.png All color formats give good dimensions, except all the RAW color formats selections where the dimensions have been zeroed out also the datasize. The experimental one puts just zeroes on :

  .header.w = 0,
  .header.h = 0,
  .data_size = 0,

Note: the current image converter doesnt add the zeroes for the dimension but gives good .data_size on all RAW color formats.

embeddedt commented 3 years ago

Dimensions being 0 are intended, as the RAW feature actually allows you to convert any type of file. For a PNG image, the PNG decoder will take care of finding the width and height from the PNG data at runtime. I don't think you're supposed to have to add them by hand - @kisvegabor is this a bug in the PHP converter?

Data size being 0 is a bug on mine which should be fixed now. I also added line breaks for RAW images as it's easier to do there.