Extra, human-relevant, colour spaces derived from RGB.
MIT License
Extra, human-relevant, colour spaces derived from RGB
This package extends the standard Python library's colorsys
module
with a few additional, useful, colour spaces. The models of colour
provided here are simple, but relevant to human vision and the perceived
lightness of different colour hues.
YUV has a perceptually relevant lightness term. It can preserve absolute chroma when manipulating luma.
HCY is intuitive to use, and its lightness term is the same as YUV's. It's particularly useful when manipulating colours to meet WCAG 2.2 or draft 3.0 WCAG contrast criteria.
GLHS is a generalization of the cylindrical coordinate spaces
provided in colorsysx
and colorsys
. It can be parameterised to
provide any of the other similar models.
ColorsysX is library code, with no bundled scripts. Other projects are free to depend on it in the normal way.
To install the latest version from PyPI, for example into your current Python virtual environment:
pip install colorsysx
from colorsysx import rgb_to_hcy, hcy_to_rgb
h, c, y = rgb_to_hcy(0.5, 0.7, 0.93)
r, g, b = hcy_to_rgb(h, c, y)
The conversion functions are named like the builtin colorsys
module's
functions, and share a very similar interface. For each colour system
ABC, this package provides two functions:
rgb_to_abc() a, b, c
abc_to_rgb() r, g, b
All inputs and outputs are tuples of 3 floats in the range [0.0, 1.0].
Unlike colorsysx
, the functions accept optional weighting parameters,
which can be used to tune the colour model being used.
ColorsysX is developed on GitHub as achadwick/python-colorsysx. Please report bugs via the issue tracker there.
ColorsysX uses nox to run tests and manage utility Python environments. Examples:
# Run all standard tests on all available Pythons
nox
# Run the main version of Python interactively in a venv with
# colorsysx available.
nox -s repl
The build system is flit, and the project is PEP 621 and PEP 517 compliant.