1 /* 2 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 /*----------------------------------------------------------------------------/ 7 / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012 8 /----------------------------------------------------------------------------*/ 9 #ifndef _TJPGDEC 10 #define _TJPGDEC 11 /*---------------------------------------------------------------------------*/ 12 /* System Configurations */ 13 14 #define JD_SZBUF 512 /* Size of stream input buffer */ 15 #define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */ 16 #define JD_USE_SCALE 1 /* Use descaling feature for output */ 17 #define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */ 18 19 /*---------------------------------------------------------------------------*/ 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /* These types must be 16-bit, 32-bit or larger integer */ 26 typedef int INT; 27 typedef unsigned int UINT; 28 29 /* These types must be 8-bit integer */ 30 typedef char CHAR; 31 typedef unsigned char UCHAR; 32 typedef unsigned char BYTE; 33 34 /* These types must be 16-bit integer */ 35 typedef short SHORT; 36 typedef unsigned short USHORT; 37 typedef unsigned short WORD; 38 typedef unsigned short WCHAR; 39 40 /* These types must be 32-bit integer */ 41 typedef long LONG; 42 typedef unsigned long ULONG; 43 typedef unsigned long DWORD; 44 45 46 /* Error code */ 47 typedef enum { 48 JDR_OK = 0, /* 0: Succeeded */ 49 JDR_INTR, /* 1: Interrupted by output function */ 50 JDR_INP, /* 2: Device error or wrong termination of input stream */ 51 JDR_MEM1, /* 3: Insufficient memory pool for the image */ 52 JDR_MEM2, /* 4: Insufficient stream input buffer */ 53 JDR_PAR, /* 5: Parameter error */ 54 JDR_FMT1, /* 6: Data format error (may be damaged data) */ 55 JDR_FMT2, /* 7: Right format but not supported */ 56 JDR_FMT3 /* 8: Not supported JPEG standard */ 57 } JRESULT; 58 59 60 61 /* Rectangular structure */ 62 typedef struct { 63 WORD left, right, top, bottom; 64 } JRECT; 65 66 67 68 /* Decompressor object structure */ 69 typedef struct JDEC JDEC; 70 struct JDEC { 71 UINT dctr; /* Number of bytes available in the input buffer */ 72 BYTE *dptr; /* Current data read ptr */ 73 BYTE *inbuf; /* Bit stream input buffer */ 74 BYTE dmsk; /* Current bit in the current read byte */ 75 BYTE scale; /* Output scaling ratio */ 76 BYTE msx, msy; /* MCU size in unit of block (width, height) */ 77 BYTE qtid[3]; /* Quantization table ID of each component */ 78 SHORT dcv[3]; /* Previous DC element of each component */ 79 WORD nrst; /* Restart inverval */ 80 UINT width, height; /* Size of the input image (pixel) */ 81 BYTE *huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ 82 WORD *huffcode[2][2]; /* Huffman code word tables [id][dcac] */ 83 BYTE *huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ 84 LONG *qttbl[4]; /* Dequaitizer tables [id] */ 85 void *workbuf; /* Working buffer for IDCT and RGB output */ 86 BYTE *mcubuf; /* Working buffer for the MCU */ 87 void *pool; /* Pointer to available memory pool */ 88 UINT sz_pool; /* Size of momory pool (bytes available) */ 89 UINT (*infunc)(JDEC *, BYTE *, UINT); /* Pointer to jpeg stream input function */ 90 void *device; /* Pointer to I/O device identifiler for the session */ 91 }; 92 93 94 95 /* TJpgDec API functions */ 96 JRESULT jd_prepare (JDEC *, UINT(*)(JDEC *, BYTE *, UINT), void *, UINT, void *); 97 JRESULT jd_decomp (JDEC *, UINT(*)(JDEC *, void *, JRECT *), BYTE); 98 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif /* _TJPGDEC */ 105