jcupitt/libvips — pull request #190 by lovell (2014-10-25 15:37:39+00:00)
Title: Expose ability to control libpng's row filter

Hi John, I've made what I hope is a suitable addition to libvips' saving of PNG format images, exposing libpng's row filter. Disabling the adaptive filter can improve image size, especially for line drawings.

Here are some tests I ran using [50020484-00001.png](https://github.com/lovell/sharp/blob/master/test/fixtures/50020484-00001.png) as the source image. In this example, the difference in output image size between using all filters and no filters is 32%.

```
vipsthumbnail 50020484-00001.png -o test6-all.png[compression=6]
vipsthumbnail 50020484-00001.png -o test6-none.png[compression=6,filter=8]
vipsthumbnail 50020484-00001.png -o test6-sub.png[compression=6,filter=10]
vipsthumbnail 50020484-00001.png -o test6-up.png[compression=6,filter=32]
vipsthumbnail 50020484-00001.png -o test6-avg.png[compression=6,filter=64]
vipsthumbnail 50020484-00001.png -o test6-paeth.png[compression=6,filter=128]

11921 test6-all.png
8071 test6-none.png
11075 test6-sub.png
12786 test6-up.png
12389 test6-avg.png
11989 test6-paeth.png

vipsthumbnail 50020484-00001.png -o test9-all.png[compression=9]
vipsthumbnail 50020484-00001.png -o test9-none.png[compression=9,filter=8]
vipsthumbnail 50020484-00001.png -o test9-sub.png[compression=9,filter=10]
vipsthumbnail 50020484-00001.png -o test9-up.png[compression=9,filter=32]
vipsthumbnail 50020484-00001.png -o test9-avg.png[compression=9,filter=64]
vipsthumbnail 50020484-00001.png -o test9-paeth.png[compression=9,filter=128]

11666 test9-all.png
7903 test9-none.png
10812 test9-sub.png
12517 test9-up.png
12177 test9-avg.png
11746 test9-paeth.png
```

Setting a specific filter rather than relying on adaptive filtering is the basic premise of tools such as _pngcrush_ and _optipng_. The latter provides more information about the filters available in "[2.2 The PNG delta filters](http://optipng.sourceforge.net/pngtech/optipng.html)".

The relevant part of the _libpng_ source is in [png.h](http://sourceforge.net/p/libpng/code/ci/libpng16/tree/png.h#l1589).