TFT_espi type conversion error when trying to display png (flash_png panda example)

I’m trying to run the ‘flash_png’ example from TFT_espi that’s supposed to display a png image of a panda, but am hitting a compilation error.

I’ve tried to include the compiler output below but I’m sorry, the formatting is messed up. I can try to provide any other info needed to diagnose this.

I have installed the pngDEC library.

As best I can tell the loop code is calling the function that draws each line of the image. It’s trying to cast the result as an int but the function is typed as void.

If I change the function type to int, I get one single line of the png rendering on the screen.

I haven’t modified anything so I’m wondering if this is perhaps a version incompatibility thing?

Using a inexpensive wroom esp32 and an st7796 driven tft screen in serial mode. The other examples I’ve tested thusfar (text, color, animations) have all worked fine.

Thank you for any ideas.

C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2025918-26972-1ofbt04.c2xw\Flash_PNG\Flash_PNG.ino:55:63: error: invalid conversion from 'void ()(PNGDRAW)' {aka 'void ()(png_draw_tag)'} to 'int ()(PNGDRAW)' {aka 'int ()(png_draw_tag)'} [-fpermissive]

55 |   int16_t rc = png.openFLASH((uint8_t *)panda, sizeof(panda), pngDraw);
  |                                                               ^~~~~~~

  |                                                               |

  |                                                               void (*)(PNGDRAW*) {aka void (*)(png_draw_tag*)}
In file included from C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved2025918-26972-1ofbt04.c2xw\Flash_PNG\Flash_PNG.ino:20:

c:\Users\user\Documents\Arduino\libraries\PNGdec\src/PNGdec.h:174:69: note:   initializing argument 3 of 'int PNG::openFLASH(uint8_t*, int, int ()(PNGDRAW))'

174 |     int openFLASH(uint8_t *pData, int iDataSize, PNG_DRAW_CALLBACK *pfnDraw);
  |                                                  ~~~~~~~~~~~~~~~~~~~^~~~~~~
exit status 1

Compilation error: invalid conversion from 'void ()(PNGDRAW)' {aka 'void ()(png_draw_tag)'} to 'int ()(PNGDRAW)' {aka 'int ()(png_draw_tag)'} [-fpermissive]

Please show your code using a code tags. Take note that you have to send exact YOUR code rather than example from the library

1 Like





// This example renders a png file that is stored in a FLASH array

// using the PNGdec library (available via library manager).




// Note: The PNGDEC required lots of RAM to work (~40kbytes) so

// this sketch is will not run on smaller memory processors (e.g.

// ESP8266, STM32F103 etc.)




// Image files can be converted to arrays using the tool here:

// 


// To use this tool:

//   1. Drag and drop file on "Browse..." button

//   2. Tick box "Treat as binary"

//   3. Click "Convert"

//   4. Click "Save as file" and move the header file to sketch folder

//   5. Open the sketch in IDE

//   6. Include the header file containing the array (panda.h in this example)




// Include the PNG decoder library

#include <PNGdec.h>

#include "panda.h" // Image is stored here in an 8-bit array




PNG png; // PNG decoder instance




#define MAX_IMAGE_WIDTH 240 // Adjust for your images




int16_t xpos = 0;

int16_t ypos = 0;




// Include the TFT library 


#include "SPI.h"

#include <TFT_eSPI.h>              // Hardware-specific library

TFT_eSPI tft = TFT_eSPI();         // Invoke custom library




//====================================================================================

//                                    Setup

//====================================================================================

void setup()

{

  Serial.begin(115200);

  Serial.println("\n\n Using the PNGdec library");




  // Initialise the TFT

  tft.begin();

  tft.fillScreen(TFT_BLACK);




  Serial.println("\r\nInitialisation done.");

}




//====================================================================================

//                                    Loop

//====================================================================================

void loop()

{

  int16_t rc = png.openFLASH((uint8_t *)panda, sizeof(panda), pngDraw);

  if (rc == PNG_SUCCESS) {

    Serial.println("Successfully opened png file");

    Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());

    tft.startWrite();

    uint32_t dt = millis();

    rc = png.decode(NULL, 0);

    Serial.print(millis() - dt); Serial.println("ms");

    tft.endWrite();

    // png.close(); // not needed for memory->memory decode

  }

  delay(3000);

  tft.fillScreen(random(0x10000));

}





//=========================================v==========================================

//                                      pngDraw

//====================================================================================

// This next function will be called during decoding of the png file to

// render each image line to the TFT.  If you use a different TFT library

// you will need to adapt this function to suit.

// Callback function to draw pixels to the display

void pngDraw(PNGDRAW *pDraw) {

  uint16_t lineBuffer[MAX_IMAGE_WIDTH];

  png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff);

  tft.pushImage(xpos, ypos + pDraw->y, pDraw->iWidth, 1, lineBuffer);

}

Thank you, I have included the code above.

try to add a return value to your function: