| 5258 | } |
| 5259 | |
| 5260 | static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, stbi__result_info *ri) |
| 5261 | { |
| 5262 | void *result=NULL; |
| 5263 | if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); |
| 5264 | if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { |
| 5265 | if (p->depth <= 8) |
| 5266 | ri->bits_per_channel = 8; |
| 5267 | else if (p->depth == 16) |
| 5268 | ri->bits_per_channel = 16; |
| 5269 | else |
| 5270 | return stbi__errpuc("bad bits_per_channel", "PNG not supported: unsupported color depth"); |
| 5271 | result = p->out; |
| 5272 | p->out = NULL; |
| 5273 | if (req_comp && req_comp != p->s->img_out_n) { |
| 5274 | if (ri->bits_per_channel == 8) |
| 5275 | result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); |
| 5276 | else |
| 5277 | result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y); |
| 5278 | p->s->img_out_n = req_comp; |
| 5279 | if (result == NULL) return result; |
| 5280 | } |
| 5281 | *x = p->s->img_x; |
| 5282 | *y = p->s->img_y; |
| 5283 | if (n) *n = p->s->img_n; |
| 5284 | } |
| 5285 | STBI_FREE(p->out); p->out = NULL; |
| 5286 | STBI_FREE(p->expanded); p->expanded = NULL; |
| 5287 | STBI_FREE(p->idata); p->idata = NULL; |
| 5288 | |
| 5289 | return result; |
| 5290 | } |
| 5291 | |
| 5292 | static void *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri) |
| 5293 | { |
no test coverage detected