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