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

Function stbi__bmp_load

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

Source from the content-addressed store, hash-verified

6092}
6093
6094static void* stbi__bmp_load(
6095 stbi__context* s, int* x, int* y, int* comp, int req_comp,
6096 stbi__result_info* ri) {
6097 stbi_uc* out;
6098 unsigned int mr = 0, mg = 0, mb = 0, ma = 0, all_a;
6099 stbi_uc pal[256][4];
6100 int psize = 0, i, j, width;
6101 int flip_vertically, pad, target;
6102 stbi__bmp_data info;
6103 STBI_NOTUSED(ri);
6104
6105 info.all_a = 255;
6106 if (stbi__bmp_parse_header(s, &info) == NULL)
6107 return NULL; // error code already set
6108
6109 flip_vertically = ((int)s->img_y) > 0;
6110 s->img_y = abs((int)s->img_y);
6111
6112 if (s->img_y > STBI_MAX_DIMENSIONS)
6113 return stbi__errpuc("too large", "Very large image (corrupt?)");
6114 if (s->img_x > STBI_MAX_DIMENSIONS)
6115 return stbi__errpuc("too large", "Very large image (corrupt?)");
6116
6117 mr = info.mr;
6118 mg = info.mg;
6119 mb = info.mb;
6120 ma = info.ma;
6121 all_a = info.all_a;
6122
6123 if (info.hsz == 12) {
6124 if (info.bpp < 24)
6125 psize = (info.offset - info.extra_read - 24) / 3;
6126 } else {
6127 if (info.bpp < 16)
6128 psize = (info.offset - info.extra_read - info.hsz) >> 2;
6129 }
6130 if (psize == 0) {
6131 if (info.offset !=
6132 s->callback_already_read + (s->img_buffer - s->img_buffer_original)) {
6133 return stbi__errpuc("bad offset", "Corrupt BMP");
6134 }
6135 }
6136
6137 if (info.bpp == 24 && ma == 0xff000000)
6138 s->img_n = 3;
6139 else
6140 s->img_n = ma ? 4 : 3;
6141 if (req_comp && req_comp >= 3) // we can directly decode 3 or 4
6142 target = req_comp;
6143 else
6144 target = s->img_n; // if they want monochrome, we'll post-convert
6145
6146 // sanity-check size
6147 if (!stbi__mad3sizes_valid(target, s->img_x, s->img_y, 0))
6148 return stbi__errpuc("too large", "Corrupt BMP");
6149
6150 out = (stbi_uc*)stbi__malloc_mad3(target, s->img_x, s->img_y, 0);
6151 if (!out)

Callers 1

stbi__load_mainFunction · 0.85

Calls 12

stbi__bmp_parse_headerFunction · 0.85
stbi__mad3sizes_validFunction · 0.85
stbi__malloc_mad3Function · 0.85
stbi__get8Function · 0.85
stbi__skipFunction · 0.85
stbi__high_bitFunction · 0.85
stbi__bitcountFunction · 0.85
stbi__get16leFunction · 0.85
stbi__get32leFunction · 0.85
stbi__shiftsignedFunction · 0.85
stbi__convert_formatFunction · 0.85
absFunction · 0.50

Tested by

no test coverage detected