more warnings, use stdint.h if possible
This commit is contained in:
parent
70df4966f0
commit
a31d50ab29
40
stb_image.c
40
stb_image.c
@ -57,9 +57,10 @@
|
|||||||
John Bartholomew
|
John Bartholomew
|
||||||
Optimizations & bugfixes Ken Hamada
|
Optimizations & bugfixes Ken Hamada
|
||||||
Fabian "ryg" Giesen Cort Stratton
|
Fabian "ryg" Giesen Cort Stratton
|
||||||
|
Blazej Dariusz Roszkowski
|
||||||
|
Thibault Reuille
|
||||||
If your name should be here but isn't, let Sean know.
|
If your name should be here but Paul Du Bois
|
||||||
|
isn't let Sean know. Guillaume George
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -349,6 +350,7 @@ extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func);
|
|||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h> // ptrdiff_t on osx
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -361,12 +363,20 @@ extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// implementation:
|
#ifdef _MSC_VER
|
||||||
typedef unsigned char stbi__uint8;
|
typedef unsigned char stbi__uint8;
|
||||||
typedef unsigned short stbi__uint16;
|
typedef unsigned short stbi__uint16;
|
||||||
typedef signed short stbi__int16;
|
typedef signed short stbi__int16;
|
||||||
typedef unsigned int stbi__uint32;
|
typedef unsigned int stbi__uint32;
|
||||||
typedef signed int stbi__int32;
|
typedef signed int stbi__int32;
|
||||||
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef uint8_t stbi__uint8;
|
||||||
|
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
|
// should produce compiler error if size is wrong
|
||||||
typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
|
typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
|
||||||
@ -727,8 +737,8 @@ static void refill_buffer(stbi *s)
|
|||||||
{
|
{
|
||||||
int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen);
|
int n = (s->io.read)(s->io_user_data,(char*)s->buffer_start,s->buflen);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
// at end of file, treat same as if from memory, but need
|
// at end of file, treat same as if from memory, but need to handle case
|
||||||
// to handle case where s->img_buffer isn't pointing to safe memory
|
// where s->img_buffer isn't pointing to safe memory, e.g. 0-byte file
|
||||||
s->read_from_callbacks = 0;
|
s->read_from_callbacks = 0;
|
||||||
s->img_buffer = s->buffer_start;
|
s->img_buffer = s->buffer_start;
|
||||||
s->img_buffer_end = s->buffer_start+1;
|
s->img_buffer_end = s->buffer_start+1;
|
||||||
@ -3014,6 +3024,7 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
|||||||
mb = 0xffu << 0;
|
mb = 0xffu << 0;
|
||||||
ma = 0xffu << 24;
|
ma = 0xffu << 24;
|
||||||
fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255
|
fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255
|
||||||
|
STBI_UNUSED(fake_a);
|
||||||
} else {
|
} else {
|
||||||
mr = 31u << 10;
|
mr = 31u << 10;
|
||||||
mg = 31u << 5;
|
mg = 31u << 5;
|
||||||
@ -3105,9 +3116,9 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
|||||||
if (!mr || !mg || !mb) { free(out); return epuc("bad masks", "Corrupt BMP"); }
|
if (!mr || !mg || !mb) { free(out); return epuc("bad masks", "Corrupt BMP"); }
|
||||||
// right shift amt to put high bit in position #7
|
// right shift amt to put high bit in position #7
|
||||||
rshift = high_bit(mr)-7; rcount = bitcount(mr);
|
rshift = high_bit(mr)-7; rcount = bitcount(mr);
|
||||||
gshift = high_bit(mg)-7; gcount = bitcount(mr);
|
gshift = high_bit(mg)-7; gcount = bitcount(mg);
|
||||||
bshift = high_bit(mb)-7; bcount = bitcount(mr);
|
bshift = high_bit(mb)-7; bcount = bitcount(mb);
|
||||||
ashift = high_bit(ma)-7; acount = bitcount(mr);
|
ashift = high_bit(ma)-7; acount = bitcount(ma);
|
||||||
}
|
}
|
||||||
for (j=0; j < (int) s->img_y; ++j) {
|
for (j=0; j < (int) s->img_y; ++j) {
|
||||||
if (easy) {
|
if (easy) {
|
||||||
@ -3122,7 +3133,7 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i=0; i < (int) s->img_x; ++i) {
|
for (i=0; i < (int) s->img_x; ++i) {
|
||||||
stbi__uint32 v = (bpp == 16 ? get16le(s) : get32le(s));
|
stbi__uint32 v = (stbi_uint32) (bpp == 16 ? get16le(s) : get32le(s));
|
||||||
int a;
|
int a;
|
||||||
out[z++] = (stbi__uint8) shiftsigned(v & mr, rshift, rcount);
|
out[z++] = (stbi__uint8) shiftsigned(v & mr, rshift, rcount);
|
||||||
out[z++] = (stbi__uint8) shiftsigned(v & mg, gshift, gcount);
|
out[z++] = (stbi__uint8) shiftsigned(v & mg, gshift, gcount);
|
||||||
@ -4309,11 +4320,11 @@ static float *hdr_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
|||||||
token = hdr_gettoken(s,buffer);
|
token = hdr_gettoken(s,buffer);
|
||||||
if (strncmp(token, "-Y ", 3)) return epf("unsupported data layout", "Unsupported HDR format");
|
if (strncmp(token, "-Y ", 3)) return epf("unsupported data layout", "Unsupported HDR format");
|
||||||
token += 3;
|
token += 3;
|
||||||
height = strtol(token, &token, 10);
|
height = (int) strtol(token, &token, 10);
|
||||||
while (*token == ' ') ++token;
|
while (*token == ' ') ++token;
|
||||||
if (strncmp(token, "+X ", 3)) return epf("unsupported data layout", "Unsupported HDR format");
|
if (strncmp(token, "+X ", 3)) return epf("unsupported data layout", "Unsupported HDR format");
|
||||||
token += 3;
|
token += 3;
|
||||||
width = strtol(token, NULL, 10);
|
width = (int) strtol(token, NULL, 10);
|
||||||
|
|
||||||
*x = width;
|
*x = width;
|
||||||
*y = height;
|
*y = height;
|
||||||
@ -4421,14 +4432,14 @@ static int stbi_hdr_info(stbi *s, int *x, int *y, int *comp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
token += 3;
|
token += 3;
|
||||||
*y = strtol(token, &token, 10);
|
*y = (int) strtol(token, &token, 10);
|
||||||
while (*token == ' ') ++token;
|
while (*token == ' ') ++token;
|
||||||
if (strncmp(token, "+X ", 3)) {
|
if (strncmp(token, "+X ", 3)) {
|
||||||
stbi_rewind( s );
|
stbi_rewind( s );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
token += 3;
|
token += 3;
|
||||||
*x = strtol(token, NULL, 10);
|
*x = (int) strtol(token, NULL, 10);
|
||||||
*comp = 3;
|
*comp = 3;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -4612,6 +4623,7 @@ int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int *x, int
|
|||||||
various warnings
|
various warnings
|
||||||
fix broken STBI_SIMD path
|
fix broken STBI_SIMD path
|
||||||
fix bug where stbi_load_from_file no longer left file pointer in correct place
|
fix bug where stbi_load_from_file no longer left file pointer in correct place
|
||||||
|
fix broken non-easy path for 32-bit BMP (possibly never used)
|
||||||
1.34 (unknown)
|
1.34 (unknown)
|
||||||
use STBI_NOTUSED in resample_row_generic(), fix one more leak in tga failure case
|
use STBI_NOTUSED in resample_row_generic(), fix one more leak in tga failure case
|
||||||
1.33 (2011-07-14)
|
1.33 (2011-07-14)
|
||||||
|
Loading…
Reference in New Issue
Block a user