MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__bmp_parse_header

Function stbi__bmp_parse_header

lite/example/cpp_example/mge/cv/stb_image.h:6001–6092  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5999}
6000
6001static void* stbi__bmp_parse_header(stbi__context* s, stbi__bmp_data* info) {
6002 int hsz;
6003 if (stbi__get8(s) != 'B' || stbi__get8(s) != 'M')
6004 return stbi__errpuc("not BMP", "Corrupt BMP");
6005 stbi__get32le(s); // discard filesize
6006 stbi__get16le(s); // discard reserved
6007 stbi__get16le(s); // discard reserved
6008 info->offset = stbi__get32le(s);
6009 info->hsz = hsz = stbi__get32le(s);
6010 info->mr = info->mg = info->mb = info->ma = 0;
6011 info->extra_read = 14;
6012
6013 if (info->offset < 0)
6014 return stbi__errpuc("bad BMP", "bad BMP");
6015
6016 if (hsz != 12 && hsz != 40 && hsz != 56 && hsz != 108 && hsz != 124)
6017 return stbi__errpuc("unknown BMP", "BMP type not supported: unknown");
6018 if (hsz == 12) {
6019 s->img_x = stbi__get16le(s);
6020 s->img_y = stbi__get16le(s);
6021 } else {
6022 s->img_x = stbi__get32le(s);
6023 s->img_y = stbi__get32le(s);
6024 }
6025 if (stbi__get16le(s) != 1)
6026 return stbi__errpuc("bad BMP", "bad BMP");
6027 info->bpp = stbi__get16le(s);
6028 if (hsz != 12) {
6029 int compress = stbi__get32le(s);
6030 if (compress == 1 || compress == 2)
6031 return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
6032 if (compress >= 4)
6033 return stbi__errpuc(
6034 "BMP JPEG/PNG",
6035 "BMP type not supported: unsupported compression"); // this includes
6036 // PNG/JPEG modes
6037 if (compress == 3 && info->bpp != 16 && info->bpp != 32)
6038 return stbi__errpuc(
6039 "bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel
6040 stbi__get32le(s); // discard sizeof
6041 stbi__get32le(s); // discard hres
6042 stbi__get32le(s); // discard vres
6043 stbi__get32le(s); // discard colorsused
6044 stbi__get32le(s); // discard max important
6045 if (hsz == 40 || hsz == 56) {
6046 if (hsz == 56) {
6047 stbi__get32le(s);
6048 stbi__get32le(s);
6049 stbi__get32le(s);
6050 stbi__get32le(s);
6051 }
6052 if (info->bpp == 16 || info->bpp == 32) {
6053 if (compress == 0) {
6054 stbi__bmp_set_mask_defaults(info, compress);
6055 } else if (compress == 3) {
6056 info->mr = stbi__get32le(s);
6057 info->mg = stbi__get32le(s);
6058 info->mb = stbi__get32le(s);

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