photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

use Rec. 709 component coefficients for color distance #42

Closed leeoniya closed 4 years ago

leeoniya commented 4 years ago

hey @photopea

i ran some visual tests and it seems that using the coefficients yields a noticeable improvement in quality across a diverse set of images. for now, i only tested at the default 255 colors setting of http://upng.photopea.com/

UPNG.quantize.dist = function(q,   r,g,b,a) {  var d0=r-q[0], d1=g-q[1], d2=b-q[2], d3=a-q[3];  return d0*d0*.2126+d1*d1*.7152+d2*d2*.0722+d3*d3;  }

the coeffs could probably be re-scaled to avoid one of the mults.

i tested for all the images here: https://github.com/leeoniya/RgbQuant.js/tree/master/demo/img

plus these:

pixel3 nightshot artificial

photopea commented 4 years ago

Hi, thats interesting. Could you maybe show me specific images, side by side, when the better quality is the most visible?

leeoniya commented 4 years ago

it's easier to see the differences by cycling between the 3 versions of each image orig -> weighted -> unweighted. side-by-side will be harder to evaluate. in some cases the improvement is obvious without the original (gradients), but for slight color shifting comparisons you need all 3 overlayed.

i can prepare all 3 sets for you if you'd like later today.

photopea commented 4 years ago

Yes, please, send me an archive with several such images.

leeoniya commented 4 years ago

like #43, you'll probably assert that UPNG's results are better.