| 81 | }; |
| 82 | |
| 83 | static void read_png(const char* imageName, |
| 84 | png_structp read_ptr, png_infop read_info, |
| 85 | image_info* outImageInfo) |
| 86 | { |
| 87 | int color_type; |
| 88 | int bit_depth, interlace_type, compression_type; |
| 89 | int i; |
| 90 | |
| 91 | png_read_info(read_ptr, read_info); |
| 92 | |
| 93 | png_get_IHDR(read_ptr, read_info, &outImageInfo->width, |
| 94 | &outImageInfo->height, &bit_depth, &color_type, |
| 95 | &interlace_type, &compression_type, NULL); |
| 96 | |
| 97 | //printf("Image %s:\n", imageName); |
| 98 | //printf("color_type=%d, bit_depth=%d, interlace_type=%d, compression_type=%d\n", |
| 99 | // color_type, bit_depth, interlace_type, compression_type); |
| 100 | |
| 101 | if (color_type == PNG_COLOR_TYPE_PALETTE) |
| 102 | png_set_palette_to_rgb(read_ptr); |
| 103 | |
| 104 | if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) |
| 105 | png_set_gray_1_2_4_to_8(read_ptr); |
| 106 | |
| 107 | if (png_get_valid(read_ptr, read_info, PNG_INFO_tRNS)) { |
| 108 | //printf("Has PNG_INFO_tRNS!\n"); |
| 109 | png_set_tRNS_to_alpha(read_ptr); |
| 110 | } |
| 111 | |
| 112 | if (bit_depth == 16) |
| 113 | png_set_strip_16(read_ptr); |
| 114 | |
| 115 | if ((color_type&PNG_COLOR_MASK_ALPHA) == 0) |
| 116 | png_set_add_alpha(read_ptr, 0xFF, PNG_FILLER_AFTER); |
| 117 | |
| 118 | if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
| 119 | png_set_gray_to_rgb(read_ptr); |
| 120 | |
| 121 | png_read_update_info(read_ptr, read_info); |
| 122 | |
| 123 | outImageInfo->rows = (png_bytepp)malloc( |
| 124 | outImageInfo->height * png_sizeof(png_bytep)); |
| 125 | outImageInfo->allocHeight = outImageInfo->height; |
| 126 | outImageInfo->allocRows = outImageInfo->rows; |
| 127 | |
| 128 | png_set_rows(read_ptr, read_info, outImageInfo->rows); |
| 129 | |
| 130 | for (i = 0; i < (int)outImageInfo->height; i++) |
| 131 | { |
| 132 | outImageInfo->rows[i] = (png_bytep) |
| 133 | malloc(png_get_rowbytes(read_ptr, read_info)); |
| 134 | } |
| 135 | |
| 136 | png_read_image(read_ptr, outImageInfo->rows); |
| 137 | |
| 138 | png_read_end(read_ptr, read_info); |
| 139 | |
| 140 | NOISY(printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n", |
no outgoing calls
no test coverage detected