http://code.google.com/p/flam3/source/detail?r=164
|
|
|
142 | 142 | } |
143 | 143 | if (setjmp(png_jmpbuf(png_ptr))) { |
144 | 144 | if (png_image) { |
145 | | for (y = 0 ; y < info_ptr->height ; y++) |
| 145 | for (y = 0 ; y < png_get_image_height(png_ptr, info_ptr) ; y++) |
146 | 146 | free (png_image[y]); |
147 | 147 | free (png_image); |
148 | 148 | } |
… |
… |
|
161 | 161 | png_set_sig_bytes (png_ptr, SIG_CHECK_SIZE); |
162 | 162 | png_read_info (png_ptr, info_ptr); |
163 | 163 | |
164 | | if (8 != info_ptr->bit_depth) { |
| 164 | if (8 != png_get_bit_depth(png_ptr, info_ptr)) { |
165 | 165 | fprintf(stderr, "bit depth type must be 8, not %d.\n", |
166 | | info_ptr->bit_depth); |
| 166 | png_get_bit_depth(png_ptr, info_ptr)); |
167 | 167 | return 0; |
168 | 168 | } |
169 | 169 | |
170 | | *width = info_ptr->width; |
171 | | *height = info_ptr->height; |
| 170 | *width = png_get_image_width(png_ptr, info_ptr); |
| 171 | *height = png_get_image_height(png_ptr, info_ptr); |
172 | 172 | p = q = malloc(4 * *width * *height); |
173 | | png_image = (png_byte **)malloc (info_ptr->height * sizeof (png_byte*)); |
| 173 | png_image = (png_byte **)malloc (*height * sizeof (png_byte*)); |
174 | 174 | |
175 | | linesize = info_ptr->width; |
176 | | switch (info_ptr->color_type) { |
| 175 | linesize = *width; |
| 176 | switch (png_get_color_type(png_ptr, info_ptr)) { |
177 | 177 | case PNG_COLOR_TYPE_RGB: |
178 | 178 | linesize *= 3; |
179 | 179 | break; |
… |
… |
|
182 | 182 | break; |
183 | 183 | default: |
184 | 184 | fprintf(stderr, "color type must be RGB or RGBA not %d.\n", |
185 | | info_ptr->color_type); |
| 185 | png_get_color_type(png_ptr, info_ptr)); |
186 | 186 | return 0; |
187 | 187 | } |
188 | 188 | |
189 | | for (y = 0 ; y < info_ptr->height ; y++) { |
| 189 | for (y = 0 ; y < *height ; y++) { |
190 | 190 | png_image[y] = malloc (linesize); |
191 | 191 | } |
192 | 192 | png_read_image (png_ptr, png_image); |
193 | 193 | png_read_end (png_ptr, info_ptr); |
194 | 194 | |
195 | | for (y = 0 ; y < info_ptr->height ; y++) { |
| 195 | for (y = 0 ; y < *height ; y++) { |
196 | 196 | unsigned char *s = png_image[y]; |
197 | | for (x = 0 ; x < info_ptr->width ; x++) { |
| 197 | for (x = 0 ; x < *width ; x++) { |
198 | 198 | |
199 | | switch (info_ptr->color_type) { |
| 199 | switch (png_get_color_type(png_ptr, info_ptr)) { |
200 | 200 | case PNG_COLOR_TYPE_RGB: |
201 | 201 | p[0] = s[0]; |
202 | 202 | p[1] = s[1]; |
… |
… |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | | for (y = 0 ; y < info_ptr->height ; y++) |
| 220 | for (y = 0 ; y < *height ; y++) |
221 | 221 | free (png_image[y]); |
222 | 222 | free (png_image); |
223 | 223 | png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL); |