Working with jpg images



  • The factor demo for the Core2 is very nice.
    I found the thread "Lesson 1.2.1. LCD. How to create image array" but that is not what is used in the factory demo.
    They use, Disbuff.drawJpg(CoverImage,21301,0,0,240,240,0,0);
    The lesson thread uses drawBitmap

    What I would like to know is how to take a .jpg image, convert it to a C file and use drawJpg to throw it on the LCD.
    Is there any info on how to do that ?

    Thanks



  • @mikemoy You don't need to, you can save jpgs to the core2 and load them directly.
    btw the lesson was written for the core1 a long time ago.



  • I have a M5Paper, not a Core2, but the APIs look very similar.
    You can use something like bin2header (https://github.com/AntumDeluge/bin2header) to convert your jpg file to a C header file and include that in your project. It will start with something like:

    static const unsigned char my_file_name_jpg[] = {...
    

    You can then use the memory buffer form of drawJpg:

          void drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x = 0,
                      uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0,
                      uint16_t offX = 0, uint16_t offY = 0,
                      jpeg_div_t scale = JPEG_DIV_NONE);
    

    Like this:

    drawJpg(my_file_name_jpg,sizeof(my_file_name_jpg),x,y,...)
    

    (As the other poster said, this might not be the best way of doing it, but it is available.)



  • Thank you for the detailed explanation.
    I wound up using "Bin2C" from segger.com because I am a windows guy ;-)
    Bin2C

    Got it working now thanks.



  • Could you please outline how this is done? I've been trying for days with no luck. It seems only PNG's are accepted , and the ones I resize look pixelated and horrible.

    Thanks ,



  • @ajb2k3 Can you please outline how this is done? I have been unable to do this at all with my core2. With UIFlow it only allows PNG uploads, and with Audrino there is no way to upload the JPG image to the core2. Google searches show 1/2 the time that it can't be done, and that I should upgrade to a FIRE , and 1/2 the time say it's possible but not how to do it.

    Thanks ,

    • D


  • @delchi Hi, I am currently rewriting my book at the moment and about to redo the whole image section to make it easy to understand.
    jpegs can most defiantly be done in UIFLOW as I have just done it.

    Images must not be bigger than the screen size.
    Images must be indexed.
    Images must be compressed,
    Images must have all non used colour data removed,
    For CoreInk image must be in 1bit mode,
    For M5paper images must be in 16bit grayscale,
    Images must be no more than 50KB in size.
    My current book version found here https://github.com/Ajb2k3/UIFlowHandbook/blob/master/UIFlowhandbook.pdf has the instructions in it.



  • @delchi I didn't have any luck with JPGS, so i just used PNG.



  • @ajb2k3 Thank you ! I'm using a core 2 and it seems like no one has had an easy time with this. I keep finding odd bugs like loops not working correctly and ghost labels popping up and it's all very frustrating w/out a solid guide. I'll keep an eye out for your book when it covers the core2.



  • @ajb2k3 And now after an afternoon of a successful PNG image working, it just suddenly stopped, and won't even allow an upload. No error message , no nothing.

    Frustration wins today. I can't believe how wonky this all is :)



  • @delchi I take it you are using UIFLOW online.
    In that case it just means that the server dropped and crashed due to the amount of people online.