Message165788
I think that I run into the same bug today. I've developing a PEP 3118 buffer interface for my wrapper of FreeImage. It returns the data as non-contiguous 3d array with the dimension height, width, color.
I've created a small test image with 5x7 RGB pixels. The first line black, second white, third grey values and the rest are red, green blue and cyan, magenta yellow in little endian (BGR order).
NumPy handles the buffer correctly:
>>> arr = numpy.asarray(img)
>>> print(arr)
[[[ 0 0 0]
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
[[255 255 255]
[255 255 255]
[255 255 255]
[255 255 255]
[255 255 255]]
[[ 80 80 80]
[112 112 112]
[160 160 160]
[192 192 192]
[240 240 240]]
[[ 0 0 255]
[ 0 255 0]
[255 0 0]
[ 0 0 255]
[ 0 255 0]]
[[255 0 0]
[ 0 0 255]
[ 0 255 0]
[255 0 0]
[ 0 0 255]]
[[ 0 255 0]
[255 0 0]
[ 0 0 255]
[ 0 255 0]
[255 0 0]]
[[255 255 0]
[255 0 255]
[ 0 255 255]
[255 255 0]
[255 0 255]]]
but memoryview.tobytes() seems to have an off-by-one error:
>>> m = memoryview(img)
>>> data = m.tobytes()
>>> len(data) == 5 * 7 * 3
True
>>> for i in range(7):
... print(" ".join("%3i" % ord(v) for v in data[i * 5 * 3:(i + 1) * 5 * 3]))
0 0 0 0 0 0 0 0 0 0 0 0 0 0 255
255 255 255 255 255 255 255 255 255 255 255 255 255 255 80
80 80 112 112 112 160 160 160 192 192 192 240 240 240 0
0 255 0 255 0 255 0 0 0 0 255 0 255 0 255
0 0 0 0 255 0 255 0 255 0 0 0 0 255 0
255 0 255 0 0 0 0 255 0 255 0 255 0 0 255
255 0 255 0 255 0 255 255 255 255 0 255 0 255 0
As you can see the first byte is missing.
Python 2.7.3 and Python 3.2.3 with numpy 1.6.1 and https://bitbucket.org/tiran/smc.freeimage/changeset/3134ecee2984 on 64bit Ubuntu. |
|
Date |
User |
Action |
Args |
2012-07-18 16:14:07 | christian.heimes | set | recipients:
+ christian.heimes, ncoghlan, pitrou, vstinner, skrah, python-dev |
2012-07-18 16:14:07 | christian.heimes | set | messageid: <1342628047.68.0.0676044841066.issue12834@psf.upfronthosting.co.za> |
2012-07-18 16:14:07 | christian.heimes | link | issue12834 messages |
2012-07-18 16:14:06 | christian.heimes | create | |
|