Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_embeddable(self) -> None:
home = sys.prefix.replace("\\", "\\\\")
fh.write(
f"""
#include "Python.h"
#include <Python.h>

int main(int argc, char* argv[])
{{
Expand Down
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
24 changes: 16 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
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"
Expand Down Expand Up @@ -333,7 +336,6 @@ def __iter__(self):
("disable-platform-guessing", None, "Disable platform guessing on Linux"),
("debug", None, "Debug logging"),
]
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
)

@staticmethod
Expand All @@ -344,7 +346,6 @@ def initialize_options(self):
self.disable_platform_guessing = self.check_configuration(
"platform-guessing", "disable"
)
self.add_imaging_libs = ""
build_ext.initialize_options(self)
for x in self.feature:
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
Expand Down Expand Up @@ -413,7 +414,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 @@ -821,7 +822,7 @@ def build_extensions(self):
#
# core library

libs = self.add_imaging_libs.split()
libs = []
defs = []
if feature.tiff:
libs.append(feature.tiff)
Expand Down Expand Up @@ -856,7 +857,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 @@ -893,8 +894,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 @@ -974,7 +982,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
15 changes: 5 additions & 10 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
* See the README file for information on usage and redistribution.
*/

#define PY_SSIZE_T_CLEAN
#include "Python.h"

#ifdef HAVE_LIBJPEG
#include "jconfig.h"
#endif
Expand All @@ -90,8 +87,6 @@

#include "libImaging/Imaging.h"

#define _USE_MATH_DEFINES
#include <math.h>
#include <stddef.h>

#undef VERBOSE
Expand Down Expand Up @@ -4417,15 +4412,15 @@ 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 */
NULL, /* m_doc */
-1, /* m_size */
functions, /* m_methods */
"lib_imaging", /* m_name */
NULL, /* m_doc */
-1, /* m_size */
functions, /* m_methods */
};

m = PyModule_Create(&module_def);
Expand Down
18 changes: 4 additions & 14 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ [email protected]\n\
https://www.cazabon.com\n\
"

#define PY_SSIZE_T_CLEAN
#include "Python.h" // Include before wchar.h so _GNU_SOURCE is set
#include "wchar.h"
#include "datetime.h"
#include "libImaging/Imaging.h" // Include before wchar.h so _GNU_SOURCE is set

#include "lcms2.h"
#include "libImaging/Imaging.h"

#define PYCMSVERSION "1.0.0 pil"
#include <wchar.h>
#include <datetime.h>
#include <lcms2.h>

/* version history */

Expand Down Expand Up @@ -619,12 +615,6 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) {

#ifdef _WIN32

#ifdef _WIN64
#define F_HANDLE "K"
#else
#define F_HANDLE "k"
#endif

static PyObject *
cms_get_display_profile_win32(PyObject *self, PyObject *args) {
char filename[MAX_PATH];
Expand Down
4 changes: 1 addition & 3 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
* Copyright (c) 1998-2007 by Secret Labs AB
*/

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "thirdparty/pythoncapi_compat.h"
#include "libImaging/Imaging.h"
#include "thirdparty/pythoncapi_compat.h"

#include <ft2build.h>
#include FT_FREETYPE_H
Expand Down
5 changes: 1 addition & 4 deletions src/_imagingmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
* See the README file for information on usage and redistribution.
*/

#include "Python.h"

#include "libImaging/Imaging.h"

#include "math.h"
#include "float.h"
#include <float.h>

#define MAX_INT32 2147483647.0
#define MIN_INT32 -2147483648.0
Expand Down
1 change: 0 additions & 1 deletion src/_imagingmorph.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* See the README file for information on usage and redistribution.
*/

#include "Python.h"
#include "libImaging/Imaging.h"

#define LUT_SIZE (1 << 9)
Expand Down
1 change: 0 additions & 1 deletion src/_imagingtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* See the README file for information on usage and redistribution.
*/

#include "Python.h"
#include "libImaging/Imaging.h"

#include "Tk/_tkmini.h"
Expand Down
13 changes: 1 addition & 12 deletions src/_webp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "libImaging/Imaging.h"

#include <webp/encode.h>
#include <webp/decode.h>
#include <webp/types.h>
Expand All @@ -17,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
4 changes: 0 additions & 4 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@

/* FIXME: make these pluggable! */

#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "libImaging/Imaging.h"

#include "libImaging/Bit.h"
#include "libImaging/Bcn.h"
#include "libImaging/Gif.h"
Expand Down
9 changes: 0 additions & 9 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* See the README file for information on usage and redistribution.
*/

#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "libImaging/Imaging.h"

/* -------------------------------------------------------------------- */
Expand All @@ -34,12 +31,6 @@

#include "libImaging/ImDib.h"

#if SIZEOF_VOID_P == 8
#define F_HANDLE "K"
#else
#define F_HANDLE "k"
#endif

typedef struct {
PyObject_HEAD ImagingDIB dib;
} ImagingDisplayObject;
Expand Down
12 changes: 1 addition & 11 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@

/* FIXME: make these pluggable! */

#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "thirdparty/pythoncapi_compat.h"
#include "libImaging/Imaging.h"
#include "thirdparty/pythoncapi_compat.h"
#include "libImaging/Gif.h"

#ifdef HAVE_UNISTD_H
Expand Down Expand Up @@ -1411,10 +1408,3 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
}

#endif

/*
* Local Variables:
* c-basic-offset: 4
* End:
*
*/
1 change: 0 additions & 1 deletion src/libImaging/ColorLUT.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Imaging.h"
#include <math.h>

/* 8 bits for result. Table can overflow [0, 1.0] range,
so we need extra bits for overflow and negative values.
Expand Down
3 changes: 1 addition & 2 deletions src/libImaging/Dib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
* See the README file for information on usage and redistribution.
*/

#include "Imaging.h"

#ifdef _WIN32

#include "Imaging.h"
#include "ImDib.h"

char *
Expand Down
3 changes: 0 additions & 3 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@

#include "Imaging.h"

#include <math.h>
#include <stdint.h>

#define CEIL(v) (int)ceil(v)
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))

Expand Down
2 changes: 0 additions & 2 deletions src/libImaging/Effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "Imaging.h"

#include <math.h>

Imaging
ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) {
/* Generate a Mandelbrot set covering the given extent */
Expand Down
2 changes: 0 additions & 2 deletions src/libImaging/Fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "Imaging.h"

#include "math.h"

Imaging
ImagingFill(Imaging im, const void *colour) {
int x, y;
Expand Down
2 changes: 0 additions & 2 deletions src/libImaging/ImDib.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#ifdef _WIN32

#include "ImPlatform.h"

#if defined(__cplusplus)
extern "C" {
#endif
Expand Down
6 changes: 1 addition & 5 deletions src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
* See the README file for information on usage and redistribution.
*/

#include "ImPlatform.h"
#include "ImagingPlatform.h"

#if defined(__cplusplus)
extern "C" {
#endif

#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif

/* -------------------------------------------------------------------- */

/*
Expand Down
Loading