gx_utility_pixelmap_resize

Hi everyone,


I am having a problem when using the gx_utility_pixelmap_resize utility to make an image smaller. The actual size of my pixelmap (p_pixelmap) is 192x144 pixels, and I would like to resize it to 144x64. I am using the following function, but it returns a GX_PTR_ERROR and I do not understand why.

GX_PIXELMAP * p_pixelmap;
GX_PIXELMAP * p_resized_pixelmap;

p_pixelmap = (GX_PIXELMAP *) event_ptr->gx_event_payload.gx_event_ulongdata;

status = gx_utility_pixelmap_resize(p_pixelmap, p_resized_pixelmap, 144, 64);

Am I doing something wrong? Has somebody worked with the mentioned function before? I can find no information about how to use it in the documentation.

  • Hi iparra,

    I think that p_resized_pixelmap (and all its members) should be allocated.

    Here's GX_PIXELMAP definition:

    typedef struct GX_PIXELMAP_STRUCT
    {
        GX_UBYTE           gx_pixelmap_version_major;               /* Pixelmap major version number            */
        GX_UBYTE           gx_pixelmap_version_minor;               /* Pixelmap minor version number            */
        GX_UBYTE           gx_pixelmap_flags;                       /* Flags defined below                      */
        GX_UBYTE           gx_pixelmap_format;                      /* Color format, defined below              */
        GX_CONST GX_UBYTE *gx_pixelmap_data;                        /* Pointer to pixelmap data                 */
        ULONG              gx_pixelmap_data_size;                   /* Size of the pixelmap data array          */
        GX_CONST GX_UBYTE *gx_pixelmap_aux_data;                    /* Auxiliary data array.                    */
        ULONG              gx_pixelmap_aux_data_size;               /* Size of the auxiliary data array         */
        ULONG              gx_pixelmap_transparent_color;           /* Used for translated GIF images           */
        GX_VALUE           gx_pixelmap_width;                       /* Width - in pixels                        */
        GX_VALUE           gx_pixelmap_height;                      /* Height - in pixels                       */
    } GX_PIXELMAP;



    and an example from GUIX Studio generated file:

    static GX_CONST GX_UBYTE DISPLAY_1_THEME_1_CHECKBOX_ON_pixelmap_data[466] =
    {
        0x8f, 0x90, 0x1a, 0x0f, 0x90 /* ... */
    };
    GX_CONST GX_PIXELMAP DISPLAY_1_THEME_1_CHECKBOX_ON_pixelmap =

    {
        0x00000001,                              /* major version                  */
        0x00000000,                              /* minor version                  */
        GX_PIXELMAP_COMPRESSED,                  /* flags                          */
        GX_COLOR_FORMAT_565RGB,                  /* Format                         */
        (GX_UBYTE *) DISPLAY_1_THEME_1_CHECKBOX_ON_pixelmap_data,
        sizeof(DISPLAY_1_THEME_1_CHECKBOX_ON_pixelmap_data),    /* the size of pixelmap_data*/
        NULL,
        0,                                       /* auxiliary data size            */
        0x00,                                    /* used for transparent iamges    */
        16,                                      /* width in pixel                 */
        16                                       /* height in pixel                */
    };


    I suggest trying something like this:

    // 144*64 = 9216
    // Not sure how many bytes are required to encode a pixel (maybe 2, 3 or 4?), so use larger value (5x).
    // It depends on flags (if it's compressed, see GX_PIXELMAP_COMPRESSED) and format (e.g. GX_COLOR_FORMAT_565RGB).
    // You can check the size of p_pixelmap in debug process.
    // Please make sure that this value will fit the MCU memory.


    #define RESIZED_PIXELMAP_SIZE 46080

    GX_UBYTE g_px_data[RESIZED_PIXELMAP_SIZE];
    // Auxiliary data necessary?
    GX_UBYTE g_px_aux_data[RESIZED_PIXELMAP_SIZE];

    GX_PIXELMAP g_resized_pixelmap = {
        0x00000001,
        0x00000000,
        GX_PIXELMAP_COMPRESSED,
        GX_COLOR_FORMAT_565RGB,
        (GX_UBYTE *) g_px_data,
        RESIZED_PIXELMAP_SIZE,
        (GX_UBYTE *) g_px_aux_data,
        RESIZED_PIXELMAP_SIZE,
        0x00,
        144,
        64
    };

    void px_resize(/* params here (event_ptr) */)
    {
        GX_PIXELMAP * p_pixelmap;

        p_pixelmap = (GX_PIXELMAP *) event_ptr->gx_event_payload.gx_event_ulongdata;
        
        status = gx_utility_pixelmap_resize(p_pixelmap, &g_resized_pixelmap, 144, 64);
    }


    Regards,
    adboc

  • Hello,

    Let me also add that you'll need to register dynamic memory allocation services using gx_system_memory_allocator_set(fn_allocate, fn_free) as GUIX needs additional memory to store the resized pixelmap. For this purpose, I recommend using wrapper functions for ThreadX Byte Pool service. I shared a project using this method in the following thread: renesasrulz.com/.../guix-circular-gauge-needle

    Regards
  • Hi,

    Ok, I registered dynamic memory allocation services as it is done on the example Karol sent me and have used a pixelmap with alpha channel enabled and 32ARGB, and the previous error disappeared; but now I receive a new error:
    0x11 GX_CALLER_ERROR

    Any idea? Why may this error show?
  • Hello,

    gx_utility_pixelmap_resize raises GX_CALLER_ERROR when memory allocator is not defined (i.e. pointer to memory-allocating functions is NULL). Please make sure that gx_system_memory_allocator_set returns GX_SUCCESS and that it's called before you execute gx_system_start();

    Regards
  • Hi,

    You were right I was calling the allocator after gx_system_start().

    Now I am facing another issue, I can resize 32ARGB pixelmap but not other formats. Is there a limitation of the pixelmap format? We are using 16 RGB.

    Regards,
    iparra
  • Hello,

    gx_utility_pixelmap_resize should work with 32, 16 and 8 bit formats (32 and 16 bit with alpha is also supported). Make sure the pixelmap is not set to "compressed" in GUIX Studio.

    Regards,
    Karol
  • Hi Karol,   I am trying to resize jpeg images in PE_HMI1.  I took the following two projects and merged for PE_HMI1 to display multiple images one by one upon clicking on the screen. 

    s7_hmi_ex_gx_gauge_1_1_0.zip and s7_sk_gx_ux_jpeg_1_1_0.zip 

    the program works fine on PE_HMI1 and i could able to see images one by one. 

    then, I am trying to add image resize part. it is not showing resized images. 

    I checked the function "gx_utility_pixelmap_resize" returned 0.  which looks correct. but I couldn't see images on the screen.  

    here is my code, i followed the above thread. 

    #define RESIZED_PIXELMAP_SIZE 46080

    GX_UBYTE g_px_data[RESIZED_PIXELMAP_SIZE];
    // Auxiliary data necessary?
    GX_UBYTE g_px_aux_data[RESIZED_PIXELMAP_SIZE];

    GX_PIXELMAP g_resized_pixelmap = {
    0x00000001,
    0x00000000,
    GX_PIXELMAP_COMPRESSED,
    GX_COLOR_FORMAT_565RGB,
    (GX_UBYTE *) g_px_data,
    RESIZED_PIXELMAP_SIZE,
    (GX_UBYTE *) g_px_aux_data,
    RESIZED_PIXELMAP_SIZE,
    0x00,
    160,
    64
    };

     void px_resize(/* params here (event_ptr) */)
    {
        GX_PIXELMAP * p_pixelmap;

        p_pixelmap = (GX_PIXELMAP *) event_ptr->gx_event_payload.gx_event_ulongdata;
        
        status = gx_utility_pixelmap_resize(p_pixelmap, &g_resized_pixelmap, 160, 64);

            gx_system_dirty_mark(win);
    }
    VOID w_main_draw(GX_WINDOW *widget)
    {
    if (p_pixelmap)
    {
          gx_canvas_pixelmap_draw(0, 0, &g_resized_pixelmap);// image doesn't show

       ///   gx_canvas_pixelmap_draw(0, 0, p_pixelmap );// image showing fine
    else
    gx_window_draw(widget);
    }

    i am adding the images that i am trying to resize. 

    Help me to understand the problem and solve the issue. 

    Thanks,

    R Prabakaran