MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__bmp_parse_header

Function stbi__bmp_parse_header

include/stb/stb_image.h:5448–5528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5446}
5447
5448static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
5449{
5450 int hsz;
5451 if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M') return stbi__errpuc("not BMP", "Corrupt BMP");
5452 stbi__get32le(s); // discard filesize
5453 stbi__get16le(s); // discard reserved
5454 stbi__get16le(s); // discard reserved
5455 info->offset = stbi__get32le(s);
5456 info->hsz = hsz = stbi__get32le(s);
5457 info->mr = info->mg = info->mb = info->ma = 0;
5458 info->extra_read = 14;
5459
5460 if (info->offset < 0) return stbi__errpuc("bad BMP", "bad BMP");
5461
5462 if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124) return stbi__errpuc("unknown BMP", "BMP type not supported: unknown");
5463 if (hsz == 12) {
5464 s->img_x = stbi__get16le(s);
5465 s->img_y = stbi__get16le(s);
5466 } else {
5467 s->img_x = stbi__get32le(s);
5468 s->img_y = stbi__get32le(s);
5469 }
5470 if (stbi__get16le(s) != 1) return stbi__errpuc("bad BMP", "bad BMP");
5471 info->bpp = stbi__get16le(s);
5472 if (hsz != 12) {
5473 int compress = stbi__get32le(s);
5474 if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
5475 if (compress >= 4) return stbi__errpuc("BMP JPEG/PNG", "BMP type not supported: unsupported compression"); // this includes PNG/JPEG modes
5476 if (compress == 3 && info->bpp != 16 && info->bpp != 32) return stbi__errpuc("bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel
5477 stbi__get32le(s); // discard sizeof
5478 stbi__get32le(s); // discard hres
5479 stbi__get32le(s); // discard vres
5480 stbi__get32le(s); // discard colorsused
5481 stbi__get32le(s); // discard max important
5482 if (hsz == 40 || hsz == 56) {
5483 if (hsz == 56) {
5484 stbi__get32le(s);
5485 stbi__get32le(s);
5486 stbi__get32le(s);
5487 stbi__get32le(s);
5488 }
5489 if (info->bpp == 16 || info->bpp == 32) {
5490 if (compress == 0) {
5491 stbi__bmp_set_mask_defaults(info, compress);
5492 } else if (compress == 3) {
5493 info->mr = stbi__get32le(s);
5494 info->mg = stbi__get32le(s);
5495 info->mb = stbi__get32le(s);
5496 info->extra_read += 12;
5497 // not documented, but generated by photoshop and handled by mspaint
5498 if (info->mr == info->mg && info->mg == info->mb) {
5499 // ?!?!?
5500 return stbi__errpuc("bad BMP", "bad BMP");
5501 }
5502 } else
5503 return stbi__errpuc("bad BMP", "bad BMP");
5504 }
5505 } else {

Callers 2

stbi__bmp_loadFunction · 0.85
stbi__bmp_infoFunction · 0.85

Calls 4

stbi__get8Function · 0.85
stbi__get32leFunction · 0.85
stbi__get16leFunction · 0.85

Tested by

no test coverage detected