Metadata-Version: 2.4
Name: python-lcms2
Version: 0.4.7
Summary: Color management for NumPy: LittleCMS2 bindings, color spaces, ICC profile authoring and colormaps
Author-email: Josue N Rivera <josuevaldez1.com@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/wzjoriv/python-lcms2
Project-URL: Repository, https://github.com/wzjoriv/python-lcms2
Project-URL: Bug Tracker, https://github.com/wzjoriv/python-lcms2/issues
Keywords: color management,lcms2,littlecms,icc,color profile,colorspace,oklab,colormap,delta e,ciecam02
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Environment :: WebAssembly :: Emscripten
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: C
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: vendor/Little-CMS/LICENSE
Requires-Dist: numpy>=2.0; implementation_name != "pypy"
Requires-Dist: numpy<2.5,>=2.0; implementation_name == "pypy"
Provides-Extra: plot
Requires-Dist: matplotlib>=3.7; extra == "plot"
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Requires-Dist: pillow>=10; extra == "test"
Requires-Dist: typer>=0.12; extra == "test"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: furo>=2024.1.29; extra == "docs"
Provides-Extra: dev
Requires-Dist: python-lcms2[docs,plot,test]; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: typer>=0.12; extra == "dev"
Requires-Dist: stubpy>=1.1.1; extra == "dev"
Requires-Dist: nbformat>=5; extra == "dev"
Requires-Dist: nbclient>=0.10; extra == "dev"
Requires-Dist: ipykernel>=6; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
Dynamic: license-file

# python-lcms2

Color management for NumPy. Convert images between ICC profiles and color spaces in one call, measure color
differences, build exact ICC profiles from your own NumPy color math, and make perceptually uniform colormaps,
all backed by [LittleCMS 2](https://github.com/mm2/Little-CMS).

[![Tests](https://github.com/wzjoriv/python-lcms2/actions/workflows/ci.yml/badge.svg)](https://github.com/wzjoriv/python-lcms2/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/python-lcms2)](https://pypi.org/project/python-lcms2/)
[![Python](https://img.shields.io/pypi/pyversions/python-lcms2)](https://pypi.org/project/python-lcms2/)
[![Free-threaded](https://img.shields.io/badge/free--threaded-3.14t%20%7C%203.15t-blue)](https://pypi.org/project/python-lcms2/#files)
[![PyPy](https://img.shields.io/badge/PyPy-3.11-blue)](https://pypi.org/project/python-lcms2/#files)
[![Pyodide](https://img.shields.io/badge/Pyodide-3.12%20%7C%203.13%20%7C%203.14-blue)](https://pypi.org/project/python-lcms2/#files)
[![LittleCMS 2.20](https://img.shields.io/badge/LittleCMS-2.20-blue)](https://github.com/mm2/Little-CMS)
[![Linux · Windows · macOS](https://img.shields.io/badge/OS-Linux%20%C2%B7%20Windows%20%C2%B7%20macOS-blue)](https://pypi.org/project/python-lcms2/#files)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/wzjoriv/python-lcms2/blob/main/LICENSE)
[![Documentation](https://img.shields.io/badge/docs-wzjoriv.github.io%2Fpython--lcms2-blue)](https://wzjoriv.github.io/python-lcms2)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

## Features

| Feature | What you get |
|---|---|
| One-call conversion | `lcms2.convert(img, "sRGB", "Display P3")`: pixel formats come from the array's dtype and shape. |
| Profiles | 24 built-ins (sRGB, Display P3, Adobe RGB, ProPhoto, Rec.2020, Lab, XYZ, …), ICC files, bytes; read and edit header, text and tags. |
| Transforms | Rendering intents, black-point compensation, soft proofing with gamut check, multi-profile chains, device links. |
| Fast and safe | The GIL is released during transforms; any contiguity or stride; alpha channels carried through. |
| Color spaces | OKLab, OKLCh, CIE LCh, HSV, HWB, Display P3, Rec.2100 PQ/HLG, … as NumPy functions, mixed freely with ICC profiles. |
| ICC authoring | `lcms2.Profile(my_space)` traces your NumPy `to_xyz`/`from_xyz` into an exact ICC v4/v5 profile. |
| Colorimetry | ΔE 76/94/2000/CMC/BFD, CIECAM02, white point ⇄ color temperature, chromatic adaptation. |
| Tone curves | Gamma, parametric and tabulated curves; evaluate, invert, join, estimate gamma. |
| Colormaps | Perceptually uniform colormaps in OKLab, gamut-mapped, color-vision-deficiency simulation, matplotlib export. |
| Measurement data | Read and write CGATS / IT8 files. |

Wheels for Windows, Linux and macOS (x86-64 and ARM64) on Python 3.10 and later, including free-threaded 3.14t and 3.15t, and PyPy 3.11; Pyodide wheels on PyPI. NumPy is the only dependency.

## Install

```bash
pip install python-lcms2
pip install "python-lcms2[plot]"      # + matplotlib for colormap export
```

## Use

```python
import numpy as np
import lcms2

img = np.asarray(...)                                  # (H, W, 3) uint8, e.g. from Pillow or OpenCV

p3  = lcms2.convert(img, "sRGB", "Display P3")         # uint8 in, uint8 out
lab = lcms2.Profile("sRGB").transform(img, "Lab")      # float64 L*a*b*

lcms2.convert([255, 0, 0], "sRGB", "Lab", intent="relative")
# array([54.29, 80.81, 69.89])
lcms2.convert([255, 0, 0], "sRGB", "oklab")
# array([0.6279, 0.2249, 0.1258])
```

Reuse a `Transform` when converting many images; formats are resolved per input and cached. `press.icc` stands
for any CMYK profile, e.g. from your printer or from [ECI](https://www.eci.org/en/downloads):

```python
to_cmyk = lcms2.Transform("sRGB", lcms2.Profile("press.icc"), intent="relative", bpc=True)
cmyk = to_cmyk(img)                                    # (H, W, 4) uint8
```

### Profiles

```python
srgb = lcms2.Profile("sRGB")                  # built-in (case-insensitive: "display p3", "adobe rgb", …)
cmyk = lcms2.Profile("press.icc")             # a file
web  = lcms2.Profile.from_bytes(icc_bytes)    # bytes, e.g. embedded in an image

cmyk                                          # <Profile 'Fogra27L CMYK Coated Press' CMYK output v2.2>
cmyk.color_space, cmyk.device_class, cmyk.tags
cmyk.description = "Press proof"
cmyk.save("press-v2.icc")
```

### Soft proofing

```python
proof = lcms2.Transform(srgb, srgb, proof=cmyk, gamut_check=True)
proof(img)                                    # how img prints; out-of-gamut pixels marked gray
```

### Your own color space, as an ICC profile

```python
from lcms2.spaces import ColorSpace

M = np.array([[0.4360747, 0.3850649, 0.1430804],   # sRGB primaries → XYZ (D50)
              [0.2225045, 0.7168786, 0.0606169],
              [0.0139322, 0.0971045, 0.7141733]])
M_inv = np.linalg.inv(M)

class Gamma18(ColorSpace):
    n_channels = 3
    def to_xyz(self, rgb):
        return np.asarray(rgb) ** 1.8 @ M.T
    def from_xyz(self, xyz):
        return np.clip(np.asarray(xyz) @ M_inv.T, 0, None) ** (1 / 1.8)

profile = lcms2.Profile(Gamma18())            # exact matrix/TRC profile, usable in any CMS
profile.save("gamma18.icc")
lcms2.convert(img, profile, "sRGB")
```

Built-in analytic spaces (`lcms2.spaces.oklab`, `oklch`, `hsv`, `display_p3`, `rec2100_pq`, …) work the same
way: `lcms2.spaces.oklab.profile` is an ICC profile of OKLab.

### Color differences

```python
lcms2.delta_e(lab1, lab2)                     # CIEDE2000, vectorized over (..., 3)
lcms2.delta_e(lab1, lab2, method="cmc", l=2, c=1)
```

### Colormaps

```python
import matplotlib.pyplot as plt

cm = lcms2.Colormap.from_colors(["#0b1a3a", "#f08a24", "#fff6d5"])   # interpolated in OKLab
cm = lcms2.Colormap.get("glacier")            # built-ins: lcms2.colormap.list()

values = np.linspace(0, 1, 256)
rgb = cm(values)                              # (256, 3) floats; bytes=True for uint8
cm.is_lightness_monotonic(), cm.uniformity()
cm.simulate("deuteranopia")                   # color-vision-deficiency preview
plt.imshow(np.random.rand(64, 64), cmap=cm.to_matplotlib())
```

## Examples

[`examples/`](https://github.com/wzjoriv/python-lcms2/tree/main/examples) is an 11-step learning path, from one-call conversions to profiles, transforms, soft proofing, color spaces, ICC authoring, colorimetry, tone curves, colormaps, CGATS files and device links. Each step is a runnable script with a Jupyter notebook beside it that shows the results (see its [README](https://github.com/wzjoriv/python-lcms2/blob/main/examples/README.md)). All figures below are drawn by the examples.

| | | |
|:---:|:---:|:---:|
| [![Soft proof and out-of-gamut pixels](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/soft_proofing.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/04_soft_proofing_and_gamut.ipynb)<br>[Soft proof and out-of-gamut pixels](https://github.com/wzjoriv/python-lcms2/blob/main/examples/04_soft_proofing_and_gamut.ipynb) | [![Gradients mixed in sRGB vs OKLab](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/gradients.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/05_color_spaces.ipynb)<br>[Gradients mixed in sRGB vs OKLab](https://github.com/wzjoriv/python-lcms2/blob/main/examples/05_color_spaces.ipynb) | [![CIEDE2000 heatmap](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/delta_e.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/07_colorimetry.ipynb)<br>[CIEDE2000 heatmap](https://github.com/wzjoriv/python-lcms2/blob/main/examples/07_colorimetry.ipynb) |
| [![Tone curves](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/tone_curves.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/08_tone_curves.ipynb)<br>[Tone curves](https://github.com/wzjoriv/python-lcms2/blob/main/examples/08_tone_curves.ipynb) | [![Built-in perceptual colormaps](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/colormaps.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/09_colormaps.ipynb)<br>[Built-in perceptual colormaps](https://github.com/wzjoriv/python-lcms2/blob/main/examples/09_colormaps.ipynb) | [![Color-vision-deficiency preview](https://raw.githubusercontent.com/wzjoriv/python-lcms2/main/docs/_static/examples/color_blindness.png)](https://github.com/wzjoriv/python-lcms2/blob/main/examples/09_colormaps.ipynb)<br>[Color-vision-deficiency preview](https://github.com/wzjoriv/python-lcms2/blob/main/examples/09_colormaps.ipynb) |

## Documentation

- [Installation](https://wzjoriv.github.io/python-lcms2/stable/start/installation.html) and [quickstart](https://wzjoriv.github.io/python-lcms2/stable/start/quickstart.html)
- Guides: [profiles](https://wzjoriv.github.io/python-lcms2/stable/guides/profiles.html), [transforms and proofing](https://wzjoriv.github.io/python-lcms2/stable/guides/transforms.html), [color spaces](https://wzjoriv.github.io/python-lcms2/stable/guides/spaces.html), [ICC authoring](https://wzjoriv.github.io/python-lcms2/stable/guides/icc-authoring.html), [colorimetry](https://wzjoriv.github.io/python-lcms2/stable/guides/colorimetry.html), [colormaps](https://wzjoriv.github.io/python-lcms2/stable/guides/colormaps.html), [CGATS files](https://wzjoriv.github.io/python-lcms2/stable/guides/cgats.html)
- [Value ranges and pixel formats](https://wzjoriv.github.io/python-lcms2/stable/explanation/formats.html)
- [API reference](https://wzjoriv.github.io/python-lcms2/stable/reference/api.html)

## Contributing

Building from source and the developer commands are in the [contributing guide](https://wzjoriv.github.io/python-lcms2/stable/contributing.html).

## License

MIT. LittleCMS is © Marti Maria Saguer, MIT license (`vendor/Little-CMS/LICENSE`).
