lcdGhostColor function

int lcdGhostColor(
  1. int panel,
  2. int segment, {
  3. double ratio = 1.15,
})

The ghost-segment colour for an LCD panel lit by segment: the panel moved toward the segment colour in OKLab until it reaches ratio against the panel (default 1.15, comfortably inside lcdGhostMaxRatio). Pure and bit-exact (OKLab lerp + bisection).

Implementation

int lcdGhostColor(int panel, int segment, {double ratio = 1.15}) {
  final p = panel | 0xFF000000;
  final s = segment | 0xFF000000;
  if (contrastRatio(s, p) <= ratio) return s;
  var lo = 0.0;
  var hi = 1.0;
  var best = p;
  for (var i = 0; i < 24; i++) {
    final mid = (lo + hi) / 2;
    final c = lerpArgbOklab(p, s, mid);
    if (contrastRatio(c, p) <= ratio) {
      best = c;
      lo = mid;
    } else {
      hi = mid;
    }
  }
  return best;
}