[Image-SIG] New feature added - need code review

Etienne Desautels tiit at sympatico.ca
Tue Nov 8 19:41:15 CET 2011


I added an option 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.

I added a few things to facilitate that. For example you can pass "keep" to the quality arg to keep the same compression quality (it will keep the same quantization table and subsampling). I also added some default quantization tables corresponding to some Photoshop default. So you can pass "web_high" to the quality arg and the image will be save with the same quantization tables and subsambling of what Photoshop will have used for this settings. It's easy to add more presets like that.

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 with more knowledge could review my code.

I tested the code on converting a big batch (~4000) of TIFF to JPEG in to 2 different resolutions and qualities. It works pretty well and my code didn't look to leak any memory. 

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.).

Here's the code: https://bitbucket.org/etienned/pil-2009-raclette


More information about the Image-SIG mailing list