ciromattia/kcc — pull request #26 by devernay (2013-03-05 17:03:37+00:00)
Title: kcc: PNG, gamma, nosplitrotate

my first github pull request. The following is copied from the emails I sent you:

I noticed that the images looked too bright on the kindle. After checking with a gamma calibration image (included in the attached zip), I noticed that the kindle display response was *linear*, whereas all PNGs and JPEGs are encoded assuming the display gamma is 2.2 (this is the so-called sRGB monitor profile). This was also noticed by others, see:
http://kindleworld.blogspot.fr/2011/04/kindle-pictures-feature-2-free-tools.html?showComment=1304191009097#c5144891602627321184

Another small problem with KCC is that it compresses *quantized* images using JPEG, which is nonsense: quantization uses the Floyd-Steinberg dithering algorithm which basically adds noise, and JPEG compresses this noise by creating blocky artifacts (look closely in the attached examples). It was also saving images as JPEG without changing the extension (which means that the epub may contain JPEG files ending with ".png" - these epubs don't work on some readers)

Normally, quantized images should be saved in PNG, non-quantized images in JPEG (in fact, KCC should offer the option to quantize or not, isn't it?). Yes this makes bigger files, but that's the best possible quality.

Did you ever try to convert a cbz with almost-square pages, and end up with half the pages either rotated or split? Do you have a cure for that? I also added an option and a checkbox to handle this.

To go further:
- I think gamma should be part of the profile (together with the palette and resolution), since newer devices may implement sRGB color profile (in which case gamma correction should be set to 1.0). The Kindle fire probably has a display gamma of 2.2, so gamma correction should be set to 1.0 for that device if/when it appears in KCC
- May be there should be a "Apply dithering" option/checkbox: when checked, the colors are quantized and images are saved as PNG, when not the colors should not be quantized and images should be saved as JPEG