Skip to main content

Python binding for LittleCMS2 library

Project description

python-lcms2

Simplified Python binding of LittleCMS2 library.

Installation

Wheel files for 64-bit Windows and Python 3.10+ are available from PyPI. Use pip to install the package:

pip install python-lcms2

The package can be uninstalled using the corresponding command:

python -m pip uninstall -y python-lcms2

Getting started

Little CMS functionality is implemented by two classes: Profile and Transform.

Profiles

A Profile object can be created using one of the built-in profiles, by reading a profile file (using the filename argument) or from data stored in memory as Python bytes object (buffer argument).

Built-in profiles include sRGB, Lab and XYZ provided by the Little CMS library and additional RGB profiles: Adobe RGB (1998), Apple RGB, Best RGB, Beta RGB, Bruce RGB, CIE RGB, ColorMatch RGB, Don RGB 4, ECI RGB v2, Ekta Space PS5, NTSC RGB, PAL/SECAM RGB, ProPhoto RGB, SMPTE-C RGB, _sRGB, and Wide Gamut RGB.

import lcms2

x = lcms2.Profile("sRGB")
p = lcms2.Profile("ProPhoto RGB")
y = lcms2.Profile(filename="CMYK.icm")

with open("CMYK.icm", "rb") as f:
    z = lcms2.Profile(buffer=f.read)

Transforms

Transforms between profiles are implemented by the respective class. To create an instance of Transform call its constructor and provide six arguments: (1) source profile, (2) source data type string, (3) destination profile, (4) destination data type string, (5) rendering intent string (optional, defaults to "PERCEPTUAL"), and (6) flags (optional, the default value is "NONE").

lab_profile = lcms2.create_profile("Lab")
rgb_profile = lcms2.create_profile("sRGB")
transform = lcms2.Transform(lab_profile, "Lab_DBL",
                            rgb_profile, "RGB_16",
                            "PERCEPTUAL",
                            "NONE")

Supported format strings can be listed as follows:

lcms2.DATA_TYPES.keys()

Rendering intents could be one of the following: 'PERCEPTUAL', 'RELATIVE_COLORIMETRIC', 'SATURATION', and 'ABSOLUTE_COLORIMETRIC' (see lcms2.INTENT dictionary).

Likewise, supported transform flags are available as keys of the lcms2.FLAG dictionary. Several flags can be combined by including them in the flags argument string separating them by commas, semicolons, spaces or the pipe symbol |, for example

flags = "GAMUTCHECK,SOFTPROOFING,PRESERVEBLACK"

The transform is calculated using the Transform.apply method, for example:

neutral_grey = transform.apply([50.0, 0.0, 0.0])

The method takes a Numpy array (or an object convertible to NumPy array) and returns a transformed array of appropriate shape. The data type of the input array must correspond to the input data type specified during transform creation. When lists and other array-compatible objects are used the data types will be converted, when possible. For instance in the example above the input data could be provided as [50, 0, 0] (list containing integers):

neutral_grey = transform.apply([50, 0, 0])

Building form source

To build python-lcms2 for your own platform, clone the repository with its submodules:

git clone --recurse-submodules git@github.com:wzjoriv/python-lcms2.git

Check that the build package is installed:

python -m pip install build --upgrade

navigate to the root directory of the repository (the one containing the pyproject.toml file) and run:

python -m build --wheel

If everything goes smoothly you will have a wheel file for you platform generated in the dist directory. It can be installed by pip as follows:

python -m pip install --upgrade dist/python_lcms2*.whl

Building the package on Windows might involve minor modifications to include and library paths. An attempt was made to automate the process (see setup.py) though there is no guarantee that the code works on your version of Windows.

Issues, bugs and feedback

You are likely to hit a few bugs and issues while using python-lcms2. Please report them through GitHub Issues.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_lcms2-0.0.20-cp314-cp314-win_amd64.whl (350.1 kB view details)

Uploaded CPython 3.14Windows x86-64

python_lcms2-0.0.20-cp313-cp313-win_amd64.whl (337.5 kB view details)

Uploaded CPython 3.13Windows x86-64

python_lcms2-0.0.20-cp312-cp312-win_amd64.whl (337.5 kB view details)

Uploaded CPython 3.12Windows x86-64

python_lcms2-0.0.20-cp311-cp311-win_amd64.whl (337.4 kB view details)

Uploaded CPython 3.11Windows x86-64

python_lcms2-0.0.20-cp310-cp310-win_amd64.whl (337.4 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file python_lcms2-0.0.20-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for python_lcms2-0.0.20-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 559cf48826e26e1d022c6791ffdc9c0b03e0b1ae191d2fd59654a4770873221d
MD5 1c35034225c11c947b42fcfbda79cfaa
BLAKE2b-256 88c7bbea7d493dbf3e5d3385f11829338f3438fd1a4747cc9a86b202e6ba0683

See more details on using hashes here.

File details

Details for the file python_lcms2-0.0.20-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for python_lcms2-0.0.20-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f9ad6e217eaf40a82becb558111ac7b82636a350c32dc4be5095545b020e3074
MD5 af0cd844f2740abd7077b063d4206dba
BLAKE2b-256 1065fb5557e250cea63a281c73d677a9e62702013a19f9104708388a44f1d0fb

See more details on using hashes here.

File details

Details for the file python_lcms2-0.0.20-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for python_lcms2-0.0.20-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b491abb878fa65ecd28b33cf8e1b8c3289734c414c6a85c5b9022ca8f928c819
MD5 eb312ad1c5a0744c02178da3345dc553
BLAKE2b-256 693788a15fe075545a0c91aed05d8ff21c57c2da71be68849f8aa821f33d4322

See more details on using hashes here.

File details

Details for the file python_lcms2-0.0.20-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for python_lcms2-0.0.20-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f639c55c7261fa96bb6449874799e446a6d38a2cd1153f871e804807f088f9a2
MD5 c9c8969f6fcf8bba4ed387f6365765eb
BLAKE2b-256 ddf8427e094b60215fa32cdeb6ca7230c321bb486964dc06e9290e92bc594cfa

See more details on using hashes here.

File details

Details for the file python_lcms2-0.0.20-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for python_lcms2-0.0.20-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3cd47577030895590e51ce22ee8fbbbd58f5f30366b6d69b80f939eede036ade
MD5 517b78889f38c07e8749a4b8631cd13e
BLAKE2b-256 983df5089d0fa2506ffe5da70dfa6706cb32715a03532b077d07aa0e073b8bd6

See more details on using hashes here.

Supported by

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