pybuffer

Assignment into Python 3.x Buffers with itemsize > 1

僤鯓⒐⒋嵵緔 提交于 2019-12-24 02:23:08
问题 I am trying to expose a buffer of image pixel information (32 bit RGBA) through the Python 3.x buffer interface. After quite a bit of playing around, I was able to get this working like so: int Image_get_buffer(PyObject* self, Py_buffer* view, int flags) { int img_len; void* img_bytes; // Do my image fetch magic get_image_pixel_data(self, &img_bytes, &img_len); // Let python fill my buffer PyBuffer_FillInfo(view, self, img_bytes, img_len, 0, flags); } And in python I can play with it like so:

Using Py_buffer and PyMemoryView_FromBuffer with different itemsizes

一笑奈何 提交于 2019-12-23 11:00:40
问题 This question is related to a previous question I asked. Namely this one if anyone is interested. Basically, what I want to do is to expose a C array to Python using a Py_buffer wrapped in a memoryview -object. I've gotten it to work using PyBuffer_FillInfo (work = I can manipulate the data in Python and write it to stdout in C), but if I try to roll my own buffer I get a segfault after the C function returns. I need to create my own buffer because PyBuffer_FillInfo assumes that the format is