kip

kip

ex_cldr Core Team

Color (github) is a comprehensive color library. Now at version 0.2 but much more developed than the long ago 0.1. In fact I expect to move this to 1.0 release quite quickly since I consider its API stable. Feedback might change that though! :slight_smile:

Features

  • 20+ color space structs including Color.SRGB, Color.AdobeRGB, Color.RGB (linear, in any of 24 named working spaces), Color.Lab, Color.LCHab, Color.Luv, Color.LCHuv, Color.XYZ, Color.XYY, Color.Oklab, Color.Oklch, Color.HSLuv, Color.HPLuv, Color.Hsl, Color.Hsv, Color.CMYK, Color.YCbCr, Color.JzAzBz, Color.ICtCp, Color.IPT, Color.CAM16UCS.

  • Top-level conversion API. Color.new/2 and Color.convert/2,3,4 accept structs, hex strings, CSS named colors, atoms, or bare lists of numbers (with strict per-space validation) and convert between any pair of supported spaces. Color.convert_many/2,3,4 is the batch equivalent. Alpha is preserved across every path.

  • Chromatic adaptation with six methods (:bradford, :xyz_scaling, :von_kries, :sharp, :cmccat2000, :cat02). Color.convert/3,4 auto-adapts the source illuminant when the target requires a fixed reference white.

  • ICC rendering intents wired into Color.convert/3,4: :relative_colorimetric (default), :absolute_colorimetric, :perceptual, :saturation. Optional black-point compensation via bpc: true.

  • ICC matrix-profile reader (Color.ICC.Profile) for ICC v2 / v4 RGB→XYZ profiles, with curv LUT and para parametric tone response curves. Loads profiles like sRGB IEC61966-2.1.icc, Display P3.icc, AdobeRGB1998.icc, and most camera and scanner profiles.

  • Color difference (ΔE). CIE76, CIE94, CIEDE2000 (verified against the Sharma 2005 test data), and CMC l:c.

  • Contrast. WCAG 2.x relative luminance and contrast ratio, APCA W3 0.1.9 (L_c), and pick_contrasting/2 for accessibility helpers.

  • Mixing and gradients. Color.Mix.mix/4 interpolates in any supported space (default Oklab) with CSS Color 4 hue-interpolation modes (:shorter, :longer, :increasing, :decreasing). Color.Mix.gradient/4 produces evenly spaced gradients.

  • Gamut checking and mapping. Color.Gamut.in_gamut?/2 and Color.Gamut.to_gamut/3 with the CSS Color 4 Oklch binary-search algorithm or simple RGB clip.

  • Color harmonies. Complementary, analogous, triadic, tetradic, and split-complementary in any cylindrical space (default Oklch).

  • Color temperature. CCT ↔ chromaticity, Planckian locus and CIE daylight locus.

  • CSS Color Module Level 4 / 5. Full parser and serialiser for hex, named colors, rgb()/rgba(), hsl()/hsla(), hwb(), lab(), lch(), oklab(), oklch(), color(srgb|display-p3|rec2020|…), device-cmyk(), color-mix(), relative color syntax, none keyword, and calc() expressions.

  • ~COLOR sigil for compile-time color literals in any supported space.

  • Spectral pipeline. Color.Spectral and Color.Spectral.Tables provide the CIE 1931 2° and CIE 1964 10° standard observer CMFs, the D65 / D50 / A / E illuminant SPDs, emissive and reflective integration to XYZ, and a metamerism helper.

  • Blend modes. All 16 CSS Compositing Level 1 modes (:multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hue, :saturation, :color, :luminosity, :normal).

  • Transfer functions. sRGB, gamma 2.2 / 1.8, L*, BT.709, BT.2020, PQ (SMPTE ST 2084), HLG, Adobe RGB γ.

A proper Color module has been largely the last sticking point before I could consider moving image to version 1.0. With this update to color I will soon be able to move image to 1.0 too.

https://github.com/elixir-image/color

Showing Posts 1 to 10

mudasobwa

mudasobwa

Creator of Cure

Splendid!

Do you think Color.ANSI (terminal escape sequences) might belong to this library, alongside with Color.CSS or it’s out of scope?

kip

kip OP

ex_cldr Core Team

Oooooo.I like that idea. Something like Color.to_ansi/1 you mean? Parsing the sequences too?

mudasobwa

mudasobwa

Creator of Cure

Yes. Both parsing and producing. I recently published Marcli which is essentially a markdown parser for terminals and I would love to use more sophisticated coloring there.

kip

kip OP

ex_cldr Core Team

Consider it done for the next release. Maybe even today.

15
Post #4
mudasobwa

mudasobwa

Creator of Cure

:heart:

Thank you!

And yes, I’ll never get tired of repeating it, your work on Elixir ecosystem is astonishing, thank you for that.

17
Post #5
kip

kip OP

ex_cldr Core Team

I published Color v0.3.0 with the following additions:

  • Color.ANSI module for parsing and emitting ANSI SGR colour escape sequences. Supports 16-colour, 256-colour indexed, and 24-bit truecolor forms, with perceptual nearest-palette matching (CIEDE2000) when encoding to the 16- or 256-colour palette. Includes parse/1, to_string/2, wrap/3, nearest_256/1, nearest_16/1, palette_256/0, palette_16/0, and a typed Color.ANSI.ParseError exception.

  • Top-level Color.to_hex/1, Color.to_css/1,2, and Color.to_ansi/1,2 convenience functions that accept any input Color.new/1 accepts and raise a typed exception on failure.

And yes, AI can definitely assist in cases like this where the domain is clear, the specification is clear and the expected results are clear.

12
Post #6
mudasobwa

mudasobwa

Creator of Cure

They say, Socrates once argued that Understanding a question is half an answer. Literally nothing has changed with ages.

a-maze-d

a-maze-d

One more thing you might want to consider adding: extra meta-info to colors.

This is maybe special to my use case, but when you try to address an LED strip, you can not only specify an RGB tripplet, but also one or even 2 white LEDs. It would be nice if those could be specified as part of a color.

I know that this a rather special use case and can cause quite a few headaches, but I thought it might still be worth considering.

kip

kip OP

ex_cldr Core Team

You can already specify and illuminate (typically d50 or d65) on a conversion. Can you point me at a reference I can study - happy to look at adding color metadata.

lud

lud

So cool!

Is there a way so safely convert oklch to a displayable srgb color?

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews