mirror of
https://github.com/nothings/stb
synced 2024-12-15 04:22:35 +03:00
Merge branch 'stbi_is_16' of https://github.com/anael-seghezzi/stb
This commit is contained in:
commit
ead2b3fe2c
100
stb_image.h
100
stb_image.h
@ -418,11 +418,14 @@ STBIDEF void stbi_image_free (void *retval_from_stbi_load);
|
||||
// get image dimensions & components without fully decoding
|
||||
STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
|
||||
STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
|
||||
STBIDEF int stbi_is_16_from_memory(stbi_uc const *buffer, int len);
|
||||
STBIDEF int stbi_is_16_from_callbacks(stbi_io_callbacks const *clbk, void *user);
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
|
||||
STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
|
||||
|
||||
STBIDEF int stbi_is_16 (char const *filename);
|
||||
STBIDEF int stbi_is_16_from_file (FILE *f);
|
||||
#endif
|
||||
|
||||
|
||||
@ -786,6 +789,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
|
||||
static int stbi__png_test(stbi__context *s);
|
||||
static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
|
||||
static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
|
||||
static int stbi__png_is16(stbi__context *s);
|
||||
#endif
|
||||
|
||||
#ifndef STBI_NO_BMP
|
||||
@ -804,6 +808,7 @@ static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
|
||||
static int stbi__psd_test(stbi__context *s);
|
||||
static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri, int bpc);
|
||||
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
|
||||
static int stbi__psd_is16(stbi__context *s);
|
||||
#endif
|
||||
|
||||
#ifndef STBI_NO_HDR
|
||||
@ -4918,6 +4923,19 @@ static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
p.s = s;
|
||||
return stbi__png_info_raw(&p, x, y, comp);
|
||||
}
|
||||
|
||||
static int stbi__png_is16(stbi__context *s)
|
||||
{
|
||||
stbi__png p;
|
||||
p.s = s;
|
||||
if (!stbi__png_info_raw(&p, NULL, NULL, NULL))
|
||||
return 0;
|
||||
if (p.depth != 16) {
|
||||
stbi__rewind(p.s);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Microsoft/Windows BMP image
|
||||
@ -6696,7 +6714,7 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
#ifndef STBI_NO_PSD
|
||||
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
{
|
||||
int channelCount, dummy;
|
||||
int channelCount, dummy, depth;
|
||||
if (!x) x = &dummy;
|
||||
if (!y) y = &dummy;
|
||||
if (!comp) comp = &dummy;
|
||||
@ -6716,7 +6734,8 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
}
|
||||
*y = stbi__get32be(s);
|
||||
*x = stbi__get32be(s);
|
||||
if (stbi__get16be(s) != 8) {
|
||||
depth = stbi__get16be(s);
|
||||
if (depth != 8 && depth != 16) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
@ -6727,6 +6746,33 @@ static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
*comp = 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int stbi__psd_is16(stbi__context *s)
|
||||
{
|
||||
int channelCount, dummy, depth;
|
||||
if (stbi__get32be(s) != 0x38425053) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
if (stbi__get16be(s) != 1) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
stbi__skip(s, 6);
|
||||
channelCount = stbi__get16be(s);
|
||||
if (channelCount < 0 || channelCount > 16) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
dummy = stbi__get32be(s);
|
||||
dummy = stbi__get32be(s);
|
||||
depth = stbi__get16be(s);
|
||||
if (depth != 16) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef STBI_NO_PIC
|
||||
@ -6957,6 +7003,19 @@ static int stbi__info_main(stbi__context *s, int *x, int *y, int *comp)
|
||||
return stbi__err("unknown image type", "Image not of any known type, or corrupt");
|
||||
}
|
||||
|
||||
static int stbi__is_16_main(stbi__context *s)
|
||||
{
|
||||
#ifndef STBI_NO_PNG
|
||||
if (stbi__png_is16(s)) return 1;
|
||||
#endif
|
||||
|
||||
#ifndef STBI_NO_PSD
|
||||
if (stbi__psd_is16(s)) return 1;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
STBIDEF int stbi_info(char const *filename, int *x, int *y, int *comp)
|
||||
{
|
||||
@ -6978,6 +7037,27 @@ STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp)
|
||||
fseek(f,pos,SEEK_SET);
|
||||
return r;
|
||||
}
|
||||
|
||||
STBIDEF int stbi_is_16(char const *filename)
|
||||
{
|
||||
FILE *f = stbi__fopen(filename, "rb");
|
||||
int result;
|
||||
if (!f) return stbi__err("can't fopen", "Unable to open file");
|
||||
result = stbi_is_16_from_file(f);
|
||||
fclose(f);
|
||||
return result;
|
||||
}
|
||||
|
||||
STBIDEF int stbi_is_16_from_file(FILE *f)
|
||||
{
|
||||
int r;
|
||||
stbi__context s;
|
||||
long pos = ftell(f);
|
||||
stbi__start_file(&s, f);
|
||||
r = stbi__is_16_main(&s);
|
||||
fseek(f,pos,SEEK_SET);
|
||||
return r;
|
||||
}
|
||||
#endif // !STBI_NO_STDIO
|
||||
|
||||
STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp)
|
||||
@ -6994,6 +7074,20 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int
|
||||
return stbi__info_main(&s,x,y,comp);
|
||||
}
|
||||
|
||||
STBIDEF int stbi_is_16_from_memory(stbi_uc const *buffer, int len)
|
||||
{
|
||||
stbi__context s;
|
||||
stbi__start_mem(&s,buffer,len);
|
||||
return stbi__is_16_main(&s);
|
||||
}
|
||||
|
||||
STBIDEF int stbi_is_16_from_callbacks(stbi_io_callbacks const *c, void *user)
|
||||
{
|
||||
stbi__context s;
|
||||
stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user);
|
||||
return stbi__is_16_main(&s);
|
||||
}
|
||||
|
||||
#endif // STB_IMAGE_IMPLEMENTATION
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user