typometer icon indicating copy to clipboard operation
typometer copied to clipboard

Overly sensitive to minor color variations

Open gnachman opened this issue 4 years ago • 4 comments

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.

gnachman avatar Mar 02 '20 08:03 gnachman

@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!

alysbrooks avatar Apr 11 '20 00:04 alysbrooks

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 :)

gnachman avatar Apr 12 '20 03:04 gnachman

Thanks, @gnachman!

alysbrooks avatar Apr 13 '20 15:04 alysbrooks

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

frarees avatar Oct 08 '20 09:10 frarees