Skip to content

Commit 0a75993

Browse files
committed
PIL.features: Add a compile-time zlib-ng feature flag and version number
1 parent 3e0849b commit 0a75993

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/reference/features.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Feature version numbers are available only where stated.
5454
Support for the following features can be checked:
5555

5656
* ``libjpeg_turbo``: (compile time) Whether Pillow was compiled against the libjpeg-turbo version of libjpeg. Compile-time version number is available.
57+
* ``zlib_ng``: (compile time) Whether Pillow was compiled against the zlib-ng version of zlib. Compile-time version number is available.
5758
* ``raqm``: Raqm library, required for ``ImageFont.Layout.RAQM`` in :py:func:`PIL.ImageFont.truetype`. Run-time version number is available for Raqm 0.7.0 or newer.
5859
* ``libimagequant``: (compile time) ImageQuant quantization support in :py:func:`PIL.Image.Image.quantize`. Run-time version number is available.
5960
* ``xcb``: (compile time) Support for X11 in :py:func:`PIL.ImageGrab.grab` via the XCB library.

src/PIL/features.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def get_supported_codecs() -> list[str]:
127127
"fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
128128
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
129129
"libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"),
130+
"zlib_ng": ("PIL._imaging", "HAVE_ZLIBNG", "zlib_ng_version"),
130131
"libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"),
131132
"xcb": ("PIL._imaging", "HAVE_XCB", None),
132133
}
@@ -308,7 +309,11 @@ def pilinfo(out: IO[str] | None = None, supported_formats: bool = True) -> None:
308309
# this check is also in src/_imagingcms.c:setup_module()
309310
version_static = tuple(int(x) for x in v.split(".")) < (2, 7)
310311
t = "compiled for" if version_static else "loaded"
311-
if name == "raqm":
312+
if name == "zlib":
313+
zlib_ng_version = version_feature("zlib_ng")
314+
if zlib_ng_version is not None:
315+
v += ", compiled for zlib-ng " + zlib_ng_version
316+
elif name == "raqm":
312317
for f in ("fribidi", "harfbuzz"):
313318
v2 = version_feature(f)
314319
if v2 is not None:

src/_imaging.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,6 +4397,20 @@ setup_module(PyObject *m) {
43974397
}
43984398
#endif
43994399

4400+
PyObject *have_zlibng;
4401+
#ifdef ZLIBNG_VERSION
4402+
have_zlibng = Py_True;
4403+
{
4404+
PyObject *v = PyUnicode_FromString(ZLIBNG_VERSION);
4405+
PyDict_SetItemString(d, "zlib_ng_version", v ? v : Py_None);
4406+
Py_XDECREF(v);
4407+
}
4408+
#else
4409+
have_zlibng = Py_False;
4410+
#endif
4411+
Py_INCREF(have_zlibng);
4412+
PyModule_AddObject(m, "HAVE_ZLIBNG", have_zlibng);
4413+
44004414
#ifdef HAVE_LIBTIFF
44014415
{
44024416
extern const char *ImagingTiffVersion(void);

0 commit comments

Comments
 (0)