robertodealmeida/pydap.responses.wms — pull request #2 by jblarsen (2014-03-19 21:11:21+00:00)
Title: Paletted PNG output

Hi Rob,

I have made an option to convert the resulting PNG to a paletted PNG. The conversion is only done when the option is enabled and when the number of colors in the plot is <= 256. I have tested the conversion against the coads.nc example file (and our own files) using this script:

http://pastebin.com/ZnXSSaJw

You should be able to run this yourself. Just run the script from a directory where you have coads.nc (the script will store some pngs in this directory). On our server I get the following results:

$ python test_paletted_png.py
Timing png generation. Please be patient...
Average cost of paletting one png: 23.85 milliseconds
Total size reduced from 102688 to 58788 (42.8 %)

It depends on the specific use case whether such a conversion makes sense (whether the extra time it takes to do the paletting outweighs the time saved transmitting the image - taking into account that the same image can be cached and sent to multiple users). For our purposes we definitely expect it to be worth the extra CPU time. Especially for quiver plots (which I have an unfinished test implementation of - I will of course submit it so that you can decide whether you want it as well when it is more polished). But your mileage might vary (which is also why it should IMO be optional).

One assumption of this conversion is that we only have GIF-style transparency. One pixel is either fully transparent or fully opaque. But that is of course also the case for the plots that are produced.

Best regards,
Jesper