FastLED 3.9.15
Loading...
Searching...
No Matches
tjpgd.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------/
2/ TJpgDec - Tiny JPEG Decompressor R0.03 include file (C)ChaN, 2021
3/----------------------------------------------------------------------------*/
4#ifndef DEF_TJPGDEC
5#define DEF_TJPGDEC
6
7// Include standard library headers outside namespace to avoid conflicts
8#include "fl/stl/string.h"
9#include "fl/stl/stdint.h"
10#include "fl/stl/noexcept.h"
11#include "tjpgdcnf.h"
12
13namespace fl {
14namespace third_party {
15
16#if JD_FASTDECODE >= 1
17typedef int16_t jd_yuv_t;
18#else
20#endif
21
22
23/* Error code */
24typedef enum {
25 JDR_OK = 0, /* 0: Succeeded */
26 JDR_INTR, /* 1: Interrupted by output function */
27 JDR_INP, /* 2: Device error or wrong termination of input stream */
28 JDR_MEM1, /* 3: Insufficient memory pool for the image */
29 JDR_MEM2, /* 4: Insufficient stream input buffer */
30 JDR_PAR, /* 5: Parameter error */
31 JDR_FMT1, /* 6: Data format error (may be broken data) */
32 JDR_FMT2, /* 7: Right format but not supported */
33 JDR_FMT3 /* 8: Not supported JPEG standard */
34} JRESULT;
35
36
37
38/* Rectangular region in the output image */
39typedef struct {
40 uint16_t left; /* Left end */
41 uint16_t right; /* Right end */
42 uint16_t top; /* Top end */
43 uint16_t bottom; /* Bottom end */
44} JRECT;
45
46
47
48/* Decompressor object structure */
49typedef struct JDEC JDEC;
50struct JDEC {
51 size_t dctr; /* Number of bytes available in the input buffer */
52 uint8_t* dptr; /* Current data read ptr */
53 uint8_t* inbuf; /* Bit stream input buffer */
54 uint8_t dbit; /* Number of bits availavble in wreg or reading bit mask */
55 uint8_t scale; /* Output scaling ratio */
56 uint8_t msx, msy; /* MCU size in unit of block (width, height) */
57 uint8_t qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */
58 uint8_t ncomp; /* Number of color components 1:grayscale, 3:color */
59 int16_t dcv[3]; /* Previous DC element of each component */
60 uint16_t nrst; /* Restart inverval */
61 uint16_t width, height; /* Size of the input image (pixel) */
62 uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
63 uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
64 uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
65 int32_t* qttbl[4]; /* Dequantizer tables [id] */
66#if JD_FASTDECODE >= 1
67 uint32_t wreg; /* Working shift register */
68 uint8_t marker; /* Detected marker (0:None) */
69#if JD_FASTDECODE == 2
70 uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */
71 uint16_t* hufflut_ac[2]; /* Fast huffman decode tables for AC short code [id] */
72 uint8_t* hufflut_dc[2]; /* Fast huffman decode tables for DC short code [id] */
73#endif
74#endif
75 void* workbuf; /* Working buffer for IDCT and RGB output */
76 jd_yuv_t* mcubuf; /* Working buffer for the MCU */
77 void* pool; /* Pointer to available memory pool */
78 size_t sz_pool; /* Size of momory pool (bytes available) */
79 size_t (*infunc)(JDEC*, uint8_t*, size_t); /* Pointer to jpeg stream input function */
80 void* device; /* Pointer to I/O device identifiler for the session */
81 uint8_t swap; /* Added by Bodmer to control byte swapping */
82};
83
84/* Extended decoder state for progressive processing */
86 JDEC base; /* Original decoder state */
87
88 /* Progressive state */
89 uint16_t current_mcu_x; /* Current MCU position X */
90 uint16_t current_mcu_y; /* Current MCU position Y */
91 uint16_t mcus_processed; /* MCUs completed so far */
92 uint16_t total_mcus; /* Total MCUs in image */
93
94 /* Suspension/Resume support */
95 uint8_t is_suspended; /* Can be suspended between MCUs */
96 uint8_t suspend_reason; /* Why suspended (data/time/callback) */
97
98 /* Buffer state preservation */
99 size_t stream_position; /* Current stream read position */
100 uint8_t bit_buffer_state; /* Partial bit decoding state */
101 uint32_t partial_bits; /* Bits waiting to be processed */
102
103 /* Memory management */
104 void* persistent_workspace; /* Workspace that survives suspend/resume */
105 uint8_t workspace_initialized; /* Track initialization state */
106};
107
108
109
110/* TJpgDec API functions */
111JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev) FL_NOEXCEPT;
112JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale) FL_NOEXCEPT;
113
114/* Progressive decompression API */
115enum { JDR_SUSPEND = 9 }; /* Suspended for progressive processing */
116
118 JDEC_Progressive* jpd, /* Progressive decoder state */
119 int (*outfunc)(JDEC*, void*, JRECT*), /* Output callback */
120 uint8_t scale, /* Scaling factor */
121 uint16_t max_mcus_per_call, /* MCU processing limit per call */
122 uint8_t* more_data_needed, /* Output: needs more input data */
123 uint8_t* processing_complete /* Output: decode finished */
125
126} // namespace third_party
127} // namespace fl
128
129#endif /* _TJPGDEC */
fl::UISlider scale("Scale", 4,.1, 4,.1)
fl::u32 uint32_t
Definition coder.h:219
JRESULT jd_decomp(JDEC *jd, int(*outfunc)(JDEC *, void *, JRECT *), uint8_t scale) FL_NOEXCEPT
fl::u16 uint16_t
Definition coder.h:214
fl::size size_t
Definition coder.h:223
JRESULT jd_prepare(JDEC *jd, size_t(*infunc)(JDEC *, uint8_t *, size_t), void *pool, size_t sz_pool, void *dev) FL_NOEXCEPT
fl::i16 int16_t
Definition coder.h:215
JRESULT jd_decomp_progressive(JDEC_Progressive *jpd, int(*outfunc)(JDEC *, void *, JRECT *), uint8_t scale, uint16_t max_mcus_per_call, uint8_t *more_data_needed, uint8_t *processing_complete) FL_NOEXCEPT
fl::i32 int32_t
Definition coder.h:220
struct JDEC JDEC
Definition tjpgd.h:49
unsigned char uint8_t
Definition coder.h:209
uint8_t jd_yuv_t
Definition tjpgd.h:19
uint8_t qtid[3]
Definition tjpgd.h:57
jd_yuv_t * mcubuf
Definition tjpgd.h:76
uint8_t * dptr
Definition tjpgd.h:52
size_t(* infunc)(JDEC *, uint8_t *, size_t)
Definition tjpgd.h:79
int16_t dcv[3]
Definition tjpgd.h:59
uint8_t * inbuf
Definition tjpgd.h:53
uint16_t height
Definition tjpgd.h:61
uint16_t * huffcode[2][2]
Definition tjpgd.h:63
uint8_t * huffbits[2][2]
Definition tjpgd.h:62
int32_t * qttbl[4]
Definition tjpgd.h:65
uint8_t * huffdata[2][2]
Definition tjpgd.h:64
fl::u16 uint16_t
Definition s16x16x4.h:214
unsigned char uint8_t
Definition s16x16x4.h:209
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT