changeset 899:63fd1801f983

Mangle new stb_image to our purposes.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 23 Feb 2015 19:49:58 +0200
parents 448eaa7239f0
children df2a9c635175
files src/dmimage.c src/stb_image.c
diffstat 2 files changed, 302 insertions(+), 331 deletions(-) [+]
line wrap: on
line diff
--- a/src/dmimage.c	Mon Feb 23 19:49:37 2015 +0200
+++ b/src/dmimage.c	Mon Feb 23 19:49:58 2015 +0200
@@ -7,10 +7,18 @@
 #include "dmimage.h"
 
 
+//#define STB_IMAGE_STATIC 1
+#define STB_IMAGE_IMPLEMENTATION 1
 #define STBI_INTERNAL_ZLIB 1
+#define STBI_NO_FAILURE_STRINGS 1
 #define STBI_FAILURE_USERMSG 1
 #define STBI_NO_STDIO 1
 #define STBI_NO_HDR 1
+
+#define STBI_MALLOC(sz)    dmMalloc(sz)
+#define STBI_REALLOC(p,sz) dmRealloc(p,sz)
+#define STBI_FREE(p)       dmFree(p)
+
 #include "stb_image.c"
 
 
@@ -82,7 +90,7 @@
 }
 
 
-static void dmSTBIskip(void *user, unsigned int n)
+static void dmSTBIskip(void *user, int n)
 {
     dmfseek((DMResource *) user, n, SEEK_CUR);
 }
--- a/src/stb_image.c	Mon Feb 23 19:49:37 2015 +0200
+++ b/src/stb_image.c	Mon Feb 23 19:49:58 2015 +0200
@@ -393,8 +393,6 @@
    STBI_rgb_alpha  = 4
 };
 
-typedef unsigned char stbi_uc;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -421,18 +419,18 @@
    int      (*eof)   (void *user);                       // returns nonzero if we are at end of file/data
 } stbi_io_callbacks;
 
-STBIDEF stbi_uc *stbi_load               (char              const *filename,           int *x, int *y, int *comp, int req_comp);
-STBIDEF stbi_uc *stbi_load_from_memory   (stbi_uc           const *buffer, int len   , int *x, int *y, int *comp, int req_comp);
-STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk  , void *user, int *x, int *y, int *comp, int req_comp);
+STBIDEF Uint8 *stbi_load               (char              const *filename,           int *x, int *y, int *comp, int req_comp);
+STBIDEF Uint8 *stbi_load_from_memory   (Uint8           const *buffer, int len   , int *x, int *y, int *comp, int req_comp);
+STBIDEF Uint8 *stbi_load_from_callbacks(stbi_io_callbacks const *clbk  , void *user, int *x, int *y, int *comp, int req_comp);
 
 #ifndef STBI_NO_STDIO
-STBIDEF stbi_uc *stbi_load_from_file  (FILE *f,                  int *x, int *y, int *comp, int req_comp);
+STBIDEF Uint8 *stbi_load_from_file  (FILE *f,                  int *x, int *y, int *comp, int req_comp);
 // for stbi_load_from_file, file pointer is left pointing immediately after image
 #endif
 
 #ifndef STBI_NO_LINEAR
    STBIDEF float *stbi_loadf                 (char const *filename,           int *x, int *y, int *comp, int req_comp);
-   STBIDEF float *stbi_loadf_from_memory     (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
+   STBIDEF float *stbi_loadf_from_memory     (Uint8 const *buffer, int len, int *x, int *y, int *comp, int req_comp);
    STBIDEF float *stbi_loadf_from_callbacks  (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
 
    #ifndef STBI_NO_STDIO
@@ -452,7 +450,7 @@
 
 // stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
 STBIDEF int    stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
-STBIDEF int    stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
+STBIDEF int    stbi_is_hdr_from_memory(Uint8 const *buffer, int len);
 #ifndef STBI_NO_STDIO
 STBIDEF int      stbi_is_hdr          (char const *filename);
 STBIDEF int      stbi_is_hdr_from_file(FILE *f);
@@ -467,7 +465,7 @@
 STBIDEF void     stbi_image_free      (void *retval_from_stbi_load);
 
 // get image dimensions & components without fully decoding
-STBIDEF int      stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
+STBIDEF int      stbi_info_from_memory(Uint8 const *buffer, int len, int *x, int *y, int *comp);
 STBIDEF int      stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
 
 #ifndef STBI_NO_STDIO
@@ -488,17 +486,6 @@
 STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
 
 
-// ZLIB client - used by PNG, available for other purposes
-
-STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
-STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);
-STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
-STBIDEF int   stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
-
-STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
-STBIDEF int   stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
-
-
 #ifdef __cplusplus
 }
 #endif
@@ -543,10 +530,6 @@
    #endif
 #endif
 
-#if defined(STBI_NO_PNG) && !defined(STBI_SUPPORT_ZLIB) && !defined(STBI_NO_ZLIB)
-#define STBI_NO_ZLIB
-#endif
-
 
 #include <stdarg.h>
 #include <stddef.h> // ptrdiff_t on osx
@@ -567,38 +550,9 @@
 #endif
 
 
-#ifndef _MSC_VER
-   #ifdef __cplusplus
-   #define stbi_inline inline
-   #else
-   #define stbi_inline
-   #endif
-#else
-   #define stbi_inline __forceinline
-#endif
-
-
-#ifdef _MSC_VER
-typedef unsigned short stbi__uint16;
-typedef   signed short stbi__int16;
-typedef unsigned int   stbi__uint32;
-typedef   signed int   stbi__int32;
-#else
-#include <stdint.h>
-typedef uint16_t stbi__uint16;
-typedef int16_t  stbi__int16;
-typedef uint32_t stbi__uint32;
-typedef int32_t  stbi__int32;
-#endif
-
-// should produce compiler error if size is wrong
-typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
-
-#ifdef _MSC_VER
+#define stbi_inline inline
 #define STBI_NOTUSED(v)  (void)(v)
-#else
-#define STBI_NOTUSED(v)  (void)sizeof(v)
-#endif
+
 
 #ifdef _MSC_VER
 #define STBI_HAS_LROTL
@@ -706,7 +660,7 @@
 // contains all the IO context, plus some basic image information
 typedef struct
 {
-   stbi__uint32 img_x, img_y;
+   Uint32 img_x, img_y;
    int img_n, img_out_n;
 
    stbi_io_callbacks io;
@@ -714,22 +668,22 @@
 
    int read_from_callbacks;
    int buflen;
-   stbi_uc buffer_start[128];
-
-   stbi_uc *img_buffer, *img_buffer_end;
-   stbi_uc *img_buffer_original;
+   Uint8 buffer_start[128];
+
+   Uint8 *img_buffer, *img_buffer_end;
+   Uint8 *img_buffer_original;
 } stbi__context;
 
 
 static void stbi__refill_buffer(stbi__context *s);
 
 // initialize a memory-decode context
-static void stbi__start_mem(stbi__context *s, stbi_uc const *buffer, int len)
+static void stbi__start_mem(stbi__context *s, Uint8 const *buffer, int len)
 {
    s->io.read = NULL;
    s->read_from_callbacks = 0;
-   s->img_buffer = s->img_buffer_original = (stbi_uc *) buffer;
-   s->img_buffer_end = (stbi_uc *) buffer+len;
+   s->img_buffer = s->img_buffer_original = (Uint8 *) buffer;
+   s->img_buffer_end = (Uint8 *) buffer+len;
 }
 
 // initialize a callback-based context
@@ -786,31 +740,31 @@
 
 #ifndef STBI_NO_JPEG
 static int      stbi__jpeg_test(stbi__context *s);
-static stbi_uc *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_PNG
 static int      stbi__png_test(stbi__context *s);
-static stbi_uc *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_BMP
 static int      stbi__bmp_test(stbi__context *s);
-static stbi_uc *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_TGA
 static int      stbi__tga_test(stbi__context *s);
-static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_PSD
 static int      stbi__psd_test(stbi__context *s);
-static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
@@ -822,19 +776,19 @@
 
 #ifndef STBI_NO_PIC
 static int      stbi__pic_test(stbi__context *s);
-static stbi_uc *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_GIF
 static int      stbi__gif_test(stbi__context *s);
-static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
 #ifndef STBI_NO_PNM
 static int      stbi__pnm_test(stbi__context *s);
-static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
+static Uint8 *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
 static int      stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
 #endif
 
@@ -846,11 +800,13 @@
    return stbi__g_failure_reason;
 }
 
+#ifndef STBI_NO_FAILURE_STRINGS
 static int stbi__err(const char *str)
 {
    stbi__g_failure_reason = str;
    return 0;
 }
+#endif
 
 static void *stbi__malloc(size_t size)
 {
@@ -878,11 +834,11 @@
 }
 
 #ifndef STBI_NO_LINEAR
-static float   *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp);
+static float   *stbi__ldr_to_hdr(Uint8 *data, int x, int y, int comp);
 #endif
 
 #ifndef STBI_NO_HDR
-static stbi_uc *stbi__hdr_to_ldr(float   *data, int x, int y, int comp);
+static Uint8 *stbi__hdr_to_ldr(float   *data, int x, int y, int comp);
 #endif
 
 static unsigned char *stbi_load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)
@@ -940,7 +896,7 @@
 }
 
 
-STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)
+STBIDEF Uint8 *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)
 {
    FILE *f = stbi__fopen(filename, "rb");
    unsigned char *result;
@@ -950,7 +906,7 @@
    return result;
 }
 
-STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)
+STBIDEF Uint8 *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp)
 {
    unsigned char *result;
    stbi__context s;
@@ -964,14 +920,14 @@
 }
 #endif //!STBI_NO_STDIO
 
-STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
+STBIDEF Uint8 *stbi_load_from_memory(Uint8 const *buffer, int len, int *x, int *y, int *comp, int req_comp)
 {
    stbi__context s;
    stbi__start_mem(&s,buffer,len);
    return stbi_load_main(&s,x,y,comp,req_comp);
 }
 
-STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)
+STBIDEF Uint8 *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)
 {
    stbi__context s;
    stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
@@ -992,7 +948,7 @@
    return stbi__errpf("unknown image type", "Image not of any known type, or corrupt");
 }
 
-STBIDEF float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
+STBIDEF float *stbi_loadf_from_memory(Uint8 const *buffer, int len, int *x, int *y, int *comp, int req_comp)
 {
    stbi__context s;
    stbi__start_mem(&s,buffer,len);
@@ -1031,7 +987,7 @@
 // defined, for API simplicity; if STBI_NO_LINEAR is defined, it always
 // reports false!
 
-STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len)
+STBIDEF int stbi_is_hdr_from_memory(Uint8 const *buffer, int len)
 {
    #ifndef STBI_NO_HDR
    stbi__context s;
@@ -1075,6 +1031,8 @@
    stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
    return stbi__hdr_test(&s);
    #else
+   (void) clbk;
+   (void) user;
    return 0;
    #endif
 }
@@ -1119,7 +1077,7 @@
    }
 }
 
-stbi_inline static stbi_uc stbi__get8(stbi__context *s)
+stbi_inline static Uint8 stbi__get8(stbi__context *s)
 {
    if (s->img_buffer < s->img_buffer_end)
       return *s->img_buffer++;
@@ -1155,7 +1113,7 @@
    s->img_buffer += n;
 }
 
-static int stbi__getn(stbi__context *s, stbi_uc *buffer, int n)
+static int stbi__getn(stbi__context *s, Uint8 *buffer, int n)
 {
    if (s->io.read) {
       int blen = (int) (s->img_buffer_end - s->img_buffer);
@@ -1185,9 +1143,9 @@
    return (z << 8) + stbi__get8(s);
 }
 
-static stbi__uint32 stbi__get32be(stbi__context *s)
-{
-   stbi__uint32 z = stbi__get16be(s);
+static Uint32 stbi__get32be(stbi__context *s)
+{
+   Uint32 z = stbi__get16be(s);
    return (z << 16) + stbi__get16be(s);
 }
 
@@ -1197,13 +1155,13 @@
    return z + (stbi__get8(s) << 8);
 }
 
-static stbi__uint32 stbi__get32le(stbi__context *s)
-{
-   stbi__uint32 z = stbi__get16le(s);
+static Uint32 stbi__get32le(stbi__context *s)
+{
+   Uint32 z = stbi__get16le(s);
    return z + (stbi__get16le(s) << 16);
 }
 
-#define STBI__BYTECAST(x)  ((stbi_uc) ((x) & 255))  // truncate int to byte without warnings
+#define STBI__BYTECAST(x)  ((Uint8) ((x) & 255))  // truncate int to byte without warnings
 
 
 //////////////////////////////////////////////////////////////////////////////
@@ -1217,9 +1175,9 @@
 //  assume data buffer is malloced, so malloc a new one and free that one
 //  only failure mode is malloc failing
 
-static stbi_uc stbi__compute_y(int r, int g, int b)
-{
-   return (stbi_uc) (((r*77) + (g*150) +  (29*b)) >> 8);
+static Uint8 stbi__compute_y(int r, int g, int b)
+{
+   return (Uint8) (((r*77) + (g*150) +  (29*b)) >> 8);
 }
 
 static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int req_comp, unsigned int x, unsigned int y)
@@ -1267,7 +1225,7 @@
 }
 
 #ifndef STBI_NO_LINEAR
-static float   *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)
+static float   *stbi__ldr_to_hdr(Uint8 *data, int x, int y, int comp)
 {
    int i,k,n;
    float *output = (float *) stbi__malloc(x * y * comp * sizeof(float));
@@ -1287,10 +1245,10 @@
 
 #ifndef STBI_NO_HDR
 #define stbi__float2int(x)   ((int) (x))
-static stbi_uc *stbi__hdr_to_ldr(float   *data, int x, int y, int comp)
+static Uint8 *stbi__hdr_to_ldr(float   *data, int x, int y, int comp)
 {
    int i,k,n;
-   stbi_uc *output = (stbi_uc *) stbi__malloc(x * y * comp);
+   Uint8 *output = (Uint8 *) stbi__malloc(x * y * comp);
    if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); }
    // compute number of non-alpha components
    if (comp & 1) n = comp; else n = comp-1;
@@ -1299,13 +1257,13 @@
          float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f;
          if (z < 0) z = 0;
          if (z > 255) z = 255;
-         output[i*comp + k] = (stbi_uc) stbi__float2int(z);
+         output[i*comp + k] = (Uint8) stbi__float2int(z);
       }
       if (k < comp) {
          float z = data[i*comp+k] * 255 + 0.5f;
          if (z < 0) z = 0;
          if (z > 255) z = 255;
-         output[i*comp + k] = (stbi_uc) stbi__float2int(z);
+         output[i*comp + k] = (Uint8) stbi__float2int(z);
       }
    }
    STBI_FREE(data);
@@ -1341,11 +1299,11 @@
 
 typedef struct
 {
-   stbi_uc  fast[1 << FAST_BITS];
+   Uint8  fast[1 << FAST_BITS];
    // weirdly, repacking this into AoS is a 10% speed loss, instead of a win
-   stbi__uint16 code[256];
-   stbi_uc  values[256];
-   stbi_uc  size[257];
+   Uint16 code[256];
+   Uint8  values[256];
+   Uint8  size[257];
    unsigned int maxcode[18];
    int    delta[17];   // old 'firstsymbol' - old 'firstcode'
 } stbi__huffman;
@@ -1355,8 +1313,8 @@
    stbi__context *s;
    stbi__huffman huff_dc[4];
    stbi__huffman huff_ac[4];
-   stbi_uc dequant[4][64];
-   stbi__int16 fast_ac[4][1 << FAST_BITS];
+   Uint8 dequant[4][64];
+   Sint16 fast_ac[4][1 << FAST_BITS];
 
 // sizes for components, interleaved MCUs
    int img_h_max, img_v_max;
@@ -1373,14 +1331,14 @@
       int dc_pred;
 
       int x,y,w2,h2;
-      stbi_uc *data;
+      Uint8 *data;
       void *raw_data, *raw_coeff;
-      stbi_uc *linebuf;
+      Uint8 *linebuf;
       short   *coeff;   // progressive only
       int      coeff_w, coeff_h; // number of 8x8 coefficient blocks
    } img_comp[4];
 
-   stbi__uint32   code_buffer; // jpeg entropy-coded buffer
+   Uint32   code_buffer; // jpeg entropy-coded buffer
    int            code_bits;   // number of valid bits
    unsigned char  marker;      // marker seen while filling entropy buffer
    int            nomore;      // flag if we saw a marker so must stop
@@ -1396,9 +1354,9 @@
    int restart_interval, todo;
 
 // kernels
-   void (*idct_block_kernel)(stbi_uc *out, int out_stride, short data[64]);
-   void (*YCbCr_to_RGB_kernel)(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step);
-   stbi_uc *(*resample_row_hv_2_kernel)(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs);
+   void (*idct_block_kernel)(Uint8 *out, int out_stride, short data[64]);
+   void (*YCbCr_to_RGB_kernel)(Uint8 *out, const Uint8 *y, const Uint8 *pcb, const Uint8 *pcr, int count, int step);
+   Uint8 *(*resample_row_hv_2_kernel)(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs);
 } stbi__jpeg;
 
 static int stbi__build_huffman(stbi__huffman *h, int *count)
@@ -1407,7 +1365,7 @@
    // build size list for each symbol (from JPEG spec)
    for (i=0; i < 16; ++i)
       for (j=0; j < count[i]; ++j)
-         h->size[k++] = (stbi_uc) (i+1);
+         h->size[k++] = (Uint8) (i+1);
    h->size[k] = 0;
 
    // compute actual symbols (from jpeg spec)
@@ -1418,7 +1376,7 @@
       h->delta[j] = k - code;
       if (h->size[k] == j) {
          while (h->size[k] == j)
-            h->code[k++] = (stbi__uint16) (code++);
+            h->code[k++] = (Uint16) (code++);
          if (code-1 >= (1 << j)) return stbi__err("bad code lengths","Corrupt JPEG");
       }
       // compute largest code + 1 for this size, preshifted as needed later
@@ -1435,7 +1393,7 @@
          int c = h->code[i] << (FAST_BITS-s);
          int m = 1 << (FAST_BITS-s);
          for (j=0; j < m; ++j) {
-            h->fast[c+j] = (stbi_uc) i;
+            h->fast[c+j] = (Uint8) i;
          }
       }
    }
@@ -1444,11 +1402,11 @@
 
 // build a table that decodes both magnitude and value of small ACs in
 // one go.
-static void stbi__build_fast_ac(stbi__int16 *fast_ac, stbi__huffman *h)
+static void stbi__build_fast_ac(Sint16 *fast_ac, stbi__huffman *h)
 {
    int i;
    for (i=0; i < (1 << FAST_BITS); ++i) {
-      stbi_uc fast = h->fast[i];
+      Uint8 fast = h->fast[i];
       fast_ac[i] = 0;
       if (fast < 255) {
          int rs = h->values[fast];
@@ -1463,7 +1421,7 @@
             if (k < m) k += (-1 << magbits) + 1;
             // if the result is small enough, we can fit it in fast_ac table
             if (k >= -128 && k <= 127)
-               fast_ac[i] = (stbi__int16) ((k << 8) + (run << 4) + (len + magbits));
+               fast_ac[i] = (Sint16) ((k << 8) + (run << 4) + (len + magbits));
          }
       }
    }
@@ -1487,7 +1445,7 @@
 }
 
 // (1 << n) - 1
-static stbi__uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535};
+static Uint32 stbi__bmask[17]={0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535};
 
 // decode a jpeg huffman value from the bitstream
 stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h)
@@ -1550,7 +1508,7 @@
    int sgn;
    if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
 
-   sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB
+   sgn = (Sint32)j->code_buffer >> 31; // sign bit is always in MSB
    k = stbi_lrot(j->code_buffer, n);
    j->code_buffer = k & ~stbi__bmask[n];
    k &= stbi__bmask[n];
@@ -1582,7 +1540,7 @@
 
 // given a value that's at position X in the zigzag stream,
 // where does it appear in the 8x8 matrix coded as row-major?
-static stbi_uc stbi__jpeg_dezigzag[64+15] =
+static Uint8 stbi__jpeg_dezigzag[64+15] =
 {
     0,  1,  8, 16,  9,  2,  3, 10,
    17, 24, 32, 25, 18, 11,  4,  5,
@@ -1598,7 +1556,7 @@
 };
 
 // decode one 64-entry block--
-static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, stbi__int16 *fac, int b, stbi_uc *dequant)
+static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman *hdc, stbi__huffman *hac, Sint16 *fac, int b, Uint8 *dequant)
 {
    int diff,dc,k;
    int t;
@@ -1677,7 +1635,7 @@
 
 // @OPTIMIZE: store non-zigzagged during the decode passes,
 // and only de-zigzag when dequantizing
-static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, stbi__int16 *fac)
+static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__huffman *hac, Sint16 *fac)
 {
    int k;
    if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
@@ -1797,14 +1755,14 @@
 }
 
 // take a -128..127 value and stbi__clamp it and convert to 0..255
-stbi_inline static stbi_uc stbi__clamp(int x)
+stbi_inline static Uint8 stbi__clamp(int x)
 {
    // trick to use a single test to catch both cases
    if ((unsigned int) x > 255) {
       if (x < 0) return 0;
       if (x > 255) return 255;
    }
-   return (stbi_uc) x;
+   return (Uint8) x;
 }
 
 #define stbi__f2f(x)  ((int) (((x) * 4096 + 0.5)))
@@ -1848,10 +1806,10 @@
    t1 += p2+p4;                                \
    t0 += p1+p3;
 
-static void stbi__idct_block(stbi_uc *out, int out_stride, short data[64])
+static void stbi__idct_block(Uint8 *out, int out_stride, short data[64])
 {
    int i,val[64],*v=val;
-   stbi_uc *o;
+   Uint8 *o;
    short *d = data;
 
    // columns
@@ -1911,7 +1869,7 @@
 // sse2 integer IDCT. not the fastest possible implementation but it
 // produces bit-identical results to the generic C version so it's
 // fully "transparent".
-static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
+static void stbi__idct_simd(Uint8 *out, int out_stride, short data[64])
 {
    // This is constructed to match our regular (generic) integer IDCT exactly.
    __m128i row0, row1, row2, row3, row4, row5, row6, row7;
@@ -2092,7 +2050,7 @@
 
 // NEON integer IDCT. should produce bit-identical
 // results to the generic C version.
-static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64])
+static void stbi__idct_simd(Uint8 *out, int out_stride, short data[64])
 {
    int16x8_t row0, row1, row2, row3, row4, row5, row6, row7;
 
@@ -2300,9 +2258,9 @@
 // if there's a pending marker from the entropy stream, return that
 // otherwise, fetch from the stream and get a marker. if there's no
 // marker, return 0xff, which is never a valid marker value
-static stbi_uc stbi__get_marker(stbi__jpeg *j)
-{
-   stbi_uc x;
+static Uint8 stbi__get_marker(stbi__jpeg *j)
+{
+   Uint8 x;
    if (j->marker != STBI__MARKER_none) { x = j->marker; j->marker = STBI__MARKER_none; return x; }
    x = stbi__get8(j->s);
    if (x != 0xff) return STBI__MARKER_none;
@@ -2454,7 +2412,7 @@
    }
 }
 
-static void stbi__jpeg_dequantize(short *data, stbi_uc *dequant)
+static void stbi__jpeg_dequantize(short *data, Uint8 *dequant)
 {
    int i;
    for (i=0; i < 64; ++i)
@@ -2509,7 +2467,7 @@
       case 0xC4: // DHT - define huffman table
          L = stbi__get16be(z->s)-2;
          while (L > 0) {
-            stbi_uc *v;
+            Uint8 *v;
             int sizes[16],i,n=0;
             int q = stbi__get8(z->s);
             int tc = q >> 4;
@@ -2649,7 +2607,7 @@
          return stbi__err("outofmem", "Out of memory");
       }
       // align blocks for idct using mmx/sse
-      z->img_comp[i].data = (stbi_uc*) (((size_t) z->img_comp[i].raw_data + 15) & ~15);
+      z->img_comp[i].data = (Uint8*) (((size_t) z->img_comp[i].raw_data + 15) & ~15);
       z->img_comp[i].linebuf = NULL;
       if (z->progressive) {
          z->img_comp[i].coeff_w = (z->img_comp[i].w2 + 7) >> 3;
@@ -2732,12 +2690,12 @@
 
 // static jfif-centered resampling (across block boundaries)
 
-typedef stbi_uc *(*resample_row_func)(stbi_uc *out, stbi_uc *in0, stbi_uc *in1,
+typedef Uint8 *(*resample_row_func)(Uint8 *out, Uint8 *in0, Uint8 *in1,
                                     int w, int hs);
 
-#define stbi__div4(x) ((stbi_uc) ((x) >> 2))
-
-static stbi_uc *resample_row_1(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+#define stbi__div4(x) ((Uint8) ((x) >> 2))
+
+static Uint8 *resample_row_1(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    STBI_NOTUSED(out);
    STBI_NOTUSED(in_far);
@@ -2746,7 +2704,7 @@
    return in_near;
 }
 
-static stbi_uc* stbi__resample_row_v_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static Uint8* stbi__resample_row_v_2(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    // need to generate two samples vertically for every one in input
    int i;
@@ -2756,11 +2714,11 @@
    return out;
 }
 
-static stbi_uc*  stbi__resample_row_h_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static Uint8*  stbi__resample_row_h_2(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    // need to generate two samples horizontally for every one in input
    int i;
-   stbi_uc *input = in_near;
+   Uint8 *input = in_near;
 
    if (w == 1) {
       // if only one sample, can't do any interpolation
@@ -2784,9 +2742,9 @@
    return out;
 }
 
-#define stbi__div16(x) ((stbi_uc) ((x) >> 4))
-
-static stbi_uc *stbi__resample_row_hv_2(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+#define stbi__div16(x) ((Uint8) ((x) >> 4))
+
+static Uint8 *stbi__resample_row_hv_2(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    // need to generate 2x2 samples for every one in input
    int i,t0,t1;
@@ -2811,7 +2769,7 @@
 }
 
 #if defined(STBI_SSE2) || defined(STBI_NEON)
-static stbi_uc *stbi__resample_row_hv_2_simd(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static Uint8 *stbi__resample_row_hv_2_simd(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    // need to generate 2x2 samples for every one in input
    int i=0,t0,t1;
@@ -2927,7 +2885,7 @@
 }
 #endif
 
-static stbi_uc *stbi__resample_row_generic(stbi_uc *out, stbi_uc *in_near, stbi_uc *in_far, int w, int hs)
+static Uint8 *stbi__resample_row_generic(Uint8 *out, Uint8 *in_near, Uint8 *in_far, int w, int hs)
 {
    // resample with nearest-neighbor
    int i,j;
@@ -2942,7 +2900,7 @@
 // this is the same YCbCr-to-RGB calculation that stb_image has used
 // historically before the algorithm changes in 1.49
 #define float2fixed(x)  ((int) ((x) * 65536 + 0.5))
-static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step)
+static void stbi__YCbCr_to_RGB_row(Uint8 *out, const Uint8 *y, const Uint8 *pcb, const Uint8 *pcr, int count, int step)
 {
    int i;
    for (i=0; i < count; ++i) {
@@ -2959,9 +2917,9 @@
       if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; }
       if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; }
       if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; }
-      out[0] = (stbi_uc)r;
-      out[1] = (stbi_uc)g;
-      out[2] = (stbi_uc)b;
+      out[0] = (Uint8)r;
+      out[1] = (Uint8)g;
+      out[2] = (Uint8)b;
       out[3] = 255;
       out += step;
    }
@@ -2970,7 +2928,7 @@
 // this is a reduced-precision calculation of YCbCr-to-RGB introduced
 // to make sure the code produces the same results in both SIMD and scalar
 #define float2fixed(x)  (((int) ((x) * 4096.0f + 0.5f)) << 8)
-static void stbi__YCbCr_to_RGB_row(stbi_uc *out, const stbi_uc *y, const stbi_uc *pcb, const stbi_uc *pcr, int count, int step)
+static void stbi__YCbCr_to_RGB_row(Uint8 *out, const Uint8 *y, const Uint8 *pcb, const Uint8 *pcr, int count, int step)
 {
    int i;
    for (i=0; i < count; ++i) {
@@ -2987,9 +2945,9 @@
       if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; }
       if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; }
       if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; }
-      out[0] = (stbi_uc)r;
-      out[1] = (stbi_uc)g;
-      out[2] = (stbi_uc)b;
+      out[0] = (Uint8)r;
+      out[1] = (Uint8)g;
+      out[2] = (Uint8)b;
       out[3] = 255;
       out += step;
    }
@@ -2997,7 +2955,7 @@
 #endif
 
 #if defined(STBI_SSE2) || defined(STBI_NEON)
-static void stbi__YCbCr_to_RGB_simd(stbi_uc *out, stbi_uc const *y, stbi_uc const *pcb, stbi_uc const *pcr, int count, int step)
+static void stbi__YCbCr_to_RGB_simd(Uint8 *out, Uint8 const *y, Uint8 const *pcb, Uint8 const *pcr, int count, int step)
 {
    int i = 0;
 
@@ -3122,9 +3080,9 @@
       if ((unsigned) r > 255) { if (r < 0) r = 0; else r = 255; }
       if ((unsigned) g > 255) { if (g < 0) g = 0; else g = 255; }
       if ((unsigned) b > 255) { if (b < 0) b = 0; else b = 255; }
-      out[0] = (stbi_uc)r;
-      out[1] = (stbi_uc)g;
-      out[2] = (stbi_uc)b;
+      out[0] = (Uint8)r;
+      out[1] = (Uint8)g;
+      out[2] = (Uint8)b;
       out[3] = 255;
       out += step;
    }
@@ -3182,14 +3140,14 @@
 typedef struct
 {
    resample_row_func resample;
-   stbi_uc *line0,*line1;
+   Uint8 *line0,*line1;
    int hs,vs;   // expansion factor in each axis
    int w_lores; // horizontal pixels pre-expansion
    int ystep;   // how far through vertical expansion we are
    int ypos;    // which pre-expansion row we're on
 } stbi__resample;
 
-static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)
+static Uint8 *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)
 {
    int n, decode_n;
    z->s->img_n = 0; // make stbi__cleanup_jpeg safe
@@ -3212,8 +3170,8 @@
    {
       int k;
       unsigned int i,j;
-      stbi_uc *output;
-      stbi_uc *coutput[4];
+      Uint8 *output;
+      Uint8 *coutput[4];
 
       stbi__resample res_comp[4];
 
@@ -3222,7 +3180,7 @@
 
          // allocate line buffer big enough for upsampling off the edges
          // with upsample factor of 4
-         z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3);
+         z->img_comp[k].linebuf = (Uint8 *) stbi__malloc(z->s->img_x + 3);
          if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }
 
          r->hs      = z->img_h_max / z->img_comp[k].h;
@@ -3240,12 +3198,12 @@
       }
 
       // can't error after this so, this is safe
-      output = (stbi_uc *) stbi__malloc(n * z->s->img_x * z->s->img_y + 1);
+      output = (Uint8 *) stbi__malloc(n * z->s->img_x * z->s->img_y + 1);
       if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }
 
       // now go ahead and resample
       for (j=0; j < z->s->img_y; ++j) {
-         stbi_uc *out = output + n * z->s->img_x * j;
+         Uint8 *out = output + n * z->s->img_x * j;
          for (k=0; k < decode_n; ++k) {
             stbi__resample *r = &res_comp[k];
             int y_bot = r->ystep >= (r->vs >> 1);
@@ -3261,7 +3219,7 @@
             }
          }
          if (n >= 3) {
-            stbi_uc *y = coutput[0];
+            Uint8 *y = coutput[0];
             if (z->s->img_n == 3) {
                z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n);
             } else
@@ -3271,7 +3229,7 @@
                   out += n;
                }
          } else {
-            stbi_uc *y = coutput[0];
+            Uint8 *y = coutput[0];
             if (n == 1)
                for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
             else
@@ -3325,6 +3283,7 @@
 }
 #endif
 
+
 // public domain zlib decode    v0.2  Sean Barrett 2006-11-18
 //    simple implementation
 //      - all input must be provided in an upfront buffer
@@ -3332,7 +3291,7 @@
 //    performance
 //      - fast huffman
 
-#ifndef STBI_NO_ZLIB
+#ifdef STBI_INTERNAL_ZLIB
 
 // fast-way is faster to check than jpeg huffman, but slow way is slower
 #define STBI__ZFAST_BITS  9 // accelerate all cases in default tables
@@ -3342,12 +3301,12 @@
 // (jpegs packs from left, zlib from right, so can't share code)
 typedef struct
 {
-   stbi__uint16 fast[1 << STBI__ZFAST_BITS];
-   stbi__uint16 firstcode[16];
+   Uint16 fast[1 << STBI__ZFAST_BITS];
+   Uint16 firstcode[16];
    int maxcode[17];
-   stbi__uint16 firstsymbol[16];
-   stbi_uc  size[288];
-   stbi__uint16 value[288];
+   Uint16 firstsymbol[16];
+   Uint8  size[288];
+   Uint16 value[288];
 } stbi__zhuffman;
 
 stbi_inline static int stbi__bitreverse16(int n)
@@ -3367,7 +3326,7 @@
    return stbi__bitreverse16(v) >> (16-bits);
 }
 
-static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num)
+static int stbi__zbuild_huffman(stbi__zhuffman *z, Uint8 *sizelist, int num)
 {
    int i,k=0;
    int code, next_code[16], sizes[17];
@@ -3383,8 +3342,8 @@
    code = 0;
    for (i=1; i < 16; ++i) {
       next_code[i] = code;
-      z->firstcode[i] = (stbi__uint16) code;
-      z->firstsymbol[i] = (stbi__uint16) k;
+      z->firstcode[i] = (Uint16) code;
+      z->firstsymbol[i] = (Uint16) k;
       code = (code + sizes[i]);
       if (sizes[i])
          if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt JPEG");
@@ -3397,9 +3356,9 @@
       int s = sizelist[i];
       if (s) {
          int c = next_code[s] - z->firstcode[s] + z->firstsymbol[s];
-         stbi__uint16 fastv = (stbi__uint16) ((s << 9) | i);
-         z->size [c] = (stbi_uc     ) s;
-         z->value[c] = (stbi__uint16) i;
+         Uint16 fastv = (Uint16) ((s << 9) | i);
+         z->size [c] = (Uint8) s;
+         z->value[c] = (Uint16) i;
          if (s <= STBI__ZFAST_BITS) {
             int k = stbi__bit_reverse(next_code[s],s);
             while (k < (1 << STBI__ZFAST_BITS)) {
@@ -3421,9 +3380,9 @@
 
 typedef struct
 {
-   stbi_uc *zbuffer, *zbuffer_end;
+   Uint8 *zbuffer, *zbuffer_end;
    int num_bits;
-   stbi__uint32 code_buffer;
+   Uint32 code_buffer;
 
    char *zout;
    char *zout_start;
@@ -3433,7 +3392,7 @@
    stbi__zhuffman z_length, z_distance;
 } stbi__zbuf;
 
-stbi_inline static stbi_uc stbi__zget8(stbi__zbuf *z)
+stbi_inline static Uint8 stbi__zget8(stbi__zbuf *z)
 {
    if (z->zbuffer >= z->zbuffer_end) return 0;
    return *z->zbuffer++;
@@ -3535,7 +3494,7 @@
          }
          *zout++ = (char) z;
       } else {
-         stbi_uc *p;
+         Uint8 *p;
          int len,dist;
          if (z == 256) {
             a->zout = zout;
@@ -3553,9 +3512,9 @@
             if (!stbi__zexpand(a, zout, len)) return 0;
             zout = a->zout;
          }
-         p = (stbi_uc *) (zout - dist);
+         p = (Uint8 *) (zout - dist);
          if (dist == 1) { // run of one byte; common in images.
-            stbi_uc v = *p;
+            Uint8 v = *p;
             do *zout++ = v; while (--len);
          } else {
             do *zout++ = *p++; while (--len);
@@ -3566,10 +3525,10 @@
 
 static int stbi__compute_huffman_codes(stbi__zbuf *a)
 {
-   static stbi_uc length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
+   static Uint8 length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 };
    stbi__zhuffman z_codelength;
-   stbi_uc lencodes[286+32+137];//padding for maximum single op
-   stbi_uc codelength_sizes[19];
+   Uint8 lencodes[286+32+137];//padding for maximum single op
+   Uint8 codelength_sizes[19];
    int i,n;
 
    int hlit  = stbi__zreceive(a,5) + 257;
@@ -3579,7 +3538,7 @@
    memset(codelength_sizes, 0, sizeof(codelength_sizes));
    for (i=0; i < hclen; ++i) {
       int s = stbi__zreceive(a,3);
-      codelength_sizes[length_dezigzag[i]] = (stbi_uc) s;
+      codelength_sizes[length_dezigzag[i]] = (Uint8) s;
    }
    if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) return 0;
 
@@ -3588,7 +3547,7 @@
       int c = stbi__zhuffman_decode(a, &z_codelength);
       STBI_ASSERT(c >= 0 && c < 19);
       if (c < 16)
-         lencodes[n++] = (stbi_uc) c;
+         lencodes[n++] = (Uint8) c;
       else if (c == 16) {
          c = stbi__zreceive(a,2)+3;
          memset(lencodes+n, lencodes[n-1], c);
@@ -3612,14 +3571,14 @@
 
 static int stbi__parse_uncomperssed_block(stbi__zbuf *a)
 {
-   stbi_uc header[4];
+   Uint8 header[4];
    int len,nlen,k;
    if (a->num_bits & 7)
       stbi__zreceive(a, a->num_bits & 7); // discard
    // drain the bit-packed data into header
    k = 0;
    while (a->num_bits > 0) {
-      header[k++] = (stbi_uc) (a->code_buffer & 255); // suppress MSVC run-time check
+      header[k++] = (Uint8) (a->code_buffer & 255); // suppress MSVC run-time check
       a->code_buffer >>= 8;
       a->num_bits -= 8;
    }
@@ -3653,7 +3612,7 @@
 }
 
 // @TODO: should statically initialize these for optimal thread safety
-static stbi_uc stbi__zdefault_length[288], stbi__zdefault_distance[32];
+static Uint8 stbi__zdefault_length[288], stbi__zdefault_distance[32];
 static void stbi__init_zdefaults(void)
 {
    int i;   // use <= to match clearly with spec
@@ -3709,8 +3668,8 @@
    stbi__zbuf a;
    char *p = (char *) stbi__malloc(initial_size);
    if (p == NULL) return NULL;
-   a.zbuffer = (stbi_uc *) buffer;
-   a.zbuffer_end = (stbi_uc *) buffer + len;
+   a.zbuffer = (Uint8 *) buffer;
+   a.zbuffer_end = (Uint8 *) buffer + len;
    if (stbi__do_zlib(&a, p, initial_size, 1, 1)) {
       if (outlen) *outlen = (int) (a.zout - a.zout_start);
       return a.zout_start;
@@ -3730,8 +3689,8 @@
    stbi__zbuf a;
    char *p = (char *) stbi__malloc(initial_size);
    if (p == NULL) return NULL;
-   a.zbuffer = (stbi_uc *) buffer;
-   a.zbuffer_end = (stbi_uc *) buffer + len;
+   a.zbuffer = (Uint8 *) buffer;
+   a.zbuffer_end = (Uint8 *) buffer + len;
    if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) {
       if (outlen) *outlen = (int) (a.zout - a.zout_start);
       return a.zout_start;
@@ -3744,8 +3703,8 @@
 STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen)
 {
    stbi__zbuf a;
-   a.zbuffer = (stbi_uc *) ibuffer;
-   a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
+   a.zbuffer = (Uint8 *) ibuffer;
+   a.zbuffer_end = (Uint8 *) ibuffer + ilen;
    if (stbi__do_zlib(&a, obuffer, olen, 0, 1))
       return (int) (a.zout - a.zout_start);
    else
@@ -3757,8 +3716,8 @@
    stbi__zbuf a;
    char *p = (char *) stbi__malloc(16384);
    if (p == NULL) return NULL;
-   a.zbuffer = (stbi_uc *) buffer;
-   a.zbuffer_end = (stbi_uc *) buffer+len;
+   a.zbuffer = (Uint8 *) buffer;
+   a.zbuffer_end = (Uint8 *) buffer+len;
    if (stbi__do_zlib(&a, p, 16384, 1, 0)) {
       if (outlen) *outlen = (int) (a.zout - a.zout_start);
       return a.zout_start;
@@ -3771,8 +3730,8 @@
 STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen)
 {
    stbi__zbuf a;
-   a.zbuffer = (stbi_uc *) ibuffer;
-   a.zbuffer_end = (stbi_uc *) ibuffer + ilen;
+   a.zbuffer = (Uint8 *) ibuffer;
+   a.zbuffer_end = (Uint8 *) ibuffer + ilen;
    if (stbi__do_zlib(&a, obuffer, olen, 0, 0))
       return (int) (a.zout - a.zout_start);
    else
@@ -3793,8 +3752,8 @@
 #ifndef STBI_NO_PNG
 typedef struct
 {
-   stbi__uint32 length;
-   stbi__uint32 type;
+   Uint32 length;
+   Uint32 type;
 } stbi__pngchunk;
 
 static stbi__pngchunk stbi__get_chunk_header(stbi__context *s)
@@ -3807,7 +3766,7 @@
 
 static int stbi__check_png_header(stbi__context *s)
 {
-   static stbi_uc png_sig[8] = { 137,80,78,71,13,10,26,10 };
+   static Uint8 png_sig[8] = { 137,80,78,71,13,10,26,10 };
    int i;
    for (i=0; i < 8; ++i)
       if (stbi__get8(s) != png_sig[i]) return stbi__err("bad png sig","Not a PNG");
@@ -3817,7 +3776,7 @@
 typedef struct
 {
    stbi__context *s;
-   stbi_uc *idata, *expanded, *out;
+   Uint8 *idata, *expanded, *out;
 } stbi__png;
 
 
@@ -3832,7 +3791,7 @@
    STBI__F_paeth_first
 };
 
-static stbi_uc first_row_filter[5] =
+static Uint8 first_row_filter[5] =
 {
    STBI__F_none,
    STBI__F_sub,
@@ -3852,19 +3811,19 @@
    return c;
 }
 
-static stbi_uc stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 };
+static Uint8 stbi__depth_scale_table[9] = { 0, 0xff, 0x55, 0, 0x11, 0,0,0, 0x01 };
 
 // create the png data from post-deflated data
-static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color)
+static int stbi__create_png_image_raw(stbi__png *a, Uint8 *raw, Uint32 raw_len, int out_n, Uint32 x, Uint32 y, int depth, int color)
 {
    stbi__context *s = a->s;
-   stbi__uint32 i,j,stride = x*out_n;
-   stbi__uint32 img_len, img_width_bytes;
+   Uint32 i,j,stride = x*out_n;
+   Uint32 img_len, img_width_bytes;
    int k;
    int img_n = s->img_n; // copy it into a local for later
 
    STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1);
-   a->out = (stbi_uc *) stbi__malloc(x * y * out_n); // extra bytes to write off the end into
+   a->out = (Uint8 *) stbi__malloc(x * y * out_n); // extra bytes to write off the end into
    if (!a->out) return stbi__err("outofmem", "Out of memory");
 
    img_width_bytes = (((img_n * x * depth) + 7) >> 3);
@@ -3876,8 +3835,8 @@
    }
 
    for (j=0; j < y; ++j) {
-      stbi_uc *cur = a->out + stride*j;
-      stbi_uc *prior = cur - stride;
+      Uint8 *cur = a->out + stride*j;
+      Uint8 *prior = cur - stride;
       int filter = *raw++;
       int filter_bytes = img_n;
       int width = x;
@@ -3961,11 +3920,11 @@
    // intefere with filtering but will still be in the cache.
    if (depth < 8) {
       for (j=0; j < y; ++j) {
-         stbi_uc *cur = a->out + stride*j;
-         stbi_uc *in  = a->out + stride*j + x*out_n - img_width_bytes;
+         Uint8 *cur = a->out + stride*j;
+         Uint8 *in  = a->out + stride*j + x*out_n - img_width_bytes;
          // unpack 1/2/4-bit into a 8-bit buffer. allows us to keep the common 8-bit path optimal at minimal cost for 1/2/4-bit
          // png guarante byte alignment, if width is not multiple of 8/4/2 we'll decode dummy trailing data that will be skipped in the later loop
-         stbi_uc scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range
+         Uint8 scale = (color == 0) ? stbi__depth_scale_table[depth] : 1; // scale grayscale values to 0..255 range
 
          // note that the final byte might overshoot and write more data than desired.
          // we can allocate enough data that this never writes out of memory, but it
@@ -4010,7 +3969,7 @@
          }
          if (img_n != out_n) {
             // insert alpha = 255
-            stbi_uc *cur = a->out + stride*j;
+            Uint8 *cur = a->out + stride*j;
             int i;
             if (img_n == 1) {
                for (i=x-1; i >= 0; --i) {
@@ -4033,15 +3992,15 @@
    return 1;
 }
 
-static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced)
-{
-   stbi_uc *final;
+static int stbi__create_png_image(stbi__png *a, Uint8 *image_data, Uint32 image_data_len, int out_n, int depth, int color, int interlaced)
+{
+   Uint8 *final;
    int p;
    if (!interlaced)
       return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color);
 
    // de-interlacing
-   final = (stbi_uc *) stbi__malloc(a->s->img_x * a->s->img_y * out_n);
+   final = (Uint8 *) stbi__malloc(a->s->img_x * a->s->img_y * out_n);
    for (p=0; p < 7; ++p) {
       int xorig[] = { 0,4,0,2,0,1,0 };
       int yorig[] = { 0,0,4,0,2,0,1 };
@@ -4052,7 +4011,7 @@
       x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p];
       y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p];
       if (x && y) {
-         stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
+         Uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
          if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) {
             STBI_FREE(final);
             return 0;
@@ -4075,11 +4034,11 @@
    return 1;
 }
 
-static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n)
+static int stbi__compute_transparency(stbi__png *z, Uint8 tc[3], int out_n)
 {
    stbi__context *s = z->s;
-   stbi__uint32 i, pixel_count = s->img_x * s->img_y;
-   stbi_uc *p = z->out;
+   Uint32 i, pixel_count = s->img_x * s->img_y;
+   Uint8 *p = z->out;
 
    // compute color-based transparency, assuming we've
    // already got 255 as the alpha value in the output
@@ -4100,12 +4059,12 @@
    return 1;
 }
 
-static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n)
-{
-   stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;
-   stbi_uc *p, *temp_out, *orig = a->out;
-
-   p = (stbi_uc *) stbi__malloc(pixel_count * pal_img_n);
+static int stbi__expand_png_palette(stbi__png *a, Uint8 *palette, int len, int pal_img_n)
+{
+   Uint32 i, pixel_count = a->s->img_x * a->s->img_y;
+   Uint8 *p, *temp_out, *orig = a->out;
+
+   p = (Uint8 *) stbi__malloc(pixel_count * pal_img_n);
    if (p == NULL) return stbi__err("outofmem", "Out of memory");
 
    // between here and free(out) below, exitting would leak
@@ -4153,12 +4112,12 @@
 static void stbi__de_iphone(stbi__png *z)
 {
    stbi__context *s = z->s;
-   stbi__uint32 i, pixel_count = s->img_x * s->img_y;
-   stbi_uc *p = z->out;
+   Uint32 i, pixel_count = s->img_x * s->img_y;
+   Uint8 *p = z->out;
 
    if (s->img_out_n == 3) {  // convert bgr to rgb
       for (i=0; i < pixel_count; ++i) {
-         stbi_uc t = p[0];
+         Uint8 t = p[0];
          p[0] = p[2];
          p[2] = t;
          p += 3;
@@ -4168,8 +4127,8 @@
       if (stbi__unpremultiply_on_load) {
          // convert bgr to rgb and unpremultiply
          for (i=0; i < pixel_count; ++i) {
-            stbi_uc a = p[3];
-            stbi_uc t = p[0];
+            Uint8 a = p[3];
+            Uint8 t = p[0];
             if (a) {
                p[0] = p[2] * 255 / a;
                p[1] = p[1] * 255 / a;
@@ -4183,7 +4142,7 @@
       } else {
          // convert bgr to rgb
          for (i=0; i < pixel_count; ++i) {
-            stbi_uc t = p[0];
+            Uint8 t = p[0];
             p[0] = p[2];
             p[2] = t;
             p += 4;
@@ -4196,9 +4155,9 @@
 
 static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
 {
-   stbi_uc palette[1024], pal_img_n=0;
-   stbi_uc has_trans=0, tc[3];
-   stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
+   Uint8 palette[1024], pal_img_n=0;
+   Uint8 has_trans=0, tc[3];
+   Uint32 ioff=0, idata_limit=0, i, pal_len=0;
    int first=1,k,interlace=0, color=0, depth=0, is_iphone=0;
    stbi__context *s = z->s;
 
@@ -4271,10 +4230,10 @@
                   palette[i*4+3] = stbi__get8(s);
             } else {
                if (!(s->img_n & 1)) return stbi__err("tRNS with alpha","Corrupt PNG");
-               if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG");
+               if (c.length != (Uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG");
                has_trans = 1;
                for (k=0; k < s->img_n; ++k)
-                  tc[k] = (stbi_uc) (stbi__get16be(s) & 255) * stbi__depth_scale_table[depth]; // non 8-bit images will be larger
+                  tc[k] = (Uint8) (stbi__get16be(s) & 255) * stbi__depth_scale_table[depth]; // non 8-bit images will be larger
             }
             break;
          }
@@ -4284,11 +4243,11 @@
             if (pal_img_n && !pal_len) return stbi__err("no PLTE","Corrupt PNG");
             if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; }
             if (ioff + c.length > idata_limit) {
-               stbi_uc *p;
+               Uint8 *p;
                if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;
                while (ioff + c.length > idata_limit)
                   idata_limit *= 2;
-               p = (stbi_uc *) STBI_REALLOC(z->idata, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory");
+               p = (Uint8 *) STBI_REALLOC(z->idata, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory");
                z->idata = p;
             }
             if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG");
@@ -4297,14 +4256,18 @@
          }
 
          case STBI__PNG_TYPE('I','E','N','D'): {
-            stbi__uint32 raw_len, bpl;
+            Uint32 raw_len, bpl;
             if (first) return stbi__err("first not IHDR", "Corrupt PNG");
             if (scan != STBI__SCAN_load) return 1;
             if (z->idata == NULL) return stbi__err("no IDAT","Corrupt PNG");
             // initial guess for decoded data size to avoid unnecessary reallocs
             bpl = (s->img_x * depth + 7) / 8; // bytes per line, per component
             raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */;
-            z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone);
+#ifdef STBI_INTERNAL_ZLIB
+            z->expanded = (Uint8 *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone);
+#else
+#  error NOT IMPLEMENTED!
+#endif
             if (z->expanded == NULL) return 0; // zlib should set error
             STBI_FREE(z->idata); z->idata = NULL;
             if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans)
@@ -4474,11 +4437,11 @@
    return result;
 }
 
-static stbi_uc *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
-{
-   stbi_uc *out;
+static Uint8 *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
+{
+   Uint8 *out;
    unsigned int mr=0,mg=0,mb=0,ma=0, fake_a=0;
-   stbi_uc pal[256][4];
+   Uint8 pal[256][4];
    int psize=0,i,j,compress=0,width;
    int bpp, flip_vertically, pad, target, offset, hsz;
    if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP");
@@ -4569,7 +4532,7 @@
       target = req_comp;
    else
       target = s->img_n; // if they want monochrome, we'll post-convert
-   out = (stbi_uc *) stbi__malloc(target * s->img_x * s->img_y);
+   out = (Uint8 *) stbi__malloc(target * s->img_x * s->img_y);
    if (!out) return stbi__errpuc("outofmem", "Out of memory");
    if (bpp < 16) {
       int z=0;
@@ -4642,7 +4605,7 @@
             }
          } else {
             for (i=0; i < (int) s->img_x; ++i) {
-               stbi__uint32 v = (stbi__uint32) (bpp == 16 ? stbi__get16le(s) : stbi__get32le(s));
+               Uint32 v = (Uint32) (bpp == 16 ? (Uint16) stbi__get16le(s) : stbi__get32le(s));
                int a;
                out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
                out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
@@ -4655,10 +4618,10 @@
       }
    }
    if (flip_vertically) {
-      stbi_uc t;
+      Uint8 t;
       for (j=0; j < (int) s->img_y>>1; ++j) {
-         stbi_uc *p1 = out +      j     *s->img_x*target;
-         stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
+         Uint8 *p1 = out +      j     *s->img_x*target;
+         Uint8 *p2 = out + (s->img_y-1-j)*s->img_x*target;
          for (i=0; i < (int) s->img_x*target; ++i) {
             t = p1[i], p1[i] = p2[i], p2[i] = t;
          }
@@ -4742,7 +4705,7 @@
    return res;
 }
 
-static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
+static Uint8 *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
 {
    //   read in the TGA header stuff
    int tga_offset = stbi__get8(s);
@@ -4808,7 +4771,7 @@
    if ( !tga_indexed && !tga_is_RLE) {
       for (i=0; i < tga_height; ++i) {
          int y = tga_inverted ? tga_height -i - 1 : i;
-         stbi_uc *tga_row = tga_data + y*tga_width*tga_comp;
+         Uint8 *tga_row = tga_data + y*tga_width*tga_comp;
          stbi__getn(s, tga_row, tga_width * tga_comp);
       }
    } else  {
@@ -4948,13 +4911,13 @@
    return r;
 }
 
-static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
+static Uint8 *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
 {
    int   pixelCount;
    int channelCount, compression;
    int channel, i, count, len;
    int w,h;
-   stbi_uc *out;
+   Uint8 *out;
 
    // Check identifier
    if (stbi__get32be(s) != 0x38425053)   // "8BPS"
@@ -5011,7 +4974,7 @@
       return stbi__errpuc("bad compression", "PSD has an unknown compression format");
 
    // Create the destination image.
-   out = (stbi_uc *) stbi__malloc(4 * w*h);
+   out = (Uint8 *) stbi__malloc(4 * w*h);
    if (!out) return stbi__errpuc("outofmem", "Out of memory");
    pixelCount = w*h;
 
@@ -5034,7 +4997,7 @@
 
       // Read the RLE data by channel.
       for (channel = 0; channel < 4; channel++) {
-         stbi_uc *p;
+         Uint8 *p;
 
          p = out+channel;
          if (channel >= channelCount) {
@@ -5057,7 +5020,7 @@
                      len--;
                   }
                } else if (len > 128) {
-                  stbi_uc   val;
+                  Uint8   val;
                   // Next -len+1 bytes in the dest are replicated from next source byte.
                   // (Interpret len as a negative 8-bit int.)
                   len ^= 0x0FF;
@@ -5080,7 +5043,7 @@
 
       // Read the data by channel.
       for (channel = 0; channel < 4; channel++) {
-         stbi_uc *p;
+         Uint8 *p;
 
          p = out + channel;
          if (channel > channelCount) {
@@ -5119,7 +5082,7 @@
 {
    int i;
    for (i=0; i<4; ++i)
-      if (stbi__get8(s) != (stbi_uc)str[i])
+      if (stbi__get8(s) != (Uint8)str[i])
          return 0;
 
    return 1;
@@ -5143,10 +5106,10 @@
 
 typedef struct
 {
-   stbi_uc size,type,channel;
+   Uint8 size,type,channel;
 } stbi__pic_packet;
 
-static stbi_uc *stbi__readval(stbi__context *s, int channel, stbi_uc *dest)
+static Uint8 *stbi__readval(stbi__context *s, int channel, Uint8 *dest)
 {
    int mask=0x80, i;
 
@@ -5160,7 +5123,7 @@
    return dest;
 }
 
-static void stbi__copyval(int channel,stbi_uc *dest,const stbi_uc *src)
+static void stbi__copyval(int channel,Uint8 *dest,const Uint8 *src)
 {
    int mask=0x80,i;
 
@@ -5169,7 +5132,7 @@
          dest[i]=src[i];
 }
 
-static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result)
+static Uint8 *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, Uint8 *result)
 {
    int act_comp=0,num_packets=0,y,chained;
    stbi__pic_packet packets[10];
@@ -5202,7 +5165,7 @@
 
       for(packet_idx=0; packet_idx < num_packets; ++packet_idx) {
          stbi__pic_packet *packet = &packets[packet_idx];
-         stbi_uc *dest = result+y*width*4;
+         Uint8 *dest = result+y*width*4;
 
          switch (packet->type) {
             default:
@@ -5222,13 +5185,13 @@
                   int left=width, i;
 
                   while (left>0) {
-                     stbi_uc count,value[4];
+                     Uint8 count,value[4];
 
                      count=stbi__get8(s);
                      if (stbi__at_eof(s))   return stbi__errpuc("bad file","file too short (pure read count)");
 
                      if (count > left)
-                        count = (stbi_uc) left;
+                        count = (Uint8) left;
 
                      if (!stbi__readval(s,packet->channel,value))  return 0;
 
@@ -5246,7 +5209,7 @@
                   if (stbi__at_eof(s))  return stbi__errpuc("bad file","file too short (mixed read count)");
 
                   if (count >= 128) { // Repeated
-                     stbi_uc value[4];
+                     Uint8 value[4];
                      int i;
 
                      if (count==128)
@@ -5280,9 +5243,9 @@
    return result;
 }
 
-static stbi_uc *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp)
-{
-   stbi_uc *result;
+static Uint8 *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp)
+{
+   Uint8 *result;
    int i, x,y;
 
    for (i=0; i<92; ++i)
@@ -5298,7 +5261,7 @@
    stbi__get16be(s); //skip `pad'
 
    // intermediate buffer is RGBA
-   result = (stbi_uc *) stbi__malloc(x*y*4);
+   result = (Uint8 *) stbi__malloc(x*y*4);
    memset(result, 0xff, x*y*4);
 
    if (!stbi__pic_load_core(s,x,y,comp, result)) {
@@ -5327,20 +5290,20 @@
 #ifndef STBI_NO_GIF
 typedef struct
 {
-   stbi__int16 prefix;
-   stbi_uc first;
-   stbi_uc suffix;
+   Sint16 prefix;
+   Uint8 first;
+   Uint8 suffix;
 } stbi__gif_lzw;
 
 typedef struct
 {
    int w,h;
-   stbi_uc *out;                 // output buffer (always 4 components)
+   Uint8 *out;                 // output buffer (always 4 components)
    int flags, bgindex, ratio, transparent, eflags;
-   stbi_uc  pal[256][4];
-   stbi_uc lpal[256][4];
+   Uint8  pal[256][4];
+   Uint8 lpal[256][4];
    stbi__gif_lzw codes[4096];
-   stbi_uc *color_table;
+   Uint8 *color_table;
    int parse, step;
    int lflags;
    int start_x, start_y;
@@ -5366,7 +5329,7 @@
    return r;
 }
 
-static void stbi__gif_parse_colortable(stbi__context *s, stbi_uc pal[256][4], int num_entries, int transp)
+static void stbi__gif_parse_colortable(stbi__context *s, Uint8 pal[256][4], int num_entries, int transp)
 {
    int i;
    for (i=0; i < num_entries; ++i) {
@@ -5379,7 +5342,7 @@
 
 static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_info)
 {
-   stbi_uc version;
+   Uint8 version;
    if (stbi__get8(s) != 'G' || stbi__get8(s) != 'I' || stbi__get8(s) != 'F' || stbi__get8(s) != '8')
       return stbi__err("not GIF", "Corrupt GIF");
 
@@ -5417,9 +5380,9 @@
    return 1;
 }
 
-static void stbi__out_gif_code(stbi__gif *g, stbi__uint16 code)
-{
-   stbi_uc *p, *c;
+static void stbi__out_gif_code(stbi__gif *g, Uint16 code)
+{
+   Uint8 *p, *c;
 
    // recurse to decode the prefixes, since the linked-list is backwards,
    // and working backwards through an interleaved image would be nasty
@@ -5451,12 +5414,12 @@
    }
 }
 
-static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
-{
-   stbi_uc lzw_cs;
-   stbi__int32 len, code;
-   stbi__uint32 first;
-   stbi__int32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
+static Uint8 *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
+{
+   Uint8 lzw_cs;
+   Sint32 len, code;
+   Uint32 first;
+   Sint32 codesize, codemask, avail, oldcode, bits, valid_bits, clear;
    stbi__gif_lzw *p;
 
    lzw_cs = stbi__get8(s);
@@ -5468,8 +5431,8 @@
    valid_bits = 0;
    for (code = 0; code < clear; code++) {
       g->codes[code].prefix = -1;
-      g->codes[code].first = (stbi_uc) code;
-      g->codes[code].suffix = (stbi_uc) code;
+      g->codes[code].first = (Uint8) code;
+      g->codes[code].suffix = (Uint8) code;
    }
 
    // support no starting clear code
@@ -5485,10 +5448,10 @@
                return g->out;
          }
          --len;
-         bits |= (stbi__int32) stbi__get8(s) << valid_bits;
+         bits |= (Sint32) stbi__get8(s) << valid_bits;
          valid_bits += 8;
       } else {
-         stbi__int32 code = bits & codemask;
+         Sint32 code = bits & codemask;
          bits >>= codesize;
          valid_bits -= codesize;
          // @OPTIMIZE: is there some way we can accelerate the non-clear path?
@@ -5509,13 +5472,13 @@
             if (oldcode >= 0) {
                p = &g->codes[avail++];
                if (avail > 4096)        return stbi__errpuc("too many codes", "Corrupt GIF");
-               p->prefix = (stbi__int16) oldcode;
+               p->prefix = (Sint16) oldcode;
                p->first = g->codes[oldcode].first;
                p->suffix = (code == avail) ? p->first : g->codes[code].first;
             } else if (code == avail)
                return stbi__errpuc("illegal code in raster", "Corrupt GIF");
 
-            stbi__out_gif_code(g, (stbi__uint16) code);
+            stbi__out_gif_code(g, (Uint16) code);
 
             if ((avail & codemask) == 0 && avail <= 0x0FFF) {
                codesize++;
@@ -5533,10 +5496,10 @@
 static void stbi__fill_gif_background(stbi__gif *g)
 {
    int i;
-   stbi_uc *c = g->pal[g->bgindex];
+   Uint8 *c = g->pal[g->bgindex];
    // @OPTIMIZE: write a dword at a time
    for (i = 0; i < g->w * g->h * 4; i += 4) {
-      stbi_uc *p  = &g->out[i];
+      Uint8 *p  = &g->out[i];
       p[0] = c[2];
       p[1] = c[1];
       p[2] = c[0];
@@ -5545,21 +5508,21 @@
 }
 
 // this function is designed to support animated gifs, although stb_image doesn't support it
-static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp)
+static Uint8 *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, int req_comp)
 {
    int i;
-   stbi_uc *old_out = 0;
+   Uint8 *old_out = 0;
 
    if (g->out == 0) {
       if (!stbi__gif_header(s, g, comp,0))     return 0; // stbi__g_failure_reason set by stbi__gif_header
-      g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
+      g->out = (Uint8 *) stbi__malloc(4 * g->w * g->h);
       if (g->out == 0)                      return stbi__errpuc("outofmem", "Out of memory");
       stbi__fill_gif_background(g);
    } else {
       // animated-gif-only path
       if (((g->eflags & 0x1C) >> 2) == 3) {
          old_out = g->out;
-         g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);
+         g->out = (Uint8 *) stbi__malloc(4 * g->w * g->h);
          if (g->out == 0)                   return stbi__errpuc("outofmem", "Out of memory");
          memcpy(g->out, old_out, g->w*g->h*4);
       }
@@ -5569,8 +5532,8 @@
       switch (stbi__get8(s)) {
          case 0x2C: /* Image Descriptor */
          {
-            stbi__int32 x, y, w, h;
-            stbi_uc *o;
+            Sint32 x, y, w, h;
+            Uint8 *o;
 
             x = stbi__get16le(s);
             y = stbi__get16le(s);
@@ -5599,13 +5562,13 @@
 
             if (g->lflags & 0x80) {
                stbi__gif_parse_colortable(s,g->lpal, 2 << (g->lflags & 7), g->eflags & 0x01 ? g->transparent : -1);
-               g->color_table = (stbi_uc *) g->lpal;
+               g->color_table = (Uint8 *) g->lpal;
             } else if (g->flags & 0x80) {
                for (i=0; i < 256; ++i)  // @OPTIMIZE: stbi__jpeg_reset only the previous transparent
                   g->pal[i][3] = 255;
                if (g->transparent >= 0 && (g->eflags & 0x01))
                   g->pal[g->transparent][3] = 0;
-               g->color_table = (stbi_uc *) g->pal;
+               g->color_table = (Uint8 *) g->pal;
             } else
                return stbi__errpuc("missing color table", "Corrupt GIF");
 
@@ -5637,7 +5600,7 @@
          }
 
          case 0x3B: // gif stream termination code
-            return (stbi_uc *) s; // using '1' causes warning on some compilers
+            return (Uint8 *) s; // using '1' causes warning on some compilers
 
          default:
             return stbi__errpuc("unknown code", "Corrupt GIF");
@@ -5645,14 +5608,14 @@
    }
 }
 
-static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
-{
-   stbi_uc *u = 0;
+static Uint8 *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
+{
+   Uint8 *u = 0;
    stbi__gif g;
    memset(&g, 0, sizeof(g));
 
    u = stbi__gif_load_next(s, &g, comp, req_comp);
-   if (u == (stbi_uc *) s) u = 0;  // end of animated gif marker
+   if (u == (Uint8 *) s) u = 0;  // end of animated gif marker
    if (u) {
       *x = g.w;
       *y = g.h;
@@ -5711,7 +5674,7 @@
    return buffer;
 }
 
-static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp)
+static void stbi__hdr_convert(float *output, Uint8 *input, int req_comp)
 {
    if ( input[3] != 0 ) {
       float f1;
@@ -5744,7 +5707,7 @@
    char *token;
    int valid = 0;
    int width, height;
-   stbi_uc *scanline;
+   Uint8 *scanline;
    float *hdr_data;
    int len;
    unsigned char count, value;
@@ -5790,7 +5753,7 @@
       // Read flat data
       for (j=0; j < height; ++j) {
          for (i=0; i < width; ++i) {
-            stbi_uc rgbe[4];
+            Uint8 rgbe[4];
            main_decode_loop:
             stbi__getn(s, rgbe, 4);
             stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp);
@@ -5807,11 +5770,11 @@
          if (c1 != 2 || c2 != 2 || (len & 0x80)) {
             // not run-length encoded, so we have to actually use THIS data as a decoded
             // pixel (note this can't be a valid pixel--one of RGB must be >= 128)
-            stbi_uc rgbe[4];
-            rgbe[0] = (stbi_uc) c1;
-            rgbe[1] = (stbi_uc) c2;
-            rgbe[2] = (stbi_uc) len;
-            rgbe[3] = (stbi_uc) stbi__get8(s);
+            Uint8 rgbe[4];
+            rgbe[0] = (Uint8) c1;
+            rgbe[1] = (Uint8) c2;
+            rgbe[2] = (Uint8) len;
+            rgbe[3] = (Uint8) stbi__get8(s);
             stbi__hdr_convert(hdr_data, rgbe, req_comp);
             i = 1;
             j = 0;
@@ -5821,7 +5784,7 @@
          len <<= 8;
          len |= stbi__get8(s);
          if (len != width) { STBI_FREE(hdr_data); STBI_FREE(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); }
-         if (scanline == NULL) scanline = (stbi_uc *) stbi__malloc(width * 4);
+         if (scanline == NULL) scanline = (Uint8 *) stbi__malloc(width * 4);
 
          for (k = 0; k < 4; ++k) {
             i = 0;
@@ -6025,16 +5988,16 @@
    return 1;
 }
 
-static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
-{
-   stbi_uc *out;
+static Uint8 *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
+{
+   Uint8 *out;
    if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n))
       return 0;
    *x = s->img_x;
    *y = s->img_y;
    *comp = s->img_n;
 
-   out = (stbi_uc *) stbi__malloc(s->img_n * s->img_x * s->img_y);
+   out = (Uint8 *) stbi__malloc(s->img_n * s->img_x * s->img_y);
    if (!out) return stbi__errpuc("outofmem", "Out of memory");
    stbi__getn(s, out, s->img_n * s->img_x * s->img_y);
 
@@ -6173,7 +6136,7 @@
 }
 #endif // !STBI_NO_STDIO
 
-STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp)
+STBIDEF int stbi_info_from_memory(Uint8 const *buffer, int len, int *x, int *y, int *comp)
 {
    stbi__context s;
    stbi__start_mem(&s,buffer,len);
@@ -6257,7 +6220,7 @@
       1.28  (2010-08-01)
               fix bug in GIF palette transparency (SpartanJ)
       1.27  (2010-08-01)
-              cast-to-stbi_uc to fix warnings
+              cast-to-Uint8 to fix warnings
       1.26  (2010-07-24)
               fix bug in file buffering for PNG reported by SpartanJ
       1.25  (2010-07-17)
@@ -6274,7 +6237,7 @@
               GIF support from Jean-Marc Lienher
               iPhone PNG-extensions from James Brown
               warning-fixes from Nicolas Schulz and Janez Zemva (i.stbi__err. Janez (U+017D)emva)
-      1.21    fix use of 'stbi_uc' in header (reported by jon blow)
+      1.21    fix use of 'Uint8' in header (reported by jon blow)
       1.20    added support for Softimage PIC, by Tom Seddon
       1.19    bug in interlaced PNG corruption check (found by ryg)
       1.18 2008-08-02