# Browser workbench

Build the artifacts and serve the static release tree from the repository root. The server is only for loading local application assets.

```powershell
node sdk/build.mjs
node web/build.mjs
python -m http.server 8000 --bind 127.0.0.1 --directory web/dist
```

Open [the local workbench](http://127.0.0.1:8000/web/). Load the seeded 16-bit sample or choose a binary PGM with MAXVAL in 1–65535. A PGM run encodes and decodes the actual byte stream in two Workers. The decoder requests encoded data one chunk at a time. The page compares every reconstructed sample with its original integer value using a 64 KiB reference window. A row too wide for that window uses a direct read. An uploaded `.jls` is decoded to binary PGM with its effective MAXVAL and big-endian two-byte samples when MAXVAL is at least 256. JLS-only decoding checks stream termination and displays “Not compared” for the original-sample error.

The Precision view exposes resolved P, MAXVAL, NEAR, T1, T2, T3 and RESET. PGM derives the smallest coded precision that holds its MAXVAL with a minimum of two bits. A bounded header read sets the NEAR menu to `0..min(255, floor(MAXVAL / 2))`. Advanced settings allow LSE threshold and RESET overrides. Standalone decode uses the codestream parameters. Raw/JLS divides PGM raster bytes by the measured JPEG-LS byte count.

The image display retains a maximum of 480 × 320 sampled positions. Click an image pixel or focus the preview and use the arrow keys to see its source coordinate and integer values. The magnifier shows the 7 × 7 neighborhood on this sampled grid, and the heat colors map the absolute sample errors relative to NEAR.

During a round trip, the workbench awaits the output sink and updates the optional archive digest before transferring an owned, whole encoded chunk to the decode Worker. Split or non-owning chunks use copies. The relay accepts one outstanding chunk and holds its acknowledgement until the decoder requests the final byte. [Chrome buffer and latency measurements](../reports/worker-relay-20261202/README.md)

The Streaming view shows actual staging and sink bytes, first-row time, acknowledgements and logical queue peaks. Compatibility displays the build revision, fixed source links, and the support scope. The verification report uses the same build metadata. The conformance table reads archived independent evidence. In-page comparison measures the current run.

The stable workbench URL loads each build from its own `builds/<buildId>/` directory. That directory includes the app, CSS, Worker, both codecs, and their build metadata. If an already open workbench loses access to its build after a deployment, a new run can fail until the page is reloaded. The report's `assetBinding` records the versioned path and the availability of matching metadata. Browser reports record asset integrity as `not_run`. The separate Chrome deployment smoke compares actual response hashes against the build manifest across a switch from A to B.

Multi-component raw downloads use SOF plane order. Their reports record sample width, little-endian order and offsets in samples. For embedded one-byte mapping, the preview and downloads show mapped output values. NEAR applies to the coding-domain indices.

Rows are provisional until the final checks and output close finish. The in-page processing timer starts after opening the sink and includes validation and output close. The first Canvas timestamp records the return of the first reconstruction drawing call. File and save-location selection and sink setup are outside the processing timer.

Choose bounded verification to discard the output after acknowledgement. This keeps the file reader, codec sessions, relay and previews bounded independently of height. Buffered download retains at most 64 MiB of output payload and materializes a Blob for normal downloads. Blob and runtime overhead can exceed that payload. Stream to a file is available only when the browser exposes `showSaveFilePicker`, and each write is awaited. The native CLI also supports file and pipe streaming.

The browser's buffered physical-budget exchange keeps a separate 4 MiB cap. On browsers exposing the save-file picker, the single-component P5 exchange can also stream to a file, with 128 MiB caps on the input, JLS and canonical U16LE reconstruction. The browser hashes bounded PGM reads, accepted writes and canonical rows incrementally. It offers the sidecar and report once the strict sample comparison and file writer close succeed. For independent recovery, use `exchange.py restore` against the saved filename and optionally the original. The browser report distinguishes write acknowledgement and close from on-disk readback. [Browser file exchange receipt](../reports/overnight-20261201/G5.md)

The workbench also links to the independent Native and Python workflow for larger, known-height P5 or U16 RAW files. That workflow uses row buffers and bounded temporary disk staging. Native ILV=1/2 `encode-planar` uses bounded positioned raw windows and output batches for regular files. Stdin and FIFOs can use explicit budgeted disk staging to bound RAM. [Large raster commands](../examples/raster-stream/README.md) · [Native spool measurements](../reports/overnight-20261201/G1.md)

Select **Synthetic planes · Physical budgets** to verify the three-component mixed-scan example. The first two components request limits 2 and 3 and share NEAR 2. The third component has its own lossless scan. Switch channels for the corresponding heatmap, legend and exact physical point values. The original planes, JLS, v2 sidecar and report are downloadable after the strict round trip. The archive supplies the exact independent Native recovery command. The sample is synthetic with user-declared calibration. [Multicomponent Native workflow](../examples/raster-stream/README.md#multicomponent-exchange)

Use **Multicomponent physical exchange** for two to four of your own P5 PGM or U16 RAW files. File header values must agree. RAW requires width, height, precision, MAXVAL and an explicit byte order. Component edits stay bound to the selected file. Earlier and Later controls move the entire component in SOF order. A manual plan such as `11,4/2 | 19/0` declares two scans. You can change the calibration or choose another plan, then compare again. Prior results remain labeled with their previous settings and cannot supply current downloads.

The workbench runs one candidate at a time and recommends the smallest JLS among the verified plans. A different verified plan can be selected, rerun and downloaded with its own sidecar and report. Scan limits, input fingerprints, bytes, sample errors and timing scopes are shown in the report. File names and sampled views are presentation fields. Verification covers the original samples. The input files in total, normalized U16 samples, canonical reconstruction and each JLS output have separate 4 MiB limits. The current candidate and one retained result can coexist with up to two sampled preview states. These are logical payloads. Use the Native workflow for larger data. [Limits and Lily reproduction](../reports/user-planes-20261202/README.md)

The UI can be restyled in `style.css` and `index.html`. English and Chinese labels are in `labels.mjs`. File-format, transport, preview and state wiring are in `pgm.mjs`, `transport.mjs`, `preview.mjs` and `app.mjs`. See the [SDK guide](../sdk/README.md) for details of the codec interface.

## Verification report and physical units

Each completed, failed or cancelled job can export [verification report v1](../docs/VERIFICATION_REPORT.md). The workbench recognizes the [pinned NASA LOLA PGM](../tests/fixtures/LUNAR_DATA.md) by SHA-256 and shows codec-added elevation error in metres. Other inputs use integer sample units.

## Browser smoke

With the local server running, install the pinned development-only driver and run the cases from the repository root. Set `MOONJLS_CHROME` to a Chromium-compatible executable path to choose another installed browser. `MOONJLS_WEB_URL` defaults to `http://127.0.0.1:8000`. The test uses Chromium's headless mode and can write a real screenshot via `MOONJLS_SCREENSHOT`.

```powershell
npm.cmd ci --prefix web
$env:MOONJLS_EXPECT_REFERENCE_WINDOW = '1'
node web/smoke.mjs
node web/preview-browser.mjs
node web/capture-presentation.mjs --output .evidence/presentation
```

See the [presentation handoff](../docs/PRESENTATION_HANDOFF.md) for the 90-second operation sequence, controlled output failure tests and paired performance guard.

### Sampled JPEG-LS decode

The Scan Structure Inspector shows the stored sampling factors, real plane sizes, and lines per MCU. The component preview resamples for display. Pixel inspection reports the selected component's coordinates and original-width integer sample values from the decoder.

Sampled images with unequal component sizes export as planar U16LE. Planes follow SOF55 declaration order and contain their actual width × height samples, with rows in raster order. The JSON report lists plane dimensions and sample offsets. The file sink suggests the neutral `.decoded` suffix because it opens before the frame header is parsed. Buffered downloads receive the format-specific suffix. The worker delivers rows incrementally and the browser writes each raw row directly to its plane offset. The host conversion measurement includes one U16LE row, and the buffered sink's retained output is reported separately.

Set `MOONJLS_ANNEX_FIXTURES` to the extracted official Annex E image directory when running `npm run smoke` to check both sampled fixtures against pinned HP 1.00 reconstruction hashes.

### Point transform

Use the Pt field with a PGM or PPM source. The workbench compares right-shifted sample integers against coded NEAR, and compares the original input and reconstructed integers against the original-scale bound. The Scan Structure Inspector and JSON report show both scales. A JLS upload takes Pt from each scan header. A transformed round trip compares exact wide reconstruction against the original. For a JLS upload, select **32-bit little-endian planes** under **Reconstructed samples** to view and export samples above 65,535. The raw output uses the declared component order, real plane dimensions and four bytes per sample. The verification report identifies the storage format and supplies multi-component offsets in samples. PGM and PPM have a maximum storable sample of 65,535. [Netpbm PGM specification](https://netpbm.sourceforge.net/doc/pgm.html)

### Workbench microscopy examples

The workbench includes three planes from a 144 × 111 crop of the Lily of the Valley confocal fluorescence microscopy dataset. The 16-bit P6 fixture keeps the original uint16 counts, which occupy 0–4095 in the source. The 8-bit fixture scales counts from 0–4095 to 0–255 before coding. The channels use neutral labels. The 16-bit preview display range is 0–4095 and the inspector reports the original integer count.

Select ILV 0, 1, or 2 to compare processing one plane per scan, alternating component rows, or alternating samples at every pixel. The workbench compares each reconstructed sample with its source. The report keeps independent-reference status separate from the live comparison. A bundled sampled JLS decodes to planes of 144 × 111, 144 × 28, and 72 × 56. The scan inspector shows one coded padding row for the first component. This decode-only run checks stream termination and reports the number of samples without an original comparison.

The microscopy image was acquired by Genevieve Buckley at Monash Micro Imaging in 2018 and distributed under CC0 by scikit-image. [Dataset record](https://scikit-image.org/docs/0.26.0/api/skimage.data.html#skimage.data.lily) · [Pinned TIFF](https://gitlab.com/scikit-image/data/-/blob/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/lily-of-the-valley-fluorescence.tif)

Run `node sdk/build.mjs` and `python web/samples/extract_lily.py PATH_TO_TIFF` with Pillow and NumPy to regenerate the three fixtures. The script checks the TIFF SHA-256 before cropping. Zero-based crop origin is (395,344), and components are TIFF pages 0, 1, and 2.

| Fixture | SHA-256 |
| --- | --- |
| `lily-8.ppm` | `d0c1829a05f81a996edaf2d55f17599f0164fe9adb4c11c5c18ea58bf06f30a9` |
| `lily-16.ppm` | `364565515c9623b242a02f92ce3dd6057fff898309c00acf6b9334cbca088239` |
| `lily-sampled.jls` | `5d07ba5cb525ec4d89998275e562fb992102314ae4603eac477c0dc23e82224c` |

For a PGM workflow with an exact physical error budget, actual sidecar downloads, and independent file recovery, see the [raster exchange guide](../docs/RASTER_EXCHANGE.md) and [browser receipts](../reports/raster-exchange-20261201/README.md).
