Christian Heimes <li...@cheimes.de> added the comment:

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.

----------
nosy: +christian.heimes
versions: +Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12834>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to