2
0

tjpgd.h 3.3 KB

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