Skip to content

Commit

Permalink
lib_imaging POC
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Sep 1, 2024
1 parent 4c5345c commit a3da224
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/reference/internal_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ on some Python versions.
:mod:`PIL.Image.core` Module
----------------------------

.. module:: PIL._imaging
.. module:: PIL.lib_imaging
.. module:: PIL.Image.core

An internal interface module previously known as :mod:`~PIL._imaging`,
Expand Down
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
import struct
import subprocess
import sys
import sysconfig
import warnings

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext


EXT_SUFFIX, _, _ = sysconfig.get_config_var("EXT_SUFFIX").rpartition(".")


def get_version():
version_file = "src/PIL/_version.py"
with open(version_file, encoding="utf-8") as f:
Expand Down Expand Up @@ -411,7 +415,7 @@ def _update_extension(self, name, libraries, define_macros=None, sources=None):
if FUZZING_BUILD:
extension.language = "c++"
extension.extra_link_args = ["--stdlib=libc++"]
break
return extension

def _remove_extension(self, name):
for extension in self.extensions:
Expand Down Expand Up @@ -854,7 +858,7 @@ def build_extensions(self):

defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"'))

self._update_extension("PIL._imaging", libs, defs)
self._update_extension("PIL.lib_imaging", libs, defs)

#
# additional libraries
Expand Down Expand Up @@ -891,8 +895,15 @@ def build_extensions(self):
self._remove_extension("PIL._imagingcms")

if feature.webp:
libs = [feature.webp, feature.webp + "mux", feature.webp + "demux"]
self._update_extension("PIL._webp", libs)
libs = [
f"_imaging{EXT_SUFFIX}",
feature.webp,
feature.webp + "mux",
feature.webp + "demux",
]
ext = self._update_extension("PIL._webp", libs)
ext.library_dirs.append(f"{self.build_lib}/PIL/")
ext.runtime_library_dirs.append("$ORIGIN")
else:
self._remove_extension("PIL._webp")

Expand Down Expand Up @@ -972,7 +983,7 @@ def debug_build():
for src_file in _LIB_IMAGING:
files.append(os.path.join("src/libImaging", src_file + ".c"))
ext_modules = [
Extension("PIL._imaging", files),
Extension("PIL.lib_imaging", files),
Extension("PIL._imagingft", ["src/_imagingft.c"]),
Extension("PIL._imagingcms", ["src/_imagingcms.c"]),
Extension("PIL._webp", ["src/_webp.c"]),
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ._deprecate import deprecate

modules = {
"pil": ("PIL._imaging", "PILLOW_VERSION"),
"pil": ("PIL.lib_imaging", "PILLOW_VERSION"),
"tkinter": ("PIL._tkinter_finder", "tk_version"),
"freetype2": ("PIL._imagingft", "freetype2_version"),
"littlecms2": ("PIL._imagingcms", "littlecms_version"),
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_supported_codecs() -> list[str]:
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
"libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"),
"libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"),
"xcb": ("PIL._imaging", "HAVE_XCB", None),
"xcb": ("PIL.lib_imaging", "HAVE_XCB", None),
}


Expand Down
4 changes: 2 additions & 2 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -4412,12 +4412,12 @@ setup_module(PyObject *m) {
}

PyMODINIT_FUNC
PyInit__imaging(void) {
PyInit_lib_imaging(void) {
PyObject *m;

static PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
"_imaging", /* m_name */
"lib_imaging", /* m_name */
NULL, /* m_doc */
-1, /* m_size */
functions, /* m_methods */
Expand Down
10 changes: 0 additions & 10 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
#error libwebp 0.5.0 and above is required. Upgrade libwebp or build Pillow with --disable-webp flag
#endif

void
ImagingSectionEnter(ImagingSectionCookie *cookie) {
*cookie = (PyThreadState *)PyEval_SaveThread();
}

void
ImagingSectionLeave(ImagingSectionCookie *cookie) {
PyEval_RestoreThread((PyThreadState *)*cookie);
}

/* -------------------------------------------------------------------- */
/* WebP Muxer Error Handling */
/* -------------------------------------------------------------------- */
Expand Down

0 comments on commit a3da224

Please sign in to comment.