[sloved][png decoder] Using the png decoder demo but display an error picture

Using the png decoder demo but display an error picture

My code is here:

    void app_main()
    {
        lv_init();

        disp_spi_init();
        ili9341_init();

        static lv_color_t buf1[DISP_BUF_SIZE];
        static lv_color_t buf2[DISP_BUF_SIZE];
        static lv_disp_buf_t disp_buf;
        lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE);

        lv_disp_drv_t disp_drv;
        lv_disp_drv_init(&disp_drv);
        disp_drv.flush_cb = ili9341_flush;
        disp_drv.buffer = &disp_buf;
        lv_disp_drv_register(&disp_drv);
        esp_register_freertos_tick_hook(lv_tick_task);

        LV_IMG_DECLARE(png_decoder_test);   /*Declare the C array*/
        uint32_t error;                     /*For the return values of png decoder functions*/

        /*Decode the PNG image*/
        unsigned char * png_decoded;    /*Will be pointer to the decoded image*/
        uint32_t png_width;             /*Will be the width of the decoded image*/
        uint32_t png_height;            /*Will be the width of the decoded image*/

        /*Decode the loaded image in ARGB8888 */
        error = lodepng_decode32(&png_decoded, &png_width, &png_height, png_decoder_test.data, png_decoder_test.data_size);

        if (error) {
            printf("error %u: %s\n", error, lodepng_error_text(error));
            while (1);
        }

        /*Initialize an image descriptor for LittlevGL with the decoded image*/
        lv_img_dsc_t png_dsc;
        png_dsc.header.always_zero = 0;                          /*It must be zero*/
        png_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;      /*Set the color format*/
        png_dsc.header.w = png_width;
        png_dsc.header.h = png_height;
        png_dsc.data_size = png_width * png_height * 4;
        png_dsc.data = png_decoded;

        /*Create an image object and set the decoded PNG image as it's source*/
        lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL);     /*Create the an image object in LittlevGL*/
        lv_img_set_src(img_obj, &png_dsc);                          /*Set the image source to the decoded PNG*/
        lv_obj_set_drag(img_obj, true);                             /*Make to image dragable*/

        /*Set a non-white background color for the scren to see the alpha is working on the image*/
        lv_style_scr.body.main_color = LV_COLOR_MAKE(0x40, 0x70, 0xAA);

        while (1) {
            vTaskDelay(1);
            lv_task_handler();
        }
    }

The original image is shown below

png_decoder_test

But my picture is shown as follows

Do not know why, if anyone would like to help me, many thanks!

Would anybody give a suggestion?

It’s weird. the same code works well on the pc-simulate project, but bot working on the esp32_ili9341 example.
@ kisvegabor @ embeddedt

We are always emailed about your posts. Please be patient. We have limited spare time in which to answer questions.

I havent looked at your code but it looks like it could be a driver/display issue, not necessarily an image issue. Have you tried just displaying a widget such as a button? might be worth doing that to prove if its a image issue or not.

It’s not a dirver issue, I try to display another imge, It works well.
see part1 and part2 of the picture blew:

If the blew code blew was encapsulated in a function, then call this function, the image will not display. This experiment was tested in PC-simulator project.

	LV_IMG_DECLARE(png_decoder_test);   /*Declare the C array*/
	/*Decode the PNG image*/
	unsigned char * png_decoded = NULL;    /*Will be pointer to the decoded image*/
	uint32_t png_width;             /*Will be the width of the decoded image*/
	uint32_t png_height;            /*Will be the width of the decoded image*/

	/*Decode the loaded image in ARGB8888 */
	 uint32_t error = lodepng_decode32(&png_decoded, &png_width, &png_height, png_decoder_test.data, png_decoder_test.data_size);

	if (error) {
		printf("error %u: %s\n", error, lodepng_error_text(error));
		while (1);
	}
	printf("error: %d\n", error);
	printf("%p\n", png_decoded);
	printf("png_width:%d\n", png_width);
	printf("png_height:%d\n", png_height);

	/*Initialize an image descriptor for LittlevGL with the decoded image*/
	lv_img_dsc_t png_dsc;
	png_dsc.header.always_zero = 0;                          /*It must be zero*/
	png_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;      /*Set the color format*/
	png_dsc.header.w = png_width;
	png_dsc.header.h = png_height;
	png_dsc.data_size = png_width * png_height * 4;
	png_dsc.data = png_decoded;
	printf("png_dsc.data_size %d, png_dsc.data %p\n", png_dsc.data_size, png_dsc.data);

	/*Create an image object and set the decoded PNG image as it's source*/
	lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL);     /*Create the an image object in LittlevGL*/
	lv_img_set_src(img_obj, &png_dsc);                          /*Set the image source to the decoded PNG*/
	lv_obj_set_drag(img_obj, true);                             /*Make to image dragable*/

	/*Set a non-white background color for the scren to see the alpha is working on the image*/
	lv_style_scr.body.main_color = LV_COLOR_MAKE(0x40, 0x70, 0xAA);

@TheGrovesy please take a look.

It might be because the lv_img_dsc_t png_dsc is only within the scope of the function? What happen if you make it static?

:+1:
Issue on PC-simulator project was solved, but I still have no clue about esp32_ili9341 problem.

Is the code in your device for setting up and showing the image exactly the same as the simulation? Are there any differences between the setup/displaying of the two images you showed in your last example where one displayed correctly?

@TheGrovesy they are amost the same, except the dirver.
Part 1 of the two images is the png decoder demo image want to display, part 2 is the png image convert by online tools(https://littlevgl.com/image-to-c-array) . It use to test the display dirver work or not.

blew is pc-simulator source code
main.c (7.6 KB)

The esp32_ili9341 source code here
main.c (3.7 KB)

please give some suggestions, thanks a lot!

I suggest not using lodepng directly. In the related blog post you find a ready to use decoder.

It can be used simply like this:

    png_decoder_init();

    LV_IMG_DECLARE(png_decoder_test);
    lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
    lv_img_set_src(img, &png_decoder_test);
1 Like

WOW … :+1::+1::+1:
You just hit the point!!