Comments (7)
You'll find the answers in the example sketches for the PNGdec and SPI display libraries. You haven't shown me where the problem is. Depending on the image size, you may not be able to decode it entirely into SRAM and instead will need to send it to the display 1 line at a time.
from unziplib.
Hi Larry,
here is my trial about that unzip then decode a PNG then send to TFT
//
// ZIP library example sketch
//
// Written by Larry Bank
// June 9, 2021
//
// This example shows how to do the following:
// - Step through all of the files in a ZIP archive
// - Display the name of each file
// - Allocate a buffer for the uncompressed file size
// - Read (decompress) the data into the buffer
// - Display the results (in this case a BMP file) on the SPI LCD
//
#include <unzipLIB.h>
UNZIP zip; // statically allocate the UNZIP structure (41K)
#include <TFT_eSPI.h> // Hardware-specific library
#include <PNGdec.h> // Include the PNG decoder library
PNG png;
#define MAX_IMAGE_WIDTH 480 // Adjust for your images
int16_t xpos = 0;
int16_t ypos = 0;
#include <FS.h>
#include <SD.h>
bool SD_present = false;
#define DEBUG 0
#if DEBUG==1
#define debug(x) Serial.print(x) // can use now debug() instead od debug()
#define debugln(x) Serial.println(x)
#else // if DEBUG is set to 0
#define debug(x) // now debug(x) is no more interpreted
#define debugln(x)
#endif
// Set these to the appropriate values for your SPI LCD display
// -1 means the pin is not connected
#define TFT_MISO 39 //MIS0 on PIN 39 for 2nd version board
#define TFT_CS 4
#define TFT_RST 26
#define TFT_DC 25
#define TFT_SCLK 18
#define TFT_MOSI 23
//SD CARD
#define sck 18 //Clk_SD
#define miso 39 //MIS0 on PIN 39 for 2nd version board
#define mosi 23 //MOSI
#define cs 5 //CS_SD
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library for LCD main screen
// Functions to access a file on the SD card
static File myfile;
//
// Callback functions needed by the unzipLIB to access a file system
// The library has built-in code for memory-to-memory transfers, but needs
// these callback functions to allow using other storage media
//
void * myOpen(const char *filename, int32_t *size)
{
myfile = SD.open(filename);
*size = myfile.size();
return (void *)&myfile;
}
void myClose(void *p)
{
ZIPFILE *pzf = (ZIPFILE *)p;
File *f = (File *)pzf->fHandle;
if (f) f->close();
}
int32_t myRead(void *p, uint8_t *buffer, int32_t length)
{
ZIPFILE *pzf = (ZIPFILE *)p;
File *f = (File *)pzf->fHandle;
return f->read(buffer, length);
}
int32_t mySeek(void *p, int32_t position, int iType)
{
ZIPFILE *pzf = (ZIPFILE *)p;
File *f = (File *)pzf->fHandle;
if (iType == SEEK_SET)
return f->seek(position);
else if (iType == SEEK_END)
{
return f->seek(position + pzf->iSize);
}
else
{ // SEEK_CUR
long l = f->position();
return f->seek(l + position);
}
}
//====================================================================================
// 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);
}
void setup()
{
Serial.begin(115200);
delay(1000); // give Serial a little time to start
// Init ialise FS
#define FileSys SD
// Initialise SD
if(!SD.begin(5))
// if(!FileSys.begin(5))
{
debugln(F("Card failed or not present, no SD Card data logging possible..."));
SD_present = false;
//return;
}
else
{
debugln(F("Card initialised... file access enabled..."));
SD_present = true;
}
if(SD_present == true)
{
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE)
{
debugln("No SD card attached");
return;
}
debug("SD Card Type: ");
if(cardType == CARD_MMC)
{
debugln("MMC");
}
else if(cardType == CARD_SD)
{
debugln("SDSC");
}
else if(cardType == CARD_SDHC)
{
debugln("SDHC");
}
else
{
debugln("UNKNOWN");
}
#if DEBUG==1
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
#endif
debug("SD Card Size: %lluMB\n");
debugln(cardSize);
}
// Initialise the TFT
debug("initializing LCD now");
tft.begin();
tft.fillScreen(TFT_BLACK);
tft.setRotation(1); // landscape
pinMode( TFT_BL , OUTPUT); // LED back-light
digitalWrite(TFT_BL, HIGH);
tft.setTextColor(TFT_YELLOW);
tft.setTextSize(2);
tft.println("welcome...");
}
void loop()
{
int rc, x, y;
char szComment[256], szName[256];
unz_file_info fi;
uint8_t *ucBitmap; // temp storage for each icon bitmap
File dir = SD.open("/");
while (true)
{
File entry = dir.openNextFile();
if (!entry) break;
if (entry.isDirectory() == false)
{
//const char *name = entry.name();
const char *name = entry.path();
const int len = strlen(name);
if (len > 3 && strcmp(name + len - 3, "ZIP") == 0)
{
Serial.print("File: ");
Serial.println(name);
rc = zip.openZIP(name, myOpen, myClose, myRead, mySeek);
if (rc == UNZ_OK)
{
Serial.print("found zip file: ");
Serial.println(name);
rc = zip.getGlobalComment(szComment, sizeof(szComment));
Serial.print("Global comment: ");
Serial.println(szComment);
zip.gotoFirstFile();
rc = UNZ_OK;
while (rc == UNZ_OK) // Display all files contained in the archive
{
rc = zip.getFileInfo(&fi, szName, sizeof(szName), NULL, 0, szComment, sizeof(szComment));
if (rc == UNZ_OK)
{
Serial.print(szName);
Serial.print(" - ");
Serial.print(fi.compressed_size, DEC);
Serial.print("/");
Serial.println(fi.uncompressed_size, DEC);
ucBitmap = (uint8_t *)malloc(fi.uncompressed_size); // allocate enough to hold the bitmap
if (ucBitmap != NULL) // malloc succeeded (it should, these bitmaps are only 2K bytes each)
{
zip.openCurrentFile(); // if you don't open it explicitly, readCurrentFile will fail with UNZ_PARAMERROR
rc = zip.readCurrentFile(ucBitmap, fi.uncompressed_size); // we know the uncompressed size of these BMP images
if (rc != fi.uncompressed_size)
{
Serial.print("Read error, rc=");
Serial.println(rc, DEC);
}
String Name(szName);
Name="/"+Name;
Serial.print("Name=");Serial.println(Name);
if (Name.endsWith(".png"))
{
// Pass support callback function names to library
int16_t rc = png.open(Name.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");
}
}
}
free(ucBitmap); // finished with this bitmap
}
delay(10); // Allow time to see it happen, otherwise it will zip by too quickly
}
rc = zip.gotoNextFile();
}
zip.closeZIP();
}
}
}
// while (1) {};
}
can you guide me in the right direction to solve this ?
The PNG are OK 480*320 (already tested with PNGde)c but now I was expecting to unzip directly from SDcard instead of have to place unzipped on the SD
Kind regards
from unziplib.
I haven't tried to do what you're doing, but PNG images use the same compression as ZIP files (FLATE), so there's no point in putting them in ZIP files. If you still want to do this, you will need to have the PNG read file function call the ZIP read function - this may not even work.
from unziplib.
Hi Larry,
Thanks for your explanation about PNG
The reasons to do that are :
This is for a SLA 3D printer, the files are many PNG
1/ slicer software currently export a ZIP with all PNG
2/ as I want to use SD but with a hosted webservice in ESP32 it is much easier to move 1 ZIP file to subdirectory I need rather than doing unzipping and transfer one by one to embedded SD,At that time all SLA printer need to pull out SD to place the files then put back in SD slot,
3/ All the printer function I am designing are accessible on computer on phone using WIFI
SO, it would be great if you can give me some suggestion to unzip then PNG decode then send to TFT (TFT_espi from Bodmer would be the best)
What I already do is with unzipped files in the subdirectory
from unziplib.
Hi Larry
"you will need to have the PNG read file function call the ZIP read function "
can you, please, give me a sample code to do that ?
Best regards
from unziplib.
Sorry, you're on your own with this project. I'm too busy with other things at the moment.
from unziplib.
OK, good to ear you are busy anyway.
Do you think this is possible to do it ? if yes what could be your price to open the way for me ?
I am expecting to lauch this project/product on crowdfunding in few it would be great to add this particular function
from unziplib.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unziplib.