tjpgd.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*----------------------------------------------------------------------------/
  2. / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2020
  3. /----------------------------------------------------------------------------*/
  4. #ifndef DEF_TJPGDEC
  5. #define DEF_TJPGDEC
  6. /*---------------------------------------------------------------------------*/
  7. /* System Configurations */
  8. #define JD_SZBUF 512 /* Size of stream input buffer */
  9. #define JD_FORMAT 1 /* 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. #if defined(_WIN32) /* Main development platform */
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short uint16_t;
  19. typedef short int16_t;
  20. typedef unsigned long uint32_t;
  21. typedef long int32_t;
  22. #else
  23. #include "stdint.h"
  24. #endif
  25. /* Error code */
  26. typedef enum {
  27. JDR_OK = 0, /* 0: Succeeded */
  28. JDR_INTR, /* 1: Interrupted by output function */
  29. JDR_INP, /* 2: Device error or wrong termination of input stream */
  30. JDR_MEM1, /* 3: Insufficient memory pool for the image */
  31. JDR_MEM2, /* 4: Insufficient stream input buffer */
  32. JDR_PAR, /* 5: Parameter error */
  33. JDR_FMT1, /* 6: Data format error (may be damaged data) */
  34. JDR_FMT2, /* 7: Right format but not supported */
  35. JDR_FMT3 /* 8: Not supported JPEG standard */
  36. } JRESULT;
  37. /* Rectangular structure */
  38. typedef struct {
  39. uint16_t left, right, top, bottom;
  40. } JRECT;
  41. /* Decompressor object structure */
  42. typedef struct JDEC JDEC;
  43. struct JDEC {
  44. unsigned int dctr; /* Number of bytes available in the input buffer */
  45. uint8_t* dptr; /* Current data read ptr */
  46. uint8_t* inbuf; /* Bit stream input buffer */
  47. uint8_t dmsk; /* Current bit in the current read byte */
  48. uint8_t scale; /* Output scaling ratio */
  49. uint8_t msx, msy; /* MCU size in unit of block (width, height) */
  50. uint8_t qtid[3]; /* Quantization table ID of each component */
  51. int16_t dcv[3]; /* Previous DC element of each component */
  52. uint16_t nrst; /* Restart inverval */
  53. uint16_t width, height; /* Size of the input image (pixel) */
  54. uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
  55. uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
  56. uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
  57. int32_t* qttbl[4]; /* Dequantizer tables [id] */
  58. void* workbuf; /* Working buffer for IDCT and RGB output */
  59. uint8_t* mcubuf; /* Working buffer for the MCU */
  60. void* pool; /* Pointer to available memory pool */
  61. unsigned int sz_pool; /* Size of momory pool (bytes available) */
  62. unsigned int (*infunc)(JDEC*, uint8_t*, unsigned int); /* Pointer to jpeg stream input function */
  63. void* device; /* Pointer to I/O device identifiler for the session */
  64. };
  65. /* TJpgDec API functions */
  66. JRESULT jd_prepare (JDEC* jd, unsigned int (*infunc)(JDEC*,uint8_t*,unsigned int), void* pool, unsigned int sz_pool, void* dev);
  67. JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif /* _TJPGDEC */