Skip to content

Commit d8447de

Browse files
authored
Merge pull request #8211 from uploadcare/remove-c-flags
Remove all WITH_* flags from _imaging.c and other flags
2 parents 126af36 + 302962d commit d8447de

File tree

4 files changed

+68
-160
lines changed

4 files changed

+68
-160
lines changed

docs/releasenotes/11.0.0.rst

+7
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ others prepare for 3.13, and to ensure Pillow could be used immediately at the r
8585
of 3.13.0 final (2024-10-01, :pep:`719`).
8686

8787
Pillow 11.0.0 now officially supports Python 3.13.
88+
89+
C-level Flags
90+
^^^^^^^^^^^^^
91+
92+
Some compiling flags like ``WITH_THREADING``, ``WITH_IMAGECHOPS``, and other
93+
``WITH_*`` were removed. These flags were not available through the build system,
94+
but they could be edited in the C source.

src/_imaging.c

+11-93
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@
9494
#include <math.h>
9595
#include <stddef.h>
9696

97-
/* Configuration stuff. Feel free to undef things you don't need. */
98-
#define WITH_IMAGECHOPS /* ImageChops support */
99-
#define WITH_IMAGEDRAW /* ImageDraw support */
100-
#define WITH_MAPPING /* use memory mapping to read some file formats */
101-
#define WITH_IMAGEPATH /* ImagePath stuff */
102-
#define WITH_ARROW /* arrow graphics stuff (experimental) */
103-
#define WITH_EFFECTS /* special effects */
104-
#define WITH_QUANTIZE /* quantization support */
105-
#define WITH_RANKFILTER /* rank filter */
106-
#define WITH_MODEFILTER /* mode filter */
107-
#define WITH_THREADING /* "friendly" threading support */
108-
#define WITH_UNSHARPMASK /* Kevin Cazabon's unsharpmask module */
109-
11097
#undef VERBOSE
11198

11299
#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i) + 1])
@@ -124,8 +111,6 @@ typedef struct {
124111

125112
static PyTypeObject Imaging_Type;
126113

127-
#ifdef WITH_IMAGEDRAW
128-
129114
typedef struct {
130115
/* to write a character, cut out sxy from glyph data, place
131116
at current position plus dxy, and advance by (dx, dy) */
@@ -152,8 +137,6 @@ typedef struct {
152137

153138
static PyTypeObject ImagingDraw_Type;
154139

155-
#endif
156-
157140
typedef struct {
158141
PyObject_HEAD ImagingObject *image;
159142
int readonly;
@@ -216,16 +199,12 @@ PyImaging_AsImaging(PyObject *op) {
216199

217200
void
218201
ImagingSectionEnter(ImagingSectionCookie *cookie) {
219-
#ifdef WITH_THREADING
220202
*cookie = (PyThreadState *)PyEval_SaveThread();
221-
#endif
222203
}
223204

224205
void
225206
ImagingSectionLeave(ImagingSectionCookie *cookie) {
226-
#ifdef WITH_THREADING
227207
PyEval_RestoreThread((PyThreadState *)*cookie);
228-
#endif
229208
}
230209

231210
/* -------------------------------------------------------------------- */
@@ -1092,7 +1071,6 @@ _filter(ImagingObject *self, PyObject *args) {
10921071
return imOut;
10931072
}
10941073

1095-
#ifdef WITH_UNSHARPMASK
10961074
static PyObject *
10971075
_gaussian_blur(ImagingObject *self, PyObject *args) {
10981076
Imaging imIn;
@@ -1117,7 +1095,6 @@ _gaussian_blur(ImagingObject *self, PyObject *args) {
11171095

11181096
return PyImagingNew(imOut);
11191097
}
1120-
#endif
11211098

11221099
static PyObject *
11231100
_getpalette(ImagingObject *self, PyObject *args) {
@@ -1375,7 +1352,6 @@ _entropy(ImagingObject *self, PyObject *args) {
13751352
return PyFloat_FromDouble(-entropy);
13761353
}
13771354

1378-
#ifdef WITH_MODEFILTER
13791355
static PyObject *
13801356
_modefilter(ImagingObject *self, PyObject *args) {
13811357
int size;
@@ -1385,7 +1361,6 @@ _modefilter(ImagingObject *self, PyObject *args) {
13851361

13861362
return PyImagingNew(ImagingModeFilter(self->image, size));
13871363
}
1388-
#endif
13891364

13901365
static PyObject *
13911366
_offset(ImagingObject *self, PyObject *args) {
@@ -1717,8 +1692,6 @@ _putdata(ImagingObject *self, PyObject *args) {
17171692
return Py_None;
17181693
}
17191694

1720-
#ifdef WITH_QUANTIZE
1721-
17221695
static PyObject *
17231696
_quantize(ImagingObject *self, PyObject *args) {
17241697
int colours = 256;
@@ -1735,7 +1708,6 @@ _quantize(ImagingObject *self, PyObject *args) {
17351708

17361709
return PyImagingNew(ImagingQuantize(self->image, colours, method, kmeans));
17371710
}
1738-
#endif
17391711

17401712
static PyObject *
17411713
_putpalette(ImagingObject *self, PyObject *args) {
@@ -1871,7 +1843,6 @@ _putpixel(ImagingObject *self, PyObject *args) {
18711843
return Py_None;
18721844
}
18731845

1874-
#ifdef WITH_RANKFILTER
18751846
static PyObject *
18761847
_rankfilter(ImagingObject *self, PyObject *args) {
18771848
int size, rank;
@@ -1881,7 +1852,6 @@ _rankfilter(ImagingObject *self, PyObject *args) {
18811852

18821853
return PyImagingNew(ImagingRankFilter(self->image, size, rank));
18831854
}
1884-
#endif
18851855

18861856
static PyObject *
18871857
_resize(ImagingObject *self, PyObject *args) {
@@ -2163,7 +2133,6 @@ _transpose(ImagingObject *self, PyObject *args) {
21632133
return PyImagingNew(imOut);
21642134
}
21652135

2166-
#ifdef WITH_UNSHARPMASK
21672136
static PyObject *
21682137
_unsharp_mask(ImagingObject *self, PyObject *args) {
21692138
Imaging imIn;
@@ -2187,7 +2156,6 @@ _unsharp_mask(ImagingObject *self, PyObject *args) {
21872156

21882157
return PyImagingNew(imOut);
21892158
}
2190-
#endif
21912159

21922160
static PyObject *
21932161
_box_blur(ImagingObject *self, PyObject *args) {
@@ -2464,9 +2432,7 @@ _split(ImagingObject *self) {
24642432
return list;
24652433
}
24662434

2467-
/* -------------------------------------------------------------------- */
2468-
2469-
#ifdef WITH_IMAGECHOPS
2435+
/* Channel operations (ImageChops) ------------------------------------ */
24702436

24712437
static PyObject *
24722438
_chop_invert(ImagingObject *self) {
@@ -2647,11 +2613,8 @@ _chop_overlay(ImagingObject *self, PyObject *args) {
26472613

26482614
return PyImagingNew(ImagingOverlay(self->image, imagep->image));
26492615
}
2650-
#endif
26512616

2652-
/* -------------------------------------------------------------------- */
2653-
2654-
#ifdef WITH_IMAGEDRAW
2617+
/* Fonts (ImageDraw and ImageFont) ------------------------------------ */
26552618

26562619
static PyObject *
26572620
_font_new(PyObject *self_, PyObject *args) {
@@ -2880,7 +2843,7 @@ static struct PyMethodDef _font_methods[] = {
28802843
{NULL, NULL} /* sentinel */
28812844
};
28822845

2883-
/* -------------------------------------------------------------------- */
2846+
/* Graphics (ImageDraw) ----------------------------------------------- */
28842847

28852848
static PyObject *
28862849
_draw_new(PyObject *self_, PyObject *args) {
@@ -3234,8 +3197,6 @@ _draw_points(ImagingDrawObject *self, PyObject *args) {
32343197
return Py_None;
32353198
}
32363199

3237-
#ifdef WITH_ARROW
3238-
32393200
/* from outline.c */
32403201
extern ImagingOutline
32413202
PyOutline_AsOutline(PyObject *outline);
@@ -3265,8 +3226,6 @@ _draw_outline(ImagingDrawObject *self, PyObject *args) {
32653226
return Py_None;
32663227
}
32673228

3268-
#endif
3269-
32703229
static PyObject *
32713230
_draw_pieslice(ImagingDrawObject *self, PyObject *args) {
32723231
double *xy;
@@ -3432,12 +3391,9 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
34323391
}
34333392

34343393
static struct PyMethodDef _draw_methods[] = {
3435-
#ifdef WITH_IMAGEDRAW
34363394
/* Graphics (ImageDraw) */
34373395
{"draw_lines", (PyCFunction)_draw_lines, METH_VARARGS},
3438-
#ifdef WITH_ARROW
34393396
{"draw_outline", (PyCFunction)_draw_outline, METH_VARARGS},
3440-
#endif
34413397
{"draw_polygon", (PyCFunction)_draw_polygon, METH_VARARGS},
34423398
{"draw_rectangle", (PyCFunction)_draw_rectangle, METH_VARARGS},
34433399
{"draw_points", (PyCFunction)_draw_points, METH_VARARGS},
@@ -3447,12 +3403,9 @@ static struct PyMethodDef _draw_methods[] = {
34473403
{"draw_ellipse", (PyCFunction)_draw_ellipse, METH_VARARGS},
34483404
{"draw_pieslice", (PyCFunction)_draw_pieslice, METH_VARARGS},
34493405
{"draw_ink", (PyCFunction)_draw_ink, METH_VARARGS},
3450-
#endif
34513406
{NULL, NULL} /* sentinel */
34523407
};
34533408

3454-
#endif
3455-
34563409
static PyObject *
34573410
pixel_access_new(ImagingObject *imagep, PyObject *args) {
34583411
PixelAccessObject *self;
@@ -3533,11 +3486,9 @@ pixel_access_setitem(PixelAccessObject *self, PyObject *xy, PyObject *color) {
35333486
}
35343487

35353488
/* -------------------------------------------------------------------- */
3536-
/* EFFECTS (experimental) */
3489+
/* EFFECTS (experimental) */
35373490
/* -------------------------------------------------------------------- */
35383491

3539-
#ifdef WITH_EFFECTS
3540-
35413492
static PyObject *
35423493
_effect_mandelbrot(ImagingObject *self, PyObject *args) {
35433494
int xsize = 512;
@@ -3589,8 +3540,6 @@ _effect_spread(ImagingObject *self, PyObject *args) {
35893540
return PyImagingNew(ImagingEffectSpread(self->image, dist));
35903541
}
35913542

3592-
#endif
3593-
35943543
/* -------------------------------------------------------------------- */
35953544
/* UTILITIES */
35963545
/* -------------------------------------------------------------------- */
@@ -3671,20 +3620,14 @@ static struct PyMethodDef methods[] = {
36713620
{"filter", (PyCFunction)_filter, METH_VARARGS},
36723621
{"histogram", (PyCFunction)_histogram, METH_VARARGS},
36733622
{"entropy", (PyCFunction)_entropy, METH_VARARGS},
3674-
#ifdef WITH_MODEFILTER
36753623
{"modefilter", (PyCFunction)_modefilter, METH_VARARGS},
3676-
#endif
36773624
{"offset", (PyCFunction)_offset, METH_VARARGS},
36783625
{"paste", (PyCFunction)_paste, METH_VARARGS},
36793626
{"point", (PyCFunction)_point, METH_VARARGS},
36803627
{"point_transform", (PyCFunction)_point_transform, METH_VARARGS},
36813628
{"putdata", (PyCFunction)_putdata, METH_VARARGS},
3682-
#ifdef WITH_QUANTIZE
36833629
{"quantize", (PyCFunction)_quantize, METH_VARARGS},
3684-
#endif
3685-
#ifdef WITH_RANKFILTER
36863630
{"rankfilter", (PyCFunction)_rankfilter, METH_VARARGS},
3687-
#endif
36883631
{"resize", (PyCFunction)_resize, METH_VARARGS},
36893632
{"reduce", (PyCFunction)_reduce, METH_VARARGS},
36903633
{"transpose", (PyCFunction)_transpose, METH_VARARGS},
@@ -3710,7 +3653,6 @@ static struct PyMethodDef methods[] = {
37103653
{"putpalettealpha", (PyCFunction)_putpalettealpha, METH_VARARGS},
37113654
{"putpalettealphas", (PyCFunction)_putpalettealphas, METH_VARARGS},
37123655

3713-
#ifdef WITH_IMAGECHOPS
37143656
/* Channel operations (ImageChops) */
37153657
{"chop_invert", (PyCFunction)_chop_invert, METH_NOARGS},
37163658
{"chop_lighter", (PyCFunction)_chop_lighter, METH_VARARGS},
@@ -3729,20 +3671,14 @@ static struct PyMethodDef methods[] = {
37293671
{"chop_hard_light", (PyCFunction)_chop_hard_light, METH_VARARGS},
37303672
{"chop_overlay", (PyCFunction)_chop_overlay, METH_VARARGS},
37313673

3732-
#endif
3733-
3734-
#ifdef WITH_UNSHARPMASK
3735-
/* Kevin Cazabon's unsharpmask extension */
3674+
/* Unsharpmask extension */
37363675
{"gaussian_blur", (PyCFunction)_gaussian_blur, METH_VARARGS},
37373676
{"unsharp_mask", (PyCFunction)_unsharp_mask, METH_VARARGS},
3738-
#endif
37393677

37403678
{"box_blur", (PyCFunction)_box_blur, METH_VARARGS},
37413679

3742-
#ifdef WITH_EFFECTS
37433680
/* Special effects */
37443681
{"effect_spread", (PyCFunction)_effect_spread, METH_VARARGS},
3745-
#endif
37463682

37473683
/* Misc. */
37483684
{"new_block", (PyCFunction)_new_block, METH_VARARGS},
@@ -3871,8 +3807,6 @@ static PyTypeObject Imaging_Type = {
38713807
getsetters, /*tp_getset*/
38723808
};
38733809

3874-
#ifdef WITH_IMAGEDRAW
3875-
38763810
static PyTypeObject ImagingFont_Type = {
38773811
PyVarObject_HEAD_INIT(NULL, 0) "ImagingFont", /*tp_name*/
38783812
sizeof(ImagingFontObject), /*tp_basicsize*/
@@ -3939,8 +3873,6 @@ static PyTypeObject ImagingDraw_Type = {
39393873
0, /*tp_getset*/
39403874
};
39413875

3942-
#endif
3943-
39443876
static PyMappingMethods pixel_access_as_mapping = {
39453877
(lenfunc)NULL, /*mp_length*/
39463878
(binaryfunc)pixel_access_getitem, /*mp_subscript*/
@@ -4309,13 +4241,11 @@ static PyMethodDef functions[] = {
43094241
{"zip_encoder", (PyCFunction)PyImaging_ZipEncoderNew, METH_VARARGS},
43104242
#endif
43114243

4312-
/* Memory mapping */
4313-
#ifdef WITH_MAPPING
4244+
/* Memory mapping */
43144245
{"map_buffer", (PyCFunction)PyImaging_MapBuffer, METH_VARARGS},
4315-
#endif
43164246

4317-
/* Display support */
43184247
#ifdef _WIN32
4248+
/* Display support */
43194249
{"display", (PyCFunction)PyImaging_DisplayWin32, METH_VARARGS},
43204250
{"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, METH_VARARGS},
43214251
{"grabscreen_win32", (PyCFunction)PyImaging_GrabScreenWin32, METH_VARARGS},
@@ -4331,30 +4261,22 @@ static PyMethodDef functions[] = {
43314261
/* Utilities */
43324262
{"getcodecstatus", (PyCFunction)_getcodecstatus, METH_VARARGS},
43334263

4334-
/* Special effects (experimental) */
4335-
#ifdef WITH_EFFECTS
4264+
/* Special effects (experimental) */
43364265
{"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, METH_VARARGS},
43374266
{"effect_noise", (PyCFunction)_effect_noise, METH_VARARGS},
43384267
{"linear_gradient", (PyCFunction)_linear_gradient, METH_VARARGS},
43394268
{"radial_gradient", (PyCFunction)_radial_gradient, METH_VARARGS},
43404269
{"wedge", (PyCFunction)_linear_gradient, METH_VARARGS}, /* Compatibility */
4341-
#endif
43424270

4343-
/* Drawing support stuff */
4344-
#ifdef WITH_IMAGEDRAW
4271+
/* Drawing support stuff */
43454272
{"font", (PyCFunction)_font_new, METH_VARARGS},
43464273
{"draw", (PyCFunction)_draw_new, METH_VARARGS},
4347-
#endif
43484274

4349-
/* Experimental path stuff */
4350-
#ifdef WITH_IMAGEPATH
4275+
/* Experimental path stuff */
43514276
{"path", (PyCFunction)PyPath_Create, METH_VARARGS},
4352-
#endif
43534277

4354-
/* Experimental arrow graphics stuff */
4355-
#ifdef WITH_ARROW
4278+
/* Experimental arrow graphics stuff */
43564279
{"outline", (PyCFunction)PyOutline_Create, METH_VARARGS},
4357-
#endif
43584280

43594281
/* Resource management */
43604282
{"get_stats", (PyCFunction)_get_stats, METH_VARARGS},
@@ -4379,16 +4301,12 @@ setup_module(PyObject *m) {
43794301
if (PyType_Ready(&Imaging_Type) < 0) {
43804302
return -1;
43814303
}
4382-
4383-
#ifdef WITH_IMAGEDRAW
43844304
if (PyType_Ready(&ImagingFont_Type) < 0) {
43854305
return -1;
43864306
}
4387-
43884307
if (PyType_Ready(&ImagingDraw_Type) < 0) {
43894308
return -1;
43904309
}
4391-
#endif
43924310
if (PyType_Ready(&PixelAccess_Type) < 0) {
43934311
return -1;
43944312
}

0 commit comments

Comments
 (0)