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