Merge branch 'master' of https://github.com/thedmd/stb into working
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Conflicts: stb_image.h
authored by Sean Barrett · committed by Sean Barrett · parents aaea13b, 10def9b · Browse files · 1 file·+33 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+33 added−22 removed
- other:+33 added−22 removed
Provenance
- Commit
b36f990- Tree
ed190cb- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
aaea13b- Parent 2
10def9b
1 file changed+33 added−22 removed
modified:stb_image.h+33 added-22 removed
1-/* stb_image - v1.44 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c1+/* stb_image - v1.45 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c2 when you control the images you're loading3 no warranty implied; use at your own risk4 5 Do this:21 unmodified lines27 - decode from arbitrary I/O callbacks28 - overridable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD)29 30 Latest revisions:31+ 1.45 (2014-08-16) workaround MSVC-ARM internal compiler error by wrapping malloc32 1.44 (2014-08-07) warnings33 1.43 (2014-07-15) fix MSVC-only bug in 1.4234 1.42 (2014-07-09) no _CRT_SECURE_NO_WARNINGS; error-path fixes; STBI_ASSERT35 1.41 (2014-06-25) fix search&replace that messed up comments/error messages37 unmodified lines73 Jerry Jansson74 If your name should be here but Hayaki Saito75 isn't, let Sean know. Johan Duparc76 Ronny Chevalier77+ Michal Cichon78 */79 80 #ifndef STBI_INCLUDE_STB_IMAGE_H81 #define STBI_INCLUDE_STB_IMAGE_H446 unmodified lines528 stbi__g_failure_reason = str;529 return 0;530 }531 532+static void *stbi__malloc(size_t size)533+{534+ return malloc(size);535+}536+537 // stbi__err - error538 // stbi__errpf - error returning pointer to float539 // stbi__errpuc - error returning pointer to unsigned char540 342 unmodified lines883 884 if (req_comp == img_n) return data;885 STBI_ASSERT(req_comp >= 1 && req_comp <= 4);886 880- good = (unsigned char *) malloc(req_comp * x * y);887+ good = (unsigned char *) stbi__malloc(req_comp * x * y);888 if (good == NULL) {889 free(data);890 return stbi__errpuc("outofmem", "Out of memory");891 }31 unmodified lines923 #ifndef STBI_NO_HDR924 static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)925 {926 int i,k,n;920- float *output = (float *) malloc(x * y * comp * sizeof(float));927+ float *output = (float *) stbi__malloc(x * y * comp * sizeof(float));928 if (output == NULL) { free(data); return stbi__errpf("outofmem", "Out of memory"); }929 // compute number of non-alpha components930 if (comp & 1) n = comp; else n = comp-1;931 for (i=0; i < x*y; ++i) {9 unmodified lines941 #define stbi__float2int(x) ((int) (x))942 static stbi_uc *stbi__hdr_to_ldr(float *data, int x, int y, int comp)943 {944 int i,k,n;938- stbi_uc *output = (stbi_uc *) malloc(x * y * comp);945+ stbi_uc *output = (stbi_uc *) stbi__malloc(x * y * comp);946 if (output == NULL) { free(data); return stbi__errpuc("outofmem", "Out of memory"); }947 // compute number of non-alpha components948 if (comp & 1) n = comp; else n = comp-1;949 for (i=0; i < x*y; ++i) {668 unmodified lines1618 // big blocks (stbi__err.g. a 16x16 iMCU on an image of width 33); we won't1619 // discard the extra data until colorspace conversion1620 z->img_comp[i].w2 = z->img_mcu_x * z->img_comp[i].h * 8;1621 z->img_comp[i].h2 = z->img_mcu_y * z->img_comp[i].v * 8;1615- z->img_comp[i].raw_data = malloc(z->img_comp[i].w2 * z->img_comp[i].h2+15);1622+ z->img_comp[i].raw_data = stbi__malloc(z->img_comp[i].w2 * z->img_comp[i].h2+15);1623 if (z->img_comp[i].raw_data == NULL) {1624 for(--i; i >= 0; --i) {1625 free(z->img_comp[i].raw_data);1626 z->img_comp[i].data = NULL;256 unmodified lines1883 stbi__resample *r = &res_comp[k];1884 1885 // allocate line buffer big enough for upsampling off the edges1886 // with upsample factor of 41880- z->img_comp[k].linebuf = (stbi_uc *) malloc(z->s->img_x + 3);1887+ z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3);1888 if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }1889 1890 r->hs = z->img_h_max / z->img_comp[k].h;1891 r->vs = z->img_v_max / z->img_comp[k].v;9 unmodified lines1901 else r->resample = stbi__resample_row_generic;1902 }1903 1904 // can't error after this so, this is safe1898- output = (stbi_uc *) malloc(n * z->s->img_x * z->s->img_y + 1);1905+ output = (stbi_uc *) stbi__malloc(n * z->s->img_x * z->s->img_y + 1);1906 if (!output) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }1907 1908 // now go ahead and resample1909 for (j=0; j < z->s->img_y; ++j) {436 unmodified lines2346 2347 STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen)2348 {2349 stbi__zbuf a;2343- char *p = (char *) malloc(initial_size);2350+ char *p = (char *) stbi__malloc(initial_size);2351 if (p == NULL) return NULL;2352 a.zbuffer = (stbi_uc *) buffer;2353 a.zbuffer_end = (stbi_uc *) buffer + len;2354 if (stbi__do_zlib(&a, p, initial_size, 1, 1)) {12 unmodified lines2367 2368 STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header)2369 {2370 stbi__zbuf a;2364- char *p = (char *) malloc(initial_size);2371+ char *p = (char *) stbi__malloc(initial_size);2372 if (p == NULL) return NULL;2373 a.zbuffer = (stbi_uc *) buffer;2374 a.zbuffer_end = (stbi_uc *) buffer + len;2375 if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) {18 unmodified lines2394 2395 STBIDEF char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen)2396 {2397 stbi__zbuf a;2391- char *p = (char *) malloc(16384);2398+ char *p = (char *) stbi__malloc(16384);2399 if (p == NULL) return NULL;2400 a.zbuffer = (stbi_uc *) buffer;2401 a.zbuffer_end = (stbi_uc *) buffer+len;2402 if (stbi__do_zlib(&a, p, 16384, 1, 0)) {89 unmodified lines2492 stbi__uint32 i,j,stride = x*out_n;2493 int k;2494 int img_n = s->img_n; // copy it into a local for later2495 STBI_ASSERT(out_n == s->img_n || out_n == s->img_n+1);2489- a->out = (stbi_uc *) malloc(x * y * out_n);2496+ a->out = (stbi_uc *) stbi__malloc(x * y * out_n);2497 if (!a->out) return stbi__err("outofmem", "Out of memory");2498 if (s->img_x == x && s->img_y == y) {2499 if (raw_len != (img_n * x + 1) * y) return stbi__err("not enough pixels","Corrupt PNG");2500 } else { // interlaced:66 unmodified lines2567 if (!interlaced)2568 return stbi__create_png_image_raw(a, raw, raw_len, out_n, a->s->img_x, a->s->img_y);2569 2570 // de-interlacing2564- final = (stbi_uc *) malloc(a->s->img_x * a->s->img_y * out_n);2571+ final = (stbi_uc *) stbi__malloc(a->s->img_x * a->s->img_y * out_n);2572 for (p=0; p < 7; ++p) {2573 int xorig[] = { 0,4,0,2,0,1,0 };2574 int yorig[] = { 0,0,4,0,2,0,1 };2575 int xspc[] = { 8,8,4,4,2,2,1 };50 unmodified lines2626 {2627 stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;2628 stbi_uc *p, *temp_out, *orig = a->out;2629 2623- p = (stbi_uc *) malloc(pixel_count * pal_img_n);2630+ p = (stbi_uc *) stbi__malloc(pixel_count * pal_img_n);2631 if (p == NULL) return stbi__err("outofmem", "Out of memory");2632 2633 // between here and free(out) below, exitting would leak2634 temp_out = p;447 unmodified lines3082 if (req_comp && req_comp >= 3) // we can directly decode 3 or 43083 target = req_comp;3084 else3085 target = s->img_n; // if they want monochrome, we'll post-convert3079- out = (stbi_uc *) malloc(target * s->img_x * s->img_y);3086+ out = (stbi_uc *) stbi__malloc(target * s->img_x * s->img_y);3087 if (!out) return stbi__errpuc("outofmem", "Out of memory");3088 if (bpp < 16) {3089 int z=0;3090 if (psize == 0 || psize > 256) { free(out); return stbi__errpuc("invalid", "Corrupt BMP"); }220 unmodified lines3311 *x = tga_width;3312 *y = tga_height;3313 if (comp) *comp = tga_comp;3314 3308- tga_data = (unsigned char*)malloc( tga_width * tga_height * tga_comp );3315+ tga_data = (unsigned char*)stbi__malloc( tga_width * tga_height * tga_comp );3316 if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");3317 3318 // skip to the data's starting position (offset usually = 0)3319 stbi__skip(s, tga_offset );10 unmodified lines3330 {3331 // any data to skip? (offset usually = 0)3332 stbi__skip(s, tga_palette_start );3333 // load the palette3327- tga_palette = (unsigned char*)malloc( tga_palette_len * tga_palette_bits / 8 );3334+ tga_palette = (unsigned char*)stbi__malloc( tga_palette_len * tga_palette_bits / 8 );3335 if (!tga_palette) {3336 free(tga_data);3337 return stbi__errpuc("outofmem", "Out of memory");3338 }182 unmodified lines3521 if (compression > 1)3522 return stbi__errpuc("bad compression", "PSD has an unknown compression format");3523 3524 // Create the destination image.3518- out = (stbi_uc *) malloc(4 * w*h);3525+ out = (stbi_uc *) stbi__malloc(4 * w*h);3526 if (!out) return stbi__errpuc("outofmem", "Out of memory");3527 pixelCount = w*h;3528 3529 // Initialize the data to zero.276 unmodified lines3806 stbi__get16be(s); //skip `fields'3807 stbi__get16be(s); //skip `pad'3808 3809 // intermediate buffer is RGBA3803- result = (stbi_uc *) malloc(x*y*4);3810+ result = (stbi_uc *) stbi__malloc(x*y*4);3811 memset(result, 0xff, x*y*4);3812 3813 if (!stbi__pic_load_core(s,x,y,comp, result)) {3814 free(result);242 unmodified lines4057 stbi_uc *old_out = 0;4058 4059 if (g->out == 0) {4060 if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header4054- g->out = (stbi_uc *) malloc(4 * g->w * g->h);4061+ g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);4062 if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");4063 stbi__fill_gif_background(g);4064 } else {4065 // animated-gif-only path4066 if (((g->eflags & 0x1C) >> 2) == 3) {4067 old_out = g->out;4061- g->out = (stbi_uc *) malloc(4 * g->w * g->h);4068+ g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);4069 if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");4070 memcpy(g->out, old_out, g->w*g->h*4);4071 }4072 }214 unmodified lines4287 if (comp) *comp = 3;4288 if (req_comp == 0) req_comp = 3;4289 4290 // Read data4284- hdr_data = (float *) malloc(height * width * req_comp * sizeof(float));4291+ hdr_data = (float *) stbi__malloc(height * width * req_comp * sizeof(float));4292 4293 // Load image data4294 // image data is stored as some number of sca4295 if ( width < 8 || width >= 32768) {30 unmodified lines4326 }4327 len <<= 8;4328 len |= stbi__get8(s);4329 if (len != width) { free(hdr_data); free(scanline); return stbi__errpf("invalid decoded scanline length", "corrupt HDR"); }4323- if (scanline == NULL) scanline = (stbi_uc *) malloc(width * 4);4330+ if (scanline == NULL) scanline = (stbi_uc *) stbi__malloc(width * 4);4331 4332 for (k = 0; k < 4; ++k) {4333 i = 0;4334 while (i < width) {228 unmodified lines4563 #endif // STB_IMAGE_IMPLEMENTATION4564 4565 /*4566 revision history:4567+ 1.44 (2014-08-16)4568+ fix MSVC-ARM internal compiler error by wrapping malloc4569+ 1.44 (2014-08-07)4570+ various warning fixes from Ronny Chevalier4571 1.43 (2014-07-15)4572 fix MSVC-only compiler problem in code changed in 1.424573 1.42 (2014-07-09)4574 don't define _CRT_SECURE_NO_WARNINGS (affects user code)110 unmodified lines