Skip to main content

Extra, human-relevant, colour spaces derived from RGB.

Project description

PyPI GitHub GitHub issues GitHub Workflow Status

colorsysX

🌈👁️ 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.

Colour models

  • YUV (specifically, YPbPr): a luma and colour difference model.
  • HCY: a cylindrical hue, relative chroma, and luma model.
  • GLHS: a generalized lightness/hue/saturation model.

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.

For developers

ColorsysX is library code, with no bundled scripts. Other projects are free to depend on it in the normal way.

Installation

To install the latest version from PyPI, for example into your current Python virtual environment:

pip install colorsysx

Interface conventions

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.

Testing and developing

ColorsysX is developed on GitHub as achadwick/python-colorsysx. Please report bugs via the issue tracker there.

ColorsysX uses tox to run tests and manage utility Python environments. Examples:

# Run all standard tests in parallel on all available Pythons
tox -p

# Run the system version of Python interactively in a venv with
# colorsysx available.
tox -e repl

The build system is flit, and the project is PEP 621 and PEP 517 compliant.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colorsysx-1.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

colorsysx-1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file colorsysx-1.1.tar.gz.

File metadata

  • Download URL: colorsysx-1.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for colorsysx-1.1.tar.gz
Algorithm Hash digest
SHA256 37e2c9c9ec5b7ba5053d081940156956812eb1ab7804ab24b4df353be805a5c5
MD5 9ac8d828167f081f21ea4267db4de8a4
BLAKE2b-256 d84afaf84a464dc4fa016f3cfee37451b220209c44c889e5234d56728b6a7d6c

See more details on using hashes here.

File details

Details for the file colorsysx-1.1-py3-none-any.whl.

File metadata

  • Download URL: colorsysx-1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for colorsysx-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a48380679463f1292261d42f0e022687112ee6fa0cebe5cbc464dad7385ad3a
MD5 275d7a6965888b855bf4324e851bf148
BLAKE2b-256 a109cdffaf18af5a8e81dfb0e1ebf537720059c25b520727e4300b48a82a4b88

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page