This patch makes OptiPNG build (and work) with libpng 1.5.
There is a slight runtime misbehavior which I believe is caused by a bug in libpng rather than my patch:
[arklinux@matterhorn tmp]$ optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 test.png
OptiPNG 0.6.4: Advanced PNG optimizer.
Copyright (C) 2001-2010 Cosmin Truta.
** Processing: test.png
Warning: Interlace handling should be turned on when using png_read_image
926x902 pixels, 4x8 bits/pixel, RGB+alpha
Recoverable errors found in input. Rerun OptiPNG with -fix enabled.
Error: Previous error(s) not fixed
Specifying -fix makes OptiPNG work (even though it shouldn't be necessary, the file is ok).
Unless I'm overlooking something, the warning is erroneously generated by libpng for non-interlaced PNG files - the warning is generated by png_read_image() if(!(png_ptr->transformations & PNG_INTERLACE)), but png_set_interlace_handling does png_ptr->transformations |= PNG_INTERLACE only if png_ptr->interlaced is set.