mozilla / mozjpeg

Improved JPEG encoder.
Other
5.45k stars 414 forks source link

Fine-tune quantization table coefficeints from DCT data #150

Open kornelski opened 9 years ago

kornelski commented 9 years ago

Scaling of quantization tables assumes that smaller divisors are always better, but that's not always true due to rounding errors.

An especially obvious case is when DC is quantized in a way that prevents it from hitting maximum value (i.e. 128 isn't evenly divisible by the DC coefficient):

quality = 9

gray background

quality = 6

white background

e.g. imagine a source image posterized to 16 levels. For such image a DC coefficient = 16 is ideal, and 8 < DC < 16 are all worse, even though they're used at higher qualities.

I think quantization tables can be made a little better:

  1. Gather unquantized DCT coefficients for the entire image
  2. For each quantization table coefficient check whether higher quantization divisor gives smaller quantization error
JosePineiro commented 7 years ago

Is the same optimization that https://github.com/mozilla/mozjpeg/issues/81 And similar to https://github.com/mozilla/mozjpeg/issues/182

jrmsmith commented 7 years ago

In my opinion, this is a waste of time. A time that would be better spent implementing #182 and #223 -- which provide the best quantization table and the best DCT coefficients.