Loading png files to the system

Hello all,

I am trying to load and draw dinamically, during execution, png files to our system. I have seen that there are several functions inside the GUIX API to convert png files into guix resources dinamically:

gx_image_reader_create
gx_image_reader_palette_set
gx_image_reader_start

But we have not been able to find any example on how to use them. Is there someone else using these functions or anyone knows where to find examples about this topic?

 

Thanks in advance

 

 Imanol

 

  • Hi Imanol,

    According to latest GUIX user manual available in Synergy Gallery, these functions should be used in the following way:

    GX_IMAGE_READER image_reader;
    GX_PIXELMAP output_map;
    UINT status;

    /* PNG data */
    GX_UBYTE png_data[] = { ... };
    INT png_data_len = ...;

    /* Output color format, available options:
     * GX_COLOR_FORMAT_32ARGB
     * GX_COLOR_FORMAT_24RGB
     * GX_COLOR_FORMAT_565RGB
     * GX_COLOR_FORMAT_8BIT_PALETTE
     */
    GX_UBYTE output_color_format = GX_COLOR_FORMAT_565RGB;

    /* Mode flags, available options (can be mixed using bitwise OR):
     * GX_IMAGE_READER_MODE_NONE
     * GX_IMAGE_READER_MODE_COMPRESS
     * GX_IMAGE_READER_MODE_ALPHA
     * GX_IMAGE_READER_MODE_DITHER
     */
    GX_UBYTE mode = GX_IMAGE_READER_MODE_NONE;


    /* Create an image reader. */
    status = gx_image_reader_create(&image_reader, png_data, png_data_len, output_color_format, mode);

    if (status != GX_SUCCESS)
    {
        /* Handle error */
        while(1);
    }

    /* Optionally set a palette. */
    /* gx_image_reader_palette_set(&image_reader, palette, palette_len); */

    /* Start a conversion. */
    status = gx_image_reader_start(&image_reader, &output_map);

    if (status != GX_SUCCESS)
    {
        /* Handle error */
        while(1);
    }

    Regards,
    adboc

  • In reply to adboc:

    Thanks adboc,

    Could you provide us with the link to that document? I have tried but we can not find it.

    Regards

    Imanol
  • In reply to adboc:

    Thanks adboc,

    Could you provide us with the link to that document? I have tried but we can not find it.

    Regards

    Imanol
  • In reply to Imanol:

    Hi Imanol,

    All documents for X-Ware components (NetX, USBX, GUIX, ThreadX, etc.) can be found under Synergy Software Package > Release Archive tab > Documentation column > X-Ware™ Component Documents for Renesas Synergy™ (For SSP 1.3.2: synergygallery.renesas.com/.../Synergy_X-Ware_Docs.zip)

    Regards,
    adboc
  • In reply to adboc:

    Thanks for the document adboc,

    We have tried to load the image by doing this:

    #define APP_PNG_MEM (153600)

    /** Memory allocated for the JPEG file buffer and information */
    static GX_UBYTE png_data[APP_PNG_MEM] BSP_ALIGN_VARIABLE(8);
    GX_UBYTE output_color_format = GX_COLOR_FORMAT_565RGB;
    GX_UBYTE mode = GX_IMAGE_READER_MODE_ALPHA;
    GX_IMAGE_READER image_reader;
    GX_PIXELMAP output_map;

    /* Open file */
    status = fx_file_open(p_media, &my_file, (CHAR*)"Pan_Chapata.png", FX_OPEN_FOR_READ);
    if (status != FX_SUCCESS)
    {
    __BKPT(0);
    }

    /* Read file */
    status = fx_file_read(&my_file, png_data, APP_PNG_MEM, &actual_size);
    if (status != FX_SUCCESS)
    {
    __BKPT(0);
    }

    status = gx_image_reader_create(&image_reader, png_data, actual_size, output_color_format, mode);
    if (status != FX_SUCCESS)
    {
    __BKPT(0);
    }

    status = gx_image_reader_start(&image_reader, &output_map);
    if (status != GX_SUCCESS)
    {
    __BKPT(0);
    }

    But we are getting an error (0x30 GX_SYSTEM_MEMORY_ERROR) when using the gx_image_reader_start function. Is there something that we are doing wrong?

    Thanks in advance

    Imanol
  • In reply to Imanol:

    Hi Imanol,

    The image reader requires memory allocator, it can be set using gx_system_memory_allocator_set function. For an example implementation please refer to GUIX user guide.

    Regards,
    adboc
  • In reply to adboc:

    Hi  ,

    we've tried what you proposed and the memory allocation seems to work, although we're no able to visualize the image on the screen. Does it need a particular png format to do so? (In the JPEG case I remember it did)

    Following your previous code, the image file is read from the USB and both gx_image_reader_create and gx_image_reader_start return success value, and these are the resulted structures:

    image_reader after gx_image_reader_create:

    image_reather and output_map after gx_image_reader_start:

    output_map doesn't get the data, apparently. Do we have to introduce the width and the height of the image (as we did with JPEG images)? Isn't gx_image_reader_create function supposed to fill up these parameters?

    Could you provide us an example that reads a PNG file?

    Thanks and regards,

    isaenz.

  • In reply to isaenz:

    Hi isaenz,

    Please investigate the following example that reads PNG files from the USB media and draws them using GUIX: s7_dk_gx_png_decode_1_2_0b1.zip. I haven't updated project for newer SSP but migration should be reasonably easy.

    Regards

  • In reply to Renesas Karol:

    Hello ,

    I've been taking a look at the example you provided but the functions gx_image_reader_create, gx_image_reader_palette_set and gx_image_reader_start are not being used. So what's the procedure to visualize a png image? (I don't manage to see the images on my screen)

    Regards,
    isaenz.
  • In reply to isaenz:

    Hi isaenz,

    I fetch the PNG data into buffer in SDRAM and then create a GX_PIXELMAP structure for it. gx_canvas_pixelmap_draw (inside custom drawing function for the window) will take care of creating image reader, allocating required memory and rendering the PNG automatically.

    EDIT: You'll need to connect USB stick with PNG files in the root directory of the FAT partition. Screen presses are used to refresh the screen and load next image.

    Regards

  • In reply to Renesas Karol:

    Hello  

     

    we're still not able to make the example work. We are using SSP1.2.0 and I think some features get lost in translation. We have a PE-HMI1 board and a custom board based on the S7G2DK.

    Do you have an example with SSP1.2.0 for the PE-HMI1? (1.2.2 could be valid too)

     

    Apart from that, is there a specific format that the PNG images have to fulfill? JPEG images do (https://renesasrulz.com/synergy/f/synergy---forum/7233/displaying-images-from-usb-storage-sk-s7g2/23951#23951) and we're wondering if this happens in this case also.

     

    Regards,

    isaenz.

  • In reply to isaenz:

    Hello isaenz,

    I had no trouble converting the project to use SSP 1.2.1 with PE-HMI1 (project attached at the bottom). "IDHR chunk not found" means that the file code is trying to open is not a PNG file - I didn't implement any filter as it's meant to be a test project only (you can touch the screen to load the next file anyway). So far I haven't found a single PNG file that wouldn't work with this (other than files that were simply too big).

    s7_hmi_gx_ux_png_decode_1_2_1.zip

    Regards

  • In reply to Renesas Karol:

    Hello  

    Thanks for the application. It works over the PE-HMI1 but I'm trying to port it to our application (custom board based on S5D9 + touchscreen, SSP 1.2.0) and I don't manage to visualize the image (same image I visualize with your application, which is the syn272.png image that belongs to S7_DK_gx_png_decode_1_2_0b1).

    Here's a couple of things I've noticed:

    1. The data size read in your application and ours don't match. In your application the data size of the read file is 56723 and in our application is 86391. Does this make any sense? (I've also tried forcing the size value to 56723, but it doesn't work either) Every other value in the GX_PIXELMAP structure is the same

    2. If we monitor the image in the memory tab, it prints OK, and the pixelmap that we're trying to print (gx_canvas_pixelmap_draw) points to that pixelmap correctly:

     

    Can you think about what could be missing? This application works fine for JPEG images (with the proper changes in order to size the image. etc).

     

    Regards,

    isaenz.

  • In reply to isaenz:

    [UPDATE]

    Hello again  

    I've look a little deeper in the read data, and I've noticed that in your application the characters 'E' 'N' 'D' are at the final part of the data (around 56723, which is the size of the read data in the pixelmap structure).

    However, in our application, those characters are around the 86585 position, which is the size that the gx_pixelmap structure states:

    So I'm wondering why this data is read in a different way when we're using the same file (same USB stick) in the same way:

    static FX_FILE      my_file;

    static UCHAR png_data[262144] BSP_ALIGN_VARIABLE(8);

    static GX_PIXELMAP png_pixelmap =
    {
        1, /* major version */
        0, /* minor version */
        GX_PIXELMAP_COMPRESSED|GX_PIXELMAP_ALPHA|GX_PIXELMAP_RAW_FORMAT, /* flags*/
        GX_COLOR_FORMAT_565RGB, /* Format */
        NULL,
        0, /* the size of pixelmap_data*/
        NULL,
        0, /* auxiliary data size */
        0, /* used for transparent iamges */
        480, /* width in pixel */
        272 /* height in pixel */
    };

    status = fx_file_read(&my_file, png_data, sizeof(png_data), &png_pixelmap.gx_pixelmap_data_size);

     

    Regards,

    isaenz.

  • In reply to isaenz:

    Hello isaenz,

    Please compare the USB host configuration. Are you using transfer driver?

    Regards