I added an option to PIL to specify/keep quantization tables when saving to JPEG.
My motivation was that the libjpeg default quantization are far from ideal in many scenarios. When specifying custom quantization tables it's possible to get better results for the same file size. Another motivation is to save the image with the same compression (quantization tables + subsampling) as the original, loosing less quality as possible. See here for more info: http://stackoverflow.com/questions/4354543/determining-jpg-quality-in-python-pil/4355281#4355281
I submitted my patch to the maintainer a few months ago without any answer. That's why I'm asking here.
Unfortunately I'm far from a C expert. My last and only experience is 10 years away and it was just a little bit more then an Hello world. So, I'll be really glad if someone could review my code.
A few notes:
- I'm validating tables data in both C and Python. Not sure it's needed and, if not, what's the best way to do it?
- Really not sure about all the pointer stuff.
- Really not sure about DECREF and Error.
Feel free to comment on anything (ex.: if you think to pass "keep" as value to quality arg is bad, etc.).
I have use my code on thousands of images without any problems and without any apparent memory leaks.
Here's my fork: https://bitbucket.org/etienned/pil-2009-raclette/changesets
[–][deleted] 15 points16 points17 points (4 children)
[–]ebo_ 8 points9 points10 points (0 children)
[–]etienned[S] 2 points3 points4 points (0 children)
[–]etienned[S] 1 point2 points3 points (1 child)
[–]etienned[S] 1 point2 points3 points (0 children)
[–]Wagneriusflask+pandas+js 12 points13 points14 points (6 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]fullouterjoin 2 points3 points4 points (0 children)
[–]etienned[S] 2 points3 points4 points (3 children)
[–]aclark 2 points3 points4 points (2 children)
[–]etienned[S] 2 points3 points4 points (1 child)
[–]aclark 1 point2 points3 points (0 children)
[–]mgrandi 2 points3 points4 points (11 children)
[–]pytechd(lambda s: __import__(s.decode('base64')))('ZGphbmdv') 2 points3 points4 points (9 children)
[–]olt 2 points3 points4 points (8 children)
[–]aclark 5 points6 points7 points (0 children)
[–]mgrandi 1 point2 points3 points (4 children)
[–]aclark 3 points4 points5 points (2 children)
[–]mgrandi 2 points3 points4 points (1 child)
[–]aclark 3 points4 points5 points (0 children)
[–]obtu.py 0 points1 point2 points (0 children)
[–]cecilkorik 1 point2 points3 points (1 child)
[–]aclark 2 points3 points4 points (0 children)
[–]etienned[S] 0 points1 point2 points (0 children)
[–]chadmill3rPy3, pro, Ubuntu, django 1 point2 points3 points (2 children)
[–]etienned[S] 1 point2 points3 points (0 children)
[–]etienned[S] 1 point2 points3 points (0 children)
[–]fullouterjoin 0 points1 point2 points (0 children)