inViewingConditions method

Hct inViewingConditions(
  1. ViewingConditions vc
)

Translate a color into different ViewingConditions.

Colors change appearance. They look different with lights on versus off, the same color, as in hex code, on white looks different when on black. This is called color relativity, most famously explicated by Josef Albers in Interaction of Color.

In color science, color appearance models can account for this and calculate the appearance of a color in different settings. HCT is based on CAM16, a color appearance model, and uses it to make these calculations.

See ViewingConditions.make for parameters affecting color appearance.

Implementation

Hct inViewingConditions(ViewingConditions vc) {
  // 1. Use CAM16 to find XYZ coordinates of color in specified VC.
  final cam16 = Cam16.fromInt(toInt());
  final viewedInVc = cam16.xyzInViewingConditions(vc);

  // 2. Create CAM16 of those XYZ coordinates in default VC.
  final recastInVc = Cam16.fromXyzInViewingConditions(
    viewedInVc[0],
    viewedInVc[1],
    viewedInVc[2],
    ViewingConditions.make(),
  );

  // 3. Create HCT from:
  // - CAM16 using default VC with XYZ coordinates in specified VC.
  // - L* converted from Y in XYZ coordinates in specified VC.
  final recastHct = Hct.from(
    recastInVc.hue,
    recastInVc.chroma,
    ColorUtils.lstarFromY(viewedInVc[1]),
  );
  return recastHct;
}