working together with FATFileSystem

Fork of TinyJpgDec by Helmut Schmücker

Files at this revision

API Documentation at this revision

Comitter:
the_sz
Date:
Sat Nov 14 02:43:21 2015 +0000
Parent:
0:b6f284347a66
Commit message:
INT -> JPEG_INT

Changed in this revision

TinyJpgDec.cpp Show annotated file Show diff for this revision Revisions of this file
TinyJpgDec.h Show annotated file Show diff for this revision Revisions of this file
integer.h Show annotated file Show diff for this revision Revisions of this file
--- a/TinyJpgDec.cpp	Sat Mar 22 18:00:42 2014 +0000
+++ b/TinyJpgDec.cpp	Sat Nov 14 02:43:21 2015 +0000
@@ -66,7 +66,7 @@
 
 #if JD_TBLCLIP
 
-#define BYTECLIP(v) Clip8[(UINT)(v) & 0x3FF]
+#define BYTECLIP(v) Clip8[(JPG_UINT)(v) & 0x3FF]
 
 static
 const BYTE Clip8[1024] = {
@@ -112,7 +112,7 @@
 
 inline
 BYTE BYTECLIP (
-    INT val
+    JPG_INT val
 )
 {
     if (val < 0) val = 0;
@@ -132,7 +132,7 @@
 static
 void* alloc_pool (  /* Pointer to allocated memory block (NULL:no memory available) */
     JDEC* jd,       /* Pointer to the decompressor object */
-    UINT nd         /* Number of bytes to allocate */
+    JPG_UINT nd         /* Number of bytes to allocate */
 )
 {
     char *rp = 0;
@@ -157,14 +157,14 @@
 /*-----------------------------------------------------------------------*/
 
 static
-JRESULT // UINT evillive
+JRESULT // JPG_UINT evillive
 create_qt_tbl (    /* 0:OK, !0:Failed */
     JDEC* jd,           /* Pointer to the decompressor object */
     const BYTE* data,   /* Pointer to the quantizer tables */
-    UINT ndata          /* Size of input data */
+    JPG_UINT ndata          /* Size of input data */
 )
 {
-    UINT i;
+    JPG_UINT i;
     BYTE d, z;
     LONG *pb;
 
@@ -195,14 +195,14 @@
 /*-----------------------------------------------------------------------*/
 
 static
-JRESULT //UINT  evillive
+JRESULT //JPG_UINT  evillive
 create_huffman_tbl (   /* 0:OK, !0:Failed */
     JDEC* jd,               /* Pointer to the decompressor object */
     const BYTE* data,       /* Pointer to the packed huffman tables */
-    UINT ndata              /* Size of input data */
+    JPG_UINT ndata              /* Size of input data */
 )
 {
-    UINT i, j, b, np, cls, num;
+    JPG_UINT i, j, b, np, cls, num;
     BYTE d, *pb, *pd;
     WORD hc, *ph;
 
@@ -255,13 +255,13 @@
 /*-----------------------------------------------------------------------*/
 
 static
-INT bitext (    /* >=0: extracted data, <0: error code */
+JPG_INT bitext (    /* >=0: extracted data, <0: error code */
     JDEC* jd,   /* Pointer to the decompressor object */
-    UINT nbit   /* Number of bits to extract (1 to 11) */
+    JPG_UINT nbit   /* Number of bits to extract (1 to 11) */
 )
 {
     BYTE msk, s, *dp;
-    UINT dc, v, f;
+    JPG_UINT dc, v, f;
 
 
     msk = jd->dmsk;
@@ -274,14 +274,14 @@
             if (!dc) {          /* No input data is available, re-fill input buffer */
                 dp = jd->inbuf; /* Top of input buffer */
                 dc = jd->infunc(jd, dp, JD_SZBUF);
-                if (!dc) return 0 - (INT)JDR_INP;   /* Err: read error or wrong stream termination */
+                if (!dc) return 0 - (JPG_INT)JDR_INP;   /* Err: read error or wrong stream termination */
             } else {
                 dp++;           /* Next data ptr */
             }
             dc--;               /* Decrement number of available bytes */
             if (f) {            /* In flag sequence? */
                 f = 0;          /* Exit flag sequence */
-                if (*dp != 0) return 0 - (INT)JDR_FMT1; /* Err: unexpected flag is detected (may be collapted data) */
+                if (*dp != 0) return 0 - (JPG_INT)JDR_FMT1; /* Err: unexpected flag is detected (may be collapted data) */
                 *dp = s = 0xFF;         /* The flag is a data 0xFF */
             } else {
                 s = *dp;                /* Get next data byte */
@@ -301,7 +301,7 @@
     jd->dctr = dc;
     jd->dptr = dp;
 
-    return (INT)v;
+    return (JPG_INT)v;
 }
 
 
@@ -312,7 +312,7 @@
 /*-----------------------------------------------------------------------*/
 
 static
-INT huffext (           /* >=0: decoded data, <0: error code */
+JPG_INT huffext (           /* >=0: decoded data, <0: error code */
     JDEC* jd,           /* Pointer to the decompressor object */
     const BYTE* hbits,  /* Pointer to the bit distribution table */
     const WORD* hcode,  /* Pointer to the code word table */
@@ -320,7 +320,7 @@
 )
 {
     BYTE msk, s, *dp;
-    UINT dc, v, f, bl, nd;
+    JPG_UINT dc, v, f, bl, nd;
 
 
     msk = jd->dmsk;
@@ -334,7 +334,7 @@
             if (!dc) {  /* No input data is available, re-fill input buffer */
                 dp = jd->inbuf; /* Top of input buffer */
                 dc = jd->infunc(jd, dp, JD_SZBUF);
-                if (!dc) {printf("huffext KO 1\n");return 0 - (INT)JDR_INP;}   /* Err: read error or wrong stream termination */
+                if (!dc) {printf("huffext KO 1\n");return 0 - (JPG_INT)JDR_INP;}   /* Err: read error or wrong stream termination */
             } else {
                 dp++;   /* Next data ptr */
             }
@@ -342,7 +342,7 @@
             if (f) {        /* In flag sequence? */
                 f = 0;      /* Exit flag sequence */
                 if (*dp != 0)
-                    {printf("huffext KO 2\n");return 0 - (INT)JDR_FMT1;}   /* Err: unexpected flag is detected (may be collapted data) */
+                    {printf("huffext KO 2\n");return 0 - (JPG_INT)JDR_FMT1;}   /* Err: unexpected flag is detected (may be collapted data) */
                 *dp = s = 0xFF;         /* The flag is a data 0xFF */
             } else {
                 s = *dp;                /* Get next data byte */
@@ -370,7 +370,7 @@
         bl--;
     } while (bl);
     printf("huffext KO 3\n");
-    return 0 - (INT)JDR_FMT1;   /* Err: code not found (may be collapted data) */
+    return 0 - (JPG_INT)JDR_FMT1;   /* Err: code not found (may be collapted data) */
 }
 
 
@@ -389,7 +389,7 @@
     const LONG M13 = (LONG)(1.41421*4096), M2 = (LONG)(1.08239*4096), M4 = (LONG)(2.61313*4096), M5 = (LONG)(1.84776*4096);
     LONG v0, v1, v2, v3, v4, v5, v6, v7;
     LONG t10, t11, t12, t13;
-    UINT i;
+    JPG_UINT i;
 
     /* Process columns */
     for (i = 0; i < 8; i++) {
@@ -495,14 +495,14 @@
 
 static
 JRESULT 
-//INT evillive
+//JPG_INT evillive
 mcu_load (
     JDEC* jd        /* Pointer to the decompressor object */
 )
 {
     LONG *tmp = (LONG*)jd->workbuf; /* Block working buffer for de-quantize and IDCT */
-    UINT blk, nby, nbc, i, z, id, cmp;
-    INT b, d, e;
+    JPG_UINT blk, nby, nbc, i, z, id, cmp;
+    JPG_INT b, d, e;
     BYTE *bp;
     const BYTE *hb, *hd;
     const WORD *hc;
@@ -548,7 +548,7 @@
             if (b == 0) break;                  /* EOB? */
             //if (b < 0) return 0 - b;            /* Err: invalid code or input error */
             if (b < 0) {printf("mcu_load KO 3\n");return (JRESULT)(-b);}//evillive
-            z = (UINT)b >> 4;                   /* Number of leading zero elements */
+            z = (JPG_UINT)b >> 4;                   /* Number of leading zero elements */
             if (z) {
                 i += z;                         /* Skip zero elements */
                 if (i >= 64) {printf("mcu_load KO 4\n");return JDR_FMT1;}   /* Too long zero run */
@@ -585,14 +585,14 @@
 static
 JRESULT mcu_output (
     JDEC* jd,   /* Pointer to the decompressor object */
-    UINT (*outfunc)(JDEC*, void*, JRECT*),  /* RGB output function */
-    UINT x,     /* MCU position in the image (left of the MCU) */
-    UINT y      /* MCU position in the image (top of the MCU) */
+    JPG_UINT (*outfunc)(JDEC*, void*, JRECT*),  /* RGB output function */
+    JPG_UINT x,     /* MCU position in the image (left of the MCU) */
+    JPG_UINT y      /* MCU position in the image (top of the MCU) */
 )
 {
-    const INT CVACC = (sizeof (INT) > 2) ? 1024 : 128;
-    UINT ix, iy, mx, my, rx, ry;
-    INT yy, cb, cr;
+    const JPG_INT CVACC = (sizeof (JPG_INT) > 2) ? 1024 : 128;
+    JPG_UINT ix, iy, mx, my, rx, ry;
+    JPG_INT yy, cb, cr;
     BYTE *py, *pc, *rgb24;
     JRECT rect;
 
@@ -639,15 +639,15 @@
                 yy = *py++;         /* Get Y component */
 
                 /* Convert YCbCr to RGB */
-                *rgb24++ = /* R */ BYTECLIP(yy + ((INT)(1.402 * CVACC) * cr) / CVACC);
-                *rgb24++ = /* G */ BYTECLIP(yy - ((INT)(0.344 * CVACC) * cb + (INT)(0.714 * CVACC) * cr) / CVACC);
-                *rgb24++ = /* B */ BYTECLIP(yy + ((INT)(1.772 * CVACC) * cb) / CVACC);
+                *rgb24++ = /* R */ BYTECLIP(yy + ((JPG_INT)(1.402 * CVACC) * cr) / CVACC);
+                *rgb24++ = /* G */ BYTECLIP(yy - ((JPG_INT)(0.344 * CVACC) * cb + (JPG_INT)(0.714 * CVACC) * cr) / CVACC);
+                *rgb24++ = /* B */ BYTECLIP(yy + ((JPG_INT)(1.772 * CVACC) * cb) / CVACC);
             }
         }
 
         /* Descale the MCU rectangular if needed */
         if (JD_USE_SCALE && jd->scale) {
-            UINT x, y, r, g, b, s, w, a;
+            JPG_UINT x, y, r, g, b, s, w, a;
             BYTE *op;
 
             /* Get averaged RGB value of each square correcponds to a pixel */
@@ -689,9 +689,9 @@
                 py += 64;
 
                 /* Convert YCbCr to RGB */
-                *rgb24++ = /* R */ BYTECLIP(yy + ((INT)(1.402 * CVACC) * cr / CVACC));
-                *rgb24++ = /* G */ BYTECLIP(yy - ((INT)(0.344 * CVACC) * cb + (INT)(0.714 * CVACC) * cr) / CVACC);
-                *rgb24++ = /* B */ BYTECLIP(yy + ((INT)(1.772 * CVACC) * cb / CVACC));
+                *rgb24++ = /* R */ BYTECLIP(yy + ((JPG_INT)(1.402 * CVACC) * cr / CVACC));
+                *rgb24++ = /* G */ BYTECLIP(yy - ((JPG_INT)(0.344 * CVACC) * cb + (JPG_INT)(0.714 * CVACC) * cr) / CVACC);
+                *rgb24++ = /* B */ BYTECLIP(yy + ((JPG_INT)(1.772 * CVACC) * cb / CVACC));
             }
         }
     }
@@ -700,7 +700,7 @@
     mx >>= jd->scale;
     if (rx < mx) {
         BYTE *s, *d;
-        UINT x, y;
+        JPG_UINT x, y;
 
         s = d = (BYTE*)jd->workbuf;
         for (y = 0; y < ry; y++) {
@@ -717,7 +717,7 @@
     if (JD_FORMAT == 1) {
         BYTE *s = (BYTE*)jd->workbuf;
         WORD w, *d = (WORD*)s;
-        UINT n = rx * ry;
+        JPG_UINT n = rx * ry;
 
         do {
             w = (*s++ & 0xF8) << 8;     /* RRRRR----------- */
@@ -744,7 +744,7 @@
     WORD rstn   /* Expected restert sequense number */
 )
 {
-    UINT i, dc;
+    JPG_UINT i, dc;
     WORD d;
     BYTE *dp;
 
@@ -789,19 +789,19 @@
 
 
 JRESULT
-//INT
+//JPG_INT
  jd_prepare (
     JDEC* jd,           /* Blank decompressor object */
-    UINT (*infunc)(JDEC*, BYTE*, UINT), /* JPEG strem input function */
+    JPG_UINT (*infunc)(JDEC*, BYTE*, JPG_UINT), /* JPEG strem input function */
     void* pool,         /* Working buffer for the decompression session */
-    UINT sz_pool,       /* Size of working buffer */
+    JPG_UINT sz_pool,       /* Size of working buffer */
     void* dev           /* I/O device identifier for the session */
 )
 {
     BYTE *seg, b;
     WORD marker;
     DWORD ofs;
-    UINT n, i, j, len;
+    JPG_UINT n, i, j, len;
     JRESULT rc;
 
 
@@ -928,7 +928,7 @@
                 jd->dctr = 0;
                 jd->dmsk = 0; /* Prepare to read bit stream */
                 if (ofs %= JD_SZBUF) {                      /* Align read offset to JD_SZBUF */
-                    jd->dctr = jd->infunc(jd, seg + ofs, JD_SZBUF - (UINT)ofs);
+                    jd->dctr = jd->infunc(jd, seg + ofs, JD_SZBUF - (JPG_UINT)ofs);
                     jd->dptr = seg + ofs - 1;
                 }
 
@@ -966,11 +966,11 @@
 
 JRESULT jd_decomp (
     JDEC* jd,                               /* Initialized decompression object */
-    UINT (*outfunc)(JDEC*, void*, JRECT*),  /* RGB output function */
+    JPG_UINT (*outfunc)(JDEC*, void*, JRECT*),  /* RGB output function */
     BYTE scale                              /* Output de-scaling factor (0 to 3) */
 )
 {
-    UINT x, y, mx, my;
+    JPG_UINT x, y, mx, my;
     WORD rst, rsc;
     JRESULT rc;
 
--- a/TinyJpgDec.h	Sat Mar 22 18:00:42 2014 +0000
+++ b/TinyJpgDec.h	Sat Nov 14 02:43:21 2015 +0000
@@ -7,7 +7,7 @@
 /* System Configurations */
 
 #define JD_SZBUF        1024 /* Size of stream input buffer */
-#define JD_FORMAT       1   /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
+#define JD_FORMAT       0   /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */
 #define JD_USE_SCALE    1   /* Use descaling feature for output */
 #define JD_TBLCLIP      1   /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */
 
@@ -46,7 +46,7 @@
     /* Decompressor object structure */
     typedef struct JDEC JDEC;
     struct JDEC {
-        UINT dctr;              /* Number of bytes available in the input buffer */
+        JPG_UINT dctr;              /* Number of bytes available in the input buffer */
         BYTE* dptr;             /* Current data read ptr */
         BYTE* inbuf;            /* Bit stream input buffer */
         BYTE dmsk;              /* Current bit in the current read byte */
@@ -55,7 +55,7 @@
         BYTE qtid[3];           /* Quantization table ID of each component */
         SHORT dcv[3];           /* Previous DC element of each component */
         WORD nrst;              /* Restart inverval */
-        UINT width, height;     /* Size of the input image (pixel) */
+        JPG_UINT width, height;     /* Size of the input image (pixel) */
         BYTE* huffbits[2][2];   /* Huffman bit distribution tables [id][dcac] */
         WORD* huffcode[2][2];   /* Huffman code word tables [id][dcac] */
         BYTE* huffdata[2][2];   /* Huffman decoded data tables [id][dcac] */
@@ -63,16 +63,16 @@
         void* workbuf;          /* Working buffer for IDCT and RGB output */
         BYTE* mcubuf;           /* Working buffer for the MCU */
         void* pool;             /* Pointer to available memory pool */
-        UINT sz_pool;           /* Size of momory pool (bytes available) */
-        UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */
+        JPG_UINT sz_pool;           /* Size of momory pool (bytes available) */
+        JPG_UINT (*infunc)(JDEC*, BYTE*, JPG_UINT);/* Pointer to jpeg stream input function */
         void* device;           /* Pointer to I/O device identifiler for the session */
     };
 
 
 
     /* TJpgDec API functions */
-    JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*);
-    JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE);
+    JRESULT jd_prepare (JDEC*, JPG_UINT(*)(JDEC*,BYTE*,JPG_UINT), void*, JPG_UINT, void*);
+    JRESULT jd_decomp (JDEC*, JPG_UINT(*)(JDEC*,void*,JRECT*), BYTE);
 
 
 #ifdef __cplusplus
--- a/integer.h	Sat Mar 22 18:00:42 2014 +0000
+++ b/integer.h	Sat Nov 14 02:43:21 2015 +0000
@@ -15,8 +15,8 @@
 /* These types must be 16-bit, 32-bit or larger integer */
 // No! They have to be 16bit types, otherwise the Huffman decoding
 // in function huffext fails on an 32-bit LPC4088 (mbed cloud compiler)
-typedef short             INT;
-typedef unsigned short    UINT;
+typedef short             JPG_INT;
+typedef unsigned short    JPG_UINT;
 
 /* These types must be 8-bit integer */
 typedef char            CHAR;