jamesbowman / openexrpython

OpenEXR bindings for Python
Other
94 stars 35 forks source link

add buffer protocol support to writePixels #9

Closed markreidvfx closed 7 years ago

markreidvfx commented 7 years ago

Hi, The following pull request adds buffer protocol support to writePixels. https://docs.python.org/3/c-api/buffer.html This allows objects that expose the buffer protocol to be passed directly to writePixels without needing to copy the image data to a str or bytes object.

For example, numpy arrays can be passed directly to writePixels:

import numpy
import OpenEXR

pixels = numpy.random.rand(640, 480).astype(numpy.float32)
h = OpenEXR.Header(640,480)
exr = OpenEXR.OutputFile("out.exr", h)
exr.writePixels({'R': pixels, 'G': pixels, 'B': pixels})
exr.close()
jamesbowman commented 7 years ago

Excellent, thanks.