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

Function stbi__pnm_load

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

Source from the content-addressed store, hash-verified

8203}
8204
8205static void* stbi__pnm_load(
8206 stbi__context* s, int* x, int* y, int* comp, int req_comp,
8207 stbi__result_info* ri) {
8208 stbi_uc* out;
8209 STBI_NOTUSED(ri);
8210
8211 ri->bits_per_channel =
8212 stbi__pnm_info(s, (int*)&s->img_x, (int*)&s->img_y, (int*)&s->img_n);
8213 if (ri->bits_per_channel == 0)
8214 return 0;
8215
8216 if (s->img_y > STBI_MAX_DIMENSIONS)
8217 return stbi__errpuc("too large", "Very large image (corrupt?)");
8218 if (s->img_x > STBI_MAX_DIMENSIONS)
8219 return stbi__errpuc("too large", "Very large image (corrupt?)");
8220
8221 *x = s->img_x;
8222 *y = s->img_y;
8223 if (comp)
8224 *comp = s->img_n;
8225
8226 if (!stbi__mad4sizes_valid(
8227 s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0))
8228 return stbi__errpuc("too large", "PNM too large");
8229
8230 out = (stbi_uc*)stbi__malloc_mad4(
8231 s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0);
8232 if (!out)
8233 return stbi__errpuc("outofmem", "Out of memory");
8234 stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8));
8235
8236 if (req_comp && req_comp != s->img_n) {
8237 out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
8238 if (out == NULL)
8239 return out; // stbi__convert_format frees input on failure
8240 }
8241 return out;
8242}
8243
8244static int stbi__pnm_isspace(char c) {
8245 return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';

Callers 1

stbi__load_mainFunction · 0.85

Calls 5

stbi__pnm_infoFunction · 0.85
stbi__mad4sizes_validFunction · 0.85
stbi__malloc_mad4Function · 0.85
stbi__getnFunction · 0.85
stbi__convert_formatFunction · 0.85

Tested by

no test coverage detected