webmproject / sjpeg

SimpleJPEG: simple jpeg encoder
Apache License 2.0
70 stars 12 forks source link

Harmonize the RGB->YUV conversion constants #55

Closed skal65535 closed 6 years ago

skal65535 commented 6 years ago

16x16 blocks and 8x8 were having different constants, rounding was slightly different, etc (mostly for historical reasons).

Now we settle everything for the formulae:

Y = ( 19595 r + 38469 g + 7471 b + HALF) >> FRAC U - 128 = (-11059 r - 21709 g + 32768 b + HALF) >> FRAC V - 128 = ( 32768 r - 27439 g - 5329 * b + HALF) >> FRAC