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