FastLED 3.10.8
Loading...
Searching...
No Matches
jpeg.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/codec/common.h" // IWYU pragma: keep
4#include "fl/stl/function.h"
5#include "fl/stl/noexcept.h"
6
7namespace fl {
8
9// Forward declarations
10class JpegDecoder;
12
13// JPEG metadata information structure
14struct JpegInfo {
15 fl::u16 width = 0;
16 fl::u16 height = 0;
19 bool is_grayscale = false;
20 bool is_valid = false;
21
23 JpegInfo(fl::u16 w, fl::u16 h, fl::u8 comp) FL_NO_EXCEPT;
24};
25
26// JPEG decoder configuration
36
37// Progressive processing configuration
39 fl::u16 max_mcus_per_tick = 2;
41 fl::size input_buffer_size = 512;
43
45};
46
47// JPEG decoder with progressive processing support
48class JpegDecoder : public IDecoder {
49public:
57
58
59 using YieldFunction = fl::function<bool()>;
61 return false; // never signal to yield
62 }
63
64 explicit JpegDecoder(const JpegConfig& config) FL_NO_EXCEPT;
66
67 // IDecoder interface
68 bool begin(fl::filebuf_ptr stream) FL_NO_EXCEPT override;
69 void end() FL_NO_EXCEPT override;
70 bool isReady() const FL_NO_EXCEPT override;
71 bool hasError(fl::string* msg = nullptr) const FL_NO_EXCEPT override;
73 // Partial, incremental decoding is supported. This will
74 // process until the jpeg is decoded or should_yield returns true.
75 DecodeResult decode(fl::optional<fl::function<bool()>> should_yield) FL_NO_EXCEPT; // Decode with optional yield callback
77 bool hasMoreFrames() const FL_NO_EXCEPT override;
78
79 // Progressive configuration
82 float getProgress() const FL_NO_EXCEPT; // 0.0 to 1.0 completion
83
84 // Incremental output access
85 bool hasPartialImage() const FL_NO_EXCEPT;
87 fl::u16 getDecodedRows() const FL_NO_EXCEPT;
88
89 // Stream interface extensions
90 bool feedData(fl::span<const fl::u8> data) FL_NO_EXCEPT;
91 bool needsMoreData() const FL_NO_EXCEPT;
92 fl::size getBytesProcessed() const FL_NO_EXCEPT;
93
94 // State access
96
97private:
98 class Impl;
100};
101
102// Main JPEG codec interface
103class Jpeg {
104public:
105 // Synchronous decode interface
106 static bool decode(const JpegConfig& config, fl::span<const fl::u8> data,
107 Frame* frame, fl::string* error_message = nullptr) FL_NO_EXCEPT;
108 static FramePtr decode(const JpegConfig& config, fl::span<const fl::u8> data,
109 fl::string* error_message = nullptr) FL_NO_EXCEPT;
110
111 // Simplified decode with defaults
112 static FramePtr decode(fl::span<const fl::u8> data, fl::string* error_message = nullptr) FL_NO_EXCEPT;
113
114 // Progressive decoder factory
116
117 // Utility methods
118 static bool decodeWithTimeout(const JpegConfig& config, fl::span<const fl::u8> data,
119 Frame* frame, fl::u32 timeout_ms,
120 float* progress_out = nullptr,
121 fl::string* error_message = nullptr) FL_NO_EXCEPT;
122
123 static bool decodeStream(const JpegConfig& config, fl::filebuf_ptr input_stream,
124 Frame* frame, fl::u32 max_time_per_chunk_ms = 4,
125 fl::function<bool(float)> progress_callback = {}) FL_NO_EXCEPT;
126
127 // Metadata parsing
128 static JpegInfo parseInfo(fl::span<const fl::u8> data, fl::string* error_message = nullptr) FL_NO_EXCEPT;
129
130 static bool isSupported() FL_NO_EXCEPT;
131};
132
133} // namespace fl
static bool decodeWithTimeout(const JpegConfig &config, fl::span< const fl::u8 > data, Frame *frame, fl::u32 timeout_ms, float *progress_out=nullptr, fl::string *error_message=nullptr) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:380
static bool decode(const JpegConfig &config, fl::span< const fl::u8 > data, Frame *frame, fl::string *error_message=nullptr) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:296
static bool isSupported() FL_NO_EXCEPT
Definition jpeg.cpp.hpp:376
static bool decodeStream(const JpegConfig &config, fl::filebuf_ptr input_stream, Frame *frame, fl::u32 max_time_per_chunk_ms=4, fl::function< bool(float)> progress_callback={}) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:443
static JpegInfo parseInfo(fl::span< const fl::u8 > data, fl::string *error_message=nullptr) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:488
static JpegDecoderPtr createDecoder(const JpegConfig &config) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:372
bool needsMoreData() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:280
fl::unique_ptr< Impl > mImpl
Definition jpeg.h:99
fl::u16 getDecodedRows() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:272
bool isReady() const FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:228
JpegDecoder(const JpegConfig &config) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:215
Frame getPartialFrame() FL_NO_EXCEPT
Definition jpeg.cpp.hpp:268
void end() FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:224
fl::size getBytesProcessed() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:284
DecodeResult decode() FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:236
static bool NeverYeildUntilDone() FL_NO_EXCEPT
Definition jpeg.h:60
bool begin(fl::filebuf_ptr stream) FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:220
ProgressiveConfig getProgressiveConfig() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:256
void setProgressiveConfig(const ProgressiveConfig &config) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:252
Frame getCurrentFrame() FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:244
State getState() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:288
bool feedData(fl::span< const fl::u8 > data) FL_NO_EXCEPT
Definition jpeg.cpp.hpp:276
bool hasMoreFrames() const FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:248
float getProgress() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:260
fl::function< bool()> YieldFunction
Definition jpeg.h:59
~JpegDecoder() FL_NO_EXCEPT override
bool hasError(fl::string *msg=nullptr) const FL_NO_EXCEPT override
Definition jpeg.cpp.hpp:232
bool hasPartialImage() const FL_NO_EXCEPT
Definition jpeg.cpp.hpp:264
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Optional< T > optional
Definition optional.h:16
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
DecodeResult
Definition idecoder.h:18
fl::shared_ptr< JpegDecoder > JpegDecoderPtr
Definition jpeg.h:11
PixelFormat
Definition pixel.h:8
Base definition for an LED controller.
Definition crgb.hpp:179
PixelFormat format
Definition jpeg.h:31
JpegConfig() FL_NO_EXCEPT=default
Quality quality
Definition jpeg.h:30
JpegInfo() FL_NO_EXCEPT=default
fl::u8 bits_per_component
Definition jpeg.h:18
fl::u16 width
Definition jpeg.h:15
bool is_valid
Definition jpeg.h:20
fl::u16 height
Definition jpeg.h:16
fl::u8 components
Definition jpeg.h:17
bool is_grayscale
Definition jpeg.h:19
fl::u16 max_mcus_per_tick
Definition jpeg.h:39
bool yield_on_row_complete
Definition jpeg.h:42
fl::size input_buffer_size
Definition jpeg.h:41
ProgressiveConfig() FL_NO_EXCEPT=default
fl::u32 max_time_per_tick_ms
Definition jpeg.h:40