mirror of
https://github.com/nothings/stb
synced 2024-12-15 04:22:35 +03:00
stb_image: Support optional args consistently.
My guideline for the rules is the PNG loader (which I consider "canonical"). In the _load functions, x and y are required but comp is optional; in the _info functions, all three are optional. Fixes issue #411 (and other related, unreported issues).
This commit is contained in:
parent
6f6e11f85f
commit
22c72a069c
38
stb_image.h
38
stb_image.h
@ -5875,9 +5875,11 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *c
|
|||||||
static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri)
|
static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp, stbi__result_info *ri)
|
||||||
{
|
{
|
||||||
stbi_uc *result;
|
stbi_uc *result;
|
||||||
int i, x,y;
|
int i, x,y, internal_comp;
|
||||||
STBI_NOTUSED(ri);
|
STBI_NOTUSED(ri);
|
||||||
|
|
||||||
|
if (!comp) comp = &internal_comp;
|
||||||
|
|
||||||
for (i=0; i<92; ++i)
|
for (i=0; i<92; ++i)
|
||||||
stbi__get8(s);
|
stbi__get8(s);
|
||||||
|
|
||||||
@ -6496,6 +6498,11 @@ static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp)
|
|||||||
char buffer[STBI__HDR_BUFLEN];
|
char buffer[STBI__HDR_BUFLEN];
|
||||||
char *token;
|
char *token;
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
|
int dummy;
|
||||||
|
|
||||||
|
if (!x) x = &dummy;
|
||||||
|
if (!y) y = &dummy;
|
||||||
|
if (!comp) comp = &dummy;
|
||||||
|
|
||||||
if (stbi__hdr_test(s) == 0) {
|
if (stbi__hdr_test(s) == 0) {
|
||||||
stbi__rewind( s );
|
stbi__rewind( s );
|
||||||
@ -6542,9 +6549,9 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
|||||||
stbi__rewind( s );
|
stbi__rewind( s );
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
*x = s->img_x;
|
if (x) *x = s->img_x;
|
||||||
*y = s->img_y;
|
if (y) *y = s->img_y;
|
||||||
*comp = info.ma ? 4 : 3;
|
if (comp) *comp = info.ma ? 4 : 3;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -6552,7 +6559,10 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
|||||||
#ifndef STBI_NO_PSD
|
#ifndef STBI_NO_PSD
|
||||||
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
||||||
{
|
{
|
||||||
int channelCount;
|
int channelCount, dummy;
|
||||||
|
if (!x) x = &dummy;
|
||||||
|
if (!y) y = &dummy;
|
||||||
|
if (!comp) comp = &dummy;
|
||||||
if (stbi__get32be(s) != 0x38425053) {
|
if (stbi__get32be(s) != 0x38425053) {
|
||||||
stbi__rewind( s );
|
stbi__rewind( s );
|
||||||
return 0;
|
return 0;
|
||||||
@ -6585,9 +6595,13 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
|||||||
#ifndef STBI_NO_PIC
|
#ifndef STBI_NO_PIC
|
||||||
static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
|
static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
|
||||||
{
|
{
|
||||||
int act_comp=0,num_packets=0,chained;
|
int act_comp=0,num_packets=0,chained,dummy;
|
||||||
stbi__pic_packet packets[10];
|
stbi__pic_packet packets[10];
|
||||||
|
|
||||||
|
if (!x) x = &dummy;
|
||||||
|
if (!y) y = &dummy;
|
||||||
|
if (!comp) comp = &dummy;
|
||||||
|
|
||||||
if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) {
|
if (!stbi__pic_is4(s,"\x53\x80\xF6\x34")) {
|
||||||
stbi__rewind(s);
|
stbi__rewind(s);
|
||||||
return 0;
|
return 0;
|
||||||
@ -6673,7 +6687,7 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|||||||
|
|
||||||
*x = s->img_x;
|
*x = s->img_x;
|
||||||
*y = s->img_y;
|
*y = s->img_y;
|
||||||
*comp = s->img_n;
|
if (comp) *comp = s->img_n;
|
||||||
|
|
||||||
if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0))
|
if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0))
|
||||||
return stbi__errpuc("too large", "PNM too large");
|
return stbi__errpuc("too large", "PNM too large");
|
||||||
@ -6727,16 +6741,20 @@ static int stbi__pnm_getinteger(stbi__context *s, char *c)
|
|||||||
|
|
||||||
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
|
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
|
||||||
{
|
{
|
||||||
int maxv;
|
int maxv, dummy;
|
||||||
char c, p, t;
|
char c, p, t;
|
||||||
|
|
||||||
stbi__rewind( s );
|
if (!x) x = &dummy;
|
||||||
|
if (!y) y = &dummy;
|
||||||
|
if (!comp) comp = &dummy;
|
||||||
|
|
||||||
|
stbi__rewind(s);
|
||||||
|
|
||||||
// Get identifier
|
// Get identifier
|
||||||
p = (char) stbi__get8(s);
|
p = (char) stbi__get8(s);
|
||||||
t = (char) stbi__get8(s);
|
t = (char) stbi__get8(s);
|
||||||
if (p != 'P' || (t != '5' && t != '6')) {
|
if (p != 'P' || (t != '5' && t != '6')) {
|
||||||
stbi__rewind( s );
|
stbi__rewind(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user