python-lcms2 0.1.1__cp312-cp312-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lcms2/__init__.py ADDED
@@ -0,0 +1,132 @@
1
+ import os
2
+ import re
3
+ from . import _lcms2
4
+ import numpy as np
5
+ from .implementation import WHITE_POINTS, CMSError, create_profile, open_profile, profile_from_memory
6
+
7
+ DATA_TYPES = _lcms2.DATA_TYPES
8
+ _DATA_TYPES_UPPER = {k.upper(): k for k in DATA_TYPES}
9
+
10
+ INTENT = {
11
+ "PERCEPTUAL": 0,
12
+ "RELATIVE_COLORIMETRIC": 1,
13
+ "SATURATION": 2,
14
+ "ABSOLUTE_COLORIMETRIC": 3
15
+ }
16
+
17
+ NON_ICC_INTENT = {
18
+ "PRESERVE_K_ONLY_PERCEPTUAL": 10,
19
+ "PRESERVE_K_ONLY_RELATIVE_COLORIMETRIC": 11,
20
+ "PRESERVE_K_ONLY_SATURATION": 12,
21
+ "PRESERVE_K_PLANE_PERCEPTUAL": 13,
22
+ "PRESERVE_K_PLANE_RELATIVE_COLORIMETRIC": 14,
23
+ "PRESERVE_K_PLANE_SATURATION": 15
24
+ }
25
+
26
+ FLAG = {
27
+ "NONE": 0x0,
28
+ "NOTPRECALC": 0x0100,
29
+ "GAMUTCHECK": 0x1000,
30
+ "SOFTPROOFING": 0x4000,
31
+ "BLACKPOINTCOMPENSATION": 0x2000,
32
+ "PRESERVEBLACK": 0x8000,
33
+ "NULLTRANSFORM": 0x0200,
34
+ "HIGHRESPRECALC": 0x0400,
35
+ "LOWRESPRECALC": 0x0800
36
+ }
37
+
38
+
39
+ def get_version():
40
+ ver = str(_lcms2.get_version())
41
+ return f"{ver[0]}.{ver[1:]}"
42
+
43
+
44
+ class Profile:
45
+ def __init__(self, builtin=None, filename=None, buffer=None,
46
+ white_point=None, degrees=2, temperature=None):
47
+ if builtin is None and filename is None and buffer is None:
48
+ self._assign(profile=_lcms2.create_default_profile())
49
+ return
50
+ if builtin is not None and filename is None and buffer is None:
51
+ self._assign(profile=create_profile(builtin, white_point=white_point, degrees=degrees, temperature=temperature))
52
+ return
53
+ if filename is not None and builtin is None and buffer is None:
54
+ self._assign(profile=open_profile(filename))
55
+ return
56
+ if buffer is not None and builtin is None and filename is None:
57
+ self._assign(profile=profile_from_memory(buffer))
58
+ return
59
+ raise CMSError(
60
+ "Only one source of profile data can be specified: a built-in profile name, filename or bytes object")
61
+
62
+ def _assign(self, profile):
63
+ self.handle = profile.handle
64
+ self.name = profile.name
65
+ self.info = profile.info
66
+ self.copyright = profile.copyright
67
+
68
+ def to_bytes(self):
69
+ return _lcms2.profile_to_bytes(self)
70
+
71
+ def save(self, filename):
72
+ with open(filename, "wb") as f:
73
+ f.write(self.to_bytes())
74
+
75
+
76
+ class Transform:
77
+ def __init__(self, src_profile, src_format, dst_profile, dst_format, intent="PERCEPTUAL", flags="NONE",
78
+ proofing_profile=None, proofing_intent=None):
79
+ if not isinstance(src_profile, (Profile, _lcms2.Profile)):
80
+ raise CMSError(f"Wrong type of src_profile. Expected Profile but got '{type(src_profile)}'")
81
+ src_format_key = _DATA_TYPES_UPPER.get(src_format.upper())
82
+ if src_format_key is None:
83
+ raise CMSError(f"Invalid source data format: '{src_format}'")
84
+ src_format = src_format_key
85
+ if not isinstance(dst_profile, (Profile, _lcms2.Profile)):
86
+ raise CMSError(f"Wrong type of dst_profile. Expected Profile but got '{type(src_profile)}'")
87
+ dst_format_key = _DATA_TYPES_UPPER.get(dst_format.upper())
88
+ if dst_format_key is None:
89
+ raise CMSError(f"Invalid destination data format: '{dst_format}'")
90
+ dst_format = dst_format_key
91
+ intent_key = intent.upper()
92
+ if intent_key not in INTENT:
93
+ raise CMSError(f"Invalid rendering intent: '{intent}'")
94
+ intent = intent_key
95
+ flag_list = [f for f in re.split("[ ,;|]+", flags) if f]
96
+ transform_flags = FLAG["NONE"]
97
+ for f in flag_list:
98
+ f = f.upper()
99
+ if f not in FLAG:
100
+ raise CMSError(f"Invalid flag: '{f}'")
101
+ transform_flags = transform_flags | FLAG[f]
102
+
103
+ if proofing_profile is not None:
104
+ if not isinstance(proofing_profile, (Profile, _lcms2.Profile)):
105
+ raise CMSError(f"Wrong type of proofing_profile. Expected Profile but got '{type(src_profile)}'")
106
+ if proofing_intent not in NON_ICC_INTENT.keys():
107
+ raise CMSError(f"Invalid proofing intent: '{proofing_intent}'")
108
+
109
+ self.src_format = src_format
110
+ self.dst_format = dst_format
111
+ self.transform = _lcms2.Transform(src_profile, DATA_TYPES[src_format][0],
112
+ dst_profile, DATA_TYPES[dst_format][0],
113
+ INTENT[intent], transform_flags,
114
+ proofing_profile,
115
+ NON_ICC_INTENT.get(proofing_intent, 0))
116
+
117
+ def apply(self, src):
118
+ _, src_numpy_type, src_channels = DATA_TYPES[self.src_format]
119
+ _, dst_numpy_type, dst_channels = DATA_TYPES[self.dst_format]
120
+ x = src
121
+ if not isinstance(src, np.ndarray):
122
+ x = np.array(src, dtype=src_numpy_type)
123
+ if x.dtype != src_numpy_type:
124
+ raise CMSError(f"Source data type ({x.dtype}) does not match transform input type ({src_numpy_type}")
125
+ if x.shape[-1] != src_channels:
126
+ raise CMSError(f"Wrong number of input channels ({x.shape[-1]}); expected {src_channels}")
127
+ dst_shape = np.empty_like(x.shape)
128
+ dst_shape[:-1] = x.shape[:-1]
129
+ dst_shape[-1] = dst_channels
130
+ dst = np.empty(shape=dst_shape, dtype=dst_numpy_type)
131
+ self.transform.apply(x, dst, x.size // src_channels)
132
+ return dst
lcms2/_lcms2.c ADDED
@@ -0,0 +1,89 @@
1
+ #define PY_SSIZE_T_CLEAN
2
+ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
3
+ #include <Python.h>
4
+
5
+ #if PY_VERSION_HEX < 0x030c0000
6
+ #define Py_T_INT T_INT
7
+ #define Py_T_OBJECT_EX T_OBJECT_EX
8
+ #endif
9
+
10
+ #include <numpy/arrayobject.h>
11
+ #include <lcms2.h>
12
+ #include <lcms2_internal.h>
13
+
14
+
15
+ #include "profile.h"
16
+ #include "transform.h"
17
+ #include "definitions.h"
18
+ #include "white_point.h"
19
+
20
+ static PyObject *
21
+ get_version (PyObject *self, PyObject *args) {
22
+ return Py_BuildValue("i", LCMS_VERSION);
23
+ }
24
+
25
+ static
26
+ PyMethodDef pycms_methods[] = {
27
+ {"create_profile", create_profile, METH_VARARGS},
28
+ {"create_default_profile", create_default_profile, METH_NOARGS},
29
+ {"create_rgb_profile", create_rgb_profile, METH_VARARGS},
30
+ {"open_profile", open_profile, METH_VARARGS},
31
+ {"profile_from_memory", profile_from_memory, METH_VARARGS},
32
+ {"profile_to_bytes", profile_to_bytes, METH_VARARGS},
33
+ {"white_point_from_temperature", white_point_from_temperature, METH_VARARGS},
34
+ {"get_version", get_version, METH_NOARGS},
35
+ {NULL, NULL}
36
+ };
37
+
38
+
39
+ static struct PyModuleDef lcms2_def =
40
+ {
41
+ PyModuleDef_HEAD_INIT,
42
+ "_lcms2", /* name of module */
43
+ "", /* module documentation, may be NULL */
44
+ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
45
+ pycms_methods
46
+ };
47
+
48
+ PyMODINIT_FUNC PyInit__lcms2(void)
49
+ {
50
+ PyObject *m;
51
+ m = PyModule_Create(&lcms2_def);
52
+ if (m == NULL)
53
+ return NULL;
54
+
55
+ if (PyType_Ready(&profile_type) < 0) {
56
+ Py_DECREF(m);
57
+ return NULL;
58
+ }
59
+
60
+ if (PyModule_AddObjectRef(m, "Profile", (PyObject *) &profile_type) < 0) {
61
+ Py_DECREF(m);
62
+ return NULL;
63
+ }
64
+
65
+ if (PyType_Ready(&transform_type) < 0) {
66
+ Py_DECREF(m);
67
+ return NULL;
68
+ }
69
+
70
+ if (PyModule_AddObjectRef(m, "Transform", (PyObject *) &transform_type) < 0) {
71
+ Py_DECREF(m);
72
+ return NULL;
73
+ }
74
+
75
+ PyObject* types_dict = create_data_types_dict();
76
+ if (types_dict == NULL)
77
+ {
78
+ Py_DECREF(m);
79
+ return NULL;
80
+ }
81
+ if (PyModule_AddObjectRef(m, "DATA_TYPES", (PyObject *) types_dict) < 0) {
82
+ Py_DECREF(m);
83
+ return NULL;
84
+ }
85
+
86
+ import_array(); // initialize NumPy
87
+
88
+ return m;
89
+ }
lcms2/_lcms2.pyd ADDED
Binary file
@@ -0,0 +1,221 @@
1
+ from . import _lcms2
2
+ import numpy as np
3
+ import os
4
+
5
+
6
+ class CMSError(Exception):
7
+ def __init__(self, message="LibCMS2 error"):
8
+ super().__init__(message)
9
+
10
+
11
+ def create_profile(profile, white_point=None, degrees=2, temperature=None):
12
+ if profile in ("sRGB", "Lab", "XYZ"):
13
+ coordinates = None
14
+ if profile == "Lab":
15
+ if isinstance(white_point, str):
16
+ coordinates = np.array(WHITE_POINTS[degrees][white_point]["xyY"])
17
+ else:
18
+ if isinstance(temperature, (int, float)):
19
+ wp_list = _lcms2.white_point_from_temperature(temperature)
20
+ coordinates = np.array(wp_list)
21
+ else:
22
+ if white_point is not None:
23
+ coordinates = np.array(white_point)
24
+ if coordinates.size != 3:
25
+ raise CMSError(
26
+ "white_point should be an array-like object of size 3 containing xyY coordinates of the white point")
27
+ p = _lcms2.create_profile(profile, coordinates)
28
+ return p
29
+
30
+ if profile in RGB_COLORSPACES.keys():
31
+ space = RGB_COLORSPACES[profile]
32
+ profile_white_point = space["white point"]
33
+ if profile_white_point not in WHITE_POINTS[degrees].keys():
34
+ raise CMSError(f"Unknown white point `{profile_white_point}`")
35
+ wp = np.array(WHITE_POINTS[degrees][profile_white_point]["xyY"])
36
+ red = np.array(space["red"])
37
+ green = np.array(space["green"])
38
+ blue = np.array(space["blue"])
39
+ tc = space["tone curve"]
40
+ curve_type = int(tc["type"])
41
+ parameters = np.array(tc["parameters"])
42
+ p = _lcms2.create_rgb_profile(wp, red, green, blue, curve_type, parameters)
43
+ return p
44
+
45
+ raise CMSError(
46
+ f"Invalid profile '{profile}'. It must be one of built in profiles ('sRGB', 'Lab' or 'XYZ') or supported RGB profiles.")
47
+
48
+
49
+ def open_profile(filename):
50
+ if not isinstance(filename, str):
51
+ raise CMSError("filename must be a string containing a path to a profile")
52
+ if not os.path.isfile(filename):
53
+ raise CMSError(f"Unable to find '{filename}'.")
54
+
55
+ p = _lcms2.open_profile(filename)
56
+ return p
57
+
58
+
59
+ def profile_from_memory(buffer):
60
+ if not isinstance(buffer, bytes):
61
+ raise CMSError("filename must be a bytes object")
62
+
63
+ p = _lcms2.profile_from_memory(buffer)
64
+ return p
65
+
66
+
67
+ """
68
+ White points of standard illuminants for 2 degrees and 10 degrees field of view
69
+ xyY are the coordinates of the white point,
70
+ CCT is correlated color temperature in Kelvins
71
+ """
72
+ WHITE_POINTS = {2: {'A': {'xyY': [0.44758, 0.40745, 1.0], 'CCT': 2856.0, 'description': 'incandescent / tungsten'},
73
+ 'B': {'xyY': [0.34842, 0.35161, 1.0], 'CCT': 4874.0,
74
+ 'description': 'obsolete, direct sunlight at noon'},
75
+ 'C': {'xyY': [0.31006, 0.31616, 1.0], 'CCT': 6774.0,
76
+ 'description': 'obsolete, average / North sky daylight NTSC 1953, PAL-M'},
77
+ 'D50': {'xyY': [0.34567, 0.3585, 1.0], 'CCT': 5003.0,
78
+ 'description': 'horizon light, ICC profile PCS'},
79
+ 'D55': {'xyY': [0.33242, 0.34743, 1.0], 'CCT': 5503.0,
80
+ 'description': 'mid-morning / mid-afternoon daylight'},
81
+ 'D65': {'xyY': [0.31272, 0.32903, 1.0], 'CCT': 6504.0,
82
+ 'description': 'noon daylight: television, sRGB color space'},
83
+ 'D75': {'xyY': [0.29902, 0.31485, 1.0], 'CCT': 7504.0, 'description': 'North sky daylight'},
84
+ 'D93': {'xyY': [0.28315, 0.29711, 1.0], 'CCT': 9305.0,
85
+ 'description': 'high-efficiency blue phosphor monitors, BT.2035, NTSC-J'},
86
+ 'E': {'xyY': [0.33333, 0.33333, 1.0], 'CCT': 5454.0, 'description': 'equal energy'},
87
+ 'F1': {'xyY': [0.3131, 0.33727, 1.0], 'CCT': 6430.0, 'description': 'daylight fluorescent'},
88
+ 'F2': {'xyY': [0.37208, 0.37529, 1.0], 'CCT': 4230.0, 'description': 'cool white fluorescent'},
89
+ 'F3': {'xyY': [0.4091, 0.3943, 1.0], 'CCT': 3450.0, 'description': 'white fluorescent'},
90
+ 'F4': {'xyY': [0.44018, 0.40329, 1.0], 'CCT': 2940.0, 'description': 'warm white fluorescent'},
91
+ 'F5': {'xyY': [0.31379, 0.34531, 1.0], 'CCT': 6350.0, 'description': 'daylight fluorescent'},
92
+ 'F6': {'xyY': [0.3779, 0.38835, 1.0], 'CCT': 4150.0, 'description': 'light white fluorescent'},
93
+ 'F7': {'xyY': [0.31292, 0.32933, 1.0], 'CCT': 6500.0,
94
+ 'description': 'D65 simulator, daylight simulator'},
95
+ 'F8': {'xyY': [0.34588, 0.35875, 1.0], 'CCT': 5000.0,
96
+ 'description': 'D50 simulator, Sylvania F40 Design 50'},
97
+ 'F9': {'xyY': [0.37417, 0.37281, 1.0], 'CCT': 4150.0,
98
+ 'description': 'cool white deluxe fluorescent'},
99
+ 'F10': {'xyY': [0.34609, 0.35986, 1.0], 'CCT': 5000.0, 'description': 'Philips TL85, Ultralume 50'},
100
+ 'F11': {'xyY': [0.38052, 0.37713, 1.0], 'CCT': 4000.0, 'description': 'Philips TL84, Ultralume 40'},
101
+ 'F12': {'xyY': [0.43695, 0.40441, 1.0], 'CCT': 3000.0, 'description': 'Philips TL83, Ultralume 30'},
102
+ 'FL3.1': {'xyY': [0.4407, 0.4033, 1.0], 'CCT': 2932.0, 'description': 'standard halophosphate'},
103
+ 'FL3.2': {'xyY': [0.3808, 0.3734, 1.0], 'CCT': 3965.0, 'description': 'standard halophosphate'},
104
+ 'FL3.3': {'xyY': [0.3153, 0.3439, 1.0], 'CCT': 6280.0, 'description': 'standard halophosphate'},
105
+ 'FL3.4': {'xyY': [0.4429, 0.4043, 1.0], 'CCT': 2904.0, 'description': 'DeLuxe type'},
106
+ 'FL3.5': {'xyY': [0.3749, 0.3672, 1.0], 'CCT': 4086.0, 'description': 'DeLuxe type'},
107
+ 'FL3.6': {'xyY': [0.3488, 0.36, 1.0], 'CCT': 4894.0, 'description': 'DeLuxe type'},
108
+ 'FL3.7': {'xyY': [0.4384, 0.4045, 1.0], 'CCT': 2979.0, 'description': 'Three-band'},
109
+ 'FL3.8': {'xyY': [0.382, 0.3832, 1.0], 'CCT': 4006.0, 'description': 'Three-band'},
110
+ 'FL3.9': {'xyY': [0.3499, 0.3591, 1.0], 'CCT': 4853.0, 'description': 'Three-band'},
111
+ 'FL3.10': {'xyY': [0.3455, 0.356, 1.0], 'CCT': 5000.0, 'description': 'Three-band'},
112
+ 'FL3.11': {'xyY': [0.3245, 0.3434, 1.0], 'CCT': 5854.0, 'description': 'Three-band'},
113
+ 'FL3.12': {'xyY': [0.4377, 0.4037, 1.0], 'CCT': 2984.0, 'description': 'Multi-band'},
114
+ 'FL3.13': {'xyY': [0.383, 0.3724, 1.0], 'CCT': 3896.0, 'description': 'Multi-band'},
115
+ 'FL3.14': {'xyY': [0.3447, 0.3609, 1.0], 'CCT': 5045.0, 'description': 'Multi-band'},
116
+ 'FL3.15': {'xyY': [0.3127, 0.3288, 1.0], 'CCT': 6509.0, 'description': 'D65 Simulator'},
117
+ 'HP1': {'xyY': [0.533, 0.415, 1.0], 'CCT': 1959.0,
118
+ 'description': 'Standard high pressure sodium lamp'},
119
+ 'HP2': {'xyY': [0.4778, 0.4158, 1.0], 'CCT': 2506.0,
120
+ 'description': 'Color-enhanced high-pressure sodium lamp'},
121
+ 'HP3': {'xyY': [0.4302, 0.4075, 1.0], 'CCT': 3144.0,
122
+ 'description': 'High pressure metal halide lamp'},
123
+ 'HP4': {'xyY': [0.3812, 0.3797, 1.0], 'CCT': 4002.0,
124
+ 'description': 'High pressure metal halide lamp'},
125
+ 'HP5': {'xyY': [0.3776, 0.3713, 1.0], 'CCT': 4039.0,
126
+ 'description': 'High pressure metal halide lamp'},
127
+ 'LED-B1': {'xyY': [0.456, 0.4078, 1.0], 'CCT': 2733.0, 'description': 'phosphor-converted blue'},
128
+ 'LED-B2': {'xyY': [0.4357, 0.4012, 1.0], 'CCT': 2998.0, 'description': 'phosphor-converted blue'},
129
+ 'LED-B3': {'xyY': [0.3756, 0.3723, 1.0], 'CCT': 4103.0, 'description': 'phosphor-converted blue'},
130
+ 'LED-B4': {'xyY': [0.3422, 0.3502, 1.0], 'CCT': 5109.0, 'description': 'phosphor-converted blue'},
131
+ 'LED-B5': {'xyY': [0.3118, 0.3236, 1.0], 'CCT': 6598.0, 'description': 'phosphor-converted blue'},
132
+ 'LED-BH1': {'xyY': [0.4474, 0.4066, 1.0], 'CCT': 2851.0,
133
+ 'description': 'mixing of phosphor-converted blue LED and red LED (blue-hybrid)'},
134
+ 'LED-RGB1': {'xyY': [0.4557, 0.4211, 1.0], 'CCT': 2840.0,
135
+ 'description': 'mixing of red, green, and blue LEDs'},
136
+ 'LED-V1': {'xyY': [0.4548, 0.4044, 1.0], 'CCT': 2724.0, 'description': 'phosphor-converted violet'},
137
+ 'LED-V2': {'xyY': [0.3781, 0.3775, 1.0], 'CCT': 4070.0, 'description': 'phosphor-converted violet'},
138
+ 'ID50': {'xyY': [0.3432, 0.3602, 1.0], 'CCT': 5098.0, 'description': 'natural indoor daylight'},
139
+ 'ID65': {'xyY': [0.3107, 0.3307, 1.0], 'CCT': 6603.0, 'description': 'natural indoor daylight'}},
140
+ 10: {'A': {'xyY': [0.45117, 0.40594, 1.0], 'CCT': 2856.0, 'description': 'incandescent / tungsten'},
141
+ 'B': {'xyY': [0.3498, 0.3527, 1.0], 'CCT': 4874.0,
142
+ 'description': 'obsolete, direct sunlight at noon'},
143
+ 'C': {'xyY': [0.31039, 0.31905, 1.0], 'CCT': 6774.0,
144
+ 'description': 'obsolete, average / North sky daylight NTSC 1953, PAL-M'},
145
+ 'D50': {'xyY': [0.34773, 0.35952, 1.0], 'CCT': 5003.0,
146
+ 'description': 'horizon light, ICC profile PCS'},
147
+ 'D55': {'xyY': [0.33411, 0.34877, 1.0], 'CCT': 5503.0,
148
+ 'description': 'mid-morning / mid-afternoon daylight'},
149
+ 'D65': {'xyY': [0.31382, 0.331, 1.0], 'CCT': 6504.0,
150
+ 'description': 'noon daylight: television, sRGB color space'},
151
+ 'D75': {'xyY': [0.29968, 0.3174, 1.0], 'CCT': 7504.0, 'description': 'North sky daylight'},
152
+ 'D93': {'xyY': [0.28327, 0.30043, 1.0], 'CCT': 9305.0,
153
+ 'description': 'high-efficiency blue phosphor monitors, BT.2035, NTSC-J'},
154
+ 'E': {'xyY': [0.33333, 0.33333, 1.0], 'CCT': 5454.0, 'description': 'equal energy'},
155
+ 'F1': {'xyY': [0.31811, 0.33559, 1.0], 'CCT': 6430.0, 'description': 'daylight fluorescent'},
156
+ 'F2': {'xyY': [0.37925, 0.36733, 1.0], 'CCT': 4230.0, 'description': 'cool white fluorescent'},
157
+ 'F3': {'xyY': [0.41761, 0.38324, 1.0], 'CCT': 3450.0, 'description': 'white fluorescent'},
158
+ 'F4': {'xyY': [0.4492, 0.39074, 1.0], 'CCT': 2940.0, 'description': 'warm white fluorescent'},
159
+ 'F5': {'xyY': [0.31975, 0.34246, 1.0], 'CCT': 6350.0, 'description': 'daylight fluorescent'},
160
+ 'F6': {'xyY': [0.3866, 0.37847, 1.0], 'CCT': 4150.0, 'description': 'light white fluorescent'},
161
+ 'F7': {'xyY': [0.31569, 0.3296, 1.0], 'CCT': 6500.0,
162
+ 'description': 'D65 simulator, daylight simulator'},
163
+ 'F8': {'xyY': [0.34902, 0.35939, 1.0], 'CCT': 5000.0,
164
+ 'description': 'D50 simulator, Sylvania F40 Design 50'},
165
+ 'F9': {'xyY': [0.37829, 0.37045, 1.0], 'CCT': 4150.0,
166
+ 'description': 'cool white deluxe fluorescent'},
167
+ 'F10': {'xyY': [0.3509, 0.35444, 1.0], 'CCT': 5000.0, 'description': 'Philips TL85, Ultralume 50'},
168
+ 'F11': {'xyY': [0.38541, 0.37123, 1.0], 'CCT': 4000.0,
169
+ 'description': 'Philips TL84, Ultralume 40'},
170
+ 'F12': {'xyY': [0.44256, 0.39717, 1.0], 'CCT': 3000.0,
171
+ 'description': 'Philips TL83, Ultralume 30'}}}
172
+
173
+ RGB_COLORSPACES = {'Adobe RGB (1998)': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D65',
174
+ 'red': [0.64, 0.33, 0.297361], 'green': [0.21, 0.71, 0.627355],
175
+ 'blue': [0.15, 0.06, 0.075285]},
176
+ 'Apple RGB': {'tone curve': {'type': 1, 'parameters': [1.8]}, 'white point': 'D65',
177
+ 'red': [0.625, 0.34, 0.244634], 'green': [0.28, 0.595, 0.672034],
178
+ 'blue': [0.155, 0.07, 0.083332]},
179
+ 'Best RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D50',
180
+ 'red': [0.7347, 0.2653, 0.228457], 'green': [0.215, 0.775, 0.737352],
181
+ 'blue': [0.13, 0.035, 0.034191]},
182
+ 'Beta RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D50',
183
+ 'red': [0.6888, 0.3112, 0.303273], 'green': [0.1986, 0.7551, 0.663786],
184
+ 'blue': [0.1265, 0.0352, 0.032941]},
185
+ 'Bruce RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D65',
186
+ 'red': [0.64, 0.33, 0.240995], 'green': [0.28, 0.65, 0.683554],
187
+ 'blue': [0.15, 0.06, 0.075452]},
188
+ 'CIE RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'E',
189
+ 'red': [0.735, 0.265, 0.176204], 'green': [0.274, 0.717, 0.812985],
190
+ 'blue': [0.167, 0.009, 0.010811]},
191
+ 'ColorMatch RGB': {'tone curve': {'type': 1, 'parameters': [1.8]}, 'white point': 'D50',
192
+ 'red': [0.63, 0.34, 0.274884], 'green': [0.295, 0.605, 0.658132],
193
+ 'blue': [0.15, 0.075, 0.066985]},
194
+ 'Don RGB 4': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D50',
195
+ 'red': [0.696, 0.3, 0.27835], 'green': [0.215, 0.765, 0.68797],
196
+ 'blue': [0.13, 0.035, 0.03368]},
197
+ 'ECI RGB v2': {
198
+ 'tone curve': {'type': 4, 'parameters': [3.000000, 0.862076, 0.137924, 0.110703, 0.080002]},
199
+ 'white point': 'D50', 'red': [0.67, 0.33, 0.32025],
200
+ 'green': [0.21, 0.71, 0.602071], 'blue': [0.14, 0.08, 0.077679]},
201
+ 'Ekta Space PS5': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D50',
202
+ 'red': [0.695, 0.305, 0.260629], 'green': [0.26, 0.7, 0.734946],
203
+ 'blue': [0.11, 0.005, 0.004425]},
204
+ 'NTSC RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'C',
205
+ 'red': [0.67, 0.33, 0.298839], 'green': [0.21, 0.71, 0.586811],
206
+ 'blue': [0.14, 0.08, 0.11435]},
207
+ 'PAL/SECAM RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D65',
208
+ 'red': [0.64, 0.33, 0.222021], 'green': [0.29, 0.6, 0.706645],
209
+ 'blue': [0.15, 0.06, 0.071334]},
210
+ 'ProPhoto RGB': {'tone curve': {'type': 1, 'parameters': [1.8]}, 'white point': 'D50',
211
+ 'red': [0.7347, 0.2653, 0.28804], 'green': [0.1596, 0.8404, 0.711874],
212
+ 'blue': [0.0366, 0.0001, 8.6e-05]},
213
+ 'SMPTE-C RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D65',
214
+ 'red': [0.63, 0.34, 0.212395], 'green': [0.31, 0.595, 0.701049],
215
+ 'blue': [0.155, 0.07, 0.086556]},
216
+ '_sRGB': {'tone curve': {'type': 4, 'parameters': [2.399994, 0.947861, 0.052139, 0.077393, 0.040451]},
217
+ 'white point': 'D65', 'red': [0.64, 0.33, 0.212656],
218
+ 'green': [0.3, 0.6, 0.715158], 'blue': [0.15, 0.06, 0.072186]},
219
+ 'Wide Gamut RGB': {'tone curve': {'type': 1, 'parameters': [2.2]}, 'white point': 'D50',
220
+ 'red': [0.735, 0.265, 0.258187], 'green': [0.115, 0.826, 0.724938],
221
+ 'blue': [0.157, 0.018, 0.016875]}}
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-lcms2
3
+ Version: 0.1.1
4
+ Summary: Python binding for LittleCMS2 library
5
+ Author-email: Josue N Rivera <josuevaldez1.com@gmail.com>
6
+ Project-URL: Homepage, https://github.com/wzjoriv/python-lcms2
7
+ Project-URL: Bug Tracker, https://github.com/wzjoriv/python-lcms2/issues
8
+ Keywords: color management,lcms2,icc,color profile,colorspace
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: C
11
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=2.0
19
+ Dynamic: license-file
20
+
21
+ # python-lcms2
22
+
23
+ Python binding for the [LittleCMS2](https://github.com/mm2/Little-CMS) color management library.
24
+
25
+ ## Installation
26
+
27
+ ```
28
+ pip install python-lcms2
29
+ ```
30
+
31
+ Pre-built wheels are available on PyPI for Windows (x86-64, ARM64), Linux (x86-64, ARM64), and macOS (Intel, Apple Silicon) on Python 3.10 and later. Windows ARM64 requires Python 3.11 or later. For other platforms, see [Building from source](#building-from-source).
32
+
33
+ ## Usage
34
+
35
+ ```python
36
+ import lcms2
37
+ ```
38
+
39
+ ### Profiles
40
+
41
+ A `Profile` can be created from a built-in name, a file on disk, or raw bytes in memory:
42
+
43
+ ```python
44
+ srgb = lcms2.Profile("sRGB")
45
+ prophoto = lcms2.Profile("ProPhoto RGB")
46
+ from_file = lcms2.Profile(filename="CMYK.icm")
47
+
48
+ with open("CMYK.icm", "rb") as f:
49
+ from_bytes = lcms2.Profile(buffer=f.read())
50
+ ```
51
+
52
+ Built-in profiles provided by LittleCMS: `sRGB`, `Lab`, `XYZ`.
53
+
54
+ Additional built-in 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`, `Wide Gamut RGB`.
55
+
56
+ ### Transforms
57
+
58
+ A `Transform` converts pixel data from one profile and format to another:
59
+
60
+ ```python
61
+ lab = lcms2.Profile("Lab")
62
+ srgb = lcms2.Profile("sRGB")
63
+
64
+ transform = lcms2.Transform(lab, "Lab_DBL", srgb, "RGB_16")
65
+ ```
66
+
67
+ The constructor signature is:
68
+
69
+ ```
70
+ Transform(src_profile, src_format, dst_profile, dst_format, intent="PERCEPTUAL", flags="NONE")
71
+ ```
72
+
73
+ #### Format strings
74
+
75
+ Format strings follow the pattern `{COLORSPACE}_{DTYPE}` with an optional suffix. The dtype suffix determines the NumPy array type expected at runtime:
76
+
77
+ | Suffix | NumPy dtype | Typical use |
78
+ |--------|-------------|-------------|
79
+ | `_8` | `uint8` | 8-bit images (0–255) |
80
+ | `_16` | `uint16` | 16-bit images (0–65535) |
81
+ | `_FLT` | `float32` | Single-precision float |
82
+ | `_DBL` | `float64` | Double-precision float |
83
+ | `_HALF_FLT` | `float16` | Half-precision float |
84
+
85
+ Common colorspace prefixes: `RGB`, `BGR`, `RGBA`, `BGRA`, `GRAY`, `Lab`, `XYZ`, `CMYK`, `YCbCr`, `HSV`, `HLS`.
86
+
87
+ Optional suffixes: `_PLANAR` (channel-first layout), `_REV` (ink-reversed), `_SE` (swap-endian), `_PREMUL` (premultiplied alpha).
88
+
89
+ The full list of supported format strings:
90
+
91
+ ```python
92
+ lcms2.DATA_TYPES.keys()
93
+ ```
94
+
95
+ Rendering intents (`lcms2.INTENT`): `PERCEPTUAL`, `RELATIVE_COLORIMETRIC`, `SATURATION`, `ABSOLUTE_COLORIMETRIC`.
96
+
97
+ Flags (`lcms2.FLAG`) can be combined with commas, spaces, semicolons, or `|`:
98
+
99
+ ```python
100
+ transform = lcms2.Transform(lab, "Lab_DBL", srgb, "RGB_16",
101
+ intent="PERCEPTUAL",
102
+ flags="GAMUTCHECK,SOFTPROOFING")
103
+ ```
104
+
105
+ ### Applying a transform
106
+
107
+ `Transform.apply` accepts a NumPy array or any array-compatible object and returns a transformed NumPy array. It works on single pixels, batches, and full images — the last dimension is always the channel axis:
108
+
109
+ ```python
110
+ result = transform.apply([50.0, 0.0, 0.0]) # L*a*b* neutral grey, shape (3,)
111
+ ```
112
+
113
+ The array dtype must match the source format declared at construction time. When passing lists or other convertibles, the data is cast automatically where possible.
114
+
115
+ #### Converting a full image
116
+
117
+ `apply` treats any array shape as `(..., channels)`, so a 2D image `(H, W, C)` is processed in one call:
118
+
119
+ ```python
120
+ import numpy as np
121
+ import lcms2
122
+
123
+ srgb = lcms2.Profile("sRGB")
124
+ prophoto = lcms2.Profile("ProPhoto RGB")
125
+
126
+ transform = lcms2.Transform(srgb, "RGB_8", prophoto, "RGB_16")
127
+
128
+ image = np.random.randint(0, 256, (480, 640, 3), dtype=np.uint8)
129
+ result = transform.apply(image) # shape (480, 640, 3), dtype uint16
130
+ ```
131
+
132
+ A common use case is editing in Lab — perceptually uniform, so lightness adjustments look natural. OpenCV loads images as BGR uint8:
133
+
134
+ ```python
135
+ import cv2
136
+ import numpy as np
137
+ import lcms2
138
+ import matplotlib.pyplot as plt
139
+
140
+ image = cv2.imread("photo.jpg") # uint8, BGR
141
+
142
+ srgb = lcms2.Profile("sRGB")
143
+ lab = lcms2.Profile("Lab")
144
+
145
+ to_lab = lcms2.Transform(srgb, "bgr_8", lab, "lab_flt")
146
+ to_srgb = lcms2.Transform(lab, "lab_flt", srgb, "rgb_flt")
147
+
148
+ lab_image = to_lab.apply(image)
149
+ lab_image[..., 0] = np.clip(lab_image[..., 0] * 1.2, 0, 100) # boost lightness
150
+
151
+ result = np.clip(to_srgb.apply(lab_image), 0.0, 1.0) # float32, RGB, 0.0–1.0
152
+
153
+ plt.imshow(result)
154
+ plt.show()
155
+ ```
156
+
157
+ Format strings are case-insensitive, so `"BGR_8"`, `"bgr_8"`, and `"Bgr_8"` are all accepted.
158
+
159
+ To save back to a file with cv2:
160
+
161
+ ```python
162
+ bgr_out = cv2.cvtColor((result * 255).astype(np.uint8), cv2.COLOR_RGB2BGR)
163
+ cv2.imwrite("output.jpg", bgr_out)
164
+ ```
165
+
166
+ ## Building from source
167
+
168
+ Clone the repository with its submodules:
169
+
170
+ ```
171
+ git clone --recurse-submodules https://github.com/wzjoriv/python-lcms2.git
172
+ cd python-lcms2
173
+ ```
174
+
175
+ Install the build tool if needed:
176
+
177
+ ```
178
+ pip install build --upgrade
179
+ ```
180
+
181
+ Build a wheel:
182
+
183
+ ```
184
+ python -m build --wheel
185
+ ```
186
+
187
+ The wheel is written to `dist/`. Install it with:
188
+
189
+ ```
190
+ pip install dist/python_lcms2*.whl
191
+ ```
192
+
193
+ Windows path detection (Windows SDK include and library directories) is handled automatically via the registry in `setup.py`. If the build fails on your Windows installation, the paths may need to be adjusted manually.
194
+
195
+ For bugs, questions, and feature requests use [GitHub Issues](https://github.com/wzjoriv/python-lcms2/issues).
196
+
197
+ ## Acknowledgements
198
+
199
+ This project is a continuation of work by prior maintainers. The lineage of the repository is:
200
+ [sk1-project](https://github.com/sk1-project) → [RomanKosobrodov](https://github.com/RomanKosobrodov/python-lcms2) → [wzjoriv](https://github.com/wzjoriv/python-lcms2).
@@ -0,0 +1,9 @@
1
+ lcms2/__init__.py,sha256=69wy3i5Qh0YngKzmnZXvd_8ETWaKtCNLtmuVLsoXOnA,5527
2
+ lcms2/_lcms2.c,sha256=aJOw7L4ABx-kA9iXveBEOXxeF4zNYUDQfyC83M7LsEc,2275
3
+ lcms2/_lcms2.pyd,sha256=iI_MAhta7GG6N7UjYWcWcoORZk4mhmZUedUFRrVdvOo,293888
4
+ lcms2/implementation.py,sha256=HUhgvSPRy8Ng6zszNsDeiOGapQ4lmHWAs134HbknrB4,16834
5
+ python_lcms2-0.1.1.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
6
+ python_lcms2-0.1.1.dist-info/METADATA,sha256=V8mHA-8U4T4ucXFVw0PjI1Mr370kLjGh9OhP3TbQp_c,6619
7
+ python_lcms2-0.1.1.dist-info/WHEEL,sha256=xym4U9WkmFNYXMouEJ5h5aY9TdzMQLuzt0iDwRD6PG0,101
8
+ python_lcms2-0.1.1.dist-info/top_level.txt,sha256=QjTMasy-VPB6SBo17SY2e-bNQAWKCqrqYmWJIuLpd_U,6
9
+ python_lcms2-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-win_arm64
5
+