Files
dora-webcam/dora_webcam/image.py
T
cristhian 6f76074709
validate / validate (push) Successful in 59m15s
name no consumer of this node
A source that documents itself through a specific downstream node depends on
that node to be understood, and that node already depends on this one for
frames. The README pointed at one by name and the CI workflow still carried a
comment about the dataflow that wired it, which no longer exists.

The output is documented by its type instead: wire `image` into anything that
takes std/media/v1/Image. PREVIEW covers seeing the frames without naming
anyone. Generic words like "a viewer" or "a consumer" stay, since they describe
a role rather than a repository.
2026-09-15 06:13:06 -03:00

49 lines
1.3 KiB
Python

"""Packing a frame as std/media/v1/Image.
The struct is respelled here rather than imported: node repositories share no
source package, so the manifest and this schema are the whole contract a
consumer has.
"""
import numpy as np
import pyarrow as pa
IMAGE_TYPE = pa.struct([
("width", pa.uint32()),
("height", pa.uint32()),
("encoding", pa.utf8()),
("data", pa.large_binary()),
])
def pack(frame: np.ndarray, encoding: str, width: int, height: int) -> pa.Array:
"""Pack encoded frame bytes as a single-row std/media/v1/Image array.
Parameters
----------
frame : np.ndarray
The bytes to send. Either a raw pixel buffer or the output of an
encoder; either way only its bytes are read.
encoding : str
Name of the encoding the bytes are in, e.g. ``bgr8`` or ``jpeg``.
width, height : int
Dimensions of the *image*, which for a compressed encoding are not the
shape of ``frame``. They are recorded so a receiver can size a buffer
without decoding first.
Returns
-------
pa.Array
One-row struct array matching ``IMAGE_TYPE``.
"""
return pa.array(
[{
"width": width,
"height": height,
"encoding": encoding,
"data": frame.tobytes(),
}],
type=IMAGE_TYPE,
)