!204 update script/libs/tsl2561.lua.
[LuatOS.git] / components / tjpgd / tjpgd.h
blob8ffe09f8039b9d4d75ea5aaca8148d160ad18d0f
1 /*----------------------------------------------------------------------------/
2 / TJpgDec - Tiny JPEG Decompressor R0.03 include file (C)ChaN, 2021
3 /----------------------------------------------------------------------------*/
4 #ifndef DEF_TJPGDEC
5 #define DEF_TJPGDEC
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
11 #include "tjpgdcnf.h"
12 #include <string.h>
14 // #if defined(_WIN32) /* VC++ or some compiler without stdint.h */
15 // typedef unsigned char uint8_t;
16 // typedef unsigned short uint16_t;
17 // typedef short int16_t;
18 // typedef unsigned long uint32_t;
19 // typedef long int32_t;
20 // #else /* Embedded platform */
21 #include <stdint.h>
22 // #endif
24 #if JD_FASTDECODE >= 1
25 typedef int16_t jd_yuv_t;
26 #else
27 typedef uint8_t jd_yuv_t;
28 #endif
31 /* Error code */
32 typedef enum {
33 JDR_OK = 0, /* 0: Succeeded */
34 JDR_INTR, /* 1: Interrupted by output function */
35 JDR_INP, /* 2: Device error or wrong termination of input stream */
36 JDR_MEM1, /* 3: Insufficient memory pool for the image */
37 JDR_MEM2, /* 4: Insufficient stream input buffer */
38 JDR_PAR, /* 5: Parameter error */
39 JDR_FMT1, /* 6: Data format error (may be broken data) */
40 JDR_FMT2, /* 7: Right format but not supported */
41 JDR_FMT3 /* 8: Not supported JPEG standard */
42 } JRESULT;
46 /* Rectangular region in the output image */
47 typedef struct {
48 uint16_t left; /* Left end */
49 uint16_t right; /* Right end */
50 uint16_t top; /* Top end */
51 uint16_t bottom; /* Bottom end */
52 } JRECT;
56 /* Decompressor object structure */
57 typedef struct JDEC JDEC;
58 struct JDEC {
59 size_t dctr; /* Number of bytes available in the input buffer */
60 uint8_t* dptr; /* Current data read ptr */
61 uint8_t* inbuf; /* Bit stream input buffer */
62 uint8_t dbit; /* Number of bits availavble in wreg or reading bit mask */
63 uint8_t scale; /* Output scaling ratio */
64 uint8_t msx, msy; /* MCU size in unit of block (width, height) */
65 uint8_t qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */
66 uint8_t ncomp; /* Number of color components 1:grayscale, 3:color */
67 int16_t dcv[3]; /* Previous DC element of each component */
68 uint16_t nrst; /* Restart inverval */
69 uint16_t width, height; /* Size of the input image (pixel) */
70 uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
71 uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
72 uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
73 int32_t* qttbl[4]; /* Dequantizer tables [id] */
74 #if JD_FASTDECODE >= 1
75 uint32_t wreg; /* Working shift register */
76 uint8_t marker; /* Detected marker (0:None) */
77 #if JD_FASTDECODE == 2
78 uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */
79 uint16_t* hufflut_ac[2]; /* Fast huffman decode tables for AC short code [id] */
80 uint8_t* hufflut_dc[2]; /* Fast huffman decode tables for DC short code [id] */
81 #endif
82 #endif
83 void* workbuf; /* Working buffer for IDCT and RGB output */
84 jd_yuv_t* mcubuf; /* Working buffer for the MCU */
85 void* pool; /* Pointer to available memory pool */
86 size_t sz_pool; /* Size of momory pool (bytes available) */
87 size_t (*infunc)(JDEC*, uint8_t*, size_t); /* Pointer to jpeg stream input function */
88 void* device; /* Pointer to I/O device identifiler for the session */
93 /* TJpgDec API functions */
94 JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev);
95 JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale);
98 #ifdef __cplusplus
100 #endif
102 #endif /* _TJPGDEC */