# Conventions

There are six conventions to know before writing a comp: coordinates and units, colour, merge direction, image extents, time, and paths. The same content in English is in `conventions` of `lamino schema --json`.

## Coordinates and units

The origin is the top left, x goes right and y goes down. Lengths are written in **width units**. The image width is 1.0, and y runs from 0 to height ÷ width (1.0 × 0.5625 for 16:9).

| What you want to write | How to write it |
| --- | --- |
| Position, offset, blur size | Width units. 1% of the width is `0.01` |
| Converting from pixel coordinates (px, py) | `(px / W, py / W)`. y is divided by the width too |
| Rotation | Degrees. Clockwise is positive |
| 3D distance (`card3d`, near / far of `fog`) | Metres |

Writing pixel counts in a parameter gives the lint `L_PIXEL_UNITS`. Parameter names are camelCase everywhere: TypeScript, the IR and the schema.

## Colour

Every image inside the engine is scene-linear (the working space, ACEScg by default) and premultiplied.

- **Entry**: `read` converts from the declared input colour space to the working space. Declare `colorspace` for anything other than an EXR in the working space (otherwise `L_COLORSPACE_UNSPECIFIED`). Without a declaration, the config's file rules, the colour space the file header names (`L_COLORSPACE_FROM_FILE`) and the default rule are used, in that order.
- **Exit**: `preview`, the review window and the stream for movies apply the display / view transform. EXR output does not.
- **Colour state**: which colour space each node's pixels are in is known from the IR. `read` is the working space, `colorspace()` is its `to`, `displayView()` is the colour space of its display / view, a merge is the B side, and other nodes inherit from their input. Merging two different states gives `L_COLOR_STATE_MISMATCH`.
- **Nodes that need straight colour**: `grade`, `colorspace` and `despill` unpremultiply only the pixels whose alpha is greater than 0, process them, and multiply back. Pixels with alpha 0 keep their rgb (emissive sparks do not disappear).

To composite display-referred material (logos, offline movies, motion graphics) with its display values as they are, write `read(path, { colorspace: "sRGB - Display", convert: false })`. If it goes back out through the view, bring it in through the inverse of the same display / view, `displayView({ display, view, inverse: true })`.

A colour parameter can be written as `[r, g, b, a]`, `[r, g, b]`, a scalar or `"#rrggbb"` (read as sRGB and linearised through the config).

The OCIO config is evaluated by a Rust port, not by the C++ OpenColorIO. A transform the port cannot evaluate is not approximated; it stops with `E_COLOR_UNSUPPORTED`. Check a job's config once at the start with `lamino color verify`.

## Merge direction

The inputs of `merge` are `inputs[0]`, A (the foreground), and `inputs[1]`, B (the background). `over` is `A + B × (1 − A's alpha)`.

| Written as | Meaning |
| --- | --- |
| `over(a, b)` | Places A over B. The first argument is the foreground |
| `bg.over(fg)` | Places fg over bg. The receiver is the background |
| `inside(a, b)`, `outside(a, b)` | `in` and `out`. There is no method form |
| `bg.blend(fg, "overlay", { mix })` | Layering with an After Effects blend mode |

As in Nuke, `merge` operations apply to all four channels, alpha included. For `add`, `subtract` and `difference`, set the output alpha with `alpha: "op" | "a" | "b" | "max"` (otherwise `L_MERGE_ALPHA`). `screen` uses a formula that does not break with values above 1.0.

Effects are computed in linear light, and values are not clamped. Entering the same numbers as in After Effects does not give the same picture, so match by comparing against a reference.

## Image extents

An image has two extents: the frame that is delivered (the display window) and the area that actually has pixels (the data window). Blurs and transforms make pixels outside the frame, and no node cuts them at the frame. Only `crop` and the writer cut (`render --out` cuts at the display window; `--keep-overscan` keeps the rest).

Blurring a plate over its whole area darkens the edges because the area outside the frame is read as transparent. `blur({ size, edge: "clamp" })` extends the edge pixels for the read.

## Time and frames

Frame numbers are integers, written as `####` in image sequence file names. A movie is read as a sequence starting at 1 (the first picture is frame 1). To shift it, use `frameOffset`.

| What you want to do | What to use |
| --- | --- |
| Mix neighbouring frames, trails, denoising | `frameBlend`, `echo`, `temporalMedian` |
| Shift, freeze | `timeOffset`, `frameHold` |
| Change the speed of footage, reverse it | `retime`. It only picks frames or mixes two; there is no optical flow |
| Change the speed of things animated by keyframes (text, shapes, parameters) | `withTime(map, () => ...)`. It moves the key times themselves, so motion stays smooth |

## Paths and output locations

- Asset paths start with a root alias, as in `$SHOTS/...`. Absolute paths and `..` are refused.
- Plates and renders are read-only.
- Output can go only to a versioned folder such as `$OUT/<name>_v001/`. Existing frames are never overwritten.
- Running the same command again fills in only the missing frames, but only when all existing frames of that version were made from the same graph. If not, nothing is written and `E_PATH_VERSION_EXISTS` is returned, so raise the version.
