Mercurial > hg > dmlib
comparison src/stb_image.c @ 1164:fa59b65149e6
Get rid of string.h dependency in stb_image.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 07:22:23 +0200 |
parents | e42aa3c940c1 |
children | 737ae4718c8f |
comparison
equal
deleted
inserted
replaced
1163:aa3738b121d1 | 1164:fa59b65149e6 |
---|---|
532 | 532 |
533 | 533 |
534 #include <stdarg.h> | 534 #include <stdarg.h> |
535 #include <stddef.h> // ptrdiff_t on osx | 535 #include <stddef.h> // ptrdiff_t on osx |
536 #include <stdlib.h> | 536 #include <stdlib.h> |
537 #include <string.h> | |
538 | 537 |
539 #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) | 538 #if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) |
540 #include <math.h> // ldexp | 539 #include <math.h> // ldexp |
541 #endif | 540 #endif |
542 | 541 |
574 | 573 |
575 #ifndef STBI_MALLOC | 574 #ifndef STBI_MALLOC |
576 #define STBI_MALLOC(sz) malloc(sz) | 575 #define STBI_MALLOC(sz) malloc(sz) |
577 #define STBI_REALLOC(p,sz) realloc(p,sz) | 576 #define STBI_REALLOC(p,sz) realloc(p,sz) |
578 #define STBI_FREE(p) free(p) | 577 #define STBI_FREE(p) free(p) |
578 #define STBI_MEMSET(p, v, s) memset(p,v,s) | |
579 #endif | 579 #endif |
580 | 580 |
581 #if defined(__GNUC__) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) | 581 #if defined(__GNUC__) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) |
582 // gcc doesn't support sse2 intrinsics unless you compile with -msse2, | 582 // gcc doesn't support sse2 intrinsics unless you compile with -msse2, |
583 // (but compiling with -msse2 allows the compiler to use SSE2 everywhere; | 583 // (but compiling with -msse2 allows the compiler to use SSE2 everywhere; |
1388 code <<= 1; | 1388 code <<= 1; |
1389 } | 1389 } |
1390 h->maxcode[j] = 0xffffffff; | 1390 h->maxcode[j] = 0xffffffff; |
1391 | 1391 |
1392 // build non-spec acceleration table; 255 is flag for not-accelerated | 1392 // build non-spec acceleration table; 255 is flag for not-accelerated |
1393 memset(h->fast, 255, 1 << FAST_BITS); | 1393 STBI_MEMSET(h->fast, 255, 1 << FAST_BITS); |
1394 for (i=0; i < k; ++i) { | 1394 for (i=0; i < k; ++i) { |
1395 int s = h->size[i]; | 1395 int s = h->size[i]; |
1396 if (s <= FAST_BITS) { | 1396 if (s <= FAST_BITS) { |
1397 int c = h->code[i] << (FAST_BITS-s); | 1397 int c = h->code[i] << (FAST_BITS-s); |
1398 int m = 1 << (FAST_BITS-s); | 1398 int m = 1 << (FAST_BITS-s); |
1568 if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); | 1568 if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
1569 t = stbi__jpeg_huff_decode(j, hdc); | 1569 t = stbi__jpeg_huff_decode(j, hdc); |
1570 if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG"); | 1570 if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG"); |
1571 | 1571 |
1572 // 0 all the ac values now so we can do it 32-bits at a time | 1572 // 0 all the ac values now so we can do it 32-bits at a time |
1573 memset(data,0,64*sizeof(data[0])); | 1573 STBI_MEMSET(data,0,64*sizeof(data[0])); |
1574 | 1574 |
1575 diff = t ? stbi__extend_receive(j, t) : 0; | 1575 diff = t ? stbi__extend_receive(j, t) : 0; |
1576 dc = j->img_comp[b].dc_pred + diff; | 1576 dc = j->img_comp[b].dc_pred + diff; |
1577 j->img_comp[b].dc_pred = dc; | 1577 j->img_comp[b].dc_pred = dc; |
1578 data[0] = (short) (dc * dequant[0]); | 1578 data[0] = (short) (dc * dequant[0]); |
1620 | 1620 |
1621 if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); | 1621 if (j->code_bits < 16) stbi__grow_buffer_unsafe(j); |
1622 | 1622 |
1623 if (j->succ_high == 0) { | 1623 if (j->succ_high == 0) { |
1624 // first scan for DC coefficient, must be first | 1624 // first scan for DC coefficient, must be first |
1625 memset(data,0,64*sizeof(data[0])); // 0 all the ac values now | 1625 STBI_MEMSET(data,0,64*sizeof(data[0])); // 0 all the ac values now |
1626 t = stbi__jpeg_huff_decode(j, hdc); | 1626 t = stbi__jpeg_huff_decode(j, hdc); |
1627 diff = t ? stbi__extend_receive(j, t) : 0; | 1627 diff = t ? stbi__extend_receive(j, t) : 0; |
1628 | 1628 |
1629 dc = j->img_comp[b].dc_pred + diff; | 1629 dc = j->img_comp[b].dc_pred + diff; |
1630 j->img_comp[b].dc_pred = dc; | 1630 j->img_comp[b].dc_pred = dc; |
4575 out = (Uint8 *) stbi__malloc(4 * w*h); | 4575 out = (Uint8 *) stbi__malloc(4 * w*h); |
4576 if (!out) return stbi__errpuc("outofmem", "Out of memory"); | 4576 if (!out) return stbi__errpuc("outofmem", "Out of memory"); |
4577 pixelCount = w*h; | 4577 pixelCount = w*h; |
4578 | 4578 |
4579 // Initialize the data to zero. | 4579 // Initialize the data to zero. |
4580 //memset( out, 0, pixelCount * 4 ); | 4580 //STBI_MEMSET( out, 0, pixelCount * 4 ); |
4581 | 4581 |
4582 // Finally, the image data. | 4582 // Finally, the image data. |
4583 if (compression) { | 4583 if (compression) { |
4584 // RLE as used by .PSD and .TIFF | 4584 // RLE as used by .PSD and .TIFF |
4585 // Loop until you get the number of unpacked bytes you are expecting: | 4585 // Loop until you get the number of unpacked bytes you are expecting: |
4858 stbi__get16be(s); //skip `fields' | 4858 stbi__get16be(s); //skip `fields' |
4859 stbi__get16be(s); //skip `pad' | 4859 stbi__get16be(s); //skip `pad' |
4860 | 4860 |
4861 // intermediate buffer is RGBA | 4861 // intermediate buffer is RGBA |
4862 result = (Uint8 *) stbi__malloc(x*y*4); | 4862 result = (Uint8 *) stbi__malloc(x*y*4); |
4863 memset(result, 0xff, x*y*4); | 4863 STBI_MEMSET(result, 0xff, x*y*4); |
4864 | 4864 |
4865 if (!stbi__pic_load_core(s,x,y,comp, result)) { | 4865 if (!stbi__pic_load_core(s,x,y,comp, result)) { |
4866 STBI_FREE(result); | 4866 STBI_FREE(result); |
4867 result=0; | 4867 result=0; |
4868 } | 4868 } |
5208 | 5208 |
5209 static Uint8 *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp) | 5209 static Uint8 *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp) |
5210 { | 5210 { |
5211 Uint8 *u = 0; | 5211 Uint8 *u = 0; |
5212 stbi__gif g; | 5212 stbi__gif g; |
5213 memset(&g, 0, sizeof(g)); | 5213 STBI_MEMSET(&g, 0, sizeof(g)); |
5214 | 5214 |
5215 u = stbi__gif_load_next(s, &g, comp, req_comp); | 5215 u = stbi__gif_load_next(s, &g, comp, req_comp); |
5216 if (u == (Uint8 *) s) u = 0; // end of animated gif marker | 5216 if (u == (Uint8 *) s) u = 0; // end of animated gif marker |
5217 if (u) { | 5217 if (u) { |
5218 *x = g.w; | 5218 *x = g.w; |