| 5538 | (unsigned)(d)) |
| 5539 | |
| 5540 | static int stbi__parse_png_file(stbi__png* z, int scan, int req_comp) { |
| 5541 | stbi_uc palette[1024], pal_img_n = 0; |
| 5542 | stbi_uc has_trans = 0, tc[3] = {0}; |
| 5543 | stbi__uint16 tc16[3]; |
| 5544 | stbi__uint32 ioff = 0, idata_limit = 0, i, pal_len = 0; |
| 5545 | int first = 1, k, interlace = 0, color = 0, is_iphone = 0; |
| 5546 | stbi__context* s = z->s; |
| 5547 | |
| 5548 | z->expanded = NULL; |
| 5549 | z->idata = NULL; |
| 5550 | z->out = NULL; |
| 5551 | |
| 5552 | if (!stbi__check_png_header(s)) |
| 5553 | return 0; |
| 5554 | |
| 5555 | if (scan == STBI__SCAN_type) |
| 5556 | return 1; |
| 5557 | |
| 5558 | for (;;) { |
| 5559 | stbi__pngchunk c = stbi__get_chunk_header(s); |
| 5560 | switch (c.type) { |
| 5561 | case STBI__PNG_TYPE('C', 'g', 'B', 'I'): |
| 5562 | is_iphone = 1; |
| 5563 | stbi__skip(s, c.length); |
| 5564 | break; |
| 5565 | case STBI__PNG_TYPE('I', 'H', 'D', 'R'): { |
| 5566 | int comp, filter; |
| 5567 | if (!first) |
| 5568 | return stbi__err("multiple IHDR", "Corrupt PNG"); |
| 5569 | first = 0; |
| 5570 | if (c.length != 13) |
| 5571 | return stbi__err("bad IHDR len", "Corrupt PNG"); |
| 5572 | s->img_x = stbi__get32be(s); |
| 5573 | s->img_y = stbi__get32be(s); |
| 5574 | if (s->img_y > STBI_MAX_DIMENSIONS) |
| 5575 | return stbi__err("too large", "Very large image (corrupt?)"); |
| 5576 | if (s->img_x > STBI_MAX_DIMENSIONS) |
| 5577 | return stbi__err("too large", "Very large image (corrupt?)"); |
| 5578 | z->depth = stbi__get8(s); |
| 5579 | if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && |
| 5580 | z->depth != 16) |
| 5581 | return stbi__err( |
| 5582 | "1/2/4/8/16-bit only", |
| 5583 | "PNG not supported: 1/2/4/8/16-bit only"); |
| 5584 | color = stbi__get8(s); |
| 5585 | if (color > 6) |
| 5586 | return stbi__err("bad ctype", "Corrupt PNG"); |
| 5587 | if (color == 3 && z->depth == 16) |
| 5588 | return stbi__err("bad ctype", "Corrupt PNG"); |
| 5589 | if (color == 3) |
| 5590 | pal_img_n = 3; |
| 5591 | else if (color & 1) |
| 5592 | return stbi__err("bad ctype", "Corrupt PNG"); |
| 5593 | comp = stbi__get8(s); |
| 5594 | if (comp) |
| 5595 | return stbi__err("bad comp method", "Corrupt PNG"); |
| 5596 | filter = stbi__get8(s); |
| 5597 | if (filter) |
no test coverage detected