OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 format = Texture::XRGB8; | 192 format = Texture::XRGB8; |
193 // Add alpha byte after each RGB triplet | 193 // Add alpha byte after each RGB triplet |
194 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); | 194 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); |
195 } | 195 } |
196 png_set_bgr(png_ptr); | 196 png_set_bgr(png_ptr); |
197 dst_components = 4; | 197 dst_components = 4; |
198 | 198 |
199 // Turn on interlace handling. REQURIED if you are not using | 199 // Turn on interlace handling. REQURIED if you are not using |
200 // png_read_image(). To see how to handle interlacing passes, | 200 // png_read_image(). To see how to handle interlacing passes, |
201 // see the png_read_row() method below: | 201 // see the png_read_row() method below: |
202 int png_number_passes = png_set_interlace_handling(png_ptr); | 202 png_set_interlace_handling(png_ptr); |
203 | 203 |
204 // Execute any setup steps for each Transform, i.e. to gamma correct and | 204 // Execute any setup steps for each Transform, i.e. to gamma correct and |
205 // add the background to the palette and update info structure. REQUIRED | 205 // add the background to the palette and update info structure. REQUIRED |
206 // if you are expecting libpng to update the palette for you (ie you | 206 // if you are expecting libpng to update the palette for you (ie you |
207 // selected such a transform above). | 207 // selected such a transform above). |
208 png_read_update_info(png_ptr, info_ptr); | 208 png_read_update_info(png_ptr, info_ptr); |
209 | 209 |
210 // Allocate storage for the pixels. | 210 // Allocate storage for the pixels. |
211 unsigned int num_mipmaps = | 211 unsigned int num_mipmaps = |
212 generate_mipmaps ? GetMipMapCount(png_width, png_height) : 1; | 212 generate_mipmaps ? GetMipMapCount(png_width, png_height) : 1; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 png_infop info_ptr = png_create_info_struct(png_ptr); | 293 png_infop info_ptr = png_create_info_struct(png_ptr); |
294 if (!info_ptr) { | 294 if (!info_ptr) { |
295 DLOG(ERROR) << "Could not create PNG info structure."; | 295 DLOG(ERROR) << "Could not create PNG info structure."; |
296 png_destroy_write_struct(&png_ptr, png_infopp_NULL); | 296 png_destroy_write_struct(&png_ptr, png_infopp_NULL); |
297 fclose(fp); | 297 fclose(fp); |
298 return false; | 298 return false; |
299 } | 299 } |
300 | 300 |
301 scoped_array<png_bytep> row_pointers(new png_bytep[height_]); | 301 scoped_array<png_bytep> row_pointers(new png_bytep[height_]); |
302 for (unsigned int i = 0; i < height_; ++i) { | 302 for (int i = 0; i < height_; ++i) { |
303 row_pointers[height_-1-i] = image_data_.get() + i * width_ * 4; | 303 row_pointers[height_-1-i] = image_data_.get() + i * width_ * 4; |
304 } | 304 } |
305 | 305 |
306 if (setjmp(png_jmpbuf(png_ptr))) { | 306 if (setjmp(png_jmpbuf(png_ptr))) { |
307 // If we get here, we had a problem reading the file. | 307 // If we get here, we had a problem reading the file. |
308 DLOG(ERROR) << "Error while writing file " << filename << "."; | 308 DLOG(ERROR) << "Error while writing file " << filename << "."; |
309 png_destroy_write_struct(&png_ptr, &info_ptr); | 309 png_destroy_write_struct(&png_ptr, &info_ptr); |
310 fclose(fp); | 310 fclose(fp); |
311 return false; | 311 return false; |
312 } | 312 } |
313 | 313 |
314 png_init_io(png_ptr, fp); | 314 png_init_io(png_ptr, fp); |
315 | 315 |
316 png_set_IHDR(png_ptr, info_ptr, width_, height_, 8, | 316 png_set_IHDR(png_ptr, info_ptr, width_, height_, 8, |
317 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, | 317 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
318 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 318 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
319 png_set_bgr(png_ptr); | 319 png_set_bgr(png_ptr); |
320 png_set_rows(png_ptr, info_ptr, row_pointers.get()); | 320 png_set_rows(png_ptr, info_ptr, row_pointers.get()); |
321 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, png_voidp_NULL); | 321 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, png_voidp_NULL); |
322 | 322 |
323 png_destroy_write_struct(&png_ptr, &info_ptr); | 323 png_destroy_write_struct(&png_ptr, &info_ptr); |
324 fclose(fp); | 324 fclose(fp); |
325 return true; | 325 return true; |
326 } | 326 } |
327 | 327 |
328 } // namespace o3d | 328 } // namespace o3d |
OLD | NEW |