Re: pygobject and buffers



On 4 September 2014 10:05, Matthias Vogelgesang
<matthias vogelgesang gmail com> wrote:
On 09/04/14 09:49, jcupitt gmail com wrote:
How have other people done this?

I wrote a tiny Python module that converts from our GObject-based buffer
class to a NumPy array [1]. Works okay but requires a memcpy.

That's neat. I wonder if you could avoid the memcpy()? The NumPy array
would need to keep a ref to a memoryview, which would in turn keep a
ref to your original GObject-based array.

I have something like this:

/**
 * vips_blob_get:
 * @blob: #VipsBlob to fetch from
 * @size: return number of bytes of data
 *
 * Get the data from a #VipsBlob.
 *
 * See also: vips_blob_new().
 *
 * Returns: (array length=size) (element-type guint8) (transfer none): the data
 */
const void *
vips_blob_get( VipsBlob *blob, size_t *size )
{
}

You'd think pygobject might be able to expose the return result as a
buffer object rather than a string. Then you could (potentially) get
it into NumPy with no memcpy() and no C needed.

You can imagine it being useful in the other direction too: you could
get maybe get binary image data out of NumPy and into cairo with fewer
copies.

John


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]