Render image in graphical display

Asked

Viewed 11 times

1

Program for IDE Arduino, ESP32. Objective is to have two functions to render in the graphic display, the logo, previously static image in the FLASH memory or preset image via UPLOAD.

The drawBitmap function, works as expected, reads a file stored in the FLASH and renders correctly on the screen.

//chamada drawBitmap(0,0,logow81h25branco, 81, 25,TFT_RED);
void drawBitmap(int x, int y, const uint16_t* bitmap, int bw, int bh,uint16_t color_bg) {

   int register buffidx = 0;
   int register row;
   int register col;
   int w = bw + y;
   int h = bh + x;

     for (row = x; row < h; row++) { // For each scanline...
          for (col = y; col < w; col++) { // For each pixel...
              //To read from Flash Memory, pgm_read_XXX is required.
              //Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address

            uint16_t color = pgm_read_word(bitmap + buffidx);
            if(color_bg != color)tft.drawPixel(col, row, color);   //pixel só cores diferente do fundo  
            buffidx++;
         } // end pixel
      }
    } // drawBitmap

The drawlogo function aims to read a file that was UPLOAD earlier. The "pgm_read_word" statement was replaced by "word(Fileread.read(),Fileread.read())" but, despite no errors, it rendered wrong on the screen. The contents of the file, is identical to the FLASH memory file.

void drawlogo(int x, int y, int bw, int bh,uint16_t color_bg)
{
     int register row;
     int register col;
     int w = bw + y;
     int h = bh + x;

     if (SPIFFS.exists("/data/logoinicial.txt")) { //lê logotipo em formato 16bits

      File FileRead = SPIFFS.open("/data/logoinicial.txt", "r");
       while (FileRead.available() > 0) {
          for (row = x; row < h; row++) { // For each scanline...
            for (col = y; col < w; col++) { // For each pixel...
                                        
              uint16_t color = word(FileRead.read(),FileRead.read());//lê 2 byte

              if(color_bg != color)tft.drawPixel(col, row, color); //pixel só cores diferente do fundo  
              
     } // end pixel
    } //end scanline
   }//while   
  FileRead.close();       
 }//SPIFFS.exists                    
}//void drawlogo

The BMP image is converted into 16bit data using the LCD Image Converter software [http://www.riuson.com/lcd-image-converter] and referenced in the code as below

const uint16_t logow81h25branco[6075] PROGMEM = {
 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 
 0xffff, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 
 0xffff, 0xffff, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 
 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0x3b98, 0xffff, 0xffff, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 
 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0xffff, 0xffff, 0x3b98, 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 
 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0xffff, 0xffff, 
 0xffff, 0xffff, 0xffff, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98, 
 0x3b98, 0x3b98, 0x3b98, 0x3b98, 0x3b98
 };

1 answer

0

Seems to me a problem of Undefined behavior along those lines

uint16_t color = word(FileRead.read(),FileRead.read());//lê 2 byte

If you leave the reading order defined via code will probably solve the problem.

byte b1 = FileRead.read();
byte b2 = FileRead.read();
uint16_t color = word(b1, b2);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.