npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chromatist

v0.1.0

Published

Color space math, for use in the browser and node-based servers

Downloads

4

Readme

Chromatist JavaScript Library

The Chromatist library aims to pull together implementations of useful color space math, for use both in the browser and in node-based servers. In particular, it currently has implementations of RGB ⇔ CIEXYZ conversions (in chromatist.rgb), CIECAM02 (in chromatist.ciecam), CIELAB (in chromatist.cielab), and HSL and HSV (in chromatist.hsl and chromatist.hsv). There is a simple gamut mapping tool in chromatist.gamut which finds a point of lower chroma but the same hue and lightness within the sRGB gamut using a bisection algorithm. chromatist.matrix3 includes a class for 3 by 3 matrices, and chromatist.mathutils includes a few useful math routines.

This is an early release: the API is likely to change somewhat going forward

Examples

Imagine we want to convert a blue color taken from a website from RGB to CIECAM02 space, take the color with complementary hue, 1.5 times the chroma, and lightness 80, and then convert that result back to RGB.

First we need to set up converters for RGB and CIECAM02. By default, the CIECAM02 converter uses a 'D65' white point, just as sRGB does, so we can leave that parameter implicit.

>>> sRGB = chromatist.rgb.Converter('sRGB')
>>> CIECAM02 = chromatist.ciecam.Converter({
...   adaptive_luminance: 50,
...   discounting: true })

Next we can define our color from hex, and convert it to XYZ space.

>>> rgb_j = chromatist.rgb.from_hex('#14214D')    // a nice dark blue
[ 0.0784, 0.1294, 0.3020 ]
>>> xyz_j = sRGB.to_XYZ(rgb_j)
[ 2.171, 1.772, 7.247 ]

Now we convert our color to CIECAM02 space, and perform our manipulations:

>>> ccam_j = CIECAM02.forward_model(xyz_j)
{ J: 10.51, C: 33.92, h: 262.5, Q: 63.91, M: 29.66, s: 68.12 }
>>> ccam_k = {J: 80, C: ccam_j.C * 1.5, h: ccam_j.h - 180}
{ J: 80, C: 50.88, h: 82.5 }

Finally we can convert our new color back to RGB and print it out in 8-bit hexadecimal:

>>> xyz_k = CIECAM02.reverse_model(ccam_k).XYZ
[ 63.85, 64.63, 18.37 ]
>>> rgb_k = sRGB.from_XYZ(xyz_k)
[ 0.9929, 0.7985, 0.3455 ]
>>> hex_k = chromatist.rgb.to_hex(rgb_k)
'#fdcc58'    // a nice bright yellow

Building and Testing Chromatist

The Chromatist project is buit using Cake. You can install Chromatist's development dependencies from inside the project root with:

npm install

Distributable versions of Chromatist can be built to the /lib directory by running:

cake build

To watch source files and rebuild on change, run:

cake watch_and_build