- /* Test supported pixel formats */
- switch (io->flags & IMAGE_COLOR_SPACE)
- {
- case COLOR_SPACE_GRAYSCALE:
- case COLOR_SPACE_RGB:
- break;
- default:
- png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, &rd->end_ptr);
- image_thread_err(io->thread, IMAGE_ERR_INVALID_PIXEL_FORMAT, "Unsupported color space.");
- return 0;
- }
-
- volatile int need_scale = io->cols != rd->cols || io->rows != rd->rows;
- struct image * volatile img = need_scale ?
- image_new(io->thread, rd->cols, rd->rows, io->flags & IMAGE_PIXEL_FORMAT, NULL) :
- image_new(io->thread, rd->cols, rd->rows, io->flags, io->pool);
- if (!img)
- {
- png_destroy_read_struct(&rd->png_ptr, &rd->info_ptr, &rd->end_ptr);
- return 0;
- }