# JPEG-LS Support Scope

MoonJLS implements the encoding, decoding and data formats of **ITU-T T.87 (06/1998) / ISO/IEC 14495-1 JPEG-LS Part 1** within its documented application limits. The implementation includes interchange images, abbreviated images, table specification data, restart intervals and deferred or extended frame geometry. [Conformance matrix](T87_CONFORMANCE_PLAN.md) · [Roadmap](ROADMAP.md)

| Dimension | Current profile (2026-12-01) | Part 1 notes |
| --- | --- | --- |
| **Image & Scan Layout** | One frame, **1–255 components** with H/V factors in 1..4. ILV=0 uses one component per scan. ILV=1/2 uses 2–4 components per scan. ILV=2 requires equal component dimensions within its scan. ILV=1 codes V_i whole lines per component per MCU and delivers its actual component rows. DNL and LSE4 extend the ordinary SOF55 geometry. The default axis limit is 65,535 and can be raised. | See application limits below. |
| **Precision & MAXVAL** | SOF55 source precision **`P=2–16`**. The coding-domain default is `MAXVAL = 2^P − 1`, including transformed scans. Explicit `MAXVAL` is in `1..2^P−1`. Wt=1 mapping returns unsigned scalar values. An opt-in byte interface returns Wt>1 entries in table order. | Preserve these contracts in the full format scope. |
| **NEAR & Pt** | Per-scan `NEAR` in `0..min(255, floor(effective_MAXVAL/2))` applies to coded samples or indices. For unmapped Pt, the original-scale bound is `s·NEAR + s − 1` (`s = 2^Pt`). Mapped output has no general NEAR-based bound. | Verify transformed output domains as each remaining table format is added. |
| **LSE & Tables** | **LSE1** preserves per-SOS defaults and validates overrides against active NEAR and MAXVAL. **LSE2/LSE3** supports Wt=1–255 definition, replacement and aligned continuation. C.3 references installed tables at Pt=0. **LSE4** uses unsigned 16-, 24- or 32-bit dimension fields. | See the table and geometry reports. |
| **Sample & Host Storage** | The core holds prediction lines and scan contexts. ILV=1 maintains independent run indices. ILV=2 shares a run index. Native `encode-planar` with ILV=1/2 and a regular seekable file uses bounded positioned raw windows and one integer staging row. Multirow windows with `CHUNK` ≥ 1 KiB use a separate output batch of up to 64 KiB. Stdin and FIFO can opt into `--input-policy spool` for bounded RAM and explicit temporary disk; the default sequential interleaved path retains the complete planar input. Native PGM/PPM and `encode-scans` also use row buffers. SDK whole-image helpers and the workbench have their own buffer accounting. | Known-height host staging and the DNL decode prefix are reported separately. |
| **Entropy & Markers** | Regular, run and interruption modes, one-bit stuffing after entropy FF, SOI/SOF55/SOS/EOI, LSE1–4, DNL, DRI and RST0–7. The decoder consumes legal APPn, COM and marker fill. The encoder emits canonical markers and can omit optional APPn/COM/fill. | See Annex C and D evidence. |
| **Backends** | Single pure MoonBit `core` compiled to **Native**, **Wasm GC**, and **JS**. | Same single pure MoonBit core across Native, Wasm GC, and JS. |

## Point transform

Unmapped Pt=0–15 is supported in the MoonBit core, Native, JS and Wasm GC. Native exposes `raw32-le` and `raw32-be` in decoder delivery order. SDK and Worker opt in to `Uint32Array`, and the workbench exports 32-bit little-endian planes in declared component order. Narrow outputs reject unrepresentable values. Nonzero Pt requires all scan mapping selectors to be zero. Independent evidence includes sampled edge MCUs. [Point-transform results and limits](POINT_TRANSFORM_RESULTS.md)

## Embedded mapping tables

Interchange encoding and decoding support embedded `Wt=1–255` tables in LSE2 and aligned LSE3 continuations, replacement between scans, and per-component SOS selectors at Pt=0. The encoder consumes indices and table definitions. The scalar interface delivers unmapped samples and Wt=1 values. Opt-in MoonBit, Native, SDK and Worker interfaces deliver Wt>1 entries as opaque bytes. The workbench previews scalar rows. NEAR applies to the index domain. C.4 can supply immutable table snapshots, and C.3 images can reference those tables alongside locally defined tables. [Embedded mapping](EMBEDDED_MAPPING_RESULTS.md) · [C.3 abbreviated images](ABBREVIATED_IMAGE_RESULTS.md)

## Boundary Separation: Part 1 vs. Part 2 & Containers

The application caps dimensions and actual sample counts. Unknown-height and explicit height-redefinition decoding have a 32 MiB first-scan prefix cap before replay. For standard streams, use integral horizontal component dimensions and preserve relative SOF component order inside each SOS. MoonJLS retains two compatibility extensions for existing users, rounding nonintegral horizontal component sizes up and allowing reordered component selectors within ILV=1. [Frame geometry](FRAME_GEOMETRY_RESULTS.md) · [T.87 §4.3.1](https://www.itu.int/rec/T-REC-T.87-199806-I/en) · [T.81 B.2.3](https://www.w3.org/Graphics/JPEG/itu-t81.pdf)

- **Included in MoonJLS Final Target**: ITU-T T.87 (06/1998) / ISO/IEC 14495-1 **JPEG-LS Part 1** (Interchange Format + Abbreviated / Table-Specification Formats + §8/Annex E conformance).
- **Separate Out-of-Scope Extensions (Not Part 1 requirements)**:
  - **ITU-T T.870 / ISO/IEC 14495-2 (JPEG-LS Part 2)** extensions.
  - **DICOM** application-layer container encapsulation.
- **Optional Standard Container**: **SPIFF** (recommended in T.87 §4.8 and Annex H.5) is documented and tracked separately from the Annex C core bitstream matrix.

## API & Verification Evidence Notes

- Grayscale compatibility entrypoints (`encode`, `decode`, `decode_with_preset`, `Encoder::new`) remain intact; single-component `decode` rejects multi-component streams cleanly with `UnsupportedFeature`. Multi-component entrypoints (`Encoder::new_scans`, `encode_scans`, `decode_multicomponent`, `inspect`) expose `FrameInfo`, `ScanInfo`, `StreamStructure`, and `ErrorLocation`. [Public API](API.md)
- Streaming decode returns `Done` strictly after `EOI`, delivers Component 1 rows immediately before Scan 2/`EOI` arrive, keeps pre-EOI rows provisional, and rejects trailing bytes by default.
- Verification datasets are explicitly separated by scope:
  - **Annex E Table E.2 (12/12)**. The same candidate passed encode and decode on JS, Wasm GC, and Native against HP 1.00. CharLS Wasm independently verified ten cases and returned `reference_unsupported` for E.2-7/8. [Conformance Results](CONFORMANCE_RESULTS.md) · [Workbench checks](../reports/t87-m3b-20261126/public-delivery/workbench-chrome.json)
  - **M3-A Golden Suite** (`scripts/verify_m3a_golden.mjs` in CI): 7 positive cases (2/3/4 components, non-contiguous IDs, reordered scans, cross-scan `LSE1`/zero-reset/per-scan `NEAR`, inter-scan `COM`/`DRI=0`) + 7 negative streams across all 3 backends & CharLS Wasm where applicable.
  - **M2 Synthetic Matrix & CI Golden** (`scripts/test_m2.py`: 388 positive + 18 variants + 7 invalid encodes + 6 Native PGM; `scripts/verify_m2_golden.mjs` in CI: 12 + 18 + 7 + 4) plus **640 full-range NEAR matrix** (`scripts/validate.py --near-matrix`). [M3-A Acceptance Summary](../reports/t87-m3a-20261125/README.md)

应用层物理预算限定为无符号整数、Pt=0、无映射和无特殊 NoData。v1 支持单分量。v2 支持 2–4 分量同宽高、H=V=1 和共同 P/MAXVAL。浏览器缓冲交换上限 4 MiB。支持文件输出的浏览器可流式交换单分量 P5 PGM，单文件上限 128 MiB。独立 Native 路径分别限制文件大小、总样本、暂存磁盘和内存块。标准编码域与用户声明的物理标度分别记录。[栅格交换](RASTER_EXCHANGE.md)
