Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Does this scare anyone else?

Does this scare anyone else?

Scheduled Pinned Locked Moved The Weird and The Wonderful
designcomgraphicsiottutorial
3 Posts 2 Posters 23 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    In LVGL you can set an image source to either be a file path or a structure.

    lv_obj_t* ui_img = lv_img_create(ui_screen);
    lv_img_dsc_t img_dsc;
    img_dsc.header.always_zero = 0;
    img_dsc.header.cf = LV_IMG_CF_RAW;
    img_dsc.header.w = 800;
    img_dsc.header.h = 480;
    img_dsc.data_size = 800*480*LV_COLOR_DEPTH/8;
    uint8_t *img_mem = (uint8_t*)ps_malloc(img_dsc.data_size);
    img_dsc.data = img_mem;
    memset(img_mem,0,img_dsc.data_size);
    lv_img_set_src(ui_img,&img_dsc);

    That's one option. Here's another

    lv_obj_t* ui_img = lv_img_create(ui_screen);
    lv_img_set_src(ui_img,"A:/minou_480.jpg");

    The lv_img_set_src() function takes a void* for the second argument and either accepts an instance of a lv_img_dsc_t structure or a string! Worse, there's no lv_img_dsc_init() function to set the struct to a known state (with for example, a magic cookie in it that can be used to flag it as the structure rather than a string) Ultimately here's how it checks:

    if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F)

    where u8_p[0] is the first byte of the source argument. This is in battle tested production code used in many many devices in the real world.

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

    P 1 Reply Last reply
    0
    • H honey the codewitch

      In LVGL you can set an image source to either be a file path or a structure.

      lv_obj_t* ui_img = lv_img_create(ui_screen);
      lv_img_dsc_t img_dsc;
      img_dsc.header.always_zero = 0;
      img_dsc.header.cf = LV_IMG_CF_RAW;
      img_dsc.header.w = 800;
      img_dsc.header.h = 480;
      img_dsc.data_size = 800*480*LV_COLOR_DEPTH/8;
      uint8_t *img_mem = (uint8_t*)ps_malloc(img_dsc.data_size);
      img_dsc.data = img_mem;
      memset(img_mem,0,img_dsc.data_size);
      lv_img_set_src(ui_img,&img_dsc);

      That's one option. Here's another

      lv_obj_t* ui_img = lv_img_create(ui_screen);
      lv_img_set_src(ui_img,"A:/minou_480.jpg");

      The lv_img_set_src() function takes a void* for the second argument and either accepts an instance of a lv_img_dsc_t structure or a string! Worse, there's no lv_img_dsc_init() function to set the struct to a known state (with for example, a magic cookie in it that can be used to flag it as the structure rather than a string) Ultimately here's how it checks:

      if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F)

      where u8_p[0] is the first byte of the source argument. This is in battle tested production code used in many many devices in the real world.

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      img_dsc.header.always_zero = 0;

      I have no idea of the layout of the struct, but for example if this is at the start, it would discriminate it from a valid string, would it not? Then the range check would separate empty strings from real ones.

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      H 1 Reply Last reply
      0
      • P Peter_in_2780

        img_dsc.header.always_zero = 0;

        I have no idea of the layout of the struct, but for example if this is at the start, it would discriminate it from a valid string, would it not? Then the range check would separate empty strings from real ones.

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #3

        It is at the beginning of the struct and it is used as a discriminator. And yet it seems extremely accident prone, and I should add the docs do not clarify this. At worst there should be, IMO, a function to initialize the structure. At best, there should actually be two lv_img_set_src() functions - one for paths, and one for lv_img_dsc_t structs.

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups