94
94
#include <math.h>
95
95
#include <stddef.h>
96
96
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
-
110
97
#undef VERBOSE
111
98
112
99
#define B16 (p , i ) ((((int)p[(i)]) << 8) + p[(i) + 1])
@@ -124,8 +111,6 @@ typedef struct {
124
111
125
112
static PyTypeObject Imaging_Type ;
126
113
127
- #ifdef WITH_IMAGEDRAW
128
-
129
114
typedef struct {
130
115
/* to write a character, cut out sxy from glyph data, place
131
116
at current position plus dxy, and advance by (dx, dy) */
@@ -152,8 +137,6 @@ typedef struct {
152
137
153
138
static PyTypeObject ImagingDraw_Type ;
154
139
155
- #endif
156
-
157
140
typedef struct {
158
141
PyObject_HEAD ImagingObject * image ;
159
142
int readonly ;
@@ -216,16 +199,12 @@ PyImaging_AsImaging(PyObject *op) {
216
199
217
200
void
218
201
ImagingSectionEnter (ImagingSectionCookie * cookie ) {
219
- #ifdef WITH_THREADING
220
202
* cookie = (PyThreadState * )PyEval_SaveThread ();
221
- #endif
222
203
}
223
204
224
205
void
225
206
ImagingSectionLeave (ImagingSectionCookie * cookie ) {
226
- #ifdef WITH_THREADING
227
207
PyEval_RestoreThread ((PyThreadState * )* cookie );
228
- #endif
229
208
}
230
209
231
210
/* -------------------------------------------------------------------- */
@@ -1092,7 +1071,6 @@ _filter(ImagingObject *self, PyObject *args) {
1092
1071
return imOut ;
1093
1072
}
1094
1073
1095
- #ifdef WITH_UNSHARPMASK
1096
1074
static PyObject *
1097
1075
_gaussian_blur (ImagingObject * self , PyObject * args ) {
1098
1076
Imaging imIn ;
@@ -1117,7 +1095,6 @@ _gaussian_blur(ImagingObject *self, PyObject *args) {
1117
1095
1118
1096
return PyImagingNew (imOut );
1119
1097
}
1120
- #endif
1121
1098
1122
1099
static PyObject *
1123
1100
_getpalette (ImagingObject * self , PyObject * args ) {
@@ -1375,7 +1352,6 @@ _entropy(ImagingObject *self, PyObject *args) {
1375
1352
return PyFloat_FromDouble (- entropy );
1376
1353
}
1377
1354
1378
- #ifdef WITH_MODEFILTER
1379
1355
static PyObject *
1380
1356
_modefilter (ImagingObject * self , PyObject * args ) {
1381
1357
int size ;
@@ -1385,7 +1361,6 @@ _modefilter(ImagingObject *self, PyObject *args) {
1385
1361
1386
1362
return PyImagingNew (ImagingModeFilter (self -> image , size ));
1387
1363
}
1388
- #endif
1389
1364
1390
1365
static PyObject *
1391
1366
_offset (ImagingObject * self , PyObject * args ) {
@@ -1717,8 +1692,6 @@ _putdata(ImagingObject *self, PyObject *args) {
1717
1692
return Py_None ;
1718
1693
}
1719
1694
1720
- #ifdef WITH_QUANTIZE
1721
-
1722
1695
static PyObject *
1723
1696
_quantize (ImagingObject * self , PyObject * args ) {
1724
1697
int colours = 256 ;
@@ -1735,7 +1708,6 @@ _quantize(ImagingObject *self, PyObject *args) {
1735
1708
1736
1709
return PyImagingNew (ImagingQuantize (self -> image , colours , method , kmeans ));
1737
1710
}
1738
- #endif
1739
1711
1740
1712
static PyObject *
1741
1713
_putpalette (ImagingObject * self , PyObject * args ) {
@@ -1871,7 +1843,6 @@ _putpixel(ImagingObject *self, PyObject *args) {
1871
1843
return Py_None ;
1872
1844
}
1873
1845
1874
- #ifdef WITH_RANKFILTER
1875
1846
static PyObject *
1876
1847
_rankfilter (ImagingObject * self , PyObject * args ) {
1877
1848
int size , rank ;
@@ -1881,7 +1852,6 @@ _rankfilter(ImagingObject *self, PyObject *args) {
1881
1852
1882
1853
return PyImagingNew (ImagingRankFilter (self -> image , size , rank ));
1883
1854
}
1884
- #endif
1885
1855
1886
1856
static PyObject *
1887
1857
_resize (ImagingObject * self , PyObject * args ) {
@@ -2163,7 +2133,6 @@ _transpose(ImagingObject *self, PyObject *args) {
2163
2133
return PyImagingNew (imOut );
2164
2134
}
2165
2135
2166
- #ifdef WITH_UNSHARPMASK
2167
2136
static PyObject *
2168
2137
_unsharp_mask (ImagingObject * self , PyObject * args ) {
2169
2138
Imaging imIn ;
@@ -2187,7 +2156,6 @@ _unsharp_mask(ImagingObject *self, PyObject *args) {
2187
2156
2188
2157
return PyImagingNew (imOut );
2189
2158
}
2190
- #endif
2191
2159
2192
2160
static PyObject *
2193
2161
_box_blur (ImagingObject * self , PyObject * args ) {
@@ -2464,9 +2432,7 @@ _split(ImagingObject *self) {
2464
2432
return list ;
2465
2433
}
2466
2434
2467
- /* -------------------------------------------------------------------- */
2468
-
2469
- #ifdef WITH_IMAGECHOPS
2435
+ /* Channel operations (ImageChops) ------------------------------------ */
2470
2436
2471
2437
static PyObject *
2472
2438
_chop_invert (ImagingObject * self ) {
@@ -2647,11 +2613,8 @@ _chop_overlay(ImagingObject *self, PyObject *args) {
2647
2613
2648
2614
return PyImagingNew (ImagingOverlay (self -> image , imagep -> image ));
2649
2615
}
2650
- #endif
2651
2616
2652
- /* -------------------------------------------------------------------- */
2653
-
2654
- #ifdef WITH_IMAGEDRAW
2617
+ /* Fonts (ImageDraw and ImageFont) ------------------------------------ */
2655
2618
2656
2619
static PyObject *
2657
2620
_font_new (PyObject * self_ , PyObject * args ) {
@@ -2880,7 +2843,7 @@ static struct PyMethodDef _font_methods[] = {
2880
2843
{NULL , NULL } /* sentinel */
2881
2844
};
2882
2845
2883
- /* --------------------- ----------------------------------------------- */
2846
+ /* Graphics (ImageDraw) ----------------------------------------------- */
2884
2847
2885
2848
static PyObject *
2886
2849
_draw_new (PyObject * self_ , PyObject * args ) {
@@ -3234,8 +3197,6 @@ _draw_points(ImagingDrawObject *self, PyObject *args) {
3234
3197
return Py_None ;
3235
3198
}
3236
3199
3237
- #ifdef WITH_ARROW
3238
-
3239
3200
/* from outline.c */
3240
3201
extern ImagingOutline
3241
3202
PyOutline_AsOutline (PyObject * outline );
@@ -3265,8 +3226,6 @@ _draw_outline(ImagingDrawObject *self, PyObject *args) {
3265
3226
return Py_None ;
3266
3227
}
3267
3228
3268
- #endif
3269
-
3270
3229
static PyObject *
3271
3230
_draw_pieslice (ImagingDrawObject * self , PyObject * args ) {
3272
3231
double * xy ;
@@ -3432,12 +3391,9 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
3432
3391
}
3433
3392
3434
3393
static struct PyMethodDef _draw_methods [] = {
3435
- #ifdef WITH_IMAGEDRAW
3436
3394
/* Graphics (ImageDraw) */
3437
3395
{"draw_lines" , (PyCFunction )_draw_lines , METH_VARARGS },
3438
- #ifdef WITH_ARROW
3439
3396
{"draw_outline" , (PyCFunction )_draw_outline , METH_VARARGS },
3440
- #endif
3441
3397
{"draw_polygon" , (PyCFunction )_draw_polygon , METH_VARARGS },
3442
3398
{"draw_rectangle" , (PyCFunction )_draw_rectangle , METH_VARARGS },
3443
3399
{"draw_points" , (PyCFunction )_draw_points , METH_VARARGS },
@@ -3447,12 +3403,9 @@ static struct PyMethodDef _draw_methods[] = {
3447
3403
{"draw_ellipse" , (PyCFunction )_draw_ellipse , METH_VARARGS },
3448
3404
{"draw_pieslice" , (PyCFunction )_draw_pieslice , METH_VARARGS },
3449
3405
{"draw_ink" , (PyCFunction )_draw_ink , METH_VARARGS },
3450
- #endif
3451
3406
{NULL , NULL } /* sentinel */
3452
3407
};
3453
3408
3454
- #endif
3455
-
3456
3409
static PyObject *
3457
3410
pixel_access_new (ImagingObject * imagep , PyObject * args ) {
3458
3411
PixelAccessObject * self ;
@@ -3533,11 +3486,9 @@ pixel_access_setitem(PixelAccessObject *self, PyObject *xy, PyObject *color) {
3533
3486
}
3534
3487
3535
3488
/* -------------------------------------------------------------------- */
3536
- /* EFFECTS (experimental) */
3489
+ /* EFFECTS (experimental) */
3537
3490
/* -------------------------------------------------------------------- */
3538
3491
3539
- #ifdef WITH_EFFECTS
3540
-
3541
3492
static PyObject *
3542
3493
_effect_mandelbrot (ImagingObject * self , PyObject * args ) {
3543
3494
int xsize = 512 ;
@@ -3589,8 +3540,6 @@ _effect_spread(ImagingObject *self, PyObject *args) {
3589
3540
return PyImagingNew (ImagingEffectSpread (self -> image , dist ));
3590
3541
}
3591
3542
3592
- #endif
3593
-
3594
3543
/* -------------------------------------------------------------------- */
3595
3544
/* UTILITIES */
3596
3545
/* -------------------------------------------------------------------- */
@@ -3671,20 +3620,14 @@ static struct PyMethodDef methods[] = {
3671
3620
{"filter" , (PyCFunction )_filter , METH_VARARGS },
3672
3621
{"histogram" , (PyCFunction )_histogram , METH_VARARGS },
3673
3622
{"entropy" , (PyCFunction )_entropy , METH_VARARGS },
3674
- #ifdef WITH_MODEFILTER
3675
3623
{"modefilter" , (PyCFunction )_modefilter , METH_VARARGS },
3676
- #endif
3677
3624
{"offset" , (PyCFunction )_offset , METH_VARARGS },
3678
3625
{"paste" , (PyCFunction )_paste , METH_VARARGS },
3679
3626
{"point" , (PyCFunction )_point , METH_VARARGS },
3680
3627
{"point_transform" , (PyCFunction )_point_transform , METH_VARARGS },
3681
3628
{"putdata" , (PyCFunction )_putdata , METH_VARARGS },
3682
- #ifdef WITH_QUANTIZE
3683
3629
{"quantize" , (PyCFunction )_quantize , METH_VARARGS },
3684
- #endif
3685
- #ifdef WITH_RANKFILTER
3686
3630
{"rankfilter" , (PyCFunction )_rankfilter , METH_VARARGS },
3687
- #endif
3688
3631
{"resize" , (PyCFunction )_resize , METH_VARARGS },
3689
3632
{"reduce" , (PyCFunction )_reduce , METH_VARARGS },
3690
3633
{"transpose" , (PyCFunction )_transpose , METH_VARARGS },
@@ -3710,7 +3653,6 @@ static struct PyMethodDef methods[] = {
3710
3653
{"putpalettealpha" , (PyCFunction )_putpalettealpha , METH_VARARGS },
3711
3654
{"putpalettealphas" , (PyCFunction )_putpalettealphas , METH_VARARGS },
3712
3655
3713
- #ifdef WITH_IMAGECHOPS
3714
3656
/* Channel operations (ImageChops) */
3715
3657
{"chop_invert" , (PyCFunction )_chop_invert , METH_NOARGS },
3716
3658
{"chop_lighter" , (PyCFunction )_chop_lighter , METH_VARARGS },
@@ -3729,20 +3671,14 @@ static struct PyMethodDef methods[] = {
3729
3671
{"chop_hard_light" , (PyCFunction )_chop_hard_light , METH_VARARGS },
3730
3672
{"chop_overlay" , (PyCFunction )_chop_overlay , METH_VARARGS },
3731
3673
3732
- #endif
3733
-
3734
- #ifdef WITH_UNSHARPMASK
3735
- /* Kevin Cazabon's unsharpmask extension */
3674
+ /* Unsharpmask extension */
3736
3675
{"gaussian_blur" , (PyCFunction )_gaussian_blur , METH_VARARGS },
3737
3676
{"unsharp_mask" , (PyCFunction )_unsharp_mask , METH_VARARGS },
3738
- #endif
3739
3677
3740
3678
{"box_blur" , (PyCFunction )_box_blur , METH_VARARGS },
3741
3679
3742
- #ifdef WITH_EFFECTS
3743
3680
/* Special effects */
3744
3681
{"effect_spread" , (PyCFunction )_effect_spread , METH_VARARGS },
3745
- #endif
3746
3682
3747
3683
/* Misc. */
3748
3684
{"new_block" , (PyCFunction )_new_block , METH_VARARGS },
@@ -3871,8 +3807,6 @@ static PyTypeObject Imaging_Type = {
3871
3807
getsetters , /*tp_getset*/
3872
3808
};
3873
3809
3874
- #ifdef WITH_IMAGEDRAW
3875
-
3876
3810
static PyTypeObject ImagingFont_Type = {
3877
3811
PyVarObject_HEAD_INIT (NULL , 0 ) "ImagingFont" , /*tp_name*/
3878
3812
sizeof (ImagingFontObject ), /*tp_basicsize*/
@@ -3939,8 +3873,6 @@ static PyTypeObject ImagingDraw_Type = {
3939
3873
0 , /*tp_getset*/
3940
3874
};
3941
3875
3942
- #endif
3943
-
3944
3876
static PyMappingMethods pixel_access_as_mapping = {
3945
3877
(lenfunc )NULL , /*mp_length*/
3946
3878
(binaryfunc )pixel_access_getitem , /*mp_subscript*/
@@ -4309,13 +4241,11 @@ static PyMethodDef functions[] = {
4309
4241
{"zip_encoder" , (PyCFunction )PyImaging_ZipEncoderNew , METH_VARARGS },
4310
4242
#endif
4311
4243
4312
- /* Memory mapping */
4313
- #ifdef WITH_MAPPING
4244
+ /* Memory mapping */
4314
4245
{"map_buffer" , (PyCFunction )PyImaging_MapBuffer , METH_VARARGS },
4315
- #endif
4316
4246
4317
- /* Display support */
4318
4247
#ifdef _WIN32
4248
+ /* Display support */
4319
4249
{"display" , (PyCFunction )PyImaging_DisplayWin32 , METH_VARARGS },
4320
4250
{"display_mode" , (PyCFunction )PyImaging_DisplayModeWin32 , METH_VARARGS },
4321
4251
{"grabscreen_win32" , (PyCFunction )PyImaging_GrabScreenWin32 , METH_VARARGS },
@@ -4331,30 +4261,22 @@ static PyMethodDef functions[] = {
4331
4261
/* Utilities */
4332
4262
{"getcodecstatus" , (PyCFunction )_getcodecstatus , METH_VARARGS },
4333
4263
4334
- /* Special effects (experimental) */
4335
- #ifdef WITH_EFFECTS
4264
+ /* Special effects (experimental) */
4336
4265
{"effect_mandelbrot" , (PyCFunction )_effect_mandelbrot , METH_VARARGS },
4337
4266
{"effect_noise" , (PyCFunction )_effect_noise , METH_VARARGS },
4338
4267
{"linear_gradient" , (PyCFunction )_linear_gradient , METH_VARARGS },
4339
4268
{"radial_gradient" , (PyCFunction )_radial_gradient , METH_VARARGS },
4340
4269
{"wedge" , (PyCFunction )_linear_gradient , METH_VARARGS }, /* Compatibility */
4341
- #endif
4342
4270
4343
- /* Drawing support stuff */
4344
- #ifdef WITH_IMAGEDRAW
4271
+ /* Drawing support stuff */
4345
4272
{"font" , (PyCFunction )_font_new , METH_VARARGS },
4346
4273
{"draw" , (PyCFunction )_draw_new , METH_VARARGS },
4347
- #endif
4348
4274
4349
- /* Experimental path stuff */
4350
- #ifdef WITH_IMAGEPATH
4275
+ /* Experimental path stuff */
4351
4276
{"path" , (PyCFunction )PyPath_Create , METH_VARARGS },
4352
- #endif
4353
4277
4354
- /* Experimental arrow graphics stuff */
4355
- #ifdef WITH_ARROW
4278
+ /* Experimental arrow graphics stuff */
4356
4279
{"outline" , (PyCFunction )PyOutline_Create , METH_VARARGS },
4357
- #endif
4358
4280
4359
4281
/* Resource management */
4360
4282
{"get_stats" , (PyCFunction )_get_stats , METH_VARARGS },
@@ -4379,16 +4301,12 @@ setup_module(PyObject *m) {
4379
4301
if (PyType_Ready (& Imaging_Type ) < 0 ) {
4380
4302
return -1 ;
4381
4303
}
4382
-
4383
- #ifdef WITH_IMAGEDRAW
4384
4304
if (PyType_Ready (& ImagingFont_Type ) < 0 ) {
4385
4305
return -1 ;
4386
4306
}
4387
-
4388
4307
if (PyType_Ready (& ImagingDraw_Type ) < 0 ) {
4389
4308
return -1 ;
4390
4309
}
4391
- #endif
4392
4310
if (PyType_Ready (& PixelAccess_Type ) < 0 ) {
4393
4311
return -1 ;
4394
4312
}
0 commit comments