# Nodes: lamino

The basic nodes: `import { read, merge, blur } from "lamino"`. A node whose first input is an image can also be called as a method, `img.blur({ ... })`.

- **Sources** [`read`](#read) [`constant`](#constant) [`ramp`](#ramp) [`checker`](#checker) [`cryptomatte`](#cryptomatte)
- **Compositing** [`merge`](#merge)
- **Colour** [`grade`](#grade) [`clamp`](#clamp) [`colorspace`](#colorspace) [`displayView`](#displayview) [`lut`](#lut)
- **Transforms** [`transform`](#transform) [`crop`](#crop)
- **Filters** [`blur`](#blur) [`erode`](#erode)
- **Channels** [`premult`](#premult) [`unpremult`](#unpremult) [`shuffle`](#shuffle)
- **Measurement** [`measure`](#measure)
- **Shaders** [`shader`](#shader)
- **Time** [`frameBlend`](#frameblend) [`echo`](#echo) [`temporalMedian`](#temporalmedian) [`timeOffset`](#timeoffset) [`frameHold`](#framehold) [`retime`](#retime)

## Sources

### `read`

Read an image sequence or still (EXR, DPX, JPG, PNG, TIFF).

Module `lamino`, category Sources, output image

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `path` | path | none |  |  |  | Alias path, e.g. $SHOTS/SHOW/010/plate/A001_C003.####.dpx |
| `colorspace` | str | `"auto"` |  |  |  | Input colorspace (OCIO name, alias or role). "auto" uses the config's file rules; lint warns (L_COLORSPACE_UNSPECIFIED) when only the default rule matched. |
| `convert` | bool | `true` |  |  |  | Convert from `colorspace` to the working space (true). false keeps the pixels in the declared colorspace, e.g. display-referred PNG values for a display-referred composite; needs an explicit colorspace. |
| `layer` | str | `""` |  |  |  | EXR layer name; "" is the base layer. |
| `channels` | json | `null` |  |  |  | Optional list of channel names mapped to R,G,B,A (e.g. ["R","G","B"] or ["Y"]). Default: R,G,B,A by name. |
| `alpha` | enum | `"auto"` |  |  |  | How the file stores alpha. auto: EXR=premult, PNG/TIFF/JPG=straight (or none without alpha); video follows the stream (ProRes 4444, Animation, PNG / HAP in MOV, VP8 / VP9 with alpha: straight unless the stream says premultiplied; no alpha plane = none). Values: `auto` `premult` `straight` `none` |
| `missing` | enum | `"error"` |  |  |  | What to do when a frame file is missing: fail the frame, hold the nearest earlier existing frame of the sequence (E_FRAME_MISSING when none), or return black. Values: `error` `hold` `black` |
| `frameOffset` | int | `0` |  | frames |  | Added to the comp frame to get the file frame. |
| `par` | float | `0` | 0 or more |  |  | Pixel aspect ratio override; 0 reads it from the file (1.0 if absent). |

Decodes the frame, converts it to the working colorspace (straight rgb where alpha > 0, see the premultiplication rule) and premultiplies it. `convert: false` skips the conversion: the pixels stay in the declared `colorspace` (which must then be explicit, not "auto": E_IR_PARAM_INVALID), still premultiplied, and the node's colour state (`color_state`) is that colourspace instead of the working space, so a display-referred PNG declared e.g. "sRGB - Display" is composited in display values and previewed without a second view transform. Paths use a root alias (`$SHOTS/...`) and `####` for the frame number. EXR layers are selected with `layer`. Data layers (depth, motion, position, uv, …) are read with the `aov` node instead; a colourspace flagged `is_data` by the config is refused here. `missing: hold` uses the nearest earlier frame that exists on disk (within the sequence); when none exists the frame fails with E_FRAME_MISSING. Proxy evaluation reads a source proxy built by `lamino proxy build` (`.lamino/proxy/<factor>/<name>.exr`, lossy half) for every colour read whose frame has a verified lock hash: the default layer under the frame hash, a named `layer` or an explicit `channels` list under a name that also holds the selection (`project::source_proxy_name`). Without a verified hash or a matching proxy the full file is read and downsampled in memory. Data reads (`aov`, cryptomatte) never use source proxies. Output window (`OutputWindow::Source`): the file's data window placed with its display window's top-left at comp (0, 0); overscan is kept (negative coordinates left of / above the display), nothing is resampled when the file's resolution differs from the comp (L_RES_MISMATCH), and at proxy levels the window is scaled down rounding outward; see `descriptor::source_window`. AOV sugar: with any AOV option (`kind`, `units`, `direction`, `depthRange`, `measure`, ...) the script layer compiles `read()` to an `aov` node and infers `kind` by the rule documented on `aov` (`depthRange` alone means depth; contradicting hints are E_IR_PARAM_INVALID). The lock file records the content hash of every frame read; provenance of generated assets is added with `lamino prov add` and copied onto this node by `check`. Cache key deps: the frame's lock hash (or interim size+mtime identity while pending), the input→working transform id and the proxy source kind.

Examples:

```ts
// Log plate
const plate = read("$SHOTS/SHOW/010/plate/A001_C003.####.dpx", { colorspace: "ARRI LogC4", missing: "error" });

// EXR layer
const fw = read("$SHOTS/SHOW/010/render/fireworks_v012.####.exr", { layer: "beauty", alpha: "premult" });

// Display values as they are
const bg = read("$SHOTS/SHOW/010/ref/backdrop.png", { colorspace: "sRGB - Display", convert: false });
```

### `constant`

A solid colour over the whole display window.

Module `lamino`, category Sources, output image, pointwise (fused with its neighbours)

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `color` | color | `[0, 0, 0, 1]` |  |  | yes | RGBA colour. |

Colour is working-space premultiplied RGBA (default opaque black, so a 3-component colour is opaque), or a #hex sRGB string converted through the color config.

Examples:

```ts
// Black
const bg = constant({ color: [0, 0, 0] });

// Transparent
const empty = constant({ color: [0, 0, 0, 0] });
```

### `ramp`

Linear or radial gradient between two colours, or through a list of stops.

Module `lamino`, category Sources, output image, pointwise (fused with its neighbours)

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `type` | enum | `"linear"` |  |  |  | Linear (along start → end) or radial (around start, out to end). Values: `linear` `radial` |
| `direction` | enum | `"horizontal"` |  |  |  | Gradient axis when neither `start` nor `end` is given (horizontal: t = x; vertical: t = y, both in width units). Values: `horizontal` `vertical` |
| `start` | vec2 | `[0, 0]` |  | width units | yes | Point where the gradient is `color0`, width units [x, y] (y in 0..H/W). Writing it (or `end`) switches from `direction` to the points. |
| `end` | vec2 | `[1, 0]` |  | width units | yes | Point where the gradient is `color1`, width units [x, y] (y in 0..H/W). Writing it (or `start`) switches from `direction` to the points. |
| `color0` | color | `[0, 0, 0, 1]` |  |  | yes | Colour at the start. |
| `color1` | color | `[1, 1, 1, 1]` |  |  | yes | Colour at the end. |
| `stops` | json | `[]` |  |  |  | Gradient stops [{ offset, color }, …] (2 to 8) used instead of color0 / color1; empty = not used. |

`color0 + (color1 − color0) · t`, evaluated at pixel centres; values are not clamped (beyond the end points the gradient extrapolates). **`type: "radial"`**: t = |q − start| / |end − start|, at most 1: `color0` at the centre `start`, `color1` on the circle through `end` and beyond it (a radial ramp never extrapolates). It always uses the points (`direction` with it is E_IR_PARAM_INVALID). **`stops`**: 2 to 8 entries { offset, color } with offsets that do not decrease replace `color0` / `color1`: the colour is interpolated linearly between neighbouring stops and held before the first and after the last (so a ramp with stops never extrapolates either; two stops at one offset are a hard step). Colours as every Color parameter, premultiplied as written. **Points**: with `start` and / or `end` written, t is the projection of the pixel centre q onto the segment, t = (q − start)·(end − start) / |end − start|², so `color0` is at `start`, `color1` at `end`, and the gradient is constant perpendicular to the segment. Both are in width units (x in 0..1, y in 0..H/W, origin top-left); a point left out takes its default (`start` [0, 0], `end` [1, 0]). To run top to bottom of a 16:9 frame: `start: [0.5, 0], end: [0.5, 0.5625]` (y = H/W). `start == end` is E_IR_PARAM_INVALID (at validation when both are static, else when the frame is evaluated). **`direction`** is the shorthand used when neither point is written, and writing it together with a point is E_IR_PARAM_INVALID: horizontal = t = x (`color0` at the left edge x = 0, `color1` at the right edge x = 1, i.e. start [0, ·], end [1, ·]); vertical = t = y (`color0` at the top edge y = 0, `color1` at y = 1.0, which is below the frame unless it is square: the bottom edge is y = H/W, where a 16:9 frame reaches 56.25 % of the way; use `start` / `end` to end on the bottom edge). The shorthand evaluates exactly as before the points existed.

Examples:

```ts
// Radial glow spot
const spot = ramp({ type: "radial", start: [0.5, 0.28], end: [0.5, 0.5], color0: [1, 0.9, 0.7, 1], color1: [0, 0, 0, 0] });

// Three-colour sky
const sky = ramp({ start: [0.5, 0], end: [0.5, 0.5625], stops: [{ offset: 0, color: "#0b1d4d" }, { offset: 0.7, color: "#e8845a" }, { offset: 1, color: "#ffd9a0" }] });

// Top to bottom (16:9)
const sky = ramp({ start: [0.5, 0], end: [0.5, 0.5625], color0: [0.2, 0.3, 0.6], color1: [0.9, 0.7, 0.5] });

// Diagonal
const g = ramp({ start: [0.2, 0.1], end: [0.8, 0.5] });
```

### `checker`

Checkerboard (analytic; used by tests and as a stand-in).

Module `lamino`, category Sources, output image, pointwise (fused with its neighbours)

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `size` | float | `0.1` | 0.0001 or more | width units |  | Square size in width units. |
| `colorA` | color | `[0.1, 0.1, 0.1, 1]` |  |  | yes | First colour. |
| `colorB` | color | `[0.9, 0.9, 0.9, 1]` |  |  | yes | Second colour. |

Square (x, y) in width units belongs to colourA when floor(x/size) + floor(y/size) is even.

### `cryptomatte`

Coverage matte of named objects from a Cryptomatte EXR (names resolved through the manifest).

Module `lamino`, category Sources, output mask

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `path` | path | none |  |  |  | Alias path of the Cryptomatte EXR (`####` for the frame number). |
| `layer` | str | `""` |  |  |  | Cryptomatte layer name; "" is the first cryptomatte layer in the file. |
| `names` | json | none |  |  |  | Array of object names or globs matched against the manifest (exact names first, then globs). |
| `ids` | json | `null` |  |  |  | Optional array of float ids selected directly (for objects missing from the manifest). |
| `manifFile` | path | `null` |  |  |  | Optional sidecar manifest (alias path, same asset root as the EXR); overrides the header's manifest and `manif_file`. |
| `missing` | enum | `"error"` |  |  |  | What to do when a frame file is missing: fail the frame, hold the nearest earlier existing frame of the sequence (E_FRAME_MISSING when none), or return black. Values: `error` `hold` `black` |
| `frameOffset` | int | `0` |  | frames |  | Added to the comp frame to get the file frame. |

A **data source** (`SourceKind::Data`): the rank pairs `<layer>00.R/G`, `<layer>00.B/A`, `<layer>01.R/G`, … are read losslessly — no colour conversion, no premultiplication, no proxy averaging (ids break in the colour path). Each name in `names` is hashed with MurmurHash3_32 and converted to its float id as the Cryptomatte specification does (uint32 → float32 bit cast with the exponent clamped away from zero / inf / NaN); every rank whose id matches adds its coverage. Coverages are accumulated in stable rank order **before** the result is reduced to the proxy level, so proxy and full-resolution mattes agree up to the reduction. Output port `mask`: coverage 0..1 in alpha and in rgb. `layer`: the cryptomatte layer (the `name` of a `cryptomatte/<n>/…` header set, e.g. `crypto_object`); `""` = the first one in the file. `names`: object names or globs (`*`, `?`, `[…]`); an exact manifest name wins over a glob; a glob that matches nothing lints L_CRYPTO_NO_MATCH; an exact name the manifest does not have is E_IR_PARAM_INVALID (the fix names the nearest entries). `ids`: float ids added directly (objects absent from the manifest). The manifest is the header's `cryptomatte/<n>/manifest`, or the file named by the header's `manif_file` (resolved relative to the EXR's directory, inside the same asset root), or `manifFile` (an alias path, overrides both); its `hash` must be `MurmurHash3_32` and its `conversion` `uint32_to_float32`, anything else is E_IMAGE_FORMAT. A sidecar manifest enters the lock, the cache key deps and the dev watch. Missing frames follow `missing` as for `read`. Output window: the file's data window (`OutputWindow::Source`).

Examples:

```ts
// Hero matte
const hero = cryptomatte("$SHOTS/SHOW/010/render/beauty.####.exr", { layer: "crypto_object", names: ["hero_*", "ground"] });

// Use it
const graded = inside(plate.grade({ gain: 1.3 }), hero).over(plate);
```

## Compositing

### `merge`

Combine A (foreground, input 0) with B (background, input 1): Porter-Duff operations and layer blend modes.

Module `lamino`, category Compositing, output image, pointwise (fused with its neighbours)

- Input `A` (image): Foreground.
- Input `B` (image): Background.
- Input `mask` (mask, optional): Optional effect mask.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `op` | enum | `"over"` |  |  |  | Compositing operation or blend mode. Values: `over` `under` `screen` `add` `subtract` `multiply` `difference` `max` `min` `in` `out` `mask` `stencil` `xor` `copy` `maskLuma` `stencilLuma` `from` `divide` `exclusion` `overlay` `softLight` `hardLight` `colorDodge` `colorBurn` `linearBurn` `linearLight` `vividLight` `pinLight` `hardMix` `hue` `saturation` `color` `luminosity` `darkerColor` `lighterColor` |
| `alpha` | enum | `"op"` |  |  |  | Output alpha: the op's own (op), A's (a), B's (b) or the larger of the two (max). RGB always follows `op`. Values: `op` `a` `b` `max` |
| `composite` | enum | `"channels"` |  |  |  | How a blend function is applied: on the stored values of every channel (channels), or as a layer blend mode on straight colour inside source-over compositing (layer). Values: `channels` `layer` |
| `mix` | float | `1` | 0 to 1 |  | yes | Blend between B (0) and the full result (1). |
| `luma` | vec3 | `[0.2722287, 0.6740818, 0.0536895]` |  |  |  | Luma weights of maskLuma / stencilLuma and of hue / saturation / color / luminosity / darkerColor / lighterColor (default AP1 / ACEScg). |

Premultiplied Porter-Duff, Nuke / Natron semantics with alpha masking off: every formula applies to all four channels (rgb and alpha alike). With a = A.alpha, b = B.alpha: over: A + B(1-a) · under: B + A(1-b) · in: A·b · out: A·(1-b) · mask: B·a · stencil: B·(1-a) · xor: A(1-b) + B(1-a) · add: A + B · subtract: A - B · multiply: A·B · difference: |A - B| · max: max(A, B) · min: min(A, B) · screen (per channel): if 0 ≤ A ≤ 1 and 0 ≤ B ≤ 1 then A + B - A·B else max(A, B)  (HDR-safe) · copy: A (with `mask` / `mix`: A where the mask is, B elsewhere) · maskLuma: B·y · stencilLuma: B·(1 − y) with y = clamp(dot(luma, A.rgb), 0, 1) (After Effects' Stencil Luma / Silhouette Luma; its Stencil Alpha is `mask`, its Silhouette Alpha is `stencil`). **Blend modes**. Each is a function f(B, A) of the backdrop B and the source A, per channel unless noted; s⁺ / b⁺ are max(·, 0); screen(x, y) is the HDR-safe screen above: from: B − A (After Effects' Subtract) · divide: B / A where A > 0, else 1 where B > 0, else 0 · exclusion: B + A − 2·A·B where both lie in 0..1, else |B − A| · hardLight: A⁺ ≤ 0.5 ? 2·A⁺·B⁺ : screen(B⁺, 2·A⁺ − 1) · overlay: hardLight with A and B swapped · softLight (W3C): B⁺ ≥ 1 ? B⁺ : A⁺ ≤ 0.5 ? B⁺ − (1 − 2A⁺)·B⁺·(1 − B⁺) : B⁺ + (2A⁺ − 1)·(D − B⁺), D = B⁺ ≤ 0.25 ? ((16B⁺ − 12)·B⁺ + 4)·B⁺ : sqrt(B⁺) · colorDodge: B⁺ ≤ 0 ? 0 : A⁺ ≥ 1 ? max(B⁺, 1) : max(B⁺, min(1, B⁺ / (1 − A⁺))) · colorBurn: B⁺ ≥ 1 ? B⁺ : A⁺ ≤ 0 ? 0 : max(0, 1 − (1 − B⁺) / A⁺) · linearBurn: max(B + A − 1, 0) · linearLight: max(B + 2A − 1, 0) · vividLight: A⁺ ≤ 0.5 ? colorBurn(B⁺, 2A⁺) : colorDodge(B⁺, 2A⁺ − 1) · pinLight: A ≤ 0.5 ? min(B, 2A) : max(B, 2A − 1) · hardMix: B + A ≥ 1 ? 1 : 0. Not per channel (rgb as a triple, on A⁺ / B⁺; Y = dot(`luma`, rgb), Sat = max − min; W3C's SetLum / SetSat with the `luma` weights, and its ClipColor without the upper clip, so values above 1 survive): hue: SetLum(SetSat(A, Sat(B)), Y(B)) · saturation: SetLum(SetSat(B, Sat(A)), Y(B)) · color: SetLum(A, Y(B)) · luminosity: SetLum(B, Y(A)) · darkerColor: Y(A) < Y(B) ? A : B · lighterColor: Y(A) > Y(B) ? A : B. HDR: the functions written for 0..1 never return a negative number or NaN for any finite input; where a formula would invert above 1 (screen, exclusion, softLight, the dodge / burn family) the backdrop wins or the difference is used, as written above. hardMix returns 0 or 1 only. **`composite`** says how a blend function is applied. `channels` (default; Nuke / Natron): the result is f(B, A) on the stored, premultiplied values of all four channels (the triple functions give rgb, and alpha = a + b − a·b). `layer` (After Effects / W3C compositing; what a layer with a blend mode does): with the straight colours Cs = A.rgb / a and Cb = B.rgb / b (0 where the alpha is 0), rgb = A.rgb·(1 − b) + B.rgb·(1 − a) + a·b·f(Cb, Cs) and alpha = a + b − a·b: the blend acts only where both layers have coverage, and the backdrop shows through a transparent source. It applies to screen, add, subtract, multiply, difference, max, min and every blend mode above; over, under, in, out, mask, stencil, xor, copy, maskLuma and stencilLuma ignore it. In `layer` mode a source pixel with alpha 0 has no straight colour, so light without coverage shows only where the backdrop is transparent: add emissive elements with `channels`. Script: `bg.blend(fg, "overlay")` is merge({ op: "overlay", composite: "layer" }). `alpha` picks the output alpha while rgb always follows `op`: "op" (default) = the op's own alpha (the formula above on the alpha channel); "a" = A.alpha; "b" = B.alpha; "max" = max(A.alpha, B.alpha). Use it where the op is meant for colour only, e.g. `add` of two opaque layers (alpha 2 with "op"; "b" or "max" keeps 1) or `subtract` / `difference` of two opaque layers (alpha 0 with "op"). The choice is applied to the op result before `mix` / `mask`, so those blend the chosen alpha with B's like every other channel. `mix` blends the result with B (0 = B unchanged). An optional `mask` input (port 2) multiplies the effect: result = B + (result - B)·mask·mix, mask read from the input's alpha. Output data window: union of the connected inputs (in/mask are zero outside the intersection anyway). Nothing is clamped. Muting a merge sets `mix = 0` (B passes through). Script sugar: `bg.over(fg)` places `fg` over `bg` (receiver is B); `a.add(b)`, `bg.screen(fg)`; `over(a, b)` is A over B.

Examples:

```ts
// Fireworks over plate
const comp = plate.over(fw);            // fw over plate

// Glow screened onto fireworks
const fxGlow = fw.screen(glow);      // merge{op:"screen"} inputs [glow, fw]

// Explicit
const comp = merge(fg, bg, { op: "over", mix: 0.8 });

// Add light, keep the plate's alpha
const lit = plate.add(glow, { alpha: "b" });   // rgb = glow + plate, alpha = plate's

// A layer with a blend mode (After Effects: Overlay at 60 %)
const graded = plate.blend(texture, "overlay", { mix: 0.6 });

// Replace a region through a matte
const patched = merge(fixed, plate, { op: "copy", mask: matte });
```

## Colour

### `grade`

Lift / gain / gamma / offset colour correction (Nuke-style).

Module `lamino`, category Colour, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `blackpoint` | color | `[0, 0, 0, 0]` |  |  | yes | Input black. |
| `whitepoint` | color | `[1, 1, 1, 1]` |  |  | yes | Input white. |
| `lift` | color | `[0, 0, 0, 0]` |  |  | yes | Output black. |
| `gain` | color | `[1, 1, 1, 1]` |  |  | yes | Output white. |
| `multiply` | color | `[1, 1, 1, 1]` |  |  | yes | Multiplier. |
| `offset` | color | `[0, 0, 0, 0]` |  |  | yes | Added after multiply. |
| `gamma` | color | `[1, 1, 1, 1]` | 0.001 or more |  | yes | Gamma (applied as power 1/gamma). |
| `saturation` | float | `1` | 0 or more |  | yes | Saturation (1 = unchanged, 0 = grey). |
| `luma` | vec3 | `[0.2722287, 0.6740818, 0.0536895]` |  |  |  | Luma weights for saturation (default AP1 / ACEScg). |
| `unpremult` | bool | `true` |  |  |  | Unpremultiply before grading and re-premultiply after. |
| `clampBlack` | bool | `false` |  |  |  | Clamp rgb at 0 after grading. |
| `clampWhite` | bool | `false` |  |  |  | Clamp rgb at 1 after grading. |

On straight RGB (unpremultiplied where alpha > 0 when `unpremult` is true): A = multiply·(gain − lift)/(whitepoint − blackpoint); B = offset + lift − A·blackpoint; out = (A·in + B)^(1/gamma)  (bases ≤ 0 are passed through unchanged; gamma applies to rgb only). Pixels with alpha == 0 (when `unpremult` is true) get the a → 0 limit: saturation, then rgb·A only (B and gamma are not applied), so a gain reaches additive glow pixels; with gamma 1 the result is continuous with alpha 0.001 (for gamma != 1 the a -> 0 limit does not exist, so skipping gamma is a convention). clampBlack / clampWhite apply to the slope result. With `unpremult: false` every pixel gets the full formula on its premultiplied values. Saturation is applied first using `luma` weights (AP1 by default). Alpha is affected only by the alpha components of the vectors (default: unchanged). The result is re-premultiplied by the OUTPUT alpha where it is > 0. Clamps are optional. Scalars broadcast to rgb; 3-component values take the parameter's identity alpha (0 for lift/offset/blackpoint, 1 for gain/multiply/whitepoint/gamma).

Examples:

```ts
// Gain
const bright = fw.grade({ gain: 1.4 });

// Per-channel
const out = comp.grade({ lift: -0.01, gain: [1.0, 0.98, 1.02] });

// Animated
const fade = plate.grade({ multiply: keys([[1001, 0], [1012, 1]]), unpremult: false });
```

### `clamp`

Clamp each channel to [min, max].

Module `lamino`, category Colour, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `min` | vec4 | `[0, 0, 0, 0]` |  |  | yes | Lower bound RGBA. |
| `max` | vec4 | `[1, 1, 1, 1]` |  |  | yes | Upper bound RGBA. |

### `colorspace`

Convert between colourspaces of the color config (OCIO).

Module `lamino`, category Colour, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `from` | str | none |  |  |  | Source colourspace. |
| `to` | str | none |  |  |  | Destination colourspace. |
| `unpremult` | bool | `true` |  |  |  | Unpremultiply before converting. |

Roles (`scene_linear`) and aliases (`acescg`) are accepted. Applied to straight RGB when `unpremult` is true (re-premultiplied by alpha where > 0). Pixels with alpha == 0: when the whole transform is a single 3×3 matrix (`ColorTransform::linear_matrix`, no offset, no curve, no LUT) the matrix is applied to rgb directly; otherwise rgb passes through unchanged. Data spaces are refused. The WGSL kernel is generated per node from the OCIO processor (shader text + LUT textures at @group(2)); its source hash and the config hash enter the cache key. Colour state (`color_state`): the output is in `to`; `from` must be the input's state (the working space after a converting read, the previous `to` after a colorspace), else lint L_COLORSPACE_FROM_MISMATCH. Converting to a display colour space (e.g. "sRGB - Display") makes the node display-referred: previews, probe, compare, the review window and movies show it without a second view transform, and render records the state in the EXR header `lamino:colorspace`. **A display colour space is not a view:** between a scene-referred space and a display colour space OCIO applies the config's *default view transform*, which in the ACES configs is `Un-tone-mapped` — the display's primaries and transfer curve only, no tone curve (18% grey becomes 0.461 in `sRGB - Display`; the view `ACES 1.0 - SDR Video` shows it as 0.356). The picture then differs from what previews of the scene-referred node show. To finish in the values of a view, or to bring display-referred material into the working space through the inverse of a view, use `displayView`; lint points there (L_DISPLAY_WITHOUT_VIEW).

Examples:

```ts
// Grade in log
const graded = plate.colorspace({ from: "scene_linear", to: "ACEScct" }).grade({ gain: 1.1 }).colorspace({ from: "ACEScct", to: "scene_linear" });

// Display to display
const p3 = disp.colorspace({ from: "sRGB - Display", to: "Display P3 - Display" }); // between display colour spaces: no view transform involved
```

### `displayView`

Apply the view transform of a display / view pair of the color config, or its inverse (OCIO DisplayViewTransform).

Module `lamino`, category Colour, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `display` | str | none |  |  |  | Display of the color config, e.g. "sRGB - Display". |
| `view` | str | none |  |  |  | View of that display, e.g. "ACES 1.0 - SDR Video". |
| `inverse` | bool | `false` |  |  |  | false: `colorspace` → display / view values. true: display / view values → `colorspace`. |
| `colorspace` | str | `"scene_linear"` |  |  |  | The scene-referred side of the transform (OCIO `src`): the input's colourspace forward, the output's inverse. |
| `unpremult` | bool | `true` |  |  |  | Unpremultiply before converting. |

The transform previews, probe, compare, the review window and movies apply to scene-referred nodes, as a node: OCIO's `DisplayViewTransform` with `src` = `colorspace`, built by the same colour processor, so a forward `displayView` and a preview of its input with the same display / view hold the same values. **Forward** (`inverse: false`): the input is scene-referred, in `colorspace` (default `scene_linear`, the working space); the output is display-referred, in the colour space the pair writes (`sRGB - Display` for `sRGB - Display` / `ACES 1.0 - SDR Video`), so viewers show it without a second view transform and render records it in the EXR header `lamino:colorspace`. Use it to finish in the values of a view. **Inverse** (`inverse: true`): the input is display-referred, in the colour space the pair writes (a `read(path, { colorspace: "<display>", convert: false })`, or a forward `displayView`); the output is scene-referred, in `colorspace`. Use it to bring display-referred material (an offline movie, a logo, a motion graphics render) into the working space so that the same view shows its values again. The input's colour state is checked by lint (L_COLORSPACE_FROM_MISMATCH), not by the kernel: like `colorspace`, the node decodes the values as what its parameters say. **Names:** `display` and `view` must be a pair of the config (E_COLOR_SPACE lists the pairs; they have no roles or aliases, so a comp that names them is tied to configs that have that pair — `ACES 1.0 - SDR Video` exists in builtin:aces-1.3, not in builtin:aces-2.0). A view that writes a data space (`Raw`) is refused. **What the inverse cannot do** (it is the config's inverse, nothing is fitted): the round trip display → scene → display returns the display values only where the forward transform can produce them. Greys return within 1e-4. The ACES 1.x output transforms do not reach the saturated edge of the display cube: under `sRGB - Display` / `ACES 1.0 - SDR Video` 16% of the cube is off by more than 1/1023 and 3% by more than 1/255 (display yellow [1, 1, 0] comes back as [0.99, 1.0, 0.53]; away from the faces of the cube the error stays below 0.01). A view limited to a smaller gamut or a lower peak than its display (D60 sim, Rec.709 limited, HDR views below the display's peak) cannot return what it never writes. The ACES 2.0 views invert over the whole cube of their own display. Display white becomes a large scene value (16.3 under `ACES 1.0 - SDR Video`, 128 under `ACES 2.0 - SDR 100 nits`), and the last 8-bit code values below white are far apart in scene values (0.98 → 7.0, 0.99 → 9.8): filters, resizes and blurs downstream weight those pixels by their scene value, and compression noise near white is amplified. The inverse transform is the right way in when the material goes back out through the same view; it is not a guess of the scene light. Premultiplication and alpha == 0 pixels as `colorspace` (straight rgb where alpha > 0 under `unpremult`; a view transform is not a matrix, so alpha == 0 pixels pass through). The WGSL kernel is generated from the OCIO processor, as for `colorspace`. **Backends:** the CPU kernel is C++ OpenColorIO's result bit for bit in both directions; the WGSL of an inverse agrees with it within 1e-3 of the pixel's largest channel (`lamino color verify`, class `gpuInverseView`: the inverse of a tone curve amplifies float32 rounding near display white).

Examples:

```ts
// Finish in the values of a view
const disp = comped.displayView({ display: "sRGB - Display", view: "ACES 1.0 - SDR Video" }); // previews show it without a second view transform

// Bring an offline movie in through the inverse of the delivery view
const offline = read("$W/In/edit/offline.mp4", { colorspace: "Rec.1886 Rec.709 - Display", convert: false }).displayView({ display: "Rec.1886 Rec.709 - Display", view: "ACES 1.0 - SDR Video", inverse: true });
const out = offline.over(cg); // viewed or delivered through Rec.1886 Rec.709 - Display / ACES 1.0 - SDR Video, the offline's values come back
```

### `lut`

Apply a 1D or 3D LUT file (.cube, .spi1d, .spi3d) to RGB.

Module `lamino`, category Colour, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `path` | path | none |  |  |  | Alias path of the LUT file (.cube, .spi1d or .spi3d), e.g. $SHOTS/SHOW/grade/look_v002.cube. |
| `interpolation` | enum | `"linear"` |  |  |  | 3D tables: trilinear (linear) or tetrahedral. 1D tables are always linear. Values: `linear` `tetrahedral` |
| `unpremult` | bool | `true` |  |  |  | Unpremultiply before the LUT (re-premultiplied by alpha where > 0). |
| `outputColorspace` | str | `""` |  |  |  | The colourspace the LUT's output is in (name, alias or role), declared: nothing is converted. Empty: the input's colour state. |

The LUT is applied **as is** to whatever the input holds: no colour conversion happens before or after it (put a `colorspace` in front when the LUT expects, say, log or display-referred values). The file is an asset: an alias path read through the project sandbox, recorded with its hash in `lamino.lock` by `check`, and its content hash enters the cache key, so replacing the file re-renders. Formats: `.cube` (Resolve / Adobe: `LUT_1D_SIZE` and / or `LUT_3D_SIZE`, red changing fastest; `DOMAIN_MIN` / `DOMAIN_MAX` or `LUT_1D_INPUT_RANGE` / `LUT_3D_INPUT_RANGE`, default 0..1; a file with both tables applies the 1D one first), `.spi1d` (`From`, `Length`, `Components` 1 or 3) and `.spi3d` (domain 0..1, explicit indices). Other formats (`.csp`, `.3dl`, …) are refused with E_COLOR_UNSUPPORTED; a malformed file is E_IMAGE_READ located at the file and line. **Domain:** each channel is clamped to the domain the file declares before the lookup, as the formats specify (the end entries extend flat); a NaN input reads the domain minimum on the CPU and is unspecified on the GPU. **Interpolation:** 1D tables are linear (per channel, `np.interp` on evenly spaced entries); 3D tables are trilinear (`linear`, default) or `tetrahedral`. Output values are the table's, unclamped. Alpha passes through. With `unpremult` (default, as `colorspace`) the LUT sees straight RGB where alpha > 0 and the result is re-premultiplied; pixels with alpha == 0 keep their RGB (a LUT is not a pure matrix, so it has no a → 0 limit). With `unpremult: false` the stored values go through the LUT, alpha 0 or not. **Colour state:** a LUT does not say what its output is, so the node keeps its input's colour state unless `outputColorspace` declares one (a look baked from scene values to display values: the display colour space). It is a declaration, nothing is converted: viewers start the view from it, render records it, and lint compares it with what the next node expects.

Examples:

```ts
// A baked view: scene values in, display values out
const disp = comp.colorspace({ from: "scene_linear", to: "ACEScct" }).lut({ path: "$SHOTS/SHOW/lut/acescct_to_rec709.cube", outputColorspace: "Rec.1886 Rec.709 - Display" }); // shown without a second view transform

// Display-referred grade
const graded = comp.displayView({ display: "sRGB - Display", view: "ACES 1.0 - SDR Video" }).lut({ path: "$SHOTS/SHOW/grade/look_v002.cube" });

// Log look, tetrahedral
const look = plate.lut({ path: "$SHOTS/SHOW/010/lut/show_look.spi3d", interpolation: "tetrahedral" });
```

## Transforms

### `transform`

Translate / rotate / scale in width units.

Module `lamino`, category Transforms, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `translate` | vec2 | `[0, 0]` |  | width units | yes | Offset [x, y]. |
| `rotate` | float | `0` |  | degrees | yes | Rotation in degrees, clockwise positive. |
| `scale` | vec2 | `[1, 1]` |  | factor | yes | Scale [x, y]. |
| `anchor` | vec2 | `[0, 0]` |  | width units | yes | Pivot [x, y] in width units. In scripts, giving anchor sets center to false (it becomes the pivot); anchor with center: true is an error. In the IR it is ignored when center is true. |
| `center` | bool | `true` |  |  |  | Pivot about the display centre (default true unless the script gives anchor). |
| `filter` | enum | `"bilinear"` |  |  |  | Resampling filter (fixed support in source pixels; see the description). Values: `nearest` `bilinear` `bicubic` `lanczos3` |
| `edge` | enum | `"transparent"` |  |  |  | Outside the input data window: transparent black, the nearest edge pixel, the mirrored picture or the repeated picture (with anything but `transparent` the output also covers the display window). Values: `transparent` `clamp` `mirror` `wrap` |

Order: scale, rotate (degrees, clockwise), then translate, about `anchor` (width units; `center` uses the display centre). Inverse-mapped resampling with the chosen filter; pixel centres at +0.5. Filters: nearest; bilinear; bicubic = Catmull-Rom (4×4 taps); lanczos3 = separable Lanczos with a = 3 (6×6 taps, the weights of each axis divided by their sum). Every filter has a fixed support in **source** pixels: none of them widens its kernel when the transform shrinks the image, so a strong downscale aliases — blur first (sigma ≈ 0.5 / scale px) when that matters. Lanczos (like Catmull-Rom) overshoots next to hard edges: results can go below 0 or above the input's range, alpha included; nothing is clamped (add `clamp` after it if needed). `edge` decides what lies outside the input data window: `transparent` (default) reads transparent black there; `clamp` reads the nearest edge pixel of the data window (on both axes), so the image extends infinitely; `mirror` reads the picture reflected at each edge of the data window and `wrap` the picture repeated (a tiling of the plane: Motion Tile, Offset). Output data window = bounding box of the transformed input data window (overscan is kept; E_RESOURCE_LIMIT beyond 16× the display area); with any `edge` but `transparent` it is that box united with the display window (the extended plane is cut to it), and the whole input is requested, never a part of it (the edge pixels must be the data window's own). An input with an empty data window gives an empty output either way. Pixel aspect ratio is honoured (rotation is computed in square pixels). Script sugar: `{ x, y }` → translate, scalar `scale` → both axes.

Examples:

```ts
// Nudge
const moved = fw.transform({ x: 0.02, y: -0.01, scale: 1.05 });

// Scale a background up and fill the frame with its edge pixels
const bg = read("$SHOTS/SHOW/010/bg.png").transform({ scale: 1.3, x: 0.08, filter: "lanczos3", edge: "clamp" });
```

### `crop`

Crop the data window to a box (the display window is unchanged).

Module `lamino`, category Transforms, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `box` | vec4 | `[0, 0, 1, 1]` |  | width units |  | [x0, y0, x1, y1] in width units. |

Output data window = input data window ∩ box (box in width units, rounded outward to pixels; the default [0,0,1,1] is taller than a 16:9 display, so `crop({})` is a no-op inside the display). Reformatting the display window is not a node operation; change the comp `res` instead.

Examples:

```ts
// Letterbox
const cut = plate.crop({ box: [0, 0.07, 1, 0.4925] });
```

## Filters

### `blur`

Gaussian, box or disc blur; `size` is the sigma in width units.

Module `lamino`, category Filters, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `size` | float | `0.01` | 0 or more | width units | yes | Sigma in width units (0.01 = 1% of the width). |
| `aspect` | float | `1` | 0 to 16 |  | yes | Vertical sigma = size · aspect. |
| `kernel` | enum | `"gaussian"` |  |  |  | Kernel shape (all three have the variance sigma² per axis). Values: `gaussian` `box` `disc` |
| `dimensions` | enum | `"both"` |  |  |  | Axes that are blurred. Values: `both` `horizontal` `vertical` |
| `channels` | enum | `"rgba"` |  |  |  | Channels replaced by their blurred value; the others pass through. Values: `rgba` `rgb` `alpha` `r` `g` `b` |
| `edge` | enum | `"transparent"` |  |  |  | Outside the input's data window: transparent black (`transparent`, edges fade) or the nearest edge pixel (`clamp`, edges keep their colour). Values: `transparent` `clamp` |

sigma_x = size·W px, sigma_y = size·aspect·W px (W = display width at this proxy level). `kernel`:              gaussian (separable): truncated at ceil(3·sigma), normalised, summed in fixed order (left→right, top→bottom);              box (separable): half-width = sqrt(3)·sigma (variance-matched), equal weights;              disc (one 2-D pass, the shape of an out-of-focus highlight): an ellipse of radii R_x = 2·sigma_x by R_y = 2·sigma_y px              (variance-matched: a disc of radius R has the variance R²/4 per axis). Taps (i, j) with |i| ≤ ceil(R_x), |j| ≤ ceil(R_y),              weight = clamp(R + 0.5 − R·sqrt((i/R_x)² + (j/R_y)²), 0, 1) with R = max(R_x, R_y) (a soft rim about one pixel wide on              the longer axis), rows summed top→bottom, each row left→right, divided by the summed weights; its cost grows with              the square of the radius (use it for bokeh, not for large soft blurs). A sigma below 0.25 px on an axis leaves that              axis untouched (the disc then has only the taps on the other axis; both below it is a copy).              `dimensions` (AE's Blur Dimensions) keeps one axis untouched: `horizontal` blurs along x only, `vertical` along y only              (the disc then collapses to a segment on that axis: equal weights over ±2·sigma with soft ends).              `channels` picks what is replaced by its blurred value: `rgba` (default), `rgb` (alpha stays as it was), `alpha` (rgb              stays), or one of `r` / `g` / `b`; the other channels are the input's (transparent black outside its data window).              The image is blurred premultiplied, as it is; with anything but `rgba` the result is no longer a consistently              premultiplied image, which is what a channel blur asks for.              Output window = input window grown by the padding (overscan kept; with `edge: clamp` the input window).              ROI padding = 3·size·max(1, aspect) width units (whatever the kernel and `dimensions`). Two passes (horizontal, vertical); the intermediate covers the work window (the output window grown by the ROI padding).              `edge`: `transparent` (default) reads transparent black outside the input's data window, so the borders of a plate darken;              `clamp` reads the nearest pixel of the data window instead (the input extended by repeating its edge pixels, like AE's              Repeat Edge Pixels), so a full-frame plate keeps its edge colour, and the output window is the input window (no padding              ring: the extension is infinite, so there is nothing to keep outside). Window rule (`RoiFn` of lamino-nodes):              `transparent` = input window grown by the padding, `clamp` = input window.

Examples:

```ts
// Glow base
const glow = fw.blur({ size: 0.02 });

// Soften a plate without dark borders
const soft = plate.blur({ size: 0.005, edge: "clamp" });

// Fast box blur along x only
const smear = plate.blur({ size: 0.01, kernel: "box", dimensions: "horizontal" });

// Soften only the matte
const softMatte = fg.blur({ size: 0.002, channels: "alpha" });
```

### `erode`

Morphological erode (positive size) or dilate (negative) of alpha or all channels.

Module `lamino`, category Filters, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `size` | float | `0.001` |  | width units | yes | Radius in width units; negative dilates. |
| `channels` | enum | `"alpha"` |  |  |  | Which channels to process. Values: `alpha` `rgba` |
| `shape` | enum | `"disc"` |  |  |  | Structuring element. Values: `disc` `square` |

Minimum (erode) / maximum (dilate) over a disc or square of radius |size| (pixels = |size|·W, rounded to nearest). `channels: alpha` processes alpha and scales rgb by new/old alpha where old alpha > 0 (rgb unchanged where old alpha == 0) so edges shrink cleanly; `rgba` applies to every channel independently. Output window = input grown by the radius. Used by `withAlpha({ erode })`.

Examples:

```ts
// Tighten a matte
const tight = matte.erode({ size: 0.0005 });
```

## Channels

### `premult`

Multiply RGB by alpha.

Module `lamino`, category Channels, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

### `unpremult`

Divide RGB by alpha where alpha > 0.

Module `lamino`, category Channels, output image, pointwise (fused with its neighbours)

- Input `in` (image): Source.

### `shuffle`

Rearrange channels; sources may come from a second input.

Module `lamino`, category Channels, output image, pointwise (fused with its neighbours)

- Input `A` (image): Primary source.
- Input `B` (image, optional): Secondary source for `1.x` channels.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `r` | enum | `"r"` |  |  |  | Source for red. Values: `r` `g` `b` `a` `1.r` `1.g` `1.b` `1.a` `0` `1` |
| `g` | enum | `"g"` |  |  |  | Source for green. Values: `r` `g` `b` `a` `1.r` `1.g` `1.b` `1.a` `0` `1` |
| `b` | enum | `"b"` |  |  |  | Source for blue. Values: `r` `g` `b` `a` `1.r` `1.g` `1.b` `1.a` `0` `1` |
| `a` | enum | `"a"` |  |  |  | Source for alpha. Values: `r` `g` `b` `a` `1.r` `1.g` `1.b` `1.a` `0` `1` |

Each output channel names a source: `r g b a` (from input 0), `1.r 1.g 1.b 1.a` (from input 1), `0`, `1`. Output data window = input 0's (input 1 is sampled over the same window; outside its data window it reads transparent black). An **unconnected** B reads transparent black too: `1.r` names input 1 explicitly and never falls back to A (as Nuke does), so a forgotten matte connection shows up as an empty channel instead of silently copying A. `withAlpha(matte)` in `lamino/fx` is `shuffle(matte, { a: "1.r" })` followed by `erode`; the result is straight (call `.premult()`).

Examples:

```ts
// Alpha from a matte's red
const keyed = fg.shuffle(matte, { a: "1.r" });

// Luma to alpha
const m = img.shuffle({ a: "r" });
```

## Measurement

### `measure`

Reduce an image (optionally masked, optionally within a region) to one statistic held in a 1×1 image.

Module `lamino`, category Measurement, output image

- Input `in` (image): Image to measure.
- Input `mask` (mask, optional): Optional weight: its alpha weights mean and centroid; pixels where it is <= 0 are left out of min, max and bbox.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `stat` | enum | `"mean"` |  |  |  | mean / min / max: premultiplied RGBA; bbox: [x0, y0, x1, y1] in width units; centroid: [x, y, area, coverage]. Values: `mean` `min` `max` `bbox` `centroid` |
| `region` | vec4 | `[0, 0, 0, 0]` |  | width units | yes | [x0, y0, x1, y1] in width units; [0, 0, 0, 0] = the whole input data window. |
| `threshold` | float | `0` |  |  | yes | bbox: a pixel counts when its alpha is greater than this. |

The output is a **1×1 image at display pixel (0, 0)** (data window [0, 0, 1, 1]); its four channels hold the statistic. Read it downstream with `texelFetch(srcN, ivec2(0, 0), 0)` in a `shader` that declares neither `hint pointwise` nor `padding` (such a shader reads its whole inputs, so the pixel is always evaluated; a pointwise or padded consumer asks only for its own region and gets nothing where that region misses (0, 0)), or with `probe` at [0, 0]. Values never become parameters: the statistic flows as an image. **Measured pixels:** the pixels of `region` (width units; a pixel counts when its centre lies in [x0, x1) × [y0, y1)), or the whole input data window when `region` is [0, 0, 0, 0] (the default); outside the input's data window the input is transparent black. A region with x1 <= x0 or y1 <= y0 (other than all zeros) or a non-finite value is E_IR_PARAM_RANGE; a region larger than the 16× display budget is E_RESOURCE_LIMIT. `mask` (optional): its alpha m is a weight; without it m = 1. **Statistics** (`stat`): `mean` = Σ m·rgba / Σ m (the premultiplied RGBA mean); `min` / `max` = per channel over the pixels with m > 0; `bbox` = [x0, y0, x1, y1] in width units of the pixel edges enclosing the pixels with m > 0 and alpha > `threshold`; `centroid` = [x, y, area, coverage] with w = alpha·m: x, y = the w-weighted mean of the pixel centres in width units, area = Σ w / W² (alpha area in square width units), coverage = Σ w / Σ m (mean alpha of the measured pixels). An empty selection (no pixel, Σ m = 0, Σ w = 0 for the centroid's x / y / area) gives 0 in the affected channels. NaN in the input propagates into mean and centroid; min, max and bbox are unspecified when the input holds NaN (`probe` reports it as L_NAN_INF). **Order:** the sums are f32 with one fixed order on both backends: the measured box is cut into 16×16 tiles (row-major from its top-left corner), each tile is summed in row-major order, tile k is added to partial k mod 256 in increasing k, and the 256 partials are combined by a pairwise tree (partial[i] ⊕= partial[i + s] for i < s, s = 128, 64, …, 1). CPU and GPU agree within the declared tolerance (relative 1e-5); repeated runs are bit-identical. **Proxy:** statistics are computed on the evaluated (proxy) image: mean, min and max follow the downsampled pixels (proxy-dependent), bbox and the centroid are in width units (stable up to the proxy pixel size), area is in square width units. Muting the node passes its input through unchanged (a full image, not 1×1).

Examples:

```ts
// Match a layer to the stage light
const avg = stage.measure({ region: [0.3, 0.2, 0.7, 0.5] });   // 1×1: the mean colour
const tinted = toto.shader({ source: TINT }, avg);   // TINT: `#pragma lamino inputs 2`, no `hint pointwise`; `vec4 m = texelFetch(src1, ivec2(0, 0), 0);`

// Alpha bounding box and centroid
const box = toto.measure({ stat: "bbox", threshold: 0.01 });
const c = toto.measure({ stat: "centroid" });
```

## Shaders

### `shader`

Run a GLSL fragment-style shader over the inputs (the one runtime extension point).

Module `lamino`, category Shaders, output image, reads its whole input, no CPU implementation

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `source` | shader | none |  |  |  | GLSL source text (inline). |
| `sourceFile` | str | `""` |  |  |  | Project-relative path the source came from (for errors and #include resolution); "" when written inline. |
| `params` | json | `{}` |  |  |  | Uniform values: {name: number \| [n,n] \| [n,n,n] \| [n,n,n,n] \| bool \| "enum option" \| keys(...)}. |
| `seed` | int | `0` |  |  |  | Seed for any randomness inside the shader (`lamino.seed`). |

Vulkan GLSL 450 (naga). Write `void main()` that assigns `fragColor` (vec4, premultiplied, working space; inputs are NOT unpremultiplied for you). Provided by the engine (see `lamino_core::glsl::GLSL_PRELUDE`): `vec2 p` — the pixel centre in WIDTH UNITS (x in 0..1, y in 0..H/W; the same unit as every parameter, so a circle is `distance(p, center)`), `vec2 uv` — texture coordinates 0..1 on both axes (`uv = p * vec2(1.0, resolution.x / resolution.y)`), `vec2 resolution` (display size in pixels at the current proxy level), `int frame`, `float time` (seconds), `int seed`, and one uniform per declared parameter. Inputs are read with `texture(srcN, uv)` (bilinear, deterministic; rewritten by the engine to `lamino_sample_t`), `texelFetch(srcN, ivec2 px)` for exact pixels, and `texture(srcN_prev, uv)` / `texture(srcN_next, uv)` when `temporal` is declared. Reserved names: resolution frame time seed p uv fragColor srcN out_tex main Params params lamino, any lamino_* / LAMINO_* identifier, and <name>_i; a GLSL keyword or type name (in, out, sample, smooth, float, mat2, …) cannot name a param either. Declarations are `#pragma lamino` lines: `param <name> <type> [default= min= max= unit=]`, `inputs <n> [src<i>=data ...]` (0 for a generator; default 1; inputs × (1+before+after) ≤ 8, the texture slots of a pass; `src<i>=data` makes input i a data port that takes an `aov` output — depth, position, normal, motion, uv — whose values arrive in the same `srcN` texture unconverted and not premultiplied; read them with `texelFetch`, since far depth is +inf), `padding <width units>`, `temporal <before> <after>`, `hint pointwise`, `version <n>`. The GLSL preprocessor is available: `#define` (also function-like macros), `#ifdef` / `#if` / `#else` / `#endif` may be used. `#include "lib/noise.glsl"` is resolved inside the project / library roots and the expanded source hash enters the cache key. Without `padding` or `hint pointwise` the node reads the whole input and lint warns (L_SHADER_NO_MARGIN). Compile errors are reported with the original file and line. `source` is the GLSL text (the script layer inlines a `.glsl` file and records its path in `sourceFile`); `params` holds the uniform values, validated against the declarations and animatable. Output window = input 0's (grown by `padding` when declared), or the display window for a generator (`inputs 0`). There is no CPU kernel: the reference for shader goldens is the software adapter (WARP on Windows, lavapipe on Linux), and with `--backend cpu` shader nodes alone run there (inputs uploaded, result downloaded) while every other node runs its CPU kernel; a machine without a software adapter fails such a comp before the first frame with E_GPU.

Examples:

```ts
// Inline vignette
const vig = img.shader({ source: `
  #pragma lamino param strength float default=0.8 min=0 max=4
  #pragma lamino hint pointwise
  void main() {
    vec4 c = texture(src0, uv);
    vec2 center = vec2(0.5, 0.5 * resolution.y / resolution.x);
    float d = distance(p, center);           // width units: a true circle
    fragColor = c * (1.0 - strength * d * d);
  }`, params: { strength: 0.8 } });

// From a file
import { lightning } from "../../common/fx/lightning";   // a TS module wrapping shader({ source: <file text>, sourceFile: "common/fx/lightning.glsl" })
const bolt = lightning({ seed: 3, branches: 5, width: 0.004 });
```

## Time

### `frameBlend`

Weighted average of the frames around the current one (frame averaging / motion smear).

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `before` | int | `1` | 0 to 7 | frames |  | Frames read before the current one (0..=7). |
| `after` | int | `1` | 0 to 7 | frames |  | Frames read after the current one (0..=7). |
| `weights` | json | `"box"` |  |  |  | `"box"`, `"triangle"` or an array of `before + 1 + after` positive numbers (oldest frame first), normalised to sum 1. |

out(frame) = Σ_k w_k · in(frame + k) for k = −before..=after, on premultiplied RGBA as stored (colour and alpha are averaged alike; nothing is clamped). The window is read from the parameters at plan time (`TemporalRequest::FromParams`); before + after ≤ 7 so that the GPU binds the current frame and the window in one pass (a larger extent is E_IR_PARAM_RANGE). `weights`: `"box"` = equal weights; `"triangle"` = w_k = max(before, after) + 1 − |k| (the current frame heaviest, the farthest frame of the longer side 1); or an array of exactly before + 1 + after positive numbers in frame order (oldest first). Weights are normalised to sum 1; a non-positive weight or a wrong count is E_IR_PARAM_RANGE. Frames before the first or after the last frame of a source follow that source's `missing` rule (E_FRAME_MISSING with `missing: error`). Output data window: the union of the blended frames' windows. Muting passes the current frame through. No spatial extent (`Scale::Independent`).

Examples:

```ts
// Smear
const smeared = plate.frameBlend({ before: 2, after: 2, weights: "triangle" });

// Explicit weights
const avg = plate.frameBlend({ before: 1, after: 0, weights: [1, 3] });
```

### `echo`

Trails: decayed copies of the previous frames composited under the current one.

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `frames` | int | `4` | 1 to 7 | frames |  | Previous frames composited under the current one (1..=7). |
| `decay` | float | `0.5` | 0 to 1 |  | yes | Multiplier per frame of age (frame − k is scaled by decay^k). |

acc = in(frame − frames) · decay^frames; for k = frames − 1 down to 1: acc = (in(frame − k) · decay^k) over acc; out = in(frame) over acc — older frames go **under** the newer ones, each multiplied as premultiplied RGBA (colour and alpha together) by decay^k. `frames` (1..=7, read at plan time `FromParams` with `before` only; not animatable) is the number of previous frames; `decay` is animatable. Frames before the first frame of a source follow its `missing` rule. Output data window: the union of the frames' windows. Nothing is clamped. Muting passes the current frame through.

Examples:

```ts
// Spark trails
const trails = sparks.echo({ frames: 5, decay: 0.6 });
```

### `temporalMedian`

Per-channel median over the surrounding frames (flicker and dropout removal).

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `radius` | int | `1` | 0 to 3 | frames |  | Frames on each side of the current one (0..=3; the window is 2·radius + 1 frames). |

For every pixel and every channel independently, the median of the 2·radius + 1 values at frames frame − radius ..= frame + radius (premultiplied values as stored; the result need not be a colour that occurs in any single frame). radius 0 is a copy; radius ≤ 3 keeps the window within the GPU's 8 image slots. The radius is read at plan time (`FromParams`, the same parameter on both sides) and is not animatable. Frames outside a source follow its `missing` rule. Output data window: the union of the frames' windows. Muting passes the current frame through.

Examples:

```ts
// Deflicker
const stable = plate.temporalMedian({ radius: 1 });
```

### `timeOffset`

Shift the input in time: out(frame) = in(frame + frames).

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `frames` | int | `0` |  | frames |  | Offset added to the comp frame (negative = delay). |

A time map (`TemporalRequest::Mapped(Shift)`): the upstream graph is evaluated **once**, at frame + frames, and the current frame of the input is not read at all (the evaluator plans the sources and windows of the mapped frame, so a source frame missing at the current frame does not fail). Positive `frames` looks ahead, negative delays. The parameter is not animatable (one mapped frame per output frame; integer arithmetic is checked, a result outside the representable range is E_IR_PARAM_RANGE). A mapped frame a source does not have follows that source's `missing` rule. Cache keys hold the mapped absolute frame and the upstream root's key. Output data window: the input's window at the mapped frame. For speed changes, reverse play and speed curves use `retime`. Muting passes the current frame through.

Examples:

```ts
// Two frames late
const late = plate.timeOffset({ frames: -2 });
```

### `frameHold`

Freeze one frame: every output frame shows the input at `frame`.

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `frame` | int | `1` |  | frames |  | The comp frame to hold. |

A time map (`TemporalRequest::Mapped(Hold)`): `frame` is an absolute comp frame; the upstream graph is evaluated once at that frame (cached, the cache key does not depend on the output frame) and the current frame of the input is not read. Not animatable. A frame a source does not have follows its `missing` rule. Output data window: the input's window at the held frame. Muting passes the current frame through.

Examples:

```ts
// Freeze the first frame
const still = plate.frameHold({ frame: 1001 });
```

### `retime`

Time remap: out(frame) = in(time(frame)), time keyframed or computed.

Module `lamino`, category Time, output image

- Input `in` (image): Source.

| Parameter | Type | Default | Range | Unit | Keys | Description |
|---|---|---|---|---|---|---|
| `time` | float | none |  | frames | yes | Comp frame of the input to show (may be fractional). |
| `sample` | enum | `"floor"` |  |  |  | Frames for a fractional time: the frame at or before, the nearest frame, or a blend of the two around it. Values: `floor` `nearest` `blend` |

A time map (`TemporalRequest::Mapped(Retime)`): `time` is the comp frame of the input shown at each output frame, an animatable number. The upstream graph — a read, or a whole precomp with its own animation — is evaluated at that frame, and the current frame of the input is read only when the map lands on it. Constant speed: `time: t(f => 1001 + (f - 1001) * 1.5)`; reverse: `t(f => 1100 - (f - 1001))`; a speed curve: `keys([[1001, 1001], [1048, 1100, ease.inOut]])`. `sample` picks the frames for a fractional time: `floor` (the frame at or before, as OTIO LinearTimeWarp), `nearest` (halves round up) or `blend` (the two frames around it, weighted by the fraction, on premultiplied RGBA). Upstream animation is evaluated at those whole frames only: the engine never evaluates between frames, so a keyed move slowed down by `retime` steps or cross-fades. For keyframed content — text, shapes, any animated parameter, a precomp of them — build the sub-graph inside `withTime(map, () => …)` instead: it moves the key times and the `t()` sample times themselves, so the result is smooth, and reads the whole-frame sources inside it through a `retime` with the same map. A frame a source does not have follows its `missing` rule. Output data window: the union of the frames read. Muting passes the current frame through.

Examples:

```ts
// Play at 1.5× from frame 1001
const fast = plate.retime({ time: t(f => 1001 + (f - 1001) * 1.5), sample: "blend" });

// Keyframed content at half speed: map the keys instead
const slow = withTime({ speed: 0.5, origin: 1001 }, () => title());
```
