I am trying to draw a png at a given location on an LCD. I have found the following example code which works and I can change the the location of the LCD but I want to be able to change the location dynamically by passing integer variables to the function but it looks like the function I call, then calls another function. I confess, this code is completely beyond me but I have tried to understand it. Could someone explain the workings of the code so that I might figure it out?
#include <PNGdec.h>
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
#include <SPI.h>
#include "world.h"
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
// Invoke library
TFT_eSPI tft = TFT_eSPI(LCD_HEIGHT, LCD_WIDTH);
PNG png;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
void drawWorld() {
int16_t rc = png.openFLASH((uint8_t *)world, sizeof(world), mapDraw);
//int rc;
//rc = png.open("world.png", myOpen, myClose, myRead, mySeek, PNGDrawLarge);
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
}
}
//=========================================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 mapDraw(PNGDRAW *pDraw) {
uint16_t lineBuffer[320];
png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff);
tft.pushImage(6, 5 + pDraw->y, pDraw->iWidth, 1, lineBuffer);
}