MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__pnm_info

Function stbi__pnm_info

Source/Utils/stb_image.h:7578–7619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7576}
7577
7578static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
7579{
7580 int maxv, dummy;
7581 char c, p, t;
7582
7583 if (!x) x = &dummy;
7584 if (!y) y = &dummy;
7585 if (!comp) comp = &dummy;
7586
7587 stbi__rewind(s);
7588
7589 // Get identifier
7590 p = (char) stbi__get8(s);
7591 t = (char) stbi__get8(s);
7592 if (p != 'P' || (t != '5' && t != '6')) {
7593 stbi__rewind(s);
7594 return 0;
7595 }
7596
7597 *comp = (t == '6') ? 3 : 1; // '5' is 1-component .pgm; '6' is 3-component .ppm
7598
7599 c = (char) stbi__get8(s);
7600 stbi__pnm_skip_whitespace(s, &c);
7601
7602 *x = stbi__pnm_getinteger(s, &c); // read width
7603 if(*x == 0)
7604 return stbi__err("invalid width", "PPM image header had zero or overflowing width");
7605 stbi__pnm_skip_whitespace(s, &c);
7606
7607 *y = stbi__pnm_getinteger(s, &c); // read height
7608 if (*y == 0)
7609 return stbi__err("invalid width", "PPM image header had zero or overflowing width");
7610 stbi__pnm_skip_whitespace(s, &c);
7611
7612 maxv = stbi__pnm_getinteger(s, &c); // read max value
7613 if (maxv > 65535)
7614 return stbi__err("max value > 65535", "PPM image supports only 8-bit and 16-bit images");
7615 else if (maxv > 255)
7616 return 16;
7617 else
7618 return 8;
7619}
7620
7621static int stbi__pnm_is16(stbi__context *s)
7622{

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