Skip to content

Commit bba81c8

Browse files
committed
Update for ESP8266 and latest Arduino board support package
ESP8266 board support package 2.3.0 or later required
1 parent c0fad79 commit bba81c8

File tree

8 files changed

+64
-50
lines changed

8 files changed

+64
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Arduino JPEGDecoder library
33

44
News: October 2019 - *I have created a new Arduino compatible [Jpeg decoder library here.](https://github.com/Bodmer/TJpg_Decoder) This new library is based on TinyJpegDec, this is 60% faster on 32bit processors, it also has a much simpler interface.*
55

6-
This Arduino library supports the rendering of Jpeg files stored both on SD card and in arrays within program memory (FLASH) onto a TFT display. In addition images stored in the SPIFFS (or LittleFS) Flash filing system or "PROGMEM" arrays can be used with the ESP8266 and ESP32 processors. For the ESP8266 use board Core 2.3.0 (or later) in the Arduino IDE to avoid File definition conflicts if the SPIFFS and SD libraries are used together.
6+
This Arduino library supports the rendering of Jpeg files stored both on SD card and in arrays within program memory (FLASH) onto a TFT display. In addition images stored in the LittleFS Flash filing system or "PROGMEM" arrays can be used with the RP2040, ESP8266 and ESP32 processors. For the ESP8266 use board Core 2.3.0 (or later) in the Arduino IDE to avoid File definition conflicts if the SPIFFS and SD libraries are used together.
77

88
The library works on the Arduino Due, ESP32 and ESP8266 (e.g. NodeMCU 1.0). Users have also reported success with the STM32 based processor boards.
99

examples/Other libraries/SPIFFS_Jpeg/SPIFFS_functions.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//====================================================================================
99
// Print a SPIFFS directory list (root directory)
1010
//====================================================================================
11-
#ifdef ESP8266
11+
#ifdef ARDUINO_ARCH_ESP8266
1212
void listFiles(void) {
1313
Serial.println();
1414
Serial.println("SPIFFS files found:");

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "JPEGDecoder",
3-
"version": "1.8.1",
3+
"version": "2.0.0",
44
"keywords": "jpeg, jpg, decoder, TFT",
55
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=JPEGDecoder
2-
version=1.8.1
2+
version=2.0.0
33
author=Bodmer <[email protected]>, Makoto Kurauchi, Rich Geldreich
44
maintainer=Bodmer
55
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0

src/JPEGDecoder.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Bodmer (20/1/17): Prevent deleting the pImage pointer twice (causes an exception
3434
tidy up code.
3535
3636
Bodmer (24/1/17): Correct greyscale images, update examples
37+
38+
Bodmer (26/2/22): Removed deprecated SPIFFS
3739
*/
3840

3941
#include "JPEGDecoder.h"
@@ -65,18 +67,18 @@ uint8_t JPEGDecoder::pjpeg_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pB
6567
uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pBytes_actually_read, void *pCallback_data) {
6668
uint n;
6769

68-
//pCallback_data;
70+
pCallback_data = pCallback_data; // Supress warning
6971

7072
n = jpg_min(g_nInFileSize - g_nInFileOfs, buf_size);
7173

7274
if (jpg_source == JPEG_ARRAY) { // We are handling an array
73-
for (int i = 0; i < n; i++) {
75+
for (uint i = 0; i < n; i++) {
7476
pBuf[i] = pgm_read_byte(jpg_data++);
7577
//Serial.println(pBuf[i],HEX);
7678
}
7779
}
7880

79-
#ifdef LOAD_SPIFFS
81+
#ifdef LOAD_FLASH_FS
8082
if (jpg_source == JPEG_FS_FILE) g_pInFileFs.read(pBuf,n); // else we are handling a file
8183
#endif
8284

@@ -270,10 +272,10 @@ int JPEGDecoder::readSwappedBytes(void) {
270272
}
271273

272274

273-
// Generic file call for SD or SPIFFS, uses leading / to distinguish SPIFFS files
275+
// Generic file call for SD or Little_FS, uses leading / to distinguish Little_FS files
274276
int JPEGDecoder::decodeFile(const char *pFilename){
275277

276-
#if defined (ESP8266) || defined (ESP32)
278+
#if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32)
277279
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
278280
if (*pFilename == '/')
279281
#endif
@@ -289,7 +291,7 @@ int JPEGDecoder::decodeFile(const char *pFilename){
289291

290292
int JPEGDecoder::decodeFile(const String& pFilename){
291293

292-
#if defined (ESP8266) || defined (ESP32)
294+
#if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32)
293295
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
294296
if (pFilename.charAt(0) == '/')
295297
#endif
@@ -304,32 +306,32 @@ int JPEGDecoder::decodeFile(const String& pFilename){
304306
}
305307

306308

307-
#ifdef LOAD_SPIFFS
309+
#ifdef LOAD_FLASH_FS
308310

309-
// Call specific to SPIFFS
311+
// Call specific to Little_FS
310312
int JPEGDecoder::decodeFsFile(const char *pFilename) {
311313

312-
fs::File pInFile = SPIFFS.open( pFilename, "r");
314+
fs::File pInFile = LittleFS.open( pFilename, "r");
313315

314316
return decodeFsFile(pInFile);
315317
}
316318

317319
int JPEGDecoder::decodeFsFile(const String& pFilename) {
318320

319-
fs::File pInFile = SPIFFS.open( pFilename, "r");
321+
fs::File pInFile = LittleFS.open( pFilename, "r");
320322

321323
return decodeFsFile(pInFile);
322324
}
323325

324-
int JPEGDecoder::decodeFsFile(fs::File jpgFile) { // This is for the SPIFFS library
326+
int JPEGDecoder::decodeFsFile(fs::File jpgFile) { // This is for the Little_FS library
325327

326328
g_pInFileFs = jpgFile;
327329

328-
jpg_source = JPEG_FS_FILE; // Flag to indicate a SPIFFS file
330+
jpg_source = JPEG_FS_FILE; // Flag to indicate a Little_FS file
329331

330332
if (!g_pInFileFs) {
331333
#ifdef DEBUG
332-
Serial.println("ERROR: SPIFFS file not found!");
334+
Serial.println("ERROR: Little_FS file not found!");
333335
#endif
334336

335337
return -1;
@@ -465,7 +467,7 @@ void JPEGDecoder::abort(void) {
465467
if(pImage) delete[] pImage;
466468
pImage = NULL;
467469

468-
#ifdef LOAD_SPIFFS
470+
#ifdef LOAD_FLASH_FS
469471
if (jpg_source == JPEG_FS_FILE) if (g_pInFileFs) g_pInFileFs.close();
470472
#endif
471473

src/JPEGDecoder.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,31 @@ Latest version here:
2727
#define PROGMEM __attribute__((section(".fini2")))
2828
#endif
2929

30-
#if defined (ESP8266) || defined (ESP32)
31-
32-
//#include "arduino.h"
33-
#include <pgmspace.h>
30+
#ifdef ESP32 // SDFAT library not compatible with ESP32
31+
//#undef LOAD_SD_LIBRARY
32+
#undef LOAD_SDFAT_LIBRARY
33+
#endif
3434

35-
// If the sketch has included FS.h without setting FS_NO_GLOBALS first then it is likely
36-
// there will be a redefinition of 'class fs::File' error due to conflict with the
37-
// SD library, so we can't load the SD library. (At 12/1/18 this appears to be fixed)
38-
//#if !defined (FS_NO_GLOBALS) && defined (FS_H)
39-
//#undef LOAD_SD_LIBRARY
40-
//#undef LOAD_SDFAT_LIBRARY
41-
//#endif
42-
43-
#ifdef ESP32 // SDFAT library not compatible with ESP32
44-
//#undef LOAD_SD_LIBRARY
45-
#undef LOAD_SDFAT_LIBRARY
35+
// New ESP8266 board package uses ARDUINO_ARCH_ESP8266
36+
// old package defined ESP8266
37+
#if defined (ESP8266)
38+
#ifndef ARDUINO_ARCH_ESP8266
39+
#define ARDUINO_ARCH_ESP8266
4640
#endif
41+
#endif
4742

48-
#define LOAD_SPIFFS
49-
#define FS_NO_GLOBALS
43+
#if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32)
44+
#define LOAD_FLASH_FS
45+
#include <pgmspace.h>
5046
#include <FS.h>
51-
52-
#ifdef ESP32
53-
#include "SPIFFS.h" // ESP32 only
54-
#endif
55-
47+
#include <LittleFS.h>
48+
#define SPIFFS LittleFS
49+
#elif defined (ARDUINO_ARCH_RP2040)
50+
#define LOAD_FLASH_FS
51+
#include <FS.h>
52+
#include <LittleFS.h>
53+
#define SPIFFS LittleFS
54+
#define TJPGD_LOAD_FFS
5655
#endif
5756

5857
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
@@ -90,7 +89,7 @@ class JPEGDecoder {
9089
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
9190
File g_pInFileSd;
9291
#endif
93-
#ifdef LOAD_SPIFFS
92+
#ifdef LOAD_FLASH_FS
9493
fs::File g_pInFileFs;
9594
#endif
9695
pjpeg_scan_type_t scan_type;
@@ -144,7 +143,7 @@ class JPEGDecoder {
144143
int decodeSdFile (File g_pInFile);
145144
#endif
146145

147-
#ifdef LOAD_SPIFFS
146+
#ifdef LOAD_FLASH_FS
148147
int decodeFsFile (const char *pFilename);
149148
int decodeFsFile (const String& pFilename);
150149
int decodeFsFile (fs::File g_pInFile);

src/User_Config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ File jpegFile = SD.open( filename, FILE_READ);
2929
// duplicate definitions in the SD library and the SPIFFS library.
3030

3131

32-
#ifdef ESP8266
32+
#ifdef ARDUINO_ARCH_ESP8266
3333
// Uncomment out the next #define if you want the bytes swapped in the image blocks
3434
// returned by read().
3535

@@ -38,5 +38,5 @@ File jpegFile = SD.open( filename, FILE_READ);
3838
// the sketch. Images will look psychedelic with wrong colours if the SPI transmit byte
3939
// order is not right for your sketch!
4040

41-
// #define SWAP_BYTES // Deprecated, only included for backwards compatibility
41+
#define SWAP_BYTES // Deprecated, only included for backwards compatibility
4242
#endif

src/picojpeg.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ static uint8 gMaxMCUXSize;
211211
static uint8 gMaxMCUYSize;
212212
static uint16 gMaxMCUSPerRow;
213213
static uint16 gMaxMCUSPerCol;
214-
static uint16 gNumMCUSRemaining;
214+
215+
static uint16 gNumMCUSRemainingX, gNumMCUSRemainingY;
216+
215217
static uint8 gMCUOrg[6];
216218

217219
static pjpeg_need_bytes_callback_t g_pNeedBytesCallback;
@@ -1025,6 +1027,7 @@ static uint8 processRestart(void)
10251027
//------------------------------------------------------------------------------
10261028
// FIXME: findEOI() is not actually called at the end of the image
10271029
// (it's optional, and probably not needed on embedded devices)
1030+
/*
10281031
static uint8 findEOI(void)
10291032
{
10301033
uint8 c;
@@ -1048,6 +1051,7 @@ static uint8 findEOI(void)
10481051
10491052
return 0;
10501053
}
1054+
*/
10511055
//------------------------------------------------------------------------------
10521056
static uint8 checkHuffTables(void)
10531057
{
@@ -1196,7 +1200,10 @@ static uint8 initFrame(void)
11961200
gMaxMCUSPerRow = (gImageXSize + (gMaxMCUXSize - 1)) >> ((gMaxMCUXSize == 8) ? 3 : 4);
11971201
gMaxMCUSPerCol = (gImageYSize + (gMaxMCUYSize - 1)) >> ((gMaxMCUYSize == 8) ? 3 : 4);
11981202

1199-
gNumMCUSRemaining = gMaxMCUSPerRow * gMaxMCUSPerCol;
1203+
// This can overflow on large JPEG's.
1204+
//gNumMCUSRemaining = gMaxMCUSPerRow * gMaxMCUSPerCol;
1205+
gNumMCUSRemainingX = gMaxMCUSPerRow;
1206+
gNumMCUSRemainingY = gMaxMCUSPerCol;
12001207

12011208
return 0;
12021209
}
@@ -1207,7 +1214,7 @@ static uint8 initFrame(void)
12071214

12081215
#define PJPG_DCT_SCALE (1U << PJPG_DCT_SCALE_BITS)
12091216

1210-
#define PJPG_DESCALE(x) PJPG_ARITH_SHIFT_RIGHT_N_16(((x) + (1U << (PJPG_DCT_SCALE_BITS - 1))), PJPG_DCT_SCALE_BITS)
1217+
#define PJPG_DESCALE(x) PJPG_ARITH_SHIFT_RIGHT_N_16(((x) + (1 << (PJPG_DCT_SCALE_BITS - 1))), PJPG_DCT_SCALE_BITS)
12111218

12121219
#define PJPG_WFIX(x) ((x) * PJPG_DCT_SCALE + 0.5f)
12131220

@@ -2267,14 +2274,20 @@ unsigned char pjpeg_decode_mcu(void)
22672274
if (gCallbackStatus)
22682275
return gCallbackStatus;
22692276

2270-
if (!gNumMCUSRemaining)
2277+
if ((!gNumMCUSRemainingX) && (!gNumMCUSRemainingY))
22712278
return PJPG_NO_MORE_BLOCKS;
2272-
2279+
22732280
status = decodeNextMCU();
22742281
if ((status) || (gCallbackStatus))
22752282
return gCallbackStatus ? gCallbackStatus : status;
22762283

2277-
gNumMCUSRemaining--;
2284+
gNumMCUSRemainingX--;
2285+
if (!gNumMCUSRemainingX)
2286+
{
2287+
gNumMCUSRemainingY--;
2288+
if (gNumMCUSRemainingY > 0)
2289+
gNumMCUSRemainingX = gMaxMCUSPerRow;
2290+
}
22782291

22792292
return 0;
22802293
}

0 commit comments

Comments
 (0)