38
38
39
39
__license__ = "MIT"
40
40
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
41
- __version__ = "17/10/2012 "
41
+ __date__ = "30/05/2024 "
42
42
43
43
import io
44
44
from .fabioimage import FabioImage
@@ -84,17 +84,21 @@ def read(self, fname, dim1, dim2, offset=0, bytecode="int32", endian="<"):
84
84
:param int dim2: image dimensions (Slow index)
85
85
:param int offset: starting position of the data-block. If negative, starts at the end.
86
86
:param bytecode: can be "int8","int16","int32","int64","uint8","uint16","uint32","uint64","float32","float64",...
87
- :param endian: among short or long endian ("<" or ">")
87
+ :param endian: among litte or big endian ("<" or ">")
88
88
89
89
"""
90
+ assert endian in ('<' , '>' , '=' )
91
+ bytecode = numpy .dtype (bytecode )
92
+ if not bytecode .str .startswith (endian ):
93
+ bytecode = numpy .dtype (endian + bytecode .str [1 :])
90
94
self .filename = fname
91
95
self ._shape = dim2 , dim1
92
96
self ._bytecode = bytecode
93
- with open (self .filename , "rb" ) as f :
97
+ with open (self .filename , "rb" ) as f :
94
98
dims = [dim2 , dim1 ]
95
99
bpp = numpy .dtype (bytecode ).itemsize
96
100
size = dims [0 ] * dims [1 ] * bpp
97
-
101
+
98
102
if offset >= 0 :
99
103
f .seek (offset )
100
104
else :
@@ -107,8 +111,6 @@ def read(self, fname, dim1, dim2, offset=0, bytecode="int32", endian="<"):
107
111
logger .error ('Uncommon error encountered when reading file' )
108
112
rawData = f .read (size )
109
113
data = numpy .frombuffer (rawData , bytecode ).copy ().reshape (tuple (dims ))
110
- if self .swap_needed (endian ):
111
- data .byteswap (True )
112
114
self .data = data
113
115
self ._shape = None
114
116
return self
0 commit comments