ReviewOS

also looking at this

home-lang/home

feat(video): add checked capture plane packing

#915
Merged chris wants to merge feat/checked-plane-packing into main
3 files +68 -0
packages/video/docs/capture-planes.mdadded+23-0
Changes to packages/video/docs/capture-planes.md
@@ -0,0 +1,23 @@
1# Packing captured image planes
2
3`core/plane_pack.zig` provides allocation-free checked copies for capture buffers
4whose row padding is not part of the image. It is also exported as
5`video.plane_pack`.
6
7- `rows(source, stride, active_row_bytes, height, destination)` copies active bytes.
8- `packI420(planes, strides, width, height, destination)` packs separate Y, U, V
9 planes into tight I420; each source plane can have its own stride.
10
11Both validate sizes with checked arithmetic before writing. Final row padding
12need not be present. I420 requires positive even dimensions. Truncated chroma,
13undersized output and overflow are errors; the destination remains unchanged.
14Sources remain borrowed, the caller owns the destination, and source and output
15must not overlap. These helpers do not convert color, resize, or synchronize DMA.
16
17zig-camera uses these helpers after beginning CPU access to a leased DMA buffer.
18The camera ISP produces its low-resolution stream; packing only happens for an
19explicit owned copy. A mapped view keeps the original padding and ownership.
20
21Focused validation: `zig test packages/video/src/core/plane_pack.zig` on Zig
220.15.2 and Home's 0.17 development toolchain. This does not establish correctness
23of the entire video package's unrelated codecs or conversion paths.