compatibility for LCMS<2.7, vix LCMS version string

This commit is contained in:
nulano 2020-10-12 02:58:08 +01:00
parent 934c44b3c3
commit 40c9a5a2a0
3 changed files with 16 additions and 3 deletions

View File

@ -48,7 +48,7 @@ def test_sanity():
assert list(map(type, v)) == [str, str, str, str]
# internal version number
assert re.search(r"\d+\.\d+$", features.version_module("littlecms2"))
assert re.search(r"\d+\.\d+(\.\d+)?$", features.version_module("littlecms2"))
skip_missing()
i = ImageCms.profileToProfile(hopper(), SRGB, SRGB)

View File

@ -224,6 +224,8 @@ def pilinfo(out=None, supported_formats=True):
If ``True``, a list of all supported image file formats will be printed.
"""
from pkg_resources import parse_version
if out is None:
out = sys.stdout
@ -269,7 +271,10 @@ def pilinfo(out=None, supported_formats=True):
else:
v = version(name)
if v is not None:
t = "compiled for" if name in ("pil", "jpg") else "loaded"
version_static = name in ("pil", "jpg")
if name == "littlecms2":
version_static = parse_version(v) < parse_version("2.7.0")
t = "compiled for" if version_static else "loaded"
print("---", feature, "support ok,", t, v, file=out)
else:
print("---", feature, "support ok", file=out)

View File

@ -1512,8 +1512,16 @@ setup_module(PyObject* m) {
d = PyModule_GetDict(m);
#if LCMS_VERSION < 2070
vn = LCMS_VERSION;
#else
vn = cmsGetEncodedCMMversion();
v = PyUnicode_FromFormat("%d.%d", vn / 100, vn % 100);
#endif
if (vn % 10) {
v = PyUnicode_FromFormat("%d.%d.%d", vn / 1000, (vn / 10) % 100, vn % 10);
} else {
v = PyUnicode_FromFormat("%d.%d", vn / 1000, (vn / 10) % 100);
}
PyDict_SetItemString(d, "littlecms_version", v);
return 0;