lightweight python implementation of Björn Ottosson's oklab colour space
Project description
lightweight python implementation of Björn Ottosson's oklab/oklch colour space.
i like oklab but there isnt a straightforward python package for working with it. so i made it.
install
install it from PyPI:
python -m pip install oklab
how to use?
import oklab
oklab.lch_to_hex((0.75, 0.125, 310.0))
# '#c697e9'
oklab.hex_to_lch('#ff0000')
# (0.6279536182521783, 0.25762679148825324, 29.227131291763712)
oklab.lab_to_xyz((1.0, 0.0, 0.0))
# (0.9504559270516719, 0.9999999999999998, 1.0890577507598782)
features
- 6 formats:
rgb,hex,lab,lch,xyz,lms - 30 conversion functions (complete graph)
- numerical accuracy + roundtrip precision
- source correctness
- zero dependencies
- clamping (in native oklab space via chroma reduction)
- configurable RGB primaries (P3, rec2020, …)
- [❌] CMYK support (scope creep)
sources
- function names inspired by hsluv
- outputs sanity-checked against oklch.com and wikipedia
M0sourced from Björn's CSSWG commentM2_invsourced from Björn's blogpostXYZ_TO_RGB,RGB_TO_XYZsourced from colour scienceM1,M1_inv,M2,RGB_TO_LMS,LMS_TO_RGBderived numerically using numpy- tests sourced from Björn's blogpost
conversion graph
here is a graph of the atomic conversions:
- lab: oklab cartesian space
- lch: oklch cylindrical space
- lms: intermediate lms-like space
- xyz: CIEXYZ space
- rgb: sRGB
- hex: 8-bit sRGB in hexadecimal
all composed conversions are derived via shortest path in this graph
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oklab-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: oklab-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4af3b7c2194646b526ba1ae6427f0582b6c7b19222770577a057d3acf92cd331
|
|
| MD5 |
f875fb3ba625a0ff03188fee150f4a59
|
|
| BLAKE2b-256 |
1df33cbeef1753cd0d8160619f47ea3839d5a51bb2e07f3ef1166fa519ff5035
|