acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

tjpgd.h (3345B)

      1 /*----------------------------------------------------------------------------/
      2 / TJpgDec - Tiny JPEG Decompressor R0.03 include file         (C)ChaN, 2021
      3 /----------------------------------------------------------------------------*/
      4 #ifndef DEF_TJPGDEC
      5 #define DEF_TJPGDEC
      6 
      7 #ifdef __cplusplus
      8 extern "C" {
      9 #endif
     10 
     11 #include "../../../lv_conf_internal.h"
     12 #if LV_USE_SJPG
     13 
     14 #include "tjpgdcnf.h"
     15 #include <string.h>
     16 #include <stdint.h>
     17 
     18 #if JD_FASTDECODE >= 1
     19 typedef int16_t jd_yuv_t;
     20 #else
     21 typedef uint8_t jd_yuv_t;
     22 #endif
     23 
     24 
     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 broken data) */
     34 	JDR_FMT2,	/* 7: Right format but not supported */
     35 	JDR_FMT3	/* 8: Not supported JPEG standard */
     36 } JRESULT;
     37 
     38 /* Rectangular region in the output image */
     39 typedef struct {
     40 	uint16_t left;		/* Left end */
     41 	uint16_t right;		/* Right end */
     42 	uint16_t top;		/* Top end */
     43 	uint16_t bottom;	/* Bottom end */
     44 } JRECT;
     45 
     46 /* Decompressor object structure */
     47 typedef struct JDEC JDEC;
     48 struct JDEC {
     49 	size_t dctr;				/* Number of bytes available in the input buffer */
     50 	uint8_t* dptr;				/* Current data read ptr */
     51 	uint8_t* inbuf;				/* Bit stream input buffer */
     52 	uint8_t dbit;				/* Number of bits availavble in wreg or reading bit mask */
     53 	uint8_t scale;				/* Output scaling ratio */
     54 	uint8_t msx, msy;			/* MCU size in unit of block (width, height) */
     55 	uint8_t qtid[3];			/* Quantization table ID of each component, Y, Cb, Cr */
     56 	uint8_t ncomp;				/* Number of color components 1:grayscale, 3:color */
     57 	int16_t dcv[3];				/* Previous DC element of each component */
     58 	uint16_t nrst;				/* Restart inverval */
     59 	uint16_t width, height;		/* Size of the input image (pixel) */
     60 	uint8_t* huffbits[2][2];	/* Huffman bit distribution tables [id][dcac] */
     61 	uint16_t* huffcode[2][2];	/* Huffman code word tables [id][dcac] */
     62 	uint8_t* huffdata[2][2];	/* Huffman decoded data tables [id][dcac] */
     63 	int32_t* qttbl[4];			/* Dequantizer tables [id] */
     64 #if JD_FASTDECODE >= 1
     65 	uint32_t wreg;				/* Working shift register */
     66 	uint8_t marker;				/* Detected marker (0:None) */
     67 #if JD_FASTDECODE == 2
     68 	uint8_t longofs[2][2];		/* Table offset of long code [id][dcac] */
     69 	uint16_t* hufflut_ac[2];	/* Fast huffman decode tables for AC short code [id] */
     70 	uint8_t* hufflut_dc[2];		/* Fast huffman decode tables for DC short code [id] */
     71 #endif
     72 #endif
     73 	void* workbuf;				/* Working buffer for IDCT and RGB output */
     74 	jd_yuv_t* mcubuf;			/* Working buffer for the MCU */
     75 	void* pool;					/* Pointer to available memory pool */
     76 	size_t sz_pool;				/* Size of momory pool (bytes available) */
     77 	size_t (*infunc)(JDEC*, uint8_t*, size_t);	/* Pointer to jpeg stream input function */
     78 	void* device;				/* Pointer to I/O device identifiler for the session */
     79 };
     80 
     81 
     82 
     83 /* TJpgDec API functions */
     84 JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev);
     85 JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale);
     86 
     87 #endif /*LV_USE_SJPG*/
     88 
     89 #ifdef __cplusplus
     90 }
     91 #endif
     92 
     93 #endif /* _TJPGDEC */