FastLED 3.9.15
Loading...
Searching...
No Matches
driver.h
Go to the documentation of this file.
1// Driver layer for TJpg_Decoder to enable instance-based progressive JPEG decoding
2// This file provides an instance-based wrapper around the TJpg decoder to eliminate
3// global state dependencies and enable concurrent JPEG decoding
4
5#pragma once
6
7#include "platforms/avr/is_avr.h"
8#include "fl/stl/shared_ptr.h"
9#include "fl/stl/span.h"
10#include "fl/stl/string.h"
11#include "fl/stl/unique_ptr.h"
12#include "fl/codec/pixel.h"
13#include "fl/fx/frame.h"
15#include "fl/stl/noexcept.h"
16#include "src/tjpgd.h"
17
18namespace fl {
19namespace third_party {
20
21// Forward declarations
24
25// Progressive configuration for time-budgeted decoding
27 fl::u16 max_mcus_per_tick = 16; // Maximum MCUs to process per tick
28 fl::u32 max_time_per_tick_ms = 4; // Maximum time per processing tick (4ms default)
29};
30
31// Instance-based TJpg decoder that contains all state internally
33public:
41
42private:
43 // Embedded state structure to avoid any global dependencies
45 // Workspace for TJpg decoder (must be aligned)
46 // On AVR, alignment beyond 1 byte causes issues with new operator
47#ifdef FL_IS_AVR
48 fl::u8 workspace[4096];
49#else
50 fl::u8 workspace[4096] __attribute__((aligned(4)));
51#endif
52
53 // Input stream management
54 const fl::u8* array_data = nullptr;
55 fl::size array_index = 0;
56 fl::size array_size = 0;
57
58 // Configuration
59 bool swap_bytes = false;
61
62 // Back-reference to parent decoder for callbacks
65
66 // Progressive decoder state (if using progressive mode)
68 bool use_progressive_ = false;
69
70 // Configuration
73
74 // Frame management
77 fl::size frame_buffer_size_ = 0;
78
79 // State tracking
82 float progress_ = 0.0f;
83
84 // Input data management
87 fl::size input_size_ = 0;
88
89 // Processing time management
90 fl::u32 start_time_ms_ = 0;
92
93 // Internal methods
97 fl::size getBytesPerPixel() const FL_NOEXCEPT;
98 void setError(const fl::string& msg) FL_NOEXCEPT;
99 bool shouldYield() const FL_NOEXCEPT;
100 void startTick() FL_NOEXCEPT;
101
102 // Static callbacks that use instance context
103 static fl::size inputCallback(JDEC* jd, fl::u8* buff, fl::size nbyte) FL_NOEXCEPT;
104 static int outputCallback(JDEC* jd, void* bitmap, JRECT* rect) FL_NOEXCEPT;
105
106public:
109
110 // Main decoding interface
112 bool processChunk() FL_NOEXCEPT; // Process one chunk with time budget
114
115 // Progressive configuration
119
120 // Scale configuration for quality settings
122 embedded_tjpg_.jpg_scale = scale;
123 }
124
125 // State queries
126 State getState() const FL_NOEXCEPT { return state_; }
127 bool hasError(fl::string* msg = nullptr) const FL_NOEXCEPT;
128 float getProgress() const FL_NOEXCEPT { return progress_; }
130
131 // Progressive features
132 bool hasPartialImage() const FL_NOEXCEPT;
134 fl::u16 getDecodedRows() const FL_NOEXCEPT;
135 fl::size getBytesProcessed() const FL_NOEXCEPT;
136};
137
138// Factory function
140
141} // namespace third_party
142} // namespace fl
fl::UISlider scale("Scale", 4,.1, 4,.1)
fl::size getBytesPerPixel() const FL_NOEXCEPT
bool beginDecodingStream(fl::filebuf_ptr stream, PixelFormat format) FL_NOEXCEPT
static fl::size inputCallback(JDEC *jd, fl::u8 *buff, fl::size nbyte) FL_NOEXCEPT
struct fl::third_party::TJpgInstanceDecoder::EmbeddedTJpgState embedded_tjpg_
JDEC_Progressive progressive_state_
Definition driver.h:67
fl::unique_ptr< fl::u8[]> frame_buffer_
Definition driver.h:76
fl::unique_ptr< fl::u8[]> input_buffer_
Definition driver.h:86
Frame getCurrentFrame() const FL_NOEXCEPT
void setProgressiveConfig(const TJpgProgressiveConfig &config) FL_NOEXCEPT
Definition driver.h:116
fl::u16 getDecodedRows() const FL_NOEXCEPT
Frame getPartialFrame() const FL_NOEXCEPT
fl::shared_ptr< Frame > current_frame_
Definition driver.h:75
bool hasPartialImage() const FL_NOEXCEPT
float getProgress() const FL_NOEXCEPT
Definition driver.h:128
fl::size getBytesProcessed() const FL_NOEXCEPT
bool hasError(fl::string *msg=nullptr) const FL_NOEXCEPT
bool shouldYield() const FL_NOEXCEPT
TJpgProgressiveConfig progressive_config_
Definition driver.h:71
State getState() const FL_NOEXCEPT
Definition driver.h:126
void allocateFrameBuffer(fl::u16 width, fl::u16 height) FL_NOEXCEPT
void setScale(fl::u8 scale) FL_NOEXCEPT
Definition driver.h:121
void setError(const fl::string &msg) FL_NOEXCEPT
static int outputCallback(JDEC *jd, void *bitmap, JRECT *rect) FL_NOEXCEPT
unsigned char u8
Definition coder.h:132
fl::shared_ptr< TJpgInstanceDecoder > TJpgInstanceDecoderPtr
Definition driver.h:23
TJpgInstanceDecoderPtr createTJpgInstanceDecoder() FL_NOEXCEPT
unsigned char u8
Definition stdint.h:131
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
fl::shared_ptr< filebuf > filebuf_ptr
Definition idecoder.h:15
fl::string format(const char *fmt)
Format with no arguments.
Definition format.h:439
PixelFormat
Definition pixel.h:7
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT