Skip to content

Commit fa81960

Browse files
committed
Make qimage_to_array() work on big endian
Make sure the returned ndarray is ordered the same as on little endian systems. Solves pyapp-kit#287
1 parent 49a8114 commit fa81960

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/superqt/utils/_img_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
from typing import TYPE_CHECKING
24

35
from qtpy.QtGui import QImage
@@ -37,4 +39,8 @@ def qimage_to_array(img: QImage) -> "np.ndarray":
3739
arr = np.frombuffer(b, np.uint8).reshape(h, w, c)
3840

3941
# reverse channel colors for numpy
40-
return arr.take([2, 1, 0, 3], axis=2)
42+
# On big endian we need to specify a different order
43+
if sys.byteorder == 'big':
44+
return arr.take([1, 2, 3, 0], axis=2)
45+
else:
46+
return arr.take([2, 1, 0, 3], axis=2)

0 commit comments

Comments
 (0)