Zero-copy conversion between Qt QImage (in `Format_RGB32`/`Format_ARGB32`) and NumPy ndarray (in HWC BGRX 8888 format).
Project description
qimage-hwc-bgrx-8888-ndarray-interop
Zero-copy conversion between Qt QImage (in Format_RGB32/Format_ARGB32) and NumPy ndarray (in HWC BGRX 8888 format).
Features
- Zero-copy: Memory is shared between objects - no pointless data copying!
- Cross-binding: Supports PyQt6, PyQt5, PyQt4, PySide6, PySide2, or PySide.
- Safety: Explicit checks for packing and format - no surprises.
Installation
Install your preferred Qt binding, then run:
pip install qimage-hwc-bgrx-8888-ndarray-interop
Usage
# coding=utf-8
from qimage_hwc_bgrx_8888_ndarray_interop import (
qimage_to_hwc_bgrx_8888_ndarray_view,
qimage_to_hwc_bgrx_8888_ndarray,
hwc_bgrx_8888_ndarray_to_qimage_view,
hwc_bgrx_8888_ndarray_to_qimage,
)
# Convert a QImage to numpy.ndarray (zero-copy view):
arr_view = qimage_to_hwc_bgrx_8888_ndarray_view(qimage)
# Convert a QImage to a copy of image data:
arr = qimage_to_hwc_bgrx_8888_ndarray(qimage)
# Convert a contiguous (H, W, 4) uint8 ndarray back to a QImage (zero-copy view):
qimg_view = hwc_bgrx_8888_ndarray_to_qimage_view(arr)
# Convert ndarray to a QImage (copies data):
qimg_copy = hwc_bgrx_8888_ndarray_to_qimage(arr)
Safety & Caveats
- Endianness: Only little-endian systems are supported (typical modern computers).
- On unsupported (big-endian) systems,
RuntimeErroris raised at import time.
- On unsupported (big-endian) systems,
- Tightly packed images only: QImage must have
bytesPerLine == width * 4for zero-copy view. - Memory lifetime matters:
- Do not let the QImage or ndarray be garbage collected while the other exists and references its buffer.
- If in doubt, use the
copy()variants.
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qimage_hwc_bgrx_8888_ndarray_interop-0.1.0a0.tar.gz.
File metadata
- Download URL: qimage_hwc_bgrx_8888_ndarray_interop-0.1.0a0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78b6f66993264a16e1cb779967ce7fa2d788899db17b94cf8838837b9a84afa4
|
|
| MD5 |
2c4aa9dd2abd9f60ee852acae1e297fd
|
|
| BLAKE2b-256 |
8f4ec77e27654bb55289a7909ee4d608240743d95a4dbe281e5d7b6be5f47ca6
|
File details
Details for the file qimage_hwc_bgrx_8888_ndarray_interop-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: qimage_hwc_bgrx_8888_ndarray_interop-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e865ffde38f82f99ee005d8a4d15c648ae31f31eabb9d8d609c6dd2a96980ba
|
|
| MD5 |
71584c4c49aedcd9931ee2204d3672a3
|
|
| BLAKE2b-256 |
01a5122291b85f0e736b905de63e70fb0b8099330dd63d859b3fd30298da2ac5
|