2
* The Python Imaging Library.
4
* the imaging library bindings
7
* 1995-09-24 fl Created
8
* 1996-03-24 fl Ready for first public release (release 0.0)
9
* 1996-03-25 fl Added fromstring (for Jack's "img" library)
10
* 1996-03-28 fl Added channel operations
11
* 1996-03-31 fl Added point operation
12
* 1996-04-08 fl Added new/new_block/new_array factories
13
* 1996-04-13 fl Added decoders
14
* 1996-05-04 fl Added palette hack
15
* 1996-05-12 fl Compile cleanly as C++
16
* 1996-05-19 fl Added matrix conversions, gradient fills
17
* 1996-05-27 fl Added display_mode
18
* 1996-07-22 fl Added getbbox, offset
19
* 1996-07-23 fl Added sequence semantics
20
* 1996-08-13 fl Added logical operators, point mode
21
* 1996-08-16 fl Modified paste interface
22
* 1996-09-06 fl Added putdata methods, use abstract interface
23
* 1996-11-01 fl Added xbm encoder
24
* 1996-11-04 fl Added experimental path stuff, draw_lines, etc
25
* 1996-12-10 fl Added zip decoder, crc32 interface
26
* 1996-12-14 fl Added modulo arithmetics
27
* 1996-12-29 fl Added zip encoder
28
* 1997-01-03 fl Added fli and msp decoders
29
* 1997-01-04 fl Added experimental sun_rle and tga_rle decoders
30
* 1997-01-05 fl Added gif encoder, getpalette hack
31
* 1997-02-23 fl Added histogram mask
32
* 1997-05-12 fl Minor tweaks to match the IFUNC95 interface
33
* 1997-05-21 fl Added noise generator, spread effect
34
* 1997-06-05 fl Added mandelbrot generator
35
* 1997-08-02 fl Modified putpalette to coerce image mode if necessary
36
* 1998-01-11 fl Added INT32 support
37
* 1998-01-22 fl Fixed draw_points to draw the last point too
38
* 1998-06-28 fl Added getpixel, getink, draw_ink
39
* 1998-07-12 fl Added getextrema
40
* 1998-07-17 fl Added point conversion to arbitrary formats
41
* 1998-09-21 fl Added support for resampling filters
42
* 1998-09-22 fl Added support for quad transform
43
* 1998-12-29 fl Added support for arcs, chords, and pieslices
44
* 1999-01-10 fl Added some experimental arrow graphics stuff
45
* 1999-02-06 fl Added draw_bitmap, font acceleration stuff
46
* 2001-04-17 fl Fixed some egcs compiler nits
47
* 2001-09-17 fl Added screen grab primitives (win32)
48
* 2002-03-09 fl Added stretch primitive
49
* 2002-03-10 fl Fixed filter handling in rotate
50
* 2002-06-06 fl Added I, F, and RGB support to putdata
51
* 2002-06-08 fl Added rankfilter
52
* 2002-06-09 fl Added support for user-defined filter kernels
53
* 2002-11-19 fl Added clipboard grab primitives (win32)
54
* 2002-12-11 fl Added draw context
55
* 2003-04-26 fl Tweaks for Python 2.3 beta 1
56
* 2003-05-21 fl Added createwindow primitive (win32)
57
* 2003-09-13 fl Added thread section hooks
58
* 2003-09-15 fl Added expand helper
59
* 2003-09-26 fl Added experimental LA support
60
* 2004-02-21 fl Handle zero-size images in quantize
61
* 2004-06-05 fl Added ptr attribute (used to access Imaging objects)
62
* 2004-06-05 fl Don't crash when fetching pixels from zero-wide images
63
* 2004-09-17 fl Added getcolors
64
* 2004-10-04 fl Added modefilter
65
* 2005-10-02 fl Added access proxy
66
* 2006-06-18 fl Always draw last point in polyline
68
* Copyright (c) 1997-2006 by Secret Labs AB
69
* Copyright (c) 1995-2006 by Fredrik Lundh
71
* See the README file for information on usage and redistribution.
80
/* Configuration stuff. Feel free to undef things you don't need. */
81
#define WITH_IMAGECHOPS /* ImageChops support */
82
#define WITH_IMAGEDRAW /* ImageDraw support */
83
#define WITH_MAPPING /* use memory mapping to read some file formats */
84
#define WITH_IMAGEPATH /* ImagePath stuff */
85
#define WITH_ARROW /* arrow graphics stuff (experimental) */
86
#define WITH_EFFECTS /* special effects */
87
#define WITH_QUANTIZE /* quantization support */
88
#define WITH_RANKFILTER /* rank filter */
89
#define WITH_MODEFILTER /* mode filter */
90
#define WITH_THREADING /* "friendly" threading support */
91
#define WITH_UNSHARPMASK /* Kevin Cazabon's unsharpmask module */
93
#define WITH_DEBUG /* extra debugging interfaces */
95
/* PIL Plus extensions */
96
#undef WITH_CRACKCODE /* pil plus */
100
#define CLIP(x) ((x) <= 0 ? 0 : (x) < 256 ? (x) : 255)
102
#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i)+1])
103
#define L16(p, i) ((((int)p[(i)+1]) << 8) + p[(i)])
104
#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536))
106
#if PY_VERSION_HEX < 0x01060000
107
#define PyObject_New PyObject_NEW
108
#define PyObject_Del PyMem_DEL
111
#if PY_VERSION_HEX < 0x02050000
112
#define Py_ssize_t int
113
#define ssizeargfunc intargfunc
114
#define ssizessizeargfunc intintargfunc
115
#define ssizeobjargproc intobjargproc
116
#define ssizessizeobjargproc intintobjargproc
119
/* -------------------------------------------------------------------- */
120
/* OBJECT ADMINISTRATION */
121
/* -------------------------------------------------------------------- */
126
ImagingAccess access;
129
staticforward PyTypeObject Imaging_Type;
131
#ifdef WITH_IMAGEDRAW
135
/* to write a character, cut out sxy from glyph data, place
136
at current position plus dxy, and advance by (dx, dy) */
138
int dx0, dy0, dx1, dy1;
139
int sx0, sy0, sx1, sy1;
151
staticforward PyTypeObject ImagingFont_Type;
155
ImagingObject* image;
160
staticforward PyTypeObject ImagingDraw_Type;
166
ImagingObject* image;
170
staticforward PyTypeObject PixelAccess_Type;
173
PyImagingNew(Imaging imOut)
175
ImagingObject* imagep;
180
imagep = PyObject_New(ImagingObject, &Imaging_Type);
181
if (imagep == NULL) {
182
ImagingDelete(imOut);
187
printf("imaging %p allocated\n", imagep);
190
imagep->image = imOut;
191
imagep->access = ImagingAccessNew(imOut);
193
return (PyObject*) imagep;
197
_dealloc(ImagingObject* imagep)
201
printf("imaging %p deleted\n", imagep);
205
ImagingAccessDelete(imagep->image, imagep->access);
206
ImagingDelete(imagep->image);
207
PyObject_Del(imagep);
210
#define PyImaging_Check(op) ((op)->ob_type == &Imaging_Type)
212
Imaging PyImaging_AsImaging(PyObject *op)
214
if (!PyImaging_Check(op)) {
215
PyErr_BadInternalCall();
219
return ((ImagingObject *)op)->image;
223
/* -------------------------------------------------------------------- */
224
/* THREAD HANDLING */
225
/* -------------------------------------------------------------------- */
227
void ImagingSectionEnter(ImagingSectionCookie* cookie)
229
#ifdef WITH_THREADING
230
*cookie = (PyThreadState *) PyEval_SaveThread();
234
void ImagingSectionLeave(ImagingSectionCookie* cookie)
236
#ifdef WITH_THREADING
237
PyEval_RestoreThread((PyThreadState*) *cookie);
241
/* -------------------------------------------------------------------- */
242
/* BUFFER HANDLING */
243
/* -------------------------------------------------------------------- */
244
/* Python compatibility API */
246
#if PY_VERSION_HEX < 0x02020000
248
int PyImaging_CheckBuffer(PyObject *buffer)
250
PyBufferProcs *procs = buffer->ob_type->tp_as_buffer;
251
if (procs && procs->bf_getreadbuffer && procs->bf_getsegcount &&
252
procs->bf_getsegcount(buffer, NULL) == 1)
257
int PyImaging_ReadBuffer(PyObject* buffer, const void** ptr)
259
PyBufferProcs *procs = buffer->ob_type->tp_as_buffer;
260
return procs->bf_getreadbuffer(buffer, 0, ptr);
265
int PyImaging_CheckBuffer(PyObject* buffer)
267
return PyObject_CheckReadBuffer(buffer);
270
int PyImaging_ReadBuffer(PyObject* buffer, const void** ptr)
272
/* must call check_buffer first! */
273
#if PY_VERSION_HEX < 0x02050000
278
PyObject_AsReadBuffer(buffer, ptr, &n);
284
/* -------------------------------------------------------------------- */
285
/* EXCEPTION REROUTING */
286
/* -------------------------------------------------------------------- */
289
static const char* must_be_sequence = "argument must be a sequence";
290
static const char* wrong_mode = "unrecognized image mode";
291
static const char* wrong_raw_mode = "unrecognized raw mode";
292
static const char* outside_image = "image index out of range";
293
static const char* outside_palette = "palette index out of range";
294
static const char* no_palette = "image has no palette";
295
static const char* readonly = "image is readonly";
296
/* static const char* no_content = "image has no content"; */
299
ImagingError_IOError(void)
301
PyErr_SetString(PyExc_IOError, "error when accessing file");
306
ImagingError_MemoryError(void)
308
return PyErr_NoMemory();
312
ImagingError_Mismatch(void)
314
PyErr_SetString(PyExc_ValueError, "images do not match");
319
ImagingError_ModeError(void)
321
PyErr_SetString(PyExc_ValueError, "image has wrong mode");
326
ImagingError_ValueError(const char *message)
330
(message) ? (char*) message : "unrecognized argument value"
336
ImagingError_Clear(void)
341
/* -------------------------------------------------------------------- */
343
/* -------------------------------------------------------------------- */
346
getbands(const char* mode)
351
/* FIXME: add primitive to libImaging to avoid extra allocation */
352
im = ImagingNew(mode, 0, 0);
363
#define TYPE_UINT8 (0x100|sizeof(UINT8))
364
#define TYPE_INT32 (0x200|sizeof(INT32))
365
#define TYPE_FLOAT32 (0x300|sizeof(FLOAT32))
366
#define TYPE_DOUBLE (0x400|sizeof(double))
369
getlist(PyObject* arg, int* length, const char* wrong_length, int type)
374
if (!PySequence_Check(arg)) {
375
PyErr_SetString(PyExc_TypeError, must_be_sequence);
379
n = PyObject_Length(arg);
380
if (length && wrong_length && n != *length) {
381
PyErr_SetString(PyExc_ValueError, wrong_length);
385
list = malloc(n * (type & 0xff));
387
return PyErr_NoMemory();
391
if (PyList_Check(arg)) {
392
for (i = 0; i < n; i++) {
393
PyObject *op = PyList_GET_ITEM(arg, i);
394
int temp = PyInt_AsLong(op);
395
((UINT8*)list)[i] = CLIP(temp);
398
for (i = 0; i < n; i++) {
399
PyObject *op = PySequence_GetItem(arg, i);
400
int temp = PyInt_AsLong(op);
402
((UINT8*)list)[i] = CLIP(temp);
407
if (PyList_Check(arg)) {
408
for (i = 0; i < n; i++) {
409
PyObject *op = PyList_GET_ITEM(arg, i);
410
int temp = PyInt_AsLong(op);
411
((INT32*)list)[i] = temp;
414
for (i = 0; i < n; i++) {
415
PyObject *op = PySequence_GetItem(arg, i);
416
int temp = PyInt_AsLong(op);
418
((INT32*)list)[i] = temp;
423
if (PyList_Check(arg)) {
424
for (i = 0; i < n; i++) {
425
PyObject *op = PyList_GET_ITEM(arg, i);
426
double temp = PyFloat_AsDouble(op);
427
((FLOAT32*)list)[i] = (FLOAT32) temp;
430
for (i = 0; i < n; i++) {
431
PyObject *op = PySequence_GetItem(arg, i);
432
double temp = PyFloat_AsDouble(op);
434
((FLOAT32*)list)[i] = (FLOAT32) temp;
439
if (PyList_Check(arg)) {
440
for (i = 0; i < n; i++) {
441
PyObject *op = PyList_GET_ITEM(arg, i);
442
double temp = PyFloat_AsDouble(op);
443
((double*)list)[i] = temp;
446
for (i = 0; i < n; i++) {
447
PyObject *op = PySequence_GetItem(arg, i);
448
double temp = PyFloat_AsDouble(op);
450
((double*)list)[i] = temp;
464
static inline PyObject*
465
getpixel(Imaging im, ImagingAccess access, int x, int y)
474
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
475
PyErr_SetString(PyExc_IndexError, outside_image);
479
access->get_pixel(im, x, y, &pixel);
482
case IMAGING_TYPE_UINT8:
485
return PyInt_FromLong(pixel.b[0]);
487
return Py_BuildValue("ii", pixel.b[0], pixel.b[1]);
489
return Py_BuildValue("iii", pixel.b[0], pixel.b[1], pixel.b[2]);
491
return Py_BuildValue("iiii", pixel.b[0], pixel.b[1], pixel.b[2], pixel.b[3]);
494
case IMAGING_TYPE_INT32:
495
return PyInt_FromLong(pixel.i);
496
case IMAGING_TYPE_FLOAT32:
497
return PyFloat_FromDouble(pixel.f);
498
case IMAGING_TYPE_SPECIAL:
499
if (strncmp(im->mode, "I;16", 4) == 0)
500
return PyInt_FromLong(pixel.h);
510
getink(PyObject* color, Imaging im, char* ink)
515
/* fill ink buffer (four bytes) with something that can
516
be cast to either UINT8 or INT32 */
519
case IMAGING_TYPE_UINT8:
520
/* unsigned integer */
521
if (im->bands == 1) {
522
/* unsigned integer, single layer */
523
r = PyInt_AsLong(color);
524
if (r == -1 && PyErr_Occurred())
527
ink[1] = ink[2] = ink[3] = 0;
530
if (PyInt_Check(color)) {
531
r = PyInt_AS_LONG(color);
532
/* compatibility: ABGR */
533
a = (UINT8) (r >> 24);
534
b = (UINT8) (r >> 16);
535
g = (UINT8) (r >> 8);
538
if (im->bands == 2) {
539
if (!PyArg_ParseTuple(color, "i|i", &r, &a))
543
if (!PyArg_ParseTuple(color, "iii|i", &r, &g, &b, &a))
553
case IMAGING_TYPE_INT32:
555
r = PyInt_AsLong(color);
556
if (r == -1 && PyErr_Occurred())
560
case IMAGING_TYPE_FLOAT32:
562
f = PyFloat_AsDouble(color);
563
if (f == -1.0 && PyErr_Occurred())
565
*(FLOAT32*) ink = (FLOAT32) f;
567
case IMAGING_TYPE_SPECIAL:
568
if (strncmp(im->mode, "I;16", 4) == 0) {
569
r = PyInt_AsLong(color);
570
if (r == -1 && PyErr_Occurred())
573
ink[1] = (UINT8) (r >> 8);
579
PyErr_SetString(PyExc_ValueError, wrong_mode);
583
/* -------------------------------------------------------------------- */
585
/* -------------------------------------------------------------------- */
588
_fill(PyObject* self, PyObject* args)
599
if (!PyArg_ParseTuple(args, "s|(ii)O", &mode, &xsize, &ysize, &color))
602
im = ImagingNew(mode, xsize, ysize);
607
if (!getink(color, im, buffer)) {
612
buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0;
614
(void) ImagingFill(im, buffer);
616
return PyImagingNew(im);
620
_new(PyObject* self, PyObject* args)
625
if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize))
628
return PyImagingNew(ImagingNew(mode, xsize, ysize));
632
_new_array(PyObject* self, PyObject* args)
637
if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize))
640
return PyImagingNew(ImagingNewArray(mode, xsize, ysize));
644
_new_block(PyObject* self, PyObject* args)
649
if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize))
652
return PyImagingNew(ImagingNewBlock(mode, xsize, ysize));
656
_getcount(PyObject* self, PyObject* args)
658
if (!PyArg_ParseTuple(args, ":getcount"))
661
return PyInt_FromLong(ImagingNewCount);
665
_linear_gradient(PyObject* self, PyObject* args)
669
if (!PyArg_ParseTuple(args, "s", &mode))
672
return PyImagingNew(ImagingFillLinearGradient(mode));
676
_radial_gradient(PyObject* self, PyObject* args)
680
if (!PyArg_ParseTuple(args, "s", &mode))
683
return PyImagingNew(ImagingFillRadialGradient(mode));
687
_open_ppm(PyObject* self, PyObject* args)
691
if (!PyArg_ParseTuple(args, "s", &filename))
694
return PyImagingNew(ImagingOpenPPM(filename));
698
_blend(ImagingObject* self, PyObject* args)
700
ImagingObject* imagep1;
701
ImagingObject* imagep2;
705
if (!PyArg_ParseTuple(args, "O!O!|d",
706
&Imaging_Type, &imagep1,
707
&Imaging_Type, &imagep2,
711
return PyImagingNew(ImagingBlend(imagep1->image, imagep2->image,
715
/* -------------------------------------------------------------------- */
717
/* -------------------------------------------------------------------- */
720
_convert(ImagingObject* self, PyObject* args)
724
ImagingObject *paletteimage = NULL;
726
if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage))
728
if (paletteimage != NULL) {
729
if (!PyImaging_Check(paletteimage)) {
730
PyObject_Print((PyObject *)paletteimage, stderr, 0);
731
PyErr_SetString(PyExc_ValueError, "palette argument must be image with mode 'P'");
734
if (paletteimage->image->palette == NULL) {
735
PyErr_SetString(PyExc_ValueError, "null palette");
740
return PyImagingNew(ImagingConvert(self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither));
744
_convert2(ImagingObject* self, PyObject* args)
746
ImagingObject* imagep1;
747
ImagingObject* imagep2;
748
if (!PyArg_ParseTuple(args, "O!O!",
749
&Imaging_Type, &imagep1,
750
&Imaging_Type, &imagep2))
753
if (!ImagingConvert2(imagep1->image, imagep2->image))
761
_convert_matrix(ImagingObject* self, PyObject* args)
765
if (!PyArg_ParseTuple(args, "s(ffff)", &mode, m+0, m+1, m+2, m+3)) {
767
if (!PyArg_ParseTuple(args, "s(ffffffffffff)", &mode,
770
m+8, m+9, m+10, m+11))
774
return PyImagingNew(ImagingConvertMatrix(self->image, mode, m));
778
_copy(ImagingObject* self, PyObject* args)
780
if (!PyArg_ParseTuple(args, ""))
783
return PyImagingNew(ImagingCopy(self->image));
787
_copy2(ImagingObject* self, PyObject* args)
789
ImagingObject* imagep1;
790
ImagingObject* imagep2;
791
if (!PyArg_ParseTuple(args, "O!O!",
792
&Imaging_Type, &imagep1,
793
&Imaging_Type, &imagep2))
796
if (!ImagingCopy2(imagep1->image, imagep2->image))
804
_crop(ImagingObject* self, PyObject* args)
807
if (!PyArg_ParseTuple(args, "(iiii)", &x0, &y0, &x1, &y1))
810
return PyImagingNew(ImagingCrop(self->image, x0, y0, x1, y1));
814
_expand(ImagingObject* self, PyObject* args)
818
if (!PyArg_ParseTuple(args, "ii|i", &x, &y, &mode))
821
return PyImagingNew(ImagingExpand(self->image, x, y, mode));
825
_filter(ImagingObject* self, PyObject* args)
832
float divisor, offset;
833
PyObject* kernel = NULL;
834
if (!PyArg_ParseTuple(args, "(ii)ffO", &xsize, &ysize,
835
&divisor, &offset, &kernel))
838
/* get user-defined kernel */
839
kerneldata = getlist(kernel, &kernelsize, NULL, TYPE_FLOAT32);
842
if (kernelsize != xsize * ysize) {
844
return ImagingError_ValueError("bad kernel size");
847
imOut = PyImagingNew(
848
ImagingFilter(self->image, xsize, ysize, kerneldata, offset, divisor)
856
#ifdef WITH_UNSHARPMASK
858
_gaussian_blur(ImagingObject* self, PyObject* args)
864
if (!PyArg_ParseTuple(args, "f", &radius))
868
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
872
if (!ImagingGaussianBlur(imIn, imOut, radius))
875
return PyImagingNew(imOut);
880
_getpalette(ImagingObject* self, PyObject* args)
883
int palettesize = 256;
885
ImagingShuffler pack;
888
char* rawmode = "RGB";
889
if (!PyArg_ParseTuple(args, "|ss", &mode, &rawmode))
892
if (!self->image->palette) {
893
PyErr_SetString(PyExc_ValueError, no_palette);
897
pack = ImagingFindPacker(mode, rawmode, &bits);
899
PyErr_SetString(PyExc_ValueError, wrong_raw_mode);
903
palette = PyString_FromStringAndSize(NULL, palettesize * bits / 8);
907
pack((UINT8*) PyString_AsString(palette),
908
self->image->palette->palette, palettesize);
914
_getxy(PyObject* xy, int* x, int *y)
918
if (!PyTuple_Check(xy) || PyTuple_GET_SIZE(xy) != 2)
921
value = PyTuple_GET_ITEM(xy, 0);
922
if (PyInt_Check(value))
923
*x = PyInt_AS_LONG(value);
924
else if (PyFloat_Check(value))
925
*x = (int) PyFloat_AS_DOUBLE(value);
929
value = PyTuple_GET_ITEM(xy, 1);
930
if (PyInt_Check(value))
931
*y = PyInt_AS_LONG(value);
932
else if (PyFloat_Check(value))
933
*y = (int) PyFloat_AS_DOUBLE(value);
942
"argument must be sequence of length 2"
949
"an integer is required"
955
_getpixel(ImagingObject* self, PyObject* args)
960
if (PyTuple_GET_SIZE(args) != 1) {
963
"argument 1 must be sequence of length 2"
968
xy = PyTuple_GET_ITEM(args, 0);
970
if (_getxy(xy, &x, &y))
973
if (self->access == NULL) {
978
return getpixel(self->image, self->access, x, y);
982
_histogram(ImagingObject* self, PyObject* args)
996
PyObject* extremap = NULL;
997
ImagingObject* maskp = NULL;
998
if (!PyArg_ParseTuple(args, "|OO!", &extremap, &Imaging_Type, &maskp))
1003
switch (self->image->type) {
1004
case IMAGING_TYPE_UINT8:
1005
if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1))
1011
case IMAGING_TYPE_INT32:
1012
if (!PyArg_ParseTuple(extremap, "ii", &i0, &i1))
1017
case IMAGING_TYPE_FLOAT32:
1018
if (!PyArg_ParseTuple(extremap, "dd", &f0, &f1))
1020
extrema.f[0] = (FLOAT32) f0;
1021
extrema.f[1] = (FLOAT32) f1;
1030
h = ImagingGetHistogram(self->image, (maskp) ? maskp->image : NULL, ep);
1035
/* Build an integer list containing the histogram */
1036
list = PyList_New(h->bands * 256);
1037
for (i = 0; i < h->bands * 256; i++) {
1039
item = PyInt_FromLong(h->histogram[i]);
1045
PyList_SetItem(list, i, item);
1048
ImagingHistogramDelete(h);
1053
#ifdef WITH_MODEFILTER
1055
_modefilter(ImagingObject* self, PyObject* args)
1058
if (!PyArg_ParseTuple(args, "i", &size))
1061
return PyImagingNew(ImagingModeFilter(self->image, size));
1066
_offset(ImagingObject* self, PyObject* args)
1068
int xoffset, yoffset;
1069
if (!PyArg_ParseTuple(args, "ii", &xoffset, &yoffset))
1072
return PyImagingNew(ImagingOffset(self->image, xoffset, yoffset));
1076
_paste(ImagingObject* self, PyObject* args)
1083
ImagingObject* maskp = NULL;
1084
if (!PyArg_ParseTuple(args, "O(iiii)|O!",
1087
&Imaging_Type, &maskp))
1090
if (PyImaging_Check(source))
1091
status = ImagingPaste(
1092
self->image, PyImaging_AsImaging(source),
1093
(maskp) ? maskp->image : NULL,
1098
if (!getink(source, self->image, ink))
1100
status = ImagingFill2(
1102
(maskp) ? maskp->image : NULL,
1115
_point(ImagingObject* self, PyObject* args)
1117
static const char* wrong_number = "wrong number of lut entries";
1125
if (!PyArg_ParseTuple(args, "Oz", &list, &mode))
1128
if (mode && !strcmp(mode, "F")) {
1131
/* map from 8-bit data to floating point */
1133
data = getlist(list, &n, wrong_number, TYPE_FLOAT32);
1136
im = ImagingPoint(self->image, mode, (void*) data);
1139
} else if (!strcmp(self->image->mode, "I") && mode && !strcmp(mode, "L")) {
1142
/* map from 16-bit subset of 32-bit data to 8-bit */
1143
/* FIXME: support arbitrary number of entries (requires API change) */
1145
data = getlist(list, &n, wrong_number, TYPE_UINT8);
1148
im = ImagingPoint(self->image, mode, (void*) data);
1156
bands = getbands(mode);
1160
bands = self->image->bands;
1162
/* map to integer data */
1164
data = getlist(list, &n, wrong_number, TYPE_INT32);
1168
if (mode && !strcmp(mode, "I"))
1169
im = ImagingPoint(self->image, mode, (void*) data);
1170
else if (mode && bands > 1) {
1171
for (i = 0; i < 256; i++) {
1172
lut[i*4] = CLIP(data[i]);
1173
lut[i*4+1] = CLIP(data[i+256]);
1174
lut[i*4+2] = CLIP(data[i+512]);
1176
lut[i*4+3] = CLIP(data[i+768]);
1178
im = ImagingPoint(self->image, mode, (void*) lut);
1180
/* map individual bands */
1181
for (i = 0; i < n; i++)
1182
lut[i] = CLIP(data[i]);
1183
im = ImagingPoint(self->image, mode, (void*) lut);
1188
return PyImagingNew(im);
1192
_point_transform(ImagingObject* self, PyObject* args)
1195
double offset = 0.0;
1196
if (!PyArg_ParseTuple(args, "|dd", &scale, &offset))
1199
return PyImagingNew(ImagingPointTransform(self->image, scale, offset));
1203
_putdata(ImagingObject* self, PyObject* args)
1210
double offset = 0.0;
1211
if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset))
1214
if (!PySequence_Check(data)) {
1215
PyErr_SetString(PyExc_TypeError, must_be_sequence);
1219
image = self->image;
1221
n = PyObject_Length(data);
1222
if (n > (int) (image->xsize * image->ysize)) {
1223
PyErr_SetString(PyExc_TypeError, "too many data entries");
1227
if (image->image8) {
1228
if (PyString_Check(data)) {
1230
p = (unsigned char*) PyString_AS_STRING((PyStringObject*) data);
1231
if (scale == 1.0 && offset == 0.0)
1232
/* Plain string data */
1233
for (i = y = 0; i < n; i += image->xsize, y++) {
1235
if (x > (int) image->xsize)
1237
memcpy(image->image8[y], p+i, x);
1240
/* Scaled and clipped string data */
1241
for (i = x = y = 0; i < n; i++) {
1242
image->image8[y][x] = CLIP((int) (p[i] * scale + offset));
1243
if (++x >= (int) image->xsize)
1247
if (scale == 1.0 && offset == 0.0) {
1249
if (PyList_Check(data)) {
1250
for (i = x = y = 0; i < n; i++) {
1251
PyObject *op = PyList_GET_ITEM(data, i);
1252
image->image8[y][x] = (UINT8) CLIP(PyInt_AsLong(op));
1253
if (++x >= (int) image->xsize)
1257
for (i = x = y = 0; i < n; i++) {
1258
PyObject *op = PySequence_GetItem(data, i);
1259
image->image8[y][x] = (UINT8) CLIP(PyInt_AsLong(op));
1261
if (++x >= (int) image->xsize)
1266
if (PyList_Check(data)) {
1267
/* Scaled and clipped data */
1268
for (i = x = y = 0; i < n; i++) {
1269
PyObject *op = PyList_GET_ITEM(data, i);
1270
image->image8[y][x] = CLIP(
1271
(int) (PyFloat_AsDouble(op) * scale + offset));
1272
if (++x >= (int) image->xsize)
1276
for (i = x = y = 0; i < n; i++) {
1277
PyObject *op = PySequence_GetItem(data, i);
1278
image->image8[y][x] = CLIP(
1279
(int) (PyFloat_AsDouble(op) * scale + offset));
1281
if (++x >= (int) image->xsize)
1286
PyErr_Clear(); /* Avoid weird exceptions */
1290
switch (image->type) {
1291
case IMAGING_TYPE_INT32:
1292
for (i = x = y = 0; i < n; i++) {
1293
PyObject *op = PySequence_GetItem(data, i);
1294
IMAGING_PIXEL_INT32(image, x, y) =
1295
(INT32) (PyFloat_AsDouble(op) * scale + offset);
1297
if (++x >= (int) image->xsize)
1300
PyErr_Clear(); /* Avoid weird exceptions */
1302
case IMAGING_TYPE_FLOAT32:
1303
for (i = x = y = 0; i < n; i++) {
1304
PyObject *op = PySequence_GetItem(data, i);
1305
IMAGING_PIXEL_FLOAT32(image, x, y) =
1306
(FLOAT32) (PyFloat_AsDouble(op) * scale + offset);
1308
if (++x >= (int) image->xsize)
1311
PyErr_Clear(); /* Avoid weird exceptions */
1314
for (i = x = y = 0; i < n; i++) {
1316
PyObject *op = PySequence_GetItem(data, i);
1317
if (!op || !getink(op, image, ink)) {
1321
/* FIXME: what about scale and offset? */
1322
image->image32[y][x] = *((INT32*) ink);
1324
if (++x >= (int) image->xsize)
1327
PyErr_Clear(); /* Avoid weird exceptions */
1336
#ifdef WITH_QUANTIZE
1340
_quantize(ImagingObject* self, PyObject* args)
1345
if (!PyArg_ParseTuple(args, "|iii", &colours, &method, &kmeans))
1348
if (!self->image->xsize || !self->image->ysize) {
1349
/* no content; return an empty image */
1350
return PyImagingNew(
1351
ImagingNew("P", self->image->xsize, self->image->ysize)
1355
return PyImagingNew(ImagingQuantize(self->image, colours, method, kmeans));
1360
_putpalette(ImagingObject* self, PyObject* args)
1362
ImagingShuffler unpack;
1368
if (!PyArg_ParseTuple(args, "ss#", &rawmode, &palette, &palettesize))
1371
if (strcmp(self->image->mode, "L") != 0 && strcmp(self->image->mode, "P")) {
1372
PyErr_SetString(PyExc_ValueError, wrong_mode);
1376
unpack = ImagingFindUnpacker("RGB", rawmode, &bits);
1378
PyErr_SetString(PyExc_ValueError, wrong_raw_mode);
1382
ImagingPaletteDelete(self->image->palette);
1384
strcpy(self->image->mode, "P");
1386
self->image->palette = ImagingPaletteNew("RGB");
1388
unpack(self->image->palette->palette, palette, palettesize * 8 / bits);
1395
_putpalettealpha(ImagingObject* self, PyObject* args)
1399
if (!PyArg_ParseTuple(args, "i|i", &index, &alpha))
1402
if (!self->image->palette) {
1403
PyErr_SetString(PyExc_ValueError, no_palette);
1407
if (index < 0 || index >= 256) {
1408
PyErr_SetString(PyExc_ValueError, outside_palette);
1412
strcpy(self->image->palette->mode, "RGBA");
1413
self->image->palette->palette[index*4+3] = (UINT8) alpha;
1420
_putpixel(ImagingObject* self, PyObject* args)
1427
if (!PyArg_ParseTuple(args, "(ii)O", &x, &y, &color))
1432
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
1433
PyErr_SetString(PyExc_IndexError, outside_image);
1437
if (!getink(color, im, ink))
1441
self->access->put_pixel(im, x, y, ink);
1447
#ifdef WITH_RANKFILTER
1449
_rankfilter(ImagingObject* self, PyObject* args)
1452
if (!PyArg_ParseTuple(args, "ii", &size, &rank))
1455
return PyImagingNew(ImagingRankFilter(self->image, size, rank));
1460
_resize(ImagingObject* self, PyObject* args)
1466
int filter = IMAGING_TRANSFORM_NEAREST;
1467
if (!PyArg_ParseTuple(args, "(ii)|i", &xsize, &ysize, &filter))
1472
imOut = ImagingNew(imIn->mode, xsize, ysize);
1474
(void) ImagingResize(imOut, imIn, filter);
1476
return PyImagingNew(imOut);
1480
_rotate(ImagingObject* self, PyObject* args)
1486
int filter = IMAGING_TRANSFORM_NEAREST;
1487
if (!PyArg_ParseTuple(args, "d|i", &theta, &filter))
1492
theta = fmod(theta, 360.0);
1496
if (filter && imIn->type != IMAGING_TYPE_SPECIAL) {
1497
/* Rotate with resampling filter */
1498
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1499
(void) ImagingRotate(imOut, imIn, theta, filter);
1500
} else if (theta == 90.0 || theta == 270.0) {
1501
/* Use fast version */
1502
imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
1505
(void) ImagingRotate90(imOut, imIn);
1507
(void) ImagingRotate270(imOut, imIn);
1510
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1513
/* No rotation: simply copy the input image */
1514
(void) ImagingCopy2(imOut, imIn);
1515
else if (theta == 180.0)
1516
/* Use fast version */
1517
(void) ImagingRotate180(imOut, imIn);
1519
/* Use ordinary version */
1520
(void) ImagingRotate(imOut, imIn, theta, 0);
1524
return PyImagingNew(imOut);
1527
#define IS_RGB(mode)\
1528
(!strcmp(mode, "RGB") || !strcmp(mode, "RGBA") || !strcmp(mode, "RGBX"))
1531
im_setmode(ImagingObject* self, PyObject* args)
1533
/* attempt to modify the mode of an image in place */
1539
if (!PyArg_ParseTuple(args, "s#:setmode", &mode, &modelen))
1544
/* move all logic in here to the libImaging primitive */
1546
if (!strcmp(im->mode, mode)) {
1547
; /* same mode; always succeeds */
1548
} else if (IS_RGB(im->mode) && IS_RGB(mode)) {
1549
/* color to color */
1550
strcpy(im->mode, mode);
1551
im->bands = modelen;
1552
if (!strcmp(mode, "RGBA"))
1553
(void) ImagingFillBand(im, 3, 255);
1555
/* trying doing an in-place conversion */
1556
if (!ImagingConvertInPlace(im, mode))
1561
ImagingAccessDelete(im, self->access);
1562
self->access = ImagingAccessNew(im);
1569
_stretch(ImagingObject* self, PyObject* args)
1576
int filter = IMAGING_TRANSFORM_NEAREST;
1577
if (!PyArg_ParseTuple(args, "(ii)|i", &xsize, &ysize, &filter))
1582
/* two-pass resize: minimize size of intermediate image */
1583
if (imIn->xsize * ysize < xsize * imIn->ysize)
1584
imTemp = ImagingNew(imIn->mode, imIn->xsize, ysize);
1586
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
1591
if (!ImagingStretch(imTemp, imIn, filter)) {
1592
ImagingDelete(imTemp);
1596
imOut = ImagingNew(imIn->mode, xsize, ysize);
1598
ImagingDelete(imTemp);
1603
if (!ImagingStretch(imOut, imTemp, filter)) {
1604
ImagingDelete(imOut);
1605
ImagingDelete(imTemp);
1609
ImagingDelete(imTemp);
1611
return PyImagingNew(imOut);
1615
_transform2(ImagingObject* self, PyObject* args)
1617
static const char* wrong_number = "wrong number of matrix entries";
1624
ImagingObject* imagep;
1628
int filter = IMAGING_TRANSFORM_NEAREST;
1630
if (!PyArg_ParseTuple(args, "(iiii)O!iO|ii",
1632
&Imaging_Type, &imagep,
1638
case IMAGING_TRANSFORM_AFFINE:
1641
case IMAGING_TRANSFORM_PERSPECTIVE:
1644
case IMAGING_TRANSFORM_QUAD:
1648
n = -1; /* force error */
1651
a = getlist(data, &n, wrong_number, TYPE_DOUBLE);
1655
imOut = self->image;
1656
imIn = imagep->image;
1658
/* FIXME: move transform dispatcher into libImaging */
1661
case IMAGING_TRANSFORM_AFFINE:
1662
imOut = ImagingTransformAffine(
1663
imOut, imIn, x0, y0, x1, y1, a, filter, 1
1666
case IMAGING_TRANSFORM_PERSPECTIVE:
1667
imOut = ImagingTransformPerspective(
1668
imOut, imIn, x0, y0, x1, y1, a, filter, 1
1671
case IMAGING_TRANSFORM_QUAD:
1672
imOut = ImagingTransformQuad(
1673
imOut, imIn, x0, y0, x1, y1, a, filter, 1
1677
(void) ImagingError_ValueError("bad transform method");
1690
_transpose(ImagingObject* self, PyObject* args)
1696
if (!PyArg_ParseTuple(args, "i", &op))
1702
case 0: /* flip left right */
1703
case 1: /* flip top bottom */
1704
case 3: /* rotate 180 */
1705
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1707
case 2: /* rotate 90 */
1708
case 4: /* rotate 270 */
1709
imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
1712
PyErr_SetString(PyExc_ValueError, "No such transpose operation");
1719
(void) ImagingFlipLeftRight(imOut, imIn);
1722
(void) ImagingFlipTopBottom(imOut, imIn);
1725
(void) ImagingRotate90(imOut, imIn);
1728
(void) ImagingRotate180(imOut, imIn);
1731
(void) ImagingRotate270(imOut, imIn);
1735
return PyImagingNew(imOut);
1738
#ifdef WITH_UNSHARPMASK
1740
_unsharp_mask(ImagingObject* self, PyObject* args)
1746
int percent, threshold;
1747
if (!PyArg_ParseTuple(args, "fii", &radius, &percent, &threshold))
1752
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1756
if (!ImagingUnsharpMask(imIn, imOut, radius, percent, threshold))
1759
return PyImagingNew(imOut);
1763
/* -------------------------------------------------------------------- */
1766
_isblock(ImagingObject* self, PyObject* args)
1768
return PyInt_FromLong((long) self->image->block);
1772
_getbbox(ImagingObject* self, PyObject* args)
1775
if (!ImagingGetBBox(self->image, bbox)) {
1780
return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]);
1784
_getcolors(ImagingObject* self, PyObject* args)
1786
ImagingColorItem* items;
1790
int maxcolors = 256;
1791
if (!PyArg_ParseTuple(args, "i:getcolors", &maxcolors))
1794
items = ImagingGetColors(self->image, maxcolors, &colors);
1798
if (colors > maxcolors) {
1802
out = PyList_New(colors);
1803
for (i = 0; i < colors; i++) {
1804
ImagingColorItem* v = &items[i];
1805
PyObject* item = Py_BuildValue(
1806
"iN", v->count, getpixel(self->image, self->access, v->x, v->y)
1808
PyList_SetItem(out, i, item);
1818
_getextrema(ImagingObject* self, PyObject* args)
1827
status = ImagingGetExtrema(self->image, &extrema);
1832
switch (self->image->type) {
1833
case IMAGING_TYPE_UINT8:
1834
return Py_BuildValue("ii", extrema.u[0], extrema.u[1]);
1835
case IMAGING_TYPE_INT32:
1836
return Py_BuildValue("ii", extrema.i[0], extrema.i[1]);
1837
case IMAGING_TYPE_FLOAT32:
1838
return Py_BuildValue("dd", extrema.f[0], extrema.f[1]);
1846
_getprojection(ImagingObject* self, PyObject* args)
1848
unsigned char* xprofile;
1849
unsigned char* yprofile;
1852
xprofile = malloc(self->image->xsize);
1853
yprofile = malloc(self->image->ysize);
1855
if (xprofile == NULL || yprofile == NULL) {
1858
return PyErr_NoMemory();
1861
ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
1863
result = Py_BuildValue("s#s#", xprofile, self->image->xsize,
1864
yprofile, self->image->ysize);
1872
/* -------------------------------------------------------------------- */
1875
_getband(ImagingObject* self, PyObject* args)
1879
if (!PyArg_ParseTuple(args, "i", &band))
1882
return PyImagingNew(ImagingGetBand(self->image, band));
1886
_fillband(ImagingObject* self, PyObject* args)
1891
if (!PyArg_ParseTuple(args, "ii", &band, &color))
1894
if (!ImagingFillBand(self->image, band, color))
1902
_putband(ImagingObject* self, PyObject* args)
1904
ImagingObject* imagep;
1906
if (!PyArg_ParseTuple(args, "O!i",
1907
&Imaging_Type, &imagep,
1911
if (!ImagingPutBand(self->image, imagep->image, band))
1918
/* -------------------------------------------------------------------- */
1920
#ifdef WITH_IMAGECHOPS
1923
_chop_invert(ImagingObject* self, PyObject* args)
1925
return PyImagingNew(ImagingNegative(self->image));
1929
_chop_lighter(ImagingObject* self, PyObject* args)
1931
ImagingObject* imagep;
1933
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
1936
return PyImagingNew(ImagingChopLighter(self->image, imagep->image));
1940
_chop_darker(ImagingObject* self, PyObject* args)
1942
ImagingObject* imagep;
1944
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
1947
return PyImagingNew(ImagingChopDarker(self->image, imagep->image));
1951
_chop_difference(ImagingObject* self, PyObject* args)
1953
ImagingObject* imagep;
1955
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
1958
return PyImagingNew(ImagingChopDifference(self->image, imagep->image));
1962
_chop_multiply(ImagingObject* self, PyObject* args)
1964
ImagingObject* imagep;
1966
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
1969
return PyImagingNew(ImagingChopMultiply(self->image, imagep->image));
1973
_chop_screen(ImagingObject* self, PyObject* args)
1975
ImagingObject* imagep;
1977
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
1980
return PyImagingNew(ImagingChopScreen(self->image, imagep->image));
1984
_chop_add(ImagingObject* self, PyObject* args)
1986
ImagingObject* imagep;
1993
if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep,
1997
return PyImagingNew(ImagingChopAdd(self->image, imagep->image,
2002
_chop_subtract(ImagingObject* self, PyObject* args)
2004
ImagingObject* imagep;
2011
if (!PyArg_ParseTuple(args, "O!|fi", &Imaging_Type, &imagep,
2015
return PyImagingNew(ImagingChopSubtract(self->image, imagep->image,
2020
_chop_and(ImagingObject* self, PyObject* args)
2022
ImagingObject* imagep;
2024
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
2027
return PyImagingNew(ImagingChopAnd(self->image, imagep->image));
2031
_chop_or(ImagingObject* self, PyObject* args)
2033
ImagingObject* imagep;
2035
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
2038
return PyImagingNew(ImagingChopOr(self->image, imagep->image));
2042
_chop_xor(ImagingObject* self, PyObject* args)
2044
ImagingObject* imagep;
2046
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
2049
return PyImagingNew(ImagingChopXor(self->image, imagep->image));
2053
_chop_add_modulo(ImagingObject* self, PyObject* args)
2055
ImagingObject* imagep;
2057
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
2060
return PyImagingNew(ImagingChopAddModulo(self->image, imagep->image));
2064
_chop_subtract_modulo(ImagingObject* self, PyObject* args)
2066
ImagingObject* imagep;
2068
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep))
2071
return PyImagingNew(ImagingChopSubtractModulo(self->image, imagep->image));
2077
/* -------------------------------------------------------------------- */
2079
#ifdef WITH_IMAGEDRAW
2082
_font_new(PyObject* self_, PyObject* args)
2084
ImagingFontObject *self;
2086
static const char* wrong_length = "descriptor table has wrong size";
2088
ImagingObject* imagep;
2089
unsigned char* glyphdata;
2090
int glyphdata_length;
2091
if (!PyArg_ParseTuple(args, "O!s#",
2092
&Imaging_Type, &imagep,
2093
&glyphdata, &glyphdata_length))
2096
if (glyphdata_length != 256 * 20) {
2097
PyErr_SetString(PyExc_ValueError, wrong_length);
2101
self = PyObject_New(ImagingFontObject, &ImagingFont_Type);
2106
self->bitmap = imagep->image;
2111
for (i = 0; i < 256; i++) {
2112
self->glyphs[i].dx = S16(B16(glyphdata, 0));
2113
self->glyphs[i].dy = S16(B16(glyphdata, 2));
2114
self->glyphs[i].dx0 = S16(B16(glyphdata, 4));
2115
self->glyphs[i].dy0 = S16(B16(glyphdata, 6));
2116
self->glyphs[i].dx1 = S16(B16(glyphdata, 8));
2117
self->glyphs[i].dy1 = S16(B16(glyphdata, 10));
2118
self->glyphs[i].sx0 = S16(B16(glyphdata, 12));
2119
self->glyphs[i].sy0 = S16(B16(glyphdata, 14));
2120
self->glyphs[i].sx1 = S16(B16(glyphdata, 16));
2121
self->glyphs[i].sy1 = S16(B16(glyphdata, 18));
2122
if (self->glyphs[i].dy0 < y0)
2123
y0 = self->glyphs[i].dy0;
2124
if (self->glyphs[i].dy1 > y1)
2125
y1 = self->glyphs[i].dy1;
2129
self->baseline = -y0;
2130
self->ysize = y1 - y0;
2132
/* keep a reference to the bitmap object */
2136
return (PyObject*) self;
2140
_font_dealloc(ImagingFontObject* self)
2142
Py_XDECREF(self->ref);
2147
textwidth(ImagingFontObject* self, const unsigned char* text)
2151
for (xsize = 0; *text; text++)
2152
xsize += self->glyphs[*text].dx;
2158
_font_getmask(ImagingFontObject* self, PyObject* args)
2166
unsigned char* text;
2168
if (!PyArg_ParseTuple(args, "s|s:getmask", &text, &mode))
2171
im = ImagingNew(self->bitmap->mode, textwidth(self, text), self->ysize);
2176
(void) ImagingFill(im, &b);
2179
for (x = 0; *text; text++) {
2180
glyph = &self->glyphs[*text];
2181
bitmap = ImagingCrop(
2183
glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1
2187
status = ImagingPaste(
2189
glyph->dx0+x, glyph->dy0+b, glyph->dx1+x, glyph->dy1+b
2191
ImagingDelete(bitmap);
2198
return PyImagingNew(im);
2206
_font_getsize(ImagingFontObject* self, PyObject* args)
2208
unsigned char* text;
2209
if (!PyArg_ParseTuple(args, "s:getsize", &text))
2212
return Py_BuildValue("ii", textwidth(self, text), self->ysize);
2215
static struct PyMethodDef _font_methods[] = {
2216
{"getmask", (PyCFunction)_font_getmask, 1},
2217
{"getsize", (PyCFunction)_font_getsize, 1},
2218
{NULL, NULL} /* sentinel */
2222
_font_getattr(ImagingFontObject* self, char* name)
2224
return Py_FindMethod(_font_methods, (PyObject*) self, name);
2227
/* -------------------------------------------------------------------- */
2230
_draw_new(PyObject* self_, PyObject* args)
2232
ImagingDrawObject *self;
2234
ImagingObject* imagep;
2236
if (!PyArg_ParseTuple(args, "O!|i", &Imaging_Type, &imagep, &blend))
2239
self = PyObject_New(ImagingDrawObject, &ImagingDraw_Type);
2243
/* keep a reference to the image object */
2245
self->image = imagep;
2247
self->ink[0] = self->ink[1] = self->ink[2] = self->ink[3] = 0;
2249
self->blend = blend;
2251
return (PyObject*) self;
2255
_draw_dealloc(ImagingDrawObject* self)
2257
Py_XDECREF(self->image);
2261
extern int PyPath_Flatten(PyObject* data, double **xy);
2264
_draw_ink(ImagingDrawObject* self, PyObject* args)
2268
char* mode = NULL; /* not used in this release */
2269
if (!PyArg_ParseTuple(args, "O|s", &color, &mode))
2272
if (!getink(color, self->image->image, (char*) &ink))
2275
return PyInt_FromLong((int) ink);
2279
_draw_arc(ImagingDrawObject* self, PyObject* args)
2285
if (!PyArg_ParseTuple(args, "(iiii)iii|i",
2287
&start, &end, &ink))
2290
if (ImagingDrawArc(self->image->image, x0, y0, x1, y1, start, end,
2299
_draw_bitmap(ImagingDrawObject* self, PyObject* args)
2305
ImagingObject* bitmap;
2307
if (!PyArg_ParseTuple(args, "OO!i", &data, &Imaging_Type, &bitmap, &ink))
2310
n = PyPath_Flatten(data, &xy);
2316
"coordinate list must contain exactly 1 coordinate"
2321
n = ImagingDrawBitmap(
2322
self->image->image, (int) xy[0], (int) xy[1], bitmap->image,
2336
_draw_chord(ImagingDrawObject* self, PyObject* args)
2341
if (!PyArg_ParseTuple(args, "(iiii)iiii",
2342
&x0, &y0, &x1, &y1, &start, &end, &ink, &fill))
2345
if (ImagingDrawChord(self->image->image, x0, y0, x1, y1,
2346
start, end, &ink, fill, self->blend) < 0)
2354
_draw_ellipse(ImagingDrawObject* self, PyObject* args)
2362
if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &fill))
2365
n = PyPath_Flatten(data, &xy);
2371
"coordinate list must contain exactly 2 coordinates"
2376
n = ImagingDrawEllipse(
2377
self->image->image, (int) xy[0], (int) xy[1], (int) xy[2], (int) xy[3],
2378
&ink, fill, self->blend
2391
_draw_line(ImagingDrawObject* self, PyObject* args)
2395
if (!PyArg_ParseTuple(args, "(ii)(ii)i", &x0, &y0, &x1, &y1, &ink))
2398
if (ImagingDrawLine(self->image->image, x0, y0, x1, y1,
2399
&ink, self->blend) < 0)
2407
_draw_lines(ImagingDrawObject* self, PyObject* args)
2415
if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &width))
2418
n = PyPath_Flatten(data, &xy);
2424
for (i = 0; i < n-1; i++) {
2426
if (ImagingDrawLine(
2428
(int) p[0], (int) p[1], (int) p[2], (int) p[3],
2429
&ink, self->blend) < 0) {
2434
if (p) /* draw last point */
2437
(int) p[2], (int) p[3],
2441
for (i = 0; i < n-1; i++) {
2442
double *p = &xy[i+i];
2443
if (ImagingDrawWideLine(
2445
(int) p[0], (int) p[1], (int) p[2], (int) p[3],
2446
&ink, width, self->blend) < 0) {
2460
_draw_point(ImagingDrawObject* self, PyObject* args)
2464
if (!PyArg_ParseTuple(args, "(ii)i", &x, &y, &ink))
2467
if (ImagingDrawPoint(self->image->image, x, y, &ink, self->blend) < 0)
2475
_draw_points(ImagingDrawObject* self, PyObject* args)
2482
if (!PyArg_ParseTuple(args, "Oi", &data, &ink))
2485
n = PyPath_Flatten(data, &xy);
2489
for (i = 0; i < n; i++) {
2490
double *p = &xy[i+i];
2491
if (ImagingDrawPoint(self->image->image, (int) p[0], (int) p[1],
2492
&ink, self->blend) < 0) {
2506
/* from outline.c */
2507
extern ImagingOutline PyOutline_AsOutline(PyObject* outline);
2510
_draw_outline(ImagingDrawObject* self, PyObject* args)
2512
ImagingOutline outline;
2517
if (!PyArg_ParseTuple(args, "Oi|i", &outline_, &ink, &fill))
2520
outline = PyOutline_AsOutline(outline_);
2522
PyErr_SetString(PyExc_TypeError, "expected outline object");
2526
if (ImagingDrawOutline(self->image->image, outline,
2527
&ink, fill, self->blend) < 0)
2537
_draw_pieslice(ImagingDrawObject* self, PyObject* args)
2542
if (!PyArg_ParseTuple(args, "(iiii)iiii",
2543
&x0, &y0, &x1, &y1, &start, &end, &ink, &fill))
2546
if (ImagingDrawPieslice(self->image->image, x0, y0, x1, y1,
2547
start, end, &ink, fill, self->blend) < 0)
2555
_draw_polygon(ImagingDrawObject* self, PyObject* args)
2564
if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &fill))
2567
n = PyPath_Flatten(data, &xy);
2573
"coordinate list must contain at least 2 coordinates"
2578
/* Copy list of vertices to array */
2579
ixy = (int*) malloc(n * 2 * sizeof(int));
2581
for (i = 0; i < n; i++) {
2582
ixy[i+i] = (int) xy[i+i];
2583
ixy[i+i+1] = (int) xy[i+i+1];
2588
if (ImagingDrawPolygon(self->image->image, n, ixy,
2589
&ink, fill, self->blend) < 0) {
2601
_draw_rectangle(ImagingDrawObject* self, PyObject* args)
2609
if (!PyArg_ParseTuple(args, "Oi|i", &data, &ink, &fill))
2612
n = PyPath_Flatten(data, &xy);
2618
"coordinate list must contain exactly 2 coordinates"
2623
n = ImagingDrawRectangle(
2624
self->image->image, (int) xy[0], (int) xy[1],
2625
(int) xy[2], (int) xy[3], &ink, fill, self->blend
2637
static struct PyMethodDef _draw_methods[] = {
2638
#ifdef WITH_IMAGEDRAW
2639
/* Graphics (ImageDraw) */
2640
{"draw_line", (PyCFunction)_draw_line, 1},
2641
{"draw_lines", (PyCFunction)_draw_lines, 1},
2643
{"draw_outline", (PyCFunction)_draw_outline, 1},
2645
{"draw_polygon", (PyCFunction)_draw_polygon, 1},
2646
{"draw_rectangle", (PyCFunction)_draw_rectangle, 1},
2647
{"draw_point", (PyCFunction)_draw_point, 1},
2648
{"draw_points", (PyCFunction)_draw_points, 1},
2649
{"draw_arc", (PyCFunction)_draw_arc, 1},
2650
{"draw_bitmap", (PyCFunction)_draw_bitmap, 1},
2651
{"draw_chord", (PyCFunction)_draw_chord, 1},
2652
{"draw_ellipse", (PyCFunction)_draw_ellipse, 1},
2653
{"draw_pieslice", (PyCFunction)_draw_pieslice, 1},
2654
{"draw_ink", (PyCFunction)_draw_ink, 1},
2656
{NULL, NULL} /* sentinel */
2660
_draw_getattr(ImagingDrawObject* self, char* name)
2662
return Py_FindMethod(_draw_methods, (PyObject*) self, name);
2669
pixel_access_new(ImagingObject* imagep, PyObject* args)
2671
PixelAccessObject *self;
2674
if (!PyArg_ParseTuple(args, "|i", &readonly))
2677
self = PyObject_New(PixelAccessObject, &PixelAccess_Type);
2681
/* keep a reference to the image object */
2683
self->image = imagep;
2685
self->readonly = readonly;
2687
return (PyObject*) self;
2691
pixel_access_dealloc(PixelAccessObject* self)
2693
Py_XDECREF(self->image);
2698
pixel_access_getitem(PixelAccessObject *self, PyObject *xy)
2701
if (_getxy(xy, &x, &y))
2704
return getpixel(self->image->image, self->image->access, x, y);
2708
pixel_access_setitem(PixelAccessObject *self, PyObject *xy, PyObject *color)
2710
Imaging im = self->image->image;
2714
if (self->readonly) {
2715
(void) ImagingError_ValueError(readonly);
2719
if (_getxy(xy, &x, &y))
2722
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
2723
PyErr_SetString(PyExc_IndexError, outside_image);
2727
if (!color) /* FIXME: raise exception? */
2730
if (!getink(color, im, ink))
2733
self->image->access->put_pixel(im, x, y, ink);
2738
/* -------------------------------------------------------------------- */
2739
/* EFFECTS (experimental) */
2740
/* -------------------------------------------------------------------- */
2745
_effect_mandelbrot(ImagingObject* self, PyObject* args)
2752
extent[0] = -3; extent[1] = -2.5;
2753
extent[2] = 2; extent[3] = 2.5;
2755
if (!PyArg_ParseTuple(args, "|(ii)(dddd)i", &xsize, &ysize,
2756
&extent[0], &extent[1], &extent[2], &extent[3],
2760
return PyImagingNew(ImagingEffectMandelbrot(xsize, ysize, extent, quality));
2764
_effect_noise(ImagingObject* self, PyObject* args)
2768
if (!PyArg_ParseTuple(args, "(ii)|f", &xsize, &ysize, &sigma))
2771
return PyImagingNew(ImagingEffectNoise(xsize, ysize, sigma));
2775
_effect_spread(ImagingObject* self, PyObject* args)
2779
if (!PyArg_ParseTuple(args, "i", &dist))
2782
return PyImagingNew(ImagingEffectSpread(self->image, dist));
2787
/* -------------------------------------------------------------------- */
2789
/* -------------------------------------------------------------------- */
2792
_crc32(PyObject* self, PyObject* args)
2794
unsigned char* buffer;
2801
if (!PyArg_ParseTuple(args, "s#|(ii)", &buffer, &bytes, &hi, &lo))
2804
crc = ((UINT32) (hi & 0xFFFF) << 16) + (lo & 0xFFFF);
2806
crc = ImagingCRC32(crc, (unsigned char *)buffer, bytes);
2808
return Py_BuildValue("ii", (crc >> 16) & 0xFFFF, crc & 0xFFFF);
2812
_getcodecstatus(PyObject* self, PyObject* args)
2817
if (!PyArg_ParseTuple(args, "i", &status))
2821
case IMAGING_CODEC_OVERRUN:
2822
msg = "buffer overrun"; break;
2823
case IMAGING_CODEC_BROKEN:
2824
msg = "broken data stream"; break;
2825
case IMAGING_CODEC_UNKNOWN:
2826
msg = "unrecognized data stream contents"; break;
2827
case IMAGING_CODEC_CONFIG:
2828
msg = "codec configuration error"; break;
2829
case IMAGING_CODEC_MEMORY:
2830
msg = "out of memory"; break;
2836
return PyString_FromString(msg);
2839
/* -------------------------------------------------------------------- */
2840
/* DEBUGGING HELPERS */
2841
/* -------------------------------------------------------------------- */
2847
_save_ppm(ImagingObject* self, PyObject* args)
2851
if (!PyArg_ParseTuple(args, "s", &filename))
2854
if (!ImagingSavePPM(self->image, filename))
2863
/* -------------------------------------------------------------------- */
2867
static struct PyMethodDef methods[] = {
2869
/* Put commonly used methods first */
2870
{"getpixel", (PyCFunction)_getpixel, 1},
2871
{"putpixel", (PyCFunction)_putpixel, 1},
2873
{"pixel_access", (PyCFunction)pixel_access_new, 1},
2875
/* Standard processing methods (Image) */
2876
{"convert", (PyCFunction)_convert, 1},
2877
{"convert2", (PyCFunction)_convert2, 1},
2878
{"convert_matrix", (PyCFunction)_convert_matrix, 1},
2879
{"copy", (PyCFunction)_copy, 1},
2880
{"copy2", (PyCFunction)_copy2, 1},
2881
#ifdef WITH_CRACKCODE
2882
{"crackcode", (PyCFunction)_crackcode, 1},
2884
{"crop", (PyCFunction)_crop, 1},
2885
{"expand", (PyCFunction)_expand, 1},
2886
{"filter", (PyCFunction)_filter, 1},
2887
{"histogram", (PyCFunction)_histogram, 1},
2888
#ifdef WITH_MODEFILTER
2889
{"modefilter", (PyCFunction)_modefilter, 1},
2891
{"offset", (PyCFunction)_offset, 1},
2892
{"paste", (PyCFunction)_paste, 1},
2893
{"point", (PyCFunction)_point, 1},
2894
{"point_transform", (PyCFunction)_point_transform, 1},
2895
{"putdata", (PyCFunction)_putdata, 1},
2896
#ifdef WITH_QUANTIZE
2897
{"quantize", (PyCFunction)_quantize, 1},
2899
#ifdef WITH_RANKFILTER
2900
{"rankfilter", (PyCFunction)_rankfilter, 1},
2902
{"resize", (PyCFunction)_resize, 1},
2903
{"rotate", (PyCFunction)_rotate, 1},
2904
{"stretch", (PyCFunction)_stretch, 1},
2905
{"transpose", (PyCFunction)_transpose, 1},
2906
{"transform2", (PyCFunction)_transform2, 1},
2908
{"isblock", (PyCFunction)_isblock, 1},
2910
{"getbbox", (PyCFunction)_getbbox, 1},
2911
{"getcolors", (PyCFunction)_getcolors, 1},
2912
{"getextrema", (PyCFunction)_getextrema, 1},
2913
{"getprojection", (PyCFunction)_getprojection, 1},
2915
{"getband", (PyCFunction)_getband, 1},
2916
{"putband", (PyCFunction)_putband, 1},
2917
{"fillband", (PyCFunction)_fillband, 1},
2919
{"setmode", (PyCFunction)im_setmode, 1},
2921
{"getpalette", (PyCFunction)_getpalette, 1},
2922
{"putpalette", (PyCFunction)_putpalette, 1},
2923
{"putpalettealpha", (PyCFunction)_putpalettealpha, 1},
2925
#ifdef WITH_IMAGECHOPS
2926
/* Channel operations (ImageChops) */
2927
{"chop_invert", (PyCFunction)_chop_invert, 1},
2928
{"chop_lighter", (PyCFunction)_chop_lighter, 1},
2929
{"chop_darker", (PyCFunction)_chop_darker, 1},
2930
{"chop_difference", (PyCFunction)_chop_difference, 1},
2931
{"chop_multiply", (PyCFunction)_chop_multiply, 1},
2932
{"chop_screen", (PyCFunction)_chop_screen, 1},
2933
{"chop_add", (PyCFunction)_chop_add, 1},
2934
{"chop_subtract", (PyCFunction)_chop_subtract, 1},
2935
{"chop_add_modulo", (PyCFunction)_chop_add_modulo, 1},
2936
{"chop_subtract_modulo", (PyCFunction)_chop_subtract_modulo, 1},
2937
{"chop_and", (PyCFunction)_chop_and, 1},
2938
{"chop_or", (PyCFunction)_chop_or, 1},
2939
{"chop_xor", (PyCFunction)_chop_xor, 1},
2942
#ifdef WITH_UNSHARPMASK
2943
/* Kevin Cazabon's unsharpmask extension */
2944
{"gaussian_blur", (PyCFunction)_gaussian_blur, 1},
2945
{"unsharp_mask", (PyCFunction)_unsharp_mask, 1},
2949
/* Special effects */
2950
{"effect_spread", (PyCFunction)_effect_spread, 1},
2954
{"new_array", (PyCFunction)_new_array, 1},
2955
{"new_block", (PyCFunction)_new_block, 1},
2958
{"save_ppm", (PyCFunction)_save_ppm, 1},
2961
{NULL, NULL} /* sentinel */
2968
_getattr(ImagingObject* self, char* name)
2972
res = Py_FindMethod(methods, (PyObject*) self, name);
2976
if (strcmp(name, "mode") == 0)
2977
return PyString_FromString(self->image->mode);
2978
if (strcmp(name, "size") == 0)
2979
return Py_BuildValue("ii", self->image->xsize, self->image->ysize);
2980
if (strcmp(name, "bands") == 0)
2981
return PyInt_FromLong(self->image->bands);
2982
if (strcmp(name, "id") == 0)
2983
return PyInt_FromLong((long) self->image);
2984
if (strcmp(name, "ptr") == 0)
2985
return PyCObject_FromVoidPtrAndDesc(self->image, IMAGING_MAGIC, NULL);
2986
PyErr_SetString(PyExc_AttributeError, name);
2991
/* basic sequence semantics */
2994
image_length(ImagingObject *self)
2996
Imaging im = self->image;
2998
return im->xsize * im->ysize;
3002
image_item(ImagingObject *self, Py_ssize_t i)
3005
Imaging im = self->image;
3007
if (im->xsize > 0) {
3011
x = y = 0; /* leave it to getpixel to raise an exception */
3013
return getpixel(im, self->access, x, y);
3016
static PySequenceMethods image_as_sequence = {
3017
(inquiry) image_length, /*sq_length*/
3018
(binaryfunc) NULL, /*sq_concat*/
3019
(ssizeargfunc) NULL, /*sq_repeat*/
3020
(ssizeargfunc) image_item, /*sq_item*/
3021
(ssizessizeargfunc) NULL, /*sq_slice*/
3022
(ssizeobjargproc) NULL, /*sq_ass_item*/
3023
(ssizessizeobjargproc) NULL, /*sq_ass_slice*/
3027
/* type description */
3029
statichere PyTypeObject Imaging_Type = {
3030
PyObject_HEAD_INIT(NULL)
3032
"ImagingCore", /*tp_name*/
3033
sizeof(ImagingObject), /*tp_size*/
3036
(destructor)_dealloc, /*tp_dealloc*/
3038
(getattrfunc)_getattr, /*tp_getattr*/
3042
0, /*tp_as_number */
3043
&image_as_sequence, /*tp_as_sequence */
3044
0, /*tp_as_mapping */
3048
#ifdef WITH_IMAGEDRAW
3050
statichere PyTypeObject ImagingFont_Type = {
3051
PyObject_HEAD_INIT(NULL)
3053
"ImagingFont", /*tp_name*/
3054
sizeof(ImagingFontObject), /*tp_size*/
3057
(destructor)_font_dealloc, /*tp_dealloc*/
3059
(getattrfunc)_font_getattr, /*tp_getattr*/
3062
statichere PyTypeObject ImagingDraw_Type = {
3063
PyObject_HEAD_INIT(NULL)
3065
"ImagingDraw", /*tp_name*/
3066
sizeof(ImagingDrawObject), /*tp_size*/
3069
(destructor)_draw_dealloc, /*tp_dealloc*/
3071
(getattrfunc)_draw_getattr, /*tp_getattr*/
3076
static PyMappingMethods pixel_access_as_mapping = {
3077
(inquiry) NULL, /*mp_length*/
3078
(binaryfunc) pixel_access_getitem, /*mp_subscript*/
3079
(objobjargproc) pixel_access_setitem, /*mp_ass_subscript*/
3082
/* type description */
3084
statichere PyTypeObject PixelAccess_Type = {
3085
PyObject_HEAD_INIT(NULL)
3086
0, "PixelAccess", sizeof(PixelAccessObject), 0,
3088
(destructor)pixel_access_dealloc, /*tp_dealloc*/
3094
0, /*tp_as_number */
3095
0, /*tp_as_sequence */
3096
&pixel_access_as_mapping, /*tp_as_mapping */
3100
/* -------------------------------------------------------------------- */
3102
/* FIXME: this is something of a mess. Should replace this with
3103
pluggable codecs, but not before PIL 1.2 */
3105
/* Decoders (in decode.c) */
3106
extern PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args);
3107
extern PyObject* PyImaging_FliDecoderNew(PyObject* self, PyObject* args);
3108
extern PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args);
3109
extern PyObject* PyImaging_HexDecoderNew(PyObject* self, PyObject* args);
3110
extern PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args);
3111
extern PyObject* PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args);
3112
extern PyObject* PyImaging_MspDecoderNew(PyObject* self, PyObject* args);
3113
extern PyObject* PyImaging_PackbitsDecoderNew(PyObject* self, PyObject* args);
3114
extern PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args);
3115
extern PyObject* PyImaging_PcxDecoderNew(PyObject* self, PyObject* args);
3116
extern PyObject* PyImaging_RawDecoderNew(PyObject* self, PyObject* args);
3117
extern PyObject* PyImaging_SunRleDecoderNew(PyObject* self, PyObject* args);
3118
extern PyObject* PyImaging_TgaRleDecoderNew(PyObject* self, PyObject* args);
3119
extern PyObject* PyImaging_XbmDecoderNew(PyObject* self, PyObject* args);
3120
extern PyObject* PyImaging_ZipDecoderNew(PyObject* self, PyObject* args);
3122
/* Encoders (in encode.c) */
3123
extern PyObject* PyImaging_EpsEncoderNew(PyObject* self, PyObject* args);
3124
extern PyObject* PyImaging_GifEncoderNew(PyObject* self, PyObject* args);
3125
extern PyObject* PyImaging_JpegEncoderNew(PyObject* self, PyObject* args);
3126
extern PyObject* PyImaging_PcxEncoderNew(PyObject* self, PyObject* args);
3127
extern PyObject* PyImaging_RawEncoderNew(PyObject* self, PyObject* args);
3128
extern PyObject* PyImaging_XbmEncoderNew(PyObject* self, PyObject* args);
3129
extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args);
3131
/* Display support etc (in display.c) */
3133
extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args);
3134
extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args);
3135
extern PyObject* PyImaging_DisplayModeWin32(PyObject* self, PyObject* args);
3136
extern PyObject* PyImaging_GrabScreenWin32(PyObject* self, PyObject* args);
3137
extern PyObject* PyImaging_GrabClipboardWin32(PyObject* self, PyObject* args);
3138
extern PyObject* PyImaging_ListWindowsWin32(PyObject* self, PyObject* args);
3139
extern PyObject* PyImaging_EventLoopWin32(PyObject* self, PyObject* args);
3140
extern PyObject* PyImaging_DrawWmf(PyObject* self, PyObject* args);
3143
/* Experimental path stuff (in path.c) */
3144
extern PyObject* PyPath_Create(ImagingObject* self, PyObject* args);
3146
/* Experimental outline stuff (in outline.c) */
3147
extern PyObject* PyOutline_Create(ImagingObject* self, PyObject* args);
3149
extern PyObject* PyImaging_Mapper(PyObject* self, PyObject* args);
3150
extern PyObject* PyImaging_MapBuffer(PyObject* self, PyObject* args);
3152
static PyMethodDef functions[] = {
3154
/* Object factories */
3155
{"blend", (PyCFunction)_blend, 1},
3156
{"fill", (PyCFunction)_fill, 1},
3157
{"new", (PyCFunction)_new, 1},
3159
{"getcount", (PyCFunction)_getcount, 1},
3162
{"convert", (PyCFunction)_convert2, 1},
3163
{"copy", (PyCFunction)_copy2, 1},
3166
{"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, 1},
3167
{"eps_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1},
3168
{"fli_decoder", (PyCFunction)PyImaging_FliDecoderNew, 1},
3169
{"gif_decoder", (PyCFunction)PyImaging_GifDecoderNew, 1},
3170
{"gif_encoder", (PyCFunction)PyImaging_GifEncoderNew, 1},
3171
{"hex_decoder", (PyCFunction)PyImaging_HexDecoderNew, 1},
3172
{"hex_encoder", (PyCFunction)PyImaging_EpsEncoderNew, 1}, /* EPS=HEX! */
3174
{"jpeg_decoder", (PyCFunction)PyImaging_JpegDecoderNew, 1},
3175
{"jpeg_encoder", (PyCFunction)PyImaging_JpegEncoderNew, 1},
3177
{"tiff_lzw_decoder", (PyCFunction)PyImaging_TiffLzwDecoderNew, 1},
3178
{"msp_decoder", (PyCFunction)PyImaging_MspDecoderNew, 1},
3179
{"packbits_decoder", (PyCFunction)PyImaging_PackbitsDecoderNew, 1},
3180
{"pcd_decoder", (PyCFunction)PyImaging_PcdDecoderNew, 1},
3181
{"pcx_decoder", (PyCFunction)PyImaging_PcxDecoderNew, 1},
3182
{"pcx_encoder", (PyCFunction)PyImaging_PcxEncoderNew, 1},
3183
{"raw_decoder", (PyCFunction)PyImaging_RawDecoderNew, 1},
3184
{"raw_encoder", (PyCFunction)PyImaging_RawEncoderNew, 1},
3185
{"sun_rle_decoder", (PyCFunction)PyImaging_SunRleDecoderNew, 1},
3186
{"tga_rle_decoder", (PyCFunction)PyImaging_TgaRleDecoderNew, 1},
3187
{"xbm_decoder", (PyCFunction)PyImaging_XbmDecoderNew, 1},
3188
{"xbm_encoder", (PyCFunction)PyImaging_XbmEncoderNew, 1},
3190
{"zip_decoder", (PyCFunction)PyImaging_ZipDecoderNew, 1},
3191
{"zip_encoder", (PyCFunction)PyImaging_ZipEncoderNew, 1},
3194
/* Memory mapping */
3197
{"map", (PyCFunction)PyImaging_Mapper, 1},
3199
{"map_buffer", (PyCFunction)PyImaging_MapBuffer, 1},
3202
/* Display support */
3204
{"display", (PyCFunction)PyImaging_DisplayWin32, 1},
3205
{"display_mode", (PyCFunction)PyImaging_DisplayModeWin32, 1},
3206
{"grabscreen", (PyCFunction)PyImaging_GrabScreenWin32, 1},
3207
{"grabclipboard", (PyCFunction)PyImaging_GrabClipboardWin32, 1},
3208
{"createwindow", (PyCFunction)PyImaging_CreateWindowWin32, 1},
3209
{"eventloop", (PyCFunction)PyImaging_EventLoopWin32, 1},
3210
{"listwindows", (PyCFunction)PyImaging_ListWindowsWin32, 1},
3211
{"drawwmf", (PyCFunction)PyImaging_DrawWmf, 1},
3215
{"crc32", (PyCFunction)_crc32, 1},
3216
{"getcodecstatus", (PyCFunction)_getcodecstatus, 1},
3218
/* Debugging stuff */
3219
{"open_ppm", (PyCFunction)_open_ppm, 1},
3221
/* Special effects (experimental) */
3223
{"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1},
3224
{"effect_noise", (PyCFunction)_effect_noise, 1},
3225
{"linear_gradient", (PyCFunction)_linear_gradient, 1},
3226
{"radial_gradient", (PyCFunction)_radial_gradient, 1},
3227
{"wedge", (PyCFunction)_linear_gradient, 1}, /* Compatibility */
3230
/* Drawing support stuff */
3231
#ifdef WITH_IMAGEDRAW
3232
{"font", (PyCFunction)_font_new, 1},
3233
{"draw", (PyCFunction)_draw_new, 1},
3236
/* Experimental path stuff */
3237
#ifdef WITH_IMAGEPATH
3238
{"path", (PyCFunction)PyPath_Create, 1},
3241
/* Experimental arrow graphics stuff */
3243
{"outline", (PyCFunction)PyOutline_Create, 1},
3246
{NULL, NULL} /* sentinel */
3255
/* Patch object type */
3256
Imaging_Type.ob_type = &PyType_Type;
3257
#ifdef WITH_IMAGEDRAW
3258
ImagingFont_Type.ob_type = &PyType_Type;
3259
ImagingDraw_Type.ob_type = &PyType_Type;
3261
PixelAccess_Type.ob_type = &PyType_Type;
3263
ImagingAccessInit();
3265
m = Py_InitModule("_imaging", functions);
3266
d = PyModule_GetDict(m);
3270
extern const char* ImagingJpegVersion(void);
3271
PyDict_SetItemString(d, "jpeglib_version", PyString_FromString(ImagingJpegVersion()));
3277
extern const char* ImagingZipVersion(void);
3278
PyDict_SetItemString(d, "zlib_version", PyString_FromString(ImagingZipVersion()));