Add libraries, picocalc notes.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
|
||||
// This example renders a png file that is stored in a FLASH array
|
||||
// using the PNGdec library (available via library manager).
|
||||
|
||||
// Image files can be converted to arrays using the tool here:
|
||||
// https://notisrac.github.io/FileToCArray/
|
||||
// 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 inatance
|
||||
|
||||
#define MAX_IMAGE_WIDTH 240 // Adjust for your images
|
||||
|
||||
int16_t xpos = 0;
|
||||
int16_t ypos = 0;
|
||||
|
||||
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
|
||||
#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);
|
||||
}
|
||||
11425
libraries/TFT_eSPI/examples/PNG Images/Flash_PNG/panda.h
Normal file
11425
libraries/TFT_eSPI/examples/PNG Images/Flash_PNG/panda.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,86 @@
|
||||
|
||||
// This example renders a png file that is stored in a FLASH array
|
||||
// using the PNGdec library (available via library manager).
|
||||
|
||||
// The example png is encoded as ARGB 8 bits per pixel with indexed colour
|
||||
// It was created using GIMP and has a transparent background area.
|
||||
|
||||
// Image files can be converted to arrays using the tool here:
|
||||
// https://notisrac.github.io/FileToCArray/
|
||||
// To use this tool:
|
||||
// 1. Drag and drop PNG image 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
|
||||
// (alternatively use the "Copy to clipboard" and paste into a new tab)
|
||||
// 5. Open the sketch in IDE
|
||||
// 6. Include the header file containing the array (SpongeBob.h in this example)
|
||||
|
||||
// Include the PNG decoder library, available via the IDE library manager
|
||||
#include <PNGdec.h>
|
||||
|
||||
// Include image array
|
||||
#include "SpongeBob.h"
|
||||
|
||||
PNG png; // PNG decoder instance
|
||||
|
||||
#define MAX_IMAGE_WIDTH 240 // Sets rendering line buffer lengths, adjust for your images
|
||||
|
||||
// Include the TFT library - see https://github.com/Bodmer/TFT_eSPI for library information
|
||||
#include "SPI.h"
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
// Position variables must be global (PNGdec does not handle position coordinates)
|
||||
int16_t xpos = 0;
|
||||
int16_t ypos = 0;
|
||||
|
||||
//====================================================================================
|
||||
// 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()
|
||||
{
|
||||
uint16_t pngw = 0, pngh = 0; // To store width and height of image
|
||||
|
||||
int16_t rc = png.openFLASH((uint8_t *)bob, sizeof(bob), pngDraw);
|
||||
|
||||
if (rc == PNG_SUCCESS) {
|
||||
Serial.println("Successfully opened png file");
|
||||
pngw = png.getWidth();
|
||||
pngh = png.getHeight();
|
||||
Serial.printf("Image metrics: (%d x %d), %d bpp, pixel type: %d\n", pngw, pngh, png.getBpp(), png.getPixelType());
|
||||
|
||||
tft.startWrite();
|
||||
uint32_t dt = millis();
|
||||
rc = png.decode(NULL, 0);
|
||||
tft.endWrite();
|
||||
Serial.print(millis() - dt); Serial.println("ms");
|
||||
tft.endWrite();
|
||||
|
||||
// png.close(); // Required for files, not needed for FLASH arrays
|
||||
}
|
||||
|
||||
delay(250);
|
||||
|
||||
// Randomly change position
|
||||
xpos = random(tft.width() - pngw);
|
||||
ypos = random(tft.height() - pngh);
|
||||
|
||||
// Fill screen with a random colour at random intervals
|
||||
if (random(100) < 20) tft.fillScreen(random(0x10000));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
|
||||
// PNGdec support functions
|
||||
|
||||
//=========================================v==========================================
|
||||
// pngDraw: Callback function to draw pixels to the display
|
||||
//====================================================================================
|
||||
// This function will be called during decoding of the png file to render each image
|
||||
// line to the TFT. PNGdec generates the image line and a 1bpp mask.
|
||||
void pngDraw(PNGDRAW *pDraw) {
|
||||
uint16_t lineBuffer[MAX_IMAGE_WIDTH]; // Line buffer for rendering
|
||||
uint8_t maskBuffer[1 + MAX_IMAGE_WIDTH / 8]; // Mask buffer
|
||||
|
||||
png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff);
|
||||
|
||||
if (png.getAlphaMask(pDraw, maskBuffer, 255)) {
|
||||
// Note: pushMaskedImage is for pushing to the TFT and will not work pushing into a sprite
|
||||
tft.pushMaskedImage(xpos, ypos + pDraw->y, pDraw->iWidth, 1, lineBuffer, maskBuffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
|
||||
// This example if for processors with LittleFS capability (e.g. RP2040,
|
||||
// ESP32, ESP8266). It renders a png file that is stored in LittleFS
|
||||
// using the PNGdec library (available via library manager).
|
||||
|
||||
// The test image is in the sketch "data" folder (press Ctrl+K to see it).
|
||||
// You must upload the image to LittleFS using the Arduino IDE Tools Data
|
||||
// Upload menu option (you may need to install extra tools for that).
|
||||
|
||||
// Don't forget to use the Arduino IDE Tools menu to allocate a LittleFS
|
||||
// memory partition before uploading the sketch and data!
|
||||
|
||||
#include <LittleFS.h>
|
||||
#define FileSys LittleFS
|
||||
|
||||
// Include the PNG decoder library
|
||||
#include <PNGdec.h>
|
||||
|
||||
PNG png;
|
||||
#define MAX_IMAGE_WIDTH 240 // Adjust for your images
|
||||
|
||||
int16_t xpos = 0;
|
||||
int16_t ypos = 0;
|
||||
|
||||
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
|
||||
#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 FS
|
||||
if (!FileSys.begin()) {
|
||||
Serial.println("LittleFS initialisation failed!");
|
||||
while (1) yield(); // Stay here twiddling thumbs waiting
|
||||
}
|
||||
|
||||
// Initialise the TFT
|
||||
tft.begin();
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
Serial.println("\r\nInitialisation done.");
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
// Loop
|
||||
//====================================================================================
|
||||
void loop()
|
||||
{
|
||||
// Scan LittleFS and load any *.png files
|
||||
File root = LittleFS.open("/", "r");
|
||||
while (File file = root.openNextFile()) {
|
||||
String strname = file.name();
|
||||
strname = "/" + strname;
|
||||
Serial.println(file.name());
|
||||
// If it is not a directory and filename ends in .png then load it
|
||||
if (!file.isDirectory() && strname.endsWith(".png")) {
|
||||
// Pass support callback function names to library
|
||||
int16_t rc = png.open(strname.c_str(), pngOpen, pngClose, pngRead, pngSeek, pngDraw);
|
||||
if (rc == PNG_SUCCESS) {
|
||||
tft.startWrite();
|
||||
Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
|
||||
uint32_t dt = millis();
|
||||
if (png.getWidth() > MAX_IMAGE_WIDTH) {
|
||||
Serial.println("Image too wide for allocated line buffer size!");
|
||||
}
|
||||
else {
|
||||
rc = png.decode(NULL, 0);
|
||||
png.close();
|
||||
}
|
||||
tft.endWrite();
|
||||
// How long did rendering take...
|
||||
Serial.print(millis()-dt); Serial.println("ms");
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Here are the callback functions that the decPNG library
|
||||
// will use to open files, fetch data and close the file.
|
||||
|
||||
File pngfile;
|
||||
|
||||
void * pngOpen(const char *filename, int32_t *size) {
|
||||
Serial.printf("Attempting to open %s\n", filename);
|
||||
pngfile = FileSys.open(filename, "r");
|
||||
*size = pngfile.size();
|
||||
return &pngfile;
|
||||
}
|
||||
|
||||
void pngClose(void *handle) {
|
||||
File pngfile = *((File*)handle);
|
||||
if (pngfile) pngfile.close();
|
||||
}
|
||||
|
||||
int32_t pngRead(PNGFILE *page, uint8_t *buffer, int32_t length) {
|
||||
if (!pngfile) return 0;
|
||||
page = page; // Avoid warning
|
||||
return pngfile.read(buffer, length);
|
||||
}
|
||||
|
||||
int32_t pngSeek(PNGFILE *page, int32_t position) {
|
||||
if (!pngfile) return 0;
|
||||
page = page; // Avoid warning
|
||||
return pngfile.seek(position);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
@@ -0,0 +1,107 @@
|
||||
|
||||
// This example if for processors with LittleFS capability (e.g. RP2040,
|
||||
// ESP32, ESP8266). It renders a png file that is stored in LittleFS
|
||||
// using the PNGdec library (available via library manager).
|
||||
|
||||
// It uses DMA to send image data to the TFT while the decoding takes
|
||||
// place. The processor and display combination must support DMA to
|
||||
// run this sketch! The decode time dominates so DMA is mainly an advantage
|
||||
// for slow display interface speeds.
|
||||
|
||||
// The test image is in the sketch "data" folder (press Ctrl+K to see it).
|
||||
// You must upload the image to LittleFS using the Arduino IDE Tools Data
|
||||
// Upload menu option (you may need to install extra tools for that).
|
||||
|
||||
// Don't forget to use the Arduino IDE Tools menu to allocate a LittleFS
|
||||
// memory partition before uploading the sketch and data!
|
||||
|
||||
#include <LittleFS.h>
|
||||
#define FileSys LittleFS
|
||||
|
||||
// Include the PNG decoder library
|
||||
#include <PNGdec.h>
|
||||
|
||||
PNG png;
|
||||
#define MAX_IMAGE_WIDTH 240 // Adjust for your images
|
||||
|
||||
int16_t xpos = 0;
|
||||
int16_t ypos = 0;
|
||||
|
||||
// Include the TFT library https://github.com/Bodmer/TFT_eSPI
|
||||
#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 FS
|
||||
if (!FileSys.begin()) {
|
||||
Serial.println("LittleFS initialisation failed!");
|
||||
while (1) yield(); // Stay here twiddling thumbs waiting
|
||||
}
|
||||
|
||||
// Initialise the TFT
|
||||
tft.begin();
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.initDMA();
|
||||
|
||||
Serial.println("\r\nInitialisation done.");
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
// Loop
|
||||
//====================================================================================
|
||||
void loop()
|
||||
{
|
||||
// Scan LittleFS and load any *.png files
|
||||
File root = LittleFS.open("/", "r");
|
||||
while (File file = root.openNextFile()) {
|
||||
String strname = file.name();
|
||||
strname = "/" + strname;
|
||||
Serial.println(file.name());
|
||||
// If it is not a directory and filename ends in .png then load it
|
||||
if (!file.isDirectory() && strname.endsWith(".png")) {
|
||||
// Pass support callback function names to library
|
||||
int16_t rc = png.open(strname.c_str(), pngOpen, pngClose, pngRead, pngSeek, pngDraw);
|
||||
if (rc == PNG_SUCCESS) {
|
||||
tft.startWrite();
|
||||
Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
|
||||
uint32_t dt = millis();
|
||||
if (png.getWidth() > MAX_IMAGE_WIDTH) {
|
||||
Serial.println("Image too wide for allocated lin buffer!");
|
||||
}
|
||||
else {
|
||||
rc = png.decode(NULL, 0);
|
||||
png.close();
|
||||
}
|
||||
tft.endWrite();
|
||||
// How long did rendering take...
|
||||
Serial.print(millis()-dt); Serial.println("ms");
|
||||
}
|
||||
}
|
||||
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];
|
||||
static uint16_t dmaBuffer[MAX_IMAGE_WIDTH]; // static so buffer persists after fn exit
|
||||
|
||||
png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff);
|
||||
tft.pushImageDMA(xpos, ypos + pDraw->y, pDraw->iWidth, 1, lineBuffer, dmaBuffer);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Here are the callback functions that the decPNG library
|
||||
// will use to open files, fetch data and close the file.
|
||||
|
||||
File pngfile;
|
||||
|
||||
void * pngOpen(const char *filename, int32_t *size) {
|
||||
Serial.printf("Attempting to open %s\n", filename);
|
||||
pngfile = FileSys.open(filename, "r");
|
||||
*size = pngfile.size();
|
||||
return &pngfile;
|
||||
}
|
||||
|
||||
void pngClose(void *handle) {
|
||||
File pngfile = *((File*)handle);
|
||||
if (pngfile) pngfile.close();
|
||||
}
|
||||
|
||||
int32_t pngRead(PNGFILE *page, uint8_t *buffer, int32_t length) {
|
||||
if (!pngfile) return 0;
|
||||
page = page; // Avoid warning
|
||||
return pngfile.read(buffer, length);
|
||||
}
|
||||
|
||||
int32_t pngSeek(PNGFILE *page, int32_t position) {
|
||||
if (!pngfile) return 0;
|
||||
page = page; // Avoid warning
|
||||
return pngfile.seek(position);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
Reference in New Issue
Block a user