Skip to content

Commit 358d041

Browse files
penguinpeepre-commit-ci[bot]Czaki
authored
Make qimage_to_array() work on big endian (#288)
* Make qimage_to_array() work on big endian Make sure the returned ndarray is ordered the same as on little endian systems. Solves #287 * style: [pre-commit.ci] auto fixes [...] * Update src/superqt/utils/_img_utils.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
1 parent 49a8114 commit 358d041

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/superqt/utils/_img_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import TYPE_CHECKING
23

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

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

0 commit comments

Comments
 (0)