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
|
||||
static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
||||
{
|
||||
int hsz;
|
||||
if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
stbi__skip(s,12);
|
||||
hsz = stbi__get32le(s);
|
||||
if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) {
|
||||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
void *p;
|
||||
stbi__bmp_data info;
|
||||
|
||||
info.all_a = 255;
|
||||
p = stbi__bmp_parse_header(s, &info);
|
||||
stbi__rewind( s );
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
*x = s->img_x;
|
||||
*y = s->img_y;
|
||||
*comp = info.ma ? 4 : 3;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -81,15 +81,17 @@ int main(int argc, char **argv)
|
||||
|
||||
for (i=1; i < argc; ++i) {
|
||||
int res;
|
||||
int w2,h2,n2;
|
||||
unsigned char *data;
|
||||
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, 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, 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(w == w2 && h == h2 && n == n2);
|
||||
assert(res);
|
||||
if (data) {
|
||||
char fname[512];
|
||||
|
Loading…
Reference in New Issue
Block a user