deltaE94 function

double deltaE94(
  1. LabColor lab1,
  2. LabColor lab2, [
  3. Weights weights = const Weights()
])

The 1976 definition was extended to address perceptual non-uniformities, while retaining the CIELAB color space, by the introduction of application-specific weights derived from an automotive paint test's tolerance data.

Source: https://en.wikipedia.org/wiki/Color_difference#CIE94

Implementation

double deltaE94(LabColor lab1, LabColor lab2,
    [Weights weights = const Weights()]) {
  double k1, k2;
  if (weights.l == 1) {
    k1 = 0.045;
    k2 = 0.015;
  } else {
    k1 = 0.048;
    k2 = 0.014;
  }
  // Cab
  double c1 = sqrt(pow(lab1.a, 2) + pow(lab1.b, 2)),
      c2 = sqrt(pow(lab2.a, 2) + pow(lab2.b, 2)),
      cab = c1 - c2;
  // L
  double l = (lab1.l - lab2.l) / weights.lightness;
  // a
  double sc = 1 + (k1 * c1), a = cab / (weights.a * sc);
  // b - Top
  double hab =
      sqrt(pow(lab1.a - lab2.a, 2) + pow(lab1.b - lab2.b, 2) - pow(cab, 2));
  // b - Bottom
  double sh = 1 + (k2 * c1), b = hab / sh;

  return sqrt(pow(l, 2) + pow(a, 2) + pow(b, 2));
}