Mercurial > hg > dmlib
changeset 870:2711f99b40e5
Modify stb_image so that we can eventually lift out the zlib functionality.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 03 Feb 2015 20:07:38 +0200 |
parents | 4cecc74e1b85 |
children | fc272f5f2d15 |
files | src/dmimage.c src/stb_image.c |
diffstat | 2 files changed, 28 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmimage.c Tue Feb 03 19:39:29 2015 +0200 +++ b/src/dmimage.c Tue Feb 03 20:07:38 2015 +0200 @@ -7,6 +7,7 @@ #include "dmimage.h" +#define STBI_INTERNAL_ZLIB 1 #define STBI_FAILURE_USERMSG 1 #define STBI_NO_STDIO 1 #define STBI_NO_HDR 1
--- a/src/stb_image.c Tue Feb 03 19:39:29 2015 +0200 +++ b/src/stb_image.c Tue Feb 03 20:07:38 2015 +0200 @@ -1944,6 +1944,9 @@ return stbi_jpeg_info_raw(&j, x, y, comp); } + +#ifdef STBI_INTERNAL_ZLIB + // public domain zlib decode v0.2 Sean Barrett 2006-11-18 // simple implementation // - all input must be provided in an upfront buffer @@ -2239,7 +2242,7 @@ { int cmf = zget8(a); int cm = cmf & 15; - // int cinfo = cmf >> 4; + // int cinfo = cmf >> 4; int flg = zget8(a); if ((cmf*256+flg) % 31 != 0) return e("bad zlib header","Corrupt PNG"); // zlib spec if (flg & 32) return e("no preset dict","Corrupt PNG"); // preset dictionary not allowed in png @@ -2378,6 +2381,8 @@ return -1; } +#endif + // public domain "baseline" PNG decoder v0.10 Sean Barrett 2006-11-18 // simple implementation // - only 8-bit samples @@ -2450,10 +2455,16 @@ int k; int img_n = s->img_n; // copy it into a local for later assert(out_n == s->img_n || out_n == s->img_n+1); +#ifdef STBI_INTERNAL_ZLIB if (stbi_png_partial) y = 1; +#endif a->out = (Uint8 *) malloc(x * y * out_n); if (!a->out) return e("outofmem", "Out of memory"); - if (!stbi_png_partial) { + +#ifdef STBI_INTERNAL_ZLIB + if (!stbi_png_partial) +#endif + { if (s->img_x == x && s->img_y == y) { if (raw_len != (img_n * x + 1) * y) return e("not enough pixels","Corrupt PNG"); } else { // interlaced: @@ -2524,11 +2535,13 @@ { Uint8 *final; int p; - int save; if (!interlaced) return create_png_image_raw(a, raw, raw_len, out_n, a->s->img_x, a->s->img_y); - save = stbi_png_partial; + +#ifdef STBI_INTERNAL_ZLIB + int save = stbi_png_partial; stbi_png_partial = 0; +#endif // de-interlacing final = (Uint8 *) malloc(a->s->img_x * a->s->img_y * out_n); @@ -2557,7 +2570,9 @@ } a->out = final; +#ifdef STBI_INTERNAL_ZLIB stbi_png_partial = save; +#endif return 1; } @@ -2784,7 +2799,11 @@ if (first) return e("first not IHDR", "Corrupt PNG"); if (scan != SCAN_load) return 1; if (z->idata == NULL) return e("no IDAT","Corrupt PNG"); +#ifdef STBI_INTERNAL_ZLIB z->expanded = (Uint8 *) stbi_zlib_decode_malloc_guesssize_headerflag((char *) z->idata, ioff, 16384, (int *) &raw_len, !iphone); +#else +# error NOT IMPLEMENTED! +#endif if (z->expanded == NULL) return 0; // zlib should set error free(z->idata); z->idata = NULL; if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) @@ -3258,7 +3277,7 @@ tga_image_type -= 8; tga_is_RLE = 1; } - // int tga_alpha_bits = tga_inverted & 15; + // int tga_alpha_bits = tga_inverted & 15; tga_inverted = 1 - ((tga_inverted >> 5) & 1); // error check @@ -4097,7 +4116,7 @@ for (;;) { switch (get8(s)) { - case 0x2C: // Image Descriptor + case 0x2C: // Image Descriptor { int32 x, y, w, h; Uint8 *o; @@ -4258,10 +4277,10 @@ if (req_comp == 4) output[3] = 1; } else { switch (req_comp) { - case 4: output[3] = 1; // fallthrough + case 4: output[3] = 1; // fallthrough case 3: output[0] = output[1] = output[2] = 0; break; - case 2: output[1] = 1; // fallthrough + case 2: output[1] = 1; // fallthrough case 1: output[0] = 0; break; }