The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly. |
Home Writing PNG Images writepng_encode_image() | |
writepng_encode_image()What happens next depends on whether the user requested that the PNG image be interlaced. If so, there's really no good way to read and write the image progressively, so we simply allocate a buffer large enough for the whole thing and read it in. We also allocate and initialize a row_pointers array, where each element points at the beginning of a row of pixels, and then call writepng_encode_image(): int writepng_encode_image(mainprog_info *mainprog_ptr) { png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; if (setjmp(mainprog_ptr->jmpbuf)) { png_destroy_write_struct(&png_ptr, &info_ptr); mainprog_ptr->png_ptr = NULL; mainprog_ptr->info_ptr = NULL; return 2; } png_write_image(png_ptr, mainprog_ptr->row_pointers); png_write_end(png_ptr, NULL); return 0; } One can see that the actual process of writing the image data is quite
simple. We first restore our two struct pointers; we could simply use them
as is, but that would require some ugly typecasts. Next we set up the usual
PNG error-handling code, followed by the call that really matters:
|
|
Home Writing PNG Images writepng_encode_image() |