tjpgd.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*----------------------------------------------------------------------------/
  2. / TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2011
  3. /----------------------------------------------------------------------------*/
  4. /* System Configurations */
  5. #define JD_SZBUF (16 * 1024) /* Size of stream input buffer (should be multiple of 512) */
  6. #define JD_USE_SCALE 0 /* Use descaling feature for output */
  7. /*---------------------------------------------------------------------------*/
  8. #include "integer.h"
  9. /* Error code */
  10. typedef enum {
  11. JDR_OK = 0, /* 0: Succeeded */
  12. JDR_INTR, /* 1: Interrupted by output function */
  13. JDR_INP, /* 2: Device error or wrong termination of input stream */
  14. JDR_MEM1, /* 3: Insufficient memory pool for the image */
  15. JDR_MEM2, /* 4: Insufficient stream input buffer */
  16. JDR_PAR, /* 5: Parameter error */
  17. JDR_FMT1, /* 6: Data format error (may be damaged data) */
  18. JDR_FMT2, /* 7: Right format but not supported */
  19. JDR_FMT3 /* 8: Not supported JPEG standard */
  20. } JRESULT;
  21. typedef struct {
  22. WORD left, right, top, bottom;
  23. } JRECT;
  24. /* Decompressor object structure */
  25. typedef struct JDEC JDEC;
  26. struct JDEC {
  27. UINT dctr; /* Number of bytes available in the input buffer */
  28. BYTE* dptr; /* Current data read ptr */
  29. BYTE* inbuf; /* Bit stream input buffer */
  30. BYTE dmsk; /* Current bit in the current read byte */
  31. BYTE scale; /* Output scaling ratio */
  32. BYTE msx, msy; /* MCU size in unit of block (width, height) */
  33. BYTE qtid[3]; /* Quantization table ID of each component */
  34. SHORT dcv[3]; /* Previous DC element of each component */
  35. WORD nrst; /* Restart inverval */
  36. UINT width, height; /* Size of the input image (pixel) */
  37. BYTE* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */
  38. WORD* huffcode[2][2]; /* Huffman code word tables [id][dcac] */
  39. BYTE* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */
  40. LONG* qttbl[4]; /* Dequaitizer tables [id] */
  41. void* workbuf; /* Working buffer for IDCT and RGB output */
  42. BYTE* mcubuf; /* Working buffer for the MCU */
  43. void* pool; /* Pointer to available memory pool */
  44. UINT sz_pool; /* Size of momory pool (bytes available) */
  45. UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
  46. UINT (*outfunc)(JDEC*, void*, JRECT*); /* Pointer to RGB output function */
  47. void* device; /* Pointer to I/O device identifiler for the session */
  48. BYTE format; /* the output format, 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
  49. };
  50. #define LDB_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr))<<8)|(WORD)*(BYTE*)((ptr)+1))
  51. /* TJpgDec API functions */
  52. JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*);
  53. JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE);