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

Function stbi__pnm_load

include/stb/stb_image.h:7506–7541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7504}
7505
7506static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
7507{
7508 stbi_uc *out;
7509 STBI_NOTUSED(ri);
7510
7511 ri->bits_per_channel = stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n);
7512 if (ri->bits_per_channel == 0)
7513 return 0;
7514
7515 if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
7516 if (s->img_x > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
7517
7518 *x = s->img_x;
7519 *y = s->img_y;
7520 if (comp) *comp = s->img_n;
7521
7522 if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0))
7523 return stbi__errpuc("too large", "PNM too large");
7524
7525 out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0);
7526 if (!out) return stbi__errpuc("outofmem", "Out of memory");
7527 if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) {
7528 STBI_FREE(out);
7529 return stbi__errpuc("bad PNM", "PNM file truncated");
7530 }
7531
7532 if (req_comp && req_comp != s->img_n) {
7533 if (ri->bits_per_channel == 16) {
7534 out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y);
7535 } else {
7536 out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
7537 }
7538 if (out == NULL) return out; // stbi__convert_format frees input on failure
7539 }
7540 return out;
7541}
7542
7543static int stbi__pnm_isspace(char c)
7544{

Callers 1

stbi__load_mainFunction · 0.85

Calls 6

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

Tested by

no test coverage detected