The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly.



readpng2_end_callback()

Once the last row-callback has been made, the program is basically done. Because of the way the main program's row-display code was written to deal with interlaced images, when the last row of pixels is sent, it is guaranteed to be flushed to the display immediately. Thus, when libpng calls our final callback routine, readpng2_end_callback(), it does nothing more than retrieve the pointer to our mainprog_info struct and call the corresponding mainprog_finish_display() function, which in turn merely sets a ``done'' flag and lets the user know that the image is complete:

static void rpng2_x_finish_display()
{
    rpng2_info.done = TRUE;
    printf("Done.  Press Q, Esc or mouse button 1 to quit.\n");
}

It would also have been reasonable to free both the image_data and bg_data buffers at this point, and a memory-constrained application certainly would do so--or, more likely, it would never have allocated full buffers in the first place, instead handling everything on a per-row basis and calculating the background pattern on the fly. Regardless, I chose to free all front-end buffers in the front-end cleanup routine, which is the last function called before the program exits.




Last Update: 2010-Nov-26