Lines 418-437
static PyObject *
Link Here
|
418 |
image_surface_create_for_data (PyTypeObject *type, PyObject *args) { |
418 |
image_surface_create_for_data (PyTypeObject *type, PyObject *args) { |
419 |
cairo_surface_t *surface; |
419 |
cairo_surface_t *surface; |
420 |
cairo_format_t format; |
420 |
cairo_format_t format; |
421 |
unsigned char *buffer; |
|
|
422 |
int width, height, stride = -1, res; |
421 |
int width, height, stride = -1, res; |
423 |
Py_ssize_t buffer_len; |
|
|
424 |
PyObject *obj; |
422 |
PyObject *obj; |
425 |
|
423 |
Py_buffer buffer; |
426 |
// buffer function disabled |
|
|
427 |
PyErr_SetString(PyExc_NotImplementedError, "Surface.create_for_data: Not Implemented yet."); |
428 |
return NULL; |
429 |
|
424 |
|
430 |
if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data", |
425 |
if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data", |
431 |
&obj, &format, &width, &height, &stride)) |
426 |
&obj, &format, &width, &height, &stride)) |
432 |
return NULL; |
427 |
return NULL; |
433 |
|
428 |
|
434 |
res = PyObject_AsWriteBuffer (obj, (void **)&buffer, &buffer_len); |
429 |
res = PyObject_GetBuffer (obj, &buffer, PyBUF_WRITABLE); |
435 |
if (res == -1) |
430 |
if (res == -1) |
436 |
return NULL; |
431 |
return NULL; |
437 |
|
432 |
|
Lines 452-463
image_surface_create_for_data (PyTypeObject *type, PyObject *args) {
Link Here
|
452 |
return NULL; |
447 |
return NULL; |
453 |
} |
448 |
} |
454 |
} |
449 |
} |
455 |
if (height * stride > buffer_len) { |
450 |
if (height * stride > buffer.len) { |
456 |
PyErr_SetString(PyExc_TypeError, "buffer is not long enough"); |
451 |
PyErr_SetString(PyExc_TypeError, "buffer is not long enough"); |
457 |
return NULL; |
452 |
return NULL; |
458 |
} |
453 |
} |
459 |
Py_BEGIN_ALLOW_THREADS; |
454 |
Py_BEGIN_ALLOW_THREADS; |
460 |
surface = cairo_image_surface_create_for_data (buffer, format, width, |
455 |
surface = cairo_image_surface_create_for_data (buffer.buf, format, width, |
461 |
height, stride); |
456 |
height, stride); |
462 |
Py_END_ALLOW_THREADS; |
457 |
Py_END_ALLOW_THREADS; |
463 |
return PycairoSurface_FromSurface(surface, obj); |
458 |
return PycairoSurface_FromSurface(surface, obj); |
Lines 546-554
image_surface_format_stride_for_width (PyObject *self, PyObject *args) {
Link Here
|
546 |
|
541 |
|
547 |
static PyObject * |
542 |
static PyObject * |
548 |
image_surface_get_data (PycairoImageSurface *o) { |
543 |
image_surface_get_data (PycairoImageSurface *o) { |
549 |
PyErr_SetString(PyExc_NotImplementedError, "Surface.get_data: Not Implemented yet."); |
544 |
Py_buffer buffer; |
|
|
545 |
void *data; |
546 |
int height, stride; |
547 |
|
548 |
height = cairo_image_surface_get_height (o->surface); |
549 |
stride = cairo_image_surface_get_stride (o->surface); |
550 |
data = cairo_image_surface_get_data (o->surface); |
551 |
|
552 |
if(!PyBuffer_FillInfo(&buffer, NULL, data, height * stride, 0, PyBUF_CONTIG)) |
553 |
return PyMemoryView_FromBuffer(&buffer); |
550 |
return NULL; |
554 |
return NULL; |
551 |
// return PyBuffer_FromReadWriteObject((PyObject *)o, 0, Py_END_OF_BUFFER); |
|
|
552 |
} |
555 |
} |
553 |
|
556 |
|
554 |
static PyObject * |
557 |
static PyObject * |