~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to display.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "Python.h"
27
27
 
28
 
#if PY_VERSION_HEX < 0x01060000
29
 
#define PyObject_New PyObject_NEW
30
 
#define PyObject_Del PyMem_DEL
31
 
#endif
32
 
 
33
28
#include "Imaging.h"
 
29
#include "py3.h"
34
30
 
35
31
/* -------------------------------------------------------------------- */
36
32
/* Windows DIB support  */
44
40
    ImagingDIB dib;
45
41
} ImagingDisplayObject;
46
42
 
47
 
staticforward PyTypeObject ImagingDisplayType;
 
43
static PyTypeObject ImagingDisplayType;
48
44
 
49
45
static ImagingDisplayObject*
50
46
_new(const char* mode, int xsize, int ysize)
51
47
{
52
48
    ImagingDisplayObject *display;
53
49
 
 
50
    if (PyType_Ready(&ImagingDisplayType) < 0)
 
51
        return NULL;
 
52
 
54
53
    display = PyObject_New(ImagingDisplayObject, &ImagingDisplayType);
55
54
    if (display == NULL)
56
55
        return NULL;
176
175
}
177
176
 
178
177
static PyObject*
179
 
_fromstring(ImagingDisplayObject* display, PyObject* args)
 
178
_frombytes(ImagingDisplayObject* display, PyObject* args)
180
179
{
181
180
    char* ptr;
182
181
    int bytes;
 
182
 
 
183
#if PY_VERSION_HEX >= 0x03000000
 
184
    if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes))
 
185
        return NULL;
 
186
#else
183
187
    if (!PyArg_ParseTuple(args, "s#:fromstring", &ptr, &bytes))
184
 
        return NULL;
 
188
        return NULL;
 
189
#endif
185
190
 
186
191
    if (display->dib->ysize * display->dib->linesize != bytes) {
187
192
        PyErr_SetString(PyExc_ValueError, "wrong size");
195
200
}
196
201
 
197
202
static PyObject*
198
 
_tostring(ImagingDisplayObject* display, PyObject* args)
 
203
_tobytes(ImagingDisplayObject* display, PyObject* args)
199
204
{
 
205
#if PY_VERSION_HEX >= 0x03000000
 
206
    if (!PyArg_ParseTuple(args, ":tobytes"))
 
207
        return NULL;
 
208
#else
200
209
    if (!PyArg_ParseTuple(args, ":tostring"))
201
 
        return NULL;
 
210
        return NULL;
 
211
#endif
202
212
 
203
 
    return PyString_FromStringAndSize(
 
213
    return PyBytes_FromStringAndSize(
204
214
        display->dib->bits, display->dib->ysize * display->dib->linesize
205
215
        );
206
216
}
212
222
    {"query_palette", (PyCFunction)_query_palette, 1},
213
223
    {"getdc", (PyCFunction)_getdc, 1},
214
224
    {"releasedc", (PyCFunction)_releasedc, 1},
215
 
    {"fromstring", (PyCFunction)_fromstring, 1},
216
 
    {"tostring", (PyCFunction)_tostring, 1},
 
225
    {"frombytes", (PyCFunction)_frombytes, 1},
 
226
    {"tobytes", (PyCFunction)_tobytes, 1},
 
227
#if PY_VERSION_HEX < 0x03000000
 
228
    {"fromstring", (PyCFunction)_frombytes, 1},
 
229
    {"tostring", (PyCFunction)_tobytes, 1},
 
230
#endif
217
231
    {NULL, NULL} /* sentinel */
218
232
};
219
233
 
220
 
static PyObject*  
221
 
_getattr(ImagingDisplayObject* self, char* name)
 
234
static PyObject*
 
235
_getattr_mode(ImagingDisplayObject* self, void* closure)
222
236
{
223
 
    PyObject* res;
224
 
 
225
 
    res = Py_FindMethod(methods, (PyObject*) self, name);
226
 
    if (res)
227
 
        return res;
228
 
    PyErr_Clear();
229
 
    if (!strcmp(name, "mode"))
230
237
        return Py_BuildValue("s", self->dib->mode);
231
 
    if (!strcmp(name, "size"))
 
238
}
 
239
 
 
240
static PyObject*
 
241
_getattr_size(ImagingDisplayObject* self, void* closure)
 
242
{
232
243
        return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
233
 
    PyErr_SetString(PyExc_AttributeError, name);
234
 
    return NULL;
235
244
}
236
245
 
237
 
statichere PyTypeObject ImagingDisplayType = {
238
 
        PyObject_HEAD_INIT(NULL)
239
 
        0,                              /*ob_size*/
 
246
static struct PyGetSetDef getsetters[] = {
 
247
    { "mode",   (getter) _getattr_mode },
 
248
    { "size",   (getter) _getattr_size },
 
249
    { NULL }
 
250
};
 
251
 
 
252
static PyTypeObject ImagingDisplayType = {
 
253
        PyVarObject_HEAD_INIT(NULL, 0)
240
254
        "ImagingDisplay",               /*tp_name*/
241
255
        sizeof(ImagingDisplayObject),   /*tp_size*/
242
256
        0,                              /*tp_itemsize*/
243
257
        /* methods */
244
258
        (destructor)_delete,            /*tp_dealloc*/
245
259
        0,                              /*tp_print*/
246
 
        (getattrfunc)_getattr,          /*tp_getattr*/
247
 
        0,                              /*tp_setattr*/
248
 
        0,                              /*tp_compare*/
249
 
        0,                              /*tp_repr*/
250
 
        0,                              /*tp_hash*/
 
260
    0,                          /*tp_getattr*/
 
261
    0,                          /*tp_setattr*/
 
262
    0,                          /*tp_compare*/
 
263
    0,                          /*tp_repr*/
 
264
    0,                          /*tp_as_number */
 
265
    0,                          /*tp_as_sequence */
 
266
    0,                          /*tp_as_mapping */
 
267
    0,                          /*tp_hash*/
 
268
    0,                          /*tp_call*/
 
269
    0,                          /*tp_str*/
 
270
    0,                          /*tp_getattro*/
 
271
    0,                          /*tp_setattro*/
 
272
    0,                          /*tp_as_buffer*/
 
273
    Py_TPFLAGS_DEFAULT,         /*tp_flags*/
 
274
    0,                          /*tp_doc*/
 
275
    0,                          /*tp_traverse*/
 
276
    0,                          /*tp_clear*/
 
277
    0,                          /*tp_richcompare*/
 
278
    0,                          /*tp_weaklistoffset*/
 
279
    0,                          /*tp_iter*/
 
280
    0,                          /*tp_iternext*/
 
281
    methods,                    /*tp_methods*/
 
282
    0,                          /*tp_members*/
 
283
    getsetters,                 /*tp_getset*/
251
284
};
252
285
 
253
286
PyObject*
749
782
    int datasize;
750
783
    int width, height;
751
784
    int x0, y0, x1, y1;
752
 
    if (!PyArg_ParseTuple(args, "s#(ii)(iiii):_load", &data, &datasize,
 
785
    if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH"(ii)(iiii):_load", &data, &datasize,
753
786
                          &width, &height, &x0, &x1, &y0, &y1))
754
787
        return NULL;
755
788