Hello i've try to decode JPG image from FS so, i create and upload spiffs image (using /data directory and Arduino Ide Plugin )
On every jpg i've same error: "pjpeg_decode_init() failed with status 19"
here is my same code:
#include <TFT_eSPI.h> // Hardware-specific library#include <SPI.h>#include "GfxUi.h"TFT_eSPI tft = TFT_eSPI(); // Invoke custom library#define DEBUG#define LOAD_SPIFFSGfxUi ui = GfxUi(&tft);void writeFile(fs::FS &fs, const char * path, const char * message);void readFile(fs::FS &fs, const char * path);void listDir(fs::FS &fs, const char * dirname, uint8_t levels);void setup(void){ Serial.begin(115200); Serial.print("Start"); SPIFFS.begin(true); tft.begin(); tft.setRotation(3); tft.fillScreen(TFT_BLACK); listDir(SPIFFS, "/", 0); fs::File jpeg = SPIFFS.open("/star.jpg", "r"); //readFile(SPIFFS, "/star.jpg"); boolean decoded = JpegDec.decodeFsFile(jpeg); Serial.println("==============="); Serial.println("JPEG image info"); Serial.println("==============="); Serial.print ("Width :"); Serial.println(JpegDec.width); Serial.print ("Height :"); Serial.println(JpegDec.height); Serial.print ("Components :"); Serial.println(JpegDec.comps); Serial.print ("MCU / row :"); Serial.println(JpegDec.MCUSPerRow); Serial.print ("MCU / col :"); Serial.println(JpegDec.MCUSPerCol); Serial.print ("Scan type :"); Serial.println(JpegDec.scanType); Serial.print ("MCU width :"); Serial.println(JpegDec.MCUWidth); Serial.print ("MCU height :"); Serial.println(JpegDec.MCUHeight); Serial.println("==============="); Serial.println("");}void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ Serial.printf("Listing directory: %s\r\n", dirname); File root = fs.open(dirname); if(!root){ Serial.println("- failed to open directory"); return; } if(!root.isDirectory()){ Serial.println(" - not a directory"); return; } File file = root.openNextFile(); while(file){ if(file.isDirectory()){ Serial.print(" DIR : "); Serial.println(file.name()); if(levels){ listDir(fs, file.name(), levels -1); } } else { Serial.print(" FILE: "); Serial.print(file.name()); Serial.print("\tSIZE: "); Serial.println(file.size()); } file = root.openNextFile(); }}void readFile(fs::FS &fs, const char * path){ Serial.printf("Reading file: %s\r\n", path); File file = fs.open(path); if(!file || file.isDirectory()){ Serial.println("- failed to open file for reading"); return; } Serial.println("- read from file:"); while(file.available()){ Serial.write(file.read()); }}void writeFile(fs::FS &fs, const char * path, const char * message){ Serial.printf("Writing file: %s\r\n", path); File file = fs.open(path, FILE_WRITE); if(!file){ Serial.println("- failed to open file for writing"); return; } if(file.print(message)){ Serial.println("- file written"); } else { Serial.println("- frite failed"); }}void loop() {}Output from serial:
Listing directory: / FILE: /logo.jpg SIZE: 16346 FILE: /arduino.jpg SIZE: 8426 FILE: /star.jpg SIZE: 3853pjpeg_decode_init() failed with status 19 <--- here is===============JPEG image info===============Width :0Height :0Components :0MCU / row :0MCU / col :0Scan type :0MCU width :0MCU height :0===============- 219 is PJPG_NOT_JPEGgithub.com/Bodmer/JPEGDecoder/blob/master/src/picojpeg.h2018-09-26 18:55:36 +00:00CommentedSep 26, 2018 at 18:55
- 1you should add a test
if (jpeg)for file existence.2018-09-26 18:58:20 +00:00CommentedSep 26, 2018 at 18:58
1 Answer1
as far as I can determine uploading to SPIFFS via the Arduino IDE is broken as of the beginning of 2018. The files are uploaded but are corrupted on a read. There are a fewfixes reported. I am using a core from Dec 2017 and that works fine.
Explore related questions
See similar questions with these tags.