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>
This commit is contained in:
Sandro
2025-04-07 05:44:07 +02:00
committed by GitHub
parent 49a8114843
commit 358d041c0d

View File

@@ -1,3 +1,4 @@
import sys
from typing import TYPE_CHECKING
from qtpy.QtGui import QImage
@@ -37,4 +38,8 @@ def qimage_to_array(img: QImage) -> "np.ndarray":
arr = np.frombuffer(b, np.uint8).reshape(h, w, c)
# reverse channel colors for numpy
return arr.take([2, 1, 0, 3], axis=2)
# On big endian we need to specify a different order
if sys.byteorder == "big":
return arr.take([1, 2, 3, 0], axis=2) # pragma: no cover
else:
return arr.take([2, 1, 0, 3], axis=2)