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