Skip to content

Commit

Permalink
Merge pull request #542 from kif/539_big-endian
Browse files Browse the repository at this point in the history
This should fix the decoding of CBF files on big-endian computer.
  • Loading branch information
kif authored Oct 20, 2023
2 parents 3cc68ad + b2ead5e commit e5a23e5
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/fabio/compression/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__author__ = "Jérôme Kieffer"
__contact__ = "[email protected]"
__license__ = "MIT"
__date__ = "06/04/2020"
__date__ = "20/10/2023"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"

import sys
Expand Down Expand Up @@ -205,6 +205,7 @@ def decByteOffset_numpy(stream, size=None, dtype="int64"):
:param size: the size of the output array (of longInts)
:return: 1D-ndarray
Nota: data are always stored as little endian.
"""
logger.debug("CBF decompression using Numpy")
listnpa = []
Expand All @@ -222,23 +223,19 @@ def decByteOffset_numpy(stream, size=None, dtype="int64"):
if stream[idx + 1:idx + 3] == key32:
if stream[idx + 3:idx + 7] == key64:
# 64 bits int
res = numpy.frombuffer(stream[idx + 7:idx + 15], dtype=numpy.int64)
res = numpy.frombuffer(stream[idx + 7:idx + 15], dtype="<q")
listnpa.append(res)
shift = 15
else:
# 32 bits int
res = numpy.frombuffer(stream[idx + 3:idx + 7], dtype=numpy.int32)
res = numpy.frombuffer(stream[idx + 3:idx + 7], dtype="<i")
listnpa.append(res)
shift = 7
else: # int16
res = numpy.frombuffer(stream[idx + 1:idx + 3], dtype=numpy.int16)
res = numpy.frombuffer(stream[idx + 1:idx + 3], dtype="<h")
listnpa.append(res)
shift = 3
stream = stream[idx + shift:]
if not numpy.little_endian:
for res in listnpa:
if res.dtype != numpy.int8:
res.byteswap(True)
return numpy.ascontiguousarray(numpy.hstack(listnpa), dtype).cumsum()


Expand Down

0 comments on commit e5a23e5

Please sign in to comment.