mirror of
https://github.com/nothings/stb
synced 2024-12-15 12:22:55 +03:00
change bmp info to use common header parser
This commit is contained in:
parent
876aea3dbe
commit
297ff62859
34
stb_image.h
34
stb_image.h
@ -6088,29 +6088,17 @@ static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp)
|
|||||||
#ifndef STBI_NO_BMP
|
#ifndef STBI_NO_BMP
|
||||||
static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
||||||
{
|
{
|
||||||
int hsz;
|
void *p;
|
||||||
if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') {
|
stbi__bmp_data info;
|
||||||
stbi__rewind( s );
|
|
||||||
return 0;
|
info.all_a = 255;
|
||||||
}
|
p = stbi__bmp_parse_header(s, &info);
|
||||||
stbi__skip(s,12);
|
stbi__rewind( s );
|
||||||
hsz = stbi__get32le(s);
|
if (p == NULL)
|
||||||
if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) {
|
return 0;
|
||||||
stbi__rewind( s );
|
*x = s->img_x;
|
||||||
return 0;
|
*y = s->img_y;
|
||||||
}
|
*comp = info.ma ? 4 : 3;
|
||||||
if (hsz == 12) {
|
|
||||||
*x = stbi__get16le(s);
|
|
||||||
*y = stbi__get16le(s);
|
|
||||||
} else {
|
|
||||||
*x = stbi__get32le(s);
|
|
||||||
*y = stbi__get32le(s);
|
|
||||||
}
|
|
||||||
if (stbi__get16le(s) != 1) {
|
|
||||||
stbi__rewind( s );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*comp = stbi__get16le(s) / 8;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,15 +81,17 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
for (i=1; i < argc; ++i) {
|
for (i=1; i < argc; ++i) {
|
||||||
int res;
|
int res;
|
||||||
|
int w2,h2,n2;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
printf("%s\n", argv[i]);
|
printf("%s\n", argv[i]);
|
||||||
res = stbi_info(argv[1], &w, &h, &n);
|
res = stbi_info(argv[1], &w2, &h2, &n2);
|
||||||
data = stbi_load(argv[i], &w, &h, &n, 4); if (data) free(data); else printf("Failed &n\n");
|
data = stbi_load(argv[i], &w, &h, &n, 4); if (data) free(data); else printf("Failed &n\n");
|
||||||
data = stbi_load(argv[i], &w, &h, 0, 1); if (data) free(data); else printf("Failed 1\n");
|
data = stbi_load(argv[i], &w, &h, 0, 1); if (data) free(data); else printf("Failed 1\n");
|
||||||
data = stbi_load(argv[i], &w, &h, 0, 2); if (data) free(data); else printf("Failed 2\n");
|
data = stbi_load(argv[i], &w, &h, 0, 2); if (data) free(data); else printf("Failed 2\n");
|
||||||
data = stbi_load(argv[i], &w, &h, 0, 3); if (data) free(data); else printf("Failed 3\n");
|
data = stbi_load(argv[i], &w, &h, 0, 3); if (data) free(data); else printf("Failed 3\n");
|
||||||
data = stbi_load(argv[i], &w, &h, 0, 4);
|
data = stbi_load(argv[i], &w, &h, &n, 4);
|
||||||
assert(data);
|
assert(data);
|
||||||
|
assert(w == w2 && h == h2 && n == n2);
|
||||||
assert(res);
|
assert(res);
|
||||||
if (data) {
|
if (data) {
|
||||||
char fname[512];
|
char fname[512];
|
||||||
|
Loading…
Reference in New Issue
Block a user