# HG changeset patch # User Matti Hamalainen # Date 1425533274 -7200 # Node ID 737ae4718c8fb47b7533a6806b47e7c090be592b # Parent fa59b65149e68a52c12c6e498466800b77b8b231 Use dmMemset, dmMalloc, dmRealloc and dmFree directly. Use Uint8 instead of unsigned char. diff -r fa59b65149e6 -r 737ae4718c8f src/dmimage.c --- a/src/dmimage.c Thu Mar 05 07:22:23 2015 +0200 +++ b/src/dmimage.c Thu Mar 05 07:27:54 2015 +0200 @@ -22,10 +22,6 @@ #define STB_IMAGE_IMPLEMENTATION 1 #define STBI_NO_STDIO 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" diff -r fa59b65149e6 -r 737ae4718c8f src/stb_image.c --- a/src/stb_image.c Thu Mar 05 07:22:23 2015 +0200 +++ b/src/stb_image.c Thu Mar 05 07:27:54 2015 +0200 @@ -218,7 +218,7 @@ // // Basic usage (see HDR discussion below for HDR usage): // int x,y,n; -// unsigned char *data = stbi_load(filename, &x, &y, &n, 0); +// Uint8 *data = stbi_load(filename, &x, &y, &n, 0); // // ... process data if not NULL ... // // ... x = width, y = height, n = # 8-bit components per pixel ... // // ... replace '0' with '1'..'4' to force that many components per pixel @@ -231,7 +231,7 @@ // int *comp -- outputs # of image components in image file // int req_comp -- if non-zero, # of image components requested in result // -// The return value from an image loader is an 'unsigned char *' which points +// The return value from an image loader is an 'Uint8 *' which points // to the pixel data, or NULL on an allocation failure or if the image is // corrupt or invalid. The pixel data consists of *y scanlines of *x pixels, // with each pixel consisting of N interleaved 8-bit components; the first @@ -563,21 +563,6 @@ #define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) #endif -#if defined(STBI_MALLOC) && defined(STBI_FREE) && defined(STBI_REALLOC) -// ok -#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) -// ok -#else -#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC." -#endif - -#ifndef STBI_MALLOC -#define STBI_MALLOC(sz) malloc(sz) -#define STBI_REALLOC(p,sz) realloc(p,sz) -#define STBI_FREE(p) free(p) -#define STBI_MEMSET(p, v, s) memset(p,v,s) -#endif - #if defined(__GNUC__) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) // gcc doesn't support sse2 intrinsics unless you compile with -msse2, // (but compiling with -msse2 allows the compiler to use SSE2 everywhere; @@ -808,14 +793,10 @@ } #endif -static void *stbi__malloc(size_t size) -{ - return STBI_MALLOC(size); -} // stbi__err - error // stbi__errpf - error returning pointer to float -// stbi__errpuc - error returning pointer to unsigned char +// stbi__errpuc - error returning pointer to Uint8 #ifdef STBI_NO_FAILURE_STRINGS #define stbi__err(x,y) 0 @@ -826,11 +807,11 @@ #endif #define stbi__errpf(x,y) ((float *) (stbi__err(x,y)?NULL:NULL)) -#define stbi__errpuc(x,y) ((unsigned char *) (stbi__err(x,y)?NULL:NULL)) +#define stbi__errpuc(x,y) ((Uint8 *) (stbi__err(x,y)?NULL:NULL)) STBIDEF void stbi_image_free(void *retval_from_stbi_load) { - STBI_FREE(retval_from_stbi_load); + dmFree(retval_from_stbi_load); } #ifndef STBI_NO_LINEAR @@ -841,7 +822,7 @@ 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) +static Uint8 *stbi_load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp) { #ifndef STBI_NO_JPEG if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp); @@ -899,7 +880,7 @@ 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; + Uint8 *result; if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); result = stbi_load_from_file(f,x,y,comp,req_comp); fclose(f); @@ -908,7 +889,7 @@ STBIDEF Uint8 *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp) { - unsigned char *result; + Uint8 *result; stbi__context s; stbi__start_file(&s,f); result = stbi_load_main(&s,x,y,comp,req_comp); @@ -937,7 +918,7 @@ #ifndef STBI_NO_LINEAR static float *stbi_loadf_main(stbi__context *s, int *x, int *y, int *comp, int req_comp) { - unsigned char *data; + Uint8 *data; #ifndef STBI_NO_HDR if (stbi__hdr_test(s)) return stbi__hdr_load(s,x,y,comp,req_comp); @@ -1184,23 +1165,23 @@ 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) +static Uint8 *stbi__convert_format(Uint8 *data, int img_n, int req_comp, unsigned int x, unsigned int y) { int i,j; - unsigned char *good; + Uint8 *good; if (req_comp == img_n) return data; STBI_ASSERT(req_comp >= 1 && req_comp <= 4); - good = (unsigned char *) stbi__malloc(req_comp * x * y); + good = (Uint8 *) dmMalloc(req_comp * x * y); if (good == NULL) { - STBI_FREE(data); + dmFree(data); return stbi__errpuc("outofmem", "Out of memory"); } for (j=0; j < (int) y; ++j) { - unsigned char *src = data + j * x * img_n ; - unsigned char *dest = good + j * x * req_comp; + Uint8 *src = data + j * x * img_n ; + Uint8 *dest = good + j * x * req_comp; #define COMBO(a,b) ((a)*8+(b)) #define CASE(a,b) case COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b) @@ -1224,7 +1205,7 @@ #undef CASE } - STBI_FREE(data); + dmFree(data); return good; } @@ -1232,8 +1213,8 @@ 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)); - if (output == NULL) { STBI_FREE(data); return stbi__errpf("outofmem", "Out of memory"); } + float *output = (float *) dmMalloc(x * y * comp * sizeof(float)); + if (output == NULL) { dmFree(data); return stbi__errpf("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; for (i=0; i < x*y; ++i) { @@ -1242,7 +1223,7 @@ } if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f; } - STBI_FREE(data); + dmFree(data); return output; } #endif @@ -1252,8 +1233,8 @@ static Uint8 *stbi__hdr_to_ldr(float *data, int x, int y, int comp) { int i,k,n; - Uint8 *output = (Uint8 *) stbi__malloc(x * y * comp); - if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); } + Uint8 *output = (Uint8 *) dmMalloc(x * y * comp); + if (output == NULL) { dmFree(data); return stbi__errpuc("outofmem", "Out of memory"); } // compute number of non-alpha components if (comp & 1) n = comp; else n = comp-1; for (i=0; i < x*y; ++i) { @@ -1270,7 +1251,7 @@ output[i*comp + k] = (Uint8) stbi__float2int(z); } } - STBI_FREE(data); + dmFree(data); return output; } #endif @@ -1344,7 +1325,7 @@ Uint32 code_buffer; // jpeg entropy-coded buffer int code_bits; // number of valid bits - unsigned char marker; // marker seen while filling entropy buffer + Uint8 marker; // marker seen while filling entropy buffer int nomore; // flag if we saw a marker so must stop int progressive; @@ -1390,7 +1371,7 @@ h->maxcode[j] = 0xffffffff; // build non-spec acceleration table; 255 is flag for not-accelerated - STBI_MEMSET(h->fast, 255, 1 << FAST_BITS); + dmMemset(h->fast, 255, 1 << FAST_BITS); for (i=0; i < k; ++i) { int s = h->size[i]; if (s <= FAST_BITS) { @@ -1438,7 +1419,7 @@ if (b == 0xff) { int c = stbi__get8(j->s); if (c != 0) { - j->marker = (unsigned char) c; + j->marker = (Uint8) c; j->nomore = 1; return; } @@ -1570,7 +1551,7 @@ if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG"); // 0 all the ac values now so we can do it 32-bits at a time - STBI_MEMSET(data,0,64*sizeof(data[0])); + dmMemset(data,0,64*sizeof(data[0])); diff = t ? stbi__extend_receive(j, t) : 0; dc = j->img_comp[b].dc_pred + diff; @@ -1622,7 +1603,7 @@ if (j->succ_high == 0) { // first scan for DC coefficient, must be first - STBI_MEMSET(data,0,64*sizeof(data[0])); // 0 all the ac values now + dmMemset(data,0,64*sizeof(data[0])); // 0 all the ac values now t = stbi__jpeg_huff_decode(j, hdc); diff = t ? stbi__extend_receive(j, t) : 0; @@ -2601,11 +2582,11 @@ // discard the extra data until colorspace conversion z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8; z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8; - z->img_comp[i].raw_data = stbi__malloc(z->img_comp[i].w2 * z->img_comp[i].h2+15); + z->img_comp[i].raw_data = dmMalloc(z->img_comp[i].w2 * z->img_comp[i].h2+15); if (z->img_comp[i].raw_data == NULL) { for(--i; i >= 0; --i) { - STBI_FREE(z->img_comp[i].raw_data); + dmFree(z->img_comp[i].raw_data); z->img_comp[i].data = NULL; } return stbi__err("outofmem", "Out of memory"); @@ -2616,7 +2597,7 @@ if (z->progressive) { z->img_comp[i].coeff_w = (z->img_comp[i].w2 + 7) >> 3; z->img_comp[i].coeff_h = (z->img_comp[i].h2 + 7) >> 3; - z->img_comp[i].raw_coeff = STBI_MALLOC(z->img_comp[i].coeff_w * z->img_comp[i].coeff_h * 64 * sizeof(short) + 15); + z->img_comp[i].raw_coeff = dmMalloc(z->img_comp[i].coeff_w * z->img_comp[i].coeff_h * 64 * sizeof(short) + 15); z->img_comp[i].coeff = (short*) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); } else { z->img_comp[i].coeff = 0; @@ -2974,7 +2955,7 @@ __m128i cr_const1 = _mm_set1_epi16( - (short) ( 0.71414f*4096.0f+0.5f)); __m128i cb_const0 = _mm_set1_epi16( - (short) ( 0.34414f*4096.0f+0.5f)); __m128i cb_const1 = _mm_set1_epi16( (short) ( 1.77200f*4096.0f+0.5f)); - __m128i y_bias = _mm_set1_epi8((char) (unsigned char) 128); + __m128i y_bias = _mm_set1_epi8((char) (Uint8) 128); __m128i xw = _mm_set1_epi16(255); // alpha channel for (; i+7 < count; i += 8) { @@ -3125,17 +3106,17 @@ int i; for (i=0; i < j->s->img_n; ++i) { if (j->img_comp[i].raw_data) { - STBI_FREE(j->img_comp[i].raw_data); + dmFree(j->img_comp[i].raw_data); j->img_comp[i].raw_data = NULL; j->img_comp[i].data = NULL; } if (j->img_comp[i].raw_coeff) { - STBI_FREE(j->img_comp[i].raw_coeff); + dmFree(j->img_comp[i].raw_coeff); j->img_comp[i].raw_coeff = 0; j->img_comp[i].coeff = 0; } if (j->img_comp[i].linebuf) { - STBI_FREE(j->img_comp[i].linebuf); + dmFree(j->img_comp[i].linebuf); j->img_comp[i].linebuf = NULL; } } @@ -3184,7 +3165,7 @@ // allocate line buffer big enough for upsampling off the edges // with upsample factor of 4 - z->img_comp[k].linebuf = (Uint8 *) stbi__malloc(z->s->img_x + 3); + z->img_comp[k].linebuf = (Uint8 *) dmMalloc(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; @@ -3202,7 +3183,7 @@ } // can't error after this so, this is safe - output = (Uint8 *) stbi__malloc(n * z->s->img_x * z->s->img_y + 1); + output = (Uint8 *) dmMalloc(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 @@ -3248,7 +3229,7 @@ } } -static unsigned char *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) { stbi__jpeg j; j.s = s; @@ -3372,7 +3353,7 @@ 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 = (Uint8 *) stbi__malloc(x * y * out_n); // extra bytes to write off the end into + a->out = (Uint8 *) dmMalloc(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); @@ -3549,7 +3530,7 @@ 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 = (Uint8 *) stbi__malloc(a->s->img_x * a->s->img_y * out_n); + final = (Uint8 *) dmMalloc(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 }; @@ -3562,7 +3543,7 @@ if (x && 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); + dmFree(final); return 0; } for (j=0; j < y; ++j) { @@ -3573,7 +3554,7 @@ a->out + (j*x+i)*out_n, out_n); } } - STBI_FREE(a->out); + dmFree(a->out); image_data += img_len; image_data_len -= img_len; } @@ -3613,7 +3594,7 @@ 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); + p = (Uint8 *) dmMalloc(pixel_count * pal_img_n); if (p == NULL) return stbi__err("outofmem", "Out of memory"); // between here and free(out) below, exitting would leak @@ -3637,7 +3618,7 @@ p += 4; } } - STBI_FREE(a->out); + dmFree(a->out); a->out = temp_out; STBI_NOTUSED(len); @@ -3844,7 +3825,7 @@ if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; while (ioff + c.length > idata_limit) idata_limit *= 2; - p = (Uint8 *) STBI_REALLOC(z->idata, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); + p = (Uint8 *) dmRealloc(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"); @@ -3867,7 +3848,7 @@ raw_len, !is_iphone) != DMERR_OK) return 0; - STBI_FREE(z->idata); z->idata = NULL; + dmFree(z->idata); z->idata = NULL; if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n+1; @@ -3886,7 +3867,7 @@ if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n)) return 0; } - STBI_FREE(z->expanded); z->expanded = NULL; + dmFree(z->expanded); z->expanded = NULL; return 1; } @@ -3912,9 +3893,9 @@ } } -static unsigned char *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp) +static Uint8 *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp) { - unsigned char *result=NULL; + Uint8 *result=NULL; if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { result = p->out; @@ -3928,14 +3909,14 @@ *y = p->s->img_y; if (n) *n = p->s->img_out_n; } - STBI_FREE(p->out); p->out = NULL; - STBI_FREE(p->expanded); p->expanded = NULL; - STBI_FREE(p->idata); p->idata = NULL; + dmFree(p->out); p->out = NULL; + dmFree(p->expanded); p->expanded = NULL; + dmFree(p->idata); p->idata = NULL; return result; } -static unsigned char *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) { stbi__png p; p.s = s; @@ -4130,11 +4111,11 @@ target = req_comp; else target = s->img_n; // if they want monochrome, we'll post-convert - out = (Uint8 *) stbi__malloc(target * s->img_x * s->img_y); + out = (Uint8 *) dmMalloc(target * s->img_x * s->img_y); if (!out) return stbi__errpuc("outofmem", "Out of memory"); if (bpp < 16) { int z=0; - if (psize == 0 || psize > 256) { STBI_FREE(out); return stbi__errpuc("invalid", "Corrupt BMP"); } + if (psize == 0 || psize > 256) { dmFree(out); return stbi__errpuc("invalid", "Corrupt BMP"); } for (i=0; i < psize; ++i) { pal[i][2] = stbi__get8(s); pal[i][1] = stbi__get8(s); @@ -4145,7 +4126,7 @@ stbi__skip(s, offset - 14 - hsz - psize * (hsz == 12 ? 3 : 4)); if (bpp == 4) width = (s->img_x + 1) >> 1; else if (bpp == 8) width = s->img_x; - else { STBI_FREE(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); } + else { dmFree(out); return stbi__errpuc("bad bpp", "Corrupt BMP"); } pad = (-width)&3; for (j=0; j < (int) s->img_y; ++j) { for (i=0; i < (int) s->img_x; i += 2) { @@ -4183,7 +4164,7 @@ easy = 2; } if (!easy) { - if (!mr || !mg || !mb) { STBI_FREE(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } + if (!mr || !mg || !mb) { dmFree(out); return stbi__errpuc("bad masks", "Corrupt BMP"); } // right shift amt to put high bit in position #7 rshift = stbi__high_bit(mr)-7; rcount = stbi__bitcount(mr); gshift = stbi__high_bit(mg)-7; gcount = stbi__bitcount(mg); @@ -4193,7 +4174,7 @@ for (j=0; j < (int) s->img_y; ++j) { if (easy) { for (i=0; i < (int) s->img_x; ++i) { - unsigned char a; + Uint8 a; out[z+2] = stbi__get8(s); out[z+1] = stbi__get8(s); out[z+0] = stbi__get8(s); @@ -4321,10 +4302,10 @@ int tga_comp = tga_bits_per_pixel / 8; int tga_inverted = stbi__get8(s); // image data - unsigned char *tga_data; - unsigned char *tga_palette = NULL; + Uint8 *tga_data; + Uint8 *tga_palette = NULL; int i, j; - unsigned char raw_data[4]; + Uint8 raw_data[4]; int RLE_count = 0; int RLE_repeating = 0; int read_next_pixel = 1; @@ -4360,7 +4341,7 @@ *y = tga_height; if (comp) *comp = tga_comp; - tga_data = (unsigned char*)stbi__malloc( tga_width * tga_height * tga_comp ); + tga_data = (Uint8*)dmMalloc( tga_width * tga_height * tga_comp ); if (!tga_data) return stbi__errpuc("outofmem", "Out of memory"); // skip to the data's starting position (offset usually = 0) @@ -4379,14 +4360,14 @@ // any data to skip? (offset usually = 0) stbi__skip(s, tga_palette_start ); // load the palette - tga_palette = (unsigned char*)stbi__malloc( tga_palette_len * tga_palette_bits / 8 ); + tga_palette = (Uint8*)dmMalloc( tga_palette_len * tga_palette_bits / 8 ); if (!tga_palette) { - STBI_FREE(tga_data); + dmFree(tga_data); return stbi__errpuc("outofmem", "Out of memory"); } if (!stbi__getn(s, tga_palette, tga_palette_len * tga_palette_bits / 8 )) { - STBI_FREE(tga_data); - STBI_FREE(tga_palette); + dmFree(tga_data); + dmFree(tga_palette); return stbi__errpuc("bad palette", "Corrupt TGA"); } } @@ -4457,7 +4438,7 @@ int index2 = (tga_height - 1 - j) * tga_width * tga_comp; for (i = tga_width * tga_comp; i > 0; --i) { - unsigned char temp = tga_data[index1]; + Uint8 temp = tga_data[index1]; tga_data[index1] = tga_data[index2]; tga_data[index2] = temp; ++index1; @@ -4468,17 +4449,17 @@ // clear my palette, if I had one if ( tga_palette != NULL ) { - STBI_FREE( tga_palette ); + dmFree( tga_palette ); } } // swap RGB if (tga_comp >= 3) { - unsigned char* tga_pixel = tga_data; + Uint8* tga_pixel = tga_data; for (i=0; i < tga_width * tga_height; ++i) { - unsigned char temp = tga_pixel[0]; + Uint8 temp = tga_pixel[0]; tga_pixel[0] = tga_pixel[2]; tga_pixel[2] = temp; tga_pixel += tga_comp; @@ -4572,12 +4553,12 @@ return stbi__errpuc("bad compression", "PSD has an unknown compression format"); // Create the destination image. - out = (Uint8 *) stbi__malloc(4 * w*h); + out = (Uint8 *) dmMalloc(4 * w*h); if (!out) return stbi__errpuc("outofmem", "Out of memory"); pixelCount = w*h; // Initialize the data to zero. - //STBI_MEMSET( out, 0, pixelCount * 4 ); + //dmMemset( out, 0, pixelCount * 4 ); // Finally, the image data. if (compression) { @@ -4859,11 +4840,11 @@ stbi__get16be(s); //skip `pad' // intermediate buffer is RGBA - result = (Uint8 *) stbi__malloc(x*y*4); - STBI_MEMSET(result, 0xff, x*y*4); + result = (Uint8 *) dmMalloc(x*y*4); + dmMemset(result, 0xff, x*y*4); if (!stbi__pic_load_core(s,x,y,comp, result)) { - STBI_FREE(result); + dmFree(result); result=0; } *px = x; @@ -5113,14 +5094,14 @@ 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 = (Uint8 *) stbi__malloc(4 * g->w * g->h); + g->out = (Uint8 *) dmMalloc(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 = (Uint8 *) stbi__malloc(4 * g->w * g->h); + g->out = (Uint8 *) dmMalloc(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); } @@ -5210,7 +5191,7 @@ { Uint8 *u = 0; stbi__gif g; - STBI_MEMSET(&g, 0, sizeof(g)); + dmMemset(&g, 0, sizeof(g)); u = stbi__gif_load_next(s, &g, comp, req_comp); if (u == (Uint8 *) s) u = 0; // end of animated gif marker @@ -5308,7 +5289,7 @@ Uint8 *scanline; float *hdr_data; int len; - unsigned char count, value; + Uint8 count, value; int i, j, k, c1,c2, z; @@ -5343,7 +5324,7 @@ if (req_comp == 0) req_comp = 3; // Read data - hdr_data = (float *) stbi__malloc(height * width * req_comp * sizeof(float)); + hdr_data = (float *) dmMalloc(height * width * req_comp * sizeof(float)); // Load image data // image data is stored as some number of sca @@ -5376,13 +5357,13 @@ stbi__hdr_convert(hdr_data, rgbe, req_comp); i = 1; j = 0; - STBI_FREE(scanline); + dmFree(scanline); goto main_decode_loop; // yes, this makes no sense } 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 = (Uint8 *) stbi__malloc(width * 4); + if (len != width) { dmFree(hdr_data); dmFree(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); } + if (scanline == NULL) scanline = (Uint8 *) dmMalloc(width * 4); for (k = 0; k < 4; ++k) { i = 0; @@ -5404,7 +5385,7 @@ for (i=0; i < width; ++i) stbi__hdr_convert(hdr_data+(j*width + i)*req_comp, scanline + i*4, req_comp); } - STBI_FREE(scanline); + dmFree(scanline); } return hdr_data; @@ -5595,7 +5576,7 @@ *y = s->img_y; *comp = s->img_n; - out = (Uint8 *) stbi__malloc(s->img_n * s->img_x * s->img_y); + out = (Uint8 *) dmMalloc(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); @@ -5754,11 +5735,10 @@ revision history: 2.02 (2015-01-19) fix incorrect assert, fix warning 2.01 (2015-01-17) fix various warnings; suppress SIMD on gcc 32-bit without -msse2 - 2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG + 2.00b (2014-12-25) fix dmMalloc in progressive JPEG 2.00 (2014-12-25) optimize JPG, including x86 SSE2 & NEON SIMD (ryg) progressive JPEG (stb) PGM/PPM support (Ken Miller) - STBI_MALLOC,STBI_REALLOC,STBI_FREE GIF bugfix -- seemingly never worked STBI_NO_*, STBI_ONLY_* 1.48 (2014-12-14) fix incorrectly-named assert()