# JPEG-LS restart intervals

DRI specifies an unsigned 16-, 24- or 32-bit number of MCUs per restart interval. It remains active across scans until changed. A zero value disables restarts. Each scan starts its RST sequence at RST0. JPEG-LS counts a component line in ILV=0, a group of equal-length component lines in ILV=2, and one sampling group in ILV=1, including coded padding in its last group. At a restart the core resets prediction rows, context statistics, run indices, and the entropy reader or writer. It preserves the scan, mapping selection, and cumulative component coordinates. [T.87 C.2.5 and Annex D](https://www.itu.int/rec/T-REC-T.87-199806-I/en)

```sh
moonjls encode 12 2 8 0 pixels.raw restarted.jls raw-le 1 --restart 1
moonjls inspect restarted.jls 1 --json
node scripts/verify_restart_intervals.mjs --native-exe _build/native/release/build/cmd/moonjls/moonjls.exe
```

Inspection exposes an active nonzero `restartInterval` and the observed `restartCount` per scan. Retaining a count keeps diagnostic memory independent of the number of restart markers. The API validates ordered RST markers and neither attempts damage recovery nor provides random access. [MoonBit, Native and SDK API](API.md)

The verifier compares exact codestream bytes and reconstructed rows through JS, Wasm GC and Native, with 1-, 7- and 4096-byte chunks. Applicable non-sampled streams were cross-decoded with CharLS Wasm 0.10.0. Sampled ILV=0 and ILV=1 use independently constructed vectors. The latter also covers an odd sampling group and nonzero Pt and NEAR. Annex E runs separately, as it contains no restart interval case.

JS and Wasm GC each passed 30 encoding, 33 decoding and 24 direct CharLS checks. Native passed 27, 33 and 21 respectively. The Native CLI has a common interval option. Explicit per-scan changes are exercised by the public MoonBit and SDK encoders, and the Native decoder checked that same stream. The three core targets each passed 47/47, and the two actual Worker backends passed the split FF00/RST0 case. [Restart receipt](../reports/m4-restart-20261130/restart-intervals.json) · [Annex E and regression receipt](../reports/m4-restart-20261130/regressions.json)
