About

The Color Engineering and Illumination Toolbox is a Typescript Library for color calculations. It can be used to write Web Apps or to write a Typescript/Javascript program and run it with (Deno)[https://deno.land].

It is a somewhat special tool, as it uses spectral distributions as the basis for color calculations exclusively: colors are not represented by just three numbers, such as three R, G, and B values, but by an array of spectral power or reflectivity values. This makes color calculations not only more accurate but also allows you to calculate color appearance for specific observers and viewing conditions.

Using spectral distributions instead of just three numbers might be – if you think about it – a bit overwhelming; what if you want to work with color, and have no idea about the spectral distribution of the color you are considering? Luckily, working with color in this library, you don’t need to worry about spectral distributions too much, as the library takes care of these behind the scenes. The library has a large collection of measured and theoretical spectral distributions, which can be directly used in the various algorithms. It also has models to create spectral distributions from basic color values. For example, to get a spectral representation of an sRGB spectral color, it can generate a generic composite spectrum generated from representative red, green, and blue spectral primary spectral distributions.

Here are a couple of examples of scripts, intended to be run using the Deno runtime:

  • Calculate (x,y) chromaticity values for the CIE D65 daylight illuminant, using the CIE 1931 2º standard observer:
// import library and objects, and intialise
import init, { D65, White, Observer, Cie1931} from "https://gerardharbers.com/cie.js";
await init();

// get D65 daylight illuminant and reference white instances.
const d65 = await new D65;
const white = await new White;

// use the CIE1931 color matching functions
const cie1931 = new Cie1931;

//  
const stdObs31 = new Observer(cie1931, d65)
[,x,y] = stdObs31.lxy();

console.log(`D65 CIE 1931 2º chromaticity coordinates: (${x.toFixed(4))},${y.toFixed(4)})`);

Domains