mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-07-21 04:01:07 +02:00
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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user