Skip to content

bug: tobytes() byteorder with multibyte samples, bigendian #385

@manisandro

Description

@manisandro

Short story and end result: numpy tests are failing on bigendian arches, as reported here: https://bugzilla.redhat.com/show_bug.cgi?id=1019656

Long story: The problem is that the test image 12bit.cropped.tif is a tiff image with data stored in little-endian format and 16bit samples. Now, Image.tobytes() (which is called when doing numpy.array(img)) returns the raw data, without byteswapping. This means that i.e.

img = Image.open('12bit.cropped.tif')
print img.tobytes()[0:2]

returns '\xe0\x01' on both big- and little-endian platforms, which corresponds (correctly) to 480 on little-endian, but on big-endian it corresponds to 57345.

FIxing the issue itself should not be too much trouble, the main issue is where to fix it.
Some possibilities (without very in-depth study of the code):

  • The test is wrong. tobytes() returns the raw data, and if that appens to be in little-endian format, then it is up to the user to handle this.
  • TiffDecode should byteswap if the endianness of the image data differs from the platform endinanness.

Any other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Big-endianBig-endian processors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions