Skip to content

Commit

Permalink
Migrated JPEG Capture to JPGENC
Browse files Browse the repository at this point in the history
  • Loading branch information
tobozo committed Oct 30, 2023
1 parent 8f50950 commit b6b2591
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Binary file added assets/bifocal-pidgin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions src/utility/ScreenShotService/ScreenShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ void ScreenShotService::snap( const char* name, bool displayAfter )
struct JPGENC_IMG_Proxy_t
{
static fs::FS* fs;
static fs::File file;
static void* open(const char *filename) { JPGENC_IMG_Proxy_t::file = JPGENC_IMG_Proxy_t::fs->open(filename, FILE_WRITE); return (void *)&JPGENC_IMG_Proxy_t::file; }
static void* open(const char *filename) { static auto f = fs->open(filename, FILE_WRITE); return (void *)&f; }
static void close(JPEGFILE *p) { File *f = (File *)p->fHandle; if (f) f->close(); }
static int32_t read(JPEGFILE *p, uint8_t *buffer, int32_t length) { File *f = (File *)p->fHandle; return f->read(buffer, length); }
static int32_t write(JPEGFILE *p, uint8_t *buffer, int32_t length) { File *f = (File *)p->fHandle; return f->write(buffer, length); }
static int32_t seek(JPEGFILE *p, int32_t position) { File *f = (File *)p->fHandle; return f->seek(position); }
};

fs::FS* JPGENC_IMG_Proxy_t::fs = nullptr;


void ScreenShotService::snapJPG( const char* name, bool displayAfter )
{
Expand All @@ -135,6 +136,7 @@ void ScreenShotService::snap( const char* name, bool displayAfter )

JPEG jpg;
JPEGENCODE jpe;
JPGENC_IMG_Proxy_t::fs = _fileSystem;
JPGENC_IMG_Proxy_t IMG_Proxy = JPGENC_IMG_Proxy_t();
bool use_buffer = true;
auto color_depth = _src->getColorDepth();
Expand Down Expand Up @@ -191,13 +193,13 @@ void ScreenShotService::snap( const char* name, bool displayAfter )
iDataSize = jpg.close();

if( use_buffer ) {
JPGENC_IMG_Proxy_t::file = _fileSystem->open(fileName, "w" );
if( ! JPGENC_IMG_Proxy_t::file ) {
auto file = _fileSystem->open(fileName, "w" );
if( ! file ) {
log_e("Can't open %d for writing", fileName );
goto _end;
}
JPGENC_IMG_Proxy_t::file.write( screenShotBuffer, iDataSize );
JPGENC_IMG_Proxy_t::file.close();
file.write( screenShotBuffer, iDataSize );
file.close();
}

log_i( "[SUCCESS] Screenshot saved as %s (%d bytes) in %u ms", fileName, iDataSize, millis()-time_start);
Expand Down
1 change: 0 additions & 1 deletion src/utility/ScreenShotService/ScreenShot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "./AVI/AviMjpegEncoder.hpp"



template <typename GFX> // GFX can be either LGFX_Sprite or LGFX_Device
static void defaultReadRect( void* src, int32_t x, int32_t y, uint32_t w, uint32_t h, uint8_t* buf )
{
Expand Down

0 comments on commit b6b2591

Please sign in to comment.