Skip to content

Commit 9e72cb3

Browse files
committed
Updated JPEGDecoder library
1 parent d56c1cb commit 9e72cb3

File tree

6 files changed

+123
-37
lines changed

6 files changed

+123
-37
lines changed

src/utility/JPEGDecoder/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.7.9",
3+
"version": "1.8.0",
44
"keywords": "jpeg, jpg, decoder, TFT",
55
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
66
"repository":

src/utility/JPEGDecoder/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.7.9
2+
version=1.8.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
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Arduino JPEGDecoder library
3+
===========================
4+
5+
The original picojpeg.c and picojepeg.h code used in this Arduino library is hosted here:
6+
https://code.google.com/archive/p/picojpeg/
7+
8+
The JPEGDecoder library has been developed from the Arduino library by Makoto Kurauchi here:
9+
https://github.com/MakotoKurauchi/JPEGDecoder
10+
11+
The library has been developed and debugged by Bodmer and is hosted here:
12+
https://github.com/Bodmer/JPEGDecoder
13+
14+
The picojpeg code and the developed library is dual licensed as both public domain and
15+
(where public domain is not acceptable) the MIT license:
16+
17+
18+
picojeg code: Copyright 2013 Rich Geldreich
19+
Arduino JPEGDecoder library: Copyright 2019 Makoto Kurauchi, Bodmer
20+
21+
MIT license:
22+
23+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
24+
associated documentation files (the "Software"), to deal in the Software without restriction,
25+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
26+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
27+
furnished to do so, subject to the following conditions:
28+
29+
The above copyright notice and this permission notice shall be included in all copies or
30+
substantial portions of the Software.
31+
32+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
33+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
35+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/utility/JPEGDecoder/src/JPEGDecoder.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ uint8_t JPEGDecoder::pjpeg_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pB
6565
uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pBytes_actually_read, void *pCallback_data) {
6666
uint n;
6767

68-
(void)pCallback_data;
68+
//pCallback_data;
6969

7070
n = jpg_min(g_nInFileSize - g_nInFileOfs, buf_size);
7171

@@ -76,6 +76,10 @@ uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size,
7676
}
7777
}
7878

79+
#ifdef LOAD_SPIFFS
80+
if (jpg_source == JPEG_FS_FILE) g_pInFileFs.read(pBuf,n); // else we are handling a file
81+
#endif
82+
7983
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
8084
if (jpg_source == JPEG_SD_FILE) g_pInFileSd.read(pBuf,n); // else we are handling a file
8185
#endif
@@ -300,20 +304,61 @@ int JPEGDecoder::decodeFile(const String& pFilename){
300304
}
301305

302306

307+
#ifdef LOAD_SPIFFS
308+
309+
// Call specific to SPIFFS
310+
int JPEGDecoder::decodeFsFile(const char *pFilename) {
311+
312+
fs::File pInFile = SPIFFS.open( pFilename, "r");
313+
314+
return decodeFsFile(pInFile);
315+
}
316+
317+
int JPEGDecoder::decodeFsFile(const String& pFilename) {
318+
319+
fs::File pInFile = SPIFFS.open( pFilename, "r");
320+
321+
return decodeFsFile(pInFile);
322+
}
323+
324+
int JPEGDecoder::decodeFsFile(fs::File jpgFile) { // This is for the SPIFFS library
325+
326+
g_pInFileFs = jpgFile;
327+
328+
jpg_source = JPEG_FS_FILE; // Flag to indicate a SPIFFS file
329+
330+
if (!g_pInFileFs) {
331+
#ifdef DEBUG
332+
Serial.println("ERROR: SPIFFS file not found!");
333+
#endif
334+
335+
return -1;
336+
}
337+
338+
g_nInFileOfs = 0;
339+
340+
g_nInFileSize = g_pInFileFs.size();
341+
342+
return decodeCommon();
343+
344+
}
345+
#endif
346+
347+
303348
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
304349

305350
// Call specific to SD filing system in case leading / is used
306351
int JPEGDecoder::decodeSdFile(const char *pFilename) {
307352

308-
File pInFile = SD.open( pFilename);
353+
File pInFile = SD.open( pFilename, FILE_READ);
309354

310355
return decodeSdFile(pInFile);
311356
}
312357

313358

314359
int JPEGDecoder::decodeSdFile(const String& pFilename) {
315360
#if !defined (ARDUINO_ARCH_SAM)
316-
File pInFile = SD.open( pFilename);
361+
File pInFile = SD.open( pFilename, FILE_READ);
317362

318363
return decodeSdFile(pInFile);
319364
#else
@@ -374,12 +419,14 @@ int JPEGDecoder::decodeCommon(void) {
374419
status = pjpeg_decode_init(&image_info, pjpeg_callback, NULL, 0);
375420

376421
if (status) {
422+
#ifdef DEBUG
377423
Serial.print("pjpeg_decode_init() failed with status ");
378424
Serial.println(status);
379425

380426
if (status == PJPG_UNSUPPORTED_MODE) {
381427
Serial.println("Progressive JPEG files are not supported.");
382428
}
429+
#endif
383430

384431
return 0;
385432
}
@@ -417,6 +464,10 @@ void JPEGDecoder::abort(void) {
417464
if(pImage) delete[] pImage;
418465
pImage = NULL;
419466

467+
#ifdef LOAD_SPIFFS
468+
if (jpg_source == JPEG_FS_FILE) if (g_pInFileFs) g_pInFileFs.close();
469+
#endif
470+
420471
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
421472
if (jpg_source == JPEG_SD_FILE) if (g_pInFileSd) g_pInFileSd.close();
422473
#endif

src/utility/JPEGDecoder/src/JPEGDecoder.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Latest version here:
1010
https://github.com/Bodmer/JPEGDecoder
1111
1212
*/
13-
#define LOAD_SDFAT_LIBRARY
13+
1414
#ifndef JPEGDECODER_H
1515
#define JPEGDECODER_H
1616

@@ -38,20 +38,22 @@ Latest version here:
3838

3939
#define LOAD_SPIFFS
4040
#define FS_NO_GLOBALS
41+
#include <FS.h>
4142

4243
#ifdef ESP32
44+
#include "SPIFFS.h" // ESP32 only
4345
#endif
4446

4547
#endif
4648

4749
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
4850
#ifdef LOAD_SDFAT_LIBRARY
51+
#include <SdFat.h> // Alternative where we might need to bit bash the SPI
4952
#else
53+
#include <SD.h> // Default
5054
#endif
5155
#endif
5256

53-
#include <SD.h> // Alternative where we might need to bit bash the SPI
54-
5557

5658
#include "picojpeg.h"
5759

@@ -80,27 +82,31 @@ typedef unsigned int uint;
8082
class JPEGDecoder {
8183

8284
private:
83-
// SdFat SD;
84-
File g_pInFileSd;
85-
pjpeg_scan_type_t scan_type;
86-
pjpeg_image_info_t image_info;
87-
88-
int is_available;
89-
int mcu_x;
90-
int mcu_y;
91-
uint g_nInFileSize;
92-
uint g_nInFileOfs;
93-
uint row_pitch;
94-
uint decoded_width, decoded_height;
95-
uint row_blocks_per_mcu, col_blocks_per_mcu;
96-
uint8 status;
97-
uint8 jpg_source = 0;
98-
uint8_t *jpg_data;
99-
100-
static uint8 pjpeg_callback(unsigned char *pBuf, unsigned char buf_size, unsigned char *pBytes_actually_read, void *pCallback_data);
101-
uint8 pjpeg_need_bytes_callback(unsigned char *pBuf, unsigned char buf_size, unsigned char *pBytes_actually_read, void *pCallback_data);
102-
int decode_mcu(void);
103-
int decodeCommon(void);
85+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
86+
File g_pInFileSd;
87+
#endif
88+
#ifdef LOAD_SPIFFS
89+
fs::File g_pInFileFs;
90+
#endif
91+
pjpeg_scan_type_t scan_type;
92+
pjpeg_image_info_t image_info;
93+
94+
int is_available;
95+
int mcu_x;
96+
int mcu_y;
97+
uint g_nInFileSize;
98+
uint g_nInFileOfs;
99+
uint row_pitch;
100+
uint decoded_width, decoded_height;
101+
uint row_blocks_per_mcu, col_blocks_per_mcu;
102+
uint8 status;
103+
uint8 jpg_source = 0;
104+
uint8_t* jpg_data;
105+
106+
static uint8 pjpeg_callback(unsigned char* pBuf, unsigned char buf_size, unsigned char *pBytes_actually_read, void *pCallback_data);
107+
uint8 pjpeg_need_bytes_callback(unsigned char* pBuf, unsigned char buf_size, unsigned char *pBytes_actually_read, void *pCallback_data);
108+
int decode_mcu(void);
109+
int decodeCommon(void);
104110
public:
105111

106112
uint16_t *pImage;
@@ -136,7 +142,7 @@ class JPEGDecoder {
136142
#ifdef LOAD_SPIFFS
137143
int decodeFsFile (const char *pFilename);
138144
int decodeFsFile (const String& pFilename);
139-
int decodeFsFile (File g_pInFile);
145+
int decodeFsFile (fs::File g_pInFile);
140146
#endif
141147

142148
int decodeArray(const uint8_t array[], uint32_t array_size);

src/utility/JPEGDecoder/src/picojpeg.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,6 @@ static uint8 readSOSMarker(void)
716716
successive_high = (uint8)getBits1(4);
717717
successive_low = (uint8)getBits1(4);
718718

719-
(void)spectral_start;
720-
(void)spectral_end;
721-
(void)successive_high;
722-
(void)successive_low;
723-
724719
left -= 3;
725720

726721
while (left)
@@ -1027,7 +1022,6 @@ static uint8 processRestart(void)
10271022

10281023
return 0;
10291024
}
1030-
/*
10311025
//------------------------------------------------------------------------------
10321026
// FIXME: findEOI() is not actually called at the end of the image
10331027
// (it's optional, and probably not needed on embedded devices)
@@ -1054,7 +1048,6 @@ static uint8 findEOI(void)
10541048

10551049
return 0;
10561050
}
1057-
*/
10581051
//------------------------------------------------------------------------------
10591052
static uint8 checkHuffTables(void)
10601053
{

0 commit comments

Comments
 (0)