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

Function stbi__pnm_info

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

Source from the content-addressed store, hash-verified

8274}
8275
8276static int stbi__pnm_info(stbi__context* s, int* x, int* y, int* comp) {
8277 int maxv, dummy;
8278 char c, p, t;
8279
8280 if (!x)
8281 x = &dummy;
8282 if (!y)
8283 y = &dummy;
8284 if (!comp)
8285 comp = &dummy;
8286
8287 stbi__rewind(s);
8288
8289 // Get identifier
8290 p = (char)stbi__get8(s);
8291 t = (char)stbi__get8(s);
8292 if (p != 'P' || (t != '5' && t != '6')) {
8293 stbi__rewind(s);
8294 return 0;
8295 }
8296
8297 *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
8298
8299 c = (char)stbi__get8(s);
8300 stbi__pnm_skip_whitespace(s, &c);
8301
8302 *x = stbi__pnm_getinteger(s, &c); // read width
8303 stbi__pnm_skip_whitespace(s, &c);
8304
8305 *y = stbi__pnm_getinteger(s, &c); // read height
8306 stbi__pnm_skip_whitespace(s, &c);
8307
8308 maxv = stbi__pnm_getinteger(s, &c); // read max value
8309 if (maxv > 65535)
8310 return stbi__err(
8311 "max value > 65535", "PPM image supports only 8-bit and 16-bit images");
8312 else if (maxv > 255)
8313 return 16;
8314 else
8315 return 8;
8316}
8317
8318static int stbi__pnm_is16(stbi__context* s) {
8319 if (stbi__pnm_info(s, NULL, NULL, NULL) == 16)

Callers 3

stbi__pnm_loadFunction · 0.85
stbi__pnm_is16Function · 0.85
stbi__info_mainFunction · 0.85

Calls 5

stbi__rewindFunction · 0.85
stbi__get8Function · 0.85
stbi__pnm_getintegerFunction · 0.85
stbi__errFunction · 0.85

Tested by

no test coverage detected