gui-video bridges the video frame format with the GUI shader pixel buffer and rendering system. It enables:
- Converting between video frames and shader pixel buffers
- Rendering video frames directly into GUI windows
- Applying video effects (grayscale, invert, threshold, blend, diff) to shader buffers
- Exporting shader buffers as video frames or BMP-ready pixel data
// Direct import
guiVideo := import('gui-video')
// Or through the GUI facade (recommended)
gui := import('GUI')
Converts a video.oak frame (RGB channel bytes) into a shader pixel buffer ({width, height, data:{packed-BGR-ints}}).
Converts a shader pixel buffer back into a 3-channel video.oak frame.
Draws a video frame into the GUI window at offset (ox, oy) using 1×1 fillRect calls.
renderFrameScaled(drawCtx, window, frame, ox?, oy?, scale?) / gui.videoRenderFrameScaled(window, frame, ox?, oy?, scale?)
Renders a video frame scaled by an integer factor.
Applies luma-weighted grayscale conversion.
Inverts all color channels.
Binary black/white conversion based on luma threshold (default 127).
Alpha-blends two buffers (default alpha 0.5).
Per-channel absolute difference between two buffers.
Captures the current shader pixel buffer state as a video.oak frame for further processing.
Converts a video.oak RGB frame into the BMP pixel list expected by lib/bmp ([B, G, R] byte lists in bottom-up row order). The result can be passed directly to bmp.bmp(w, h, pixels).
gui := import('GUI')
// Create a shader buffer and render something into it
buf := gui.shaderCreateBuffer(320, 240)
shader := gui.Shader(fn(x, y, w, h, t, u) {
gui.rgb(int(x * 255 / w), int(y * 255 / h), 128)
})
gui.shaderRenderShaderToBuffer(buf, shader)
// Apply grayscale post-processing
grayBuf := gui.videoBufferGrayscale(buf)
// Render the processed buffer
gui.shaderRenderBuffer(window, grayBuf, 0, 0)
gui := import('GUI')
video := import('video')
// Create a test frame (red gradient)
f := video.mapPixels(video.blank(100, 100), fn(pixel, x, y) {
[int(x * 255 / 100), 0, 0]
})
// Render at 2× scale
gui.videoRenderFrameScaled(window, f, 10, 10, 2)
gui := import('GUI')
bmpLib := import('bmp')
video := import('video')
f := video.blank(64, 64, 3, 128)
pixels := gui.videoFrameToBmpPixels(f)
data := bmpLib.bmp(64, 64, pixels)
// write data to file...