~ubuntu-branches/ubuntu/trusty/python-imaging/trusty

« back to all changes in this revision

Viewing changes to _imaging.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-11-20 19:22:59 UTC
  • mfrom: (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091120192259-cmnfui5tv2jtq4xu
Tags: 1.1.7-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * The Python Imaging Library.
3
 
 * $Id: _imaging.c 2935 2006-12-03 12:20:39Z fredrik $
4
3
 *
5
4
 * the imaging library bindings
6
5
 *
89
88
#define WITH_RANKFILTER /* rank filter */
90
89
#define WITH_MODEFILTER /* mode filter */
91
90
#define WITH_THREADING /* "friendly" threading support */
 
91
#define WITH_UNSHARPMASK /* Kevin Cazabon's unsharpmask module */
92
92
 
93
93
#define WITH_DEBUG /* extra debugging interfaces */
94
94
 
109
109
#endif
110
110
 
111
111
#if PY_VERSION_HEX < 0x02050000
 
112
#define Py_ssize_t int
112
113
#define ssizeargfunc intargfunc
113
114
#define ssizessizeargfunc intintargfunc
114
115
#define ssizeobjargproc intobjargproc
122
123
typedef struct {
123
124
    PyObject_HEAD
124
125
    Imaging image;
 
126
    ImagingAccess access;
125
127
} ImagingObject;
126
128
 
127
129
staticforward PyTypeObject Imaging_Type;
186
188
#endif
187
189
 
188
190
    imagep->image = imOut;
 
191
    imagep->access = ImagingAccessNew(imOut);
189
192
 
190
193
    return (PyObject*) imagep;
191
194
}
198
201
    printf("imaging %p deleted\n", imagep);
199
202
#endif
200
203
 
 
204
    if (imagep->access)
 
205
      ImagingAccessDelete(imagep->image, imagep->access);
201
206
    ImagingDelete(imagep->image);
202
207
    PyObject_Del(imagep);
203
208
}
234
239
}
235
240
 
236
241
/* -------------------------------------------------------------------- */
 
242
/* BUFFER HANDLING                                                      */
 
243
/* -------------------------------------------------------------------- */
 
244
/* Python compatibility API */
 
245
 
 
246
#if PY_VERSION_HEX < 0x02020000
 
247
 
 
248
int PyImaging_CheckBuffer(PyObject *buffer)
 
249
{
 
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)
 
253
        return 1;
 
254
    return 0;
 
255
}
 
256
 
 
257
int PyImaging_ReadBuffer(PyObject* buffer, const void** ptr)
 
258
{
 
259
    PyBufferProcs *procs = buffer->ob_type->tp_as_buffer;
 
260
    return procs->bf_getreadbuffer(buffer, 0, ptr);
 
261
}
 
262
 
 
263
#else
 
264
 
 
265
int PyImaging_CheckBuffer(PyObject* buffer)
 
266
{
 
267
    return PyObject_CheckReadBuffer(buffer);
 
268
}
 
269
 
 
270
int PyImaging_ReadBuffer(PyObject* buffer, const void** ptr)
 
271
{
 
272
    /* must call check_buffer first! */
 
273
#if PY_VERSION_HEX < 0x02050000
 
274
    int n = 0;
 
275
#else
 
276
    Py_ssize_t n = 0;
 
277
#endif
 
278
    PyObject_AsReadBuffer(buffer, ptr, &n);
 
279
    return (int) n;
 
280
}
 
281
 
 
282
#endif
 
283
 
 
284
/* -------------------------------------------------------------------- */
237
285
/* EXCEPTION REROUTING                                                  */
238
286
/* -------------------------------------------------------------------- */
239
287
 
284
332
    return NULL;
285
333
}
286
334
 
 
335
void
 
336
ImagingError_Clear(void)
 
337
{
 
338
    PyErr_Clear();
 
339
}
287
340
 
288
341
/* -------------------------------------------------------------------- */
289
342
/* HELPERS                                                              */
330
383
    }
331
384
 
332
385
    list = malloc(n * (type & 0xff));
333
 
    if (!list) {
334
 
        PyErr_NoMemory();
335
 
        return NULL;
336
 
    }
 
386
    if (!list)
 
387
        return PyErr_NoMemory();
337
388
 
338
389
    switch (type) {
339
390
    case TYPE_UINT8:
411
462
}
412
463
 
413
464
static inline PyObject*
414
 
getpixel(Imaging im, int x, int y)
 
465
getpixel(Imaging im, ImagingAccess access, int x, int y)
415
466
{
416
 
    UINT8 *p;
 
467
    union {
 
468
      UINT8 b[4];
 
469
      INT16 h;
 
470
      INT32 i;
 
471
      FLOAT32 f;
 
472
    } pixel;
417
473
 
418
474
    if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
419
475
        PyErr_SetString(PyExc_IndexError, outside_image);
420
476
        return NULL;
421
477
    }
422
478
 
423
 
    /* single layer */
424
 
    if (im->image8 != NULL) {
425
 
        p = (UINT8*) &im->image8[y][x];
426
 
        switch (im->type) {
427
 
        case IMAGING_TYPE_UINT8:
428
 
            return PyInt_FromLong(p[0]);
429
 
        case IMAGING_TYPE_SPECIAL:
430
 
            /* FIXME: are 16-bit images signed or unsigned??? */
431
 
            if (strcmp(im->mode, "I;16") == 0) {
432
 
                p = (UINT8*) &im->image8[y][x+x];
433
 
                return PyInt_FromLong(L16(p, 0));
434
 
            }
435
 
            if (strcmp(im->mode, "I;16B") == 0) {
436
 
                p = (UINT8*) &im->image8[y][x+x];
437
 
                return PyInt_FromLong(B16(p, 0));
438
 
            }
439
 
        }
440
 
    }
441
 
 
442
 
    /* multilayer */
443
 
    if (im->image32 != NULL) {
444
 
        p = (UINT8*) &im->image32[y][x];
445
 
        switch (im->type) {
446
 
        case IMAGING_TYPE_UINT8:
447
 
            /* unsigned integer */
448
 
            if (im->bands == 2)
449
 
                return Py_BuildValue("ii", p[0], p[3]);
450
 
            if (im->bands == 3)
451
 
                return Py_BuildValue("iii", p[0], p[1], p[2]);
452
 
            return Py_BuildValue("iiii", p[0], p[1], p[2], p[3]);
453
 
        case IMAGING_TYPE_INT32:
454
 
            /* signed integer */
455
 
            return PyInt_FromLong(*(INT32*) p);
456
 
        case IMAGING_TYPE_FLOAT32:
457
 
            /* floating point */
458
 
            return PyFloat_FromDouble(*(FLOAT32*) p);
459
 
        }
460
 
    }
461
 
        
 
479
    access->get_pixel(im, x, y, &pixel);
 
480
 
 
481
    switch (im->type) {
 
482
    case IMAGING_TYPE_UINT8:
 
483
      switch (im->bands) {
 
484
      case 1:
 
485
        return PyInt_FromLong(pixel.b[0]);
 
486
      case 2:
 
487
        return Py_BuildValue("ii", pixel.b[0], pixel.b[1]);
 
488
      case 3:
 
489
        return Py_BuildValue("iii", pixel.b[0], pixel.b[1], pixel.b[2]);
 
490
      case 4:
 
491
        return Py_BuildValue("iiii", pixel.b[0], pixel.b[1], pixel.b[2], pixel.b[3]);
 
492
      }
 
493
      break;
 
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);
 
501
      break;
 
502
    }
 
503
 
462
504
    /* unknown type */
463
505
    Py_INCREF(Py_None);
464
506
    return Py_None;
473
515
    /* fill ink buffer (four bytes) with something that can
474
516
       be cast to either UINT8 or INT32 */
475
517
 
476
 
    if (im->image8) {
477
 
        /* unsigned integer, single layer */
478
 
        r = PyInt_AsLong(color);
479
 
        if (r == -1 && PyErr_Occurred())
480
 
            return NULL;
481
 
        ink[0] = CLIP(r);
482
 
        ink[1] = ink[2] = ink[3] = 0;
483
 
        return ink;
484
 
    } else {
485
 
        switch (im->type) {
486
 
        case IMAGING_TYPE_UINT8:
487
 
            /* unsigned integer */
 
518
    switch (im->type) {
 
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())
 
525
                return NULL;
 
526
            ink[0] = CLIP(r);
 
527
            ink[1] = ink[2] = ink[3] = 0;
 
528
        } else {
488
529
            a = 255;
489
530
            if (PyInt_Check(color)) {
490
531
                r = PyInt_AS_LONG(color);
507
548
            ink[1] = CLIP(g);
508
549
            ink[2] = CLIP(b);
509
550
            ink[3] = CLIP(a);
510
 
            return ink;
511
 
        case IMAGING_TYPE_INT32:
512
 
            /* signed integer */
 
551
        }
 
552
        return ink;
 
553
    case IMAGING_TYPE_INT32:
 
554
        /* signed integer */
 
555
        r = PyInt_AsLong(color);
 
556
        if (r == -1 && PyErr_Occurred())
 
557
            return NULL;
 
558
        *(INT32*) ink = r;
 
559
        return ink;
 
560
    case IMAGING_TYPE_FLOAT32:
 
561
        /* floating point */
 
562
        f = PyFloat_AsDouble(color);
 
563
        if (f == -1.0 && PyErr_Occurred())
 
564
            return NULL;
 
565
        *(FLOAT32*) ink = (FLOAT32) f;
 
566
        return ink;
 
567
    case IMAGING_TYPE_SPECIAL:
 
568
        if (strncmp(im->mode, "I;16", 4) == 0) {
513
569
            r = PyInt_AsLong(color);
514
570
            if (r == -1 && PyErr_Occurred())
515
571
                return NULL;
516
 
            *(INT32*) ink = r;
517
 
            return ink;
518
 
        case IMAGING_TYPE_FLOAT32:
519
 
            /* floating point */
520
 
            f = PyFloat_AsDouble(color);
521
 
            if (f == -1.0 && PyErr_Occurred())
522
 
                return NULL;
523
 
            *(FLOAT32*) ink = (FLOAT32) f;
 
572
            ink[0] = (UINT8) r;
 
573
            ink[1] = (UINT8) (r >> 8);
 
574
            ink[2] = ink[3] = 0;
524
575
            return ink;
525
576
        }
526
577
    }
560
611
    } else
561
612
        buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0;
562
613
 
563
 
    ImagingFill(im, buffer);
 
614
    (void) ImagingFill(im, buffer);
564
615
 
565
616
    return PyImagingNew(im);
566
617
}
802
853
    return imOut;
803
854
}
804
855
 
 
856
#ifdef WITH_UNSHARPMASK
 
857
static PyObject* 
 
858
_gaussian_blur(ImagingObject* self, PyObject* args)
 
859
{
 
860
    Imaging imIn;
 
861
    Imaging imOut;
 
862
 
 
863
    float radius = 0;
 
864
    if (!PyArg_ParseTuple(args, "f", &radius))
 
865
        return NULL;
 
866
 
 
867
    imIn = self->image;
 
868
    imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
 
869
    if (!imOut)
 
870
        return NULL;
 
871
 
 
872
    if (!ImagingGaussianBlur(imIn, imOut, radius))
 
873
        return NULL;
 
874
 
 
875
    return PyImagingNew(imOut);
 
876
}
 
877
#endif
 
878
 
805
879
static PyObject* 
806
880
_getpalette(ImagingObject* self, PyObject* args)
807
881
{
896
970
    if (_getxy(xy, &x, &y))
897
971
        return NULL;
898
972
 
899
 
    return getpixel(self->image, x, y);
 
973
    if (self->access == NULL) {
 
974
        Py_INCREF(Py_None);
 
975
        return Py_None;
 
976
    }
 
977
 
 
978
    return getpixel(self->image, self->access, x, y);
900
979
}
901
980
 
902
981
static PyObject*
1170
1249
                if (PyList_Check(data)) {
1171
1250
                    for (i = x = y = 0; i < n; i++) {
1172
1251
                        PyObject *op = PyList_GET_ITEM(data, i);
1173
 
                        image->image8[y][x] = CLIP(PyInt_AsLong(op));
 
1252
                        image->image8[y][x] = (UINT8) CLIP(PyInt_AsLong(op));
1174
1253
                        if (++x >= (int) image->xsize)
1175
1254
                            x = 0, y++;
1176
1255
                    }
1177
1256
                } else {
1178
1257
                    for (i = x = y = 0; i < n; i++) {
1179
1258
                        PyObject *op = PySequence_GetItem(data, i);
1180
 
                        image->image8[y][x] = CLIP(PyInt_AsLong(op));
 
1259
                        image->image8[y][x] = (UINT8) CLIP(PyInt_AsLong(op));
1181
1260
                        Py_XDECREF(op);
1182
1261
                        if (++x >= (int) image->xsize)
1183
1262
                            x = 0, y++;
1358
1437
    if (!getink(color, im, ink))
1359
1438
        return NULL;
1360
1439
 
1361
 
    if (im->image8)
1362
 
        im->image8[y][x] = ink[0];
1363
 
    else
1364
 
        im->image32[y][x] = *((INT32*) ink);
 
1440
    if (self->access)
 
1441
        self->access->put_pixel(im, x, y, ink);
1365
1442
 
1366
1443
    Py_INCREF(Py_None);
1367
1444
    return Py_None;
1394
1471
 
1395
1472
    imOut = ImagingNew(imIn->mode, xsize, ysize);
1396
1473
    if (imOut)
1397
 
        ImagingResize(imOut, imIn, filter);
 
1474
        (void) ImagingResize(imOut, imIn, filter);
1398
1475
    
1399
1476
    return PyImagingNew(imOut);
1400
1477
}
1419
1496
    if (filter && imIn->type != IMAGING_TYPE_SPECIAL) {
1420
1497
        /* Rotate with resampling filter */
1421
1498
        imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1422
 
        ImagingRotate(imOut, imIn, theta, filter);
 
1499
        (void) ImagingRotate(imOut, imIn, theta, filter);
1423
1500
    } else if (theta == 90.0 || theta == 270.0) {
1424
1501
        /* Use fast version */
1425
1502
        imOut = ImagingNew(imIn->mode, imIn->ysize, imIn->xsize);
1426
1503
        if (imOut) {
1427
1504
            if (theta == 90.0)
1428
 
                ImagingRotate90(imOut, imIn);
 
1505
                (void) ImagingRotate90(imOut, imIn);
1429
1506
            else
1430
 
                ImagingRotate270(imOut, imIn);
 
1507
                (void) ImagingRotate270(imOut, imIn);
1431
1508
        }
1432
1509
    } else {
1433
1510
        imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
1434
1511
        if (imOut) {
1435
1512
            if (theta == 0.0)
1436
1513
                /* No rotation: simply copy the input image */
1437
 
                ImagingCopy2(imOut, imIn);
 
1514
                (void) ImagingCopy2(imOut, imIn);
1438
1515
            else if (theta == 180.0)
1439
1516
                /* Use fast version */
1440
 
                ImagingRotate180(imOut, imIn);
 
1517
                (void) ImagingRotate180(imOut, imIn);
1441
1518
            else
1442
1519
                /* Use ordinary version */
1443
 
                ImagingRotate(imOut, imIn, theta, 0);
 
1520
                (void) ImagingRotate(imOut, imIn, theta, 0);
1444
1521
        }
1445
1522
    }
1446
1523
 
1464
1541
 
1465
1542
    im = self->image;
1466
1543
 
1467
 
    /* FIXME: move this to a libImaging primitive (?) */
1468
 
    /* FIXME: add support for 1->L and L->1 */
 
1544
    /* move all logic in here to the libImaging primitive */
1469
1545
 
1470
1546
    if (!strcmp(im->mode, mode)) {
1471
1547
        ; /* same mode; always succeeds */
1474
1550
        strcpy(im->mode, mode);
1475
1551
        im->bands = modelen;
1476
1552
        if (!strcmp(mode, "RGBA"))
1477
 
            ImagingFillBand(im, 3, 255);
1478
 
    } else
1479
 
        return ImagingError_ModeError();
 
1553
            (void) ImagingFillBand(im, 3, 255);
 
1554
    } else {
 
1555
        /* trying doing an in-place conversion */
 
1556
        if (!ImagingConvertInPlace(im, mode))
 
1557
            return NULL;
 
1558
    }
 
1559
 
 
1560
    if (self->access)
 
1561
        ImagingAccessDelete(im, self->access);
 
1562
    self->access = ImagingAccessNew(im);
1480
1563
 
1481
1564
    Py_INCREF(Py_None);
1482
1565
    return Py_None;
1591
1674
            );
1592
1675
        break;
1593
1676
    default:
1594
 
        ImagingError_ValueError("bad transform method");
 
1677
        (void) ImagingError_ValueError("bad transform method");
1595
1678
    }
1596
1679
 
1597
1680
    free(a);
1633
1716
    if (imOut)
1634
1717
        switch (op) {
1635
1718
        case 0:
1636
 
            ImagingFlipLeftRight(imOut, imIn);
 
1719
            (void) ImagingFlipLeftRight(imOut, imIn);
1637
1720
            break;
1638
1721
        case 1:
1639
 
            ImagingFlipTopBottom(imOut, imIn);
 
1722
            (void) ImagingFlipTopBottom(imOut, imIn);
1640
1723
            break;
1641
1724
        case 2:
1642
 
            ImagingRotate90(imOut, imIn);
 
1725
            (void) ImagingRotate90(imOut, imIn);
1643
1726
            break;
1644
1727
        case 3:
1645
 
            ImagingRotate180(imOut, imIn);
 
1728
            (void) ImagingRotate180(imOut, imIn);
1646
1729
            break;
1647
1730
        case 4:
1648
 
            ImagingRotate270(imOut, imIn);
 
1731
            (void) ImagingRotate270(imOut, imIn);
1649
1732
            break;
1650
1733
        }
1651
1734
 
1652
1735
    return PyImagingNew(imOut);
1653
1736
}
1654
1737
 
 
1738
#ifdef WITH_UNSHARPMASK
 
1739
static PyObject* 
 
1740
_unsharp_mask(ImagingObject* self, PyObject* args)
 
1741
{
 
1742
    Imaging imIn;
 
1743
    Imaging imOut;
 
1744
 
 
1745
    float radius;
 
1746
    int percent, threshold;
 
1747
    if (!PyArg_ParseTuple(args, "fii", &radius, &percent, &threshold))
 
1748
        return NULL;
 
1749
 
 
1750
 
 
1751
    imIn = self->image;
 
1752
    imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
 
1753
    if (!imOut)
 
1754
        return NULL;
 
1755
 
 
1756
    if (!ImagingUnsharpMask(imIn, imOut, radius, percent, threshold))
 
1757
        return NULL;
 
1758
 
 
1759
    return PyImagingNew(imOut);
 
1760
}
 
1761
#endif
 
1762
 
1655
1763
/* -------------------------------------------------------------------- */
1656
1764
 
1657
1765
static PyObject* 
1695
1803
        for (i = 0; i < colors; i++) {
1696
1804
            ImagingColorItem* v = &items[i];
1697
1805
            PyObject* item = Py_BuildValue(
1698
 
                "iN", v->count, getpixel(self->image, v->x, v->y)
 
1806
                "iN", v->count, getpixel(self->image, self->access, v->x, v->y)
1699
1807
                );
1700
1808
            PyList_SetItem(out, i, item);
1701
1809
        }
1747
1855
    if (xprofile == NULL || yprofile == NULL) {
1748
1856
        free(xprofile);
1749
1857
        free(yprofile);
1750
 
        PyErr_NoMemory();
1751
 
        return NULL;
 
1858
        return PyErr_NoMemory();
1752
1859
    }
1753
1860
 
1754
1861
    ImagingGetProjection(self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
2066
2173
        return NULL;
2067
2174
 
2068
2175
    b = 0;
2069
 
    ImagingFill(im, &b);
 
2176
    (void) ImagingFill(im, &b);
2070
2177
 
2071
2178
    b = self->baseline;
2072
2179
    for (x = 0; *text; text++) {
2594
2701
    if (_getxy(xy, &x, &y))
2595
2702
        return NULL;
2596
2703
 
2597
 
    return getpixel(self->image->image, x, y);
 
2704
    return getpixel(self->image->image, self->image->access, x, y);
2598
2705
}
2599
2706
 
2600
2707
static int
2605
2712
    int x, y;
2606
2713
 
2607
2714
    if (self->readonly) {
2608
 
        ImagingError_ValueError(readonly);
 
2715
        (void) ImagingError_ValueError(readonly);
2609
2716
        return -1;
2610
2717
    }
2611
2718
 
2623
2730
    if (!getink(color, im, ink))
2624
2731
        return -1;
2625
2732
 
2626
 
    if (im->image8)
2627
 
        im->image8[y][x] = ink[0];
2628
 
    else
2629
 
        im->image32[y][x] = *((INT32*) ink);
 
2733
    self->image->access->put_pixel(im, x, y, ink);
2630
2734
 
2631
2735
    return 0;
2632
2736
}
2715
2819
 
2716
2820
    switch (status) {
2717
2821
    case IMAGING_CODEC_OVERRUN:
2718
 
        msg = "buffer overrun."; break;
 
2822
        msg = "buffer overrun"; break;
2719
2823
    case IMAGING_CODEC_BROKEN:
2720
 
        msg = "broken data stream."; break;
 
2824
        msg = "broken data stream"; break;
2721
2825
    case IMAGING_CODEC_UNKNOWN:
2722
 
        msg = "unrecognized data stream contents."; break;
 
2826
        msg = "unrecognized data stream contents"; break;
2723
2827
    case IMAGING_CODEC_CONFIG:
2724
 
        msg = "codec configuration error."; break;
 
2828
        msg = "codec configuration error"; break;
2725
2829
    case IMAGING_CODEC_MEMORY:
2726
 
        msg = "out of memory."; break;
 
2830
        msg = "out of memory"; break;
2727
2831
    default:
2728
2832
        Py_INCREF(Py_None);
2729
2833
        return Py_None;
2835
2939
    {"chop_xor", (PyCFunction)_chop_xor, 1},
2836
2940
#endif
2837
2941
 
 
2942
#ifdef WITH_UNSHARPMASK
 
2943
    /* Kevin Cazabon's unsharpmask extension */
 
2944
    {"gaussian_blur", (PyCFunction)_gaussian_blur, 1},
 
2945
    {"unsharp_mask", (PyCFunction)_unsharp_mask, 1},
 
2946
#endif
 
2947
 
2838
2948
#ifdef WITH_EFFECTS
2839
2949
    /* Special effects */
2840
2950
    {"effect_spread", (PyCFunction)_effect_spread, 1},
2880
2990
 
2881
2991
/* basic sequence semantics */
2882
2992
 
2883
 
static int
 
2993
static Py_ssize_t
2884
2994
image_length(ImagingObject *self)
2885
2995
{
2886
2996
    Imaging im = self->image;
2889
2999
}
2890
3000
 
2891
3001
static PyObject *
2892
 
image_item(ImagingObject *self, int i)
 
3002
image_item(ImagingObject *self, Py_ssize_t i)
2893
3003
{
2894
3004
    int x, y;
2895
3005
    Imaging im = self->image;
2900
3010
    } else
2901
3011
        x = y = 0; /* leave it to getpixel to raise an exception */
2902
3012
 
2903
 
    return getpixel(im, x, y);
 
3013
    return getpixel(im, self->access, x, y);
2904
3014
}
2905
3015
 
2906
3016
static PySequenceMethods image_as_sequence = {
2907
 
    (inquiry)image_length, /*sq_length*/
2908
 
    (binaryfunc)0, /*sq_concat*/
2909
 
    (ssizeargfunc)0, /*sq_repeat*/
2910
 
    (ssizeargfunc)image_item, /*sq_item*/
2911
 
    (ssizessizeargfunc)0, /*sq_slice*/
2912
 
    (ssizeobjargproc)0, /*sq_ass_item*/
2913
 
    (ssizessizeobjargproc)0, /*sq_ass_slice*/
 
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*/
2914
3024
};
2915
3025
 
2916
3026
 
2964
3074
#endif
2965
3075
 
2966
3076
static PyMappingMethods pixel_access_as_mapping = {
2967
 
    (inquiry)0, /*mp_length*/
2968
 
    (binaryfunc)pixel_access_getitem, /*mp_subscript*/
2969
 
    (objobjargproc)pixel_access_setitem, /*mp_ass_subscript*/
 
3077
    (inquiry) NULL, /*mp_length*/
 
3078
    (binaryfunc) pixel_access_getitem, /*mp_subscript*/
 
3079
    (objobjargproc) pixel_access_setitem, /*mp_ass_subscript*/
2970
3080
};
2971
3081
 
2972
3082
/* type description */
2990
3100
/* -------------------------------------------------------------------- */
2991
3101
 
2992
3102
/* FIXME: this is something of a mess.  Should replace this with
2993
 
   pluggable codecs, but not before PIL 1.1 */
 
3103
   pluggable codecs, but not before PIL 1.2 */
2994
3104
 
2995
3105
/* Decoders (in decode.c) */
2996
3106
extern PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args);
3018
3128
extern PyObject* PyImaging_XbmEncoderNew(PyObject* self, PyObject* args);
3019
3129
extern PyObject* PyImaging_ZipEncoderNew(PyObject* self, PyObject* args);
3020
3130
 
3021
 
/* Display support (in display.c) */
 
3131
/* Display support etc (in display.c) */
3022
3132
#ifdef WIN32
3023
3133
extern PyObject* PyImaging_CreateWindowWin32(PyObject* self, PyObject* args);
3024
3134
extern PyObject* PyImaging_DisplayWin32(PyObject* self, PyObject* args);
3027
3137
extern PyObject* PyImaging_GrabClipboardWin32(PyObject* self, PyObject* args);
3028
3138
extern PyObject* PyImaging_ListWindowsWin32(PyObject* self, PyObject* args);
3029
3139
extern PyObject* PyImaging_EventLoopWin32(PyObject* self, PyObject* args);
 
3140
extern PyObject* PyImaging_DrawWmf(PyObject* self, PyObject* args);
3030
3141
#endif
3031
3142
 
3032
3143
/* Experimental path stuff (in path.c) */
3097
3208
    {"createwindow", (PyCFunction)PyImaging_CreateWindowWin32, 1},
3098
3209
    {"eventloop", (PyCFunction)PyImaging_EventLoopWin32, 1},
3099
3210
    {"listwindows", (PyCFunction)PyImaging_ListWindowsWin32, 1},
 
3211
    {"drawwmf", (PyCFunction)PyImaging_DrawWmf, 1},
3100
3212
#endif
3101
3213
 
3102
3214
    /* Utilities */
3137
3249
DL_EXPORT(void)
3138
3250
init_imaging(void)
3139
3251
{
 
3252
    PyObject* m;
 
3253
    PyObject* d;
 
3254
 
3140
3255
    /* Patch object type */
3141
3256
    Imaging_Type.ob_type = &PyType_Type;
3142
3257
#ifdef WITH_IMAGEDRAW
3145
3260
#endif
3146
3261
    PixelAccess_Type.ob_type = &PyType_Type;
3147
3262
 
3148
 
    Py_InitModule("_imaging", functions);
 
3263
    ImagingAccessInit();
 
3264
 
 
3265
    m = Py_InitModule("_imaging", functions);
 
3266
    d = PyModule_GetDict(m);
 
3267
 
 
3268
#ifdef HAVE_LIBJPEG
 
3269
  {
 
3270
    extern const char* ImagingJpegVersion(void);
 
3271
    PyDict_SetItemString(d, "jpeglib_version", PyString_FromString(ImagingJpegVersion()));
 
3272
  }
 
3273
#endif
 
3274
 
 
3275
#ifdef HAVE_LIBZ
 
3276
  {
 
3277
    extern const char* ImagingZipVersion(void);
 
3278
    PyDict_SetItemString(d, "zlib_version", PyString_FromString(ImagingZipVersion()));
 
3279
  }
 
3280
#endif
3149
3281
}