fromJchInViewingConditions method Null safety

Cam16 fromJchInViewingConditions(
  1. double J,
  2. double C,
  3. double h,
  4. ViewingConditions viewingConditions
)

Create a CAM16 color from lightness j, chroma c, and hue h, in viewingConditions.

Implementation

static Cam16 fromJchInViewingConditions(
    double J, double C, double h, ViewingConditions viewingConditions) {
  final Q = (4.0 / viewingConditions.c) *
      math.sqrt(J / 100.0) *
      (viewingConditions.aw + 4.0) *
      (viewingConditions.fLRoot);
  final M = C * viewingConditions.fLRoot;
  final alpha = C / math.sqrt(J / 100.0);
  final s = 50.0 *
      math.sqrt((alpha * viewingConditions.c) / (viewingConditions.aw + 4.0));

  final hueRadians = h * math.pi / 180.0;
  final jstar = (1.0 + 100.0 * 0.007) * J / (1.0 + 0.007 * J);
  final mstar = 1.0 / 0.0228 * math.log(1.0 + 0.0228 * M);
  final astar = mstar * math.cos(hueRadians);
  final bstar = mstar * math.sin(hueRadians);
  return Cam16(h, C, J, Q, M, s, jstar, astar, bstar);
}