Skip to content

Commit

Permalink
Refresh ImgViewerJpeg to use latest JPEGDEC API
Browse files Browse the repository at this point in the history
  • Loading branch information
moononournation committed Dec 28, 2020
1 parent 53ba4bb commit 0bc64b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
39 changes: 3 additions & 36 deletions examples/ImgViewerJpeg/JpegClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
#include <FS.h>
#endif

static FS *_fs;

class JpegClass
{
public:
void draw(
FS *fs, char *filename, JPEG_DRAW_CALLBACK *jpegDrawCallback, bool useBigEndian,
int x, int y, int widthLimit, int heightLimit)
{
_fs = fs;
_jpeg.open(filename, JPGOpenFile, JPGCloseFile, JPGReadFile, JPGSeekFile, jpegDrawCallback);
File f = fs->open(filename);
_jpeg.open(f, jpegDrawCallback);

// scale to fit height
int _scale;
int iMaxMCUs;
float ratio = (float)_jpeg.getHeight() / heightLimit;
if (ratio <= 1)
Expand Down Expand Up @@ -61,39 +60,7 @@ class JpegClass
}

private:
static void *JPGOpenFile(const char *szFilename, int32_t *pFileSize)
{
// Serial.println("JPGOpenFile");
static File f = _fs->open(szFilename, "r");
*pFileSize = f.size();
return &f;
}

static void JPGCloseFile(void *pHandle)
{
// Serial.println("JPGCloseFile");
File *f = static_cast<File *>(pHandle);
f->close();
}

static int32_t JPGReadFile(JPEGFILE *pFile, uint8_t *pBuf, int32_t iLen)
{
// Serial.printf("JPGReadFile, iLen: %d\n", iLen);
File *f = static_cast<File *>(pFile->fHandle);
size_t r = f->read(pBuf, iLen);
return r;
}

static int32_t JPGSeekFile(JPEGFILE *pFile, int32_t iPosition)
{
// Serial.printf("JPGSeekFile, pFile->iPos: %d, iPosition: %d\n", pFile->iPos, iPosition);
File *f = static_cast<File *>(pFile->fHandle);
f->seek(iPosition);
return iPosition;
}

JPEGDEC _jpeg;
int _scale = -1;
};

#endif // _JPEGCLASS_H_
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GFX Library for Arduino
version=1.0.3
version=1.0.4
author=Moon On Our Nation <[email protected]>
maintainer=Moon On Our Nation <[email protected]>
sentence=Arduino graphics library for various displays with various data bus interfaces
Expand Down

0 comments on commit 0bc64b6

Please sign in to comment.