TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
JPEGParser< RGB_T > Class Template Reference

Decodes baseline JPEG images into a TinyGPU ISurface, using pschatzmann/TinyJPEG (https://github.com/pschatzmann/TinyJPEG) as the underlying decoder. More...

#include <JPEGParser.h>

Collaboration diagram for JPEGParser< RGB_T >:
Collaboration graph
[legend]

Public Member Functions

 JPEGParser (ISurface< RGB_T > &target)
 
void setSwapBytes (bool swap)
 
void setScale (uint8_t scale)
 Sets the output reduction factor: 1 (full size), 2, 4, or 8.
 
bool decode (const uint8_t *data, size_t size)
 
template<typename FileT >
bool decode (FileT &file)
 
const char * errorMessage () const
 Returns the latest error message, if any.
 

Protected Member Functions

bool setError (const char *message)
 
bool checkResult (JRESULT result)
 

Static Protected Member Functions

static bool onBlock (tinyjpeg::TinyJPEGDecoder &decoder, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *data)
 

Protected Attributes

ISurface< RGB_T > & target_
 
tinyjpeg::TinyJPEGDecoder decoder_
 
const char * errorMessage_ = nullptr
 

Detailed Description

template<typename RGB_T = RGB565>
class tinygpu::JPEGParser< RGB_T >

Decodes baseline JPEG images into a TinyGPU ISurface, using pschatzmann/TinyJPEG (https://github.com/pschatzmann/TinyJPEG) as the underlying decoder.

TinyJPEG is a separate, optional Arduino/CMake library - install it alongside TinyGPU and #include <TinyGPU/IO/JPEGParser.h> explicitly (this header is not pulled in by TinyGPU.h) to opt in to JPEG support.

TinyJPEG streams decoded pixels one MCU block at a time rather than requiring memory for the whole decoded frame, so decode() resizes the target surface once (from the JPEG's own header) and then just fans each block out to setPixel() as it arrives - no intermediate frame buffer beyond the target surface itself.

Constructor & Destructor Documentation

◆ JPEGParser()

JPEGParser ( ISurface< RGB_T > &  target)
inlineexplicit

Member Function Documentation

◆ checkResult()

bool checkResult ( JRESULT  result)
inlineprotected

◆ decode() [1/2]

bool decode ( const uint8_t *  data,
size_t  size 
)
inline

Decodes a JPEG held entirely in memory into the target surface at (0, 0). Resizes the target surface to the JPEG's own dimensions first.

◆ decode() [2/2]

bool decode ( FileT &  file)
inline

Decodes a JPEG read from any file-like object (Arduino's fs::File, SD's File, or anything else exposing available()/read()/position()/ seek() - see TinyJPEG's docs/decoding.md) into the target surface at (0, 0). Resizes the target surface to the JPEG's own dimensions first. file is read from its current position and left wherever the decode stopped; this method rewinds to that starting position only between reading the header and decoding the pixels.

◆ errorMessage()

const char * errorMessage ( ) const
inline

Returns the latest error message, if any.

◆ onBlock()

static bool onBlock ( tinyjpeg::TinyJPEGDecoder &  decoder,
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t *  data 
)
inlinestaticprotected

◆ setError()

bool setError ( const char *  message)
inlineprotected

◆ setScale()

void setScale ( uint8_t  scale)
inline

Sets the output reduction factor: 1 (full size), 2, 4, or 8.

◆ setSwapBytes()

void setSwapBytes ( bool  swap)
inline

Overrides the byte-swap behavior set in the constructor (see its comment) - some panels/wiring need the opposite of the true default that's otherwise correct.

Member Data Documentation

◆ decoder_

tinyjpeg::TinyJPEGDecoder decoder_
protected

◆ errorMessage_

const char* errorMessage_ = nullptr
protected

◆ target_

ISurface<RGB_T>& target_
protected

The documentation for this class was generated from the following file: