Skip to content

Use CFFI for the pixel access object #248

@wiredfool

Description

@wiredfool

Hoisted from #67, post-close, with additional brain dumping.

@fijal said:

If you need to call, call it with cffi (C functions directly) instead of C API. That would be much better and should be reasonably fast on pypy. Pure python is obviously better (you avoid function calls), but cffi is definitely next good, if the image does not export any way to get to the raw data. to be perfectly clear - I doubt there is no way to access raw data one way or another. The ideal way would be to get the raw data pointer and access it via cffi.

The crux that I see is that (IIRC) the data isn't necessarily in a continuous block. If it were, the raw data pointer would be easy.

The backbrain is thinking that the solution might be related to checking the strides from #224. If the data's not continuous, we can fall back to slow access.

If a cffi approach would work, we'd need to require cffi and libffi-dev, but it's really only necessary on pypy, and anyone doing this on pypy would likely be ok an additional dependency.

Docs are here: http://cffi.readthedocs.org/en/latest/index.html
It looks like this is what we'd need:

ffi.buffer(cdata, [size]): return a buffer object that references the raw C data pointed to by the given ‘cdata’, of ‘size’ bytes. The ‘cdata’ must be a pointer or an array.

So, Assuming that I can get a pointer from something like PyLong_FromVoidPtr, this should give higher performance access to the pixel_access_object.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions