[Matplotlib-devel] Fwd: patch for stream prediction in pdf backend

Thomas Caswell tcaswell at gmail.com
Sat Sep 12 20:31:28 CEST 2015


Cornelius,

Thank you.

Can you submit that as a PR on github?  That is how we do our code review
now.

Tom

On Fri, Sep 11, 2015 at 1:50 PM Cornelius Weig <cornelius.weig at gmx.de>
wrote:

> Hi,
>
>  I have implemented PNG stream prediction for the pdf backend. It was
> marked as a TODO.
>
> Cheers,
>   Cornelius
>
> -------------------
>
> Details:
> At first I thought about linking to libpng, but I couldn't find an API
> for raw encoding of single lines as PDF needs it. Therefore, I
> implemented the code in plain python (it makes heavy use of numpy to do
> the number crunching). It needs testing with python 3 however...
>
> I took care of five different encoding modes as specified by RFC 2083:
> 10 - noop
> 11 - Sub encoding
> 12 - Up encoding
> 13 - Avg encoding
> 14 - Paeth encoding
> 15 - Optimal encoding (*)
>
> (*) For '15', I considered only modes 10-13, because my Paeth
> implementation
> is not very fast (nor very clean).
>
> The prediction is done by a static method in the 'Stream' class, which
> is called from writeImages. My heuristics have shown (and
> http://www.libpng.org/pub/png/book/chapter09.html also mentions it) that
> gray-scale data does usually not benefit from stream prediction.
> Therefore, the prediction is only applied to color images.
>
> Finally, I think that the encoding mode is something to be made
> adjustable by the user, so that a rcParams['pdf.prediction'] (or
> 'filter' or 'pngcompression') setting should be justified. I didn't
> touch anything of this, because that's up to you devs.
>
>
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20150912/bff6760c/attachment.html>


More information about the Matplotlib-devel mailing list