pavelfatin / typometer

Text / code editor typing latency analyzer
https://pavelfatin.com/typometer
Apache License 2.0
372 stars 12 forks source link

Overly sensitive to minor color variations #9

Open gnachman opened 4 years ago

gnachman commented 4 years ago

macOS dithers solid colors in recent OS versions. This is noticeable on 10.15 with a macbook pro in direct sunlight, for example. Furthermore, antialiasing artifacts due to unaligned drawing on a retina display can cause fuzzy edges. Because typometer checks only for exact color equivalence, it often gets tripped up.

I was unable to use it at all on macOS until I made the following changes:

  1. Change BenchmarkImpl.typeSync to consider colors differing by less than 1% to be equal (by summing the difference of the red, green, and blue channels)
  2. Change MetricsDetector.uniformLengthFrom to ignore the 2 least significant bits of each color channel.
alysbrooks commented 4 years ago

@gnachman Do you have a copy of this version somewhere? It's not a big deal to make these changes myself but if you made them available it might save me half an hour. Thanks!

gnachman commented 4 years ago

In BenchmarkImpl.typeSync(), replace if (!accessor.getPixelColor((int) round(x), y).equals(metrics.getBackground())) with an approximate equality test (I summed the error in r, g, and b and considered it equal if less than 6).

In MetricsDetector.uniformLengthFrom, replace image.getRGB(x, point.y) != color with an approximation test. I just counted the number of bits that differed, but that's mostly because I was too lazy to figure out how the RGB value was represented in an int :)

alysbrooks commented 4 years ago

Thanks, @gnachman!

frarees commented 4 years ago

Check out my fork for an implementation (specifically https://github.com/frarees/typometer/commit/0bb28184b5fa324378ce681437fe3d070a29d2e2).