45
41
} ImagingDisplayObject;
47
staticforward PyTypeObject ImagingDisplayType;
43
static PyTypeObject ImagingDisplayType;
49
45
static ImagingDisplayObject*
50
46
_new(const char* mode, int xsize, int ysize)
52
48
ImagingDisplayObject *display;
50
if (PyType_Ready(&ImagingDisplayType) < 0)
54
53
display = PyObject_New(ImagingDisplayObject, &ImagingDisplayType);
55
54
if (display == NULL)
179
_fromstring(ImagingDisplayObject* display, PyObject* args)
178
_frombytes(ImagingDisplayObject* display, PyObject* args)
183
#if PY_VERSION_HEX >= 0x03000000
184
if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes))
183
187
if (!PyArg_ParseTuple(args, "s#:fromstring", &ptr, &bytes))
186
191
if (display->dib->ysize * display->dib->linesize != bytes) {
187
192
PyErr_SetString(PyExc_ValueError, "wrong size");
198
_tostring(ImagingDisplayObject* display, PyObject* args)
203
_tobytes(ImagingDisplayObject* display, PyObject* args)
205
#if PY_VERSION_HEX >= 0x03000000
206
if (!PyArg_ParseTuple(args, ":tobytes"))
200
209
if (!PyArg_ParseTuple(args, ":tostring"))
203
return PyString_FromStringAndSize(
213
return PyBytes_FromStringAndSize(
204
214
display->dib->bits, display->dib->ysize * display->dib->linesize
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},
217
231
{NULL, NULL} /* sentinel */
221
_getattr(ImagingDisplayObject* self, char* name)
235
_getattr_mode(ImagingDisplayObject* self, void* closure)
225
res = Py_FindMethod(methods, (PyObject*) self, name);
229
if (!strcmp(name, "mode"))
230
237
return Py_BuildValue("s", self->dib->mode);
231
if (!strcmp(name, "size"))
241
_getattr_size(ImagingDisplayObject* self, void* closure)
232
243
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
233
PyErr_SetString(PyExc_AttributeError, name);
237
statichere PyTypeObject ImagingDisplayType = {
238
PyObject_HEAD_INIT(NULL)
246
static struct PyGetSetDef getsetters[] = {
247
{ "mode", (getter) _getattr_mode },
248
{ "size", (getter) _getattr_size },
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*/
244
258
(destructor)_delete, /*tp_dealloc*/
246
(getattrfunc)_getattr, /*tp_getattr*/
265
0, /*tp_as_sequence */
266
0, /*tp_as_mapping */
273
Py_TPFLAGS_DEFAULT, /*tp_flags*/
277
0, /*tp_richcompare*/
278
0, /*tp_weaklistoffset*/
281
methods, /*tp_methods*/
283
getsetters, /*tp_getset*/
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))