<div dir="ltr">Cornelius,<div><br></div><div>Thank you.</div><div><br></div><div>Can you submit that as a PR on github?  That is how we do our code review now.</div><div><br></div><div>Tom</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 11, 2015 at 1:50 PM Cornelius Weig <<a href="mailto:cornelius.weig@gmx.de">cornelius.weig@gmx.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
 I have implemented PNG stream prediction for the pdf backend. It was<br>
marked as a TODO.<br>
<br>
Cheers,<br>
  Cornelius<br>
<br>
-------------------<br>
<br>
Details:<br>
At first I thought about linking to libpng, but I couldn't find an API<br>
for raw encoding of single lines as PDF needs it. Therefore, I<br>
implemented the code in plain python (it makes heavy use of numpy to do<br>
the number crunching). It needs testing with python 3 however...<br>
<br>
I took care of five different encoding modes as specified by RFC 2083:<br>
10 - noop<br>
11 - Sub encoding<br>
12 - Up encoding<br>
13 - Avg encoding<br>
14 - Paeth encoding<br>
15 - Optimal encoding (*)<br>
<br>
(*) For '15', I considered only modes 10-13, because my Paeth implementation<br>
is not very fast (nor very clean).<br>
<br>
The prediction is done by a static method in the 'Stream' class, which<br>
is called from writeImages. My heuristics have shown (and<br>
<a href="http://www.libpng.org/pub/png/book/chapter09.html" rel="noreferrer" target="_blank">http://www.libpng.org/pub/png/book/chapter09.html</a> also mentions it) that<br>
gray-scale data does usually not benefit from stream prediction.<br>
Therefore, the prediction is only applied to color images.<br>
<br>
Finally, I think that the encoding mode is something to be made<br>
adjustable by the user, so that a rcParams['pdf.prediction'] (or<br>
'filter' or 'pngcompression') setting should be justified. I didn't<br>
touch anything of this, because that's up to you devs.<br>
<br>
<br>
_______________________________________________<br>
Matplotlib-devel mailing list<br>
<a href="mailto:Matplotlib-devel@python.org" target="_blank">Matplotlib-devel@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-devel" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-devel</a><br>
</blockquote></div>