A radial, self-clocking, multiscale optical code. The successor experiment to QR. This file is the single source of truth for any LLM agent building this project. If something here is ambiguous, pick the documented default and keep going — do not stop to ask.
IRIS is open source (MIT). Everything in this repo is meant to be public: keep the
spec, code, and tests free of secrets and proprietary assumptions, write documentation for
outside contributors, and ship a LICENSE file (MIT) plus an open-source-friendly README.
Build a working reference implementation of IRIS, a new 2D optical code that is not a square matrix. Deliverables, in priority order:
iris-core— encoder, geometry, error correction (pure, deterministic, no I/O).iris-render— turn an encoded symbol into an SVG and a raster bitmap.iris-decode— recover the payload from a bitmap (start with clean renders, then add robustness).iris-cli—iris encode "<text>" -o out.svg/iris decode in.png.- Tests — round-trip property tests + robustness tests (scratch, blur, perspective).
A successful run: random payload → encode → render → decode returns the identical payload, and survives a radial scratch and mild perspective warp.
Every optical code must solve four problems. Keep these named in code and comments:
| Pillar | QR’s answer | IRIS’s answer |
|---|---|---|
| Localization (find it) | 3 corner eyes | central pupil (bullseye) |
| Registration (orientation + perspective) | 3 eyes + alignment patterns | fit an ellipse to the pupil’s outer ring; a north marker fixes rotation |
| Sampling (where is each bit) | regular square grid | concentric rings of angular segments, each segment self-marked |
| Error correction | Reed–Solomon, linear | Reed–Solomon interleaved along rings, per-layer independent blocks |
IRIS’s three defining ideas — implement all three, they are not optional:
- Self-clocking segments. Every segment carries its own start marker. The decoder re-syncs at every cell, not once per ring. This is what makes IRIS strong against radial scratches. Because each segment self-marks, rings do not need their sectors aligned to each other.
- Capacity grows outward. Segments-per-ring scales with the ring’s radius (bigger diameter ⇒ more circumference ⇒ more bits). Outer rings dominate total capacity. You extend capacity by adding rings, never by changing the center.
- The pupil is the header. The pupil’s outer contour is invariant (it localizes & registers). Its interior is chosen from a small codebook and encodes the bootstrap config. The decoder classifies the pupil against templates; it does not bit-sample it.
All sizes are in module units u; the renderer maps u → pixels (default 8 px). Geometry is polar around center C.
┌ quiet zone (4u, blank) ┐
│ pupil (header) │ radius 0 … Rp
│ ring 0 (data, layer 0) │
│ ring 1 (data, layer 0) │
│ ring 2 (data, layer 1) │
│ ring 3 (data, layer 1) │
│ ring 4 (data, layer 2) │
│ ring 5 (data, layer 2) │
└ quiet zone (4u, blank) ┘
- Pupil radius
Rp = 6u. - Ring radial width
dr = 3u. Ringkspans radius[Rp + k*dr, Rp + (k+1)*dr]. - Default ring count
K = 6(configurable; more rings = more capacity). r_mid(k) = Rp + dr*(k + 0.5).
- Invariant outer contour: two concentric circles (outer stroke
2u). This is the only thing localization/registration touch. Never changes. - Interior glyph: one entry from a fixed codebook of ≤16 maximally-distinct templates. The selected template encodes the bootstrap word:
- symbology version (4 bits),
- ECC level of layer 0 (2 bits),
- ring schedule id → tells the decoder
Kand segments-per-ring (3 bits), - flags: annulus/hole, charset, reserved (remaining bits).
- The decoder classifies the interior (template match), it does not sample cells. Keep the codebook in
iris-core/pupil-codebook.jswith a render fn + a classifier fn per entry. - If the header needs more than the codebook can hold, spill the rest into a dedicated header ring (ring 0 with fixed segment count and max ECC) — flagged by the pupil.
- Target arc-length per segment
s_seg = 4u(constant). Then:N_k = round( 2π * r_mid(k) / s_seg ), snapped to the nearest even number, and clamped soN_k >= N_{k-1}. - Because segments are self-clocked,
N_kis independent per ring — no cross-ring alignment required. Store the actualN_karray in the symbol params; the ring-schedule id in the pupil selects which precomputed array to use. - Raw data bits in ring
k=N_k(1 bit/segment in v1). Total raw bits= Σ N_k. Note this grows ~linearly per ring and ~quadratically in total with radius — document this in code.
Each segment occupies an angular slice of its ring, split radially-agnostic but along the arc:
|■■ start tick ■■| data cell |
|<--- 30% --->|<------ 70% ------>|
always ink black OR white = 1 bit
- Start tick: leading 30% of the segment’s arc is always inked. These ticks are a regular train of marks the decoder locks onto to delineate segments locally.
- Data cell: trailing 70% is black (
1) or white (0). - North marker: the segment at angle 0 (top) of ring 0 has a tick extended inward by
+1u— unique shape ⇒ absolute rotation origin. The pupil gives coarse orientation; north gives exact. - (Stretch) multi-level/halftone data cells for higher density — out of scope for v1.
- Angle 0 at top (12 o’clock), increasing clockwise. Segment 0 of each ring starts at angle 0. Reading order: ring 0 → outward; within a ring, segment 0 → clockwise.
- Reed–Solomon over GF(256) (primitive poly
0x11d). Implement iniris-core/rs.js; validate against published test vectors. - Layers: group rings into independently-decodable layers (default: L0 = rings 0–1, L1 = rings 2–3, L2 = rings 4–5). Each layer is its own RS block with its own parity. Inner layers carry the short/low-res payload and use higher parity. This gives graceful degradation: L0 still decodes when outer layers are destroyed.
- Interleaving: within a layer, place consecutive RS symbols in segments spread around the ring and across the layer’s rings, so a localized scratch damages at most one symbol per codeword.
- ECC parity ratio default 30% (selectable via pupil ECC level).
- Pure black
#000on pure white#fff. Quiet zone blank. No anti-alias assumptions in the spec (decoder must tolerate it). - SVG is the source of truth; raster is rasterized from it at a given
u. - Deterministic: same input + params ⇒ byte-identical SVG.
Implement as discrete, individually testable stages:
- Binarize the input (adaptive threshold; Otsu fallback).
- Find pupil: detect the concentric-circle bullseye (connected components + circularity, or template match). Reject false positives by the double-ring signature.
- Fit ellipse to the pupil’s outer contour ⇒ recover the perspective transform
H. Rectify the image withHso the code becomes a true circle. - Classify pupil interior against the codebook ⇒ bootstrap word ⇒ version, ECC level, ring schedule (
K,N_k[]), flags. - Find north tick ⇒ absolute angular origin.
- Walk rings outward. For each ring: sweep the annulus at
r_mid(k), detect the tick train to delineate segments locally (this is the resync step — do NOT assume even spacing if ticks are missing; locate them). Read each data cell’s bit. - De-interleave per layer, run RS decode per layer. Decode inner layers first; return their payload even if outer layers fail.
- Assemble payload, verify, return.
Track-1 (must work): decode clean renders produced by iris-render.
Track-2 (stretch): decode photographs (add denoise, illumination correction; OpenCV via a separate optional Python tool tools/decode_cv.py is acceptable here).
- Parse payload + options → choose version, ECC, ring schedule.
- Build the bootstrap word → select pupil codebook entry.
- Byte-encode payload (charset per flags); split into layers.
- RS-encode each layer; interleave into segment bit positions per §2.6.
- Emit a
Symbolobject:{ params, pupilEntryId, ringBits: number[][] }. Rendering is a separate step.
- JavaScript first. Ship the reference implementation in plain JavaScript (ESM,
Node ≥ 18) before anything else. It is the canonical, must-work target — get the full
encode → render → decode round-trip green in JS, then (optionally) port or add typings.
- Use JSDoc type annotations for the public API so editors and
tsc --checkJscan type-check without requiring a build step. A later TypeScript layer (or.d.tsfiles) is welcome but is a follow-on, never a blocker for any milestone.
- Use JSDoc type annotations for the public API so editors and
- Monorepo with pnpm workspaces. Test runner: vitest. Lint: eslint + prettier (config can be minimal).
- No network at runtime. Keep dependencies near-zero; implement RS and geometry in-repo. Rasterization may use
sharpor@resvg/resvg-js; decoder image ops may usesharpfor pixel access.
/packages
/iris-core # encode, geometry, rs, params, pupil-codebook
/iris-render # symbol -> svg, svg -> png
/iris-decode # png -> symbol -> payload
/iris-cli # commander-based CLI
/tools
decode_cv.py # optional: photo-grade decode (OpenCV), Track-2 only
/test
vectors/ # known RS vectors, golden SVGs
README.md
AGENTS.md
- M0 Scaffold monorepo, CI script
pnpm test, empty packages compile. - M1
iris-coregeometry + params: computeN_k[], segment angles, pupil codebook (render + classify stubs). Unit tests on geometry math. - M2
iris-coreRS + layering + interleaving. Test against known vectors; test encode is deterministic. - M3
iris-render: Symbol → SVG (matches §2 exactly) + SVG → PNG. Golden-file tests. - M4
iris-decodeTrack-1: decode our own clean PNGs. Round-trip property test must pass at 100% over 1000 random payloads. - M5 Robustness: synthetic scratch (occlude a radial wedge up to 30°), gaussian blur, ±20° perspective warp. Decode success-rate targets in tests (document them; aim ≥95% for 15° wedge, ≥99% for blur σ≤1.5px).
- M6
iris-cli+ README with examples + a generated sample gallery. - M7 (stretch) Track-2 photo decode; multi-level data cells.
- Geometry functions are pure and unit-tested in isolation. No globals; pass
paramsexplicitly. - Use a typed
IrisParamsobject everywhere; never hardcode8u,6uetc. outside the default-profile constant. - Determinism is a hard requirement: no
Date.now(), no unseeded RNG in encode/render. Tests may use a seeded RNG. - Name things by the spec vocabulary:
pupil,ring,segment,tick,dataCell,north,layer,bootstrapWord. Keep them consistent across packages. - Every public function gets a one-line doc comment stating which spec section it implements.
- Charset: UTF-8 bytes. Numeric/alpha compaction modes are a stretch.
- Pupil codebook size: 16 entries. If you need fewer for v1, define 8 and reserve the rest.
- Ring schedule ids: ship 3 (small/medium/large = K of 4/6/8). Precompute their
N_k[]. - Quiet zone: 4u. Module unit: 8px. Parity: 30%. These live in
DEFAULT_PROFILE. - If a stage is too hard for Track-1 (e.g., real CV), implement the clean-render path first and leave a
// TODO Track-2with a passing clean-path test.
pnpm testgreen, including the M4 round-trip property test at 100% and the M5 robustness thresholds.iris-cli encode "hello iris" -o hello.svgproduces a valid symbol;iris-cli decode hello.pngprintshello iris.- README shows an encoded sample and documents the IRIS profile.
- Pupil — central bullseye; invariant outer contour (localize/register) + codebook interior (header).
- Ring — one annular band of data, width
dr. - Segment — one angular cell within a ring; carries a start tick + a 1-bit data cell.
- Tick — the always-inked leading mark of a segment; the self-clocking sync feature.
- North — the unique tick that fixes absolute rotation.
- Layer — a group of rings forming one independently-decodable RS block.
- Bootstrap word — the few bits the pupil encodes; read first, governs all parsing.
- Ring schedule — the chosen
KandN_k[]for a symbol.