Announcement

Collapse
No announcement yet.

cli tool for gci conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • studio81
    replied
    I've tested your solution and works perfect, thanks again! I've pasted the working (arduino) code below for anyone to use (please note the beta 4dgfx lib posted above):

    Code:
    // Use FS (SPIFFS)
    // ----------------------------------------
    //#define USE_FS
    
    // Includes
    // ----------------------------------------
    #include "ESP8266WiFi.h"
    #include "GFX4d.h"
    #include "JPEGDecoder.h"
    
    // Minimum inline function
    // ----------------------------------------
    #define minimum(a,b) (((a) < (b)) ? (a) : (b))
    
    // Globals
    // ----------------------------------------
    GFX4d gfx = GFX4d();
    
    /******************************************
     * Setup
     * 
     *****************************************/
    void setup() {
    
      gfx.begin();
      
      gfx.Cls();
      gfx.ScrollEnable(true);
      gfx.BacklightOn(true);
      gfx.Orientation(PORTRAIT);
      gfx.SmoothScrollSpeed(5);
      
      gfx.TextColor(WHITE); 
      gfx.Font(2);  
      gfx.TextSize(1);
    
      // Wait for SD card
      while(false == gfx.CheckSD()) {
        delay(200);
      }
    
      // Draw Lena.jpg
      drawJpeg("Lena.jpg", 0, 0);
    }
    
    /******************************************
     * Loop
     * 
     *****************************************/
    void loop() {
    
      yield();
    }
    
    /******************************************
     * Draw jpeg
     * https://github.com/Bodmer/JPEGDecoder/blob/master/examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino
     * 
     *****************************************/
    void drawJpeg(String filename, int xpos, int ypos) {
      
      #ifndef USE_FS
        File jpeg = SD.open(filename);
      #else
        fs::File jpeg = SPIFFS.open((char*)filename.c_str(), "r");
      #endif
    
      if (!jpeg) {
        
        gfx.print("Error: File \""); 
        gfx.print(filename); 
        gfx.println ("\" not found.");
        
        return;
      }
    
      #ifndef USE_FS
        boolean decoded = JpegDec.decodeSdFile(jpeg); // SD
      #else
        boolean decoded = JpegDec.decodeFsFile(jpeg); // SPIFFS
      #endif
      
      if (decoded) {
        renderJpeg(xpos, ypos);
      } else {
        gfx.println("Error: Jpeg file format not supported.");
      }
    }
    
    
    /******************************************
     * Render jpeg
     * https://forum.4dsystems.com.au/forum/4d-systems-hardware-aa/4d-internet-of-display-iod-modules/65645-cli-tool-for-gci-conversion
     * 
     *****************************************/
    void renderJpeg(int xpos, int ypos) {
    
      uint16_t *p_img;
      uint16_t mcu_w = JpegDec.MCUWidth;
      uint16_t mcu_h = JpegDec.MCUHeight;
      uint32_t max_x = JpegDec.width;
      uint32_t max_y = JpegDec.height;
    
      uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
      uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
    
      uint32_t win_w = mcu_w;
      uint32_t win_h = mcu_h;
    
      max_x += xpos;
      max_y += ypos;
    
      while (JpegDec.read()) {
    
        p_img = JpegDec.pImage;
        
        int mcu_x = JpegDec.MCUx * mcu_w + xpos;
        int mcu_y = JpegDec.MCUy * mcu_h + ypos;
        
        if (mcu_x + mcu_w <= max_x) {
          win_w = mcu_w;
        } else {
          win_w = min_w;
        }
        
        if (mcu_y + mcu_h <= max_y) {
          win_h = mcu_h;
        } else {
          win_h = min_h;
        }
        
        uint16_t mcu_pixels = win_w * win_h;
        
        if ((mcu_x + win_w) <= gfx.getWidth() && ( mcu_y + win_h) <= gfx.getHeight()) {
          
          gfx.setGRAM(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
          gfx.WrGRAMs16232(p_img, mcu_pixels);
          
        } else if ((mcu_y + win_h) >= gfx.getHeight()) {
          JpegDec.abort();
        }
      }
    }

    Leave a comment:


  • studio81
    replied
    Great thanks!

    Leave a comment:


  • pauleilio
    replied
    Hi Martin,

    No, you can do it quickly in blocks using gfx.setGRAM and gfx.WrGRAM.

    This is the code I used with the library.

    Code:
    void jpegRender(int xpos, int ypos) {
    
      // retrieve infomration about the image
      uint16_t  *pImg;
      uint16_t mcu_w = JpegDec.MCUWidth;
      uint16_t mcu_h = JpegDec.MCUHeight;
      uint32_t max_x = JpegDec.width;
      uint32_t max_y = JpegDec.height;
    
      uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
      uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
    
      uint32_t win_w = mcu_w;
      uint32_t win_h = mcu_h;
    
      uint32_t drawTime = millis();
    
      max_x += xpos;
      max_y += ypos;
    
      while ( JpegDec.read()) {
    
        pImg = JpegDec.pImage;
        int mcu_x = JpegDec.MCUx * mcu_w + xpos;
        int mcu_y = JpegDec.MCUy * mcu_h + ypos;
        if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
        else win_w = min_w;
        if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
        else win_h = min_h;
        uint16_t mcu_pixels = win_w * win_h;
        if ( ( mcu_x + win_w) <= gfx.getWidth() && ( mcu_y + win_h) <= gfx.getHeight())
        {
          gfx.setGRAM(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
          gfx.WrGRAMs16232(pImg, mcu_pixels);
        }
        else if ( ( mcu_y + win_h) >= gfx.getHeight()) JpegDec.abort();
      }
      drawTime = millis() - drawTime;
    }
    But you will have to use the BETA GFX4d library for this as there are 2 commands which are not in your version which I have attached below.

    Best regards

    Paul
    Attached Files

    Leave a comment:


  • studio81
    replied
    Hi Paul,

    Thanks! Looks promising. I'll have a try first, the example from JPEGDecoder is pretty clear. Maybe a pointer, do I have to set every pixel with gfx.PutPixel or is there a way to set a buffer and then update all the pixels at once?

    cheers,

    Martin

    Leave a comment:


  • pauleilio
    replied
    Hello Martin,

    Welcome to the forum.

    We have used this library with some good results.

    https://github.com/Bodmer/JPEGDecoder

    There are some modifications that need doing to integrate it with GFX4d but I can do an example if you think this would work for you. It will mean that you could send a JPEG to the IoD which takes less time than a GCI.

    I hope this helps

    Best regards

    Paul

    Leave a comment:


  • studio81
    started a topic cli tool for gci conversion

    cli tool for gci conversion

    Hi,

    I have a GEN4-IOD32T and i would like to show an (static) image of Google Maps using the static maps api. To be able to show the current GPS position I need to update the image. Grabbing the image and serving it over http is no problem, but it needs to be converted to gci first. Is there a command line tool available to convert jpg,png or bmp to gci so it can run from i.e. NodeJS?

    thanks

    Martin
Working...
X