Skip to content

Commit 53d9f9e

Browse files
committed
conv: Check the input array
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
1 parent 8c92346 commit 53d9f9e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

pixutils/conv/conv.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_bgr888(
3333
height: Height of the image in pixels
3434
bytesperline: Bytes per line, either a single int (0 for no padding) or a
3535
sequence of ints with one value per plane for multiplane formats
36-
arr: Numpy array containing the pixel data
36+
arr: Numpy uint8 array containing the pixel data
3737
options: Optional dictionary with conversion options:
3838
- backends: List of backends in priority order, e.g. ['opencv', 'numba']
3939
- range: 'limited' or 'full' (for YUV formats)
@@ -44,6 +44,10 @@ def to_bgr888(
4444
Numpy array containing the image in BGR888 format
4545
"""
4646

47+
if arr.dtype != np.uint8:
48+
raise ValueError(f'Input array must have dtype uint8, got {arr.dtype}')
49+
arr = np.ascontiguousarray(arr).reshape(-1)
50+
4751
# Normalize bytesperline to a per-plane tuple of concrete (non-zero) strides
4852
if isinstance(bytesperline, int):
4953
if len(fmt.planes) > 1 and bytesperline != 0:

0 commit comments

Comments
 (0)