Skip to content

M-Film: film simulation for Canon EOS cameras with Magic Lantern. 72 film stocks (Portra, Velvia, Tri-X, CineStill…), a film-camera interface and an in-camera darkroom that develops your RAWs. 5D Mark III, 6D, 600D, 650D, 700D, EOS M and more.

M-Film 0.1.0

HNGSeries60c1d5759642
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..6079fd6
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,7 @@
+# shell scripts run inside WSL: keep LF line endings
+*.sh text eol=lf
+*.py text eol=lf
+*.c text eol=lf
+*.h text eol=lf
+*.patch text eol=lf
+Makefile text eol=lf
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..44a4b09
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+custom: ["https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02"]
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..6efae6a
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,17 @@
+---
+name: Camera or program doesn't work
+about: The camera isn't found, a roll won't develop, something looks wrong
+labels: bug
+---
+
+**What happened**
+
+**Your computer** (Windows 10/11, macOS version, Intel or Apple silicon)
+
+**Camera connected how** (USB cable / card in a reader / folder)
+
+**Details**: in the program click the gear icon, then *What does the computer see?*, and paste everything it shows here:
+
+```
+(paste here)
+```
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..a921c24
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Buy the developer a coffee
+ url: https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02
+ about: The camera side is free. If it is useful to you, this is how to say thanks.
diff --git a/.github/workflows/camera.yml b/.github/workflows/camera.yml
new file mode 100644
index 0000000..8c83f66
--- /dev/null
+++ b/.github/workflows/camera.yml
@@ -0,0 +1,86 @@
+name: M-Film camera
+
+# Builds the camera files (Magic Lantern + Film OS) for every camera in ml-dev/cameras.txt
+# that is "working" or "testing". (Darkrooms, the desktop program, is built in its own repository.)
+# git tag v0.1.0 && git push origin v0.1.0 builds and publishes the zips under Releases
+# (the tag must match the VERSION file)
+# Actions > "M-Film camera" > Run workflow builds and keeps the zips as artifacts; with a
+# tag in the box it publishes them as well
+on:
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "Release tag to publish the builds under (leave empty to only build)"
+ required: false
+ default: ""
+ push:
+ tags: ["v*"]
+ branches: ["main"]
+ paths: ["ml-dev/**", "VERSION", ".github/workflows/camera.yml"]
+ pull_request:
+ paths: ["ml-dev/**", "VERSION", ".github/workflows/camera.yml"]
+
+permissions:
+ contents: write
+
+jobs:
+ camera:
+ strategy:
+ fail-fast: false
+ matrix:
+ platform: [EOSM.202, 100D.101, 650D.104, 700D.115, 6D.116, 70D.112, 5D3.113, 5D3.123, 550D.109, 600D.102, 60D.111, 1100D.105, 500D.111, 50D.109, 5D2.212] # from ml-dev/cameras.txt
+ runs-on: ubuntu-24.04
+ name: camera ${{ matrix.platform }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.11" # ML's module build still imports distutils (gone in 3.12)
+ - name: Toolchain and Magic Lantern (the commit the fork is made against)
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y -qq gcc-arm-none-eabi binutils-arm-none-eabi zip
+ python -m pip install -q numpy scipy pillow segno docutils
+ git clone -q --filter=blob:none https://github.com/reticulatedpines/magiclantern_simplified.git "$HOME/ml/magiclantern_simplified"
+ git -C "$HOME/ml/magiclantern_simplified" checkout -q ed3e7c0dfacfdeaf3349dee73edf9e3621217462
+ arm-none-eabi-gcc --version | head -1
+ - name: Build
+ run: bash ml-dev/build_fork.sh ${{ matrix.platform }}
+ - name: Zip
+ run: |
+ p=${{ matrix.platform }}
+ if [ "$p" = EOSM.202 ]; then d=ml-dev/out/fork; else d=ml-dev/out/fork-$p; fi
+ cp ml-dev/CAMERA-README.txt "$d/M-FILM-README.txt"
+ (cd "$d" && zip -qr "$GITHUB_WORKSPACE/M-Film-camera-$p.zip" .)
+ ls -la M-Film-camera-$p.zip
+ - uses: actions/upload-artifact@v4
+ with:
+ name: M-Film-camera-${{ matrix.platform }}
+ path: M-Film-camera-${{ matrix.platform }}.zip
+ if-no-files-found: error
+
+ release:
+ needs: [camera]
+ if: ${{ startsWith(github.ref, 'refs/tags/v') || inputs.tag != '' }}
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - name: The tag is the VERSION file's
+ run: |
+ tag="${{ inputs.tag || github.ref_name }}"
+ want="v$(tr -d ' \r\n' < VERSION)"
+ [ "$tag" = "$want" ] || { echo "tag $tag but VERSION says $want: change one of them"; exit 1; }
+ - uses: actions/download-artifact@v4
+ with:
+ path: zips
+ merge-multiple: true
+ - uses: softprops/action-gh-release@v2
+ with:
+ tag_name: ${{ inputs.tag || github.ref_name }}
+ name: M-Film ${{ inputs.tag || github.ref_name }}
+ target_commitish: ${{ github.sha }}
+ files: zips/*.zip
+ body: |
+ **On the camera** (`M-Film-camera-<camera>.zip`): the Film OS with Magic Lantern. Unzip it onto the card
+ and run *Firmware ver.* → update once (see M-FILM-README.txt in the zip). The EOS M build is tried on
+ the camera; the others build but nobody has tried them yet: see TESTING.md before you put one on your camera.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b88a112
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+# Canon firmware files (Canon's copyright, not ours to publish)
+firmware/
+
+# photos: test RAWs and developed rolls
+Pic Test/
+out/
+*.CR2
+*.cr2
+# except the photo the shelf shows developed with every film (PLAY on the shelf)
+!ml-dev/films/sample/SAMPLE.CR2
+
+# Python
+.venv/
+__pycache__/
+
+# ML build outputs, card backups and logs (rebuilt by ml-dev/build_*.sh)
+ml-dev/out/
+ml-dev/card_backup/
+ml-dev/*.log
+
+# film OS simulator output (frames, previews)
+ml-dev/filmos/sim/out/
+
+# film LUTs are usually licensed: keep them out of the repo
+ml-dev/films/luts/*.cube
+ml-dev/films/luts/filmluts/
+
diff --git a/FILMS.md b/FILMS.md
new file mode 100644
index 0000000..ba2622a
--- /dev/null
+++ b/FILMS.md
@@ -0,0 +1,53 @@
+# One photo, 72 films
+
+The same RAW from a Canon EOS M, developed by M-Film with every film it knows (half resolution here,
+downsized for the page). Colour from [Film-Luts](https://github.com/YahiaAngelo/Film-Luts) where the film has a LUT, from
+M-Film's own model otherwise; grain, halation and softness are modelled per film.
+
+[← back](README.md) · [ภาษาไทย](README.th.md)
+
+## Colour negative · 25
+
+<table>
+<tr><td width="33%"><a href="docs/films/portra400.jpg"><img src="docs/films/portra400.jpg" alt="Kodak Portra 400"></a><br><b>Kodak Portra 400</b><br><sub>ISO 400 · C-41 · Soft warm skin, gentle highlights</sub></td><td width="33%"><a href="docs/films/ektar100.jpg"><img src="docs/films/ektar100.jpg" alt="Kodak Ektar 100"></a><br><b>Kodak Ektar 100</b><br><sub>ISO 100 · C-41 · Punchy colour, ultra fine grain</sub></td><td width="33%"><a href="docs/films/gold200.jpg"><img src="docs/films/gold200.jpg" alt="Kodak Gold 200"></a><br><b>Kodak Gold 200</b><br><sub>ISO 200 · C-41 · Golden hour, all day long</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/superia400.jpg"><img src="docs/films/superia400.jpg" alt="Fujicolor Superia 400"></a><br><b>Fujicolor Superia 400</b><br><sub>ISO 400 · C-41 · Green shadows, everyday snaps</sub></td><td width="33%"><a href="docs/films/portra160.jpg"><img src="docs/films/portra160.jpg" alt="Kodak Portra 160"></a><br><b>Kodak Portra 160</b><br><sub>ISO 160 · C-41 · Fine grain, natural skin tones</sub></td><td width="33%"><a href="docs/films/portra800.jpg"><img src="docs/films/portra800.jpg" alt="Kodak Portra 800"></a><br><b>Kodak Portra 800</b><br><sub>ISO 800 · C-41 · Low light portraits, warm grain</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/portra160nc.jpg"><img src="docs/films/portra160nc.jpg" alt="Kodak Portra 160NC"></a><br><b>Kodak Portra 160NC</b><br><sub>ISO 160 · C-41 · Natural colour, soft contrast</sub></td><td width="33%"><a href="docs/films/portra160vc.jpg"><img src="docs/films/portra160vc.jpg" alt="Kodak Portra 160VC"></a><br><b>Kodak Portra 160VC</b><br><sub>ISO 160 · C-41 · Vivid colour for portraits</sub></td><td width="33%"><a href="docs/films/portra400nc.jpg"><img src="docs/films/portra400nc.jpg" alt="Kodak Portra 400NC"></a><br><b>Kodak Portra 400NC</b><br><sub>ISO 400 · C-41 · Neutral skin, quiet colour</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/portra400vc.jpg"><img src="docs/films/portra400vc.jpg" alt="Kodak Portra 400VC"></a><br><b>Kodak Portra 400VC</b><br><sub>ISO 400 · C-41 · More colour, same skin tones</sub></td><td width="33%"><a href="docs/films/portra400uc.jpg"><img src="docs/films/portra400uc.jpg" alt="Kodak Portra 400UC"></a><br><b>Kodak Portra 400UC</b><br><sub>ISO 400 · C-41 · Ultra colour, punchy everyday</sub></td><td width="33%"><a href="docs/films/elite200.jpg"><img src="docs/films/elite200.jpg" alt="Kodak Elite Color 200"></a><br><b>Kodak Elite Color 200</b><br><sub>ISO 200 · C-41 · Bright consumer colour</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/elite400.jpg"><img src="docs/films/elite400.jpg" alt="Kodak Elite Color 400"></a><br><b>Kodak Elite Color 400</b><br><sub>ISO 400 · C-41 · Everyday colour, more speed</sub></td><td width="33%"><a href="docs/films/pro160c.jpg"><img src="docs/films/pro160c.jpg" alt="Fujifilm Pro 160C"></a><br><b>Fujifilm Pro 160C</b><br><sub>ISO 160 · C-41 · Crisp colour, cool and clean</sub></td><td width="33%"><a href="docs/films/pro400h.jpg"><img src="docs/films/pro400h.jpg" alt="Fujifilm Pro 400H"></a><br><b>Fujifilm Pro 400H</b><br><sub>ISO 400 · C-41 · Airy pastels, fourth colour layer</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/pro800z.jpg"><img src="docs/films/pro800z.jpg" alt="Fujifilm Pro 800Z"></a><br><b>Fujifilm Pro 800Z</b><br><sub>ISO 800 · C-41 · Night portraits, soft palette</sub></td><td width="33%"><a href="docs/films/reala100.jpg"><img src="docs/films/reala100.jpg" alt="Fujifilm Reala 100"></a><br><b>Fujifilm Reala 100</b><br><sub>ISO 100 · C-41 · True-to-life colour, fine grain</sub></td><td width="33%"><a href="docs/films/superia100.jpg"><img src="docs/films/superia100.jpg" alt="Fujifilm Superia 100"></a><br><b>Fujifilm Superia 100</b><br><sub>ISO 100 · C-41 · Clean daylight colour</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/superia200.jpg"><img src="docs/films/superia200.jpg" alt="Fujifilm Superia 200"></a><br><b>Fujifilm Superia 200</b><br><sub>ISO 200 · C-41 · Fuji greens, everyday snaps</sub></td><td width="33%"><a href="docs/films/superia800.jpg"><img src="docs/films/superia800.jpg" alt="Fujifilm Superia 800"></a><br><b>Fujifilm Superia 800</b><br><sub>ISO 800 · C-41 · Indoor speed, Fuji colour</sub></td><td width="33%"><a href="docs/films/superia1600.jpg"><img src="docs/films/superia1600.jpg" alt="Fujifilm Superia 1600"></a><br><b>Fujifilm Superia 1600</b><br><sub>ISO 1600 · C-41 · Night snaps, bold grain</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/xtra800.jpg"><img src="docs/films/xtra800.jpg" alt="Fujifilm X-TRA 800"></a><br><b>Fujifilm X-TRA 800</b><br><sub>ISO 800 · C-41 · Fast all-rounder, cool shadows</sub></td><td width="33%"><a href="docs/films/vista200.jpg"><img src="docs/films/vista200.jpg" alt="Agfa Vista 200"></a><br><b>Agfa Vista 200</b><br><sub>ISO 200 · C-41 · Warm reds, holiday colour</sub></td><td width="33%"><a href="docs/films/ultra100.jpg"><img src="docs/films/ultra100.jpg" alt="Agfa Ultra 100"></a><br><b>Agfa Ultra 100</b><br><sub>ISO 100 · C-41 · Saturated, punchy Agfa colour</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/redscale100.jpg"><img src="docs/films/redscale100.jpg" alt="Lomography Redscale 100"></a><br><b>Lomography Redscale 100</b><br><sub>ISO 100 · C-41 · Shot through the back: red-orange</sub></td></tr>
+</table>
+
+## Slide and cross-processed · 19
+
+<table>
+<tr><td width="33%"><a href="docs/films/velvia50.jpg"><img src="docs/films/velvia50.jpg" alt="Fujichrome Velvia 50"></a><br><b>Fujichrome Velvia 50</b><br><sub>ISO 50 · E-6 · Vivid slide film, hard contrast</sub></td><td width="33%"><a href="docs/films/velvia100.jpg"><img src="docs/films/velvia100.jpg" alt="Fujifilm Velvia 100"></a><br><b>Fujifilm Velvia 100</b><br><sub>ISO 100 · E-6 · Rich colour, softer than the 50</sub></td><td width="33%"><a href="docs/films/provia100f.jpg"><img src="docs/films/provia100f.jpg" alt="Fujifilm Provia 100F"></a><br><b>Fujifilm Provia 100F</b><br><sub>ISO 100 · E-6 · Neutral slide, faithful colour</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/provia400f.jpg"><img src="docs/films/provia400f.jpg" alt="Fujifilm Provia 400F"></a><br><b>Fujifilm Provia 400F</b><br><sub>ISO 400 · E-6 · Fast slide, clean colour</sub></td><td width="33%"><a href="docs/films/provia400x.jpg"><img src="docs/films/provia400x.jpg" alt="Fujifilm Provia 400X"></a><br><b>Fujifilm Provia 400X</b><br><sub>ISO 400 · E-6 · Fast slide, finer grain</sub></td><td width="33%"><a href="docs/films/astia100f.jpg"><img src="docs/films/astia100f.jpg" alt="Fujifilm Astia 100F"></a><br><b>Fujifilm Astia 100F</b><br><sub>ISO 100 · E-6 · Soft slide film for skin</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/sensia100.jpg"><img src="docs/films/sensia100.jpg" alt="Fujifilm Sensia 100"></a><br><b>Fujifilm Sensia 100</b><br><sub>ISO 100 · E-6 · Bright consumer slide</sub></td><td width="33%"><a href="docs/films/kodachrome25.jpg"><img src="docs/films/kodachrome25.jpg" alt="Kodak Kodachrome 25"></a><br><b>Kodak Kodachrome 25</b><br><sub>ISO 25 · K-14 · Legendary fine grain, deep reds</sub></td><td width="33%"><a href="docs/films/kodachrome64.jpg"><img src="docs/films/kodachrome64.jpg" alt="Kodak Kodachrome 64"></a><br><b>Kodak Kodachrome 64</b><br><sub>ISO 64 · K-14 · Magazine colour of the 70s</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/kodachrome200.jpg"><img src="docs/films/kodachrome200.jpg" alt="Kodak Kodachrome 200"></a><br><b>Kodak Kodachrome 200</b><br><sub>ISO 200 · K-14 · Faster Kodachrome, warm grain</sub></td><td width="33%"><a href="docs/films/e100gx.jpg"><img src="docs/films/e100gx.jpg" alt="Kodak Ektachrome E100GX"></a><br><b>Kodak Ektachrome E100GX</b><br><sub>ISO 100 · E-6 · Warm, gentle Ektachrome</sub></td><td width="33%"><a href="docs/films/e100vs.jpg"><img src="docs/films/e100vs.jpg" alt="Kodak Ektachrome E100VS"></a><br><b>Kodak Ektachrome E100VS</b><br><sub>ISO 100 · E-6 · Very saturated Ektachrome</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/elitechrome200.jpg"><img src="docs/films/elitechrome200.jpg" alt="Kodak Elite Chrome 200"></a><br><b>Kodak Elite Chrome 200</b><br><sub>ISO 200 · E-6 · Everyday Kodak slide</sub></td><td width="33%"><a href="docs/films/elitechrome400.jpg"><img src="docs/films/elitechrome400.jpg" alt="Kodak Elite Chrome 400"></a><br><b>Kodak Elite Chrome 400</b><br><sub>ISO 400 · E-6 · Fast Kodak slide, more grain</sub></td><td width="33%"><a href="docs/films/extracolor100.jpg"><img src="docs/films/extracolor100.jpg" alt="Kodak ExtraColor 100"></a><br><b>Kodak ExtraColor 100</b><br><sub>ISO 100 · E-6 · Extra saturated Kodak slide</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/precisa100.jpg"><img src="docs/films/precisa100.jpg" alt="Agfa Precisa 100"></a><br><b>Agfa Precisa 100</b><br><sub>ISO 100 · E-6 · Cool, crisp Agfa slide</sub></td><td width="33%"><a href="docs/films/elite100xpro.jpg"><img src="docs/films/elite100xpro.jpg" alt="Kodak Elite 100 X-Pro"></a><br><b>Kodak Elite 100 X-Pro</b><br><sub>ISO 100 · X-PRO · Slide in C-41: wild contrast</sub></td><td width="33%"><a href="docs/films/superia200xpro.jpg"><img src="docs/films/superia200xpro.jpg" alt="Fujifilm Superia 200 X-Pro"></a><br><b>Fujifilm Superia 200 X-Pro</b><br><sub>ISO 200 · X-PRO · Cross-processed, yellow highlights</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/xproslide200.jpg"><img src="docs/films/xproslide200.jpg" alt="Lomography X-Pro Slide 200"></a><br><b>Lomography X-Pro Slide 200</b><br><sub>ISO 200 · X-PRO · Cross-process blues and yellows</sub></td></tr>
+</table>
+
+## Black and white · 22
+
+<table>
+<tr><td width="33%"><a href="docs/films/hp5.jpg"><img src="docs/films/hp5.jpg" alt="Ilford HP5 Plus 400"></a><br><b>Ilford HP5 Plus 400</b><br><sub>ISO 400 · B&W · Classic B&W, forgiving latitude</sub></td><td width="33%"><a href="docs/films/trix400.jpg"><img src="docs/films/trix400.jpg" alt="Kodak Tri-X 400"></a><br><b>Kodak Tri-X 400</b><br><sub>ISO 400 · B&W · Gritty contrast, street classic</sub></td><td width="33%"><a href="docs/films/tmax100.jpg"><img src="docs/films/tmax100.jpg" alt="Kodak T-MAX 100"></a><br><b>Kodak T-MAX 100</b><br><sub>ISO 100 · B&W · Ultra fine grain, smooth tones</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/tmax400.jpg"><img src="docs/films/tmax400.jpg" alt="Kodak T-MAX 400"></a><br><b>Kodak T-MAX 400</b><br><sub>ISO 400 · B&W · Sharp, modern B&W</sub></td><td width="33%"><a href="docs/films/tmax3200.jpg"><img src="docs/films/tmax3200.jpg" alt="Kodak T-MAX P3200"></a><br><b>Kodak T-MAX P3200</b><br><sub>ISO 3200 · B&W · Push-ready, grainy nights</sub></td><td width="33%"><a href="docs/films/bw400cn.jpg"><img src="docs/films/bw400cn.jpg" alt="Kodak BW400CN"></a><br><b>Kodak BW400CN</b><br><sub>ISO 400 · C-41 · Chromogenic B&W, smooth grain</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/hie.jpg"><img src="docs/films/hie.jpg" alt="Kodak HIE Infrared"></a><br><b>Kodak HIE Infrared</b><br><sub>ISO 400 · B&W · Infrared: white leaves, dark skies</sub></td><td width="33%"><a href="docs/films/delta100.jpg"><img src="docs/films/delta100.jpg" alt="Ilford Delta 100"></a><br><b>Ilford Delta 100</b><br><sub>ISO 100 · B&W · Fine, sharp modern B&W</sub></td><td width="33%"><a href="docs/films/delta400.jpg"><img src="docs/films/delta400.jpg" alt="Ilford Delta 400"></a><br><b>Ilford Delta 400</b><br><sub>ISO 400 · B&W · Smooth grain at 400</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/delta3200.jpg"><img src="docs/films/delta3200.jpg" alt="Ilford Delta 3200"></a><br><b>Ilford Delta 3200</b><br><sub>ISO 3200 · B&W · Pushes into the dark</sub></td><td width="33%"><a href="docs/films/fp4.jpg"><img src="docs/films/fp4.jpg" alt="Ilford FP4 Plus"></a><br><b>Ilford FP4 Plus</b><br><sub>ISO 125 · B&W · Classic medium speed B&W</sub></td><td width="33%"><a href="docs/films/panf50.jpg"><img src="docs/films/panf50.jpg" alt="Ilford Pan F Plus"></a><br><b>Ilford Pan F Plus</b><br><sub>ISO 50 · B&W · Slow, super fine grain</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/hps800.jpg"><img src="docs/films/hps800.jpg" alt="Ilford HPS 800"></a><br><b>Ilford HPS 800</b><br><sub>ISO 800 · B&W · Fast classic Ilford</sub></td><td width="33%"><a href="docs/films/xp2.jpg"><img src="docs/films/xp2.jpg" alt="Ilford XP2 Super"></a><br><b>Ilford XP2 Super</b><br><sub>ISO 400 · C-41 · C-41 B&W, smooth tones</sub></td><td width="33%"><a href="docs/films/acros100.jpg"><img src="docs/films/acros100.jpg" alt="Fujifilm Acros 100"></a><br><b>Fujifilm Acros 100</b><br><sub>ISO 100 · B&W · Fine grain, deep blacks</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/neopan1600.jpg"><img src="docs/films/neopan1600.jpg" alt="Fujifilm Neopan 1600"></a><br><b>Fujifilm Neopan 1600</b><br><sub>ISO 1600 · B&W · Fast and contrasty B&W</sub></td><td width="33%"><a href="docs/films/apx25.jpg"><img src="docs/films/apx25.jpg" alt="Agfa APX 25"></a><br><b>Agfa APX 25</b><br><sub>ISO 25 · B&W · Very fine, slow Agfa B&W</sub></td><td width="33%"><a href="docs/films/apx100.jpg"><img src="docs/films/apx100.jpg" alt="Agfa APX 100"></a><br><b>Agfa APX 100</b><br><sub>ISO 100 · B&W · Classic Agfa B&W</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/retro80s.jpg"><img src="docs/films/retro80s.jpg" alt="Rollei Retro 80S"></a><br><b>Rollei Retro 80S</b><br><sub>ISO 80 · B&W · Extended red, dark skies</sub></td><td width="33%"><a href="docs/films/retro100.jpg"><img src="docs/films/retro100.jpg" alt="Rollei Retro 100 Tonal"></a><br><b>Rollei Retro 100 Tonal</b><br><sub>ISO 100 · B&W · Soft tonal B&W</sub></td><td width="33%"><a href="docs/films/ortho25.jpg"><img src="docs/films/ortho25.jpg" alt="Rollei Ortho 25"></a><br><b>Rollei Ortho 25</b><br><sub>ISO 25 · B&W · Orthochromatic: reds go dark</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/ir400.jpg"><img src="docs/films/ir400.jpg" alt="Rollei Infrared 400"></a><br><b>Rollei Infrared 400</b><br><sub>ISO 400 · B&W · Infrared touch, glowing foliage</sub></td></tr>
+</table>
+
+## Cinema · 6
+
+<table>
+<tr><td width="33%"><a href="docs/films/cinestill800t.jpg"><img src="docs/films/cinestill800t.jpg" alt="CineStill 800T"></a><br><b>CineStill 800T</b><br><sub>ISO 800 · C-41 · Tungsten cine film, night goes blue</sub></td><td width="33%"><a href="docs/films/cinestill400t.jpg"><img src="docs/films/cinestill400t.jpg" alt="CineStill 400T"></a><br><b>CineStill 400T</b><br><sub>ISO 400 · C-41 · Your own LUT, cine colour</sub></td><td width="33%"><a href="docs/films/kodak2383.jpg"><img src="docs/films/kodak2383.jpg" alt="Kodak Vision 2383"></a><br><b>Kodak Vision 2383</b><br><sub>ISO 200 · ECP · Cinema print: teal shadows</sub></td></tr>
+<tr><td width="33%"><a href="docs/films/kodak2393.jpg"><img src="docs/films/kodak2393.jpg" alt="Kodak Vision 2393"></a><br><b>Kodak Vision 2393</b><br><sub>ISO 200 · ECP · Cinema print, richer blacks</sub></td><td width="33%"><a href="docs/films/fuji3510.jpg"><img src="docs/films/fuji3510.jpg" alt="Fujifilm Eterna 3510"></a><br><b>Fujifilm Eterna 3510</b><br><sub>ISO 200 · ECP · Fuji print film, soft colour</sub></td><td width="33%"><a href="docs/films/fuji3513.jpg"><img src="docs/films/fuji3513.jpg" alt="Fujifilm Eterna 3513"></a><br><b>Fujifilm Eterna 3513</b><br><sub>ISO 200 · ECP · Fuji print for digital masters</sub></td></tr>
+</table>
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d159169
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/PORTING.md b/PORTING.md
new file mode 100644
index 0000000..067c527
--- /dev/null
+++ b/PORTING.md
@@ -0,0 +1,124 @@
+# Taking M-Film further
+
+How to bring M-Film to another camera, or add films.
+It was made on the **Canon EOS M (firmware 2.0.2)**, the only camera it has been tried on. The camera
+side now *builds* for every DIGIC 4 and 5 camera Magic Lantern supports; see [the list](README.md#cameras)
+and [TESTING.md](TESTING.md).
+
+> ภาษาไทยสั้นๆ: ในกล้อง หน้าจอ Film OS (`ml-dev/filmos/`) แยกจากตัวกล้องผ่านชั้น `fos_port_*` แล้ว ที่ต้องทำใหม่ต่อรุ่นคือ
+> ส่วนที่ต่อกับ Magic Lantern (`ml-dev/fork/`): ปุ่ม, palette จอ, จุดดักเมนู, ขนาดไฟล์ที่กล้องบูตไหว
+> และต้องมีกล้องรุ่นนั้นไว้ทดสอบจริง อ่านต่อด้านล่าง
+
+---
+
+## The parts, and how hard each is to move
+
+| Part | Where | Tied to the EOS M? |
+|---|---|---|
+| Film OS: the screens on the camera | `ml-dev/filmos/` | Little. Talks to the camera only through `fos_port_*`. |
+| The Magic Lantern fork | `ml-dev/fork/`, `ml-dev/build_fork.sh` | Completely. Redone for every camera. |
+
+The desktop program, Darkrooms, is a separate closed-source program and isn't covered here.
+
+### 1. Film OS (moderate)
+
+All of `ml-dev/filmos/fos_*.c` draws into its own 720 × 480, 8-bit canvas and reaches the
+camera only through the functions declared at the end of `fos.h`:
+
+```
+fos_port_ms, fos_port_sleep, fos_port_key, fos_port_abort time, keys
+fos_port_present, fos_port_palette the screen
+fos_port_alloc, fos_port_free memory
+fos_port_open/read/write/seek/close, list, mkdir, card files
+fos_port_roll, get, set, action, clock, lens_*, photo, ... camera state
+```
+
+Two implementations exist: the camera's (`ml-dev/fork/src/filmroll.c`) and the simulator's
+(`ml-dev/filmos/sim/`, runs on a PC and writes PNGs: `make -C ml-dev/filmos/sim`). A new camera
+needs a new `filmroll.c`-like file; the screens stay as they are. Things to check per camera:
+
+- **Screen.** 720 × 480 is Magic Lantern's bitmap size on every camera it supports, so layouts carry
+ over. The palette trick (`palette_ours` / `palette_canon` in `filmroll.c`, 254 colours written into
+ the bitmap overlay's palette as Y/Cb/Cr) works on DIGIC 4 and 5; check that colours look right
+ (System → Screen colour has a test chart).
+- **Keys.** The EOS M has few buttons and a touch screen, so the Film OS uses SET, the four arrows,
+ the wheel, PLAY, MENU, INFO, half-shutter and two-finger touch (`MODULE_KEY_*` in `filmroll.c`).
+ Bodies with a top dial, Q button or joystick should map them; keep half-shutter = "leave".
+- **Memory and size.** The in-camera darkroom (`fos_dev.c`) decodes the CR2 in slices to stay small,
+ and the whole build must stay under what the camera can boot: on the EOS M about 727 KB of ML at
+ boot (`build_fork.sh` checks it; above that the camera hangs with the card light on). Fonts and film
+ data live on the card (`ML/DATA/FOSFONT.BIN`, `FOSFILMS.BIN`) for this reason. Every camera has a
+ different limit: find yours by adding things back until it no longer starts.
+- **The in-camera darkroom** expects the EOS M's CR2 (5280 × 3528 sensor, lossless JPEG in vertical
+ slices, RGGB, black 2048). Other DIGIC 4/5 bodies write the same kind of CR2 but with other sizes,
+ slice layouts and borders: `fos_dev.c` reads them from the file, but test with that camera's RAWs
+ (`ml-dev/filmos/sim/devtest.c` develops a CR2 on the PC exactly as the camera would).
+
+### 2. The Magic Lantern fork (hard, per camera)
+
+Magic Lantern itself is built per camera and firmware (`platform/<CAMERA>.<FW>/`). The fork changes,
+all in `ml-dev/fork/apply_fork.py` (applied to a `magiclantern_simplified` checkout):
+
+1. `src/gui-common.c`: our key handler runs before the modules' (`handle_filmroll_keys`).
+2. `src/zebra.c`: ML's LiveView overlays step aside while the Film OS draws (`filmroll_overlays_active`).
+3. `src/menu.c`: the ML menu never opens; anything asking for it gets the Film OS home
+ (`filmroll_menu_requested`).
+4. `platform/EOSM.202/features.h`: `#define FEATURE_FILMROLL`.
+5. `platform/EOSM.202/Makefile`: our objects (`filmroll.o fos_*.o`).
+6. `modules/Makefile`: lua left out (didn't build with the toolchain used).
+
+4 to 6 are per camera: `apply_fork.py SRC <platform> ...` does them for any platform, and
+`build_fork.sh <platform>` builds one (`ml-dev/out/fork-<platform>/`). What is already done for the
+other cameras:
+
+- **Shooting screen.** On the EOS M the Film OS opens from LiveView; on a DSLR also from Canon's
+ shooting screen with LiveView off (`shooting_screen()` in `filmroll.c`, `FOS_LV_ONLY`).
+- **Sensor colours.** `fos_dev.c` picks the camera's matrix and white level by `CONFIG_<camera>`
+ (from LibRaw's `colordata.cpp`); the decoder is checked on every sensor size
+ (`mkcr2 --sensor W,H,LEFT,TOP` makes a RAW of that size, `devtest` decodes it: 0 samples wrong on all).
+- **The camera's name** in About and in the prints' EXIF comes from ML (`fos_port_model()`).
+
+Still unknown on each, and only a camera can tell: whether it boots with a build this size, how the
+palette looks, which keys arrive, and whether the darkroom has the memory it needs.
+
+### Adding a camera to the list
+
+1. Add or change its line in `ml-dev/cameras.txt` (status `testing` once it builds, `working` once
+ someone has tried it; the boot limit when you know it).
+2. `python3 ml-dev/tools/cameras.py` rewrites the tables in README.md, README.th.md and TESTING.md and
+ the cameras CI builds.
+
+## Which cameras are worth trying
+
+All the DIGIC 4 and 5 cameras build already ([the list](README.md#cameras)); what they need is someone
+with the camera. The closest to the EOS M are the **100D, 650D and 700D**: the same sensor, the same
+DIGIC 5. DIGIC 6 and later (80D, 200D, EOS R …) wait for Magic Lantern itself, and the 7D doesn't build
+in Magic Lantern's current source.
+
+## How to go about a port
+
+1. **Own the camera.** Every step needs trying on the body: there is no emulator that runs this.
+ Keep a spare card with plain Magic Lantern (or none) to go back to.
+2. Build stock Magic Lantern for it and boot it. Note how big the boot image is.
+3. Add only `FEATURE_FILMROLL` with a tiny `filmroll.c` that draws one Film OS screen. Check colours
+ and that it starts.
+4. Map keys; get the shelf and Home working. Then the roll, the HUD, the film count.
+5. Watch the boot size at every step. Leave the darkroom (`fos_dev.c`, `fos_dark.c`) for last.
+6. Keep the debug log on (`filmroll.debug`, on by default; it writes `ML/FILMROLL.LOG` on the card)
+ and read it after each try.
+7. Put camera-specific code behind `#ifdef CONFIG_<CAMERA>` or in its own port file, so the
+ EOS M keeps building. Send a pull request with what you tested and on which firmware.
+
+## Adding a film
+
+- Its look: `ml-dev/films/films.py` (a model: curves, colour, grain, halation), or a LUT listed in
+ `ml-dev/films/filmluts.py`.
+- Its canister label: `ml-dev/filmos/tools/catalog.py`; regenerate with `tools/genfilms.py`.
+- Rebuild: the camera gets it in `ML/DATA/FOSFILMS.BIN`.
+
+## Ground rules
+
+- Magic Lantern can brick nothing permanently, but a bad build can leave the camera hanging at
+ power on: take the battery out, put the old card back. Say so to people you hand builds to.
+- Never commit Canon firmware, film LUTs you don't have the right to share, or other people's photos.
+- The camera side is GPL-2.0 (from Magic Lantern); keep forks open.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bacd114
--- /dev/null
+++ b/README.md
@@ -0,0 +1,211 @@
+<div align="center">
+
+<img src="docs/images/mfilm.png" width="112" alt="M-Film">
+
+# M-Film
+
+**Your Canon, shot like film.**
+
+A film camera's interface for Canon cameras that run Magic Lantern.<br>
+Load a roll from a shelf of 72 film stocks, shoot without looking at the screen, then develop the roll: in the camera, or on your computer with **Darkrooms**.<br>
+The camera side is free and open, for everyone.
+
+[![Download](https://img.shields.io/badge/Download-eca834?style=for-the-badge)](../../releases/latest)
+[![Buy the developer a coffee](https://img.shields.io/badge/Buy%20the%20developer%20a%20coffee-ffdd00?style=for-the-badge&logo=buymeacoffee&logoColor=black)](https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02)
+
+[![License GPL-2.0](https://img.shields.io/badge/license-GPL--2.0-3b352f)](LICENSE)
+[![Cameras](https://img.shields.io/badge/cameras-1%20works%20%C2%B7%2014%20in%20testing-3b352f)](#cameras)
+[![Films](https://img.shields.io/badge/films-72-3b352f)](FILMS.md)
+
+**English** · [ภาษาไทย](README.th.md) · [Films](#72-films) · [Cameras](#cameras) · [Darkrooms](#develop-on-your-computer-darkrooms) · [Take it further](PORTING.md)
+
+<br>
+
+<img src="ml-dev/filmos/preview/shelf.gif" alt="The film shelf in the camera" width="720">
+
+</div>
+
+---
+
+## A film camera, inside your camera
+
+M-Film replaces the camera's menus with a film camera drawn from scratch, with Magic Lantern running
+underneath. There is no picture on the screen after each shot and no going back through them: you shoot
+the roll, then develop it and see what you got.
+
+<table>
+<tr>
+<td width="50%"><img src="ml-dev/filmos/preview/shelf.png" alt="The film shelf"></td>
+<td width="50%"><img src="ml-dev/filmos/preview/roll.png" alt="The roll"></td>
+</tr>
+<tr>
+<td><b>Load a roll.</b> A shelf of canisters that turn to face you. Pick one and the leader comes out of it.</td>
+<td><b>Count your frames.</b> A film camera's frame counter, from S to the last frame of the roll, and a rewind.</td>
+</tr>
+<tr>
+<td><img src="ml-dev/filmos/preview/hud.png" alt="Viewfinder HUD"></td>
+<td><img src="ml-dev/filmos/preview/developing.png" alt="Developing in the camera"></td>
+</tr>
+<tr>
+<td><b>Shoot.</b> An SLR viewfinder: aperture scale, light meter needle, red seven-segment frame count.</td>
+<td><b>Develop in the camera.</b> The darkroom develops the finished roll frame by frame, into JPEG folders on the card.</td>
+</tr>
+<tr>
+<td><img src="ml-dev/filmos/preview/prints-sheet.png" alt="Contact sheet"></td>
+<td><img src="ml-dev/filmos/preview/home.png" alt="Home"></td>
+</tr>
+<tr>
+<td><b>See the prints.</b> A contact sheet of the roll, and each print full screen.</td>
+<td><b>Home</b> instead of the camera's menu: the roll you have loaded and everything else.</td>
+</tr>
+</table>
+
+Every RAW is kept, so nothing is lost: you can develop the same roll again with another film later.
+
+---
+
+## 72 films
+
+Colour negative, slide, black and white, and cinema film, on four shelves. Each film has its own colour,
+grain, halation and softness; rolls come in 36, 24 or 12 frames.
+
+<!-- samples: one photo per film in docs/samples/<film>.jpg (3:2) -->
+<table>
+<tr>
+<td width="33%"><img src="docs/samples/portra400.jpg" alt="Kodak Portra 400"><br><b>Kodak Portra 400</b><br><sub>Soft warm skin, gentle highlights</sub></td>
+<td width="33%"><img src="docs/samples/gold200.jpg" alt="Kodak Gold 200"><br><b>Kodak Gold 200</b><br><sub>Golden hour, all day long</sub></td>
+<td width="33%"><img src="docs/samples/ektar100.jpg" alt="Kodak Ektar 100"><br><b>Kodak Ektar 100</b><br><sub>Punchy colour, ultra fine grain</sub></td>
+</tr>
+<tr>
+<td><img src="docs/samples/superia400.jpg" alt="Fujicolor Superia 400"><br><b>Fujicolor Superia 400</b><br><sub>Green shadows, everyday snaps</sub></td>
+<td><img src="docs/samples/velvia50.jpg" alt="Fujichrome Velvia 50"><br><b>Fujichrome Velvia 50</b><br><sub>Vivid slide film, hard contrast</sub></td>
+<td><img src="docs/samples/kodachrome64.jpg" alt="Kodak Kodachrome 64"><br><b>Kodak Kodachrome 64</b><br><sub>Magazine colour of the 70s</sub></td>
+</tr>
+<tr>
+<td><img src="docs/samples/cinestill800t.jpg" alt="CineStill 800T"><br><b>CineStill 800T</b><br><sub>Tungsten cine film, night goes blue</sub></td>
+<td><img src="docs/samples/kodak2383.jpg" alt="Kodak Vision 2383"><br><b>Kodak Vision 2383</b><br><sub>Cinema print: teal shadows</sub></td>
+<td><img src="docs/samples/trix400.jpg" alt="Kodak Tri-X 400"><br><b>Kodak Tri-X 400</b><br><sub>Gritty contrast, street classic</sub></td>
+</tr>
+</table>
+
+**[All 72 films, on the same photo →](FILMS.md)**
+
+Colour for 63 of them comes from the [Film-Luts](https://github.com/YahiaAngelo/Film-Luts) collection; the rest
+from M-Film's own film models ([`ml-dev/films/films.py`](ml-dev/films/films.py)).
+
+---
+
+## Cameras
+
+M-Film was made on the EOS M, where it works. It now builds for every camera on which Magic Lantern
+itself is mature (DIGIC 4 and 5), but those builds **haven't been tried on a camera yet**. If you have
+one of them, you can help: [TESTING.md](TESTING.md) says how (about 20 minutes, and you can always go back).
+
+<!-- cameras:start -->
+| Camera | Canon firmware | Status | Card files |
+|---|---|---|---|
+| Canon EOS M | 2.0.2 | ✅ **Works** | `M-Film-camera-EOSM.202.zip` |
+| Canon EOS 100D / Rebel SL1 / Kiss X7 | 1.0.1 | 🧪 Builds, needs a tester | `M-Film-camera-100D.101.zip` |
+| Canon EOS 650D / Rebel T4i / Kiss X6i | 1.0.4 | 🧪 Builds, needs a tester | `M-Film-camera-650D.104.zip` |
+| Canon EOS 700D / Rebel T5i / Kiss X7i | 1.1.5 | 🧪 Builds, needs a tester | `M-Film-camera-700D.115.zip` |
+| Canon EOS 6D | 1.1.6 | 🧪 Builds, needs a tester | `M-Film-camera-6D.116.zip` |
+| Canon EOS 70D | 1.1.2 | 🧪 Builds, needs a tester | `M-Film-camera-70D.112.zip` |
+| Canon EOS 5D Mark III (firmware 1.1.3) | 1.1.3 | 🧪 Builds, needs a tester | `M-Film-camera-5D3.113.zip` |
+| Canon EOS 5D Mark III (firmware 1.2.3) | 1.2.3 | 🧪 Builds, needs a tester | `M-Film-camera-5D3.123.zip` |
+| Canon EOS 550D / Rebel T2i / Kiss X4 | 1.0.9 | 🧪 Builds, needs a tester | `M-Film-camera-550D.109.zip` |
+| Canon EOS 600D / Rebel T3i / Kiss X5 | 1.0.2 | 🧪 Builds, needs a tester | `M-Film-camera-600D.102.zip` |
+| Canon EOS 60D | 1.1.1 | 🧪 Builds, needs a tester | `M-Film-camera-60D.111.zip` |
+| Canon EOS 1100D / Rebel T3 / Kiss X50 | 1.0.5 | 🧪 Builds, needs a tester | `M-Film-camera-1100D.105.zip` |
+| Canon EOS 500D / Rebel T1i / Kiss X3 | 1.1.1 | 🧪 Builds, needs a tester | `M-Film-camera-500D.111.zip` |
+| Canon EOS 50D | 1.0.9 | 🧪 Builds, needs a tester | `M-Film-camera-50D.109.zip` |
+| Canon EOS 5D Mark II | 2.1.2 | 🧪 Builds, needs a tester | `M-Film-camera-5D2.212.zip` |
+
+**Not yet:** 7D (Magic Lantern's current source doesn't build it) · 200D, 750D, 77D, 80D, 7D Mark II, 5D Mark IV, 5DS R, 6D Mark II, 850D, M50, R, RP, R5, R6, SX70 HS, SX740 HS (Magic Lantern itself is still experimental on these).
+<!-- cameras:end -->
+
+✅ tried on the camera and works · 🧪 builds; waiting for someone to try it. The card files are in each
+[release](../../releases/latest). The list lives in [`ml-dev/cameras.txt`](ml-dev/cameras.txt); porting
+notes in [PORTING.md](PORTING.md).
+
+### Putting it on the camera
+
+1. The camera needs exactly the Canon firmware in the table (MENU → last settings tab → *Firmware ver.*).
+2. Unzip the card files for your camera onto an SD card, put it in the camera and run *Firmware ver.* →
+ update once. From then on M-Film starts with the camera from that card.
+3. Full steps, and how to go back: [TESTING.md](TESTING.md). Building it yourself:
+ `ml-dev/build_fork.sh <camera>`.
+
+---
+
+## Develop on your computer: Darkrooms
+
+The camera develops its rolls by itself, slowly. **Darkrooms** does it on your computer, fast.
+Plug the camera in (or put its card in a reader) and open Darkrooms. It finds the camera, shows every
+roll you shot with its film, and develops them at full resolution.
+
+<table>
+<tr>
+<td width="50%"><img src="docs/images/app-rolls.jpg" alt="Film rolls"></td>
+<td width="50%"><img src="docs/images/app-darkroom.jpg" alt="Developing a roll"></td>
+</tr>
+<tr>
+<td><b>Your rolls</b>, each with its canister and a strip of its frames. Develop whole rolls or pick single frames.</td>
+<td><b>The lights go red.</b> Prints come out of the developer and hang on the line.</td>
+</tr>
+<tr>
+<td><img src="docs/images/app-lights-on.jpg" alt="Lights on: the roll and its contact sheet"></td>
+<td><img src="docs/images/app-develop.jpg" alt="Develop settings"></td>
+</tr>
+<tr>
+<td><b>Lights on.</b> Every roll gets a contact sheet and its own folder.</td>
+<td><b>Full detail.</b> Every pixel of the RAW, JPEG with 4:4:4 colour, EXIF kept, optional date stamp.</td>
+</tr>
+</table>
+
+### Free, or Full
+
+| | Free | Darkrooms Full |
+|---|---|---|
+| Rolls a day | 1 | as many as you like |
+| Every film, full size, EXIF, contact sheets | ✓ | ✓ |
+| Many rolls at once on every core | | ✓ |
+| Price | free | **$5.99 once**, updates included |
+
+The camera's own darkroom stays free and unlimited. Buy Darkrooms Full in the program
+(gear icon → *Get Full*); the licence key arrives by e-mail and works on your computers.
+
+### Download
+
+| Your computer | Get | Open it |
+|---|---|---|
+| **Windows 10 / 11** | `Darkrooms-windows-x64.zip` | Unzip, run `Darkrooms.exe`. If Windows warns: *More info* → *Run anyway*. |
+| **Mac with Intel** | `Darkrooms-macos-intel.zip` | Unzip, drag to Applications, **right-click → Open** the first time. |
+| **Mac with Apple silicon** | `Darkrooms-macos-apple-silicon.zip` | Same. |
+
+From the **[latest release](../../releases/latest)**. About 25–45 MB. The program isn't signed with Apple or
+Microsoft yet, hence the warning the first time.
+
+---
+
+## Take it further
+
+- **Have one of the cameras above?** [TESTING.md](TESTING.md): try it and tell us, so it can move to ✅.
+- **Another camera?** [PORTING.md](PORTING.md) says what moves easily (the Film OS
+ screens), what has to be redone per camera (the Magic Lantern side), and how to go about it.
+- **Every screen and button** of the camera side, and how it works inside (in Thai):
+ [docs/MANUAL.th.md](docs/MANUAL.th.md).
+- **Something broken?** [Open an issue](../../issues/new/choose) and paste what the gear icon →
+ *What does the computer see?* shows.
+- **The films** (looks, LUT list) are in [`ml-dev/films/`](ml-dev/films/); the camera build bakes them in.
+- **Darkrooms**, the desktop program, is closed source and isn't in this repository.
+
+## Support
+
+The camera side of M-Film is free and stays free. If it gave you a roll you like, you can
+**[buy the developer a coffee ☕](https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02)**.
+
+## License
+
+This repository: GPL-2.0 ([LICENSE](LICENSE)), as the camera side builds on Magic Lantern.
+Darkrooms (the desktop program) is a separate, closed-source program under its own licence. Fonts, film LUTs and other
+parts: [THIRD_PARTY.md](THIRD_PARTY.md). Not affiliated with Canon, Kodak, Fujifilm or any film maker.
diff --git a/README.th.md b/README.th.md
new file mode 100644
index 0000000..1effd45
--- /dev/null
+++ b/README.th.md
@@ -0,0 +1,208 @@
+<div align="center">
+
+<img src="docs/images/mfilm.png" width="112" alt="M-Film">
+
+# M-Film
+
+**เปลี่ยนกล้อง Canon ของคุณให้ถ่ายเหมือนกล้องฟิล์ม**
+
+หน้าจอแบบกล้องฟิล์มสำหรับกล้อง Canon ที่ลง Magic Lantern ได้<br>
+เลือกม้วนจากชั้นวางฟิล์ม 72 แบบ ถ่ายโดยไม่เห็นภาพบนจอ แล้วล้างฟิล์มทั้งม้วน ในกล้องเองหรือบนคอมด้วย **Darkrooms**<br>
+ส่วนในกล้องใช้ฟรีและเปิดซอร์สสำหรับทุกคน
+
+[![ดาวน์โหลด](https://img.shields.io/badge/%E0%B8%94%E0%B8%B2%E0%B8%A7%E0%B8%99%E0%B9%8C%E0%B9%82%E0%B8%AB%E0%B8%A5%E0%B8%94-eca834?style=for-the-badge)](../../releases/latest)
+[![เลี้ยงกาแฟผู้พัฒนา](https://img.shields.io/badge/%E0%B9%80%E0%B8%A5%E0%B8%B5%E0%B9%89%E0%B8%A2%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B9%81%E0%B8%9F%E0%B8%9C%E0%B8%B9%E0%B9%89%E0%B8%9E%E0%B8%B1%E0%B8%92%E0%B8%99%E0%B8%B2-ffdd00?style=for-the-badge&logo=buymeacoffee&logoColor=black)](https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02)
+
+[![License GPL-2.0](https://img.shields.io/badge/license-GPL--2.0-3b352f)](LICENSE)
+[![Cameras](https://img.shields.io/badge/cameras-1%20works%20%C2%B7%2014%20in%20testing-3b352f)](#กล้องที่รองรับ)
+[![Films](https://img.shields.io/badge/films-72-3b352f)](FILMS.md)
+
+[English](README.md) · **ภาษาไทย** · [ฟิล์ม](#ฟิล์ม-72-แบบ) · [กล้องที่รองรับ](#กล้องที่รองรับ) · [Darkrooms](#ล้างบนคอม-darkrooms) · [คู่มือในกล้อง](docs/MANUAL.th.md) · [ทำต่อยอด](PORTING.md)
+
+<br>
+
+<img src="ml-dev/filmos/preview/shelf.gif" alt="ชั้นวางฟิล์มในกล้อง" width="720">
+
+</div>
+
+---
+
+## กล้องฟิล์ม อยู่ในกล้องของคุณ
+
+M-Film เปลี่ยนเมนูของกล้องเป็นหน้าจอกล้องฟิล์มที่วาดขึ้นใหม่ทั้งหมด โดยมี Magic Lantern ทำงานอยู่ข้างใต้
+ถ่ายแล้วไม่มีภาพขึ้นบนจอ และย้อนดูรูปไม่ได้ ถ่ายให้ครบม้วนก่อน แล้วล้างฟิล์มถึงจะได้เห็นว่าได้รูปอะไรมาบ้าง
+
+<table>
+<tr>
+<td width="50%"><img src="ml-dev/filmos/preview/shelf.png" alt="ชั้นวางฟิล์ม"></td>
+<td width="50%"><img src="ml-dev/filmos/preview/roll.png" alt="ม้วนฟิล์ม"></td>
+</tr>
+<tr>
+<td><b>ใส่ฟิล์ม</b> ชั้นวางกลักฟิล์มที่หมุนหันเข้าหาคุณ เลือกม้วนแล้วหางฟิล์มจะถูกดึงออกมาจากกลัก</td>
+<td><b>นับรูป</b> หน้าปัดนับรูปแบบกล้องฟิล์ม ตั้งแต่ S จนถึงรูปสุดท้ายของม้วน และกรอฟิล์มกลับได้</td>
+</tr>
+<tr>
+<td><img src="ml-dev/filmos/preview/hud.png" alt="HUD ตอนถ่าย"></td>
+<td><img src="ml-dev/filmos/preview/developing.png" alt="ล้างฟิล์มในกล้อง"></td>
+</tr>
+<tr>
+<td><b>ถ่าย</b> แบบช่องมองของกล้อง SLR: สเกลรูรับแสง เข็มวัดแสง และตัวเลขนับรูปสีแดงแบบ 7 ส่วน</td>
+<td><b>ล้างฟิล์มในกล้อง</b> ห้องมืดล้างม้วนที่ถ่ายครบทีละรูป ออกมาเป็นโฟลเดอร์ JPEG บนการ์ด</td>
+</tr>
+<tr>
+<td><img src="ml-dev/filmos/preview/prints-sheet.png" alt="Contact sheet"></td>
+<td><img src="ml-dev/filmos/preview/home.png" alt="Home"></td>
+</tr>
+<tr>
+<td><b>ดูรูปที่ล้างแล้ว</b> contact sheet ของทั้งม้วน และดูทีละรูปเต็มจอ</td>
+<td><b>Home</b> แทนเมนูของกล้อง: ม้วนที่ใส่อยู่ และทางไปหน้าอื่นๆ</td>
+</tr>
+</table>
+
+ไฟล์ RAW ยังเก็บไว้ครบทุกรูป ไม่มีอะไรหาย จะเอาม้วนเดิมไปล้างใหม่ด้วยฟิล์มอื่นทีหลังก็ได้
+
+ทุกหน้าจอและทุกปุ่ม: **[คู่มือในกล้อง](docs/MANUAL.th.md)**
+
+---
+
+## ฟิล์ม 72 แบบ
+
+มีทั้งฟิล์มสีเนกาทีฟ สไลด์ ขาวดำ และฟิล์มภาพยนตร์ แยกไว้บนชั้นวาง 4 ชั้น ฟิล์มแต่ละแบบมีสี เกรน halation
+และความนุ่มของภาพเป็นของตัวเอง ม้วนหนึ่งเลือกได้ 36, 24 หรือ 12 รูป
+
+<!-- samples: one photo per film in docs/samples/<film>.jpg (3:2) -->
+<table>
+<tr>
+<td width="33%"><img src="docs/samples/portra400.jpg" alt="Kodak Portra 400"><br><b>Kodak Portra 400</b><br><sub>สีผิวอุ่นนุ่ม ไฮไลต์ละมุน</sub></td>
+<td width="33%"><img src="docs/samples/gold200.jpg" alt="Kodak Gold 200"><br><b>Kodak Gold 200</b><br><sub>แสงทองยามเย็นได้ทั้งวัน</sub></td>
+<td width="33%"><img src="docs/samples/ektar100.jpg" alt="Kodak Ektar 100"><br><b>Kodak Ektar 100</b><br><sub>สีจัด เกรนละเอียดมาก</sub></td>
+</tr>
+<tr>
+<td><img src="docs/samples/superia400.jpg" alt="Fujicolor Superia 400"><br><b>Fujicolor Superia 400</b><br><sub>เงาออกเขียว ฟิล์มถ่ายเล่นทุกวัน</sub></td>
+<td><img src="docs/samples/velvia50.jpg" alt="Fujichrome Velvia 50"><br><b>Fujichrome Velvia 50</b><br><sub>ฟิล์มสไลด์สีสด คอนทราสต์แรง</sub></td>
+<td><img src="docs/samples/kodachrome64.jpg" alt="Kodak Kodachrome 64"><br><b>Kodak Kodachrome 64</b><br><sub>สีแบบนิตยสารยุค 70</sub></td>
+</tr>
+<tr>
+<td><img src="docs/samples/cinestill800t.jpg" alt="CineStill 800T"><br><b>CineStill 800T</b><br><sub>ฟิล์มหนังแสงไฟ กลางคืนออกฟ้า</sub></td>
+<td><img src="docs/samples/kodak2383.jpg" alt="Kodak Vision 2383"><br><b>Kodak Vision 2383</b><br><sub>ฟิล์มพิมพ์ภาพยนตร์ เงาออกเขียวอมฟ้า</sub></td>
+<td><img src="docs/samples/trix400.jpg" alt="Kodak Tri-X 400"><br><b>Kodak Tri-X 400</b><br><sub>ขาวดำคอนทราสต์ดิบ คลาสสิกของสตรีท</sub></td>
+</tr>
+</table>
+
+**[ดูฟิล์มทั้ง 72 แบบ บนรูปเดียวกัน →](FILMS.md)**
+
+สีของฟิล์ม 63 แบบมาจากชุด [Film-Luts](https://github.com/YahiaAngelo/Film-Luts) ที่เหลือมาจากโมเดลฟิล์มของ M-Film เอง
+([`ml-dev/films/films.py`](ml-dev/films/films.py))
+
+---
+
+## กล้องที่รองรับ
+
+M-Film ทำบน EOS M และใช้ได้จริงบนรุ่นนั้น ตอนนี้ build ได้แล้วกับทุกรุ่นที่ Magic Lantern เองใช้ได้อย่างเสถียร
+(DIGIC 4 และ 5) แต่รุ่นเหล่านั้น **ยังไม่เคยมีใครลองบนกล้องจริง** ถ้าคุณมีกล้องรุ่นไหนในตาราง ช่วยทดสอบได้:
+[TESTING.md](TESTING.md) บอกวิธีไว้ (ใช้เวลาประมาณ 20 นาที และถอดกลับได้เสมอ)
+
+<!-- cameras:start -->
+| กล้อง | เฟิร์มแวร์ Canon | สถานะ | ไฟล์ลงการ์ด |
+|---|---|---|---|
+| Canon EOS M | 2.0.2 | ✅ **ใช้ได้** | `M-Film-camera-EOSM.202.zip` |
+| Canon EOS 100D / Rebel SL1 / Kiss X7 | 1.0.1 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-100D.101.zip` |
+| Canon EOS 650D / Rebel T4i / Kiss X6i | 1.0.4 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-650D.104.zip` |
+| Canon EOS 700D / Rebel T5i / Kiss X7i | 1.1.5 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-700D.115.zip` |
+| Canon EOS 6D | 1.1.6 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-6D.116.zip` |
+| Canon EOS 70D | 1.1.2 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-70D.112.zip` |
+| Canon EOS 5D Mark III (firmware 1.1.3) | 1.1.3 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-5D3.113.zip` |
+| Canon EOS 5D Mark III (firmware 1.2.3) | 1.2.3 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-5D3.123.zip` |
+| Canon EOS 550D / Rebel T2i / Kiss X4 | 1.0.9 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-550D.109.zip` |
+| Canon EOS 600D / Rebel T3i / Kiss X5 | 1.0.2 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-600D.102.zip` |
+| Canon EOS 60D | 1.1.1 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-60D.111.zip` |
+| Canon EOS 1100D / Rebel T3 / Kiss X50 | 1.0.5 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-1100D.105.zip` |
+| Canon EOS 500D / Rebel T1i / Kiss X3 | 1.1.1 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-500D.111.zip` |
+| Canon EOS 50D | 1.0.9 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-50D.109.zip` |
+| Canon EOS 5D Mark II | 2.1.2 | 🧪 build ได้แล้ว รอคนทดสอบ | `M-Film-camera-5D2.212.zip` |
+
+**ยังไม่รองรับ:** 7D (source ปัจจุบันของ Magic Lantern build รุ่นนี้ไม่ได้) · 200D, 750D, 77D, 80D, 7D Mark II, 5D Mark IV, 5DS R, 6D Mark II, 850D, M50, R, RP, R5, R6, SX70 HS, SX740 HS (Magic Lantern เองยังเป็นรุ่นทดลองบนกล้องเหล่านี้)
+<!-- cameras:end -->
+
+✅ ลองบนกล้องแล้ว ใช้ได้ · 🧪 build ได้แล้ว รอคนลอง ไฟล์ลงการ์ดอยู่ใน [release](../../releases/latest) แต่ละเวอร์ชัน
+รายชื่อกล้องอยู่ที่ [`ml-dev/cameras.txt`](ml-dev/cameras.txt) วิธีทำให้กล้องรุ่นอื่นอยู่ใน [PORTING.md](PORTING.md)
+
+### ลงในกล้อง
+
+1. เฟิร์มแวร์ Canon ต้องตรงกับในตารางเป๊ะๆ (MENU → แท็บตั้งค่าแท็บสุดท้าย → *Firmware ver.*)
+2. แตกไฟล์ลงการ์ดของรุ่นคุณลงการ์ด SD ใส่การ์ดในกล้อง แล้วกด *Firmware ver.* → update ครั้งเดียว
+ หลังจากนั้นเปิดกล้องด้วยการ์ดใบนั้น M-Film จะเปิดขึ้นมาพร้อมกล้องเลย
+3. ขั้นตอนเต็มและวิธีถอดออก: [TESTING.md](TESTING.md) จะ build เอง: `ml-dev/build_fork.sh <กล้อง>`
+
+---
+
+## ล้างบนคอม: Darkrooms
+
+กล้องล้างม้วนได้เองแต่ช้า **Darkrooms** ล้างบนคอมได้เร็วกว่ามาก เสียบกล้อง (หรือใส่การ์ดในเครื่องอ่านการ์ด)
+แล้วเปิด Darkrooms โปรแกรมจะเจอกล้องเอง แสดงทุกม้วนที่ถ่ายพร้อมฟิล์มของม้วนนั้น แล้วล้างแบบความละเอียดเต็ม
+
+<table>
+<tr>
+<td width="50%"><img src="docs/images/app-rolls.jpg" alt="ม้วนฟิล์ม"></td>
+<td width="50%"><img src="docs/images/app-darkroom.jpg" alt="กำลังล้างม้วน"></td>
+</tr>
+<tr>
+<td><b>ม้วนของคุณ</b> แต่ละม้วนมีกลักฟิล์มและแถบรูปของม้วนนั้น ล้างทั้งม้วนหรือเลือกเฉพาะบางรูปก็ได้</td>
+<td><b>ไฟแดงขึ้น</b> รูปออกมาจากถาดน้ำยาแล้วไปแขวนตากบนราว</td>
+</tr>
+<tr>
+<td><img src="docs/images/app-lights-on.jpg" alt="เปิดไฟ: ม้วนและ contact sheet"></td>
+<td><img src="docs/images/app-develop.jpg" alt="ตั้งค่าการล้าง"></td>
+</tr>
+<tr>
+<td><b>เปิดไฟ</b> ทุกม้วนได้ contact sheet และโฟลเดอร์ของตัวเอง</td>
+<td><b>ละเอียดเต็มที่</b> ใช้ทุกพิกเซลของ RAW, JPEG สี 4:4:4, เก็บ EXIF ไว้ และใส่วันที่บนรูปได้</td>
+</tr>
+</table>
+
+### ฟรี หรือ Full
+
+| | ฟรี | Darkrooms Full |
+|---|---|---|
+| ล้างได้ต่อวัน | 1 ม้วน (ล้างม้วนเดิมซ้ำในวันเดียวกันไม่นับเพิ่ม) | ไม่จำกัด |
+| ทุกฟิล์ม เต็มความละเอียด EXIF และ contact sheet | ✓ | ✓ |
+| ล้างหลายม้วนพร้อมกันด้วยทุก core | | ✓ |
+| ราคา | ฟรี | **$5.99 จ่ายครั้งเดียว** อัปเดตฟรี |
+
+ห้องมืดในกล้องยังฟรีและไม่จำกัดเหมือนเดิม ซื้อ Darkrooms Full ได้ในโปรแกรม (ไอคอนเฟือง → *Get Full*)
+แล้ว key จะส่งมาทางอีเมล ใช้ได้กับคอมของคุณ
+
+### ดาวน์โหลด
+
+| คอมของคุณ | ไฟล์ | เปิดยังไง |
+|---|---|---|
+| **Windows 10 / 11** | `Darkrooms-windows-x64.zip` | แตกไฟล์ แล้วเปิด `Darkrooms.exe` ถ้า Windows เตือน: *More info* → *Run anyway* |
+| **Mac ชิป Intel** | `Darkrooms-macos-intel.zip` | แตกไฟล์ ลากไปไว้ใน Applications ครั้งแรกให้ **คลิกขวา → Open** |
+| **Mac ชิป Apple silicon** | `Darkrooms-macos-apple-silicon.zip` | เหมือนกัน |
+
+โหลดได้จาก **[release ล่าสุด](../../releases/latest)** ขนาดประมาณ 25–45 MB โปรแกรมยังไม่ได้ sign กับ Apple หรือ
+Microsoft ครั้งแรกจึงมีคำเตือน
+
+---
+
+## ทำต่อยอด
+
+- **มีกล้องรุ่นในตาราง?** [TESTING.md](TESTING.md): ลองแล้วบอกผล รุ่นนั้นจะได้ขึ้นเป็น ✅
+- **กล้องรุ่นอื่น?** [PORTING.md](PORTING.md) บอกว่าส่วนไหนย้ายได้ง่าย (หน้าจอ Film OS)
+ ส่วนไหนต้องทำใหม่ทุกรุ่น (ส่วนที่ต่อกับ Magic Lantern) และควรเริ่มยังไง
+- **เจอปัญหา?** [แจ้งใน issues](../../issues/new/choose) แล้วแปะสิ่งที่ขึ้นในไอคอนเฟือง →
+ *What does the computer see?*
+- **ทุกหน้าจอ ทุกปุ่ม และวิธีทำงานข้างใน:** [คู่มือในกล้อง](docs/MANUAL.th.md)
+- **ฟิล์ม** (ค่าฟิล์ม, รายการ LUT) อยู่ใน [`ml-dev/films/`](ml-dev/films/) build กล้องจะอบลงการ์ดให้
+- **Darkrooms** โปรแกรมบนคอม เป็นโปรแกรมปิดซอร์ส ไม่ได้อยู่ใน repo นี้
+
+## สนับสนุน
+
+ส่วนในกล้องของ M-Film ใช้ฟรีและจะฟรีตลอดไป ถ้าได้ม้วนที่ชอบ
+**[เลี้ยงกาแฟผู้พัฒนาได้ที่นี่ ☕](https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02)**
+
+## License
+
+repo นี้ใช้ GPL-2.0 ([LICENSE](LICENSE)) เพราะส่วนในกล้องต่อยอดจาก Magic Lantern
+Darkrooms (โปรแกรมบนคอม) เป็นโปรแกรมแยก ปิดซอร์ส ใช้สัญญาอนุญาตของตัวเอง ฟอนต์, LUT ของฟิล์ม และส่วนอื่นๆ:
+[THIRD_PARTY.md](THIRD_PARTY.md) ไม่มีส่วนเกี่ยวข้องกับ Canon, Kodak, Fujifilm หรือผู้ผลิตฟิล์มรายใด
diff --git a/TESTING.md b/TESTING.md
new file mode 100644
index 0000000..b34e746
--- /dev/null
+++ b/TESTING.md
@@ -0,0 +1,78 @@
+# Testing M-Film on your camera
+
+M-Film runs on the **Canon EOS M**. The same code now **builds** for 14 more cameras (100D, 650D, 700D,
+6D, 70D, 5D Mark III, 550D, 600D, 60D, 1100D, 500D, 50D, 5D Mark II), but nobody has tried it on one
+of those yet. If you have one, you can be the first: it takes about
+20 minutes, and you can always go back.
+
+> **Is it safe?** Magic Lantern runs from the card and changes nothing permanent in the camera.
+> The worst that usually happens is that the camera doesn't start with the card in: take the
+> battery and the card out, and it starts normally again. Still, this is untested software on your
+> camera, at your own risk. Keep a fully charged battery and don't try it in the middle of a shoot.
+
+## 1. Get the files
+
+From the [latest release](../../releases/latest) (or the newest run under *Actions*), download
+`M-Film-camera-<your camera>.zip`:
+
+<!-- cameras:start -->
+| Camera | Canon firmware it needs | File |
+|---|---|---|
+| Canon EOS M | 2.0.2 | `M-Film-camera-EOSM.202.zip` |
+| Canon EOS 100D / Rebel SL1 / Kiss X7 | 1.0.1 | `M-Film-camera-100D.101.zip` |
+| Canon EOS 650D / Rebel T4i / Kiss X6i | 1.0.4 | `M-Film-camera-650D.104.zip` |
+| Canon EOS 700D / Rebel T5i / Kiss X7i | 1.1.5 | `M-Film-camera-700D.115.zip` |
+| Canon EOS 6D | 1.1.6 | `M-Film-camera-6D.116.zip` |
+| Canon EOS 70D | 1.1.2 | `M-Film-camera-70D.112.zip` |
+| Canon EOS 5D Mark III (firmware 1.1.3) | 1.1.3 | `M-Film-camera-5D3.113.zip` |
+| Canon EOS 5D Mark III (firmware 1.2.3) | 1.2.3 | `M-Film-camera-5D3.123.zip` |
+| Canon EOS 550D / Rebel T2i / Kiss X4 | 1.0.9 | `M-Film-camera-550D.109.zip` |
+| Canon EOS 600D / Rebel T3i / Kiss X5 | 1.0.2 | `M-Film-camera-600D.102.zip` |
+| Canon EOS 60D | 1.1.1 | `M-Film-camera-60D.111.zip` |
+| Canon EOS 1100D / Rebel T3 / Kiss X50 | 1.0.5 | `M-Film-camera-1100D.105.zip` |
+| Canon EOS 500D / Rebel T1i / Kiss X3 | 1.1.1 | `M-Film-camera-500D.111.zip` |
+| Canon EOS 50D | 1.0.9 | `M-Film-camera-50D.109.zip` |
+| Canon EOS 5D Mark II | 2.1.2 | `M-Film-camera-5D2.212.zip` |
+<!-- cameras:end -->
+
+The firmware must match exactly (MENU → last settings tab → *Firmware ver.*).
+
+## 2. Install
+
+1. Format a card **in the camera**, then copy everything from the zip to the card's root.
+2. Camera off, card in, camera on. MENU → *Firmware ver.* → update (first time only: this lets the
+ camera start Magic Lantern from the card).
+3. Switch the camera off and on.
+
+## 3. What to try, and what to tell us
+
+Go through these and note what happens (a photo of the screen helps a lot):
+
+- [ ] The camera starts, and the **film shelf** appears (on a DSLR, from the normal shooting screen
+ with LiveView off; give it up to 15 seconds).
+- [ ] **Colours** look right (shelf canisters: Portra yellow, Ektar red; System → Screen colour has a chart).
+- [ ] **Buttons**: the dial and arrows move along the shelf, SET loads a film, MENU goes back,
+ half-shutter returns to the camera. Which buttons do nothing?
+- [ ] **Trash** opens Home; **PLAY** opens the prints instead of Canon's playback.
+- [ ] Load a roll and shoot a few frames **through the viewfinder**, and a few in **LiveView**.
+ Does the frame count go up? Is the HUD drawn in LiveView?
+- [ ] Rewind the roll and **develop it in the camera** (Darkroom). Do prints come out? How long per frame?
+- [ ] Open the card in the **M-Film program** on a computer: are the rolls and films there?
+
+Then [open an issue](../../issues/new/choose) with: your camera and firmware, what worked, what didn't,
+and the file **`ML/FILMROLL.LOG`** from the card attached.
+
+### If it doesn't start
+
+Battery out, card out. Then please tell us, because it most likely means the program is too big for
+that camera's memory (on the EOS M the limit is about 727 KB at boot; the other builds are 670–750 KB, and
+nobody knows their limits yet). Say
+which camera and firmware, and whether the card light stayed on.
+
+## 4. Remove it
+
+Format the card in the camera. To stop the camera looking for Magic Lantern at all, run
+`ML-SETUP.FIR` again from *Firmware ver.* and choose to remove the boot flag.
+
+Thank you! Every camera someone tries moves it from *testing* to *working* in the
+[list on the front page](README.md#cameras).
diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md
new file mode 100644
index 0000000..8eb5553
--- /dev/null
+++ b/THIRD_PARTY.md
@@ -0,0 +1,9 @@
+# Third-party software
+
+- **Magic Lantern** (GPL-2.0): the camera side builds on it. https://magiclantern.fm
+- **Film-Luts** by Yahia Angelo: the colour LUTs of 63 film stocks. They are *not* in this repository: the camera build (`ml-dev/films/getluts.py`) and Darkrooms download them from https://github.com/YahiaAngelo/Film-Luts when you ask, and
+ they stay under their own terms.
+- **Barlow** font family (SIL Open Font License 1.1): `ml-dev/filmos/fonts/OFL.txt`.
+- Film names and box art are descriptive and made for this project; they are not affiliated with or endorsed
+ by Kodak, Fujifilm, CineStill, Ilford, Agfa or others. "Canon" and "EOS M" are trademarks of Canon Inc.;
+ this project is not affiliated with Canon. Canon firmware is not included.
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/docs/MANUAL.th.md b/docs/MANUAL.th.md
new file mode 100644
index 0000000..3ad17a6
--- /dev/null
+++ b/docs/MANUAL.th.md
@@ -0,0 +1,209 @@
+# คู่มือ M-Film ในกล้อง
+
+[← หน้าแรก](../README.th.md) · [English](../README.md)
+
+ทุกหน้าจอ ทุกปุ่ม และวิธีทำงานข้างใน เขียนจาก Canon EOS M ซึ่งเป็นกล้องที่ใช้ทำ M-Film
+กล้องรุ่นอื่นหน้าจอเหมือนกัน แต่ปุ่มบางปุ่มอาจต่างไป (ดู [TESTING.md](../TESTING.md))
+
+## หน้าจอในกล้อง
+
+หน้าจอทั้งหมดในกล้องเป็นของ Film OS (M·FILM) ที่วาดเองทั้งหมด โดยมี Magic Lantern ทำงานอยู่ข้างใต้
+ไม่มีเมนู ML แล้ว: อะไรก็ตามที่เคยเปิดเมนู ML (ปุ่ม, module, script) จะเปิด Home ของ Film OS แทน
+
+| | |
+|---|---|
+| ![](../ml-dev/filmos/preview/shelf.png) | ![](../ml-dev/filmos/preview/home.png) |
+| **ชั้นวางฟิล์ม** หน้าแรกตอนเปิดกล้อง กลักฟิล์มเป็นทรงกระบอกที่มีแสงเงา ฉลากพันรอบ ฝาโลหะ แกนม้วน หางฟิล์ม และรหัส DX ด้านหลัง เลื่อนแล้วกลักจะหมุนหันเข้าหากลาง | **Home** แทนเมนู ML: ม้วนที่อยู่ในกล้อง (กลักหมุนช้าๆ) และทางไปหน้าต่างๆ |
+| ![](../ml-dev/filmos/preview/viewfinder.png) | ![](../ml-dev/filmos/preview/lens.png) |
+| **ตั้งค่า Viewfinder** ภาพตัวอย่างด้านขวาเปลี่ยนตามค่าที่ตั้ง | **ตั้งค่า Lens** ม่านรูรับแสงขยับตามค่า f ของเลนส์แมนนวล |
+| ![](../ml-dev/filmos/preview/roll.png) | ![](../ml-dev/filmos/preview/hud.png) |
+| **ม้วนฟิล์ม** หน้าปัดนับรูปแบบกล้องฟิล์ม หมุนจาก S ไปเลขรูปปัจจุบัน และกรอฟิล์มกลับได้ | **HUD ตอนถ่าย** แบบช่องมอง SLR: สเกลรูรับแสงกับเข็มวัดแสง และไฟ LED แดงแบบ 7 ส่วน |
+| ![](../ml-dev/filmos/preview/screen.png) | |
+| **Screen colour** ปรับสีจอให้ตรงกับที่ตาเห็น พร้อมแผ่นเทียบสี | |
+
+การโหลดฟิล์มจะดึงหางฟิล์มออกจากกลัก แล้วม่านชัตเตอร์ปิดและเปิดเข้าสู่ LiveView
+ตอนเปิดกล้องมี animation ม่านรูรับแสงเปิดออก (ปิดได้ใน System)
+
+### ฟิล์ม 72 ตัว บน 4 ชั้น
+- ชั้นวางแยกตามชนิด: COLOUR (เนกาทีฟสี), SLIDE (สไลด์และ cross-process), B&W, CINE
+ (CineStill และฟิล์มพิมพ์ภาพยนตร์) ▲ ▼ เปลี่ยนชั้น กลักของชั้นใหม่จะหล่นลงมา
+- 8 ตัวแรก (Portra 400, CineStill 800T, Ektar 100, Gold 200, Superia 400, Velvia 50, HP5, Tri-X)
+ สีมาจากโมเดลฟิล์มของ M-Film (`ml-dev/films/films.py`) อีก 63 ตัวมาจาก LUT ของ [Film-Luts](https://github.com/YahiaAngelo/Film-Luts)
+ (Portra 160/800/NC/VC/UC, Pro 400H, Kodachrome, Ektachrome, Provia, Acros, T-MAX, Delta,
+ Vision 2383 ฯลฯ) และ CineStill 400T จาก LUT ส่วนตัว (`ml-dev/films/luts/cinestill400t.slog3.cube`)
+- ข้อมูลฟิล์มเหล่านี้อยู่ในไฟล์ `ML/DATA/FOSFILMS.BIN` บนการ์ด (ไม่ได้อยู่ใน autoexec.bin
+ ที่ต้องเล็ก) ฉลากกลักวาดจากส่วนประกอบตามยี่ห้อ (`ml-dev/filmos/tools/catalog.py`)
+- ตารางสีของทุกฟิล์ม (`ML/DARKROOM/LOOKnn.LUT`) อบมาจาก LUT ตอน build
+ แบบเดียวกับที่ Darkrooms บนคอมใช้ (`tools/genfilms.py`) กล้องจึงไม่ต้องสร้างเอง
+- รูปตัวอย่าง (PLAY บนชั้นวาง): รูปเดียว (`ml-dev/films/sample/SAMPLE.CR2`) ล้างด้วยทุกฟิล์มตอน build
+ ด้วยตัวล้างและตารางสีเดียวกับในกล้อง ได้ `ML/SAMPLES/Fnnn.BMP` (ฟิล์มละไฟล์ ราว 26 MB ทั้งหมด)
+ ตอนนี้มีเฉพาะ build ของ EOS M เปลี่ยนรูปได้โดยวาง CR2 จาก EOS M ไฟล์ใหม่แทนแล้ว build ใหม่
+
+### สนับสนุน
+System > Support M·FILM แสดง QR code ของลิงก์โดเนท (สูงสุด 2 อัน) ใส่ลิงก์ใน `ml-dev/donate.txt`
+บรรทัดละ `ชื่อ URL` แล้ว build ใหม่ (`tools/genqr.py`, ต้องมี `pip install segno`)
+ไม่มีลิงก์ หน้านี้จะขึ้นคำขอบคุณแทน
+
+### ห้องมืด: ล้างฟิล์มในกล้อง
+
+| | |
+|---|---|
+| ![](../ml-dev/filmos/preview/end-of-roll.png) | ![](../ml-dev/filmos/preview/darkroom.png) |
+| **ถ่ายครบม้วน** กล้องถามเอง: ล้างเลย (SET) หรือใส่ม้วนใหม่ก่อน (INFO) | **Darkroom** ม้วนที่ยังไม่ล้าง / ล้างแล้ว / ยังอยู่ในกล้อง เลือกบางม้วน (SET) หรือล้างทั้งหมด (INFO) |
+| ![](../ml-dev/filmos/preview/developing.png) | ![](../ml-dev/filmos/preview/developing-line.png) |
+| **กำลังล้าง** ใต้ไฟแดง: ภาพแฝงค่อยๆ ขึ้นบนกระดาษในถาดน้ำยาตามที่ CPU อ่าน RAW ได้ แล้วภาพเข้มขึ้นจนเต็ม | ภาพที่เสร็จแล้วถูกยกขึ้นไปตากบนราว นาฬิกาจับเวลาห้องมืดเดินรอบละรูป จุดรอบหน้าปัดคือรูปทั้งม้วน |
+| ![](../ml-dev/filmos/preview/prints-sheet.png) | ![](../ml-dev/filmos/preview/prints-frame.png) |
+| **Prints** contact sheet ของม้วน (PLAY เปิดหน้านี้) | ดูทีละรูปเต็มจอ ด้วยสีของรูปนั้นเอง |
+
+- ระหว่างม้วน **ไม่ให้เห็นภาพ**: PLAY เปิด Prints (เฉพาะรูปที่ล้างแล้ว) แทน playback ของ Canon
+ (ปิดได้ที่ System > PLAY shows prints only) ตั้งในเมนู Canon เองครั้งเดียว: Image quality = RAW
+ และ Image review = Off (ถ้ายังไม่ได้ตั้ง กล้องจะขึ้นข้อความเตือนตอนโหลดม้วน; ML ไม่เปลี่ยนค่าพวกนี้เอง
+ เพราะการเขียนค่า quality ของ Canon โดยตรงเสี่ยงทำให้เฟิร์มแวร์รวน)
+- ถ่ายครบม้วน กล้องจะเปิดหน้าถามเองหลังรูปสุดท้าย ~1.5 วินาที (หรือกด SET ตอนม้วนหมด)
+ กรอกลับกลางม้วนที่หน้า Roll ก็ถามแบบเดียวกัน
+- ล้างด้วย CPU ของกล้องเอง (`fos_dev.c`): อ่าน CR2 ถอดรหัส lossless JPEG ทีละส่วน
+ รวมพิกเซลลงภาพขนาดจอ 720×480 โดยตรง แล้วทำแบบเดียวกับ Darkrooms บนคอม:
+ WB daylight, สีกล้อง → sRGB, การวัดแสงของเครื่องสแกน, balance ของฟิล์ม, vignette, halation,
+ สีของฟิล์ม (ตาราง 3D จากโมเดลเดียวกับ Darkrooms) และเกรน แล้วลดเหลือ 240 สีพร้อม dithering
+ สีที่ได้ต่างจาก Darkrooms บนคอมเฉลี่ย ~4 ระดับจาก 255 (ตรวจด้วย color chart)
+- ความเร็ว: ~0.63 พันล้านคำสั่ง ARM ต่อรูป (วัดด้วย qemu บน CR2 จริงของ EOS M; เดิม ~1.3 พันล้าน
+ และอีก ~0.55 พันล้านตอนใช้ฟิล์มตัวนั้นครั้งแรก) ประมาณ 15 วินาทีต่อรูปบนกล้อง
+ ดูเวลาจริงได้ใน `ML/FILMROLL.LOG` (บรรทัด `developed in N ms`) กล้องจะไม่ดับเองระหว่างล้าง
+ - ตัวถอดรหัสอ่านทีละคู่ของค่า โดยค่าที่ใช้อยู่เก็บใน register ทั้งหมด ไบต์ 0xFF หาล่วงหน้าทีละ 16 ไบต์
+ แล้วรวมค่าลงพิกเซลของภาพทีละ 2 ค่า (word เดียว)
+ - ระหว่างล้าง หน้าจอวาดแค่เข็มนาฬิกา ~4 ครั้งต่อวินาที เวลาที่เหลือให้การล้างเกือบทั้งหมด
+ (ตอนรูปโผล่ในถาดหรือแขวนตาก หน้าจอจึงกลับมาลื่นตามปกติ)
+ - ตารางสีของทุกฟิล์ม (`ML/DARKROOM/LOOKnn.LUT`) สร้างมาจากตอน build และติดตั้งลงการ์ดด้วย
+ กล้องจึงไม่ต้อง "ผสมน้ำยา" เอง (ถ้าโมเดลสีเปลี่ยน กล้องจะสร้างใหม่และเก็บไว้เอง)
+- หยุดกลางคันได้ (MENU) หรือกดชัตเตอร์ครึ่งเดียวกลับไปถ่าย: รูปที่ล้างเสร็จแล้วยังอยู่
+ ครั้งหน้าจะล้างต่อจากรูปที่ค้าง
+- รูปที่ล้างแล้วเป็น JPEG สีเต็ม (720×480, มี EXIF วันที่ ฟิล์ม และค่า f) อยู่ใน DCIM
+ โฟลเดอร์ละม้วน ตั้งชื่อตามวันที่ถ่ายรูปแรกและฟิล์ม: `DCIM/Sep0906 Portra400/IMG_0102.JPG`
+ (เดือนย่อ, เลขเดือน, วันที่) ม้วนที่สองของฟิล์มเดียวกันในวันเดียวกันเป็น `Sep0906 Portra400 2`
+ ถ้าการ์ดสร้างชื่อยาวไม่ได้ จะเป็น `SEP0906` แทน (log: `darkroom: JPEGs in ...`)
+ ม้วนที่มี JPEG ไม่ครบทุกรูป (เช่นล้างไว้ก่อนมีฟีเจอร์นี้) จะกลับมาเป็น TO DEVELOP
+ ล้างอีกครั้งจะทำเฉพาะรูปที่ยังไม่มี JPEG
+- สำหรับดูในกล้องยังมี `ML/DARKROOM/R<ม้วน>/F<รูป>.BMP` (240 สี) และ `SHEET.BMP` (contact sheet)
+ ม้วนถือว่าล้างแล้วเมื่อมี `SHEET.BMP` ไฟล์ CR2 เดิมยังอยู่ครบ เอาไปล้างละเอียดเต็มขนาดด้วย Darkrooms บนคอมได้เหมือนเดิม
+
+### สีบนจอ
+สีของ Film OS ส่งไปที่จอแบบเดียวกับที่ Canon แปลงสีของตัวเอง (BT.601 Y'CbCr, ขาวที่ระดับ 235)
+ตรวจกับค่าพาเลตจริงที่อ่านจาก EOS M แล้ว: แปลงกลับเป็นสีหลักได้เป๊ะ เช่นแดงเข้ม (202, 0, 0)
+ถ้ายังไม่ตรงกับที่ตาเห็น ปรับได้ที่ System > Screen colour: Colour (ความสด), Warmth (อุ่น/เย็น),
+Brightness (โทนกลาง) และ Conversion (Canon / Rec.709 แบบเดิม) ทั้งระบบเปลี่ยนทันทีขณะปรับ
+ด้านขวามีแผ่นเทียบสี: สีฉลากฟิล์ม และแถบเทา 11 ขั้น (สองขั้นที่มืดที่สุดควรยังแยกกันออก)
+
+### ปุ่ม
+
+| ที่ไหน | ปุ่ม | ทำอะไร |
+|---|---|---|
+| ตอนถ่าย (LiveView) | แตะจอสองนิ้ว หรือกด ▼ ค้าง | เปิด Home (ปุ่มที่เคยเปิดเมนู ML) |
+| | PLAY | เปิด Prints: เฉพาะรูปที่ล้างแล้ว (ไม่มี playback ของ Canon) |
+| | SET | กรอฟิล์มไปรูปถัดไป ถ้าม้วนหมดจะถามว่าจะล้างเลยไหม |
+| | หมุนวงล้อในโหมด Av | ตั้งค่า f ของเลนส์แมนนวล |
+| ชั้นวางฟิล์ม | หมุนวงล้อ / ◀ ▶ | เลือกฟิล์ม |
+| | ▲ ▼ | เปลี่ยนชั้น: COLOUR / SLIDE / B&W / CINE |
+| | INFO | จำนวนรูป 36 / 24 / 12 |
+| | SET | โหลดม้วน (ถ้ามีม้วนค้างอยู่ จะถามก่อนกรอกลับ) |
+| | PLAY | ดูรูปตัวอย่างของฟิล์มนั้นเต็มจอ (เฉพาะ EOS M) |
+| รูปตัวอย่าง | ◀ ▶ / หมุนวงล้อ | ฟิล์มก่อนหน้า / ถัดไปบนชั้นเดียวกัน |
+| | SET | โหลดม้วนฟิล์มที่ดูอยู่ |
+| | INFO | แสดง/ซ่อนแถบชื่อฟิล์ม |
+| | PLAY / MENU | กลับไปชั้นวาง ที่ฟิล์มที่ดูอยู่ |
+| Home | ▲ ▼ / หมุนวงล้อ, SET | เลือก, เปิด (PLAY = Prints) |
+| Darkroom | SET | ทำเครื่องหมายม้วนที่จะล้าง / เปิด Prints ของม้วนที่ล้างแล้ว |
+| | INFO | ล้างม้วนที่เลือก (ไม่ได้เลือก = ล้างทั้งหมด) |
+| กำลังล้าง | MENU | หยุด (รูปที่เสร็จแล้วยังอยู่) |
+| Prints | ◀ ▶ ▲ ▼, SET | เลือกรูปใน contact sheet, เปิดเต็มจอ |
+| | หมุนวงล้อ | ม้วนอื่น (ใน contact sheet) / รูปถัดไป (เต็มจอ) |
+| | INFO | แสดง/ซ่อนรายละเอียด (ม้วน, วันเวลา, f) |
+| หน้าตั้งค่า | ▲ ▼ / หมุนวงล้อ | เลือกแถว |
+| | ◀ ▶ | เปลี่ยนค่า |
+| | SET | เปิด/ปิด หรือทำคำสั่ง |
+| Screen colour | ◀ ▶ | ปรับค่า (เห็นผลทันที) |
+| ทุกหน้า | MENU | ย้อนกลับ |
+| | ชัตเตอร์ครึ่งเดียว | กลับไปถ่ายทันที |
+
+เมนูของ Canon (ฟอร์แมตการ์ด, RAW) อยู่ที่ System > Canon menu หรือกด MENU ตอนถ่ายตามปกติ
+ค่าของ ML ที่ไม่มีใน Film OS จะเป็นค่าเริ่มต้นของ ML เสมอ
+(ถ้าจำเป็นต้องใช้เมนู ML จริงๆ ให้คืน ML ทางการด้วย `restore_official.ps1`)
+
+ถ้าเปิด Debug log ไว้ ตอนปิด Film OS จะเขียนสรุปความเร็วลง `ML/FILMROLL.LOG` บรรทัดเดียว
+(`film os: N frames in N ms = N/s; per frame N ms draw (N canisters) + N present + N rest, worst N, open N ms`)
+ไม่เขียนการ์ดระหว่าง animation
+และถ้ากล้องวาดไม่ทัน Film OS จะลดรายละเอียดกลักฟิล์มเองอัตโนมัติ
+ถ้ามีปัญหาให้คืน ML ทางการด้วย `restore_official.ps1`
+
+ความเร็ว: ทุกหน้าจอวัดจากโค้ดที่ compile สำหรับ ARMv5 (ชิปเดียวกับกล้อง) ด้วย qemu
+(`sim/tools/armcount.py`) แล้ววาดเฉพาะส่วนที่ขยับ ตรวจแล้วว่าภาพตรงกับการวาดทั้งจอทุกพิกเซล
+(`FOS_FULL=1 ./out/sim ...`)
+
+สิ่งที่ควรลองบนกล้องครั้งแรก
+1. เปิดกล้อง: ม่านรูรับแสงเปิดออก แล้วเข้าชั้นวางฟิล์ม สีตรงกับภาพตัวอย่างไหม (ไม่ตรง: System > Screen colour)
+2. หมุนวงล้อเร็วๆ: ลื่นไหม (ดูบรรทัด `film os: N frames/s` ใน `ML/FILMROLL.LOG` หลังปิด Film OS)
+3. SET โหลดม้วน: กลับเข้า LiveView แล้ว picture style / WB / ISO เปลี่ยนตามฟิล์ม
+4. แตะจอสองนิ้ว (หรือกด ▼ ค้าง) ตอนถ่าย: เปิด Home และไม่มีเมนู ML ขึ้นมาเลย
+5. กดชัตเตอร์ครึ่งเดียวตอนอยู่ในหน้าไหนก็ได้: กลับไปถ่ายทันที
+6. ถ่ายสักสองสามรูป: HUD นับรูป และหน้า Roll แสดงรูปล่าสุด ไม่มีภาพขึ้นหลังถ่าย และ PLAY ไม่โชว์รูป
+7. ห้องมืด: ใส่ม้วน 12 รูป ถ่ายให้ครบ แล้วเลือก "ล้างเลย" ดูว่าภาพแฝงขึ้น ภาพไปตากบนราว และดูเวลาที่ใช้ต่อรูป
+ (`darkroom: roll ... frame N developed in N ms` ใน `ML/FILMROLL.LOG`) แล้วกด PLAY ดู Prints
+ ถ้ารูปไหนล้างไม่ได้ เหตุผลจะอยู่ใน log บรรทัด `darkroom: roll ... frame N: ...`
+
+### โค้ด
+- `ml-dev/filmos/` Film OS (C ล้วน ใช้ได้ทั้งในกล้องและบนคอม)
+ - `fos_gfx.c` ระบบวาดภาพ: palette 254 สีแบบไล่เฉด (ramp) กับ dithering, รูปทรงขอบเนียน, ตัวอักษร
+ - `fos_film.c` ข้อมูลฟิล์มแต่ละตัว และการวาดกลักฟิล์ม 3D กับลายฉลาก
+ - `fos_ui.c` ลูปหลัก, animation แบบสปริง, การเปลี่ยนหน้า, ม่านชัตเตอร์
+ - `fos_shelf.c` ชั้นวางฟิล์มและการโหลดม้วน, `fos_pages.c` Home, ตั้งค่า, ม้วนฟิล์ม
+ - `fos_hud.c` HUD ตอนถ่าย (ใช้ palette ของ Canon)
+ - `fos_dev.c` เครื่องล้างฟิล์ม: อ่าน CR2, ถอดรหัส RAW, สีฟิล์ม, ลดสี, เขียนภาพ BMP
+ - `fos_looks.c` ค่าฟิล์มแต่ละตัวสำหรับกล้อง สร้างจาก `ml-dev/films/films.py` ด้วย `tools/genlooks.py` (อย่าแก้เอง)
+ - `fos_lab.c` อ่าน log ของม้วนบนการ์ด และสถานะการล้าง, `fos_dark.c` หน้า Darkroom, กำลังล้าง, Prints
+ - `fos_font.c` ฟอนต์ที่สร้างจาก `tools/mkfont.py` (Barlow, `fonts/`) ไม่ได้ build เข้า autoexec.bin:
+ `tools/fontblob.c` แปลงเป็น `ML/DATA/FOSFONT.BIN` ที่กล้องโหลดจากการ์ด
+ - `sim/` ตัวจำลองบนคอม, `preview/` ภาพตัวอย่าง
+- `ml-dev/fork/src/filmroll.c` ส่วนเชื่อมกับกล้อง: ม้วนฟิล์ม, log, ตั้งค่ากล้องตามฟิล์ม,
+ การยึดหน้าจอและปุ่มให้ Film OS, palette
+- `ml-dev/fork/apply_fork.py` และ `fork/film-mode.patch` การแก้ไขบน
+ [magiclantern_simplified](https://github.com/reticulatedpines/magiclantern_simplified)
+ commit `ed3e7c0df` (ตรงกับ build ทางการ 2025-06-20.EOSM.202)
+- `setup_wsl.sh` ตั้งเครื่อง build ใน WSL Ubuntu
+- `build_fork.sh` build fork แล้วเก็บไฟล์สำหรับลงการ์ดไว้ที่ `ml-dev/out/fork/`
+- `install_fork.ps1` / `restore_official.ps1` ลง fork บนการ์ด / คืน ML ทางการ
+- `push_fork.ps1` push branch `film-mode` ของ fork ทั้งชุดขึ้น
+ [HNGSeries/magiclantern-eosm-film](https://github.com/HNGSeries/magiclantern-eosm-film) (private)
+- `filmroll/` โหมดฟิล์มรุ่นแรกที่ทำเป็น ML module (เก็บไว้อ้างอิง ไม่ได้ใช้แล้ว)
+
+กล้องต้องใช้เฟิร์มแวร์ 2.0.2
+
+**ขนาดของ autoexec.bin สำคัญ:** บน EOS M หน่วยความจำของ ML ทั้งหมด (โค้ด + bss) ถูกตัดมาจากหน่วยความจำของ Canon ตอนบูต
+ถ้าใหญ่เกินไปกล้องจะค้างตอนเปิด (ไฟการ์ดสีแดงติดค้าง เปิดไม่ขึ้น) `build_fork.sh` จึงหยุดถ้าเกิน 727,072 ไบต์
+(ขนาดใหญ่สุดที่เคยเปิดได้) ฟอนต์ของ Film OS จึงอยู่ในไฟล์ `ML/DATA/FOSFONT.BIN` บนการ์ด (`tools/fontblob.c`)
+โหลดหลังบูต และตารางของห้องมืดจองหน่วยความจำเฉพาะตอนเปิด Film OS
+ถ้ากล้องค้างแบบนั้น: ถอดแบต ถอดการ์ด เปิดกล้องได้ตามปกติ แล้วคืน ML ทางการด้วย `restore_official.ps1`
+
+### ตัวจำลอง
+```
+cd ml-dev/filmos/sim
+make
+./out/sim scenes/shelf.txt out/frames/shelf # กดปุ่มตามสคริปต์ เก็บทุกเฟรม
+python3 topng.py --gif out/shelf.gif out/frames/shelf/*.idx
+./previews.sh # สร้างภาพใน ../preview ใหม่
+```
+สคริปต์ใน `scenes/` เป็นบรรทัด `<ms> <ปุ่ม>` (left right up down wl wr set menu info play home)
+
+ห้องมืดในตัวจำลองใช้การ์ดจำลองที่ `sim/out/card/` (`./mkcard.sh` สร้างม้วนจาก CR2 ทดสอบ)
+```
+./mkcard.sh && ./out/sim scenes/darkroom.txt out/frames/darkroom
+make out/devtest && ./out/devtest -f portra400 IMG_0001.CR2 out.BMP out.ppm # ล้างรูปเดียวแบบที่กล้องทำ
+```
+`tools/mkcr2.c` สร้าง CR2 ทดสอบแบบของ EOS M (ตรวจกับ LibRaw แล้ว), `devtest -r` เทียบค่าที่ถอดรหัสได้ทุก sample
+แก้ฟอนต์หรือขนาดตัวอักษรที่ `tools/mkfont.py` แล้วรัน `python3 mkfont.py` (ต้องมี Pillow กับ raqm)
+
+## ฟิล์ม (`ml-dev/films/`)
+ค่าฟิล์มที่ทั้งกล้องและ Darkrooms ใช้ build กล้องจะอ่านจากที่นี่
+- `films.py` ค่าของฟิล์มแต่ละตัว ตั้งด้วยสายตา ยังไม่ได้วัดเทียบกับฟิล์มจริง
+- `filmluts.py` ฟิล์ม 63 ตัวที่สีมาจาก Film-Luts, `getluts.py` ดาวน์โหลด LUT เหล่านั้นไว้ที่
+ `luts/filmluts/` (ไม่ได้เก็บใน git) ตอน build กล้องจะอบเป็นตารางสีลงการ์ด
+- `lut.py` อ่านและใช้ไฟล์ `.cube` (`python lut.py info ไฟล์.cube` ดูว่าใน LUT มีอะไร)
+- CineStill 400T ใช้ LUT ส่วนตัว: วางไว้ที่ `luts/cinestill400t.slog3.cube`
diff --git a/docs/films/acros100.jpg b/docs/films/acros100.jpg
new file mode 100644
index 0000000..6689b5e
Binary files /dev/null and b/docs/films/acros100.jpg differ
diff --git a/docs/films/apx100.jpg b/docs/films/apx100.jpg
new file mode 100644
index 0000000..2bbe8b0
Binary files /dev/null and b/docs/films/apx100.jpg differ
diff --git a/docs/films/apx25.jpg b/docs/films/apx25.jpg
new file mode 100644
index 0000000..fa50aff
Binary files /dev/null and b/docs/films/apx25.jpg differ
diff --git a/docs/films/astia100f.jpg b/docs/films/astia100f.jpg
new file mode 100644
index 0000000..9c94447
Binary files /dev/null and b/docs/films/astia100f.jpg differ
diff --git a/docs/films/bw400cn.jpg b/docs/films/bw400cn.jpg
new file mode 100644
index 0000000..2d120f7
Binary files /dev/null and b/docs/films/bw400cn.jpg differ
diff --git a/docs/films/cinestill400t.jpg b/docs/films/cinestill400t.jpg
new file mode 100644
index 0000000..88250ff
Binary files /dev/null and b/docs/films/cinestill400t.jpg differ
diff --git a/docs/films/cinestill800t.jpg b/docs/films/cinestill800t.jpg
new file mode 100644
index 0000000..7905a09
Binary files /dev/null and b/docs/films/cinestill800t.jpg differ
diff --git a/docs/films/delta100.jpg b/docs/films/delta100.jpg
new file mode 100644
index 0000000..8060a44
Binary files /dev/null and b/docs/films/delta100.jpg differ
diff --git a/docs/films/delta3200.jpg b/docs/films/delta3200.jpg
new file mode 100644
index 0000000..2f33a67
Binary files /dev/null and b/docs/films/delta3200.jpg differ
diff --git a/docs/films/delta400.jpg b/docs/films/delta400.jpg
new file mode 100644
index 0000000..80c7bdb
Binary files /dev/null and b/docs/films/delta400.jpg differ
diff --git a/docs/films/e100gx.jpg b/docs/films/e100gx.jpg
new file mode 100644
index 0000000..90f8f0d
Binary files /dev/null and b/docs/films/e100gx.jpg differ
diff --git a/docs/films/e100vs.jpg b/docs/films/e100vs.jpg
new file mode 100644
index 0000000..fe40412
Binary files /dev/null and b/docs/films/e100vs.jpg differ
diff --git a/docs/films/ektar100.jpg b/docs/films/ektar100.jpg
new file mode 100644
index 0000000..f62b0a6
Binary files /dev/null and b/docs/films/ektar100.jpg differ
diff --git a/docs/films/elite100xpro.jpg b/docs/films/elite100xpro.jpg
new file mode 100644
index 0000000..c12c8a3
Binary files /dev/null and b/docs/films/elite100xpro.jpg differ
diff --git a/docs/films/elite200.jpg b/docs/films/elite200.jpg
new file mode 100644
index 0000000..047963b
Binary files /dev/null and b/docs/films/elite200.jpg differ
diff --git a/docs/films/elite400.jpg b/docs/films/elite400.jpg
new file mode 100644
index 0000000..cc9afe9
Binary files /dev/null and b/docs/films/elite400.jpg differ
diff --git a/docs/films/elitechrome200.jpg b/docs/films/elitechrome200.jpg
new file mode 100644
index 0000000..5bfa44f
Binary files /dev/null and b/docs/films/elitechrome200.jpg differ
diff --git a/docs/films/elitechrome400.jpg b/docs/films/elitechrome400.jpg
new file mode 100644
index 0000000..0d5a579
Binary files /dev/null and b/docs/films/elitechrome400.jpg differ
diff --git a/docs/films/extracolor100.jpg b/docs/films/extracolor100.jpg
new file mode 100644
index 0000000..75f2905
Binary files /dev/null and b/docs/films/extracolor100.jpg differ
diff --git a/docs/films/fp4.jpg b/docs/films/fp4.jpg
new file mode 100644
index 0000000..40d95f6
Binary files /dev/null and b/docs/films/fp4.jpg differ
diff --git a/docs/films/fuji3510.jpg b/docs/films/fuji3510.jpg
new file mode 100644
index 0000000..7747a2d
Binary files /dev/null and b/docs/films/fuji3510.jpg differ
diff --git a/docs/films/fuji3513.jpg b/docs/films/fuji3513.jpg
new file mode 100644
index 0000000..05dd3c3
Binary files /dev/null and b/docs/films/fuji3513.jpg differ
diff --git a/docs/films/gold200.jpg b/docs/films/gold200.jpg
new file mode 100644
index 0000000..6d73c75
Binary files /dev/null and b/docs/films/gold200.jpg differ
diff --git a/docs/films/grid.jpg b/docs/films/grid.jpg
new file mode 100644
index 0000000..9d121cb
Binary files /dev/null and b/docs/films/grid.jpg differ
diff --git a/docs/films/hie.jpg b/docs/films/hie.jpg
new file mode 100644
index 0000000..99842fb
Binary files /dev/null and b/docs/films/hie.jpg differ
diff --git a/docs/films/hp5.jpg b/docs/films/hp5.jpg
new file mode 100644
index 0000000..8760808
Binary files /dev/null and b/docs/films/hp5.jpg differ
diff --git a/docs/films/hps800.jpg b/docs/films/hps800.jpg
new file mode 100644
index 0000000..ce01d5c
Binary files /dev/null and b/docs/films/hps800.jpg differ
diff --git a/docs/films/ir400.jpg b/docs/films/ir400.jpg
new file mode 100644
index 0000000..a85c915
Binary files /dev/null and b/docs/films/ir400.jpg differ
diff --git a/docs/films/kodachrome200.jpg b/docs/films/kodachrome200.jpg
new file mode 100644
index 0000000..bb29d7a
Binary files /dev/null and b/docs/films/kodachrome200.jpg differ
diff --git a/docs/films/kodachrome25.jpg b/docs/films/kodachrome25.jpg
new file mode 100644
index 0000000..32ff6a7
Binary files /dev/null and b/docs/films/kodachrome25.jpg differ
diff --git a/docs/films/kodachrome64.jpg b/docs/films/kodachrome64.jpg
new file mode 100644
index 0000000..54e29fb
Binary files /dev/null and b/docs/films/kodachrome64.jpg differ
diff --git a/docs/films/kodak2383.jpg b/docs/films/kodak2383.jpg
new file mode 100644
index 0000000..0114e28
Binary files /dev/null and b/docs/films/kodak2383.jpg differ
diff --git a/docs/films/kodak2393.jpg b/docs/films/kodak2393.jpg
new file mode 100644
index 0000000..a11249f
Binary files /dev/null and b/docs/films/kodak2393.jpg differ
diff --git a/docs/films/neopan1600.jpg b/docs/films/neopan1600.jpg
new file mode 100644
index 0000000..6582820
Binary files /dev/null and b/docs/films/neopan1600.jpg differ
diff --git a/docs/films/ortho25.jpg b/docs/films/ortho25.jpg
new file mode 100644
index 0000000..535a93c
Binary files /dev/null and b/docs/films/ortho25.jpg differ
diff --git a/docs/films/panf50.jpg b/docs/films/panf50.jpg
new file mode 100644
index 0000000..9d16dcc
Binary files /dev/null and b/docs/films/panf50.jpg differ
diff --git a/docs/films/portra160.jpg b/docs/films/portra160.jpg
new file mode 100644
index 0000000..b2c6a21
Binary files /dev/null and b/docs/films/portra160.jpg differ
diff --git a/docs/films/portra160nc.jpg b/docs/films/portra160nc.jpg
new file mode 100644
index 0000000..3c1a1df
Binary files /dev/null and b/docs/films/portra160nc.jpg differ
diff --git a/docs/films/portra160vc.jpg b/docs/films/portra160vc.jpg
new file mode 100644
index 0000000..f2cba7f
Binary files /dev/null and b/docs/films/portra160vc.jpg differ
diff --git a/docs/films/portra400.jpg b/docs/films/portra400.jpg
new file mode 100644
index 0000000..53f3349
Binary files /dev/null and b/docs/films/portra400.jpg differ
diff --git a/docs/films/portra400nc.jpg b/docs/films/portra400nc.jpg
new file mode 100644
index 0000000..b6c2503
Binary files /dev/null and b/docs/films/portra400nc.jpg differ
diff --git a/docs/films/portra400uc.jpg b/docs/films/portra400uc.jpg
new file mode 100644
index 0000000..067322e
Binary files /dev/null and b/docs/films/portra400uc.jpg differ
diff --git a/docs/films/portra400vc.jpg b/docs/films/portra400vc.jpg
new file mode 100644
index 0000000..d0aa450
Binary files /dev/null and b/docs/films/portra400vc.jpg differ
diff --git a/docs/films/portra800.jpg b/docs/films/portra800.jpg
new file mode 100644
index 0000000..f1ad052
Binary files /dev/null and b/docs/films/portra800.jpg differ
diff --git a/docs/films/precisa100.jpg b/docs/films/precisa100.jpg
new file mode 100644
index 0000000..3e4a02a
Binary files /dev/null and b/docs/films/precisa100.jpg differ
diff --git a/docs/films/pro160c.jpg b/docs/films/pro160c.jpg
new file mode 100644
index 0000000..f2c4148
Binary files /dev/null and b/docs/films/pro160c.jpg differ
diff --git a/docs/films/pro400h.jpg b/docs/films/pro400h.jpg
new file mode 100644
index 0000000..2991a92
Binary files /dev/null and b/docs/films/pro400h.jpg differ
diff --git a/docs/films/pro800z.jpg b/docs/films/pro800z.jpg
new file mode 100644
index 0000000..2045958
Binary files /dev/null and b/docs/films/pro800z.jpg differ
diff --git a/docs/films/provia100f.jpg b/docs/films/provia100f.jpg
new file mode 100644
index 0000000..e12bf3b
Binary files /dev/null and b/docs/films/provia100f.jpg differ
diff --git a/docs/films/provia400f.jpg b/docs/films/provia400f.jpg
new file mode 100644
index 0000000..452b283
Binary files /dev/null and b/docs/films/provia400f.jpg differ
diff --git a/docs/films/provia400x.jpg b/docs/films/provia400x.jpg
new file mode 100644
index 0000000..577345d
Binary files /dev/null and b/docs/films/provia400x.jpg differ
diff --git a/docs/films/reala100.jpg b/docs/films/reala100.jpg
new file mode 100644
index 0000000..077e209
Binary files /dev/null and b/docs/films/reala100.jpg differ
diff --git a/docs/films/redscale100.jpg b/docs/films/redscale100.jpg
new file mode 100644
index 0000000..71b7911
Binary files /dev/null and b/docs/films/redscale100.jpg differ
diff --git a/docs/films/retro100.jpg b/docs/films/retro100.jpg
new file mode 100644
index 0000000..b69d4fb
Binary files /dev/null and b/docs/films/retro100.jpg differ
diff --git a/docs/films/retro80s.jpg b/docs/films/retro80s.jpg
new file mode 100644
index 0000000..43e4636
Binary files /dev/null and b/docs/films/retro80s.jpg differ
diff --git a/docs/films/sensia100.jpg b/docs/films/sensia100.jpg
new file mode 100644
index 0000000..962dc63
Binary files /dev/null and b/docs/films/sensia100.jpg differ
diff --git a/docs/films/superia100.jpg b/docs/films/superia100.jpg
new file mode 100644
index 0000000..21a6d19
Binary files /dev/null and b/docs/films/superia100.jpg differ
diff --git a/docs/films/superia1600.jpg b/docs/films/superia1600.jpg
new file mode 100644
index 0000000..6c436e0
Binary files /dev/null and b/docs/films/superia1600.jpg differ
diff --git a/docs/films/superia200.jpg b/docs/films/superia200.jpg
new file mode 100644
index 0000000..ad87ca0
Binary files /dev/null and b/docs/films/superia200.jpg differ
diff --git a/docs/films/superia200xpro.jpg b/docs/films/superia200xpro.jpg
new file mode 100644
index 0000000..09aea3d
Binary files /dev/null and b/docs/films/superia200xpro.jpg differ
diff --git a/docs/films/superia400.jpg b/docs/films/superia400.jpg
new file mode 100644
index 0000000..04b3c96
Binary files /dev/null and b/docs/films/superia400.jpg differ
diff --git a/docs/films/superia800.jpg b/docs/films/superia800.jpg
new file mode 100644
index 0000000..c019788
Binary files /dev/null and b/docs/films/superia800.jpg differ
diff --git a/docs/films/tmax100.jpg b/docs/films/tmax100.jpg
new file mode 100644
index 0000000..b6ed2b5
Binary files /dev/null and b/docs/films/tmax100.jpg differ
diff --git a/docs/films/tmax3200.jpg b/docs/films/tmax3200.jpg
new file mode 100644
index 0000000..4d09835
Binary files /dev/null and b/docs/films/tmax3200.jpg differ
diff --git a/docs/films/tmax400.jpg b/docs/films/tmax400.jpg
new file mode 100644
index 0000000..fa505fc
Binary files /dev/null and b/docs/films/tmax400.jpg differ
diff --git a/docs/films/trix400.jpg b/docs/films/trix400.jpg
new file mode 100644
index 0000000..ddc2417
Binary files /dev/null and b/docs/films/trix400.jpg differ
diff --git a/docs/films/ultra100.jpg b/docs/films/ultra100.jpg
new file mode 100644
index 0000000..032f5dd
Binary files /dev/null and b/docs/films/ultra100.jpg differ
diff --git a/docs/films/velvia100.jpg b/docs/films/velvia100.jpg
new file mode 100644
index 0000000..6363863
Binary files /dev/null and b/docs/films/velvia100.jpg differ
diff --git a/docs/films/velvia50.jpg b/docs/films/velvia50.jpg
new file mode 100644
index 0000000..5d32e1b
Binary files /dev/null and b/docs/films/velvia50.jpg differ
diff --git a/docs/films/vista200.jpg b/docs/films/vista200.jpg
new file mode 100644
index 0000000..8199208
Binary files /dev/null and b/docs/films/vista200.jpg differ
diff --git a/docs/films/xp2.jpg b/docs/films/xp2.jpg
new file mode 100644
index 0000000..6538550
Binary files /dev/null and b/docs/films/xp2.jpg differ
diff --git a/docs/films/xproslide200.jpg b/docs/films/xproslide200.jpg
new file mode 100644
index 0000000..0597fac
Binary files /dev/null and b/docs/films/xproslide200.jpg differ
diff --git a/docs/films/xtra800.jpg b/docs/films/xtra800.jpg
new file mode 100644
index 0000000..c7b6d65
Binary files /dev/null and b/docs/films/xtra800.jpg differ
diff --git a/docs/images/app-connect.jpg b/docs/images/app-connect.jpg
new file mode 100644
index 0000000..9114383
Binary files /dev/null and b/docs/images/app-connect.jpg differ
diff --git a/docs/images/app-darkroom.jpg b/docs/images/app-darkroom.jpg
new file mode 100644
index 0000000..c3e59f9
Binary files /dev/null and b/docs/images/app-darkroom.jpg differ
diff --git a/docs/images/app-develop.jpg b/docs/images/app-develop.jpg
new file mode 100644
index 0000000..62d0702
Binary files /dev/null and b/docs/images/app-develop.jpg differ
diff --git a/docs/images/app-films.jpg b/docs/images/app-films.jpg
new file mode 100644
index 0000000..d9b9424
Binary files /dev/null and b/docs/images/app-films.jpg differ
diff --git a/docs/images/app-lights-on.jpg b/docs/images/app-lights-on.jpg
new file mode 100644
index 0000000..22dc741
Binary files /dev/null and b/docs/images/app-lights-on.jpg differ
diff --git a/docs/images/app-rolls.jpg b/docs/images/app-rolls.jpg
new file mode 100644
index 0000000..d5d9b5a
Binary files /dev/null and b/docs/images/app-rolls.jpg differ
diff --git a/docs/images/mfilm.png b/docs/images/mfilm.png
new file mode 100644
index 0000000..8f2aa9d
Binary files /dev/null and b/docs/images/mfilm.png differ
diff --git a/docs/samples/cinestill800t.jpg b/docs/samples/cinestill800t.jpg
new file mode 100644
index 0000000..0a8d47c
Binary files /dev/null and b/docs/samples/cinestill800t.jpg differ
diff --git a/docs/samples/ektar100.jpg b/docs/samples/ektar100.jpg
new file mode 100644
index 0000000..a169bb5
Binary files /dev/null and b/docs/samples/ektar100.jpg differ
diff --git a/docs/samples/gold200.jpg b/docs/samples/gold200.jpg
new file mode 100644
index 0000000..ff72046
Binary files /dev/null and b/docs/samples/gold200.jpg differ
diff --git a/docs/samples/kodachrome64.jpg b/docs/samples/kodachrome64.jpg
new file mode 100644
index 0000000..12a6773
Binary files /dev/null and b/docs/samples/kodachrome64.jpg differ
diff --git a/docs/samples/kodak2383.jpg b/docs/samples/kodak2383.jpg
new file mode 100644
index 0000000..e2cd594
Binary files /dev/null and b/docs/samples/kodak2383.jpg differ
diff --git a/docs/samples/portra400.jpg b/docs/samples/portra400.jpg
new file mode 100644
index 0000000..91491dc
Binary files /dev/null and b/docs/samples/portra400.jpg differ
diff --git a/docs/samples/superia400.jpg b/docs/samples/superia400.jpg
new file mode 100644
index 0000000..8dbc9fd
Binary files /dev/null and b/docs/samples/superia400.jpg differ
diff --git a/docs/samples/trix400.jpg b/docs/samples/trix400.jpg
new file mode 100644
index 0000000..0bcb8de
Binary files /dev/null and b/docs/samples/trix400.jpg differ
diff --git a/docs/samples/velvia50.jpg b/docs/samples/velvia50.jpg
new file mode 100644
index 0000000..d0a057a
Binary files /dev/null and b/docs/samples/velvia50.jpg differ
diff --git a/ml-dev/CAMERA-README.txt b/ml-dev/CAMERA-README.txt
new file mode 100644
index 0000000..f0213bb
--- /dev/null
+++ b/ml-dev/CAMERA-README.txt
@@ -0,0 +1,25 @@
+M-Film for the camera (Film OS + Magic Lantern)
+================================================
+
+What is in here: autoexec.bin, the ML/ folder and ML-SETUP.FIR, for ONE camera model and
+ONE Canon firmware version (the zip's name says which, e.g. 650D.104 = EOS 650D, firmware 1.0.4).
+
+Only the EOS M build has been tried on a camera. The others build, but nobody has tried them yet:
+read TESTING.md at https://github.com/HNGSeries/M-Film before you use one.
+
+Install
+ 1. Check the camera's Canon firmware (MENU > the last settings tab > Firmware ver.).
+ It must be the version in this zip's name. If not, update Canon's firmware first.
+ 2. Copy everything in this zip to the root of a freshly formatted card.
+ If the camera already has Magic Lantern on that card, copying is enough: go to step 4.
+ 3. First time only: put the card in the camera, MENU > Firmware ver. > update, and follow the
+ screen. This sets the camera to start Magic Lantern from the card.
+ 4. Switch the camera on. The film shelf appears once the camera has started.
+
+If the camera doesn't start (black screen, card light stays on): take the battery out, take the
+card out, and the camera starts normally without it. Tell us (see TESTING.md).
+
+Remove: format the card in the camera, or delete autoexec.bin and ML/.
+Logs for a bug report: ML/FILMROLL.LOG on the card.
+
+Free software (GPL-2.0). Buy the developer a coffee: https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02
diff --git a/ml-dev/build_fork.sh b/ml-dev/build_fork.sh
new file mode 100644
index 0000000..bb9a220
--- /dev/null
+++ b/ml-dev/build_fork.sh
@@ -0,0 +1,97 @@
+#!/usr/bin/env bash
+# Build the film-mode ML fork inside WSL (or any Linux) and collect the card
+# files (autoexec.bin + ML/ folder, ready to copy to the card).
+#
+# build_fork.sh EOS M -> ml-dev/out/fork/
+# build_fork.sh 650D.104 another camera -> ml-dev/out/fork-650D.104/
+#
+# The cameras are the folders under platform/ in magiclantern_simplified; the
+# ones M-Film knows are listed in CAMERAS (ml-dev/cameras.txt).
+set -euo pipefail
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+SRC="${ML_SRC:-$HOME/ml/magiclantern_simplified}"
+PLAT="${1:-EOSM.202}"
+if [ "$PLAT" = "EOSM.202" ]; then OUT="$HERE/out/fork"; else OUT="$HERE/out/fork-$PLAT"; fi
+LOG="${LOG:-$HOME/ml/build_fork_$PLAT.log}"
+
+cp "$HERE"/fork/src/filmroll.{c,h} "$HERE"/filmos/fos*.{c,h} "$SRC/src/"
+sed -i 's/\r$//' "$SRC"/src/filmroll.{c,h} "$SRC"/src/fos*.{c,h}
+# M-Film's version, one for the camera and the program (VERSION at the top of the repository)
+VERSION=$(tr -d ' \r\n' < "$HERE/../VERSION")
+printf '#define MFILM_VERSION "%s"\n' "$VERSION" > "$SRC/src/fos_version.h"
+echo "M-Film $VERSION"
+python3 "$HERE/fork/apply_fork.py" "$SRC" "$PLAT"
+
+cd "$SRC/platform/$PLAT"
+make clean >/dev/null
+make -j"$(nproc)" FATAL_WARNINGS=y > "$LOG" 2>&1 || true
+grep -E "error:|warning:" "$LOG" | grep -v "#warning FIXME" || true
+
+ZIP=$(ls -t build/*.zip 2>/dev/null | head -1 || true)
+if [ -z "$ZIP" ]; then
+ echo "no zip produced, see $LOG; its end:"
+ tail -60 "$LOG"
+ exit 1
+fi
+
+# What autoexec.bin takes at boot: the camera gives ML everything from
+# RESTARTSTART to the end of its bss out of Canon's own memory, and with too
+# much it hangs at power on (card LED stays lit). The limit is known only
+# where someone has found it on the camera (cameras.txt): on the EOS M,
+# 727072 bytes is the largest build known to start (2026-10).
+LIMIT=$(awk -v p="$PLAT" '$1 == p { print $3 }' "$HERE/cameras.txt")
+RESTART=$(sed -n 's/^RESTARTSTART *= *//p' Makefile)
+BSS_END=0x$(arm-none-eabi-nm build/magiclantern | awk '$3 == "_bss_end" { print $1 }')
+USED=$((BSS_END - RESTART))
+if [ -n "$LIMIT" ] && [ "$LIMIT" != "-" ]; then
+ echo "ML takes $USED bytes at boot (limit $LIMIT)"
+ if [ "$USED" -gt "$LIMIT" ]; then
+ echo "TOO BIG: the camera may not start. Move code or data out of autoexec.bin."
+ exit 1
+ fi
+else
+ echo "ML takes $USED bytes at boot (no limit known for $PLAT yet: if the camera hangs at power on, it is too big)"
+fi
+mkdir -p "$HERE/out" && echo "$USED" > "$HERE/out/.size-$PLAT"
+
+rm -rf "$OUT" && mkdir -p "$OUT"
+(cd "$OUT" && unzip -q "$SRC/platform/$PLAT/$ZIP")
+
+# the film OS fonts, loaded from the card after boot
+gcc -O2 -I"$HERE/filmos" -o "$HOME/ml/fontblob" "$HERE/filmos/tools/fontblob.c"
+mkdir -p "$OUT/ML/data"
+"$HOME/ml/fontblob" "$OUT/ML/data/FOSFONT.BIN"
+
+# the films beyond the built-in eight (films/films.py, tools/catalog.py)
+F="$HERE/filmos"
+python3 "$F/tools/genfilms.py" "$OUT/ML/data/FOSFILMS.BIN"
+
+# the donation links in donate.txt as QR codes (needs segno: pip install segno)
+python3 -c "import segno" 2>/dev/null || pip install -q segno
+python3 "$F/tools/genqr.py" "$HERE/donate.txt" "$OUT/ML/data/FOSQR.BIN"
+
+# every film's colour table, so the darkroom never spends its first
+# develop of a film mixing one (the camera checks they match its looks):
+# mixed from the look, then baked from the film's LUT where it has one
+# (films/getluts.py fetches the Film-Luts ones; your own go in films/luts/)
+[ -d "$HERE/films/luts/filmluts" ] || python3 "$HERE/films/getluts.py"
+gcc -O2 -std=gnu99 -DFOS_DEV_TEST -I"$F" -o "$HOME/ml/devtest" "$F"/sim/devtest.c "$F"/sim/port_files.c \
+ "$F"/sim/films.c "$F"/fos_dev.c "$F"/fos_looks.c "$F"/fos_film.c "$F"/fos_gfx.c "$F"/fos_jpeg.c -lm
+mkdir -p "$OUT/ML/DARKROOM"
+FOS_FILMS="$OUT/ML/data/FOSFILMS.BIN" "$HOME/ml/devtest" -T "$OUT/ML/DARKROOM"
+python3 "$F/tools/genfilms.py" "$OUT/ML/data/FOSFILMS.BIN" --tables "$OUT/ML/DARKROOM"
+
+# the shelf's samples (PLAY on the shelf): one photo developed with every
+# film, with the tables above, as the camera's darkroom would. EOS M only for now.
+if [ "$PLAT" = "EOSM.202" ]; then
+ mkdir -p "$OUT/ML/SAMPLES"
+ FOS_FILMS="$OUT/ML/data/FOSFILMS.BIN" FOS_LUT_DIR="$OUT/ML/DARKROOM" \
+ "$HOME/ml/devtest" -S "$HERE/films/sample/SAMPLE.CR2" "$OUT/ML/SAMPLES"
+fi
+echo "== card files in $OUT =="
+(cd "$OUT" && find . -maxdepth 3 | sort | head -60)
+
+# keep the fork's source changes next to the project
+(cd "$SRC" && git add -A src/filmroll.c src/filmroll.h src/fos*.c $(ls src/fos*.h | grep -v fos_version.h) && git diff ed3e7c0df -- src platform > "$HERE/fork/film-mode.patch")
+echo "patch: $HERE/fork/film-mode.patch"
diff --git a/ml-dev/build_module.sh b/ml-dev/build_module.sh
new file mode 100644
index 0000000..7295665
--- /dev/null
+++ b/ml-dev/build_module.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+# Copy the filmroll module into the ML tree in WSL, build it, and copy the
+# .mo back to ml-dev/out/ so it can go on the card (ML/MODULES/).
+set -euo pipefail
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+SRC="$HOME/ml/magiclantern_simplified"
+
+mkdir -p "$SRC/modules/filmroll" "$HERE/out"
+cp "$HERE"/filmroll/{filmroll.c,Makefile,README.rst} "$SRC/modules/filmroll/"
+sed -i 's/\r$//' "$SRC"/modules/filmroll/{filmroll.c,Makefile,README.rst}
+
+cd "$SRC/modules/filmroll"
+make clean >/dev/null
+make FATAL_WARNINGS=y
+cp build/filmroll.mo "$HERE/out/"
+
+echo
+echo "Undefined symbols (must all exist in ML/MODULES/EOSM_202.sym on the card):"
+arm-none-eabi-nm -u build/filmroll.mo | awk '{print $2}' | while read -r s; do
+ grep -q " $s\$" "$SRC/platform/EOSM.202/build/EOSM_202.sym" && echo " ok $s" || echo " MISSING $s"
+done
+ls -l "$HERE/out/filmroll.mo"
diff --git a/ml-dev/cameras.txt b/ml-dev/cameras.txt
new file mode 100644
index 0000000..929a586
--- /dev/null
+++ b/ml-dev/cameras.txt
@@ -0,0 +1,39 @@
+# The cameras Magic Lantern runs on, and where M-Film is on each.
+# platform status boot-limit name
+# status: working tried on the camera, works
+# testing builds; waiting for someone to try it on the camera
+# planned not started yet, but should be possible
+# no not for now: Magic Lantern itself is experimental there (DIGIC 6 and later)
+# boot-limit: the largest autoexec.bin (bytes at boot) known to start on it, - if not known yet
+EOSM.202 working 727072 Canon EOS M
+100D.101 testing - Canon EOS 100D / Rebel SL1 / Kiss X7
+650D.104 testing - Canon EOS 650D / Rebel T4i / Kiss X6i
+700D.115 testing - Canon EOS 700D / Rebel T5i / Kiss X7i
+6D.116 testing - Canon EOS 6D
+70D.112 testing - Canon EOS 70D
+5D3.113 testing - Canon EOS 5D Mark III (firmware 1.1.3)
+5D3.123 testing - Canon EOS 5D Mark III (firmware 1.2.3)
+550D.109 testing - Canon EOS 550D / Rebel T2i / Kiss X4
+600D.102 testing - Canon EOS 600D / Rebel T3i / Kiss X5
+60D.111 testing - Canon EOS 60D
+1100D.105 testing - Canon EOS 1100D / Rebel T3 / Kiss X50
+500D.111 testing - Canon EOS 500D / Rebel T1i / Kiss X3
+50D.109 testing - Canon EOS 50D
+5D2.212 testing - Canon EOS 5D Mark II
+7D.203 no - Canon EOS 7D (Magic Lantern's current source doesn't build it)
+200D.101 no - Canon EOS 200D / Rebel SL2
+750D.110 no - Canon EOS 750D / Rebel T6i
+77D.110 no - Canon EOS 77D
+80D.103 no - Canon EOS 80D
+7D2.112 no - Canon EOS 7D Mark II
+5D4.133 no - Canon EOS 5D Mark IV
+5DSR.112 no - Canon EOS 5DS R
+6D2.111 no - Canon EOS 6D Mark II
+850D.100 no - Canon EOS 850D / Rebel T8i
+M50.110 no - Canon EOS M50
+R.180 no - Canon EOS R
+RP.160 no - Canon EOS RP
+R5.152 no - Canon EOS R5
+R6.150 no - Canon EOS R6
+SX70.111 no - Canon PowerShot SX70 HS
+SX740.102 no - Canon PowerShot SX740 HS
diff --git a/ml-dev/donate.txt b/ml-dev/donate.txt
new file mode 100644
index 0000000..b6c091d
--- /dev/null
+++ b/ml-dev/donate.txt
@@ -0,0 +1,7 @@
+# Donation links shown as QR codes on the camera: Settings > System >
+# Support M-FILM. Up to two lines, "Label URL"; the build turns them into
+# ML/DATA/FOSQR.BIN (filmos/tools/genqr.py). With none, the panel says thanks.
+#
+# Stripe https://buy.stripe.com/...
+# PayPal https://paypal.me/...
+Buy the developer a coffee https://buy.stripe.com/7sY14p8d93QE5Ny5M58so02
diff --git a/ml-dev/filmos/fonts/Barlow-Bold.ttf b/ml-dev/filmos/fonts/Barlow-Bold.ttf
new file mode 100644
index 0000000..2f20cbe
Binary files /dev/null and b/ml-dev/filmos/fonts/Barlow-Bold.ttf differ
diff --git a/ml-dev/filmos/fonts/Barlow-Medium.ttf b/ml-dev/filmos/fonts/Barlow-Medium.ttf
new file mode 100644
index 0000000..d546e7a
Binary files /dev/null and b/ml-dev/filmos/fonts/Barlow-Medium.ttf differ
diff --git a/ml-dev/filmos/fonts/Barlow-SemiBold.ttf b/ml-dev/filmos/fonts/Barlow-SemiBold.ttf
new file mode 100644
index 0000000..7c974a4
Binary files /dev/null and b/ml-dev/filmos/fonts/Barlow-SemiBold.ttf differ
diff --git a/ml-dev/filmos/fonts/BarlowCondensed-Bold.ttf b/ml-dev/filmos/fonts/BarlowCondensed-Bold.ttf
new file mode 100644
index 0000000..9e480f4
Binary files /dev/null and b/ml-dev/filmos/fonts/BarlowCondensed-Bold.ttf differ
diff --git a/ml-dev/filmos/fonts/BarlowCondensed-ExtraBold.ttf b/ml-dev/filmos/fonts/BarlowCondensed-ExtraBold.ttf
new file mode 100644
index 0000000..d5a6c75
Binary files /dev/null and b/ml-dev/filmos/fonts/BarlowCondensed-ExtraBold.ttf differ
diff --git a/ml-dev/filmos/fonts/BarlowCondensed-Medium.ttf b/ml-dev/filmos/fonts/BarlowCondensed-Medium.ttf
new file mode 100644
index 0000000..eee49eb
Binary files /dev/null and b/ml-dev/filmos/fonts/BarlowCondensed-Medium.ttf differ
diff --git a/ml-dev/filmos/fonts/BarlowCondensed-SemiBold.ttf b/ml-dev/filmos/fonts/BarlowCondensed-SemiBold.ttf
new file mode 100644
index 0000000..9df6657
Binary files /dev/null and b/ml-dev/filmos/fonts/BarlowCondensed-SemiBold.ttf differ
diff --git a/ml-dev/filmos/fonts/OFL.txt b/ml-dev/filmos/fonts/OFL.txt
new file mode 100644
index 0000000..2f22ba6
--- /dev/null
+++ b/ml-dev/filmos/fonts/OFL.txt
@@ -0,0 +1,93 @@
+Copyright 2017 The Barlow Project Authors (https://github.com/jpt/barlow)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/ml-dev/filmos/fos.h b/ml-dev/filmos/fos.h
new file mode 100644
index 0000000..f11c0a0
--- /dev/null
+++ b/ml-dev/filmos/fos.h
@@ -0,0 +1,235 @@
+/* fos: the film OS - the EOS M's own user interface on top of Magic Lantern.
+ *
+ * Everything the user sees (film shelf, home, settings, roll status,
+ * transitions) lives in fos_ui.c and draws with fos_gfx. It talks to the
+ * camera only through the fos_port_* functions below, which filmroll.c
+ * implements on the camera and sim/sim.c implements on a PC.
+ */
+
+#ifndef _fos_h_
+#define _fos_h_
+
+#include "fos_gfx.h"
+#include <stdio.h>
+#include <string.h>
+
+#define FOS_NAME "M" T_DOT "FILM"
+
+/* the first n characters of src (fewer if it is shorter) into dst: the
+ * camera's snprintf is Canon's, which doesn't know "%.5s" */
+static inline char *fos_copy(char *dst, int size, const char *src, int n)
+{
+ int i = 0;
+ for (; i < n && i < size - 1 && src[i]; i++) dst[i] = src[i];
+ if (size > 0) dst[i] = 0;
+ return dst;
+}
+
+/* ---------------------------------------------------------------- films */
+
+#define PS_STANDARD 0x81 /* raw PROP_PICTURE_STYLE values */
+#define PS_LANDSCAPE 0x83
+#define PS_MONO 0x86
+
+/* the shelves the films stand on */
+enum { FOS_GROUP_COLOUR, FOS_GROUP_SLIDE, FOS_GROUP_BW, FOS_GROUP_CINE, FOS_NGROUPS };
+extern const char *const fos_group_names[FOS_NGROUPS];
+
+/* a canister label drawn from parts (the films from ML/DATA/FOSFILMS.BIN;
+ * the built-in ones have their own painting in fos_film.c). An ink is a
+ * ramp and a level. */
+enum { FOS_LABEL_BAND, FOS_LABEL_CAP, FOS_LABEL_STRIPES };
+struct fos_label
+{
+ uint8_t style;
+ uint8_t leader; /* level of a grey (B&W) leader, 0 = colour film */
+ uint8_t bg[2], band[2], accent[2], text[2], num[2];
+ char top[20]; /* small, above the name */
+ char word[14]; /* the name */
+ char num_s[8]; /* big: digits and H, P, T */
+ char sub[18]; /* small, under the number */
+};
+
+struct fos_film
+{
+ const char *key; /* must match films/films.py */
+ const char *brand;
+ const char *name;
+ const char *process; /* "C-41", "E-6", "B&W" */
+ const char *desc;
+ int box_iso; /* rated speed */
+ int iso; /* what the camera is set to (EOS M has no ISO 50) */
+ int picstyle; /* in-camera preview only; the look comes from the lab */
+ int contrast, saturation, color_tone, sharpness;
+ int kelvin;
+ int wbs_gm; /* + green, - magenta (-9..9) */
+ int wbs_ba; /* + amber, - blue (-9..9) */
+ uint8_t grain, punch, colour, warmth; /* 1..5, for the shelf */
+ const char *shortname; /* in folder names: "Portra400" */
+ int group; /* FOS_GROUP_* */
+ const struct fos_label *label; /* NULL: painted by hand */
+};
+
+/* the built-in films, then those from ML/DATA/FOSFILMS.BIN once loaded */
+extern const struct fos_film *fos_films;
+extern int fos_nfilms;
+#define FOS_FILM_FILE "FOSFILMS.BIN"
+/* blob: the file's contents, kept while the films are used; 1 when usable */
+int fos_films_load(const uint8_t *blob, int size);
+
+extern const int fos_exposure_choices[]; /* 36, 24, 12 */
+#define FOS_NEXP 3
+
+/* f-numbers x100 in 1/3 stops; see fos_film.c */
+extern const int fos_fstops[];
+extern const int fos_nfstops;
+void fos_format_fstop(char *buf, int size, int index);
+
+/* ---------------------------------------------------------------- keys */
+
+enum
+{
+ FK_NONE,
+ FK_LEFT, FK_RIGHT, FK_UP, FK_DOWN, /* the four presses of the rear dial */
+ FK_WHEEL_L, FK_WHEEL_R, /* turning it */
+ FK_SET, FK_MENU, FK_INFO, FK_PLAY,
+ FK_HOME, /* what used to open the ML menu */
+ FK_RELEASE = 0x100, /* or-ed in: a press above ended */
+};
+
+/* ---------------------------------------------------------------- settings */
+
+enum
+{
+ FS_HUD, FS_LEDS, FS_FOCUS, FS_WIND,
+ FS_APKEYS, FS_LENS_WIDE, FS_FSTOP,
+ FS_STARTUP, FS_PLAYLOCK, FS_BOOTANIM, FS_DEBUG,
+ FS_FILM, FS_EXP,
+ FS_SCR_STD, /* screen colour: 0 Canon's conversion, 1 Rec.709 */
+ FS_SCR_SAT, FS_SCR_WARM, FS_SCR_BRIGHT, /* -FOS_SCR_STEPS..FOS_SCR_STEPS */
+ FS_COUNT
+};
+#define FOS_SCR_STEPS 6
+
+enum
+{
+ FA_LOAD, /* a = film, b = exposure choice */
+ FA_REWIND, /* end the roll in the camera */
+ FA_REAPPLY, /* film settings again (after changing WB by hand) */
+ FA_CANON_MENU, /* leave and open Canon's menu */
+ FA_BUSY, /* a = 1: long work (developing) begins, keep the camera awake; 0: done */
+};
+
+#define FOS_RECENT 5
+struct fos_roll
+{
+ int loaded;
+ int number;
+ int film;
+ int exposures;
+ int shot;
+ int need_wind;
+ char loaded_at[20]; /* "2026-08-08 09:10" */
+ int nrecent; /* newest first */
+ struct { int no; char time[6]; char fstop[6]; } recent[FOS_RECENT];
+};
+
+/* screens fos_ui_run can open on; BOOT_LV plays the boot animation and
+ * goes straight back to the camera */
+enum { FOS_OPEN_SHELF, FOS_OPEN_HOME, FOS_OPEN_BOOT, FOS_OPEN_BOOT_LV,
+ FOS_OPEN_PRINTS, /* PLAY: the latest prints */
+ FOS_OPEN_END, /* the roll has just been finished */
+ FOS_OPEN_DARKROOM };
+
+/* ---------------------------------------------------------------- the port */
+
+int fos_port_ms();
+void fos_port_sleep(int ms);
+int fos_port_key(); /* next key event, FK_NONE if none */
+int fos_port_abort(); /* leave right away (half-shutter, power off) */
+void fos_port_present(const uint8_t *rows, int pitch, int y0, int y1); /* rows = row y0 */
+void fos_port_palette(); /* load fos_pal[1..254] */
+void *fos_port_alloc(int size); /* big, temporary buffers */
+void fos_port_free(void *p);
+/* files on the card, for developing; fos_port_open returns NULL on failure */
+void *fos_port_open(const char *path, int write);
+int fos_port_read(void *f, void *buf, int size); /* bytes read */
+int fos_port_write(void *f, const void *buf, int size); /* bytes written */
+int fos_port_seek(void *f, int offset); /* from the start; < 0 on failure */
+void fos_port_close(void *f);
+const char *fos_port_card(); /* the card's root, ending in '/' */
+/* every entry of a directory, until fn returns 0; < 0 if it can't be read */
+int fos_port_list(const char *dir, int (*fn)(void *ctx, const char *name, int is_dir), void *ctx);
+int fos_port_mkdir(const char *path); /* 0 on success or if it exists */
+
+void fos_port_roll(struct fos_roll *r);
+int fos_port_get(int setting);
+void fos_port_set(int setting, int value);
+void fos_port_action(int action, int a, int b);
+void fos_port_clock(char *buf, int size); /* "14:32" */
+int fos_port_lens_manual();
+const char *fos_port_lens_name();
+const char *fos_port_version();
+const char *fos_port_model(); /* "Canon EOS M": the camera it runs on */
+/* photographs: palette entries 1..n become pal's colours at k/256 of
+ * their brightness, FOS_FIXED_BASE.. the fixed overlay colours (fos_dev.h);
+ * fos_port_palette() goes back to the film OS's own */
+void fos_port_photo(const uint8_t (*pal)[3], int n, int k);
+void fos_port_log(const char *msg); /* the debug log, if it is on */
+/* developing works in slices until a time budget is spent; the simulator's
+ * clock stands still meanwhile, so it caps the slices instead (0: no cap) */
+int fos_port_dev_cap();
+
+/* frame times, summed over about a second of animation; open_ms is how
+ * long the film OS took to show its first frame (first report only) */
+struct fos_stat { int frames, draw_ms, present_ms, rest_ms, worst_ms, open_ms, cans_ms; }; /* cans_ms: part of draw_ms */
+void fos_port_stat(const struct fos_stat *s); /* keep it, don't log while animating */
+
+/* ---------------------------------------------------------------- the viewfinder HUD */
+
+/* what the HUD shows; fos_hud.c draws it with Canon's palette */
+struct fos_hud
+{
+ int lit; /* LEDs on (half-press, or always) */
+ int blink; /* 0/1, toggles a few times a second */
+ int meter; /* the meter has a reading */
+ int fstop, widest, want; /* indices into fos_fstops; want = what the meter asks for */
+ char shutter[12]; /* "125", "2\"", "0.5\"" */
+ int frame, exposures, finished, need_wind;
+ int focus_screen;
+ const char *film;
+};
+
+struct fos_hud_palette
+{
+ uint8_t clear, black, white, red, dark_red;
+ uint8_t gray[101]; /* percent -> index */
+};
+
+void fos_hud_draw(uint8_t *vram, int pitch, const struct fos_hud *h, const struct fos_hud_palette *p);
+void fos_hud_clear(uint8_t *vram, int pitch, const struct fos_hud_palette *p);
+
+/* ---------------------------------------------------------------- the UI */
+
+void fos_ui_init();
+void fos_ui_run(int screen);
+
+/* canister art, fos_film.c; quality 2 = everything, 1 = no texture
+ * filtering, 0 = no reflections either (the UI lowers it on a slow camera) */
+extern int fos_can_quality;
+struct fos_can;
+struct fos_can *fos_can_new(int film, int exposures);
+void fos_can_free(struct fos_can *c);
+void fos_can_set_exposures(struct fos_can *c, int exposures);
+
+/* draw a canister standing on floor_y, centred on cx (1/256 px);
+ * scale 256 = full size, rot = turn (0..65535, 0 = label to the front),
+ * light 0..256 dims it for depth, leader 0 = none, 256 = the usual tongue,
+ * more = pulled further out, reflect 0..256 = its mirror image in the floor,
+ * fast = moving too quickly to need the label filtered between texels */
+struct fos_can_pose { int cx8, floor_y, scale, rot, light, leader, reflect, fast; };
+void fos_can_draw(struct fos_canvas *cv, struct fos_can *c, const struct fos_can_pose *p);
+int fos_can_height(int scale);
+int fos_can_width(int scale);
+
+#endif
diff --git a/ml-dev/filmos/fos_dark.c b/ml-dev/filmos/fos_dark.c
new file mode 100644
index 0000000..0058dd4
--- /dev/null
+++ b/ml-dev/filmos/fos_dark.c
@@ -0,0 +1,1313 @@
+/* fos_dark: the darkroom.
+ *
+ * Rolls that have been shot and rewound wait here to be developed. The
+ * camera develops them itself (fos_dev.c), a slice at a time between the
+ * frames of a darkroom scene under the red safelight: the latent image
+ * comes up on the paper in the tray, the print darkens to its full depth,
+ * and goes up on the line to dry. The prints are looked at here as well,
+ * each on its own palette, and PLAY comes here too: nothing undeveloped is
+ * ever shown.
+ */
+
+#include "fos_ui.h"
+#include "fos_dev.h"
+#include <string.h>
+
+#define MAX_ROLLS 48
+
+/* The darkroom's lists live in memory taken while the film OS is up, not
+ * in autoexec.bin: on the EOS M every byte of that is taken from Canon's
+ * own memory at boot. */
+static struct dark_mem
+{
+ struct fos_lab_roll rolls[MAX_ROLLS];
+ uint8_t marked[MAX_ROLLS];
+ int queue[MAX_ROLLS];
+ struct fos_lab_frame frames[FOS_MAX_FRAMES], meta[FOS_MAX_FRAMES];
+ char paths[FOS_MAX_FRAMES][64];
+ struct fos_print print;
+} *dm;
+#define rolls (dm->rolls)
+#define marked (dm->marked)
+#define queue (dm->queue)
+#define pv_meta (dm->meta)
+#define pv_print (dm->print)
+
+static int nrolls;
+
+static int dark_mem()
+{
+ if (!dm && (dm = fos_port_alloc(sizeof(*dm)))) memset(dm, 0, sizeof(*dm));
+ return dm != 0;
+}
+
+void dark_free()
+{
+ fos_port_free(dm);
+ dm = 0;
+}
+
+static void rescan()
+{
+ nrolls = dm ? fos_lab_scan(rolls, MAX_ROLLS) : 0;
+}
+
+static int roll_index(int number)
+{
+ for (int i = 0; i < nrolls; i++)
+ if (rolls[i].number == number) return i;
+ return -1;
+}
+
+/* developed: every frame has its print and the contact sheet is there;
+ * waiting: shot, out of the camera, and a print or the sheet missing
+ * (developing again skips the prints already made) */
+/* developed: every frame printed, and every print in DCIM as a JPEG */
+static int is_developed(const struct fos_lab_roll *r) { return r->sheet && r->developed >= r->shot && r->jpegs >= r->developed; }
+static int is_waiting(const struct fos_lab_roll *r) { return !is_developed(r) && !r->in_camera && r->shot > 0; }
+static int has_prints(const struct fos_lab_roll *r) { return r->sheet || r->developed > 0; }
+
+/* about how long a frame takes, measured while developing */
+static int ms_per_frame = 15000;
+
+static void format_eta(char *buf, int size, int frames, int extra_ms)
+{
+ int s = (int) (((int64_t) frames * ms_per_frame + extra_ms) / 1000);
+ if (s < 60) snprintf(buf, size, "under a minute");
+ else if (s < 90 * 60) snprintf(buf, size, "about %d min", (s + 30) / 60);
+ else snprintf(buf, size, "about %d h %02d min", s / 3600, (s % 3600 + 30) / 60);
+}
+
+static const char *short_date(const char *when)
+{
+ /* "2026-10-22 17:45" -> "22 Oct 2026" */
+ static const char *const mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+ static char b[16];
+ int m = (when[5] - '0') * 10 + (when[6] - '0');
+ if (strlen(when) < 10 || m < 1 || m > 12) return "";
+ char year[5];
+ snprintf(b, sizeof(b), "%c%c %s %s", when[8] == '0' ? ' ' : when[8], when[9], mon[m - 1], fos_copy(year, sizeof(year), when, 4));
+ return b[0] == ' ' ? b + 1 : b;
+}
+
+/* ================================================================ the list */
+
+static int dk_sel;
+static struct spring dk_hl, dk_scroll;
+static int dk_hints_for = -1; /* the hints show what SET does on this row */
+
+#define DK_X 24
+#define DK_W 672
+#define DK_Y 124
+#define DK_ROW 60
+#define DK_ROWS 5
+
+static int count_waiting(int *frames)
+{
+ int n = 0, f = 0;
+ for (int i = 0; i < nrolls; i++)
+ if (is_waiting(&rolls[i])) { n++; f += rolls[i].shot - (rolls[i].jpegs < rolls[i].developed ? rolls[i].jpegs : rolls[i].developed); }
+ if (frames) *frames = f;
+ return n;
+}
+
+static int count_marked()
+{
+ int n = 0;
+ for (int i = 0; i < nrolls; i++) n += marked[i] && is_waiting(&rolls[i]);
+ return n;
+}
+
+static void dark_bake()
+{
+ ui_bg_plain();
+ ui_to_bg(1);
+ ui_status_bar("DARKROOM");
+ fos_text(cv, &fos_font_lg, DK_X, 82, "Darkroom", C_TEXT, OPAQUE, 0);
+ char b[96], eta[32];
+ int frames, waiting = count_waiting(&frames);
+ if (!nrolls)
+ snprintf(b, sizeof(b), "No rolls yet " T_MDASH " finish one, rewind it, and it waits here.");
+ else if (waiting)
+ {
+ format_eta(eta, sizeof(eta), frames, 0);
+ snprintf(b, sizeof(b), "%d roll%s to develop " T_DOT " %d frames " T_DOT " %s", waiting, waiting > 1 ? "s" : "", frames, eta);
+ }
+ else
+ snprintf(b, sizeof(b), "Everything is developed " T_DOT " %d roll%s of prints", nrolls, nrolls > 1 ? "s" : "");
+ int w = fos_text(cv, &fos_font_sm, DK_X, 106, b, C_TEXT3, OPAQUE, 0);
+ /* the camera takes its time; a computer doesn't */
+ if (waiting && w + 260 < DK_W)
+ fos_text_r(cv, &fos_font_sm, DK_X + DK_W, 106, "Faster: Darkrooms on a computer", C_ACCENT2, OPAQUE, 0);
+ ui_to_bg(0);
+}
+
+static void dark_hints()
+{
+ const struct fos_lab_roll *r = nrolls ? &rolls[dk_sel] : 0;
+ int nm = count_marked();
+ char dev[32];
+ if (nm) snprintf(dev, sizeof(dev), "Develop %d", nm);
+ else snprintf(dev, sizeof(dev), "Develop all");
+ struct hint h[4];
+ int n = 0;
+ if (r && is_waiting(r)) h[n++] = (struct hint) { "SET", marked[dk_sel] ? "Unmark" : "Mark" };
+ else if (r && has_prints(r)) h[n++] = (struct hint) { "SET", "Prints" };
+ if (count_waiting(0)) h[n++] = (struct hint) { "INFO", dev };
+ h[n++] = (struct hint) { "PLAY", "Prints" };
+ h[n++] = (struct hint) { "MENU", "Back" };
+ ui_bg_restore(0, HINTS_Y, FOS_W, FOS_H - HINTS_Y);
+ ui_hints(h, n);
+ dk_hints_for = dk_sel * 2 + marked[dk_sel];
+}
+
+void dark_enter(int arg)
+{
+ fos_port_roll(&ui_roll);
+ dark_mem();
+ rescan();
+ if (dm) memset(marked, 0, sizeof(marked));
+ int i = arg ? roll_index(arg) : -1;
+ if (i < 0)
+ {
+ /* the newest roll waiting, else the newest */
+ i = 0;
+ for (int k = 0; k < nrolls; k++)
+ if (is_waiting(&rolls[k])) { i = k; break; }
+ }
+ dk_sel = i;
+ dk_hl.x = (float) dk_sel; dk_hl.v = 0;
+ dk_scroll.x = (float) fos_clamp(dk_sel - DK_ROWS / 2, 0, nrolls > DK_ROWS ? nrolls - DK_ROWS : 0);
+ dk_scroll.v = 0;
+ dk_hints_for = -1;
+ dark_bake();
+}
+
+void dark_queue_clear();
+void dark_queue_add(int roll);
+
+static void dark_develop()
+{
+ /* the marked rolls, or every one waiting; oldest first */
+ int nm = count_marked();
+ dark_queue_clear();
+ for (int i = nrolls - 1; i >= 0; i--)
+ if (is_waiting(&rolls[i]) && (!nm || marked[i])) dark_queue_add(rolls[i].number);
+ ui_go(SCR_DEVELOP, 0, GO_FADE);
+}
+
+void dark_key(int k)
+{
+ if (!dm)
+ {
+ if (k == FK_MENU) ui_go(SCR_HOME, 2, GO_POP);
+ return;
+ }
+ const struct fos_lab_roll *r = nrolls ? &rolls[dk_sel] : 0;
+ switch (k)
+ {
+ case FK_UP: case FK_WHEEL_L:
+ if (dk_sel > 0) dk_sel--;
+ break;
+ case FK_DOWN: case FK_WHEEL_R:
+ if (dk_sel < nrolls - 1) dk_sel++;
+ break;
+ case FK_SET: case FK_RIGHT:
+ if (!r) break;
+ if (r->in_camera) ui_toast("Still in the camera " T_MDASH " rewind it first");
+ else if (is_waiting(r) && k == FK_SET) marked[dk_sel] ^= 1;
+ else if (has_prints(r)) ui_go(SCR_PRINTS, r->number, GO_FADE);
+ break;
+ case FK_INFO:
+ if (count_waiting(0)) dark_develop();
+ else ui_toast(nrolls ? "Nothing to develop" : "No rolls yet");
+ break;
+ case FK_PLAY:
+ ui_go(SCR_PRINTS, r && has_prints(r) ? r->number : 0, GO_FADE);
+ break;
+ case FK_MENU:
+ ui_go(SCR_HOME, 2, GO_POP);
+ break;
+ case FK_HOME:
+ ui_leave();
+ break;
+ }
+ ui_damage(DK_Y - 4, FOS_H);
+}
+
+int dark_update(int dt)
+{
+ int moving = 0;
+ float top = (float) fos_clamp(dk_sel - DK_ROWS / 2, 0, nrolls > DK_ROWS ? nrolls - DK_ROWS : 0);
+ moving |= spring_step(&dk_hl, (float) dk_sel, dt, 3.4f, 0.82f);
+ moving |= spring_step(&dk_scroll, top, dt, 2.6f, 0.9f);
+ if (moving) ui_damage(DK_Y - 4, DK_Y + DK_ROWS * DK_ROW + 4);
+ return moving;
+}
+
+/* a round mark: empty, or filled with a tick */
+static void mark_dot(int cx, int cy, int on)
+{
+ if (on)
+ {
+ fos_disc(cv, cx * 256, cy * 256, 10 * 256, C_ACCENT, OPAQUE);
+ fos_line(cv, (cx - 5) * 256, cy * 256, (cx - 1) * 256, (cy + 4) * 256, 2 * 256, FC(RAMP_GRAY, 12), OPAQUE);
+ fos_line(cv, (cx - 1) * 256, (cy + 4) * 256, (cx + 6) * 256, (cy - 4) * 256, 2 * 256, FC(RAMP_GRAY, 12), OPAQUE);
+ }
+ else fos_ring(cv, cx * 256, cy * 256, 10 * 256, 2 * 256, FC(RAMP_GRAY, 90), OPAQUE);
+}
+
+static void dark_row(int i, int y)
+{
+ const struct fos_lab_roll *r = &rolls[i];
+ int sel = i == dk_sel;
+ int x = DK_X + 20;
+ if (is_waiting(r)) mark_dot(x + 12, y + DK_ROW / 2, marked[i]);
+ else ui_icon(r->in_camera ? ICON_FILM : ICON_PRINTS, x + 12, y + DK_ROW / 2, sel ? C_TEXT2 : C_TEXT3, OPAQUE);
+ char b[96];
+ fos_text(cv, &fos_font_mdb, x + 42, y + 27, fos_films[r->film].name, sel ? C_TEXT : C_TEXT2, OPAQUE, 0);
+ const char *when = r->last[0] ? r->last : r->loaded;
+ snprintf(b, sizeof(b), "Roll %03d " T_DOT " %d frame%s " T_DOT " %s", r->number, r->shot, r->shot == 1 ? "" : "s", short_date(when));
+ fos_text(cv, &fos_font_sm, x + 42, y + 48, b, C_TEXT3, OPAQUE, 0);
+ fcol c;
+ if (r->in_camera) { snprintf(b, sizeof(b), "IN CAMERA"); c = C_TEXT3; }
+ else if (is_developed(r)) { snprintf(b, sizeof(b), "DEVELOPED"); c = C_TEXT3; }
+ else if (r->developed) { snprintf(b, sizeof(b), "%d OF %d DEVELOPED", r->developed, r->shot); c = C_ACCENT; }
+ else { snprintf(b, sizeof(b), "TO DEVELOP"); c = C_ACCENT; }
+ fos_text_r(cv, &fos_font_xs, DK_X + DK_W - 24, y + 36, b, c, OPAQUE, 48);
+}
+
+void dark_draw()
+{
+ if (ui_clobbered)
+ {
+ ui_clobbered = 0;
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ ui_damage_all();
+ dk_hints_for = -1;
+ }
+ if (!dm)
+ {
+ fos_text_c(cv, &fos_font_md, 360, DK_Y + 120, "Not enough memory for the darkroom.", C_TEXT3, OPAQUE, 0);
+ return;
+ }
+ if (dk_hints_for != dk_sel * 2 + marked[dk_sel]) dark_hints();
+
+ int y0 = DK_Y - 4, y1 = DK_Y + DK_ROWS * DK_ROW + 4;
+ struct fos_canvas save = *cv;
+ ui_bg_restore(0, y0, FOS_W, y1 - y0);
+ fos_clip(cv, 0, DK_Y, FOS_W, DK_Y + DK_ROWS * DK_ROW);
+ if (!nrolls)
+ {
+ fos_text_c(cv, &fos_font_md, 360, DK_Y + 120, "Shot rolls appear here once they are rewound.", C_TEXT3, OPAQUE, 0);
+ *cv = save;
+ return;
+ }
+ float top = dk_scroll.x;
+ int hy = DK_Y + (int) ((dk_hl.x - top) * DK_ROW + 0.5f);
+ fos_rrect(cv, DK_X, hy, DK_W, DK_ROW, 12, FC(RAMP_GRAY, 27), OPAQUE);
+ fos_rrect(cv, DK_X, hy + 10, 3, DK_ROW - 20, 1, C_ACCENT, OPAQUE);
+ for (int i = (int) top; i < nrolls && i <= (int) top + DK_ROWS; i++)
+ dark_row(i, DK_Y + (int) ((i - top) * DK_ROW + 0.5f));
+ *cv = save;
+ /* the list goes on: a hint at the edge */
+ if (top > 0.05f) fos_tri(cv, DK_X + DK_W - 14, DK_Y - 8, 8, 3, C_TEXT3, OPAQUE);
+ if (top < nrolls - DK_ROWS - 0.05f) fos_tri(cv, DK_X + DK_W - 14, DK_Y + DK_ROWS * DK_ROW + 6, 8, 1, C_TEXT3, OPAQUE);
+ ui_damage(y0, y1 + 8);
+}
+
+/* ================================================================ developing */
+
+/* the scene, under the safelight */
+#define SL(level) FC(RAMP_RED, level)
+#define SL_TEXT SL(222)
+#define SL_TEXT2 SL(160)
+#define SL_TEXT3 SL(104)
+#define SL_ACCENT FC(RAMP_ORANGE, 200)
+
+/* the tray, the paper in it and the picture on the paper */
+#define TRAY_X 24
+#define TRAY_Y 128
+#define TRAY_W 400
+#define TRAY_H 284
+#define BATH_X (TRAY_X + 12)
+#define BATH_Y (TRAY_Y + 12)
+#define BATH_W (TRAY_W - 24)
+#define BATH_H (TRAY_H - 24)
+#define PAPER_W 348
+#define PAPER_H 240
+#define PAPER_X (TRAY_X + (TRAY_W - PAPER_W) / 2)
+#define PAPER_Y (TRAY_Y + (TRAY_H - PAPER_H) / 2)
+#define IMG_W 324
+#define IMG_H 216
+#define IMG_X (PAPER_X + (PAPER_W - IMG_W) / 2)
+#define IMG_Y (PAPER_Y + (PAPER_H - IMG_H) / 2)
+#define GHOST_W (IMG_W / 2)
+#define GHOST_H (IMG_H / 2)
+#define PAPER_LV 124 /* white paper under the safelight */
+#define BLACK_LV 9
+
+/* the line the prints dry on */
+#define LINE_Y 52
+#define DRY_W 66
+#define DRY_H 44
+#define DRY_STEP 92
+#define DRY_X0 36
+#define DRY_N 7
+
+/* the panel and its timer */
+#define PANEL_CX 572
+#define DIAL_CY2 282
+#define DIAL_R2 58
+
+#define EMERGE_MS 1700
+#define HOLD_MS 900
+#define LIFT_MS 450
+#define SLIDE_MS 450
+#define STEP_MS 60 /* developing per frame while the scene moves */
+#define CALM_MS 250 /* and while it is still: the dial's hand ticks */
+
+static int nqueue, qi;
+static char dcim_dir[128]; /* the roll's JPEG folder, or "" */
+static int nframes, fi, roll_ready;
+static int cur_roll, cur_film, cur_frame;
+static struct fos_dev *dev;
+static int frame_t0;
+static int total_frames, done_frames, failed_frames, rolls_done;
+static int finished, asking_stop;
+static struct spring stop_sheet;
+static int dv_t;
+
+/* the tray: what the paper shows */
+enum { TRAY_LATENT, TRAY_EMERGE, TRAY_HOLD, TRAY_LIFT, TRAY_IN, TRAY_EMPTY };
+static int tray, tray_t;
+static uint8_t *ghost; /* GHOST_W x GHOST_H: the latent image */
+static uint8_t *img; /* IMG_W x IMG_H: the finished print */
+static int ghost_t; /* ms since the latent image was read */
+static int ghost_final; /* read once more when the RAW is through */
+static int pending_frame; /* a print waiting for the tray, 0 = none */
+static char pending_path[64];
+static int tray_dirty = 1, line_dirty = 1, panel_dirty = 1;
+static int last_doing = -1;
+static char last_error[72]; /* why the last frame that failed did */
+
+/* the line: newest first */
+static uint8_t *dry; /* DRY_N x DRY_W x DRY_H */
+static int ndry, dry_t = 100000; /* dry_t: ms since the newest went up */
+
+void dark_queue_clear() { nqueue = 0; }
+void dark_queue_add(int roll) { if (dark_mem() && nqueue < MAX_ROLLS) queue[nqueue++] = roll; }
+
+static int file_exists(const char *path)
+{
+ void *f = fos_port_open(path, 0);
+ if (f) fos_port_close(f);
+ return f != 0;
+}
+
+/* the print's picture, small and grey, for the tray */
+static void load_tray_image(const char *path)
+{
+ struct fos_print p;
+ memset(img, 255, IMG_W * IMG_H);
+ if (!fos_print_load(path, &p)) return;
+ uint8_t lum[FOS_PRINT_COLOURS + 1];
+ lum[0] = 0;
+ for (int i = 0; i < FOS_PRINT_COLOURS; i++)
+ lum[i + 1] = (uint8_t) ((p.pal[i][0] * 77 + p.pal[i][1] * 150 + p.pal[i][2] * 29) >> 8);
+ for (int y = 0; y < IMG_H; y++)
+ {
+ int sy = (2 * y + 1) * FOS_PRINT_H / (2 * IMG_H);
+ for (int x = 0; x < IMG_W; x++)
+ {
+ int sx = (2 * x + 1) * FOS_PRINT_W / (2 * IMG_W);
+ /* the borders of a portrait frame stay white paper */
+ if (sx < p.x0 || sx >= p.x0 + p.w) continue;
+ const uint8_t *s = p.px + sy * FOS_PRINT_W + sx;
+ int k0 = s[0], k1 = s[1], k2 = s[FOS_PRINT_W], k3 = s[FOS_PRINT_W + 1];
+ img[y * IMG_W + x] = (uint8_t) ((lum[k0 > 240 ? 0 : k0] + lum[k1 > 240 ? 0 : k1] + lum[k2 > 240 ? 0 : k2]
+ + lum[k3 > 240 ? 0 : k3]) >> 2);
+ }
+ }
+ fos_print_free(&p);
+}
+
+/* a finished frame's thumbnail onto the line; a portrait frame's sides
+ * are white paper */
+static void hang(const uint8_t *thumb, int x0, int w)
+{
+ if (!dry || !thumb) return;
+ memmove(dry + DRY_W * DRY_H, dry, (DRY_N - 1) * DRY_W * DRY_H);
+ for (int y = 0; y < DRY_H; y++)
+ for (int x = 0; x < DRY_W; x++)
+ {
+ int px = (2 * x + 1) * FOS_PRINT_W / (2 * DRY_W);
+ const uint8_t *s = thumb + 3 * ((y * FOS_THUMB_H / DRY_H) * FOS_THUMB_W + x * FOS_THUMB_W / DRY_W);
+ dry[y * DRY_W + x] = px < x0 || px >= x0 + w ? 255 : (uint8_t) ((s[0] * 77 + s[1] * 150 + s[2] * 29) >> 8);
+ }
+ if (ndry < DRY_N) ndry++;
+ dry_t = 0;
+ line_dirty = 1;
+}
+
+/* the next frame to develop, or the next roll's; the contact sheet when a
+ * roll is through */
+static void next_job()
+{
+ char path[64];
+ while (qi < nqueue)
+ {
+ if (!roll_ready)
+ {
+ cur_roll = queue[qi];
+ int ri = roll_index(cur_roll);
+ cur_film = ri >= 0 ? rolls[ri].film : 0;
+ nframes = fos_lab_frames(cur_roll, dm->frames, FOS_MAX_FRAMES);
+ {
+ char msg[96];
+ int raws = 0;
+ for (int i = 0; i < nframes; i++) raws += !dm->frames[i].missing;
+ snprintf(msg, sizeof(msg), "darkroom: roll %03d (%s): %d frames, %d RAW files", cur_roll,
+ fos_films[cur_film].key, nframes, raws);
+ fos_port_log(msg);
+ }
+ fos_lab_prepare(cur_roll);
+ /* the roll's JPEGs go in DCIM, in a folder named for the day
+ * its first frame was shot and the film */
+ const char *first = 0;
+ for (int i = 0; i < nframes; i++)
+ if (dm->frames[i].when[0] && (!first || strcmp(dm->frames[i].when, first) < 0)) first = dm->frames[i].when;
+ if (fos_lab_dcim_dir(dcim_dir, sizeof(dcim_dir), cur_roll, cur_film, first) < 0)
+ {
+ dcim_dir[0] = 0;
+ fos_port_log("darkroom: no folder for the JPEGs in DCIM");
+ }
+ else
+ {
+ char msg[160];
+ snprintf(msg, sizeof(msg), "darkroom: JPEGs in %s", dcim_dir);
+ fos_port_log(msg);
+ }
+ fi = 0;
+ roll_ready = 1;
+ panel_dirty = 1;
+ }
+ while (fi < nframes)
+ {
+ const struct fos_lab_frame *f = &dm->frames[fi++];
+ fos_lab_print_path(path, sizeof(path), cur_roll, f->no);
+ /* its JPEG in DCIM: IMG_0102.CR2 -> IMG_0102.JPG */
+ char jpeg[160] = "";
+ if (dcim_dir[0])
+ {
+ const char *base = strrchr(f->cr2, '/');
+ char name[9];
+ snprintf(jpeg, sizeof(jpeg), "%s/%s.JPG", dcim_dir, fos_copy(name, sizeof(name), base ? base + 1 : f->cr2, 8));
+ }
+ /* developed before (and, by this version, written to DCIM too) */
+ if (file_exists(path) && (!jpeg[0] || f->missing || file_exists(jpeg))) continue;
+ if (f->missing)
+ {
+ char msg[120];
+ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d: no RAW file %s", cur_roll, f->no, f->cr2);
+ fos_port_log(msg);
+ snprintf(last_error, sizeof(last_error), "No RAW file " T_MDASH " shoot with Image quality RAW");
+ failed_frames++;
+ done_frames++;
+ continue;
+ }
+ cur_frame = f->no;
+ dev = fos_dev_start(f->cr2, path, cur_film, f->no, f->when, f->fstop);
+ if (dev && jpeg[0]) fos_dev_jpeg(dev, jpeg);
+ frame_t0 = ui_now;
+ ghost_t = 100000;
+ ghost_final = 0;
+ memset(ghost, 255, GHOST_W * GHOST_H); /* fresh paper */
+ panel_dirty = 1;
+ if (dev) return;
+ snprintf(last_error, sizeof(last_error), "Not enough memory");
+ failed_frames++;
+ done_frames++;
+ }
+ /* the roll is through: its contact sheet */
+ const char *pp[FOS_MAX_FRAMES];
+ for (int i = 0; i < nframes; i++)
+ {
+ fos_lab_print_path(dm->paths[i], sizeof(dm->paths[i]), cur_roll, i + 1);
+ pp[i] = dm->paths[i];
+ }
+ fos_lab_print_path(path, sizeof(path), cur_roll, 0);
+ if (!fos_dev_sheet(path, cur_film, pp, nframes)) fos_port_log("darkroom: can't write the contact sheet");
+ rolls_done++;
+ qi++;
+ roll_ready = 0;
+ }
+ finished = 1;
+ cur_frame = 0;
+ panel_dirty = 1;
+ fos_dev_release();
+ fos_port_action(FA_BUSY, 0, 0);
+}
+
+static void frame_finished(int ok)
+{
+ char msg[160];
+ int took = ui_now - frame_t0;
+ if (ok)
+ {
+ /* a running mean, the first frames counting fully */
+ ms_per_frame = done_frames - failed_frames < 3 ? took : (ms_per_frame * 3 + took) / 4;
+ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d developed in %d ms", cur_roll, cur_frame, took);
+ fos_port_log(msg);
+ if (!pending_frame)
+ {
+ pending_frame = cur_frame;
+ fos_lab_print_path(pending_path, sizeof(pending_path), cur_roll, cur_frame);
+ }
+ int x0, w;
+ fos_dev_picture(dev, &x0, &w);
+ hang(fos_dev_thumb(dev), x0, w);
+ }
+ else
+ {
+ const char *why = fos_dev_error(dev) && fos_dev_error(dev)[0] ? fos_dev_error(dev) : "stopped without a reason";
+ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d: %s", cur_roll, cur_frame, why);
+ fos_port_log(msg);
+ snprintf(last_error, sizeof(last_error), "Frame %d: %s", cur_frame, why);
+ failed_frames++;
+ }
+ done_frames++;
+ fos_dev_free(dev);
+ dev = 0;
+ panel_dirty = 1;
+}
+
+static void develop_bake()
+{
+ ui_to_bg(1);
+ /* the room: dark, the safelight from above */
+ fos_vgrad(cv, 0, 0, FOS_W, FOS_H, RAMP_RED, LV12(30), LV12(7));
+ fos_text(cv, &fos_font_xs, 24, 26, "DARKROOM", SL_TEXT2, OPAQUE, 64);
+ /* the line */
+ fos_fill(cv, 12, LINE_Y, FOS_W - 24, 2, SL(70));
+ /* the tray and the developer in it */
+ fos_rrect(cv, TRAY_X, TRAY_Y, TRAY_W, TRAY_H, 16, SL(26), OPAQUE);
+ fos_rrect_line(cv, TRAY_X, TRAY_Y, TRAY_W, TRAY_H, 16, 2, SL(48), OPAQUE);
+ fos_rrect(cv, BATH_X, BATH_Y, BATH_W, BATH_H, 10, SL(15), OPAQUE);
+ ui_to_bg(0);
+}
+
+void develop_enter(int arg)
+{
+ if (!dark_mem()) nqueue = 0;
+ rescan();
+ total_frames = done_frames = failed_frames = rolls_done = 0;
+ for (int i = 0; i < nqueue; i++)
+ {
+ int ri = roll_index(queue[i]);
+ if (ri >= 0) total_frames += rolls[ri].shot - rolls[ri].developed;
+ }
+ qi = 0; roll_ready = 0; dev = 0;
+ last_error[0] = 0;
+ finished = nqueue == 0;
+ asking_stop = 0;
+ stop_sheet.x = stop_sheet.v = 0;
+ cur_frame = 0;
+ dv_t = 0;
+ tray = TRAY_LATENT; tray_t = 0;
+ pending_frame = 0;
+ ndry = 0; dry_t = 100000;
+ ghost = fos_port_alloc(GHOST_W * GHOST_H);
+ img = fos_port_alloc(IMG_W * IMG_H);
+ dry = fos_port_alloc(DRY_N * DRY_W * DRY_H);
+ if (ghost) memset(ghost, 255, GHOST_W * GHOST_H);
+ tray_dirty = line_dirty = panel_dirty = 1;
+ last_doing = -1;
+ char dir[64];
+ fos_lab_cache_dir(dir, sizeof(dir));
+ fos_dev_cache(dir);
+ if (!finished) fos_port_action(FA_BUSY, 1, 0);
+ develop_bake();
+}
+
+void develop_leave()
+{
+ if (dev) { fos_dev_free(dev); dev = 0; }
+ if (!finished) fos_port_action(FA_BUSY, 0, 0);
+ finished = 1;
+ fos_dev_release();
+ fos_port_free(ghost); ghost = 0;
+ fos_port_free(img); img = 0;
+ fos_port_free(dry); dry = 0;
+}
+
+void develop_key(int k)
+{
+ if (asking_stop)
+ {
+ if (k == FK_SET) { asking_stop = 0; ui_go(SCR_DARK, cur_roll, GO_FADE); }
+ else if (k == FK_MENU) asking_stop = 0;
+ ui_clobbered = 1;
+ return;
+ }
+ switch (k)
+ {
+ case FK_MENU:
+ if (finished) ui_go(SCR_DARK, cur_roll, GO_FADE);
+ else asking_stop = 1;
+ ui_clobbered = 1;
+ break;
+ case FK_SET: case FK_PLAY:
+ if (finished) ui_go(SCR_PRINTS, nqueue ? queue[0] : 0, GO_FADE);
+ break;
+ case FK_HOME:
+ ui_leave();
+ break;
+ }
+}
+
+int develop_update(int dt)
+{
+ dv_t += dt;
+ if (!ghost || !img || !dry || !dm)
+ {
+ /* no memory for the scene: say so and stop */
+ if (!finished) { finished = 1; fos_port_action(FA_BUSY, 0, 0); ui_toast("Not enough memory to develop"); }
+ return 0;
+ }
+ /* the work: only once the screen has settled, and not while asking */
+ if (!finished && !asking_stop && ui_settled())
+ {
+ if (!dev) next_job();
+ if (dev)
+ {
+ /* the work takes nearly all of a frame when nothing on the
+ * screen moves but the dial's hand */
+ int calm = (tray == TRAY_LATENT || tray == TRAY_EMPTY) && dry_t >= SLIDE_MS + 100
+ && stop_sheet.x < 0.002f;
+ int p = fos_dev_step(dev, calm ? CALM_MS : STEP_MS);
+ if (p >= 0 && p < 1000 && !ghost_final && fos_dev_doing(dev) == FOS_DEV_FIXING)
+ {
+ /* the whole latent image, while it can still be read */
+ ghost_final = 1;
+ if (fos_dev_preview(dev, ghost, GHOST_W, GHOST_H) && (tray == TRAY_LATENT || tray == TRAY_IN)) tray_dirty = 1;
+ }
+ else if (p >= 0 && p < 1000 && ghost_t > 600 && fos_dev_preview(dev, ghost, GHOST_W, GHOST_H))
+ {
+ /* the latent image so far; the paper shows it when it is in the bath */
+ ghost_t = 0;
+ if (tray == TRAY_LATENT || tray == TRAY_IN) tray_dirty = 1;
+ }
+ if (p >= 1000) frame_finished(1);
+ else if (p < 0) frame_finished(0);
+ }
+ }
+
+ /* the tray */
+ tray_t += dt;
+ ghost_t += dt;
+ switch (tray)
+ {
+ case TRAY_LATENT:
+ if (pending_frame)
+ {
+ load_tray_image(pending_path);
+ tray = TRAY_EMERGE; tray_t = 0;
+ tray_dirty = 1;
+ }
+ break;
+ case TRAY_EMERGE:
+ tray_dirty = 1;
+ if (tray_t > EMERGE_MS) { tray = TRAY_HOLD; tray_t = 0; }
+ break;
+ case TRAY_HOLD:
+ if (tray_t > HOLD_MS) { tray = TRAY_LIFT; tray_t = 0; }
+ break;
+ case TRAY_LIFT:
+ tray_dirty = 1;
+ if (tray_t > LIFT_MS)
+ {
+ pending_frame = 0;
+ tray = finished ? TRAY_EMPTY : TRAY_IN;
+ tray_t = 0;
+ ghost_t = 100000;
+ }
+ break;
+ case TRAY_IN:
+ tray_dirty = 1;
+ if (tray_t > SLIDE_MS) { tray = TRAY_LATENT; tray_t = 0; }
+ break;
+ case TRAY_EMPTY:
+ break;
+ }
+ if (finished && tray == TRAY_LATENT && !pending_frame) { tray = TRAY_EMPTY; tray_dirty = 1; }
+ if (dry_t < SLIDE_MS + 100) { dry_t += dt; line_dirty = 1; }
+ else dry_t += dt;
+ int moving = spring_step(&stop_sheet, asking_stop ? 1 : 0, dt, 3.0f, 0.95f);
+ if (moving) ui_clobbered = 1;
+ return 1; /* the timer's hand keeps going */
+}
+
+/* grey levels (paper 255 .. black 0) at density k/256 of their own, as
+ * dithered positions on the red ramp */
+static void density_table(int16_t *pos, int k)
+{
+ for (int l = 0; l < 256; l++)
+ {
+ int d = (255 - l) * k >> 8; /* density 0..255 */
+ int lv = LV12(PAPER_LV) - (LV12(PAPER_LV) - LV12(BLACK_LV)) * d / 255;
+ pos[l] = (int16_t) fos_ramp_pos(RAMP_RED, lv);
+ }
+}
+
+/* the paper and what is on it, its top edge dy below where it rests */
+static void draw_paper(int dy)
+{
+ struct fos_canvas save = *cv;
+ fos_clip(cv, BATH_X, BATH_Y, BATH_X + BATH_W, BATH_Y + BATH_H);
+ ui_bg_restore(BATH_X, BATH_Y, BATH_W, BATH_H);
+ int px = PAPER_X, py = PAPER_Y + dy;
+ /* a soft shadow under it in the bath */
+ fos_rrect(cv, px + 3, py + 4, PAPER_W, PAPER_H, 3, SL(10), 160);
+ fos_fill(cv, px, py, PAPER_W, PAPER_H, SL(PAPER_LV));
+ int16_t pos[256];
+ const uint8_t *src = 0;
+ int half = 0;
+ if (tray == TRAY_LATENT || tray == TRAY_IN)
+ {
+ /* the latent image, faint */
+ density_table(pos, 90);
+ src = ghost;
+ half = 1;
+ }
+ else
+ {
+ /* the darks first, then the rest, to the print's full depth */
+ float t = tray == TRAY_EMERGE ? clampf((float) tray_t / EMERGE_MS, 0, 1) : 1;
+ for (int l = 0; l < 256; l++)
+ {
+ float dfull = (255 - l) / 255.0f;
+ float k = t >= 1 ? 1 : ease_out(clampf(t * (0.7f + dfull) * 1.3f, 0, 1));
+ int d = (int) ((255 - l) * (0.35f + 0.65f * k));
+ int lv = LV12(PAPER_LV) - (LV12(PAPER_LV) - LV12(BLACK_LV)) * d / 255;
+ pos[l] = (int16_t) fos_ramp_pos(RAMP_RED, lv);
+ }
+ src = img;
+ }
+ int y0 = IMG_Y + dy;
+ int ya = fos_clamp(y0, cv->cy0, cv->cy1), yb = fos_clamp(y0 + IMG_H, cv->cy0, cv->cy1);
+ const int base = fos_ramp_base[RAMP_RED], last = fos_ramp_last[RAMP_RED];
+ for (int y = ya; y < yb; y++)
+ {
+ int sy = y - y0;
+ const uint8_t *s = half ? src + (sy >> 1) * GHOST_W : src + sy * IMG_W;
+ uint8_t *o = &cv->px[y * cv->pitch + IMG_X];
+ const uint8_t *bay = fos_bayer[y & 3];
+ for (int x = 0; x < IMG_W; x++)
+ {
+ int p = (pos[s[half ? x >> 1 : x]] + bay[x & 3]) >> 4;
+ o[x] = (uint8_t) (base + (p > last ? last : p));
+ }
+ }
+ *cv = save;
+ ui_damage(BATH_Y, BATH_Y + BATH_H);
+}
+
+static void draw_tray()
+{
+ switch (tray)
+ {
+ case TRAY_LIFT:
+ {
+ /* lifted out of the bath: up and away */
+ float t = clampf((float) tray_t / LIFT_MS, 0, 1);
+ draw_paper(-(int) (t * t * (PAPER_H + 40)));
+ break;
+ }
+ case TRAY_IN:
+ {
+ /* fresh paper slides in */
+ float t = ease_out(clampf((float) tray_t / SLIDE_MS, 0, 1));
+ draw_paper((int) ((1 - t) * (BATH_H + 10)));
+ break;
+ }
+ case TRAY_EMPTY:
+ ui_bg_restore(BATH_X, BATH_Y, BATH_W, BATH_H);
+ ui_damage(BATH_Y, BATH_Y + BATH_H);
+ break;
+ default:
+ draw_paper(0);
+ }
+}
+
+/* the prints drying, newest on the left; a new one drops in */
+static void draw_line()
+{
+ int y0 = LINE_Y - 8, y1 = LINE_Y + DRY_H + 22;
+ ui_bg_restore(0, y0, FOS_W, y1 - y0);
+ int16_t pos[256];
+ density_table(pos, 256);
+ const int base = fos_ramp_base[RAMP_RED], last = fos_ramp_last[RAMP_RED];
+ struct fos_canvas save = *cv;
+ fos_clip(cv, 0, y0, FOS_W, y1);
+ for (int i = 0; i < ndry; i++)
+ {
+ /* the older ones move along a place, then the new one comes */
+ float shift = ease_out(clampf((float) dry_t / (SLIDE_MS / 2), 0, 1));
+ float drop = ease_out(clampf((float) (dry_t - SLIDE_MS / 2) / (SLIDE_MS / 2), 0, 1));
+ if (i == 0 && drop <= 0) continue;
+ float slot = i == 0 ? 0 : i - (1 - shift);
+ int x = DRY_X0 + (int) (slot * DRY_STEP);
+ int y = LINE_Y + 8 - (i == 0 ? (int) ((1 - drop) * 70) : 0);
+ if (x > FOS_W) continue;
+ fos_fill(cv, x - 3, y - 3, DRY_W + 6, DRY_H + 6, SL(PAPER_LV));
+ int ya = fos_clamp(y, cv->cy0, cv->cy1), yb = fos_clamp(y + DRY_H, cv->cy0, cv->cy1);
+ const uint8_t *src = dry + i * DRY_W * DRY_H;
+ for (int yy = ya; yy < yb; yy++)
+ {
+ const uint8_t *s = src + (yy - y) * DRY_W;
+ uint8_t *o = &cv->px[yy * cv->pitch + x];
+ const uint8_t *bay = fos_bayer[yy & 3];
+ for (int k = 0; k < DRY_W && x + k < FOS_W; k++)
+ {
+ int p = (pos[s[k]] + bay[k & 3]) >> 4;
+ o[k] = (uint8_t) (base + (p > last ? last : p));
+ }
+ }
+ /* the peg */
+ fos_rrect(cv, x + DRY_W / 2 - 4, y - 12, 8, 14, 2, FC(RAMP_METAL, 60), OPAQUE);
+ }
+ *cv = save;
+ ui_damage(y0, y1);
+}
+
+/* the darkroom timer: a frame a turn, the roll's frames round its face */
+static void draw_dial(float frac)
+{
+ int cx = PANEL_CX, cy = DIAL_CY2, R = DIAL_R2;
+ ui_bg_restore(cx - R - 6, cy - R - 6, 2 * R + 12, 2 * R + 12);
+ fos_disc(cv, cx * 256, cy * 256, (R + 4) * 256, SL(20), OPAQUE);
+ fos_ring(cv, cx * 256, cy * 256, (R + 4) * 256, 2 * 256, SL(56), OPAQUE);
+ for (int i = 0; i < 60; i++)
+ {
+ int a = i * 65536 / 60 - 16384, r0 = i % 5 ? R - 6 : R - 11;
+ fos_line(cv, cx * 256 + fos_cos(a) * r0 / 16, cy * 256 + fos_sin(a) * r0 / 16,
+ cx * 256 + fos_cos(a) * (R - 1) / 16, cy * 256 + fos_sin(a) * (R - 1) / 16, i % 5 ? 200 : 360, SL(i % 5 ? 70 : 120), OPAQUE);
+ }
+ /* the roll's frames as dots: developed, this one, to come */
+ int n = nframes > 0 ? nframes : 1;
+ for (int i = 0; i < n && nframes; i++)
+ {
+ int a = i * 65536 / n - 16384, r = R - 22;
+ int no = i + 1;
+ fcol c = finished || no < cur_frame ? SL(190) : no == cur_frame ? SL_ACCENT : SL(64);
+ fos_disc(cv, cx * 256 + fos_cos(a) * r / 16, cy * 256 + fos_sin(a) * r / 16, n > 24 ? 480 : 640, c, OPAQUE);
+ }
+ /* the hand */
+ int a = (int) (frac * 65536) - 16384;
+ fos_line(cv, cx * 256 - fos_cos(a) * 12 / 16, cy * 256 - fos_sin(a) * 12 / 16,
+ cx * 256 + fos_cos(a) * (R - 8) / 16, cy * 256 + fos_sin(a) * (R - 8) / 16, 2 * 256, SL_ACCENT, OPAQUE);
+ fos_disc(cv, cx * 256, cy * 256, 4 * 256, SL_ACCENT, OPAQUE);
+ ui_damage(cy - R - 6, cy + R + 6);
+}
+
+static const char *stage_name()
+{
+ switch (fos_dev_doing(dev))
+ {
+ case FOS_DEV_MIXING: return "Mixing the chemistry";
+ case FOS_DEV_DEVELOPING: return "Exposing the paper";
+ case FOS_DEV_FIXING: return "Developer";
+ case FOS_DEV_DRYING: return "Fixer " T_DOT " wash";
+ }
+ return "";
+}
+
+static void draw_panel()
+{
+ int x0 = 440, x1 = FOS_W - 12;
+ char b[96], eta[32];
+ ui_bg_restore(x0, 120, x1 - x0, 112);
+ ui_bg_restore(x0, 346, x1 - x0, 72);
+ if (finished)
+ {
+ fos_text_c(cv, &fos_font_xs, PANEL_CX, 150, "DONE", SL_ACCENT, OPAQUE, 64);
+ snprintf(b, sizeof(b), "%d roll%s", rolls_done, rolls_done == 1 ? "" : "s");
+ fos_text_c(cv, &fos_font_lg, PANEL_CX, 182, b, SL_TEXT, OPAQUE, 0);
+ snprintf(b, sizeof(b), "%d print%s", done_frames - failed_frames, done_frames - failed_frames == 1 ? "" : "s");
+ fos_text_c(cv, &fos_font_sm, PANEL_CX, 206, b, SL_TEXT2, OPAQUE, 0);
+ if (failed_frames)
+ {
+ snprintf(b, sizeof(b), "%d frame%s could not be developed", failed_frames, failed_frames == 1 ? "" : "s");
+ fos_text_c(cv, &fos_font_sm, PANEL_CX, 372, b, SL_TEXT2, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_xs, PANEL_CX, 394, last_error, SL_TEXT3, OPAQUE, 0);
+ }
+ }
+ else
+ {
+ snprintf(b, sizeof(b), "ROLL %03d", cur_roll);
+ fos_text_c(cv, &fos_font_xs, PANEL_CX, 150, b, SL_ACCENT, OPAQUE, 64);
+ fos_text_c(cv, &fos_font_lg, PANEL_CX, 182, fos_films[cur_film].name, SL_TEXT, OPAQUE, 0);
+ if (cur_frame) snprintf(b, sizeof(b), "Frame %d of %d", cur_frame, nframes);
+ else b[0] = 0;
+ fos_text_c(cv, &fos_font_sm, PANEL_CX, 206, b, SL_TEXT2, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_md, PANEL_CX, 376, dev ? stage_name() : "", SL_TEXT, OPAQUE, 0);
+ int left = total_frames - done_frames;
+ int spent = dev ? ui_now - frame_t0 : 0;
+ format_eta(eta, sizeof(eta), left, -(spent < ms_per_frame ? spent : ms_per_frame));
+ snprintf(b, sizeof(b), "%d to go " T_DOT " %s", left, eta);
+ fos_text_c(cv, &fos_font_sm, PANEL_CX, 400, b, SL_TEXT3, OPAQUE, 0);
+ }
+ ui_damage(120, 232);
+ ui_damage(346, 418);
+}
+
+static void develop_hints()
+{
+ ui_bg_restore(0, HINTS_Y, FOS_W, FOS_H - HINTS_Y);
+ int base = HINTS_Y + 23, x = 24;
+ if (finished)
+ {
+ x += ui_keycap(x, base, "SET") + 8;
+ x += fos_text(cv, &fos_font_sm, x, base - 1, "See the prints", SL_TEXT2, OPAQUE, 0) + 22;
+ x += ui_keycap(x, base, "MENU") + 8;
+ fos_text(cv, &fos_font_sm, x, base - 1, "Darkroom", SL_TEXT2, OPAQUE, 0);
+ }
+ else
+ {
+ x += ui_keycap(x, base, "MENU") + 8;
+ x += fos_text(cv, &fos_font_sm, x, base - 1, "Stop", SL_TEXT2, OPAQUE, 0) + 22;
+ fos_text_r(cv, &fos_font_sm, FOS_W - 24, base - 1, "Keep the camera on " T_DOT " faster with Darkrooms on a computer", SL_TEXT3, OPAQUE, 0);
+ }
+ ui_damage(HINTS_Y, FOS_H);
+}
+
+void develop_draw()
+{
+ static int was_finished = -1;
+ if (ui_clobbered)
+ {
+ ui_clobbered = 0;
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ ui_damage_all();
+ tray_dirty = line_dirty = panel_dirty = 1;
+ was_finished = -1;
+ }
+ if (tray_dirty) { draw_tray(); tray_dirty = 0; }
+ if (line_dirty) { draw_line(); line_dirty = 0; }
+ if (panel_dirty) { draw_panel(); panel_dirty = 0; }
+ if (was_finished != finished) { develop_hints(); was_finished = finished; }
+ /* the panel's stage name follows the work */
+ int doing = fos_dev_doing(dev);
+ if (dev && doing != last_doing) { last_doing = doing; draw_panel(); }
+ int p = dev ? fos_dev_progress(dev) : 0;
+ draw_dial(p > 0 ? p / 1000.0f : 0);
+ if (stop_sheet.x > 0.002f)
+ ui_sheet(stop_sheet.x, "Stop developing?", "The prints made so far are kept; the rest wait in the darkroom.", "Stop", "Keep going");
+}
+
+/* ================================================================ the prints */
+
+/* While a print is up the palette is the print's own: entries 1..240 its
+ * colours, the overlay drawn with the fixed ones (PX_*). Changing what is
+ * shown goes through black, so the screen never shows one picture in
+ * another's colours. */
+
+enum { PV_WAIT, PV_IN, PV_SHOW, PV_OUT, PV_NONE };
+enum { NEXT_LOAD, NEXT_BACK };
+
+static int pv_roll; /* index into rolls */
+static int pv_alone;
+static int pv_mode; /* 0 the contact sheet, 1 a frame */
+static int pv_cur; /* the frame (1..), also the sheet's cursor */
+static int pv_state, pv_t, pv_next;
+static int pv_info, pv_info_t;
+static int pv_frames; /* frames on the roll */
+static int pv_have; /* pv_print holds a picture */
+static int pv_dirty; /* the picture or the overlay changed */
+
+#define FADE_MS 180
+#define INFO_H 44
+
+static int prints_roll_at(int from, int dir)
+{
+ for (int i = from; i >= 0 && i < nrolls; i += dir)
+ if (has_prints(&rolls[i])) return i;
+ return -1;
+}
+
+static void pv_load()
+{
+ char path[64];
+ if (pv_have) fos_print_free(&pv_print);
+ pv_have = 0;
+ if (pv_roll < 0) return;
+ const struct fos_lab_roll *r = &rolls[pv_roll];
+ fos_lab_print_path(path, sizeof(path), r->number, pv_mode ? pv_cur : 0);
+ pv_have = fos_print_load(path, &pv_print);
+ if (!pv_have)
+ {
+ char msg[96];
+ snprintf(msg, sizeof(msg), "prints: can't load %s", path);
+ fos_port_log(msg);
+ }
+ pv_dirty = 1;
+}
+
+static void pv_palette(int k)
+{
+ static const uint8_t black[1][3] = { { 0, 0, 0 } };
+ if (pv_have) fos_port_photo((const uint8_t (*)[3]) pv_print.pal, FOS_PRINT_COLOURS, k);
+ else fos_port_photo(black, 1, k);
+}
+
+void prints_enter(int arg)
+{
+ pv_alone = (arg & PRINTS_ALONE) != 0;
+ arg &= ~PRINTS_ALONE;
+ pv_have = 0;
+ dark_mem();
+ rescan();
+ int i = arg ? roll_index(arg) : -1;
+ if (i < 0 || !has_prints(&rolls[i])) i = prints_roll_at(0, 1);
+ pv_roll = i;
+ pv_mode = 0;
+ pv_cur = 1;
+ pv_frames = i >= 0 ? rolls[i].shot : 0;
+ if (i >= 0) fos_lab_frames(rolls[i].number, pv_meta, FOS_MAX_FRAMES);
+ pv_have = 0;
+ pv_state = i >= 0 ? PV_WAIT : PV_NONE;
+ pv_t = 0;
+ pv_info = 1;
+ pv_info_t = 0;
+ pv_dirty = 1;
+ if (pv_state == PV_NONE)
+ {
+ ui_bg_plain();
+ ui_to_bg(1);
+ ui_status_bar("PRINTS");
+ fos_text_c(cv, &fos_font_lg, 360, 220, "No prints yet", C_TEXT, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_sm, 360, 248, "Develop a roll in the darkroom and its prints show here.", C_TEXT3, OPAQUE, 0);
+ struct hint h[] = { { "SET", "Darkroom" }, { "MENU", "Back" } };
+ ui_hints(h, 2);
+ ui_to_bg(0);
+ }
+ else memset(ui_bg, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+}
+
+void prints_leave()
+{
+ if (pv_have) fos_print_free(&pv_print);
+ pv_have = 0;
+ if (pv_state != PV_NONE) fos_port_palette();
+}
+
+static void pv_go(int next)
+{
+ if (pv_state == PV_OUT) return;
+ pv_next = next;
+ pv_state = PV_OUT;
+ pv_t = 0;
+}
+
+static void pv_back()
+{
+ if (pv_alone) ui_leave();
+ else if (ui_from() == SCR_DARK || ui_from() == SCR_DEVELOP)
+ ui_go(SCR_DARK, pv_roll >= 0 ? rolls[pv_roll].number : 0, GO_FADE);
+ else ui_go(SCR_HOME, 2, GO_FADE);
+}
+
+void prints_key(int k)
+{
+ if (pv_state == PV_NONE)
+ {
+ if (k == FK_SET) ui_go(SCR_DARK, 0, GO_FADE);
+ else if (k == FK_MENU || k == FK_PLAY) { if (pv_alone) ui_leave(); else ui_go(SCR_HOME, 2, GO_FADE); }
+ return;
+ }
+ if (pv_state != PV_SHOW) return;
+ int n = pv_frames;
+ switch (k)
+ {
+ case FK_LEFT: case FK_RIGHT: case FK_UP: case FK_DOWN:
+ {
+ int d = k == FK_LEFT ? -1 : k == FK_RIGHT ? 1 : k == FK_UP ? -6 : 6;
+ if (pv_mode && (k == FK_UP || k == FK_DOWN)) break;
+ int to = pv_cur + d;
+ if (to < 1 || to > n) break;
+ pv_cur = to;
+ if (pv_mode) pv_go(NEXT_LOAD);
+ else pv_dirty = 1;
+ break;
+ }
+ case FK_WHEEL_L: case FK_WHEEL_R:
+ if (pv_mode)
+ {
+ int to = pv_cur + (k == FK_WHEEL_L ? -1 : 1);
+ if (to >= 1 && to <= n) { pv_cur = to; pv_go(NEXT_LOAD); }
+ }
+ else
+ {
+ /* the other rolls: newer to the left */
+ int to = prints_roll_at(pv_roll + (k == FK_WHEEL_L ? -1 : 1), k == FK_WHEEL_L ? -1 : 1);
+ if (to >= 0)
+ {
+ pv_roll = to;
+ pv_frames = rolls[to].shot;
+ pv_cur = 1;
+ fos_lab_frames(rolls[to].number, pv_meta, FOS_MAX_FRAMES);
+ pv_go(NEXT_LOAD);
+ }
+ }
+ break;
+ case FK_SET:
+ pv_mode = !pv_mode;
+ pv_go(NEXT_LOAD);
+ break;
+ case FK_INFO:
+ pv_info = !pv_info;
+ pv_info_t = 0;
+ pv_dirty = 1;
+ break;
+ case FK_MENU:
+ if (pv_mode) { pv_mode = 0; pv_go(NEXT_LOAD); }
+ else pv_go(NEXT_BACK);
+ break;
+ case FK_PLAY:
+ pv_go(NEXT_BACK);
+ break;
+ case FK_HOME:
+ pv_go(NEXT_BACK);
+ break;
+ }
+ if (pv_state == PV_SHOW && (k == FK_SET || k == FK_LEFT || k == FK_RIGHT)) pv_info_t = 0;
+ if (pv_dirty) ui_damage_all();
+}
+
+int prints_update(int dt)
+{
+ if (pv_state == PV_NONE) return 0;
+ pv_t += dt;
+ switch (pv_state)
+ {
+ case PV_WAIT:
+ if (!ui_settled()) return 1;
+ pv_load();
+ pv_palette(0);
+ pv_state = PV_IN;
+ pv_t = 0;
+ pv_info_t = 0;
+ return 1;
+ case PV_IN:
+ pv_palette(fos_clamp(pv_t * 256 / FADE_MS, 0, 256));
+ if (pv_t >= FADE_MS) pv_state = PV_SHOW;
+ return 1;
+ case PV_OUT:
+ pv_palette(fos_clamp(256 - pv_t * 256 / FADE_MS, 0, 256));
+ if (pv_t < FADE_MS) return 1;
+ if (pv_next == NEXT_LOAD)
+ {
+ pv_load();
+ pv_state = PV_IN;
+ pv_t = 0;
+ return 1;
+ }
+ /* back to the film OS's colours, on black */
+ pv_state = PV_NONE;
+ if (pv_have) fos_print_free(&pv_print);
+ pv_have = 0;
+ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+ fos_port_present(cv->px, FOS_W, 0, FOS_H);
+ fos_port_palette();
+ memset(ui_bg, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+ pv_back();
+ return 1;
+ case PV_SHOW:
+ /* the details go after a while on their own */
+ if (pv_info && pv_info_t < 3000)
+ {
+ pv_info_t += dt;
+ if (pv_info_t >= 3000) { pv_info = 0; pv_dirty = 1; ui_damage_all(); }
+ }
+ return 0;
+ }
+ return 0;
+}
+
+static void sheet_cell(int i, int *x, int *y)
+{
+ int rows = (pv_frames + 5) / 6;
+ int y0 = (FOS_PRINT_H - rows * FOS_THUMB_H) / 2;
+ *x = (i % 6) * FOS_THUMB_W + FOS_SHEET_FX;
+ *y = y0 + (i / 6) * FOS_THUMB_H + FOS_SHEET_FY;
+}
+
+static void frame_rect(int x, int y, int w, int h, uint8_t ix)
+{
+ for (int k = 0; k < 2; k++)
+ {
+ memset(&cv->px[(y + k) * cv->pitch + x], ix, w);
+ memset(&cv->px[(y + h - 1 - k) * cv->pitch + x], ix, w);
+ }
+ for (int j = y; j < y + h; j++)
+ {
+ cv->px[j * cv->pitch + x] = cv->px[j * cv->pitch + x + 1] = ix;
+ cv->px[j * cv->pitch + x + w - 1] = cv->px[j * cv->pitch + x + w - 2] = ix;
+ }
+}
+
+void prints_draw()
+{
+ if (pv_state == PV_NONE)
+ {
+ if (ui_clobbered) { ui_clobbered = 0; ui_bg_restore(0, 0, FOS_W, FOS_H); ui_damage_all(); }
+ return;
+ }
+ if (pv_state == PV_WAIT)
+ {
+ /* black, in the film OS's colours, until the screen has settled */
+ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+ ui_clobbered = 0;
+ return;
+ }
+ if (pv_state == PV_OUT) return; /* what is fading out stays as it was */
+ if (!pv_dirty && !ui_clobbered) return;
+ pv_dirty = 0;
+ ui_clobbered = 0;
+ /* the picture */
+ if (pv_have) memcpy(cv->px, pv_print.px, FOS_W * FOS_H);
+ else
+ {
+ memset(cv->px, PX_BLACK, FOS_W * FOS_H);
+ char b[64];
+ snprintf(b, sizeof(b), pv_mode ? "Frame %d was not developed" : "No contact sheet", pv_cur);
+ ui_photo_text(&fos_font_md, 360, 244, b, 0, 1);
+ }
+ const struct fos_lab_roll *r = &rolls[pv_roll];
+ if (!pv_mode)
+ {
+ int x, y;
+ sheet_cell(pv_cur - 1, &x, &y);
+ frame_rect(x - 4, y - 4, FOS_SHEET_FW + 8, FOS_SHEET_FH + 8, PX_AMBER);
+ }
+ if (pv_info)
+ {
+ char b[96], c[64];
+ int y = FOS_H - INFO_H;
+ memset(&cv->px[y * cv->pitch], PX_PANEL, FOS_W * INFO_H);
+ memset(&cv->px[y * cv->pitch], PX_LINE, FOS_W);
+ const struct fos_lab_frame *m = pv_cur >= 1 && pv_cur <= FOS_MAX_FRAMES ? &pv_meta[pv_cur - 1] : 0;
+ snprintf(b, sizeof(b), "ROLL %03d", r->number);
+ int x = 20 + ui_photo_text(&fos_font_xs, 20, y + 28, b, 1, 0);
+ snprintf(b, sizeof(b), "%s " T_DOT " frame %d of %d", fos_films[r->film].name, pv_cur, pv_frames);
+ x += 14 + ui_photo_text(&fos_font_sm, x + 14, y + 28, b, 0, 0);
+ if (m && m->when[0])
+ {
+ snprintf(c, sizeof(c), "%s%s%s", m->when, m->fstop[0] ? " f/" : "", m->fstop);
+ ui_photo_text(&fos_font_sm, x + 14, y + 28, c, 0, 0);
+ }
+ ui_photo_text(&fos_font_xs, FOS_W - 20, y + 28, pv_mode ? "SET SHEET INFO HIDE" : "SET OPEN WHEEL ROLLS", 0, 2);
+ }
+ ui_damage_all();
+}
diff --git a/ml-dev/filmos/fos_dev.c b/ml-dev/filmos/fos_dev.c
new file mode 100644
index 0000000..83672d7
--- /dev/null
+++ b/ml-dev/filmos/fos_dev.c
@@ -0,0 +1,2145 @@
+/* fos_dev: developing film in the camera, a frame at a time.
+ *
+ * The frame's CR2 is read a chunk at a time and its lossless JPEG decoded;
+ * every sample is added straight into the print pixel it falls in, so the
+ * 18 million sample mosaic becomes a 720 x 480 picture without ever being
+ * held: a box filter and the demosaic in one. The print then gets what
+ * the desktop darkroom (Darkrooms) does: daylight balance, the camera's colours
+ * to sRGB, the scanner's exposure, the film's balance, vignette and
+ * halation, the film's colour (a 3D table built from the same film model),
+ * and grain. Finally it is reduced to FOS_PRINT_COLOURS colours with error
+ * diffusion, its own palette, for the 8-bit screen.
+ *
+ * Everything runs in steps that stop after a time budget, so the film OS
+ * keeps animating on the same task: no threads, no locks.
+ */
+
+#include "fos.h"
+#include "fos_dev.h"
+#include "fos_jpeg.h"
+#include <math.h>
+#include <string.h>
+
+#ifdef FOS_DEV_TEST
+void fos_dev_test_sample(int x, int y, int v);
+#endif
+
+static int u16le(const uint8_t *p) { return p[0] | p[1] << 8; }
+static unsigned u32le(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (unsigned) p[3] << 24; }
+static void put32(uint8_t *p, uint32_t v) { p[0] = (uint8_t) v; p[1] = (uint8_t) (v >> 8); p[2] = (uint8_t) (v >> 16); p[3] = (uint8_t) (v >> 24); }
+
+/* ---------------------------------------------------------------- the film model */
+
+static const float LUMA[3] = { 0.2126f, 0.7152f, 0.0722f };
+static const float REF[7][3] = { /* red orange yellow green cyan blue magenta */
+ { 1, 0, 0 }, { 1, 0.5f, 0 }, { 1, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 1, 0, 1 } };
+#define PI_F 3.14159265f
+
+const struct fos_look *fos_look_of(const char *key)
+{
+ for (int i = 0; i < fos_nlooks; i++)
+ if (!strcmp(fos_looks[i].key, key)) return &fos_looks[i];
+ for (int i = 0; i < fos_nmore_looks; i++)
+ if (!strcmp(fos_more_looks[i].key, key)) return &fos_more_looks[i];
+ return &fos_looks[0];
+}
+
+static float dot3(const float a[3], const float b[3])
+{
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+}
+
+static float hue_angle(int i)
+{
+ static float angle[7];
+ static int ready;
+ if (!ready)
+ {
+ for (int k = 0; k < 7; k++)
+ {
+ float y = dot3(REF[k], LUMA);
+ angle[k] = atan2f((REF[k][0] - y) / 1.5748f, (REF[k][2] - y) / 1.8556f);
+ }
+ ready = 1;
+ }
+ return angle[i];
+}
+
+static float wrap(float a)
+{
+ a = fmodf(a + PI_F, 2 * PI_F);
+ if (a < 0) a += 2 * PI_F;
+ return a - PI_F;
+}
+
+/* the characteristic curve: logistic in log2 exposure around mid grey */
+static float curve(float x, float slope, float pivot, float black, float white)
+{
+ float xx = log2f((x > 1e-6f ? x : 1e-6f) / 0.18f) - pivot;
+ float k = 4 * slope / (white - black);
+ return black + (white - black) / (1 + expf(-k * xx));
+}
+
+static void shift_hues(const struct fos_look *f, float rgb[3])
+{
+ float y = dot3(rgb, LUMA);
+ float cb = (rgb[2] - y) / 1.8556f, cr = (rgb[0] - y) / 1.5748f;
+ float h = atan2f(cr, cb), c = sqrtf(cb * cb + cr * cr);
+ float gate = c / 0.04f > 1 ? 1 : c / 0.04f;
+ float dh = 0, cm = 1;
+ const float sigma = 35 * PI_F / 180;
+ for (int i = 0; i < f->nhues; i++)
+ {
+ const struct fos_hue_shift *s = &f->hues[i];
+ float hs = hue_angle(s->from);
+ float d = wrap(h - hs) / sigma;
+ float w = expf(-0.5f * d * d) * gate;
+ if (s->from != s->to) dh += w * s->amount * wrap(hue_angle(s->to) - hs);
+ cm *= 1 + w * (s->chroma - 1);
+ }
+ h += dh;
+ c *= cm;
+ cb = c * cosf(h); cr = c * sinf(h);
+ rgb[0] = y + 1.5748f * cr;
+ rgb[2] = y + 1.8556f * cb;
+ rgb[1] = (y - LUMA[0] * rgb[0] - LUMA[2] * rgb[2]) / LUMA[1];
+}
+
+void fos_film_color(const struct fos_look *f, const float in[3], float out[3])
+{
+ if (f->mono)
+ {
+ float v = curve(dot3(in, f->mono_mix), f->contrast[0], f->pivot[0], f->black[0], f->white[0]);
+ out[0] = out[1] = out[2] = v;
+ return;
+ }
+ float y = dot3(in, LUMA), lin[3];
+ for (int c = 0; c < 3; c++)
+ {
+ lin[c] = y + (in[c] - y) * f->sat;
+ if (lin[c] < 0) lin[c] = 0;
+ out[c] = curve(lin[c], f->contrast[c], f->pivot[c], f->black[c], f->white[c]);
+ }
+ if (f->nhues) shift_hues(f, out);
+}
+
+/* linear sRGB of a blackbody at t kelvin (as cct_to_rgb in the lab) */
+static void cct_rgb(float t, float out[3])
+{
+ float x, y;
+ if (t <= 4000) x = -0.2661239e9f / (t * t * t) - 0.2343589e6f / (t * t) + 0.8776956e3f / t + 0.179910f;
+ else x = -3.0258469e9f / (t * t * t) + 2.1070379e6f / (t * t) + 0.2226347e3f / t + 0.240390f;
+ if (t <= 2222) y = -1.1063814f * x * x * x - 1.34811020f * x * x + 2.18555832f * x - 0.20219683f;
+ else if (t <= 4000) y = -0.9549476f * x * x * x - 1.37418593f * x * x + 2.09137015f * x - 0.16748867f;
+ else y = 3.0817580f * x * x * x - 5.87338670f * x * x + 3.75112997f * x - 0.37001483f;
+ float X = x / y, Y = 1, Z = (1 - x - y) / y;
+ out[0] = 3.2406f * X - 1.5372f * Y - 0.4986f * Z;
+ out[1] = -0.9689f * X + 1.8758f * Y + 0.0415f * Z;
+ out[2] = 0.0557f * X - 0.2040f * Y + 1.0570f * Z;
+}
+
+/* ---------------------------------------------------------------- the film's table */
+
+/* The film's colour as a 3D table over Cineon log code (the density of a
+ * film scan): the same thing `lut.py export` writes, and as close to the
+ * lab's model. Building it takes the camera a few seconds, so it is kept
+ * in memory and on the card. */
+#define GRID 33
+#define NGRID (GRID * GRID * GRID)
+#define LOOK_MODEL 1 /* bump when fos_film_color changes */
+#define CIN_BLACK 0.0108f /* 10^((95 - 685) * 0.002 / 0.6) */
+
+static struct
+{
+ uint8_t lut[NGRID][3];
+ /* linear (4096 = 1.0) -> grid position (1/256) of its Cineon code:
+ * 0..4095 one by one, then up to 65535 in steps of 16 */
+ uint16_t cin[4096 + 3841];
+} *tab;
+static int lut_film = -1, lut_built; /* lut_built: grid points done */
+static char cache_dir[128];
+
+void fos_dev_cache(const char *dir)
+{
+ snprintf(cache_dir, sizeof(cache_dir), "%s", dir ? dir : "");
+}
+
+void fos_dev_release()
+{
+ fos_port_free(tab);
+ tab = 0;
+ lut_film = -1;
+}
+
+static float cineon_decode(float v)
+{
+ float x = powf(10, (v * 1023 - 685) / 300);
+ return (x - CIN_BLACK) / (1 - CIN_BLACK);
+}
+
+static int cineon_encode(float lin)
+{
+ float x = (lin > 0 ? lin : 0) * (1 - CIN_BLACK) + CIN_BLACK;
+ float v = (685 + 300 * log10f(x)) / 1023;
+ return v < 0 ? 0 : v > 1 ? 65535 : (int) (v * 65535 + 0.5f);
+}
+
+static int tables_ready()
+{
+ if (tab) return 1;
+ tab = fos_port_alloc(sizeof(*tab));
+ if (!tab) return 0;
+ for (int i = 0; i < 4096 + 3841; i++)
+ {
+ int code = cineon_encode((i < 4096 ? i : 4096 + (i - 4096) * 16) / 4096.0f);
+ tab->cin[i] = (uint16_t) ((code * ((GRID - 1) * 256)) >> 16);
+ }
+ lut_film = -1;
+ return 1;
+}
+
+/* linear 0..65535 (4096 = 1.0, up to 16) -> grid position in 1/256 */
+FOS_INLINE int cin_pos(const uint16_t *cin, int lin)
+{
+ return cin[lin < 4096 ? lin : lin > 65535 ? 4096 + 3840 : 4096 + ((lin - 4096) >> 4)];
+}
+
+/* the look's numbers, so a table on the card is only used for the same look */
+/* the look's numbers and its film, so a table on the card is only used
+ * for the same look (tools/genfilms.py works it out the same way for the
+ * tables it bakes from LUTs) */
+static uint32_t look_hash(const struct fos_look *f)
+{
+ const uint8_t *p = (const uint8_t *) &f->balance;
+ const uint8_t *e = (const uint8_t *) f->mono_mix + sizeof(f->mono_mix);
+ uint32_t h = 2166136261u ^ (GRID * 256 + LOOK_MODEL);
+ for (const char *k = f->key; *k; k++) h = (h ^ (uint8_t) *k) * 16777619u;
+ for (; p < e; p++) h = (h ^ *p) * 16777619u;
+ return h;
+}
+
+static void *lut_file(int film, int write)
+{
+ if (!cache_dir[0]) return 0;
+ char path[160];
+ snprintf(path, sizeof(path), "%s/LOOK%02d.LUT", cache_dir, film);
+ return fos_port_open(path, write);
+}
+
+static int lut_load(const struct fos_look *f, int film)
+{
+ void *fp = lut_file(film, 0);
+ if (!fp) return 0;
+ uint8_t h[8];
+ int ok = fos_port_read(fp, h, 8) == 8 && !memcmp(h, "FOL1", 4) && u32le(h + 4) == look_hash(f)
+ && fos_port_read(fp, tab->lut, sizeof(tab->lut)) == (int) sizeof(tab->lut);
+ fos_port_close(fp);
+ return ok;
+}
+
+static void lut_save(const struct fos_look *f, int film)
+{
+ void *fp = lut_file(film, 1);
+ if (!fp) return;
+ uint8_t h[8] = { 'F', 'O', 'L', '1' };
+ put32(h + 4, look_hash(f));
+ fos_port_write(fp, h, 8);
+ fos_port_write(fp, tab->lut, sizeof(tab->lut));
+ fos_port_close(fp);
+}
+
+/* build up to `count` more grid points; 1 when the table is complete */
+static __attribute__((noinline)) int lut_build(const struct fos_look *f, int film, int count)
+{
+ if (lut_film != film)
+ {
+ lut_film = film;
+ lut_built = lut_load(f, film) ? NGRID : 0;
+ }
+ if (lut_built >= NGRID) return 1;
+ for (; lut_built < NGRID && count-- > 0; lut_built++)
+ {
+ int i = lut_built, r = i % GRID, g = (i / GRID) % GRID, b = i / (GRID * GRID);
+ float lin[3] = { cineon_decode(r / (float) (GRID - 1)), cineon_decode(g / (float) (GRID - 1)),
+ cineon_decode(b / (float) (GRID - 1)) }, out[3];
+ fos_film_color(f, lin, out);
+ for (int c = 0; c < 3; c++)
+ {
+ int v = (int) (out[c] * 255 + 0.5f);
+ tab->lut[i][c] = (uint8_t) (v < 0 ? 0 : v > 255 ? 255 : v);
+ }
+ }
+ if (lut_built < NGRID) return 0;
+ lut_save(f, film);
+ return 1;
+}
+
+/* the film's table, into the cache now: the build puts every film's on
+ * the card, so the camera never has to mix one */
+int fos_dev_table(int film)
+{
+ if (!tables_ready()) return 0;
+ film = fos_clamp(film, 0, fos_nfilms - 1);
+ lut_film = -1;
+ while (!lut_build(fos_look_of(fos_films[film].key), film, NGRID)) {}
+ return 1;
+}
+
+/* tetrahedral lookup at grid positions in 1/256: the four corners of the
+ * cell's tetrahedron the point is in, weighted */
+FOS_INLINE void lut_apply(const uint8_t (*lut)[3], int pr, int pg, int pb, uint8_t out[3])
+{
+ int fr = pr & 255, fg = pg & 255, fb = pb & 255;
+ const uint8_t *p = lut[((pb >> 8) * GRID + (pg >> 8)) * GRID + (pr >> 8)];
+ const int R = 3, G = 3 * GRID, B = 3 * GRID * GRID;
+ int o1, o2, w0, w1, w2, w3;
+ if (fr >= fg)
+ {
+ if (fg >= fb) { o1 = R; o2 = R + G; w0 = 256 - fr; w1 = fr - fg; w2 = fg - fb; w3 = fb; }
+ else if (fr >= fb) { o1 = R; o2 = R + B; w0 = 256 - fr; w1 = fr - fb; w2 = fb - fg; w3 = fg; }
+ else { o1 = B; o2 = R + B; w0 = 256 - fb; w1 = fb - fr; w2 = fr - fg; w3 = fg; }
+ }
+ else
+ {
+ if (fb >= fg) { o1 = B; o2 = G + B; w0 = 256 - fb; w1 = fb - fg; w2 = fg - fr; w3 = fr; }
+ else if (fb >= fr) { o1 = G; o2 = G + B; w0 = 256 - fg; w1 = fg - fb; w2 = fb - fr; w3 = fr; }
+ else { o1 = G; o2 = R + G; w0 = 256 - fg; w1 = fg - fr; w2 = fr - fb; w3 = fb; }
+ }
+ const int o3 = R + G + B;
+ for (int c = 0; c < 3; c++, p++)
+ out[c] = (uint8_t) ((w0 * p[0] + w1 * p[o1] + w2 * p[o2] + w3 * p[o3] + 128) >> 8);
+}
+
+/* ---------------------------------------------------------------- the frame */
+
+#define CHUNK (192 * 1024) /* read from the card at a time */
+#define GW (FOS_PRINT_W / 4) /* the halation's grid */
+#define GH (FOS_PRINT_H / 4)
+#define FAST_BITS 9
+#define DIFF_BITS 11
+#define UNPACK 2688 /* samples decoded at a time: an EOS M slice's row */
+
+enum { ST_OPEN, ST_DECODE, ST_KEY, ST_EXPOSE, ST_GLOW, ST_FINISH, ST_JPEG, ST_QUANT, ST_DITHER, ST_WRITE, ST_DONE, ST_FAIL };
+
+struct huff
+{
+ /* a code and its difference bits together, when they fit in
+ * DIFF_BITS: difference << 4 | bits used; 0 = the slower way (small,
+ * so it stays in the camera's data cache) */
+ int16_t fastd[1 << DIFF_BITS];
+ uint16_t fast[1 << FAST_BITS]; /* len << 8 | symbol, 0 = longer than FAST_BITS */
+ int maxcode[18], valptr[17], mincode[17];
+ uint8_t vals[256];
+};
+
+struct box { int lo[3], hi[3]; long count; };
+
+struct fos_dev
+{
+ char cr2[128], print[128], when[20], fstop[8];
+ char jpeg[160]; /* the full-colour frame as a JPEG too, or "" */
+ int film, frame;
+ const struct fos_look *look;
+ int stage, row; /* row: progress through a per-row stage */
+ const char *err;
+ char errbuf[48];
+ void *f;
+
+ /* the file, destuffed into whole bytes of entropy data */
+ uint8_t *buf;
+ const uint8_t *bp, *be, *safe, *ff; /* the next byte, the end, see fill() */
+ int file_pos, file_end;
+ uint32_t bitbuf;
+ int vbits;
+
+ /* the raw */
+ int raw_w, raw_h, orient;
+ int crop_l, crop_t, crop_w, crop_h, ob_l, ob_r;
+ int slices[3];
+ int clrs, wide, high, bits, psv;
+ struct huff *huff[4];
+ struct huff tables[4];
+
+ /* decoding */
+ int jcol, comp, vpred[4];
+ uint16_t samples[4 + UNPACK];
+ int sl, sx, sy, sw, sx0; /* where the next sample goes: slice, column in it, row */
+ long done, total;
+
+ /* the print being built */
+ int ow, oh, ox0; /* picture size and its left edge on the print */
+ int32_t *rowoff; /* raw row -> its place in the print's sums, or < 0 */
+ uint16_t *seg_of, *seg_x0; /* raw column -> its segment; a segment's first column */
+ int32_t *seg_off; /* segment -> its place in the print's sums */
+ uint8_t *seg_desc; /* a row's pieces: pairs (<= 4) | 0x40 a last even column | 0x80 an odd first */
+ int32_t *desc_off; /* a piece's place in the print's sums */
+ int32_t *seg_piece; /* a segment's first piece */
+ uint8_t *rowob, *colob; /* optical black */
+ uint16_t *ne_r, *no_r, *ne_c, *no_c; /* raw rows / columns per print line, even and odd */
+ int rows_axis_x; /* raw rows run along the print's x (portrait) */
+ uint32_t *sums; /* 3 per print pixel */
+ int64_t black_sum;
+ long black_n;
+ int black16; /* black level, 1/16 raw units */
+ int pre[3]; /* daylight balance and white level, raw/16 -> 1/4096, << 14 */
+ int mat[3][3]; /* camera -> linear sRGB, 1/4096 */
+ int mul[3]; /* exposure and film balance, 1/4096 */
+ uint16_t *lin; /* in place of sums: linear sRGB, 4096 = 1.0 */
+ int32_t *glow; /* halation, a quarter of the print each way */
+ uint8_t *rgb; /* the finished print, RGB */
+ uint8_t thumb[FOS_THUMB_W * FOS_THUMB_H * 3];
+ int16_t vig_x[FOS_PRINT_W], vig_y[FOS_PRINT_H];
+ uint8_t gx[FOS_PRINT_W], fx[FOS_PRINT_W]; /* glow cell and weight (1/8) per column */
+ unsigned seed;
+ uint16_t pos[3 * FOS_PRINT_W]; /* a row's positions on the film's grid */
+
+ /* palette */
+ uint32_t *hist;
+ uint8_t *inv;
+ uint8_t pal[FOS_PRINT_COLOURS][3];
+ int npal;
+ struct box boxes[FOS_PRINT_COLOURS];
+ uint8_t by_green[FOS_PRINT_COLOURS]; /* the palette in order of green */
+ int16_t *err_rows;
+ uint8_t *idx;
+};
+
+/* The sensor's colours, XYZ -> camera, and its white level: LibRaw's
+ * colordata.cpp (the Adobe matrices), per camera the fork is built for.
+ * The EOS M's is the default (and the 650D's, 700D's and 100D's: one sensor). */
+#define M3(a, b, c, d, e, f, g, h, i) { { a / 10000.f, b / 10000.f, c / 10000.f }, { d / 10000.f, e / 10000.f, f / 10000.f }, \
+ { g / 10000.f, h / 10000.f, i / 10000.f } }
+#if defined(CONFIG_6D) || defined(CONFIG_70D)
+static const float XYZ_CAM[3][3] = M3(7034, -804, -1014, -4420, 12564, 2058, -851, 1994, 5758);
+#elif defined(CONFIG_5D3)
+static const float XYZ_CAM[3][3] = M3(6722, -635, -963, -4287, 12460, 2028, -908, 2162, 5668);
+#elif defined(CONFIG_5D2)
+static const float XYZ_CAM[3][3] = M3(4716, 603, -830, -7798, 15474, 2480, -1496, 1937, 6651);
+#elif defined(CONFIG_7D)
+static const float XYZ_CAM[3][3] = M3(6844, -996, -856, -3876, 11761, 2396, -593, 1772, 6198);
+#elif defined(CONFIG_50D)
+static const float XYZ_CAM[3][3] = M3(4920, 616, -593, -6493, 13964, 2784, -1774, 3178, 7005);
+#elif defined(CONFIG_60D)
+static const float XYZ_CAM[3][3] = M3(6719, -994, -925, -4408, 12426, 2211, -887, 2129, 6051);
+#elif defined(CONFIG_500D)
+static const float XYZ_CAM[3][3] = M3(4763, 712, -646, -6821, 14399, 2640, -1921, 3276, 6561);
+#elif defined(CONFIG_550D)
+static const float XYZ_CAM[3][3] = M3(6941, -1164, -857, -3825, 11597, 2534, -416, 1540, 6039);
+#elif defined(CONFIG_600D)
+static const float XYZ_CAM[3][3] = M3(6461, -907, -882, -4300, 12184, 2378, -819, 1944, 5931);
+#elif defined(CONFIG_1100D)
+static const float XYZ_CAM[3][3] = M3(6444, -904, -893, -4563, 12308, 2535, -903, 2016, 6728);
+#else /* EOS M, 100D, 650D, 700D */
+static const float XYZ_CAM[3][3] = { { 0.6602f, -0.0841f, -0.0939f }, { -0.4472f, 1.2458f, 0.2247f }, { -0.0975f, 0.2039f, 0.6148f } };
+#endif
+static const float RGB_XYZ[3][3] = { { 0.4124564f, 0.3575761f, 0.1804375f }, { 0.2126729f, 0.7151522f, 0.0721750f },
+ { 0.0193339f, 0.1191920f, 0.9503041f } };
+/* raw value of a full pixel (LibRaw's maximum); the EOS M's measured 13600 */
+#if defined(CONFIG_6D)
+#define WHITE_LEVEL 15490
+#elif defined(CONFIG_70D)
+#define WHITE_LEVEL 15303
+#elif defined(CONFIG_5D3)
+#define WHITE_LEVEL 15488
+#elif defined(CONFIG_5D2)
+#define WHITE_LEVEL 15600
+#elif defined(CONFIG_7D) || defined(CONFIG_600D) || defined(CONFIG_1100D)
+#define WHITE_LEVEL 13584
+#elif defined(CONFIG_50D)
+#define WHITE_LEVEL 15763
+#elif defined(CONFIG_60D)
+#define WHITE_LEVEL 12279
+#elif defined(CONFIG_500D)
+#define WHITE_LEVEL 13433
+#elif defined(CONFIG_550D)
+#define WHITE_LEVEL 15831
+#elif defined(CONFIG_700D)
+#define WHITE_LEVEL 15360
+#elif defined(CONFIG_100D)
+#define WHITE_LEVEL 13583
+#elif defined(CONFIG_650D)
+#define WHITE_LEVEL 13645
+#else
+#define WHITE_LEVEL 13600
+#endif
+
+static int fail(struct fos_dev *d, const char *why)
+{
+ d->err = why;
+ d->stage = ST_FAIL;
+ return -1;
+}
+
+/* a buffer couldn't be had: which one, for the log */
+static int fail_mem(struct fos_dev *d, int size)
+{
+ snprintf(d->errbuf, sizeof(d->errbuf), "out of memory (%d KB)", (size + 1023) / 1024);
+ return fail(d, d->errbuf);
+}
+
+/* ---- reading */
+
+static int read_at(struct fos_dev *d, int offset, void *buf, int size)
+{
+ if (fos_port_seek(d->f, offset) < 0) return 0;
+ return fos_port_read(d->f, buf, size) == size;
+}
+
+
+/* the value of TIFF tag `tag` in the IFD at `ifd` (offset for anything
+ * longer than 4 bytes); -1 when absent */
+static long tiff_tag(struct fos_dev *d, unsigned ifd, int tag, int *count)
+{
+ uint8_t n2[2], e[12];
+ if (!read_at(d, (int) ifd, n2, 2)) return -1;
+ int n = u16le(n2);
+ for (int i = 0; i < n && i < 400; i++)
+ {
+ if (!read_at(d, (int) ifd + 2 + 12 * i, e, 12)) return -1;
+ if (u16le(e) != tag) continue;
+ int type = u16le(e + 2);
+ unsigned cnt = u32le(e + 4);
+ if (count) *count = (int) cnt;
+ if (type == 3 && cnt <= 2) return u16le(e + 8);
+ return (long) u32le(e + 8);
+ }
+ return -1;
+}
+
+static int parse_tiff(struct fos_dev *d)
+{
+ uint8_t h[16];
+ if (!read_at(d, 0, h, 16)) return fail(d, "can't read the file");
+ if (h[0] != 'I' || h[1] != 'I' || h[8] != 'C' || h[9] != 'R') return fail(d, "not a CR2 file");
+ unsigned ifd0 = u32le(h + 4), raw_ifd = u32le(h + 12);
+ long o = tiff_tag(d, ifd0, 0x0112, 0);
+ d->orient = o > 0 ? (int) o : 1;
+
+ /* the sensor's picture area from the Canon maker note, if it says */
+ d->crop_l = -1;
+ long exif = tiff_tag(d, ifd0, 0x8769, 0);
+ long mn = exif > 0 ? tiff_tag(d, (unsigned) exif, 0x927C, 0) : -1;
+ int cnt = 0;
+ long si = mn > 0 ? tiff_tag(d, (unsigned) mn, 0x00E0, &cnt) : -1;
+ if (si > 0 && cnt >= 13)
+ {
+ uint8_t s[26];
+ if (read_at(d, (int) si, s, 26))
+ {
+ d->crop_l = u16le(s + 10); d->crop_t = u16le(s + 12);
+ d->crop_w = u16le(s + 14) - d->crop_l + 1; d->crop_h = u16le(s + 16) - d->crop_t + 1;
+ d->ob_l = u16le(s + 18); d->ob_r = u16le(s + 22);
+ }
+ }
+
+ long off = tiff_tag(d, raw_ifd, 0x0111, 0);
+ if (off <= 0) return fail(d, "no RAW in this file");
+ d->file_pos = (int) off;
+ long len = tiff_tag(d, raw_ifd, 0x0117, 0);
+ d->file_end = len > 0 ? (int) (off + len) : 0x7fffffff;
+ d->slices[0] = 0;
+ long sl = tiff_tag(d, raw_ifd, 0xC640, &cnt);
+ if (sl > 0 && cnt == 3)
+ {
+ uint8_t s[6];
+ if (read_at(d, (int) sl, s, 6))
+ {
+ d->slices[0] = u16le(s); d->slices[1] = u16le(s + 2); d->slices[2] = u16le(s + 4);
+ }
+ }
+ return 1;
+}
+
+static int build_huff(struct huff *h, const uint8_t *counts, const uint8_t *vals, int nvals)
+{
+ memset(h, 0, sizeof(*h));
+ memcpy(h->vals, vals, nvals > 256 ? 256 : nvals);
+ int code = 0, k = 0;
+ for (int len = 1; len <= 16; len++)
+ {
+ h->valptr[len] = k;
+ h->mincode[len] = code;
+ for (int i = 0; i < counts[len - 1]; i++, k++, code++)
+ if (len <= FAST_BITS)
+ {
+ int shift = FAST_BITS - len;
+ for (int j = 0; j < 1 << shift; j++)
+ h->fast[(code << shift) | j] = (uint16_t) (len << 8 | vals[k]);
+ }
+ h->maxcode[len] = counts[len - 1] ? code - 1 : -1;
+ code <<= 1;
+ }
+ h->maxcode[17] = 0x7fffffff;
+ /* the common short code and difference in one lookup */
+ for (int i = 0; i < 1 << DIFF_BITS; i++)
+ {
+ int e = h->fast[i >> (DIFF_BITS - FAST_BITS)], len = e >> 8, s = e & 0xFF;
+ if (!e || s == 16 || len + s > DIFF_BITS) continue;
+ int diff = 0;
+ if (s)
+ {
+ diff = (i >> (DIFF_BITS - len - s)) & ((1 << s) - 1);
+ if (!(diff >> (s - 1))) diff -= (1 << s) - 1;
+ }
+ h->fastd[i] = (int16_t) (diff * 16 + len + s);
+ }
+ return k == nvals;
+}
+
+/* the lossless JPEG's header, up to the scan */
+static int parse_ljpeg_in(struct fos_dev *d, uint8_t *hdr, int size);
+
+static int parse_ljpeg(struct fos_dev *d)
+{
+ const int HDR = 2048;
+ uint8_t *hdr = fos_port_alloc(HDR); /* not on the film OS task's small stack */
+ if (!hdr) return fail_mem(d, HDR);
+ int r = parse_ljpeg_in(d, hdr, HDR);
+ fos_port_free(hdr);
+ return r;
+}
+
+static int parse_ljpeg_in(struct fos_dev *d, uint8_t *hdr, int size)
+{
+ int n = d->file_end - d->file_pos < size ? d->file_end - d->file_pos : size;
+ if (n < 64 || !read_at(d, d->file_pos, hdr, n)) return fail(d, "can't read the RAW");
+ if (hdr[0] != 0xFF || hdr[1] != 0xD8) return fail(d, "the RAW is not a lossless JPEG");
+ int p = 2, have_sof = 0, ntab = 0;
+ while (p + 4 <= n)
+ {
+ if (hdr[p] != 0xFF) return fail(d, "broken RAW header");
+ int tag = hdr[p + 1], len = hdr[p + 2] << 8 | hdr[p + 3];
+ const uint8_t *s = hdr + p + 4;
+ if (p + 2 + len > n) return fail(d, "RAW header too long");
+ if (tag == 0xC3)
+ {
+ d->bits = s[0];
+ d->high = s[1] << 8 | s[2];
+ d->wide = s[3] << 8 | s[4];
+ d->clrs = s[5];
+ if (((s[7] >> 4) * (s[7] & 15) - 1) & 3) return fail(d, "sRAW / mRAW: shoot full RAW");
+ have_sof = 1;
+ }
+ else if (tag == 0xC4)
+ {
+ for (const uint8_t *q = s; q < s + len - 2;)
+ {
+ int id = *q++;
+ if (id & ~3) return fail(d, "unexpected Huffman table");
+ int total = 0;
+ for (int i = 0; i < 16; i++) total += q[i];
+ if (!build_huff(&d->tables[id], q, q + 16, total)) return fail(d, "bad Huffman table");
+ if (id + 1 > ntab) ntab = id + 1;
+ q += 16 + total;
+ }
+ }
+ else if (tag == 0xDD && (s[0] | s[1]))
+ return fail(d, "unsupported RAW: restart markers");
+ else if (tag == 0xDA)
+ {
+ d->psv = s[1 + s[0] * 2];
+ d->bits -= s[3 + s[0] * 2] & 15;
+ d->file_pos += p + 2 + len;
+ if (!have_sof || !ntab) return fail(d, "RAW header incomplete");
+ /* LibRaw's rule, which Canon follows: component c takes table c,
+ * or the last one defined */
+ for (int c = 0; c < 4; c++) d->huff[c] = &d->tables[c < ntab ? c : ntab - 1];
+ /* the same table twice (the EOS M's): one copy, half the cache */
+ for (int c = 1; c < 4; c++)
+ if (d->huff[c] != d->huff[0] && !memcmp(d->huff[c], d->huff[0], sizeof(struct huff))) d->huff[c] = d->huff[0];
+ if (d->clrs < 1 || d->clrs > 4 || d->bits < 8 || d->bits > 16) return fail(d, "unsupported RAW layout");
+ if (d->psv != 1) return fail(d, "unsupported RAW predictor");
+ return 1;
+ }
+ p += 2 + len;
+ }
+ return fail(d, "RAW header not found");
+}
+
+/* the next chunk of the file after the keep bytes not yet used (at bp);
+ * past the end, zeros. The JPEG's byte stuffing stays in: the bit reader
+ * takes it out as it goes, rather than in a pass of its own. Returns the
+ * buffer's length. */
+static int refill(struct fos_dev *d, const uint8_t *bp, int keep)
+{
+ memmove(d->buf, bp, keep);
+ int n = d->file_end - d->file_pos;
+ if (n > CHUNK) n = CHUNK;
+ if (n > 0 && fos_port_seek(d->f, d->file_pos) >= 0 && (n = fos_port_read(d->f, d->buf + keep, n)) > 0)
+ d->file_pos += n;
+ else
+ {
+ d->file_pos = d->file_end;
+ n = 8;
+ memset(d->buf + keep, 0, 8);
+ }
+ return keep + n;
+}
+
+/* ---- the print's geometry: which raw rows and columns land where */
+
+static int setup_maps(struct fos_dev *d)
+{
+ d->raw_w = d->wide * d->clrs;
+ d->raw_h = d->high;
+ if (!(d->clrs & 1) && d->raw_w > 4 * d->raw_h)
+ {
+ /* some cameras store the sensor as a frame twice as wide and half
+ * as high (as dcraw and LibRaw read it): the samples run the same */
+ d->raw_w /= 2;
+ d->raw_h *= 2;
+ }
+ if (d->slices[0] && d->slices[0] * d->slices[1] + d->slices[2] != d->raw_w)
+ return fail(d, "RAW slices don't add up");
+ if (d->crop_l < 0 || d->crop_l + d->crop_w > d->raw_w || d->crop_t + d->crop_h > d->raw_h || d->crop_w < 64)
+ {
+ /* no sensor info: the EOS M's picture area, scaled to this sensor */
+ d->crop_l = d->raw_w * 84 / 5280; d->crop_t = d->raw_h * 64 / 3528;
+ d->crop_w = d->raw_w - d->crop_l - d->raw_w * 12 / 5280;
+ d->crop_h = d->raw_h - d->crop_t - d->raw_h * 8 / 3528;
+ d->ob_l = 0; d->ob_r = d->crop_l - 12;
+ }
+ if (d->ob_r - d->ob_l < 16)
+ {
+ /* No black mask given (the EOS M gives none): the masked columns
+ * left of the picture, well clear of it. The picture area Canon
+ * names starts at 84, but light already reaches column 72. */
+ d->ob_l = 0; d->ob_r = d->crop_l - 1;
+ }
+ if (d->ob_r > d->crop_l - 20) d->ob_r = d->crop_l - 20;
+ int portrait = d->orient == 6 || d->orient == 8;
+ d->rows_axis_x = portrait;
+ d->oh = FOS_PRINT_H;
+ d->ow = portrait ? FOS_PRINT_H * FOS_PRINT_H / FOS_PRINT_W : FOS_PRINT_W;
+ d->ox0 = (FOS_PRINT_W - d->ow) / 2;
+
+ d->rowoff = fos_port_alloc(d->raw_h * 4);
+ d->seg_of = fos_port_alloc(d->raw_w * 2);
+ d->seg_x0 = fos_port_alloc((FOS_PRINT_W + 1) * 2);
+ d->seg_off = fos_port_alloc(FOS_PRINT_W * 4);
+ d->rowob = fos_port_alloc(d->raw_h);
+ d->colob = fos_port_alloc(d->raw_w);
+ d->ne_r = fos_port_alloc(FOS_PRINT_W * 2 * 2);
+ d->ne_c = fos_port_alloc(FOS_PRINT_W * 2 * 2);
+ if (!d->rowoff || !d->seg_of || !d->seg_x0 || !d->seg_off || !d->rowob || !d->colob || !d->ne_r || !d->ne_c)
+ return fail_mem(d, d->raw_w * 10 + d->raw_h * 5);
+ d->no_r = d->ne_r + FOS_PRINT_W;
+ d->no_c = d->ne_c + FOS_PRINT_W;
+ memset(d->ne_r, 0, FOS_PRINT_W * 4);
+ memset(d->ne_c, 0, FOS_PRINT_W * 4);
+
+ /* raw rows: across the picture's height (landscape) or width (portrait) */
+ int rlen = portrait ? d->ow : d->oh, clen = portrait ? d->oh : d->ow;
+ int rflip = d->orient == 6 || d->orient == 3, cflip = d->orient == 8 || d->orient == 3;
+ const int32_t OUT = -1;
+ for (int y = 0; y < d->raw_h; y++)
+ {
+ int a = y - d->crop_t;
+ d->rowob[y] = a >= 0 && a < d->crop_h;
+ if (a < 0 || a >= d->crop_h) { d->rowoff[y] = OUT; continue; }
+ int o = (int) ((long) a * rlen / d->crop_h);
+ if (rflip) o = rlen - 1 - o;
+ if (y & 1) d->no_r[o]++; else d->ne_r[o]++;
+ d->rowoff[y] = 3 * (portrait ? d->ox0 + o : o * FOS_PRINT_W);
+ }
+ /* raw columns: segment k of them (in raw order) makes print line o */
+ for (int k = 0; k <= clen; k++) d->seg_x0[k] = (uint16_t) d->crop_w;
+ for (int x = 0; x < d->raw_w; x++)
+ {
+ int a = x - d->crop_l;
+ d->colob[x] = x >= d->ob_l + 4 && x <= d->ob_r - 4;
+ d->seg_of[x] = 0;
+ if (a < 0 || a >= d->crop_w) continue;
+ int k = (int) ((long) a * clen / d->crop_w);
+ if (d->seg_x0[k] > a) d->seg_x0[k] = (uint16_t) a;
+ d->seg_of[x] = (uint16_t) k;
+ int o = cflip ? clen - 1 - k : k;
+ if (x & 1) d->no_c[o]++; else d->ne_c[o]++;
+ d->seg_off[k] = 3 * (portrait ? o * FOS_PRINT_W : d->ox0 + o);
+ }
+ for (int k = 0; k <= clen; k++) d->seg_x0[k] = (uint16_t) (d->seg_x0[k] + d->crop_l);
+ /* the segments' shapes, the same on every row, for sum_row: when the
+ * samples fit word halves four times and every segment has two */
+ if (d->bits <= 14 && d->crop_w >= 2 * clen && d->crop_w <= 32 * clen)
+ {
+ d->seg_desc = fos_port_alloc(4 * clen);
+ d->desc_off = fos_port_alloc(4 * clen * 4);
+ d->seg_piece = fos_port_alloc((clen + 1) * 4);
+ if (!d->seg_desc || !d->desc_off || !d->seg_piece) return fail_mem(d, 24 * clen);
+ int n = 0;
+ for (int k = 0; k < clen; k++)
+ {
+ d->seg_piece[k] = n;
+ int s0 = d->seg_x0[k], len = d->seg_x0[k + 1] - s0, odd = s0 & 1, pairs = (len - odd) >> 1;
+ /* four pairs at most a piece; a longer segment (portrait) in more */
+ do
+ {
+ int p = pairs < 4 ? pairs : 4;
+ pairs -= p;
+ d->seg_desc[n] = (uint8_t) (p | (!pairs && ((len - odd) & 1)) << 6 | odd << 7);
+ d->desc_off[n++] = d->seg_off[k];
+ odd = 0;
+ }
+ while (pairs > 0);
+ }
+ d->seg_piece[clen] = n;
+ }
+
+ d->sums = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
+ if (!d->sums) return fail_mem(d, FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
+ memset(d->sums, 0, FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
+ d->total = (long) d->raw_w * d->raw_h;
+ d->sl = 0; d->sx = 0; d->sy = 0; d->sx0 = 0;
+ d->sw = d->slices[0] ? d->slices[1] : d->raw_w;
+ for (int c = 0; c < 4; c++) d->vpred[c] = 1 << (d->bits - 1);
+ return 1;
+}
+
+/* ---- decoding */
+
+/* a code longer than FAST_BITS, a bit at a time (vbits >= 16):
+ * len << 8 | symbol, or 0 for a code that doesn't exist */
+static int slow_symbol(const struct huff *h, uint32_t bitbuf, int vbits)
+{
+ int len = FAST_BITS;
+ int code = (int) ((bitbuf >> (vbits - len)) & ((1 << len) - 1));
+ while (len < 16 && code > h->maxcode[len])
+ {
+ len++;
+ code = (int) ((bitbuf >> (vbits - len)) & ((1u << len) - 1));
+ }
+ if (code > h->maxcode[len]) return 0;
+ return len << 8 | h->vals[h->valptr[len] + code - h->mincode[len]];
+}
+
+typedef uint32_t __attribute__((may_alias)) word;
+
+/* a byte of w is 0xFF: a zero byte of ~w, (~w - 0x01010101) & w & 0x80808080,
+ * and ~w - k is ~(w + k) */
+#define FF_IN(w) ((w) & ~((w) + 0x01010101u))
+
+/* the first 0xFF at or after p, or be: the bytes before it are taken
+ * without looking at each, sixteen at a time here */
+static __attribute__((noinline)) const uint8_t *next_ff(const uint8_t *p, const uint8_t *be)
+{
+ for (; p < be && ((uintptr_t) p & 3); p++)
+ if (*p == 0xFF) return p;
+ for (; be - p >= 16; p += 16)
+ {
+ const word *q = (const word *) p;
+ if ((FF_IN(q[0]) | FF_IN(q[1]) | FF_IN(q[2]) | FF_IN(q[3])) & 0x80808080u) break;
+ }
+ while (p < be && *p != 0xFF) p++;
+ return p;
+}
+
+/* The bit reader keeps its state in d between the decoder's calls, and in
+ * registers in its loop, which hands it over to these for what is rare:
+ * the buffer's end, the 0xFF bytes, codes longer than the one lookup. */
+
+/* at least 25 bits, the careful way: a stuffed 0xFF 0x00 is one 0xFF; any
+ * other marker ends the data, and zeros follow. Then where the next 0xFF
+ * is: below safe, the next three bytes are data in the buffer and no 0xFF. */
+static __attribute__((noinline)) void fill(struct fos_dev *d)
+{
+ uint32_t bitbuf = d->bitbuf;
+ int vbits = d->vbits;
+ const uint8_t *bp = d->bp, *be = d->be, *ff = d->ff;
+ while (vbits <= 24)
+ {
+ if (be - bp < 2)
+ {
+ int len = refill(d, bp, (int) (be - bp));
+ bp = d->buf; be = bp + len;
+ ff = 0;
+ }
+ uint32_t c = *bp++;
+ if (c == 0xFF)
+ {
+ if (!*bp) bp++;
+ else { c = 0; bp = be; d->file_pos = d->file_end; }
+ }
+ bitbuf = bitbuf << 8 | c;
+ vbits += 8;
+ }
+ d->bitbuf = bitbuf; d->vbits = vbits;
+ d->bp = bp; d->be = be;
+ if (!ff || bp > ff)
+ {
+ d->ff = next_ff(bp, be);
+ d->safe = d->ff - 2;
+ }
+}
+
+/* a difference the one lookup doesn't cover: the code, then its bits */
+static __attribute__((noinline)) int slow_diff(struct fos_dev *d, const struct huff *h)
+{
+ fill(d);
+ int e = h->fast[(d->bitbuf >> (d->vbits - FAST_BITS)) & ((1 << FAST_BITS) - 1)];
+ if (!e) e = slow_symbol(h, d->bitbuf, d->vbits);
+ d->vbits -= e >> 8;
+ int s = e & 0xFF, diff = 0;
+ if (s == 16) diff = -32768;
+ else if (s)
+ {
+ if (d->vbits < s) fill(d);
+ d->vbits -= s;
+ diff = (int) ((d->bitbuf >> d->vbits) & ((1u << s) - 1));
+ if (!(diff >> (s - 1))) diff -= (1 << s) - 1;
+ }
+ fill(d);
+ return diff;
+}
+
+#define LOAD() (bitbuf = d->bitbuf, vbits = d->vbits, bp = d->bp, safe = d->safe)
+#define SAVE() (d->bitbuf = bitbuf, d->vbits = vbits, d->bp = bp)
+
+/* at least 24 bits: two short codes' worth */
+#define FILL() \
+ do \
+ { \
+ if (__builtin_expect(bp < safe, 1)) \
+ { \
+ if (vbits <= 16) { bitbuf = bitbuf << 16 | (uint32_t) bp[0] << 8 | bp[1]; bp += 2; vbits += 16; } \
+ if (vbits <= 24) { bitbuf = bitbuf << 8 | *bp++; vbits += 8; } \
+ } \
+ else { SAVE(); fill(d); LOAD(); } \
+ } while (0)
+
+/* a difference from table h (its lookup t, read at the byte offset the
+ * mask leaves); bitbuf must hold DIFF_BITS + 1:
+ * the code and its bits in one lookup, as nearly always (99.8 % on the
+ * EOS M's files) */
+#define DIFF_OR(t, h, diff, also) \
+ do \
+ { \
+ diff = *(const int16_t *) ((const uint8_t *) (t) + ((bitbuf >> (vbits - DIFF_BITS - 1)) & ((2 << DIFF_BITS) - 2))); \
+ if (__builtin_expect(diff & 15, 1)) { vbits -= diff & 15; diff >>= 4; } \
+ else { SAVE(); diff = slow_diff(d, h); LOAD(); also; } \
+ } while (0)
+#define DIFF(t, h, diff) DIFF_OR(t, h, diff, (void) 0)
+
+/* n pairs of the two components (the EOS M's layout), each from the one
+ * to its left: on its own, so all it works with stays in registers */
+static __attribute__((noinline)) void pairs(struct fos_dev *d, uint16_t *out, int n)
+{
+ const struct huff *h0 = d->huff[0], *h1 = d->huff[1];
+ const int16_t *t0 = h0->fastd, *t1 = h1->fastd;
+ uint32_t bitbuf;
+ int vbits;
+ const uint8_t *bp, *safe;
+ LOAD();
+ int p0 = out[-2], p1 = out[-1], diff;
+ uint16_t *stop = out + 2 * n;
+ while (out < stop)
+ {
+ /* a pair takes three bytes at most: as many as safe leaves room
+ * for, without looking (until a long code, which reads on) */
+ int room = (int) (safe - bp) >> 2, left = (int) (stop - out) >> 1;
+ if (room <= 0)
+ {
+ FILL();
+ DIFF(t0, h0, diff); p0 += diff; out[0] = (uint16_t) p0;
+ DIFF(t1, h1, diff); p1 += diff; out[1] = (uint16_t) p1;
+ out += 2;
+ continue;
+ }
+ uint16_t *block = out + 2 * (room < left ? room : left);
+ for (; out < block; out += 2)
+ {
+ if (vbits <= 16) { bitbuf = bitbuf << 16 | (uint32_t) bp[0] << 8 | bp[1]; bp += 2; vbits += 16; }
+ if (vbits <= 24) { bitbuf = bitbuf << 8 | *bp++; vbits += 8; }
+ DIFF_OR(t0, h0, diff, block = out + 2); p0 += diff; out[0] = (uint16_t) p0;
+ DIFF_OR(t1, h1, diff, block = out + 2); p1 += diff; out[1] = (uint16_t) p1;
+ }
+ }
+ SAVE();
+}
+
+/* the next count samples of the lossless JPEG into out[0..count-1];
+ * out[-clrs..-1] hold the ones before */
+static __attribute__((noinline)) void unpack(struct fos_dev *d, uint16_t *out, int count)
+{
+ const int clrs = d->clrs, wide = d->wide;
+ uint32_t bitbuf;
+ int vbits;
+ const uint8_t *bp, *safe;
+ int comp = d->comp, jcol = d->jcol;
+ uint16_t *end = out + count;
+ while (out < end)
+ {
+ int diff;
+ if (jcol && !comp && end - out >= clrs && (clrs == 2 || clrs == 4))
+ {
+ /* whole groups of the components, each from the one to its
+ * left, kept in registers */
+ int n = wide - jcol;
+ if (n > (int) (end - out) / clrs) n = (int) (end - out) / clrs;
+ jcol += n;
+ if (jcol == wide) jcol = 0;
+ if (clrs == 2)
+ {
+ pairs(d, out, n);
+ out += 2 * n;
+ }
+ else
+ {
+ const struct huff *h0 = d->huff[0], *h1 = d->huff[1], *h2 = d->huff[2], *h3 = d->huff[3];
+ uint16_t *stop = out + 4 * n;
+ int p0 = out[-4], p1 = out[-3], p2 = out[-2], p3 = out[-1];
+ LOAD();
+ for (; out < stop; out += 4)
+ {
+ FILL();
+ DIFF(h0->fastd, h0, diff); p0 += diff; out[0] = (uint16_t) p0;
+ DIFF(h1->fastd, h1, diff); p1 += diff; out[1] = (uint16_t) p1;
+ FILL();
+ DIFF(h2->fastd, h2, diff); p2 += diff; out[2] = (uint16_t) p2;
+ DIFF(h3->fastd, h3, diff); p3 += diff; out[3] = (uint16_t) p3;
+ }
+ SAVE();
+ }
+ continue;
+ }
+ /* one at a time: a row's first group (predicted from above), odd
+ * layouts, the ends of the count */
+ const struct huff *h = d->huff[comp];
+ LOAD();
+ FILL();
+ DIFF(h->fastd, h, diff);
+ SAVE();
+ if (jcol) *out = (uint16_t) (out[-clrs] + diff);
+ else *out = (uint16_t) (d->vpred[comp] += diff);
+ out++;
+ if (++comp == clrs)
+ {
+ comp = 0;
+ if (++jcol == wide) jcol = 0;
+ }
+ }
+ d->comp = comp; d->jcol = jcol;
+}
+
+/* a raw row's samples v..vend-1 into its print pixels: segment by segment
+ * (next: where the next starts, at[] the sample of a column; off: where
+ * the segment goes in row), its even and odd columns apart */
+static __attribute__((noinline)) void sum_samples(const uint16_t *at, const uint16_t *v, const uint16_t *vend,
+ const uint16_t *next, const int32_t *off, uint32_t *row)
+{
+ while (v < vend)
+ {
+ const uint16_t *ve = at + *next++;
+ if (ve > vend) ve = vend;
+ uint32_t a = 0, b = 0;
+ if ((v - at) & 1) b = *v++;
+ for (; ve - v >= 2; v += 2) { a += v[0]; b += v[1]; }
+ if (v < ve) a += *v++;
+ uint32_t *p = row + *off++;
+ p[0] += a;
+ p[1] += b;
+ }
+}
+
+/* a whole row of the picture the same way, in the pieces seg_desc gives
+ * (n of them; off: where each goes in row), with the even columns 4-byte
+ * aligned: a pair of samples as one word, and up to four pairs of 14 bits
+ * summed in its halves */
+static __attribute__((noinline)) void sum_row(const uint16_t *v, const uint8_t *desc, int n, const int32_t *off, uint32_t *row)
+{
+ for (const uint8_t *e = desc + n; desc < e; desc++, off++)
+ {
+ int k = *desc;
+ uint32_t b = 0;
+ if (k & 0x80) b = *v++;
+ const word *q = (const word *) v;
+ uint32_t w = 0;
+ switch (k & 7)
+ {
+ case 4: w += q[3]; /* fall through */
+ case 3: w += q[2]; /* fall through */
+ case 2: w += q[1]; /* fall through */
+ case 1: w += q[0]; /* fall through */
+ default: break;
+ }
+ v += 2 * (k & 7);
+ uint32_t a = w & 0xFFFF;
+ if (k & 0x40) a += *v++;
+ uint32_t *p = row + *off;
+ p[0] += a;
+ p[1] += b + (w >> 16);
+ }
+}
+
+/* count samples to where they fall in the print, slice by slice, top to
+ * bottom: a print pixel's run of samples along a raw row is summed in
+ * registers, even and odd columns (two colours of the mosaic) apart, and
+ * added once. The masked columns left of the picture give the black. */
+static __attribute__((noinline)) void scatter(struct fos_dev *d, const uint16_t *src, int n)
+{
+ uint32_t *sums = d->sums;
+ const uint16_t *seg_x0 = d->seg_x0, *seg_of = d->seg_of;
+ const int32_t *seg_off = d->seg_off;
+ const uint8_t *colob = d->colob;
+ const int pic0 = d->crop_l, pic1 = d->crop_l + d->crop_w;
+ const uint8_t *desc = d->seg_desc;
+ int sx = d->sx, sy = d->sy, sw = d->sw, sx0 = d->sx0;
+ int64_t black_sum = d->black_sum;
+ long black_n = d->black_n;
+ while (n > 0)
+ {
+ int run = sw - sx < n ? sw - sx : n;
+ n -= run;
+ const int ro = d->rowoff[sy];
+#ifdef FOS_DEV_TEST
+ for (int k = 0; k < run; k++) fos_dev_test_sample(sx0 + sx + k, sy, src[k]);
+#endif
+ if (ro >= 0)
+ {
+ const int x0 = sx0 + sx, x1 = x0 + run;
+ const int pa = x0 > pic0 ? x0 : pic0, pb = x1 < pic1 ? x1 : pic1;
+ for (int x = x0; x < x1 && x < pa; x++)
+ if (colob[x]) { black_sum += src[x - x0]; black_n++; }
+ if (pa < pb)
+ {
+ /* sample of raw column x at at[x]; RGGB at the sensor's top
+ * left: the even columns' colour, then the odd ones' */
+ const uint16_t *at = src - x0;
+ uint32_t *row = sums + ro + (sy & 1);
+ /* the segments it touches, and those it has whole (a row
+ * of the picture is in two of Canon's slices) */
+ int k0 = seg_of[pa], k1 = seg_of[pb - 1] + 1;
+ int w0 = seg_x0[k0] < pa ? k0 + 1 : k0, w1 = seg_x0[k1] > pb ? k1 - 1 : k1;
+ if (!desc || ((uintptr_t) at & 3) || w0 >= w1)
+ sum_samples(at, at + pa, at + pb, seg_x0 + k0 + 1, seg_off + k0, row);
+ else
+ {
+ if (w0 > k0) sum_samples(at, at + pa, at + seg_x0[w0], seg_x0 + k0 + 1, seg_off + k0, row);
+ const int i0 = d->seg_piece[w0];
+ sum_row(at + seg_x0[w0], desc + i0, d->seg_piece[w1] - i0, d->desc_off + i0, row);
+ if (w1 < k1) sum_samples(at, at + seg_x0[w1], at + pb, seg_x0 + w1 + 1, seg_off + w1, row);
+ }
+ }
+ }
+ src += run;
+ sx += run;
+ if (sx == sw)
+ {
+ sx = 0;
+ if (++sy == d->raw_h)
+ {
+ sy = 0;
+ sx0 += sw;
+ d->sl++;
+ sw = d->sl < d->slices[0] ? d->slices[1] : d->slices[2];
+ }
+ }
+ }
+ d->sx = sx; d->sy = sy; d->sw = sw; d->sx0 = sx0;
+ d->black_sum = black_sum; d->black_n = black_n;
+}
+
+/* decode about n samples straight into the print's sums */
+static void decode(struct fos_dev *d, long n)
+{
+ uint16_t *s = d->samples + 4;
+ while (n > 0 && d->done < d->total)
+ {
+ /* to the end of a raw row, so scatter has it whole */
+ int k = d->sw - d->sx;
+ if (k > UNPACK) k = UNPACK;
+ if (k > d->total - d->done) k = (int) (d->total - d->done);
+ unpack(d, s, k);
+ scatter(d, s, k);
+ /* the last of each component, for the next ones' prediction */
+ memmove(s - d->clrs, s + k - d->clrs, d->clrs * 2);
+ d->done += k;
+ n -= k;
+ }
+}
+
+/* ---- finishing */
+
+/* 65536 / n for the samples a print pixel's channel got */
+static uint32_t recip[64];
+
+/* scene-linear sRGB of print pixel i (4096 = 1.0), clipped as the lab's
+ * RAW converter does, times d->mul; 0 where the picture isn't */
+FOS_INLINE void pixel_linear(const struct fos_dev *d, int x, int y, int lin[3])
+{
+ int i = y * FOS_PRINT_W + x;
+ int xr, xc; /* print line fed by raw rows / columns */
+ if (d->rows_axis_x) { xr = x - d->ox0; xc = y; if (xr < 0 || xr >= d->ow) { lin[0] = lin[1] = lin[2] = 0; return; } }
+ else { xr = y; xc = x; }
+ int er = d->ne_r[xr], or_ = d->no_r[xr], ec = d->ne_c[xc], oc = d->no_c[xc];
+ int n[3] = { er * ec, er * oc + or_ * ec, or_ * oc };
+ int cam[3];
+ for (int c = 0; c < 3; c++)
+ {
+ /* the mean (sums <= 16383 n, so this fits), less black, balanced */
+ int m = n[c] < 64 ? (int) (d->sums[3 * i + c] * recip[n[c]] >> 12) - d->black16 : 0;
+ int v = m > 0 ? (int) (((int64_t) m * d->pre[c]) >> 14) : 0;
+ cam[c] = v < 0 ? 0 : v > 4096 ? 4096 : v;
+ }
+ for (int c = 0; c < 3; c++)
+ {
+ int v = (d->mat[c][0] * cam[0] + d->mat[c][1] * cam[1] + d->mat[c][2] * cam[2]) >> 12;
+ v = v < 0 ? 0 : v > 4096 ? 4096 : v;
+ v = (v * d->mul[c]) >> 12;
+ lin[c] = v > 65535 ? 65535 : v;
+ }
+}
+
+/* camera -> sRGB with daylight balance, and the black and white levels */
+static void setup_colour(struct fos_dev *d)
+{
+ float cam_rgb[3][3], pre[3];
+ for (int i = 0; i < 3; i++)
+ {
+ float sum = 0;
+ for (int j = 0; j < 3; j++)
+ {
+ cam_rgb[i][j] = 0;
+ for (int k = 0; k < 3; k++) cam_rgb[i][j] += XYZ_CAM[i][k] * RGB_XYZ[k][j];
+ sum += cam_rgb[i][j];
+ }
+ for (int j = 0; j < 3; j++) cam_rgb[i][j] /= sum;
+ pre[i] = 1 / sum;
+ }
+ float green = pre[1];
+ for (int i = 0; i < 3; i++) pre[i] /= green;
+ /* rgb_cam = inverse(cam_rgb) */
+ float (*m)[3] = cam_rgb, inv[3][3];
+ float det = m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
+ + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
+ inv[0][0] = (m[1][1] * m[2][2] - m[1][2] * m[2][1]) / det;
+ inv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) / det;
+ inv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) / det;
+ inv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) / det;
+ inv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) / det;
+ inv[1][2] = (m[0][2] * m[1][0] - m[0][0] * m[1][2]) / det;
+ inv[2][0] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) / det;
+ inv[2][1] = (m[0][1] * m[2][0] - m[0][0] * m[2][1]) / det;
+ inv[2][2] = (m[0][0] * m[1][1] - m[0][1] * m[1][0]) / det;
+
+ float black = d->black_n ? (float) d->black_sum / (float) d->black_n : 2048;
+ if (black < 0 || black > WHITE_LEVEL / 2) black = 2048; /* a damaged file */
+ d->black16 = (int) (black * 16 + 0.5f);
+ /* raw/16 above black -> 4096 at the white level, balanced, << 14 */
+ for (int c = 0; c < 3; c++)
+ {
+ d->pre[c] = (int) (pre[c] * 4096 * 16384 / ((WHITE_LEVEL - black) * 16) + 0.5f);
+ d->mul[c] = 4096;
+ for (int j = 0; j < 3; j++) d->mat[c][j] = (int) (inv[c][j] * 4096 + (inv[c][j] < 0 ? -0.5f : 0.5f));
+ }
+ for (int k = 1; k < 64; k++) recip[k] = 65536 / k;
+}
+
+/* small, fast noise */
+FOS_INLINE int rnd(unsigned *s)
+{
+ *s = *s * 1664525u + 1013904223u;
+ return (int) (*s >> 16 & 0xFFFF) - 32768;
+}
+
+/* ---------------------------------------------------------------- palette */
+
+/* median cut over a 5-5-5 histogram (struct box: with struct fos_dev) */
+
+static void box_shrink(const uint32_t *hist, struct box *b)
+{
+ int lo[3] = { 31, 31, 31 }, hi[3] = { 0, 0, 0 };
+ long count = 0;
+ for (int r = b->lo[0]; r <= b->hi[0]; r++)
+ for (int g = b->lo[1]; g <= b->hi[1]; g++)
+ for (int bl = b->lo[2]; bl <= b->hi[2]; bl++)
+ {
+ uint32_t n = hist[r << 10 | g << 5 | bl];
+ if (!n) continue;
+ count += n;
+ if (r < lo[0]) lo[0] = r;
+ if (r > hi[0]) hi[0] = r;
+ if (g < lo[1]) lo[1] = g;
+ if (g > hi[1]) hi[1] = g;
+ if (bl < lo[2]) lo[2] = bl;
+ if (bl > hi[2]) hi[2] = bl;
+ }
+ if (count) { memcpy(b->lo, lo, sizeof(lo)); memcpy(b->hi, hi, sizeof(hi)); }
+ b->count = count;
+}
+
+static void median_cut(struct fos_dev *d)
+{
+ struct box *boxes = d->boxes;
+ int n = 1;
+ boxes[0].lo[0] = boxes[0].lo[1] = boxes[0].lo[2] = 0;
+ boxes[0].hi[0] = boxes[0].hi[1] = boxes[0].hi[2] = 31;
+ box_shrink(d->hist, &boxes[0]);
+ while (n < FOS_PRINT_COLOURS)
+ {
+ /* the box with the most pixels that can still be split, weighted
+ * by its size so big smooth areas get their share */
+ int best = -1;
+ long best_score = 0;
+ for (int i = 0; i < n; i++)
+ {
+ struct box *b = &boxes[i];
+ int span = 0;
+ for (int c = 0; c < 3; c++) if (b->hi[c] - b->lo[c] > span) span = b->hi[c] - b->lo[c];
+ if (!span) continue;
+ long score = b->count * (span + 1);
+ if (score > best_score) { best_score = score; best = i; }
+ }
+ if (best < 0) break;
+ struct box *b = &boxes[best];
+ int axis = 0, span = -1;
+ for (int c = 0; c < 3; c++) if (b->hi[c] - b->lo[c] > span) { span = b->hi[c] - b->lo[c]; axis = c; }
+ /* the median along that axis */
+ long half = b->count / 2, acc = 0;
+ int cut = b->lo[axis];
+ for (int v = b->lo[axis]; v < b->hi[axis]; v++)
+ {
+ int lo[3] = { b->lo[0], b->lo[1], b->lo[2] }, hi[3] = { b->hi[0], b->hi[1], b->hi[2] };
+ lo[axis] = hi[axis] = v;
+ for (int r = lo[0]; r <= hi[0]; r++)
+ for (int g = lo[1]; g <= hi[1]; g++)
+ for (int bl = lo[2]; bl <= hi[2]; bl++)
+ acc += d->hist[r << 10 | g << 5 | bl];
+ cut = v;
+ if (acc >= half) break;
+ }
+ struct box nb = *b;
+ b->hi[axis] = cut;
+ nb.lo[axis] = cut + 1;
+ box_shrink(d->hist, b);
+ box_shrink(d->hist, &nb);
+ boxes[n++] = nb;
+ }
+ /* each box's colour: the mean of its pixels */
+ d->npal = n;
+ for (int i = 0; i < n; i++)
+ {
+ const struct box *b = &boxes[i];
+ int64_t s[3] = { 0, 0, 0 }, cnt = 0;
+ for (int r = b->lo[0]; r <= b->hi[0]; r++)
+ for (int g = b->lo[1]; g <= b->hi[1]; g++)
+ for (int bl = b->lo[2]; bl <= b->hi[2]; bl++)
+ {
+ uint32_t k = d->hist[r << 10 | g << 5 | bl];
+ s[0] += (int64_t) k * (r * 8 + 4); s[1] += (int64_t) k * (g * 8 + 4); s[2] += (int64_t) k * (bl * 8 + 4);
+ cnt += k;
+ }
+ for (int c = 0; c < 3; c++)
+ d->pal[i][c] = (uint8_t) (cnt ? (s[c] + cnt / 2) / cnt : 0);
+ }
+}
+
+/* the palette in order of green, to search outwards from the nearest
+ * green and stop once green alone is further than the best so far */
+static void sort_palette(struct fos_dev *d)
+{
+ uint8_t *by_green = d->by_green;
+ for (int i = 0; i < d->npal; i++)
+ {
+ int j = i;
+ for (; j > 0 && d->pal[by_green[j - 1]][1] > d->pal[i][1]; j--) by_green[j] = by_green[j - 1];
+ by_green[j] = (uint8_t) i;
+ }
+}
+
+/* the nearest palette entry for a 5-5-5 cell, worked out when first needed */
+static __attribute__((noinline)) int nearest(struct fos_dev *d, int cell)
+{
+ int v = d->inv[cell];
+ if (v) return v - 1;
+ int r = (cell >> 10) * 8 + 4, g = (cell >> 5 & 31) * 8 + 4, b = (cell & 31) * 8 + 4;
+ const uint8_t *by_green = d->by_green;
+ int lo = 0, hi = d->npal;
+ while (lo < hi)
+ {
+ int mid = (lo + hi) >> 1;
+ if (d->pal[by_green[mid]][1] < g) lo = mid + 1; else hi = mid;
+ }
+ int best = by_green[lo < d->npal ? lo : d->npal - 1], bd = 1 << 30;
+ for (int up = lo, down = lo - 1; up < d->npal || down >= 0; )
+ {
+ int done = 1;
+ if (up < d->npal)
+ {
+ const uint8_t *p = d->pal[by_green[up]];
+ int dg = p[1] - g;
+ if (4 * dg * dg < bd)
+ {
+ int dr = r - p[0], db = b - p[2], dd = 3 * dr * dr + 4 * dg * dg + 2 * db * db;
+ if (dd < bd) { bd = dd; best = by_green[up]; }
+ up++;
+ done = 0;
+ }
+ else up = d->npal;
+ }
+ if (down >= 0)
+ {
+ const uint8_t *p = d->pal[by_green[down]];
+ int dg = g - p[1];
+ if (4 * dg * dg < bd)
+ {
+ int dr = r - p[0], db = b - p[2], dd = 3 * dr * dr + 4 * dg * dg + 2 * db * db;
+ if (dd < bd) { bd = dd; best = by_green[down]; }
+ down--;
+ done = 0;
+ }
+ else down = -1;
+ }
+ if (done) break;
+ }
+ d->inv[cell] = (uint8_t) (best + 1);
+ return best;
+}
+
+/* ---------------------------------------------------------------- files */
+
+/* the overlay's colours over a photograph: black, a panel, greys up to
+ * white for text on it, the accent, red, a line, and a dim grey */
+const uint8_t fos_fixed_rgb[FOS_FIXED_N][3] =
+{
+ { 0, 0, 0 }, { 22, 21, 20 }, { 52, 50, 48 }, { 88, 85, 82 }, { 128, 124, 120 }, { 170, 166, 160 },
+ { 210, 206, 200 }, { 244, 241, 236 }, { 236, 168, 52 }, { 150, 104, 34 }, { 214, 64, 52 }, { 60, 58, 56 },
+ { 112, 108, 104 }, { 0, 0, 0 },
+};
+
+/* A print is an 8-bit BMP, so it also opens on a PC: the file and info
+ * headers, 256 palette entries (1..240 the print's), our own header with
+ * the frame's details, the pixels top row first, then the thumbnail. */
+#define BMP_PAL (14 + 40)
+#define BMP_META (BMP_PAL + 256 * 4)
+#define META_SIZE 64
+#define BMP_PIXELS (BMP_META + META_SIZE)
+#define BMP_THUMB (BMP_PIXELS + FOS_PRINT_W * FOS_PRINT_H)
+#define THUMB_SIZE (FOS_THUMB_W * FOS_THUMB_H * 3)
+#define BMP_SIZE (BMP_THUMB + THUMB_SIZE)
+
+
+static int write_print(const char *path, int film, int frame, const char *when, const char *fstop,
+ const uint8_t pal[][3], int npal, const uint8_t *px, const uint8_t *thumb, int x0, int w)
+{
+ static uint8_t h[BMP_PIXELS];
+ memset(h, 0, sizeof(h));
+ h[0] = 'B'; h[1] = 'M';
+ put32(h + 2, BMP_SIZE);
+ put32(h + 10, BMP_PIXELS);
+ put32(h + 14, 40);
+ put32(h + 18, FOS_PRINT_W);
+ put32(h + 22, (uint32_t) -FOS_PRINT_H); /* top-down */
+ h[26] = 1; h[28] = 8;
+ put32(h + 34, FOS_PRINT_W * FOS_PRINT_H);
+ put32(h + 38, 2835); put32(h + 42, 2835); /* 72 dpi */
+ put32(h + 46, 256);
+ for (int i = 0; i < npal && i < FOS_PRINT_COLOURS; i++)
+ {
+ uint8_t *q = h + BMP_PAL + 4 * (i + 1);
+ q[0] = pal[i][2]; q[1] = pal[i][1]; q[2] = pal[i][0];
+ }
+ uint8_t *m = h + BMP_META;
+ memcpy(m, "FOP2", 4);
+ m[4] = (uint8_t) film;
+ m[6] = (uint8_t) frame; m[7] = (uint8_t) (frame >> 8);
+ if (when) memcpy(m + 8, when, strlen(when) < 19 ? strlen(when) : 19);
+ if (fstop) memcpy(m + 28, fstop, strlen(fstop) < 7 ? strlen(fstop) : 7);
+ m[36] = (uint8_t) x0; m[37] = (uint8_t) (x0 >> 8); /* the picture's columns */
+ m[38] = (uint8_t) w; m[39] = (uint8_t) (w >> 8);
+
+ void *f = fos_port_open(path, 1);
+ if (!f) return 0;
+ int ok = fos_port_write(f, h, BMP_PIXELS) == BMP_PIXELS
+ && fos_port_write(f, px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H
+ && fos_port_write(f, thumb, THUMB_SIZE) == THUMB_SIZE;
+ fos_port_close(f);
+ return ok;
+}
+
+static int is_print(const uint8_t *h)
+{
+ return h[0] == 'B' && h[1] == 'M' && u32le(h + 10) == BMP_PIXELS && u32le(h + 18) == FOS_PRINT_W
+ && !memcmp(h + BMP_META, "FOP2", 4);
+}
+
+int fos_print_thumb(const char *path, uint8_t *thumb)
+{
+ void *f = fos_port_open(path, 0);
+ if (!f) return 0;
+ static uint8_t h[BMP_PIXELS];
+ int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h)
+ && fos_port_seek(f, BMP_THUMB) >= 0 && fos_port_read(f, thumb, THUMB_SIZE) == THUMB_SIZE;
+ fos_port_close(f);
+ return ok;
+}
+
+int fos_print_load(const char *path, struct fos_print *p)
+{
+ memset(p, 0, sizeof(*p));
+ void *f = fos_port_open(path, 0);
+ if (!f) return 0;
+ static uint8_t h[BMP_PIXELS];
+ int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h);
+ if (ok)
+ {
+ const uint8_t *m = h + BMP_META;
+ p->film = m[4];
+ p->frame = u16le(m + 6);
+ memcpy(p->when, m + 8, 19);
+ memcpy(p->fstop, m + 28, 7);
+ p->x0 = u16le(m + 36);
+ p->w = u16le(m + 38);
+ if (!p->w || p->x0 + p->w > FOS_PRINT_W) p->x0 = 0, p->w = FOS_PRINT_W;
+ for (int i = 0; i < FOS_PRINT_COLOURS; i++)
+ {
+ const uint8_t *q = h + BMP_PAL + 4 * (i + 1);
+ p->pal[i][0] = q[2]; p->pal[i][1] = q[1]; p->pal[i][2] = q[0];
+ }
+ p->px = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
+ ok = p->px && fos_port_read(f, p->px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H;
+ }
+ fos_port_close(f);
+ if (!ok) fos_print_free(p);
+ return ok;
+}
+
+void fos_print_free(struct fos_print *p)
+{
+ fos_port_free(p->px);
+ p->px = 0;
+}
+
+/* ---------------------------------------------------------------- quantize an RGB print */
+
+/* histogram, palette, error diffusion: rows y0..y1-1 of the dithering per
+ * call (the histogram and palette when y0 == 0) */
+static int quant_alloc(struct fos_dev *d)
+{
+ d->hist = fos_port_alloc(32768 * 4);
+ d->inv = fos_port_alloc(32768);
+ d->err_rows = fos_port_alloc((FOS_PRINT_W + 2) * 3 * 2 * 2);
+ if (!d->idx) d->idx = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
+ if (!d->hist || !d->inv || !d->err_rows || !d->idx) return 0;
+ memset(d->hist, 0, 32768 * 4);
+ memset(d->inv, 0, 32768);
+ memset(d->err_rows, 0, (FOS_PRINT_W + 2) * 3 * 2 * 2);
+ for (int i = 0; i < FOS_PRINT_W * FOS_PRINT_H; i++)
+ {
+ const uint8_t *p = d->rgb + 3 * i;
+ d->hist[(p[0] >> 3) << 10 | (p[1] >> 3) << 5 | p[2] >> 3]++;
+ }
+ median_cut(d);
+ sort_palette(d);
+ return 1;
+}
+
+static __attribute__((noinline)) void dither_rows(struct fos_dev *d, int y0, int y1)
+{
+ const int W = FOS_PRINT_W;
+ const uint8_t *inv = d->inv;
+ const uint8_t (*pal)[3] = d->pal;
+ for (int y = y0; y < y1; y++)
+ {
+ /* serpentine: every other row right to left */
+ const int dir = y & 1 ? -1 : 1, st = 3 * dir;
+ int16_t *cur = d->err_rows + ((y & 1) ? (W + 2) * 3 : 0);
+ int16_t *nxt = d->err_rows + ((y & 1) ? 0 : (W + 2) * 3);
+ memset(nxt, 0, (W + 2) * 3 * 2);
+ const int x = dir > 0 ? 0 : W - 1;
+ const uint8_t *p = d->rgb + 3 * (y * W + x);
+ uint8_t *o = d->idx + y * W + x;
+ int16_t *c = cur + (x + 1) * 3, *n = nxt + (x + 1) * 3;
+ for (int k = 0; k < W; k++, p += st, o += dir, c += st, n += st)
+ {
+ int r = p[0] + (c[0] >> 4), g = p[1] + (c[1] >> 4), b = p[2] + (c[2] >> 4);
+ r = r < 0 ? 0 : r > 255 ? 255 : r;
+ g = g < 0 ? 0 : g > 255 ? 255 : g;
+ b = b < 0 ? 0 : b > 255 ? 255 : b;
+ int cell = (r >> 3) << 10 | (g >> 3) << 5 | b >> 3;
+ int i = inv[cell] ? inv[cell] - 1 : nearest(d, cell);
+ *o = (uint8_t) (i + 1);
+ const uint8_t *q = pal[i];
+ /* Floyd-Steinberg, in 1/16 */
+ int e = r - q[0];
+ c[st] = (int16_t) (c[st] + e * 7); n[-st] = (int16_t) (n[-st] + e * 3); n[0] = (int16_t) (n[0] + e * 5); n[st] = (int16_t) (n[st] + e);
+ e = g - q[1];
+ c[st + 1] = (int16_t) (c[st + 1] + e * 7); n[1 - st] = (int16_t) (n[1 - st] + e * 3); n[1] = (int16_t) (n[1] + e * 5); n[st + 1] = (int16_t) (n[st + 1] + e);
+ e = b - q[2];
+ c[st + 2] = (int16_t) (c[st + 2] + e * 7); n[2 - st] = (int16_t) (n[2 - st] + e * 3); n[2] = (int16_t) (n[2] + e * 5); n[st + 2] = (int16_t) (n[st + 2] + e);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- one frame */
+
+struct fos_dev *fos_dev_start(const char *cr2, const char *print, int film, int frame,
+ const char *when, const char *fstop)
+{
+ struct fos_dev *d = fos_port_alloc(sizeof(struct fos_dev));
+ if (!d) return 0;
+ memset(d, 0, sizeof(*d));
+ snprintf(d->cr2, sizeof(d->cr2), "%s", cr2);
+ snprintf(d->print, sizeof(d->print), "%s", print);
+ snprintf(d->when, sizeof(d->when), "%s", when ? when : "");
+ snprintf(d->fstop, sizeof(d->fstop), "%s", fstop ? fstop : "");
+ d->film = fos_clamp(film, 0, fos_nfilms - 1);
+ d->frame = frame;
+ d->look = fos_look_of(fos_films[d->film].key);
+ d->seed = 12345u + (unsigned) frame * 7919u;
+ d->stage = ST_OPEN;
+ return d;
+}
+
+void fos_dev_jpeg(struct fos_dev *d, const char *path)
+{
+ if (d) snprintf(d->jpeg, sizeof(d->jpeg), "%s", path ? path : "");
+}
+
+void fos_dev_free(struct fos_dev *d)
+{
+ if (!d) return;
+ if (d->f) fos_port_close(d->f);
+ fos_port_free(d->buf); fos_port_free(d->rowoff); fos_port_free(d->seg_of);
+ fos_port_free(d->seg_x0); fos_port_free(d->seg_off); fos_port_free(d->seg_desc); fos_port_free(d->desc_off); fos_port_free(d->seg_piece);
+ fos_port_free(d->rowob); fos_port_free(d->colob); fos_port_free(d->ne_r); fos_port_free(d->ne_c);
+ fos_port_free(d->sums); fos_port_free(d->glow); fos_port_free(d->rgb);
+ fos_port_free(d->hist); fos_port_free(d->inv); fos_port_free(d->err_rows); fos_port_free(d->idx);
+ fos_port_free(d);
+}
+
+const uint8_t *fos_dev_thumb(const struct fos_dev *d)
+{
+ return d && d->stage == ST_DONE ? d->thumb : 0;
+}
+
+const char *fos_dev_error(const struct fos_dev *d)
+{
+ return d ? d->err : "out of memory";
+}
+
+int fos_dev_doing(const struct fos_dev *d)
+{
+ if (!d) return FOS_DEV_FAILED;
+ switch (d->stage)
+ {
+ case ST_OPEN: return FOS_DEV_MIXING;
+ case ST_DECODE: return lut_film == d->film && lut_built >= NGRID ? FOS_DEV_DEVELOPING : FOS_DEV_MIXING;
+ case ST_KEY: case ST_EXPOSE: case ST_GLOW: case ST_FINISH: return FOS_DEV_FIXING;
+ case ST_JPEG: case ST_QUANT: case ST_DITHER: case ST_WRITE: return FOS_DEV_DRYING;
+ case ST_DONE: return FOS_DEV_DONE;
+ }
+ return FOS_DEV_FAILED;
+}
+
+/* how far along, 0..1000: decoding is most of the work */
+static int progress(const struct fos_dev *d)
+{
+ const int H = FOS_PRINT_H;
+ switch (d->stage)
+ {
+ case ST_OPEN: return 0;
+ case ST_DECODE: return d->total ? (int) ((int64_t) d->done * 800 / d->total) : 0; /* 64 bits: long is 32 on the camera */
+ case ST_KEY: return 800;
+ case ST_EXPOSE: return 805 + d->row * 60 / H;
+ case ST_GLOW: return 865;
+ case ST_FINISH: return 870 + d->row * 64 / H;
+ case ST_JPEG: return 934;
+ case ST_QUANT: return 940;
+ case ST_DITHER: return 950 + d->row * 45 / H;
+ case ST_WRITE: return 995;
+ case ST_DONE: return 1000;
+ }
+ return -1;
+}
+
+void fos_dev_picture(const struct fos_dev *d, int *x0, int *w)
+{
+ *x0 = d && d->rows_axis_x ? d->ox0 : 0;
+ *w = d && d->rows_axis_x ? d->ow : FOS_PRINT_W;
+}
+
+int fos_dev_progress(const struct fos_dev *d)
+{
+ return d ? progress(d) : -1;
+}
+
+/* the lab scanner: the log-average luminance to a fixed key (negatives),
+ * or what was exposed (slides); then the film's balance */
+static void stage_key(struct fos_dev *d)
+{
+ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
+ float ev = 1.0f;
+ if (!d->look->slide)
+ {
+ /* counted in a histogram so the logs are few */
+ uint32_t *hist = (uint32_t *) d->rgb; /* free until ST_FINISH */
+ memset(hist, 0, 4097 * 4);
+ int n = 0;
+ for (int y = 0; y < H; y += 4) /* as the lab: every fourth pixel */
+ for (int x = 0; x < W; x += 4)
+ {
+ int lin[3];
+ if (d->rows_axis_x && (x < d->ox0 || x >= d->ox0 + d->ow)) continue;
+ pixel_linear(d, x, y, lin);
+ hist[(871 * lin[0] + 2929 * lin[1] + 296 * lin[2]) >> 12]++;
+ n++;
+ }
+ float acc = 0;
+ for (int v = 0; v <= 4096; v++)
+ if (hist[v]) acc += (float) hist[v] * logf(v / 4096.0f + 1e-4f);
+ float key = n ? expf(acc / (float) n) : 0.11f;
+ ev = log2f(0.11f / key);
+ ev = ev < -2 ? -2 : ev > 3.5f ? 3.5f : ev;
+#ifdef FOS_DEV_TEST
+ fprintf(stderr, "scanner: key %.4f, %.3f EV; black %d/16, pre %d %d %d\n", (double) key, (double) ev, d->black16, d->pre[0], d->pre[1], d->pre[2]);
+#endif
+ }
+ float k = exp2f(ev + d->look->ev);
+ float bal[3] = { 1, 1, 1 };
+ if (d->look->balance != 5500)
+ {
+ float a[3], b[3];
+ cct_rgb(5500, a);
+ cct_rgb((float) d->look->balance, b);
+ for (int c = 0; c < 3; c++) bal[c] = a[c] / b[c];
+ for (int c = 0; c < 3; c++) bal[c] /= a[1] / b[1];
+ }
+ for (int c = 0; c < 3; c++) d->mul[c] = (int) (k * bal[c] * 4096 + 0.5f);
+}
+
+/* Exposing a row goes in two passes, each small enough for the
+ * registers: the camera's colours, then linear sRGB. */
+
+/* n pixels' sums to camera colour (4096 = white): the means (of counts
+ * fixed a, b times along x ra[], rb[]: the even and odd raw rows and
+ * columns), less black, balanced */
+static __attribute__((noinline)) void expose_cam(const struct fos_dev *d, const uint32_t *sm, uint16_t *cam, int n,
+ int a, int b, const uint16_t *ra, const uint16_t *rb)
+{
+ const int black = d->black16, p0 = d->pre[0], p1 = d->pre[1], p2 = d->pre[2];
+ for (const uint16_t *e = ra + n; ra < e; ra++, rb++, sm += 3, cam += 3)
+ {
+ int n0 = a * *ra, n1 = a * *rb + b * *ra, n2 = b * *rb;
+ int c0 = 0, c1 = 0, c2 = 0;
+ /* (sums <= 16383 n, so this fits) */
+ if (n0 < 64) { int m = (int) (sm[0] * recip[n0] >> 12) - black; if (m > 0) { c0 = (m * p0) >> 14; if (c0 > 4096) c0 = 4096; } }
+ if (n1 < 64) { int m = (int) (sm[1] * recip[n1] >> 12) - black; if (m > 0) { c1 = (m * p1) >> 14; if (c1 > 4096) c1 = 4096; } }
+ if (n2 < 64) { int m = (int) (sm[2] * recip[n2] >> 12) - black; if (m > 0) { c2 = (m * p2) >> 14; if (c2 > 4096) c2 = 4096; } }
+ cam[0] = (uint16_t) c0; cam[1] = (uint16_t) c1; cam[2] = (uint16_t) c2;
+ }
+}
+
+/* n pixels' camera colour to linear sRGB (4096 = 1.0) at o, exposed and
+ * balanced for the film; the highlights into the glow row g from x */
+static __attribute__((noinline)) void expose_lin(const struct fos_dev *d, const uint16_t *cam, uint16_t *o, int n,
+ int32_t *g, int x)
+{
+ const int m00 = d->mat[0][0], m01 = d->mat[0][1], m02 = d->mat[0][2];
+ const int m10 = d->mat[1][0], m11 = d->mat[1][1], m12 = d->mat[1][2];
+ const int m20 = d->mat[2][0], m21 = d->mat[2][1], m22 = d->mat[2][2];
+ const int u0 = d->mul[0], u1 = d->mul[1], u2 = d->mul[2];
+ const int thr = (int) (d->look->hal_thr * 4096);
+ for (const uint16_t *e = cam + 3 * n; cam < e; cam += 3, o += 3, x++)
+ {
+ int c0 = cam[0], c1 = cam[1], c2 = cam[2];
+ int r = (m00 * c0 + m01 * c1 + m02 * c2) >> 12;
+ int gg = (m10 * c0 + m11 * c1 + m12 * c2) >> 12;
+ int bb = (m20 * c0 + m21 * c1 + m22 * c2) >> 12;
+ r = r < 0 ? 0 : r > 4096 ? 4096 : r;
+ gg = gg < 0 ? 0 : gg > 4096 ? 4096 : gg;
+ bb = bb < 0 ? 0 : bb > 4096 ? 4096 : bb;
+ r = (r * u0) >> 12; gg = (gg * u1) >> 12; bb = (bb * u2) >> 12;
+ if (r > 65535) r = 65535;
+ if (gg > 65535) gg = 65535;
+ if (bb > 65535) bb = 65535;
+ o[0] = (uint16_t) r; o[1] = (uint16_t) gg; o[2] = (uint16_t) bb;
+ if (g)
+ {
+ int l = (871 * r + 2929 * gg + 296 * bb) >> 12;
+ if (l > thr) g[x >> 2] += l - thr;
+ }
+ }
+}
+
+/* rows y0..y1-1 to linear sRGB, in place over the sums (a row's sums are
+ * read before it is written, and its values only ever overwrite sums
+ * already read); the highlights go into the halation grid on the way. The
+ * same sums as pixel_linear, walked along the row. */
+static __attribute__((noinline)) void stage_expose(struct fos_dev *d, int y0, int y1)
+{
+ const int W = FOS_PRINT_W;
+ uint16_t *lin = (uint16_t *) d->sums;
+ for (int y = y0; y < y1; y++)
+ {
+ int32_t *g = d->glow ? d->glow + (y >> 2) * GW : 0;
+ int xa = 0, xb = W;
+ /* the counts of the samples summed: rows fixed and columns along the
+ * row (landscape), or the other way round (portrait) */
+ int a, b;
+ const uint16_t *ra, *rb;
+ if (d->rows_axis_x)
+ {
+ xa = d->ox0; xb = d->ox0 + d->ow;
+ a = d->ne_c[y]; b = d->no_c[y]; ra = d->ne_r; rb = d->no_r;
+ }
+ else { a = d->ne_r[y]; b = d->no_r[y]; ra = d->ne_c; rb = d->no_c; }
+ expose_cam(d, d->sums + 3 * (y * W + xa), d->pos, xb - xa, a, b, ra, rb);
+ memset(lin + 3 * y * W, 0, 6 * xa);
+ memset(lin + 3 * (y * W + xb), 0, 6 * (W - xb));
+ expose_lin(d, d->pos, lin + 3 * (y * W + xa), xb - xa, g, xa);
+ }
+ d->lin = lin;
+}
+
+/* halation: the highlights' glow, spread about as the lab's gaussian
+ * (0.6 % of the frame) by two [1 2 1] passes each way on the grid */
+static void stage_glow(struct fos_dev *d)
+{
+ int32_t *g = d->glow, tmp[GW > GH ? GW : GH];
+ for (int i = 0; i < GW * GH; i++) g[i] >>= 4; /* the cell's mean */
+ for (int pass = 0; pass < 2; pass++)
+ {
+ for (int y = 0; y < GH; y++)
+ {
+ int32_t *r = g + y * GW;
+ for (int x = 0; x < GW; x++)
+ tmp[x] = (r[x > 0 ? x - 1 : 0] + 2 * r[x] + r[x < GW - 1 ? x + 1 : GW - 1]) >> 2;
+ memcpy(r, tmp, sizeof(int32_t) * GW);
+ }
+ for (int x = 0; x < GW; x++)
+ {
+ for (int y = 0; y < GH; y++)
+ tmp[y] = (g[(y > 0 ? y - 1 : 0) * GW + x] + 2 * g[y * GW + x] + g[(y < GH - 1 ? y + 1 : GH - 1) * GW + x]) >> 2;
+ for (int y = 0; y < GH; y++) g[y * GW + x] = tmp[y];
+ }
+ }
+}
+
+/* a cell of the glow grid and the weight of the next, in 1/8, for print
+ * line p: cell centres sit at 4j + 1.5 */
+static void glow_pos(int p, int n, uint8_t *cell, uint8_t *frac)
+{
+ int t = 2 * p - 3;
+ if (t < 0) { *cell = 0; *frac = 0; return; }
+ int j = t >> 3;
+ if (j >= n - 1) { *cell = (uint8_t) (n - 2); *frac = 8; return; }
+ *cell = (uint8_t) j;
+ *frac = (uint8_t) (t & 7);
+}
+
+/* Finishing a row of the print goes in three passes, each small enough
+ * for the registers: where its pixels fall on the film's table, the
+ * table, the grain. */
+
+/* n pixels from lin: the vignette (vig[x] for pixel x, in 1/4096) and the
+ * halation (the glow row grow mixed along it by gx, fx; hal: its colour)
+ * on the linear light, then its place on the grid */
+static __attribute__((noinline)) void finish_pos(const uint16_t *lin, uint16_t *pos, int n, int vy, const int16_t *vx,
+ const int32_t *grow, const uint8_t *gx, const uint8_t *fx, const int *hal)
+{
+ const uint16_t *cin = tab->cin;
+ if (!grow)
+ {
+ for (const uint16_t *e = lin + 3 * n; lin < e; lin += 3, pos += 3, vx++)
+ {
+ int vig = vy - *vx;
+ pos[0] = cin_pos(cin, (lin[0] * vig) >> 12);
+ pos[1] = cin_pos(cin, (lin[1] * vig) >> 12);
+ pos[2] = cin_pos(cin, (lin[2] * vig) >> 12);
+ }
+ return;
+ }
+ const int h0 = hal[0], h1 = hal[1], h2 = hal[2];
+ for (const uint16_t *e = lin + 3 * n; lin < e; lin += 3, pos += 3, vx++, gx++, fx++)
+ {
+ int vig = vy - *vx;
+ int a = *gx, f = *fx;
+ int glow = (grow[a] * (8 - f) + grow[a + 1] * f) >> 6;
+ pos[0] = cin_pos(cin, ((lin[0] * vig) >> 12) + ((glow * h0) >> 8));
+ pos[1] = cin_pos(cin, ((lin[1] * vig) >> 12) + ((glow * h1) >> 8));
+ pos[2] = cin_pos(cin, ((lin[2] * vig) >> 12) + ((glow * h2) >> 8));
+ }
+}
+
+static __attribute__((noinline)) void finish_lut(const uint16_t *pos, uint8_t *o, int n)
+{
+ const uint8_t (*lut)[3] = tab->lut;
+ for (const uint16_t *e = pos + 3 * n; pos < e; pos += 3, o += 3)
+ lut_apply(lut, pos[0], pos[1], pos[2], o);
+}
+
+/* grain at screen size: the lab's, softened by the downscale (grain: its
+ * strength), strongest in the mid tones */
+static __attribute__((noinline)) unsigned finish_grain(uint8_t *o, int n, unsigned seed, int grain, int mono)
+{
+ for (uint8_t *e = o + 3 * n; o < e; o += 3)
+ {
+ int l = (o[0] * 54 + o[1] * 183 + o[2] * 19) >> 8;
+ int wgt = (l * (255 - l)) >> 6;
+ int shared = rnd(&seed);
+ for (int c = 0; c < 3; c++)
+ {
+ int k = mono ? shared : (shared * 3 + rnd(&seed) * 2) / 4;
+ int v = o[c] + (int) (((long) k * grain >> 15) * wgt >> 16);
+ o[c] = (uint8_t) (v < 0 ? 0 : v > 255 ? 255 : v);
+ }
+ }
+ return seed;
+}
+
+/* row y of the print: vignette, halation, the film's table, grain */
+static __attribute__((noinline)) void stage_finish(struct fos_dev *d, int y)
+{
+ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
+ const struct fos_look *L = d->look;
+ int pw = d->rows_axis_x ? d->ow : W, px0 = d->rows_axis_x ? d->ox0 : 0;
+ if (y == 0)
+ {
+ /* vignette, as the lab: 1 - 0.12 r^2, r^2 = (x^2 + y^2) / 2 over
+ * -1..1; the x and y parts, in 1/4096 */
+ for (int x = 0; x < pw; x++) { float t = 2.0f * x / (pw - 1) - 1; d->vig_x[x] = (int16_t) (0.06f * t * t * 4096); }
+ for (int k = 0; k < H; k++) { float t = 2.0f * k / (H - 1) - 1; d->vig_y[k] = (int16_t) (0.06f * t * t * 4096); }
+ for (int x = 0; x < W; x++) glow_pos(x, GW, &d->gx[x], &d->fx[x]);
+ }
+ int hal[3];
+ for (int c = 0; c < 3; c++) hal[c] = d->glow ? (int) (L->halation * L->hal_tint[c] * 256) : 0;
+ /* the glow between the grid's two rows about this one, in 1/8 */
+ int32_t grow[GW];
+ if (d->glow)
+ {
+ uint8_t gy, fy;
+ glow_pos(y, GH, &gy, &fy);
+ const int32_t *g0 = d->glow + gy * GW, *g1 = g0 + GW;
+ for (int j = 0; j < GW; j++) grow[j] = g0[j] * (8 - fy) + g1[j] * fy;
+ }
+ uint8_t *o = d->rgb + 3 * y * W;
+ memset(o, 0, 3 * px0);
+ memset(o + 3 * (px0 + pw), 0, 3 * (W - px0 - pw));
+ finish_pos(d->lin + 3 * (y * W + px0), d->pos, pw, 4096 - d->vig_y[y], d->vig_x,
+ d->glow ? grow : 0, d->gx + px0, d->fx + px0, hal);
+ finish_lut(d->pos, o + 3 * px0, pw);
+ int grain = (int) (L->grain * 255 * 0.55f * 256);
+ if (grain) d->seed = finish_grain(o + 3 * px0, pw, d->seed, grain, L->mono);
+}
+
+/* the thumbnail: 6 x 6 boxes, a row of them at a time */
+static void make_thumb(struct fos_dev *d)
+{
+ const int W = FOS_PRINT_W;
+ int acc[FOS_THUMB_W * 3];
+ for (int ty = 0; ty < FOS_THUMB_H; ty++)
+ {
+ memset(acc, 0, sizeof(acc));
+ for (int j = 0; j < 6; j++)
+ {
+ const uint8_t *p = d->rgb + 3 * (ty * 6 + j) * W;
+ for (int tx = 0; tx < FOS_THUMB_W; tx++, p += 18)
+ {
+ int *a = acc + 3 * tx;
+ a[0] += p[0] + p[3] + p[6] + p[9] + p[12] + p[15];
+ a[1] += p[1] + p[4] + p[7] + p[10] + p[13] + p[16];
+ a[2] += p[2] + p[5] + p[8] + p[11] + p[14] + p[17];
+ }
+ }
+ for (int i = 0; i < FOS_THUMB_W * 3; i++)
+ d->thumb[3 * ty * FOS_THUMB_W + i] = (uint8_t) ((acc[i] * 455 + 8192) >> 14); /* / 36 */
+ }
+}
+
+int fos_dev_step(struct fos_dev *d, int budget_ms)
+{
+ if (!d) return -1;
+ int t0 = fos_port_ms(), cap = fos_port_dev_cap(), slices = 0;
+ const int W = FOS_PRINT_W, H = FOS_PRINT_H, N = W * H;
+ while ((fos_port_ms() - t0 < budget_ms || d->stage == ST_OPEN) && (!cap || slices++ < cap))
+ {
+ switch (d->stage)
+ {
+ case ST_OPEN:
+ if (!tables_ready()) return fail_mem(d, (int) sizeof(*tab));
+ d->f = fos_port_open(d->cr2, 0);
+ if (!d->f) return fail(d, "can't open the RAW file");
+ if (parse_tiff(d) < 0 || parse_ljpeg(d) < 0 || setup_maps(d) < 0) return -1;
+ {
+ char msg[320];
+ const char *name = strrchr(d->cr2, '/');
+ snprintf(msg, sizeof(msg), "dev: %s raw %dx%d (ljpeg %dx%d, %d comps, %d bits) slices %d x %d + %d, "
+ "picture %d,%d %dx%d, black cols %d..%d, orientation %d",
+ name ? name + 1 : d->cr2, d->raw_w, d->raw_h, d->wide, d->high, d->clrs, d->bits,
+ d->slices[0], d->slices[1], d->slices[2], d->crop_l, d->crop_t, d->crop_w, d->crop_h,
+ d->ob_l, d->ob_r, d->orient);
+ fos_port_log(msg);
+ }
+ d->buf = fos_port_alloc(CHUNK + 16);
+ if (!d->buf) return fail_mem(d, CHUNK + 16);
+ d->bp = d->be = d->buf;
+ d->safe = d->buf; /* the first read fills it */
+ d->ff = 0;
+ d->stage = ST_DECODE;
+ break;
+ case ST_DECODE:
+ /* the film's table first, a little at a time */
+ if (!lut_build(d->look, d->film, 64)) break;
+ decode(d, 1 << 14);
+ if (d->done >= d->total)
+ {
+ fos_port_close(d->f);
+ d->f = 0;
+ fos_port_free(d->buf); d->buf = 0;
+ d->rgb = fos_port_alloc(N * 3);
+ if (!d->rgb) return fail_mem(d, N * 3);
+ if (d->look->halation > 0)
+ {
+ d->glow = fos_port_alloc(GW * GH * 4);
+ if (d->glow) memset(d->glow, 0, GW * GH * 4);
+ }
+ setup_colour(d);
+ d->stage = ST_KEY;
+ return progress(d); /* the latent image can be read once more */
+ }
+ break;
+ case ST_KEY:
+ stage_key(d);
+ d->stage = ST_EXPOSE;
+ d->row = 0;
+ break;
+ case ST_EXPOSE:
+ stage_expose(d, d->row, d->row + 8);
+ d->row += 8;
+ if (d->row >= H) d->stage = d->glow ? ST_GLOW : ST_FINISH, d->row = 0;
+ break;
+ case ST_GLOW:
+ stage_glow(d);
+ d->stage = ST_FINISH;
+ d->row = 0;
+ break;
+ case ST_FINISH:
+ stage_finish(d, d->row);
+ if (++d->row == H)
+ {
+ make_thumb(d);
+ fos_port_free(d->sums); d->sums = 0; d->lin = 0;
+ fos_port_free(d->glow); d->glow = 0;
+ d->stage = d->jpeg[0] ? ST_JPEG : ST_QUANT;
+ }
+ break;
+ case ST_JPEG:
+ {
+ /* the picture only: a portrait frame without the print's sides */
+ int x0 = d->rows_axis_x ? d->ox0 : 0, w = d->rows_axis_x ? d->ow : W;
+ char desc[48];
+ snprintf(desc, sizeof(desc), "%s %s", fos_films[d->film].brand, fos_films[d->film].name);
+ struct fos_jpeg_meta m = { d->when, desc, d->fstop };
+ if (!fos_jpeg_write(d->jpeg, d->rgb + 3 * x0, 3 * W, w, H, 92, &m))
+ {
+ char msg[200];
+ snprintf(msg, sizeof(msg), "dev: can't write %s", d->jpeg);
+ fos_port_log(msg);
+ }
+ d->stage = ST_QUANT;
+ break;
+ }
+ case ST_QUANT:
+ if (!quant_alloc(d)) return fail_mem(d, 32768 * 5 + FOS_PRINT_W * FOS_PRINT_H);
+ d->stage = ST_DITHER;
+ d->row = 0;
+ break;
+ case ST_DITHER:
+ dither_rows(d, d->row, d->row + 8);
+ d->row += 8;
+ if (d->row >= H) d->stage = ST_WRITE;
+ break;
+ case ST_WRITE:
+ if (!write_print(d->print, d->film, d->frame, d->when, d->fstop, d->pal, d->npal, d->idx, d->thumb,
+ d->rows_axis_x ? d->ox0 : 0, d->rows_axis_x ? d->ow : W))
+ return fail(d, "can't write the print");
+ d->stage = ST_DONE;
+ return 1000;
+ case ST_DONE:
+ return 1000;
+ default:
+ return -1;
+ }
+ }
+ return progress(d);
+}
+
+/* ---------------------------------------------------------------- the contact sheet */
+
+int fos_dev_sheet(const char *sheet, int film, const char *const *prints, int frames)
+{
+ struct fos_dev *d = fos_dev_start("", sheet, film, 0, "", "");
+ if (!d) return 0;
+ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
+ d->rgb = fos_port_alloc(W * H * 3);
+ uint8_t *thumb = fos_port_alloc(FOS_THUMB_W * FOS_THUMB_H * 3);
+ if (!d->rgb || !thumb) { fos_port_free(thumb); fos_dev_free(d); return 0; }
+ /* strips of six frames on black, each frame inset by its rebate */
+ memset(d->rgb, 0, W * H * 3);
+ int rows = (frames + 5) / 6;
+ int y0 = (H - rows * FOS_THUMB_H) / 2;
+ for (int i = 0; i < frames; i++)
+ {
+ if (!prints[i] || !fos_print_thumb(prints[i], thumb)) continue;
+ int cx = (i % 6) * FOS_THUMB_W + FOS_SHEET_FX, cy = y0 + (i / 6) * FOS_THUMB_H + FOS_SHEET_FY;
+ for (int y = 0; y < FOS_SHEET_FH; y++)
+ for (int x = 0; x < FOS_SHEET_FW; x++)
+ {
+ int sx = x * FOS_THUMB_W / FOS_SHEET_FW, sy = y * FOS_THUMB_H / FOS_SHEET_FH;
+ memcpy(d->rgb + 3 * ((cy + y) * W + cx + x), thumb + 3 * (sy * FOS_THUMB_W + sx), 3);
+ }
+ if (i == 0) memcpy(d->thumb, thumb, sizeof(d->thumb)); /* the roll's own thumbnail */
+ }
+ fos_port_free(thumb);
+ int ok = quant_alloc(d);
+ if (ok)
+ {
+ dither_rows(d, 0, H);
+ ok = write_print(sheet, film, 0, "", "", d->pal, d->npal, d->idx, d->thumb, 0, W);
+ }
+ fos_dev_free(d);
+ return ok;
+}
+
+/* ---------------------------------------------------------------- the latent image */
+
+/* where print pixel (px, py) comes from on the sensor: its middle */
+static void raw_of(const struct fos_dev *d, int px, int py, int *rx, int *ry)
+{
+ int rlen, clen, a, b;
+ if (d->rows_axis_x) { rlen = d->ow; clen = d->oh; a = px - d->ox0; b = py; }
+ else { rlen = d->oh; clen = d->ow; a = py; b = px; }
+ if (d->orient == 6 || d->orient == 3) a = rlen - 1 - a;
+ if (d->orient == 8 || d->orient == 3) b = clen - 1 - b;
+ *ry = d->crop_t + (int) ((long) (2 * a + 1) * d->crop_h / (2 * rlen));
+ *rx = d->crop_l + (int) ((long) (2 * b + 1) * d->crop_w / (2 * clen));
+}
+
+int fos_dev_preview(const struct fos_dev *d, uint8_t *lum, int w, int h)
+{
+ if (!d || (d->stage != ST_DECODE && d->stage != ST_KEY) || !d->sums) return 0;
+ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
+ for (int ty = 0; ty < h; ty++)
+ {
+ int py = (2 * ty + 1) * H / (2 * h);
+ for (int tx = 0; tx < w; tx++)
+ {
+ int px = (2 * tx + 1) * W / (2 * w);
+ uint8_t *o = &lum[ty * w + tx];
+ *o = 255; /* blank paper */
+ if (d->rows_axis_x && (px < d->ox0 || px >= d->ox0 + d->ow)) continue;
+ int rx, ry;
+ raw_of(d, px, py, &rx, &ry);
+ int reached = d->done >= d->total || rx < d->sx0 || (rx < d->sx0 + d->sw && ry < d->sy);
+ if (!reached) continue;
+ /* green, roughly exposed: enough to see the picture come */
+ int xr = d->rows_axis_x ? px - d->ox0 : py, xc = d->rows_axis_x ? py : px;
+ int n = d->ne_r[xr] * d->no_c[xc] + d->no_r[xr] * d->ne_c[xc];
+ if (!n) continue;
+ int g = (int) (d->sums[3 * (py * W + px) + 1] / n) - 2048;
+ int v = g <= 0 ? 0 : g >= 2900 ? 4096 : g * 4096 / 2900;
+ *o = (uint8_t) (fos_isqrt((unsigned) v * 16) * 255 / 256);
+ }
+ }
+ return 1;
+}
diff --git a/ml-dev/filmos/fos_dev.h b/ml-dev/filmos/fos_dev.h
new file mode 100644
index 0000000..6393835
--- /dev/null
+++ b/ml-dev/filmos/fos_dev.h
@@ -0,0 +1,153 @@
+/* fos_dev: developing film in the camera.
+ *
+ * A frame's CR2 RAW becomes a print for the screen: 720 x 480 in its own
+ * palette of FOS_PRINT_COLOURS colours. Developing runs in steps of a few
+ * tens of ms, so the film OS keeps animating on the same task while the
+ * camera works through a roll.
+ */
+
+#ifndef _fos_dev_h_
+#define _fos_dev_h_
+
+#include <stdint.h>
+
+/* ---------------------------------------------------------------- looks */
+
+/* a film's look, from films/films.py (see fos_looks.c; Darkrooms on the desktop uses the same) */
+struct fos_hue_shift { int8_t from, to; float amount, chroma; };
+struct fos_look
+{
+ const char *key; /* matches fos_films[].key */
+ int balance; /* K the film is balanced for */
+ int slide; /* reversal film: no scanner exposure */
+ float ev, sat;
+ float contrast[3], pivot[3], black[3], white[3];
+ int nhues;
+ struct fos_hue_shift hues[4];
+ float halation, hal_thr, hal_tint[3];
+ float grain, grain_size;
+ int mono;
+ float mono_mix[3];
+};
+extern const struct fos_look fos_looks[];
+extern const int fos_nlooks;
+/* the looks of the films from ML/DATA/FOSFILMS.BIN (fos_films_load) */
+extern const struct fos_look *fos_more_looks;
+extern int fos_nmore_looks;
+const struct fos_look *fos_look_of(const char *key);
+
+/* the film's colour for one scene-linear sRGB value (0.18 = mid grey):
+ * the print, display sRGB 0..1. Same model as film_color() in the lab. */
+void fos_film_color(const struct fos_look *f, const float lin[3], float out[3]);
+
+/* ---------------------------------------------------------------- prints */
+
+#define FOS_PRINT_W 720
+#define FOS_PRINT_H 480
+#define FOS_PRINT_COLOURS 240 /* palette indices 1..240 */
+#define FOS_FIXED_BASE 241 /* 241..254: the same in every palette */
+#define FOS_FIXED_N 14 /* 241..254 */
+#define FOS_THUMB_W 120
+#define FOS_THUMB_H 80
+
+struct fos_print
+{
+ int frame; /* 0 = the roll's contact sheet */
+ int film; /* index into fos_films */
+ char when[20]; /* "2026-10-22 17:45" */
+ char fstop[8];
+ int x0, w; /* the picture's columns (a portrait frame is narrower) */
+ uint8_t pal[FOS_PRINT_COLOURS][3];
+ uint8_t *px; /* FOS_PRINT_W x FOS_PRINT_H */
+};
+
+/* while a photograph is up, the overlay draws with these */
+enum { PX_BLACK = FOS_FIXED_BASE, PX_PANEL, PX_G1, PX_G2, PX_G3, PX_G4, PX_G5, PX_WHITE,
+ PX_AMBER, PX_AMBER2, PX_RED, PX_LINE, PX_DIM, PX_SPARE };
+extern const uint8_t fos_fixed_rgb[FOS_FIXED_N][3];
+
+int fos_print_load(const char *path, struct fos_print *p); /* allocates p->px; 0 on failure */
+void fos_print_free(struct fos_print *p);
+int fos_print_thumb(const char *path, uint8_t *thumb); /* FOS_THUMB_W x FOS_THUMB_H RGB */
+
+/* ---------------------------------------------------------------- developing */
+
+struct fos_dev;
+
+/* where the film tables are kept between sessions (NULL: not kept) */
+void fos_dev_cache(const char *dir);
+/* build film's table into the cache now (the build makes the card's copies) */
+int fos_dev_table(int film);
+/* also write the frame in full colour as a JPEG at path (before the first step) */
+void fos_dev_jpeg(struct fos_dev *d, const char *path);
+/* forget the film table (leaving the darkroom) */
+void fos_dev_release();
+
+/* develop one frame: cr2 in, a print file out */
+struct fos_dev *fos_dev_start(const char *cr2, const char *print, int film, int frame,
+ const char *when, const char *fstop);
+/* work for about budget_ms; returns progress 0..1000, 1000 when the print
+ * is written, or < 0 when the frame can't be developed */
+int fos_dev_step(struct fos_dev *d, int budget_ms);
+/* the finished frame, small, RGB: for the contact sheet and the animation */
+const uint8_t *fos_dev_thumb(const struct fos_dev *d);
+const char *fos_dev_error(const struct fos_dev *d);
+/* what it is doing, for the darkroom's animation */
+enum { FOS_DEV_MIXING, FOS_DEV_DEVELOPING, FOS_DEV_FIXING, FOS_DEV_DRYING, FOS_DEV_DONE, FOS_DEV_FAILED };
+int fos_dev_doing(const struct fos_dev *d);
+int fos_dev_progress(const struct fos_dev *d); /* 0..1000, as fos_dev_step returned */
+void fos_dev_picture(const struct fos_dev *d, int *x0, int *w); /* the picture's columns on the print */
+void fos_dev_free(struct fos_dev *d);
+
+/* the print in progress, w x h, as the latent image coming up: a rough
+ * luminance, 255 (paper) where nothing has been read yet; 0 if there is
+ * nothing to show (not reading the RAW) */
+int fos_dev_preview(const struct fos_dev *d, uint8_t *lum, int w, int h);
+
+/* the roll's contact sheet from its frames' prints (NULL: not
+ * developed); written as a print with frame 0. Frame i sits in cell
+ * (i % 6, i / 6) of FOS_THUMB_W x FOS_THUMB_H cells, rows centred */
+#define FOS_SHEET_FX 6
+#define FOS_SHEET_FY 4
+#define FOS_SHEET_FW 108
+#define FOS_SHEET_FH 72
+int fos_dev_sheet(const char *sheet, int film, const char *const *prints, int frames);
+
+/* ---------------------------------------------------------------- the rolls on the card (fos_lab.c) */
+
+#define FOS_MAX_FRAMES 40
+
+struct fos_lab_roll
+{
+ int number;
+ int film; /* index into fos_films */
+ int exposures;
+ int shot; /* frames in its logs */
+ int developed; /* frames with a print */
+ int sheet; /* its contact sheet is there */
+ int jpegs; /* JPEGs in its folder in DCIM */
+ int in_camera; /* still loaded: rewind it before developing */
+ char loaded[17]; /* "2026-10-22 17:45" */
+ char last[17]; /* its last frame */
+};
+
+struct fos_lab_frame
+{
+ int no;
+ char cr2[64];
+ int missing; /* the file isn't there (deleted, or shot as JPEG) */
+ char when[17];
+ char fstop[6];
+};
+
+int fos_lab_scan(struct fos_lab_roll *rolls, int max); /* newest first; how many */
+int fos_lab_frames(int roll, struct fos_lab_frame *frames, int max); /* frame order; how many */
+void fos_lab_print_path(char *buf, int size, int roll, int frame); /* frame 0: the contact sheet */
+int fos_lab_prepare(int roll); /* its print folder; 0 = ok */
+void fos_lab_cache_dir(char *buf, int size); /* where film tables are kept */
+/* the roll's folder of JPEGs in DCIM, made if need be: "Sep0906 Portra400"
+ * (month, month number, day of its first frame; when: "2026-09-06 10:15")
+ * or SEP0906 where the card takes no long names. 0 = ok */
+int fos_lab_dcim_dir(char *buf, int size, int roll, int film, const char *when);
+
+#endif
diff --git a/ml-dev/filmos/fos_film.c b/ml-dev/filmos/fos_film.c
new file mode 100644
index 0000000..b95883d
--- /dev/null
+++ b/ml-dev/filmos/fos_film.c
@@ -0,0 +1,1132 @@
+/* fos_film: the film stocks, and their 35 mm canisters drawn as small 3D
+ * objects - a lithographed steel cylinder with crimped caps, the spool end
+ * on top, the felt light trap and the film leader sticking out of it.
+ *
+ * Each stock's label is painted once into a texture that wraps around the
+ * cylinder, a ramp and a level per texel with the anti-aliased edges
+ * already blended. Light on a cylinder only scales and lifts levels, so
+ * each column of the drawing folds its shading into a gain and an offset
+ * per ramp, and a label pixel costs a lookup, a multiply and a dither.
+ */
+
+#include "fos.h"
+#include "fos_dev.h"
+#include <math.h>
+#include <stddef.h>
+#include <string.h>
+
+/* ---------------------------------------------------------------- the stocks */
+
+/* Picture style values are starting points for the in-camera JPEG preview
+ * only; the real look comes from the lab. Mono stocks leave saturation and
+ * tone alone because the Monochrome style uses those for filter / toning. */
+static const struct fos_film builtin[] =
+{
+ { "portra400", "KODAK", "Portra 400", "C-41", "Soft warm skin, gentle highlights",
+ 400, 400, PS_STANDARD, -1, -1, 1, 2, 5500, 0, 1, 2, 2, 2, 4, "Portra400", FOS_GROUP_COLOUR, 0 },
+ { "cinestill800t", "CINESTILL", "800T", "C-41", "Tungsten cine film, night goes blue",
+ 800, 800, PS_STANDARD, 1, 1, -1, 2, 3200, 0, 0, 4, 3, 3, 1, "CineStill800T", FOS_GROUP_CINE, 0 },
+ { "ektar100", "KODAK", "Ektar 100", "C-41", "Punchy colour, ultra fine grain",
+ 100, 100, PS_LANDSCAPE, 1, 2, 0, 3, 5200, 0, 0, 1, 4, 5, 3, "Ektar100", FOS_GROUP_COLOUR, 0 },
+ { "gold200", "KODAK", "Gold 200", "C-41", "Golden hour, all day long",
+ 200, 200, PS_STANDARD, 1, 1, 2, 2, 5600, 0, 2, 3, 3, 4, 5, "Gold200", FOS_GROUP_COLOUR, 0 },
+ { "superia400", "FUJIFILM", "Superia 400", "C-41", "Green shadows, everyday snaps",
+ 400, 400, PS_STANDARD, 1, 1, 0, 2, 5200, 1, 0, 3, 3, 3, 2, "Superia400", FOS_GROUP_COLOUR, 0 },
+ { "velvia50", "FUJIFILM", "Velvia 50", "E-6", "Vivid slide film, hard contrast",
+ 50, 100, PS_LANDSCAPE, 3, 4, 0, 3, 5200, 0, 0, 1, 5, 5, 3, "Velvia50", FOS_GROUP_SLIDE, 0 },
+ { "hp5", "ILFORD", "HP5 Plus", "B&W", "Classic B&W, forgiving latitude",
+ 400, 400, PS_MONO, 1, 0, 0, 2, 5200, 0, 0, 4, 2, 0, 0, "HP5", FOS_GROUP_BW, 0 },
+ { "trix400", "KODAK", "Tri-X 400", "B&W", "Gritty contrast, street classic",
+ 400, 400, PS_MONO, 3, 0, 0, 2, 5200, 0, 0, 5, 4, 0, 0, "TriX400", FOS_GROUP_BW, 0 },
+};
+#define NBUILTIN ((int) (sizeof(builtin) / sizeof(builtin[0])))
+
+const struct fos_film *fos_films = builtin;
+int fos_nfilms = NBUILTIN;
+
+const char *const fos_group_names[FOS_NGROUPS] = { "COLOUR", "SLIDE", "B&W", "CINE" };
+
+const struct fos_look *fos_more_looks;
+int fos_nmore_looks;
+
+/* A film in ML/DATA/FOSFILMS.BIN (written by tools/genfilms.py, which
+ * packs the same layout): after a 12-byte header ("FOSM", version, record
+ * size, count), one of these each. The look is struct fos_look from its
+ * balance on, as the camera lays it out. */
+#define LOOK_FROM offsetof(struct fos_look, balance)
+#define LOOK_BYTES (offsetof(struct fos_look, mono_mix) + sizeof(((struct fos_look *) 0)->mono_mix) - LOOK_FROM)
+struct film_rec
+{
+ char key[16], brand[16], name[24], process[8], desc[48], shortname[24];
+ int32_t box_iso, iso, picstyle, contrast, saturation, color_tone, sharpness, kelvin, wbs_gm, wbs_ba;
+ uint8_t grain, punch, colour, warmth;
+ int32_t group;
+ struct fos_label label;
+ uint8_t look[LOOK_BYTES];
+};
+
+int fos_films_load(const uint8_t *blob, int size)
+{
+ if (!blob || size < 12 || memcmp(blob, "FOSM", 4) || blob[4] != 1) return 0;
+ int rs = blob[6] | blob[7] << 8, n = (int) (blob[8] | blob[9] << 8);
+ if (rs != (int) sizeof(struct film_rec) || size < 12 + n * rs || n <= 0) return 0;
+ struct fos_film *all = fos_port_alloc((NBUILTIN + n) * (int) sizeof(*all));
+ struct fos_look *looks = fos_port_alloc(n * (int) sizeof(*looks));
+ if (!all || !looks) { fos_port_free(all); fos_port_free(looks); return 0; }
+ memcpy(all, builtin, sizeof(builtin));
+ for (int i = 0; i < n; i++)
+ {
+ struct film_rec *r = (struct film_rec *) (blob + 12 + i * rs);
+ r->key[15] = r->brand[15] = r->name[23] = r->process[7] = r->desc[47] = r->shortname[23] = 0;
+ r->label.top[19] = r->label.word[13] = r->label.num_s[7] = r->label.sub[17] = 0;
+ struct fos_film *f = &all[NBUILTIN + i];
+ *f = (struct fos_film) { r->key, r->brand, r->name, r->process, r->desc, r->box_iso, r->iso, r->picstyle,
+ r->contrast, r->saturation, r->color_tone, r->sharpness, r->kelvin, r->wbs_gm, r->wbs_ba,
+ r->grain, r->punch, r->colour, r->warmth, r->shortname,
+ fos_clamp(r->group, 0, FOS_NGROUPS - 1), &r->label };
+ memset(&looks[i], 0, sizeof(looks[i]));
+ looks[i].key = r->key;
+ memcpy((uint8_t *) &looks[i] + LOOK_FROM, r->look, LOOK_BYTES);
+ looks[i].nhues = fos_clamp(looks[i].nhues, 0, 4);
+ }
+ fos_films = all;
+ fos_nfilms = NBUILTIN + n;
+ fos_more_looks = looks;
+ fos_nmore_looks = n;
+ return 1;
+}
+
+const int fos_exposure_choices[FOS_NEXP] = { 36, 24, 12 };
+
+/* f-numbers x100 in 1/3 stops; index i sits (i - 1) thirds above f/1
+ * (f/0.95 is close enough to f/1 to share the bottom of the scale) */
+const int fos_fstops[] =
+{
+ 95, 100, 110, 120, 140, 160, 180, 200, 220, 250,
+ 280, 320, 350, 400, 450, 500, 560, 630, 710, 800,
+ 900, 1000, 1100, 1300, 1400, 1600, 1800, 2000, 2200,
+};
+const int fos_nfstops = sizeof(fos_fstops) / sizeof(fos_fstops[0]);
+
+void fos_format_fstop(char *buf, int size, int index)
+{
+ int v = fos_fstops[fos_clamp(index, 0, fos_nfstops - 1)];
+ if (v < 100)
+ snprintf(buf, size, "0.%02d", v);
+ else if (v % 100 == 0 || v >= 1000)
+ snprintf(buf, size, "%d", v / 100);
+ else
+ snprintf(buf, size, "%d.%d", v / 100, (v / 10) % 10);
+}
+
+/* ---------------------------------------------------------------- geometry */
+
+/* full-size canister, px */
+#define R 50 /* body radius */
+#define RC 53 /* caps stick out a little */
+#define RS 19 /* spool end */
+#define HB 150 /* body (label) height */
+#define TB 9 /* top crimp band */
+#define BB 8 /* bottom crimp band */
+#define HS 12 /* spool end above the cap */
+#define TILT 56 /* ellipse height / width, 1/256: we look down ~13 degrees */
+
+/* label texture: 360 degrees across, body height down */
+#define TW 320
+#define TH HB
+#define U_FRONT (TW / 2) /* texture column facing us at rot 0 */
+#define U_LIP (U_FRONT + TW * 82 / 360) /* the felt lip, on the right */
+
+int fos_can_quality = 2;
+
+struct fos_can
+{
+ int film;
+ int exposures;
+ uint16_t *tex; /* ramp << 12 | 12-bit level, column by column */
+ int ramps; /* bit mask of the ramps in it */
+ int gloss; /* 0..256 */
+ int leader_ramp, leader_lv;
+};
+
+int fos_can_height(int scale)
+{
+ int e = RC * TILT / 256;
+ return (HS + RS * TILT / 256 + e + TB + HB + BB + e) * scale / 256;
+}
+
+int fos_can_width(int scale)
+{
+ return 2 * RC * scale / 256;
+}
+
+/* ---------------------------------------------------------------- shading profiles */
+
+/* sampled across the cylinder, x / radius from -1 to +1 */
+#define NPROF 256
+static int16_t prof_ang[NPROF]; /* surface angle, 1/65536 turn (+ = right) */
+static int16_t prof_light[NPROF]; /* printed label: diffuse, 0..256 */
+static int16_t prof_spec[NPROF]; /* printed label: gloss highlight, 0..256 */
+static int16_t prof_metal[NPROF]; /* steel caps: 12-bit level */
+static int16_t prof_dark[NPROF]; /* black plastic spool: 12-bit level */
+static int prof_ready = 0;
+
+static float smooth(float a, float b, float x)
+{
+ float t = (x - a) / (b - a);
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
+ return t * t * (3 - 2 * t);
+}
+
+static float lobe(float th, float centre, float width)
+{
+ float d = (th - centre) / width;
+ return expf(-d * d);
+}
+
+static void build_profiles()
+{
+ const float deg = 3.14159265f / 180;
+ for (int i = 0; i < NPROF; i++)
+ {
+ float xn = (i + 0.5f) / NPROF * 2 - 1;
+ float th = asinf(xn); /* -90..90 degrees */
+ prof_ang[i] = (int16_t) (th / (2 * 3.14159265f) * 65536);
+
+ /* softbox up-left in front, a rim light behind on the right */
+ float key = cosf(th + 38 * deg);
+ key = (key + 0.35f) / 1.35f;
+ key = key < 0 ? 0 : key;
+ float rim = smooth(55 * deg, 86 * deg, th) * 0.55f;
+ float edge = 0.62f + 0.38f * sqrtf(cosf(th));
+ float light = (0.16f + 0.84f * key) * edge + rim;
+ prof_light[i] = (int16_t) (light * 256);
+
+ float sheen = lobe(th, -24 * deg, 16 * deg) * 0.22f + lobe(th, -21 * deg, 3.0f * deg) * 0.55f
+ + lobe(th, 74 * deg, 6 * deg) * 0.25f;
+ prof_spec[i] = (int16_t) (sheen * 256);
+
+ /* brushed steel: dark body with sharp reflections of the studio */
+ float m = 0.24f + 0.30f * key
+ + 0.55f * lobe(th, -22 * deg, 9 * deg)
+ + 0.30f * lobe(th, -55 * deg, 14 * deg)
+ + 0.18f * lobe(th, 30 * deg, 18 * deg)
+ + 0.45f * lobe(th, 80 * deg, 7 * deg);
+ m *= edge;
+ prof_metal[i] = (int16_t) fos_clamp((int) (m * LV_MAX), 0, LV_MAX);
+
+ float p = 0.06f + 0.10f * key + 0.22f * lobe(th, -25 * deg, 8 * deg) + 0.12f * lobe(th, 78 * deg, 8 * deg);
+ prof_dark[i] = (int16_t) fos_clamp((int) (p * LV_MAX), 0, LV_MAX);
+ }
+ prof_ready = 1;
+}
+
+/* profile index for d (1/256 px from the left edge) with inv = NPROF * 65536 / diameter */
+#define PROF(d, inv) fos_clamp(((d) * (inv)) >> 16, 0, NPROF - 1)
+
+/* ---------------------------------------------------------------- label painting */
+
+/* an ink is the texel it paints */
+static int ink(struct fos_can *c, int ramp, int level)
+{
+ c->ramps |= 1 << ramp;
+ return ramp << 12 | LV12(level);
+}
+
+/* texture column for u, which is never more than a turn out */
+FOS_INLINE int wrap_u(int u)
+{
+ return u < 0 ? u + TW : u >= TW ? u - TW : u;
+}
+
+/* put ink k with coverage cov (0..15) on texel (u, v) */
+static void tex_put(struct fos_can *c, int u, int v, int k, int cov)
+{
+ if (cov <= 0 || v < 0 || v >= TH) return;
+ uint16_t *t = &c->tex[wrap_u(u) * TH + v];
+ if (cov >= 15) { *t = k; return; }
+ int r, lv;
+ fos_lerp2(*t >> 12, *t & 0xFFF, k >> 12, k & 0xFFF, cov * 17, &r, &lv);
+ *t = r << 12 | lv;
+}
+
+static void tex_rect(struct fos_can *c, int u, int v, int w, int h, int k)
+{
+ if (v < 0) { h += v; v = 0; }
+ if (v + h > TH) h = TH - v;
+ for (int i = u; i < u + w && h > 0; i++)
+ {
+ uint16_t *t = &c->tex[wrap_u(i) * TH + v];
+ for (int j = 0; j < h; j++)
+ t[j] = k;
+ }
+}
+
+/* glyph coverage straight from the font, optionally turned 90 degrees
+ * counter-clockwise (text reading upwards) */
+static void tex_glyph(struct fos_can *c, const struct fos_font *f, const struct fos_glyph *g,
+ int u, int v, int k, int vertical)
+{
+ const uint8_t *p = f->bits + g->off;
+ int col = 0, row = 0;
+ while (row < g->h)
+ {
+ int b = *p++;
+ int run, val;
+ if (b & 0x80) { run = (b & 0x7F) + 1; val = 0; }
+ else { run = (b >> 4) + 1; val = b & 15; }
+ while (run--)
+ {
+ if (val)
+ {
+ int gx = g->ox + col, gy = g->oy + row;
+ if (vertical) tex_put(c, u + gy, v - gx, k, val);
+ else tex_put(c, u + gx, v + gy, k, val);
+ }
+ if (++col == g->w) { col = 0; row++; }
+ }
+ }
+}
+
+/* text along the label; align -1 left, 0 centre, 1 right; returns width */
+static int tex_text(struct fos_can *c, const struct fos_font *f, int u, int base, const char *s,
+ int k, int track, int align)
+{
+ int w = fos_text_w(f, s, track);
+ int pen = (u - (align + 1) * w / 2) * 16;
+ for (const char *q = s; *q; q++)
+ {
+ int i = f->lut[(uint8_t) *q];
+ if (i == 0xFF) continue;
+ const struct fos_glyph *g = &f->glyphs[i];
+ tex_glyph(c, f, g, (pen + 8) >> 4, base, k, 0);
+ pen += g->adv + track;
+ }
+ return w;
+}
+
+/* text reading upwards, centred on (u, v); the baseline is at u */
+static void tex_vtext(struct fos_can *c, const struct fos_font *f, int u, int v, const char *s, int k, int track)
+{
+ int w = fos_text_w(f, s, track);
+ int pen = (v + w / 2) * 16;
+ for (const char *q = s; *q; q++)
+ {
+ int i = f->lut[(uint8_t) *q];
+ if (i == 0xFF) continue;
+ const struct fos_glyph *g = &f->glyphs[i];
+ tex_glyph(c, f, g, u, (pen + 8) >> 4, k, 1);
+ pen -= g->adv + track;
+ }
+}
+
+/* DX CAS code: two rows of six cells, bare steel (conducts) or painted.
+ * The first cell of each row is always bare; the rest come from the box
+ * speed and the exposure count, like the real thing (close enough). */
+static void tex_dx(struct fos_can *c, int u, int v, int iso, int exposures, int steel, int paint)
+{
+ static const int isos[] = { 25, 50, 64, 100, 125, 160, 200, 400, 800, 1600, 3200 };
+ int code = 0;
+ for (int i = 0; i < (int) (sizeof(isos) / sizeof(isos[0])); i++)
+ if (isos[i] == iso) code = i + 3;
+ int row1 = 1 | (code << 1);
+ int row2 = 1 | ((exposures == 36 ? 5 : exposures == 24 ? 3 : 2) << 1) | 0x20;
+ for (int i = 0; i < 6; i++)
+ {
+ tex_rect(c, u + i * 7, v, 6, 8, (row1 >> i) & 1 ? steel : paint);
+ tex_rect(c, u + i * 7, v + 9, 6, 8, (row2 >> i) & 1 ? steel : paint);
+ }
+}
+
+/* a UPC-ish barcode, the same for the same stock, about 50 texels wide */
+static void tex_barcode(struct fos_can *c, int u, int v, int h, const char *seed, int ink_bar)
+{
+ unsigned int x = 2166136261u;
+ for (const char *s = seed; *s; s++) x = (x ^ (uint8_t) *s) * 16777619u;
+ int pos = u;
+ for (int i = 0; i < 18; i++)
+ {
+ x = x * 1103515245u + 12345u;
+ int bar = 1 + (x >> 16) % 2, gap = 1 + (x >> 20) % 2;
+ int hh = (i == 0 || i == 9 || i == 17) ? h + 3 : h;
+ tex_rect(c, pos, v, bar, hh, ink_bar);
+ pos += bar + gap;
+ }
+}
+
+/* the parts every canister shares: the felt lip, and the back with the
+ * DX code, the barcode and the small print. Going round from the lip:
+ * DX code and exposures, barcode, then "PROCESS" reading upwards, all
+ * clear of the front panel (about U_FRONT +- 65). */
+static void paint_common(struct fos_can *c, int body, int text, const char *process)
+{
+ const struct fos_film *f = &fos_films[c->film];
+ int steel = ink(c, RAMP_METAL, 205);
+ int black = ink(c, RAMP_GRAY, 16);
+ int felt = ink(c, RAMP_GRAY, 9);
+
+ /* the light trap: a strip of black velvet between two folded edges */
+ tex_rect(c, U_LIP - 5, 0, 10, TH, felt);
+ tex_rect(c, U_LIP - 7, 0, 2, TH, steel);
+ tex_rect(c, U_LIP + 5, 0, 2, TH, steel);
+
+ char buf[32];
+ int u_dx = U_LIP + 22; /* 255 */
+ tex_rect(c, u_dx - 3, TH / 2 - 12, 48, 24, black);
+ tex_dx(c, u_dx, TH / 2 - 9, f->box_iso, c->exposures, steel, black);
+ snprintf(buf, sizeof(buf), "135-%d", c->exposures);
+ tex_text(c, &fos_font_lsm, u_dx + 21, TH / 2 - 20, buf, text, 16, 0);
+
+ tex_barcode(c, U_LIP + 76, TH - 52, 26, f->key, text); /* 309, round the seam */
+
+ snprintf(buf, sizeof(buf), "PROCESS %s", process);
+ tex_vtext(c, &fos_font_lsm, 64, TH / 2, buf, text, 16);
+ (void) body;
+}
+
+/* text that fits the front of the canister: the widest tracking that does,
+ * squeezed a little if even none is too wide */
+static void tex_text_fit(struct fos_can *c, const struct fos_font *f, int u, int base, const char *s, int k, int track)
+{
+ const int room = 108;
+ while (track > -32 && fos_text_w(f, s, track) > room) track -= 4;
+ tex_text(c, f, u, base, s, k, track, 0);
+}
+
+static int label_ink(struct fos_can *c, const uint8_t ink2[2])
+{
+ return ink(c, ink2[0] < RAMP_COUNT ? ink2[0] : RAMP_GRAY, ink2[1]);
+}
+
+/* a label from its parts (struct fos_label): the films from the card */
+static void paint_parts(struct fos_can *c, const struct fos_film *f)
+{
+ const struct fos_label *l = f->label;
+ const int u = U_FRONT - 4;
+ int bg = label_ink(c, l->bg), band = label_ink(c, l->band), acc = label_ink(c, l->accent);
+ int txt = label_ink(c, l->text), num = label_ink(c, l->num);
+ char bottom[40];
+ if (l->sub[0]) snprintf(bottom, sizeof(bottom), "%s 135-%d", l->sub, c->exposures);
+ else snprintf(bottom, sizeof(bottom), "135-%d", c->exposures);
+ tex_rect(c, 0, 0, TW, TH, bg);
+ const struct fos_font *word = fos_text_w(&fos_font_lname, l->word, -32) <= 108 ? &fos_font_lname : &fos_font_lsm;
+ switch (l->style)
+ {
+ case FOS_LABEL_CAP: /* a coloured cap over the top (Portra) */
+ tex_rect(c, 0, 0, TW, 24, band);
+ tex_rect(c, 0, 24, TW, 4, acc);
+ tex_text_fit(c, &fos_font_lsm, u, 17, l->top, acc, 24);
+ tex_text_fit(c, word, u, 58, l->word, txt, 40);
+ tex_text(c, &fos_font_lbig, u, 112, l->num_s, num, 0, 0);
+ tex_rect(c, 0, 120, TW, 3, acc);
+ tex_rect(c, 0, 125, TW, 9, band);
+ tex_text_fit(c, &fos_font_lsm, u, 147, bottom, txt, 16);
+ break;
+ case FOS_LABEL_STRIPES: /* thin stripes top and bottom (Ektar) */
+ tex_rect(c, 0, 6, TW, 5, acc);
+ tex_rect(c, 0, TH - 11, TW, 5, acc);
+ tex_text_fit(c, &fos_font_lsm, u, 30, l->top, acc, 24);
+ tex_text_fit(c, word, u, 60, l->word, txt, 40);
+ tex_text(c, &fos_font_lbig, u, 116, l->num_s, num, 0, 0);
+ tex_text_fit(c, &fos_font_lsm, u, 133, bottom, txt, 16);
+ break;
+ default: /* a band the name sits on (Gold) */
+ tex_rect(c, 0, 36, TW, 34, band);
+ tex_text_fit(c, &fos_font_lsm, u, 26, l->top, acc, 40);
+ tex_text_fit(c, word, u, 63, l->word, txt, 48);
+ tex_text(c, &fos_font_lbig, u, 122, l->num_s, num, 0, 0);
+ tex_text_fit(c, &fos_font_lsm, u, 140, bottom, num, 16);
+ break;
+ }
+ paint_common(c, bg, txt, f->process);
+ if (l->leader)
+ {
+ c->leader_ramp = RAMP_GRAY;
+ c->leader_lv = LV12(l->leader);
+ }
+}
+
+static void paint_label(struct fos_can *c)
+{
+ const struct fos_film *f = &fos_films[c->film];
+ const int u = U_FRONT - 4; /* optical centre of the front panel */
+ char exp[16];
+ snprintf(exp, sizeof(exp), "135-%d", c->exposures);
+ c->ramps = 1 << RAMP_GRAY; /* what an unpainted texel is */
+ c->gloss = 220;
+ c->leader_ramp = RAMP_LEADER;
+ c->leader_lv = LV12(120);
+
+ if (f->label)
+ paint_parts(c, f);
+ else if (!strcmp(f->key, "portra400"))
+ {
+ int cream = ink(c, RAMP_GRAY, 226), yel = ink(c, RAMP_AMBER, 188), org = ink(c, RAMP_ORANGE, 160);
+ int red = ink(c, RAMP_RED, 150), blk = ink(c, RAMP_GRAY, 22);
+ tex_rect(c, 0, 0, TW, TH, cream);
+ tex_rect(c, 0, 0, TW, 24, yel);
+ tex_rect(c, 0, 24, TW, 4, org);
+ tex_text(c, &fos_font_lsm, u, 17, "KODAK PROFESSIONAL", red, 24, 0);
+ tex_text(c, &fos_font_lname, u, 58, "PORTRA", blk, 40, 0);
+ tex_text(c, &fos_font_lbig, u, 112, "400", blk, 0, 0);
+ tex_rect(c, 0, 120, TW, 3, org);
+ tex_rect(c, 0, 125, TW, 9, yel);
+ tex_text(c, &fos_font_lsm, u, 147, exp, blk, 16, 0);
+ tex_vtext(c, &fos_font_lname, u - 62, 76, "KODAK", red, 24);
+ paint_common(c, cream, blk, f->process);
+ }
+ else if (!strcmp(f->key, "cinestill800t"))
+ {
+ int blk = ink(c, RAMP_GRAY, 20), red = ink(c, RAMP_RED, 150), wht = ink(c, RAMP_GRAY, 238);
+ tex_rect(c, 0, 0, TW, TH, blk);
+ tex_rect(c, 0, 10, TW, 3, red);
+ tex_rect(c, 0, TH - 13, TW, 3, red);
+ tex_text(c, &fos_font_lname, u, 44, "CINESTILL", wht, 24, 0);
+ int w = fos_text_w(&fos_font_lbig, "800T", 0);
+ int x0 = u - w / 2;
+ int w8 = tex_text(c, &fos_font_lbig, x0, 104, "800", wht, 0, -1);
+ tex_text(c, &fos_font_lbig, x0 + w8, 104, "T", red, 0, -1);
+ tex_text(c, &fos_font_lsm, u, 124, "TUNGSTEN 3200K", red, 24, 0);
+ tex_text(c, &fos_font_lsm, u, 139, exp, wht, 16, 0);
+ paint_common(c, blk, wht, f->process);
+ }
+ else if (!strcmp(f->key, "ektar100"))
+ {
+ int crim = ink(c, RAMP_CRIMSON, 128), yel = ink(c, RAMP_AMBER, 188), wht = ink(c, RAMP_GRAY, 240);
+ tex_rect(c, 0, 0, TW, TH, crim);
+ tex_rect(c, 0, 6, TW, 5, yel);
+ tex_rect(c, 0, TH - 11, TW, 5, yel);
+ tex_text(c, &fos_font_lsm, u, 30, "KODAK PROFESSIONAL", yel, 24, 0);
+ tex_text(c, &fos_font_lname, u, 60, "EKTAR", wht, 48, 0);
+ tex_text(c, &fos_font_lbig, u, 116, "100", yel, 0, 0);
+ tex_text(c, &fos_font_lsm, u, 132, exp, wht, 16, 0);
+ paint_common(c, crim, wht, f->process);
+ }
+ else if (!strcmp(f->key, "gold200"))
+ {
+ int yel = ink(c, RAMP_AMBER, 190), red = ink(c, RAMP_RED, 148), blk = ink(c, RAMP_GRAY, 22);
+ int wht = ink(c, RAMP_GRAY, 240);
+ tex_rect(c, 0, 0, TW, TH, yel);
+ tex_rect(c, 0, 36, TW, 32, red);
+ tex_text(c, &fos_font_lsm, u, 24, "KODAK", red, 48, 0);
+ tex_text(c, &fos_font_lname, u, 62, "GOLD", wht, 56, 0);
+ tex_text(c, &fos_font_lbig, u, 122, "200", blk, 0, 0);
+ tex_text(c, &fos_font_lsm, u, 140, exp, blk, 16, 0);
+ tex_vtext(c, &fos_font_lsm, u - 60, 96, "COLOR", red, 24);
+ paint_common(c, yel, blk, f->process);
+ }
+ else if (!strcmp(f->key, "superia400"))
+ {
+ int grn = ink(c, RAMP_GREEN, 140), wht = ink(c, RAMP_GRAY, 240), red = ink(c, RAMP_RED, 150);
+ int dk = ink(c, RAMP_GREEN, 70);
+ tex_rect(c, 0, 0, TW, TH, grn);
+ tex_rect(c, 0, 72, TW, 52, dk);
+ tex_rect(c, 0, 124, TW, 3, red);
+ tex_text(c, &fos_font_lsm, u, 24, "FUJIFILM", wht, 48, 0);
+ tex_text(c, &fos_font_lname, u, 58, "SUPERIA", wht, 24, 0);
+ tex_text(c, &fos_font_lbig, u, 118, "400", wht, 0, 0);
+ tex_text(c, &fos_font_lsm, u, 142, exp, wht, 16, 0);
+ paint_common(c, grn, wht, f->process);
+ }
+ else if (!strcmp(f->key, "velvia50"))
+ {
+ int vio = ink(c, RAMP_VIOLET, 118), wht = ink(c, RAMP_GRAY, 240), lil = ink(c, RAMP_VIOLET, 225);
+ tex_rect(c, 0, 0, TW, TH, vio);
+ tex_rect(c, 0, 0, TW, 6, lil);
+ tex_rect(c, 0, TH - 6, TW, 6, lil);
+ tex_text(c, &fos_font_lsm, u, 28, "FUJICHROME", wht, 32, 0);
+ tex_text(c, &fos_font_lname, u, 58, "VELVIA", wht, 40, 0);
+ tex_text(c, &fos_font_lbig, u, 116, "50", lil, 0, 0);
+ tex_text(c, &fos_font_lsm, u, 134, "RVP 50 " , wht, 24, 0);
+ paint_common(c, vio, wht, f->process);
+ c->leader_lv = LV12(70);
+ }
+ else if (!strcmp(f->key, "hp5"))
+ {
+ int wht = ink(c, RAMP_GRAY, 236), blk = ink(c, RAMP_GRAY, 20), blu = ink(c, RAMP_BLUE, 160);
+ tex_rect(c, 0, 0, TW, TH, wht);
+ tex_rect(c, 0, 40, TW, 76, blk);
+ tex_rect(c, 0, 116, TW, 3, blu);
+ tex_text(c, &fos_font_lname, u, 32, "ILFORD", blk, 48, 0);
+ tex_text(c, &fos_font_lbig, u, 92, "HP5", wht, 0, 0);
+ tex_text(c, &fos_font_lsm, u, 108, "PLUS", blu, 64, 0);
+ tex_text(c, &fos_font_lname, u - 16, 142, "400", blk, 24, 0);
+ tex_text(c, &fos_font_lsm, u + 30, 141, exp, blk, 0, 0);
+ paint_common(c, wht, blk, f->process);
+ c->leader_ramp = RAMP_GRAY;
+ c->leader_lv = LV12(52);
+ }
+ else if (!strcmp(f->key, "trix400"))
+ {
+ int blk = ink(c, RAMP_GRAY, 18), yel = ink(c, RAMP_AMBER, 190), wht = ink(c, RAMP_GRAY, 238);
+ int red = ink(c, RAMP_RED, 150);
+ tex_rect(c, 0, 0, TW, TH, blk);
+ tex_rect(c, 0, 14, TW, 50, yel);
+ tex_text(c, &fos_font_lsm, u, 30, "KODAK", blk, 48, 0);
+ tex_text(c, &fos_font_lname, u, 56, "TRI-X", blk, 40, 0);
+ tex_text(c, &fos_font_lbig, u, 120, "400", wht, 0, 0);
+ tex_text(c, &fos_font_lsm, u - 30, 138, "TX", red, 16, 0);
+ tex_text(c, &fos_font_lsm, u + 14, 138, exp, wht, 16, 0);
+ paint_common(c, blk, wht, f->process);
+ c->leader_ramp = RAMP_GRAY;
+ c->leader_lv = LV12(48);
+ }
+}
+
+struct fos_can *fos_can_new(int film, int exposures)
+{
+ if (!prof_ready) build_profiles();
+ struct fos_can *c = fos_port_alloc(sizeof(struct fos_can));
+ if (!c) return 0;
+ memset(c, 0, sizeof(*c));
+ c->tex = fos_port_alloc(TW * TH * sizeof(uint16_t));
+ if (!c->tex) { fos_port_free(c); return 0; }
+ c->film = fos_clamp(film, 0, fos_nfilms - 1);
+ c->exposures = exposures;
+ memset(c->tex, 0, TW * TH * sizeof(uint16_t));
+ paint_label(c);
+ return c;
+}
+
+void fos_can_free(struct fos_can *c)
+{
+ if (!c) return;
+ fos_port_free(c->tex);
+ fos_port_free(c);
+}
+
+void fos_can_set_exposures(struct fos_can *c, int exposures)
+{
+ if (!c || c->exposures == exposures) return;
+ c->exposures = exposures;
+ memset(c->tex, 0, TW * TH * sizeof(uint16_t));
+ paint_label(c);
+}
+
+
+/* ---------------------------------------------------------------- drawing */
+
+/* ellipse half-height of a circle of radius r8 at offset dx8 (all 1/256 px) */
+static int arc8(int dx8, int r8)
+{
+ int q = r8 * r8 - dx8 * dx8;
+ if (q <= 0) return 0;
+ return fos_isqrt((unsigned) q >> 8) * 16 * TILT / 256;
+}
+
+/* one column of the canister, worked out once per frame */
+struct can_col
+{
+ int16_t body; /* column crosses the body (not only the caps) */
+ int16_t u, uf; /* label texture column and its fraction (0..255) */
+ int16_t cov; /* silhouette coverage 0..256 */
+ int16_t metal; /* caps, 12-bit, lit */
+ int16_t spool; /* spool side, 12-bit, lit; -1 outside it */
+ int16_t ex, sx; /* x across the cap / the spool, 4096 = edge */
+ int32_t ex2, sx2; /* ... squared */
+ int32_t gain, offs; /* the label's light here: lv * gain / 65536 + offs */
+ int32_t top8; /* y of the top band's upper edge, 1/256 px */
+ int32_t cap8; /* the highest the cap or the spool reaches */
+ int32_t sp_top8, sp_bot8; /* spool side, 1/256 px */
+};
+
+#define MAX_COLS 176
+#define MAX_CAP_ROWS 64
+static struct can_col cols[MAX_COLS];
+
+
+FOS_INLINE int lit(int lv, int light)
+{
+ return (lv * light) >> 8;
+}
+
+FOS_INLINE void put(struct fos_canvas *cv, int x, int y, int ramp, int lv, int cov)
+{
+ uint8_t *px = &cv->px[y * cv->pitch + x];
+ if (cov >= 256) *px = fos_ixd(ramp, fos_ramp_pos(ramp, lv), x, y);
+ else if (cov > 0) *px = fos_mix(*px, ramp, lv, cov);
+}
+
+#define ABS16(v) ((v) < 0 ? -(v) : (v))
+
+/* ramp position (1/16 entries) -> palette index, clamped at the light end */
+static uint8_t ix_tab[RAMP_COUNT][256];
+static int ix_tab_ready;
+
+static void build_ix_tab()
+{
+ for (int r = 0; r < RAMP_COUNT; r++)
+ for (int q = 0; q < 256; q++)
+ ix_tab[r][q] = fos_ramp_base[r] + (q > fos_ramp_last[r] ? fos_ramp_last[r] : q);
+ ix_tab_ready = 1;
+}
+
+/* n rows of the leader fully inside its edges; v (0..4096 across the
+ * film) steps by dv, holes are the v ranges [h, h + 480) */
+__attribute__((noinline))
+static void leader_run(uint8_t *px, int pitch, int n, int v, int dv, int lv_along, int sheen_k, int lmul,
+ const uint8_t *tab, const uint8_t *bay, int h1, int h2)
+{
+ for (int i = 0; i < n; i++, v += dv, px += pitch)
+ {
+ if ((unsigned) (v - h1) < 480 || (unsigned) (v - h2) < 480) continue;
+ /* glossy emulsion: a soft sheen a third of the way down */
+ int sheen = 4096 - ABS16(v - 1300) * 5;
+ int lv = lv_along + (sheen > 0 ? (sheen * sheen_k) >> 20 : 0);
+ int q = (((lv * lmul) >> 16) + bay[i & 3]) >> 4;
+ *px = tab[q & 255];
+ }
+}
+
+/* the film leader coming out of the lip: full width at first, then the
+ * cut-down tongue, perforated along its edges. It leaves the lip heading
+ * away from us, so it tapers a little and rises with distance. */
+static void draw_leader(struct fos_canvas *cv, const struct fos_can *c, const struct fos_can_pose *p,
+ int y_body_top, int s)
+{
+ int lip = (U_LIP - U_FRONT) * 65536 / TW - p->rot; /* lip angle on screen */
+ int sn = fos_sin(lip); /* 4096 = right edge */
+ if (sn < 900) return;
+ /* p->leader: 256 = the usual tongue, more = pulled out further */
+ int len = (70 * s >> 8) * p->leader / 256 * sn / 4096; /* foreshortened as it turns */
+ int tongue = 50 * s / 256 * sn / 4096;
+ if (len < 4) return;
+ int x0 = (p->cx8 >> 8) + (R * s / 256) * sn / 4096 - 3 * s / 256;
+ int fw8 = 112 * s; /* film width, 1/256 px */
+ int mid8 = y_body_top * 256 + HB * s / 2;
+ int full = len - tongue > len * 28 / 100 ? len - tongue : len * 28 / 100; /* full width before the cut */
+ int curve = 12 * s / 256 + 1;
+ int perf_w = fos_clamp(8 * s / 256, 2, 20), pitch = fos_clamp(15 * s / 256, 4, 40);
+ int end_r = 9 * s / 256 + 1;
+ int ramp = c->leader_ramp;
+ int lmul = (p->light * fos_ramp_mul[ramp]) >> 8; /* light and ramp position in one */
+ int inv_len = 65536 / len;
+ if (!ix_tab_ready) build_ix_tab();
+ int xa = fos_clamp(x0, cv->cx0, cv->cx1), xb = fos_clamp(x0 + len, cv->cx0, cv->cx1);
+
+ for (int x = xa; x < xb; x++)
+ {
+ int t = x - x0;
+ int depth = (t * inv_len) >> 8; /* 0 at the lip, 256 at the tip */
+ int hw8 = (fw8 / 2) * (256 - depth * 40 / 256) >> 8;
+ int cy8 = mid8 - depth * s / 64;
+ int top8 = cy8 - hw8, bot8 = cy8 + hw8;
+ if (t > full)
+ {
+ /* the tongue keeps the lower half; the cut curves down to it */
+ int k = t - full;
+ int f = k >= curve ? 4096 : (4096 - fos_cos(k * 32768 / curve)) / 2;
+ top8 = cy8 - hw8 + ((hw8 * f) >> 12);
+ int rem = len - t;
+ if (rem < end_r)
+ {
+ int dy = fos_isqrt((unsigned) (end_r * end_r - (end_r - rem) * (end_r - rem))) * 256;
+ int c8 = (top8 + bot8) / 2;
+ if (top8 < c8 - dy) top8 = c8 - dy;
+ if (bot8 > c8 + dy) bot8 = c8 + dy;
+ }
+ }
+ if (bot8 <= top8) continue;
+ int ph = (t + pitch / 2) % pitch;
+ int perf_col = ph < perf_w && t > 2;
+ /* darker where it disappears into the lip and towards the tip */
+ int along = 3000 + 1100 * fos_sin(depth * 128 + 0x2000) / 4096 - (t < 3 ? 1400 : 0);
+ int lv_along = lit(c->leader_lv, along * 256 / 4096);
+ int sheen_k = (LV_MAX - lv_along) * 60;
+ int ya = fos_clamp(top8 >> 8, cv->cy0, cv->cy1), yb = fos_clamp((bot8 >> 8) + 1, cv->cy0, cv->cy1);
+ /* position across the film, 0..4096 from its top edge, stepped per row */
+ int dv = 4096 * 256 / (2 * hw8 > 0 ? 2 * hw8 : 1);
+ int v = ((ya * 256 + 128 - (cy8 - hw8)) * dv) >> 8;
+ /* sprocket holes, as ranges of v: the background shows */
+ int h1 = perf_col && t <= full ? 300 : 1 << 20, h2 = perf_col ? 3316 : 1 << 20;
+ /* whole rows inside the edges go through the quick loop */
+ int yf0 = fos_clamp((top8 + 255) >> 8, ya, yb), yf1 = fos_clamp(bot8 >> 8, yf0, yb);
+ uint8_t *px = &cv->px[ya * cv->pitch + x];
+ for (int y = ya; y < yb; y++, v += dv, px += cv->pitch)
+ {
+ if (y == yf0 && yf1 > yf0)
+ {
+ uint8_t bay[4];
+ for (int j = 0; j < 4; j++) bay[j] = fos_bayer[(y + j) & 3][x & 3];
+ leader_run(px, cv->pitch, yf1 - yf0, v, dv, lv_along, sheen_k, lmul, &ix_tab[ramp][0], bay, h1, h2);
+ int n = yf1 - yf0 - 1;
+ y += n; v += n * dv; px += n * cv->pitch;
+ continue;
+ }
+ int yc = y * 256 + 128;
+ int cov = fos_clamp(128 + (yc - top8), 0, 256) * fos_clamp(128 + (bot8 - yc), 0, 256) >> 8;
+ if (cov <= 0) continue;
+ if ((unsigned) (v - h1) < 480 || (unsigned) (v - h2) < 480) continue;
+ /* glossy emulsion: a soft sheen a third of the way down */
+ int sheen = 4096 - ABS16(v - 1300) * 5;
+ int lv = lv_along + (sheen > 0 ? (sheen * sheen_k) >> 20 : 0);
+ *px = fos_mix(*px, ramp, lit(lv, p->light), cov);
+ }
+ }
+}
+
+/* geometry of one pose, shared by the parts */
+struct can_geo
+{
+ int s, r8, rc8, rs8, cx8;
+ int e_c, e_s; /* cap / spool ellipse half heights */
+ int tb8, hb8, bb8, hs8;
+ int yc8; /* cap ellipse centre */
+ int xl, xr; /* the canister's columns */
+ int x0, x1; /* ... those inside the clip */
+};
+
+static int prepare(const struct fos_canvas *cv, const struct fos_can *c, const struct fos_can_pose *p,
+ struct can_geo *g)
+{
+ int s = p->scale;
+ if (s <= 0) return 0;
+ g->s = s;
+ g->r8 = R * s; g->rc8 = RC * s; g->rs8 = RS * s;
+ g->cx8 = p->cx8;
+ g->e_c = g->rc8 * TILT / 256;
+ g->e_s = g->rs8 * TILT / 256;
+ g->tb8 = TB * s; g->hb8 = HB * s; g->bb8 = BB * s; g->hs8 = HS * s;
+ g->yc8 = p->floor_y * 256 - (g->e_c + g->tb8 + g->hb8 + g->bb8);
+ g->xl = (g->cx8 - g->rc8) >> 8;
+ g->xr = (g->cx8 + g->rc8 + 255) >> 8;
+ if (g->xr - g->xl > MAX_COLS) return 0;
+ g->x0 = fos_clamp(g->xl, cv->cx0, cv->cx1);
+ g->x1 = fos_clamp(g->xr, cv->cx0, cv->cx1);
+
+ /* reciprocals instead of divisions in the loop */
+ int inv_pb = (NPROF << 16) / (2 * g->r8), inv_pc = (NPROF << 16) / (2 * g->rc8);
+ int inv_ps = (NPROF << 16) / (2 * g->rs8);
+ int inv_ec = (1 << 28) / g->rc8, inv_es = (1 << 28) / g->rs8;
+ int fade = p->light;
+ for (int x = g->x0; x < g->x1; x++)
+ {
+ struct can_col *k = &cols[x - g->xl];
+ int dx8 = x * 256 + 128 - g->cx8;
+ int adx = dx8 < 0 ? -dx8 : dx8;
+ k->body = adx < g->r8;
+ int pi = k->body ? PROF(dx8 + g->r8, inv_pb) : PROF(dx8 + g->rc8, inv_pc);
+ int u16 = ((prof_ang[pi] + p->rot) & 0xFFFF) * TW + U_FRONT * 65536;
+ k->u = wrap_u(u16 >> 16);
+ k->uf = (u16 >> 8) & 0xFF;
+ k->cov = fos_clamp(128 + (g->rc8 - adx), 0, 256);
+ k->metal = lit(prof_metal[PROF(dx8 + g->rc8, inv_pc)], fade);
+ int arc_c = arc8(dx8, g->rc8);
+ k->top8 = g->yc8 + arc_c;
+ k->cap8 = g->yc8 - arc_c - 512;
+ k->ex = fos_clamp((dx8 * inv_ec) >> 16, -8192, 8192);
+ k->sx = fos_clamp((fos_clamp(dx8, -4 * g->rs8, 4 * g->rs8) * inv_es) >> 16, -16384, 16384);
+ k->ex2 = k->ex * k->ex;
+ k->sx2 = k->sx * k->sx;
+ if (adx < g->rs8)
+ {
+ int arc_s = arc8(dx8, g->rs8);
+ k->spool = lit(prof_dark[PROF(dx8 + g->rs8, inv_ps)], fade);
+ k->sp_top8 = g->yc8 - g->hs8 + arc_s;
+ k->sp_bot8 = g->yc8 + arc_s;
+ if (g->yc8 - g->hs8 - arc_s - 256 < k->cap8) k->cap8 = g->yc8 - g->hs8 - arc_s - 256;
+ }
+ else k->spool = -1;
+ /* diffuse light, then the gloss over it, all faded */
+ int sp = (prof_spec[pi] * c->gloss) >> 8;
+ k->gain = ((prof_light[pi] * (256 - sp)) >> 8) * fade;
+ k->offs = (sp * LV_MAX * fade) >> 16;
+ }
+ return 1;
+}
+
+/* the cap seen from above: rolled rim, recessed disc, the spool end */
+static void draw_cap(struct fos_canvas *cv, const struct can_geo *g, int rot, int fade)
+{
+ if (!ix_tab_ready) build_ix_tab();
+ int ya = fos_clamp(((g->yc8 - g->hs8 - g->e_s) >> 8) - 2, cv->cy0, cv->cy1);
+ int yb = fos_clamp(((g->yc8 + g->e_c) >> 8) + 2, ya, cv->cy1);
+ if (yb - ya > MAX_CAP_ROWS) yb = ya + MAX_CAP_ROWS;
+ /* per row: y across the cap and the spool top (4096 = edge), squared,
+ * and the rim's and the disc's light falling off towards us */
+ struct { int ey2, sy, sy2, rim, disc, inv; } rows[MAX_CAP_ROWS];
+ int ec = g->e_c ? g->e_c : 1, es = g->e_s ? g->e_s : 1;
+ int inv_e = (1 << 28) / ec, inv_s = (1 << 28) / es;
+ for (int y = ya; y < yb; y++)
+ {
+ int yc = y * 256 + 128, j = y - ya;
+ int ey = (fos_clamp(yc - g->yc8, -4 * ec, 4 * ec) * inv_e) >> 16;
+ int sy = (fos_clamp(yc - (g->yc8 - g->hs8), -4 * es, 4 * es) * inv_s) >> 16;
+ rows[j].ey2 = ey * ey;
+ rows[j].sy = sy;
+ rows[j].sy2 = sy * sy;
+ rows[j].rim = LV12(150) - ey * LV12(60) / 4096;
+ rows[j].disc = LV12(96) - ey * LV12(22) / 4096;
+ /* how fast rho2 changes per px going down: the edge is that soft */
+ int gy = 2 * (ey < 0 ? -ey : ey) * 256 / ec;
+ rows[j].inv = (1 << 24) / (gy > 64 ? gy : 64);
+ }
+ int cs = fos_cos(rot * 2), sn = fos_sin(rot * 2);
+ for (int x = g->x0; x < g->x1; x++)
+ {
+ const struct can_col *k = &cols[x - g->xl];
+ if (k->cov <= 0) continue;
+ /* ... and going across: the edge's anti-aliasing follows the steeper */
+ int gx = 2 * (k->ex < 0 ? -k->ex : k->ex) * 256 / g->rc8;
+ int inv_x = (1 << 24) / (gx > 64 ? gx : 64);
+ int y0 = fos_clamp(k->cap8 >> 8, ya, yb);
+ int rim_x = k->ex * LV12(40) / 4096, disc_x = k->ex * LV12(30) / 4096;
+ int spool_top = LV12(34) - k->sx * LV12(14) / 4096, slot_x = cs * k->sx;
+ uint8_t bay[4];
+ for (int j = 0; j < 4; j++) bay[j] = fos_bayer[j][x & 3];
+ uint8_t *px = &cv->px[y0 * cv->pitch + x];
+ for (int y = y0; y < yb; y++, px += cv->pitch)
+ {
+ int yc = y * 256 + 128, j = y - ya;
+ if (yc >= k->top8) break;
+ int rho2 = (k->ex2 + rows[j].ey2) >> 12; /* 4096 = edge */
+ if (rho2 > 4096 + 400) continue;
+ int inv = rows[j].inv < inv_x ? rows[j].inv : inv_x;
+ int cov = 128 + (((4096 - rho2) * inv) >> 16);
+ if (cov <= 0) continue;
+ if (cov > 256) cov = 256;
+ if (k->cov < 256) cov = cov * k->cov >> 8;
+ int ramp = RAMP_METAL, lv;
+ int srho2 = (k->sx2 + rows[j].sy2) >> 12;
+ if (srho2 <= 4096)
+ {
+ /* top of the spool: black plastic with the key slot */
+ ramp = RAMP_GRAY;
+ int along = (slot_x + sn * rows[j].sy) >> 12;
+ int slot = along > -1000 && along < 1000 && srho2 < 3000;
+ lv = slot ? LV12(8) : srho2 > 3300 ? LV12(48) : spool_top;
+ }
+ else if (k->spool >= 0 && yc >= k->sp_top8 && yc < k->sp_bot8)
+ {
+ ramp = RAMP_GRAY;
+ lv = k->spool;
+ goto out;
+ }
+ else if (rho2 > 3250)
+ {
+ /* rolled rim: catches the light, brighter at the back */
+ lv = rows[j].rim - rim_x - (rho2 > 3900 ? LV12(40) : 0);
+ }
+ else
+ {
+ /* recessed disc: a soft gradient, a ring round the spool */
+ lv = srho2 < 4096 * 5 / 3 ? LV12(60) : rows[j].disc - disc_x;
+ }
+ lv = fos_clamp(lit(lv, fade), 0, LV_MAX);
+ out:
+ if (cov >= 256) *px = ix_tab[ramp][((fos_ramp_pos(ramp, lv) + bay[y & 3]) >> 4) & 255];
+ else if (cov > 0) *px = fos_mix(*px, ramp, lv, cov);
+ }
+ }
+}
+
+/* Label pixels down a column (the canvas is FOS_W wide). v8 is the
+ * texture row in 1/256, stepping by ds. For each ramp gb holds 8 words:
+ * this column's gain, then its offset with the dither threshold of rows
+ * 0..3 of the run already added. Kept apart from the rest of the drawing
+ * so the loop has the registers to itself. */
+#define LABEL_TEXEL(j) \
+ { \
+ int t = *(const uint16_t *) ((const uint8_t *) b0 + ((v8 >> 7) & ~1)); \
+ int r = t >> 12; \
+ const int32_t *k = &gb[r * 8]; \
+ int q = ((((t & 0xFFF) * k[0]) >> 16) + k[1 + (j)]) >> 4; \
+ *px = tab[r << 8 | (q & 255)]; \
+ px += FOS_W; v8 += ds; \
+ }
+
+__attribute__((noinline))
+static void label_run(uint8_t *px, int n, int v8, int ds, const uint16_t *b0, const int32_t *gb)
+{
+ const uint8_t *tab = &ix_tab[0][0];
+ for (; n >= 4; n -= 4)
+ {
+ LABEL_TEXEL(0) LABEL_TEXEL(1) LABEL_TEXEL(2) LABEL_TEXEL(3)
+ }
+ if (n > 0) LABEL_TEXEL(0)
+ if (n > 1) LABEL_TEXEL(1)
+ if (n > 2) LABEL_TEXEL(2)
+}
+
+/* the same between two texture columns, a fraction uf of the way to b1:
+ * levels of one ramp blend, different inks dither (thr: thresholds) */
+#define LABEL_TEXEL2(j) \
+ { \
+ int o = (v8 >> 7) & ~1; \
+ int t = *(const uint16_t *) ((const uint8_t *) b0 + o); \
+ int t1 = *(const uint16_t *) ((const uint8_t *) b1 + o); \
+ if (t1 != t) \
+ { \
+ if ((t ^ t1) >> 12) { if (uf > thr[j]) t = t1; } \
+ else t += (((t1 & 0xFFF) - (t & 0xFFF)) * uf) >> 8; \
+ } \
+ int r = t >> 12; \
+ const int32_t *k = &gb[r * 8]; \
+ int q = ((((t & 0xFFF) * k[0]) >> 16) + k[1 + (j)]) >> 4; \
+ *px = tab[r << 8 | (q & 255)]; \
+ px += FOS_W; v8 += ds; \
+ }
+
+__attribute__((noinline))
+static void label_run_filtered(uint8_t *px, int n, int v8, int ds, const uint16_t *b0, const uint16_t *b1,
+ int uf, const int32_t *gb, const uint8_t *thr)
+{
+ const uint8_t *tab = &ix_tab[0][0];
+ for (; n >= 4; n -= 4)
+ {
+ LABEL_TEXEL2(0) LABEL_TEXEL2(1) LABEL_TEXEL2(2) LABEL_TEXEL2(3)
+ }
+ if (n > 0) LABEL_TEXEL2(0)
+ if (n > 1) LABEL_TEXEL2(1)
+ if (n > 2) LABEL_TEXEL2(2)
+}
+
+/* first row whose centre is at least a below edge8 (1/256 px) */
+FOS_INLINE int row_at(int edge8, int a)
+{
+ return (edge8 + a - 128 + 255) >> 8;
+}
+
+/* the bands and the label, a column at a time: the texture row just steps */
+static void draw_body(struct fos_canvas *cv, const struct fos_can *c, const struct can_geo *g, int fade, int fast)
+{
+ int ds = 65536 / g->s; /* texels per row, 8.8 */
+ int band_t = g->tb8, body_b = g->tb8 + g->hb8, band_b = body_b + g->bb8;
+ int step_t = 65536 / (band_t ? band_t : 1), step_b = 65536 / (g->bb8 ? g->bb8 : 1);
+ int lip_hi = lit(LV12(40), fade), groove = lit(LV12(70), fade), ridge = lit(LV12(30), fade);
+ int filter = fos_can_quality > 1;
+ int pitch = cv->pitch;
+ if (!ix_tab_ready) build_ix_tab();
+
+ for (int x = g->x0; x < g->x1; x++)
+ {
+ const struct can_col *k = &cols[x - g->xl];
+ if (k->cov <= 0) continue;
+ int ya = fos_clamp(row_at(k->top8, 0), cv->cy0, cv->cy1);
+ int yb = fos_clamp(row_at(k->top8, band_t), cv->cy0, cv->cy1);
+ int yc_ = fos_clamp(row_at(k->top8, body_b), cv->cy0, cv->cy1);
+ int yd = fos_clamp(row_at(k->top8, band_b), cv->cy0, cv->cy1);
+ int y;
+
+ /* top crimp: a rolled lip above, a groove below; f = 0..256 down the band */
+ int f = ((ya * 256 + 128 - k->top8) * step_t) >> 8;
+ for (y = ya; y < yb; y++, f += step_t)
+ {
+ int lv = k->metal + (f < 70 ? lip_hi : 0) - (f > 210 ? groove : 0);
+ put(cv, x, y, RAMP_METAL, fos_clamp(lv, 0, LV_MAX), k->cov);
+ }
+
+ /* the printed label */
+ if (k->body && yb < yc_)
+ {
+ const uint16_t *b0 = &c->tex[k->u * TH];
+ const uint16_t *b1 = &c->tex[(k->u + 1 < TW ? k->u + 1 : 0) * TH];
+ int v8 = ((yb * 256 + 128 - k->top8 - band_t) * ds) >> 8;
+ /* keep the texture row inside the label */
+ int ye = yc_;
+ if (v8 < 0) v8 = 0;
+ if (((v8 + (ye - yb - 1) * ds) >> 8) >= TH) ye = yb + ((TH * 256 - 1 - v8) / ds) + 1;
+ uint8_t *px = &cv->px[yb * pitch + x];
+ if (k->cov >= 256 && ye > yb && pitch == FOS_W)
+ {
+ /* this column's light, folded into each ramp's position
+ * scale, with the dither of the run's rows 0..3 */
+ int32_t gb[RAMP_COUNT * 8];
+ uint8_t thr[4];
+ int g4 = k->gain >> 4;
+ int bay[4];
+ for (int j = 0; j < 4; j++)
+ {
+ int yy = (yb + j) & 3;
+ bay[j] = fos_bayer[yy][x & 3];
+ thr[j] = fos_bayer[(yy + 2) & 3][(x + 1) & 3] * 16 + 8;
+ }
+ for (int r = 0; r < RAMP_COUNT; r++)
+ {
+ if (!(c->ramps & (1 << r))) continue;
+ int32_t *e = &gb[r * 8];
+ int o = (k->offs * fos_ramp_mul[r]) >> 16;
+ e[0] = (g4 * fos_ramp_mul[r]) >> 12;
+ e[1] = o + bay[0]; e[2] = o + bay[1]; e[3] = o + bay[2]; e[4] = o + bay[3];
+ }
+ if (filter && k->uf && !fast)
+ label_run_filtered(px, ye - yb, v8, ds, b0, b1, k->uf, gb, thr);
+ else
+ label_run(px, ye - yb, v8, ds, b0, gb);
+ }
+ else
+ {
+ /* the silhouette's edge columns, blended with what is behind */
+ for (y = yb; y < ye; y++, v8 += ds, px += pitch)
+ {
+ int t = b0[v8 >> 8];
+ int lv = (((t & 0xFFF) * k->gain) >> 16) + k->offs;
+ *px = fos_mix(*px, t >> 12, lv > LV_MAX ? LV_MAX : lv, k->cov);
+ }
+ }
+ }
+
+ /* bottom crimp, its lower edge following the cap ellipse */
+ int rel = yc_ * 256 + 128 - k->top8;
+ f = ((rel - body_b) * step_b) >> 8;
+ for (y = yc_; y < yd; y++, rel += 256, f += step_b)
+ {
+ int lv = k->metal - (f < 50 ? groove : 0) + (f > 140 && f < 200 ? ridge : 0);
+ int cov = k->cov;
+ int below = rel - (band_b - 256);
+ if (below > 0) cov = cov * (256 - below) >> 8;
+ put(cv, x, y, RAMP_METAL, fos_clamp(lv, 0, LV_MAX), cov);
+ }
+ }
+}
+
+/* the canister mirrored in the glossy floor, fading out below it: a little
+ * of each pixel above the bottom edge glazed over the floor below it */
+static void draw_reflection(struct fos_canvas *cv, const struct fos_can_pose *p, const struct can_geo *g)
+{
+ int depth = 38 * g->s / 256;
+ if (depth <= 0) return;
+ int y0 = fos_clamp(p->floor_y, cv->cy0, cv->cy1), y1 = fos_clamp(p->floor_y + depth, cv->cy0, cv->cy1);
+ if (y1 - y0 > 64) y1 = y0 + 64;
+ int kk[64];
+ for (int y = y0; y < y1; y++)
+ {
+ int k = p->reflect * (depth - (y - p->floor_y)) / depth;
+ kk[y - y0] = (k * k / 256) * 200 >> 8; /* the print a little darker in the floor */
+ if (kk[y - y0] < 2) { y1 = y; break; } /* fainter than a level step */
+ }
+ int edge_off = g->tb8 + g->hb8 + g->bb8; /* from the band's top edge to the bottom outline */
+ int pitch = cv->pitch;
+ for (int x = g->x0; x < g->x1; x++)
+ {
+ const struct can_col *col = &cols[x - g->xl];
+ if (col->cov < 128) continue;
+ int edge8 = col->top8 + edge_off;
+ int reach = col->body ? 1 << 30 : g->bb8; /* past the body only the band shows */
+ for (int y = y0; y < y1; y++)
+ {
+ int up = y * 256 + 128 - edge8; /* below the edge = above it in the mirror */
+ if (up < 0) continue;
+ if (up >= reach) break;
+ int sy = (edge8 - up) >> 8;
+ if (sy < cv->cy0) break;
+ int k = kk[y - y0];
+ if (k <= 0) break;
+ uint8_t *px = &cv->px[y * pitch + x];
+ *px = fos_glaze(*px, cv->px[sy * pitch + x], k, x, y);
+ }
+ }
+}
+
+void fos_can_draw(struct fos_canvas *cv, struct fos_can *c, const struct fos_can_pose *p)
+{
+ struct can_geo g;
+ if (!c || !prepare(cv, c, p, &g)) return;
+ if (g.xr <= cv->cx0 || g.xl >= cv->cx1) return;
+ if (p->leader)
+ draw_leader(cv, c, p, (g.yc8 + g.tb8) >> 8, g.s);
+ draw_cap(cv, &g, p->rot, p->light);
+ draw_body(cv, c, &g, p->light, p->fast);
+ if (p->reflect && fos_can_quality > 0)
+ draw_reflection(cv, p, &g);
+}
diff --git a/ml-dev/filmos/fos_font.c b/ml-dev/filmos/fos_font.c
new file mode 100644
index 0000000..ba76a9e
--- /dev/null
+++ b/ml-dev/filmos/fos_font.c
@@ -0,0 +1,4254 @@
+/* generated by tools/mkfont.py from Barlow (SIL Open Font License 1.1,
+ * see fonts/OFL.txt) - do not edit. Not linked into the camera: it goes
+ * on the card as ML/DATA/FOSFONT.BIN (tools/fontblob.c) */
+
+#include "fos_gfx.h"
+
+static const uint8_t xs_bits[] = {
+ 128,8,14,129,8,14,129,8,13,129,7,13,129,7,13,129,6,12,133,2,3,129,9,13,
+ 128,11,10,6,14,26,6,14,9,8,5,12,151,129,6,15,2,3,15,5,130,8,14,128,
+ 5,15,2,129,12,95,1,128,4,14,12,5,12,13,5,130,14,8,128,27,130,2,15,8,
+ 1,13,10,1,128,4,95,9,128,1,8,15,22,15,8,2,129,8,14,128,5,15,3,129,
+ 130,15,4,130,1,7,15,10,2,129,12,15,13,15,14,2,4,15,4,128,2,14,9,4,
+ 15,4,129,23,128,11,15,9,3,131,7,13,15,10,1,131,6,15,9,6,15,130,10,11,
+ 3,15,9,3,4,14,8,128,5,13,15,14,9,1,130,15,5,129,128,6,14,13,5,129,
+ 13,3,130,14,8,9,13,128,7,10,131,10,31,8,1,14,2,132,3,2,128,9,8,135,
+ 3,13,1,135,11,6,5,30,4,131,4,12,128,14,6,7,13,131,12,4,128,14,7,8,
+ 13,130,6,10,129,5,14,13,3,128,128,1,11,15,13,6,131,10,14,7,10,15,2,130,
+ 10,13,128,5,15,4,130,3,15,10,14,12,131,2,13,15,12,1,130,1,14,12,8,15,
+ 6,5,10,128,6,15,2,128,7,31,8,128,5,15,10,6,10,31,3,129,8,13,14,12,
+ 6,11,13,1,27,10,11,25,139,129,10,13,129,2,15,7,129,8,15,2,129,11,14,130,
+ 14,11,130,15,10,130,15,10,130,14,11,130,12,13,130,8,15,2,129,3,15,7,130,10,
+ 13,128,128,11,12,130,5,15,4,129,1,15,10,130,12,13,130,10,15,1,129,9,15,2,
+ 129,9,15,2,129,10,15,1,129,12,13,129,1,15,9,129,5,15,4,129,27,129,2,1,
+ 13,1,3,5,12,14,12,7,5,12,14,12,6,2,1,13,1,3,152,129,7,12,131,7,
+ 12,129,17,7,13,17,9,63,14,2,4,9,13,20,129,7,12,135,128,14,5,2,15,1,
+ 4,12,128,65,9,47,12,2,36,3,142,131,1,15,8,129,3,1,128,130,9,13,131,14,
+ 8,130,5,15,2,130,11,12,130,1,15,6,130,7,15,1,130,12,11,130,3,15,5,130,
+ 8,14,131,128,3,12,14,13,7,128,1,14,12,6,9,15,5,4,15,4,129,13,9,4,
+ 15,3,129,13,10,4,15,3,129,13,10,4,15,3,129,13,10,3,15,4,129,13,9,1,
+ 14,12,6,9,15,5,128,3,12,14,13,7,128,2,10,15,10,128,5,10,14,10,130,12,
+ 10,130,12,10,130,12,10,130,12,10,130,12,10,130,12,10,130,12,10,128,128,5,13,15,
+ 12,5,128,3,15,11,6,11,15,2,6,15,2,128,3,15,5,131,9,15,1,130,5,15,
+ 7,130,4,15,10,130,3,14,11,130,2,13,14,6,21,3,5,79,8,5,79,18,21,7,
+ 15,13,1,129,2,29,2,130,13,15,10,2,130,20,28,132,5,15,2,6,15,2,128,6,
+ 15,18,15,11,6,29,129,5,13,15,12,3,128,129,3,15,6,132,11,13,132,3,15,6,
+ 132,10,13,128,5,15,2,128,3,15,7,2,6,15,4,128,7,79,14,128,2,36,8,15,
+ 6,132,5,15,3,132,5,15,2,128,5,79,1,5,15,7,37,128,5,15,3,1,130,5,
+ 15,12,15,14,6,128,5,15,11,5,11,15,2,1,2,129,3,15,5,3,10,3,128,4,
+ 15,5,1,14,12,6,12,14,1,128,3,12,15,12,4,128,128,6,13,14,12,5,128,3,
+ 15,11,6,12,15,1,5,15,3,128,2,6,1,5,15,12,15,14,6,128,5,15,11,5,
+ 11,15,2,5,15,4,128,4,15,5,4,15,4,128,4,15,5,1,14,12,6,12,14,1,
+ 128,4,12,15,12,4,128,10,79,2,10,11,21,11,15,1,2,1,129,14,10,131,5,15,
+ 4,131,10,13,131,1,15,8,131,7,15,2,131,13,11,131,3,15,5,130,128,5,12,14,
+ 12,4,128,2,15,10,6,11,15,1,3,15,7,2,8,15,2,128,10,47,8,128,1,14,
+ 11,5,11,14,1,5,15,3,128,4,15,4,6,15,4,128,4,15,4,2,14,12,6,12,
+ 14,1,128,4,13,15,12,4,128,128,7,13,15,11,3,128,4,15,10,6,12,13,128,7,
+ 15,1,128,6,15,2,6,15,6,2,10,15,3,128,11,31,13,15,3,129,19,5,15,3,
+ 4,14,3,128,5,15,3,2,15,12,6,13,14,1,128,5,13,15,12,4,128,133,7,15,
+ 1,129,1,3,140,7,15,1,129,1,3,129,128,11,12,129,12,14,1,140,9,10,129,11,
+ 7,129,13,3,128,131,1,7,129,2,9,14,13,3,10,15,12,6,128,9,15,8,130,2,
+ 9,15,13,7,1,129,1,8,30,131,1,6,8,63,14,1,51,2,8,63,14,1,51,2,
+ 139,5,3,131,8,15,11,5,130,3,10,15,13,6,130,4,30,128,5,11,15,12,5,8,
+ 15,10,3,129,4,2,131,128,7,13,14,11,2,128,5,15,9,6,13,12,128,8,14,129,
+ 8,15,131,2,13,12,130,2,29,3,130,10,14,2,131,23,132,3,2,132,12,11,130,141,
+ 7,13,31,12,3,131,11,14,8,5,6,11,15,3,129,8,12,1,131,10,11,128,1,14,
+ 3,2,12,14,13,4,3,14,128,4,12,128,9,8,2,15,3,1,15,128,6,10,128,13,
+ 2,128,15,1,2,14,128,5,11,128,13,4,5,15,2,8,9,128,2,15,2,6,14,12,
+ 9,14,11,1,129,9,13,5,18,5,1,131,1,9,47,13,3,133,1,4,2,132,130,13,
+ 15,4,132,3,15,14,10,132,8,13,7,14,132,13,8,2,15,4,130,3,15,4,128,13,
+ 9,130,8,14,129,8,14,130,13,79,4,128,3,15,7,35,14,9,128,7,15,1,130,10,
+ 14,128,1,63,12,4,128,1,15,10,5,6,12,14,17,15,7,129,4,15,3,1,15,7,
+ 1,2,9,13,17,79,6,128,1,15,9,20,10,15,2,1,15,7,129,3,15,5,1,15,
+ 10,5,6,11,15,2,1,63,12,5,128,128,2,10,30,10,2,129,29,23,14,13,128,3,
+ 15,5,129,5,15,3,4,15,4,132,4,15,4,132,4,15,4,130,1,128,3,15,5,129,
+ 5,15,3,128,29,23,14,13,129,2,11,30,10,2,128,1,63,12,4,128,1,15,10,5,
+ 6,12,15,2,1,15,7,129,3,15,5,1,15,7,129,2,15,6,1,15,7,129,2,15,
+ 6,1,15,7,129,2,15,6,1,15,7,129,3,15,5,1,15,10,5,6,12,15,2,1,
+ 63,12,4,128,1,95,2,1,15,10,53,128,1,15,7,132,1,15,7,33,129,1,63,10,
+ 129,1,15,9,20,2,129,1,15,7,132,1,15,10,53,128,1,95,2,1,95,17,15,10,
+ 53,128,1,15,7,132,1,15,7,33,129,1,63,10,129,1,15,9,20,2,129,1,15,7,
+ 132,1,15,7,132,1,15,7,132,128,2,10,30,10,2,129,13,14,7,6,29,128,3,15,
+ 5,129,4,13,3,4,15,4,128,33,128,4,15,4,1,47,3,4,15,4,128,4,7,15,
+ 19,15,5,129,5,15,2,128,13,14,7,6,13,11,129,2,11,30,10,1,128,1,15,7,
+ 129,1,15,6,1,15,7,129,1,15,6,1,15,7,129,1,15,6,1,15,7,17,2,15,
+ 6,1,95,6,1,15,9,20,5,15,6,1,15,7,129,1,15,6,1,15,7,129,1,15,
+ 6,1,15,7,129,1,15,6,1,15,7,1,15,7,1,15,7,1,15,7,1,15,7,1,
+ 15,7,1,15,7,1,15,7,1,15,7,132,13,9,133,13,9,133,13,9,133,13,9,133,
+ 13,9,128,9,10,130,13,9,128,10,13,130,14,9,128,6,15,10,6,11,15,4,129,7,
+ 13,15,13,6,129,1,15,7,129,6,15,4,1,15,7,128,4,15,7,128,1,15,7,3,
+ 14,10,129,1,15,8,13,12,1,129,1,47,13,1,129,1,15,13,3,14,9,129,1,15,
+ 7,128,7,15,4,128,1,15,7,129,12,13,17,15,7,129,3,15,8,1,15,7,132,1,
+ 15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,
+ 15,10,53,128,1,95,128,1,15,11,130,7,15,5,1,31,6,128,2,31,5,1,15,30,
+ 2,12,14,15,5,1,15,8,13,14,15,6,15,5,1,15,7,4,15,9,2,15,5,1,
+ 15,7,128,3,1,2,15,5,1,15,7,130,2,15,5,1,15,7,130,2,15,5,1,15,
+ 7,130,2,15,5,1,15,10,130,27,128,1,31,4,129,27,128,1,31,13,1,128,27,128,
+ 1,15,8,14,8,128,27,128,1,15,23,15,2,27,128,1,15,7,128,12,43,128,1,15,
+ 7,128,3,31,11,128,1,15,7,129,9,15,11,128,1,15,7,129,1,14,11,128,128,2,
+ 10,30,10,2,129,12,14,23,29,128,3,15,6,129,4,15,20,15,4,129,2,15,5,4,
+ 15,4,129,2,15,5,4,15,4,129,2,15,5,3,15,5,129,4,15,4,128,12,14,7,
+ 6,29,129,2,10,30,11,2,128,2,63,13,5,128,2,15,9,5,6,12,15,18,15,6,
+ 129,3,15,5,2,15,6,1,2,9,15,3,2,79,9,128,2,15,8,20,2,129,2,15,
+ 6,132,2,15,6,132,2,15,6,132,128,2,11,30,8,130,29,6,8,15,8,128,4,15,
+ 4,129,9,14,128,6,15,2,129,7,15,128,6,15,2,129,7,15,128,6,15,2,129,7,
+ 15,128,6,15,2,129,8,15,128,3,15,8,128,1,13,12,129,10,15,30,15,5,130,5,
+ 15,12,3,132,14,9,130,1,63,13,5,128,1,15,10,21,11,15,2,1,15,7,129,3,
+ 15,5,1,15,7,17,8,15,3,1,79,9,128,1,15,9,4,28,129,1,15,7,128,4,
+ 15,4,128,1,15,7,129,12,11,128,1,15,7,129,5,15,4,128,4,12,30,9,1,128,
+ 2,15,11,6,7,14,11,128,4,15,4,129,7,14,128,1,29,5,132,1,9,30,8,130,
+ 1,129,6,14,11,128,6,15,1,129,7,15,1,3,15,12,22,29,129,5,12,15,14,10,
+ 2,128,8,95,1,3,5,6,15,10,21,131,15,7,133,15,7,133,15,7,133,15,7,133,
+ 15,7,133,15,7,133,15,7,130,2,15,6,129,1,15,6,2,15,6,129,2,15,6,2,
+ 15,6,129,2,15,6,2,15,6,129,2,15,6,2,15,6,129,2,15,6,2,15,6,129,
+ 2,15,6,1,15,7,129,3,15,5,128,11,14,7,6,13,14,1,128,1,10,30,11,3,
+ 128,7,15,2,129,2,15,6,3,15,6,129,6,15,2,128,13,10,129,11,12,129,8,14,
+ 128,1,15,7,129,4,15,20,15,2,130,14,8,9,13,131,9,29,8,131,4,31,3,132,
+ 14,13,130,8,15,1,128,3,15,9,129,8,14,128,4,15,4,128,6,15,13,129,12,11,
+ 128,1,15,8,128,10,14,15,2,1,15,7,129,11,12,128,14,8,15,6,4,15,3,129,
+ 7,15,3,15,3,12,9,8,14,130,3,15,10,15,128,9,13,12,11,131,14,15,11,128,
+ 5,31,7,131,10,15,8,128,1,31,3,131,6,15,4,129,13,14,130,5,15,4,129,4,
+ 15,5,128,11,13,129,13,11,129,2,15,23,15,2,130,8,30,8,131,1,31,1,131,8,
+ 30,8,130,2,15,23,15,2,129,11,13,129,13,11,128,5,15,4,129,4,15,5,6,15,
+ 3,129,6,15,3,128,13,11,128,1,14,10,129,5,15,3,7,15,2,130,12,11,14,9,
+ 131,5,31,2,132,13,10,133,13,10,133,13,10,133,13,10,130,8,79,10,3,37,8,15,
+ 8,131,28,131,9,14,2,130,4,15,6,130,1,14,10,131,11,13,1,130,6,15,9,37,
+ 3,8,79,10,49,128,8,31,9,128,8,15,4,2,128,8,14,130,8,14,130,8,14,130,
+ 8,14,130,8,14,130,8,14,130,8,14,130,8,14,130,8,14,17,128,8,31,9,128,2,
+ 20,2,128,1,15,6,131,11,12,131,5,15,2,130,1,14,8,131,9,13,131,4,15,4,
+ 131,13,9,131,8,14,131,2,15,5,129,33,128,6,31,12,128,1,4,28,130,11,12,130,
+ 11,12,130,11,12,130,11,12,130,11,12,130,11,12,130,11,12,130,11,12,129,1,11,12,
+ 128,6,31,12,128,1,20,3,129,21,130,1,30,1,129,5,29,5,129,11,24,11,128,1,
+ 15,3,2,15,1,6,13,129,12,6,151,81,128,11,79,5,3,68,1,17,128,4,14,2,
+ 128,3,2,148,128,6,13,15,12,3,128,4,15,10,6,29,129,1,128,1,7,15,17,10,
+ 63,1,7,15,7,4,9,15,1,7,15,23,13,15,17,11,14,13,10,15,1,3,15,5,
+ 131,3,15,5,131,3,15,10,30,6,128,3,15,14,6,11,15,19,15,7,128,1,15,7,
+ 3,15,6,129,14,9,3,15,7,128,1,15,7,3,15,14,6,11,15,19,15,10,30,6,
+ 128,128,3,12,14,12,5,128,1,14,12,6,11,15,3,4,15,4,128,1,8,3,5,15,
+ 2,131,4,15,4,128,1,7,2,1,14,12,6,11,15,3,128,3,12,15,13,5,128,131,
+ 1,15,6,131,1,15,7,128,4,12,14,10,15,7,1,14,13,6,12,15,7,4,15,5,
+ 128,3,15,7,5,15,3,128,2,15,7,3,15,5,128,3,15,7,1,14,13,6,12,15,
+ 7,128,4,12,14,10,15,6,128,3,12,14,12,4,128,1,14,12,6,11,14,1,4,15,
+ 5,1,4,15,21,79,7,3,15,7,36,2,128,13,12,6,8,13,2,128,3,11,15,13,
+ 7,128,128,3,13,15,6,128,8,15,6,2,9,47,6,3,11,14,5,2,128,9,14,130,
+ 9,14,130,9,14,130,9,14,130,9,14,129,128,4,13,14,11,15,6,1,14,12,6,12,
+ 15,6,5,15,4,128,3,15,22,15,2,128,2,15,6,5,15,4,128,3,15,6,2,15,
+ 12,6,12,15,6,128,5,13,14,11,15,6,131,4,15,4,129,4,6,13,14,1,129,13,
+ 14,11,3,128,3,15,5,131,3,15,5,131,3,15,10,30,6,128,3,15,13,6,12,15,
+ 2,3,15,5,128,4,15,4,3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,
+ 5,128,3,15,5,3,15,5,128,3,15,5,2,14,7,128,4,1,2,15,6,2,15,6,
+ 2,15,6,2,15,6,2,15,6,2,15,6,2,15,6,128,2,14,6,129,4,1,128,2,
+ 15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,
+ 15,5,128,2,15,5,3,10,15,3,10,14,8,128,3,15,5,131,3,15,5,131,3,15,
+ 5,1,12,13,1,3,15,5,10,14,3,128,3,15,12,15,9,129,3,31,12,14,1,128,
+ 3,15,8,2,15,6,128,3,15,5,128,10,13,128,3,15,5,128,4,15,5,3,15,5,
+ 3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,
+ 3,15,10,13,14,6,7,14,13,5,128,3,15,12,6,12,15,11,6,29,128,3,15,5,
+ 128,5,15,3,128,7,15,1,3,15,5,128,5,15,3,128,7,15,1,3,15,5,128,5,
+ 15,3,128,7,15,1,3,15,5,128,5,15,3,128,7,15,1,3,15,5,128,5,15,2,
+ 128,7,15,1,3,15,10,30,6,128,3,15,13,6,12,15,2,3,15,5,128,4,15,4,
+ 3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,5,
+ 128,3,15,5,128,3,12,14,13,5,128,1,14,13,6,11,15,2,4,15,4,128,1,15,
+ 7,5,15,2,129,14,9,4,15,4,128,1,15,7,128,29,6,11,15,2,128,3,11,14,
+ 13,4,128,2,15,10,30,7,128,2,15,14,6,10,15,4,2,15,8,128,1,15,9,2,
+ 15,6,129,13,10,2,15,8,128,1,15,9,2,15,14,6,10,15,4,2,15,10,30,7,
+ 128,2,15,6,131,2,15,6,131,2,15,6,131,128,3,12,14,10,15,6,1,14,13,6,
+ 12,15,7,3,15,5,128,3,15,7,5,15,3,128,2,15,7,4,15,5,128,3,15,7,
+ 1,14,13,6,12,15,7,128,4,13,14,10,15,7,131,1,15,7,131,1,15,7,131,1,
+ 15,6,3,15,10,14,9,3,15,13,6,19,15,6,129,3,15,5,129,3,15,5,129,3,
+ 15,5,129,3,15,5,129,128,8,14,15,11,2,4,15,8,6,13,11,4,15,7,1,2,
+ 3,128,6,13,15,11,18,5,128,3,28,5,15,9,6,13,12,128,8,14,15,12,3,128,
+ 5,6,130,10,12,129,9,47,5,3,12,13,5,2,128,10,12,130,10,12,130,10,12,130,
+ 9,14,6,1,128,4,13,15,3,4,15,3,128,4,15,3,4,15,4,128,4,15,20,15,
+ 4,128,4,15,20,15,4,128,4,15,20,15,4,128,5,15,4,2,15,12,6,12,15,4,
+ 128,6,30,10,15,3,8,15,1,128,8,15,2,4,15,5,128,28,129,14,9,1,15,7,
+ 129,9,13,5,15,3,129,5,15,12,13,131,14,15,8,131,10,15,4,129,8,14,129,14,
+ 10,128,1,15,7,4,15,3,2,15,14,128,5,15,3,1,15,7,6,14,15,3,9,13,
+ 129,11,42,13,7,13,9,129,7,30,6,9,12,15,5,129,3,31,2,5,31,1,130,29,
+ 128,1,15,11,129,7,15,3,128,8,15,3,128,28,3,15,8,129,3,15,14,13,131,10,
+ 15,6,130,3,15,14,13,130,12,13,3,14,8,128,7,15,4,128,7,15,3,9,14,129,
+ 8,14,128,5,15,3,128,12,10,128,1,15,7,1,15,5,129,27,5,15,1,129,6,14,
+ 9,11,130,1,31,6,131,12,15,2,131,10,12,130,2,7,15,6,130,6,14,10,131,9,
+ 63,7,3,21,11,15,5,129,4,15,8,129,2,14,11,130,12,13,1,129,8,15,8,21,
+ 3,10,63,8,130,1,129,5,31,2,128,10,15,5,129,10,13,130,10,13,130,10,12,129,
+ 5,15,8,129,6,15,7,130,11,12,130,10,13,130,10,13,130,10,14,2,129,7,31,2,
+ 129,3,4,128,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,
+ 8,15,17,130,8,15,12,129,2,10,15,3,129,4,15,3,129,4,15,3,129,4,15,4,
+ 129,1,14,13,1,128,1,29,1,128,4,15,4,129,4,15,3,129,4,15,3,128,1,8,
+ 15,3,128,8,15,14,1,128,2,4,1,129,134,2,13,15,8,2,7,1,4,9,5,12,
+ 15,13,1,131,3,1,142,130,4,15,4,128,3,134,129,1,129,1,12,15,11,1,9,11,
+ 5,11,7,10,8,2,10,8,3,14,15,13,2,128,1,3,1,158,128,4,129,4,128,5,
+ 15,6,10,14,1,128,7,15,14,3,129,10,31,6,128,4,14,3,7,14,1,128,1,129,
+ 1,134,81,9,63,10,2,52,2,139,113,128,9,111,4,2,100,1,145,5,15,2,9,11,
+ 128,12,5,146,138,1,15,8,128,6,15,3,128,28,129,3,1,128,1,3,129,18,128,3,
+ 29,3,8,31,9,2,29,3,135,128,3,15,4,128,12,9,128,4,15,2,129,12,9,129,
+ 3,15,3,131,128,11,10,130,2,15,4,130,10,11,129,2,15,4,129,11,10,134,
+};
+static const struct fos_glyph xs_glyphs[] = {
+ { 0, 3, 0, 0, 0, 42 }, /* 0x20 */
+ { 0, 4, 9, 0, -9, 70 }, /* 0x21 */
+ { 25, 4, 9, 0, -9, 68 }, /* 0x22 */
+ { 37, 9, 9, 0, -9, 141 }, /* 0x23 */
+ { 96, 7, 12, 0, -11, 118 }, /* 0x24 */
+ { 162, 11, 9, 0, -9, 173 }, /* 0x25 */
+ { 226, 9, 9, 0, -9, 143 }, /* 0x26 */
+ { 292, 2, 9, 0, -9, 32 }, /* 0x27 */
+ { 297, 5, 12, -1, -11, 66 }, /* 0x28 */
+ { 338, 5, 12, 0, -11, 66 }, /* 0x29 */
+ { 382, 5, 9, 0, -9, 83 }, /* 0x2a */
+ { 403, 6, 7, 0, -7, 102 }, /* 0x2b */
+ { 426, 3, 3, 0, -2, 55 }, /* 0x2c */
+ { 435, 5, 6, 0, -6, 84 }, /* 0x2d */
+ { 443, 4, 3, 0, -2, 57 }, /* 0x2e */
+ { 451, 6, 9, 0, -9, 93 }, /* 0x2f */
+ { 483, 7, 9, 0, -9, 118 }, /* 0x30 */
+ { 541, 5, 9, 0, -9, 73 }, /* 0x31 */
+ { 572, 7, 9, 0, -9, 115 }, /* 0x32 */
+ { 619, 7, 9, 0, -9, 110 }, /* 0x33 */
+ { 661, 8, 9, 0, -9, 122 }, /* 0x34 */
+ { 706, 7, 9, 0, -9, 110 }, /* 0x35 */
+ { 760, 7, 9, 0, -9, 110 }, /* 0x36 */
+ { 823, 7, 9, 0, -9, 102 }, /* 0x37 */
+ { 860, 7, 9, 0, -9, 111 }, /* 0x38 */
+ { 921, 7, 9, 0, -9, 110 }, /* 0x39 */
+ { 981, 5, 7, 0, -7, 74 }, /* 0x3a */
+ { 996, 4, 8, 0, -7, 65 }, /* 0x3b */
+ { 1013, 6, 7, 0, -7, 102 }, /* 0x3c */
+ { 1044, 6, 6, 0, -6, 102 }, /* 0x3d */
+ { 1057, 6, 7, 0, -7, 102 }, /* 0x3e */
+ { 1087, 7, 9, 0, -9, 104 }, /* 0x3f */
+ { 1127, 11, 12, 0, -10, 171 }, /* 0x40 */
+ { 1222, 9, 9, 0, -9, 135 }, /* 0x41 */
+ { 1274, 8, 9, 0, -9, 129 }, /* 0x42 */
+ { 1331, 8, 9, 0, -9, 126 }, /* 0x43 */
+ { 1383, 8, 9, 0, -9, 129 }, /* 0x44 */
+ { 1444, 8, 9, 0, -9, 123 }, /* 0x45 */
+ { 1483, 8, 9, 0, -9, 117 }, /* 0x46 */
+ { 1521, 8, 9, 0, -9, 128 }, /* 0x47 */
+ { 1581, 8, 9, 0, -9, 132 }, /* 0x48 */
+ { 1640, 3, 9, 0, -9, 54 }, /* 0x49 */
+ { 1667, 8, 9, 0, -9, 121 }, /* 0x4a */
+ { 1709, 8, 9, 0, -9, 129 }, /* 0x4b */
+ { 1771, 8, 9, 0, -9, 119 }, /* 0x4c */
+ { 1807, 9, 9, 0, -9, 149 }, /* 0x4d */
+ { 1877, 9, 9, 0, -9, 139 }, /* 0x4e */
+ { 1942, 8, 9, 0, -9, 129 }, /* 0x4f */
+ { 2001, 8, 9, 0, -9, 124 }, /* 0x50 */
+ { 2050, 8, 11, 0, -9, 122 }, /* 0x51 */
+ { 2119, 8, 9, 0, -9, 128 }, /* 0x52 */
+ { 2177, 8, 9, 0, -9, 123 }, /* 0x53 */
+ { 2234, 8, 9, 0, -9, 120 }, /* 0x54 */
+ { 2265, 8, 9, 0, -9, 132 }, /* 0x55 */
+ { 2329, 8, 9, 0, -9, 127 }, /* 0x56 */
+ { 2379, 12, 9, 0, -9, 183 }, /* 0x57 */
+ { 2467, 8, 9, 0, -9, 128 }, /* 0x58 */
+ { 2518, 8, 9, 0, -9, 125 }, /* 0x59 */
+ { 2561, 7, 9, 0, -9, 115 }, /* 0x5a */
+ { 2596, 5, 14, 0, -11, 84 }, /* 0x5b */
+ { 2643, 6, 9, 0, -9, 93 }, /* 0x5c */
+ { 2674, 5, 14, 0, -11, 84 }, /* 0x5d */
+ { 2720, 6, 10, 0, -10, 97 }, /* 0x5e */
+ { 2747, 7, 3, 0, -2, 106 }, /* 0x5f */
+ { 2755, 3, 10, 0, -10, 46 }, /* 0x60 */
+ { 2764, 7, 7, 0, -7, 109 }, /* 0x61 */
+ { 2805, 7, 9, 0, -9, 116 }, /* 0x62 */
+ { 2857, 7, 7, 0, -7, 110 }, /* 0x63 */
+ { 2903, 7, 9, 0, -9, 116 }, /* 0x64 */
+ { 2960, 7, 7, 0, -7, 113 }, /* 0x65 */
+ { 3002, 5, 9, 0, -9, 78 }, /* 0x66 */
+ { 3036, 7, 10, 0, -7, 114 }, /* 0x67 */
+ { 3100, 7, 9, 0, -9, 113 }, /* 0x68 */
+ { 3156, 3, 9, 0, -9, 53 }, /* 0x69 */
+ { 3183, 4, 12, -1, -9, 52 }, /* 0x6a */
+ { 3230, 7, 9, 0, -9, 109 }, /* 0x6b */
+ { 3285, 3, 9, 0, -9, 50 }, /* 0x6c */
+ { 3312, 11, 7, 0, -7, 172 }, /* 0x6d */
+ { 3388, 7, 7, 0, -7, 113 }, /* 0x6e */
+ { 3436, 7, 7, 0, -7, 116 }, /* 0x6f */
+ { 3483, 7, 10, 0, -7, 117 }, /* 0x70 */
+ { 3541, 7, 10, 0, -7, 117 }, /* 0x71 */
+ { 3602, 5, 7, 0, -7, 78 }, /* 0x72 */
+ { 3631, 6, 7, 0, -7, 103 }, /* 0x73 */
+ { 3671, 5, 9, 0, -9, 78 }, /* 0x74 */
+ { 3705, 7, 7, 0, -7, 113 }, /* 0x75 */
+ { 3750, 7, 7, 0, -7, 105 }, /* 0x76 */
+ { 3788, 10, 7, 0, -7, 158 }, /* 0x77 */
+ { 3845, 7, 7, 0, -7, 107 }, /* 0x78 */
+ { 3885, 7, 10, 0, -7, 102 }, /* 0x79 */
+ { 3935, 6, 7, 0, -7, 95 }, /* 0x7a */
+ { 3964, 5, 14, 0, -11, 73 }, /* 0x7b */
+ { 4012, 2, 11, 0, -10, 40 }, /* 0x7c */
+ { 4034, 5, 14, 0, -11, 73 }, /* 0x7d */
+ { 4092, 7, 6, 0, -6, 109 }, /* 0x7e */
+ { 4111, 3, 5, 0, -5, 47 }, /* 0x80 */
+ { 4118, 5, 12, 0, -12, 79 }, /* 0x81 */
+ { 4146, 6, 7, 0, -7, 91 }, /* 0x82 */
+ { 4178, 6, 5, 0, -5, 97 }, /* 0x83 */
+ { 4186, 9, 5, 0, -5, 139 }, /* 0x84 */
+ { 4195, 3, 9, 0, -9, 38 }, /* 0x85 */
+ { 4204, 11, 3, 0, -2, 173 }, /* 0x86 */
+ { 4223, 4, 5, 0, -5, 65 }, /* 0x87 */
+ { 4233, 4, 6, 0, -6, 72 }, /* 0x88 */
+ { 4252, 5, 6, 0, -6, 77 }, /* 0x89 */
+};
+static const uint8_t xs_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern xs_kern[] = {
+ {39,45,-10},{39,52,-4},{39,65,-16},{39,74,-10},{39,99,-10},{39,100,-10},{39,101,-10},{39,103,-7},
+ {39,111,-10},{39,113,-7},{39,115,-5},{44,48,-6},{44,84,-12},{44,86,-6},{44,87,-6},{44,89,-12},
+ {44,118,-8},{44,119,-8},{44,121,-8},{45,39,-5},{45,45,-29},{45,55,-13},{45,84,-7},{45,118,-5},
+ {45,119,-5},{45,120,-5},{45,121,-5},{45,133,-5},{46,48,-6},{46,84,-12},{46,86,-6},{46,87,-6},
+ {46,89,-12},{46,118,-8},{46,119,-8},{46,121,-8},{48,49,-4},{52,39,-6},{52,49,-20},{52,55,-12},
+ {53,49,-4},{55,44,-12},{55,46,-12},{56,49,-4},{57,49,-4},{65,39,-19},{65,67,-4},{65,71,-4},
+ {65,79,-4},{65,81,-4},{65,83,-9},{65,84,-16},{65,86,-6},{65,87,-6},{65,89,-17},{65,102,-5},
+ {65,103,-4},{65,113,-4},{65,116,-5},{65,118,-9},{65,119,-9},{65,121,-9},{65,133,-14},{66,65,-7},
+ {66,86,-5},{66,87,-5},{66,88,-5},{66,89,-7},{67,89,-5},{68,65,-7},{68,86,-5},{68,87,-5},
+ {68,88,-5},{68,89,-7},{70,44,-17},{70,45,-11},{70,46,-17},{70,65,-14},{70,74,-11},{70,97,-9},
+ {70,99,-11},{70,100,-11},{70,101,-11},{70,103,-7},{70,109,-5},{70,110,-5},{70,111,-11},{70,112,-5},
+ {70,113,-7},{70,114,-5},{70,115,-9},{70,117,-6},{70,118,-10},{70,119,-10},{70,120,-9},{70,121,-10},
+ {70,122,-5},{71,89,-5},{75,45,-6},{75,65,4},{75,67,-5},{75,71,-5},{75,74,-4},{75,79,-5},
+ {75,81,-5},{75,83,-4},{75,99,-6},{75,100,-6},{75,101,-6},{75,103,-5},{75,111,-6},{75,113,-5},
+ {75,118,-8},{75,119,-8},{75,121,-8},{76,39,-16},{76,65,5},{76,84,-18},{76,86,-8},{76,87,-8},
+ {76,89,-9},{76,118,-5},{76,119,-5},{76,121,-5},{76,133,-10},{79,89,-5},{80,44,-5},{80,45,-5},
+ {80,46,-5},{80,65,-9},{80,74,-5},{80,88,-6},{80,89,-6},{80,99,-5},{80,100,-5},{80,101,-5},
+ {80,111,-5},{81,65,-5},{81,86,-6},{81,87,-6},{81,88,-6},{81,89,-10},{82,65,5},{82,86,-4},
+ {82,87,-4},{82,89,-5},{83,88,-7},{83,89,-5},{84,44,-12},{84,45,-16},{84,46,-12},{84,65,-13},
+ {84,67,-7},{84,71,-7},{84,74,-8},{84,79,-7},{84,81,-7},{84,97,-6},{84,99,-16},{84,100,-16},
+ {84,101,-16},{84,103,-13},{84,109,-12},{84,110,-12},{84,111,-16},{84,112,-12},{84,113,-13},{84,114,-12},
+ {84,115,-12},{84,117,-10},{84,118,-10},{84,119,-10},{84,120,-11},{84,121,-10},{86,44,-12},{86,45,-12},
+ {86,46,-12},{86,65,-20},{86,67,-6},{86,71,-6},{86,74,-8},{86,75,-4},{86,79,-6},{86,81,-6},
+ {86,83,-4},{86,97,-12},{86,99,-12},{86,100,-12},{86,101,-12},{86,103,-11},{86,111,-12},{86,113,-11},
+ {86,115,-8},{87,44,-12},{87,45,-12},{87,46,-12},{87,65,-20},{87,67,-6},{87,71,-6},{87,74,-8},
+ {87,75,-4},{87,79,-6},{87,81,-6},{87,83,-4},{87,97,-12},{87,99,-12},{87,100,-12},{87,101,-12},
+ {87,103,-11},{87,111,-12},{87,113,-11},{87,115,-8},{88,45,-6},{88,67,-5},{88,71,-5},{88,79,-5},
+ {88,81,-5},{88,83,-5},{88,99,-6},{88,100,-6},{88,101,-6},{88,103,-7},{88,111,-6},{88,113,-7},
+ {88,118,-6},{88,119,-6},{88,121,-6},{89,44,-19},{89,45,-15},{89,46,-19},{89,65,-23},{89,67,-7},
+ {89,71,-7},{89,74,-11},{89,79,-7},{89,81,-7},{89,83,-5},{89,97,-12},{89,99,-15},{89,100,-15},
+ {89,101,-15},{89,102,-8},{89,103,-17},{89,109,-11},{89,110,-11},{89,111,-15},{89,112,-11},{89,113,-17},
+ {89,114,-11},{89,115,-9},{89,116,-8},{89,117,-8},{89,118,-7},{89,119,-7},{89,120,-8},{89,121,-7},
+ {89,122,-5},{97,39,-5},{97,84,-6},{97,89,-7},{97,133,-4},{98,39,-8},{98,118,-4},{98,119,-4},
+ {98,121,-4},{99,39,-5},{99,44,-5},{99,46,-5},{99,120,-4},{99,133,-4},{101,39,-7},{101,44,-4},
+ {101,46,-4},{101,118,-5},{101,119,-5},{101,120,-4},{101,121,-5},{101,133,-5},{102,44,-11},{102,45,-7},
+ {102,46,-11},{102,99,-7},{102,100,-7},{102,101,-7},{102,103,-6},{102,111,-7},{102,113,-6},{104,39,-8},
+ {104,118,-4},{104,119,-4},{104,121,-4},{107,45,-7},{107,97,-4},{107,99,-7},{107,100,-7},{107,101,-7},
+ {107,103,-5},{107,111,-7},{107,113,-5},{109,39,-8},{109,118,-4},{109,119,-4},{109,121,-4},{110,39,-8},
+ {110,118,-4},{110,119,-4},{110,121,-4},{111,39,-5},{111,55,-13},{111,84,-7},{111,118,-5},{111,119,-5},
+ {111,120,-5},{111,121,-5},{111,133,-5},{112,39,-8},{112,118,-4},{112,119,-4},{112,121,-4},{114,39,5},
+ {114,44,-8},{114,46,-8},{114,103,-4},{114,113,-4},{114,118,4},{114,119,4},{114,121,4},{114,133,10},
+ {115,39,-4},{115,118,-7},{115,119,-7},{115,121,-7},{115,133,-5},{118,44,-8},{118,45,-6},{118,46,-8},
+ {118,97,-5},{118,99,-6},{118,100,-6},{118,101,-6},{118,103,-6},{118,111,-6},{118,113,-6},{118,115,-7},
+ {118,133,8},{119,44,-8},{119,45,-6},{119,46,-8},{119,97,-5},{119,99,-6},{119,100,-6},{119,101,-6},
+ {119,103,-6},{119,111,-6},{119,113,-6},{119,115,-7},{119,133,8},{120,45,-6},{120,99,-6},{120,100,-6},
+ {120,101,-6},{120,103,-5},{120,111,-6},{120,113,-5},{121,44,-8},{121,45,-6},{121,46,-8},{121,97,-5},
+ {121,99,-6},{121,100,-6},{121,101,-6},{121,103,-6},{121,111,-6},{121,113,-6},{121,115,-7},{121,133,8},
+ {133,45,-17},{133,65,-14},{133,97,-4},{133,99,-17},{133,100,-17},{133,101,-17},{133,103,-16},{133,111,-17},
+ {133,113,-16},{133,115,-14},{133,118,-4},{133,119,-4},{133,121,-4},
+};
+const struct fos_font fos_font_xs_data = { xs_bits, xs_glyphs, xs_lut, xs_kern, 389, 13, 3 };
+
+static const uint8_t sm_bits[] = {
+ 128,2,15,6,129,1,15,6,129,1,15,5,129,1,15,5,129,1,15,5,130,15,5,130,
+ 15,4,139,4,14,6,129,4,14,6,128,8,13,1,15,5,8,12,128,15,5,7,11,128,
+ 14,3,167,130,10,13,129,12,11,132,13,10,129,15,8,130,6,111,10,129,2,7,15,7,
+ 4,8,15,6,3,130,6,15,3,128,7,15,1,130,1,8,15,2,1,10,14,1,130,127,
+ 2,129,3,13,12,20,14,10,3,131,14,9,128,1,15,7,131,2,15,6,128,3,15,4,
+ 130,130,3,13,1,133,6,15,4,131,4,14,47,13,3,129,13,12,2,1,4,29,128,1,
+ 15,7,130,6,15,1,128,28,2,129,1,2,129,1,11,15,10,4,133,3,10,15,11,2,
+ 129,1,130,2,11,13,128,3,15,3,130,4,15,3,1,15,10,1,129,9,15,1,128,7,
+ 31,13,14,15,7,130,3,8,15,9,3,132,2,15,3,130,129,9,14,12,2,129,1,14,
+ 2,130,7,13,5,9,12,129,9,8,131,10,5,129,14,1,3,13,1,131,8,10,2,5,
+ 14,128,11,6,132,1,12,31,20,12,135,3,1,128,13,4,137,6,10,128,9,15,14,3,
+ 132,1,14,2,6,13,5,7,14,132,8,9,128,8,7,129,13,2,130,2,14,1,128,5,
+ 13,5,8,13,131,10,6,130,8,14,13,3,128,129,5,13,15,13,5,132,3,15,11,5,
+ 10,15,3,131,6,15,3,128,1,15,7,131,2,15,8,128,7,15,4,132,7,15,11,15,
+ 8,133,5,31,8,133,7,15,9,11,14,3,128,5,2,128,1,15,9,128,1,11,14,6,
+ 15,6,128,3,15,5,129,1,13,15,10,129,1,14,13,22,10,31,11,130,3,11,30,12,
+ 5,3,14,9,128,8,14,8,13,7,12,143,129,6,15,2,129,1,14,10,130,6,15,5,
+ 130,10,15,1,130,29,131,15,11,131,15,11,131,15,11,131,29,131,10,15,1,130,6,15,
+ 5,130,1,14,10,131,6,15,2,128,128,7,14,2,129,1,14,10,130,10,15,1,129,6,
+ 15,5,129,3,15,8,129,1,15,10,130,15,11,129,1,15,10,129,3,15,8,129,6,15,
+ 5,129,10,15,1,128,1,14,9,129,7,14,2,128,1,128,4,9,128,1,5,13,9,11,
+ 26,128,4,31,9,128,5,13,9,27,10,1,128,4,9,128,1,163,130,10,9,133,11,9,
+ 131,17,11,10,17,128,6,95,5,1,20,12,11,20,1,130,11,9,133,10,9,138,128,7,
+ 13,129,10,9,129,13,5,129,15,1,128,128,65,6,63,12,1,52,3,145,128,9,13,1,
+ 128,10,13,1,131,13,9,131,4,15,4,131,9,14,132,14,9,131,5,15,3,131,10,13,
+ 131,1,14,8,131,6,15,3,131,11,12,131,1,15,7,131,6,15,2,131,129,7,13,14,
+ 13,7,130,7,15,9,5,8,15,8,129,13,10,130,9,14,129,15,8,130,7,15,1,128,
+ 15,8,130,7,15,1,128,15,8,130,7,15,1,128,15,8,130,7,15,1,128,15,8,130,
+ 7,15,1,128,13,10,130,9,14,129,7,15,8,5,8,15,8,130,7,13,14,13,7,129,
+ 128,5,12,15,5,128,3,15,13,15,5,129,2,3,15,5,130,3,15,5,130,3,15,5,
+ 130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,
+ 128,128,1,9,30,12,4,130,12,14,7,5,11,15,3,128,2,15,7,129,1,15,8,128,
+ 1,8,3,129,2,15,7,133,9,15,2,132,6,15,7,132,4,15,10,132,2,14,12,1,
+ 131,1,29,1,132,12,15,7,52,128,2,95,13,128,2,95,5,128,36,6,14,15,3,130,
+ 1,12,15,5,130,1,11,15,5,131,5,31,11,3,131,3,2,11,14,1,132,3,15,5,
+ 2,8,2,129,1,15,7,3,15,6,129,4,15,4,128,11,14,22,29,1,128,1,9,30,
+ 11,2,128,130,4,15,5,133,11,13,133,3,15,7,133,10,14,1,132,2,15,8,128,3,
+ 15,4,129,8,15,2,128,3,15,5,128,1,14,11,17,4,15,6,128,5,111,3,1,52,
+ 6,15,7,1,132,3,15,5,133,3,15,5,128,1,95,3,1,15,9,52,17,15,7,132,
+ 1,15,7,132,1,15,11,13,15,13,6,128,1,15,14,6,4,10,15,4,128,6,3,129,
+ 1,15,8,133,14,9,128,14,9,129,1,15,8,128,9,15,7,5,12,15,2,129,8,13,
+ 14,12,4,128,128,1,9,14,15,12,4,129,11,14,7,5,12,15,2,1,15,8,129,3,
+ 15,6,1,15,7,132,1,15,10,13,15,14,6,128,1,31,7,5,11,15,3,1,15,9,
+ 129,1,15,8,1,15,7,130,14,9,128,14,10,129,1,15,8,128,9,15,8,5,11,15,
+ 2,129,8,13,15,12,4,128,7,95,6,8,13,36,9,15,4,1,2,130,11,14,132,2,
+ 15,8,132,7,15,2,132,13,12,132,4,15,6,132,9,15,1,131,1,14,10,132,6,15,
+ 4,132,11,13,131,129,8,30,11,2,129,8,15,8,6,29,1,128,14,10,129,4,15,5,
+ 128,15,9,129,2,15,6,128,10,14,4,2,10,15,2,128,1,14,47,7,129,11,14,6,
+ 4,10,15,18,15,7,129,1,15,8,2,15,7,129,1,15,8,128,12,14,7,5,11,15,
+ 3,128,1,10,14,15,12,5,128,128,1,9,30,11,2,129,11,15,7,6,13,14,1,2,
+ 15,7,129,4,15,5,4,15,4,129,1,15,7,3,15,6,129,3,15,7,128,29,4,2,
+ 11,15,7,128,3,14,31,11,15,7,130,3,2,1,15,7,128,13,8,129,2,15,6,128,
+ 11,14,7,5,12,14,2,128,1,10,30,12,4,128,128,2,14,8,130,2,14,8,148,2,
+ 14,8,130,2,14,8,129,128,5,14,6,129,7,15,8,130,1,140,2,15,3,129,4,15,
+ 130,6,12,130,8,9,129,140,4,11,5,130,5,12,15,11,2,1,7,13,15,9,3,129,
+ 7,15,10,1,131,3,12,15,11,4,132,3,10,15,13,6,1,131,2,9,15,5,133,1,
+ 2,6,95,5,1,83,1,143,6,95,5,1,83,1,143,135,6,11,4,132,3,12,15,12,
+ 5,132,3,10,15,13,6,1,131,2,11,15,5,130,5,11,15,11,2,1,7,13,15,10,
+ 3,129,7,14,8,2,131,2,1,133,128,3,11,30,9,1,128,1,14,12,5,7,14,11,
+ 128,6,15,3,129,8,15,1,2,6,130,9,14,132,8,15,8,131,9,15,7,131,2,15,
+ 8,132,2,12,4,140,4,14,5,132,4,14,5,130,144,7,12,31,14,9,2,131,2,29,
+ 8,5,4,6,12,14,3,129,1,13,9,1,130,1,128,8,12,129,8,11,128,3,13,15,
+ 10,13,129,14,2,128,13,4,128,12,10,4,27,129,13,4,1,15,128,1,15,1,128,7,
+ 9,128,1,14,18,15,128,2,15,19,13,10,2,9,13,129,15,2,128,11,31,7,14,15,
+ 14,3,129,26,129,18,128,1,3,1,130,2,14,11,4,1,2,4,8,133,2,11,47,14,
+ 8,135,1,19,133,130,1,31,2,133,6,31,7,133,11,12,11,12,132,1,15,23,15,2,
+ 131,6,15,3,2,15,7,131,11,13,129,28,130,1,15,8,129,8,15,2,129,6,15,4,
+ 129,3,15,7,129,11,95,12,128,1,15,10,51,9,15,2,5,15,4,131,3,15,6,128,
+ 10,63,13,7,130,10,13,20,5,10,15,7,129,10,13,131,12,11,129,10,13,131,27,129,
+ 10,13,33,6,15,4,129,10,79,10,130,10,13,36,8,15,9,129,10,13,131,10,14,129,
+ 10,13,131,10,13,129,10,13,20,5,8,15,8,129,10,63,13,7,129,129,5,12,30,11,
+ 3,130,5,15,11,5,6,12,15,3,129,28,130,1,14,10,129,15,8,131,23,129,15,8,
+ 135,15,8,135,15,8,135,15,8,131,23,129,28,130,1,14,10,129,5,15,11,5,6,12,
+ 15,3,130,5,12,30,11,3,129,128,10,63,12,6,130,10,13,20,5,9,15,7,129,10,
+ 13,131,11,13,129,10,13,131,8,15,129,10,13,131,8,15,129,10,13,131,8,15,129,10,
+ 13,131,8,15,129,10,13,131,8,15,129,10,13,131,11,13,129,10,13,20,5,9,15,7,
+ 129,10,63,12,6,129,128,10,95,11,129,10,13,68,3,129,10,13,135,10,13,135,10,13,
+ 49,131,10,63,14,131,10,13,36,3,131,10,13,135,10,13,135,10,13,68,3,129,10,95,
+ 11,128,128,10,95,11,128,10,13,68,3,128,10,13,134,10,13,134,10,13,49,130,10,63,
+ 14,130,10,13,36,3,130,10,13,134,10,13,134,10,13,134,10,12,133,129,5,12,30,11,
+ 4,130,5,15,11,5,6,12,15,4,129,28,130,1,14,10,129,15,9,131,5,6,129,15,
+ 8,129,49,129,15,8,128,2,47,12,129,15,8,129,3,4,28,129,15,9,131,11,12,129,
+ 28,130,1,14,9,129,5,15,11,5,6,12,14,3,130,5,12,30,11,3,129,128,10,12,
+ 131,7,15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,
+ 1,128,10,13,49,8,15,1,128,10,111,1,128,10,13,52,9,15,1,128,10,13,131,7,
+ 15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,1,128,10,12,131,7,15,1,128,
+ 10,12,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,
+ 10,13,129,10,13,129,10,12,128,133,8,14,134,9,14,134,9,14,134,9,14,134,9,14,
+ 134,9,14,128,5,8,131,9,14,128,9,14,131,9,14,128,7,15,2,130,28,128,2,14,
+ 13,6,5,10,15,6,129,2,10,30,12,5,129,128,10,12,130,1,12,13,1,128,10,13,
+ 130,11,14,2,129,10,13,129,9,15,4,130,10,13,128,8,15,6,131,10,13,6,15,9,
+ 132,10,14,15,14,12,132,10,15,9,4,15,8,131,10,13,129,8,15,3,130,10,13,130,
+ 29,1,129,10,13,130,3,15,8,129,10,12,131,7,15,4,128,10,12,134,10,13,134,10,
+ 13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,69,3,
+ 128,10,95,9,128,10,15,3,131,11,15,2,128,10,15,12,130,6,31,2,128,10,31,8,
+ 128,2,14,31,2,128,10,13,9,15,3,11,14,8,15,2,128,10,13,1,13,14,15,5,
+ 6,15,2,128,10,13,128,4,15,10,128,6,15,2,128,10,13,129,3,1,128,6,15,2,
+ 128,10,13,132,6,15,2,128,10,13,132,6,15,2,128,10,13,132,6,15,2,128,10,12,
+ 132,6,15,2,128,10,14,2,130,1,15,6,129,10,15,11,130,1,15,7,129,10,31,5,
+ 129,1,15,7,129,10,12,11,13,1,128,1,15,7,129,10,12,2,15,8,128,1,15,7,
+ 129,10,13,128,8,15,3,1,15,7,129,10,13,129,13,12,1,15,7,129,10,13,129,4,
+ 15,8,15,7,129,10,13,130,9,31,7,129,10,13,130,1,14,15,7,129,10,12,131,5,
+ 15,6,128,129,4,11,30,11,3,130,4,15,11,22,12,15,3,129,12,13,130,1,13,11,
+ 129,14,9,131,10,13,129,15,8,131,9,14,129,15,8,131,9,14,129,15,8,131,9,14,
+ 129,14,9,131,10,13,129,12,13,130,1,13,11,129,4,15,11,22,12,15,3,130,4,11,
+ 30,11,3,129,128,12,63,13,8,129,28,20,5,9,15,8,128,12,11,131,11,13,128,12,
+ 11,131,10,14,128,28,33,5,15,10,128,12,79,11,1,128,28,20,3,2,130,12,11,134,
+ 12,11,134,12,11,134,12,11,133,129,6,12,15,13,9,1,129,7,15,9,5,7,14,11,
+ 129,14,10,130,5,15,4,2,15,6,130,1,15,7,3,15,6,130,1,15,7,3,15,6,
+ 130,1,15,7,3,15,6,130,1,15,7,2,15,6,130,1,15,7,1,15,8,130,3,15,
+ 5,128,10,14,5,1,3,12,14,1,128,1,11,47,13,3,131,3,15,8,133,1,13,5,
+ 130,128,10,63,14,8,130,10,13,20,5,8,15,8,129,10,13,131,10,13,129,10,13,131,
+ 9,14,129,10,13,33,5,14,10,129,10,79,11,1,129,10,13,20,10,14,131,10,13,129,
+ 2,15,6,130,10,13,130,10,13,130,10,13,130,2,15,6,129,10,12,131,10,13,128,128,
+ 1,8,13,15,14,10,2,129,10,14,7,5,7,13,14,1,128,15,8,130,3,15,7,128,
+ 14,10,131,7,4,128,5,15,12,6,1,132,3,10,15,14,9,1,132,1,7,30,18,9,
+ 2,130,2,15,8,3,15,6,130,1,14,9,128,12,15,8,5,6,11,15,4,128,1,8,
+ 13,15,14,11,4,128,6,111,9,2,20,7,15,8,20,2,130,4,15,4,133,4,15,4,
+ 133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,
+ 133,3,15,4,130,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,12,11,131,7,
+ 15,1,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,
+ 12,11,131,7,15,1,128,12,11,131,8,15,1,128,9,14,1,130,12,13,129,3,14,12,
+ 6,5,10,15,6,130,3,11,30,12,5,129,5,15,4,131,9,14,128,1,15,8,131,13,
+ 10,129,11,13,130,3,15,5,129,6,15,2,129,8,15,1,129,1,15,7,129,12,10,131,
+ 28,128,2,15,5,131,7,15,1,6,15,1,131,2,15,6,27,133,12,11,15,6,133,7,
+ 31,1,133,2,15,11,131,7,15,2,130,29,130,1,15,8,3,15,6,129,2,31,3,129,
+ 4,15,4,128,14,10,129,6,31,7,129,8,14,129,10,14,129,10,28,11,129,12,11,129,
+ 6,15,3,128,14,24,14,128,1,15,7,129,1,15,7,3,15,20,15,4,5,15,2,130,
+ 12,11,6,15,1,128,15,8,9,13,131,8,14,11,12,129,11,12,13,9,131,4,31,8,
+ 129,7,31,5,132,14,15,4,129,3,31,1,132,10,15,1,130,14,12,130,3,15,6,131,
+ 12,13,129,9,14,1,129,6,15,4,129,1,14,10,128,1,14,10,131,6,15,4,9,14,
+ 2,132,11,13,15,7,133,4,15,14,134,10,14,15,5,132,5,15,5,10,14,1,130,1,
+ 13,11,128,2,14,9,130,9,14,2,129,6,15,4,128,3,15,7,131,12,13,128,4,15,
+ 6,130,1,14,9,128,11,13,130,9,15,2,128,3,15,7,128,2,15,8,130,10,14,1,
+ 10,14,1,130,2,15,10,15,7,132,8,15,13,133,2,15,7,133,1,15,7,133,1,15,
+ 7,133,1,15,7,133,1,15,6,130,5,111,17,52,5,14,13,133,8,15,4,132,3,15,
+ 9,133,12,13,1,132,8,15,4,132,3,15,8,133,29,1,132,8,15,3,132,3,15,11,
+ 68,128,5,111,1,128,33,129,7,47,3,128,7,15,20,1,128,7,15,1,130,7,15,1,
+ 130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,
+ 130,7,15,1,130,7,15,1,130,7,15,2,1,129,7,47,3,128,1,36,1,128,128,12,
+ 11,132,7,15,1,131,2,15,6,132,11,12,132,6,15,2,131,1,15,7,132,11,13,132,
+ 5,15,3,131,1,14,8,132,10,13,132,4,15,3,129,49,129,14,31,11,129,3,4,13,
+ 12,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,129,17,28,
+ 129,14,31,12,129,3,20,2,129,3,15,8,131,9,13,14,130,1,14,4,14,5,129,7,
+ 13,128,8,11,129,13,7,128,2,15,2,4,15,1,129,11,8,162,128,81,128,9,95,8,
+ 2,84,2,4,14,2,128,9,10,154,128,2,10,30,11,3,129,13,14,6,5,12,14,1,
+ 128,4,3,128,1,4,15,4,128,4,12,63,5,2,15,12,5,4,6,15,21,15,3,129,
+ 5,15,5,3,15,10,5,7,14,15,5,128,6,13,14,12,7,15,4,128,13,10,134,13,
+ 10,134,13,10,134,13,11,10,14,13,7,130,13,15,10,5,10,15,6,129,13,14,130,13,
+ 12,129,13,11,130,10,14,129,13,11,130,10,14,129,13,14,130,13,11,129,13,15,10,5,
+ 10,15,5,129,13,11,10,14,13,6,129,129,7,13,15,12,5,129,8,15,8,5,10,15,
+ 5,128,14,9,130,11,8,1,15,7,132,1,15,7,133,14,10,130,11,7,128,8,15,8,
+ 5,10,15,5,129,7,13,15,12,5,128,133,12,11,134,12,11,134,12,11,130,8,30,9,
+ 13,11,129,8,15,9,5,12,15,11,129,14,11,129,2,15,11,128,1,15,8,130,14,11,
+ 128,1,15,7,130,14,11,129,14,11,129,1,15,11,129,7,15,9,5,12,15,11,130,8,
+ 30,9,13,11,128,129,8,13,14,13,6,130,8,14,7,5,10,15,4,129,14,9,33,13,
+ 9,128,1,95,11,128,1,15,9,52,2,129,14,10,130,3,130,7,15,9,5,8,15,6,
+ 130,7,13,15,13,7,129,129,7,13,15,4,128,1,15,12,5,1,128,3,15,5,129,7,
+ 63,3,2,7,15,8,4,1,128,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,
+ 130,3,15,5,130,3,15,5,129,128,1,9,30,9,13,10,129,10,15,8,5,11,15,10,
+ 128,1,15,10,129,1,15,10,128,2,15,6,130,13,10,128,2,15,6,130,13,10,128,1,
+ 15,9,129,1,15,10,129,10,15,8,5,11,15,10,129,1,9,30,9,14,10,133,1,15,
+ 8,130,1,5,6,12,15,3,130,4,15,13,10,3,129,128,13,10,134,13,10,134,13,10,
+ 134,13,11,10,14,13,7,130,13,15,9,5,11,15,4,129,13,12,129,1,15,8,129,13,
+ 10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,
+ 10,130,14,9,128,128,11,13,129,11,12,133,11,12,129,11,12,129,11,12,129,11,12,129,
+ 11,12,129,11,12,129,11,12,129,11,12,128,129,13,11,130,12,11,135,12,10,130,12,11,
+ 130,12,11,130,12,11,130,12,11,130,12,11,130,12,11,130,12,11,130,13,10,128,3,8,
+ 15,7,128,10,14,9,1,128,128,13,10,133,13,10,133,13,10,133,13,10,129,10,14,2,
+ 128,13,10,128,9,15,4,129,13,10,8,15,8,130,13,14,15,13,10,130,13,15,6,5,
+ 15,3,129,13,10,129,13,10,129,13,10,129,7,15,2,128,13,10,129,1,14,9,128,13,
+ 10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,
+ 10,129,13,10,129,13,10,128,128,13,11,10,30,7,3,12,15,12,4,129,13,15,8,5,
+ 12,15,14,7,6,13,14,129,13,11,129,3,15,8,129,6,15,2,128,13,10,129,2,15,
+ 6,129,5,15,3,128,13,10,129,2,15,6,129,5,15,3,128,13,10,129,2,15,6,129,
+ 5,15,3,128,13,10,129,2,15,6,129,5,15,3,128,13,10,129,1,15,6,129,4,15,
+ 3,128,13,11,10,14,13,7,130,13,15,9,5,11,15,4,129,13,12,129,1,15,8,129,
+ 13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,
+ 13,10,130,14,9,128,129,7,13,15,12,5,130,7,15,8,5,10,15,5,129,14,10,130,
+ 28,128,2,15,7,130,9,14,128,2,15,7,130,10,14,129,14,10,130,28,129,7,15,8,
+ 5,10,15,5,130,7,13,15,12,5,129,128,28,10,14,13,7,130,12,15,11,5,9,15,
+ 6,129,12,14,1,129,12,13,129,28,130,8,15,129,28,130,9,15,129,12,14,1,129,12,
+ 13,129,12,15,11,5,10,15,7,129,28,10,14,13,8,130,12,11,134,12,11,134,12,11,
+ 133,129,8,30,9,13,11,129,7,15,9,5,12,15,11,129,14,11,129,1,15,11,128,1,
+ 15,7,130,14,11,128,1,15,8,130,14,11,129,14,11,129,2,15,11,129,8,15,9,5,
+ 12,15,11,130,8,30,9,13,11,134,12,11,134,12,11,134,12,11,128,128,13,11,10,14,
+ 8,128,13,15,9,5,3,128,13,12,131,13,10,131,13,10,131,13,10,131,13,10,131,13,
+ 10,130,128,3,11,30,10,2,129,14,12,5,6,13,12,128,2,15,7,129,3,7,129,8,
+ 15,12,7,2,131,2,7,12,15,8,128,2,8,2,129,8,15,17,14,12,5,6,13,14,
+ 129,4,11,30,11,3,128,128,4,15,3,130,4,15,3,129,7,63,18,7,15,6,4,129,
+ 4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,3,15,10,4,130,9,14,15,
+ 1,128,15,8,130,15,7,129,15,8,130,15,7,129,15,8,130,15,7,129,15,8,130,15,
+ 7,129,15,8,130,15,7,129,14,9,129,2,15,7,129,11,15,7,5,12,15,7,129,2,
+ 10,30,8,15,7,128,6,15,3,129,6,15,4,1,15,8,129,10,14,129,11,13,129,14,
+ 9,129,6,15,2,5,15,4,129,1,15,7,9,14,131,11,12,14,9,131,6,31,4,131,
+ 1,15,14,130,7,15,2,129,14,11,129,3,15,5,2,15,6,128,3,31,129,8,15,1,
+ 128,13,10,128,7,14,15,4,128,12,11,129,8,14,128,11,9,12,8,1,15,6,129,4,
+ 15,3,15,5,8,12,5,15,2,130,14,11,15,1,3,15,11,12,131,10,15,11,129,14,
+ 15,8,131,5,15,7,129,9,15,3,129,5,15,5,129,6,15,5,128,10,14,1,2,14,
+ 10,129,1,13,10,11,13,1,130,4,31,4,131,3,31,3,130,1,13,12,11,13,1,129,
+ 9,14,18,14,9,128,5,15,6,129,5,15,5,8,15,2,129,6,15,18,15,6,129,11,
+ 12,129,12,11,128,1,15,7,129,7,15,1,5,15,2,129,2,15,5,10,11,131,12,10,
+ 14,6,131,6,31,1,131,1,15,10,132,2,15,5,130,1,4,12,13,131,3,15,12,3,
+ 131,6,79,10,2,36,10,15,7,130,3,15,10,130,1,13,12,1,130,11,14,2,130,8,
+ 15,4,130,5,15,10,36,3,8,79,10,130,17,128,1,13,15,11,128,6,15,8,2,128,
+ 6,15,2,129,6,15,2,129,6,15,2,129,7,15,1,128,4,14,12,129,5,14,9,130,
+ 8,15,1,129,6,15,2,129,6,15,2,129,6,15,2,129,6,15,5,1,128,2,14,15,
+ 11,129,1,3,2,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,
+ 15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,128,1,130,7,
+ 15,14,4,128,1,5,15,10,130,13,10,130,13,10,130,13,10,130,13,11,130,8,15,7,
+ 129,6,15,8,129,28,130,13,10,130,13,10,130,13,10,129,2,15,10,128,7,31,6,128,
+ 1,3,2,129,135,1,10,15,13,6,2,8,19,11,5,7,14,15,14,2,131,1,3,1,
+ 152,2,14,8,128,2,14,8,144,134,8,14,15,9,128,5,14,21,13,6,8,7,129,7,
+ 9,6,12,3,2,12,7,128,10,31,10,130,18,171,2,11,1,128,2,10,17,12,13,4,
+ 13,11,1,128,1,12,15,12,1,129,2,13,15,13,2,128,2,13,11,2,12,13,17,8,
+ 1,128,1,7,142,128,81,6,79,12,1,68,3,148,128,113,1,128,6,127,15,4,1,116,
+ 4,1,160,2,15,6,8,13,128,12,7,152,128,9,13,1,128,4,14,5,128,1,13,9,
+ 129,10,13,1,128,5,14,5,128,1,14,9,128,128,10,14,10,128,5,47,21,47,5,128,
+ 10,14,10,138,129,9,13,1,129,6,14,3,129,1,14,8,131,6,14,2,131,9,13,1,
+ 140,128,4,15,4,131,7,14,2,131,13,10,130,7,14,2,129,4,15,4,141,
+};
+static const struct fos_glyph sm_glyphs[] = {
+ { 0, 3, 0, 0, 0, 51 }, /* 0x20 */
+ { 0, 5, 11, 0, -11, 84 }, /* 0x21 */
+ { 35, 5, 11, 0, -11, 76 }, /* 0x22 */
+ { 51, 11, 10, 0, -10, 171 }, /* 0x23 */
+ { 121, 9, 14, 0, -13, 144 }, /* 0x24 */
+ { 208, 13, 11, 0, -11, 215 }, /* 0x25 */
+ { 301, 11, 11, 0, -11, 173 }, /* 0x26 */
+ { 389, 2, 11, 0, -11, 37 }, /* 0x27 */
+ { 396, 6, 13, -1, -11, 74 }, /* 0x28 */
+ { 442, 5, 13, 0, -11, 74 }, /* 0x29 */
+ { 494, 6, 11, 0, -11, 102 }, /* 0x2a */
+ { 522, 8, 8, 0, -8, 127 }, /* 0x2b */
+ { 550, 4, 4, 0, -3, 68 }, /* 0x2c */
+ { 563, 6, 6, 0, -6, 102 }, /* 0x2d */
+ { 572, 4, 2, 0, -2, 70 }, /* 0x2e */
+ { 580, 7, 11, 0, -11, 109 }, /* 0x2f */
+ { 620, 9, 11, 0, -11, 145 }, /* 0x30 */
+ { 696, 6, 11, 0, -11, 90 }, /* 0x31 */
+ { 745, 9, 11, 0, -11, 139 }, /* 0x32 */
+ { 806, 8, 11, 0, -11, 134 }, /* 0x33 */
+ { 867, 9, 11, 0, -11, 146 }, /* 0x34 */
+ { 925, 8, 11, 0, -11, 134 }, /* 0x35 */
+ { 988, 8, 11, 0, -11, 134 }, /* 0x36 */
+ { 1064, 8, 11, 0, -11, 123 }, /* 0x37 */
+ { 1109, 8, 11, 0, -11, 135 }, /* 0x38 */
+ { 1185, 8, 11, 0, -11, 134 }, /* 0x39 */
+ { 1262, 6, 7, 0, -7, 89 }, /* 0x3a */
+ { 1279, 5, 9, 0, -8, 80 }, /* 0x3b */
+ { 1303, 8, 9, 0, -9, 127 }, /* 0x3c */
+ { 1345, 8, 8, 0, -8, 127 }, /* 0x3d */
+ { 1359, 8, 9, 0, -9, 127 }, /* 0x3e */
+ { 1402, 8, 11, 0, -11, 123 }, /* 0x3f */
+ { 1454, 13, 13, 0, -11, 211 }, /* 0x40 */
+ { 1565, 10, 11, 0, -11, 161 }, /* 0x41 */
+ { 1631, 10, 11, 0, -11, 160 }, /* 0x42 */
+ { 1699, 10, 11, 0, -11, 155 }, /* 0x43 */
+ { 1761, 10, 11, 0, -11, 158 }, /* 0x44 */
+ { 1830, 10, 11, 0, -11, 153 }, /* 0x45 */
+ { 1874, 9, 11, 0, -11, 145 }, /* 0x46 */
+ { 1915, 10, 11, 0, -11, 157 }, /* 0x47 */
+ { 1989, 10, 11, 0, -11, 165 }, /* 0x48 */
+ { 2063, 4, 11, 0, -11, 67 }, /* 0x49 */
+ { 2097, 9, 11, 0, -11, 148 }, /* 0x4a */
+ { 2149, 10, 11, 0, -11, 158 }, /* 0x4b */
+ { 2224, 9, 11, 0, -11, 146 }, /* 0x4c */
+ { 2260, 11, 11, 0, -11, 183 }, /* 0x4d */
+ { 2356, 11, 11, 0, -11, 172 }, /* 0x4e */
+ { 2451, 10, 11, 0, -11, 159 }, /* 0x4f */
+ { 2524, 9, 11, 0, -11, 152 }, /* 0x50 */
+ { 2577, 9, 13, 0, -11, 149 }, /* 0x51 */
+ { 2665, 10, 11, 0, -11, 157 }, /* 0x52 */
+ { 2735, 9, 11, 0, -11, 151 }, /* 0x53 */
+ { 2814, 9, 11, 0, -11, 147 }, /* 0x54 */
+ { 2861, 10, 11, 0, -11, 164 }, /* 0x55 */
+ { 2940, 10, 11, 0, -11, 154 }, /* 0x56 */
+ { 3007, 14, 11, 0, -11, 225 }, /* 0x57 */
+ { 3116, 10, 11, 0, -11, 155 }, /* 0x58 */
+ { 3190, 9, 11, 0, -11, 150 }, /* 0x59 */
+ { 3250, 9, 11, 0, -11, 141 }, /* 0x5a */
+ { 3293, 6, 16, 0, -13, 101 }, /* 0x5b */
+ { 3358, 7, 11, 0, -11, 109 }, /* 0x5c */
+ { 3398, 6, 16, 0, -13, 101 }, /* 0x5d */
+ { 3440, 7, 11, 0, -11, 117 }, /* 0x5e */
+ { 3474, 8, 3, 0, -2, 127 }, /* 0x5f */
+ { 3483, 3, 11, 0, -11, 54 }, /* 0x60 */
+ { 3490, 8, 8, 0, -8, 132 }, /* 0x61 */
+ { 3547, 9, 11, 0, -11, 142 }, /* 0x62 */
+ { 3611, 8, 8, 0, -8, 135 }, /* 0x63 */
+ { 3659, 9, 11, 0, -11, 142 }, /* 0x64 */
+ { 3725, 9, 8, 0, -8, 137 }, /* 0x65 */
+ { 3775, 6, 11, 0, -11, 94 }, /* 0x66 */
+ { 3825, 9, 11, 0, -8, 139 }, /* 0x67 */
+ { 3903, 9, 11, 0, -11, 139 }, /* 0x68 */
+ { 3965, 4, 11, 0, -11, 65 }, /* 0x69 */
+ { 3996, 5, 14, -1, -11, 63 }, /* 0x6a */
+ { 4040, 8, 11, 0, -11, 131 }, /* 0x6b */
+ { 4102, 4, 11, 0, -11, 60 }, /* 0x6c */
+ { 4136, 13, 8, 0, -8, 211 }, /* 0x6d */
+ { 4225, 9, 8, 0, -8, 139 }, /* 0x6e */
+ { 4278, 9, 8, 0, -8, 142 }, /* 0x6f */
+ { 4331, 9, 11, 0, -8, 143 }, /* 0x70 */
+ { 4393, 9, 11, 0, -8, 143 }, /* 0x71 */
+ { 4459, 6, 8, 0, -8, 95 }, /* 0x72 */
+ { 4490, 8, 8, 0, -8, 125 }, /* 0x73 */
+ { 4543, 6, 10, 0, -10, 94 }, /* 0x74 */
+ { 4585, 9, 8, 0, -8, 138 }, /* 0x75 */
+ { 4638, 8, 8, 0, -8, 126 }, /* 0x76 */
+ { 4684, 12, 8, 0, -8, 190 }, /* 0x77 */
+ { 4763, 8, 8, 0, -8, 128 }, /* 0x78 */
+ { 4813, 8, 11, 0, -8, 122 }, /* 0x79 */
+ { 4873, 7, 8, 0, -8, 115 }, /* 0x7a */
+ { 4907, 5, 16, 0, -13, 84 }, /* 0x7b */
+ { 4973, 3, 13, 0, -12, 46 }, /* 0x7c */
+ { 5012, 5, 16, 0, -13, 84 }, /* 0x7d */
+ { 5068, 8, 7, 0, -7, 131 }, /* 0x7e */
+ { 5089, 4, 6, 0, -6, 56 }, /* 0x80 */
+ { 5097, 6, 14, 0, -14, 97 }, /* 0x81 */
+ { 5126, 7, 8, 0, -8, 110 }, /* 0x82 */
+ { 5165, 7, 6, 0, -6, 118 }, /* 0x83 */
+ { 5174, 11, 6, 0, -6, 173 }, /* 0x84 */
+ { 5187, 3, 11, 0, -11, 42 }, /* 0x85 */
+ { 5196, 13, 2, 0, -2, 209 }, /* 0x86 */
+ { 5221, 5, 6, 0, -6, 80 }, /* 0x87 */
+ { 5236, 6, 7, 0, -7, 90 }, /* 0x88 */
+ { 5257, 6, 7, 0, -7, 98 }, /* 0x89 */
+};
+static const uint8_t sm_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern sm_kern[] = {
+ {39,45,-13},{39,65,-18},{39,74,-10},{39,99,-13},{39,100,-13},{39,101,-13},{39,103,-9},{39,109,-4},
+ {39,110,-4},{39,111,-13},{39,112,-4},{39,113,-9},{39,114,-4},{39,115,-7},{44,45,-4},{44,48,-8},
+ {44,84,-12},{44,86,-6},{44,87,-6},{44,89,-12},{44,99,-4},{44,100,-4},{44,101,-4},{44,103,-4},
+ {44,111,-4},{44,113,-4},{44,118,-10},{44,119,-10},{44,121,-10},{45,39,-5},{45,45,-32},{45,55,-13},
+ {45,84,-11},{45,118,-6},{45,119,-6},{45,120,-4},{45,121,-6},{45,133,-6},{46,45,-4},{46,48,-8},
+ {46,84,-12},{46,86,-6},{46,87,-6},{46,89,-12},{46,99,-4},{46,100,-4},{46,101,-4},{46,103,-4},
+ {46,111,-4},{46,113,-4},{46,118,-10},{46,119,-10},{46,121,-10},{48,49,-6},{52,39,-6},{52,49,-24},
+ {52,55,-12},{53,49,-6},{54,49,-4},{55,44,-13},{55,46,-13},{56,49,-6},{57,49,-5},{65,39,-21},
+ {65,45,-4},{65,67,-4},{65,71,-4},{65,79,-4},{65,81,-4},{65,83,-10},{65,84,-18},{65,86,-10},
+ {65,87,-10},{65,89,-20},{65,90,4},{65,99,-4},{65,100,-4},{65,101,-4},{65,102,-5},{65,103,-5},
+ {65,111,-4},{65,113,-5},{65,116,-5},{65,118,-9},{65,119,-9},{65,121,-9},{65,133,-16},{66,65,-7},
+ {66,86,-6},{66,87,-6},{66,88,-5},{66,89,-6},{66,103,-4},{66,113,-4},{66,115,-4},{67,74,4},
+ {67,89,-4},{68,65,-7},{68,86,-6},{68,87,-6},{68,88,-5},{68,89,-6},{68,103,-4},{68,113,-4},
+ {68,115,-4},{70,44,-20},{70,45,-12},{70,46,-20},{70,65,-15},{70,74,-12},{70,97,-10},{70,99,-12},
+ {70,100,-12},{70,101,-12},{70,103,-7},{70,109,-5},{70,110,-5},{70,111,-12},{70,112,-5},{70,113,-7},
+ {70,114,-5},{70,115,-9},{70,117,-6},{70,118,-11},{70,119,-11},{70,120,-9},{70,121,-11},{70,122,-5},
+ {71,74,4},{71,89,-4},{75,45,-6},{75,65,6},{75,67,-5},{75,71,-5},{75,74,-4},{75,79,-5},
+ {75,81,-5},{75,99,-6},{75,100,-6},{75,101,-6},{75,103,-5},{75,111,-6},{75,113,-5},{75,118,-8},
+ {75,119,-8},{75,121,-8},{76,39,-16},{76,65,8},{76,84,-23},{76,86,-9},{76,87,-9},{76,89,-8},
+ {76,102,-4},{76,116,-4},{76,118,-5},{76,119,-5},{76,121,-5},{76,133,-9},{79,74,4},{79,89,-4},
+ {80,44,-7},{80,45,-6},{80,46,-7},{80,65,-9},{80,74,-5},{80,88,-6},{80,89,-6},{80,99,-6},
+ {80,100,-6},{80,101,-6},{80,111,-6},{81,65,-4},{81,74,4},{81,86,-6},{81,87,-6},{81,88,-6},
+ {81,89,-11},{82,65,7},{82,89,-5},{83,84,-4},{83,88,-7},{83,89,-4},{84,44,-12},{84,45,-19},
+ {84,46,-12},{84,65,-15},{84,67,-10},{84,71,-10},{84,74,-8},{84,79,-10},{84,81,-10},{84,97,-6},
+ {84,99,-19},{84,100,-19},{84,101,-19},{84,103,-15},{84,109,-14},{84,110,-14},{84,111,-19},{84,112,-14},
+ {84,113,-15},{84,114,-14},{84,115,-14},{84,117,-11},{84,118,-11},{84,119,-11},{84,120,-13},{84,121,-11},
+ {86,44,-15},{86,45,-14},{86,46,-15},{86,65,-25},{86,67,-7},{86,71,-7},{86,74,-8},{86,75,-6},
+ {86,79,-7},{86,81,-7},{86,97,-13},{86,99,-14},{86,100,-14},{86,101,-14},{86,103,-12},{86,111,-14},
+ {86,113,-12},{86,115,-8},{87,44,-15},{87,45,-14},{87,46,-15},{87,65,-25},{87,67,-7},{87,71,-7},
+ {87,74,-8},{87,75,-6},{87,79,-7},{87,81,-7},{87,97,-13},{87,99,-14},{87,100,-14},{87,101,-14},
+ {87,103,-12},{87,111,-14},{87,113,-12},{87,115,-8},{88,45,-6},{88,67,-5},{88,71,-5},{88,79,-5},
+ {88,81,-5},{88,83,-6},{88,99,-6},{88,100,-6},{88,101,-6},{88,103,-7},{88,111,-6},{88,113,-7},
+ {88,118,-6},{88,119,-6},{88,121,-6},{89,44,-23},{89,45,-17},{89,46,-23},{89,65,-25},{89,67,-7},
+ {89,71,-7},{89,74,-11},{89,79,-7},{89,81,-7},{89,83,-5},{89,97,-13},{89,99,-17},{89,100,-17},
+ {89,101,-17},{89,102,-8},{89,103,-20},{89,109,-13},{89,110,-13},{89,111,-17},{89,112,-13},{89,113,-20},
+ {89,114,-13},{89,115,-9},{89,116,-8},{89,117,-8},{89,118,-9},{89,119,-9},{89,120,-8},{89,121,-9},
+ {89,122,-5},{97,39,-7},{97,84,-6},{97,89,-7},{98,39,-8},{98,44,-4},{98,46,-4},{98,118,-4},
+ {98,119,-4},{98,121,-4},{99,39,-5},{99,44,-7},{99,46,-7},{101,39,-7},{101,44,-5},{101,46,-5},
+ {101,118,-5},{101,119,-5},{101,120,-5},{101,121,-5},{101,133,-5},{102,44,-13},{102,45,-10},{102,46,-13},
+ {102,97,-4},{102,99,-10},{102,100,-10},{102,101,-10},{102,103,-9},{102,111,-10},{102,113,-9},{102,115,-4},
+ {102,133,4},{104,39,-8},{104,44,-4},{104,46,-4},{104,118,-4},{104,119,-4},{104,121,-4},{107,45,-7},
+ {107,99,-7},{107,100,-7},{107,101,-7},{107,103,-5},{107,111,-7},{107,113,-5},{109,39,-8},{109,44,-4},
+ {109,46,-4},{109,118,-4},{109,119,-4},{109,121,-4},{110,39,-8},{110,44,-4},{110,46,-4},{110,118,-4},
+ {110,119,-4},{110,121,-4},{111,39,-5},{111,55,-13},{111,84,-11},{111,118,-6},{111,119,-6},{111,120,-4},
+ {111,121,-6},{111,133,-6},{112,39,-8},{112,44,-4},{112,46,-4},{112,118,-4},{112,119,-4},{112,121,-4},
+ {114,39,7},{114,44,-9},{114,46,-9},{114,103,-4},{114,113,-4},{114,118,6},{114,119,6},{114,121,6},
+ {114,133,13},{115,39,-6},{115,118,-8},{115,119,-8},{115,121,-8},{115,133,-5},{118,44,-10},{118,45,-6},
+ {118,46,-10},{118,97,-4},{118,99,-6},{118,100,-6},{118,101,-6},{118,103,-7},{118,111,-6},{118,113,-7},
+ {118,115,-8},{118,133,13},{119,44,-10},{119,45,-6},{119,46,-10},{119,97,-4},{119,99,-6},{119,100,-6},
+ {119,101,-6},{119,103,-7},{119,111,-6},{119,113,-7},{119,115,-8},{119,133,13},{120,45,-7},{120,99,-7},
+ {120,100,-7},{120,101,-7},{120,103,-4},{120,111,-7},{120,113,-4},{121,44,-10},{121,45,-6},{121,46,-10},
+ {121,97,-4},{121,99,-6},{121,100,-6},{121,101,-6},{121,103,-7},{121,111,-6},{121,113,-7},{121,115,-8},
+ {121,133,13},{133,45,-20},{133,65,-16},{133,97,-6},{133,99,-20},{133,100,-20},{133,101,-20},{133,103,-17},
+ {133,111,-20},{133,113,-17},{133,115,-16},
+};
+const struct fos_font fos_font_sm_data = { sm_bits, sm_glyphs, sm_lut, sm_kern, 427, 16, 4 };
+
+static const uint8_t md_bits[] = {
+ 129,9,15,4,131,9,15,4,131,9,15,3,131,9,15,3,131,9,15,3,131,8,15,2,
+ 131,8,15,2,131,8,15,2,131,7,15,1,146,1,132,13,15,5,131,11,14,4,129,7,
+ 15,21,15,23,15,4,5,15,22,15,3,4,15,21,15,2,3,15,4,187,131,5,8,1,
+ 129,6,7,133,14,15,129,1,15,13,132,2,15,12,129,4,15,10,131,127,31,1,129,9,
+ 12,15,12,25,13,15,11,9,1,130,9,15,5,129,12,15,2,132,11,15,3,129,14,15,
+ 1,132,13,15,1,128,1,15,14,131,11,127,15,5,129,6,11,15,13,25,11,15,12,9,
+ 3,130,5,15,9,129,7,15,6,132,8,15,6,129,10,15,4,132,10,15,4,129,12,15,
+ 2,130,131,4,15,6,134,1,7,15,9,1,132,8,79,9,1,129,6,15,10,2,1,3,
+ 10,15,9,129,11,15,1,131,13,15,1,128,12,15,1,131,9,14,2,128,8,15,11,2,
+ 134,1,12,31,10,4,133,1,7,14,31,12,4,134,5,12,31,6,135,5,31,17,15,11,
+ 132,9,15,4,128,30,1,131,10,15,2,128,9,15,11,3,17,6,15,12,129,1,10,79,
+ 12,2,131,2,8,15,11,4,134,3,15,7,131,129,2,11,14,13,4,131,11,10,132,1,
+ 13,14,10,12,15,3,129,4,15,2,132,4,14,1,129,12,8,129,12,9,133,4,14,1,
+ 129,12,8,128,6,14,1,133,1,13,14,10,12,15,3,1,13,7,135,2,11,15,13,4,
+ 128,7,13,141,1,14,5,141,9,12,141,3,15,4,128,1,7,9,5,136,27,128,2,14,
+ 47,8,134,4,15,2,128,9,12,2,1,7,15,1,133,12,9,129,10,9,129,2,15,3,
+ 132,6,14,1,129,5,15,11,10,14,12,133,13,7,131,6,13,14,11,2,129,130,6,13,
+ 15,13,9,1,134,7,15,14,10,12,15,12,134,14,15,2,129,11,15,4,133,14,15,130,
+ 9,15,5,133,9,15,7,128,3,15,14,1,133,1,13,15,8,14,15,6,135,6,31,14,
+ 5,135,5,47,13,2,134,5,15,14,5,7,15,12,1,128,22,130,13,15,4,129,8,15,
+ 11,4,15,12,130,15,14,131,9,31,14,3,130,14,15,2,130,6,31,9,131,8,15,14,
+ 26,13,15,14,13,15,4,131,6,12,14,15,12,8,1,2,30,2,128,7,15,6,7,15,
+ 5,6,15,21,15,3,157,129,1,13,14,1,130,7,15,8,131,14,15,2,130,4,15,12,
+ 131,9,15,8,131,12,15,5,131,14,15,3,131,31,2,130,1,31,2,131,31,2,131,14,
+ 15,3,131,12,15,5,131,9,15,8,131,5,15,12,132,14,15,2,131,8,15,8,131,1,
+ 13,14,1,128,128,2,15,11,131,10,15,5,130,5,15,12,131,14,15,2,130,11,15,6,
+ 130,8,15,9,130,6,15,12,130,5,15,13,130,4,15,13,130,5,15,13,130,6,15,12,
+ 130,8,15,9,130,11,15,6,129,1,14,15,2,129,5,15,11,130,11,15,5,129,2,15,
+ 11,129,130,9,8,130,2,8,1,9,8,1,8,1,3,12,14,28,14,12,2,129,9,31,
+ 8,129,2,11,14,29,14,11,18,8,1,9,8,1,9,2,130,9,8,194,131,13,11,135,
+ 13,12,135,13,12,131,4,127,3,2,41,30,41,2,131,13,12,135,13,12,135,13,11,151,
+ 128,1,15,9,129,4,15,5,129,7,15,1,129,9,13,130,12,8,129,2,89,2,4,95,
+ 4,167,129,2,131,6,15,12,130,5,14,10,129,132,12,15,1,132,3,15,11,133,8,15,
+ 6,133,13,15,1,132,3,15,11,133,9,15,5,133,14,15,1,132,4,15,10,133,9,15,
+ 5,133,30,1,132,4,15,10,133,10,15,4,133,30,133,5,15,9,133,129,1,9,13,15,
+ 14,10,3,130,1,13,15,13,10,12,31,3,129,7,15,10,130,6,15,12,129,11,15,4,
+ 131,14,15,129,11,15,2,131,13,15,1,128,12,15,2,131,13,15,1,128,12,15,2,131,
+ 13,15,1,128,12,15,2,131,13,15,1,128,12,15,2,131,13,15,1,128,11,15,2,131,
+ 13,15,1,128,11,15,4,131,14,15,129,7,15,10,130,6,15,12,129,1,13,15,13,10,
+ 12,31,3,130,1,9,13,15,14,10,3,129,128,1,7,14,15,6,129,14,47,7,129,9,
+ 5,8,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,
+ 131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,6,
+ 128,129,3,10,14,15,12,7,131,3,31,11,10,14,15,10,130,11,15,6,129,1,13,15,
+ 4,129,14,15,131,8,15,7,129,23,131,10,15,5,134,2,15,14,1,134,12,15,7,134,
+ 9,15,11,134,7,15,13,1,133,5,15,14,3,133,3,14,15,4,133,2,14,15,6,134,
+ 12,15,14,73,8,129,14,111,13,128,128,14,111,3,128,8,57,12,31,2,132,4,14,15,
+ 7,132,3,14,15,8,132,2,14,15,9,133,11,31,11,5,132,3,8,7,13,15,7,134,
+ 1,30,1,134,10,15,4,1,7,6,131,9,15,5,1,15,14,131,11,15,4,128,11,15,
+ 6,129,3,15,14,129,3,14,15,11,10,14,15,6,130,3,10,30,12,5,129,131,5,15,
+ 10,135,12,15,4,134,4,15,12,135,11,15,5,134,3,15,13,135,10,15,6,134,2,15,
+ 13,130,12,15,2,129,9,15,7,130,12,15,2,128,1,31,59,14,15,11,3,2,127,15,
+ 4,134,12,15,2,135,12,15,2,135,12,15,2,135,11,15,2,128,128,12,111,1,128,13,
+ 15,10,73,129,13,15,1,134,13,15,1,134,13,15,1,134,13,15,2,6,9,7,3,130,
+ 13,15,14,63,7,129,13,15,11,2,128,4,14,15,2,128,5,6,1,130,8,15,6,134,
+ 6,15,8,128,8,11,2,130,7,15,7,128,8,15,9,129,1,13,15,4,128,1,13,15,
+ 12,10,13,15,10,130,2,9,13,14,13,7,129,129,2,10,13,15,12,7,130,3,31,12,
+ 10,14,15,9,129,10,15,7,129,2,14,15,2,128,13,15,2,130,10,15,4,128,13,15,
+ 1,130,17,129,13,15,1,6,9,8,3,130,13,15,13,63,7,129,13,15,12,3,128,5,
+ 31,2,128,13,15,4,130,8,15,7,128,13,15,1,130,6,15,8,128,12,15,2,130,7,
+ 15,7,128,8,15,8,129,1,13,15,4,128,1,13,15,12,10,13,15,10,130,2,9,13,
+ 15,13,8,129,5,127,3,6,15,10,57,14,15,3,4,11,2,130,2,15,13,134,8,15,
+ 8,134,13,15,2,133,4,15,12,134,10,15,6,133,1,14,15,1,133,6,15,10,134,12,
+ 15,4,133,2,15,14,134,8,15,8,134,13,15,3,133,4,15,12,132,129,1,9,14,15,
+ 12,6,131,1,13,15,12,10,14,15,7,130,7,15,9,129,2,30,1,129,11,15,3,130,
+ 10,15,3,129,10,15,4,130,11,15,3,129,5,15,12,3,1,7,15,13,131,9,63,14,
+ 2,130,2,13,15,11,10,14,15,8,130,10,15,6,129,1,13,15,3,129,14,15,131,7,
+ 15,7,129,14,15,131,8,15,7,129,11,15,7,129,1,13,15,3,129,3,31,11,10,14,
+ 15,10,131,3,10,14,15,13,7,130,129,3,11,30,12,5,131,3,14,15,11,10,14,15,
+ 6,130,11,15,6,129,2,30,1,129,15,14,131,10,15,4,128,1,15,13,131,9,15,5,
+ 129,15,14,131,10,15,5,129,11,15,6,129,2,14,15,5,129,4,31,11,10,14,31,5,
+ 130,4,12,14,13,25,15,5,135,8,15,5,129,9,12,2,130,9,15,5,129,10,15,7,
+ 129,1,13,15,3,129,3,31,11,10,14,15,10,131,3,11,30,12,7,130,130,2,132,10,
+ 15,8,131,8,14,7,160,2,132,10,15,8,131,8,14,7,129,129,9,11,2,129,3,31,
+ 9,129,1,12,14,4,148,10,15,1,130,12,13,131,14,9,130,1,15,6,130,2,15,3,
+ 129,144,6,13,3,131,1,7,14,15,14,2,129,2,8,14,15,13,7,1,128,1,10,31,
+ 11,5,131,4,15,14,4,133,2,12,15,14,9,3,133,4,11,31,11,4,133,2,9,31,
+ 13,2,133,2,8,14,3,135,1,128,3,125,2,4,127,3,147,3,125,2,4,127,3,157,
+ 137,4,12,5,134,3,31,13,6,1,132,1,8,14,15,14,8,1,133,6,12,31,9,1,
+ 133,5,31,3,131,3,10,31,11,1,129,5,12,31,10,3,129,3,13,15,14,9,2,131,
+ 4,14,7,1,133,1,136,129,5,12,30,11,3,130,7,15,14,10,11,31,3,128,1,15,
+ 14,2,129,6,15,11,128,4,15,10,130,1,15,13,128,1,6,4,130,4,15,12,133,2,
+ 13,15,6,132,3,14,15,10,132,2,14,15,7,133,7,15,9,134,8,15,7,134,1,3,
+ 1,135,2,135,10,15,8,134,9,14,6,131,132,3,8,12,30,13,8,2,133,1,9,31,
+ 12,26,12,31,6,131,1,12,15,7,1,131,2,11,15,4,130,10,14,3,128,2,24,2,
+ 9,1,128,28,129,3,15,5,128,3,14,31,14,15,1,128,4,15,2,128,9,13,129,11,
+ 13,2,1,12,14,129,1,15,4,128,12,9,129,14,6,129,8,12,129,1,15,5,128,14,
+ 7,128,2,15,3,129,26,129,4,15,2,128,13,8,128,3,15,4,128,2,14,11,129,11,
+ 13,129,27,129,14,13,10,13,14,15,11,12,15,6,129,6,15,4,128,4,12,15,10,1,
+ 9,14,13,7,131,12,14,5,132,1,134,2,13,15,13,10,9,10,12,15,4,134,1,7,
+ 12,14,15,13,10,5,132,131,1,31,9,136,6,31,14,136,11,15,13,15,4,134,1,15,
+ 14,5,15,9,134,5,15,9,1,15,14,134,10,15,4,128,11,15,4,132,1,30,129,6,
+ 15,9,132,5,15,10,129,2,15,13,132,10,15,5,130,12,15,3,131,14,15,1,130,7,
+ 15,8,130,4,127,13,130,9,15,10,72,13,15,3,129,14,15,2,132,8,15,8,128,4,
+ 15,12,133,3,15,12,128,128,5,79,13,11,4,130,5,15,13,41,12,31,5,129,5,15,
+ 8,131,6,15,13,129,5,15,8,132,14,15,129,5,15,8,132,30,129,5,15,8,131,5,
+ 15,8,129,5,15,12,41,11,15,8,130,5,111,13,3,129,5,15,8,130,2,9,15,13,
+ 129,5,15,8,132,13,15,2,128,5,15,8,132,12,15,3,128,5,15,8,131,3,15,14,
+ 1,128,5,15,12,41,11,31,7,129,5,79,14,11,4,129,130,5,11,30,12,7,1,131,
+ 9,15,14,11,10,13,15,13,1,129,4,15,13,2,130,10,15,9,129,9,15,5,131,1,
+ 15,13,129,11,15,3,132,8,9,129,11,15,3,136,11,15,3,136,11,15,3,136,11,15,
+ 3,136,11,15,3,132,24,129,9,15,5,131,1,15,13,129,4,15,13,2,130,10,15,9,
+ 130,9,15,14,11,10,13,15,12,1,131,5,11,30,12,7,1,129,128,5,79,14,11,4,
+ 130,5,15,13,41,11,31,5,129,5,15,8,131,5,15,14,129,5,15,8,132,12,15,3,
+ 128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,
+ 128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,
+ 128,5,15,8,132,12,15,3,128,5,15,8,131,5,15,14,129,5,15,12,41,11,31,5,
+ 129,5,79,14,11,4,129,128,5,127,14,129,5,15,13,89,8,129,5,15,8,136,5,15,
+ 8,136,5,15,8,136,5,15,8,136,5,15,12,57,6,131,5,95,11,131,5,15,8,136,
+ 5,15,8,136,5,15,8,136,5,15,8,136,5,15,12,89,8,129,5,127,14,128,128,5,
+ 127,14,128,5,15,13,89,8,128,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,
+ 135,5,15,12,57,6,130,5,95,10,130,5,15,8,135,5,15,8,135,5,15,8,135,5,
+ 15,8,135,5,15,8,135,5,15,8,134,130,5,11,30,12,7,132,9,15,14,11,10,14,
+ 15,12,1,129,4,15,13,2,129,1,11,15,8,129,9,15,5,131,2,15,13,129,11,15,
+ 3,132,28,129,11,15,3,136,11,15,3,136,11,15,3,129,13,63,129,11,15,3,129,8,
+ 25,31,129,11,15,3,132,14,15,129,9,15,6,132,15,14,129,4,15,13,2,130,8,15,
+ 9,130,9,15,14,11,10,13,15,13,2,131,5,11,14,15,13,8,1,129,128,5,15,8,
+ 132,8,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,
+ 132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,12,
+ 73,13,15,5,129,5,127,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,
+ 5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,
+ 5,129,5,15,8,132,8,15,5,128,128,5,15,8,129,5,15,8,129,5,15,8,129,5,
+ 15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,
+ 15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,128,135,30,137,15,14,
+ 137,15,14,137,15,14,137,15,14,137,15,14,137,15,14,137,15,14,129,6,13,5,132,15,
+ 14,129,7,15,6,132,15,14,129,6,15,8,131,2,15,13,129,2,15,14,2,130,10,15,
+ 8,130,7,31,11,10,13,15,13,1,131,5,11,14,15,13,8,1,130,128,5,15,8,131,
+ 1,13,15,4,128,5,15,8,130,1,12,15,6,129,5,15,8,130,11,15,9,130,5,15,
+ 8,129,9,15,11,131,5,15,8,128,7,15,12,1,131,5,15,8,6,15,14,2,132,5,
+ 15,12,31,14,2,132,5,31,14,10,15,10,132,5,31,4,128,12,15,5,131,5,15,9,
+ 129,3,15,14,1,130,5,15,8,130,8,15,10,130,5,15,8,131,12,15,5,129,5,15,
+ 8,131,3,15,14,1,128,5,15,8,132,8,15,9,128,5,15,8,135,5,15,8,135,5,
+ 15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,
+ 15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,13,90,7,128,5,127,11,
+ 128,5,15,12,133,8,15,10,129,5,31,8,131,3,31,10,129,5,47,3,130,13,31,10,
+ 129,5,15,14,15,12,129,8,15,13,15,10,129,5,15,8,11,15,8,3,15,14,5,15,
+ 10,129,5,15,8,2,14,15,13,15,5,4,15,10,129,5,15,8,128,6,31,10,128,4,
+ 15,10,129,5,15,8,129,10,14,1,128,4,15,10,129,5,15,8,133,4,15,10,129,5,
+ 15,8,133,4,15,10,129,5,15,8,133,4,15,10,129,5,15,8,133,4,15,10,129,5,
+ 15,8,133,4,15,10,129,5,15,8,133,4,15,10,128,128,5,15,11,132,2,15,12,129,
+ 5,31,6,131,2,15,12,129,5,31,14,1,130,2,15,12,129,5,15,14,15,9,130,2,
+ 15,12,129,5,15,9,12,15,3,129,2,15,12,129,5,15,8,4,15,12,129,2,15,12,
+ 129,5,15,8,128,9,15,7,128,2,15,12,129,5,15,8,128,1,30,18,15,12,129,5,
+ 15,8,129,6,15,10,2,15,12,129,5,15,8,130,12,15,6,15,12,129,5,15,8,130,
+ 3,15,14,15,12,129,5,15,8,131,8,31,12,129,5,15,8,131,1,13,15,12,129,5,
+ 15,8,132,5,15,12,128,130,5,11,30,13,8,1,131,8,31,11,10,13,15,13,1,129,
+ 3,15,14,2,130,9,15,9,129,9,15,6,131,1,14,15,129,11,15,3,132,12,15,2,
+ 128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,
+ 128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,128,9,15,6,131,1,14,15,
+ 129,3,15,14,2,130,9,15,9,130,8,31,11,10,13,15,13,1,131,5,11,14,15,13,
+ 8,1,129,128,7,79,14,12,5,130,7,15,12,41,11,31,6,129,7,15,7,131,4,15,
+ 14,129,7,15,7,132,12,15,2,128,7,15,7,132,12,15,2,128,7,15,7,131,4,15,
+ 14,129,7,15,12,41,11,31,6,129,7,79,14,11,5,130,7,15,7,136,7,15,7,136,
+ 7,15,7,136,7,15,7,136,7,15,7,136,7,15,6,135,130,7,12,30,11,4,132,12,
+ 15,13,10,11,31,7,130,7,15,10,1,129,2,14,15,2,129,12,15,2,131,7,15,7,
+ 129,14,15,132,5,15,9,129,30,132,5,15,9,129,30,132,5,15,9,129,30,132,5,15,
+ 9,129,30,132,5,15,9,129,14,15,132,6,15,9,129,12,15,4,131,10,15,7,129,6,
+ 15,14,5,1,2,8,31,2,130,10,95,5,132,5,10,15,14,8,2,134,2,15,12,136,
+ 2,15,11,132,128,5,79,14,12,5,130,5,15,13,41,11,31,6,129,5,15,8,131,3,
+ 15,14,129,5,15,8,132,12,15,3,128,5,15,8,132,12,15,3,128,5,15,8,131,3,
+ 15,14,129,5,15,12,41,10,31,6,129,5,95,13,5,130,5,15,8,129,3,15,11,131,
+ 5,15,8,130,10,15,3,130,5,15,8,130,3,15,11,130,5,15,8,131,11,15,3,129,
+ 5,15,8,131,4,15,11,129,5,15,8,132,11,15,3,129,2,9,13,30,11,6,131,2,
+ 14,15,12,10,11,14,15,10,130,9,15,7,130,1,12,15,6,129,12,15,2,131,5,15,
+ 9,129,10,15,6,131,1,7,5,129,3,31,9,3,135,3,12,31,12,6,135,4,10,31,
+ 13,5,135,1,8,31,4,129,8,6,132,6,15,10,129,15,13,132,3,15,11,129,12,15,
+ 7,131,9,15,9,129,3,14,15,13,26,13,15,13,1,130,2,9,13,30,12,7,1,129,
+ 3,127,15,11,2,41,11,15,13,41,6,131,4,15,9,135,4,15,9,135,4,15,9,135,
+ 4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,
+ 4,15,9,135,4,15,9,135,4,15,9,131,128,7,15,6,132,9,15,4,129,8,15,6,
+ 132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,
+ 132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,
+ 132,9,15,5,129,8,15,6,132,9,15,5,129,7,15,7,132,9,15,4,129,5,15,9,
+ 132,12,15,3,129,1,14,15,4,130,6,15,13,131,5,31,12,10,12,15,14,3,132,3,
+ 10,14,15,13,9,2,130,4,15,12,133,10,15,4,128,14,15,1,131,1,30,129,9,15,
+ 6,131,4,15,10,129,5,15,10,131,9,15,5,129,1,30,131,13,14,1,130,10,15,4,
+ 129,3,15,10,131,6,15,9,129,7,15,6,131,1,15,13,129,12,15,1,132,11,15,3,
+ 1,15,11,133,6,15,7,6,15,6,133,2,15,12,10,15,2,134,12,31,12,135,7,31,
+ 7,135,2,31,2,131,6,15,9,131,5,15,12,132,30,128,2,15,13,131,9,31,2,130,
+ 4,15,10,129,13,15,2,130,13,31,6,130,8,15,6,129,9,15,6,129,1,15,14,15,
+ 9,130,12,15,2,129,5,15,10,129,5,15,7,14,13,129,1,15,13,130,1,15,14,129,
+ 9,15,3,11,15,2,128,5,15,9,131,11,15,3,128,12,14,128,7,15,6,128,9,15,
+ 5,131,7,15,7,1,15,11,128,3,15,10,128,13,15,1,131,3,15,11,5,15,7,129,
+ 30,2,15,12,133,30,9,15,4,129,10,15,9,15,8,133,10,47,130,6,47,4,133,6,
+ 31,11,130,3,47,1,133,1,31,8,131,14,15,11,135,12,15,4,131,10,15,7,131,2,
+ 15,14,1,131,1,13,15,3,128,8,15,9,131,8,15,9,130,13,15,3,129,2,15,14,
+ 1,130,4,15,12,129,11,15,5,132,10,15,6,5,15,11,133,2,30,13,15,2,134,7,
+ 31,8,135,6,31,7,134,1,46,15,2,133,10,15,6,5,15,11,132,4,15,12,129,11,
+ 15,5,131,13,15,3,129,2,15,13,1,129,8,15,9,131,8,15,8,128,2,15,14,1,
+ 131,1,13,15,3,2,15,13,132,3,15,13,129,9,15,6,131,11,15,5,129,2,15,14,
+ 1,129,4,15,12,131,9,15,7,129,12,15,4,131,1,30,1,5,15,11,133,8,15,8,
+ 12,15,3,133,1,14,31,10,135,7,31,2,135,2,15,12,136,2,15,12,136,2,15,12,
+ 136,2,15,12,136,2,15,12,136,2,15,12,132,3,127,15,17,89,10,31,1,134,10,15,
+ 8,134,5,15,12,134,1,14,15,3,134,10,15,8,134,5,15,13,134,1,14,15,3,134,
+ 10,15,8,134,4,15,13,1,133,1,13,15,4,134,9,15,9,134,2,31,10,89,1,3,
+ 127,15,1,3,57,2,129,5,63,4,129,5,15,9,132,5,15,9,132,5,15,9,132,5,
+ 15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,
+ 15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,13,25,2,
+ 129,5,63,4,129,128,8,15,5,133,3,15,10,134,13,15,1,133,8,15,6,133,3,15,
+ 11,134,13,15,1,133,7,15,6,133,2,15,12,134,12,15,2,133,7,15,7,133,2,15,
+ 12,134,11,15,2,133,6,15,7,133,1,15,12,128,129,4,57,2,129,6,63,3,132,11,
+ 15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,
+ 15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,
+ 15,3,132,11,15,3,129,4,25,13,15,3,129,6,63,3,130,2,8,3,133,10,15,12,
+ 132,1,15,13,15,3,131,7,15,2,14,9,131,13,11,128,9,14,1,129,4,15,5,128,
+ 3,15,7,129,11,14,130,12,13,128,2,15,8,130,6,15,4,181,4,121,4,7,127,6,
+ 2,8,3,129,12,13,129,3,15,6,171,129,4,11,30,12,6,130,6,31,11,10,14,15,
+ 8,129,10,14,5,129,1,14,15,1,134,12,15,2,128,1,7,12,14,63,2,128,11,15,
+ 14,10,25,14,15,18,15,13,1,130,12,15,18,15,12,130,3,31,2,128,13,15,12,10,
+ 11,47,2,128,2,10,14,15,12,5,11,15,2,128,8,15,5,135,9,15,5,135,9,15,
+ 5,135,9,15,5,135,9,15,7,10,30,10,2,130,9,31,14,10,13,15,13,1,129,9,
+ 15,14,1,129,11,15,8,129,9,15,8,130,3,15,12,129,9,15,6,130,1,15,14,129,
+ 9,15,6,130,1,15,14,129,9,15,8,130,3,15,12,129,9,15,14,1,129,10,15,7,
+ 129,9,31,13,10,12,15,13,1,129,8,15,6,10,15,14,10,2,129,129,1,8,13,15,
+ 13,8,1,130,1,13,15,12,10,13,15,13,1,129,7,15,9,130,9,15,8,129,12,15,
+ 3,130,2,8,4,129,13,15,1,135,13,15,1,135,12,15,3,130,2,7,3,129,7,15,
+ 9,130,10,15,7,129,1,12,15,12,10,13,15,13,1,130,1,8,13,15,13,8,1,129,
+ 134,4,15,9,135,4,15,10,135,4,15,10,135,4,15,10,130,2,9,13,15,11,6,15,
+ 10,129,1,13,15,13,10,13,31,10,129,7,15,11,129,1,13,15,10,129,11,15,4,130,
+ 7,15,10,129,13,15,2,130,5,15,10,129,13,15,2,130,5,15,10,129,11,15,4,130,
+ 7,15,10,129,6,15,10,129,1,13,15,10,129,1,13,15,12,10,13,31,10,130,1,9,
+ 30,11,6,15,9,128,129,1,9,13,15,14,9,1,130,1,13,15,12,10,13,15,12,130,
+ 8,15,8,130,10,15,5,129,12,15,2,130,4,15,9,129,13,111,10,129,13,15,89,6,
+ 129,11,15,2,135,6,15,9,130,4,11,2,130,12,15,13,10,11,15,14,3,130,1,8,
+ 13,15,14,9,2,129,130,9,13,15,8,129,7,15,14,10,5,129,10,15,5,131,11,15,
+ 3,129,5,79,8,3,9,14,15,10,9,5,129,12,15,2,131,12,15,2,131,12,15,2,
+ 131,12,15,2,131,12,15,2,131,12,15,2,131,12,15,2,131,11,15,2,129,129,2,10,
+ 30,10,7,15,8,129,2,14,15,12,10,13,31,9,129,9,15,9,129,1,12,15,9,129,
+ 13,15,2,130,7,15,9,129,14,15,131,5,15,9,129,14,15,131,5,15,9,129,13,15,
+ 2,130,6,15,9,129,9,15,9,130,12,15,9,129,2,14,15,12,10,13,31,9,130,2,
+ 10,30,11,8,15,9,135,8,15,7,134,2,14,15,4,131,6,9,11,31,10,132,9,15,
+ 14,11,6,130,128,9,15,4,135,9,15,5,135,9,15,5,135,9,15,5,135,9,15,7,
+ 11,30,10,2,130,9,31,13,10,13,15,13,1,129,9,15,11,129,1,12,15,5,129,9,
+ 15,5,130,7,15,7,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,
+ 15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,
+ 15,4,130,6,15,7,128,128,7,14,8,129,8,15,10,130,2,135,6,15,7,129,7,15,
+ 7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,
+ 7,129,7,15,7,129,6,15,7,128,129,8,14,6,130,10,15,8,131,2,137,8,15,5,
+ 130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,
+ 130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,5,130,12,15,4,128,8,13,15,
+ 14,129,13,14,10,2,129,128,9,15,4,134,9,15,5,134,9,15,5,134,9,15,5,134,
+ 9,15,5,129,4,15,14,1,128,9,15,5,128,3,30,3,129,9,15,5,2,14,15,5,
+ 130,9,15,6,13,15,12,131,9,47,13,15,3,130,9,31,5,4,15,10,130,9,15,7,
+ 129,12,15,2,129,9,15,5,129,5,15,9,129,9,15,5,130,13,15,2,128,9,15,4,
+ 130,6,15,8,128,9,15,4,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,
+ 129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,
+ 129,9,15,5,129,9,15,5,129,9,15,4,128,128,9,15,6,10,30,10,2,3,11,30,
+ 10,1,130,9,31,12,10,14,15,13,14,12,10,14,15,11,130,9,15,10,129,1,14,15,
+ 10,129,1,14,15,2,129,9,15,5,130,10,15,5,130,10,15,4,129,9,15,5,130,10,
+ 15,4,130,10,15,4,129,9,15,5,130,10,15,4,130,10,15,4,129,9,15,5,130,10,
+ 15,4,130,10,15,4,129,9,15,5,130,10,15,4,130,10,15,4,129,9,15,5,130,10,
+ 15,4,130,10,15,4,129,9,15,4,130,9,15,4,130,9,15,4,128,128,9,15,7,11,
+ 30,10,2,130,9,31,13,10,13,15,13,1,129,9,15,11,129,1,12,15,5,129,9,15,
+ 5,130,7,15,7,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,
+ 5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,
+ 4,130,6,15,7,128,129,1,8,13,15,13,8,1,130,1,12,15,13,10,12,15,12,1,
+ 129,7,15,10,130,9,15,8,129,12,15,3,130,2,15,12,129,13,15,1,131,15,14,129,
+ 13,15,1,131,15,14,129,11,15,3,130,2,15,12,129,7,15,10,130,9,15,8,129,1,
+ 12,15,13,10,12,15,13,1,130,1,8,13,15,13,9,1,129,128,7,15,8,10,30,10,
+ 2,130,7,31,14,10,11,15,14,2,129,7,15,14,2,129,8,15,9,129,7,15,10,130,
+ 2,15,13,129,7,15,7,131,14,15,129,7,15,7,131,14,15,129,7,15,10,130,2,15,
+ 14,129,7,15,14,2,129,10,15,9,129,7,31,14,10,12,15,14,2,129,7,15,8,10,
+ 30,10,3,130,7,15,7,135,7,15,7,135,7,15,7,135,7,15,6,134,129,1,9,13,
+ 15,11,6,15,9,129,1,13,15,12,10,13,31,10,129,6,15,10,129,1,13,15,10,129,
+ 11,15,4,130,7,15,10,129,13,15,2,130,5,15,10,129,13,15,2,130,5,15,10,129,
+ 11,15,4,130,7,15,10,129,7,15,11,129,1,13,15,10,129,1,13,15,13,10,13,31,
+ 10,130,2,10,30,11,6,15,10,135,4,15,10,135,4,15,10,135,4,15,10,135,4,15,
+ 9,128,128,9,15,6,10,14,13,1,128,9,31,13,10,9,129,9,15,11,132,9,15,6,
+ 132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,4,
+ 131,129,7,12,30,11,4,130,9,15,14,26,14,15,5,129,30,1,129,3,15,11,129,12,
+ 15,5,130,17,129,3,12,15,14,10,5,1,132,5,9,14,15,13,3,129,18,130,6,15,
+ 11,129,15,14,1,129,3,15,13,129,9,15,14,26,14,15,8,130,7,12,30,12,6,129,
+ 129,6,7,132,13,15,132,13,15,130,5,79,6,3,9,14,15,25,4,129,13,15,132,13,
+ 15,132,13,15,132,13,15,132,13,15,132,13,15,2,131,10,15,13,9,3,129,2,11,14,
+ 15,4,128,11,15,2,130,8,15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,
+ 15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,
+ 15,5,129,11,15,3,130,9,15,5,129,10,15,8,129,1,13,15,5,129,3,31,12,10,
+ 14,31,5,130,4,11,30,10,9,15,5,128,5,15,11,131,14,15,2,1,14,15,1,129,
+ 4,15,12,129,10,15,6,129,8,15,7,129,5,15,10,129,13,15,2,130,30,1,3,15,
+ 12,131,9,15,5,7,15,7,131,4,15,9,12,15,2,132,30,15,12,133,9,31,7,133,
+ 4,31,2,130,5,15,9,130,9,15,5,130,11,15,3,1,15,13,130,14,15,10,129,1,
+ 15,13,129,11,15,2,128,3,31,14,129,5,15,9,129,7,15,6,128,7,15,12,15,3,
+ 128,9,15,4,129,2,15,10,128,11,14,4,15,7,128,13,14,131,13,14,1,14,10,128,
+ 14,11,2,15,10,131,8,15,7,15,6,128,9,15,7,15,6,131,4,15,14,15,2,128,
+ 5,15,14,15,1,132,14,15,12,129,1,31,12,133,10,15,8,130,11,15,7,130,4,15,
+ 12,130,1,13,15,4,128,9,15,7,129,9,15,8,129,1,13,15,3,4,15,13,131,3,
+ 15,12,13,15,3,132,8,31,7,133,6,31,6,132,2,30,13,14,2,131,12,15,5,4,
+ 15,12,130,8,15,9,129,8,15,8,128,4,15,13,1,130,12,15,3,7,15,9,130,1,
+ 30,128,2,15,13,130,5,15,10,129,12,15,3,129,9,15,4,129,7,15,7,129,13,14,
+ 130,2,15,12,128,3,15,9,131,11,15,1,7,15,4,131,6,15,6,12,13,132,1,15,
+ 12,15,8,133,11,31,3,133,6,15,13,134,5,15,8,134,11,15,2,132,8,12,15,10,
+ 132,1,15,14,9,1,132,4,111,4,2,57,10,31,4,132,11,15,9,132,8,15,11,132,
+ 5,15,13,1,131,2,14,15,3,131,1,12,15,6,132,10,15,9,132,5,31,73,3,6,
+ 111,5,129,1,7,9,8,130,11,31,13,130,31,3,131,15,14,132,15,14,132,15,14,132,
+ 15,14,131,2,15,13,130,3,13,15,8,130,4,31,4,131,5,15,12,131,1,15,13,132,
+ 15,14,132,15,14,132,15,14,132,15,14,132,14,15,12,8,130,5,13,15,13,128,2,15,
+ 11,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,
+ 12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,
+ 12,128,2,15,12,128,2,15,12,128,2,15,11,128,3,25,5,130,5,47,5,131,9,15,
+ 8,131,5,15,9,131,5,15,9,131,5,15,9,131,5,15,9,131,4,15,11,131,1,13,
+ 15,9,131,9,15,13,130,3,15,13,1,130,5,15,9,131,5,15,9,131,5,15,9,131,
+ 5,15,9,131,6,15,9,129,3,9,14,15,7,129,5,31,11,1,129,128,1,7,9,6,
+ 1,129,5,128,1,12,47,14,10,13,15,5,1,10,5,1,4,10,30,7,168,128,17,129,
+ 13,15,5,128,12,14,4,139,129,5,9,8,2,130,9,47,14,4,128,4,15,7,1,2,
+ 28,128,7,13,130,4,15,1,6,14,2,129,8,14,128,1,13,14,10,11,15,8,129,2,
+ 11,14,13,7,201,128,8,5,130,9,3,128,1,13,15,5,128,10,15,9,129,2,13,15,
+ 12,15,9,131,2,31,11,132,10,47,5,130,10,15,9,2,13,15,5,128,1,12,9,129,
+ 2,13,6,155,2,105,20,111,7,172,2,121,41,7,128,4,127,47,12,198,128,13,14,1,
+ 3,15,9,128,8,15,3,128,12,11,169,129,2,131,17,131,2,130,6,15,12,129,1,14,
+ 15,4,129,9,15,9,129,5,14,10,129,1,12,14,3,129,8,14,7,128,128,5,13,14,
+ 7,128,1,14,47,20,63,7,1,14,47,4,128,5,13,14,7,146,129,1,13,14,1,130,
+ 9,15,5,130,5,15,9,131,12,15,1,131,5,15,9,132,9,15,5,131,1,13,14,1,
+ 142,128,1,14,13,1,132,4,15,10,133,8,15,6,132,1,30,132,8,15,6,131,4,15,
+ 10,131,1,14,13,1,146,
+};
+static const struct fos_glyph md_glyphs[] = {
+ { 0, 4, 0, 0, 0, 64 }, /* 0x20 */
+ { 0, 7, 14, 0, -14, 105 }, /* 0x21 */
+ { 47, 6, 14, 0, -14, 95 }, /* 0x22 */
+ { 68, 13, 13, 0, -13, 214 }, /* 0x23 */
+ { 170, 11, 17, 0, -15, 180 }, /* 0x24 */
+ { 277, 17, 14, 0, -14, 268 }, /* 0x25 */
+ { 405, 14, 14, 0, -14, 216 }, /* 0x26 */
+ { 523, 3, 14, 0, -14, 46 }, /* 0x27 */
+ { 535, 7, 17, -1, -15, 93 }, /* 0x28 */
+ { 604, 6, 17, 0, -15, 93 }, /* 0x29 */
+ { 674, 8, 15, 0, -15, 127 }, /* 0x2a */
+ { 716, 10, 10, 0, -10, 158 }, /* 0x2b */
+ { 744, 5, 5, 0, -3, 84 }, /* 0x2c */
+ { 763, 8, 7, 0, -7, 128 }, /* 0x2d */
+ { 770, 6, 3, 0, -2, 88 }, /* 0x2e */
+ { 781, 9, 14, 0, -14, 136 }, /* 0x2f */
+ { 835, 11, 14, 0, -14, 181 }, /* 0x30 */
+ { 948, 7, 14, 0, -14, 113 }, /* 0x31 */
+ { 1009, 11, 14, 0, -14, 174 }, /* 0x32 */
+ { 1090, 10, 14, 0, -14, 168 }, /* 0x33 */
+ { 1173, 11, 14, 0, -14, 182 }, /* 0x34 */
+ { 1242, 10, 14, 0, -14, 167 }, /* 0x35 */
+ { 1333, 10, 14, 0, -14, 167 }, /* 0x36 */
+ { 1444, 10, 14, 0, -14, 154 }, /* 0x37 */
+ { 1507, 11, 14, 0, -14, 169 }, /* 0x38 */
+ { 1618, 11, 14, 0, -14, 168 }, /* 0x39 */
+ { 1724, 7, 10, 0, -9, 111 }, /* 0x3a */
+ { 1745, 6, 11, 0, -9, 100 }, /* 0x3b */
+ { 1777, 10, 11, 0, -11, 158 }, /* 0x3c */
+ { 1834, 10, 9, 0, -9, 158 }, /* 0x3d */
+ { 1848, 10, 11, 0, -11, 158 }, /* 0x3e */
+ { 1903, 10, 14, 0, -14, 154 }, /* 0x3f */
+ { 1980, 16, 14, 0, -12, 263 }, /* 0x40 */
+ { 2143, 13, 14, 0, -14, 202 }, /* 0x41 */
+ { 2239, 12, 14, 0, -14, 200 }, /* 0x42 */
+ { 2344, 12, 14, 0, -14, 194 }, /* 0x43 */
+ { 2442, 12, 14, 0, -14, 198 }, /* 0x44 */
+ { 2551, 12, 14, 0, -14, 191 }, /* 0x45 */
+ { 2614, 11, 14, 0, -14, 181 }, /* 0x46 */
+ { 2675, 12, 14, 0, -14, 196 }, /* 0x47 */
+ { 2780, 13, 14, 0, -14, 206 }, /* 0x48 */
+ { 2890, 5, 14, 0, -14, 83 }, /* 0x49 */
+ { 2947, 12, 14, 0, -14, 185 }, /* 0x4a */
+ { 3019, 12, 14, 0, -14, 197 }, /* 0x4b */
+ { 3134, 11, 14, 0, -14, 182 }, /* 0x4c */
+ { 3192, 14, 14, 0, -14, 229 }, /* 0x4d */
+ { 3327, 13, 14, 0, -14, 215 }, /* 0x4e */
+ { 3463, 12, 14, 0, -14, 199 }, /* 0x4f */
+ { 3579, 12, 14, 0, -14, 190 }, /* 0x50 */
+ { 3664, 12, 16, 0, -14, 186 }, /* 0x51 */
+ { 3772, 12, 14, 0, -14, 196 }, /* 0x52 */
+ { 3879, 12, 14, 0, -14, 188 }, /* 0x53 */
+ { 3984, 11, 14, 0, -14, 184 }, /* 0x54 */
+ { 4044, 13, 14, 0, -14, 205 }, /* 0x55 */
+ { 4159, 12, 14, 0, -14, 192 }, /* 0x56 */
+ { 4254, 18, 14, 0, -14, 281 }, /* 0x57 */
+ { 4415, 12, 14, 0, -14, 193 }, /* 0x58 */
+ { 4517, 12, 14, 0, -14, 187 }, /* 0x59 */
+ { 4597, 11, 14, 0, -14, 176 }, /* 0x5a */
+ { 4659, 8, 18, 0, -16, 126 }, /* 0x5b */
+ { 4733, 9, 14, 0, -14, 136 }, /* 0x5c */
+ { 4790, 8, 18, 0, -16, 126 }, /* 0x5d */
+ { 4864, 9, 14, 0, -14, 147 }, /* 0x5e */
+ { 4914, 10, 2, 0, -2, 159 }, /* 0x5f */
+ { 4920, 4, 14, 0, -14, 67 }, /* 0x60 */
+ { 4931, 10, 10, 0, -10, 165 }, /* 0x61 */
+ { 5005, 11, 14, 0, -14, 177 }, /* 0x62 */
+ { 5107, 11, 10, 0, -10, 168 }, /* 0x63 */
+ { 5184, 11, 14, 0, -14, 177 }, /* 0x64 */
+ { 5286, 11, 10, 0, -10, 172 }, /* 0x65 */
+ { 5358, 7, 14, 0, -14, 117 }, /* 0x66 */
+ { 5421, 11, 14, 0, -10, 174 }, /* 0x67 */
+ { 5524, 11, 14, 0, -14, 173 }, /* 0x68 */
+ { 5623, 5, 14, 0, -14, 82 }, /* 0x69 */
+ { 5674, 6, 18, -1, -14, 79 }, /* 0x6a */
+ { 5743, 10, 14, 0, -14, 164 }, /* 0x6b */
+ { 5836, 5, 14, 0, -14, 75 }, /* 0x6c */
+ { 5893, 17, 10, 0, -10, 264 }, /* 0x6d */
+ { 6019, 11, 10, 0, -10, 173 }, /* 0x6e */
+ { 6102, 11, 10, 0, -10, 178 }, /* 0x6f */
+ { 6185, 11, 14, 0, -10, 179 }, /* 0x70 */
+ { 6284, 11, 14, 0, -10, 179 }, /* 0x71 */
+ { 6386, 8, 10, 0, -10, 119 }, /* 0x72 */
+ { 6433, 10, 10, 0, -10, 156 }, /* 0x73 */
+ { 6504, 7, 13, 0, -13, 118 }, /* 0x74 */
+ { 6554, 11, 10, 0, -10, 172 }, /* 0x75 */
+ { 6636, 10, 10, 0, -10, 157 }, /* 0x76 */
+ { 6700, 15, 10, 0, -10, 238 }, /* 0x77 */
+ { 6814, 10, 10, 0, -10, 160 }, /* 0x78 */
+ { 6883, 10, 14, 0, -10, 152 }, /* 0x79 */
+ { 6967, 9, 10, 0, -10, 144 }, /* 0x7a */
+ { 7010, 7, 18, 0, -16, 105 }, /* 0x7b */
+ { 7078, 4, 16, 0, -14, 57 }, /* 0x7c */
+ { 7142, 7, 18, 0, -16, 105 }, /* 0x7d */
+ { 7219, 10, 7, 0, -7, 164 }, /* 0x7e */
+ { 7245, 4, 6, 0, -6, 70 }, /* 0x80 */
+ { 7256, 8, 16, 0, -16, 121 }, /* 0x81 */
+ { 7301, 9, 10, 0, -10, 138 }, /* 0x82 */
+ { 7348, 9, 7, 0, -7, 147 }, /* 0x83 */
+ { 7354, 14, 7, 0, -7, 216 }, /* 0x84 */
+ { 7364, 4, 14, 0, -14, 52 }, /* 0x85 */
+ { 7379, 16, 3, 0, -2, 261 }, /* 0x86 */
+ { 7412, 6, 8, 0, -8, 100 }, /* 0x87 */
+ { 7434, 7, 9, 0, -9, 113 }, /* 0x88 */
+ { 7465, 8, 9, 0, -9, 123 }, /* 0x89 */
+};
+static const uint8_t md_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern md_kern[] = {
+ {39,45,-16},{39,52,-4},{39,65,-23},{39,74,-13},{39,99,-16},{39,100,-16},{39,101,-16},{39,103,-12},
+ {39,109,-5},{39,110,-5},{39,111,-16},{39,112,-5},{39,113,-12},{39,114,-5},{39,115,-8},{44,45,-5},
+ {44,48,-10},{44,84,-14},{44,86,-7},{44,87,-7},{44,89,-14},{44,99,-5},{44,100,-5},{44,101,-5},
+ {44,102,-4},{44,103,-5},{44,111,-5},{44,113,-5},{44,116,-4},{44,117,-4},{44,118,-13},{44,119,-13},
+ {44,121,-13},{45,39,-6},{45,44,-4},{45,45,-40},{45,46,-4},{45,55,-16},{45,84,-14},{45,118,-7},
+ {45,119,-7},{45,120,-5},{45,121,-7},{45,133,-8},{46,45,-5},{46,48,-10},{46,84,-14},{46,86,-7},
+ {46,87,-7},{46,89,-14},{46,99,-5},{46,100,-5},{46,101,-5},{46,102,-4},{46,103,-5},{46,111,-5},
+ {46,113,-5},{46,116,-4},{46,117,-4},{46,118,-13},{46,119,-13},{46,121,-13},{48,49,-7},{50,49,-4},
+ {52,39,-7},{52,49,-30},{52,55,-14},{53,49,-7},{54,49,-4},{55,44,-17},{55,46,-17},{56,49,-7},
+ {57,49,-6},{65,39,-26},{65,45,-4},{65,67,-5},{65,71,-5},{65,74,4},{65,79,-5},{65,81,-5},
+ {65,83,-12},{65,84,-23},{65,86,-12},{65,87,-12},{65,89,-25},{65,90,5},{65,99,-4},{65,100,-4},
+ {65,101,-4},{65,102,-6},{65,103,-7},{65,111,-4},{65,113,-7},{65,116,-6},{65,118,-12},{65,119,-12},
+ {65,121,-12},{65,133,-20},{66,44,-4},{66,46,-4},{66,65,-9},{66,84,-4},{66,86,-7},{66,87,-7},
+ {66,88,-6},{66,89,-8},{66,102,-4},{66,103,-5},{66,113,-5},{66,115,-5},{66,116,-4},{66,117,-4},
+ {67,74,5},{67,89,-5},{68,44,-4},{68,46,-4},{68,65,-9},{68,84,-4},{68,86,-7},{68,87,-7},
+ {68,88,-6},{68,89,-8},{68,102,-4},{68,103,-5},{68,113,-5},{68,115,-5},{68,116,-4},{68,117,-4},
+ {69,86,4},{69,87,4},{70,44,-25},{70,45,-15},{70,46,-25},{70,65,-19},{70,74,-15},{70,97,-12},
+ {70,99,-15},{70,100,-15},{70,101,-15},{70,103,-9},{70,109,-6},{70,110,-6},{70,111,-15},{70,112,-6},
+ {70,113,-9},{70,114,-6},{70,115,-12},{70,117,-7},{70,118,-13},{70,119,-13},{70,120,-11},{70,121,-13},
+ {70,122,-6},{71,74,5},{71,89,-5},{74,44,-4},{74,46,-4},{74,65,-4},{74,67,-4},{74,71,-4},
+ {74,79,-4},{74,81,-4},{75,45,-7},{75,65,7},{75,67,-6},{75,71,-6},{75,74,-4},{75,79,-6},
+ {75,81,-6},{75,83,-4},{75,88,4},{75,99,-7},{75,100,-7},{75,101,-7},{75,103,-6},{75,111,-7},
+ {75,113,-6},{75,118,-10},{75,119,-10},{75,121,-10},{76,39,-20},{76,65,11},{76,84,-28},{76,86,-11},
+ {76,87,-11},{76,89,-10},{76,102,-4},{76,116,-4},{76,118,-6},{76,119,-6},{76,121,-6},{76,133,-12},
+ {78,66,-4},{78,68,-4},{78,69,-4},{78,70,-4},{78,78,-4},{78,80,-4},{79,74,5},{79,89,-5},
+ {80,44,-9},{80,45,-7},{80,46,-9},{80,65,-11},{80,74,-6},{80,86,-4},{80,87,-4},{80,88,-7},
+ {80,89,-7},{80,99,-7},{80,100,-7},{80,101,-7},{80,103,-4},{80,111,-7},{80,113,-4},{80,115,-4},
+ {81,65,-5},{81,74,5},{81,86,-7},{81,87,-7},{81,88,-7},{81,89,-14},{82,65,9},{82,86,-4},
+ {82,87,-4},{82,88,4},{82,89,-6},{83,44,-4},{83,46,-4},{83,84,-5},{83,86,-4},{83,87,-4},
+ {83,88,-9},{83,89,-5},{84,44,-14},{84,45,-24},{84,46,-14},{84,65,-19},{84,67,-13},{84,71,-13},
+ {84,74,-10},{84,79,-13},{84,81,-13},{84,97,-7},{84,99,-24},{84,100,-24},{84,101,-24},{84,103,-19},
+ {84,105,-4},{84,109,-17},{84,110,-17},{84,111,-24},{84,112,-17},{84,113,-19},{84,114,-17},{84,115,-17},
+ {84,117,-14},{84,118,-13},{84,119,-13},{84,120,-16},{84,121,-13},{85,44,-4},{85,46,-4},{85,65,-4},
+ {85,67,-4},{85,71,-4},{85,79,-4},{85,81,-4},{86,44,-19},{86,45,-17},{86,46,-19},{86,65,-31},
+ {86,66,-4},{86,67,-8},{86,68,-4},{86,69,-4},{86,70,-4},{86,71,-8},{86,74,-10},{86,75,-7},
+ {86,78,-4},{86,79,-8},{86,80,-4},{86,81,-8},{86,83,-4},{86,97,-17},{86,99,-17},{86,100,-17},
+ {86,101,-17},{86,103,-15},{86,109,-4},{86,110,-4},{86,111,-17},{86,112,-4},{86,113,-15},{86,114,-4},
+ {86,115,-10},{86,117,-4},{86,118,-4},{86,119,-4},{86,121,-4},{87,44,-19},{87,45,-17},{87,46,-19},
+ {87,65,-31},{87,66,-4},{87,67,-8},{87,68,-4},{87,69,-4},{87,70,-4},{87,71,-8},{87,74,-10},
+ {87,75,-7},{87,78,-4},{87,79,-8},{87,80,-4},{87,81,-8},{87,83,-4},{87,97,-17},{87,99,-17},
+ {87,100,-17},{87,101,-17},{87,103,-15},{87,109,-4},{87,110,-4},{87,111,-17},{87,112,-4},{87,113,-15},
+ {87,114,-4},{87,115,-10},{87,117,-4},{87,118,-4},{87,119,-4},{87,121,-4},{88,45,-8},{88,67,-6},
+ {88,71,-6},{88,79,-6},{88,81,-6},{88,83,-8},{88,97,-4},{88,99,-8},{88,100,-8},{88,101,-8},
+ {88,103,-8},{88,111,-8},{88,113,-8},{88,118,-7},{88,119,-7},{88,121,-7},{89,44,-28},{89,45,-22},
+ {89,46,-28},{89,65,-31},{89,66,-4},{89,67,-9},{89,68,-4},{89,69,-4},{89,70,-4},{89,71,-9},
+ {89,74,-13},{89,78,-4},{89,79,-9},{89,80,-4},{89,81,-9},{89,83,-6},{89,97,-17},{89,99,-22},
+ {89,100,-22},{89,101,-22},{89,102,-11},{89,103,-25},{89,109,-16},{89,110,-16},{89,111,-22},{89,112,-16},
+ {89,113,-25},{89,114,-16},{89,115,-11},{89,116,-11},{89,117,-11},{89,118,-11},{89,119,-11},{89,120,-11},
+ {89,121,-11},{89,122,-6},{97,39,-8},{97,84,-7},{97,89,-9},{97,133,-4},{98,39,-11},{98,44,-5},
+ {98,46,-5},{98,118,-4},{98,119,-4},{98,121,-4},{99,39,-6},{99,44,-8},{99,46,-8},{99,120,-4},
+ {99,133,-4},{101,39,-9},{101,44,-6},{101,46,-6},{101,118,-6},{101,119,-6},{101,120,-6},{101,121,-6},
+ {101,133,-6},{102,39,4},{102,44,-16},{102,45,-13},{102,46,-16},{102,97,-4},{102,99,-13},{102,100,-13},
+ {102,101,-13},{102,103,-11},{102,111,-13},{102,113,-11},{102,115,-5},{102,133,5},{103,39,-4},{104,39,-11},
+ {104,44,-5},{104,46,-5},{104,118,-4},{104,119,-4},{104,121,-4},{107,45,-9},{107,97,-4},{107,99,-9},
+ {107,100,-9},{107,101,-9},{107,103,-7},{107,111,-9},{107,113,-7},{109,39,-11},{109,44,-5},{109,46,-5},
+ {109,118,-4},{109,119,-4},{109,121,-4},{110,39,-11},{110,44,-5},{110,46,-5},{110,118,-4},{110,119,-4},
+ {110,121,-4},{111,39,-6},{111,44,-4},{111,46,-4},{111,55,-16},{111,84,-14},{111,118,-7},{111,119,-7},
+ {111,120,-5},{111,121,-7},{111,133,-8},{112,39,-11},{112,44,-5},{112,46,-5},{112,118,-4},{112,119,-4},
+ {112,121,-4},{113,39,-4},{114,39,9},{114,44,-12},{114,46,-12},{114,102,4},{114,103,-5},{114,113,-5},
+ {114,116,4},{114,118,7},{114,119,7},{114,121,7},{114,133,16},{115,39,-7},{115,115,-4},{115,118,-10},
+ {115,119,-10},{115,121,-10},{115,133,-6},{116,45,-4},{116,99,-4},{116,100,-4},{116,101,-4},{116,111,-4},
+ {118,44,-13},{118,45,-7},{118,46,-13},{118,97,-5},{118,99,-7},{118,100,-7},{118,101,-7},{118,103,-8},
+ {118,111,-7},{118,113,-8},{118,115,-10},{118,133,16},{119,44,-13},{119,45,-7},{119,46,-13},{119,97,-5},
+ {119,99,-7},{119,100,-7},{119,101,-7},{119,103,-8},{119,111,-7},{119,113,-8},{119,115,-10},{119,133,16},
+ {120,45,-8},{120,99,-8},{120,100,-8},{120,101,-8},{120,103,-5},{120,111,-8},{120,113,-5},{121,44,-13},
+ {121,45,-7},{121,46,-13},{121,97,-5},{121,99,-7},{121,100,-7},{121,101,-7},{121,103,-8},{121,111,-7},
+ {121,113,-8},{121,115,-10},{121,133,16},{133,45,-25},{133,65,-20},{133,97,-7},{133,99,-25},{133,100,-25},
+ {133,101,-25},{133,103,-21},{133,111,-25},{133,113,-21},{133,115,-20},{133,118,-4},{133,119,-4},{133,121,-4},
+};
+const struct fos_font fos_font_md_data = { md_bits, md_glyphs, md_lut, md_kern, 544, 20, 4 };
+
+static const uint8_t mdb_bits[] = {
+ 129,11,15,8,131,11,15,8,131,11,15,7,131,11,15,7,131,10,15,7,131,10,15,6,
+ 131,10,15,6,131,9,15,6,131,9,15,5,131,8,15,5,145,10,14,4,130,1,31,10,
+ 131,11,14,4,129,8,15,9,1,31,1,8,15,9,128,31,1,7,15,8,128,31,128,7,
+ 15,7,128,14,15,128,6,15,6,128,13,14,198,131,14,15,5,128,1,31,4,132,2,31,
+ 3,128,3,31,2,132,4,31,1,128,5,31,131,2,127,31,6,129,2,127,31,6,130,2,
+ 12,15,10,18,13,15,9,2,132,13,15,8,129,14,15,6,133,14,15,6,129,31,5,131,
+ 1,2,31,6,2,3,31,5,1,130,13,127,15,10,130,13,127,15,10,131,7,15,13,129,
+ 8,15,12,133,10,15,10,129,11,15,9,133,12,15,8,129,13,15,6,131,131,6,15,9,
+ 135,6,15,9,133,3,11,47,11,4,130,3,14,95,5,129,10,15,12,3,1,3,12,15,
+ 14,1,128,13,15,4,130,1,31,4,128,13,15,5,131,11,13,4,128,9,15,14,5,134,
+ 1,13,31,12,6,133,1,9,47,13,6,133,2,8,14,31,8,134,1,9,31,18,30,132,
+ 13,15,6,1,31,3,131,13,15,6,128,13,15,13,4,17,7,31,3,128,4,111,10,130,
+ 4,12,47,14,8,133,6,15,11,135,5,15,10,131,129,3,12,15,12,4,131,13,11,132,
+ 2,14,10,3,9,15,2,129,6,15,4,132,7,14,130,14,8,128,1,14,11,133,7,14,
+ 130,14,8,128,7,15,3,133,3,15,7,1,7,15,3,1,14,11,135,6,14,15,14,6,
+ 128,8,15,3,137,2,1,128,1,14,10,141,8,15,2,140,1,14,9,141,9,15,2,128,
+ 6,13,14,10,2,134,2,15,9,128,6,15,6,4,28,134,9,15,2,128,12,10,129,3,
+ 15,3,132,2,15,8,129,12,10,129,3,15,3,132,10,14,1,129,6,15,6,3,12,13,
+ 132,2,15,8,131,7,13,14,11,2,129,130,6,12,15,14,10,2,134,7,79,14,1,133,
+ 14,15,11,2,4,14,15,8,132,1,31,4,129,10,15,10,133,14,15,8,128,1,13,15,
+ 8,133,7,31,5,12,31,2,134,11,63,5,134,1,11,47,4,134,1,13,31,14,15,10,
+ 129,2,1,130,10,15,14,20,31,8,1,13,14,4,129,31,6,129,6,31,13,15,13,1,
+ 128,2,31,4,130,9,47,3,130,14,15,11,19,7,14,31,14,1,130,8,95,14,13,15,
+ 11,131,5,11,14,15,12,8,1,3,14,15,7,128,8,15,11,8,15,10,7,15,9,7,
+ 15,9,5,15,8,157,130,11,15,8,130,5,31,2,130,12,15,10,130,3,31,5,130,7,
+ 31,1,130,10,15,14,131,13,15,11,131,14,15,10,131,31,9,131,31,9,131,14,15,10,
+ 131,13,15,11,131,11,15,13,131,7,31,1,130,3,31,5,131,12,15,10,131,6,31,2,
+ 131,12,15,8,128,128,3,31,2,131,11,15,11,131,5,31,2,130,1,31,8,131,12,15,
+ 12,131,9,31,1,130,6,31,3,130,5,31,4,130,4,31,5,130,4,31,5,130,5,31,
+ 4,130,6,31,3,130,9,31,131,12,15,12,130,1,31,7,130,6,31,2,130,12,15,10,
+ 130,3,15,14,2,129,130,26,130,1,5,128,11,10,128,5,128,5,15,60,15,5,128,5,
+ 13,31,13,4,129,5,13,31,13,4,128,5,15,12,13,28,15,4,1,5,128,11,10,128,
+ 6,131,26,194,130,1,15,13,134,1,15,14,134,1,15,14,132,18,3,15,14,34,128,5,
+ 127,2,5,127,2,130,1,15,14,134,1,15,14,134,1,15,13,151,128,4,15,11,129,7,
+ 15,7,129,10,15,3,129,12,14,130,14,10,129,128,82,128,5,95,6,5,95,6,167,128,
+ 5,14,10,129,11,31,129,5,14,9,128,132,10,15,9,132,1,14,15,5,132,5,15,14,
+ 133,10,15,9,132,1,14,15,4,132,5,15,14,133,10,15,9,132,1,31,4,132,5,15,
+ 14,133,11,15,9,132,1,31,4,132,6,15,14,133,11,15,9,132,1,31,4,132,5,15,
+ 13,133,129,1,8,13,15,14,10,3,130,1,13,95,4,129,8,31,7,2,4,13,15,13,
+ 129,12,15,9,130,4,31,2,128,13,15,7,130,1,31,4,128,14,15,6,130,1,31,4,
+ 128,14,15,6,130,1,31,4,128,14,15,6,130,1,31,4,128,14,15,6,130,1,31,4,
+ 128,14,15,6,130,1,31,4,128,13,15,7,130,1,31,4,128,12,15,9,130,4,31,2,
+ 128,7,31,7,2,4,13,15,13,129,1,12,95,4,130,1,8,13,15,14,10,3,129,128,
+ 1,8,31,10,128,1,14,47,10,128,1,15,29,15,10,129,2,128,10,15,10,131,10,15,
+ 10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,
+ 10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,128,129,2,10,14,15,13,
+ 8,1,130,3,14,79,12,130,12,15,14,5,2,7,31,6,129,31,6,130,11,15,10,128,
+ 1,30,4,130,10,15,11,134,1,14,15,7,134,10,15,14,1,133,6,31,7,133,3,31,
+ 11,133,2,14,15,13,1,132,1,12,15,14,3,133,10,31,4,133,8,31,8,66,129,127,
+ 15,1,128,127,15,1,128,127,7,129,127,7,129,1,34,3,14,31,4,132,1,12,31,5,
+ 132,1,12,31,6,133,11,31,12,2,133,11,63,5,132,1,5,2,9,15,14,1,135,14,
+ 15,6,135,12,15,8,128,2,14,13,2,130,12,15,8,128,1,31,5,129,1,14,15,7,
+ 129,11,15,13,4,2,10,31,2,129,2,14,79,7,131,2,10,30,12,5,130,131,8,15,
+ 14,135,1,14,15,8,135,6,31,1,135,12,15,10,135,4,31,3,135,10,15,12,135,2,
+ 31,6,129,12,15,7,130,8,15,14,130,12,15,8,130,14,15,10,35,13,15,9,2,128,
+ 3,127,15,10,128,3,127,15,10,135,12,15,8,136,12,15,8,136,12,15,8,136,12,15,
+ 7,129,128,14,111,4,129,14,111,4,129,14,15,7,66,130,14,15,5,135,14,15,5,135,
+ 14,15,9,12,14,13,8,1,130,14,95,12,130,14,15,14,5,2,7,31,6,129,9,10,
+ 5,130,12,15,9,135,9,15,11,129,21,2,130,9,15,11,129,13,15,9,130,13,15,9,
+ 129,8,31,6,2,8,31,4,129,1,12,79,10,131,1,8,13,14,13,7,130,129,3,10,
+ 14,15,13,7,131,3,95,10,130,11,15,14,5,3,10,31,3,129,14,15,7,130,14,15,
+ 7,129,31,5,130,8,9,4,129,31,5,128,1,133,31,9,13,31,11,2,130,111,14,1,
+ 129,31,14,4,1,6,31,7,129,31,7,130,10,15,11,129,14,15,5,130,8,15,12,129,
+ 13,15,8,130,11,15,10,129,8,15,14,5,2,7,31,6,129,1,13,79,12,131,1,9,
+ 13,15,13,8,1,129,7,127,6,7,127,6,7,15,8,34,4,31,4,3,7,3,130,8,
+ 15,14,134,13,15,9,133,4,31,3,133,9,15,13,134,14,15,8,133,5,31,2,133,10,
+ 15,12,133,1,14,15,7,133,5,31,2,133,11,15,11,133,1,31,6,133,6,15,14,1,
+ 131,129,2,9,14,15,13,7,131,2,14,79,10,130,9,15,14,5,2,8,31,3,129,13,
+ 15,8,130,13,15,7,129,13,15,7,130,12,15,7,129,9,15,14,5,2,8,31,3,129,
+ 1,13,79,7,130,2,13,79,9,130,10,15,13,3,1,6,31,5,129,31,6,130,11,15,
+ 9,128,1,31,4,130,9,15,11,129,31,7,130,12,15,9,129,11,15,14,5,3,8,31,
+ 5,129,2,14,79,11,131,2,10,14,15,13,7,130,129,3,11,30,12,5,131,4,95,7,
+ 130,13,15,12,3,2,9,31,2,128,2,31,4,130,14,15,6,128,4,31,1,130,12,15,
+ 8,128,3,31,3,130,14,15,8,129,14,15,12,2,1,9,31,8,129,7,111,8,130,7,
+ 14,31,9,13,15,8,132,1,129,12,15,8,129,8,9,3,130,12,15,8,129,13,15,8,
+ 130,14,15,8,129,10,15,14,5,2,9,31,4,129,3,14,79,11,131,2,10,14,15,13,
+ 7,130,129,7,14,8,131,13,15,13,131,7,14,7,152,7,14,8,131,13,15,13,131,7,
+ 14,7,136,128,1,12,14,5,129,6,31,11,129,1,12,14,5,154,12,15,3,130,14,15,
+ 130,1,15,12,130,3,15,8,130,4,15,5,129,135,1,134,2,8,14,2,131,3,10,47,
+ 2,129,5,11,47,10,3,128,3,13,31,13,7,1,130,5,31,9,133,3,14,31,12,6,
+ 1,131,1,6,13,31,14,8,2,132,5,11,47,2,133,3,10,15,2,135,2,1,5,127,
+ 2,5,127,2,147,5,127,2,5,127,2,157,1,136,5,14,7,1,133,5,31,14,9,2,
+ 132,5,11,47,10,3,132,2,9,14,31,11,1,132,1,11,31,2,130,1,7,13,31,13,
+ 1,128,3,10,47,11,5,129,5,47,10,3,131,5,14,9,2,133,17,135,129,4,11,14,
+ 15,12,5,130,6,95,7,128,1,14,15,11,19,11,31,1,4,31,1,129,2,31,4,3,
+ 10,9,130,2,31,4,133,11,15,14,1,131,1,11,31,6,131,1,12,31,6,132,6,31,
+ 4,133,8,15,12,134,3,7,5,144,6,14,8,134,12,15,14,134,6,14,8,131,132,2,
+ 7,12,30,13,8,2,134,7,111,14,5,132,9,31,9,5,18,5,10,31,3,130,6,15,
+ 13,3,133,6,15,12,129,1,30,2,135,11,15,2,128,7,15,6,129,8,30,10,15,4,
+ 128,6,15,5,128,11,14,129,8,15,6,4,14,15,2,128,4,15,6,128,14,11,129,14,
+ 9,129,10,15,129,4,15,6,1,15,9,128,2,15,5,129,12,13,129,7,15,3,128,15,
+ 9,128,4,15,6,128,2,15,13,129,12,14,129,14,12,128,1,15,14,10,13,31,10,12,
+ 15,6,129,10,15,2,128,5,13,14,11,3,10,14,13,7,130,5,15,12,1,140,11,15,
+ 13,7,3,2,4,6,11,2,133,1,12,95,14,4,135,6,12,14,15,13,8,2,132,131,
+ 2,47,1,135,6,47,6,135,11,47,10,134,1,31,11,15,14,134,5,31,2,31,4,133,
+ 9,15,11,128,12,15,9,133,14,15,6,128,7,15,13,132,3,31,2,128,3,31,3,131,
+ 8,15,12,130,13,15,7,131,12,15,7,130,8,15,12,130,2,31,78,31,1,129,6,127,
+ 15,6,129,11,15,10,132,10,15,10,128,1,31,6,132,7,15,14,128,4,31,2,132,3,
+ 31,4,128,8,79,14,11,4,130,8,127,5,129,8,15,12,34,4,13,15,13,129,8,15,
+ 12,131,4,31,1,128,8,15,12,131,3,31,1,128,8,15,12,130,2,12,15,13,129,8,
+ 111,14,3,129,8,111,9,130,8,15,12,34,4,13,15,9,129,8,15,12,131,3,31,2,
+ 128,8,15,12,131,1,31,4,128,8,15,12,131,3,31,4,128,8,15,12,34,4,13,15,
+ 14,1,128,8,127,6,129,8,79,14,11,4,129,130,5,11,30,12,7,1,131,9,95,13,
+ 1,129,5,31,10,19,7,31,9,129,10,15,12,131,8,15,14,129,12,15,7,131,3,31,
+ 1,128,13,15,7,136,13,15,7,136,13,15,7,136,13,15,7,136,13,15,7,136,12,15,
+ 7,131,3,31,1,128,10,15,12,131,8,15,14,129,5,31,10,19,7,31,9,130,9,95,
+ 12,1,131,5,11,30,12,7,1,129,128,8,79,14,10,3,130,8,127,4,129,8,15,12,
+ 34,5,13,15,14,129,8,15,12,131,4,31,3,128,8,15,12,132,31,5,128,8,15,12,
+ 132,31,5,128,8,15,12,132,31,5,128,8,15,12,132,31,5,128,8,15,12,132,31,5,
+ 128,8,15,12,132,31,5,128,8,15,12,132,31,5,128,8,15,12,131,4,31,3,128,8,
+ 15,12,34,5,13,15,14,129,8,127,4,129,8,79,14,10,3,129,128,8,127,14,129,8,
+ 127,14,129,8,15,12,82,1,129,8,15,12,136,8,15,12,136,8,15,12,136,8,15,12,
+ 50,1,131,8,95,10,131,8,95,10,131,8,15,12,136,8,15,12,136,8,15,12,136,8,
+ 15,12,82,1,129,8,127,14,129,8,127,14,128,128,8,127,14,128,8,127,14,128,8,15,
+ 12,82,1,128,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,50,1,130,8,95,
+ 10,130,8,95,10,130,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,
+ 12,135,8,15,11,134,130,5,11,30,12,7,132,9,95,12,1,129,4,31,10,19,7,31,
+ 9,129,10,15,12,131,7,15,14,129,12,15,8,131,3,31,1,128,13,15,7,136,13,15,
+ 7,129,1,50,129,13,15,7,129,79,2,128,13,15,7,129,79,2,128,13,15,7,131,3,
+ 31,2,128,12,15,8,131,3,31,1,128,10,15,12,131,7,15,14,129,4,31,11,4,2,
+ 6,14,15,8,130,9,95,12,1,131,5,11,14,15,13,8,1,129,128,8,15,11,132,14,
+ 15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,
+ 15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,66,14,
+ 15,6,129,8,127,15,6,129,8,127,15,6,129,8,15,12,132,14,15,6,129,8,15,12,
+ 132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,
+ 132,14,15,6,129,8,15,11,132,14,15,6,128,128,8,15,11,129,8,15,12,129,8,15,
+ 12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,
+ 12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,
+ 11,128,134,2,31,2,135,2,31,2,135,2,31,2,135,2,31,2,135,2,31,2,135,2,
+ 31,2,135,2,31,2,135,2,31,2,128,3,5,4,131,2,31,2,128,8,15,12,131,2,
+ 31,2,128,8,15,12,131,3,31,2,128,6,15,14,1,130,7,31,129,1,31,12,4,2,
+ 6,14,15,10,130,6,95,13,1,131,4,11,14,15,13,8,1,130,128,8,15,11,131,3,
+ 14,15,7,128,8,15,12,130,1,13,15,11,129,8,15,12,130,11,15,14,1,129,8,15,
+ 12,129,8,31,4,130,8,15,12,128,4,31,7,131,8,15,12,2,14,15,11,132,8,15,
+ 28,31,2,132,8,79,9,132,8,47,10,31,3,131,8,31,5,128,13,15,12,131,8,15,
+ 12,129,4,31,6,130,8,15,12,130,10,15,14,1,129,8,15,12,130,1,14,15,9,129,
+ 8,15,12,131,6,31,3,128,8,15,11,132,12,15,12,128,8,15,11,135,8,15,12,135,
+ 8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,
+ 8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,82,1,128,8,127,
+ 12,128,8,127,12,128,8,15,14,1,132,11,15,12,129,8,31,9,131,5,31,13,129,8,
+ 47,4,129,1,13,31,13,129,8,47,12,129,8,47,13,129,8,15,14,31,7,3,31,13,
+ 15,13,129,8,15,12,8,15,14,12,15,12,7,15,13,129,8,15,12,128,13,47,3,7,
+ 15,13,129,8,15,12,128,4,31,9,128,7,15,13,129,8,15,12,129,8,11,1,128,7,
+ 15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,
+ 15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,15,13,129,8,15,11,133,7,
+ 15,12,128,128,8,15,13,1,131,6,15,14,129,8,31,8,131,6,15,14,129,8,31,14,
+ 2,130,6,15,14,129,8,47,10,130,6,15,14,129,8,63,3,129,6,15,14,129,8,15,
+ 27,15,11,129,6,15,14,129,8,15,11,3,31,5,128,6,15,14,129,8,15,11,128,9,
+ 15,13,128,6,15,14,129,8,15,11,128,1,14,15,7,6,15,14,129,8,15,11,129,7,
+ 15,14,7,15,14,129,8,15,11,130,13,15,14,15,14,129,8,15,11,130,4,47,14,129,
+ 8,15,12,131,11,31,14,129,8,15,12,131,2,31,14,129,8,15,11,132,8,15,14,128,
+ 130,4,11,30,13,7,1,131,7,95,12,1,129,3,31,11,4,3,7,31,10,129,9,15,
+ 12,131,7,31,1,128,12,15,8,131,2,31,3,128,13,15,7,132,31,4,128,13,15,7,
+ 132,31,4,128,13,15,7,132,31,4,128,13,15,7,132,31,4,128,13,15,7,132,31,4,
+ 128,12,15,8,131,2,31,3,128,10,15,12,131,6,31,1,128,4,31,11,4,3,7,14,
+ 15,10,130,8,95,13,1,131,4,11,30,13,7,1,129,128,10,79,14,11,4,130,10,127,
+ 5,129,10,15,11,34,4,13,15,13,129,10,15,10,131,4,31,3,128,10,15,10,131,1,
+ 31,4,128,10,15,10,131,3,31,3,128,10,15,11,34,4,13,15,13,129,10,127,5,129,
+ 10,79,14,11,4,130,10,15,10,136,10,15,10,136,10,15,10,136,10,15,10,136,10,15,
+ 10,136,10,15,10,135,130,6,12,30,11,4,132,11,95,7,130,7,31,8,19,11,31,3,
+ 129,12,15,10,131,13,15,8,129,31,5,131,9,15,11,128,1,31,4,131,8,15,12,128,
+ 1,31,4,131,8,15,12,128,1,31,4,131,8,15,12,128,1,31,4,131,8,15,12,128,
+ 1,31,4,131,8,15,12,129,31,5,131,9,15,11,129,13,15,9,131,12,15,9,129,7,
+ 31,6,1,2,9,31,3,129,1,11,95,8,132,7,13,31,12,5,134,4,31,1,135,4,
+ 31,1,131,128,8,79,14,12,4,130,8,127,5,129,8,15,12,34,4,12,15,13,129,8,
+ 15,12,131,3,31,3,128,8,15,12,132,31,5,128,8,15,12,131,3,31,3,128,8,15,
+ 12,34,4,12,15,14,1,128,8,127,6,129,8,95,13,5,130,8,15,12,129,6,15,13,
+ 131,8,15,12,130,14,15,5,130,8,15,12,130,7,15,13,130,8,15,12,130,1,14,15,
+ 5,129,8,15,12,131,8,15,12,129,8,15,11,131,2,31,4,129,1,9,13,15,14,11,
+ 6,131,2,14,95,10,130,10,15,14,5,2,3,10,31,6,129,13,15,7,131,11,15,11,
+ 129,13,15,7,131,6,14,11,129,9,15,14,6,135,1,13,31,13,8,2,133,1,8,14,
+ 47,9,1,133,1,6,12,31,13,2,135,5,14,15,10,128,2,31,1,131,7,15,13,128,
+ 1,31,5,131,8,15,13,129,12,15,14,7,3,2,6,14,15,9,129,2,14,95,13,1,
+ 130,1,8,13,14,15,13,8,1,129,4,127,15,13,128,5,127,15,14,129,34,8,15,13,
+ 34,1,132,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,
+ 15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,6,
+ 15,13,132,128,10,15,10,132,14,15,5,129,10,15,10,132,14,15,6,129,10,15,10,132,
+ 14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,
+ 14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,
+ 14,15,6,129,10,15,10,132,14,15,6,129,9,15,11,132,31,5,129,7,15,14,1,130,
+ 5,31,2,129,1,14,15,12,4,2,6,14,15,12,131,5,95,14,2,132,3,10,14,15,
+ 13,9,2,130,4,31,2,132,13,15,8,1,31,6,131,2,31,4,128,11,15,10,131,6,
+ 15,14,129,7,15,14,131,10,15,10,129,2,31,3,130,14,15,5,130,13,15,7,129,3,
+ 31,1,130,9,15,11,129,7,15,12,131,4,31,1,128,11,15,7,131,1,31,4,1,31,
+ 3,132,11,15,8,4,15,13,133,6,15,12,8,15,9,133,2,31,13,15,5,134,13,47,
+ 1,134,8,31,11,135,4,31,6,131,6,15,14,1,130,7,31,1,130,5,15,14,128,3,
+ 31,4,130,11,31,4,130,9,15,11,129,14,15,7,130,14,31,8,130,13,15,8,129,10,
+ 15,11,129,3,47,12,129,1,31,4,129,6,15,14,129,6,63,129,4,31,1,129,3,31,
+ 3,128,9,15,12,31,4,128,8,15,12,131,14,15,6,128,13,15,6,13,15,7,128,11,
+ 15,8,131,10,15,10,1,31,3,10,15,11,128,14,15,5,131,6,15,13,5,15,14,128,
+ 6,15,14,3,31,1,131,3,31,10,15,11,128,2,31,9,15,13,133,14,47,7,129,14,
+ 47,9,133,10,47,3,129,10,47,5,133,6,47,130,6,47,2,133,3,31,11,130,2,31,
+ 13,135,13,15,8,131,13,15,9,131,2,31,6,131,1,14,15,7,128,9,15,14,1,130,
+ 10,15,13,1,128,2,14,15,8,129,3,31,6,130,8,31,2,128,12,15,12,131,1,14,
+ 15,11,6,31,4,132,6,63,11,134,13,47,3,134,6,31,11,135,12,47,2,133,5,63,
+ 10,133,13,15,11,6,31,3,131,7,31,2,128,12,15,12,130,1,14,15,8,129,4,31,
+ 5,129,9,15,14,1,130,10,15,13,128,2,31,5,131,1,14,15,7,3,31,4,131,4,
+ 31,3,128,11,15,11,131,11,15,11,129,4,31,3,129,3,31,4,130,12,15,10,129,10,
+ 15,12,131,5,31,18,31,5,132,13,15,8,9,15,12,133,5,15,14,31,5,134,13,31,
+ 13,135,6,31,6,135,3,31,2,135,3,31,2,135,3,31,2,135,3,31,2,135,3,31,
+ 2,135,3,31,2,131,4,127,15,3,4,127,15,3,128,82,10,15,14,1,133,4,31,6,
+ 133,1,13,15,11,134,8,15,14,2,133,3,31,7,134,12,15,12,134,7,31,3,133,2,
+ 31,7,134,12,15,12,134,6,31,3,133,1,14,15,10,82,128,4,127,15,3,4,127,15,
+ 3,4,63,8,129,5,63,8,129,5,31,18,1,129,5,31,132,5,31,132,5,31,132,5,
+ 31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,
+ 31,132,5,31,132,5,31,132,5,31,18,1,129,5,63,9,129,4,63,8,129,128,10,15,
+ 8,133,6,15,14,133,1,31,4,133,11,15,9,133,6,15,14,133,1,31,4,133,10,15,
+ 9,133,5,15,14,133,1,31,4,133,10,15,9,133,5,15,14,133,1,14,15,4,133,10,
+ 15,9,133,5,15,14,133,1,14,15,4,129,7,63,5,129,7,63,6,129,1,18,14,15,
+ 6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,
+ 6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,
+ 6,132,14,15,6,132,14,15,6,129,1,18,14,15,6,129,7,63,6,129,7,63,5,130,
+ 3,8,5,133,11,15,14,132,1,47,5,131,6,15,10,15,10,131,12,15,2,13,15,1,
+ 129,2,15,12,128,8,15,6,129,7,15,7,128,3,15,11,129,13,15,2,129,13,15,2,
+ 3,15,12,130,7,15,7,181,1,114,1,8,127,11,8,127,11,128,2,1,128,2,30,1,
+ 128,4,15,9,175,129,4,11,30,12,6,130,6,95,9,129,14,15,12,3,2,8,31,2,
+ 128,2,4,2,130,31,5,129,7,12,14,63,5,128,11,111,5,3,31,10,3,18,14,15,
+ 21,31,1,129,1,31,5,3,31,7,2,4,12,31,5,128,12,111,5,128,2,10,14,15,
+ 12,4,14,15,5,128,11,15,8,135,11,15,9,135,11,15,9,135,11,15,9,135,11,15,
+ 25,30,10,2,130,11,95,14,2,129,11,31,9,3,6,31,10,129,11,15,14,130,9,15,
+ 14,129,11,15,11,130,4,31,2,128,11,15,10,130,3,31,3,128,11,15,11,130,4,31,
+ 2,128,11,15,14,130,8,15,14,129,11,31,10,3,6,31,9,129,11,95,14,2,129,11,
+ 15,25,30,10,2,129,129,1,8,13,14,13,8,1,130,1,12,79,12,1,129,7,31,6,
+ 2,6,14,15,9,129,13,15,9,130,8,15,11,129,31,5,135,31,5,135,31,5,135,12,
+ 15,9,130,7,12,8,129,7,31,6,2,5,14,15,9,129,1,12,79,13,1,130,1,8,
+ 13,15,13,8,1,129,134,6,15,13,135,6,15,14,135,6,15,14,135,6,15,14,130,1,
+ 9,13,14,10,8,15,14,129,1,13,95,14,129,7,31,8,3,7,31,14,129,12,15,11,
+ 130,11,15,14,129,14,15,7,130,8,15,14,129,31,6,130,7,15,14,129,14,15,7,130,
+ 8,15,14,129,12,15,10,130,12,15,14,129,7,31,7,3,8,31,14,129,1,13,95,14,
+ 130,1,9,30,10,7,15,13,128,129,1,8,13,15,13,9,1,130,1,12,79,13,1,129,
+ 7,15,14,4,2,5,14,15,7,129,13,15,7,130,8,15,11,129,127,13,129,127,14,129,
+ 14,15,6,66,1,129,11,15,9,130,1,4,130,6,31,7,2,3,11,15,5,130,11,95,
+ 4,131,7,13,15,14,10,2,129,130,9,13,15,11,130,8,47,11,130,11,15,12,3,1,
+ 130,13,15,8,130,6,79,12,128,6,79,12,129,2,13,15,8,2,1,130,13,15,7,132,
+ 13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,
+ 12,15,7,130,129,2,10,30,10,9,15,12,129,2,14,95,12,129,9,31,6,2,7,31,
+ 12,129,14,15,9,130,11,15,12,129,31,5,130,8,15,12,128,1,31,4,130,8,15,12,
+ 129,31,5,130,8,15,12,129,14,15,8,130,11,15,12,129,10,31,6,2,7,31,12,129,
+ 2,14,95,12,130,2,10,30,26,15,12,135,11,15,10,131,1,2,3,9,31,5,131,11,
+ 63,11,132,11,15,14,11,6,130,128,11,15,8,135,12,15,8,135,12,15,8,135,12,15,
+ 8,135,12,15,25,14,15,11,3,130,12,95,14,1,129,12,31,7,2,7,31,7,129,12,
+ 15,11,130,12,15,10,129,12,15,9,130,9,15,11,129,12,15,8,130,9,15,11,129,12,
+ 15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,
+ 15,8,130,9,15,11,129,11,15,8,130,9,15,10,128,128,7,14,8,129,12,15,14,129,
+ 7,14,8,134,9,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,
+ 10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,9,15,10,128,
+ 130,8,14,7,131,14,15,13,131,8,14,7,138,10,15,9,131,10,15,10,131,10,15,10,
+ 131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,
+ 131,10,15,10,131,10,15,10,131,11,15,9,129,2,6,31,7,129,47,14,2,129,15,14,
+ 11,3,129,128,11,15,8,134,12,15,8,134,12,15,8,134,12,15,8,134,12,15,8,129,
+ 6,31,5,128,12,15,8,128,4,31,9,129,12,15,8,2,14,15,12,130,12,15,9,13,
+ 31,2,130,12,79,4,130,12,47,12,15,10,130,12,31,5,4,31,2,129,12,15,9,129,
+ 13,15,8,129,12,15,8,129,6,15,14,1,128,12,15,8,129,1,14,15,6,128,11,15,
+ 8,130,9,15,12,128,11,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,
+ 8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,
+ 8,129,12,15,8,129,12,15,8,129,12,15,8,129,11,15,8,128,128,11,15,25,30,11,
+ 3,1,9,30,11,2,130,12,95,14,11,63,13,130,12,31,6,2,9,47,6,2,9,31,
+ 4,129,12,15,10,130,14,15,10,130,14,15,6,129,12,15,8,130,12,15,8,130,13,15,
+ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,12,15,8,130,12,15,8,130,13,15,
+ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,12,15,8,130,12,15,8,130,13,15,
+ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,11,15,8,130,12,15,7,130,12,15,
+ 7,128,128,11,15,25,14,15,11,3,130,12,95,14,1,129,12,31,7,2,7,31,7,129,
+ 12,15,11,130,12,15,10,129,12,15,9,130,9,15,11,129,12,15,8,130,9,15,11,129,
+ 12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,
+ 12,15,8,130,9,15,11,129,11,15,8,130,9,15,10,128,129,1,7,13,14,13,8,1,
+ 130,1,12,79,12,1,129,7,31,6,2,5,14,15,8,129,12,15,9,130,7,15,14,129,
+ 31,5,130,4,31,17,31,4,130,3,31,2,128,31,5,130,4,31,1,128,12,15,9,130,
+ 8,15,13,129,6,31,6,2,6,31,7,130,11,79,12,1,130,1,7,13,15,13,8,1,
+ 129,128,10,15,10,8,30,11,3,130,10,95,14,3,129,10,31,10,3,5,14,15,11,129,
+ 10,31,1,129,7,31,1,128,10,15,12,130,3,31,3,128,10,15,11,130,2,31,4,128,
+ 10,15,12,130,3,31,3,128,10,31,1,129,7,31,1,128,10,31,10,3,5,14,15,11,
+ 129,10,95,14,3,129,10,15,10,8,30,11,3,130,10,15,10,135,10,15,10,135,10,15,
+ 10,135,10,15,10,134,129,1,9,30,10,7,15,13,129,1,13,95,14,129,7,31,6,2,
+ 8,31,14,129,12,15,10,130,12,15,14,129,14,15,7,130,8,15,14,129,31,6,130,7,
+ 15,14,129,14,15,7,130,8,15,14,129,12,15,11,130,11,15,14,129,7,31,7,3,7,
+ 31,14,129,1,13,95,14,130,2,9,14,15,10,8,15,14,135,6,15,14,135,6,15,14,
+ 135,6,15,14,135,6,15,13,128,128,11,15,25,14,13,2,128,12,79,1,128,12,31,7,
+ 18,129,12,15,11,132,12,15,9,132,12,15,8,132,12,15,8,132,12,15,8,132,12,15,
+ 8,132,12,15,8,132,11,15,8,131,129,6,12,30,11,5,130,8,95,6,129,31,9,2,
+ 3,10,15,13,129,31,4,129,1,8,7,129,9,31,10,5,1,132,8,14,31,14,9,1,
+ 131,1,5,10,14,15,11,128,1,25,1,129,4,31,17,31,9,19,10,31,1,128,8,95,
+ 9,130,6,12,30,12,6,129,129,7,8,2,131,14,15,4,131,14,15,4,129,6,79,10,
+ 6,79,10,128,2,14,15,6,2,1,129,14,15,4,131,14,15,4,131,14,15,4,131,14,
+ 15,4,131,14,15,5,131,13,15,10,2,1,129,11,47,7,129,2,11,14,15,7,128,13,
+ 15,6,130,11,15,8,129,13,15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,
+ 15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,
+ 15,7,130,11,15,9,129,13,15,9,130,13,15,9,129,11,15,14,5,2,9,31,9,129,
+ 4,111,9,130,4,12,30,8,11,15,8,128,6,31,2,129,1,14,15,7,2,31,6,129,
+ 5,31,3,128,12,15,10,129,9,15,13,129,8,15,14,129,13,15,9,129,3,31,3,2,
+ 31,4,130,13,15,7,6,15,14,131,9,15,11,10,15,10,131,4,15,30,15,5,132,14,
+ 47,1,132,10,31,11,133,5,31,6,130,6,15,14,130,9,15,10,130,11,15,9,2,31,
+ 3,129,13,15,14,130,31,5,128,13,15,6,128,2,47,3,128,4,31,1,128,9,15,10,
+ 128,6,47,7,128,7,15,12,129,5,15,13,128,9,15,12,15,10,128,11,15,8,129,1,
+ 31,2,13,15,4,15,14,128,14,15,4,130,12,15,6,15,14,128,12,15,6,15,14,131,
+ 8,15,13,15,10,128,8,15,13,15,11,131,4,47,6,128,4,47,6,132,14,31,2,128,
+ 1,47,2,132,10,15,13,130,11,15,13,130,5,15,14,2,129,1,13,15,10,128,11,15,
+ 11,129,9,15,14,1,128,2,14,15,6,3,31,6,130,7,15,14,13,15,12,132,12,47,
+ 2,132,5,31,10,133,12,47,2,131,7,31,12,15,11,130,2,14,15,8,2,14,15,6,
+ 129,11,15,13,1,128,7,15,14,1,5,31,4,130,12,15,9,7,15,14,130,1,31,4,
+ 3,31,3,129,5,15,14,129,13,15,7,129,9,15,10,129,8,15,11,129,13,15,5,129,
+ 4,31,128,2,15,14,1,130,14,15,4,6,15,10,131,9,15,8,10,15,6,131,4,15,
+ 12,14,15,1,132,14,31,11,133,10,31,6,133,5,31,2,133,7,15,11,132,1,4,14,
+ 15,6,131,1,47,13,132,1,15,14,10,2,132,5,111,6,5,111,6,128,50,11,15,14,
+ 2,131,6,31,5,131,3,31,9,131,1,13,15,12,132,11,15,14,2,131,8,31,4,131,
+ 4,31,9,50,1,7,111,7,6,111,7,129,3,12,31,4,129,11,47,5,129,14,15,11,
+ 2,130,14,15,6,131,14,15,6,131,14,15,6,131,14,15,6,131,31,5,130,6,31,3,
+ 129,4,31,10,130,4,31,12,131,5,31,4,131,31,5,131,14,15,6,131,14,15,6,131,
+ 14,15,6,131,14,15,6,131,14,15,11,2,130,11,47,5,129,3,12,31,4,3,31,1,
+ 4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,
+ 4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,
+ 4,31,1,4,31,12,3,129,5,47,11,130,2,11,15,14,131,6,15,14,131,6,15,14,
+ 131,6,15,14,131,6,15,14,131,5,31,131,4,31,6,131,11,31,4,130,12,31,4,129,
+ 4,31,5,130,5,31,131,6,15,14,131,6,15,14,131,6,15,14,131,6,15,14,130,2,
+ 11,15,14,129,5,47,11,129,4,31,12,3,129,130,1,134,4,13,15,14,8,3,5,12,
+ 3,2,127,8,1,9,7,1,3,9,30,8,168,128,10,14,5,128,1,31,10,129,10,14,
+ 4,148,130,1,132,3,12,31,8,129,1,14,63,8,128,6,15,8,1,2,13,14,128,8,
+ 15,1,129,7,15,1,6,15,9,2,4,13,14,128,1,13,63,7,129,2,10,14,13,7,
+ 209,128,8,9,129,1,11,4,128,2,14,15,9,1,11,15,12,129,4,14,15,14,15,13,
+ 2,130,5,31,14,2,130,1,11,47,9,129,1,11,15,13,6,14,15,9,128,1,12,13,
+ 2,128,4,14,8,129,17,130,2,147,128,98,1,5,111,10,5,111,10,172,128,114,34,1,
+ 5,127,47,11,5,127,47,11,192,128,13,15,6,2,31,1,6,15,11,128,9,15,6,128,
+ 13,14,1,168,128,5,14,10,130,10,14,5,129,3,14,12,130,11,31,129,1,31,10,129,
+ 8,31,3,129,5,14,9,130,10,14,4,129,3,14,12,129,128,5,13,14,8,128,2,63,
+ 6,5,63,9,2,63,5,128,4,13,14,7,146,129,2,14,15,2,130,11,15,7,130,6,
+ 15,12,131,14,15,4,131,7,15,11,132,12,15,6,131,2,30,2,142,128,3,15,14,1,
+ 131,9,15,10,131,1,13,15,4,131,5,15,12,131,12,15,5,130,8,15,10,130,3,15,
+ 14,1,143,
+};
+static const struct fos_glyph mdb_glyphs[] = {
+ { 0, 4, 0, 0, 0, 64 }, /* 0x20 */
+ { 0, 7, 15, 0, -15, 107 }, /* 0x21 */
+ { 53, 7, 15, 0, -15, 104 }, /* 0x22 */
+ { 85, 14, 14, 0, -14, 217 }, /* 0x23 */
+ { 188, 11, 19, 0, -17, 181 }, /* 0x24 */
+ { 302, 17, 15, 0, -15, 267 }, /* 0x25 */
+ { 443, 14, 15, 0, -15, 220 }, /* 0x26 */
+ { 566, 3, 15, 0, -15, 50 }, /* 0x27 */
+ { 582, 7, 18, -1, -16, 101 }, /* 0x28 */
+ { 653, 7, 18, 0, -16, 101 }, /* 0x29 */
+ { 726, 8, 16, 0, -16, 127 }, /* 0x2a */
+ { 772, 10, 11, 0, -11, 157 }, /* 0x2b */
+ { 810, 5, 5, 0, -3, 85 }, /* 0x2c */
+ { 829, 8, 8, 0, -8, 129 }, /* 0x2d */
+ { 839, 5, 3, 0, -3, 87 }, /* 0x2e */
+ { 851, 9, 15, 0, -15, 143 }, /* 0x2f */
+ { 914, 11, 15, 0, -15, 182 }, /* 0x30 */
+ { 1031, 7, 15, 0, -15, 113 }, /* 0x31 */
+ { 1098, 11, 15, 0, -15, 176 }, /* 0x32 */
+ { 1182, 11, 15, 0, -15, 170 }, /* 0x33 */
+ { 1269, 12, 15, 0, -15, 187 }, /* 0x34 */
+ { 1346, 11, 15, 0, -15, 170 }, /* 0x35 */
+ { 1437, 11, 15, 0, -15, 169 }, /* 0x36 */
+ { 1542, 10, 15, 0, -15, 156 }, /* 0x37 */
+ { 1609, 11, 15, 0, -15, 171 }, /* 0x38 */
+ { 1718, 11, 15, 0, -15, 169 }, /* 0x39 */
+ { 1826, 7, 10, 0, -10, 114 }, /* 0x3a */
+ { 1851, 6, 12, 0, -10, 100 }, /* 0x3b */
+ { 1885, 10, 11, 0, -11, 157 }, /* 0x3c */
+ { 1942, 10, 9, 0, -9, 157 }, /* 0x3d */
+ { 1956, 10, 11, 0, -11, 157 }, /* 0x3e */
+ { 2012, 10, 15, 0, -15, 160 }, /* 0x3f */
+ { 2086, 16, 16, 0, -14, 263 }, /* 0x40 */
+ { 2255, 13, 15, 0, -15, 207 }, /* 0x41 */
+ { 2354, 12, 15, 0, -15, 199 }, /* 0x42 */
+ { 2461, 12, 15, 0, -15, 195 }, /* 0x43 */
+ { 2554, 12, 15, 0, -15, 198 }, /* 0x44 */
+ { 2658, 12, 15, 0, -15, 189 }, /* 0x45 */
+ { 2725, 11, 15, 0, -15, 180 }, /* 0x46 */
+ { 2790, 12, 15, 0, -15, 196 }, /* 0x47 */
+ { 2898, 13, 15, 0, -15, 204 }, /* 0x48 */
+ { 3013, 5, 15, 0, -15, 84 }, /* 0x49 */
+ { 3074, 12, 15, 0, -15, 186 }, /* 0x4a */
+ { 3162, 12, 15, 0, -15, 198 }, /* 0x4b */
+ { 3279, 11, 15, 0, -15, 183 }, /* 0x4c */
+ { 3341, 14, 15, 0, -15, 229 }, /* 0x4d */
+ { 3483, 13, 15, 0, -15, 214 }, /* 0x4e */
+ { 3624, 12, 15, 0, -15, 199 }, /* 0x4f */
+ { 3735, 12, 15, 0, -15, 190 }, /* 0x50 */
+ { 3822, 12, 17, 0, -15, 188 }, /* 0x51 */
+ { 3939, 12, 15, 0, -15, 196 }, /* 0x52 */
+ { 4049, 12, 15, 0, -15, 189 }, /* 0x53 */
+ { 4162, 12, 15, 0, -15, 185 }, /* 0x54 */
+ { 4227, 13, 15, 0, -15, 204 }, /* 0x55 */
+ { 4348, 12, 15, 0, -15, 195 }, /* 0x56 */
+ { 4450, 18, 15, 0, -15, 281 }, /* 0x57 */
+ { 4618, 12, 15, 0, -15, 197 }, /* 0x58 */
+ { 4723, 12, 15, 0, -15, 192 }, /* 0x59 */
+ { 4806, 11, 15, 0, -15, 177 }, /* 0x5a */
+ { 4873, 8, 20, 0, -17, 129 }, /* 0x5b */
+ { 4941, 9, 15, 0, -15, 143 }, /* 0x5c */
+ { 5003, 8, 20, 0, -17, 129 }, /* 0x5d */
+ { 5087, 9, 15, 0, -15, 149 }, /* 0x5e */
+ { 5144, 10, 3, 0, -3, 163 }, /* 0x5f */
+ { 5153, 4, 15, 0, -15, 70 }, /* 0x60 */
+ { 5165, 10, 11, 0, -11, 167 }, /* 0x61 */
+ { 5237, 11, 15, 0, -15, 179 }, /* 0x62 */
+ { 5334, 11, 11, 0, -11, 170 }, /* 0x63 */
+ { 5406, 11, 15, 0, -15, 179 }, /* 0x64 */
+ { 5505, 11, 11, 0, -11, 173 }, /* 0x65 */
+ { 5577, 8, 15, 0, -15, 120 }, /* 0x66 */
+ { 5644, 11, 15, 0, -11, 176 }, /* 0x67 */
+ { 5745, 11, 15, 0, -15, 174 }, /* 0x68 */
+ { 5847, 5, 15, 0, -15, 82 }, /* 0x69 */
+ { 5904, 7, 19, -2, -15, 80 }, /* 0x6a */
+ { 5979, 10, 15, 0, -15, 167 }, /* 0x6b */
+ { 6077, 5, 15, 0, -15, 76 }, /* 0x6c */
+ { 6138, 17, 11, 0, -11, 265 }, /* 0x6d */
+ { 6266, 11, 11, 0, -11, 174 }, /* 0x6e */
+ { 6352, 11, 11, 0, -11, 178 }, /* 0x6f */
+ { 6433, 11, 15, 0, -11, 180 }, /* 0x70 */
+ { 6534, 11, 15, 0, -11, 180 }, /* 0x71 */
+ { 6633, 8, 11, 0, -11, 120 }, /* 0x72 */
+ { 6682, 10, 11, 0, -11, 158 }, /* 0x73 */
+ { 6752, 7, 14, 0, -14, 120 }, /* 0x74 */
+ { 6814, 11, 11, 0, -11, 173 }, /* 0x75 */
+ { 6900, 10, 11, 0, -11, 161 }, /* 0x76 */
+ { 6971, 15, 11, 0, -11, 244 }, /* 0x77 */
+ { 7092, 10, 11, 0, -11, 165 }, /* 0x78 */
+ { 7169, 10, 15, 0, -11, 156 }, /* 0x79 */
+ { 7261, 9, 11, 0, -11, 146 }, /* 0x7a */
+ { 7307, 7, 20, 0, -17, 112 }, /* 0x7b */
+ { 7389, 4, 18, 0, -16, 61 }, /* 0x7c */
+ { 7443, 7, 20, 0, -17, 112 }, /* 0x7d */
+ { 7525, 10, 8, 0, -8, 167 }, /* 0x7e */
+ { 7549, 5, 7, 0, -7, 72 }, /* 0x80 */
+ { 7562, 8, 18, 0, -18, 121 }, /* 0x81 */
+ { 7609, 9, 10, 0, -10, 140 }, /* 0x82 */
+ { 7666, 9, 8, 0, -8, 149 }, /* 0x83 */
+ { 7676, 13, 8, 0, -8, 214 }, /* 0x84 */
+ { 7689, 4, 15, 0, -15, 58 }, /* 0x85 */
+ { 7708, 17, 3, 0, -3, 266 }, /* 0x86 */
+ { 7744, 6, 8, 0, -8, 100 }, /* 0x87 */
+ { 7765, 7, 9, 0, -9, 110 }, /* 0x88 */
+ { 7795, 7, 9, 0, -9, 118 }, /* 0x89 */
+};
+static const uint8_t mdb_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern mdb_kern[] = {
+ {39,45,-16},{39,52,-5},{39,65,-25},{39,74,-16},{39,97,-4},{39,99,-16},{39,100,-16},{39,101,-16},
+ {39,103,-11},{39,109,-4},{39,110,-4},{39,111,-16},{39,112,-4},{39,113,-11},{39,114,-4},{39,115,-8},
+ {44,45,-4},{44,48,-9},{44,84,-18},{44,86,-9},{44,87,-9},{44,89,-18},{44,99,-4},{44,100,-4},
+ {44,101,-4},{44,103,-4},{44,111,-4},{44,113,-4},{44,118,-13},{44,119,-13},{44,121,-13},{45,39,-7},
+ {45,44,-4},{45,45,-45},{45,46,-4},{45,55,-20},{45,84,-11},{45,102,-4},{45,116,-4},{45,118,-8},
+ {45,119,-8},{45,120,-7},{45,121,-8},{45,133,-8},{46,45,-4},{46,48,-9},{46,84,-18},{46,86,-9},
+ {46,87,-9},{46,89,-18},{46,99,-4},{46,100,-4},{46,101,-4},{46,103,-4},{46,111,-4},{46,113,-4},
+ {46,118,-13},{46,119,-13},{46,121,-13},{48,49,-5},{50,51,-4},{52,39,-9},{52,49,-30},{52,55,-18},
+ {53,49,-5},{54,49,-4},{55,44,-19},{55,46,-19},{56,49,-5},{57,49,-6},{65,39,-28},{65,45,-5},
+ {65,67,-6},{65,71,-6},{65,79,-6},{65,81,-6},{65,83,-13},{65,84,-25},{65,85,-4},{65,86,-9},
+ {65,87,-9},{65,89,-26},{65,90,4},{65,99,-5},{65,100,-5},{65,101,-5},{65,102,-7},{65,103,-7},
+ {65,111,-5},{65,113,-7},{65,116,-7},{65,118,-14},{65,119,-14},{65,121,-14},{65,133,-21},{66,65,-11},
+ {66,84,-5},{66,86,-8},{66,87,-8},{66,88,-7},{66,89,-10},{66,103,-4},{66,113,-4},{66,115,-4},
+ {67,74,4},{67,86,-4},{67,87,-4},{67,89,-7},{68,65,-11},{68,84,-5},{68,86,-8},{68,87,-8},
+ {68,88,-7},{68,89,-10},{68,103,-4},{68,113,-4},{68,115,-4},{70,44,-27},{70,45,-17},{70,46,-27},
+ {70,65,-22},{70,74,-17},{70,97,-14},{70,99,-17},{70,100,-17},{70,101,-17},{70,103,-12},{70,109,-7},
+ {70,110,-7},{70,111,-17},{70,112,-7},{70,113,-12},{70,114,-7},{70,115,-14},{70,117,-9},{70,118,-15},
+ {70,119,-15},{70,120,-14},{70,121,-15},{70,122,-7},{71,74,4},{71,86,-4},{71,87,-4},{71,89,-7},
+ {74,65,-5},{75,45,-9},{75,65,5},{75,67,-7},{75,71,-7},{75,74,-6},{75,79,-7},{75,81,-7},
+ {75,83,-5},{75,99,-9},{75,100,-9},{75,101,-9},{75,103,-7},{75,111,-9},{75,113,-7},{75,115,-4},
+ {75,118,-12},{75,119,-12},{75,121,-12},{76,39,-25},{76,65,8},{76,84,-28},{76,86,-12},{76,87,-12},
+ {76,89,-13},{76,102,-5},{76,116,-5},{76,118,-7},{76,119,-7},{76,121,-7},{76,122,4},{76,133,-15},
+ {79,74,4},{79,86,-4},{79,87,-4},{79,89,-7},{80,44,-7},{80,45,-8},{80,46,-7},{80,65,-14},
+ {80,74,-7},{80,86,-5},{80,87,-5},{80,88,-9},{80,89,-9},{80,99,-8},{80,100,-8},{80,101,-8},
+ {80,103,-5},{80,111,-8},{80,113,-5},{80,115,-5},{81,65,-7},{81,74,4},{81,84,-4},{81,86,-9},
+ {81,87,-9},{81,88,-9},{81,89,-15},{82,65,7},{82,86,-5},{82,87,-5},{82,89,-7},{83,84,-4},
+ {83,86,-5},{83,87,-5},{83,88,-11},{83,89,-7},{84,44,-18},{84,45,-25},{84,46,-18},{84,65,-20},
+ {84,67,-11},{84,71,-11},{84,74,-13},{84,79,-11},{84,81,-11},{84,97,-9},{84,99,-25},{84,100,-25},
+ {84,101,-25},{84,103,-20},{84,109,-18},{84,110,-18},{84,111,-25},{84,112,-18},{84,113,-20},{84,114,-18},
+ {84,115,-18},{84,117,-15},{84,118,-15},{84,119,-15},{84,120,-17},{84,121,-15},{85,65,-5},{86,44,-19},
+ {86,45,-18},{86,46,-19},{86,65,-31},{86,67,-9},{86,71,-9},{86,74,-13},{86,75,-5},{86,79,-9},
+ {86,81,-9},{86,83,-5},{86,97,-18},{86,99,-18},{86,100,-18},{86,101,-18},{86,103,-17},{86,109,-4},
+ {86,110,-4},{86,111,-18},{86,112,-4},{86,113,-17},{86,114,-4},{86,115,-12},{86,117,-5},{86,118,-5},
+ {86,119,-5},{86,121,-5},{87,44,-19},{87,45,-18},{87,46,-19},{87,65,-31},{87,67,-9},{87,71,-9},
+ {87,74,-13},{87,75,-5},{87,79,-9},{87,81,-9},{87,83,-5},{87,97,-18},{87,99,-18},{87,100,-18},
+ {87,101,-18},{87,103,-17},{87,109,-4},{87,110,-4},{87,111,-18},{87,112,-4},{87,113,-17},{87,114,-4},
+ {87,115,-12},{87,117,-5},{87,118,-5},{87,119,-5},{87,121,-5},{88,45,-9},{88,67,-7},{88,71,-7},
+ {88,74,-4},{88,79,-7},{88,81,-7},{88,83,-8},{88,97,-5},{88,99,-9},{88,100,-9},{88,101,-9},
+ {88,103,-11},{88,111,-9},{88,113,-11},{88,118,-9},{88,119,-9},{88,121,-9},{89,44,-29},{89,45,-23},
+ {89,46,-29},{89,65,-35},{89,67,-10},{89,71,-10},{89,74,-17},{89,79,-10},{89,81,-10},{89,83,-7},
+ {89,97,-19},{89,99,-23},{89,100,-23},{89,101,-23},{89,102,-12},{89,103,-27},{89,109,-16},{89,110,-16},
+ {89,111,-23},{89,112,-16},{89,113,-27},{89,114,-16},{89,115,-14},{89,116,-12},{89,117,-12},{89,118,-12},
+ {89,119,-12},{89,120,-12},{89,121,-12},{89,122,-7},{97,39,-8},{97,84,-9},{97,89,-11},{97,118,-4},
+ {97,119,-4},{97,121,-4},{97,133,-5},{98,39,-12},{98,44,-4},{98,46,-4},{98,118,-6},{98,119,-6},
+ {98,121,-6},{98,133,-4},{99,39,-7},{99,44,-8},{99,46,-8},{99,120,-5},{99,133,-5},{101,39,-11},
+ {101,44,-6},{101,46,-6},{101,118,-7},{101,119,-7},{101,120,-6},{101,121,-7},{101,133,-7},{102,44,-16},
+ {102,45,-12},{102,46,-16},{102,97,-4},{102,99,-12},{102,100,-12},{102,101,-12},{102,103,-9},{102,111,-12},
+ {102,113,-9},{102,115,-4},{102,133,4},{104,39,-12},{104,44,-4},{104,46,-4},{104,118,-6},{104,119,-6},
+ {104,121,-6},{104,133,-4},{107,45,-12},{107,97,-5},{107,99,-12},{107,100,-12},{107,101,-12},{107,103,-8},
+ {107,111,-12},{107,113,-8},{109,39,-12},{109,44,-4},{109,46,-4},{109,118,-6},{109,119,-6},{109,121,-6},
+ {109,133,-4},{110,39,-12},{110,44,-4},{110,46,-4},{110,118,-6},{110,119,-6},{110,121,-6},{110,133,-4},
+ {111,39,-7},{111,44,-4},{111,46,-4},{111,55,-20},{111,84,-11},{111,102,-4},{111,116,-4},{111,118,-8},
+ {111,119,-8},{111,120,-7},{111,121,-8},{111,133,-8},{112,39,-12},{112,44,-4},{112,46,-4},{112,118,-6},
+ {112,119,-6},{112,121,-6},{112,133,-4},{114,39,7},{114,44,-12},{114,46,-12},{114,103,-6},{114,113,-6},
+ {114,118,5},{114,119,5},{114,121,5},{114,133,16},{115,39,-5},{115,118,-11},{115,119,-11},{115,120,-4},
+ {115,121,-11},{115,133,-7},{118,44,-12},{118,45,-9},{118,46,-12},{118,97,-7},{118,99,-9},{118,100,-9},
+ {118,101,-9},{118,103,-9},{118,111,-9},{118,113,-9},{118,115,-11},{118,133,12},{119,44,-12},{119,45,-9},
+ {119,46,-12},{119,97,-7},{119,99,-9},{119,100,-9},{119,101,-9},{119,103,-9},{119,111,-9},{119,113,-9},
+ {119,115,-11},{119,133,12},{120,45,-10},{120,99,-10},{120,100,-10},{120,101,-10},{120,103,-7},{120,111,-10},
+ {120,113,-7},{121,44,-12},{121,45,-9},{121,46,-12},{121,97,-7},{121,99,-9},{121,100,-9},{121,101,-9},
+ {121,103,-9},{121,111,-9},{121,113,-9},{121,115,-11},{121,133,12},{133,45,-27},{133,65,-22},{133,97,-5},
+ {133,99,-27},{133,100,-27},{133,101,-27},{133,102,-4},{133,103,-24},{133,111,-27},{133,113,-24},{133,115,-22},
+ {133,116,-4},{133,118,-5},{133,119,-5},{133,120,-4},{133,121,-5},
+};
+const struct fos_font fos_font_mdb_data = { mdb_bits, mdb_glyphs, mdb_lut, mdb_kern, 501, 20, 4 };
+
+static const uint8_t lg_bits[] = {
+ 130,14,31,1,132,47,1,132,14,31,1,132,14,31,1,132,14,31,133,13,31,133,13,31,
+ 133,13,15,14,133,12,15,14,133,12,15,14,133,11,15,13,133,11,15,13,133,10,15,12,
+ 150,1,11,14,9,132,6,47,3,131,6,47,3,131,1,11,14,9,130,6,31,7,128,10,
+ 31,3,6,31,7,128,10,31,3,5,31,6,128,9,31,2,4,31,6,128,8,31,1,3,
+ 31,5,128,7,31,1,2,31,4,128,6,15,14,245,132,2,20,3,130,3,20,1,134,8,
+ 31,9,130,14,31,4,134,11,31,7,129,1,47,1,134,13,31,4,129,3,31,14,135,47,
+ 2,129,6,31,12,132,7,127,79,11,130,7,127,79,11,130,5,11,13,31,13,43,47,12,
+ 11,7,132,10,31,8,130,47,2,134,12,31,5,129,2,47,135,14,31,3,129,4,31,13,
+ 132,5,27,47,43,12,31,14,11,8,130,7,127,79,12,130,7,127,79,11,132,8,31,9,
+ 130,14,31,3,134,11,31,6,129,1,47,1,134,13,31,4,129,3,31,14,135,47,2,129,
+ 6,31,11,135,35,130,1,19,2,132,133,12,15,14,139,12,15,14,137,1,5,14,15,14,
+ 6,2,134,7,111,9,1,131,9,127,15,11,130,3,47,7,2,1,3,9,47,6,129,7,
+ 31,8,132,7,31,12,129,8,31,6,132,1,31,14,129,7,31,10,133,9,10,9,129,2,
+ 47,10,2,137,8,63,10,4,136,7,14,63,13,6,135,1,8,14,63,13,3,136,6,12,
+ 47,14,2,137,5,13,31,10,129,9,27,133,2,47,129,13,31,1,133,13,31,1,128,11,
+ 31,8,132,2,47,129,6,47,9,3,17,4,12,31,11,130,12,127,31,3,130,1,10,111,
+ 13,4,133,3,8,14,31,9,5,1,136,11,31,139,11,31,133,130,2,10,30,11,4,132,
+ 1,13,15,4,133,2,14,31,14,31,5,131,8,15,12,134,11,15,9,129,6,15,14,130,
+ 2,14,15,3,134,15,14,131,12,15,3,129,9,15,10,135,14,15,1,130,12,15,3,128,
+ 3,31,2,135,10,15,10,2,1,8,15,13,129,11,15,8,136,2,13,63,14,4,128,4,
+ 15,14,1,137,1,8,28,9,2,129,12,15,7,145,6,15,13,145,1,13,15,5,145,7,
+ 15,12,145,1,14,15,4,129,7,13,15,13,7,138,9,15,10,129,10,31,14,31,10,136,
+ 2,31,2,128,5,15,13,2,128,2,13,15,5,135,11,15,9,129,9,15,6,130,6,15,
+ 9,134,4,15,14,1,129,9,15,6,130,6,15,9,134,12,15,7,130,5,15,13,2,128,
+ 2,13,15,5,133,5,15,13,1,131,10,31,14,31,10,134,13,15,5,133,7,13,15,13,
+ 7,130,131,2,9,13,15,14,11,6,138,4,14,95,11,1,135,1,14,31,14,11,12,47,
+ 8,135,5,31,14,2,129,6,31,14,135,6,31,11,130,1,47,1,134,4,31,14,1,129,
+ 5,31,14,136,13,31,11,128,4,14,31,9,136,3,47,12,47,13,1,137,6,79,12,2,
+ 137,1,9,63,11,138,2,13,79,14,3,130,2,133,13,31,14,6,10,31,14,2,128,2,
+ 14,12,3,130,7,31,14,3,129,11,31,13,2,12,31,9,130,11,31,7,130,1,12,79,
+ 13,1,130,12,31,6,131,1,13,47,14,2,131,11,31,12,1,129,1,6,14,47,10,132,
+ 6,47,14,11,12,14,95,6,132,9,127,12,8,47,3,132,4,10,13,15,14,13,9,4,
+ 129,8,31,13,1,128,6,31,10,6,31,10,5,31,9,4,31,8,3,31,7,2,31,6,
+ 179,130,1,13,31,2,132,8,31,11,132,2,47,4,132,8,31,13,133,13,31,8,132,3,
+ 47,3,132,7,47,133,10,31,12,133,13,31,10,133,14,31,9,133,47,8,133,47,7,133,
+ 47,8,133,14,31,9,133,13,31,10,133,10,31,12,133,7,47,133,4,47,3,133,14,31,
+ 8,133,8,31,13,133,2,47,3,133,8,31,11,133,1,13,31,3,129,129,10,31,7,132,
+ 3,47,2,132,10,31,10,132,5,47,1,131,1,14,31,7,132,10,31,12,132,7,47,1,
+ 131,4,47,4,131,2,47,6,131,1,47,7,132,47,8,132,14,31,9,132,47,8,131,1,
+ 47,7,131,2,47,6,131,4,47,3,131,7,31,14,132,10,31,11,131,1,14,31,6,131,
+ 5,47,1,131,11,31,9,131,3,31,14,2,131,9,31,6,130,131,8,15,4,132,2,129,
+ 8,15,4,128,17,128,1,14,12,3,8,15,4,5,13,10,128,2,13,31,14,15,14,31,
+ 11,130,6,14,47,12,4,131,6,14,47,12,4,129,2,13,31,14,15,13,31,11,128,1,
+ 14,12,3,8,15,4,5,13,10,129,2,129,8,15,4,128,17,132,8,15,4,252,132,10,
+ 15,14,137,11,31,137,11,31,137,11,31,137,11,31,132,2,127,47,5,2,127,47,5,1,
+ 10,43,14,31,59,3,132,11,31,137,11,31,137,11,31,137,10,15,14,158,129,10,31,1,
+ 130,13,15,13,131,31,9,130,2,31,5,130,5,31,1,130,7,15,13,131,9,15,8,130,
+ 1,10,107,10,128,2,127,15,128,2,127,15,205,129,9,14,11,1,129,4,47,6,129,4,
+ 47,6,130,9,14,11,1,128,134,11,31,5,134,2,31,14,1,134,7,31,10,135,12,31,
+ 4,134,3,31,14,135,8,31,9,135,13,31,3,134,4,31,13,135,9,31,7,134,1,14,
+ 31,2,134,5,31,12,135,11,31,6,134,1,47,1,134,6,31,10,135,12,31,5,134,2,
+ 31,14,135,8,31,9,135,13,31,4,134,3,31,13,135,131,5,11,14,15,14,12,7,1,
+ 132,1,11,111,13,3,131,9,47,14,11,13,47,13,1,129,2,47,8,130,4,47,7,129,
+ 6,31,13,132,8,31,11,129,7,31,10,132,5,31,12,129,8,31,9,132,4,31,13,129,
+ 8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,
+ 8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,
+ 7,31,10,132,5,31,12,129,6,31,13,132,8,31,11,129,2,47,8,130,4,47,6,130,
+ 9,47,14,11,13,47,13,1,131,11,111,13,2,133,5,11,14,15,14,12,7,1,130,129,
+ 1,7,14,31,9,130,6,14,63,10,130,12,79,10,130,11,12,8,10,31,10,133,7,31,
+ 10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,
+ 10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,
+ 10,133,7,31,10,133,7,31,9,129,130,1,7,12,14,15,13,9,3,133,3,14,111,8,
+ 131,1,14,47,12,11,14,47,6,130,7,31,14,4,129,1,11,31,13,130,10,31,9,131,
+ 2,47,1,129,11,31,6,131,1,47,2,129,2,20,1,131,5,31,14,137,1,13,31,9,
+ 137,10,31,14,2,136,7,47,6,136,5,47,10,136,3,14,31,12,136,2,14,31,13,1,
+ 135,1,13,31,14,2,135,1,11,31,14,3,136,10,47,4,136,8,47,14,107,6,129,10,
+ 127,47,9,129,9,127,47,9,128,128,9,127,31,11,129,10,127,31,12,129,6,91,13,47,
+ 11,135,3,14,31,14,3,134,4,14,31,14,3,134,4,14,31,14,3,134,4,14,31,14,
+ 3,135,14,63,11,5,134,6,95,8,134,6,1,128,6,47,3,137,9,31,9,137,5,31,
+ 13,129,3,20,132,3,31,14,129,14,31,4,131,4,31,13,129,11,31,8,131,8,31,11,
+ 129,6,31,14,3,129,3,14,31,7,130,13,47,28,47,13,131,2,13,95,13,3,132,1,
+ 7,12,30,12,7,1,130,133,13,31,6,138,5,31,14,1,138,12,31,8,138,4,47,1,
+ 138,11,31,9,138,3,47,3,138,9,31,11,138,1,47,4,129,4,31,12,132,8,31,12,
+ 130,5,31,12,131,1,14,31,5,130,5,31,12,131,6,31,13,131,5,31,12,131,13,31,
+ 14,60,13,47,12,5,129,127,79,6,129,14,127,63,6,137,5,31,13,139,5,31,12,139,
+ 5,31,12,139,5,31,12,139,4,31,12,130,128,8,127,31,8,129,9,127,31,8,129,9,
+ 31,13,107,5,129,9,31,8,137,9,31,8,137,9,31,8,137,9,31,8,137,9,31,8,
+ 7,12,14,13,11,4,131,9,127,15,9,130,9,63,12,11,14,47,6,129,9,47,4,130,
+ 10,31,13,129,3,22,4,131,2,47,2,137,47,3,128,2,20,2,132,47,3,128,8,31,
+ 12,131,4,47,1,128,3,47,6,129,1,12,31,12,130,10,47,13,11,14,47,4,130,1,
+ 11,111,6,133,5,11,30,13,9,3,130,130,1,8,12,30,13,9,3,132,3,14,111,6,
+ 130,1,14,47,28,63,3,129,6,47,4,129,2,13,31,9,129,9,31,10,131,7,31,12,
+ 129,9,31,8,131,2,24,6,129,9,31,8,137,9,31,8,7,13,15,14,11,5,131,9,
+ 127,15,9,130,9,63,12,11,14,47,6,129,9,47,5,129,1,11,31,12,129,9,31,11,
+ 131,3,47,1,128,9,31,8,132,14,31,3,128,9,31,8,132,14,31,3,128,7,31,11,
+ 131,3,47,1,128,2,47,5,129,1,11,31,11,130,10,47,12,11,14,47,4,130,1,11,
+ 111,7,133,6,11,14,15,13,10,3,130,4,127,47,10,4,127,47,11,4,31,12,75,14,
+ 31,10,4,31,4,132,13,31,6,1,22,1,131,4,47,1,135,10,31,10,135,1,47,4,
+ 135,6,31,14,136,12,31,8,135,3,47,2,135,8,31,12,136,14,31,6,135,5,47,1,
+ 135,10,31,10,135,1,47,4,135,7,31,14,136,12,31,8,135,3,47,2,135,8,31,12,
+ 133,131,7,12,14,15,13,9,3,132,2,13,111,6,131,12,47,12,11,14,47,2,129,4,
+ 47,4,129,1,12,31,9,129,7,31,10,131,4,31,12,129,7,31,10,131,4,31,12,129,
+ 4,47,4,129,1,12,31,8,130,11,47,28,14,31,14,2,130,1,13,111,3,131,7,127,
+ 12,130,2,47,8,1,128,4,14,31,8,129,8,31,11,131,5,31,13,129,11,31,7,131,
+ 1,47,1,128,12,31,7,131,1,47,2,128,10,31,10,131,4,47,129,6,47,4,129,1,
+ 12,31,11,130,13,47,12,11,14,47,4,130,2,13,111,6,132,1,7,12,14,15,13,9,
+ 3,130,130,2,8,12,30,12,7,1,132,4,14,95,13,2,130,1,14,47,11,12,47,13,
+ 130,8,31,13,2,129,2,14,31,6,129,12,31,6,131,8,31,11,129,14,31,3,131,4,
+ 31,12,129,14,31,3,131,5,31,13,129,13,31,6,131,8,31,13,129,9,31,13,2,129,
+ 3,14,31,13,129,3,63,11,12,63,13,130,6,95,14,31,13,131,3,10,14,15,13,9,
+ 5,31,13,137,4,31,13,129,4,24,5,131,4,31,13,129,8,31,11,131,6,31,12,129,
+ 6,47,4,129,2,13,31,10,129,1,14,47,28,63,3,130,3,14,111,6,132,1,8,12,
+ 30,13,9,3,130,130,7,14,12,2,132,1,47,8,132,1,47,8,133,7,14,12,2,173,
+ 7,14,12,2,132,1,47,8,132,1,47,8,133,7,14,12,2,140,129,3,12,14,9,131,
+ 12,47,5,130,12,47,5,130,3,12,14,9,163,1,31,10,131,3,31,8,131,4,31,4,
+ 131,6,31,1,131,8,15,13,132,9,15,10,132,10,15,6,130,137,2,8,4,135,3,9,
+ 31,5,133,4,11,63,5,131,5,12,63,14,8,1,128,1,7,13,63,12,5,130,1,14,
+ 47,14,9,3,132,2,47,10,1,134,2,63,12,5,134,4,11,63,13,7,1,133,3,10,
+ 79,9,3,133,2,8,14,63,4,134,1,7,13,31,5,137,5,12,5,140,1,125,45,4,
+ 2,127,47,5,2,127,47,5,166,1,125,45,4,2,127,47,5,2,127,47,5,179,1,9,
+ 3,137,2,31,11,4,135,2,63,12,6,134,6,12,63,13,7,1,133,4,10,63,14,8,
+ 2,133,2,8,14,63,4,135,7,47,5,133,4,10,63,5,131,6,12,63,13,6,129,2,
+ 8,14,63,11,4,130,1,79,10,3,132,2,31,14,8,2,134,2,13,7,1,149,130,3,
+ 9,13,30,12,8,1,132,8,111,14,3,130,6,47,14,11,12,47,13,1,129,13,31,10,
+ 1,129,4,47,5,128,1,47,2,131,11,31,8,128,1,29,12,132,11,31,8,136,3,47,
+ 5,135,4,14,31,12,135,8,47,13,2,134,8,47,9,1,134,2,47,7,136,4,31,13,
+ 137,4,31,12,165,2,12,14,6,137,10,47,137,10,31,14,137,2,13,14,6,133,135,5,
+ 9,12,30,13,11,7,1,138,6,13,127,15,6,135,1,10,31,12,6,3,1,128,2,5,
+ 11,31,10,133,1,12,15,14,5,135,6,31,7,132,10,15,14,2,137,7,31,2,130,4,
+ 31,3,129,2,9,12,11,6,11,13,3,129,13,15,7,130,12,15,8,129,3,14,95,2,
+ 129,9,15,11,129,2,31,2,129,12,15,10,18,12,31,130,7,15,13,129,6,15,12,129,
+ 2,15,14,1,129,6,15,13,130,6,15,13,129,9,15,9,129,6,15,11,130,7,15,11,
+ 130,7,15,12,129,11,15,8,129,8,15,8,130,9,15,9,130,11,15,9,129,11,15,7,
+ 129,9,15,8,130,13,15,9,129,1,14,15,5,129,10,15,9,129,7,15,13,2,128,8,
+ 31,13,2,1,11,15,13,130,8,15,12,129,2,14,63,14,79,14,4,130,4,31,2,129,
+ 3,11,30,10,2,4,12,15,14,11,3,132,13,15,11,146,3,31,10,1,134,2,137,7,
+ 31,13,7,3,18,3,7,12,14,2,137,5,14,127,13,4,138,1,7,11,14,15,14,13,
+ 10,5,1,134,133,5,47,12,140,10,63,2,138,1,79,7,138,5,79,12,138,10,31,11,
+ 47,2,137,14,31,4,13,31,7,136,4,31,14,128,8,31,12,136,9,31,10,128,3,47,
+ 1,135,14,31,6,129,14,31,6,134,4,47,1,129,9,31,11,134,9,31,11,130,5,47,
+ 1,133,13,31,7,130,1,14,31,6,132,3,47,2,131,10,31,10,132,8,47,71,11,31,
+ 14,1,131,13,127,63,5,130,2,127,79,10,130,7,31,14,134,6,31,14,130,12,31,9,
+ 134,1,47,4,128,1,47,3,135,11,31,9,128,129,111,14,13,10,4,133,127,47,9,132,
+ 47,59,12,63,6,131,47,2,131,2,12,31,12,131,47,2,132,3,31,14,131,47,2,132,
+ 1,47,131,47,2,132,5,31,12,131,47,2,130,1,5,14,31,6,131,127,47,7,132,127,
+ 31,12,2,132,47,59,12,14,31,14,3,131,47,2,131,1,10,31,12,131,47,2,132,1,
+ 47,2,130,47,2,133,13,31,4,130,47,2,132,1,47,3,130,47,2,131,1,10,31,14,
+ 1,130,47,75,14,47,8,131,127,47,10,132,127,13,10,4,131,131,2,7,12,14,15,13,
+ 10,5,134,5,14,111,12,2,131,4,63,12,11,14,47,13,1,130,13,31,12,2,130,6,
+ 47,7,129,4,31,14,2,132,8,31,12,129,6,31,11,133,3,47,129,7,31,10,134,22,
+ 5,129,7,31,10,139,7,31,10,139,7,31,10,139,7,31,10,139,7,31,10,139,7,31,
+ 10,134,5,6,5,129,6,31,11,133,3,31,14,129,4,31,14,2,132,8,31,12,130,13,
+ 31,12,2,130,6,47,7,130,4,63,12,11,14,47,12,1,131,5,14,111,12,2,133,2,
+ 7,12,14,15,13,10,5,131,129,111,14,13,8,2,133,127,47,7,132,47,59,12,63,6,
+ 131,47,2,131,2,12,31,13,131,47,2,132,3,47,3,130,47,2,133,14,31,4,130,47,
+ 2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,
+ 31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,
+ 47,2,133,14,31,4,130,47,2,132,3,47,3,130,47,2,131,2,12,31,13,131,47,59,
+ 12,63,6,131,127,47,7,132,111,14,13,9,3,131,129,127,63,11,130,127,63,12,130,47,
+ 123,11,8,130,47,2,139,47,2,139,47,2,139,47,2,139,47,2,139,127,15,11,133,127,
+ 15,11,133,47,91,7,133,47,2,139,47,2,139,47,2,139,47,2,139,47,2,139,47,123,
+ 11,8,130,127,63,12,130,127,63,11,128,129,127,63,11,129,127,63,11,129,47,123,11,7,
+ 129,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,127,15,11,132,127,15,11,132,
+ 47,91,7,132,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,
+ 138,47,1,136,131,2,7,12,14,15,13,11,5,135,5,14,111,12,2,132,4,63,13,11,
+ 13,47,13,1,131,13,31,12,2,130,5,14,31,8,130,4,31,14,2,132,6,31,13,130,
+ 6,31,11,133,2,47,130,7,31,10,134,33,130,7,31,10,140,7,31,10,130,9,75,10,
+ 130,7,31,10,130,13,95,130,7,31,10,130,13,95,130,7,31,10,133,2,47,130,7,31,
+ 10,133,1,47,130,6,31,11,133,3,31,14,130,3,31,14,1,132,7,31,11,131,13,31,
+ 12,3,130,5,14,31,5,131,4,63,13,11,13,47,11,133,5,14,111,11,1,134,2,7,
+ 12,14,15,14,11,5,132,129,47,1,133,10,31,5,130,47,2,133,11,31,6,130,47,2,
+ 133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,
+ 6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,127,79,6,130,127,79,6,130,
+ 47,107,14,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,
+ 31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,
+ 47,2,133,11,31,6,130,47,1,133,11,31,5,128,129,47,1,130,47,2,130,47,2,130,
+ 47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,
+ 47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,1,128,
+ 137,5,31,10,139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,
+ 139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,130,33,133,6,31,11,129,6,
+ 31,11,133,6,31,11,129,6,31,11,133,6,31,11,129,5,31,12,133,7,31,10,129,3,
+ 47,2,132,11,31,8,130,13,31,12,2,130,8,47,3,130,5,63,12,11,14,47,9,132,
+ 6,127,10,134,2,8,12,30,13,10,4,132,129,47,1,132,1,13,31,8,130,47,2,132,
+ 12,31,12,131,47,2,131,10,31,14,1,131,47,2,130,7,47,3,132,47,2,129,5,47,
+ 6,133,47,2,128,3,14,31,9,134,47,18,13,31,11,135,47,2,12,31,13,1,135,47,
+ 12,47,10,136,127,4,135,63,14,11,31,13,1,134,63,4,1,14,31,8,134,47,6,129,
+ 5,47,3,133,47,2,130,11,31,12,133,47,2,130,2,14,31,7,132,47,2,131,6,47,
+ 2,131,47,2,132,12,31,11,131,47,2,132,2,47,6,130,47,1,133,7,31,14,1,129,
+ 47,1,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,
+ 47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,
+ 47,123,11,6,129,127,63,9,129,127,63,9,129,47,5,134,2,14,31,4,130,47,14,1,
+ 133,10,47,5,130,63,10,132,5,63,5,130,79,5,130,1,14,63,5,130,79,13,1,129,
+ 10,79,5,130,47,14,31,9,128,5,47,14,31,5,130,47,5,47,5,13,31,8,12,31,
+ 5,130,47,2,9,79,13,128,12,31,5,130,47,2,1,13,63,4,128,12,31,5,130,47,
+ 2,128,4,47,9,129,12,31,5,130,47,2,129,9,15,13,1,129,12,31,5,130,47,2,
+ 130,2,1,130,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,5,130,47,2,
+ 135,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,
+ 5,130,47,1,135,12,31,4,128,129,47,4,134,47,1,130,47,12,133,1,47,1,130,63,
+ 7,132,1,47,1,130,63,14,2,131,1,47,1,130,79,10,131,1,47,1,130,95,4,130,
+ 1,47,1,130,47,8,31,13,131,47,1,130,47,1,13,31,7,130,47,1,130,47,1,4,
+ 31,14,2,129,47,1,130,47,1,128,10,31,10,129,47,1,130,47,1,128,2,14,31,4,
+ 128,47,1,130,47,1,129,7,31,13,1,47,1,130,47,1,130,12,31,8,47,1,130,47,
+ 1,130,4,95,1,130,47,1,131,9,79,1,130,47,1,131,1,14,63,1,130,47,1,132,
+ 6,63,1,130,47,2,133,12,47,1,130,47,1,133,3,14,31,1,128,131,1,7,12,14,
+ 15,13,11,5,135,4,14,111,12,2,132,3,63,12,11,13,47,13,1,131,12,31,13,2,
+ 130,4,14,31,8,130,3,47,2,132,5,31,14,130,6,31,11,134,47,2,129,7,31,10,
+ 134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,
+ 134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,
+ 134,13,31,3,129,6,31,11,134,47,2,129,3,47,2,132,5,31,14,131,12,31,12,2,
+ 130,4,14,31,8,131,3,63,12,11,13,47,13,1,132,4,14,111,12,2,134,1,7,12,
+ 14,15,13,11,6,132,128,2,127,13,10,4,131,3,127,47,8,130,3,47,59,12,14,47,
+ 5,129,3,31,14,132,2,12,31,12,129,3,31,14,133,2,47,2,128,3,31,14,134,14,
+ 31,4,128,3,31,14,134,14,31,3,128,3,31,14,133,4,47,1,128,3,31,14,131,1,
+ 5,14,31,11,129,3,127,47,14,3,129,3,127,31,13,4,130,3,47,59,10,9,5,1,
+ 131,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,
+ 139,2,31,14,138,131,3,9,13,30,12,8,2,134,7,111,14,5,132,6,47,14,11,12,
+ 63,4,130,1,47,10,1,129,1,12,31,13,130,6,31,13,1,131,2,14,31,4,129,9,
+ 31,8,133,11,31,7,129,11,31,6,133,8,31,8,129,11,31,6,133,8,31,9,129,11,
+ 31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,
+ 31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,31,7,133,9,31,8,129,9,
+ 31,9,133,11,31,7,129,5,31,14,2,131,4,47,3,130,13,31,13,4,17,5,14,31,
+ 11,131,3,14,127,13,2,132,3,12,95,11,2,135,3,12,31,10,2,138,9,31,8,139,
+ 9,31,7,133,129,127,14,11,5,133,127,47,9,132,47,75,14,47,7,131,47,2,131,1,
+ 10,31,14,131,47,2,132,1,47,3,130,47,2,133,13,31,4,130,47,2,132,1,47,3,
+ 130,47,2,131,1,10,31,14,1,130,47,75,14,47,8,131,127,47,10,132,127,15,13,5,
+ 133,47,2,129,3,31,13,134,47,2,130,11,31,6,133,47,2,130,4,31,13,133,47,2,
+ 131,12,31,6,132,47,2,131,5,31,13,132,47,2,132,13,31,6,131,47,2,132,6,31,
+ 13,131,47,1,133,13,31,5,128,131,6,11,14,15,14,12,8,3,133,2,12,127,9,132,
+ 12,47,13,11,12,63,9,130,5,31,14,4,130,1,9,47,3,129,8,31,9,133,11,31,
+ 7,129,7,31,9,133,7,31,9,129,5,31,14,3,132,1,20,2,130,12,47,10,3,137,
+ 1,12,63,13,7,2,136,6,13,79,10,2,136,4,10,63,14,4,137,1,7,14,31,14,
+ 2,129,4,21,1,132,2,13,31,8,129,13,31,3,133,6,31,11,129,11,31,7,133,8,
+ 31,10,129,7,47,6,131,4,14,31,7,129,1,13,47,14,12,11,13,47,14,1,130,2,
+ 12,127,13,3,133,5,10,13,14,15,14,11,6,1,130,1,127,79,10,128,1,127,79,11,
+ 128,1,10,59,14,31,12,59,7,134,13,31,4,139,13,31,4,139,13,31,4,139,13,31,
+ 4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,
+ 4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,12,31,
+ 4,133,128,2,31,14,134,11,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
+ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
+ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
+ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
+ 31,5,129,3,31,14,134,12,31,5,129,1,47,1,133,13,31,4,130,14,31,6,132,4,
+ 47,2,130,9,31,14,5,130,3,13,31,11,131,1,13,47,13,11,13,47,14,3,132,2,
+ 12,111,14,4,135,6,11,13,15,14,12,7,1,131,1,47,3,134,10,31,9,128,12,31,
+ 8,134,14,31,5,128,8,31,12,133,4,31,14,129,3,47,1,132,8,31,10,130,13,31,
+ 5,132,12,31,5,130,9,31,10,131,1,47,1,130,4,31,14,131,6,31,11,132,14,31,
+ 3,130,10,31,6,132,10,31,8,130,14,31,2,132,5,31,12,129,3,31,12,133,1,47,
+ 1,128,8,31,7,134,11,31,5,128,12,31,3,134,6,31,10,1,31,13,135,2,31,14,
+ 5,31,8,136,12,31,13,31,3,136,7,63,14,137,3,63,9,138,13,47,4,138,8,31,
+ 14,133,3,47,1,132,13,31,8,132,3,31,14,129,14,31,5,131,2,47,12,132,7,31,
+ 11,129,11,31,8,131,5,63,1,131,11,31,7,129,7,31,12,131,9,63,5,131,14,31,
+ 3,129,3,47,1,130,13,63,8,130,3,31,14,131,14,31,4,129,1,31,14,31,12,130,
+ 7,31,10,131,10,31,8,129,5,31,9,14,31,1,129,11,31,7,131,6,31,12,129,8,
+ 31,5,10,31,5,129,14,31,3,131,2,47,1,128,12,31,2,7,31,9,128,3,31,14,
+ 133,13,31,4,1,31,13,128,3,31,12,128,6,31,10,133,9,31,8,4,31,10,129,14,
+ 31,1,10,31,6,133,5,31,12,7,31,6,129,11,31,5,14,31,2,133,1,47,12,31,
+ 3,129,7,31,11,31,14,135,12,63,14,130,3,79,10,135,8,63,11,131,14,63,6,135,
+ 4,63,7,131,11,63,2,136,14,47,4,131,7,47,13,137,11,47,132,4,47,10,137,6,
+ 31,11,133,14,31,5,132,128,14,31,7,134,12,31,8,129,6,31,14,1,132,6,31,14,
+ 1,130,12,31,10,131,1,14,31,6,131,3,47,3,130,9,31,12,133,9,31,12,129,3,
+ 47,3,133,1,14,31,6,128,11,31,9,135,6,31,14,6,31,14,1,136,12,79,7,137,
+ 4,63,13,139,11,47,6,138,3,63,12,138,12,79,6,136,6,31,14,7,31,14,1,134,
+ 1,14,31,6,128,12,31,9,134,9,31,12,129,3,47,3,132,3,47,3,130,9,31,12,
+ 132,11,31,9,131,1,14,31,6,130,5,31,14,1,132,6,31,14,1,129,13,31,6,134,
+ 12,31,8,128,1,14,31,5,133,2,14,31,3,128,8,31,12,133,10,31,11,129,1,14,
+ 31,5,131,2,47,3,130,7,31,12,131,10,31,10,131,1,14,31,5,129,2,47,3,132,
+ 7,31,12,129,10,31,10,133,1,14,31,4,2,47,2,134,7,31,12,10,31,9,135,1,
+ 14,79,2,136,6,63,9,138,13,47,2,138,8,31,10,139,8,31,10,139,8,31,10,139,
+ 8,31,10,139,8,31,10,139,8,31,10,139,8,31,10,139,7,31,9,133,128,127,63,12,
+ 129,127,63,12,129,10,123,14,31,12,137,3,47,5,136,1,13,31,10,137,9,31,13,1,
+ 136,4,47,4,136,1,14,31,8,137,10,31,12,137,6,47,3,136,2,14,31,7,137,11,
+ 31,12,137,7,31,14,2,136,3,47,6,137,12,31,10,137,8,31,14,1,137,47,13,123,
+ 8,129,127,63,12,129,127,63,12,128,1,95,7,130,1,95,8,130,1,47,43,5,130,1,
+ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
+ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
+ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
+ 47,1,133,1,47,43,5,130,1,95,8,130,1,95,8,130,128,4,31,12,136,14,31,2,
+ 135,9,31,8,135,4,31,13,136,13,31,3,135,8,31,9,135,2,31,14,136,12,31,5,
+ 135,7,31,10,135,1,47,1,135,11,31,6,135,6,31,11,135,1,14,31,2,135,10,31,
+ 7,135,4,31,12,136,14,31,3,135,9,31,8,135,3,31,13,136,13,31,3,130,9,79,
+ 14,131,9,95,131,6,27,12,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,
+ 134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,
+ 134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,131,6,43,47,131,9,
+ 95,131,9,79,14,128,131,4,31,11,136,10,47,2,134,1,14,47,8,134,6,31,12,15,
+ 13,134,11,15,12,4,31,4,132,2,31,7,128,14,15,9,132,7,31,2,128,9,15,14,
+ 1,131,13,15,12,129,3,31,6,130,3,31,6,130,13,15,11,130,9,31,1,130,8,31,
+ 2,129,14,15,11,131,2,31,7,232,4,123,43,10,1,6,127,63,2,6,127,63,2,1,
+ 14,15,12,130,4,31,6,130,7,15,14,1,223,130,3,9,13,15,14,12,8,2,132,7,
+ 111,14,4,130,4,47,14,27,14,31,14,1,129,10,31,13,1,129,1,13,31,7,130,2,
+ 4,3,131,8,31,9,131,2,7,26,27,13,31,10,130,9,127,15,10,129,8,127,31,10,
+ 129,14,31,11,4,1,129,8,31,10,128,2,47,2,131,9,31,10,128,1,47,5,130,5,
+ 14,31,10,129,13,47,12,11,13,63,10,129,4,111,12,31,10,130,3,10,14,15,14,10,
+ 3,7,31,9,128,128,4,31,12,138,4,31,12,138,4,31,12,138,4,31,12,138,4,31,
+ 12,138,4,31,12,2,10,30,12,7,1,131,4,31,30,79,12,1,130,4,63,14,11,13,
+ 47,10,130,4,47,12,1,129,8,47,3,129,4,47,5,131,14,31,7,129,4,47,132,9,
+ 31,10,129,4,31,14,132,7,31,11,129,4,31,14,132,7,31,11,129,4,47,132,9,31,
+ 10,129,4,47,4,131,13,31,7,129,4,47,12,1,129,7,47,2,129,4,63,14,11,13,
+ 47,10,130,4,31,30,79,12,1,130,4,31,12,2,10,30,12,7,131,131,5,11,14,15,
+ 14,10,4,133,10,111,10,131,9,47,13,11,13,47,9,129,2,47,7,130,8,47,2,128,
+ 7,31,12,132,13,15,14,4,128,9,31,8,132,2,1,130,10,31,7,137,10,31,7,137,
+ 9,31,8,132,1,131,6,31,12,132,14,15,12,3,128,2,47,7,130,8,47,1,129,8,
+ 47,13,11,13,47,9,131,9,111,10,133,5,11,14,15,14,10,5,130,137,11,31,5,138,
+ 12,31,5,138,12,31,5,138,12,31,5,138,12,31,5,132,6,12,30,11,3,12,31,5,
+ 130,1,11,79,30,31,5,130,9,47,13,11,14,63,5,129,2,47,9,129,1,11,47,5,
+ 129,6,31,14,1,130,3,47,5,129,9,31,10,132,14,31,5,129,10,31,9,132,13,31,
+ 5,129,10,31,8,132,13,31,5,129,8,31,10,132,14,31,5,129,6,31,14,131,3,47,
+ 5,129,1,47,8,129,1,11,47,5,130,9,47,13,11,14,63,5,130,1,11,95,14,31,
+ 5,132,6,12,30,11,3,11,31,5,128,131,5,11,14,15,14,10,4,134,10,111,9,132,
+ 9,47,12,11,13,47,6,130,2,47,4,130,8,31,13,130,7,31,10,132,14,31,2,129,
+ 9,31,13,75,14,31,5,129,10,127,47,6,129,9,127,47,6,129,8,31,8,138,5,31,
+ 12,132,1,2,131,1,14,31,8,130,2,12,14,4,131,6,47,14,11,12,47,13,132,8,
+ 111,13,3,133,4,10,13,15,14,12,7,1,130,131,6,11,14,31,1,130,6,79,2,130,
+ 13,47,12,10,1,130,47,5,132,1,47,1,130,3,127,2,3,127,3,2,27,47,43,2,
+ 129,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,
+ 132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,131,130,1,8,12,
+ 30,11,3,13,31,3,130,1,13,127,15,4,130,11,47,13,11,14,63,4,129,4,47,7,
+ 129,1,11,47,4,129,8,31,12,131,3,47,4,129,10,31,8,132,14,31,4,129,11,31,
+ 7,132,13,31,4,129,11,31,6,132,13,31,4,129,10,31,8,132,14,31,4,129,9,31,
+ 11,131,2,47,4,129,5,47,7,129,1,10,47,4,130,13,47,13,11,14,63,4,130,2,
+ 13,127,15,4,131,1,7,12,30,11,3,14,31,3,137,2,47,1,136,1,11,31,12,133,
+ 6,27,12,63,4,133,10,79,14,5,134,9,31,14,11,7,1,131,128,4,31,12,138,5,
+ 31,12,138,5,31,12,138,5,31,12,138,5,31,12,138,5,31,12,2,10,14,15,13,8,
+ 1,131,5,31,30,79,13,1,130,5,63,13,11,14,47,9,130,5,47,9,129,1,11,31,
+ 14,130,5,31,14,131,3,47,1,129,5,31,12,131,1,47,1,129,5,31,12,132,47,1,
+ 129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,
+ 12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,4,31,12,132,47,
+ 1,128,129,3,7,3,130,3,31,14,2,129,6,47,5,129,3,31,14,2,130,3,7,3,
+ 137,2,31,14,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,
+ 47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,31,14,129,131,4,7,
+ 2,132,4,31,14,1,131,8,47,3,131,4,31,14,1,132,4,7,2,141,3,31,13,132,
+ 3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
+ 3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
+ 3,31,14,132,4,31,13,131,1,11,31,12,129,4,11,14,47,8,129,6,63,13,1,129,
+ 5,15,14,12,7,1,130,128,4,31,12,137,5,31,12,137,5,31,12,137,5,31,12,137,
+ 5,31,12,137,5,31,12,130,1,12,31,10,129,5,31,12,130,11,31,13,1,129,5,31,
+ 12,129,10,31,14,3,130,5,31,12,128,8,47,5,131,5,31,12,6,47,9,132,5,31,
+ 14,63,9,132,5,127,2,131,5,63,7,8,31,8,131,5,47,9,128,2,31,14,1,130,
+ 5,31,13,130,10,31,7,130,5,31,12,130,4,31,14,130,5,31,12,131,12,31,6,129,
+ 5,31,12,131,6,31,13,129,4,31,12,132,13,31,5,128,4,31,12,129,5,31,12,129,
+ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,
+ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,
+ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,4,31,12,128,128,4,31,12,
+ 2,10,14,15,13,8,1,128,2,10,14,15,13,8,1,130,5,31,30,79,12,3,14,79,
+ 12,1,129,5,63,13,11,14,79,13,11,14,47,7,129,5,47,7,129,2,13,47,8,129,
+ 1,13,31,11,129,5,31,14,131,7,31,14,131,6,31,13,129,5,31,12,131,4,31,13,
+ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
+ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
+ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
+ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,4,31,12,131,4,31,12,
+ 131,3,31,13,128,128,4,31,12,3,10,14,15,13,8,1,131,5,31,30,79,13,1,130,
+ 5,63,13,11,14,47,9,130,5,47,9,129,1,11,31,14,130,5,31,14,131,3,47,1,
+ 129,5,31,12,131,1,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,
+ 31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,
+ 47,1,129,5,31,12,132,47,1,129,4,31,12,132,47,1,128,131,5,11,14,15,14,11,
+ 4,134,9,111,9,132,8,47,13,11,13,47,7,130,2,47,8,130,8,31,14,1,129,6,
+ 31,13,132,13,31,6,129,9,31,8,132,8,31,9,129,11,31,7,132,7,31,10,129,10,
+ 31,7,132,7,31,10,129,9,31,8,132,9,31,9,129,6,31,13,132,13,31,5,129,1,
+ 14,31,8,130,8,31,14,1,130,7,47,13,11,13,47,7,132,9,111,8,134,4,10,14,
+ 15,14,11,4,131,128,2,31,14,2,10,30,12,7,1,131,3,47,14,79,13,1,130,3,
+ 63,14,11,13,47,11,130,3,47,13,2,129,6,47,4,129,3,47,6,131,12,31,8,129,
+ 3,47,2,131,7,31,11,129,3,47,1,131,6,31,12,129,3,47,1,131,6,31,12,129,
+ 3,47,2,131,8,31,11,129,3,47,6,131,13,31,9,129,3,47,13,2,129,7,47,4,
+ 129,3,63,14,11,13,47,12,130,3,47,13,79,13,2,130,3,31,14,2,10,30,12,8,
+ 1,131,3,31,14,138,3,31,14,138,3,31,14,138,3,31,14,138,2,31,14,137,131,6,
+ 12,30,11,3,11,31,5,130,1,11,95,14,31,5,130,9,47,13,11,14,63,5,129,1,
+ 47,8,129,1,11,47,5,129,6,31,14,131,3,47,5,129,8,31,10,132,14,31,5,129,
+ 10,31,8,132,13,31,5,129,10,31,9,132,13,31,5,129,9,31,10,132,14,31,5,129,
+ 6,31,14,1,130,3,47,5,129,2,47,9,129,1,11,47,5,130,9,47,13,11,14,63,
+ 5,130,1,12,79,30,31,5,132,6,12,30,11,3,12,31,5,138,12,31,5,138,12,31,
+ 5,138,12,31,5,138,12,31,5,138,11,31,5,128,128,4,31,12,3,11,30,9,128,5,
+ 31,30,47,9,128,5,63,14,11,12,5,128,5,47,10,132,5,47,1,132,5,31,13,133,
+ 5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,
+ 5,31,12,133,4,31,12,132,130,5,11,14,15,14,12,7,132,10,111,13,1,129,6,47,
+ 13,11,12,47,10,129,10,31,8,130,3,47,1,128,10,31,6,131,6,24,1,128,5,47,
+ 10,5,1,134,7,79,11,6,133,2,8,13,63,13,3,134,2,7,13,31,13,1,128,7,
+ 25,1,131,13,31,4,128,12,31,8,130,3,14,31,4,128,7,47,14,11,12,47,14,1,
+ 129,10,127,5,131,5,10,13,15,14,13,9,2,129,129,1,7,8,5,133,3,31,12,133,
+ 3,31,12,133,3,31,12,131,3,111,14,128,3,127,128,2,11,12,31,14,27,10,130,3,
+ 31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,
+ 31,12,133,3,31,14,1,132,2,47,14,11,8,131,12,63,12,131,1,9,13,31,11,128,
+ 128,7,31,9,131,2,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
+ 130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
+ 130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
+ 130,7,31,12,131,5,31,14,130,6,47,5,129,2,13,31,14,130,1,63,12,11,14,47,
+ 14,131,6,95,13,31,14,132,4,10,14,15,13,8,3,31,14,129,3,47,2,131,8,31,
+ 12,129,14,31,7,131,13,31,8,129,9,31,11,130,2,47,3,129,4,47,1,129,6,31,
+ 13,131,14,31,5,129,11,31,9,131,9,31,9,129,14,31,4,131,5,31,13,128,4,31,
+ 14,133,14,31,2,8,31,9,133,10,31,7,13,31,4,133,5,31,13,31,14,134,1,14,
+ 63,10,135,10,63,5,135,5,47,14,136,1,14,31,10,132,3,31,14,131,5,31,10,131,
+ 6,31,11,129,14,31,3,130,10,31,14,131,10,31,7,129,10,31,7,130,13,47,4,130,
+ 14,31,3,129,6,31,11,129,2,63,7,129,3,31,13,130,2,31,14,129,6,63,11,129,
+ 7,31,9,131,12,31,3,128,10,31,13,31,1,128,11,31,5,131,8,31,7,128,14,15,
+ 12,7,31,4,128,14,31,1,131,4,31,10,3,31,8,3,31,8,4,31,11,133,14,15,
+ 14,7,31,4,128,13,15,12,8,31,7,133,10,31,13,31,1,128,9,31,13,31,2,133,
+ 6,63,11,129,5,63,13,134,1,63,7,129,1,63,9,135,12,47,3,130,11,47,4,135,
+ 7,31,14,131,7,31,14,1,131,3,31,14,3,131,6,47,2,128,8,31,12,130,2,14,
+ 31,7,129,1,13,31,7,129,10,31,12,131,3,31,14,2,5,47,3,132,8,31,11,14,
+ 31,7,133,1,13,63,12,135,3,63,3,135,2,47,14,2,135,12,63,11,134,7,31,14,
+ 13,31,6,132,3,47,6,4,31,14,2,131,12,31,10,129,9,31,12,130,8,31,14,1,
+ 129,1,13,31,7,128,2,47,5,131,3,47,2,5,31,13,132,9,31,8,1,47,3,131,
+ 14,31,3,128,10,31,7,130,3,31,13,129,5,31,12,130,8,31,8,129,1,47,1,129,
+ 12,31,3,130,10,31,5,128,1,31,13,131,5,31,10,128,5,31,8,131,1,14,15,14,
+ 128,10,31,3,132,10,31,3,14,15,13,133,5,31,11,31,8,133,1,14,63,3,134,10,
+ 47,13,135,5,47,8,135,1,47,3,135,3,31,12,136,11,31,6,133,7,10,13,31,14,
+ 1,133,12,63,5,134,11,14,13,10,3,134,1,127,31,5,2,127,31,5,1,10,75,13,
+ 47,5,133,1,13,31,11,134,12,31,13,1,133,10,31,14,2,133,7,47,4,133,5,47,
+ 6,133,3,14,31,9,133,1,13,31,11,134,11,31,13,1,133,3,47,13,91,20,127,31,
+ 7,3,127,31,6,130,2,11,14,31,8,130,12,63,8,129,2,47,14,11,5,129,3,47,
+ 2,131,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,4,31,
+ 13,132,10,31,11,130,1,14,47,5,130,1,47,10,131,1,12,47,6,132,9,31,12,132,
+ 4,31,13,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
+ 3,47,2,131,2,47,14,11,5,130,12,63,8,130,2,11,14,31,8,128,47,2,128,47,
+ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,
+ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,
+ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,1,47,13,6,130,1,79,4,
+ 129,1,10,12,47,8,132,11,31,10,132,7,31,10,132,7,31,10,132,7,31,10,132,7,
+ 31,10,132,7,31,10,132,7,31,11,132,5,47,3,131,1,13,47,6,131,4,47,8,130,
+ 1,14,31,14,5,130,5,31,14,1,131,7,31,11,132,7,31,10,132,7,31,10,132,7,
+ 31,10,132,7,31,10,132,7,31,10,132,11,31,10,130,10,12,47,8,129,1,79,4,129,
+ 1,47,13,6,130,129,5,12,14,13,9,3,129,4,10,2,129,6,95,28,31,14,1,128,
+ 14,31,11,12,95,8,129,3,11,3,129,2,8,13,15,13,6,213,128,3,13,14,5,129,
+ 11,31,13,129,11,31,13,129,3,13,14,5,164,129,3,10,30,11,4,130,4,95,6,129,
+ 13,15,11,3,2,8,31,2,4,15,13,131,11,15,7,6,15,11,131,8,15,8,4,15,
+ 13,131,11,15,6,128,13,15,11,3,2,8,31,2,128,4,14,79,6,130,3,10,30,11,
+ 4,255,131,129,4,1,131,18,130,5,15,12,1,129,2,13,14,2,129,13,31,12,1,2,
+ 13,31,10,129,2,13,31,12,13,31,11,1,130,2,13,63,11,1,132,3,63,2,132,2,
+ 13,63,12,1,130,2,13,31,12,13,31,12,1,129,12,31,11,1,2,13,31,9,129,3,
+ 14,11,1,129,2,29,2,130,3,1,131,17,165,1,10,123,11,7,128,2,127,31,11,128,
+ 2,127,31,11,206,1,10,123,91,10,1,2,127,127,3,2,127,127,2,235,128,6,31,9,
+ 128,11,31,4,1,31,13,128,4,31,7,128,9,31,2,128,12,15,10,194,129,9,14,11,
+ 1,130,2,12,14,6,131,8,14,12,1,129,4,47,6,130,10,47,130,2,47,7,129,4,
+ 47,6,130,10,31,14,130,2,47,7,130,9,14,11,1,130,2,13,14,6,131,8,14,11,
+ 1,128,129,7,13,15,11,2,129,7,63,13,1,128,14,79,6,2,95,8,128,14,79,6,
+ 128,7,63,13,1,129,7,13,14,11,2,160,130,1,13,15,14,1,131,10,31,5,131,6,
+ 31,9,131,2,14,15,13,1,131,9,31,5,132,2,14,15,12,133,6,31,9,133,10,31,
+ 5,132,1,13,15,14,1,155,129,10,31,5,133,1,14,15,14,1,133,4,31,10,134,9,
+ 31,6,133,1,31,13,133,8,31,6,132,4,31,11,132,1,13,15,14,1,132,9,31,5,
+ 161,
+};
+static const struct fos_glyph lg_glyphs[] = {
+ { 0, 5, 0, 0, 0, 86 }, /* 0x20 */
+ { 0, 9, 19, 0, -19, 145 }, /* 0x21 */
+ { 67, 9, 19, 0, -19, 140 }, /* 0x22 */
+ { 110, 18, 19, 0, -19, 292 }, /* 0x23 */
+ { 250, 15, 24, 0, -22, 245 }, /* 0x24 */
+ { 401, 22, 19, 0, -19, 360 }, /* 0x25 */
+ { 602, 19, 19, 0, -19, 297 }, /* 0x26 */
+ { 774, 4, 19, 0, -19, 67 }, /* 0x27 */
+ { 793, 10, 23, -1, -20, 137 }, /* 0x28 */
+ { 883, 9, 23, 0, -20, 137 }, /* 0x29 */
+ { 977, 11, 21, 0, -21, 172 }, /* 0x2a */
+ { 1054, 13, 14, 0, -14, 212 }, /* 0x2b */
+ { 1100, 7, 7, 0, -5, 114 }, /* 0x2c */
+ { 1128, 11, 10, 0, -10, 175 }, /* 0x2d */
+ { 1141, 7, 4, 0, -4, 118 }, /* 0x2e */
+ { 1160, 12, 19, 0, -19, 193 }, /* 0x2f */
+ { 1239, 15, 19, 0, -19, 245 }, /* 0x30 */
+ { 1391, 10, 19, 0, -19, 152 }, /* 0x31 */
+ { 1474, 15, 19, 0, -19, 238 }, /* 0x32 */
+ { 1593, 14, 19, 0, -19, 229 }, /* 0x33 */
+ { 1711, 16, 19, 0, -19, 253 }, /* 0x34 */
+ { 1812, 14, 19, 0, -19, 229 }, /* 0x35 */
+ { 1931, 14, 19, 0, -19, 229 }, /* 0x36 */
+ { 2075, 13, 19, 0, -19, 211 }, /* 0x37 */
+ { 2161, 14, 19, 0, -19, 230 }, /* 0x38 */
+ { 2306, 14, 19, 0, -19, 228 }, /* 0x39 */
+ { 2453, 10, 13, 0, -13, 153 }, /* 0x3a */
+ { 2490, 8, 15, 0, -13, 136 }, /* 0x3b */
+ { 2537, 13, 14, 0, -14, 212 }, /* 0x3c */
+ { 2612, 13, 13, 0, -13, 212 }, /* 0x3d */
+ { 2638, 13, 14, 0, -14, 212 }, /* 0x3e */
+ { 2710, 14, 19, 0, -19, 216 }, /* 0x3f */
+ { 2806, 22, 20, 0, -18, 355 }, /* 0x40 */
+ { 3052, 18, 19, 0, -19, 280 }, /* 0x41 */
+ { 3181, 17, 19, 0, -19, 269 }, /* 0x42 */
+ { 3305, 16, 19, 0, -19, 263 }, /* 0x43 */
+ { 3440, 17, 19, 0, -19, 267 }, /* 0x44 */
+ { 3566, 16, 19, 0, -19, 256 }, /* 0x45 */
+ { 3635, 15, 19, 0, -19, 243 }, /* 0x46 */
+ { 3700, 17, 19, 0, -19, 265 }, /* 0x47 */
+ { 3847, 17, 19, 0, -19, 275 }, /* 0x48 */
+ { 3974, 7, 19, 0, -19, 113 }, /* 0x49 */
+ { 4032, 16, 19, 0, -19, 251 }, /* 0x4a */
+ { 4140, 17, 19, 0, -19, 268 }, /* 0x4b */
+ { 4271, 15, 19, 0, -19, 247 }, /* 0x4c */
+ { 4332, 19, 19, 0, -19, 309 }, /* 0x4d */
+ { 4497, 18, 19, 0, -19, 289 }, /* 0x4e */
+ { 4651, 17, 19, 0, -19, 268 }, /* 0x4f */
+ { 4806, 16, 19, 0, -19, 257 }, /* 0x50 */
+ { 4925, 16, 22, 0, -19, 254 }, /* 0x51 */
+ { 5092, 17, 19, 0, -19, 265 }, /* 0x52 */
+ { 5217, 16, 19, 0, -19, 255 }, /* 0x53 */
+ { 5367, 16, 19, 0, -19, 250 }, /* 0x54 */
+ { 5450, 17, 19, 0, -19, 275 }, /* 0x55 */
+ { 5606, 16, 19, 0, -19, 264 }, /* 0x56 */
+ { 5738, 24, 19, 0, -19, 379 }, /* 0x57 */
+ { 5959, 17, 19, 0, -19, 266 }, /* 0x58 */
+ { 6100, 16, 19, 0, -19, 259 }, /* 0x59 */
+ { 6212, 15, 19, 0, -19, 239 }, /* 0x5a */
+ { 6298, 11, 25, 0, -21, 174 }, /* 0x5b */
+ { 6400, 12, 19, 0, -19, 193 }, /* 0x5c */
+ { 6477, 11, 25, 0, -21, 174 }, /* 0x5d */
+ { 6558, 13, 19, 0, -19, 201 }, /* 0x5e */
+ { 6634, 14, 3, 0, -3, 220 }, /* 0x5f */
+ { 6647, 6, 19, 0, -19, 95 }, /* 0x60 */
+ { 6661, 14, 14, 0, -14, 226 }, /* 0x61 */
+ { 6773, 15, 19, 0, -19, 241 }, /* 0x62 */
+ { 6907, 14, 14, 0, -14, 229 }, /* 0x63 */
+ { 7003, 15, 19, 0, -19, 241 }, /* 0x64 */
+ { 7139, 15, 14, 0, -14, 234 }, /* 0x65 */
+ { 7237, 10, 19, 0, -19, 162 }, /* 0x66 */
+ { 7316, 15, 19, 0, -14, 237 }, /* 0x67 */
+ { 7458, 15, 19, 0, -19, 235 }, /* 0x68 */
+ { 7586, 7, 20, 0, -20, 110 }, /* 0x69 */
+ { 7653, 9, 25, -2, -20, 108 }, /* 0x6a */
+ { 7759, 14, 19, 0, -19, 226 }, /* 0x6b */
+ { 7887, 6, 19, 0, -19, 103 }, /* 0x6c */
+ { 7964, 22, 14, 0, -14, 358 }, /* 0x6d */
+ { 8141, 15, 14, 0, -14, 235 }, /* 0x6e */
+ { 8249, 15, 14, 0, -14, 240 }, /* 0x6f */
+ { 8357, 15, 19, 0, -14, 243 }, /* 0x70 */
+ { 8494, 15, 19, 0, -14, 243 }, /* 0x71 */
+ { 8630, 10, 14, 0, -14, 162 }, /* 0x72 */
+ { 8696, 13, 14, 0, -14, 213 }, /* 0x73 */
+ { 8798, 10, 18, 0, -18, 162 }, /* 0x74 */
+ { 8880, 15, 14, 0, -14, 234 }, /* 0x75 */
+ { 8994, 14, 14, 0, -14, 218 }, /* 0x76 */
+ { 9088, 21, 14, 0, -14, 329 }, /* 0x77 */
+ { 9249, 14, 14, 0, -14, 223 }, /* 0x78 */
+ { 9349, 13, 19, 0, -14, 211 }, /* 0x79 */
+ { 9468, 12, 14, 0, -14, 197 }, /* 0x7a */
+ { 9533, 9, 25, 0, -21, 151 }, /* 0x7b */
+ { 9643, 5, 23, 0, -21, 82 }, /* 0x7c */
+ { 9712, 9, 25, 0, -21, 151 }, /* 0x7d */
+ { 9821, 14, 10, 0, -10, 226 }, /* 0x7e */
+ { 9858, 6, 10, 0, -10, 98 }, /* 0x80 */
+ { 9877, 10, 22, 0, -22, 163 }, /* 0x81 */
+ { 9939, 12, 14, 0, -14, 189 }, /* 0x82 */
+ { 10021, 13, 9, 0, -9, 202 }, /* 0x83 */
+ { 10037, 18, 9, 0, -9, 289 }, /* 0x84 */
+ { 10052, 5, 19, 0, -19, 78 }, /* 0x85 */
+ { 10076, 22, 4, 0, -4, 359 }, /* 0x86 */
+ { 10130, 8, 11, 0, -11, 136 }, /* 0x87 */
+ { 10164, 9, 12, 0, -12, 149 }, /* 0x88 */
+ { 10208, 10, 12, 0, -12, 159 }, /* 0x89 */
+};
+static const uint8_t lg_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern lg_kern[] = {
+ {39,45,-22},{39,52,-7},{39,65,-34},{39,74,-22},{39,97,-5},{39,99,-22},{39,100,-22},{39,101,-22},
+ {39,103,-15},{39,109,-6},{39,110,-6},{39,111,-22},{39,112,-6},{39,113,-15},{39,114,-6},{39,115,-10},
+ {44,45,-6},{44,48,-13},{44,84,-25},{44,86,-12},{44,87,-12},{44,89,-25},{44,99,-6},{44,100,-6},
+ {44,101,-6},{44,102,-4},{44,103,-6},{44,111,-6},{44,113,-6},{44,116,-4},{44,118,-17},{44,119,-17},
+ {44,121,-17},{45,39,-10},{45,44,-6},{45,45,-60},{45,46,-6},{45,55,-27},{45,84,-14},{45,102,-5},
+ {45,116,-5},{45,118,-11},{45,119,-11},{45,120,-10},{45,121,-11},{45,133,-11},{46,45,-6},{46,48,-13},
+ {46,84,-25},{46,86,-12},{46,87,-12},{46,89,-25},{46,99,-6},{46,100,-6},{46,101,-6},{46,102,-4},
+ {46,103,-6},{46,111,-6},{46,113,-6},{46,116,-4},{46,118,-17},{46,119,-17},{46,121,-17},{48,49,-7},
+ {50,49,-4},{50,51,-5},{52,39,-12},{52,49,-41},{52,55,-25},{53,49,-7},{54,49,-5},{55,44,-25},
+ {55,46,-25},{56,49,-7},{57,49,-9},{65,39,-38},{65,45,-7},{65,67,-8},{65,71,-8},{65,79,-8},
+ {65,81,-8},{65,83,-18},{65,84,-34},{65,85,-5},{65,86,-13},{65,87,-13},{65,89,-35},{65,90,6},
+ {65,99,-7},{65,100,-7},{65,101,-7},{65,102,-10},{65,103,-9},{65,111,-7},{65,113,-9},{65,116,-10},
+ {65,118,-19},{65,119,-19},{65,121,-19},{65,133,-29},{66,44,-4},{66,46,-4},{66,65,-14},{66,84,-7},
+ {66,86,-10},{66,87,-10},{66,88,-10},{66,89,-14},{66,102,-4},{66,103,-6},{66,113,-6},{66,115,-5},
+ {66,116,-4},{66,117,-4},{67,65,-4},{67,74,6},{67,86,-5},{67,87,-5},{67,89,-10},{67,103,-4},
+ {67,113,-4},{68,44,-4},{68,46,-4},{68,65,-14},{68,84,-7},{68,86,-10},{68,87,-10},{68,88,-10},
+ {68,89,-14},{68,102,-4},{68,103,-6},{68,113,-6},{68,115,-5},{68,116,-4},{68,117,-4},{69,86,4},
+ {69,87,4},{70,44,-36},{70,45,-22},{70,46,-36},{70,65,-29},{70,74,-23},{70,97,-19},{70,99,-22},
+ {70,100,-22},{70,101,-22},{70,103,-16},{70,109,-10},{70,110,-10},{70,111,-22},{70,112,-10},{70,113,-16},
+ {70,114,-10},{70,115,-19},{70,117,-12},{70,118,-21},{70,119,-21},{70,120,-19},{70,121,-21},{70,122,-10},
+ {71,65,-4},{71,74,6},{71,86,-5},{71,87,-5},{71,89,-10},{71,103,-4},{71,113,-4},{74,44,-4},
+ {74,46,-4},{74,65,-6},{74,67,-4},{74,71,-4},{74,79,-4},{74,81,-4},{75,45,-12},{75,65,7},
+ {75,67,-10},{75,71,-10},{75,74,-8},{75,79,-10},{75,81,-10},{75,83,-7},{75,99,-12},{75,100,-12},
+ {75,101,-12},{75,103,-10},{75,111,-12},{75,113,-10},{75,115,-5},{75,118,-17},{75,119,-17},{75,121,-17},
+ {76,39,-34},{76,65,11},{76,84,-37},{76,86,-16},{76,87,-16},{76,89,-18},{76,102,-7},{76,116,-7},
+ {76,118,-10},{76,119,-10},{76,121,-10},{76,122,5},{76,133,-21},{78,66,-4},{78,68,-4},{78,69,-4},
+ {78,70,-4},{78,78,-4},{78,80,-4},{79,65,-4},{79,74,6},{79,86,-5},{79,87,-5},{79,89,-10},
+ {79,103,-4},{79,113,-4},{80,44,-10},{80,45,-11},{80,46,-10},{80,65,-19},{80,74,-10},{80,86,-6},
+ {80,87,-6},{80,88,-12},{80,89,-12},{80,99,-11},{80,100,-11},{80,101,-11},{80,103,-7},{80,111,-11},
+ {80,113,-7},{80,115,-6},{81,65,-10},{81,74,6},{81,84,-5},{81,86,-12},{81,87,-12},{81,88,-12},
+ {81,89,-20},{81,103,-4},{81,113,-4},{82,65,10},{82,86,-7},{82,87,-7},{82,89,-10},{83,44,-4},
+ {83,46,-4},{83,84,-6},{83,86,-7},{83,87,-7},{83,88,-14},{83,89,-10},{84,44,-25},{84,45,-34},
+ {84,46,-25},{84,65,-26},{84,67,-15},{84,71,-15},{84,74,-17},{84,79,-15},{84,81,-15},{84,97,-12},
+ {84,99,-34},{84,100,-34},{84,101,-34},{84,103,-26},{84,105,-4},{84,109,-24},{84,110,-24},{84,111,-34},
+ {84,112,-24},{84,113,-26},{84,114,-24},{84,115,-25},{84,117,-20},{84,118,-21},{84,119,-21},{84,120,-22},
+ {84,121,-21},{85,44,-4},{85,46,-4},{85,65,-6},{85,67,-4},{85,71,-4},{85,79,-4},{85,81,-4},
+ {86,44,-26},{86,45,-25},{86,46,-26},{86,65,-42},{86,66,-4},{86,67,-13},{86,68,-4},{86,69,-4},
+ {86,70,-4},{86,71,-13},{86,74,-17},{86,75,-7},{86,78,-4},{86,79,-13},{86,80,-4},{86,81,-13},
+ {86,83,-7},{86,97,-24},{86,99,-25},{86,100,-25},{86,101,-25},{86,103,-23},{86,109,-6},{86,110,-6},
+ {86,111,-25},{86,112,-6},{86,113,-23},{86,114,-6},{86,115,-16},{86,117,-7},{86,118,-7},{86,119,-7},
+ {86,121,-7},{87,44,-26},{87,45,-25},{87,46,-26},{87,65,-42},{87,66,-4},{87,67,-13},{87,68,-4},
+ {87,69,-4},{87,70,-4},{87,71,-13},{87,74,-17},{87,75,-7},{87,78,-4},{87,79,-13},{87,80,-4},
+ {87,81,-13},{87,83,-7},{87,97,-24},{87,99,-25},{87,100,-25},{87,101,-25},{87,103,-23},{87,109,-6},
+ {87,110,-6},{87,111,-25},{87,112,-6},{87,113,-23},{87,114,-6},{87,115,-16},{87,117,-7},{87,118,-7},
+ {87,119,-7},{87,121,-7},{88,45,-13},{88,67,-10},{88,71,-10},{88,74,-5},{88,79,-10},{88,81,-10},
+ {88,83,-11},{88,97,-7},{88,99,-13},{88,100,-13},{88,101,-13},{88,103,-14},{88,111,-13},{88,113,-14},
+ {88,118,-12},{88,119,-12},{88,121,-12},{89,44,-39},{89,45,-32},{89,46,-39},{89,65,-47},{89,66,-4},
+ {89,67,-14},{89,68,-4},{89,69,-4},{89,70,-4},{89,71,-14},{89,74,-23},{89,78,-4},{89,79,-14},
+ {89,80,-4},{89,81,-14},{89,83,-10},{89,97,-25},{89,99,-32},{89,100,-32},{89,101,-32},{89,102,-16},
+ {89,103,-36},{89,109,-22},{89,110,-22},{89,111,-32},{89,112,-22},{89,113,-36},{89,114,-22},{89,115,-19},
+ {89,116,-16},{89,117,-16},{89,118,-16},{89,119,-16},{89,120,-16},{89,121,-16},{89,122,-10},{97,39,-10},
+ {97,84,-12},{97,89,-15},{97,118,-5},{97,119,-5},{97,121,-5},{97,133,-7},{98,39,-16},{98,44,-6},
+ {98,46,-6},{98,118,-8},{98,119,-8},{98,121,-8},{98,133,-5},{99,39,-10},{99,44,-10},{99,46,-10},
+ {99,118,-4},{99,119,-4},{99,120,-7},{99,121,-4},{99,133,-7},{101,39,-15},{101,44,-9},{101,46,-9},
+ {101,102,-4},{101,116,-4},{101,118,-10},{101,119,-10},{101,120,-9},{101,121,-10},{101,133,-10},{102,39,4},
+ {102,44,-22},{102,45,-16},{102,46,-22},{102,97,-5},{102,99,-16},{102,100,-16},{102,101,-16},{102,103,-12},
+ {102,111,-16},{102,113,-12},{102,115,-6},{102,133,6},{103,39,-4},{104,39,-16},{104,44,-6},{104,46,-6},
+ {104,118,-8},{104,119,-8},{104,121,-8},{104,133,-5},{107,45,-16},{107,97,-7},{107,99,-16},{107,100,-16},
+ {107,101,-16},{107,103,-11},{107,111,-16},{107,113,-11},{109,39,-16},{109,44,-6},{109,46,-6},{109,118,-8},
+ {109,119,-8},{109,121,-8},{109,133,-5},{110,39,-16},{110,44,-6},{110,46,-6},{110,118,-8},{110,119,-8},
+ {110,121,-8},{110,133,-5},{111,39,-10},{111,44,-6},{111,46,-6},{111,55,-27},{111,84,-14},{111,102,-5},
+ {111,116,-5},{111,118,-11},{111,119,-11},{111,120,-10},{111,121,-11},{111,133,-11},{112,39,-16},{112,44,-6},
+ {112,46,-6},{112,118,-8},{112,119,-8},{112,121,-8},{112,133,-5},{113,39,-4},{114,39,10},{114,44,-16},
+ {114,45,-4},{114,46,-16},{114,99,-4},{114,100,-4},{114,101,-4},{114,102,4},{114,103,-8},{114,111,-4},
+ {114,113,-8},{114,116,4},{114,118,7},{114,119,7},{114,121,7},{114,133,21},{115,39,-7},{115,115,-4},
+ {115,118,-15},{115,119,-15},{115,120,-5},{115,121,-15},{115,133,-10},{116,45,-4},{116,99,-4},{116,100,-4},
+ {116,101,-4},{116,111,-4},{118,44,-17},{118,45,-12},{118,46,-17},{118,97,-10},{118,99,-12},{118,100,-12},
+ {118,101,-12},{118,103,-13},{118,111,-12},{118,113,-13},{118,115,-15},{118,133,17},{119,44,-17},{119,45,-12},
+ {119,46,-17},{119,97,-10},{119,99,-12},{119,100,-12},{119,101,-12},{119,103,-13},{119,111,-12},{119,113,-13},
+ {119,115,-15},{119,133,17},{120,45,-13},{120,99,-13},{120,100,-13},{120,101,-13},{120,103,-10},{120,111,-13},
+ {120,113,-10},{121,44,-17},{121,45,-12},{121,46,-17},{121,97,-10},{121,99,-12},{121,100,-12},{121,101,-12},
+ {121,103,-13},{121,111,-12},{121,113,-13},{121,115,-15},{121,133,17},{133,45,-36},{133,65,-29},{133,97,-7},
+ {133,99,-36},{133,100,-36},{133,101,-36},{133,102,-5},{133,103,-32},{133,111,-36},{133,113,-32},{133,115,-29},
+ {133,116,-5},{133,118,-7},{133,119,-7},{133,120,-5},{133,121,-7},
+};
+const struct fos_font fos_font_lg_data = { lg_bits, lg_glyphs, lg_lut, lg_kern, 589, 27, 6 };
+
+static const uint8_t xl_bits[] = {
+ 130,2,14,63,7,133,3,79,9,133,2,79,8,133,2,79,8,133,1,79,7,133,1,79,
+ 7,133,1,79,7,134,79,6,134,79,6,134,14,63,6,134,14,63,5,134,14,63,5,134,
+ 13,63,4,134,13,63,4,134,12,63,4,134,12,63,3,134,11,63,3,134,11,63,3,134,
+ 11,63,2,134,10,63,2,134,10,63,1,134,9,63,1,134,7,47,14,200,3,11,14,13,
+ 8,134,3,79,9,133,9,95,1,132,11,95,3,132,9,95,1,132,2,79,9,134,3,11,
+ 14,13,8,131,1,14,63,4,128,1,14,63,4,1,79,4,128,1,79,4,128,79,4,129,
+ 79,4,128,14,63,3,129,14,63,3,128,13,63,2,129,13,63,2,128,13,63,1,129,13,
+ 63,1,128,12,63,1,129,12,63,1,128,11,63,130,11,63,129,10,47,14,130,10,47,14,
+ 129,10,47,13,130,10,47,13,129,7,47,11,130,7,47,11,255,255,232,135,2,14,63,8,
+ 132,8,79,2,138,4,79,8,132,11,79,1,138,7,79,6,132,13,63,14,139,9,79,3,
+ 131,1,79,12,139,11,79,1,131,3,79,10,139,13,63,14,132,5,79,7,139,79,12,132,
+ 7,79,5,138,3,79,10,132,10,79,3,134,2,14,127,127,111,3,131,3,127,127,127,4,
+ 131,3,127,127,127,4,131,3,127,127,127,4,131,2,127,127,127,3,134,1,79,11,132,8,
+ 79,4,138,3,79,9,132,10,79,2,138,5,79,7,132,12,79,139,7,79,5,132,14,63,
+ 13,139,9,79,3,131,1,79,11,139,11,79,1,131,3,79,9,139,13,63,14,132,5,79,
+ 8,135,12,127,127,111,7,132,14,127,127,111,8,132,14,127,127,111,8,132,14,127,127,111,
+ 8,132,12,127,127,111,7,135,12,79,1,131,4,79,8,139,14,63,13,132,6,79,6,138,
+ 2,79,10,132,8,79,4,138,4,79,8,132,11,79,1,138,6,79,6,132,13,63,14,139,
+ 9,79,3,131,1,79,12,139,11,79,1,131,3,79,9,139,5,55,6,132,1,71,3,165,
+ 135,3,47,13,144,4,63,144,4,47,14,144,4,47,14,142,2,7,12,63,9,4,138,1,
+ 9,127,15,12,3,135,1,13,127,47,14,4,134,12,127,79,14,3,132,6,127,111,12,132,
+ 13,79,12,3,128,2,8,95,4,130,2,79,14,1,131,8,79,9,130,5,79,8,132,1,
+ 79,12,130,6,79,5,133,13,63,14,130,6,79,5,133,11,63,14,130,4,79,8,133,10,
+ 63,13,130,1,79,14,1,142,11,79,11,1,141,4,95,12,2,141,9,95,14,4,140,1,
+ 12,111,8,140,1,12,111,12,2,139,1,10,111,14,4,140,7,127,6,140,3,13,111,7,
+ 140,1,10,111,5,141,6,14,79,14,1,141,3,14,79,8,142,4,79,13,130,2,11,60,
+ 4,133,12,79,1,129,4,79,7,133,8,79,2,129,4,79,8,133,9,79,3,129,3,79,
+ 11,133,11,79,1,129,1,95,4,131,4,79,14,131,11,79,14,5,17,6,14,79,10,131,
+ 5,127,127,4,132,11,127,95,10,133,2,13,127,63,12,1,134,2,11,127,31,10,1,137,
+ 5,11,14,63,14,10,4,141,4,63,1,143,3,63,1,143,4,63,1,143,3,47,14,1,
+ 135,133,2,7,12,30,13,9,3,139,11,47,5,140,6,14,111,10,1,136,4,47,13,140,
+ 7,127,31,12,1,135,12,47,6,139,4,47,13,5,1,128,3,10,47,9,134,6,47,12,
+ 140,11,31,12,1,132,8,47,2,133,13,47,5,139,1,47,3,134,13,31,7,132,7,47,
+ 12,140,3,31,14,135,9,31,9,131,1,14,47,4,140,3,31,14,135,9,31,9,131,8,
+ 47,10,141,1,47,4,134,13,31,7,130,1,14,47,3,142,11,31,12,1,132,8,47,2,
+ 130,9,47,9,143,4,47,13,5,1,128,3,10,47,9,130,2,63,2,144,7,127,31,12,
+ 1,130,10,47,8,146,6,14,111,10,1,130,3,47,14,1,147,2,7,12,30,13,9,4,
+ 132,11,47,7,160,4,47,14,1,160,12,47,6,160,5,47,13,161,13,47,5,160,6,47,
+ 12,160,1,14,47,4,160,7,47,11,132,6,11,14,15,14,10,5,148,1,14,47,3,130,
+ 2,12,111,11,1,146,9,47,10,130,2,14,127,15,13,1,144,2,63,2,130,12,31,14,
+ 7,2,128,2,9,47,10,144,10,47,9,130,6,47,3,132,6,47,2,142,3,47,14,1,
+ 130,11,31,8,134,11,31,8,142,11,47,7,131,14,31,3,134,6,31,11,141,4,47,14,
+ 1,131,47,2,134,5,31,12,141,12,47,6,132,14,31,3,134,6,31,11,140,5,47,13,
+ 133,11,31,8,134,11,31,8,140,13,47,5,133,6,47,4,132,6,47,2,139,6,47,12,
+ 135,12,31,14,7,2,128,2,9,47,10,139,1,14,47,4,135,2,14,127,15,13,1,139,
+ 7,47,11,137,2,13,111,11,1,140,13,31,14,3,139,5,11,13,15,13,10,4,134,134,
+ 1,6,10,13,14,15,13,10,6,146,5,14,127,13,4,143,6,127,63,6,141,3,127,95,
+ 4,140,11,127,95,13,139,2,95,9,2,1,7,95,5,138,6,79,11,131,8,79,9,138,
+ 7,79,6,131,2,79,11,138,8,79,4,131,1,79,12,138,6,79,6,131,3,79,11,138,
+ 3,79,10,131,9,79,8,139,13,79,3,129,4,95,4,139,6,79,12,128,3,14,79,13,
+ 141,12,79,10,14,95,4,141,2,127,63,7,143,6,127,31,8,145,13,127,7,145,10,127,
+ 4,145,11,127,15,4,144,10,127,31,13,1,132,1,136,7,127,63,11,131,2,14,10,2,
+ 133,2,95,12,2,13,79,7,130,10,47,8,1,131,10,79,13,1,128,2,14,79,4,128,
+ 4,79,7,131,14,79,3,130,5,79,14,2,13,63,14,1,130,3,79,11,132,8,127,47,
+ 7,131,5,79,7,133,11,127,15,13,132,6,79,7,133,1,13,127,4,132,5,79,10,134,
+ 3,111,8,133,3,95,3,133,8,111,1,134,14,79,14,6,1,128,2,6,13,127,9,134,
+ 9,127,127,79,5,133,2,14,127,127,63,14,2,133,4,127,95,12,10,79,11,134,3,12,
+ 127,31,13,6,129,12,79,7,135,4,9,12,14,15,14,13,11,8,4,131,3,14,63,14,
+ 129,1,14,63,8,128,1,79,9,129,79,8,129,14,63,7,129,13,63,6,129,13,63,6,
+ 129,12,63,5,129,11,63,4,129,10,63,3,129,10,63,2,129,7,47,14,1,255,192,132,
+ 12,63,12,134,7,79,8,133,1,14,79,2,133,7,79,11,134,13,79,6,133,4,95,1,
+ 133,9,79,11,134,14,79,7,133,4,95,3,133,8,79,14,134,12,79,10,134,95,7,133,
+ 3,95,4,133,5,95,2,133,8,95,134,10,79,13,134,11,79,11,134,13,79,10,134,14,
+ 79,9,134,14,79,8,134,95,8,134,95,8,134,95,8,134,14,79,8,134,14,79,9,134,
+ 13,79,10,134,11,79,11,134,10,79,12,134,8,79,14,134,6,95,1,133,4,95,4,133,
+ 1,95,7,134,12,79,10,134,9,79,13,134,4,95,2,133,1,14,79,6,134,10,79,10,
+ 134,5,79,14,1,134,14,79,5,134,7,79,10,134,1,14,79,1,134,8,79,8,134,1,
+ 13,63,12,130,130,12,63,12,135,8,79,7,134,2,79,14,1,134,11,79,7,134,6,79,
+ 13,134,1,95,4,134,11,79,9,134,7,79,14,134,3,95,4,134,14,79,8,134,11,79,
+ 12,134,8,95,134,4,95,3,133,2,95,6,134,95,8,134,13,79,10,134,12,79,11,134,
+ 11,79,13,134,9,79,14,134,9,79,14,134,9,95,134,8,95,134,9,95,134,9,79,14,
+ 134,10,79,14,134,11,79,12,134,12,79,11,134,13,79,10,134,95,8,133,2,95,5,133,
+ 5,95,3,133,8,79,14,134,11,79,11,134,14,79,8,133,3,95,3,133,7,79,14,134,
+ 12,79,9,133,1,95,4,133,6,79,13,134,11,79,6,133,2,79,14,1,133,8,79,6,
+ 134,12,63,12,132,134,8,31,10,141,10,31,11,141,10,31,11,136,9,6,130,10,31,11,
+ 130,6,10,130,4,31,12,3,128,10,31,11,128,3,12,31,5,129,12,63,9,11,31,12,
+ 8,63,13,129,7,14,127,79,7,130,2,10,127,31,11,2,133,4,12,95,13,5,135,2,
+ 11,95,12,2,134,7,14,127,15,8,1,130,4,13,127,63,13,4,129,13,63,11,12,31,
+ 12,11,63,14,129,6,31,13,5,128,10,31,11,128,5,14,31,7,130,11,8,1,129,10,
+ 31,11,129,1,9,12,1,135,10,31,11,141,10,31,11,141,8,31,10,255,255,238,135,2,
+ 63,2,143,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,143,3,
+ 63,3,136,8,127,127,31,8,129,10,127,127,31,10,129,10,127,127,31,10,129,10,127,127,
+ 31,10,129,8,127,127,31,8,136,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,
+ 143,3,63,3,143,3,63,3,143,2,63,2,255,161,129,1,14,47,14,131,2,63,13,131,
+ 4,63,9,131,6,63,6,131,8,63,3,131,10,47,14,132,11,47,11,132,13,47,7,132,
+ 63,4,131,2,63,1,131,4,47,12,132,4,47,8,131,128,8,127,63,12,129,10,127,63,
+ 14,129,10,127,63,14,129,10,127,63,14,129,8,127,63,12,255,208,130,7,13,14,12,4,
+ 132,9,79,3,130,1,95,9,130,3,95,12,130,1,95,9,131,9,79,3,132,7,13,14,
+ 11,3,130,138,10,63,14,139,1,79,12,139,5,79,8,139,9,79,3,139,14,63,13,139,
+ 3,79,9,139,8,79,4,139,12,63,14,139,2,79,10,139,7,79,6,139,11,79,1,138,
+ 1,79,12,139,5,79,7,139,10,79,2,139,14,63,13,139,4,79,8,139,8,79,4,139,
+ 13,63,14,139,2,79,10,139,7,79,5,139,12,79,1,138,1,79,11,139,6,79,7,139,
+ 10,79,2,139,14,63,12,139,4,79,8,139,9,79,3,139,13,63,14,139,3,79,9,139,
+ 8,79,5,139,12,79,1,138,2,79,11,139,6,79,6,139,11,79,2,139,13,63,11,139,
+ 134,5,10,13,14,15,13,11,7,2,139,4,13,127,15,9,137,6,127,63,12,1,134,4,
+ 127,95,11,134,13,127,111,6,132,6,95,7,1,128,4,12,79,13,132,11,79,7,131,1,
+ 14,79,3,131,14,63,14,133,7,79,6,131,79,12,133,4,79,8,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
+ 79,9,130,1,79,11,133,3,79,9,131,79,12,133,4,79,8,131,14,63,14,133,7,79,
+ 6,131,11,79,7,131,1,14,79,3,131,6,95,7,1,128,4,12,79,13,133,13,127,111,
+ 6,133,4,127,95,11,135,6,127,63,12,1,136,4,13,127,15,9,140,5,10,13,14,15,
+ 14,11,7,2,134,130,1,7,13,79,6,130,2,8,14,111,8,129,5,127,31,8,129,7,
+ 127,31,8,129,6,127,31,8,129,6,127,31,8,129,3,11,8,5,2,5,79,8,134,4,
+ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
+ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
+ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
+ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
+ 79,8,134,4,79,8,134,4,79,8,134,3,79,6,129,133,2,8,12,14,15,14,12,9,
+ 3,138,9,127,15,11,1,134,1,12,127,47,13,2,133,11,127,79,12,132,5,127,111,6,
+ 131,13,79,11,3,128,3,12,79,13,130,2,79,14,1,130,1,14,79,2,129,6,79,8,
+ 132,9,79,5,129,8,79,6,132,7,79,7,129,8,79,5,132,6,79,7,129,8,79,5,
+ 132,7,79,6,129,3,72,1,132,11,79,4,140,1,14,79,1,140,6,79,12,141,13,79,
+ 7,140,5,79,14,1,140,13,79,9,140,8,79,14,1,139,3,95,6,140,12,79,12,140,
+ 7,95,3,139,3,95,7,139,1,13,79,11,140,9,79,14,2,139,5,95,5,139,2,14,
+ 79,9,140,12,79,13,1,139,8,79,14,3,139,4,95,6,139,1,14,79,10,140,6,127,
+ 127,31,2,128,7,127,127,31,3,128,7,127,127,31,3,128,7,127,127,31,3,128,5,127,
+ 127,31,2,128,1,14,127,127,3,129,2,127,127,15,4,129,2,127,127,15,4,129,2,127,
+ 127,15,4,129,1,14,127,127,3,139,1,14,79,13,140,11,79,14,3,139,7,95,6,139,
+ 4,95,10,139,1,14,79,13,1,139,11,95,3,139,7,95,6,139,4,95,10,139,1,13,
+ 95,11,5,138,1,13,127,13,3,137,2,13,127,14,2,137,2,13,10,6,9,79,11,142,
+ 4,79,4,142,11,63,9,142,7,63,13,142,5,79,1,141,4,79,3,141,3,79,4,129,
+ 1,68,133,3,79,5,129,8,79,3,132,4,79,5,129,8,79,4,132,4,79,4,129,7,
+ 79,6,132,6,79,3,129,6,79,9,132,9,79,1,129,4,79,14,1,130,1,14,63,13,
+ 130,1,14,79,12,3,1,3,12,79,9,131,9,127,111,3,131,1,14,127,79,10,133,4,
+ 14,127,47,13,1,134,3,12,127,15,11,1,137,4,9,12,14,15,14,12,9,4,133,134,
+ 1,14,63,14,143,6,79,12,143,11,79,7,142,2,95,2,142,6,79,13,143,11,79,8,
+ 142,1,95,3,142,6,79,13,143,11,79,8,142,1,95,4,142,6,79,14,143,11,79,9,
+ 142,1,95,4,142,6,79,14,143,11,79,10,131,13,63,10,132,1,95,5,131,79,12,132,
+ 6,79,14,1,131,79,12,132,11,79,10,132,79,12,131,1,95,5,132,79,12,131,6,95,
+ 1,132,79,12,131,11,79,11,133,79,12,130,1,127,127,63,14,1,2,127,127,79,18,127,
+ 127,79,18,127,127,79,2,1,14,127,127,47,14,1,141,79,12,144,79,12,144,79,12,144,
+ 79,12,144,79,12,144,79,12,144,79,12,144,79,12,144,13,63,10,130,129,14,127,127,5,
+ 129,1,127,127,15,7,129,1,127,127,15,7,129,1,127,127,15,7,129,1,127,127,15,5,
+ 129,1,79,12,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,
+ 141,1,79,11,141,1,79,11,141,1,79,11,128,2,9,13,15,14,12,7,1,132,1,79,
+ 11,7,111,13,2,131,1,127,111,13,1,130,1,127,127,9,130,1,127,127,15,1,129,1,
+ 95,13,5,17,7,95,6,129,1,95,3,131,9,79,9,130,11,60,9,132,3,79,11,142,
+ 79,13,142,13,63,14,142,12,79,142,12,79,130,7,56,5,133,13,63,14,130,14,63,13,
+ 133,14,63,13,130,13,79,2,131,2,79,12,130,10,79,8,131,8,79,9,130,6,95,7,
+ 17,7,95,6,130,1,14,127,95,14,1,131,7,127,95,7,133,10,127,63,10,135,7,127,
+ 31,7,137,1,7,11,14,31,13,11,7,1,132,133,1,7,11,13,30,13,10,6,138,7,
+ 14,127,13,4,135,10,127,63,6,133,8,127,95,3,131,2,127,111,11,131,8,79,14,6,
+ 1,2,10,95,2,130,12,79,6,131,12,79,6,130,14,63,14,132,6,79,7,130,79,12,
+ 132,4,79,8,129,1,79,12,132,2,77,6,129,1,79,12,141,1,79,12,141,1,79,12,
+ 1,8,13,15,14,12,8,2,134,79,14,13,111,7,133,127,111,7,132,127,127,4,131,127,
+ 127,12,131,111,7,17,7,95,3,130,95,8,131,9,79,8,130,95,2,131,3,79,10,130,
+ 95,133,79,12,130,79,14,133,13,63,13,130,79,13,133,13,63,14,130,79,12,133,12,79,
+ 130,79,12,133,12,79,130,14,63,13,133,13,79,130,13,63,14,133,14,79,130,11,79,2,
+ 131,3,79,13,130,8,79,8,131,9,79,11,130,4,95,7,17,8,95,7,131,13,127,111,
+ 2,131,5,127,95,8,133,8,127,63,10,135,6,14,127,15,7,137,1,7,11,13,31,14,
+ 11,7,1,132,1,14,127,127,13,128,2,127,127,31,128,3,127,127,31,128,3,127,127,31,
+ 128,3,127,127,31,128,3,63,8,133,5,79,13,128,3,63,8,133,9,79,9,128,1,9,
+ 42,4,133,13,79,4,139,2,95,1,139,7,79,11,140,11,79,6,139,1,95,2,139,4,
+ 79,13,140,9,79,9,140,13,79,4,139,2,79,14,140,7,79,11,140,11,79,6,139,1,
+ 14,79,2,139,4,79,13,140,9,79,8,140,13,79,4,139,2,79,14,140,6,79,11,140,
+ 11,79,6,140,14,79,2,139,4,79,13,140,8,79,8,140,13,79,4,139,2,79,14,140,
+ 6,79,10,140,10,79,6,140,14,79,2,139,4,79,13,140,6,79,7,136,133,2,7,11,
+ 14,15,14,13,10,5,139,8,127,15,13,4,136,11,127,63,5,134,8,127,95,3,132,2,
+ 127,111,11,132,7,79,14,5,1,2,9,95,2,131,12,79,5,131,11,79,7,131,14,63,
+ 14,132,4,79,10,130,1,79,10,132,1,79,11,130,1,79,9,133,79,11,131,14,63,11,
+ 132,1,79,10,131,12,63,14,132,4,79,8,131,7,79,6,131,10,79,3,131,2,79,14,
+ 5,1,2,9,79,13,133,7,127,95,4,134,9,127,63,8,136,11,127,31,6,136,9,127,
+ 47,12,2,134,8,127,79,14,1,132,2,79,14,6,1,2,10,79,9,132,6,79,7,131,
+ 12,79,1,131,11,79,1,131,6,79,5,131,14,63,12,132,2,79,9,131,79,10,133,79,
+ 11,130,1,79,9,133,79,12,130,1,79,10,132,1,79,11,131,14,63,12,132,2,79,10,
+ 131,12,79,1,131,5,79,8,131,9,79,6,131,11,79,4,131,4,79,14,6,1,2,9,
+ 79,14,133,12,127,95,7,133,3,127,79,13,135,6,127,47,13,2,136,4,13,127,11,2,
+ 138,1,6,11,14,15,14,13,9,4,134,132,1,6,10,13,14,15,14,11,7,2,137,6,
+ 14,127,15,8,135,9,127,63,10,133,6,127,95,7,131,1,14,127,111,1,130,5,95,9,
+ 2,1,5,14,79,7,130,9,79,11,131,5,79,11,130,11,79,4,132,14,63,13,130,12,
+ 79,1,132,12,79,130,13,79,133,11,79,1,129,13,79,133,10,79,2,129,13,79,133,10,
+ 79,2,129,12,79,2,132,11,79,2,129,11,79,3,132,12,79,2,129,9,79,5,132,14,
+ 79,2,129,7,79,10,131,4,95,3,129,3,95,9,2,1,5,14,95,3,130,12,127,127,
+ 3,130,4,127,127,3,131,7,127,111,3,132,6,111,14,13,79,3,133,1,8,12,14,15,
+ 13,9,2,10,79,3,141,10,79,3,141,10,79,3,129,2,72,2,132,10,79,3,129,6,
+ 79,6,132,10,79,3,129,6,79,7,132,11,79,3,129,5,79,9,132,13,79,2,129,3,
+ 79,14,1,130,5,79,14,131,14,79,12,2,1,5,14,79,11,131,7,127,111,4,131,1,
+ 13,127,79,11,133,3,14,127,47,12,1,134,2,12,127,15,9,1,137,4,9,13,14,15,
+ 14,11,8,2,133,131,7,13,14,12,4,134,8,79,4,133,14,79,11,132,2,95,13,133,
+ 14,79,11,133,8,79,4,134,7,13,14,12,4,255,137,7,13,14,12,4,134,8,79,4,
+ 133,14,79,11,132,2,95,13,133,14,79,11,133,8,79,4,134,7,13,14,12,4,131,130,
+ 5,13,15,12,4,132,6,79,4,131,14,79,13,130,3,111,2,129,3,111,2,130,14,79,
+ 13,131,7,79,5,132,6,13,15,13,5,232,14,63,1,131,2,63,14,132,3,63,11,132,
+ 5,63,8,132,6,63,5,132,7,63,2,132,9,47,14,133,10,47,11,133,11,47,8,133,
+ 13,47,5,133,14,47,2,133,14,31,13,132,146,20,145,4,12,15,10,143,5,12,47,10,
+ 141,6,13,79,10,138,1,7,14,111,10,136,1,8,14,127,15,8,134,2,9,127,31,11,
+ 4,133,3,10,127,15,14,9,2,133,4,11,127,15,13,7,1,134,8,127,15,12,5,137,
+ 10,111,10,3,139,10,79,9,2,141,10,79,14,7,1,140,10,127,9,3,138,4,13,127,
+ 15,11,4,138,5,12,127,15,13,6,1,137,4,11,127,15,14,8,2,137,3,10,127,31,
+ 10,2,137,2,9,127,15,10,139,2,8,14,95,10,141,1,7,14,63,10,143,1,7,13,
+ 31,10,146,6,12,9,148,1,172,128,8,127,127,31,8,129,10,127,127,31,10,129,10,127,
+ 127,31,10,129,8,127,127,31,8,239,8,127,127,31,8,129,10,127,127,31,10,129,10,127,
+ 127,31,10,129,8,127,127,31,8,255,198,128,20,147,10,15,12,4,145,10,47,12,5,143,
+ 10,79,13,6,141,10,111,14,7,1,138,8,127,15,14,8,1,137,4,11,127,31,9,2,
+ 137,2,9,14,127,15,10,3,137,1,7,13,127,15,11,4,138,5,12,127,15,8,139,3,
+ 10,111,10,141,2,9,79,10,140,1,7,14,79,10,138,3,9,127,10,136,4,11,127,15,
+ 13,4,133,1,6,13,127,15,12,5,133,2,8,14,127,15,11,4,133,2,10,127,31,10,
+ 3,135,10,127,15,9,2,137,10,95,14,8,2,139,10,63,14,7,1,141,10,31,13,7,
+ 1,143,10,12,6,146,1,191,133,3,9,12,14,15,14,12,9,3,137,1,11,127,15,11,
+ 1,134,3,13,127,47,13,2,132,1,13,127,79,12,1,131,10,127,111,7,130,3,95,9,
+ 2,128,3,12,79,14,130,8,79,10,131,1,14,79,3,129,11,79,2,132,9,79,6,129,
+ 13,63,14,133,6,79,7,129,14,63,13,133,5,79,8,129,11,61,10,133,7,79,7,141,
+ 12,79,5,140,6,95,1,139,4,95,10,139,4,111,3,138,4,111,7,138,4,111,8,138,
+ 1,14,95,8,139,9,95,7,140,14,79,8,140,2,79,13,141,3,79,9,141,4,79,8,
+ 141,3,79,8,142,4,53,1,205,4,12,14,13,7,142,3,79,8,141,10,95,1,140,12,
+ 95,2,140,10,95,141,3,79,8,142,4,12,14,13,7,136,142,1,6,9,12,30,15,14,
+ 13,10,7,3,151,4,11,127,63,12,6,147,3,12,127,127,12,3,144,8,127,127,63,6,
+ 141,1,11,95,11,6,3,1,128,1,2,4,8,13,95,7,139,1,12,79,8,1,137,5,
+ 13,79,4,137,1,12,63,12,2,140,1,10,63,14,1,136,9,63,10,144,10,63,8,135,
+ 5,63,9,145,1,13,47,14,1,133,1,14,47,11,132,5,11,30,12,6,5,43,3,131,
+ 5,63,5,133,8,47,14,1,131,9,127,31,5,132,13,47,10,132,1,14,47,6,131,6,
+ 127,47,3,132,8,47,13,132,7,47,12,132,14,47,9,1,2,12,63,1,132,5,63,132,
+ 13,47,6,131,4,47,12,130,4,47,14,133,3,63,1,130,2,47,14,1,131,7,47,7,
+ 130,3,47,12,133,3,63,1,130,6,47,10,132,9,47,4,130,5,47,10,133,3,63,131,
+ 9,47,6,132,11,47,2,130,6,47,8,133,4,63,131,12,47,4,132,13,47,131,8,47,
+ 6,133,7,47,12,131,14,47,1,132,47,14,131,10,47,4,133,11,47,9,130,1,63,132,
+ 2,47,12,131,12,47,3,132,1,14,47,5,130,1,63,132,4,47,10,131,13,47,4,132,
+ 7,63,1,130,1,63,132,5,47,9,130,1,63,9,131,3,14,47,9,132,63,1,131,4,
+ 47,12,130,6,79,7,2,1,6,14,47,14,2,132,14,47,4,131,1,63,6,1,5,14,
+ 127,79,6,133,12,47,8,132,10,127,127,47,8,134,9,47,13,132,1,12,95,12,4,13,
+ 111,14,6,135,4,63,5,133,7,12,14,15,12,7,1,128,1,7,12,14,15,14,11,7,
+ 1,137,14,47,13,1,159,7,63,11,159,1,13,63,10,1,139,2,145,5,79,13,4,136,
+ 1,8,15,8,145,7,95,12,7,3,1,128,1,2,5,10,63,2,145,8,127,127,31,8,
+ 146,5,14,127,111,10,1,147,1,8,14,127,47,10,3,151,1,5,9,12,14,15,14,13,
+ 12,9,5,1,143,135,12,79,9,142,2,95,14,142,5,111,2,141,8,111,5,141,12,111,
+ 9,141,127,12,140,3,127,15,140,6,127,15,3,139,10,63,11,63,7,139,13,47,14,5,
+ 63,10,138,1,63,11,2,63,13,138,5,63,9,128,14,63,1,137,8,63,6,128,12,63,
+ 5,137,11,63,3,128,9,63,8,137,14,63,129,6,63,11,136,3,63,13,129,3,63,14,
+ 136,6,63,10,129,1,79,3,135,9,63,7,130,13,63,6,135,13,63,4,130,10,63,9,
+ 134,1,79,1,130,7,63,13,134,4,63,14,131,4,79,1,133,7,63,11,131,1,79,4,
+ 133,11,63,8,132,13,63,8,133,14,63,5,132,11,63,11,132,2,127,127,14,132,5,127,
+ 127,15,2,131,9,127,127,15,6,131,12,127,127,15,9,130,1,127,127,31,12,130,4,79,
+ 6,134,10,79,1,129,7,79,3,134,7,79,4,129,10,79,135,4,79,7,129,13,63,12,
+ 135,2,79,10,128,2,79,9,136,14,63,14,128,3,79,6,136,10,79,1,129,3,127,15,
+ 14,12,9,5,136,4,127,79,14,6,134,4,127,111,10,133,4,127,127,9,132,4,127,127,
+ 15,3,131,4,79,8,130,2,8,95,10,131,4,79,8,132,6,79,14,131,4,79,8,133,
+ 12,79,3,130,4,79,8,133,8,79,4,130,4,79,8,133,6,79,5,130,4,79,8,133,
+ 6,79,4,130,4,79,8,133,7,79,2,130,4,79,8,133,12,63,13,131,4,79,8,132,
+ 5,79,8,131,4,79,8,130,2,8,79,14,1,131,4,127,127,4,132,4,127,95,14,3,
+ 133,4,127,95,13,3,133,4,127,111,14,4,132,4,79,8,130,2,7,14,63,13,1,131,
+ 4,79,8,132,4,79,9,131,4,79,8,133,10,79,1,130,4,79,8,133,4,79,6,130,
+ 4,79,8,133,2,79,9,130,4,79,8,133,1,79,11,130,4,79,8,133,2,79,11,130,
+ 4,79,8,133,4,79,10,130,4,79,8,133,9,79,9,130,4,79,8,132,3,95,5,130,
+ 4,79,8,130,1,6,14,95,1,130,4,127,127,15,9,131,4,127,127,13,1,131,4,127,
+ 111,13,2,132,4,127,95,10,1,133,3,127,31,13,11,8,2,133,134,4,9,12,14,15,
+ 14,12,9,4,139,3,12,127,15,12,3,136,5,127,79,6,134,3,127,111,4,133,12,127,
+ 111,13,132,4,95,9,2,128,2,8,95,5,131,9,79,10,132,8,79,10,131,12,79,2,
+ 132,1,79,13,131,13,63,14,134,13,63,14,131,14,63,14,134,13,79,131,14,63,14,134,
+ 5,56,6,131,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,
+ 14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,
+ 14,63,14,144,14,63,14,144,14,63,14,134,5,56,6,131,14,63,14,134,13,79,131,13,
+ 63,14,134,13,63,14,131,12,79,2,132,1,79,13,131,8,79,10,132,8,79,9,131,4,
+ 95,9,2,128,2,8,95,5,132,12,127,111,12,133,3,14,127,95,3,134,4,14,127,47,
+ 14,5,136,3,12,127,15,12,3,139,4,9,12,14,15,14,12,9,4,134,129,3,127,15,
+ 14,13,10,6,1,136,4,127,79,14,6,135,4,127,111,8,134,4,127,127,6,133,4,127,
+ 127,15,2,132,4,79,8,130,2,7,95,8,132,4,79,8,132,7,79,13,132,4,79,8,
+ 133,13,79,2,131,4,79,8,133,10,79,3,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
+ 133,8,79,4,131,4,79,8,133,11,79,3,131,4,79,8,132,1,14,79,2,131,4,79,
+ 8,132,8,79,13,132,4,79,8,130,2,8,95,9,132,4,127,127,15,2,132,4,127,127,
+ 7,133,4,127,111,9,134,4,127,79,14,6,135,3,127,15,14,13,10,6,1,134,129,3,
+ 127,127,14,1,130,4,127,127,15,2,130,4,127,127,15,2,130,4,127,127,15,2,130,4,
+ 127,127,14,1,130,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,
+ 142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,127,63,
+ 10,135,4,127,63,11,135,4,127,63,11,135,4,127,63,11,135,4,127,63,10,135,4,79,
+ 8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,
+ 8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,127,127,14,1,130,4,127,127,15,
+ 2,130,4,127,127,15,2,130,4,127,127,15,2,130,3,127,127,14,1,128,129,3,127,127,
+ 14,1,129,4,127,127,15,1,129,4,127,127,15,1,129,4,127,127,15,1,129,4,127,127,
+ 14,1,129,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,
+ 79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,127,63,9,134,
+ 4,127,63,11,134,4,127,63,11,134,4,127,63,11,134,4,127,63,9,134,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,3,79,6,139,134,5,9,12,14,15,14,13,9,5,139,3,13,127,15,13,
+ 4,136,6,127,79,7,134,4,127,111,5,133,13,127,111,14,1,131,5,95,8,2,128,2,
+ 8,95,7,131,9,79,9,132,7,79,11,131,12,79,1,133,14,63,13,131,13,63,14,134,
+ 12,79,131,14,63,13,134,12,79,131,14,63,13,134,11,79,131,14,63,13,134,1,50,1,
+ 131,14,63,13,144,14,63,13,144,14,63,13,144,14,63,13,144,14,63,13,130,9,127,13,
+ 131,14,63,13,130,11,127,15,131,14,63,13,130,11,127,15,131,14,63,13,130,11,127,15,
+ 131,14,63,13,130,9,127,15,131,14,63,13,134,12,79,131,14,63,13,134,12,79,131,14,
+ 63,13,134,12,79,131,14,63,13,134,12,79,131,14,63,13,134,12,79,131,13,63,14,134,
+ 13,63,14,131,12,79,1,132,1,79,13,131,9,79,9,132,8,79,10,131,5,95,8,2,
+ 128,2,8,95,5,132,13,127,111,13,133,4,127,111,4,134,6,127,79,5,136,3,13,127,
+ 15,12,3,139,5,9,13,14,15,14,12,9,4,134,129,3,79,6,133,8,63,14,1,131,
+ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
+ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
+ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
+ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
+ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,127,127,31,2,131,4,127,
+ 127,31,2,131,4,127,127,31,2,131,4,127,127,31,2,131,4,127,127,31,2,131,4,79,
+ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
+ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
+ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
+ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
+ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,3,79,6,133,8,63,14,1,129,129,
+ 2,79,6,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
+ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
+ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
+ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
+ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
+ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,3,79,6,129,140,5,79,5,
+ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
+ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
+ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
+ 142,6,79,6,142,6,79,6,130,3,52,1,133,6,79,6,129,2,79,9,133,6,79,6,
+ 129,2,79,10,133,6,79,6,129,2,79,10,133,6,79,6,129,2,79,10,133,6,79,6,
+ 129,2,79,11,133,7,79,5,129,1,79,13,133,10,79,4,130,13,79,5,131,2,95,1,
+ 130,8,79,14,6,17,4,13,79,12,131,2,127,127,5,132,7,127,95,11,134,9,127,63,
+ 12,1,135,6,14,127,15,8,138,1,6,10,13,14,15,13,11,7,2,134,129,2,79,6,
+ 134,10,79,5,130,4,79,8,133,4,79,14,1,130,4,79,8,133,12,79,7,131,4,79,
+ 8,132,4,79,14,1,131,4,79,8,132,12,79,6,132,4,79,8,131,5,79,13,133,4,
+ 79,8,131,13,79,6,133,4,79,8,130,6,79,13,134,4,79,8,130,13,79,5,134,4,
+ 79,8,129,7,79,12,135,4,79,8,128,1,14,79,4,135,4,79,8,128,7,79,11,136,
+ 4,79,8,1,14,79,3,136,4,79,24,79,11,137,4,79,9,14,79,3,137,4,127,47,
+ 14,138,4,127,63,5,137,4,127,63,12,137,4,127,79,3,136,4,127,79,9,136,4,111,
+ 8,14,79,1,135,4,95,13,128,8,79,7,135,4,95,4,128,2,79,13,135,4,79,10,
+ 130,11,79,5,134,4,79,8,130,5,79,11,134,4,79,8,131,13,79,3,133,4,79,8,
+ 131,7,79,9,133,4,79,8,131,1,95,1,132,4,79,8,132,10,79,7,132,4,79,8,
+ 132,4,79,13,132,4,79,8,133,13,79,5,131,4,79,8,133,6,79,11,131,4,79,8,
+ 133,1,14,79,3,130,4,79,8,134,9,79,9,130,3,79,6,134,3,14,63,14,128,129,
+ 2,79,6,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
+ 4,127,127,14,1,129,4,127,127,15,2,129,4,127,127,15,2,129,4,127,127,15,2,129,
+ 3,127,127,14,1,129,4,79,7,136,9,79,4,131,7,95,2,134,3,95,5,131,7,95,
+ 9,134,11,95,5,131,7,111,3,132,4,111,5,131,7,111,11,132,12,111,5,131,7,127,
+ 4,130,5,127,5,131,7,127,12,130,12,127,5,131,7,127,15,5,128,6,127,15,5,131,
+ 7,127,15,13,1,13,127,15,5,131,7,127,31,13,127,31,5,131,7,127,127,79,5,131,
+ 7,79,7,127,14,8,79,5,131,7,79,5,8,111,23,79,5,131,7,79,5,1,14,79,
+ 13,128,7,79,5,131,7,79,5,128,7,79,5,128,7,79,5,131,7,79,5,129,13,47,
+ 12,129,7,79,5,131,7,79,5,129,5,47,4,129,7,79,5,131,7,79,5,130,12,15,
+ 10,130,7,79,5,131,7,79,5,130,3,15,2,130,7,79,5,131,7,79,5,131,2,131,
+ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
+ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
+ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
+ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
+ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,5,79,4,136,
+ 5,79,4,129,129,2,79,14,1,134,14,63,8,131,4,95,7,133,1,79,10,131,4,95,
+ 12,133,1,79,10,131,4,111,2,132,1,79,10,131,4,111,8,132,1,79,10,131,4,111,
+ 13,132,1,79,10,131,4,127,3,131,1,79,10,131,4,127,8,131,1,79,10,131,4,127,
+ 14,131,1,79,10,131,4,127,15,4,130,1,79,10,131,4,127,15,9,130,1,79,10,131,
+ 4,127,15,14,130,1,79,10,131,4,127,31,5,129,1,79,10,131,4,79,13,63,10,129,
+ 1,79,10,131,4,79,7,14,63,1,128,1,79,10,131,4,79,6,9,63,6,128,1,79,
+ 10,131,4,79,6,4,63,11,128,1,79,10,131,4,79,6,128,13,63,2,1,79,10,131,
+ 4,79,6,128,8,63,7,1,79,10,131,4,79,6,128,3,63,12,1,79,10,131,4,79,
+ 6,129,13,63,4,79,10,131,4,79,6,129,7,63,10,79,10,131,4,79,6,129,2,127,
+ 31,10,131,4,79,6,130,12,127,15,10,131,4,79,6,130,6,127,15,10,131,4,79,6,
+ 130,1,127,15,10,131,4,79,7,131,11,127,10,131,4,79,7,131,5,127,10,131,4,79,
+ 7,131,1,14,111,10,131,4,79,7,132,9,111,10,131,4,79,7,132,4,111,10,131,4,
+ 79,7,133,14,95,10,131,4,79,7,133,8,95,10,131,4,79,7,133,3,95,10,131,3,
+ 79,5,134,12,79,8,129,134,3,8,12,14,15,14,13,9,5,139,2,11,127,15,13,5,
+ 136,4,14,127,63,7,134,2,14,127,95,6,133,11,127,111,14,1,131,3,95,10,3,128,
+ 2,7,95,8,131,8,79,10,132,5,79,13,131,11,79,3,133,12,79,1,130,13,63,14,
+ 134,9,79,3,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
+ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
+ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
+ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
+ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
+ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,13,63,14,
+ 134,9,79,3,130,11,79,3,133,12,79,1,130,8,79,10,132,5,79,13,131,3,95,10,
+ 3,128,2,7,95,8,132,11,127,111,14,1,132,2,14,127,95,6,134,4,14,127,63,8,
+ 136,2,11,127,15,13,5,139,3,8,12,14,15,14,13,10,5,134,129,4,127,31,14,12,
+ 8,2,135,5,127,95,9,134,5,127,111,11,1,132,5,127,127,9,132,5,127,127,15,4,
+ 131,5,79,7,130,1,7,14,79,11,131,5,79,7,132,4,95,1,130,5,79,7,133,10,
+ 79,5,130,5,79,7,133,6,79,7,130,5,79,7,133,4,79,8,130,5,79,7,133,3,
+ 79,8,130,5,79,7,133,5,79,7,130,5,79,7,133,10,79,6,130,5,79,7,132,4,
+ 95,2,130,5,79,7,130,1,6,14,79,13,131,5,127,127,15,6,131,5,127,127,12,132,
+ 5,127,111,13,2,132,5,127,95,11,1,133,5,127,31,14,13,9,4,135,5,79,7,143,
+ 5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,
+ 5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,
+ 5,79,7,143,4,79,5,141,134,4,9,12,14,15,14,12,7,2,139,2,11,127,15,8,
+ 137,3,13,127,47,11,1,134,1,13,127,79,10,134,9,127,111,5,132,2,95,9,2,128,
+ 3,12,79,12,132,6,79,10,131,1,13,79,3,131,10,79,3,132,7,79,6,131,12,79,
+ 133,4,79,8,131,13,63,14,133,2,79,9,131,14,63,14,133,2,79,10,131,14,63,14,
+ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
+ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
+ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
+ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
+ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,13,63,14,
+ 133,2,79,10,131,13,79,133,4,79,9,131,11,79,3,132,7,79,7,131,7,79,10,131,
+ 1,13,79,3,131,2,95,9,2,128,3,12,79,13,133,10,127,111,6,133,2,14,127,79,
+ 12,135,4,14,127,47,13,2,136,3,12,127,15,11,1,139,6,13,79,11,4,142,8,79,
+ 4,143,8,79,4,143,8,79,4,143,8,79,4,143,7,79,3,135,129,3,127,31,14,12,
+ 8,3,135,4,127,95,9,1,133,4,127,111,12,1,132,4,127,127,10,132,4,127,127,15,
+ 5,131,4,79,8,130,1,6,14,79,12,131,4,79,8,132,4,95,2,130,4,79,8,133,
+ 9,79,6,130,4,79,8,133,5,79,8,130,4,79,8,133,3,79,9,130,4,79,8,133,
+ 3,79,10,130,4,79,8,133,5,79,9,130,4,79,8,133,9,79,7,130,4,79,8,132,
+ 3,95,3,130,4,79,8,130,1,6,14,79,13,131,4,127,127,15,7,131,4,127,127,12,
+ 132,4,127,111,13,2,132,4,127,95,10,1,133,4,127,95,1,134,4,79,8,129,4,79,
+ 5,134,4,79,8,130,14,63,10,134,4,79,8,130,10,79,1,133,4,79,8,130,6,79,
+ 5,133,4,79,8,130,1,79,10,133,4,79,8,131,12,63,14,133,4,79,8,131,7,79,
+ 5,132,4,79,8,131,3,79,10,132,4,79,8,132,13,63,14,132,4,79,8,132,9,79,
+ 4,131,4,79,8,132,4,79,9,131,4,79,8,133,14,63,14,131,4,79,8,133,10,79,
+ 4,130,4,79,8,133,6,79,9,130,3,79,6,133,1,14,63,12,128,133,3,8,12,14,
+ 15,14,13,9,5,138,1,10,127,15,12,3,135,2,13,127,63,5,134,12,127,79,14,3,
+ 132,6,127,111,12,132,13,79,12,3,128,2,8,95,4,130,2,79,14,1,131,8,79,9,
+ 130,5,79,8,132,1,79,12,130,6,79,5,133,13,63,13,130,6,79,5,133,11,63,14,
+ 130,4,79,8,133,10,63,13,130,1,79,14,1,142,11,79,12,1,141,3,95,13,2,141,
+ 9,95,14,5,140,1,12,111,9,1,139,1,12,111,13,3,139,1,10,111,14,5,140,6,
+ 127,8,140,3,13,111,8,140,1,9,111,6,141,5,14,79,14,2,141,3,14,79,8,142,
+ 4,79,13,130,2,11,60,4,133,12,79,1,129,4,79,7,133,8,79,2,129,4,79,8,
+ 133,9,79,2,129,3,79,11,133,11,79,1,129,1,95,4,131,4,79,13,131,11,79,14,
+ 5,17,6,14,79,8,131,4,127,127,2,132,10,127,95,7,134,11,127,63,9,136,8,14,
+ 127,14,6,138,1,7,11,13,15,14,13,10,6,1,133,128,7,127,127,47,3,129,9,127,
+ 127,47,4,129,9,127,127,47,4,129,9,127,127,47,4,129,7,127,127,47,3,136,12,79,
+ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
+ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
+ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
+ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
+ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,10,63,14,136,129,6,
+ 79,3,133,5,79,5,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
+ 79,4,133,6,79,6,131,7,79,5,133,6,79,6,131,6,79,6,133,8,79,4,131,4,
+ 79,10,133,11,79,2,132,95,3,131,4,79,14,133,10,79,13,5,17,6,14,79,8,133,
+ 3,127,111,14,1,134,8,127,95,6,136,9,127,63,8,138,7,14,127,14,5,140,1,7,
+ 11,13,30,13,10,6,1,134,128,8,79,8,135,12,79,2,129,6,79,11,134,1,79,14,
+ 130,3,79,14,134,4,79,11,131,95,1,133,6,79,8,131,12,79,4,133,9,79,5,131,
+ 9,79,7,133,11,79,2,131,5,79,9,133,14,63,14,132,2,79,12,132,1,79,10,133,
+ 14,63,14,132,4,79,7,133,11,79,2,131,6,79,4,133,8,79,5,131,9,79,1,133,
+ 5,79,7,131,11,63,13,134,1,79,10,131,14,63,9,135,13,63,12,130,1,79,6,135,
+ 10,79,130,4,79,3,135,7,79,2,129,6,79,136,4,79,5,129,9,63,12,136,1,79,
+ 8,129,11,63,8,137,12,63,10,129,14,63,5,137,9,63,13,128,1,79,2,137,6,79,
+ 128,4,63,14,138,3,79,3,6,63,11,139,14,63,5,9,63,7,139,12,63,8,11,63,
+ 4,139,8,63,11,14,63,1,139,5,127,15,13,140,2,127,15,10,141,14,127,7,141,11,
+ 127,3,141,8,127,142,4,111,12,142,1,111,9,143,13,95,6,143,10,95,2,143,6,79,
+ 13,136,128,11,63,14,2,133,12,63,5,133,10,63,14,1,128,10,79,5,132,1,79,8,
+ 133,13,63,14,129,7,79,7,132,3,79,11,132,1,79,11,129,4,79,10,132,5,79,13,
+ 132,3,79,8,129,1,79,12,132,7,95,1,131,5,79,6,130,13,79,132,10,95,3,131,
+ 7,79,3,130,10,79,2,131,12,95,5,131,10,79,131,7,79,5,131,14,95,8,131,12,
+ 63,12,131,4,79,7,130,1,111,10,131,14,63,9,131,1,79,10,130,4,111,13,130,1,
+ 79,7,132,13,63,12,130,6,127,130,4,79,4,132,10,63,14,130,8,127,2,129,6,79,
+ 1,132,7,79,2,129,10,127,5,129,8,63,13,133,4,79,5,129,13,47,10,63,7,129,
+ 10,63,10,133,1,79,7,129,63,5,14,47,10,129,13,63,7,134,13,63,10,128,2,63,
+ 3,12,47,12,129,79,5,134,10,63,12,128,4,63,1,10,47,14,128,2,79,2,134,7,
+ 63,14,128,7,47,14,128,7,63,2,4,63,14,135,4,79,2,9,47,12,128,5,63,4,
+ 7,63,11,135,1,79,5,11,47,9,128,2,63,7,9,63,8,136,14,63,7,13,47,7,
+ 129,63,9,11,63,6,136,11,63,11,63,5,129,13,47,12,14,63,3,136,8,127,15,3,
+ 129,10,127,15,137,5,127,15,1,129,8,127,12,137,2,127,14,130,6,127,9,138,14,111,
+ 11,130,3,127,6,138,11,111,9,130,1,127,4,138,8,111,7,131,14,111,1,138,5,111,
+ 5,131,11,95,13,139,2,111,3,131,9,95,10,140,14,95,132,6,95,7,140,11,79,13,
+ 132,4,95,5,140,8,79,11,132,2,95,2,140,5,79,9,133,14,63,14,141,2,14,63,
+ 6,133,11,63,10,134,128,6,79,5,134,4,79,6,129,2,79,11,134,10,79,2,130,11,
+ 79,2,132,1,79,11,131,5,79,7,132,6,79,5,132,13,63,12,132,11,63,13,133,8,
+ 79,3,130,2,79,8,133,2,79,8,130,7,79,2,134,10,63,13,130,12,63,10,135,4,
+ 79,4,128,3,79,4,136,13,63,9,128,8,63,13,137,7,63,14,1,13,63,7,137,1,
+ 79,9,79,1,138,10,127,15,10,139,4,127,15,4,140,13,111,13,141,7,111,7,141,1,
+ 111,1,142,10,79,10,143,13,79,13,142,4,111,4,141,10,111,10,140,2,127,15,2,139,
+ 8,127,15,8,139,14,63,14,63,14,138,5,79,4,79,5,137,12,63,12,128,10,63,12,
+ 136,3,79,6,128,5,79,3,135,9,79,1,129,14,63,9,134,1,14,63,10,130,9,63,
+ 14,1,133,7,79,4,130,3,79,7,133,13,63,13,132,12,63,13,132,4,79,8,132,7,
+ 79,4,131,10,79,2,132,1,79,10,130,2,79,12,134,11,79,2,129,6,79,5,134,5,
+ 79,6,128,128,7,79,6,134,9,79,4,129,3,79,12,134,14,79,1,130,13,79,1,132,
+ 4,79,10,131,8,79,5,132,8,79,5,131,3,79,9,132,13,63,14,133,12,63,14,131,
+ 2,79,9,133,7,79,3,130,6,79,4,133,2,79,7,130,10,63,14,135,12,63,12,130,
+ 14,63,9,135,7,79,1,128,4,79,3,135,1,79,5,128,8,63,13,137,11,63,9,128,
+ 12,63,8,137,6,63,14,2,79,3,137,1,79,9,63,13,139,10,127,15,7,139,5,127,
+ 15,2,139,1,14,111,12,141,10,111,7,141,4,111,2,142,14,79,11,143,9,79,6,143,
+ 8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,
+ 8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,
+ 8,79,4,143,6,79,3,135,128,10,127,127,11,129,11,127,127,13,129,11,127,127,13,129,
+ 11,127,127,13,129,10,127,127,12,140,8,79,9,139,1,14,79,3,139,6,79,11,140,13,
+ 79,4,139,5,79,12,140,12,79,5,139,4,79,13,140,11,79,6,139,3,79,14,1,139,
+ 10,79,7,139,2,79,14,1,139,8,79,9,139,1,14,79,2,139,7,79,10,140,14,79,
+ 3,139,6,79,11,140,13,79,4,139,5,79,12,140,12,79,5,139,3,79,13,140,10,79,
+ 6,139,2,79,14,1,139,9,79,8,139,1,95,1,139,8,79,9,140,11,127,127,11,129,
+ 11,127,127,13,129,11,127,127,13,129,11,127,127,13,129,10,127,127,11,128,128,8,127,15,
+ 11,133,10,127,15,13,133,10,127,15,13,133,10,127,15,13,133,10,127,15,11,133,10,79,
+ 3,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
+ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
+ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
+ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
+ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
+ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,3,137,10,127,
+ 15,11,133,10,127,15,13,133,10,127,15,13,133,10,127,15,13,133,8,127,15,11,132,129,
+ 10,63,14,1,139,7,79,5,139,2,79,10,140,13,63,14,140,8,79,4,139,4,79,8,
+ 140,14,63,13,140,10,79,3,139,5,79,7,139,1,79,12,140,11,79,1,139,6,79,6,
+ 139,2,79,10,140,12,63,14,140,8,79,4,139,3,79,9,140,14,63,13,140,9,79,3,
+ 139,5,79,8,139,1,14,63,12,140,11,79,2,139,6,79,6,139,1,79,11,140,12,79,
+ 1,139,7,79,5,139,3,79,9,140,13,63,14,140,9,79,4,139,4,79,8,140,14,63,
+ 13,140,10,79,2,139,5,79,7,139,1,79,11,140,11,79,1,139,6,79,4,131,4,127,
+ 15,14,1,132,5,127,31,1,132,5,127,31,1,132,5,127,31,1,132,4,127,31,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
+ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,132,
+ 4,127,31,1,132,5,127,31,1,132,5,127,31,1,132,5,127,31,1,132,4,127,15,14,
+ 1,128,134,4,63,13,142,9,79,4,141,14,79,8,140,4,95,13,140,9,111,3,139,14,
+ 111,8,138,4,63,13,47,13,138,9,47,14,5,63,3,137,14,47,10,128,14,47,8,136,
+ 4,63,6,128,10,47,13,136,9,63,1,128,6,63,3,135,13,47,12,129,2,63,8,134,
+ 3,63,7,130,12,47,13,134,8,63,3,130,8,63,3,133,13,47,13,131,3,63,8,132,
+ 3,63,9,132,14,47,13,132,8,63,4,132,10,63,3,131,13,47,14,1,132,5,63,8,
+ 130,3,63,11,133,1,63,12,130,6,63,5,134,10,63,1,255,255,187,1,14,127,127,15,
+ 4,2,127,127,31,6,2,127,127,31,6,2,127,127,31,6,1,14,127,127,15,4,128,10,
+ 47,14,3,131,2,14,47,11,132,5,63,5,132,9,47,14,1,132,12,47,8,132,2,14,
+ 31,14,1,255,255,161,133,1,6,11,13,30,13,10,6,1,138,6,14,127,14,6,136,9,
+ 127,63,8,134,7,127,95,6,132,1,14,127,95,14,1,131,6,95,6,1,2,8,95,6,
+ 131,9,79,8,131,8,79,10,131,8,76,3,131,2,79,12,143,79,13,143,14,63,13,135,
+ 4,9,12,30,127,13,133,5,13,127,79,13,132,8,127,111,13,131,5,127,127,13,131,13,
+ 79,13,6,2,130,14,63,13,130,3,79,14,2,132,14,63,13,130,6,79,9,133,14,63,
+ 13,130,7,79,6,133,79,13,130,8,79,8,132,2,79,13,130,7,79,12,132,10,79,13,
+ 130,6,95,9,2,1,4,11,95,13,130,2,127,127,15,13,131,12,127,127,13,131,3,14,
+ 127,111,13,132,4,13,127,6,14,63,13,133,1,6,11,14,15,14,12,8,2,128,13,63,
+ 11,129,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,
+ 11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,2,8,12,30,13,
+ 8,2,134,11,79,7,14,111,6,133,11,127,111,5,132,11,127,111,14,1,131,11,127,127,
+ 6,131,11,95,8,2,1,6,14,79,10,131,11,79,9,131,5,79,13,131,11,79,3,132,
+ 14,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
+ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
+ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
+ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,3,132,14,63,14,131,11,79,9,131,
+ 5,79,13,131,11,95,7,2,1,6,14,79,10,131,11,127,127,6,131,11,127,111,14,1,
+ 131,11,127,111,5,132,11,79,11,127,6,133,9,63,14,1,3,10,13,15,14,13,9,2,
+ 132,133,3,8,12,14,15,14,13,10,6,1,136,1,10,127,15,14,6,134,1,13,127,63,
+ 8,133,12,127,95,6,131,5,127,111,14,1,130,11,79,14,5,1,2,9,95,5,130,14,
+ 79,4,131,9,79,8,129,1,79,13,132,4,79,10,129,1,79,11,132,2,79,8,129,1,
+ 79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,
+ 79,11,141,1,79,11,133,66,130,1,79,11,132,2,79,9,129,1,79,13,132,4,79,10,
+ 130,14,79,4,131,10,79,8,130,11,79,14,5,1,2,9,95,5,130,6,127,111,14,1,
+ 131,12,127,95,7,132,2,13,127,63,9,134,1,11,127,15,14,6,137,3,8,12,14,15,
+ 14,13,10,6,1,132,140,2,79,7,142,4,79,8,142,4,79,8,142,4,79,8,142,4,
+ 79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,134,3,9,13,30,12,
+ 7,1,4,79,8,133,8,111,13,7,79,8,132,7,127,111,8,131,2,127,127,8,131,8,
+ 127,127,8,131,12,79,13,4,1,2,10,95,8,131,95,3,131,11,79,8,130,1,79,12,
+ 132,6,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
+ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
+ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
+ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,12,132,5,79,8,131,95,3,131,
+ 11,79,8,131,12,79,13,4,1,2,9,95,8,131,8,127,127,8,131,2,127,127,8,132,
+ 7,127,111,8,133,8,127,11,79,8,134,3,9,13,14,15,13,9,3,2,79,7,129,133,
+ 3,8,12,14,15,14,13,10,6,1,136,1,10,127,15,14,5,134,1,13,127,63,7,133,
+ 12,127,95,5,131,5,127,111,13,131,11,79,14,5,1,2,9,95,3,130,14,79,4,131,
+ 11,79,7,129,1,79,13,132,5,79,8,129,1,79,11,132,3,79,9,129,1,79,11,132,
+ 2,79,9,129,1,79,11,132,3,79,9,129,1,127,127,15,9,129,1,127,127,15,9,129,
+ 1,127,127,15,9,129,1,127,127,15,7,129,1,79,11,141,1,79,11,141,1,79,11,141,
+ 1,79,13,132,3,14,63,5,130,14,79,4,131,10,79,5,130,11,79,14,5,1,2,9,
+ 95,1,130,6,127,111,11,132,12,127,95,3,132,2,14,127,63,7,134,1,11,127,15,14,
+ 6,137,3,8,12,14,15,14,13,10,6,1,132,134,4,9,12,46,1,133,3,12,95,2,
+ 132,2,14,111,1,132,10,127,1,131,1,127,14,132,4,95,7,2,133,6,79,9,135,7,
+ 79,5,135,7,79,5,133,12,127,47,3,129,14,127,47,4,129,14,127,47,4,129,12,127,
+ 47,3,131,7,79,5,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
+ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
+ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
+ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,5,79,3,132,132,4,10,13,15,
+ 14,12,7,1,2,79,7,133,10,111,13,6,79,8,132,9,127,111,8,131,3,127,127,8,
+ 131,9,127,127,8,131,12,79,14,5,1,2,10,95,8,131,95,4,131,12,79,8,130,1,
+ 79,13,132,6,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
+ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
+ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
+ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,13,132,6,79,8,131,95,
+ 4,131,12,79,8,131,12,79,14,5,1,2,10,95,8,131,8,127,127,8,131,2,127,127,
+ 8,132,8,127,15,14,79,8,133,9,111,12,5,79,8,134,4,10,13,15,14,11,6,128,
+ 5,79,7,142,6,79,7,142,10,79,5,141,1,14,79,2,140,1,11,79,14,138,1,3,
+ 7,14,95,8,136,13,127,47,2,136,14,127,31,7,137,14,127,15,9,138,14,111,13,6,
+ 139,11,31,14,13,11,8,4,135,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,
+ 79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,
+ 79,1,128,7,12,14,15,13,10,3,134,11,79,3,13,111,7,133,11,79,14,127,15,5,
+ 132,11,127,111,14,132,11,127,127,5,131,11,95,8,17,6,14,79,8,131,11,79,10,131,
+ 7,79,11,131,11,79,4,131,2,79,12,131,11,79,2,132,79,13,131,11,79,1,132,14,
+ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
+ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
+ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
+ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
+ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
+ 63,13,131,9,63,14,1,132,13,63,11,129,130,7,13,14,12,4,132,8,79,3,130,1,
+ 95,10,130,2,95,12,130,1,95,10,131,8,79,3,132,7,13,14,12,4,165,6,79,3,
+ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
+ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
+ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
+ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
+ 131,6,79,3,129,132,1,8,13,14,11,3,135,10,63,14,2,133,2,95,8,133,5,95,
+ 10,133,2,95,8,134,10,63,14,2,134,1,8,13,14,11,3,191,9,63,14,1,134,11,
+ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
+ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
+ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
+ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
+ 79,1,134,11,79,1,134,12,79,1,133,1,14,79,134,7,79,14,132,2,7,95,11,130,
+ 4,127,15,8,130,5,127,15,2,130,5,127,7,131,5,95,14,5,132,4,15,30,12,9,
+ 5,134,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,
+ 11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,131,3,14,63,11,
+ 131,11,79,1,131,12,79,3,131,11,79,1,130,7,79,9,132,11,79,1,129,2,14,63,
+ 13,1,132,11,79,1,129,10,79,4,133,11,79,1,128,5,79,9,134,11,79,17,13,63,
+ 14,1,134,11,79,1,8,79,5,135,11,79,4,79,10,136,11,79,14,79,9,136,11,127,
+ 47,14,136,11,127,63,5,135,11,127,63,11,135,11,127,79,1,134,11,111,4,79,7,134,
+ 11,95,8,128,10,63,12,134,11,79,13,1,128,6,79,3,133,11,79,4,129,1,79,8,
+ 133,11,79,1,130,11,63,14,133,11,79,1,130,6,79,5,132,11,79,1,130,1,79,10,
+ 132,11,79,1,131,11,79,1,131,11,79,1,131,6,79,6,131,11,79,1,131,2,79,12,
+ 131,11,79,1,132,12,79,2,130,9,63,14,1,132,6,79,6,128,129,11,63,12,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
+ 63,14,131,14,63,14,131,14,63,14,131,12,63,12,129,129,9,63,14,128,2,8,12,30,
+ 12,8,2,131,5,10,13,15,14,11,5,134,11,79,8,111,14,4,128,1,11,111,10,133,
+ 11,127,95,14,3,11,127,15,9,132,11,127,127,127,47,3,131,11,127,127,127,47,8,131,
+ 11,95,7,17,8,111,13,3,128,3,12,79,12,131,11,79,10,131,11,95,3,130,2,95,
+ 131,11,79,4,131,5,79,12,132,12,79,1,130,11,79,1,131,3,79,10,132,10,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
+ 130,9,63,14,132,1,14,63,7,132,7,63,14,1,128,129,9,63,14,17,8,12,14,15,
+ 13,10,3,134,11,79,6,14,111,7,133,11,127,111,5,132,11,127,111,14,132,11,127,127,
+ 5,131,11,95,8,17,6,14,79,8,131,11,79,10,131,7,79,11,131,11,79,4,131,2,
+ 79,12,131,11,79,2,132,79,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
+ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
+ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
+ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
+ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
+ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,9,63,14,1,132,13,
+ 63,11,129,133,3,8,12,14,15,14,13,10,6,1,137,1,10,127,15,14,6,135,1,13,
+ 127,63,9,134,12,127,95,6,132,5,127,111,14,1,131,11,79,14,5,1,2,8,95,5,
+ 131,14,79,4,131,9,79,9,130,1,79,13,132,3,79,11,130,1,79,11,132,1,79,11,
+ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
+ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
+ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
+ 130,1,79,13,132,3,79,11,131,14,79,4,131,9,79,9,131,11,79,14,5,1,2,8,
+ 95,6,131,6,127,111,14,1,132,12,127,95,7,133,2,13,127,63,10,135,1,11,127,15,
+ 14,7,138,3,8,12,14,15,14,13,11,7,1,133,129,6,79,3,2,9,13,30,13,9,
+ 3,134,8,79,11,127,8,133,8,127,111,8,132,8,127,127,3,131,8,127,127,9,131,8,
+ 95,10,2,1,4,13,79,13,131,8,79,12,131,3,95,1,130,8,79,7,132,11,79,2,
+ 130,8,79,5,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
+ 130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
+ 130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
+ 130,8,79,5,132,9,79,2,130,8,79,7,132,11,79,2,130,8,79,12,131,2,95,1,
+ 130,8,95,10,2,1,4,13,79,13,131,8,127,127,9,131,8,127,127,3,131,8,127,111,
+ 8,132,8,79,8,13,111,9,133,8,79,4,1,7,12,14,15,13,10,3,134,8,79,4,
+ 142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,
+ 142,8,79,4,142,6,79,3,140,132,3,9,13,30,13,9,18,79,7,133,8,127,11,79,
+ 8,132,7,127,111,8,131,2,127,127,8,131,8,127,127,8,131,12,79,14,5,1,2,10,
+ 95,8,131,95,3,131,11,79,8,130,1,79,12,132,6,79,8,130,1,79,10,132,4,79,
+ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
+ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
+ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
+ 8,130,1,79,12,132,5,79,8,131,95,3,131,11,79,8,131,12,79,13,4,1,2,9,
+ 95,8,131,8,127,127,8,131,2,127,127,8,132,7,127,111,8,133,8,111,13,7,79,8,
+ 134,3,9,13,30,12,7,1,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,
+ 4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,3,79,7,129,
+ 129,9,63,14,1,128,6,12,30,10,130,11,79,1,9,79,2,129,11,79,6,79,14,130,
+ 11,79,14,79,11,130,11,127,47,9,130,11,127,47,6,130,11,95,14,6,2,1,3,1,
+ 130,11,95,3,135,11,79,10,136,11,79,4,136,11,79,2,136,11,79,1,136,11,79,1,
+ 136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,
+ 136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,
+ 136,9,63,14,1,134,132,1,7,11,13,30,13,11,6,1,136,6,14,127,14,5,134,7,
+ 127,63,6,132,3,127,95,3,131,11,127,95,11,130,1,95,8,2,1,5,14,79,1,129,
+ 3,79,10,131,5,79,5,129,3,79,5,132,79,6,129,3,79,7,132,7,57,3,129,1,
+ 79,14,4,140,11,95,9,2,138,4,127,11,5,137,8,127,15,13,6,136,6,14,127,15,
+ 12,2,135,2,10,127,15,14,2,136,2,8,14,111,13,138,1,6,13,95,6,139,1,12,
+ 79,10,129,3,57,8,132,3,79,12,129,7,79,1,131,1,79,12,129,6,79,6,131,4,
+ 79,10,129,2,79,14,7,2,1,5,13,79,6,130,10,127,95,13,131,1,12,127,63,14,
+ 3,132,1,9,127,31,11,2,135,2,7,11,30,15,14,12,9,3,132,130,7,63,14,135,
+ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,9,79,1,131,1,14,127,31,
+ 13,128,2,127,63,128,2,127,63,128,1,14,127,31,14,131,8,79,1,134,8,79,1,134,
+ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,
+ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,
+ 8,79,1,134,8,79,4,134,8,79,13,3,133,6,127,7,131,3,127,9,132,12,111,9,
+ 132,2,13,95,9,133,1,6,11,13,14,31,7,128,129,12,63,12,132,1,14,63,8,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
+ 14,63,14,132,2,79,10,131,14,63,14,132,3,79,10,131,14,79,1,131,5,79,10,131,
+ 13,79,6,131,11,79,10,131,11,79,14,5,17,9,95,10,131,8,127,127,10,131,2,127,
+ 127,10,132,8,127,111,10,133,9,111,14,5,79,10,134,3,10,13,15,14,13,8,17,14,
+ 63,8,129,128,14,79,3,132,6,79,11,129,14,79,6,132,10,79,9,129,10,79,9,132,
+ 13,79,5,129,6,79,12,131,1,95,2,129,3,95,131,3,79,13,131,14,79,3,130,6,
+ 79,9,131,10,79,6,130,9,79,6,131,7,79,8,130,12,79,2,131,3,79,11,130,14,
+ 63,13,133,14,63,14,129,2,79,10,133,10,79,2,128,5,79,6,133,7,79,5,128,8,
+ 79,2,133,3,79,7,128,11,63,14,135,14,63,10,128,14,63,10,135,10,63,13,1,79,
+ 6,135,7,79,5,79,3,135,3,79,12,63,14,137,14,127,15,10,137,10,127,15,7,137,
+ 7,127,15,3,137,3,127,14,139,14,111,11,139,11,111,7,139,7,111,3,139,3,95,14,
+ 141,13,79,10,134,128,14,63,7,132,11,63,5,132,11,63,9,129,14,63,11,132,14,63,
+ 9,132,79,7,129,11,63,13,131,2,79,11,131,3,79,4,129,8,79,1,130,5,79,14,
+ 131,5,79,1,129,4,79,3,130,7,95,1,130,8,63,12,130,1,79,5,130,10,95,4,
+ 130,10,63,9,131,13,63,8,130,12,95,7,130,13,63,6,131,9,63,10,130,111,9,130,
+ 79,3,131,6,63,13,129,3,111,12,129,2,63,14,132,3,79,129,5,111,14,129,5,63,
+ 11,133,14,63,3,128,8,47,14,63,2,128,7,63,8,133,11,63,5,128,10,47,7,63,
+ 5,128,10,63,5,133,8,63,8,128,13,47,4,13,47,7,128,13,63,1,133,5,63,10,
+ 1,63,1,10,47,10,128,63,13,134,1,63,12,3,47,13,128,7,47,13,2,63,10,135,
+ 13,63,6,47,11,128,5,63,5,63,7,135,10,63,12,47,8,128,2,63,12,63,3,135,
+ 7,127,5,129,14,127,136,3,127,3,129,12,111,12,137,127,130,9,111,9,137,12,95,12,
+ 130,6,111,5,137,9,95,10,130,3,111,2,137,5,95,7,130,1,95,14,138,2,95,4,
+ 131,13,79,11,139,14,79,2,131,10,79,7,139,9,63,13,132,6,79,3,133,128,14,63,
+ 14,2,132,4,79,12,129,9,79,9,132,12,79,7,129,2,95,2,130,4,79,14,1,130,
+ 10,79,8,130,11,79,8,131,3,79,14,1,128,3,79,14,1,132,11,79,7,128,10,79,
+ 8,133,3,79,13,2,95,2,134,11,79,13,79,9,135,4,127,47,2,136,12,127,15,10,
+ 137,5,127,15,2,138,12,111,10,139,5,111,3,139,6,111,3,139,13,111,10,138,5,127,
+ 15,3,137,12,127,15,10,136,4,127,47,2,135,12,79,12,79,9,134,4,79,13,1,14,
+ 79,2,133,11,79,6,128,9,79,8,132,3,79,14,1,128,2,79,14,1,131,10,79,8,
+ 130,10,79,8,130,2,95,1,130,3,79,14,1,129,9,79,9,132,12,79,7,129,14,63,
+ 14,2,132,4,79,12,128,2,79,12,133,11,79,4,1,95,1,132,14,79,2,128,12,79,
+ 4,131,2,79,13,129,8,79,7,131,5,79,9,129,4,79,9,131,7,79,6,129,1,79,
+ 12,131,10,79,2,130,12,79,131,13,63,13,131,8,79,2,130,79,9,131,4,79,5,129,
+ 3,79,6,131,1,79,8,129,6,79,2,132,12,63,11,129,8,63,13,133,8,63,13,129,
+ 11,63,9,133,4,79,1,128,13,63,6,133,1,79,4,1,79,2,134,11,63,6,4,63,
+ 13,135,8,63,9,6,63,9,135,4,63,12,9,63,6,136,79,13,63,2,136,11,127,13,
+ 137,7,127,9,137,4,127,5,138,14,111,2,138,11,95,13,139,7,95,9,139,3,95,5,
+ 140,14,79,2,140,14,63,13,140,2,79,9,140,6,79,5,139,1,13,63,14,1,137,1,
+ 5,12,79,10,136,3,127,15,4,136,4,127,11,137,4,111,14,2,137,4,95,12,2,138,
+ 4,31,14,12,9,4,139,128,7,127,95,14,129,9,127,111,1,128,9,127,111,1,128,9,
+ 127,111,1,128,7,127,111,137,2,95,12,137,10,95,3,136,3,95,10,137,12,79,14,2,
+ 136,5,95,7,137,13,79,13,137,7,95,5,136,1,14,79,11,137,9,95,3,136,2,95,
+ 9,137,11,79,14,1,136,4,95,6,137,12,79,12,137,6,95,4,136,1,14,79,10,137,
+ 7,95,2,137,12,127,111,3,128,12,127,111,4,128,12,127,111,4,128,12,127,111,4,128,
+ 11,127,111,3,134,6,11,14,63,7,133,1,11,111,8,133,8,127,8,133,14,127,8,132,
+ 3,127,15,7,132,5,95,9,1,134,5,79,12,136,5,79,8,136,5,79,7,136,5,79,
+ 7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,
+ 7,136,6,79,7,136,7,79,6,136,11,79,5,135,5,95,2,133,3,11,95,12,134,10,
+ 111,4,134,10,79,14,4,135,10,95,6,135,9,111,4,134,1,6,13,79,13,136,2,14,
+ 79,2,136,10,79,5,136,7,79,6,136,5,79,7,136,5,79,7,136,5,79,7,136,5,
+ 79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,
+ 79,8,136,5,79,12,136,5,95,8,1,134,3,127,15,7,133,14,127,8,133,9,127,8,
+ 133,1,12,111,8,135,6,12,14,63,7,128,128,7,63,14,1,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
+ 2,129,10,79,2,129,10,79,2,129,8,63,14,1,128,128,8,63,14,11,6,135,10,111,
+ 11,134,10,127,7,133,10,127,14,133,8,127,15,2,134,2,10,95,4,136,13,79,4,136,
+ 9,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,
+ 8,79,4,136,8,79,4,136,8,79,4,136,7,79,5,136,7,79,6,136,6,79,11,136,
+ 3,95,4,136,13,95,10,3,134,5,111,8,135,5,14,79,8,135,6,95,8,134,5,111,
+ 8,134,13,79,13,5,134,3,79,14,2,135,6,79,9,136,7,79,6,136,8,79,5,136,
+ 8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,
+ 8,79,4,136,8,79,4,136,9,79,4,136,13,79,4,134,2,9,95,4,132,8,127,15,
+ 3,132,10,127,14,133,10,127,7,133,10,111,11,134,8,63,14,11,6,134,131,1,7,12,
+ 30,11,5,143,3,13,95,12,4,132,8,14,6,132,3,14,127,15,10,4,17,8,47,11,
+ 2,130,12,127,127,47,5,129,5,127,127,47,10,130,4,14,47,9,2,128,3,10,127,15,
+ 13,1,131,1,10,15,6,132,4,12,95,12,1,134,1,135,5,11,14,15,13,7,1,255,
+ 255,139,130,7,13,14,12,4,132,8,79,4,131,14,79,11,130,2,95,13,131,14,79,11,
+ 131,8,79,4,132,7,13,14,12,4,251,132,3,9,13,15,14,13,9,2,136,9,127,8,
+ 134,11,127,31,11,132,8,127,63,8,130,3,63,12,4,17,5,13,63,2,129,10,47,11,
+ 132,1,12,47,9,129,14,47,2,133,3,47,13,128,1,47,12,135,13,47,128,2,47,10,
+ 135,12,47,17,47,12,135,13,47,129,14,47,2,133,3,47,13,129,10,47,11,132,1,12,
+ 47,9,129,3,63,12,4,17,5,13,63,2,130,8,127,63,7,132,11,127,31,11,134,9,
+ 127,8,136,3,9,13,31,13,9,3,255,255,255,180,130,2,9,1,135,6,5,132,2,13,
+ 15,12,1,133,7,31,5,130,1,13,47,12,1,131,7,63,5,129,4,79,12,1,129,7,
+ 79,10,130,6,79,12,1,7,79,11,1,131,6,79,13,79,11,1,133,6,127,15,11,1,
+ 135,6,111,11,1,137,10,95,2,137,7,111,12,1,135,7,127,15,12,1,133,7,79,13,
+ 79,12,1,131,7,79,11,1,6,79,12,1,129,5,79,11,1,129,6,79,11,129,1,13,
+ 47,11,1,131,6,63,5,130,2,13,15,11,1,133,6,31,5,132,2,8,1,135,5,4,
+ 255,135,128,8,127,111,7,129,10,127,111,8,129,10,127,111,8,129,10,127,111,8,129,8,
+ 127,111,7,255,228,128,8,127,127,127,31,3,129,10,127,127,127,31,4,129,10,127,127,127,
+ 31,4,129,10,127,127,127,31,4,129,8,127,127,127,31,3,255,255,232,129,10,63,14,130,
+ 14,63,11,129,2,79,6,129,6,79,1,129,9,63,11,130,12,63,6,129,1,79,1,129,
+ 4,63,11,130,7,63,6,130,10,63,1,130,12,47,10,255,219,130,7,13,14,12,4,133,
+ 2,10,30,10,2,133,4,12,14,13,7,132,9,79,3,131,1,13,63,13,132,3,79,9,
+ 130,1,95,9,131,5,95,5,131,10,95,1,129,3,95,12,131,8,95,7,131,12,95,3,
+ 129,1,95,9,131,5,95,5,131,10,95,1,130,9,79,3,131,1,13,63,12,132,3,79,
+ 8,132,7,13,14,11,3,133,2,10,30,10,1,133,4,12,14,13,7,130,131,3,10,13,
+ 15,14,10,4,134,8,111,10,132,7,127,15,9,130,2,127,47,3,129,7,127,47,9,129,
+ 9,127,47,11,129,9,127,47,11,129,6,127,47,8,129,1,14,127,31,2,130,6,127,15,
+ 8,132,7,111,8,134,3,9,13,15,13,10,4,236,133,6,63,11,135,1,14,63,5,135,
+ 9,63,11,135,2,79,3,135,10,63,9,135,4,63,14,1,135,12,63,7,135,5,63,13,
+ 136,11,63,6,136,6,63,12,137,12,63,6,136,4,63,14,1,136,11,63,8,136,2,79,
+ 2,136,9,63,11,136,1,14,63,5,136,6,63,12,205,130,13,63,4,137,7,63,13,138,
+ 13,63,6,137,4,63,14,1,137,11,63,8,137,2,79,2,137,8,63,10,137,1,14,63,
+ 3,137,8,63,9,136,1,13,63,4,136,8,63,11,136,2,79,2,136,10,63,9,136,4,
+ 63,14,1,136,12,63,7,136,7,63,13,137,13,63,4,214,
+};
+static const struct fos_glyph xl_glyphs[] = {
+ { 0, 10, 0, 0, 0, 160 }, /* 0x20 */
+ { 0, 13, 35, 0, -35, 215 }, /* 0x21 */
+ { 124, 15, 35, 0, -35, 245 }, /* 0x22 */
+ { 211, 30, 34, 0, -34, 485 }, /* 0x23 */
+ { 456, 22, 43, 0, -39, 347 }, /* 0x24 */
+ { 721, 39, 35, 0, -35, 618 }, /* 0x25 */
+ { 1103, 29, 35, 0, -35, 465 }, /* 0x26 */
+ { 1393, 8, 35, 0, -35, 122 }, /* 0x27 */
+ { 1439, 14, 43, 0, -38, 223 }, /* 0x28 */
+ { 1612, 14, 43, 0, -38, 223 }, /* 0x29 */
+ { 1781, 18, 38, 0, -38, 289 }, /* 0x2a */
+ { 1918, 22, 26, 0, -26, 351 }, /* 0x2b */
+ { 2006, 10, 12, 0, -7, 159 }, /* 0x2c */
+ { 2055, 16, 18, 0, -18, 260 }, /* 0x2d */
+ { 2082, 11, 7, 0, -7, 169 }, /* 0x2e */
+ { 2115, 19, 35, 0, -35, 309 }, /* 0x2f */
+ { 2256, 23, 35, 0, -35, 360 }, /* 0x30 */
+ { 2525, 14, 35, 0, -35, 219 }, /* 0x31 */
+ { 2679, 21, 35, 0, -35, 340 }, /* 0x32 */
+ { 2883, 21, 35, 0, -35, 341 }, /* 0x33 */
+ { 3095, 23, 35, 0, -35, 367 }, /* 0x34 */
+ { 3259, 21, 35, 0, -35, 342 }, /* 0x35 */
+ { 3469, 21, 35, 0, -35, 343 }, /* 0x36 */
+ { 3700, 20, 35, 0, -35, 314 }, /* 0x37 */
+ { 3860, 22, 35, 0, -35, 347 }, /* 0x38 */
+ { 4115, 21, 35, 0, -35, 338 }, /* 0x39 */
+ { 4373, 13, 24, 0, -24, 202 }, /* 0x3a */
+ { 4439, 11, 29, 0, -25, 174 }, /* 0x3b */
+ { 4524, 22, 26, 0, -26, 351 }, /* 0x3c */
+ { 4665, 22, 22, 0, -22, 351 }, /* 0x3d */
+ { 4715, 22, 26, 0, -26, 351 }, /* 0x3e */
+ { 4856, 21, 35, 0, -35, 330 }, /* 0x3f */
+ { 5032, 38, 36, 0, -32, 607 }, /* 0x40 */
+ { 5477, 23, 35, 0, -35, 365 }, /* 0x41 */
+ { 5708, 23, 35, 0, -35, 370 }, /* 0x42 */
+ { 5970, 23, 35, 0, -35, 366 }, /* 0x43 */
+ { 6188, 24, 35, 0, -35, 378 }, /* 0x44 */
+ { 6454, 22, 35, 0, -35, 348 }, /* 0x45 */
+ { 6620, 21, 35, 0, -35, 332 }, /* 0x46 */
+ { 6776, 23, 35, 0, -35, 370 }, /* 0x47 */
+ { 7022, 24, 35, 0, -35, 382 }, /* 0x48 */
+ { 7295, 11, 35, 0, -35, 179 }, /* 0x49 */
+ { 7436, 22, 35, 0, -35, 354 }, /* 0x4a */
+ { 7628, 24, 35, 0, -35, 382 }, /* 0x4b */
+ { 7895, 21, 35, 0, -35, 332 }, /* 0x4c */
+ { 8045, 27, 35, 0, -35, 430 }, /* 0x4d */
+ { 8356, 25, 35, 0, -35, 406 }, /* 0x4e */
+ { 8671, 23, 35, 0, -35, 374 }, /* 0x4f */
+ { 8946, 23, 35, 0, -35, 366 }, /* 0x50 */
+ { 9152, 23, 41, 0, -35, 364 }, /* 0x51 */
+ { 9450, 23, 35, 0, -35, 369 }, /* 0x52 */
+ { 9715, 22, 35, 0, -35, 347 }, /* 0x53 */
+ { 9951, 23, 35, 0, -35, 362 }, /* 0x54 */
+ { 10102, 24, 35, 0, -35, 382 }, /* 0x55 */
+ { 10376, 24, 35, 0, -35, 377 }, /* 0x56 */
+ { 10610, 33, 35, 0, -35, 532 }, /* 0x57 */
+ { 10998, 23, 35, 0, -35, 368 }, /* 0x58 */
+ { 11235, 23, 35, 0, -35, 365 }, /* 0x59 */
+ { 11432, 20, 35, 0, -35, 325 }, /* 0x5a */
+ { 11588, 17, 46, 0, -39, 264 }, /* 0x5b */
+ { 11783, 19, 35, 0, -35, 309 }, /* 0x5c */
+ { 11925, 17, 46, 0, -39, 264 }, /* 0x5d */
+ { 12122, 21, 35, 0, -35, 330 }, /* 0x5e */
+ { 12259, 20, 5, 0, -5, 324 }, /* 0x5f */
+ { 12286, 10, 35, 0, -35, 165 }, /* 0x60 */
+ { 12318, 22, 26, 0, -26, 347 }, /* 0x61 */
+ { 12506, 22, 35, 0, -35, 350 }, /* 0x62 */
+ { 12745, 21, 26, 0, -26, 338 }, /* 0x63 */
+ { 12918, 22, 35, 0, -35, 350 }, /* 0x64 */
+ { 13151, 21, 26, 0, -26, 341 }, /* 0x65 */
+ { 13333, 15, 35, 0, -35, 233 }, /* 0x66 */
+ { 13483, 22, 36, 0, -26, 345 }, /* 0x67 */
+ { 13737, 22, 35, 0, -35, 351 }, /* 0x68 */
+ { 13980, 11, 36, 0, -36, 172 }, /* 0x69 */
+ { 14117, 14, 47, -3, -37, 169 }, /* 0x6a */
+ { 14306, 22, 35, 0, -35, 346 }, /* 0x6b */
+ { 14538, 10, 35, 0, -35, 159 }, /* 0x6c */
+ { 14679, 33, 26, 0, -26, 532 }, /* 0x6d */
+ { 14991, 22, 26, 0, -26, 351 }, /* 0x6e */
+ { 15195, 22, 26, 0, -26, 346 }, /* 0x6f */
+ { 15398, 22, 35, 0, -26, 353 }, /* 0x70 */
+ { 15633, 22, 35, 0, -26, 353 }, /* 0x71 */
+ { 15864, 16, 26, 0, -26, 250 }, /* 0x72 */
+ { 15990, 20, 26, 0, -26, 318 }, /* 0x73 */
+ { 16171, 14, 32, 0, -32, 226 }, /* 0x74 */
+ { 16310, 22, 26, 0, -26, 350 }, /* 0x75 */
+ { 16515, 21, 26, 0, -26, 332 }, /* 0x76 */
+ { 16685, 30, 26, 0, -26, 474 }, /* 0x77 */
+ { 16965, 21, 26, 0, -26, 334 }, /* 0x78 */
+ { 17143, 20, 36, 0, -26, 322 }, /* 0x79 */
+ { 17359, 18, 26, 0, -26, 294 }, /* 0x7a */
+ { 17476, 16, 46, 0, -39, 255 }, /* 0x7b */
+ { 17676, 9, 42, 0, -38, 137 }, /* 0x7c */
+ { 17847, 16, 46, 0, -39, 255 }, /* 0x7d */
+ { 18044, 24, 19, 0, -19, 384 }, /* 0x7e */
+ { 18122, 11, 18, 0, -18, 172 }, /* 0x80 */
+ { 18155, 18, 41, 0, -41, 287 }, /* 0x81 */
+ { 18278, 19, 24, 0, -24, 311 }, /* 0x82 */
+ { 18410, 19, 17, 0, -17, 302 }, /* 0x83 */
+ { 18437, 30, 17, 0, -17, 474 }, /* 0x84 */
+ { 18475, 9, 35, 0, -35, 132 }, /* 0x85 */
+ { 18521, 34, 7, 0, -7, 543 }, /* 0x86 */
+ { 18620, 15, 19, 0, -19, 242 }, /* 0x87 */
+ { 18686, 15, 22, 0, -22, 238 }, /* 0x88 */
+ { 18759, 16, 22, 0, -22, 249 }, /* 0x89 */
+};
+static const uint8_t xl_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
+ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
+ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
+ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern xl_kern[] = {
+ {39,45,-19},{39,65,-34},{39,74,-41},{39,97,-12},{39,99,-19},{39,100,-19},{39,101,-19},{39,111,-19},
+ {39,115,-16},{44,48,-32},{44,55,-25},{44,75,-7},{44,76,-7},{44,84,-41},{44,86,-26},{44,87,-26},
+ {44,88,8},{44,89,-54},{44,118,-14},{44,119,-14},{44,121,-14},{45,39,-5},{45,45,-46},{45,118,-12},
+ {45,119,-12},{45,120,-13},{45,121,-12},{46,48,-32},{46,55,-25},{46,75,-7},{46,76,-7},{46,84,-41},
+ {46,86,-26},{46,87,-26},{46,88,8},{46,89,-54},{46,118,-14},{46,119,-14},{46,121,-14},{49,49,-10},
+ {50,49,-17},{51,49,-20},{52,49,-41},{52,55,-42},{53,49,-10},{54,49,-14},{55,44,-39},{55,46,-39},
+ {56,49,-18},{57,49,-18},{65,39,-34},{65,65,18},{65,67,-13},{65,71,-13},{65,79,-13},{65,81,-13},
+ {65,83,-18},{65,84,-47},{65,86,-55},{65,87,-55},{65,89,-38},{65,102,-4},{65,116,-4},{65,117,-9},
+ {65,118,-26},{65,119,-26},{65,120,10},{65,121,-26},{65,133,-40},{66,44,-7},{66,46,-7},{66,65,-16},
+ {66,86,-17},{66,87,-17},{66,88,-18},{66,89,-22},{66,115,-7},{66,118,-5},{66,119,-5},{66,121,-5},
+ {67,45,-6},{67,65,-6},{67,88,-9},{67,89,-8},{67,99,-6},{67,100,-6},{67,101,-6},{67,111,-6},
+ {67,118,-5},{67,119,-5},{67,121,-5},{68,44,-7},{68,46,-7},{68,65,-16},{68,86,-17},{68,87,-17},
+ {68,88,-18},{68,89,-22},{68,115,-7},{68,118,-5},{68,119,-5},{68,121,-5},{69,65,15},{69,74,10},
+ {70,45,-25},{70,65,-29},{70,74,-7},{70,97,-18},{70,99,-25},{70,100,-25},{70,101,-25},{70,102,-5},
+ {70,103,-25},{70,109,-25},{70,110,-25},{70,111,-25},{70,112,-25},{70,113,-25},{70,114,-25},{70,115,-21},
+ {70,116,-5},{70,117,-13},{70,118,-14},{70,119,-14},{70,120,-14},{70,121,-14},{70,122,-14},{71,45,-6},
+ {71,65,-6},{71,88,-9},{71,89,-8},{71,99,-6},{71,100,-6},{71,101,-6},{71,111,-6},{71,118,-5},
+ {71,119,-5},{71,121,-5},{74,44,-7},{74,46,-7},{74,65,-9},{74,66,-7},{74,68,-7},{74,69,-7},
+ {74,70,-7},{74,78,-7},{74,80,-7},{75,44,7},{75,46,7},{75,65,10},{75,67,-13},{75,71,-13},
+ {75,79,-13},{75,81,-13},{75,83,-14},{76,44,7},{76,46,7},{76,65,21},{76,84,-60},{76,89,-25},
+ {76,102,-10},{76,116,-10},{79,45,-6},{79,65,-6},{79,88,-9},{79,89,-8},{79,99,-6},{79,100,-6},
+ {79,101,-6},{79,111,-6},{79,118,-5},{79,119,-5},{79,121,-5},{80,44,-21},{80,46,-21},{80,65,-25},
+ {80,74,-36},{80,86,-9},{80,87,-9},{80,88,-14},{80,89,-14},{81,45,-6},{81,65,-6},{81,88,-8},
+ {81,89,-9},{81,99,-6},{81,100,-6},{81,101,-6},{81,111,-6},{81,118,-5},{81,119,-5},{81,121,-5},
+ {82,65,6},{82,89,-18},{83,84,-7},{83,86,-10},{83,87,-10},{83,88,-21},{83,89,-18},{83,118,-5},
+ {83,119,-5},{83,121,-5},{84,44,-35},{84,45,-50},{84,46,-35},{84,65,-38},{84,67,-19},{84,71,-19},
+ {84,79,-19},{84,81,-19},{84,97,-32},{84,99,-50},{84,100,-50},{84,101,-50},{84,102,-9},{84,103,-46},
+ {84,109,-22},{84,110,-22},{84,111,-50},{84,112,-22},{84,113,-46},{84,114,-22},{84,115,-40},{84,116,-9},
+ {84,117,-13},{84,118,-24},{84,119,-24},{84,120,-10},{84,121,-24},{84,122,-18},{85,44,-7},{85,46,-7},
+ {85,65,-9},{85,66,-7},{85,68,-7},{85,69,-7},{85,70,-7},{85,78,-7},{85,80,-7},{86,44,-25},
+ {86,45,-36},{86,46,-25},{86,65,-53},{86,67,-11},{86,71,-11},{86,74,-22},{86,79,-11},{86,81,-11},
+ {86,83,-10},{86,97,-19},{86,99,-36},{86,100,-36},{86,101,-36},{86,102,-10},{86,103,-26},{86,109,-14},
+ {86,110,-14},{86,111,-36},{86,112,-14},{86,113,-26},{86,114,-14},{86,115,-30},{86,116,-10},{86,117,-5},
+ {86,118,-8},{86,119,-8},{86,120,-14},{86,121,-8},{86,122,-9},{87,44,-25},{87,45,-36},{87,46,-25},
+ {87,65,-53},{87,67,-11},{87,71,-11},{87,74,-22},{87,79,-11},{87,81,-11},{87,83,-10},{87,97,-19},
+ {87,99,-36},{87,100,-36},{87,101,-36},{87,102,-10},{87,103,-26},{87,109,-14},{87,110,-14},{87,111,-36},
+ {87,112,-14},{87,113,-26},{87,114,-14},{87,115,-30},{87,116,-10},{87,117,-5},{87,118,-8},{87,119,-8},
+ {87,120,-14},{87,121,-8},{87,122,-9},{88,45,-9},{88,67,-10},{88,71,-10},{88,74,-5},{88,79,-10},
+ {88,81,-10},{88,83,-21},{88,99,-9},{88,100,-9},{88,101,-9},{88,102,-9},{88,103,-9},{88,111,-9},
+ {88,113,-9},{88,115,-9},{88,116,-9},{88,117,-9},{88,118,-30},{88,119,-30},{88,121,-30},{89,44,-54},
+ {89,45,-42},{89,46,-54},{89,65,-50},{89,66,-10},{89,67,-14},{89,68,-10},{89,69,-10},{89,70,-10},
+ {89,71,-14},{89,74,-36},{89,78,-10},{89,79,-14},{89,80,-10},{89,81,-14},{89,82,-4},{89,83,-18},
+ {89,99,-42},{89,100,-42},{89,101,-42},{89,102,-18},{89,103,-41},{89,109,-25},{89,110,-25},{89,111,-42},
+ {89,112,-25},{89,113,-41},{89,114,-25},{89,116,-18},{89,117,-22},{89,118,-27},{89,119,-27},{89,120,-14},
+ {89,121,-27},{89,122,-14},{97,39,-10},{97,118,-9},{97,119,-9},{97,121,-9},{97,133,-10},{98,39,-4},
+ {98,44,-7},{98,46,-7},{98,118,-5},{98,119,-5},{98,120,-9},{98,121,-5},{99,102,-4},{99,116,-4},
+ {99,118,-13},{99,119,-13},{99,120,-9},{99,121,-13},{101,39,-8},{101,97,-4},{101,118,-9},{101,119,-9},
+ {101,121,-9},{101,133,-9},{102,103,-7},{102,113,-7},{102,133,16},{103,118,-7},{103,119,-7},{103,121,-7},
+ {104,39,-4},{104,44,-7},{104,46,-7},{104,118,-5},{104,119,-5},{104,120,-9},{104,121,-5},{105,106,-5},
+ {107,45,-14},{107,99,-14},{107,100,-14},{107,101,-14},{107,102,-9},{107,103,-14},{107,111,-14},{107,113,-14},
+ {107,115,-14},{107,116,-9},{109,39,-4},{109,44,-7},{109,46,-7},{109,118,-5},{109,119,-5},{109,120,-9},
+ {109,121,-5},{110,39,-4},{110,44,-7},{110,46,-7},{110,118,-5},{110,119,-5},{110,120,-9},{110,121,-5},
+ {111,39,-5},{111,118,-12},{111,119,-12},{111,120,-13},{111,121,-12},{112,39,-4},{112,44,-7},{112,46,-7},
+ {112,118,-5},{112,119,-5},{112,120,-9},{112,121,-5},{113,118,-7},{113,119,-7},{113,121,-7},{114,45,-5},
+ {114,99,-5},{114,100,-5},{114,101,-5},{114,103,-8},{114,111,-5},{114,113,-8},{114,118,6},{114,119,6},
+ {114,121,6},{114,133,18},{115,39,-10},{115,115,-12},{115,118,-14},{115,119,-14},{115,120,-9},{115,121,-14},
+ {115,133,-10},{117,133,-7},{118,44,-14},{118,45,-10},{118,46,-14},{118,97,-9},{118,99,-10},{118,100,-10},
+ {118,101,-10},{118,103,-16},{118,111,-10},{118,113,-16},{118,115,-10},{118,118,7},{118,119,7},{118,121,7},
+ {118,133,17},{119,44,-14},{119,45,-10},{119,46,-14},{119,97,-9},{119,99,-10},{119,100,-10},{119,101,-10},
+ {119,103,-16},{119,111,-10},{119,113,-16},{119,115,-10},{119,118,7},{119,119,7},{119,121,7},{119,133,17},
+ {120,45,-13},{120,99,-13},{120,100,-13},{120,101,-13},{120,111,-13},{121,44,-14},{121,45,-10},{121,46,-14},
+ {121,97,-9},{121,99,-10},{121,100,-10},{121,101,-10},{121,103,-16},{121,111,-10},{121,113,-16},{121,115,-10},
+ {121,118,7},{121,119,7},{121,121,7},{121,133,17},{133,45,-50},{133,65,-46},{133,74,-50},{133,97,-46},
+ {133,99,-50},{133,100,-50},{133,101,-50},{133,103,-33},{133,109,-21},{133,110,-21},{133,111,-50},{133,112,-21},
+ {133,113,-33},{133,114,-21},{133,115,-58},
+};
+const struct fos_font fos_font_xl_data = { xl_bits, xl_glyphs, xl_lut, xl_kern, 515, 50, 10 };
+
+static const uint8_t num_bits[] = {
+ 130,113,113,49,133,6,127,127,79,5,131,8,127,127,79,7,131,8,127,127,79,7,131,8,
+ 127,127,79,7,131,8,127,127,79,7,131,8,127,127,79,7,131,6,127,127,79,4,255,255,
+ 255,255,211,132,3,10,14,15,13,9,2,136,5,95,14,4,134,2,14,111,14,1,133,8,
+ 127,15,8,133,12,127,15,11,133,13,127,15,13,133,12,127,15,11,133,8,127,15,8,133,
+ 2,14,111,14,2,134,5,95,14,4,136,3,10,14,15,14,9,2,149,145,9,95,14,2,
+ 148,14,111,1,147,4,111,11,148,8,111,7,148,13,111,3,147,2,111,14,148,6,111,10,
+ 148,10,111,5,148,14,111,1,147,4,111,12,148,8,111,8,148,12,111,4,147,1,111,14,
+ 148,5,111,10,148,10,111,6,148,14,111,2,147,3,111,13,148,7,111,8,148,12,111,4,
+ 147,1,111,14,148,5,111,11,148,9,111,7,148,13,111,2,147,3,111,13,148,7,111,9,
+ 148,11,111,5,147,1,127,1,147,4,111,11,148,9,111,7,148,13,111,3,147,2,111,14,
+ 148,6,111,9,148,11,111,5,148,14,111,1,147,4,111,12,148,8,111,8,148,12,111,3,
+ 147,2,111,14,148,6,111,10,148,10,111,6,148,14,111,2,147,3,111,12,148,8,111,8,
+ 148,12,111,4,147,1,111,14,148,5,111,11,148,9,111,6,148,14,111,2,147,3,111,13,
+ 148,7,111,9,148,11,111,4,147,1,127,1,147,5,111,11,148,9,111,7,148,13,111,3,
+ 147,2,111,13,148,7,111,9,148,11,111,5,148,14,111,1,147,1,14,95,10,147,142,3,
+ 5,39,6,4,2,154,5,11,127,15,13,8,2,149,5,13,127,95,9,1,145,1,10,127,
+ 127,15,14,4,143,1,12,127,127,63,5,142,11,127,127,95,4,140,8,127,127,111,14,2,
+ 138,3,127,31,14,10,25,12,127,31,10,138,10,127,14,6,132,2,10,127,15,3,136,2,
+ 127,13,2,135,8,127,10,136,7,127,4,137,11,127,1,135,11,111,10,138,2,127,4,135,
+ 14,111,4,139,11,111,8,134,2,127,1,139,7,111,10,134,3,111,13,140,5,111,12,134,
+ 4,111,12,140,4,111,12,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
+ 4,111,12,140,3,111,13,134,4,111,12,140,4,111,12,134,3,111,13,140,5,111,12,134,
+ 2,127,140,7,111,10,135,14,111,4,139,11,111,8,135,11,111,10,138,2,127,4,135,7,
+ 127,4,137,10,127,1,135,2,127,13,2,135,8,127,10,137,10,127,14,5,132,2,10,127,
+ 15,3,137,3,127,31,14,10,25,12,127,31,10,139,8,127,127,111,14,2,140,11,127,127,
+ 95,4,141,1,12,127,127,63,5,143,1,10,127,127,15,14,4,146,5,13,127,95,10,1,
+ 149,6,11,127,15,13,8,2,154,3,5,39,6,4,2,142,135,3,11,111,13,137,3,10,
+ 127,31,1,134,3,10,127,63,1,132,2,10,127,95,1,131,9,127,127,1,130,2,127,127,
+ 15,1,130,1,127,127,15,1,131,127,127,15,1,131,14,127,127,1,131,13,63,13,9,5,
+ 2,127,1,131,10,13,9,5,1,131,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
+ 140,127,1,140,127,1,140,127,1,140,127,1,140,12,95,13,131,140,1,4,6,39,5,3,
+ 152,6,11,127,14,9,3,147,5,13,127,79,10,2,143,1,10,127,127,14,4,141,1,11,
+ 127,127,31,14,4,140,10,127,127,63,14,2,138,7,127,127,95,11,137,1,14,127,15,12,
+ 25,11,127,31,6,136,9,127,12,3,131,2,11,127,13,135,1,127,12,1,134,11,127,5,
+ 134,5,127,3,135,2,14,111,9,134,10,111,10,137,8,111,13,134,13,111,5,137,3,127,
+ 1,133,127,2,138,14,111,3,132,2,127,1,138,12,111,4,132,3,127,139,11,111,6,132,
+ 4,127,139,12,111,6,132,4,127,139,12,111,5,132,4,127,139,14,111,4,132,2,14,95,
+ 13,138,2,127,3,152,6,127,1,152,10,111,12,152,1,14,111,9,152,5,127,5,152,11,
+ 127,1,151,3,127,10,152,9,127,4,151,2,127,13,152,9,127,7,151,3,127,14,1,151,
+ 11,127,7,151,5,127,14,1,150,1,13,127,6,151,8,127,12,151,3,127,15,3,151,12,
+ 127,9,151,7,127,14,1,150,2,14,127,5,151,11,127,10,151,6,127,14,2,150,1,14,
+ 127,6,151,10,127,11,151,5,127,14,2,150,1,14,127,7,151,10,127,12,151,5,127,15,
+ 3,150,1,14,127,7,151,10,127,12,151,5,127,15,3,150,1,14,127,8,151,10,127,12,
+ 151,5,127,15,3,150,1,14,127,7,151,10,127,12,113,113,33,133,127,127,127,79,11,131,
+ 1,127,127,127,79,13,131,1,127,127,127,79,13,131,1,127,127,127,79,13,131,1,127,127,
+ 127,79,13,131,1,127,127,127,79,13,132,13,127,127,127,63,10,129,130,8,127,127,127,31,
+ 14,1,133,11,127,127,127,47,2,133,11,127,127,127,47,2,133,11,127,127,127,47,2,133,
+ 11,127,127,127,47,2,133,11,127,127,127,47,2,133,9,127,127,127,47,2,134,113,113,2,
+ 14,127,11,151,9,127,14,2,150,4,127,15,6,150,1,13,127,11,151,9,127,14,2,150,
+ 4,127,15,7,150,1,13,127,12,151,9,127,15,2,150,3,127,15,7,151,13,127,12,151,
+ 8,127,15,2,150,3,127,15,7,151,13,127,12,151,8,127,15,3,150,3,127,15,7,151,
+ 12,127,15,4,150,7,127,63,9,2,147,9,127,79,14,6,146,1,12,127,95,8,146,2,
+ 13,127,95,6,146,2,14,15,14,9,7,9,14,127,2,146,3,8,1,130,1,10,111,11,
+ 154,10,111,3,153,1,14,95,10,154,8,95,14,1,153,3,111,5,154,14,95,8,154,12,
+ 95,10,154,10,95,13,154,9,111,154,8,111,2,153,7,111,3,153,6,111,3,153,6,111,
+ 4,132,1,7,88,3,139,6,111,5,132,4,111,11,139,7,111,4,132,4,111,12,139,7,
+ 111,3,132,4,111,13,139,8,111,3,132,3,111,14,139,10,111,2,132,1,127,1,138,11,
+ 111,134,127,3,138,13,95,13,134,13,111,7,137,1,111,10,134,10,111,12,137,6,111,7,
+ 134,7,127,4,136,13,111,3,134,3,127,13,1,134,8,111,14,136,12,127,13,3,131,1,
+ 9,127,8,136,6,127,31,12,25,10,14,127,15,2,137,12,127,127,95,9,138,3,14,127,
+ 127,63,13,1,139,4,14,127,127,31,14,3,141,4,13,127,127,14,4,143,1,10,127,95,
+ 11,2,146,2,8,13,127,14,10,3,151,2,5,6,23,6,5,3,141,140,1,13,111,6,
+ 154,6,127,4,154,11,111,14,154,1,127,9,154,6,127,4,154,11,111,14,154,1,127,10,
+ 154,6,127,5,154,10,111,14,1,153,1,127,10,154,5,127,5,154,10,127,1,153,1,14,
+ 111,11,154,5,127,6,154,10,127,1,154,14,111,11,154,5,127,6,154,10,127,2,154,14,
+ 111,12,154,4,127,7,154,9,127,2,154,14,111,12,154,4,127,8,154,9,127,3,154,14,
+ 111,13,135,6,111,5,137,4,127,8,135,8,111,8,137,9,127,3,135,8,111,8,137,13,
+ 111,13,136,8,111,8,136,4,127,9,136,8,111,8,136,8,127,4,136,8,111,8,136,13,
+ 111,14,137,8,111,8,135,3,127,9,137,8,111,8,135,8,127,4,137,8,111,8,135,13,
+ 111,14,138,8,111,8,134,3,127,10,138,8,111,8,134,8,127,5,138,8,111,8,134,13,
+ 127,2,113,33,9,111,8,17,131,3,127,127,127,127,15,4,129,6,127,127,127,127,15,5,
+ 129,6,127,127,127,127,15,5,129,6,127,127,127,127,15,5,129,6,127,127,127,127,15,5,
+ 129,6,127,127,127,127,15,5,129,4,127,127,127,127,14,3,151,8,111,8,155,8,111,8,
+ 155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,
+ 155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,
+ 155,8,111,8,155,6,111,5,132,130,2,14,127,127,127,31,4,133,3,127,127,127,47,6,
+ 133,3,127,127,127,47,6,133,3,127,127,127,47,6,133,3,127,127,127,47,6,133,3,127,
+ 127,127,47,6,133,3,127,127,127,47,4,133,3,111,13,113,113,17,135,3,111,13,153,3,
+ 111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,
+ 111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,
+ 111,13,153,3,111,13,153,3,111,13,130,1,5,10,13,14,15,14,13,10,5,140,3,111,
+ 13,129,5,14,127,15,13,5,138,3,111,13,128,9,127,79,9,137,3,111,14,10,127,111,
+ 9,136,3,127,127,127,15,6,135,3,127,127,127,15,14,1,134,3,127,127,127,31,8,134,
+ 3,127,31,14,7,3,1,128,3,8,14,127,14,134,3,127,15,12,1,133,3,14,127,4,
+ 133,3,127,14,1,135,4,127,8,133,3,127,7,137,11,111,11,133,3,127,2,137,5,111,
+ 14,134,8,89,6,138,2,127,1,153,14,111,3,153,11,111,6,153,9,111,7,153,9,111,
+ 7,153,8,111,8,153,7,111,9,153,8,111,8,153,8,111,8,133,4,86,3,139,9,111,
+ 7,132,1,111,13,139,10,111,6,132,1,127,1,138,13,111,5,133,14,111,3,138,127,3,
+ 133,12,111,7,137,3,127,1,133,9,111,11,137,8,111,14,134,5,127,3,135,1,14,111,
+ 11,134,1,127,12,1,134,10,127,7,135,10,127,12,2,131,1,10,127,15,2,135,4,127,
+ 31,12,25,11,14,127,15,11,137,10,127,127,111,2,137,2,14,127,127,79,7,139,3,14,
+ 127,127,47,9,141,4,13,127,127,15,8,143,1,10,127,95,13,4,146,2,9,13,127,14,
+ 11,5,151,2,5,6,23,6,5,3,140,141,1,4,5,23,6,5,2,151,2,8,12,127,
+ 13,7,1,146,1,8,127,79,14,7,144,2,13,127,127,11,1,141,4,14,127,127,31,12,
+ 1,139,2,14,127,127,63,9,139,12,127,127,95,6,137,6,127,31,12,25,12,127,15,14,
+ 137,13,127,13,3,131,4,14,127,6,135,4,127,13,1,133,3,14,111,13,135,8,127,3,
+ 135,8,127,1,134,12,111,10,136,1,127,5,134,127,5,137,11,111,8,133,1,127,2,137,
+ 7,111,9,133,2,127,138,6,111,10,133,3,111,14,138,5,111,11,133,3,111,14,138,5,
+ 111,11,133,3,111,14,138,3,111,10,133,3,111,14,139,1,82,134,3,111,14,153,3,111,
+ 14,153,3,111,14,153,3,111,14,153,3,111,14,129,2,8,12,14,15,14,13,11,7,3,
+ 141,3,111,14,128,8,127,31,11,3,139,3,127,11,127,79,8,138,3,127,127,111,11,137,
+ 3,127,127,127,9,136,3,127,127,127,15,6,135,3,127,127,127,15,14,1,134,3,127,47,
+ 10,4,1,128,2,7,14,127,9,134,3,127,31,6,133,2,13,111,14,134,3,127,15,9,
+ 135,3,127,5,133,3,127,15,1,136,11,111,9,133,2,127,10,137,5,111,12,133,2,127,
+ 6,137,1,127,133,2,127,4,138,14,111,2,132,2,127,2,138,12,111,4,132,2,127,1,
+ 138,10,111,6,132,2,127,139,9,111,8,132,2,127,139,8,111,9,132,2,111,14,139,7,
+ 111,9,132,2,111,14,139,7,111,10,132,2,111,14,139,8,111,10,132,1,127,139,8,111,
+ 9,132,1,127,139,9,111,9,133,127,2,138,10,111,8,133,13,111,3,138,12,111,6,133,
+ 11,111,5,138,14,111,5,133,8,111,9,137,3,127,3,133,5,111,14,137,8,127,1,133,
+ 2,127,6,135,1,14,111,13,135,12,111,14,2,134,10,127,8,135,7,127,13,3,131,1,
+ 10,127,15,3,135,1,14,127,15,12,25,11,127,31,11,137,7,127,127,111,3,138,12,127,
+ 127,79,8,139,1,13,127,127,47,10,141,2,12,127,127,15,9,144,8,14,127,79,13,5,
+ 146,1,7,12,127,14,11,5,151,1,4,6,23,6,5,3,140,128,3,14,127,127,127,47,
+ 9,129,5,127,127,127,63,11,129,5,127,127,127,63,11,129,5,127,127,127,63,11,129,5,
+ 127,127,127,63,11,129,5,127,127,127,63,11,129,6,127,127,127,63,11,129,6,95,4,113,
+ 65,14,111,8,129,6,95,4,139,3,127,4,129,6,95,4,139,8,127,1,129,6,95,3,
+ 139,12,111,11,130,1,7,56,7,139,1,127,7,149,5,127,3,149,9,111,14,150,13,111,
+ 10,149,2,127,5,149,6,127,1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,
+ 14,150,12,111,11,149,1,127,7,149,5,127,3,149,9,111,13,150,13,111,9,149,2,127,
+ 5,149,6,127,1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,
+ 11,149,1,127,7,149,5,127,2,149,9,111,13,150,13,111,9,149,2,127,5,149,6,127,
+ 1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,11,149,1,127,
+ 6,149,5,127,2,149,9,111,13,150,13,111,9,149,2,127,5,149,6,127,1,149,10,111,
+ 12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,10,149,1,127,6,149,5,127,
+ 2,149,9,111,13,150,13,111,9,150,13,95,14,4,142,141,2,5,6,23,6,4,2,152,
+ 2,9,13,127,13,8,2,147,1,10,127,95,9,1,144,4,14,127,127,14,3,142,5,127,
+ 127,63,4,140,3,14,127,127,63,14,2,139,13,127,127,95,12,138,7,127,31,12,25,12,
+ 127,31,6,137,13,127,12,3,131,3,12,127,13,136,5,127,12,1,133,1,12,127,4,135,
+ 9,127,3,135,4,127,8,135,13,111,11,137,11,111,12,134,1,127,5,137,4,111,14,134,
+ 3,127,1,138,127,2,133,4,111,13,139,12,111,3,133,4,111,11,139,11,111,3,133,4,
+ 111,10,139,10,111,3,133,3,111,11,139,11,111,3,133,2,111,12,139,12,111,1,134,111,
+ 14,139,14,95,14,135,12,111,2,137,3,111,12,135,8,111,7,137,7,111,8,135,3,111,
+ 13,137,13,111,3,136,12,111,6,135,6,111,12,137,4,127,4,133,4,127,4,138,10,127,
+ 9,3,17,3,9,127,10,139,1,12,127,127,63,12,1,140,1,12,127,127,31,11,1,143,
+ 8,127,127,8,145,6,127,127,7,143,1,11,127,127,31,11,1,140,1,12,127,127,63,12,
+ 140,9,127,9,3,17,4,10,127,8,138,3,127,5,133,6,127,2,137,10,111,8,135,9,
+ 111,9,136,1,111,14,1,135,1,111,14,136,6,111,9,137,11,111,4,135,9,111,5,137,
+ 6,111,8,135,13,111,1,137,3,111,12,135,111,14,139,111,14,134,2,111,12,139,13,111,
+ 1,133,3,111,11,139,12,111,2,133,4,111,10,139,11,111,3,133,4,111,10,139,11,111,
+ 4,133,4,111,11,139,12,111,3,133,4,111,12,139,12,111,3,133,2,111,13,139,14,111,
+ 2,133,1,127,1,137,1,127,135,14,111,3,137,4,111,13,135,11,111,7,137,8,111,10,
+ 135,7,111,13,137,13,111,7,135,3,127,5,135,5,127,3,136,12,111,14,2,133,2,14,
+ 111,12,137,6,127,13,3,131,3,13,127,6,138,13,127,15,12,25,12,127,15,13,139,4,
+ 127,127,95,4,140,9,127,127,63,8,142,11,127,127,31,10,144,9,127,127,9,146,5,13,
+ 127,63,13,5,148,1,6,12,127,12,6,1,152,1,4,6,23,6,4,1,141,139,1,4,
+ 5,6,7,6,5,4,1,150,1,7,12,127,15,12,6,147,7,14,127,79,14,6,143,1,
+ 11,127,127,15,10,1,140,1,13,127,127,47,11,140,11,127,127,79,9,138,6,127,127,111,
+ 4,136,1,14,127,15,14,10,9,10,13,127,15,12,136,6,127,15,8,1,131,5,14,127,
+ 3,135,11,127,7,134,4,127,9,134,1,127,12,136,9,111,14,134,4,127,5,136,2,127,
+ 2,133,6,111,14,138,12,111,5,133,8,111,11,138,8,111,7,133,9,111,8,138,6,111,
+ 9,133,10,111,7,138,5,111,11,133,11,111,6,138,4,111,12,133,12,111,6,138,3,111,
+ 13,133,12,111,5,138,3,111,13,133,12,111,5,138,2,111,14,133,12,111,5,138,3,111,
+ 14,133,12,111,6,138,3,111,14,133,11,111,6,138,4,111,14,133,10,111,7,138,4,111,
+ 14,133,8,111,9,138,6,111,14,133,6,111,11,138,8,111,14,133,3,111,13,138,10,111,
+ 14,133,1,127,2,137,14,111,14,134,13,111,7,136,4,127,14,134,8,111,14,1,135,12,
+ 127,14,134,3,127,11,1,133,9,127,15,14,135,11,127,13,6,2,128,1,5,12,127,31,
+ 14,135,3,127,127,127,15,14,136,9,127,127,127,14,137,12,127,127,111,14,137,1,12,127,
+ 127,95,14,138,1,10,127,79,11,111,14,140,5,12,127,15,14,5,2,127,142,4,8,12,
+ 14,31,14,12,7,1,128,2,127,153,2,127,153,2,127,153,2,127,153,2,127,135,97,138,
+ 2,127,134,13,95,14,138,2,127,134,127,1,137,2,127,134,14,111,2,137,2,127,134,14,
+ 111,2,137,3,111,14,134,13,111,4,137,5,111,13,134,11,111,7,137,9,111,12,134,9,
+ 111,12,137,14,111,9,134,5,127,5,135,6,127,5,134,1,127,13,1,133,3,14,127,1,
+ 135,10,127,12,2,131,5,14,127,10,136,3,127,31,11,9,10,13,127,31,2,137,9,127,
+ 127,95,9,138,1,13,127,127,63,12,140,2,14,127,127,31,13,2,141,2,12,127,127,11,
+ 1,143,1,8,127,79,14,7,147,2,9,13,127,11,7,1,151,2,5,6,7,6,5,4,
+ 1,141,134,7,12,30,12,6,139,1,12,95,10,138,10,127,7,136,2,127,15,14,136,5,
+ 127,31,3,135,7,127,31,4,135,5,127,31,3,135,2,127,15,14,137,10,127,7,137,1,
+ 12,95,10,139,1,7,12,15,14,12,6,255,255,225,7,12,30,12,6,139,1,12,95,10,
+ 138,10,127,7,136,2,127,15,14,136,5,127,31,3,135,7,127,31,4,135,5,127,31,3,
+ 135,2,127,15,14,137,10,127,7,137,1,12,95,10,139,1,7,12,15,14,12,6,154,141,
+ 3,5,6,23,6,4,1,152,6,11,14,127,12,7,1,147,5,13,127,79,14,7,145,9,
+ 127,127,15,11,1,141,1,12,127,127,47,13,2,140,10,127,127,79,13,1,138,7,127,127,
+ 111,10,137,2,127,31,13,10,9,10,13,127,31,4,136,9,127,13,4,132,4,12,127,12,
+ 135,1,14,111,13,1,134,1,12,127,4,134,4,127,3,136,1,14,111,9,134,8,111,10,
+ 138,6,111,13,134,11,111,5,138,1,14,111,1,133,12,111,1,139,11,111,3,133,13,111,
+ 140,9,111,5,133,14,95,14,140,8,111,6,133,14,111,140,7,111,6,133,13,111,2,139,
+ 7,111,6,133,11,111,6,139,6,111,5,133,8,111,11,140,3,68,3,134,4,127,4,153,
+ 1,14,111,13,2,153,8,127,13,1,152,1,14,127,13,2,152,6,127,15,14,3,152,12,
+ 127,31,5,151,2,14,127,31,9,151,3,14,127,31,12,2,150,5,127,47,14,4,150,4,
+ 14,127,47,8,150,3,13,127,47,10,1,149,1,12,127,47,13,2,150,9,127,47,14,3,
+ 150,6,14,127,31,14,5,150,3,13,127,47,5,150,1,10,127,47,3,151,6,127,31,13,
+ 1,151,4,14,127,15,10,152,2,13,127,15,3,152,2,13,127,10,153,2,14,127,1,153,
+ 6,127,5,154,12,111,8,133,7,92,10,140,7,111,11,133,12,111,1,139,3,111,12,133,
+ 12,111,1,139,1,111,12,133,12,111,2,139,1,111,12,133,12,111,3,139,2,111,11,133,
+ 10,111,6,139,4,111,10,133,8,111,10,139,8,111,8,133,5,111,14,1,138,14,111,4,
+ 133,1,127,9,137,8,127,1,134,11,127,6,135,5,127,10,135,5,127,15,9,1,131,1,
+ 8,127,15,4,136,12,127,31,11,25,11,127,31,11,137,3,127,127,111,14,2,138,6,127,
+ 127,95,5,140,8,127,127,63,6,142,6,127,127,15,14,5,144,3,11,127,95,10,2,147,
+ 3,9,14,127,14,9,3,152,2,5,39,6,5,2,141,
+};
+static const struct fos_glyph num_glyphs[] = {
+ { 0, 17, 0, 0, 0, 269 }, /* 0x20 */
+ { 0, 27, 30, 0, -30, 430 }, /* 0x2d */
+ { 51, 17, 12, 0, -12, 271 }, /* 0x2e */
+ { 115, 30, 60, 0, -60, 488 }, /* 0x2f */
+ { 358, 38, 62, 0, -61, 601 }, /* 0x30 */
+ { 856, 22, 60, 0, -60, 357 }, /* 0x31 */
+ { 1073, 35, 61, 0, -61, 558 }, /* 0x32 */
+ { 1434, 35, 61, 0, -60, 562 }, /* 0x33 */
+ { 1819, 37, 60, 0, -60, 591 }, /* 0x34 */
+ { 2145, 35, 61, 0, -60, 564 }, /* 0x35 */
+ { 2555, 35, 62, 0, -61, 564 }, /* 0x36 */
+ { 3041, 32, 60, 0, -60, 512 }, /* 0x37 */
+ { 3327, 36, 62, 0, -61, 577 }, /* 0x38 */
+ { 3813, 35, 62, 0, -61, 556 }, /* 0x39 */
+ { 4298, 20, 40, 0, -40, 315 }, /* 0x3a */
+ { 4415, 36, 62, 0, -61, 573 }, /* 0x53 */
+};
+static const uint8_t num_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,1,2,3,
+ 4,5,6,7,8,9,10,11,12,13,14,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern num_kern[] = {
+ {45,45,-65},{45,46,-8},{46,45,-8},{46,48,-51},{46,55,-39},{49,49,-23},{50,49,-36},{51,49,-43},
+ {52,49,-65},{52,55,-67},{53,49,-23},{54,49,-30},{55,46,-69},{55,49,-8},{56,49,-38},{57,49,-38},
+ {83,46,-8},
+};
+const struct fos_font fos_font_num_data = { num_bits, num_glyphs, num_lut, num_kern, 17, 84, 17 };
+
+static const uint8_t lbig_bits[] = {
+ 134,2,7,11,13,14,15,14,12,9,5,140,2,9,127,31,13,6,137,4,14,127,79,10,
+ 1,134,3,127,127,11,133,1,14,127,127,15,9,132,8,127,127,47,2,130,1,14,127,127,
+ 47,9,130,5,127,15,12,10,14,127,14,130,8,127,11,129,3,127,15,2,129,10,127,5,
+ 130,11,127,4,129,11,127,3,130,9,127,5,129,12,127,3,130,9,127,6,129,12,127,3,
+ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
+ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
+ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
+ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
+ 130,9,127,6,129,12,127,3,130,9,127,6,129,11,127,3,130,9,127,5,129,10,127,5,
+ 130,11,127,4,129,8,127,11,129,3,127,15,2,129,5,127,15,12,10,14,127,14,130,1,
+ 14,127,127,47,9,131,8,127,127,47,2,131,1,14,127,127,15,9,133,3,127,127,12,135,
+ 4,14,127,79,11,1,136,2,10,127,31,14,6,140,2,7,11,13,14,15,14,12,9,5,
+ 135,130,5,10,14,127,5,128,2,9,14,127,47,6,128,8,127,79,6,128,8,127,79,6,
+ 128,8,127,79,6,128,8,127,79,6,128,7,127,79,6,128,7,127,79,6,128,1,53,11,
+ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
+ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
+ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
+ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
+ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,6,127,5,128,134,1,6,10,13,
+ 14,15,14,13,10,5,1,138,1,9,127,31,14,7,136,5,14,127,79,11,1,133,5,127,
+ 127,12,1,131,3,127,127,31,8,131,12,127,127,47,2,129,4,127,127,63,8,129,9,127,
+ 15,11,10,127,15,13,129,12,127,8,129,6,127,15,1,128,14,127,2,130,127,15,3,128,
+ 127,15,1,130,13,127,3,128,127,15,1,130,127,15,2,128,13,111,14,1,129,3,127,15,
+ 1,140,8,127,13,140,1,14,127,9,140,7,127,15,4,139,2,14,127,13,140,11,127,15,
+ 6,139,7,127,15,12,139,4,127,31,3,138,2,14,127,15,7,138,1,13,127,15,10,139,
+ 11,127,15,12,1,138,9,127,15,14,2,138,8,127,15,14,3,138,6,127,31,4,138,4,
+ 127,31,5,138,3,14,127,15,7,138,2,14,127,15,9,139,11,127,31,121,41,4,128,12,
+ 127,127,79,10,128,12,127,127,79,10,128,12,127,127,79,10,128,12,127,127,79,10,128,12,
+ 127,127,79,10,128,12,127,127,79,10,128,10,127,127,79,8,128,2,127,127,63,9,129,4,
+ 127,127,63,11,129,4,127,127,63,11,129,4,127,127,63,11,129,4,127,127,63,11,129,4,
+ 127,127,63,11,129,4,127,127,63,11,129,1,8,121,10,127,31,9,138,1,11,127,15,12,
+ 1,137,1,11,127,15,13,1,138,11,127,15,14,2,138,10,127,15,14,3,138,10,127,31,
+ 4,138,10,127,31,6,138,8,127,31,11,3,138,6,127,63,14,6,137,7,127,79,8,137,
+ 7,127,79,4,137,7,15,14,8,7,14,111,13,138,5,2,129,3,127,3,142,13,111,7,
+ 142,12,111,9,142,12,111,10,142,11,111,11,129,4,102,4,131,11,111,11,129,127,14,131,
+ 11,111,12,129,127,15,131,12,111,11,129,14,127,2,130,13,111,11,129,13,127,8,129,4,
+ 127,10,129,11,127,15,11,10,127,15,8,129,8,127,127,63,4,129,2,127,127,47,14,131,
+ 9,127,127,31,6,132,12,127,127,10,133,1,11,127,95,10,136,6,13,127,31,13,5,139,
+ 4,9,12,14,31,14,12,9,5,134,134,5,127,14,1,143,11,127,12,143,1,127,15,8,
+ 143,6,127,15,3,143,11,127,13,143,1,127,15,8,143,6,127,15,4,143,11,127,14,143,
+ 1,127,15,9,143,6,127,15,4,143,11,127,14,143,1,127,15,10,143,6,127,15,5,143,
+ 11,127,15,1,142,1,127,15,11,129,9,111,14,2,131,6,127,15,6,129,12,127,3,131,
+ 11,127,15,1,129,12,127,3,130,1,127,15,11,130,12,127,3,130,6,127,15,7,130,12,
+ 127,3,130,11,127,15,2,130,12,127,3,129,1,127,127,127,15,12,5,127,127,127,15,13,
+ 6,127,127,127,15,13,6,127,127,127,15,13,6,127,127,127,15,13,6,127,127,127,15,13,
+ 6,127,127,127,15,13,2,121,89,14,127,10,9,6,142,12,127,3,144,12,127,3,144,12,
+ 127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,10,
+ 111,14,2,129,128,9,127,127,63,14,129,11,127,127,79,1,128,11,127,127,79,1,128,11,
+ 127,127,79,1,128,11,127,127,79,1,128,11,127,127,79,1,128,11,127,127,79,1,128,11,
+ 127,11,121,41,8,129,11,127,4,141,11,127,4,141,11,127,4,141,11,127,4,141,11,127,
+ 4,141,11,127,4,1,7,12,30,13,10,5,133,11,127,7,13,111,11,1,131,11,127,127,
+ 31,13,1,130,11,127,127,47,10,130,11,127,127,63,3,129,11,127,127,63,9,129,11,127,
+ 127,63,13,129,11,127,15,11,10,14,127,15,129,11,127,9,129,4,127,15,2,128,3,119,
+ 1,130,13,127,3,141,11,127,4,141,10,127,4,141,10,127,4,128,8,127,4,130,11,127,
+ 4,128,9,127,7,130,12,127,3,128,7,127,12,129,3,127,15,2,128,4,127,15,12,10,
+ 14,127,15,1,128,1,14,127,127,47,12,130,9,127,127,47,7,130,2,127,127,31,13,1,
+ 131,6,127,127,15,4,133,7,127,95,14,4,135,3,12,127,47,10,1,138,3,8,11,13,
+ 14,15,14,13,10,7,1,133,134,4,8,11,13,14,15,14,12,9,5,139,5,13,127,31,
+ 14,7,136,10,127,95,12,1,133,10,127,127,12,1,131,6,127,127,31,9,130,1,14,127,
+ 127,47,2,129,4,127,127,63,7,129,8,127,15,12,10,127,15,10,129,10,127,10,129,7,
+ 127,12,129,10,127,5,129,2,127,13,129,10,127,5,129,2,127,13,129,10,127,5,130,6,
+ 103,4,129,10,127,5,141,10,127,5,1,8,13,15,14,13,9,3,133,10,127,10,14,111,
+ 10,1,131,10,127,127,31,12,1,130,10,127,127,47,9,130,10,127,127,63,3,129,10,127,
+ 127,63,9,129,10,127,14,4,1,9,127,13,129,10,127,8,129,1,127,15,1,128,9,127,
+ 6,130,13,127,3,128,9,127,5,130,12,127,4,128,9,127,5,130,12,127,5,128,9,127,
+ 5,130,11,127,5,128,9,127,5,130,11,127,5,128,9,127,5,130,12,127,5,128,8,127,
+ 7,130,13,127,5,128,6,127,12,129,4,127,15,4,128,4,127,15,12,10,14,127,15,2,
+ 128,1,127,127,63,14,130,10,127,127,47,9,130,3,127,127,31,14,2,131,8,127,127,15,
+ 6,133,8,127,111,6,135,4,12,127,47,11,2,138,3,8,11,13,14,15,14,13,10,7,
+ 2,133,5,127,127,79,4,7,127,127,79,5,7,127,127,79,5,7,127,127,79,5,7,127,
+ 127,79,5,7,127,127,79,5,7,127,127,79,5,8,95,14,57,10,127,15,5,8,95,11,
+ 131,6,127,15,1,7,95,10,131,10,127,12,128,1,84,1,130,1,14,127,7,139,5,127,
+ 15,2,139,9,127,13,140,14,127,8,139,3,127,15,3,139,8,127,14,140,13,127,9,139,
+ 2,127,15,4,139,7,127,14,140,11,127,10,139,1,127,15,6,139,6,127,15,1,139,10,
+ 127,11,140,14,127,7,139,4,127,15,2,139,9,127,13,140,13,127,8,139,3,127,15,3,
+ 139,8,127,14,140,12,127,9,139,2,127,15,4,139,7,127,14,140,11,127,10,139,1,127,
+ 15,5,139,5,127,15,1,139,10,127,11,140,12,127,6,136,134,3,8,11,14,31,14,12,
+ 8,4,139,3,12,127,31,13,5,136,7,127,95,9,134,7,127,127,10,132,4,127,127,31,
+ 6,131,12,127,127,31,14,130,2,127,127,63,5,129,7,127,15,11,10,127,15,9,129,9,
+ 127,8,129,7,127,12,129,11,127,3,129,2,127,13,129,11,127,1,130,127,12,129,10,127,
+ 2,130,127,11,129,8,127,4,129,2,127,8,129,4,127,12,2,1,11,127,2,130,13,127,
+ 127,31,11,131,5,127,127,15,14,2,132,10,127,111,14,3,134,8,127,95,5,135,9,127,
+ 95,14,5,133,11,127,127,15,3,131,7,127,127,31,12,131,14,111,13,18,12,127,2,129,
+ 4,127,5,129,4,127,7,129,8,127,2,129,2,127,10,129,10,127,1,130,127,12,129,11,
+ 127,1,130,14,111,13,129,11,127,2,130,127,12,129,10,127,3,129,2,127,11,129,8,127,
+ 9,129,8,127,9,129,4,127,15,27,127,15,4,129,1,127,127,47,14,1,130,9,127,127,
+ 31,8,131,1,13,127,127,13,1,132,4,14,127,95,14,3,134,4,14,127,63,13,3,136,
+ 2,10,127,31,9,1,139,2,7,11,13,31,14,11,7,2,134,133,2,7,10,13,14,15,
+ 14,13,11,8,4,138,2,10,127,47,13,5,135,6,127,111,9,133,5,127,127,15,9,131,
+ 2,14,127,127,31,5,130,8,127,127,47,12,130,13,127,127,63,2,128,1,127,31,10,12,
+ 127,15,6,128,2,127,15,4,129,10,127,8,128,3,127,14,130,5,127,10,128,4,127,13,
+ 130,4,127,11,128,4,127,13,130,4,127,11,128,4,127,13,130,4,127,11,128,3,127,13,
+ 130,4,127,11,128,2,127,14,130,4,127,11,128,1,127,15,1,129,6,127,11,129,13,127,
+ 9,1,2,13,127,11,129,9,127,127,63,11,129,3,127,127,63,11,130,9,127,127,47,11,
+ 130,1,12,127,127,31,11,131,1,10,127,11,127,11,133,3,9,12,14,15,13,9,3,4,
+ 127,11,141,4,127,12,129,1,99,2,130,4,127,12,129,11,127,2,129,4,127,12,129,12,
+ 127,3,129,4,127,12,129,11,127,4,129,5,127,12,129,10,127,10,129,10,127,11,129,8,
+ 127,15,11,12,127,15,9,129,4,127,127,63,5,130,13,127,127,31,14,1,130,6,127,127,
+ 31,7,132,9,127,127,11,134,9,127,95,10,1,135,5,13,127,31,13,6,139,4,9,12,
+ 14,15,14,13,12,8,4,134,128,1,14,111,11,131,9,127,2,129,2,127,13,131,11,127,
+ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
+ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
+ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
+ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
+ 4,129,2,127,14,57,14,127,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,
+ 127,95,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,
+ 127,95,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
+ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
+ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
+ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
+ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,1,14,111,11,
+ 131,9,127,2,128,128,2,14,127,63,14,11,7,2,135,3,127,127,15,8,1,133,3,127,
+ 127,31,13,2,132,3,127,127,47,13,1,131,3,127,127,63,10,131,3,127,127,79,4,130,
+ 3,127,127,79,11,130,3,127,14,25,12,127,31,2,129,3,127,11,130,5,127,15,6,129,
+ 3,127,11,131,11,127,8,129,3,127,11,131,6,127,10,129,3,127,11,131,4,127,11,129,
+ 3,127,11,131,5,127,10,129,3,127,11,131,7,127,9,129,3,127,11,131,13,127,7,129,
+ 3,127,12,129,2,11,127,15,4,129,3,127,127,79,14,130,3,127,127,79,8,130,3,127,
+ 127,63,14,1,130,3,127,127,63,4,131,3,127,127,47,5,132,3,127,127,15,12,3,133,
+ 3,127,79,14,12,9,4,135,3,127,12,143,3,127,11,143,3,127,11,143,3,127,11,143,
+ 3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,
+ 3,127,11,143,3,127,11,143,3,127,11,143,2,14,111,10,142,128,11,127,127,95,14,129,
+ 13,127,127,111,1,128,13,127,127,111,1,128,13,127,127,111,1,128,13,127,127,111,1,128,
+ 13,127,127,111,1,128,13,127,127,111,1,128,6,89,12,127,12,89,8,136,8,127,7,143,
+ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
+ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
+ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
+ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
+ 8,127,7,143,8,127,7,143,8,127,7,143,6,127,5,135,
+};
+static const struct fos_glyph lbig_glyphs[] = {
+ { 0, 11, 0, 0, 0, 173 }, /* 0x20 */
+ { 0, 25, 37, 0, -37, 394 }, /* 0x30 */
+ { 289, 16, 37, 0, -37, 254 }, /* 0x31 */
+ { 451, 24, 37, 0, -37, 390 }, /* 0x32 */
+ { 688, 24, 37, 0, -37, 385 }, /* 0x33 */
+ { 922, 27, 37, 0, -37, 439 }, /* 0x34 */
+ { 1132, 24, 37, 0, -37, 389 }, /* 0x35 */
+ { 1376, 24, 37, 0, -37, 390 }, /* 0x36 */
+ { 1658, 23, 37, 0, -37, 365 }, /* 0x37 */
+ { 1840, 24, 37, 0, -37, 385 }, /* 0x38 */
+ { 2105, 24, 37, 0, -37, 385 }, /* 0x39 */
+ { 2384, 26, 37, 0, -37, 417 }, /* 0x48 */
+ { 2669, 26, 37, 0, -37, 410 }, /* 0x50 */
+ { 2897, 26, 37, 0, -37, 419 }, /* 0x54 */
+};
+static const uint8_t lbig_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 1,2,3,4,5,6,7,8,9,10,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 11,255,255,255,255,255,255,255,12,255,255,255,13,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern lbig_kern[] = {
+ {50,49,-5},{51,49,-7},{52,49,-48},{52,55,-51},{54,49,-4},{56,49,-6},{57,49,-6},
+};
+const struct fos_font fos_font_lbig_data = { lbig_bits, lbig_glyphs, lbig_lut, lbig_kern, 7, 54, 11 };
+
+static const uint8_t lname_bits[] = {
+ 128,4,47,3,129,4,47,3,129,3,47,2,129,3,47,2,129,2,47,1,129,2,47,1,
+ 129,1,47,130,1,47,131,31,14,131,31,14,131,14,15,13,145,10,14,10,130,6,47,5,
+ 129,6,47,5,130,10,14,10,129,9,31,10,128,47,3,8,31,9,128,47,3,7,31,8,
+ 128,14,31,2,7,31,7,128,13,31,1,6,31,6,128,12,31,128,4,31,5,128,11,15,
+ 14,227,131,6,23,5,129,39,4,132,14,31,9,128,1,47,7,131,1,47,7,128,4,47,
+ 4,131,4,47,4,128,6,47,2,129,4,127,63,8,128,4,127,63,8,128,4,127,63,8,
+ 130,13,31,10,128,1,47,8,132,47,8,128,2,47,6,131,2,47,7,128,4,47,4,129,
+ 2,127,63,10,128,2,127,63,10,128,2,127,63,10,130,11,31,12,129,13,31,10,132,13,
+ 31,10,129,47,8,132,47,8,128,3,47,5,131,1,40,3,128,2,40,2,130,129,3,10,
+ 30,10,2,131,5,31,3,131,3,14,15,30,15,14,2,130,13,15,10,132,11,15,7,129,
+ 8,15,10,129,7,31,2,132,13,15,130,1,15,12,128,1,14,15,8,133,11,15,7,129,
+ 8,15,10,128,8,15,14,1,133,3,14,15,30,15,14,3,2,31,7,135,3,11,30,10,
+ 3,128,10,15,13,142,3,31,5,142,11,15,12,142,5,31,4,128,6,11,12,9,1,136,
+ 13,15,10,128,10,63,14,2,134,6,31,2,5,15,12,3,1,9,15,10,133,1,14,15,
+ 9,128,10,15,4,130,14,15,133,8,15,14,1,128,10,15,4,130,14,15,132,2,14,15,
+ 7,129,6,15,11,1,128,7,15,11,132,9,15,13,1,130,12,15,30,15,14,3,131,2,
+ 31,5,131,1,9,30,11,3,129,130,5,11,30,12,7,135,7,95,12,1,132,2,127,8,
+ 132,6,47,6,2,12,31,13,132,6,47,2,128,9,31,14,132,4,47,6,1,13,31,12,
+ 133,11,31,14,12,47,5,133,2,14,79,9,134,2,13,63,7,134,2,14,79,7,129,10,
+ 5,130,11,47,12,47,5,7,31,10,128,2,47,8,128,11,95,8,128,4,47,4,128,1,
+ 12,63,12,129,4,47,10,18,9,63,3,129,1,14,127,31,9,130,6,127,47,5,130,4,
+ 11,14,15,14,12,7,1,11,31,14,1,9,31,13,8,31,12,8,31,11,7,31,10,6,
+ 31,9,5,31,8,171,129,5,47,2,130,13,31,12,130,6,47,6,130,12,47,1,129,2,
+ 47,12,130,6,47,8,130,9,47,5,130,12,47,3,130,13,47,1,130,14,47,131,14,47,
+ 131,14,47,131,13,47,1,130,12,47,3,130,9,47,5,130,6,47,8,130,2,47,12,131,
+ 12,47,1,130,6,47,6,131,13,31,12,131,5,47,2,128,128,6,31,14,2,130,1,14,
+ 31,10,131,9,47,3,130,4,47,8,131,14,31,14,131,11,47,2,130,9,47,5,130,6,
+ 47,8,130,5,47,9,130,4,47,10,130,3,47,11,130,4,47,10,130,5,47,9,130,6,
+ 47,8,130,9,47,5,130,11,47,2,129,1,47,14,130,4,47,8,130,9,47,3,129,1,
+ 14,31,10,130,6,31,14,2,129,130,7,15,7,131,7,1,7,15,8,1,7,128,4,15,
+ 14,11,15,11,14,15,5,3,12,79,13,4,129,11,47,12,1,128,3,12,79,12,3,4,
+ 15,14,11,15,12,14,15,5,128,6,1,7,15,8,1,7,131,7,15,7,211,131,12,15,
+ 11,135,13,15,12,135,13,15,12,135,13,15,12,131,6,127,15,5,6,127,15,22,127,15,
+ 5,131,13,15,12,135,13,15,12,135,12,15,12,164,128,10,31,5,128,13,31,2,128,14,
+ 15,13,129,31,10,128,2,31,6,128,3,31,2,128,135,6,95,10,6,95,10,6,95,10,
+ 175,128,7,14,13,3,128,1,47,10,128,1,47,10,129,7,14,12,2,128,132,2,47,5,
+ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,47,1,132,12,31,11,132,2,47,6,
+ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,47,1,132,12,31,11,132,2,47,6,
+ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,31,14,1,132,129,1,9,13,15,14,
+ 10,3,130,2,14,95,5,129,11,111,14,17,47,11,1,7,47,6,3,47,5,129,47,8,
+ 4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,
+ 129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,
+ 9,3,47,5,129,47,8,1,47,11,1,7,47,6,128,11,111,14,1,128,2,14,95,5,
+ 130,2,9,13,15,14,10,3,129,2,8,13,47,3,11,79,3,11,79,3,6,7,9,47,
+ 3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,
+ 3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,
+ 3,129,5,47,3,129,2,9,13,15,14,10,2,130,4,14,79,14,3,129,13,111,12,128,
+ 4,47,8,1,11,47,2,6,47,3,128,5,47,3,5,44,2,128,7,47,2,133,12,31,
+ 14,133,4,47,9,132,1,13,31,14,2,132,10,47,6,132,6,47,9,132,3,47,12,132,
+ 2,14,31,14,2,131,1,12,47,4,132,5,127,15,8,5,127,15,8,5,127,15,8,2,
+ 127,15,1,2,127,15,1,2,127,15,1,132,9,47,10,132,6,47,12,1,131,4,47,13,
+ 1,131,2,14,47,7,132,1,11,63,12,1,131,1,7,4,12,31,9,134,5,31,13,134,
+ 4,47,128,3,41,1,128,4,47,1,6,47,2,128,5,47,1,4,47,8,1,11,31,14,
+ 128,1,14,111,10,129,5,95,14,2,130,3,10,14,15,13,9,2,129,130,5,47,6,134,
+ 11,47,1,133,1,47,11,134,7,47,5,134,12,31,14,1,133,2,47,10,134,8,47,4,
+ 128,14,31,8,129,13,31,14,129,47,8,128,3,47,9,129,47,8,128,8,127,31,11,10,
+ 127,31,11,10,127,31,11,133,1,47,9,135,47,8,135,47,8,135,47,8,135,14,31,8,
+ 128,3,127,15,19,127,15,19,127,15,19,47,5,133,3,47,4,133,3,47,4,133,3,47,
+ 5,6,10,8,3,129,3,47,14,63,5,128,3,127,14,128,3,47,11,3,10,47,3,128,
+ 36,1,128,3,47,5,133,2,47,6,2,45,5,128,3,47,5,1,47,11,1,9,47,4,
+ 128,11,111,14,1,128,2,14,95,5,130,2,9,13,15,14,11,4,129,129,2,10,13,15,
+ 14,10,2,130,4,14,79,14,3,129,13,111,12,128,2,47,10,1,10,47,2,3,47,5,
+ 128,5,47,2,3,47,5,129,34,128,3,47,8,12,15,12,5,129,3,127,5,128,3,127,
+ 13,128,3,47,11,1,9,47,2,3,47,6,128,3,47,5,3,47,5,128,3,47,6,2,
+ 47,6,128,3,47,6,128,14,31,11,1,9,47,5,128,10,127,2,128,2,14,95,7,130,
+ 2,9,13,15,13,11,4,129,9,127,13,10,127,14,10,127,14,10,31,3,128,1,14,31,
+ 12,2,20,129,4,47,7,132,8,47,3,132,13,31,13,132,2,47,8,132,7,47,4,132,
+ 11,31,14,132,1,47,10,132,5,47,5,132,10,47,1,132,14,31,11,132,4,47,7,132,
+ 9,47,2,132,13,31,12,131,129,2,9,13,15,13,10,3,130,3,14,95,4,129,12,111,
+ 13,128,2,47,9,2,10,47,19,47,4,128,4,47,3,2,47,9,1,9,31,14,1,128,
+ 13,111,7,129,4,95,11,130,1,12,95,6,129,10,31,11,1,11,31,13,128,1,47,5,
+ 128,5,47,2,3,47,4,128,4,47,19,47,5,128,5,47,3,1,47,11,1,11,31,14,
+ 129,10,111,8,129,2,13,79,12,1,130,1,9,13,15,13,8,1,129,129,6,12,30,13,
+ 8,1,130,9,95,13,1,128,3,127,9,128,7,47,7,1,12,31,13,128,8,47,1,128,
+ 8,47,128,8,47,1,128,7,47,1,7,47,1,128,8,47,1,4,47,7,1,13,47,17,
+ 14,127,1,128,7,127,1,129,7,13,15,12,10,47,1,128,34,129,7,47,1,4,47,3,
+ 128,7,47,1,4,47,8,1,12,47,128,1,14,111,11,129,5,95,14,2,130,4,11,14,
+ 15,13,9,2,129,128,1,11,14,10,130,6,47,5,129,6,47,5,129,1,11,14,10,158,
+ 1,11,14,10,130,6,47,5,129,6,47,5,129,1,11,14,10,129,128,6,14,13,4,128,
+ 2,47,14,128,2,47,14,129,7,14,13,4,153,9,31,6,129,11,31,4,129,12,31,1,
+ 129,13,15,12,130,14,15,9,130,31,5,129,129,2,9,13,15,14,10,3,130,4,14,95,
+ 5,128,1,14,111,14,1,6,47,7,1,8,47,5,8,47,129,2,47,7,3,37,129,4,
+ 47,6,132,2,13,47,1,131,3,14,47,6,131,2,14,47,6,132,7,47,5,133,9,31,
+ 14,134,4,23,5,145,3,13,14,6,134,11,47,134,11,47,134,3,13,14,6,131,130,1,
+ 63,1,133,4,63,5,133,7,63,8,133,10,63,11,133,14,79,132,2,31,11,13,31,3,
+ 131,6,31,9,10,31,6,131,9,31,6,7,31,10,131,12,31,3,4,31,13,130,1,47,
+ 1,2,47,1,129,4,31,13,129,14,31,5,129,7,31,14,27,14,31,8,129,11,127,12,
+ 129,14,127,15,128,2,47,3,129,3,47,3,6,47,1,129,1,47,7,9,31,13,131,13,
+ 31,10,128,13,63,14,11,6,131,14,111,11,130,14,127,6,129,14,31,10,1,4,14,31,
+ 11,129,14,31,9,129,9,31,13,129,14,31,9,129,9,31,13,129,14,31,10,128,3,14,
+ 31,9,129,14,111,14,2,129,14,111,6,130,14,111,14,3,129,14,31,10,128,3,13,31,
+ 11,129,14,31,9,129,7,47,1,128,14,31,9,129,7,47,2,128,14,31,10,128,3,13,
+ 47,1,128,14,127,11,129,14,111,14,2,129,13,79,13,8,1,129,129,1,8,13,15,14,
+ 12,5,131,2,13,95,9,130,10,127,5,128,1,47,11,2,3,14,31,10,128,2,47,6,
+ 129,11,31,12,128,2,47,6,129,3,21,3,128,2,47,6,134,2,47,6,134,2,47,6,
+ 134,2,47,6,134,2,47,6,134,2,47,6,129,3,21,4,128,2,47,6,129,11,31,12,
+ 128,1,47,11,2,3,14,31,10,129,10,127,4,129,2,13,95,9,131,1,8,13,15,14,
+ 11,5,130,128,13,63,14,12,6,131,14,111,11,130,14,127,7,129,14,31,10,128,4,14,
+ 31,12,129,14,31,9,129,10,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,
+ 31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,
+ 31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,10,
+ 31,14,129,14,31,10,128,4,14,31,12,129,14,127,7,129,14,111,11,130,13,63,14,12,
+ 6,130,128,13,127,4,128,14,127,4,128,14,127,4,128,14,31,10,134,14,31,9,134,14,
+ 31,9,134,14,31,10,134,14,95,1,130,14,95,1,130,14,95,1,130,14,31,10,134,14,
+ 31,9,134,14,31,9,134,14,31,10,134,14,127,4,128,14,127,4,128,13,127,4,128,13,
+ 127,3,128,14,127,4,128,14,127,3,128,14,31,10,134,14,31,9,134,14,31,9,134,14,
+ 31,10,134,14,95,131,14,95,131,14,95,131,14,31,10,134,14,31,9,134,14,31,9,134,
+ 14,31,9,134,14,31,9,134,14,31,9,134,13,31,9,133,129,1,8,13,15,14,12,6,
+ 131,2,13,95,11,130,11,127,7,128,1,47,12,2,3,14,31,11,128,2,47,6,129,11,
+ 31,12,128,2,47,6,129,3,20,3,128,2,47,6,134,2,47,6,3,63,12,128,2,47,
+ 6,3,63,12,128,2,47,6,3,63,12,128,2,47,6,129,11,31,12,128,2,47,6,129,
+ 11,31,12,128,2,47,6,129,11,31,12,128,1,47,12,2,4,47,10,129,11,127,4,129,
+ 2,14,95,9,131,1,8,13,15,14,11,5,130,128,13,31,9,129,9,31,13,129,14,31,
+ 9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,
+ 9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,10,129,10,31,14,129,14,127,
+ 14,129,14,127,14,129,14,127,14,129,14,31,10,129,10,31,14,129,14,31,9,129,9,31,
+ 14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,
+ 14,129,14,31,9,129,9,31,14,129,13,31,9,129,9,31,13,128,128,13,31,9,129,14,
+ 31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,
+ 31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,
+ 31,9,129,14,31,9,129,14,31,9,129,13,31,9,128,133,5,47,3,133,5,47,3,133,
+ 5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,
+ 5,47,3,133,5,47,3,5,24,7,129,5,47,3,10,31,13,129,5,47,3,10,31,14,
+ 129,5,47,3,8,47,5,1,11,47,1,3,127,11,129,8,95,14,2,130,5,11,14,15,
+ 13,9,1,129,128,13,31,9,129,2,14,31,8,128,14,31,9,129,10,31,14,1,128,14,
+ 31,9,128,3,47,8,129,14,31,9,128,10,31,14,1,129,14,31,9,3,47,7,130,14,
+ 31,9,11,31,14,1,130,14,31,13,47,7,131,14,95,1,131,14,95,6,131,14,95,12,
+ 131,14,47,11,47,3,130,14,31,12,1,14,31,10,130,14,31,9,128,9,47,2,129,14,
+ 31,9,128,3,47,8,129,14,31,9,129,11,31,14,129,14,31,9,129,5,47,6,128,13,
+ 31,9,130,13,31,12,128,13,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,
+ 31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,
+ 31,9,134,14,31,9,134,14,31,9,134,14,31,10,134,14,127,4,128,14,127,4,128,13,
+ 127,4,128,14,31,11,130,2,14,31,10,129,63,5,129,9,47,10,129,63,13,128,2,63,
+ 10,129,79,7,11,63,10,129,127,47,10,129,47,14,111,10,129,47,9,13,31,9,13,31,
+ 10,129,47,8,5,15,14,1,13,31,10,129,47,8,128,11,7,128,13,31,10,129,47,8,
+ 128,2,129,13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,129,47,8,131,
+ 13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,
+ 129,14,31,8,131,12,31,10,128,128,13,31,14,1,129,11,31,11,129,14,47,6,129,11,
+ 31,11,129,14,47,11,129,11,31,11,129,14,63,1,128,11,31,11,129,14,63,6,128,11,
+ 31,11,129,14,63,11,128,11,31,11,129,14,79,1,11,31,11,129,14,31,13,31,6,11,
+ 31,11,129,14,31,9,14,15,27,31,11,129,14,31,25,31,12,31,11,129,14,31,9,4,
+ 79,11,129,14,31,9,128,14,63,11,129,14,31,9,128,9,63,11,129,14,31,9,128,4,
+ 63,11,129,14,31,9,129,14,47,11,129,14,31,9,129,9,47,11,129,13,31,9,129,4,
+ 47,11,128,129,1,8,13,15,14,12,6,131,1,13,95,11,130,10,127,7,129,47,12,2,
+ 3,14,31,12,128,2,47,6,129,9,31,14,128,2,47,6,129,8,47,128,2,47,6,129,
+ 8,47,128,2,47,6,129,8,47,128,2,47,6,129,8,47,128,2,47,6,129,8,47,128,
+ 2,47,6,129,8,47,128,2,47,6,129,8,47,128,2,47,6,129,9,31,14,128,1,47,
+ 12,2,3,14,31,12,129,10,127,7,129,1,13,95,11,131,1,8,13,15,14,12,6,130,
+ 128,13,79,13,7,1,130,14,111,12,130,14,127,8,129,14,31,9,128,3,13,31,13,129,
+ 14,31,9,129,7,47,1,128,14,31,9,129,7,47,1,128,14,31,9,128,3,13,31,14,
+ 129,14,127,10,129,14,111,13,2,129,14,79,14,10,2,130,14,31,9,135,14,31,9,135,
+ 14,31,9,135,14,31,9,135,14,31,9,135,14,31,9,135,14,31,9,134,130,7,12,30,
+ 11,3,132,12,95,5,130,8,111,14,1,129,14,31,12,2,5,47,7,128,1,47,6,129,
+ 13,31,9,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,
+ 13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,
+ 13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,1,47,6,129,
+ 13,31,9,129,13,31,12,1,5,47,6,129,7,111,14,1,130,11,95,4,132,6,47,12,
+ 2,134,47,8,135,47,8,131,128,13,79,13,8,1,130,14,111,12,1,129,14,127,8,129,
+ 14,31,10,128,3,13,31,14,129,14,31,9,129,7,47,1,128,14,31,9,129,7,47,2,
+ 128,14,31,10,128,3,13,31,14,129,14,127,9,129,14,111,13,1,129,14,111,1,130,14,
+ 31,10,3,47,4,130,14,31,9,128,13,31,9,130,14,31,9,128,9,31,14,130,14,31,
+ 9,128,4,47,4,129,14,31,9,128,1,47,8,129,14,31,9,129,11,31,13,129,13,31,
+ 9,129,6,47,3,129,3,10,14,15,14,10,2,130,4,95,14,4,129,14,111,13,128,3,
+ 47,9,1,8,47,4,5,47,3,128,2,47,5,3,47,7,129,39,2,128,12,47,6,133,
+ 3,14,47,10,1,132,3,13,47,13,3,132,1,10,63,4,133,6,47,14,17,38,1,128,
+ 5,47,6,4,47,4,129,47,7,2,47,10,1,7,47,6,128,12,111,14,1,128,3,14,
+ 95,6,130,2,9,13,15,14,10,4,129,6,127,31,1,6,127,31,1,6,127,31,1,130,
+ 1,47,9,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,
+ 135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,14,31,8,131,128,14,31,8,
+ 129,8,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,
+ 14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,
+ 8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,
+ 31,14,129,47,8,129,9,31,14,129,14,31,9,129,9,31,14,129,12,31,14,19,14,31,
+ 11,129,6,127,6,130,11,95,10,132,6,12,30,12,6,130,5,47,6,129,2,47,8,2,
+ 47,8,129,4,47,5,128,14,31,11,129,6,47,2,128,11,31,13,129,9,31,14,129,8,
+ 47,1,128,11,31,11,129,4,47,3,128,13,31,7,129,1,47,5,128,47,4,130,13,31,
+ 8,3,47,1,130,10,31,10,5,31,13,131,6,31,12,7,31,9,131,3,31,14,10,31,
+ 6,132,47,14,31,3,132,12,63,14,133,8,63,11,133,5,63,8,133,2,63,5,134,13,
+ 47,1,130,6,47,3,129,14,31,4,129,13,31,10,3,47,5,128,2,47,7,129,47,7,
+ 1,47,8,128,4,47,9,128,2,47,4,128,12,31,10,128,6,47,12,128,5,47,1,128,
+ 9,31,12,128,8,47,14,128,7,31,13,129,6,47,128,11,63,1,9,31,11,129,3,47,
+ 2,13,63,4,11,31,8,130,47,5,31,13,31,6,13,31,5,130,12,31,9,31,8,31,
+ 9,47,2,130,9,31,14,31,4,31,14,31,14,131,6,79,2,12,63,11,131,3,63,14,
+ 128,10,63,8,132,14,47,12,128,8,63,5,132,11,47,10,128,5,63,2,132,8,47,8,
+ 128,3,47,14,133,5,47,6,129,47,12,133,2,47,3,129,13,31,8,130,4,47,4,129,
+ 5,47,2,128,13,31,10,129,11,31,11,129,7,31,14,1,2,47,5,129,1,14,31,5,
+ 7,31,13,131,9,31,11,12,31,7,131,3,95,1,132,12,63,10,133,5,63,4,133,1,
+ 47,14,134,5,63,3,133,11,63,9,132,3,95,1,131,9,31,11,13,31,7,130,1,14,
+ 31,6,7,31,13,130,7,31,14,1,2,47,5,129,13,31,10,129,11,31,11,128,4,47,
+ 4,129,5,47,2,4,47,5,129,7,47,2,128,14,31,9,129,12,31,12,129,9,31,13,
+ 128,1,47,7,129,4,47,2,5,47,2,130,14,31,6,9,31,11,131,8,31,10,13,31,
+ 6,131,3,95,1,132,13,63,10,133,8,63,5,133,2,47,14,1,134,13,31,10,135,13,
+ 31,10,135,13,31,10,135,13,31,10,135,13,31,10,135,13,31,10,135,12,31,10,131,7,
+ 127,10,8,127,11,7,127,11,132,4,47,7,132,11,31,14,1,131,4,47,7,132,11,31,
+ 14,1,131,4,47,7,132,11,31,14,1,131,4,47,7,132,11,31,14,1,131,4,47,7,
+ 132,11,31,14,1,131,4,47,7,132,7,127,10,8,127,11,7,127,10,
+};
+static const struct fos_glyph lname_glyphs[] = {
+ { 0, 5, 0, 0, 0, 80 }, /* 0x20 */
+ { 0, 7, 17, 0, -17, 112 }, /* 0x21 */
+ { 57, 9, 17, 0, -17, 138 }, /* 0x22 */
+ { 98, 15, 17, 0, -17, 246 }, /* 0x23 */
+ { 213, 19, 17, 0, -17, 306 }, /* 0x25 */
+ { 393, 15, 17, 0, -17, 241 }, /* 0x26 */
+ { 515, 4, 17, 0, -17, 68 }, /* 0x27 */
+ { 534, 8, 21, 0, -19, 124 }, /* 0x28 */
+ { 616, 8, 21, 0, -19, 124 }, /* 0x29 */
+ { 705, 9, 18, 0, -18, 144 }, /* 0x2a */
+ { 765, 11, 13, 0, -13, 175 }, /* 0x2b */
+ { 806, 5, 6, 0, -4, 84 }, /* 0x2c */
+ { 830, 8, 10, 0, -10, 132 }, /* 0x2d */
+ { 841, 6, 4, 0, -4, 89 }, /* 0x2e */
+ { 860, 10, 17, 0, -17, 166 }, /* 0x2f */
+ { 930, 11, 17, 0, -17, 181 }, /* 0x30 */
+ { 1041, 7, 17, 0, -17, 114 }, /* 0x31 */
+ { 1109, 11, 17, 0, -17, 175 }, /* 0x32 */
+ { 1199, 11, 17, 0, -17, 174 }, /* 0x33 */
+ { 1291, 12, 17, 0, -17, 194 }, /* 0x34 */
+ { 1369, 11, 17, 0, -17, 176 }, /* 0x35 */
+ { 1459, 11, 17, 0, -17, 176 }, /* 0x36 */
+ { 1568, 10, 17, 0, -17, 163 }, /* 0x37 */
+ { 1640, 11, 17, 0, -17, 176 }, /* 0x38 */
+ { 1747, 11, 17, 0, -17, 174 }, /* 0x39 */
+ { 1853, 7, 12, 0, -12, 110 }, /* 0x3a */
+ { 1890, 6, 14, 0, -12, 93 }, /* 0x3b */
+ { 1932, 11, 17, 0, -17, 175 }, /* 0x3f */
+ { 2014, 12, 17, 0, -17, 193 }, /* 0x41 */
+ { 2114, 12, 17, 0, -17, 188 }, /* 0x42 */
+ { 2226, 12, 17, 0, -17, 186 }, /* 0x43 */
+ { 2331, 12, 17, 0, -17, 190 }, /* 0x44 */
+ { 2450, 11, 17, 0, -17, 175 }, /* 0x45 */
+ { 2518, 11, 17, 0, -17, 168 }, /* 0x46 */
+ { 2584, 12, 17, 0, -17, 187 }, /* 0x47 */
+ { 2701, 12, 17, 0, -17, 192 }, /* 0x48 */
+ { 2826, 6, 17, 0, -17, 92 }, /* 0x49 */
+ { 2895, 11, 17, 0, -17, 181 }, /* 0x4a */
+ { 2980, 12, 17, 0, -17, 196 }, /* 0x4b */
+ { 3102, 11, 17, 0, -17, 170 }, /* 0x4c */
+ { 3170, 14, 17, 0, -17, 219 }, /* 0x4d */
+ { 3297, 13, 17, 0, -17, 206 }, /* 0x4e */
+ { 3435, 12, 17, 0, -17, 189 }, /* 0x4f */
+ { 3552, 12, 17, 0, -17, 186 }, /* 0x50 */
+ { 3644, 12, 20, 0, -17, 184 }, /* 0x51 */
+ { 3776, 12, 17, 0, -17, 188 }, /* 0x52 */
+ { 3893, 11, 17, 0, -17, 178 }, /* 0x53 */
+ { 3995, 12, 17, 0, -17, 187 }, /* 0x54 */
+ { 4052, 12, 17, 0, -17, 192 }, /* 0x55 */
+ { 4168, 12, 17, 0, -17, 195 }, /* 0x56 */
+ { 4275, 17, 17, 0, -17, 276 }, /* 0x57 */
+ { 4436, 12, 17, 0, -17, 190 }, /* 0x58 */
+ { 4541, 12, 17, 0, -17, 190 }, /* 0x59 */
+ { 4631, 10, 17, 0, -17, 165 }, /* 0x5a */
+};
+static const uint8_t lname_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,255,4,5,6,7,8,9,10,11,12,13,14,
+ 15,16,17,18,19,20,21,22,23,24,25,26,255,255,255,27,255,28,29,30,31,32,33,34,
+ 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern lname_kern[] = {
+ {39,45,-9},{39,65,-20},{39,74,-26},{44,48,-17},{44,55,-14},{44,84,-22},{44,86,-16},{44,87,-16},
+ {44,88,4},{44,89,-30},{45,45,-28},{46,48,-17},{46,55,-14},{46,84,-22},{46,86,-16},{46,87,-16},
+ {46,88,4},{46,89,-30},{50,49,-6},{51,49,-6},{52,49,-22},{52,55,-22},{54,49,-4},{55,44,-18},
+ {55,46,-18},{56,49,-6},{57,49,-6},{65,39,-20},{65,65,6},{65,67,-8},{65,71,-8},{65,79,-8},
+ {65,81,-8},{65,83,-10},{65,84,-24},{65,86,-30},{65,87,-30},{65,89,-22},{66,65,-8},{66,86,-10},
+ {66,87,-10},{66,88,-11},{66,89,-14},{67,65,-4},{67,88,-6},{67,89,-5},{68,65,-8},{68,86,-10},
+ {68,87,-10},{68,88,-11},{68,89,-14},{69,65,6},{70,45,-14},{70,65,-16},{71,65,-4},{71,88,-6},
+ {71,89,-5},{74,65,-6},{75,67,-8},{75,71,-8},{75,79,-8},{75,81,-8},{75,83,-9},{76,65,7},
+ {76,84,-33},{76,89,-14},{79,65,-4},{79,88,-6},{79,89,-5},{80,44,-7},{80,46,-7},{80,65,-14},
+ {80,74,-23},{80,86,-6},{80,87,-6},{80,88,-9},{80,89,-9},{81,65,-4},{81,88,-5},{81,89,-6},
+ {82,89,-11},{83,86,-6},{83,87,-6},{83,88,-11},{83,89,-10},{84,44,-17},{84,45,-28},{84,46,-17},
+ {84,65,-22},{84,67,-8},{84,71,-8},{84,79,-8},{84,81,-8},{85,65,-6},{86,44,-14},{86,45,-20},
+ {86,46,-14},{86,65,-30},{86,67,-7},{86,71,-7},{86,74,-14},{86,79,-7},{86,81,-7},{86,83,-6},
+ {87,44,-14},{87,45,-20},{87,46,-14},{87,65,-30},{87,67,-7},{87,71,-7},{87,74,-14},{87,79,-7},
+ {87,81,-7},{87,83,-6},{88,45,-6},{88,67,-6},{88,71,-6},{88,79,-6},{88,81,-6},{88,83,-11},
+ {89,44,-30},{89,45,-24},{89,46,-30},{89,65,-28},{89,67,-9},{89,71,-9},{89,74,-23},{89,79,-9},
+ {89,81,-9},{89,83,-11},
+};
+const struct fos_font fos_font_lname_data = { lname_bits, lname_glyphs, lname_lut, lname_kern, 130, 25, 5 };
+
+static const uint8_t lsm_bits[] = {
+ 128,15,7,129,15,7,129,14,7,129,14,6,129,14,6,129,13,5,133,4,1,128,1,14,
+ 8,128,11,9,10,27,25,10,9,24,9,151,129,27,128,27,130,14,9,128,14,9,129,95,
+ 5,128,7,15,8,7,15,8,2,128,4,15,3,4,15,3,129,6,15,3,6,15,3,128,
+ 7,79,14,128,2,12,13,4,12,13,3,129,13,10,128,12,10,129,128,7,14,11,1,128,
+ 5,11,129,2,13,6,11,7,128,13,3,129,3,11,2,24,7,9,131,11,15,14,3,14,
+ 2,132,3,1,24,128,1,132,2,14,2,12,15,9,131,10,23,10,5,12,4,129,3,13,
+ 128,6,11,6,12,3,129,11,5,128,1,11,15,8,128,128,5,13,14,8,131,14,12,9,
+ 15,4,129,1,15,7,3,15,5,130,9,14,29,1,130,6,31,2,130,3,15,10,14,8,
+ 7,8,128,8,15,128,5,31,7,128,7,15,23,31,2,128,1,10,30,8,28,128,43,10,
+ 25,139,128,12,11,128,4,15,6,128,9,15,2,128,12,14,129,14,12,129,15,11,129,15,
+ 11,129,14,11,129,12,13,129,9,15,1,128,4,15,5,129,13,11,128,1,15,7,129,11,
+ 14,129,7,15,3,128,4,15,6,128,2,15,8,128,1,15,9,128,1,15,9,128,2,15,
+ 8,128,4,15,6,128,7,15,3,128,11,13,128,1,15,7,128,18,12,2,1,6,13,14,
+ 12,3,6,13,14,12,19,2,12,2,1,152,129,11,6,129,17,11,7,1,128,10,63,6,
+ 2,4,12,9,4,1,129,11,6,141,4,15,128,6,12,128,24,128,49,10,31,13,2,20,
+ 3,139,130,6,15,2,1,3,128,129,3,15,5,129,7,15,1,129,12,11,129,2,15,6,
+ 129,6,15,2,129,11,12,129,1,15,7,129,5,15,3,129,9,13,130,128,8,14,13,6,
+ 128,5,15,8,10,15,2,7,15,128,3,15,5,8,15,128,2,15,5,8,15,128,2,15,
+ 5,8,15,128,2,15,5,7,15,128,3,15,21,15,8,10,15,2,128,8,30,6,128,8,
+ 14,15,128,8,12,15,129,8,15,129,8,15,129,8,15,129,8,15,129,8,15,129,8,15,
+ 129,8,15,128,128,9,14,13,4,128,6,15,7,12,13,128,9,14,128,8,15,131,11,13,
+ 130,4,15,6,129,1,13,11,130,10,14,2,129,6,15,9,21,1,9,63,4,8,63,128,
+ 2,5,6,15,12,130,10,14,2,129,5,15,11,1,130,4,11,10,131,7,14,128,8,12,
+ 128,7,15,128,7,15,7,28,128,1,10,14,13,4,128,128,1,15,8,130,7,15,3,130,
+ 28,130,2,15,7,5,15,2,8,15,3,7,15,3,12,63,11,3,20,8,15,5,130,5,
+ 15,2,130,5,15,2,7,63,1,8,15,37,128,8,15,131,8,15,12,15,7,128,7,15,
+ 7,11,15,1,128,1,128,5,15,2,4,9,128,5,15,2,4,15,9,11,15,129,9,14,
+ 13,5,128,128,9,14,13,5,128,5,15,8,12,14,128,7,15,1,3,6,128,7,15,14,
+ 15,6,128,7,15,8,11,15,128,7,15,1,5,15,3,7,15,1,5,15,3,4,15,9,
+ 11,15,1,128,9,14,13,6,128,12,47,14,12,9,5,29,1,128,1,14,9,129,4,15,
+ 5,129,9,15,1,129,13,11,129,2,15,7,129,7,15,2,129,11,13,129,1,10,14,13,
+ 5,128,6,15,7,11,14,128,6,15,3,8,15,1,128,12,31,12,128,3,15,8,12,7,
+ 128,6,15,128,6,14,128,7,15,128,6,15,1,3,15,9,12,14,129,8,14,13,4,128,
+ 1,11,14,12,3,128,8,15,7,13,12,128,11,12,128,8,14,128,9,14,3,11,15,128,
+ 3,14,47,129,2,3,8,15,128,8,14,128,9,15,128,6,15,8,29,129,10,14,13,3,
+ 128,130,2,15,7,128,3,1,136,2,15,7,128,3,1,5,14,3,6,15,3,128,1,134,
+ 4,15,1,5,12,128,7,9,128,1,10,14,13,3,128,8,15,7,12,13,128,10,12,128,
+ 8,15,1,130,12,13,130,10,15,5,129,3,15,7,130,2,10,2,131,4,1,130,4,14,
+ 4,129,129,14,13,130,3,31,2,129,6,12,14,5,129,10,9,11,9,129,13,6,8,12,
+ 128,1,15,4,5,15,1,4,63,4,8,14,19,15,7,27,129,12,10,4,31,14,8,128,
+ 4,15,7,9,15,5,4,15,3,128,15,8,4,15,20,15,5,4,47,12,128,4,15,22,
+ 15,5,4,15,3,128,13,9,4,15,23,15,7,4,31,14,10,1,128,8,30,7,128,4,
+ 15,24,15,4,7,15,17,11,5,7,15,1,130,7,15,1,130,7,15,1,130,7,15,17,
+ 11,5,4,15,24,15,4,128,8,30,7,128,4,31,14,8,128,4,15,7,8,15,5,4,
+ 15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,8,4,
+ 15,3,1,15,8,4,15,7,9,15,5,4,31,14,8,128,4,63,3,4,15,7,21,1,
+ 4,15,3,130,4,15,4,1,129,4,47,1,128,4,15,6,4,129,4,15,3,130,4,15,
+ 7,21,1,4,63,3,4,63,3,4,15,7,21,1,4,15,3,130,4,15,4,1,129,4,
+ 47,1,128,4,15,6,4,129,4,15,3,130,4,15,3,130,4,15,3,130,128,8,30,8,
+ 128,4,15,25,15,4,7,15,17,12,5,7,15,33,128,7,15,2,31,23,15,1,5,15,
+ 23,15,17,15,7,4,15,25,15,4,128,8,30,7,128,4,15,3,128,15,7,4,15,3,
+ 128,15,8,4,15,3,128,15,8,4,15,4,1,15,8,4,63,8,4,15,6,4,15,8,
+ 4,15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,7,4,15,3,4,15,3,
+ 4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,130,7,15,
+ 1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,21,128,7,15,1,12,11,
+ 128,7,15,1,9,14,6,12,13,128,1,11,14,12,3,128,4,15,3,1,14,10,4,15,
+ 3,8,15,2,4,15,4,14,9,128,4,15,12,14,1,128,4,47,2,128,4,15,9,14,
+ 8,128,4,15,3,9,14,1,4,15,19,15,6,4,15,3,128,28,4,15,3,130,4,15,
+ 3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,
+ 7,21,1,4,63,3,5,15,6,128,6,15,21,15,14,2,14,15,21,31,14,31,21,15,
+ 8,15,8,15,21,15,3,8,3,15,21,15,3,128,3,15,21,15,3,128,3,15,21,15,
+ 3,128,3,15,21,15,2,128,2,15,5,4,15,7,128,9,13,128,4,15,13,128,9,13,
+ 128,4,31,3,9,13,128,4,15,14,25,13,128,4,15,8,14,9,13,128,4,15,4,30,
+ 13,128,4,15,3,10,15,13,128,4,15,3,4,15,13,128,4,15,3,128,14,13,128,128,
+ 7,30,8,128,4,15,9,8,15,5,7,15,1,128,15,8,7,15,1,128,15,8,7,15,
+ 1,128,15,8,7,15,1,128,15,8,7,15,1,128,15,8,4,15,9,8,15,5,128,7,
+ 30,8,128,5,47,9,128,5,15,7,8,15,6,5,15,3,128,14,9,5,15,20,15,7,
+ 5,47,13,1,5,15,6,3,1,128,5,15,3,130,5,15,3,130,5,15,3,130,128,7,
+ 14,13,6,128,3,15,9,10,15,2,6,15,1,3,15,5,7,15,1,2,15,6,7,15,
+ 1,2,15,6,7,15,1,2,15,6,7,15,1,2,15,22,15,3,4,15,5,1,46,13,
+ 1,128,2,29,2,130,12,10,129,4,47,9,128,4,15,7,8,15,6,4,15,3,128,14,
+ 9,4,15,20,15,8,4,47,13,1,4,15,6,14,8,128,4,15,3,9,13,128,4,15,
+ 3,4,15,3,4,15,3,128,14,8,128,10,14,13,5,128,6,15,7,11,14,1,8,14,
+ 128,4,13,2,3,15,9,131,5,14,12,2,130,2,29,128,7,12,128,4,15,3,6,15,
+ 8,10,15,1,128,9,14,13,5,128,10,63,8,3,5,14,12,5,3,129,13,10,131,13,
+ 10,131,13,10,131,13,10,131,13,10,131,13,10,131,13,10,129,5,15,2,128,14,8,5,
+ 15,2,128,14,8,5,15,2,128,14,8,5,15,2,128,14,8,5,15,2,128,14,8,5,
+ 15,2,128,14,8,5,15,3,128,14,8,2,15,10,8,15,5,128,6,13,14,8,128,8,
+ 15,1,128,13,10,5,15,3,1,15,7,2,15,6,3,15,4,128,14,8,6,15,1,128,
+ 27,8,12,129,8,14,11,9,129,4,15,14,6,129,1,31,3,130,13,14,129,9,14,128,
+ 6,15,1,3,15,4,6,15,1,8,15,4,6,15,1,3,15,4,10,15,6,8,13,128,
+ 1,15,6,29,9,10,11,129,12,9,15,9,11,13,8,129,9,14,15,4,14,15,5,129,
+ 6,15,13,2,31,2,129,3,15,10,128,30,130,1,15,8,128,12,11,129,7,15,17,15,
+ 7,1,15,23,14,1,128,10,28,9,129,3,31,3,130,14,13,130,3,31,3,129,9,28,
+ 9,128,1,15,23,14,1,7,15,17,15,7,7,15,1,2,15,6,2,15,5,6,15,1,
+ 128,12,10,27,129,6,14,15,5,129,1,15,14,1,130,12,11,131,12,11,131,12,11,131,
+ 12,11,129,10,47,14,3,21,13,12,129,3,15,5,129,11,13,129,3,15,6,129,10,14,
+ 129,2,15,7,129,9,15,6,21,10,47,14,
+};
+static const struct fos_glyph lsm_glyphs[] = {
+ { 0, 3, 0, 0, 0, 42 }, /* 0x20 */
+ { 0, 4, 9, 0, -9, 56 }, /* 0x21 */
+ { 26, 4, 9, 0, -9, 64 }, /* 0x22 */
+ { 36, 8, 9, 0, -9, 126 }, /* 0x23 */
+ { 90, 10, 9, 0, -9, 161 }, /* 0x25 */
+ { 159, 8, 9, 0, -9, 121 }, /* 0x26 */
+ { 214, 2, 9, 0, -9, 32 }, /* 0x27 */
+ { 218, 4, 12, 0, -11, 58 }, /* 0x28 */
+ { 259, 4, 12, 0, -11, 58 }, /* 0x29 */
+ { 305, 5, 9, 0, -9, 75 }, /* 0x2a */
+ { 324, 6, 7, 0, -7, 91 }, /* 0x2b */
+ { 346, 3, 3, 0, -2, 41 }, /* 0x2c */
+ { 354, 4, 6, 0, -6, 68 }, /* 0x2d */
+ { 362, 3, 3, 0, -2, 44 }, /* 0x2e */
+ { 369, 5, 9, 0, -9, 80 }, /* 0x2f */
+ { 403, 6, 9, 0, -9, 94 }, /* 0x30 */
+ { 455, 4, 9, 0, -9, 57 }, /* 0x31 */
+ { 484, 6, 9, 0, -9, 88 }, /* 0x32 */
+ { 525, 6, 9, 0, -9, 89 }, /* 0x33 */
+ { 567, 6, 9, 0, -9, 95 }, /* 0x34 */
+ { 606, 6, 9, 0, -9, 89 }, /* 0x35 */
+ { 651, 6, 9, 0, -9, 89 }, /* 0x36 */
+ { 705, 5, 9, 0, -9, 82 }, /* 0x37 */
+ { 740, 6, 9, 0, -9, 90 }, /* 0x38 */
+ { 792, 6, 9, 0, -9, 88 }, /* 0x39 */
+ { 841, 3, 8, 0, -7, 52 }, /* 0x3a */
+ { 855, 3, 8, 0, -7, 45 }, /* 0x3b */
+ { 873, 6, 9, 0, -9, 86 }, /* 0x3f */
+ { 914, 6, 9, 0, -9, 95 }, /* 0x41 */
+ { 955, 6, 9, 0, -9, 96 }, /* 0x42 */
+ { 1002, 6, 9, 0, -9, 95 }, /* 0x43 */
+ { 1044, 6, 9, 0, -9, 98 }, /* 0x44 */
+ { 1096, 6, 9, 0, -9, 90 }, /* 0x45 */
+ { 1134, 6, 9, 0, -9, 86 }, /* 0x46 */
+ { 1172, 6, 9, 0, -9, 96 }, /* 0x47 */
+ { 1215, 6, 9, 0, -9, 99 }, /* 0x48 */
+ { 1266, 3, 9, 0, -9, 47 }, /* 0x49 */
+ { 1293, 6, 9, 0, -9, 92 }, /* 0x4a */
+ { 1336, 6, 9, 0, -9, 99 }, /* 0x4b */
+ { 1386, 6, 9, 0, -9, 86 }, /* 0x4c */
+ { 1422, 7, 9, 0, -9, 112 }, /* 0x4d */
+ { 1475, 7, 9, 0, -9, 105 }, /* 0x4e */
+ { 1535, 6, 9, 0, -9, 97 }, /* 0x4f */
+ { 1587, 6, 9, 0, -9, 95 }, /* 0x50 */
+ { 1630, 6, 11, 0, -9, 95 }, /* 0x51 */
+ { 1689, 6, 9, 0, -9, 96 }, /* 0x52 */
+ { 1738, 6, 9, 0, -9, 90 }, /* 0x53 */
+ { 1786, 6, 9, 0, -9, 94 }, /* 0x54 */
+ { 1817, 6, 9, 0, -9, 99 }, /* 0x55 */
+ { 1871, 6, 9, 0, -9, 98 }, /* 0x56 */
+ { 1917, 9, 9, 0, -9, 138 }, /* 0x57 */
+ { 1988, 6, 9, 0, -9, 96 }, /* 0x58 */
+ { 2028, 6, 9, 0, -9, 95 }, /* 0x59 */
+ { 2067, 5, 9, 0, -9, 84 }, /* 0x5a */
+};
+static const uint8_t lsm_lut[256] = {
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,0,1,2,3,255,4,5,6,7,8,9,10,11,12,13,14,
+ 15,16,17,18,19,20,21,22,23,24,25,26,255,255,255,27,255,28,29,30,31,32,33,34,
+ 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+};
+static const struct fos_kern lsm_kern[] = {
+ {39,45,-5},{39,65,-9},{39,74,-11},{44,48,-8},{44,55,-6},{44,84,-11},{44,86,-7},{44,87,-7},
+ {44,89,-14},{45,45,-12},{46,48,-8},{46,55,-6},{46,84,-11},{46,86,-7},{46,87,-7},{46,89,-14},
+ {50,49,-4},{51,49,-5},{52,49,-11},{52,55,-11},{54,49,-4},{55,44,-10},{55,46,-10},{56,49,-5},
+ {57,49,-5},{65,39,-9},{65,65,5},{65,83,-5},{65,84,-12},{65,86,-14},{65,87,-14},{65,89,-10},
+ {66,65,-4},{66,86,-4},{66,87,-4},{66,88,-5},{66,89,-6},{68,65,-4},{68,86,-4},{68,87,-4},
+ {68,88,-5},{68,89,-6},{69,65,4},{70,45,-6},{70,65,-7},{75,83,-4},{76,65,5},{76,84,-16},
+ {76,89,-6},{80,44,-5},{80,46,-5},{80,65,-6},{80,74,-9},{80,88,-4},{80,89,-4},{82,89,-5},
+ {83,88,-5},{83,89,-5},{84,44,-9},{84,45,-13},{84,46,-9},{84,65,-10},{84,67,-5},{84,71,-5},
+ {84,79,-5},{84,81,-5},{86,44,-6},{86,45,-9},{86,46,-6},{86,65,-14},{86,74,-6},{87,44,-6},
+ {87,45,-9},{87,46,-6},{87,65,-14},{87,74,-6},{88,83,-5},{89,44,-14},{89,45,-11},{89,46,-14},
+ {89,65,-13},{89,67,-4},{89,71,-4},{89,74,-9},{89,79,-4},{89,81,-4},{89,83,-5},
+};
+const struct fos_font fos_font_lsm_data = { lsm_bits, lsm_glyphs, lsm_lut, lsm_kern, 87, 13, 3 };
diff --git a/ml-dev/filmos/fos_gfx.c b/ml-dev/filmos/fos_gfx.c
new file mode 100644
index 0000000..a4e0f3a
--- /dev/null
+++ b/ml-dev/filmos/fos_gfx.c
@@ -0,0 +1,959 @@
+/* fos_gfx: palette ramps, dithering, anti-aliased shapes and text.
+ * See fos_gfx.h for the idea. Everything here is integer maths except the
+ * one-time palette build. */
+
+#include "fos_gfx.h"
+#include <string.h>
+
+/* ---------------------------------------------------------------- ramps */
+
+struct ramp_def
+{
+ uint32_t lo, mid, hi; /* near-black, hue, light tint (0xRRGGBB) */
+ int mid_at; /* level of the hue, 0 = straight lo -> hi */
+ int n; /* palette entries */
+};
+
+/* 254 entries in all (index 0 and 255 stay Canon's) */
+static const struct ramp_def ramp_defs[RAMP_COUNT] =
+{
+ [RAMP_GRAY] = { 0x040303, 0, 0xFFFCF6, 0, 86 },
+ [RAMP_METAL] = { 0x050608, 0x878F98, 0xF4F7FA, 150, 22 },
+ [RAMP_AMBER] = { 0x080402, 0xF4A81C, 0xFFF2D2, 185, 24 },
+ [RAMP_RED] = { 0x080202, 0xDF262D, 0xFFD8D4, 150, 18 },
+ [RAMP_ORANGE] = { 0x080302, 0xEA5D1E, 0xFFDEC9, 160, 16 },
+ [RAMP_CRIMSON] = { 0x060102, 0x9C1320, 0xF6C4C8, 120, 16 },
+ [RAMP_GREEN] = { 0x020604, 0x13894B, 0xD0F5DF, 140, 18 },
+ [RAMP_VIOLET] = { 0x040208, 0x5A2D8A, 0xE9DCF7, 120, 16 },
+ [RAMP_BLUE] = { 0x020508, 0x1E77C6, 0xD5EBFF, 150, 16 },
+ [RAMP_LEADER] = { 0x050403, 0x4C3B2E, 0xDCCAB6, 130, 22 },
+};
+
+uint32_t fos_pal[256];
+
+uint8_t fos_ramp_base[RAMP_COUNT];
+uint8_t fos_ramp_last[RAMP_COUNT];
+int fos_ramp_mul[RAMP_COUNT];
+#define ramp_base fos_ramp_base
+#define ramp_mul fos_ramp_mul
+static uint8_t ramp_n[RAMP_COUNT];
+
+uint8_t fos_rev_ramp[256];
+uint16_t fos_rev_lv[256];
+uint8_t fos_luma_tab[256];
+uint8_t fos_chroma_tab[256];
+uint16_t fos_lum2lv[RAMP_COUNT][256];
+#define rev_ramp fos_rev_ramp
+#define rev_lv fos_rev_lv
+#define luma_tab fos_luma_tab
+#define chroma_tab fos_chroma_tab
+#define lum2lv fos_lum2lv
+
+const uint8_t fos_bayer[4][4] =
+{
+ { 0, 8, 2, 10 },
+ { 12, 4, 14, 6 },
+ { 3, 11, 1, 9 },
+ { 15, 7, 13, 5 },
+};
+
+static int chan(uint32_t c, int s) { return (c >> s) & 0xFF; }
+
+static uint32_t lerp_rgb(uint32_t a, uint32_t b, int t, int tmax)
+{
+ uint32_t out = 0;
+ for (int s = 0; s <= 16; s += 8)
+ {
+ int v = chan(a, s) + (chan(b, s) - chan(a, s)) * t / tmax;
+ out |= (uint32_t) fos_clamp(v, 0, 255) << s;
+ }
+ return out;
+}
+
+static int rgb_luma(uint32_t c)
+{
+ return (54 * chan(c, 16) + 183 * chan(c, 8) + 19 * chan(c, 0) + 128) >> 8;
+}
+
+static int rgb_chroma(uint32_t c)
+{
+ int r = chan(c, 16), g = chan(c, 8), b = chan(c, 0);
+ int mx = r > g ? (r > b ? r : b) : (g > b ? g : b);
+ int mn = r < g ? (r < b ? r : b) : (g < b ? g : b);
+ return mx - mn;
+}
+
+FOS_INLINE int ix_near(int ramp, int lv)
+{
+ int n = ramp_n[ramp];
+ int p = ((lv < 0 ? 0 : lv) * ramp_mul[ramp] + (8 << 16)) >> 20;
+ return ramp_base[ramp] + (p >= n ? n - 1 : p);
+}
+
+FOS_INLINE int ix_dith(int ramp, int lv, int x, int y)
+{
+ int n = ramp_n[ramp];
+ int p = (((lv < 0 ? 0 : lv) * ramp_mul[ramp] >> 16) + fos_bayer[y & 3][x & 3]) >> 4;
+ return ramp_base[ramp] + (p >= n ? n - 1 : p);
+}
+
+void fos_gfx_init()
+{
+ int ix = 1;
+ for (int r = 0; r < RAMP_COUNT; r++)
+ {
+ const struct ramp_def *d = &ramp_defs[r];
+ ramp_base[r] = ix;
+ ramp_n[r] = d->n;
+ fos_ramp_last[r] = d->n - 1;
+ ramp_mul[r] = (d->n - 1) * 16 * 65536 / LV_MAX;
+ for (int i = 0; i < d->n; i++, ix++)
+ {
+ int lv = i * 255 / (d->n - 1); /* 0..255 along the ramp */
+ uint32_t c;
+ if (!d->mid_at)
+ c = lerp_rgb(d->lo, d->hi, lv, 255);
+ else if (lv <= d->mid_at)
+ c = lerp_rgb(d->lo, d->mid, lv, d->mid_at);
+ else
+ c = lerp_rgb(d->mid, d->hi, lv - d->mid_at, 255 - d->mid_at);
+ fos_pal[ix] = c;
+ rev_ramp[ix] = r;
+ rev_lv[ix] = i * LV_MAX / (d->n - 1);
+ luma_tab[ix] = rgb_luma(c);
+ chroma_tab[ix] = rgb_chroma(c);
+ }
+ }
+
+ /* Canon's entries (and anything unused) read as black */
+ for (int i = ix; i < 256; i++)
+ rev_ramp[i] = RAMP_GRAY;
+ rev_ramp[0] = RAMP_GRAY;
+
+ /* luminance -> level, per ramp (ramps get lighter monotonically) */
+ for (int r = 0; r < RAMP_COUNT; r++)
+ {
+ int b = ramp_base[r], n = ramp_n[r];
+ int j = 0;
+ for (int l = 0; l < 256; l++)
+ {
+ while (j < n - 2 && luma_tab[b + j + 1] < l)
+ j++;
+ int l0 = luma_tab[b + j], l1 = luma_tab[b + j + 1];
+ int f = l1 > l0 ? fos_clamp((l - l0) * 256 / (l1 - l0), 0, 256) : 0;
+ int lv = (j * 256 + f) * LV_MAX / ((n - 1) * 256);
+ lum2lv[r][l] = fos_clamp(lv, 0, LV_MAX);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- screen colour */
+
+uint32_t fos_screen_yuv(int ix, int white_y, int std, int sat, int warm, int bright)
+{
+ return fos_screen_yuv_rgb(fos_pal[ix], white_y, std, sat, warm, bright);
+}
+
+uint32_t fos_screen_yuv_rgb(uint32_t rgb, int white_y, int std, int sat, int warm, int bright)
+{
+ int c[3] = { (rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF };
+ /* warmer: more red, less blue, white included */
+ c[0] = fos_clamp(c[0] * (100 + 3 * warm) / 100, 0, 255);
+ c[2] = fos_clamp(c[2] * (100 - 3 * warm) / 100, 0, 255);
+ /* brighter: the mid tones lift, black and white stay */
+ for (int i = 0; i < 3; i++)
+ c[i] = fos_clamp(c[i] + bright * 6 * c[i] * (255 - c[i]) / (100 * 255), 0, 255);
+ int r = c[0], g = c[1], b = c[2];
+ int s = 100 + 6 * sat; /* colour, % */
+ int y, u, v;
+ if (std == 1)
+ {
+ y = (217 * r + 732 * g + 73 * b) / 1024;
+ u = (-117 * r - 394 * g + 512 * b) / 1024;
+ v = (512 * r - 465 * g - 46 * b) / 1024;
+ }
+ else
+ {
+ /* BT.601 Y'CbCr, all of it scaled so white lands on Canon's white:
+ * Canon's own entries on the EOS M decode this way to clean
+ * primaries (dark red 202,0,0; blue 0,0,170; green 0,155,0) */
+ int yf = (299 * r + 587 * g + 114 * b) / 1000;
+ y = yf * white_y / 255;
+ u = (b - yf) * 564 / 1000 * white_y / 255;
+ v = (r - yf) * 713 / 1000 * white_y / 255;
+ }
+ y = fos_clamp(y, 0, 255);
+ u = fos_clamp(u * s / 100, -127, 127);
+ v = fos_clamp(v * s / 100, -127, 127);
+ return (uint32_t) y << 16 | (uint32_t) (u & 0xFF) << 8 | (uint32_t) (v & 0xFF);
+}
+
+uint32_t fos_screen_rgb(uint32_t yuv, int white_y)
+{
+ int y = (yuv >> 16) & 0xFF, u = (int8_t) ((yuv >> 8) & 0xFF), v = (int8_t) (yuv & 0xFF);
+ /* undo the scale, then BT.601 */
+ y = y * 255 / white_y; u = u * 255 / white_y; v = v * 255 / white_y;
+ int r = y + v * 1000 / 713;
+ int b = y + u * 1000 / 564;
+ int g = (1000 * y - 299 * r - 114 * b) / 587;
+ return (uint32_t) fos_clamp(r, 0, 255) << 16 | (uint32_t) fos_clamp(g, 0, 255) << 8 | (uint32_t) fos_clamp(b, 0, 255);
+}
+
+uint8_t fos_ix(fcol c)
+{
+ return ix_near(FC_RAMP(c) % RAMP_COUNT, LV12(FC_LEVEL(c)));
+}
+
+uint8_t fos_ix_dither(int ramp, int lv, int x, int y)
+{
+ return ix_dith(ramp, lv, x, y);
+}
+
+fcol fos_colour_of(uint8_t ix)
+{
+ return FC(rev_ramp[ix], rev_lv[ix] * 255 / LV_MAX);
+}
+
+int fos_luma(uint8_t ix)
+{
+ return luma_tab[ix];
+}
+
+/* the blend of (ramp, lv) over dst at opacity a: within one ramp it is a
+ * level blend; across ramps it keeps the luminance and takes the ramp that
+ * contributes more colour, so amber text on grey gets amber edges and
+ * white text on amber gets light-amber ones */
+static void mix_target(uint8_t dst, int ramp, int lv, int a, int *out_ramp, int *out_lv)
+{
+ int rd = rev_ramp[dst];
+ if (rd == ramp)
+ {
+ *out_ramp = ramp;
+ *out_lv = rev_lv[dst] + (((lv - rev_lv[dst]) * a) >> 8);
+ return;
+ }
+ int src = ix_near(ramp, lv);
+ int ld = luma_tab[dst], ls = luma_tab[src];
+ int l = ld + (((ls - ld) * a) >> 8);
+ int r = chroma_tab[src] * a >= chroma_tab[dst] * (256 - a) ? ramp : rd;
+ *out_ramp = r;
+ *out_lv = lum2lv[r][fos_clamp(l, 0, 255)];
+}
+
+void fos_lerp2(int ra, int la, int rb, int lb, int a, int *ramp, int *lv)
+{
+ if (ra == rb)
+ {
+ *ramp = ra;
+ *lv = la + (((lb - la) * a) >> 8);
+ return;
+ }
+ int ia = ix_near(ra, la), ib = ix_near(rb, lb);
+ int l = luma_tab[ia] + (((luma_tab[ib] - luma_tab[ia]) * a) >> 8);
+ int r = chroma_tab[ib] * a >= chroma_tab[ia] * (256 - a) ? rb : ra;
+ *ramp = r;
+ *lv = lum2lv[r][fos_clamp(l, 0, 255)];
+}
+
+uint8_t fos_mix(uint8_t dst, int ramp, int lv, int a)
+{
+ if (a >= OPAQUE) return ix_near(ramp, lv);
+ if (a <= 0) return dst;
+ int r, l;
+ mix_target(dst, ramp, lv, a, &r, &l);
+ return ix_near(r, l);
+}
+
+uint8_t fos_mix_dither(uint8_t dst, int ramp, int lv, int a, int x, int y)
+{
+ if (a >= OPAQUE) return ix_dith(ramp, lv, x, y);
+ if (a <= 0) return dst;
+ int r, l;
+ mix_target(dst, ramp, lv, a, &r, &l);
+ return ix_dith(r, l, x, y);
+}
+
+/* ---------------------------------------------------------------- maths */
+
+int fos_isqrt(unsigned int v)
+{
+ if (!v) return 0;
+ unsigned int r = 0, bit = 1u << ((31 - __builtin_clz(v)) & ~1);
+ while (bit)
+ {
+ if (v >= r + bit) { v -= r + bit; r = (r >> 1) + bit; }
+ else r >>= 1;
+ bit >>= 2;
+ }
+ return r;
+}
+
+/* quarter-wave sine, 4096 = 1.0 */
+static const int16_t sin_q[65] =
+{
+ 0, 101, 201, 301, 401, 501, 601, 700, 799, 897, 995, 1092, 1189, 1285, 1380, 1474,
+ 1567, 1660, 1751, 1842, 1931, 2019, 2106, 2191, 2276, 2359, 2440, 2520, 2598, 2675, 2751, 2824,
+ 2896, 2967, 3035, 3102, 3166, 3229, 3290, 3349, 3406, 3461, 3513, 3564, 3612, 3659, 3703, 3745,
+ 3784, 3822, 3857, 3889, 3920, 3948, 3973, 3996, 4017, 4036, 4052, 4065, 4076, 4085, 4091, 4095,
+ 4096,
+};
+
+int fos_sin(int a)
+{
+ a &= 0xFFFF;
+ int q = a >> 14; /* quadrant */
+ int t = a & 0x3FFF; /* 0..16383 within it */
+ if (q & 1) t = 0x4000 - t;
+ int i = t >> 8, f = t & 0xFF;
+ int v = i >= 64 ? 4096 : sin_q[i] + (((sin_q[i + 1] - sin_q[i]) * f) >> 8);
+ return q & 2 ? -v : v;
+}
+
+int fos_cos(int a)
+{
+ return fos_sin(a + 0x4000);
+}
+
+/* ---------------------------------------------------------------- canvas */
+
+void fos_canvas_init(struct fos_canvas *cv, uint8_t *px, int pitch, int w, int h)
+{
+ cv->px = px;
+ cv->pitch = pitch;
+ cv->w = w;
+ cv->h = h;
+ fos_noclip(cv);
+}
+
+void fos_noclip(struct fos_canvas *cv)
+{
+ cv->cx0 = 0; cv->cy0 = 0; cv->cx1 = cv->w; cv->cy1 = cv->h;
+}
+
+void fos_clip(struct fos_canvas *cv, int x0, int y0, int x1, int y1)
+{
+ cv->cx0 = fos_clamp(x0, 0, cv->w);
+ cv->cy0 = fos_clamp(y0, 0, cv->h);
+ cv->cx1 = fos_clamp(x1, cv->cx0, cv->w);
+ cv->cy1 = fos_clamp(y1, cv->cy0, cv->h);
+}
+
+/* clip a rectangle; returns 0 if nothing is left */
+static int clip_rect(const struct fos_canvas *cv, int *x, int *y, int *w, int *h)
+{
+ int x0 = *x, y0 = *y, x1 = *x + *w, y1 = *y + *h;
+ if (x0 < cv->cx0) x0 = cv->cx0;
+ if (y0 < cv->cy0) y0 = cv->cy0;
+ if (x1 > cv->cx1) x1 = cv->cx1;
+ if (y1 > cv->cy1) y1 = cv->cy1;
+ if (x1 <= x0 || y1 <= y0) return 0;
+ *x = x0; *y = y0; *w = x1 - x0; *h = y1 - y0;
+ return 1;
+}
+
+#define PX(cv, x, y) ((cv)->px[(y) * (cv)->pitch + (x)])
+
+void fos_fill_ix(struct fos_canvas *cv, int x, int y, int w, int h, uint8_t ix)
+{
+ if (!clip_rect(cv, &x, &y, &w, &h)) return;
+ uint32_t word = ix * 0x01010101u;
+ for (int j = 0; j < h; j++)
+ {
+ uint8_t *p = &PX(cv, x, y + j);
+ int n = w;
+ while (n && ((uintptr_t) p & 3)) { *p++ = ix; n--; }
+ while (n >= 4) { *(uint32_t *) p = word; p += 4; n -= 4; }
+ while (n--) *p++ = ix;
+ }
+}
+
+void fos_fill(struct fos_canvas *cv, int x, int y, int w, int h, fcol c)
+{
+ fos_fill_ix(cv, x, y, w, h, fos_ix(c));
+}
+
+void fos_blend(struct fos_canvas *cv, int x, int y, int w, int h, fcol c, int alpha)
+{
+ if (alpha >= OPAQUE) { fos_fill(cv, x, y, w, h, c); return; }
+ if (alpha <= 0 || !clip_rect(cv, &x, &y, &w, &h)) return;
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ for (int j = y; j < y + h; j++)
+ for (int i = x; i < x + w; i++)
+ PX(cv, i, j) = fos_mix_dither(PX(cv, i, j), ramp, lv, alpha, i, j);
+}
+
+void fos_scale_levels(struct fos_canvas *cv, int x, int y, int w, int h, int k)
+{
+ if (!clip_rect(cv, &x, &y, &w, &h)) return;
+ /* every index, darkened, for the four pixels of a 2 x 2 dither */
+ uint8_t lut[4][256];
+ for (int ph = 0; ph < 4; ph++)
+ for (int i = 0; i < 256; i++)
+ lut[ph][i] = ix_dith(rev_ramp[i], (rev_lv[i] * k) >> 8, ph & 1, ph >> 1);
+ for (int j = y; j < y + h; j++)
+ {
+ uint8_t *p = &PX(cv, x, j);
+ int n = w, i = x;
+ for (; n && ((uintptr_t) p & 3); n--, p++, i++)
+ *p = lut[(j & 1) * 2 + (i & 1)][*p];
+ const uint8_t *l0 = lut[(j & 1) * 2 + (i & 1)], *l1 = lut[(j & 1) * 2 + ((i + 1) & 1)];
+ for (; n >= 4; n -= 4, p += 4, i += 4)
+ {
+ uint32_t v = *(uint32_t *) p;
+ *(uint32_t *) p = l0[v & 0xFF] | l1[(v >> 8) & 0xFF] << 8 | l0[(v >> 16) & 0xFF] << 16 | (uint32_t) l1[v >> 24] << 24;
+ }
+ for (; n; n--, p++, i++)
+ *p = lut[(j & 1) * 2 + (i & 1)][*p];
+ }
+}
+
+void fos_vgrad(struct fos_canvas *cv, int x, int y, int w, int h, int ramp, int lv0, int lv1)
+{
+ int y_top = y, h_all = h;
+ if (h_all <= 0 || !clip_rect(cv, &x, &y, &w, &h)) return;
+ int base = ramp_base[ramp], last = ramp_n[ramp] - 1;
+ for (int j = y; j < y + h; j++)
+ {
+ int lv = lv0 + (lv1 - lv0) * (j - y_top) / (h_all > 1 ? h_all - 1 : 1);
+ int pos = ((lv < 0 ? 0 : lv) * ramp_mul[ramp]) >> 16;
+ /* the four dithered indices of this row */
+ uint8_t ix[4];
+ for (int k = 0; k < 4; k++)
+ {
+ int q = (pos + fos_bayer[j & 3][k]) >> 4;
+ ix[k] = base + (q > last ? last : q);
+ }
+ uint8_t *p = &PX(cv, x, j);
+ for (int i = x; i < x + w; i++)
+ *p++ = ix[i & 3];
+ }
+}
+
+/* ---------------------------------------------------------------- AA shapes */
+
+FOS_INLINE void put_cov(struct fos_canvas *cv, int x, int y, int ramp, int lv, int ix_solid, int cov, int alpha)
+{
+ if (cov <= 0) return;
+ int a = cov >= 256 ? alpha : (cov * alpha) >> 8;
+ if (a >= OPAQUE) PX(cv, x, y) = ix_solid;
+ else if (a > 0) PX(cv, x, y) = fos_mix(PX(cv, x, y), ramp, lv, a);
+}
+
+/* pixels x0..x1-1 of row y fully covered */
+static void put_run(struct fos_canvas *cv, int x0, int x1, int y, int ramp, int lv, int ix_solid, int alpha)
+{
+ if (x1 <= x0) return;
+ uint8_t *p = &PX(cv, x0, y);
+ if (alpha >= OPAQUE) { memset(p, ix_solid, x1 - x0); return; }
+ if (alpha <= 0) return;
+ for (int x = x0; x < x1; x++, p++)
+ *p = fos_mix(*p, ramp, lv, alpha);
+}
+
+/* coverage (0..256) of pixel (i, j) in a w x h rounded rect at the origin */
+static int rrect_cov(int i, int j, int w, int h, int r)
+{
+ if (i < 0 || j < 0 || i >= w || j >= h) return 0;
+ int cx, cy;
+ if (i < r) cx = r; else if (i >= w - r) cx = w - r; else return 256;
+ if (j < r) cy = r; else if (j >= h - r) cy = h - r; else return 256;
+ /* distance from the pixel centre to the corner circle centre, 1/16 px */
+ int dx = (i * 16 + 8) - cx * 16;
+ int dy = (j * 16 + 8) - cy * 16;
+ if ((i < r && dx > 0) || (i >= w - r && dx < 0)) dx = 0;
+ if ((j < r && dy > 0) || (j >= h - r && dy < 0)) dy = 0;
+ int d = fos_isqrt(dx * dx + dy * dy) - r * 16; /* 1/16 px, + outside */
+ return fos_clamp(128 - d * 16, 0, 256);
+}
+
+void fos_rrect(struct fos_canvas *cv, int x, int y, int w, int h, int r, fcol c, int alpha)
+{
+ if (w <= 0 || h <= 0) return;
+ r = fos_clamp(r, 0, (w < h ? w : h) / 2);
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+ /* straight middle band in one go */
+ if (alpha >= OPAQUE)
+ fos_fill_ix(cv, x, y + r, w, h - 2 * r, solid);
+ else
+ fos_blend(cv, x, y + r, w, h - 2 * r, c, alpha);
+ for (int j = 0; j < h; j++)
+ {
+ if (j >= r && j < h - r) continue;
+ int py = y + j;
+ if (py < cv->cy0 || py >= cv->cy1) continue;
+ /* the corners, then the straight part between them in one run */
+ for (int i = 0; i < w; i++)
+ {
+ if (i == r && w - r > r)
+ {
+ put_run(cv, fos_clamp(x + r, cv->cx0, cv->cx1), fos_clamp(x + w - r, cv->cx0, cv->cx1),
+ py, ramp, lv, solid, alpha);
+ i = w - r - 1;
+ continue;
+ }
+ int px = x + i;
+ if (px < cv->cx0 || px >= cv->cx1) continue;
+ put_cov(cv, px, py, ramp, lv, solid, rrect_cov(i, j, w, h, r), alpha);
+ }
+ }
+}
+
+void fos_rrect_line(struct fos_canvas *cv, int x, int y, int w, int h, int r, int t, fcol c, int alpha)
+{
+ if (w <= 0 || h <= 0 || t <= 0) return;
+ r = fos_clamp(r, 0, (w < h ? w : h) / 2);
+ int ri = r > t ? r - t : 0;
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+ for (int j = 0; j < h; j++)
+ {
+ int py = y + j;
+ if (py < cv->cy0 || py >= cv->cy1) continue;
+ int inner_row = j >= t + ri && j < h - t - ri;
+ int border_row = j < t || j >= h - t; /* straight top / bottom edge */
+ int cut = r > t ? r : t;
+ for (int i = 0; i < w; i++)
+ {
+ if (inner_row && i >= t && i < w - t) { i = w - t - 1; continue; }
+ if (!inner_row && i == cut && w - cut > cut)
+ {
+ /* between the corners the border is solid or empty */
+ if (border_row)
+ put_run(cv, fos_clamp(x + cut, cv->cx0, cv->cx1), fos_clamp(x + w - cut, cv->cx0, cv->cx1),
+ py, ramp, lv, solid, alpha);
+ i = w - cut - 1;
+ continue;
+ }
+ int px = x + i;
+ if (px < cv->cx0 || px >= cv->cx1) continue;
+ int cov = rrect_cov(i, j, w, h, r) - rrect_cov(i - t, j - t, w - 2 * t, h - 2 * t, ri);
+ put_cov(cv, px, py, ramp, lv, solid, cov, alpha);
+ }
+ }
+}
+
+/* distance (1/16 px, + outside) of a pixel at squared distance d2 (1/16 px)
+ * from a circle of radius r16: near the edge of a big circle the square
+ * root is as good as linear, d = (d2 - r^2) / 2r */
+FOS_INLINE int circle_d(int d2, int r16, int inv2r)
+{
+ if (inv2r) return ((d2 - r16 * r16) * inv2r) >> 16;
+ return fos_isqrt((unsigned) d2) - r16;
+}
+
+/* inv2r for circle_d, or 0 when the circle is too small to approximate */
+static int circle_inv(int r16)
+{
+ return r16 >= 16 * 12 ? 65536 / (2 * r16) : 0;
+}
+
+void fos_disc(struct fos_canvas *cv, int cx8, int cy8, int r8, fcol c, int alpha)
+{
+ if (r8 <= 0) return;
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+ int r16 = r8 >> 4, inv2r = circle_inv(r16);
+ int y0 = (cy8 - r8) >> 8, y1 = (cy8 + r8 + 255) >> 8;
+ int x0 = (cx8 - r8) >> 8, x1 = (cx8 + r8 + 255) >> 8;
+ y0 = fos_clamp(y0, cv->cy0, cv->cy1); y1 = fos_clamp(y1, cv->cy0, cv->cy1);
+ x0 = fos_clamp(x0, cv->cx0, cv->cx1); x1 = fos_clamp(x1, cv->cx0, cv->cx1);
+ for (int y = y0; y < y1; y++)
+ {
+ int dy = ((y * 256 + 128) - cy8) >> 4;
+ int cx16 = cx8 >> 4;
+ /* pixels whose centre is half a pixel inside the edge are solid */
+ int in = r16 - 8;
+ int half = in > 0 && in * in > dy * dy ? fos_isqrt(in * in - dy * dy) : -1;
+ int sx0 = half >= 0 ? (cx16 - half - 8 + 15) >> 4 : x1;
+ int sx1 = half >= 0 ? (cx16 + half - 8) >> 4 : x0 - 1;
+ int s0 = fos_clamp(sx0, x0, x1), s1 = fos_clamp(sx1 + 1, s0, x1);
+ /* nothing beyond half a pixel outside the edge */
+ int out = r16 + 8;
+ if (out * out <= dy * dy) continue;
+ int ohalf = fos_isqrt(out * out - dy * dy);
+ int xa = fos_clamp(((cx16 - ohalf - 8) >> 4) - 1, x0, x1), xb = fos_clamp(((cx16 + ohalf - 8) >> 4) + 2, xa, x1);
+ for (int x = xa; x < xb; x++)
+ {
+ if (x == s0 && s1 > s0)
+ {
+ put_run(cv, s0, s1, y, ramp, lv, solid, alpha);
+ x = s1 - 1;
+ continue;
+ }
+ int dx = ((x * 256 + 128) - cx8) >> 4;
+ int d = circle_d(dx * dx + dy * dy, r16, inv2r);
+ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - d * 16, 0, 256), alpha);
+ }
+ }
+}
+
+void fos_ring(struct fos_canvas *cv, int cx8, int cy8, int r8, int t8, fcol c, int alpha)
+{
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+ int ro = r8 + t8 / 2 + 256;
+ int y0 = fos_clamp((cy8 - ro) >> 8, cv->cy0, cv->cy1), y1 = fos_clamp((cy8 + ro + 255) >> 8, cv->cy0, cv->cy1);
+ int x0 = fos_clamp((cx8 - ro) >> 8, cv->cx0, cv->cx1), x1 = fos_clamp((cx8 + ro + 255) >> 8, cv->cx0, cv->cx1);
+ int r16 = r8 >> 4, h16 = t8 >> 5, inv2r = circle_inv(r16);
+ int inner = r16 - h16 - 16, outer = r16 + h16 + 16; /* nothing inside / beyond these */
+ for (int y = y0; y < y1; y++)
+ {
+ int dy = ((y * 256 + 128) - cy8) >> 4;
+ if (dy * dy >= outer * outer) continue;
+ int ox = fos_isqrt(outer * outer - dy * dy);
+ int ix = inner > 0 && dy * dy < inner * inner ? fos_isqrt(inner * inner - dy * dy) : -1;
+ int xa = fos_clamp(((cx8 - ox * 16) >> 8) - 1, x0, x1), xb = fos_clamp(((cx8 + ox * 16) >> 8) + 2, x0, x1);
+ for (int x = xa; x < xb; x++)
+ {
+ int dx = ((x * 256 + 128) - cx8) >> 4;
+ if (ix > 0 && dx > -ix && dx < ix)
+ {
+ /* across the hole */
+ x = fos_clamp(((cx8 + ix * 16 - 128 + 255) >> 8) - 1, x, xb);
+ continue;
+ }
+ int d = circle_d(dx * dx + dy * dy, r16, inv2r);
+ if (d < 0) d = -d;
+ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - (d - h16) * 16, 0, 256), alpha);
+ }
+ }
+}
+
+void fos_line(struct fos_canvas *cv, int x0_8, int y0_8, int x1_8, int y1_8, int w8, fcol c, int alpha)
+{
+ /* a thin quad: the segment pushed out by half the width both ways */
+ int dx = (x1_8 - x0_8) >> 4, dy = (y1_8 - y0_8) >> 4;
+ int len = fos_isqrt((unsigned) (dx * dx + dy * dy));
+ if (!len) return;
+ int ox = -dy * (w8 / 2) / len, oy = dx * (w8 / 2) / len;
+ int q[8] = { x0_8 + ox, y0_8 + oy, x1_8 + ox, y1_8 + oy, x1_8 - ox, y1_8 - oy, x0_8 - ox, y0_8 - oy };
+ fos_convex(cv, q, 4, c, alpha);
+}
+
+/* convex polygon, vertices in 1/256 px, either winding */
+#define MAX_POLY 12
+void fos_convex(struct fos_canvas *cv, const int *xy8, int n, fcol c, int alpha)
+{
+ if (n < 3 || n > MAX_POLY) return;
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+
+ /* signed area tells the winding, so normals can point outwards */
+ int64_t area = 0;
+ for (int i = 0; i < n; i++)
+ {
+ int j = (i + 1) % n;
+ area += (int64_t) xy8[2 * i] * xy8[2 * j + 1] - (int64_t) xy8[2 * j] * xy8[2 * i + 1];
+ }
+ int sgn = area > 0 ? 1 : -1;
+
+ /* edge lines: nx * x + ny * y - c, unit normal in 1/4096, distance in 1/256 px;
+ * inv = 2^24 / nx turns "where does this edge cross" into a multiply */
+ int nx[MAX_POLY], ny[MAX_POLY], nc[MAX_POLY], inv[MAX_POLY];
+ int ymin = 1 << 30, ymax = -(1 << 30), xmin = 1 << 30, xmax = -(1 << 30);
+ for (int i = 0; i < n; i++)
+ {
+ int j = (i + 1) % n;
+ int ex = xy8[2 * j] - xy8[2 * i], ey = xy8[2 * j + 1] - xy8[2 * i + 1];
+ /* length in 1/16 px; long edges (the shutter blades) measured coarser so
+ * the squares fit */
+ int sh = ((ex < 0 ? -ex : ex) | (ey < 0 ? -ey : ey)) >= (1 << 19) ? 7 : 4;
+ int len = fos_isqrt((unsigned) ((ex >> sh) * (ex >> sh) + (ey >> sh) * (ey >> sh))) << (sh - 4);
+ if (!len) len = 1;
+ nx[i] = sgn * (ey >> 4) * 4096 / len;
+ ny[i] = -sgn * (ex >> 4) * 4096 / len;
+ nc[i] = (int) (((int64_t) nx[i] * xy8[2 * i] + (int64_t) ny[i] * xy8[2 * i + 1]) >> 12);
+ inv[i] = nx[i] ? (1 << 24) / nx[i] : 0;
+ if (xy8[2 * i + 1] < ymin) ymin = xy8[2 * i + 1];
+ if (xy8[2 * i + 1] > ymax) ymax = xy8[2 * i + 1];
+ if (xy8[2 * i] < xmin) xmin = xy8[2 * i];
+ if (xy8[2 * i] > xmax) xmax = xy8[2 * i];
+ }
+ int py0 = fos_clamp((ymin >> 8) - 1, cv->cy0, cv->cy1), py1 = fos_clamp((ymax >> 8) + 2, cv->cy0, cv->cy1);
+ int px0 = fos_clamp((xmin >> 8) - 1, cv->cx0, cv->cx1), px1 = fos_clamp((xmax >> 8) + 2, cv->cx0, cv->cx1);
+
+ for (int y = py0; y < py1; y++)
+ {
+ int yc = y * 256 + 128;
+ /* [in0, in1]: every edge at least half a pixel inside (solid);
+ * [out0, out1]: no edge more than half a pixel outside */
+ int in0 = px0 * 256, in1 = px1 * 256, out0 = px0 * 256, out1 = px1 * 256;
+ int empty = 0, nosolid = 0;
+ for (int i = 0; i < n; i++)
+ {
+ /* d(x) = nx * x / 4096 + base (1/256 px) */
+ int base = (int) (((int64_t) ny[i] * yc) >> 12) - nc[i];
+ if (!nx[i])
+ {
+ if (base > 128) empty = 1;
+ if (base > -128) nosolid = 1;
+ continue;
+ }
+ int xa = (int) (((int64_t) (-128 - base) * inv[i]) >> 12);
+ int xb = (int) (((int64_t) (128 - base) * inv[i]) >> 12);
+ if (nx[i] > 0) { if (xa < in1) in1 = xa; if (xb < out1) out1 = xb; }
+ else { if (xa > in0) in0 = xa; if (xb > out0) out0 = xb; }
+ }
+ if (empty || out1 < out0) continue;
+ if (nosolid) in1 = in0 - 1;
+ int sx0 = fos_clamp((out0 >> 8) - 1, px0, px1), sx1 = fos_clamp((out1 >> 8) + 2, px0, px1);
+ /* whole pixels at least half a pixel inside every edge: one run */
+ int s0 = sx1, s1 = sx1;
+ if (in1 > in0)
+ {
+ s0 = fos_clamp((in0 + 255) >> 8, sx0, sx1);
+ s1 = fos_clamp(in1 >> 8, s0, sx1);
+ }
+ for (int x = sx0; x < sx1; x++)
+ {
+ int xc = x * 256 + 128;
+ if (x == s0 && s1 > s0)
+ {
+ put_run(cv, s0, s1, y, ramp, lv, solid, alpha);
+ x = s1 - 1;
+ continue;
+ }
+ /* pixel centres are on the canvas, so this fits in 32 bits */
+ int dmax = -(1 << 30);
+ for (int i = 0; i < n; i++)
+ {
+ int d = ((nx[i] * xc + ny[i] * yc) >> 12) - nc[i];
+ if (d > dmax) dmax = d;
+ }
+ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - dmax, 0, 256), alpha);
+ }
+ }
+}
+
+void fos_tri(struct fos_canvas *cv, int cx, int cy, int size, int dir, fcol c, int alpha)
+{
+ /* an arrow head pointing right, rotated by dir quarter turns */
+ static const int base[6] = { 1, 0, -1, -1, -1, 1 };
+ int pts[6];
+ for (int i = 0; i < 3; i++)
+ {
+ int x = base[2 * i], y = base[2 * i + 1];
+ for (int k = 0; k < dir; k++) { int t = x; x = -y; y = t; }
+ pts[2 * i] = cx * 256 + 128 + x * size * 128;
+ pts[2 * i + 1] = cy * 256 + 128 + y * size * 128;
+ }
+ fos_convex(cv, pts, 3, c, alpha);
+}
+
+/* ---------------------------------------------------------------- text */
+
+/* ---- the fonts, from the card */
+
+#define FONT_DEF(n) struct fos_font fos_font_##n;
+FOS_FONTS(FONT_DEF)
+#define FONT_SLOT(n) &fos_font_##n,
+static struct fos_font *const font_slots[] = { FOS_FONTS(FONT_SLOT) };
+#define NFONTS ((int) (sizeof(font_slots) / sizeof(font_slots[0])))
+static int fonts_ready;
+
+static uint32_t get32(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (uint32_t) p[3] << 24; }
+
+/* "FOSF", version 1, the number of fonts; each font: bits, glyphs, kerning
+ * pairs, ascent, descent (u32), then its bits, glyphs, lut and kerning,
+ * each part starting on 4 bytes */
+int fos_fonts_load(const uint8_t *b, int size)
+{
+ fonts_ready = 0;
+ if (!b || size < 12 || memcmp(b, "FOSF", 4) || get32(b + 4) != 1 || (int) get32(b + 8) != NFONTS
+ || sizeof(struct fos_glyph) != 8 || sizeof(struct fos_kern) != 3)
+ return 0;
+ int at = 12;
+ for (int i = 0; i < NFONTS; i++)
+ {
+ if (at + 20 > size) return 0;
+ uint32_t nbits = get32(b + at), nglyphs = get32(b + at + 4), nkern = get32(b + at + 8);
+ int asc = (int) get32(b + at + 12), desc = (int) get32(b + at + 16);
+ at += 20;
+ uint32_t need = ((nbits + 3) & ~3u) + nglyphs * 8 + 256 + ((nkern * 3 + 3) & ~3u);
+ if (nbits > (uint32_t) size || nglyphs > 256 || nkern > 65536 || (uint32_t) (size - at) < need) return 0;
+ struct fos_font *f = font_slots[i];
+ f->bits = b + at; at += (nbits + 3) & ~3u;
+ f->glyphs = (const struct fos_glyph *) (b + at); at += nglyphs * 8;
+ f->lut = b + at; at += 256;
+ f->kern = nkern ? (const struct fos_kern *) (b + at) : 0;
+ at += (nkern * 3 + 3) & ~3u;
+ f->nkern = (int) nkern;
+ f->ascent = asc;
+ f->descent = desc;
+ /* every glyph the lut names must exist */
+ for (int c = 0; c < 256; c++)
+ if (f->lut[c] != 0xFF && f->lut[c] >= nglyphs) { memset(f, 0, sizeof(*f)); return 0; }
+ }
+ fonts_ready = 1;
+ return 1;
+}
+
+int fos_fonts_ready()
+{
+ return fonts_ready;
+}
+
+static const struct fos_glyph *glyph_of(const struct fos_font *f, int ch)
+{
+ if (!f->lut) return 0; /* not loaded */
+ int i = f->lut[ch & 0xFF];
+ return i == 0xFF ? 0 : &f->glyphs[i];
+}
+
+static int kern_of(const struct fos_font *f, int a, int b)
+{
+ int lo = 0, hi = f->nkern - 1;
+ int key = a << 8 | b;
+ while (lo <= hi)
+ {
+ int mid = (lo + hi) / 2;
+ int k = f->kern[mid].a << 8 | f->kern[mid].b;
+ if (k == key) return f->kern[mid].k;
+ if (k < key) lo = mid + 1; else hi = mid - 1;
+ }
+ return 0;
+}
+
+static void draw_glyph(struct fos_canvas *cv, const struct fos_font *f, const struct fos_glyph *g,
+ int x, int y, int ramp, int lv, int solid, int alpha)
+{
+ int gx = x + g->ox, gy = y + g->oy;
+ int w = g->w, h = g->h;
+ if (!w || !h) return;
+ if (gx >= cv->cx1 || gy >= cv->cy1 || gx + w <= cv->cx0 || gy + h <= cv->cy0) return;
+
+ const uint8_t *p = f->bits + g->off;
+ int col = 0, row = 0;
+ int inside = gx >= cv->cx0 && gx + w <= cv->cx1 && gy >= cv->cy0 && gy + h <= cv->cy1;
+ int memo_dst = -1, memo_a = -1, memo_out = 0;
+ while (row < h)
+ {
+ int b = *p++;
+ int run, v;
+ if (b & 0x80) { run = (b & 0x7F) + 1; v = 0; }
+ else { run = (b >> 4) + 1; v = b & 15; }
+ if (!v)
+ {
+ col += run;
+ while (col >= w) { col -= w; row++; }
+ continue;
+ }
+ int a = v == 15 ? alpha : (v * 17 * alpha) >> 8;
+ if (inside)
+ {
+ /* runs never pass the end of the bitmap, but may wrap rows */
+ uint8_t *q = &PX(cv, gx + col, gy + row);
+ if (a >= OPAQUE)
+ while (run--)
+ {
+ *q++ = solid;
+ if (++col == w) { col = 0; row++; q = &PX(cv, gx, gy + row); }
+ }
+ else
+ while (run--)
+ {
+ /* the backdrop is a couple of dithered indices: remember the last blend */
+ if (*q != memo_dst || a != memo_a)
+ {
+ memo_dst = *q; memo_a = a;
+ memo_out = fos_mix(*q, ramp, lv, a);
+ }
+ *q++ = memo_out;
+ if (++col == w) { col = 0; row++; q = &PX(cv, gx, gy + row); }
+ }
+ continue;
+ }
+ while (run--)
+ {
+ int px = gx + col, py = gy + row;
+ if (px >= cv->cx0 && px < cv->cx1 && py >= cv->cy0 && py < cv->cy1)
+ {
+ if (a >= OPAQUE) PX(cv, px, py) = solid;
+ else PX(cv, px, py) = fos_mix(PX(cv, px, py), ramp, lv, a);
+ }
+ if (++col == w) { col = 0; row++; }
+ }
+ }
+}
+
+int fos_text_w(const struct fos_font *f, const char *s, int track)
+{
+ int pen = 0, prev = 0;
+ for (; *s; s++)
+ {
+ int ch = (uint8_t) *s;
+ const struct fos_glyph *g = glyph_of(f, ch);
+ if (!g) continue;
+ if (prev) pen += kern_of(f, prev, ch) + track;
+ pen += g->adv;
+ prev = ch;
+ }
+ return (pen + 8) >> 4;
+}
+
+int fos_text(struct fos_canvas *cv, const struct fos_font *f, int x, int y, const char *s, fcol c, int alpha, int track)
+{
+ if (alpha <= 0) return fos_text_w(f, s, track);
+ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
+ int solid = fos_ix(c);
+ int pen = x * 16, prev = 0;
+ for (; *s; s++)
+ {
+ int ch = (uint8_t) *s;
+ const struct fos_glyph *g = glyph_of(f, ch);
+ if (!g) continue;
+ if (prev) pen += kern_of(f, prev, ch) + track;
+ draw_glyph(cv, f, g, (pen + 8) >> 4, y, ramp, lv, solid, alpha);
+ pen += g->adv;
+ prev = ch;
+ }
+ return ((pen + 8) >> 4) - x;
+}
+
+int fos_text_c(struct fos_canvas *cv, const struct fos_font *f, int cx, int y, const char *s, fcol c, int alpha, int track)
+{
+ int w = fos_text_w(f, s, track);
+ fos_text(cv, f, cx - w / 2, y, s, c, alpha, track);
+ return w;
+}
+
+int fos_text_r(struct fos_canvas *cv, const struct fos_font *f, int rx, int y, const char *s, fcol c, int alpha, int track)
+{
+ int w = fos_text_w(f, s, track);
+ fos_text(cv, f, rx - w, y, s, c, alpha, track);
+ return w;
+}
+
+int fos_text_map(uint8_t *px, int pitch, int w, int h, const struct fos_font *f, int x, int y,
+ const char *s, const uint8_t map[16], int track)
+{
+ int pen = x * 16, prev = 0;
+ for (; *s; s++)
+ {
+ int ch = (uint8_t) *s;
+ const struct fos_glyph *g = glyph_of(f, ch);
+ if (!g) continue;
+ if (prev) pen += kern_of(f, prev, ch) + track;
+ int gx = ((pen + 8) >> 4) + g->ox, gy = y + g->oy;
+ const uint8_t *p = f->bits + g->off;
+ int col = 0, row = 0;
+ while (row < g->h)
+ {
+ int b = *p++;
+ int run, v;
+ if (b & 0x80) { run = (b & 0x7F) + 1; v = 0; }
+ else { run = (b >> 4) + 1; v = b & 15; }
+ while (run--)
+ {
+ int qx = gx + col, qy = gy + row;
+ if (v && map[v] && qx >= 0 && qx < w && qy >= 0 && qy < h)
+ px[qy * pitch + qx] = map[v];
+ if (++col == g->w) { col = 0; row++; }
+ }
+ }
+ pen += g->adv;
+ prev = ch;
+ }
+ return ((pen + 8) >> 4) - x;
+}
diff --git a/ml-dev/filmos/fos_gfx.h b/ml-dev/filmos/fos_gfx.h
new file mode 100644
index 0000000..22d1f64
--- /dev/null
+++ b/ml-dev/filmos/fos_gfx.h
@@ -0,0 +1,216 @@
+/* fos_gfx: drawing for the film OS.
+ *
+ * The screen is the EOS M 8-bit bitmap overlay. Our palette is a set of
+ * tone ramps, each running from near-black through a hue to a light tint,
+ * so every colour is "a ramp and a level along it". Shading, gradients,
+ * fades and anti-aliasing all become level changes, and ordered dithering
+ * between neighbouring ramp entries keeps them smooth with 254 colours.
+ *
+ * Plain C, no ML headers: the same code runs on the camera and in the
+ * simulator (sim/).
+ */
+
+#ifndef _fos_gfx_h_
+#define _fos_gfx_h_
+
+#include <stdint.h>
+
+/* the camera build warns (and fails) when gcc declines an inline at -Os,
+ * so the few hot helpers are forced */
+#define FOS_INLINE static inline __attribute__((always_inline))
+
+#define FOS_W 720
+#define FOS_H 480
+
+enum
+{
+ RAMP_GRAY, /* warm neutral, also black and white ink */
+ RAMP_METAL, /* cool steel for canister caps */
+ RAMP_AMBER, /* UI accent and Kodak yellow */
+ RAMP_RED,
+ RAMP_ORANGE,
+ RAMP_CRIMSON,
+ RAMP_GREEN,
+ RAMP_VIOLET,
+ RAMP_BLUE,
+ RAMP_LEADER, /* unprocessed film base */
+ RAMP_COUNT
+};
+
+/* a colour: ramp in the high byte, level 0..255 in the low byte */
+typedef uint16_t fcol;
+#define FC(ramp, level) ((fcol) (((ramp) << 8) | (level)))
+#define FC_RAMP(c) ((c) >> 8)
+#define FC_LEVEL(c) ((c) & 0xFF)
+
+/* shading works with 12-bit levels */
+#define LV_MAX 4095
+#define LV12(level8) ((level8) * 4095 / 255)
+
+/* opacity 0..256 */
+#define OPAQUE 256
+
+/* palette index 0 is Canon's transparent entry: LiveView shows through */
+#define IX_CLEAR 0
+
+struct fos_canvas
+{
+ uint8_t *px;
+ int pitch;
+ int w, h;
+ int cx0, cy0, cx1, cy1; /* clip rectangle, cx1 / cy1 exclusive */
+};
+
+struct fos_glyph { uint16_t off; uint8_t w, h; int8_t ox, oy; uint16_t adv; };
+struct fos_kern { uint8_t a, b; int8_t k; };
+
+struct fos_font
+{
+ const uint8_t *bits; /* run-length coded 4-bit coverage */
+ const struct fos_glyph *glyphs;
+ const uint8_t *lut; /* byte -> glyph, 0xFF = none */
+ const struct fos_kern *kern; /* sorted by (a, b), 1/16 px */
+ int nkern;
+ int ascent, descent;
+};
+
+/* The fonts live in a file on the card (ML/DATA/FOSFONT.BIN, made from
+ * fos_font.c by tools/fontblob.c), not in autoexec.bin: on the EOS M every
+ * byte of autoexec.bin is taken from Canon's own memory at boot, and too
+ * much stops the camera from starting. Until fos_fonts_load succeeds,
+ * text draws nothing. */
+extern struct fos_font fos_font_xs, fos_font_sm, fos_font_md, fos_font_mdb,
+ fos_font_lg, fos_font_xl, fos_font_num,
+ fos_font_lbig, fos_font_lname, fos_font_lsm;
+#define FOS_FONT_FILE "FOSFONT.BIN"
+#define FOS_FONTS(X) X(xs) X(sm) X(md) X(mdb) X(lg) X(xl) X(num) X(lbig) X(lname) X(lsm) /* the file's order */
+/* blob: the file's contents, kept for as long as the fonts are used;
+ * 1 when it holds every font */
+int fos_fonts_load(const uint8_t *blob, int size);
+int fos_fonts_ready();
+
+/* characters beyond ASCII in our strings (see tools/mkfont.py) */
+#define T_DOT "\x80" /* middle dot */
+#define T_DEG "\x81"
+#define T_TIMES "\x82"
+#define T_NDASH "\x83"
+#define T_MDASH "\x84"
+#define T_APOS "\x85"
+#define T_ELLIPSIS "\x86"
+#define T_BULLET "\x87"
+#define T_LSAQUO "\x88" /* single angle quotes */
+#define T_RSAQUO "\x89"
+
+/* 0x00RRGGBB for each palette index we own (1..254) */
+extern uint32_t fos_pal[256];
+
+/* What the overlay gets for palette index ix: Y << 16 | U << 8 | V, U and
+ * V signed bytes. std 0 is Canon's own conversion (BT.601 Y'CbCr, scaled
+ * so white sits at white_y, the luma of Canon's white: 235 on the EOS M);
+ * std 1 is full-range Rec.709. sat, warm and bright are the screen colour
+ * settings, -6..6, 0 = as designed. */
+uint32_t fos_screen_yuv(int ix, int white_y, int std, int sat, int warm, int bright);
+uint32_t fos_screen_yuv_rgb(uint32_t rgb, int white_y, int std, int sat, int warm, int bright); /* any 0xRRGGBB */
+
+/* back to 0xRRGGBB, as a screen decoding Canon's way would show it */
+uint32_t fos_screen_rgb(uint32_t yuv, int white_y);
+
+void fos_gfx_init();
+
+/* palette index of a flat colour */
+uint8_t fos_ix(fcol c);
+
+/* palette index for a 12-bit level, dithered for pixel (x, y) */
+uint8_t fos_ix_dither(int ramp, int lv, int x, int y);
+
+/* the same, inline, for inner loops */
+extern uint8_t fos_ramp_base[RAMP_COUNT];
+extern uint8_t fos_ramp_last[RAMP_COUNT]; /* entries - 1 */
+extern int fos_ramp_mul[RAMP_COUNT]; /* lv * mul >> 16 = position in 1/16 entries */
+extern const uint8_t fos_bayer[4][4];
+
+FOS_INLINE int fos_ramp_pos(int ramp, int lv)
+{
+ return ((lv < 0 ? 0 : lv) * fos_ramp_mul[ramp]) >> 16;
+}
+
+FOS_INLINE uint8_t fos_ixd(int ramp, int pos16, int x, int y)
+{
+ int p = (pos16 + fos_bayer[y & 3][x & 3]) >> 4;
+ return fos_ramp_base[ramp] + (p > fos_ramp_last[ramp] ? fos_ramp_last[ramp] : p);
+}
+
+/* the colour behind a palette index, and its luminance */
+fcol fos_colour_of(uint8_t ix);
+int fos_luma(uint8_t ix);
+
+/* the same as tables, for inner loops */
+extern uint8_t fos_rev_ramp[256];
+extern uint16_t fos_rev_lv[256]; /* 12-bit */
+extern uint8_t fos_luma_tab[256];
+extern uint8_t fos_chroma_tab[256];
+extern uint16_t fos_lum2lv[RAMP_COUNT][256]; /* luminance -> level, per ramp */
+
+/* a pixel at k/256 of its brightness, dithered again */
+FOS_INLINE uint8_t fos_darken(uint8_t ix, int k, int x, int y)
+{
+ int r = fos_rev_ramp[ix];
+ return fos_ixd(r, fos_ramp_pos(r, (fos_rev_lv[ix] * k) >> 8), x, y);
+}
+
+/* dst with k/256 of src glazed over it (reflections): luminance blends,
+ * the ramp is whichever brings more colour */
+FOS_INLINE uint8_t fos_glaze(uint8_t dst, uint8_t src, int k, int x, int y)
+{
+ int ld = fos_luma_tab[dst];
+ int l = ld + (((fos_luma_tab[src] - ld) * k) >> 8);
+ int r = fos_chroma_tab[src] * k >= fos_chroma_tab[dst] * (256 - k) ? fos_rev_ramp[src] : fos_rev_ramp[dst];
+ return fos_ixd(r, fos_ramp_pos(r, fos_lum2lv[r][l]), x, y);
+}
+
+/* blend a 12-bit level of a ramp over a pixel (opacity 0..256) */
+uint8_t fos_mix(uint8_t dst, int ramp, int lv, int alpha);
+uint8_t fos_mix_dither(uint8_t dst, int ramp, int lv, int alpha, int x, int y);
+
+/* the colour a of the way from (ra, la) to (rb, lb), as a ramp and level */
+void fos_lerp2(int ra, int la, int rb, int lb, int a, int *ramp, int *lv);
+
+/* canvas */
+void fos_canvas_init(struct fos_canvas *cv, uint8_t *px, int pitch, int w, int h);
+void fos_clip(struct fos_canvas *cv, int x0, int y0, int x1, int y1);
+void fos_noclip(struct fos_canvas *cv);
+
+void fos_fill(struct fos_canvas *cv, int x, int y, int w, int h, fcol c);
+void fos_fill_ix(struct fos_canvas *cv, int x, int y, int w, int h, uint8_t ix);
+void fos_blend(struct fos_canvas *cv, int x, int y, int w, int h, fcol c, int alpha);
+void fos_scale_levels(struct fos_canvas *cv, int x, int y, int w, int h, int k); /* k/256 */
+void fos_vgrad(struct fos_canvas *cv, int x, int y, int w, int h, int ramp, int lv0, int lv1);
+
+/* anti-aliased shapes; coordinates in 1/256 px where named *8 */
+void fos_rrect(struct fos_canvas *cv, int x, int y, int w, int h, int r, fcol c, int alpha);
+void fos_rrect_line(struct fos_canvas *cv, int x, int y, int w, int h, int r, int t, fcol c, int alpha);
+void fos_disc(struct fos_canvas *cv, int cx8, int cy8, int r8, fcol c, int alpha);
+void fos_ring(struct fos_canvas *cv, int cx8, int cy8, int r8, int t8, fcol c, int alpha);
+void fos_line(struct fos_canvas *cv, int x0_8, int y0_8, int x1_8, int y1_8, int w8, fcol c, int alpha);
+void fos_convex(struct fos_canvas *cv, const int *xy8, int n, fcol c, int alpha);
+void fos_tri(struct fos_canvas *cv, int cx, int cy, int size, int dir, fcol c, int alpha); /* dir 0 right, 1 down, 2 left, 3 up */
+
+/* text: y is the baseline; track is extra spacing in 1/16 px */
+int fos_text(struct fos_canvas *cv, const struct fos_font *f, int x, int y, const char *s, fcol c, int alpha, int track);
+int fos_text_w(const struct fos_font *f, const char *s, int track);
+int fos_text_c(struct fos_canvas *cv, const struct fos_font *f, int cx, int y, const char *s, fcol c, int alpha, int track);
+int fos_text_r(struct fos_canvas *cv, const struct fos_font *f, int rx, int y, const char *s, fcol c, int alpha, int track);
+
+/* text onto any 8-bit buffer with someone else's palette: map[coverage]
+ * (1..15) is the index to write, 0 leaves the pixel alone */
+int fos_text_map(uint8_t *px, int pitch, int w, int h, const struct fos_font *f, int x, int y,
+ const char *s, const uint8_t map[16], int track);
+
+/* small integer helpers */
+int fos_isqrt(unsigned int v);
+int fos_sin(int a); /* a: 0..65535 = one turn; result -4096..4096 */
+int fos_cos(int a);
+
+FOS_INLINE int fos_clamp(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
+
+#endif
diff --git a/ml-dev/filmos/fos_hud.c b/ml-dev/filmos/fos_hud.c
new file mode 100644
index 0000000..5365348
--- /dev/null
+++ b/ml-dev/filmos/fos_hud.c
@@ -0,0 +1,262 @@
+/* fos_hud: the SLR viewfinder over LiveView - an aperture scale with the
+ * meter needle on the right, a strip of red seven-segment LEDs below.
+ *
+ * Unlike the film OS screens this draws with Canon's palette (LiveView
+ * shows through index 0, and Canon keeps drawing its own bits), so it
+ * takes the indices it may use from the caller and draws straight into
+ * the overlay buffer.
+ */
+
+#include "fos.h"
+
+#define W 720
+#define H 480
+#define STRIP_W 64 /* meter strip on the right */
+#define BAR_H 44 /* LED readout at the bottom */
+#define VIEW_W (W - STRIP_W)
+#define VIEW_H (H - BAR_H)
+#define THIRD_PX 14 /* scale spacing per 1/3 stop */
+#define SCALE_TOP 26 /* y of f/22; f/1 sits 27 thirds below */
+
+static uint8_t *vr;
+static int vp;
+static const struct fos_hud_palette *pal;
+
+static void fill(int x, int y, int w, int h, uint8_t c)
+{
+ if (x < 0) { w += x; x = 0; }
+ if (y < 0) { h += y; y = 0; }
+ if (x + w > W) w = W - x;
+ if (y + h > H) h = H - y;
+ for (int j = 0; j < h; j++)
+ memset(vr + (y + j) * vp + x, c, w > 0 ? w : 0);
+}
+
+static int fstop_y(int index)
+{
+ return SCALE_TOP + (fos_nfstops - 1 - index) * THIRD_PX;
+}
+
+/* text through a coverage map: grey on black, or red LEDs (two levels) */
+static int text_gray(const struct fos_font *f, int x, int y, const char *s, int pct, int track)
+{
+ uint8_t map[16];
+ map[0] = 0;
+ for (int i = 1; i < 16; i++)
+ map[i] = i < 3 ? 0 : pal->gray[pct * i / 15];
+ return fos_text_map(vr, vp, W, H, f, x, y, s, map, track);
+}
+
+static int text_led(const struct fos_font *f, int x, int y, const char *s, int on, int track)
+{
+ uint8_t map[16];
+ for (int i = 0; i < 16; i++)
+ map[i] = i < 5 ? 0 : !on ? pal->gray[i < 10 ? 6 : 9] : i < 10 ? pal->dark_red : pal->red;
+ return fos_text_map(vr, vp, W, H, f, x, y, s, map, track);
+}
+
+/* ---------------------------------------------------------------- seven segments */
+
+/* segments a..g as bits 0..6 */
+static int seg_bits(int ch)
+{
+ static const uint8_t digits[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F };
+ if (ch >= '0' && ch <= '9') return digits[ch - '0'];
+ switch (ch)
+ {
+ case '-': return 0x40;
+ case 'E': return 0x79;
+ case 'n': return 0x54;
+ case 'd': return 0x5E;
+ case 'F': return 0x71;
+ case 'b': return 0x7C;
+ case 'u': return 0x1C;
+ case 'L': return 0x38;
+ case 'S': return 0x6D;
+ }
+ return 0;
+}
+
+#define DIG_W 15
+#define DIG_H 26
+#define SEG_T 3
+#define DIG_GAP 6
+
+/* one slanted digit; off segments are drawn faintly, like the unlit LEDs
+ * you can just see behind a real viewfinder mask */
+static void seg_digit(int x, int y, int bits, uint8_t on, uint8_t off)
+{
+ int half = DIG_H / 2;
+ for (int r = 0; r < DIG_H; r++)
+ {
+ int slant = (DIG_H - 1 - r) * 3 / DIG_H; /* leans right like the real ones */
+ int yy = y + r;
+ /* horizontals: a at the top, g in the middle, d at the bottom */
+ int hseg = -1;
+ if (r < SEG_T) hseg = 0;
+ else if (r >= half - 1 && r < half - 1 + SEG_T) hseg = 6;
+ else if (r >= DIG_H - SEG_T) hseg = 3;
+ if (hseg >= 0)
+ {
+ /* chamfered ends: shorter where the segment meets the verticals */
+ int inset = hseg == 6 ? 2 : (r == 0 || r == DIG_H - 1) ? 2 : 1;
+ fill(x + slant + inset + 1, yy, DIG_W - 2 * inset - 2, 1, (bits >> hseg) & 1 ? on : off);
+ }
+ /* verticals: f and b above the middle, e and c below */
+ int upper = r < half;
+ if (r > 1 && r < DIG_H - 2 && r != half - 1 + SEG_T / 2)
+ {
+ int left = upper ? 5 : 4, right = upper ? 1 : 2;
+ fill(x + slant, yy, SEG_T - (r == 2 || r == DIG_H - 3 ? 1 : 0), 1, (bits >> left) & 1 ? on : off);
+ fill(x + slant + DIG_W - SEG_T, yy, SEG_T, 1, (bits >> right) & 1 ? on : off);
+ }
+ }
+}
+
+/* a string of digits; '.' is a dot after the previous digit, '"' the
+ * seconds mark; returns the width */
+static int seg_text(int x, int y, const char *s, int lit)
+{
+ uint8_t on = lit ? pal->red : pal->gray[9], off = pal->gray[4];
+ int x0 = x;
+ for (; *s; s++)
+ {
+ if (*s == '.')
+ {
+ fill(x - DIG_GAP + 1, y + DIG_H - SEG_T, SEG_T, SEG_T, on);
+ x += 2;
+ continue;
+ }
+ if (*s == '"')
+ {
+ fill(x - 2, y, 2, 6, on);
+ fill(x + 2, y, 2, 6, on);
+ x += 8;
+ continue;
+ }
+ seg_digit(x, y, seg_bits(*s), on, off);
+ x += DIG_W + DIG_GAP;
+ }
+ return x - x0;
+}
+
+/* the meter's pointer: a red wedge pointing at the scale */
+static void needle(int y, uint8_t c)
+{
+ int x0 = W - STRIP_W + 4;
+ for (int r = -7; r <= 7; r++)
+ fill(x0, y + r, 16 - 2 * (r < 0 ? -r : r), 1, c);
+}
+
+/* ---------------------------------------------------------------- the HUD */
+
+void fos_hud_draw(uint8_t *vram, int pitch, const struct fos_hud *h, const struct fos_hud_palette *p)
+{
+ vr = vram; vp = pitch; pal = p;
+ uint8_t bg = p->black;
+ char label[8];
+
+ /* the meter strip */
+ int sx = W - STRIP_W;
+ fill(sx, 0, STRIP_W, VIEW_H, bg);
+ fill(sx, 0, 1, VIEW_H, p->gray[18]);
+ /* red zones: more light than f/22 can take, less than the lens can open to */
+ fill(sx + 27, 4, 4, SCALE_TOP - 11, p->dark_red);
+ fill(sx + 27, fstop_y(h->widest) + 9, 4, 20, p->dark_red);
+ for (int i = 1; i < fos_nfstops; i++)
+ {
+ int y = fstop_y(i);
+ int usable = i >= h->widest;
+ if ((i - 1) % 3)
+ {
+ fill(sx + 27, y, 4, 1, p->gray[usable ? 30 : 14]); /* thirds */
+ continue;
+ }
+ fos_format_fstop(label, sizeof(label), i);
+ fill(sx + 24, y, 8, 1, p->gray[usable ? 55 : 22]);
+ text_gray(&fos_font_xs, sx + 36, y + 5, label, i == h->fstop ? 100 : usable ? 62 : 26, 0);
+ }
+ /* the aperture you set: white tick */
+ fill(sx + 20, fstop_y(h->fstop) - 1, 14, 3, p->white);
+ /* the needle points at the aperture the meter asks for, and blinks
+ * at either end when that is out of reach */
+ if (h->lit && h->meter)
+ {
+ int y;
+ int out = h->want > fos_nfstops - 1 || h->want < h->widest;
+ if (h->want > fos_nfstops - 1) y = SCALE_TOP - 12;
+ else if (h->want < h->widest) y = fstop_y(h->widest) + 18;
+ else y = fstop_y(h->want);
+ if (!out || h->blink)
+ needle(y, p->red);
+ }
+
+ /* the LED strip */
+ int by = VIEW_H;
+ fill(0, by, W, BAR_H, bg);
+ fill(0, by, W, 1, p->gray[18]);
+ int ty = by + (BAR_H - DIG_H) / 2 + 1;
+ int base = ty + DIG_H;
+
+ /* wind reminder: blinks whether or not the meter is on */
+ text_led(&fos_font_mdb, 20, base - 3, "WIND", h->need_wind && h->blink, 24);
+
+ /* shutter speed: 1/125 shows as 125, slow speeds keep their seconds mark */
+ seg_text(132, ty, h->shutter, h->lit);
+
+ /* aperture */
+ text_gray(&fos_font_xs, 262, base - 4, "f", h->lit ? 70 : 30, 0);
+ fos_format_fstop(label, sizeof(label), h->fstop);
+ seg_text(274, ty, label, h->lit);
+
+ /* meter on */
+ for (int r = -6; r <= 6; r++)
+ {
+ int w2 = fos_isqrt(36 - r * r);
+ fill(392 - w2, by + BAR_H / 2 + r, 2 * w2 + 1, 1, h->lit ? p->red : p->gray[9]);
+ }
+
+ /* the frame counter, END at the end */
+ int lit_count = h->lit || h->finished;
+ if (h->finished)
+ seg_text(452, ty, h->blink ? "End" : " ", 1);
+ else
+ {
+ char n[8];
+ snprintf(n, sizeof(n), "%d", h->frame);
+ int w = seg_text(452, ty, n, lit_count);
+ snprintf(n, sizeof(n), "/%d", h->exposures);
+ text_gray(&fos_font_sm, 452 + w + 2, base - 2, n, lit_count ? 55 : 28, 0);
+ }
+
+ /* which film, quietly */
+ if (h->film)
+ {
+ int w = fos_text_w(&fos_font_xs, h->film, 32);
+ text_gray(&fos_font_xs, W - 22 - w, base - 6, h->film, 40, 32);
+ }
+
+ /* focusing screen: microprism collar and split-image circle */
+ if (h->focus_screen)
+ {
+ int cx = VIEW_W / 2, cy = VIEW_H / 2;
+ for (int a = 0; a < 360; a += 2)
+ {
+ int c = fos_cos(a * 65536 / 360), s = fos_sin(a * 65536 / 360);
+ int x = cx + c * 62 / 4096, y = cy + s * 62 / 4096;
+ fill(x, y, 1, 1, p->gray[70]);
+ x = cx + c * 28 / 4096; y = cy + s * 28 / 4096;
+ fill(x, y, 1, 1, p->white);
+ }
+ fill(cx - 28, cy, 57, 1, p->white);
+ }
+}
+
+/* make our strips transparent again so LiveView shows through */
+void fos_hud_clear(uint8_t *vram, int pitch, const struct fos_hud_palette *p)
+{
+ vr = vram; vp = pitch; pal = p;
+ fill(W - STRIP_W, 0, STRIP_W, VIEW_H, p->clear);
+ fill(0, VIEW_H, W, BAR_H, p->clear);
+ fill(VIEW_W / 2 - 64, VIEW_H / 2 - 64, 129, 129, p->clear);
+}
diff --git a/ml-dev/filmos/fos_jpeg.c b/ml-dev/filmos/fos_jpeg.c
new file mode 100644
index 0000000..a46bf4e
--- /dev/null
+++ b/ml-dev/filmos/fos_jpeg.c
@@ -0,0 +1,358 @@
+/* fos_jpeg: a small baseline JPEG writer for the developed frames - 4:2:0,
+ * the standard Huffman tables, integer DCT (the camera has no FPU), and
+ * EXIF with the date, the film and the f-stop.
+ */
+
+#include "fos_jpeg.h"
+#include "fos.h"
+#include <string.h>
+
+/* ---------------------------------------------------------------- tables */
+
+static const uint8_t zigzag[64] =
+{
+ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63,
+};
+
+/* the example tables of the standard (K.1, K.2), in natural order */
+static const uint8_t std_q[2][64] =
+{
+ { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92,
+ 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99 },
+ { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 },
+};
+
+/* the standard's Huffman tables (K.3): code counts by length, then values */
+static const uint8_t dc_bits[2][16] = { { 0, 1, 5, 1, 1, 1, 1, 1, 1 }, { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
+static const uint8_t dc_vals[12] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
+static const uint8_t ac_bits[2][16] =
+{
+ { 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d },
+ { 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 },
+};
+static const uint8_t ac_vals[2][162] =
+{
+ { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
+ 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
+ 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
+ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
+ 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
+ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa },
+ { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+ 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
+ 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
+ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+ 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
+ 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
+ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa },
+};
+
+/* ---------------------------------------------------------------- output */
+
+struct jw
+{
+ void *f;
+ uint8_t buf[2048];
+ int n, ok;
+ uint32_t bits;
+ int nbits;
+ uint16_t dc_code[2][12], ac_code[2][256];
+ uint8_t dc_len[2][12], ac_len[2][256];
+ int32_t recip[2][64]; /* 65536 / (8 q), zigzag order */
+ uint8_t q[2][64]; /* zigzag order, as written */
+};
+
+static void flush(struct jw *w)
+{
+ if (w->n && fos_port_write(w->f, w->buf, w->n) != w->n) w->ok = 0;
+ w->n = 0;
+}
+
+static void put8(struct jw *w, int b)
+{
+ if (w->n == (int) sizeof(w->buf)) flush(w);
+ w->buf[w->n++] = (uint8_t) b;
+}
+
+static void put16(struct jw *w, int v) { put8(w, v >> 8); put8(w, v); }
+
+static void put_bits(struct jw *w, uint32_t code, int len)
+{
+ w->bits = w->bits << len | (code & ((1u << len) - 1));
+ w->nbits += len;
+ while (w->nbits >= 8)
+ {
+ int b = (int) (w->bits >> (w->nbits - 8)) & 0xFF;
+ put8(w, b);
+ if (b == 0xFF) put8(w, 0); /* stuffed */
+ w->nbits -= 8;
+ }
+}
+
+static void huff_codes(const uint8_t *bits, const uint8_t *vals, uint16_t *code, uint8_t *len)
+{
+ int c = 0, k = 0;
+ for (int l = 1; l <= 16; l++)
+ {
+ for (int i = 0; i < bits[l - 1]; i++, k++)
+ {
+ code[vals[k]] = (uint16_t) c++;
+ len[vals[k]] = (uint8_t) l;
+ }
+ c <<= 1;
+ }
+}
+
+/* ---------------------------------------------------------------- one block */
+
+/* forward DCT, integer (libjpeg's islow, its constants in 1/8192): the
+ * output 8 times too large */
+enum { C0298 = 2446, C0390 = 3196, C0541 = 4433, C0765 = 6270, C0899 = 7373, C1175 = 9633,
+ C1501 = 12299, C1847 = 15137, C1961 = 16069, C2053 = 16819, C2562 = 20995, C3072 = 25172 };
+static void fdct(int32_t *d)
+{
+ for (int pass = 0; pass < 2; pass++)
+ {
+ for (int i = 0; i < 8; i++)
+ {
+ int32_t *p = pass ? d + i : d + i * 8;
+ const int s = pass ? 8 : 1;
+ int32_t t0 = p[0] + p[7 * s], t7 = p[0] - p[7 * s], t1 = p[s] + p[6 * s], t6 = p[s] - p[6 * s];
+ int32_t t2 = p[2 * s] + p[5 * s], t5 = p[2 * s] - p[5 * s], t3 = p[3 * s] + p[4 * s], t4 = p[3 * s] - p[4 * s];
+ int32_t t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2;
+ const int sh = pass ? 15 : 11;
+ if (pass) { p[0] = (t10 + t11 + 2) >> 2; p[4 * s] = (t10 - t11 + 2) >> 2; }
+ else { p[0] = (t10 + t11) * 4; p[4 * s] = (t10 - t11) * 4; }
+ int32_t z1 = (t12 + t13) * C0541;
+ p[2 * s] = (z1 + t13 * C0765 + (1 << (sh - 1))) >> sh;
+ p[6 * s] = (z1 - t12 * C1847 + (1 << (sh - 1))) >> sh;
+ int32_t a = t4 + t7, b = t5 + t6, c = t4 + t6, e = t5 + t7;
+ int32_t z5 = (c + e) * C1175;
+ t4 *= C0298; t5 *= C2053; t6 *= C3072; t7 *= C1501;
+ a *= -C0899; b *= -C2562; c = c * -C1961 + z5; e = e * -C0390 + z5;
+ p[7 * s] = (t4 + a + c + (1 << (sh - 1))) >> sh;
+ p[5 * s] = (t5 + b + e + (1 << (sh - 1))) >> sh;
+ p[3 * s] = (t6 + b + c + (1 << (sh - 1))) >> sh;
+ p[s] = (t7 + a + e + (1 << (sh - 1))) >> sh;
+ }
+ }
+}
+
+static int bit_size(int v)
+{
+ int n = 0;
+ if (v < 0) v = -v;
+ while (v) { n++; v >>= 1; }
+ return n;
+}
+
+/* a block of samples (level-shifted) to the file; t: 0 luma, 1 chroma */
+static void block(struct jw *w, int32_t *d, int t, int *dc_prev)
+{
+ fdct(d);
+ int q[64];
+ for (int i = 0; i < 64; i++)
+ {
+ int32_t v = d[zigzag[i]], r = w->recip[t][i];
+ q[i] = v >= 0 ? (int) ((v * r + 32768) >> 16) : -(int) ((-v * r + 32768) >> 16);
+ }
+ int diff = q[0] - *dc_prev, n = bit_size(diff);
+ *dc_prev = q[0];
+ put_bits(w, w->dc_code[t][n], w->dc_len[t][n]);
+ if (n) put_bits(w, (uint32_t) (diff < 0 ? diff - 1 : diff), n);
+ int run = 0;
+ for (int i = 1; i < 64; i++)
+ {
+ if (!q[i]) { run++; continue; }
+ while (run > 15) { put_bits(w, w->ac_code[t][0xF0], w->ac_len[t][0xF0]); run -= 16; }
+ int s = bit_size(q[i]), sym = run << 4 | s;
+ put_bits(w, w->ac_code[t][sym], w->ac_len[t][sym]);
+ put_bits(w, (uint32_t) (q[i] < 0 ? q[i] - 1 : q[i]), s);
+ run = 0;
+ }
+ if (run) put_bits(w, w->ac_code[t][0], w->ac_len[t][0]);
+}
+
+/* ---------------------------------------------------------------- EXIF */
+
+/* a tiny TIFF: IFD0 (description, make, model, software, date) and the
+ * EXIF IFD (date taken, f-number) */
+static int exif(uint8_t *out, const struct fos_jpeg_meta *m)
+{
+ char date[20] = "";
+ if (m->when && strlen(m->when) >= 16)
+ {
+ /* "2026-10-22 17:45" -> "2026:10:22 17:45:00" */
+ memcpy(date, m->when, 16);
+ date[4] = date[7] = ':';
+ memcpy(date + 16, ":00", 4);
+ }
+ int fnum = 0; /* x10 */
+ if (m->fstop && *m->fstop)
+ {
+ const char *s = m->fstop;
+ while (*s >= '0' && *s <= '9') fnum = fnum * 10 + (*s++ - '0');
+ fnum *= 10;
+ if (*s == '.' && s[1] >= '0' && s[1] <= '9') fnum += s[1] - '0';
+ }
+ struct { int tag, type; const char *s; } ifd0[] =
+ {
+ { 0x010E, 2, m->desc }, { 0x010F, 2, "Canon" }, { 0x0110, 2, fos_port_model() },
+ { 0x0131, 2, "M-FILM darkroom" }, { 0x0132, 2, date },
+ };
+ const int n0 = 6, n1 = 1 + (fnum > 0);
+ int p = 8, data = 8 + 2 + n0 * 12 + 4 + 2 + n1 * 12 + 4;
+ memcpy(out, "II*\0\x08\0\0\0", 8);
+#define W16(v) (out[p] = (uint8_t) (v), out[p + 1] = (uint8_t) ((v) >> 8), p += 2)
+#define W32(v) (W16((v) & 0xFFFF), W16((uint32_t) (v) >> 16))
+ W16(n0);
+ for (int i = 0; i < n0 - 1; i++)
+ {
+ const char *s = ifd0[i].s && *ifd0[i].s ? ifd0[i].s : " ";
+ int len = (int) strlen(s) + 1;
+ W16(ifd0[i].tag); W16(2); W32(len);
+ if (len <= 4) { memset(out + p, 0, 4); memcpy(out + p, s, len); p += 4; }
+ else { W32(data); memcpy(out + data, s, len); data += (len + 1) & ~1; }
+ }
+ int exif_at = 8 + 2 + n0 * 12 + 4;
+ W16(0x8769); W16(4); W32(1); W32(exif_at);
+ W32(0);
+ W16(n1); /* tags in ascending order */
+ if (fnum > 0)
+ {
+ W16(0x829D); W16(5); W32(1); W32(data);
+ int q = data;
+ out[q] = (uint8_t) fnum; out[q + 1] = (uint8_t) (fnum >> 8); out[q + 2] = out[q + 3] = 0;
+ out[q + 4] = 10; out[q + 5] = out[q + 6] = out[q + 7] = 0;
+ data += 8;
+ }
+ W16(0x9003); W16(2); W32(20); W32(data);
+ memcpy(out + data, date[0] ? date : " ", 20);
+ data += 20;
+ W32(0);
+#undef W16
+#undef W32
+ return data;
+}
+
+/* ---------------------------------------------------------------- the file */
+
+int fos_jpeg_write(const char *path, const uint8_t *rgb, int stride, int width, int height,
+ int quality, const struct fos_jpeg_meta *meta)
+{
+ struct jw *w = fos_port_alloc(sizeof(struct jw));
+ if (!w) return 0;
+ memset(w, 0, sizeof(*w));
+ w->ok = 1;
+ int scale = quality < 50 ? 5000 / quality : 200 - quality * 2;
+ for (int t = 0; t < 2; t++)
+ {
+ for (int i = 0; i < 64; i++)
+ {
+ int v = (std_q[t][zigzag[i]] * scale + 50) / 100;
+ v = v < 1 ? 1 : v > 255 ? 255 : v;
+ w->q[t][i] = (uint8_t) v;
+ w->recip[t][i] = 65536 / (8 * v);
+ }
+ huff_codes(dc_bits[t], dc_vals, w->dc_code[t], w->dc_len[t]);
+ huff_codes(ac_bits[t], ac_vals[t], w->ac_code[t], w->ac_len[t]);
+ }
+ w->f = fos_port_open(path, 1);
+ if (!w->f) { fos_port_free(w); return 0; }
+
+ put16(w, 0xFFD8);
+ /* JFIF */
+ put16(w, 0xFFE0); put16(w, 16);
+ static const uint8_t jfif[14] = { 'J', 'F', 'I', 'F', 0, 1, 1, 0, 0, 1, 0, 1, 0, 0 };
+ for (int i = 0; i < 14; i++) put8(w, jfif[i]);
+ /* EXIF */
+ if (meta)
+ {
+ uint8_t ex[512];
+ memset(ex, 0, sizeof(ex));
+ int n = exif(ex, meta);
+ put16(w, 0xFFE1); put16(w, n + 8);
+ static const uint8_t tag[6] = { 'E', 'x', 'i', 'f', 0, 0 };
+ for (int i = 0; i < 6; i++) put8(w, tag[i]);
+ for (int i = 0; i < n; i++) put8(w, ex[i]);
+ }
+ /* quantisation, frame, Huffman tables */
+ for (int t = 0; t < 2; t++)
+ {
+ put16(w, 0xFFDB); put16(w, 67); put8(w, t);
+ for (int i = 0; i < 64; i++) put8(w, w->q[t][i]);
+ }
+ put16(w, 0xFFC0); put16(w, 17); put8(w, 8); put16(w, height); put16(w, width); put8(w, 3);
+ put8(w, 1); put8(w, 0x22); put8(w, 0);
+ put8(w, 2); put8(w, 0x11); put8(w, 1);
+ put8(w, 3); put8(w, 0x11); put8(w, 1);
+ for (int t = 0; t < 2; t++)
+ {
+ int nd = 0, na = 0;
+ for (int i = 0; i < 16; i++) { nd += dc_bits[t][i]; na += ac_bits[t][i]; }
+ put16(w, 0xFFC4); put16(w, 2 + 17 + nd + 17 + na);
+ put8(w, t);
+ for (int i = 0; i < 16; i++) put8(w, dc_bits[t][i]);
+ for (int i = 0; i < nd; i++) put8(w, dc_vals[i]);
+ put8(w, 0x10 | t);
+ for (int i = 0; i < 16; i++) put8(w, ac_bits[t][i]);
+ for (int i = 0; i < na; i++) put8(w, ac_vals[t][i]);
+ }
+ put16(w, 0xFFDA); put16(w, 12); put8(w, 3);
+ put8(w, 1); put8(w, 0x00); put8(w, 2); put8(w, 0x11); put8(w, 3); put8(w, 0x11);
+ put8(w, 0); put8(w, 63); put8(w, 0);
+
+ /* the picture, 16 x 16 at a time: four luma blocks, then Cb and Cr
+ * from the means of 2 x 2 pixels; the edges repeat the last pixel */
+ int dc[3] = { 0, 0, 0 };
+ int32_t blk[64], cb[64], cr[64];
+ for (int my = 0; my < height; my += 16)
+ for (int mx = 0; mx < width; mx += 16)
+ {
+ memset(cb, 0, sizeof(cb));
+ memset(cr, 0, sizeof(cr));
+ for (int b = 0; b < 4; b++)
+ {
+ int bx = mx + (b & 1) * 8, by = my + (b >> 1) * 8;
+ for (int y = 0; y < 8; y++)
+ {
+ const uint8_t *row = rgb + (by + y < height ? by + y : height - 1) * stride;
+ for (int x = 0; x < 8; x++)
+ {
+ const uint8_t *px = row + 3 * (bx + x < width ? bx + x : width - 1);
+ int r = px[0], g = px[1], bl = px[2];
+ blk[y * 8 + x] = ((19595 * r + 38470 * g + 7471 * bl + 32768) >> 16) - 128;
+ int k = ((b >> 1) * 4 + (y >> 1)) * 8 + (b & 1) * 4 + (x >> 1);
+ cb[k] += -11059 * r - 21709 * g + 32768 * bl;
+ cr[k] += 32768 * r - 27439 * g - 5329 * bl;
+ }
+ }
+ block(w, blk, 0, &dc[0]);
+ }
+ for (int i = 0; i < 64; i++) { cb[i] = (cb[i] + 131072) >> 18; cr[i] = (cr[i] + 131072) >> 18; }
+ block(w, cb, 1, &dc[1]);
+ block(w, cr, 1, &dc[2]);
+ }
+ if (w->nbits) put_bits(w, 0x7F, 8 - w->nbits); /* pad with ones */
+ put16(w, 0xFFD9);
+ flush(w);
+ fos_port_close(w->f);
+ int ok = w->ok;
+ fos_port_free(w);
+ return ok;
+}
diff --git a/ml-dev/filmos/fos_jpeg.h b/ml-dev/filmos/fos_jpeg.h
new file mode 100644
index 0000000..ae60ddb
--- /dev/null
+++ b/ml-dev/filmos/fos_jpeg.h
@@ -0,0 +1,19 @@
+#ifndef _fos_jpeg_h_
+#define _fos_jpeg_h_
+
+#include <stdint.h>
+
+/* what goes into the JPEG's EXIF (any may be NULL) */
+struct fos_jpeg_meta
+{
+ const char *when; /* "2026-10-22 17:45" */
+ const char *desc; /* the film */
+ const char *fstop; /* "2.8" */
+};
+
+/* width x height RGB pixels (rows stride bytes apart) as a baseline JPEG
+ * at path; quality 1..100. 1 when written. */
+int fos_jpeg_write(const char *path, const uint8_t *rgb, int stride, int width, int height,
+ int quality, const struct fos_jpeg_meta *meta);
+
+#endif
diff --git a/ml-dev/filmos/fos_lab.c b/ml-dev/filmos/fos_lab.c
new file mode 100644
index 0000000..b6a5312
--- /dev/null
+++ b/ml-dev/filmos/fos_lab.c
@@ -0,0 +1,358 @@
+/* fos_lab: the rolls on the card and their prints, for the darkroom.
+ *
+ * A roll is what its logs say: DCIM/xxxCANON/ROLL_nnn.TXT, written by the
+ * camera frame by frame (a roll that ran into a new DCIM folder has a log
+ * in each). Its prints are kept in ML/DARKROOM/Rnnn/, Fnn.BMP for frame nn
+ * and SHEET.BMP for the contact sheet; a roll is developed when they are
+ * all there.
+ */
+
+#include "fos.h"
+#include "fos_dev.h"
+#include <string.h>
+#include <stdlib.h>
+
+#define LOG_MAX (16 * 1024)
+
+void fos_lab_print_path(char *buf, int size, int roll, int frame)
+{
+ if (frame) snprintf(buf, size, "%sML/DARKROOM/R%03d/F%02d.BMP", fos_port_card(), roll, frame);
+ else snprintf(buf, size, "%sML/DARKROOM/R%03d/SHEET.BMP", fos_port_card(), roll);
+}
+
+void fos_lab_cache_dir(char *buf, int size)
+{
+ snprintf(buf, size, "%sML/DARKROOM", fos_port_card());
+}
+
+static int first_only(void *ctx, const char *name, int is_dir) { return 0; }
+
+static int dir_exists(const char *path)
+{
+ return fos_port_list(path, first_only, 0) >= 0;
+}
+
+/* a folder of ours: it holds the roll's tag file */
+static int tagged(const char *dir, int roll)
+{
+ char path[128];
+ snprintf(path, sizeof(path), "%s/ROLL%03d.TXT", dir, roll);
+ void *f = fos_port_open(path, 0);
+ if (f) fos_port_close(f);
+ return f != 0;
+}
+
+static int make_tagged(const char *dir, int roll, int film)
+{
+ if (fos_port_mkdir(dir) < 0) return 0;
+ char path[128], text[96];
+ snprintf(path, sizeof(path), "%s/ROLL%03d.TXT", dir, roll);
+ void *f = fos_port_open(path, 1);
+ if (!f) return 0;
+ int n = snprintf(text, sizeof(text), "roll = %03d\nfilm = %s\n", roll, fos_films[film].key);
+ fos_port_write(f, text, n);
+ fos_port_close(f);
+ return 1;
+}
+
+int fos_lab_dcim_dir(char *buf, int size, int roll, int film, const char *when)
+{
+ static const char *const months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+ int m = when && strlen(when) >= 10 ? atoi(when + 5) : 0, d = m ? atoi(when + 8) : 0;
+ if (m < 1 || m > 12 || d < 1 || d > 31) return -1;
+ film = fos_clamp(film, 0, fos_nfilms - 1);
+ const char *film_name = fos_films[film].shortname ? fos_films[film].shortname : fos_films[film].key;
+ /* "Sep0906 Portra400", "Sep0906 Portra400 2" for another roll that day */
+ for (int k = 1; k < 10; k++)
+ {
+ if (k == 1) snprintf(buf, size, "%sDCIM/%s%02d%02d %s", fos_port_card(), months[m - 1], m, d, film_name);
+ else snprintf(buf, size, "%sDCIM/%s%02d%02d %s %d", fos_port_card(), months[m - 1], m, d, film_name, k);
+ if (dir_exists(buf)) { if (tagged(buf, roll)) return 0; continue; }
+ if (make_tagged(buf, roll, film) && dir_exists(buf)) return 0;
+ break; /* no long names on this card */
+ }
+ /* SEP0906, SEP0906B, ... */
+ char up[4] = { months[m - 1][0], (char) (months[m - 1][1] - 32), (char) (months[m - 1][2] - 32), 0 };
+ for (int k = 0; k < 26; k++)
+ {
+ char suffix[2] = { (char) (k ? 'A' + k : 0), 0 };
+ snprintf(buf, size, "%sDCIM/%s%02d%02d%s", fos_port_card(), up, m, d, suffix);
+ if (dir_exists(buf)) { if (tagged(buf, roll)) return 0; continue; }
+ if (make_tagged(buf, roll, film)) return 0;
+ return -1;
+ }
+ return -1;
+}
+
+int fos_lab_prepare(int roll)
+{
+ char path[64];
+ snprintf(path, sizeof(path), "%sML/DARKROOM", fos_port_card());
+ if (fos_port_mkdir(path)) return -1;
+ snprintf(path, sizeof(path), "%sML/DARKROOM/R%03d", fos_port_card(), roll);
+ return fos_port_mkdir(path);
+}
+
+static int film_index(const char *key)
+{
+ for (int i = 0; i < fos_nfilms; i++)
+ if (!strcmp(fos_films[i].key, key)) return i;
+ return 0;
+}
+
+/* ---------------------------------------------------------------- reading logs */
+
+/* one log, a line at a time: header lines ("film = portra400") and
+ * frames ("12 IMG_0012.CR2 2026-08-08 09:15:15 f/2.8") */
+struct log_reader
+{
+ void (*header)(void *ctx, const char *key, const char *value);
+ void (*frame)(void *ctx, int no, const char *file, const char *when, const char *fstop);
+ void *ctx;
+};
+
+static void read_log(const char *path, const struct log_reader *r)
+{
+ char *buf = fos_port_alloc(LOG_MAX + 1);
+ if (!buf) return;
+ void *f = fos_port_open(path, 0);
+ int n = f ? fos_port_read(f, buf, LOG_MAX) : 0;
+ if (f) fos_port_close(f);
+ buf[n > 0 ? n : 0] = 0;
+ for (char *line = buf; *line; )
+ {
+ char *next = strchr(line, '\n');
+ if (next) *next++ = 0;
+ else next = line + strlen(line);
+ char *cr = strchr(line, '\r');
+ if (cr) *cr = 0;
+ while (*line == ' ') line++;
+ char *eq = strchr(line, '=');
+ if (*line == '#' || !*line) { line = next; continue; }
+ if (eq && !(line[0] >= '0' && line[0] <= '9'))
+ {
+ char *k = line, *v = eq + 1, *e = eq;
+ while (e > k && e[-1] == ' ') e--;
+ *e = 0;
+ while (*v == ' ') v++;
+ if (r->header) r->header(r->ctx, k, v);
+ }
+ else if (line[0] >= '0' && line[0] <= '9')
+ {
+ char *tok[5];
+ int nt = 0;
+ for (char *p = line; *p && nt < 5; )
+ {
+ while (*p == ' ' || *p == '\t') p++;
+ if (!*p) break;
+ tok[nt++] = p;
+ while (*p && *p != ' ' && *p != '\t') p++;
+ if (*p) *p++ = 0;
+ }
+ if (nt >= 2 && r->frame)
+ {
+ char when[20] = "";
+ char hm[6];
+ if (nt >= 4) snprintf(when, sizeof(when), "%s %s", tok[2], fos_copy(hm, sizeof(hm), tok[3], 5));
+ r->frame(r->ctx, atoi(tok[0]), tok[1], when, nt >= 5 && !strncmp(tok[4], "f/", 2) ? tok[4] + 2 : "");
+ }
+ }
+ line = next;
+ }
+ fos_port_free(buf);
+}
+
+/* every ROLL_nnn.TXT on the card: fn(ctx, folder, file name, roll number) */
+struct each_log { void (*fn)(void *ctx, const char *folder, const char *name, int number); void *ctx; const char *folder; };
+
+static int log_entry(void *ctx, const char *name, int is_dir)
+{
+ struct each_log *e = ctx;
+ if (!is_dir && !strncmp(name, "ROLL_", 5) && strlen(name) == 12
+ && (!strcmp(name + 8, ".TXT") || !strcmp(name + 8, ".txt")))
+ e->fn(e->ctx, e->folder, name, atoi(name + 5));
+ return 1;
+}
+
+static int folder_entry(void *ctx, const char *name, int is_dir)
+{
+ struct each_log *e = ctx;
+ /* DCIM folders: three digits and five characters, "100CANON" */
+ if (!is_dir || strlen(name) != 8 || name[0] < '1' || name[0] > '9') return 1;
+ char dir[64];
+ snprintf(dir, sizeof(dir), "%sDCIM/%s", fos_port_card(), name);
+ struct each_log sub = *e;
+ sub.folder = name;
+ fos_port_list(dir, log_entry, &sub);
+ return 1;
+}
+
+static void each_log(void (*fn)(void *, const char *, const char *, int), void *ctx)
+{
+ char dir[64];
+ snprintf(dir, sizeof(dir), "%sDCIM", fos_port_card());
+ struct each_log e = { fn, ctx, 0 };
+ fos_port_list(dir, folder_entry, &e);
+}
+
+/* ---------------------------------------------------------------- the catalogue */
+
+struct scan { struct fos_lab_roll *rolls; int n, max; struct fos_lab_roll *cur; };
+
+static void scan_header(void *ctx, const char *k, const char *v)
+{
+ struct fos_lab_roll *r = ((struct scan *) ctx)->cur;
+ if (!strcmp(k, "film")) r->film = film_index(v);
+ else if (!strcmp(k, "exposures")) r->exposures = atoi(v);
+ else if (!strcmp(k, "loaded") && (!r->loaded[0] || strncmp(v, r->loaded, 16) < 0))
+ fos_copy(r->loaded, sizeof(r->loaded), v, 16);
+}
+
+static void scan_frame(void *ctx, int no, const char *file, const char *when, const char *fstop)
+{
+ struct fos_lab_roll *r = ((struct scan *) ctx)->cur;
+ if (no > r->shot) r->shot = no;
+ if (strcmp(when, r->last) > 0) snprintf(r->last, sizeof(r->last), "%s", when);
+}
+
+static void scan_log(void *ctx, const char *folder, const char *name, int number)
+{
+ struct scan *s = ctx;
+ struct fos_lab_roll *r = 0;
+ for (int i = 0; i < s->n; i++)
+ if (s->rolls[i].number == number) r = &s->rolls[i];
+ if (!r)
+ {
+ if (s->n >= s->max) return;
+ r = &s->rolls[s->n++];
+ memset(r, 0, sizeof(*r));
+ r->number = number;
+ r->exposures = 36;
+ }
+ char path[64];
+ snprintf(path, sizeof(path), "%sDCIM/%s/%s", fos_port_card(), folder, name);
+ s->cur = r;
+ struct log_reader rd = { scan_header, scan_frame, s };
+ read_log(path, &rd);
+}
+
+static int print_entry(void *ctx, const char *name, int is_dir)
+{
+ struct fos_lab_roll *r = ctx;
+ if (is_dir) return 1;
+ if (!strcmp(name, "SHEET.BMP")) r->sheet = 1;
+ else if (name[0] == 'F' && strlen(name) == 7 && !strcmp(name + 3, ".BMP"))
+ {
+ int no = atoi(name + 1);
+ if (no >= 1 && no <= r->shot) r->developed++;
+ }
+ return 1;
+}
+
+/* our folders in DCIM (not Canon's "100CANON"): which roll each holds, by
+ * its tag file, and how many JPEGs */
+struct jpeg_scan { struct fos_lab_roll *rolls; int n; int roll, count; };
+
+static int jpeg_file(void *ctx, const char *name, int is_dir)
+{
+ struct jpeg_scan *s = ctx;
+ int len = (int) strlen(name);
+ if (is_dir) return 1;
+ if (len == 11 && !strncmp(name, "ROLL", 4) && !strcmp(name + 7, ".TXT")) s->roll = atoi(name + 4);
+ else if (len > 4 && !strcmp(name + len - 4, ".JPG")) s->count++;
+ return 1;
+}
+
+static int jpeg_folder(void *ctx, const char *name, int is_dir)
+{
+ struct jpeg_scan *s = ctx;
+ if (!is_dir || (strlen(name) == 8 && name[0] >= '1' && name[0] <= '9')) return 1;
+ char dir[128];
+ snprintf(dir, sizeof(dir), "%sDCIM/%s", fos_port_card(), name);
+ s->roll = -1;
+ s->count = 0;
+ fos_port_list(dir, jpeg_file, s);
+ for (int i = 0; i < s->n; i++)
+ if (s->rolls[i].number == s->roll) s->rolls[i].jpegs += s->count;
+ return 1;
+}
+
+int fos_lab_scan(struct fos_lab_roll *rolls, int max)
+{
+ struct scan s = { rolls, 0, max, 0 };
+ each_log(scan_log, &s);
+ struct fos_roll cam;
+ fos_port_roll(&cam);
+ for (int i = 0; i < s.n; i++)
+ {
+ struct fos_lab_roll *r = &rolls[i];
+ char dir[64];
+ snprintf(dir, sizeof(dir), "%sML/DARKROOM/R%03d", fos_port_card(), r->number);
+ fos_port_list(dir, print_entry, r);
+ r->in_camera = cam.loaded && cam.number == r->number;
+ }
+ char dcim[64];
+ snprintf(dcim, sizeof(dcim), "%sDCIM", fos_port_card());
+ struct jpeg_scan js = { rolls, s.n, -1, 0 };
+ fos_port_list(dcim, jpeg_folder, &js);
+ /* newest first */
+ for (int i = 1; i < s.n; i++)
+ for (int j = i; j > 0; j--)
+ {
+ struct fos_lab_roll *a = &rolls[j - 1], *b = &rolls[j];
+ int c = strcmp(a->loaded, b->loaded);
+ if (c > 0 || (c == 0 && a->number > b->number)) break;
+ struct fos_lab_roll t = *a; *a = *b; *b = t;
+ }
+ return s.n;
+}
+
+/* ---------------------------------------------------------------- one roll's frames */
+
+struct frames { struct fos_lab_frame *frames; int max, roll; const char *folder; };
+
+static void frames_frame(void *ctx, int no, const char *file, const char *when, const char *fstop)
+{
+ struct frames *s = ctx;
+ if (no < 1 || no > s->max) return;
+ struct fos_lab_frame *f = &s->frames[no - 1];
+ f->no = no;
+ snprintf(f->cr2, sizeof(f->cr2), "%sDCIM/%s/%s", fos_port_card(), s->folder, file);
+ snprintf(f->when, sizeof(f->when), "%s", when);
+ snprintf(f->fstop, sizeof(f->fstop), "%s", fstop);
+}
+
+static void frames_log(void *ctx, const char *folder, const char *name, int number)
+{
+ struct frames *s = ctx;
+ if (number != s->roll) return;
+ char path[64];
+ snprintf(path, sizeof(path), "%sDCIM/%s/%s", fos_port_card(), folder, name);
+ s->folder = folder;
+ struct log_reader rd = { 0, frames_frame, s };
+ read_log(path, &rd);
+}
+
+int fos_lab_frames(int roll, struct fos_lab_frame *frames, int max)
+{
+ memset(frames, 0, sizeof(*frames) * max);
+ struct frames s = { frames, max, roll, 0 };
+ each_log(frames_log, &s);
+ int n = 0;
+ for (int i = 0; i < max; i++)
+ {
+ if (frames[i].no) n = i + 1;
+ else frames[i].no = i + 1;
+ }
+ /* a frame whose file has gone (deleted on the camera, or never a RAW)
+ * can't be developed */
+ for (int i = 0; i < n; i++)
+ {
+ if (!frames[i].cr2[0]) { frames[i].missing = 1; continue; }
+ void *f = fos_port_open(frames[i].cr2, 0);
+ if (f) fos_port_close(f);
+ else frames[i].missing = 1;
+ }
+ return n;
+}
diff --git a/ml-dev/filmos/fos_looks.c b/ml-dev/filmos/fos_looks.c
new file mode 100644
index 0000000..c041267
--- /dev/null
+++ b/ml-dev/filmos/fos_looks.c
@@ -0,0 +1,49 @@
+/* fos_looks: the film looks the camera develops with.
+ * Generated from films/films.py by tools/genlooks.py: edit those, not this. */
+
+#include "fos_dev.h"
+
+const struct fos_look fos_looks[] =
+{
+ { "portra400", 5500, 0, 0.3f, 0.85f,
+ { 0.165f, 0.17f, 0.158f }, { -0.15f, 0.0f, 0.1f }, { 0.03f, 0.026f, 0.028f }, { 0.97f, 0.955f, 0.92f },
+ 3, { { 1, 0, 0.06f, 1.05f }, { 3, 2, 0.12f, 0.85f }, { 5, 4, 0.08f, 0.85f } },
+ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.018f, 1.1f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "cinestill800t", 3200, 0, 0.0f, 0.95f,
+ { 0.18f, 0.18f, 0.172f }, { -0.05f, 0.0f, -0.05f }, { 0.02f, 0.032f, 0.045f }, { 0.97f, 0.96f, 0.95f },
+ 2, { { 4, 5, 0.1f, 1.0f }, { 0, 1, 0.08f, 1.05f } },
+ 6.0f, 0.6f, { 1.0f, 0.28f, 0.06f }, 0.026f, 1.4f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "ektar100", 5500, 0, 0.0f, 1.25f,
+ { 0.19f, 0.19f, 0.186f }, { -0.05f, 0.0f, 0.05f }, { 0.025f, 0.02f, 0.025f }, { 0.98f, 0.97f, 0.95f },
+ 2, { { 0, 6, 0.05f, 1.1f }, { 5, 5, 0.0f, 1.15f } },
+ 0.6f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.009f, 0.8f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "gold200", 5500, 0, 0.2f, 1.08f,
+ { 0.185f, 0.18f, 0.168f }, { -0.25f, -0.05f, 0.2f }, { 0.035f, 0.028f, 0.022f }, { 0.98f, 0.95f, 0.86f },
+ 2, { { 2, 1, 0.1f, 1.1f }, { 3, 2, 0.15f, 0.9f } },
+ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.016f, 1.1f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "superia400", 5500, 0, 0.1f, 1.05f,
+ { 0.18f, 0.183f, 0.178f }, { 0.05f, -0.1f, 0.0f }, { 0.022f, 0.036f, 0.032f }, { 0.96f, 0.97f, 0.95f },
+ 3, { { 3, 4, 0.18f, 1.05f }, { 0, 6, 0.06f, 1.0f }, { 2, 3, 0.06f, 0.95f } },
+ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.02f, 1.2f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "velvia50", 5500, 1, -0.3f, 1.45f,
+ { 0.25f, 0.25f, 0.25f }, { 0.0f, 0.0f, -0.05f }, { 0.01f, 0.01f, 0.015f }, { 0.98f, 0.98f, 0.98f },
+ 3, { { 3, 3, 0.0f, 1.15f }, { 5, 6, 0.06f, 1.15f }, { 0, 6, 0.06f, 1.1f } },
+ 0.3f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.007f, 0.7f,
+ 0, { 0.0f, 0.0f, 0.0f } },
+ { "hp5", 5500, 0, 0.2f, 1.0f,
+ { 0.175f, 0.175f, 0.175f }, { 0.0f, 0.0f, 0.0f }, { 0.03f, 0.03f, 0.03f }, { 0.96f, 0.96f, 0.96f },
+ 0, { { 0 } },
+ 0.4f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.028f, 1.3f,
+ 1, { 0.3f, 0.6f, 0.1f } },
+ { "trix400", 5500, 0, 0.0f, 1.0f,
+ { 0.205f, 0.205f, 0.205f }, { 0.1f, 0.1f, 0.1f }, { 0.02f, 0.02f, 0.02f }, { 0.97f, 0.97f, 0.97f },
+ 0, { { 0 } },
+ 0.4f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.036f, 1.3f,
+ 1, { 0.42f, 0.48f, 0.1f } },
+};
+const int fos_nlooks = sizeof(fos_looks) / sizeof(fos_looks[0]);
diff --git a/ml-dev/filmos/fos_pages.c b/ml-dev/filmos/fos_pages.c
new file mode 100644
index 0000000..597cc06
--- /dev/null
+++ b/ml-dev/filmos/fos_pages.c
@@ -0,0 +1,1100 @@
+/* fos_pages: home, the settings pages and the roll in the camera.
+ *
+ * Home is the film OS's main menu: the roll you are shooting on the left
+ * (its canister slowly turning), the places you can go on the right. The
+ * settings pages replace the Magic Lantern menu; every row is a toggle,
+ * a choice or an action, and the highlight glides between rows.
+ */
+
+#include "fos_ui.h"
+#include <string.h>
+#include <math.h>
+
+static float absf(float v) { return v < 0 ? -v : v; }
+
+static int roll_active()
+{
+ return ui_roll.loaded && ui_roll.shot < ui_roll.exposures;
+}
+
+/* the highlight behind the selected row of a list */
+static void row_highlight(int x, int w, float y, int h)
+{
+ int yi = (int) (y + 0.5f);
+ fos_rrect(cv, x, yi, w, h, 12, FC(RAMP_GRAY, 27), OPAQUE);
+ fos_rrect(cv, x, yi + 10, 3, h - 20, 1, C_ACCENT, OPAQUE);
+}
+
+/* ---------------------------------------------------------------- the film card */
+
+#define CARD_X 24
+#define CARD_Y 52
+#define CARD_W 268
+#define CARD_H 378
+
+#define CAN_FLOOR (CARD_Y + 210)
+#define CAN_SCALE 186
+
+/* the canister in the card, turning slowly (a turn every 24 s) */
+static void card_canister(int t_ms)
+{
+ if (!ui_roll.loaded) return;
+ struct fos_can *c = ui_can(ui_roll.film);
+ struct fos_can_pose p = { (CARD_X + CARD_W / 2) * 256, CAN_FLOOR, CAN_SCALE, 0, 256, 256, 70, 0 };
+ p.rot = (int) ((int64_t) t_ms * 65536 / 24000);
+ fos_can_draw(cv, c, &p);
+}
+
+/* the box the turning canister lives in */
+static void card_canister_box(int *x0, int *y0, int *x1, int *y1)
+{
+ int cx = CARD_X + CARD_W / 2;
+ int w = fos_can_width(CAN_SCALE), h = fos_can_height(CAN_SCALE);
+ *x0 = cx - w / 2 - 50; *x1 = cx + w / 2 + 56;
+ *y0 = CAN_FLOOR - h - 4; *y1 = CAN_FLOOR + 34;
+}
+
+/* the roll in the camera, everything but the canister: a counter and a
+ * strip of frames */
+static void film_card()
+{
+ fos_rrect(cv, CARD_X, CARD_Y, CARD_W, CARD_H, 18, FC(RAMP_GRAY, 15), OPAQUE);
+ int cx = CARD_X + CARD_W / 2;
+ char b[64];
+ if (!ui_roll.loaded)
+ {
+ /* an empty chamber */
+ fos_rrect_line(cv, cx - 40, CARD_Y + 60, 80, 132, 14, 2, FC(RAMP_GRAY, 48), OPAQUE);
+ fos_text_c(cv, &fos_font_lg, cx, CARD_Y + 240, "No film", C_TEXT, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_sm, cx, CARD_Y + 266, "Load a roll to start shooting", C_TEXT3, OPAQUE, 0);
+ return;
+ }
+
+ fos_text_c(cv, &fos_font_xs, cx, CARD_Y + 26, "IN CAMERA", C_TEXT3, OPAQUE, 48);
+ int y = CARD_Y + 250;
+ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
+ fos_text_c(cv, &fos_font_xs, cx, y, b, C_ACCENT, OPAQUE, 64);
+ fos_text_c(cv, &fos_font_lg, cx, y + 30, fos_films[ui_roll.film].name, C_TEXT, OPAQUE, 0);
+
+ /* frames as a strip: shot ones lit */
+ int n = ui_roll.exposures, shot = ui_roll.shot;
+ int fw = n > 24 ? 5 : n > 12 ? 7 : 12, gap = 1;
+ int sw = n * (fw + gap) - gap;
+ int sx = cx - sw / 2, sy = y + 46;
+ fos_rrect(cv, sx - 6, sy - 6, sw + 12, 24, 4, FC(RAMP_GRAY, 8), OPAQUE);
+ for (int i = 0; i < n; i++)
+ fos_fill(cv, sx + i * (fw + gap), sy, fw, 12, i < shot ? C_ACCENT2 : FC(RAMP_GRAY, 30));
+ if (shot < n)
+ fos_fill(cv, sx + shot * (fw + gap), sy, fw, 12, C_ACCENT);
+ int left = n - shot;
+ if (left > 0)
+ snprintf(b, sizeof(b), "%d shot " T_DOT " %d left", shot, left);
+ else
+ snprintf(b, sizeof(b), "End of roll " T_DOT " rewind to load");
+ fos_text_c(cv, &fos_font_sm, cx, sy + 36, b, left > 0 ? C_TEXT2 : C_RED, OPAQUE, 0);
+}
+
+/* ---------------------------------------------------------------- home */
+
+enum { H_FILM, H_ROLL, H_DARK, H_FINDER, H_LENS, H_SYSTEM, H_COUNT };
+
+static int home_sel;
+static struct spring home_hl;
+static int home_t, home_spun;
+static int home_spin; /* the canister's turn is due */
+static int home_full = 1; /* next frame redraws everything */
+static int home_list = 1; /* ... the list on the right */
+
+#define LIST_X 312
+#define LIST_W 384
+#define LIST_Y 56
+#define ROW_H 64
+
+static void home_bake()
+{
+ ui_bg_plain();
+ ui_to_bg(1);
+ ui_status_bar("HOME");
+ struct hint h[] = { { "^v", "Select" }, { "SET", "Open" }, { "PLAY", "Prints" }, { "MENU", "Back to camera" } };
+ ui_hints(h, 4);
+ film_card();
+ ui_to_bg(0);
+}
+
+void home_enter(int arg)
+{
+ fos_port_roll(&ui_roll);
+ if (arg >= 0 && arg < H_COUNT) home_sel = arg;
+ home_hl.x = home_sel; home_hl.v = 0;
+ home_t = home_spun = 0;
+ home_full = 1;
+ if (ui_roll.loaded) ui_can(ui_roll.film);
+ home_bake();
+}
+
+static void home_open(int i)
+{
+ switch (i)
+ {
+ case H_FILM: ui_go(SCR_SHELF, 1, GO_PUSH); break;
+ case H_ROLL: ui_go(SCR_ROLL, 0, GO_PUSH); break;
+ case H_DARK: ui_go(SCR_DARK, 0, GO_PUSH); break;
+ case H_FINDER: ui_go(SCR_PAGE, 0, GO_PUSH); break;
+ case H_LENS: ui_go(SCR_PAGE, 1, GO_PUSH); break;
+ case H_SYSTEM: ui_go(SCR_PAGE, 2, GO_PUSH); break;
+ }
+}
+
+void home_key(int k)
+{
+ switch (k)
+ {
+ case FK_UP: case FK_WHEEL_L:
+ home_sel = (home_sel + H_COUNT - 1) % H_COUNT;
+ break;
+ case FK_DOWN: case FK_WHEEL_R:
+ home_sel = (home_sel + 1) % H_COUNT;
+ break;
+ case FK_SET: case FK_RIGHT:
+ home_open(home_sel);
+ break;
+ case FK_MENU: case FK_HOME:
+ ui_leave();
+ break;
+ case FK_PLAY:
+ ui_go(SCR_PRINTS, 0, GO_FADE);
+ break;
+ }
+ home_list = 1;
+ ui_damage(LIST_Y, LIST_Y + H_COUNT * ROW_H);
+}
+
+int home_update(int dt)
+{
+ int moving = 0;
+ home_t += dt;
+ if (spring_step(&home_hl, home_sel, dt, 3.4f, 0.82f))
+ {
+ home_list = 1;
+ ui_damage(LIST_Y, LIST_Y + H_COUNT * ROW_H);
+ moving = 1;
+ }
+ /* the canister keeps turning, slowly enough that a dozen frames a
+ * second of only its corner of the screen look smooth */
+ if (ui_roll.loaded && home_t - home_spun >= 80)
+ {
+ int x0, y0, x1, y1;
+ card_canister_box(&x0, &y0, &x1, &y1);
+ home_spun = home_t;
+ home_spin = 1;
+ ui_damage(y0, y1);
+ moving = 1;
+ }
+ return moving;
+}
+
+static void home_row(int i, int y, int selected)
+{
+ static const char *titles[H_COUNT] = { "Film", "Roll", "Darkroom", "Viewfinder", "Lens", "System" };
+ static const int icons[H_COUNT] = { ICON_FILM, ICON_ROLL, ICON_PRINTS, ICON_FINDER, ICON_LENS, ICON_SYSTEM };
+ char sub[80];
+ char ap[8];
+ switch (i)
+ {
+ case H_FILM:
+ snprintf(sub, sizeof(sub), "%s", roll_active() ? "Change film (rewinds this roll)" : "Choose a stock and load a roll");
+ break;
+ case H_ROLL:
+ if (ui_roll.loaded)
+ snprintf(sub, sizeof(sub), "Roll %03d " T_DOT " %d of %d", ui_roll.number, ui_roll.shot, ui_roll.exposures);
+ else
+ snprintf(sub, sizeof(sub), "No film in the camera");
+ break;
+ case H_DARK:
+ snprintf(sub, sizeof(sub), "Develop your rolls " T_DOT " your prints");
+ break;
+ case H_FINDER:
+ snprintf(sub, sizeof(sub), "HUD %s " T_DOT " wind %s", fos_port_get(FS_HUD) ? "on" : "off",
+ fos_port_get(FS_WIND) == 0 ? "off" : fos_port_get(FS_WIND) == 1 ? "reminder" : "locks shutter");
+ break;
+ case H_LENS:
+ fos_format_fstop(ap, sizeof(ap), fos_port_get(FS_FSTOP));
+ if (fos_port_lens_manual())
+ snprintf(sub, sizeof(sub), "Manual lens " T_DOT " f/%s", ap);
+ else
+ snprintf(sub, sizeof(sub), "%s", fos_port_lens_name());
+ break;
+ case H_SYSTEM:
+ snprintf(sub, sizeof(sub), "Screen colour, start screen, Canon menu");
+ break;
+ }
+ int x = LIST_X + 20;
+ fcol ic = selected ? C_ACCENT : C_TEXT3;
+ ui_icon(icons[i], x + 14, y + ROW_H / 2, ic, OPAQUE);
+ fos_text(cv, &fos_font_mdb, x + 46, y + 28, titles[i], selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
+ fos_text(cv, &fos_font_sm, x + 46, y + 49, sub, C_TEXT3, OPAQUE, 0);
+ fos_tri(cv, LIST_X + LIST_W - 22, y + ROW_H / 2, 8, 0, selected ? C_TEXT2 : FC(RAMP_GRAY, 60), OPAQUE);
+}
+
+void home_draw()
+{
+ int x0, y0, x1, y1;
+ card_canister_box(&x0, &y0, &x1, &y1);
+ if (ui_clobbered) home_full = 1;
+ if (!home_full)
+ {
+ /* the card and the list sit side by side: each is redrawn alone */
+ struct fos_canvas save = *cv;
+ if (home_spin)
+ {
+ home_spin = 0;
+ ui_bg_restore(x0, y0, x1 - x0, y1 - y0);
+ fos_clip(cv, x0, y0, x1, y1);
+ card_canister(home_t);
+ *cv = save;
+ ui_damage(y0, y1);
+ }
+ if (home_list)
+ {
+ int ly1 = LIST_Y + H_COUNT * ROW_H;
+ ui_bg_restore(LIST_X, LIST_Y, LIST_W, ly1 - LIST_Y);
+ fos_clip(cv, LIST_X, LIST_Y, LIST_X + LIST_W, ly1);
+ row_highlight(LIST_X, LIST_W, LIST_Y + home_hl.x * ROW_H, ROW_H);
+ for (int i = 0; i < H_COUNT; i++)
+ home_row(i, LIST_Y + i * ROW_H, i == home_sel);
+ *cv = save;
+ ui_damage(LIST_Y, ly1);
+ home_list = 0;
+ }
+ return;
+ }
+ home_full = 0;
+ home_list = 0;
+ home_spin = 0;
+ ui_clobbered = 0;
+ ui_damage_all();
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ card_canister(home_t);
+ row_highlight(LIST_X, LIST_W, LIST_Y + home_hl.x * ROW_H, ROW_H);
+ for (int i = 0; i < H_COUNT; i++)
+ home_row(i, LIST_Y + i * ROW_H, i == home_sel);
+}
+
+/* ---------------------------------------------------------------- settings pages */
+
+enum { IT_TOGGLE, IT_CHOICE, IT_FSTOP, IT_ACTION, IT_INFO, IT_LEVEL, IT_PAGE };
+
+#define PAGE_SYSTEM 2
+#define PAGE_SCREEN 3
+#define SYS_SCREEN_ROW 2 /* where Screen colour sits in System */
+#define ACT_SCR_RESET 100 /* handled here, not by the port */
+
+struct item
+{
+ const char *label;
+ int kind;
+ int setting; /* FS_*, or FA_* for actions */
+ const char *const *choices;
+ int n;
+ const char *help;
+};
+
+static const char *const wind_choices[] = { "Off", "Reminder", "Locks shutter" };
+static const char *const apkey_choices[] = { "Dial in Av", "Up / Down", "Menu only" };
+static const char *const start_choices[] = { "Off", "When no film", "Always" };
+
+static const struct item finder_items[] =
+{
+ { "Viewfinder HUD", IT_TOGGLE, FS_HUD, 0, 0, "SLR-style meter needle and LED readout over LiveView." },
+ { "LEDs on half-press", IT_TOGGLE, FS_LEDS, 0, 0, "Like a real SLR: the readout lights only while metering." },
+ { "Focusing screen", IT_TOGGLE, FS_FOCUS, 0, 0, "A split-image circle and microprism collar (decoration only)." },
+ { "Wind lever", IT_CHOICE, FS_WIND, wind_choices, 3, "After each frame press SET to wind on. Locking is experimental." },
+};
+
+static const struct item lens_items[] =
+{
+ { "Lens", IT_INFO, -1, 0, 0, "Adapted manual lenses report no aperture: set it here." },
+ { "Aperture", IT_FSTOP, FS_FSTOP, 0, 0, "The f-stop on the lens ring. Shown in the HUD, logged for the lab." },
+ { "Widest aperture", IT_FSTOP, FS_LENS_WIDE, 0, 0, "Your manual lens' widest f-stop: the ring stops there." },
+ { "Aperture control", IT_CHOICE, FS_APKEYS, apkey_choices, 3, "How to turn the aperture ring in LiveView." },
+};
+
+static const struct item system_items[] =
+{
+ { "Start screen", IT_CHOICE, FS_STARTUP, start_choices, 3, "The film shelf when the camera turns on." },
+ { "Boot animation", IT_TOGGLE, FS_BOOTANIM, 0, 0, "The aperture opening on the name at power on." },
+ { "Screen colour", IT_PAGE, PAGE_SCREEN, 0, 0, "Match these colours to what you see around you." },
+ { "PLAY shows prints only", IT_TOGGLE, FS_PLAYLOCK, 0, 0, "Canon's playback would show frames the darkroom hasn't developed." },
+ { "Re-apply film settings", IT_ACTION, FA_REAPPLY, 0, 0, "After changing picture style, white balance or ISO by hand." },
+ { "Canon menu", IT_ACTION, FA_CANON_MENU, 0, 0, "Leave and open the camera's own menu (format card, RAW...)." },
+ { "Debug log", IT_TOGGLE, FS_DEBUG, 0, 0, "Writes ML/FILMROLL.LOG for troubleshooting." },
+ { "Support " FOS_NAME, IT_INFO, -3, 0, 0, "Scan the code with your phone to buy the developer a coffee." },
+ { "About", IT_INFO, -2, 0, 0, FOS_NAME " " T_DOT " Barlow typeface by Jeremy Tribby (SIL OFL)" },
+};
+
+static const char *const std_choices[] = { "Canon", "Rec.709" };
+
+static const struct item screen_items[] =
+{
+ { "Conversion", IT_CHOICE, FS_SCR_STD, std_choices, 2, "How colours are sent to the screen. Canon's way suits the EOS M." },
+ { "Colour", IT_LEVEL, FS_SCR_SAT, 0, 0, "Less or more saturated." },
+ { "Warmth", IT_LEVEL, FS_SCR_WARM, 0, 0, "Towards blue or towards amber, white included." },
+ { "Brightness", IT_LEVEL, FS_SCR_BRIGHT, 0, 0, "Deeper or lighter mid tones; black and white stay." },
+ { "Reset", IT_ACTION, ACT_SCR_RESET, 0, 0, "Back to the colours as designed." },
+};
+
+static const struct { const char *title; const char *sub; const struct item *items; int n; } pages[] =
+{
+ { "Viewfinder", "What you see in LiveView while you shoot", finder_items, 4 },
+ { "Lens", "Aperture for manual lenses", lens_items, 4 },
+ { "System", "Screen colour, start up and the Canon menu", system_items, 9 },
+ { "Screen colour", "Live: the whole film OS changes as you go", screen_items, 5 },
+};
+
+static int page, page_sel, page_top;
+static struct spring page_hl, page_scroll, knob[8];
+static int help_fade; /* ms since the selection changed */
+
+#define P_LIST_Y 118
+#define P_ROW_H 46
+#define P_ROWS 6
+#define P_X 24
+#define P_W 404
+
+/* the preview panel beside the list */
+#define PV_X 444
+#define PV_Y P_LIST_Y
+#define PV_W 252
+#define PV_H (P_ROWS * P_ROW_H)
+
+static struct spring lens_open; /* the aperture in the lens preview, 0..1 */
+
+/* what the next frame redraws */
+enum { D_LIST = 1, D_PREV = 2, D_HELP = 4, D_ALL = 8 };
+static int pg_dirty = D_ALL;
+#define LIST_RECT_Y0 (P_LIST_Y - 4)
+#define LIST_RECT_Y1 (P_LIST_Y + P_ROWS * P_ROW_H + 16)
+#define HELP_RECT_Y0 (HINTS_Y - 32)
+
+/* how open the blades look for fos_fstops[index]: a stop closes the
+ * opening by a constant factor, slower than real so f/16 still shows */
+static float fstop_open(int index)
+{
+ float stops = (index - 1) / 3.0f;
+ return 0.94f * expf(-0.30f * stops);
+}
+
+static void page_bake()
+{
+ ui_bg_plain();
+ ui_to_bg(1);
+ ui_status_bar("SETTINGS");
+ fos_text(cv, &fos_font_lg, P_X + 4, 80, pages[page].title, C_TEXT, OPAQUE, 0);
+ fos_text(cv, &fos_font_sm, P_X + 4, 104, pages[page].sub, C_TEXT3, OPAQUE, 0);
+ struct hint h[] = { { "^v", "Select" }, { "<>", "Change" }, { "SET", "Toggle" }, { "MENU", "Back" } };
+ struct hint hs[] = { { "^v", "Select" }, { "<>", "Adjust" }, { "MENU", "Back" } };
+ if (page == PAGE_SCREEN) ui_hints(hs, 3);
+ else ui_hints(h, 4);
+ fos_rrect(cv, PV_X, PV_Y, PV_W, PV_H, 16, FC(RAMP_GRAY, 15), OPAQUE);
+ static const char *captions[] = { "LIVEVIEW PREVIEW", "APERTURE", 0, "TEST CHART" };
+ if (captions[page]) /* System's panel captions itself */
+ fos_text_c(cv, &fos_font_xs, PV_X + PV_W / 2, PV_Y + PV_H - 14, captions[page], C_TEXT3, OPAQUE, 48);
+ ui_to_bg(0);
+}
+
+static int item_value(const struct item *it)
+{
+ return it->setting >= 0 && it->kind != IT_ACTION && it->kind != IT_PAGE ? fos_port_get(it->setting) : 0;
+}
+
+/* where an item's knob springs to: a switch 0 / 1, a slider its value */
+static float knob_target(const struct item *it)
+{
+ if (it->kind == IT_LEVEL) return item_value(it);
+ return it->kind == IT_TOGGLE && item_value(it) ? 1 : 0;
+}
+
+void page_enter(int arg)
+{
+ /* from home: a page; between pages: page | row << 4 */
+ if (ui_from() == SCR_HOME || ui_from() == SCR_PAGE)
+ {
+ page = fos_clamp(arg & 15, 0, PAGE_SCREEN);
+ page_sel = fos_clamp(arg >> 4, 0, pages[page].n - 1);
+ }
+ page_top = page_sel >= P_ROWS ? page_sel - P_ROWS + 1 : 0;
+ page_hl.x = page_sel; page_hl.v = 0;
+ page_scroll.x = page_top; page_scroll.v = 0;
+ for (int i = 0; i < pages[page].n && i < 8; i++)
+ {
+ knob[i].x = knob_target(&pages[page].items[i]);
+ knob[i].v = 0;
+ }
+ help_fade = 1000;
+ lens_open.x = fstop_open(fos_port_get(FS_FSTOP)); lens_open.v = 0;
+ pg_dirty = D_ALL;
+ page_bake();
+}
+
+static void change(const struct item *it, int dir)
+{
+ int v = fos_port_get(it->setting);
+ switch (it->kind)
+ {
+ case IT_TOGGLE:
+ fos_port_set(it->setting, !v);
+ break;
+ case IT_CHOICE:
+ fos_port_set(it->setting, fos_clamp(v + dir, 0, it->n - 1));
+ break;
+ case IT_LEVEL:
+ fos_port_set(it->setting, fos_clamp(v + dir, -FOS_SCR_STEPS, FOS_SCR_STEPS));
+ break;
+ case IT_FSTOP:
+ {
+ int lo = it->setting == FS_FSTOP ? fos_port_get(FS_LENS_WIDE) : 0;
+ fos_port_set(it->setting, fos_clamp(v + dir, lo, fos_nfstops - 1));
+ if (it->setting == FS_LENS_WIDE && fos_port_get(FS_FSTOP) < fos_port_get(FS_LENS_WIDE))
+ fos_port_set(FS_FSTOP, fos_port_get(FS_LENS_WIDE));
+ break;
+ }
+ }
+}
+
+static void page_damage(int what)
+{
+ pg_dirty |= what;
+ if (what & D_ALL) ui_damage_all();
+ if (what & (D_LIST | D_PREV)) ui_damage(LIST_RECT_Y0, LIST_RECT_Y1);
+ if (what & D_HELP) ui_damage(HELP_RECT_Y0, HINTS_Y);
+}
+
+void page_key(int k)
+{
+ const struct item *items = pages[page].items;
+ int n = pages[page].n;
+ const struct item *it = &items[page_sel];
+ /* moving the selection redraws the list and the help (and the lens,
+ * which shows the selected f-stop); changing a value, list and preview */
+ int dirty = k == FK_UP || k == FK_DOWN || k == FK_WHEEL_L || k == FK_WHEEL_R
+ ? D_LIST | D_HELP | (page == 1 || page == PAGE_SYSTEM ? D_PREV : 0)
+ : k == FK_LEFT || k == FK_RIGHT || k == FK_SET ? D_LIST | D_PREV : D_ALL;
+ switch (k)
+ {
+ case FK_UP: case FK_WHEEL_L:
+ if (page_sel > 0) { page_sel--; help_fade = 0; }
+ break;
+ case FK_DOWN: case FK_WHEEL_R:
+ if (page_sel < n - 1) { page_sel++; help_fade = 0; }
+ break;
+ case FK_LEFT: case FK_RIGHT:
+ if (it->kind == IT_TOGGLE) change(it, 0);
+ else if (it->kind == IT_CHOICE || it->kind == IT_FSTOP || it->kind == IT_LEVEL)
+ change(it, k == FK_RIGHT ? 1 : -1);
+ else if (it->kind == IT_PAGE && k == FK_RIGHT)
+ ui_go(SCR_PAGE, it->setting, GO_PUSH);
+ break;
+ case FK_SET:
+ if (it->kind == IT_TOGGLE) change(it, 0);
+ else if (it->kind == IT_CHOICE)
+ fos_port_set(it->setting, (fos_port_get(it->setting) + 1) % it->n);
+ else if (it->kind == IT_FSTOP) change(it, 1);
+ else if (it->kind == IT_PAGE) ui_go(SCR_PAGE, it->setting, GO_PUSH);
+ else if (it->kind == IT_ACTION && it->setting == ACT_SCR_RESET)
+ {
+ fos_port_set(FS_SCR_STD, 0);
+ fos_port_set(FS_SCR_SAT, 0);
+ fos_port_set(FS_SCR_WARM, 0);
+ fos_port_set(FS_SCR_BRIGHT, 0);
+ ui_toast("Screen colour as designed");
+ }
+ else if (it->kind == IT_ACTION)
+ {
+ fos_port_action(it->setting, 0, 0);
+ if (it->setting == FA_CANON_MENU) ui_leave();
+ if (it->setting == FA_REAPPLY)
+ ui_toast(ui_roll.loaded ? "Film settings go in when you return to the camera" : "No film loaded");
+ }
+ break;
+ case FK_MENU:
+ if (page == PAGE_SCREEN) ui_go(SCR_PAGE, PAGE_SYSTEM | SYS_SCREEN_ROW << 4, GO_POP);
+ else ui_go(SCR_HOME, page + H_FINDER, GO_POP);
+ break;
+ case FK_HOME: case FK_PLAY:
+ ui_leave();
+ break;
+ }
+ if (page_sel < page_top) page_top = page_sel;
+ if (page_sel >= page_top + P_ROWS) page_top = page_sel - P_ROWS + 1;
+ page_damage(dirty);
+}
+
+int page_update(int dt)
+{
+ int dirty = 0;
+ if (spring_step(&page_hl, page_sel, dt, 3.6f, 0.82f)) dirty |= D_LIST;
+ if (spring_step(&page_scroll, page_top, dt, 3.0f, 0.95f)) dirty |= D_LIST;
+ for (int i = 0; i < pages[page].n && i < 8; i++)
+ if (spring_step(&knob[i], knob_target(&pages[page].items[i]), dt, 4.0f, 0.75f))
+ dirty |= D_LIST | (page == 0 ? D_PREV : 0); /* the viewfinder preview follows the switches */
+ if (help_fade < 400) { help_fade += dt; dirty |= D_HELP; }
+ if (page == 1)
+ {
+ const struct item *it = &pages[page].items[page_sel];
+ int idx = it->setting == FS_LENS_WIDE ? fos_port_get(FS_LENS_WIDE) : fos_port_get(FS_FSTOP);
+ if (spring_step(&lens_open, fstop_open(idx), dt, 2.6f, 0.72f)) dirty |= D_PREV;
+ }
+ page_damage(dirty);
+ return dirty != 0;
+}
+
+/* ---- the previews */
+
+/* a dusk scene through the viewfinder, with the HUD as set */
+static void preview_finder()
+{
+ int sx = PV_X + 12, sy = PV_Y + 14, sw = PV_W - 24, sh = 152;
+ int horizon = sy + sh * 64 / 100;
+ fos_vgrad(cv, sx, sy, sw, horizon - sy, RAMP_AMBER, LV12(64), LV12(178));
+ fos_vgrad(cv, sx, horizon, sw, sy + sh - horizon, RAMP_GRAY, LV12(16), LV12(8));
+ fos_disc(cv, (sx + 74) * 256, (horizon - 26) * 256, 24 * 256, FC(RAMP_AMBER, 214), 110);
+ fos_disc(cv, (sx + 74) * 256, (horizon - 26) * 256, 15 * 256, FC(RAMP_GRAY, 246), OPAQUE);
+ /* hills */
+ int hills[][6] = {
+ { sx - 20, horizon + 8, sx + 70, horizon - 16, sx + 150, horizon + 8 },
+ { sx + 90, horizon + 8, sx + 170, horizon - 28, sx + sw + 30, horizon + 8 },
+ };
+ for (int i = 0; i < 2; i++)
+ {
+ int q[6];
+ for (int j = 0; j < 6; j++) q[j] = hills[i][j] * 256;
+ fos_convex(cv, q, 3, FC(RAMP_GRAY, 12), OPAQUE);
+ }
+ fos_fill(cv, sx, horizon + 8, sw, sy + sh - horizon - 8, FC(RAMP_GRAY, 12));
+
+ float hud = knob[0].x, leds_half = knob[1].x, focus = knob[2].x;
+ int wind = fos_port_get(FS_WIND);
+ if (focus > 0.01f)
+ {
+ int cx = (sx + (sw - 20) / 2) * 256, cy = (sy + (sh - 14) / 2) * 256;
+ fos_ring(cv, cx, cy, 21 * 256, 256, FC(RAMP_GRAY, 210), (int) (focus * 150));
+ fos_ring(cv, cx, cy, 9 * 256, 300, FC(RAMP_GRAY, 250), (int) (focus * 230));
+ fos_line(cv, cx - 9 * 256, cy, cx + 9 * 256, cy, 300, FC(RAMP_GRAY, 250), (int) (focus * 230));
+ }
+ if (hud > 0.01f)
+ {
+ int a = (int) (hud * 256);
+ /* meter strip and LED strip, as on the camera but small */
+ fos_blend(cv, sx + sw - 20, sy, 20, sh - 14, FC(RAMP_GRAY, 0), a);
+ fos_blend(cv, sx, sy + sh - 14, sw, 14, FC(RAMP_GRAY, 0), a);
+ for (int i = 0; i < 10; i++)
+ fos_fill(cv, sx + sw - 12, sy + 8 + i * 12, 5, 1, FC(RAMP_GRAY, 120 * a / 256));
+ fos_tri(cv, sx + sw - 16, sy + 8 + 5 * 12, 6, 0, FC(RAMP_RED, 150), a);
+ int lit = (int) (150 - leds_half * 100);
+ fos_text(cv, &fos_font_xs, sx + 50, sy + sh - 3, "125 f4 12", FC(RAMP_RED, lit), a, 16);
+ if (wind)
+ fos_text(cv, &fos_font_xs, sx + 6, sy + sh - 3, "WIND", FC(RAMP_RED, 150), a, 16);
+ }
+ /* what that means */
+ const char *l1 = !fos_port_get(FS_HUD) ? "Canon's own screen only" :
+ fos_port_get(FS_LEDS) ? "LEDs light on half-press" : "LEDs always lit";
+ const char *l2 = wind == 0 ? "No wind lever" : wind == 1 ? "SET winds on after each frame" : "Shutter locked until you wind";
+ fos_text_c(cv, &fos_font_sm, PV_X + PV_W / 2, sy + sh + 32, l1, C_TEXT2, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_sm, PV_X + PV_W / 2, sy + sh + 54, l2, C_TEXT3, OPAQUE, 0);
+}
+
+static void preview_lens()
+{
+ int cx = PV_X + PV_W / 2, cy = PV_Y + 90;
+ int open = (int) (clampf(lens_open.x, 0.02f, 1) * 4096);
+ ui_aperture(cx, cy, 68, open, 3000 + (4096 - open) * 3);
+ const struct item *it = &pages[page].items[page_sel];
+ int idx = it->setting == FS_LENS_WIDE ? fos_port_get(FS_LENS_WIDE) : fos_port_get(FS_FSTOP);
+ char ap[8], b[24];
+ fos_format_fstop(ap, sizeof(ap), idx);
+ snprintf(b, sizeof(b), "f/%s", ap);
+ fos_text_c(cv, &fos_font_xl, cx, cy + 126, b, C_TEXT, OPAQUE, 0);
+ if (it->setting == FS_LENS_WIDE)
+ snprintf(b, sizeof(b), "WIDEST THE LENS OPENS");
+ else
+ snprintf(b, sizeof(b), "SET ON THE RING");
+ fos_text_c(cv, &fos_font_xs, cx, cy + 148, b, C_ACCENT2, OPAQUE, 32);
+}
+
+/* swatches of the labels' inks and a grey wedge: compare with the boxes */
+static void preview_chart()
+{
+ static const struct { int ramp, level; const char *name; } inks[8] =
+ {
+ { RAMP_AMBER, 190, "GOLD" }, { RAMP_RED, 150, "RED" }, { RAMP_ORANGE, 160, "PORTRA" }, { RAMP_CRIMSON, 128, "EKTAR" },
+ { RAMP_GREEN, 140, "FUJI" }, { RAMP_VIOLET, 118, "VELVIA" }, { RAMP_BLUE, 160, "ILFORD" }, { RAMP_LEADER, 120, "FILM" },
+ };
+ int x0 = PV_X + 14, y0 = PV_Y + 16, sw = 50, gap = 6;
+ for (int i = 0; i < 8; i++)
+ {
+ int x = x0 + (i % 4) * (sw + gap), y = y0 + (i / 4) * 74;
+ fos_rrect(cv, x, y, sw, 44, 8, FC(inks[i].ramp, inks[i].level), OPAQUE);
+ fos_text_c(cv, &fos_font_xs, x + sw / 2, y + 60, inks[i].name, C_TEXT3, OPAQUE, 16);
+ }
+ /* eleven steps from black to white: the darkest two should still differ */
+ int wy = y0 + 160, ww = PV_W - 28;
+ for (int i = 0; i < 11; i++)
+ {
+ int xa = x0 + i * ww / 11, xb = x0 + (i + 1) * ww / 11;
+ fos_fill(cv, xa, wy, xb - xa, 36, FC(RAMP_GRAY, i * 255 / 10));
+ }
+ fos_rrect_line(cv, x0 - 1, wy - 1, ww + 2, 38, 2, 1, FC(RAMP_GRAY, 60), OPAQUE);
+ fos_text(cv, &fos_font_xs, x0, wy + 54, "0", C_TEXT3, OPAQUE, 0);
+ fos_text_r(cv, &fos_font_xs, x0 + ww, wy + 54, "100%", C_TEXT3, OPAQUE, 0);
+}
+
+/* the donation links as QR codes (ML/DATA/FOSQR.BIN, see tools/genqr.py),
+ * read the first time they are shown */
+struct qr { char label[48], url[80]; int n; const uint8_t *bits; };
+static struct qr qrs[2];
+static int nqr = -1;
+
+static void qr_load()
+{
+ char path[64];
+ snprintf(path, sizeof(path), "%sML/DATA/FOSQR.BIN", fos_port_card());
+ nqr = 0;
+ void *f = fos_port_open(path, 0);
+ if (!f) return;
+ static uint8_t blob[1024];
+ int size = fos_port_read(f, blob, sizeof(blob));
+ fos_port_close(f);
+ if (size < 8 || memcmp(blob, "FOSQ", 4)) return;
+ int n = blob[4], p = 8;
+ for (int i = 0; i < n && i < 2; i++)
+ {
+ if (p + 132 > size) break;
+ struct qr *q = &qrs[nqr];
+ memcpy(q->label, blob + p, 48); q->label[47] = 0;
+ memcpy(q->url, blob + p + 48, 80); q->url[79] = 0;
+ q->n = blob[p + 128] | blob[p + 129] << 8;
+ q->bits = blob + p + 132;
+ p += 132 + (q->n * q->n + 7) / 8;
+ if (q->n < 21 || q->n > 61 || p > size) break;
+ nqr++;
+ }
+}
+
+/* a code centred on (cx, cy), its label at base */
+static void draw_qr(const struct qr *q, int cx, int cy, int mod, int base)
+{
+ int quiet = 2, side = (q->n + 2 * quiet) * mod, x0 = cx - side / 2, y = cy - side / 2;
+ fos_fill(cv, x0, y, side, side, FC(RAMP_GRAY, 245));
+ for (int r = 0; r < q->n; r++)
+ for (int c = 0; c < q->n; c++)
+ {
+ int i = r * q->n + c;
+ if (q->bits[i >> 3] >> (7 - (i & 7)) & 1)
+ fos_fill(cv, x0 + (quiet + c) * mod, y + (quiet + r) * mod, mod, mod, FC(RAMP_GRAY, 8));
+ }
+ const struct fos_font *f = fos_text_w(&fos_font_mdb, q->label, 0) <= PV_W - 24 ? &fos_font_mdb : &fos_font_sm;
+ fos_text_c(cv, f, cx, base, q->label, C_TEXT, OPAQUE, 0);
+}
+
+static void preview_support()
+{
+ int cx = PV_X + PV_W / 2;
+ if (nqr < 0) qr_load();
+ if (nqr == 0)
+ {
+ ui_aperture(cx, PV_Y + 80, 40, 1700, 5000);
+ fos_text_c(cv, &fos_font_lg, cx, PV_Y + 162, "Thank you", C_TEXT, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_sm, cx, PV_Y + 186, "for shooting film with " FOS_NAME, C_TEXT2, OPAQUE, 0);
+ }
+ else if (nqr == 1)
+ draw_qr(&qrs[0], cx, PV_Y + 116, 200 / (qrs[0].n + 4), PV_Y + 238);
+ else
+ for (int i = 0; i < 2; i++)
+ draw_qr(&qrs[i], cx + (i ? 62 : -62), PV_Y + 116, 112 / (qrs[i].n + 4), PV_Y + 190);
+ fos_text_c(cv, &fos_font_xs, cx, PV_Y + PV_H - 14, "SUPPORT", C_TEXT3, OPAQUE, 48);
+}
+
+static void preview_about()
+{
+ int cx = PV_X + PV_W / 2;
+ fos_text_c(cv, &fos_font_xs, cx, PV_Y + PV_H - 14, "ABOUT", C_TEXT3, OPAQUE, 48);
+ ui_aperture(cx, PV_Y + 64, 40, 1700, 5000);
+ fos_text_c(cv, &fos_font_lg, cx, PV_Y + 142, FOS_NAME, C_TEXT, OPAQUE, 64);
+ char m[48];
+ snprintf(m, sizeof(m), "Film OS for the %s", fos_port_model());
+ fos_text_c(cv, &fos_font_sm, cx, PV_Y + 166, m, C_TEXT2, OPAQUE, 0);
+ char b[48];
+ snprintf(b, sizeof(b), "VERSION %s " T_DOT " %s", fos_port_version(), __DATE__);
+ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 196, b, C_TEXT3, OPAQUE, 24);
+ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 214, "MAGIC LANTERN INSIDE", C_TEXT3, OPAQUE, 24);
+ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 232, "BARLOW TYPEFACE " T_DOT " SIL OFL", C_TEXT3, OPAQUE, 24);
+}
+
+/* an on / off switch; k = 0..1 where the knob is */
+static void toggle_switch(int rx, int cy, float k)
+{
+ int w = 44, h = 24;
+ int x = rx - w, y = cy - h / 2;
+ int on_lv = (int) (k * 186);
+ fos_rrect(cv, x, y, w, h, h / 2, k > 0.5f ? FC(RAMP_AMBER, 40 + on_lv * 146 / 186) : FC(RAMP_GRAY, 40 + (int) ((1 - k) * 12)), OPAQUE);
+ int kx = x + 12 + (int) (k * (w - 24));
+ fos_disc(cv, kx * 256, cy * 256, 9 * 256, FC(RAMP_GRAY, 244), OPAQUE);
+}
+
+/* a -6..6 slider ending at rx: notches, a knob at k, the value beside it */
+static void level_slider(int rx, int cy, float k, int value, int selected)
+{
+ int w = 150, x0 = rx - w;
+ fos_fill(cv, x0, cy, w, 2, FC(RAMP_GRAY, 40));
+ for (int i = -FOS_SCR_STEPS; i <= FOS_SCR_STEPS; i++)
+ {
+ int x = x0 + (i + FOS_SCR_STEPS) * w / (2 * FOS_SCR_STEPS);
+ int big = i == 0;
+ fos_fill(cv, x, cy - (big ? 6 : 3), 1, big ? 13 : 7, FC(RAMP_GRAY, big ? 120 : 60));
+ }
+ /* from the middle to the knob, lit */
+ int kx = x0 + (int) ((k + FOS_SCR_STEPS) * w / (2 * FOS_SCR_STEPS));
+ int mid = x0 + w / 2;
+ if (kx != mid)
+ fos_fill(cv, kx < mid ? kx : mid, cy, kx < mid ? mid - kx : kx - mid, 2, selected ? C_ACCENT : C_ACCENT2);
+ fos_disc(cv, kx * 256 + 128, cy * 256 + 128, 8 * 256, selected ? FC(RAMP_GRAY, 244) : FC(RAMP_GRAY, 170), OPAQUE);
+ char b[16];
+ if (value > 0) snprintf(b, sizeof(b), "+%d", value);
+ else if (value < 0) snprintf(b, sizeof(b), T_NDASH "%d", -value);
+ else snprintf(b, sizeof(b), "0");
+ fos_text_r(cv, &fos_font_mdb, x0 - 16, cy + 7, b, selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
+}
+
+static void page_row(const struct item *it, int i, int y, int selected)
+{
+ int base = y + 30;
+ fos_text(cv, &fos_font_md, P_X + 22, base, it->label, selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
+ int rx = P_X + P_W - 20;
+ char b[48];
+ switch (it->kind)
+ {
+ case IT_TOGGLE:
+ toggle_switch(rx, y + P_ROW_H / 2, knob[i].x);
+ break;
+ case IT_CHOICE:
+ case IT_FSTOP:
+ {
+ int v = fos_port_get(it->setting);
+ if (it->kind == IT_CHOICE)
+ snprintf(b, sizeof(b), "%s", it->choices[fos_clamp(v, 0, it->n - 1)]);
+ else
+ {
+ char ap[8];
+ fos_format_fstop(ap, sizeof(ap), v);
+ snprintf(b, sizeof(b), "f/%s", ap);
+ }
+ int w = fos_text_w(&fos_font_mdb, b, 0);
+ fcol vc = selected ? C_ACCENT : C_TEXT2;
+ if (selected)
+ {
+ fos_tri(cv, rx - w - 18, y + P_ROW_H / 2 - 1, 7, 2, C_TEXT3, OPAQUE);
+ fos_tri(cv, rx - 4, y + P_ROW_H / 2 - 1, 7, 0, C_TEXT3, OPAQUE);
+ rx -= 14;
+ }
+ fos_text_r(cv, &fos_font_mdb, rx, base, b, vc, OPAQUE, 0);
+ break;
+ }
+ case IT_ACTION:
+ case IT_PAGE:
+ fos_tri(cv, rx - 4, y + P_ROW_H / 2 - 1, 8, 0, selected ? C_ACCENT : C_TEXT3, OPAQUE);
+ break;
+ case IT_LEVEL:
+ level_slider(rx, y + P_ROW_H / 2, knob[i].x, fos_port_get(it->setting), selected);
+ break;
+ case IT_INFO:
+ if (it->setting == -1)
+ snprintf(b, sizeof(b), "%s", fos_port_lens_manual() ? "Manual" : fos_port_lens_name());
+ else if (it->setting == -3)
+ {
+ if (nqr < 0) qr_load();
+ snprintf(b, sizeof(b), "%s", nqr > 0 ? "Scan the code" : "");
+ }
+ else
+ snprintf(b, sizeof(b), "%s", fos_port_version());
+ fos_text_r(cv, &fos_font_md, rx, base, b, C_TEXT3, OPAQUE, 0);
+ break;
+ }
+}
+
+void page_draw()
+{
+ const struct item *items = pages[page].items;
+ int n = pages[page].n;
+ int what = ui_clobbered ? D_ALL : pg_dirty;
+ pg_dirty = 0;
+ struct fos_canvas save = *cv;
+ if (what & D_ALL)
+ {
+ ui_clobbered = 0;
+ ui_damage_all();
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ what = D_LIST | D_PREV | D_HELP;
+ }
+ else
+ {
+ /* only the parts that change, each from the background */
+ if (what & D_LIST) ui_bg_restore(0, LIST_RECT_Y0, PV_X - 4, LIST_RECT_Y1 - LIST_RECT_Y0);
+ if (what & D_PREV) ui_bg_restore(PV_X, PV_Y, PV_W, PV_H);
+ if (what & D_HELP) ui_bg_restore(0, HELP_RECT_Y0, FOS_W, HINTS_Y - HELP_RECT_Y0);
+ }
+ if (what & D_PREV)
+ {
+ fos_clip(cv, PV_X, PV_Y, PV_X + PV_W, PV_Y + PV_H);
+ if (page == 0) preview_finder();
+ else if (page == 1) preview_lens();
+ else if (page == PAGE_SCREEN) preview_chart();
+ else if (items[page_sel].setting == -3 && items[page_sel].kind == IT_INFO) preview_support();
+ else preview_about();
+ *cv = save;
+ }
+ if (what & D_HELP)
+ {
+ /* help for the selected row, fading in */
+ float a = clampf(help_fade / 260.0f, 0, 1);
+ if (!ui_toast_up())
+ fos_text(cv, &fos_font_sm, P_X + 22, HINTS_Y - 14, items[page_sel].help, C_TEXT3, (int) (ease_out(a) * 256), 0);
+ }
+ if (!(what & D_LIST)) return;
+ fos_clip(cv, 0, P_LIST_Y - 2, PV_X - 4, P_LIST_Y + P_ROWS * P_ROW_H + 2);
+ float top = page_scroll.x;
+ row_highlight(P_X, P_W, P_LIST_Y + (page_hl.x - top) * P_ROW_H, P_ROW_H);
+ for (int i = 0; i < n; i++)
+ {
+ float y = P_LIST_Y + (i - top) * P_ROW_H;
+ if (y < P_LIST_Y - P_ROW_H || y > P_LIST_Y + P_ROWS * P_ROW_H) continue;
+ page_row(&items[i], i, (int) (y + 0.5f), i == page_sel);
+ if (i < n - 1 && i != page_sel && i + 1 != page_sel)
+ fos_fill(cv, P_X + 22, (int) (y + 0.5f) + P_ROW_H, P_W - 44, 1, FC(RAMP_GRAY, 22));
+ }
+ *cv = save;
+ /* more below / above */
+ if (page_top + P_ROWS < n)
+ fos_tri(cv, P_X + P_W / 2, P_LIST_Y + P_ROWS * P_ROW_H + 8, 8, 1, C_TEXT3, OPAQUE);
+}
+
+/* ---------------------------------------------------------------- the roll */
+
+static struct spring dial; /* frames shown on the counter */
+static int asking_rewind;
+static struct spring sheet;
+static int rewinding, rewind_t;
+static int rewind_then; /* after rewinding: 1 develop it, 0 load a new roll */
+static int rewind_number;
+static int roll_sheet_drawn; /* the last frame had the sheet on it */
+
+#define DIAL_CX 176
+#define DIAL_CY 244
+#define DIAL_R 118
+
+static void roll_bake()
+{
+ ui_bg_plain();
+ ui_to_bg(1);
+ ui_status_bar("ROLL");
+ struct hint h1[] = { { "SET", "Rewind roll" }, { "MENU", "Back" } };
+ struct hint h2[] = { { "SET", "Load film" }, { "MENU", "Back" } };
+ if (ui_roll.loaded) ui_hints(h1, 2); else ui_hints(h2, 2);
+ ui_to_bg(0);
+}
+
+void roll_enter(int arg)
+{
+ fos_port_roll(&ui_roll);
+ dial.x = -1.5f; dial.v = 0; /* from "S", like a fresh counter */
+ roll_sheet_drawn = 0;
+ asking_rewind = arg == 1 && ui_roll.loaded; /* the roll has just been finished */
+ sheet.x = 0; sheet.v = 0;
+ rewinding = 0;
+ roll_bake();
+}
+
+void roll_key(int k)
+{
+ if (rewinding) return;
+ if (asking_rewind)
+ {
+ if (k == FK_SET || k == FK_INFO)
+ {
+ asking_rewind = 0;
+ rewinding = 1;
+ rewind_t = 0;
+ rewind_then = k == FK_SET;
+ rewind_number = ui_roll.number;
+ fos_port_action(FA_REWIND, 0, 0);
+ }
+ else if (k == FK_MENU) asking_rewind = 0;
+ ui_damage_all();
+ return;
+ }
+ switch (k)
+ {
+ case FK_SET:
+ if (ui_roll.loaded) asking_rewind = 1;
+ else ui_go(SCR_SHELF, 1, GO_PUSH);
+ break;
+ case FK_MENU:
+ ui_go(SCR_HOME, H_ROLL, GO_POP);
+ break;
+ case FK_HOME: case FK_PLAY:
+ ui_leave();
+ break;
+ }
+ ui_damage_all();
+}
+
+int roll_update(int dt)
+{
+ int moving = 0;
+ float target = ui_roll.loaded ? ui_roll.shot : -1.5f;
+ if (rewinding)
+ {
+ rewind_t += dt;
+ target = -1.5f;
+ moving = 1;
+ if (rewind_t > 1500)
+ {
+ fos_port_roll(&ui_roll);
+ if (rewind_then)
+ {
+ dark_queue_clear();
+ dark_queue_add(rewind_number);
+ ui_go(SCR_DEVELOP, 0, GO_FADE);
+ }
+ else ui_go(SCR_SHELF, 1, GO_PUSH);
+ return 1;
+ }
+ }
+ moving |= spring_step(&dial, target, dt, rewinding ? 1.2f : 0.9f, rewinding ? 1.0f : 0.78f);
+ moving |= spring_step(&sheet, asking_rewind ? 1 : 0, dt, 3.0f, 0.95f);
+ if (moving) ui_damage_all();
+ return moving;
+}
+
+/* the box the dial turns in */
+#define DIAL_BOX_X0 (DIAL_CX - DIAL_R - 18)
+#define DIAL_BOX_X1 (DIAL_CX + DIAL_R + 18)
+#define DIAL_BOX_Y0 (DIAL_CY - DIAL_R - 22)
+#define DIAL_BOX_Y1 (DIAL_CY + DIAL_R + 18)
+
+/* the frame counter: a dial of numbers turning under a fixed mark, like
+ * the little window on top of a film camera */
+static void counter_dial(float frames)
+{
+ int cx = DIAL_CX * 256, cy = DIAL_CY * 256;
+ fos_disc(cv, cx, cy, (DIAL_R + 14) * 256, FC(RAMP_GRAY, 15), OPAQUE);
+ fos_disc(cv, cx, cy, DIAL_R * 256, FC(RAMP_METAL, 26), OPAQUE);
+ fos_ring(cv, cx, cy, DIAL_R * 256, 512, FC(RAMP_METAL, 60), OPAQUE);
+ fos_ring(cv, cx, cy, (DIAL_R - 30) * 256, 256, FC(RAMP_METAL, 40), OPAQUE);
+ /* 7.5 degrees a frame; frame "frames" sits at the top */
+ const int per = 65536 * 75 / 3600;
+ for (int f = -2; f <= 40; f++)
+ {
+ float rel = f - frames;
+ if (absf(rel) > 22) continue;
+ int a = -16384 + (int) (rel * per);
+ int r = f % 2 == 0 || f < 0 ? DIAL_R - 16 : DIAL_R - 10;
+ int x = cx + fos_cos(a) * r / 16, y = cy + fos_sin(a) * r / 16;
+ float near = clampf(1 - absf(rel) / 3.0f, 0, 1);
+ if (f == -2)
+ fos_text_c(cv, &fos_font_mdb, x >> 8, (y >> 8) + 7, "S", FC(RAMP_RED, 140 + (int) (near * 40)), OPAQUE, 0);
+ else if (f >= 0 && f % 2 == 0)
+ {
+ char b[4];
+ snprintf(b, sizeof(b), "%d", f);
+ fcol c = near > 0.5f ? C_TEXT : FC(RAMP_GRAY, 120 + (int) (near * 100));
+ fos_text_c(cv, &fos_font_mdb, x >> 8, (y >> 8) + 7, b, c, OPAQUE, 0);
+ }
+ else if (f > 0)
+ fos_disc(cv, x, y, 2 * 256, FC(RAMP_GRAY, 120), OPAQUE);
+ int t0 = DIAL_R - 4, t1 = DIAL_R;
+ fos_line(cv, cx + fos_cos(a) * t0 / 16, cy + fos_sin(a) * t0 / 16, cx + fos_cos(a) * t1 / 16,
+ cy + fos_sin(a) * t1 / 16, 300, FC(RAMP_METAL, 90), OPAQUE);
+ }
+ /* the fixed mark */
+ fos_tri(cv, DIAL_CX, DIAL_CY - DIAL_R - 6, 12, 1, C_ACCENT, OPAQUE);
+ /* the middle: what the counter means */
+ char b[16];
+ int shown = (int) (frames + 0.5f);
+ if (frames < -0.75f) snprintf(b, sizeof(b), "S");
+ else snprintf(b, sizeof(b), "%d", shown < 0 ? 0 : shown);
+ fos_text_c(cv, &fos_font_num, DIAL_CX, DIAL_CY + 26, b, C_TEXT, OPAQUE, 0);
+ fos_text_c(cv, &fos_font_xs, DIAL_CX, DIAL_CY + 52, "FRAMES", C_TEXT3, OPAQUE, 48);
+}
+
+void roll_draw()
+{
+ if (!ui_clobbered && sheet.x <= 0 && !roll_sheet_drawn && !rewinding)
+ {
+ /* only the dial turns */
+ struct fos_canvas save = *cv;
+ ui_bg_restore(DIAL_BOX_X0, DIAL_BOX_Y0, DIAL_BOX_X1 - DIAL_BOX_X0, DIAL_BOX_Y1 - DIAL_BOX_Y0);
+ fos_clip(cv, DIAL_BOX_X0, DIAL_BOX_Y0, DIAL_BOX_X1, DIAL_BOX_Y1);
+ counter_dial(dial.x);
+ *cv = save;
+ return;
+ }
+ ui_clobbered = 0;
+ roll_sheet_drawn = sheet.x > 0;
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ counter_dial(dial.x);
+ int x = 336;
+ char b[96];
+ if (!ui_roll.loaded)
+ {
+ fos_text(cv, &fos_font_xs, x, 96, "NO ROLL", C_ACCENT, OPAQUE, 64);
+ fos_text(cv, &fos_font_lg, x, 132, "The camera is empty", C_TEXT, OPAQUE, 0);
+ fos_text(cv, &fos_font_sm, x, 160, "Load a roll from the film shelf.", C_TEXT3, OPAQUE, 0);
+ return;
+ }
+ const struct fos_film *f = &fos_films[ui_roll.film];
+ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
+ fos_text(cv, &fos_font_xs, x, 96, b, C_ACCENT, OPAQUE, 64);
+ fos_text(cv, &fos_font_lg, x, 132, f->name, C_TEXT, OPAQUE, 0);
+ snprintf(b, sizeof(b), "%s " T_DOT " ISO %d " T_DOT " %d exposures", f->process, f->box_iso, ui_roll.exposures);
+ fos_text(cv, &fos_font_sm, x, 158, b, C_TEXT2, OPAQUE, 0);
+ if (ui_roll.loaded_at[0])
+ {
+ snprintf(b, sizeof(b), "Loaded %s", ui_roll.loaded_at);
+ fos_text(cv, &fos_font_sm, x, 180, b, C_TEXT3, OPAQUE, 0);
+ }
+
+ /* the last frames, newest first */
+ int y = 220;
+ fos_text(cv, &fos_font_xs, x, y, "LAST FRAMES", C_TEXT3, OPAQUE, 48);
+ fos_fill(cv, x, y + 8, 340, 1, C_LINE);
+ y += 34;
+ if (!ui_roll.nrecent)
+ fos_text(cv, &fos_font_sm, x, y, "Nothing shot yet " T_MDASH " the roll is fresh.", C_TEXT3, OPAQUE, 0);
+ for (int i = 0; i < ui_roll.nrecent && i < FOS_RECENT; i++, y += 30)
+ {
+ snprintf(b, sizeof(b), "%d", ui_roll.recent[i].no);
+ fos_text_r(cv, &fos_font_mdb, x + 30, y, b, i == 0 ? C_TEXT : C_TEXT2, OPAQUE, 0);
+ fos_text(cv, &fos_font_md, x + 54, y, ui_roll.recent[i].time, C_TEXT2, OPAQUE, 0);
+ snprintf(b, sizeof(b), "f/%s", ui_roll.recent[i].fstop);
+ fos_text(cv, &fos_font_md, x + 140, y, b, C_TEXT3, OPAQUE, 0);
+ }
+
+ if (rewinding)
+ {
+ float t = clampf(rewind_t / 900.0f, 0, 1);
+ fos_text_c(cv, &fos_font_lg, 360, 420, "Rewinding" T_ELLIPSIS, FC(RAMP_GRAY, (int) (240 * ease_out(t))), OPAQUE, 0);
+ }
+ char body[96];
+ int left = ui_roll.exposures - ui_roll.shot;
+ if (left > 0)
+ {
+ snprintf(b, sizeof(b), "Rewind roll %03d?", ui_roll.number);
+ snprintf(body, sizeof(body), "%d frames stay unexposed. Develop it now, or load a new roll first.", left);
+ }
+ else
+ {
+ snprintf(b, sizeof(b), "Roll %03d is finished", ui_roll.number);
+ snprintf(body, sizeof(body), "Rewind it, then develop it now or load a new roll first.");
+ }
+ ui_sheet3(sheet.x, b, body, "Develop now", "New roll", left > 0 ? "Cancel" : "Not now");
+}
diff --git a/ml-dev/filmos/fos_shelf.c b/ml-dev/filmos/fos_shelf.c
new file mode 100644
index 0000000..12e1e2f
--- /dev/null
+++ b/ml-dev/filmos/fos_shelf.c
@@ -0,0 +1,914 @@
+/* fos_shelf: the film shelf - the canisters on a dark stage, turning
+ * towards you as they glide past - and loading a roll.
+ *
+ * The carousel position is a spring that chases the selected film, so
+ * quick turns of the dial pile up into one smooth glide, and every
+ * canister's place, size, light and turn follow from how far it is from
+ * that position. The text below follows the same position: it slides out
+ * with the film leaving the middle and in with the one arriving.
+ *
+ * The films stand on shelves by kind (colour, slide, B&W, cine): up and
+ * down change shelf, and the canisters of the next one drop in.
+ *
+ * PLAY shows the film's sample: one photo developed with every film when
+ * the card was made (ML/SAMPLES), full screen on its own palette.
+ */
+
+#include "fos_ui.h"
+#include "fos_dev.h"
+#include <string.h>
+
+#define FLOOR_Y 262
+#define DOTS_Y 290
+#define BRAND_Y 320
+#define NAME_Y 366
+#define DESC_Y 392
+#define CHIPS_Y 406
+
+#define TABS_Y 56
+#define MAX_CANS 10 /* labels painted at a time: the shelf's middle and a few around */
+#define MAX_LIST 96 /* films on a shelf */
+
+/* everything that moves on the shelf is between these rows */
+#define MOVING_Y0 (STATUS_H - 8)
+#define MOVING_Y1 HINTS_Y
+
+static struct { int film; struct fos_can *c; unsigned used; } cans[MAX_CANS];
+static unsigned can_clock;
+static uint8_t *info_mask; /* the name block for fading, see info_build() */
+static int info_film = -1, info_x0, info_x1;
+static int16_t info_row0[128], info_row1[128]; /* inked span of each row */
+
+static struct spring pos; /* carousel, in places on the shelf */
+static int target; /* the selected film's place on the shelf */
+static int group; /* the shelf: FOS_GROUP_* */
+static int list[MAX_LIST], nlist; /* its films */
+static int group_at[FOS_NGROUPS]; /* the place last chosen on each shelf */
+static struct spring drop; /* a new shelf's canisters dropping in, 1 -> 0 */
+static int drop_dir;
+static int exp_sel;
+static struct spring exp_roll; /* the exposures chip rolls to the new number */
+static int exp_prev;
+static int nudge; /* bump at either end */
+
+/* rewind-and-load question */
+static int asking;
+static struct spring sheet;
+
+/* loading a roll */
+static int loading, load_t;
+
+static int sheet_drawn; /* the last frame had the sheet on it */
+
+static char baked_clock[16];
+static void bake();
+
+/* the sample, full screen; changing what is shown goes through black, as
+ * the prints do (fos_dark.c) */
+enum { SM_OFF, SM_WAIT, SM_IN, SM_SHOW, SM_OUT };
+enum { SM_NEXT_LOAD, SM_NEXT_BACK, SM_NEXT_ROLL };
+static int sm_state, sm_t, sm_next;
+static int sm_black; /* the black before the picture is on screen */
+static int has_samples; /* the card has them (made for this camera) */
+static struct fos_print sm_print;
+static int sm_have; /* sm_print holds the film's sample */
+static int sm_info = 1; /* the film's details along the bottom */
+static int sm_dirty;
+#define SM_FADE_MS 180
+#define SM_INFO_H 44
+
+static void sample_path(char *buf, int size, int film)
+{
+ snprintf(buf, size, "%sML/SAMPLES/F%03d.BMP", fos_port_card(), film);
+}
+
+/* ---------------------------------------------------------------- canisters */
+
+/* a film's canister: kept painted for the last few asked for */
+struct fos_can *ui_can(int film)
+{
+ if (film < 0 || film >= fos_nfilms) return 0;
+ int slot = 0;
+ for (int i = 0; i < MAX_CANS; i++)
+ {
+ if (cans[i].c && cans[i].film == film)
+ {
+ cans[i].used = ++can_clock;
+ return cans[i].c;
+ }
+ if (!cans[i].c || (cans[slot].c && cans[i].used < cans[slot].used)) slot = i;
+ }
+ fos_can_free(cans[slot].c);
+ cans[slot].c = fos_can_new(film, fos_exposure_choices[exp_sel]);
+ cans[slot].film = film;
+ cans[slot].used = ++can_clock;
+ return cans[slot].c;
+}
+
+void ui_cans_free()
+{
+ fos_port_free(info_mask);
+ info_mask = 0;
+ info_film = -1;
+ for (int i = 0; i < MAX_CANS; i++)
+ {
+ fos_can_free(cans[i].c);
+ cans[i].c = 0;
+ }
+}
+
+void ui_cans_exposures(int exposures)
+{
+ for (int i = 0; i < MAX_CANS; i++)
+ if (cans[i].c) fos_can_set_exposures(cans[i].c, exposures);
+}
+
+/* the films of shelf g, and the place of film on it (0 if not there) */
+static int shelf_list(int g, int film)
+{
+ int at = 0;
+ group = g;
+ nlist = 0;
+ for (int i = 0; i < fos_nfilms && nlist < MAX_LIST; i++)
+ if (fos_films[i].group == g)
+ {
+ if (i == film) at = nlist;
+ list[nlist++] = i;
+ }
+ return at;
+}
+
+/* the labels the shelf will show first, painted now rather than mid-glide */
+static void paint_around(int at)
+{
+ for (int d = 0; d <= 3; d++)
+ {
+ if (at + d < nlist) ui_can(list[at + d]);
+ if (d && at - d >= 0) ui_can(list[at - d]);
+ }
+}
+
+/* ---------------------------------------------------------------- the stage */
+
+static float absf(float v) { return v < 0 ? -v : v; }
+
+#ifndef ABS
+#define ABS(v) ((v) < 0 ? -(v) : (v))
+#endif
+
+/* the stage's light at (x, y), 12-bit */
+static int stage_lv(int x, int y)
+{
+ int dx = x - 360;
+ int lv;
+ if (y < FLOOR_Y - 6)
+ {
+ /* backdrop: a soft spotlight behind the middle canister */
+ int dy = (y - 150) * 3 / 2;
+ int d2 = (dx * dx + dy * dy) >> 4;
+ int spot = d2 < 9000 ? (9000 - d2) * (9000 - d2) / 9000 * LV12(20) / 9000 : 0;
+ lv = LV12(10) + spot + (FLOOR_Y - y) * LV12(3) / FLOOR_Y;
+ }
+ else
+ {
+ /* floor: a lit ellipse under the canister fading into the dark */
+ int dy = (y - (FLOOR_Y + 4)) * 5;
+ int d2 = (dx * dx + dy * dy) >> 4;
+ int pool = d2 < 7000 ? (7000 - d2) * LV12(13) / 7000 : 0;
+ int fall = fos_clamp((y - FLOOR_Y) * LV12(6) / 60, 0, LV12(6));
+ lv = LV12(13) + pool - fall;
+ if (y > FLOOR_Y + 40) lv = lv * (FOS_H - y) / (FOS_H - FLOOR_Y - 40);
+ lv = fos_clamp(lv, LV12(4), LV_MAX);
+ }
+ /* the seam between backdrop and floor, very soft */
+ if (y >= FLOOR_Y - 6 && y < FLOOR_Y + 2)
+ lv = lv * (256 - (4 - ABS(y - (FLOOR_Y - 2))) * 10) / 256;
+ return lv;
+}
+
+/* the stage: a backdrop lit from above, a floor, a pool of light in the
+ * middle. The light changes slowly, so it is worked out every 8 px and
+ * stepped in between; rows y0..y1-1 only */
+static void stage_bg(int y0, int y1)
+{
+ const int mul = fos_ramp_mul[RAMP_GRAY];
+ const int base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
+ for (int y = y0; y < y1; y++)
+ {
+ uint8_t *row = &ui_bg[y * FOS_W];
+ const uint8_t *bay = fos_bayer[y & 3];
+ int p1 = stage_lv(0, y) * mul;
+ for (int x = 0; x < FOS_W; x += 8)
+ {
+ int p0 = p1;
+ p1 = stage_lv(x + 8, y) * mul;
+ int p = p0, dp = (p1 - p0) >> 3;
+ for (int i = 0; i < 8; i++, p += dp)
+ {
+ int q = ((p >> 16) + bay[i & 3]) >> 4;
+ row[x + i] = base + (q > last ? last : q);
+ }
+ }
+ }
+}
+
+/* where film i stands for carousel offset d (films from the middle) */
+static void pose_of(float d, struct fos_can_pose *p, float lift, float spread)
+{
+ float ad = absf(d);
+ float n = clampf(ad, 0, 1), f = clampf(ad - 1, 0, 1.8f);
+ float sx = d < 0 ? -1 : 1;
+ float x = 360 + sx * (n * 192 + f * 122) * spread;
+ float scale = 1.0f - n * 0.27f - f * 0.17f;
+ float light = 1.0f - n * 0.42f - f * 0.30f;
+ float rot = d * 0.085f; /* turns: faces the middle */
+ p->cx8 = (int) (x * 256);
+ p->floor_y = (int) (FLOOR_Y - n * 12 - f * 8 - lift);
+ p->scale = (int) (scale * 256);
+ p->rot = (int) (rot * 65536);
+ p->light = (int) (clampf(light, 0, 1) * 256);
+ p->leader = 256;
+ p->fast = absf(pos.v) > 1.2f; /* films a second: too quick to see the fine print */
+ /* the middle one is mirrored in the floor, fading as it leaves */
+ p->reflect = (int) (64 * clampf(1.25f - absf(d), 0, 1));
+}
+
+/* a soft contact shadow under a canister */
+static void contact_shadow(int cx, int y, int rx, int ry, int strength)
+{
+ if (rx <= 0 || ry <= 0) return;
+ int x0 = fos_clamp(cx - rx, cv->cx0, cv->cx1), x1 = fos_clamp(cx + rx, cv->cx0, cv->cx1);
+ int y0 = fos_clamp(y - ry, cv->cy0, cv->cy1), y1 = fos_clamp(y + ry, cv->cy0, cv->cy1);
+ int sx = 65536 / rx, sy = 65536 / ry; /* 1/256 of the radius per px */
+ for (int j = y0; j < y1; j++)
+ {
+ int dy = ((j - y) * sy) >> 8;
+ if (dy * dy >= 65536) continue;
+ /* only the part of the row inside the ellipse */
+ int half = (fos_isqrt(65536 - dy * dy) * rx >> 8) + 1;
+ int xa = fos_clamp(cx - half, x0, x1), xb = fos_clamp(cx + half + 1, xa, x1);
+ int dx8 = (xa - cx) * sx;
+ uint8_t *p = &cv->px[j * cv->pitch + xa];
+ for (int i = xa; i < xb; i++, p++, dx8 += sx)
+ {
+ int dx = dx8 >> 8;
+ int d2 = (dx * dx + dy * dy) >> 8;
+ if (d2 >= 256) continue;
+ int k = 256 - ((strength * (((256 - d2) * (256 - d2)) >> 8)) >> 8);
+ *p = fos_darken(*p, k, i, j);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- screen */
+
+void shelf_enter(int arg)
+{
+ exp_sel = fos_clamp(fos_port_get(FS_EXP), 0, FOS_NEXP - 1);
+ exp_prev = exp_sel;
+ exp_roll.x = 1; exp_roll.v = 0;
+ int film = ui_roll.loaded && ui_roll.shot < ui_roll.exposures ? ui_roll.film : fos_port_get(FS_FILM);
+ film = fos_clamp(film, 0, fos_nfilms - 1);
+ target = shelf_list(fos_films[film].group, film);
+ for (int g = 0; g < FOS_NGROUPS; g++) group_at[g] = 0;
+ group_at[group] = target;
+ drop.x = 0; drop.v = 0;
+ pos.x = target; pos.v = 0;
+ /* arriving from elsewhere: the shelf glides in from one film over */
+ if (arg == 0) pos.x = target - 0.6f;
+ nudge = 0;
+ asking = 0;
+ sheet.x = 0; sheet.v = 0;
+ loading = 0;
+ sheet_drawn = 0;
+ sm_state = SM_OFF;
+ sm_have = 0;
+ char path[64];
+ sample_path(path, sizeof(path), 0);
+ void *f = fos_port_open(path, 0);
+ has_samples = f != 0;
+ if (f) fos_port_close(f);
+ paint_around(target);
+ ui_cans_exposures(fos_exposure_choices[exp_sel]);
+ bake();
+}
+
+void shelf_leave()
+{
+ if (sm_have) fos_print_free(&sm_print);
+ sm_have = 0;
+ if (sm_state != SM_OFF) fos_port_palette();
+ sm_state = SM_OFF;
+}
+
+static int roll_in_progress()
+{
+ return ui_roll.loaded && ui_roll.shot < ui_roll.exposures;
+}
+
+static void start_loading()
+{
+ loading = 1;
+ load_t = 0;
+ asking = 0;
+ bake();
+ fos_port_set(FS_FILM, list[target]);
+ fos_port_set(FS_EXP, exp_sel);
+ fos_port_action(FA_LOAD, list[target], exp_sel);
+ fos_port_roll(&ui_roll);
+}
+
+/* what the next frame changes: the whole screen while the sheet or the
+ * loading animation is up, else the band between status bar and hints */
+static void shelf_damage()
+{
+ if (loading || asking || sheet.x > 0 || sheet_drawn || sm_state != SM_OFF) ui_damage_all();
+ else ui_damage(MOVING_Y0, MOVING_Y1);
+}
+
+/* ---------------------------------------------------------------- the sample */
+
+static void sm_load()
+{
+ char path[64];
+ if (sm_have) fos_print_free(&sm_print);
+ sm_have = 0;
+ sample_path(path, sizeof(path), list[target]);
+ sm_have = fos_print_load(path, &sm_print);
+ /* made with another set of films: not this one's */
+ if (sm_have && sm_print.film != list[target]) { fos_print_free(&sm_print); sm_have = 0; }
+ if (!sm_have)
+ {
+ char msg[96];
+ snprintf(msg, sizeof(msg), "shelf: no sample in %s", path);
+ fos_port_log(msg);
+ }
+ sm_dirty = 1;
+}
+
+static void sm_palette(int k)
+{
+ static const uint8_t black[1][3] = { { 0, 0, 0 } };
+ if (sm_have) fos_port_photo((const uint8_t (*)[3]) sm_print.pal, FOS_PRINT_COLOURS, k);
+ else fos_port_photo(black, 1, k);
+}
+
+static void sm_go(int next)
+{
+ if (sm_state == SM_OUT) return;
+ sm_next = next;
+ sm_state = SM_OUT;
+ sm_t = 0;
+}
+
+static void sample_key(int k)
+{
+ if (sm_state != SM_SHOW) return;
+ switch (k)
+ {
+ case FK_LEFT: case FK_WHEEL_L: case FK_RIGHT: case FK_WHEEL_R:
+ {
+ /* the next film on this shelf; the shelf follows */
+ int to = target + (k == FK_LEFT || k == FK_WHEEL_L ? -1 : 1);
+ if (to < 0 || to >= nlist) break;
+ target = to;
+ group_at[group] = target;
+ sm_go(SM_NEXT_LOAD);
+ break;
+ }
+ case FK_INFO:
+ sm_info = !sm_info;
+ sm_dirty = 1;
+ break;
+ case FK_SET:
+ sm_go(SM_NEXT_ROLL);
+ break;
+ case FK_MENU: case FK_PLAY: case FK_HOME:
+ sm_go(SM_NEXT_BACK);
+ break;
+ }
+}
+
+static int sample_update(int dt)
+{
+ sm_t += dt;
+ switch (sm_state)
+ {
+ case SM_WAIT:
+ /* once the screen is black in the film OS's colours, the picture */
+ if (!sm_black) return 1;
+ sm_load();
+ sm_palette(0);
+ sm_state = SM_IN;
+ sm_t = 0;
+ return 1;
+ case SM_IN:
+ sm_palette(fos_clamp(sm_t * 256 / SM_FADE_MS, 0, 256));
+ if (sm_t >= SM_FADE_MS) sm_state = SM_SHOW;
+ return 1;
+ case SM_OUT:
+ sm_palette(fos_clamp(256 - sm_t * 256 / SM_FADE_MS, 0, 256));
+ if (sm_t < SM_FADE_MS) return 1;
+ if (sm_next == SM_NEXT_LOAD)
+ {
+ sm_load();
+ sm_state = SM_IN;
+ sm_t = 0;
+ return 1;
+ }
+ /* back to the shelf's colours, on black, at the film shown last */
+ sm_state = SM_OFF;
+ if (sm_have) fos_print_free(&sm_print);
+ sm_have = 0;
+ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+ fos_port_present(cv->px, FOS_W, 0, FOS_H);
+ fos_port_palette();
+ pos.x = target; pos.v = 0;
+ paint_around(target);
+ ui_clobbered = 1;
+ if (sm_next == SM_NEXT_ROLL)
+ {
+ if (roll_in_progress()) asking = 1;
+ else start_loading();
+ }
+ shelf_damage();
+ return 1;
+ }
+ return 0;
+}
+
+static void sample_draw()
+{
+ if (sm_state == SM_WAIT)
+ {
+ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
+ ui_clobbered = 0;
+ ui_damage_all();
+ sm_black = 1;
+ return;
+ }
+ if (sm_state == SM_OUT) return; /* what is fading out stays as it was */
+ if (!sm_dirty && !ui_clobbered) return;
+ sm_dirty = 0;
+ ui_clobbered = 0;
+ const struct fos_film *f = &fos_films[list[target]];
+ if (sm_have) memcpy(cv->px, sm_print.px, FOS_W * FOS_H);
+ else
+ {
+ memset(cv->px, PX_BLACK, FOS_W * FOS_H);
+ ui_photo_text(&fos_font_md, 360, 244, "No sample for this film", 0, 1);
+ }
+ if (sm_info)
+ {
+ char b[96];
+ int y = FOS_H - SM_INFO_H;
+ memset(&cv->px[y * cv->pitch], PX_PANEL, FOS_W * SM_INFO_H);
+ memset(&cv->px[y * cv->pitch], PX_LINE, FOS_W);
+ int x = 20 + ui_photo_text(&fos_font_xs, 20, y + 28, "SAMPLE", 1, 0);
+ snprintf(b, sizeof(b), "%s %s " T_DOT " ISO %d " T_DOT " %s", f->brand, f->name, f->box_iso, f->process);
+ ui_photo_text(&fos_font_sm, x + 14, y + 28, b, 0, 0);
+ ui_photo_text(&fos_font_xs, FOS_W - 20, y + 28, "SET LOAD PLAY BACK", 0, 2);
+ }
+ ui_damage_all();
+}
+
+/* ---------------------------------------------------------------- keys */
+
+void shelf_key(int k)
+{
+ if (loading) return;
+ if (sm_state != SM_OFF)
+ {
+ sample_key(k);
+ shelf_damage();
+ return;
+ }
+ if (asking)
+ {
+ if (k == FK_SET) start_loading();
+ else if (k == FK_MENU || k == FK_LEFT || k == FK_RIGHT || k == FK_WHEEL_L || k == FK_WHEEL_R)
+ asking = 0;
+ shelf_damage();
+ return;
+ }
+ switch (k)
+ {
+ case FK_LEFT: case FK_WHEEL_L:
+ if (target > 0) target--; else nudge = -1;
+ break;
+ case FK_RIGHT: case FK_WHEEL_R:
+ if (target < nlist - 1) target++; else nudge = 1;
+ break;
+ case FK_UP: case FK_DOWN:
+ {
+ /* the next shelf (skipping empty ones), at the film last chosen there */
+ int dir = k == FK_DOWN ? 1 : -1, from = group, g = group;
+ group_at[group] = target;
+ do
+ {
+ g = (g + dir + FOS_NGROUPS) % FOS_NGROUPS;
+ shelf_list(g, -1);
+ }
+ while (!nlist && g != from);
+ target = fos_clamp(group_at[g], 0, nlist - 1);
+ pos.x = target; pos.v = 0;
+ drop.x = 1; drop.v = 0;
+ drop_dir = dir;
+ paint_around(target);
+ bake();
+ ui_clobbered = 1;
+ break;
+ }
+ case FK_INFO:
+ exp_prev = exp_sel;
+ exp_sel = (exp_sel + (k == FK_UP ? FOS_NEXP - 1 : 1)) % FOS_NEXP;
+ exp_roll.x = 0; exp_roll.v = 0;
+ ui_cans_exposures(fos_exposure_choices[exp_sel]);
+ break;
+ case FK_SET:
+ if (roll_in_progress()) asking = 1;
+ else start_loading();
+ break;
+ case FK_MENU:
+ if (ui_from() == SCR_HOME) ui_go(SCR_HOME, 0, GO_POP);
+ else ui_leave();
+ break;
+ case FK_PLAY:
+ if (has_samples)
+ {
+ /* the canisters settle where they are going first */
+ pos.x = target; pos.v = 0;
+ sm_state = SM_WAIT;
+ sm_t = 0;
+ sm_black = 0;
+ break;
+ }
+ ui_go(SCR_HOME, 0, GO_POP);
+ break;
+ case FK_HOME:
+ ui_go(SCR_HOME, 0, GO_POP);
+ break;
+ }
+ shelf_damage();
+}
+
+int shelf_update(int dt)
+{
+ if (sm_state != SM_OFF) return sample_update(dt);
+ int moving = 0;
+ char clock[16];
+ fos_port_clock(clock, sizeof(clock));
+ if (strcmp(clock, baked_clock))
+ {
+ /* a new minute: only the status bar changes */
+ stage_bg(0, STATUS_H);
+ ui_to_bg(1);
+ ui_status_bar("FILM");
+ ui_to_bg(0);
+ memcpy(baked_clock, clock, sizeof(baked_clock));
+ ui_damage(0, STATUS_H);
+ ui_clobbered = 1;
+ }
+ float goal = target + (nudge ? nudge * 0.18f : 0);
+ moving |= spring_step(&pos, goal, dt, 2.1f, 0.86f);
+ if (nudge && absf(pos.x - goal) < 0.05f) nudge = 0;
+ moving |= spring_step(&exp_roll, 1, dt, 3.2f, 0.9f);
+ moving |= spring_step(&sheet, asking ? 1 : 0, dt, 3.0f, 0.95f);
+ moving |= spring_step(&drop, 0, dt, 2.6f, 0.9f);
+ if (loading)
+ {
+ load_t += dt;
+ moving = 1;
+ if (load_t > 1900) ui_leave();
+ }
+ if (moving)
+ shelf_damage();
+ return moving;
+}
+
+/* ---------------------------------------------------------------- drawing */
+
+static void draw_canisters(float lift_mid, float spread, float fade_sides, int leader_mid)
+{
+ int t0 = fos_port_ms();
+ struct { int i; float d; } order[8];
+ int n = 0;
+ for (int i = 0; i < nlist && n < 8; i++)
+ {
+ float d = i - pos.x;
+ if (absf(d) > 2.7f) continue;
+ order[n].i = i; order[n].d = d; n++;
+ }
+ /* far ones first */
+ for (int a = 0; a < n; a++)
+ for (int b = a + 1; b < n; b++)
+ if (absf(order[b].d) > absf(order[a].d))
+ {
+ int ti = order[a].i; float td = order[a].d;
+ order[a] = order[b];
+ order[b].i = ti; order[b].d = td;
+ }
+
+ for (int k = 0; k < n; k++)
+ {
+ int i = list[order[k].i];
+ float d = order[k].d;
+ struct fos_can_pose p;
+ int mid = absf(d) < 0.5f;
+ pose_of(d, &p, mid ? lift_mid : 0, spread);
+ if (!mid) p.light = (int) (p.light * (1 - fade_sides));
+ if (drop.x > 0.002f)
+ {
+ /* a new shelf: its canisters drop in from above (or rise from below), the far ones a little later */
+ float t = clampf(drop.x * (1 + absf(d) * 0.25f), 0, 1);
+ p.floor_y -= (int) (t * 90 * drop_dir);
+ p.light = (int) (p.light * (1 - t));
+ p.reflect = (int) (p.reflect * (1 - t));
+ }
+ if (mid && leader_mid) p.leader = leader_mid;
+ if (p.light <= 4) continue;
+ struct fos_can *c = ui_can(i);
+ int w = fos_can_width(p.scale);
+ contact_shadow(p.cx8 >> 8, p.floor_y, w * 6 / 10, 7 * p.scale / 256 + 2, 150 * p.light / 256);
+ fos_can_draw(cv, c, &p);
+
+ /* the film that is in the camera wears a tag */
+ if (roll_in_progress() && i == ui_roll.film && !loading)
+ {
+ int cx = p.cx8 >> 8;
+ int top = p.floor_y - fos_can_height(p.scale) - 14;
+ int a = (int) (p.light * 1.0f);
+ const char *t = "IN CAMERA";
+ int tw = fos_text_w(&fos_font_xs, t, 24);
+ fos_rrect(cv, cx - tw / 2 - 10, top - 13, tw + 20, 20, 10, FC(RAMP_AMBER, 186 * a / 256), OPAQUE);
+ fos_text_c(cv, &fos_font_xs, cx, top + 2, t, FC(RAMP_GRAY, 14), OPAQUE, 24);
+ }
+ }
+ ui_cans_ms += fos_port_ms() - t0;
+}
+
+/* chips under the name: fixed sizes, so only the values change */
+#define CHIP_H 26
+static const char *chip_labels[3] = { "ISO", "PROCESS", "EXP" };
+static const char *chip_widest[3] = { "800", "C-41", "36" };
+static int chip_x[3], chip_w[3], chip_vx[3];
+
+static void chips_layout()
+{
+ int total = 0;
+ for (int i = 0; i < 3; i++)
+ {
+ int lw = fos_text_w(&fos_font_xs, chip_labels[i], 24);
+ int vw = fos_text_w(&fos_font_mdb, chip_widest[i], 0);
+ chip_w[i] = lw + vw + 32;
+ total += chip_w[i] + (i ? 10 : 0);
+ }
+ int x = 360 - total / 2;
+ for (int i = 0; i < 3; i++)
+ {
+ chip_x[i] = x;
+ chip_vx[i] = x + 12 + fos_text_w(&fos_font_xs, chip_labels[i], 24) + 8;
+ x += chip_w[i] + 10;
+ }
+}
+
+static void draw_static(int alpha)
+{
+ struct hint h[] = { { "<>", "Film" }, { "^v", "Shelf" }, { "INFO", "Exposures" },
+ { "SET", roll_in_progress() ? "Rewind & load" : "Load" }, { "MENU", "Back" },
+ { "PLAY", "Sample" } };
+ if (alpha >= OPAQUE) ui_hints(h, has_samples ? 6 : 5);
+ /* the shelves, this one lit */
+ int tw = 0;
+ for (int g = 0; g < FOS_NGROUPS; g++) tw += fos_text_w(&fos_font_xs, fos_group_names[g], 64) + (g ? 30 : 0);
+ int tx = 360 - tw / 2;
+ for (int g = 0; g < FOS_NGROUPS; g++)
+ {
+ int w = fos_text_w(&fos_font_xs, fos_group_names[g], 64);
+ fos_text(cv, &fos_font_xs, tx, TABS_Y, fos_group_names[g], g == group ? C_ACCENT : C_TEXT3, alpha, 64);
+ if (g == group) fos_rrect(cv, tx + w / 2 - 8, TABS_Y + 6, 16, 3, 1, C_ACCENT, alpha);
+ tx += w + 30;
+ }
+ for (int i = 0; i < 3; i++)
+ {
+ int exp = i == 2;
+ fos_rrect(cv, chip_x[i], CHIPS_Y, chip_w[i], CHIP_H, CHIP_H / 2, exp ? FC(RAMP_GRAY, 24) : FC(RAMP_GRAY, 17), alpha);
+ fos_rrect_line(cv, chip_x[i], CHIPS_Y, chip_w[i], CHIP_H, CHIP_H / 2, 1, exp ? C_ACCENT2 : FC(RAMP_GRAY, 46), alpha);
+ fos_text(cv, &fos_font_xs, chip_x[i] + 12, CHIPS_Y + 18, chip_labels[i], C_TEXT3, alpha, 24);
+ }
+ int n = nlist, x0 = 360 - n * 6;
+ for (int i = 0; i < n; i++)
+ fos_disc(cv, (x0 + i * 12 + 6) * 256, DOTS_Y * 256, 2 * 256, FC(RAMP_GRAY, 60), alpha);
+}
+
+/* the stage and everything that doesn't move, drawn once; while a roll
+ * loads, only the stage stays */
+static void bake()
+{
+ stage_bg(0, FOS_H);
+ ui_to_bg(1);
+ ui_status_bar("FILM");
+ chips_layout();
+ if (!loading) draw_static(OPAQUE);
+ ui_to_bg(0);
+ fos_port_clock(baked_clock, sizeof(baked_clock));
+}
+
+static void draw_dot_marker()
+{
+ /* the current film: a short amber bar sliding with the carousel */
+ int x0 = 360 - nlist * 6;
+ float px = x0 + clampf(pos.x, 0, nlist - 1) * 12 + 6;
+ fos_rrect(cv, (int) px - 7, DOTS_Y - 2, 14, 4, 2, C_ACCENT, OPAQUE);
+}
+
+/* The film's name block, kept for fading: per pixel its ink (high
+ * nibble) and coverage (low nibble), so a frame of the glide blends the
+ * pixels without decoding the glyphs again. */
+#define INFO_Y0 (BRAND_Y - 16)
+#define INFO_Y1 (DESC_Y + 8)
+#define INFO_H (INFO_Y1 - INFO_Y0)
+
+static void info_build(int film)
+{
+ const struct fos_film *f = &fos_films[film];
+ const struct { const struct fos_font *font; int y; const char *s; int track; } part[3] =
+ {
+ { &fos_font_xs, BRAND_Y, f->brand, 64 },
+ { &fos_font_xl, NAME_Y, f->name, 0 },
+ { &fos_font_sm, DESC_Y, f->desc, 0 },
+ };
+ memset(info_mask, 0, FOS_W * INFO_H);
+ info_x0 = FOS_W; info_x1 = 0;
+ for (int i = 0; i < 3; i++)
+ {
+ uint8_t map[16];
+ map[0] = 0;
+ for (int v = 1; v < 16; v++) map[v] = (i + 1) << 4 | v;
+ int w = fos_text_w(part[i].font, part[i].s, part[i].track);
+ int x = 360 - w / 2;
+ fos_text_map(info_mask, FOS_W, FOS_W, INFO_H, part[i].font, x, part[i].y - INFO_Y0, part[i].s, map, part[i].track);
+ if (x - 4 < info_x0) info_x0 = fos_clamp(x - 4, 0, FOS_W);
+ if (x + w + 4 > info_x1) info_x1 = fos_clamp(x + w + 4, 0, FOS_W);
+ }
+ for (int j = 0; j < INFO_H; j++)
+ {
+ const uint8_t *m = &info_mask[j * FOS_W];
+ int a = info_x0, b = info_x1;
+ while (a < b && !m[a]) a++;
+ while (b > a && !m[b - 1]) b--;
+ info_row0[j] = a; info_row1[j] = b;
+ }
+ info_film = film;
+}
+
+/* the block at opacity alpha, moved xo px. Grey ink over the grey stage
+ * blends as levels of one ramp, which is cheap; the few pixels of the
+ * amber brand take the full blend. */
+static void info_fade(int alpha, int xo)
+{
+ const fcol inks[4] = { 0, C_ACCENT, C_TEXT, C_TEXT2 };
+ int ink_lv[4];
+ for (int i = 1; i < 4; i++)
+ ink_lv[i] = FC_RAMP(inks[i]) == RAMP_GRAY ? LV12(FC_LEVEL(inks[i])) : -1;
+ const int mul = fos_ramp_mul[RAMP_GRAY], base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
+ int ka = alpha * 17; /* coverage 15 at full opacity -> 255 */
+ for (int j = 0; j < INFO_H; j++)
+ {
+ int y = INFO_Y0 + j;
+ if (y < cv->cy0 || y >= cv->cy1) continue;
+ int xa = fos_clamp(info_row0[j], cv->cx0 - xo, cv->cx1 - xo), xb = fos_clamp(info_row1[j], xa, cv->cx1 - xo);
+ const uint8_t *m = &info_mask[j * FOS_W];
+ uint8_t *row = &cv->px[y * cv->pitch + xo];
+ uint8_t bay[4];
+ for (int k = 0; k < 4; k++)
+ bay[k] = fos_bayer[y & 3][(k + xo) & 3];
+ for (int x = xa; x < xb; x++)
+ {
+ int v = m[x];
+ if (!v) continue;
+ int op = ((v & 15) * ka) >> 8;
+ int k = v >> 4, d = row[x];
+ if (ink_lv[k] >= 0 && fos_rev_ramp[d] == RAMP_GRAY)
+ {
+ int lv = fos_rev_lv[d] + (((ink_lv[k] - fos_rev_lv[d]) * op) >> 8);
+ int q = (((lv * mul) >> 16) + bay[x & 3]) >> 4;
+ row[x] = base + (q > last ? last : q);
+ }
+ else
+ row[x] = fos_mix(d, FC_RAMP(inks[k]), LV12(FC_LEVEL(inks[k])), op);
+ }
+ }
+}
+
+static void draw_info()
+{
+ int place = (int) (pos.x + 100.5f) - 100;
+ place = fos_clamp(place, 0, nlist - 1);
+ int ni = list[place];
+ float frac = pos.x - place;
+ float a = clampf(1 - absf(frac) * 2.2f, 0, 1) * (1 - drop.x);
+ a = a * a * (3 - 2 * a);
+ int alpha = (int) (a * 256);
+ int xo = (int) (-frac * 70);
+ const struct fos_film *f = &fos_films[ni];
+
+ if (alpha > 0)
+ {
+ if (!info_mask) info_mask = fos_port_alloc(FOS_W * INFO_H);
+ if (alpha < OPAQUE && info_mask)
+ {
+ if (info_film != ni) info_build(ni);
+ info_fade(alpha, xo);
+ }
+ else
+ {
+ fos_text_c(cv, &fos_font_xs, 360 + xo, BRAND_Y, f->brand, C_ACCENT, alpha, 64);
+ fos_text_c(cv, &fos_font_xl, 360 + xo, NAME_Y, f->name, C_TEXT, alpha, 0);
+ fos_text_c(cv, &fos_font_sm, 360 + xo, DESC_Y, f->desc, C_TEXT2, alpha, 0);
+ }
+ char b[16];
+ snprintf(b, sizeof(b), "%d", f->box_iso);
+ fos_text(cv, &fos_font_mdb, chip_vx[0], CHIPS_Y + 19, b, C_TEXT, alpha, 0);
+ fos_text(cv, &fos_font_mdb, chip_vx[1], CHIPS_Y + 19, f->process, C_TEXT, alpha, 0);
+ }
+
+ /* exposures: the number rolls up or down when it changes */
+ struct fos_canvas save = *cv;
+ fos_clip(cv, chip_vx[2] - 4, CHIPS_Y + 3, chip_x[2] + chip_w[2] - 8, CHIPS_Y + CHIP_H - 3);
+ char nb[8], ob[8];
+ snprintf(nb, sizeof(nb), "%d", fos_exposure_choices[exp_sel]);
+ snprintf(ob, sizeof(ob), "%d", fos_exposure_choices[exp_prev]);
+ int dy = (int) ((1 - exp_roll.x) * 20);
+ fos_text(cv, &fos_font_mdb, chip_vx[2], CHIPS_Y + 19 + dy, nb, C_ACCENT, OPAQUE, 0);
+ if (exp_roll.x < 1)
+ fos_text(cv, &fos_font_mdb, chip_vx[2], CHIPS_Y + 19 + dy - 20, ob, C_ACCENT, OPAQUE, 0);
+ *cv = save;
+}
+
+static void draw_sheet()
+{
+ char t[48], b[96];
+ snprintf(t, sizeof(t), "Rewind roll %03d?", ui_roll.number);
+ snprintf(b, sizeof(b), "%d of %d frames on %s are still unexposed. They will be lost.",
+ ui_roll.exposures - ui_roll.shot, ui_roll.exposures, fos_films[ui_roll.film].name);
+ ui_sheet(sheet.x, t, b, "Rewind and load", "Keep shooting");
+}
+
+/* SET: the leader is drawn out of the canister across the stage, the
+ * other stocks step aside, and the roll number is stamped */
+static void draw_loading()
+{
+ float t = load_t;
+ float aside = ease_in_out(clampf(t / 450.0f, 0, 1));
+ float lift = 10 * ease_out(clampf(t / 400.0f, 0, 1));
+ float pull = ease_in_out(clampf((t - 250) / 850.0f, 0, 1));
+ int leader = 256 + (int) (pull * 256 * 7);
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ /* the chips and dots fade away with the other stocks */
+ if (aside < 1) draw_static((int) (256 * (1 - aside)));
+ draw_canisters(lift, 1 + aside * 0.8f, aside, leader);
+
+ float ta = ease_out(clampf((t - 900) / 450.0f, 0, 1));
+ if (ta > 0)
+ {
+ int a = (int) (ta * 256);
+ char b[48];
+ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
+ fos_text_c(cv, &fos_font_xs, 360, BRAND_Y + 8, b, C_ACCENT, a, 64);
+ fos_text_c(cv, &fos_font_xl, 360, NAME_Y + 8 - (int) ((1 - ta) * 12), "Loaded", C_TEXT, a, 0);
+ snprintf(b, sizeof(b), "%s " T_DOT " %d exposures", fos_films[list[target]].name, fos_exposure_choices[exp_sel]);
+ fos_text_c(cv, &fos_font_sm, 360, DESC_Y + 8, b, C_TEXT2, a, 0);
+ }
+}
+
+void shelf_draw()
+{
+ if (sm_state != SM_OFF)
+ {
+ sample_draw();
+ return;
+ }
+ if (loading)
+ {
+ draw_loading();
+ return;
+ }
+ if (ui_clobbered || sheet.x > 0 || sheet_drawn)
+ {
+ ui_clobbered = 0;
+ ui_damage_all();
+ ui_bg_restore(0, 0, FOS_W, FOS_H);
+ }
+ else
+ {
+ /* the status bar and the key hints never move here */
+ ui_bg_restore(0, MOVING_Y0, FOS_W, MOVING_Y1 - MOVING_Y0);
+ ui_damage(MOVING_Y0, MOVING_Y1);
+ }
+ draw_canisters(0, 1, 0, 0);
+ draw_dot_marker();
+ draw_info();
+ draw_sheet();
+ sheet_drawn = sheet.x > 0;
+}
diff --git a/ml-dev/filmos/fos_ui.c b/ml-dev/filmos/fos_ui.c
new file mode 100644
index 0000000..2f85cf7
--- /dev/null
+++ b/ml-dev/filmos/fos_ui.c
@@ -0,0 +1,923 @@
+/* fos_ui: the loop, navigation, transitions and shared widgets of the
+ * film OS. The screens themselves are in fos_shelf.c and fos_pages.c.
+ *
+ * One loop reads keys, steps every animation by the time that really
+ * passed and redraws only while something moves, so a quiet screen costs
+ * nothing. Screens draw into our own canvas; the port copies the rows
+ * that changed to the camera's bitmap overlay.
+ */
+
+#include "fos_ui.h"
+#include "fos_dev.h"
+#include <string.h>
+
+struct fos_canvas *cv;
+uint8_t *ui_bg;
+int ui_now;
+struct fos_roll ui_roll;
+int ui_clobbered = 1;
+int ui_cans_ms;
+
+static struct fos_canvas canvas;
+static uint8_t *buf_cv, *buf_bg, *buf_snap;
+
+static int screen, screen_from;
+static int dmg_y0 = FOS_H, dmg_y1 = 0;
+
+/* screen change in progress */
+static int tr_how, tr_t, tr_len; /* tr_t counts up to tr_len (ms) */
+static int leaving; /* 1 while the shutter opens on LiveView */
+static int leave_t;
+static int quit;
+static int boot_then_leave;
+
+/* opening: the shutter closes over LiveView, then opens on us */
+static int enter_t;
+#define ENTER_LEN 420
+#define LEAVE_LEN 380
+
+/* the toast */
+static char toast_msg[80];
+static int toast_t = 100000;
+#define TOAST_LEN 1800
+
+/* held keys repeat */
+static int held_key, held_since, held_last;
+
+/* ---------------------------------------------------------------- animation */
+
+float clampf(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }
+
+float ease_out(float t)
+{
+ t = clampf(t, 0, 1);
+ float u = 1 - t;
+ return 1 - u * u * u;
+}
+
+float ease_in_out(float t)
+{
+ t = clampf(t, 0, 1);
+ return t < 0.5f ? 4 * t * t * t : 1 - (-2 * t + 2) * (-2 * t + 2) * (-2 * t + 2) / 2;
+}
+
+int spring_step(struct spring *s, float target, int dt, float hz, float zeta)
+{
+ float w = 6.2831853f * hz;
+ while (dt > 0)
+ {
+ float h = (dt > 8 ? 8 : dt) / 1000.0f;
+ float a = w * w * (target - s->x) - 2 * zeta * w * s->v;
+ s->v += a * h;
+ s->x += s->v * h;
+ dt -= 8;
+ }
+ float d = target - s->x;
+ if (d < 0.0015f && d > -0.0015f && s->v < 0.02f && s->v > -0.02f)
+ {
+ s->x = target;
+ s->v = 0;
+ return 0;
+ }
+ return 1;
+}
+
+/* ---------------------------------------------------------------- damage */
+
+void ui_damage(int y0, int y1)
+{
+ if (y0 < dmg_y0) dmg_y0 = fos_clamp(y0, 0, FOS_H);
+ if (y1 > dmg_y1) dmg_y1 = fos_clamp(y1, 0, FOS_H);
+}
+
+void ui_damage_all()
+{
+ ui_damage(0, FOS_H);
+}
+
+/* ---------------------------------------------------------------- widgets */
+
+void ui_bg_restore(int x, int y, int w, int h)
+{
+ x = fos_clamp(x, 0, FOS_W); y = fos_clamp(y, 0, FOS_H);
+ w = fos_clamp(w, 0, FOS_W - x); h = fos_clamp(h, 0, FOS_H - y);
+ for (int j = y; j < y + h; j++)
+ memcpy(&cv->px[j * cv->pitch + x], &ui_bg[j * FOS_W + x], w);
+}
+
+/* static parts of a screen are drawn once into its background */
+void ui_to_bg(int on)
+{
+ static struct fos_canvas bgcv, *saved;
+ if (on && cv != &bgcv)
+ {
+ saved = cv;
+ fos_canvas_init(&bgcv, ui_bg, FOS_W, FOS_W, FOS_H);
+ cv = &bgcv;
+ }
+ else if (!on && cv == &bgcv)
+ cv = saved;
+}
+
+/* a dark backdrop with a little light from above */
+static int plain_lv(int x, int y)
+{
+ int dx = (x - 360) * 2 / 3, dy = y - 40;
+ int d2 = (dx * dx + dy * dy) >> 6; /* soft pool of light */
+ return LV12(9) + (d2 < 2400 ? (2400 - d2) * LV12(9) / 2400 : 0);
+}
+
+static uint8_t *buf_plain; /* the backdrop, worked out once a session */
+
+void ui_bg_plain()
+{
+ if (buf_plain)
+ {
+ memcpy(ui_bg, buf_plain, FOS_W * FOS_H);
+ return;
+ }
+ /* the light changes slowly: worked out on an 8 px grid, stepped between */
+ const int mul = fos_ramp_mul[RAMP_GRAY];
+ const int base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
+ static int grid[2][FOS_W / 8 + 1];
+ for (int i = 0; i <= FOS_W / 8; i++)
+ grid[1][i] = plain_lv(i * 8, 0) * mul;
+ for (int y = 0; y < FOS_H; y++)
+ {
+ if (!(y & 7))
+ for (int i = 0; i <= FOS_W / 8; i++)
+ {
+ grid[0][i] = grid[1][i];
+ grid[1][i] = plain_lv(i * 8, y + 8) * mul;
+ }
+ int fy = y & 7;
+ uint8_t *row = &ui_bg[y * FOS_W];
+ const uint8_t *bay = fos_bayer[y & 3];
+ for (int x = 0, i = 0; x < FOS_W; x += 8, i++)
+ {
+ int p0 = grid[0][i] + ((grid[1][i] - grid[0][i]) >> 3) * fy;
+ int p1 = grid[0][i + 1] + ((grid[1][i + 1] - grid[0][i + 1]) >> 3) * fy;
+ int p = p0, dp = (p1 - p0) >> 3;
+ for (int k = 0; k < 8; k++, p += dp)
+ {
+ int q = ((p >> 16) + bay[k & 3]) >> 4;
+ row[x + k] = base + (q > last ? last : q);
+ }
+ }
+ }
+ /* keep it for the next page, if there is room */
+ buf_plain = fos_port_alloc(FOS_W * FOS_H);
+ if (buf_plain) memcpy(buf_plain, ui_bg, FOS_W * FOS_H);
+}
+
+void ui_status_bar(const char *title)
+{
+ /* wordmark: a small aperture and the name */
+ int y = 24;
+ for (int i = 0; i < 6; i++)
+ {
+ int a = i * 65536 / 6 + 3000;
+ int x0 = 26 * 256 + fos_cos(a) * 7 / 16, y0 = 18 * 256 + fos_sin(a) * 7 / 16;
+ int x1 = 26 * 256 + fos_cos(a + 65536 / 6) * 7 / 16, y1 = 18 * 256 + fos_sin(a + 65536 / 6) * 7 / 16;
+ fos_line(cv, x0, y0, x1, y1, 400, C_ACCENT, OPAQUE);
+ }
+ int x = fos_text(cv, &fos_font_xs, 42, y, FOS_NAME, C_TEXT2, OPAQUE, 40) + 42;
+ if (title && *title)
+ {
+ fos_fill(cv, x + 12, 12, 1, 14, C_LINE);
+ fos_text(cv, &fos_font_xs, x + 25, y, title, C_TEXT3, OPAQUE, 40);
+ }
+
+ /* right: the roll in the camera and the time */
+ char clock[16], buf[48];
+ fos_port_clock(clock, sizeof(clock));
+ int rx = FOS_W - 24;
+ rx -= fos_text_r(cv, &fos_font_mdb, rx, y + 1, clock, C_TEXT, OPAQUE, 0) + 18;
+ if (ui_roll.loaded)
+ {
+ int left = ui_roll.exposures - ui_roll.shot;
+ if (left > 0)
+ snprintf(buf, sizeof(buf), "%s %d/%d", fos_films[ui_roll.film].name, ui_roll.shot, ui_roll.exposures);
+ else
+ snprintf(buf, sizeof(buf), "%s END OF ROLL", fos_films[ui_roll.film].name);
+ int w = fos_text_w(&fos_font_xs, buf, 16);
+ fos_rrect(cv, rx - w - 24, 9, w + 24, 20, 10, C_PANEL, OPAQUE);
+ fos_disc(cv, (rx - w - 14) * 256, 19 * 256, 3 * 256, left > 0 ? C_ACCENT : C_RED, OPAQUE);
+ fos_text(cv, &fos_font_xs, rx - w - 6, y - 1, buf, C_TEXT2, OPAQUE, 16);
+ }
+}
+
+int ui_keycap(int x, int base, const char *key)
+{
+ /* arrows are drawn, words are written */
+ int w;
+ if (!strcmp(key, "<>") || !strcmp(key, "^v"))
+ {
+ w = 34;
+ fos_rrect_line(cv, x, base - 15, w, 20, 6, 1, FC(RAMP_GRAY, 90), OPAQUE);
+ int vert = key[0] == '^';
+ fos_tri(cv, x + 11, base - 5, 7, vert ? 3 : 2, C_TEXT2, OPAQUE);
+ fos_tri(cv, x + 23, base - 5, 7, vert ? 1 : 0, C_TEXT2, OPAQUE);
+ return w;
+ }
+ w = fos_text_w(&fos_font_xs, key, 16) + 14;
+ fos_rrect_line(cv, x, base - 15, w, 20, 6, 1, FC(RAMP_GRAY, 90), OPAQUE);
+ fos_text(cv, &fos_font_xs, x + 7, base - 1, key, C_TEXT2, OPAQUE, 16);
+ return w;
+}
+
+void ui_hints(const struct hint *h, int n)
+{
+ int base = HINTS_Y + 23;
+ int x = 24;
+ for (int i = 0; i < n; i++)
+ {
+ x += ui_keycap(x, base, h[i].key) + 8;
+ x += fos_text(cv, &fos_font_sm, x, base - 1, h[i].label, C_TEXT3, OPAQUE, 0) + 22;
+ }
+}
+
+/* overlay text: coverage onto the panel greys, or the accent */
+int ui_photo_text(const struct fos_font *f, int x, int y, const char *s, int accent, int align)
+{
+ static const uint8_t grey[16] = { 0, PX_G1, PX_G1, PX_G2, PX_G2, PX_G3, PX_G3, PX_G3, PX_G4, PX_G4,
+ PX_G5, PX_G5, PX_G5, PX_WHITE, PX_WHITE, PX_WHITE };
+ static const uint8_t amber[16] = { 0, PX_G1, PX_G1, PX_G2, PX_AMBER2, PX_AMBER2, PX_AMBER2, PX_AMBER2,
+ PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER };
+ int w = fos_text_w(f, s, accent ? 40 : 0);
+ if (align == 1) x -= w / 2;
+ else if (align == 2) x -= w;
+ fos_text_map(cv->px, cv->pitch, FOS_W, FOS_H, f, x, y, s, accent ? amber : grey, accent ? 40 : 0);
+ return w;
+}
+
+void ui_dots(int x, int y, int n, int filled, fcol on)
+{
+ for (int i = 0; i < n; i++)
+ {
+ if (i < filled)
+ fos_rrect(cv, x + i * 13, y, 10, 4, 2, on, OPAQUE);
+ else
+ fos_rrect(cv, x + i * 13, y, 10, 4, 2, FC(RAMP_GRAY, 46), OPAQUE);
+ }
+}
+
+void ui_toast(const char *msg)
+{
+ snprintf(toast_msg, sizeof(toast_msg), "%s", msg);
+ toast_t = 0;
+}
+
+int ui_toast_up()
+{
+ return toast_t < TOAST_LEN;
+}
+
+static void toast_draw()
+{
+ if (toast_t >= TOAST_LEN) return;
+ float in = clampf(toast_t / 180.0f, 0, 1), out = clampf((TOAST_LEN - toast_t) / 300.0f, 0, 1);
+ float k = ease_out(in) * out;
+ int a = (int) (k * 256);
+ int w = fos_text_w(&fos_font_sm, toast_msg, 0) + 36;
+ int y = HINTS_Y - 38 + (int) ((1 - ease_out(in)) * 10);
+ fos_rrect(cv, 360 - w / 2, y, w, 32, 16, FC(RAMP_GRAY, 34), a);
+ fos_rrect_line(cv, 360 - w / 2, y, w, 32, 16, 1, FC(RAMP_GRAY, 58), a);
+ fos_text_c(cv, &fos_font_sm, 360, y + 21, toast_msg, C_TEXT, a, 0);
+}
+
+void ui_sheet(float s, const char *title, const char *body, const char *yes, const char *no)
+{
+ ui_sheet3(s, title, body, yes, 0, no);
+}
+
+void ui_sheet3(float s, const char *title, const char *body, const char *yes, const char *alt, const char *no)
+{
+ if (s <= 0.002f) return;
+ int sh = 150;
+ int y = FOS_H - (int) (sh * ease_out(s)) + 6;
+ fos_scale_levels(cv, 0, 0, FOS_W, y + 18, (int) (256 - s * 130)); /* what shows above it */
+ fos_rrect(cv, 12, y, FOS_W - 24, sh + 20, 18, FC(RAMP_GRAY, 24), OPAQUE);
+ fos_rrect_line(cv, 12, y, FOS_W - 24, sh + 20, 18, 1, FC(RAMP_GRAY, 48), OPAQUE);
+ fos_text(cv, &fos_font_lg, 40, y + 44, title, C_TEXT, OPAQUE, 0);
+ fos_text(cv, &fos_font_sm, 40, y + 74, body, C_TEXT2, OPAQUE, 0);
+ int base = y + 118;
+ int x = 40;
+ x += ui_keycap(x, base, "SET") + 8;
+ x += fos_text(cv, &fos_font_md, x, base, yes, C_ACCENT, OPAQUE, 0) + 28;
+ if (alt)
+ {
+ x += ui_keycap(x, base, "INFO") + 8;
+ x += fos_text(cv, &fos_font_md, x, base, alt, C_TEXT, OPAQUE, 0) + 28;
+ }
+ x += ui_keycap(x, base, "MENU") + 8;
+ fos_text(cv, &fos_font_md, x, base, no, C_TEXT2, OPAQUE, 0);
+}
+
+/* small line icons, about 26 px */
+void ui_icon(int kind, int cx, int cy, fcol c, int a)
+{
+ int X = cx * 256, Y = cy * 256;
+ int w = 2 * 256;
+ switch (kind)
+ {
+ case ICON_FILM: /* a canister from the side, leader out */
+ fos_rrect_line(cv, cx - 8, cy - 10, 13, 21, 3, 2, c, a);
+ fos_fill(cv, cx - 5, cy - 13, 7, 3, c);
+ fos_rrect(cv, cx + 5, cy - 4, 8, 9, 1, c, a);
+ break;
+ case ICON_ROLL: /* a strip of two frames */
+ fos_rrect_line(cv, cx - 12, cy - 9, 24, 18, 2, 2, c, a);
+ for (int i = 0; i < 4; i++)
+ {
+ fos_fill(cv, cx - 9 + i * 6, cy - 7, 3, 2, c);
+ fos_fill(cv, cx - 9 + i * 6, cy + 5, 3, 2, c);
+ }
+ fos_fill(cv, cx - 1, cy - 4, 2, 8, c);
+ break;
+ case ICON_FINDER: /* the focusing screen */
+ fos_rrect_line(cv, cx - 12, cy - 9, 24, 18, 2, 2, c, a);
+ fos_ring(cv, X, Y, 5 * 256, w, c, a);
+ fos_line(cv, X - 5 * 256, Y, X + 5 * 256, Y, 300, c, a);
+ break;
+ case ICON_LENS: /* an aperture */
+ for (int i = 0; i < 6; i++)
+ {
+ int t = i * 65536 / 6 + 4000;
+ fos_line(cv, X + fos_cos(t) * 11 / 16, Y + fos_sin(t) * 11 / 16,
+ X + fos_cos(t + 65536 / 6) * 11 / 16, Y + fos_sin(t + 65536 / 6) * 11 / 16, w, c, a);
+ fos_line(cv, X + fos_cos(t) * 11 / 16, Y + fos_sin(t) * 11 / 16,
+ X + fos_cos(t + 65536 / 3) * 5 / 16, Y + fos_sin(t + 65536 / 3) * 5 / 16, 350, c, a);
+ }
+ break;
+ case ICON_PRINTS: /* two prints, the front one with a hill and a sun */
+ fos_fill(cv, cx - 13, cy - 11, 2, 14, c);
+ fos_fill(cv, cx - 13, cy - 11, 18, 2, c);
+ fos_rrect_line(cv, cx - 8, cy - 6, 21, 16, 2, 2, c, a);
+ fos_tri(cv, cx + 1, cy + 5, 7, 3, c, a);
+ fos_disc(cv, (cx + 8) * 256, (cy - 1) * 256, 2 * 256, c, a);
+ break;
+ case ICON_SYSTEM: /* a gear */
+ fos_ring(cv, X, Y, 7 * 256, 3 * 256, c, a);
+ for (int i = 0; i < 8; i++)
+ {
+ int t = i * 65536 / 8;
+ fos_line(cv, X + fos_cos(t) * 8 / 16, Y + fos_sin(t) * 8 / 16,
+ X + fos_cos(t) * 12 / 16, Y + fos_sin(t) * 12 / 16, 3 * 256, c, a);
+ }
+ break;
+ }
+}
+
+/* ---------------------------------------------------------------- the aperture */
+
+#define BLADES 7
+
+/* the blades around an opening of radius r px centred on (cx8, cy8):
+ * each blade is the region beyond one edge of the opening, wedged between
+ * the extended edges of its neighbours */
+static void blades(int cx8, int cy8, int r, int angle, int reach, int shade0)
+{
+ int vx[BLADES], vy[BLADES], dx[BLADES], dy[BLADES];
+ for (int k = 0; k < BLADES; k++)
+ {
+ int a = angle + k * 65536 / BLADES;
+ vx[k] = cx8 + fos_cos(a) * r / 16;
+ vy[k] = cy8 + fos_sin(a) * r / 16;
+ }
+ for (int k = 0; k < BLADES; k++)
+ {
+ int j = (k + 1) % BLADES;
+ int ex = (vx[j] - vx[k]) >> 8, ey = (vy[j] - vy[k]) >> 8;
+ int len = fos_isqrt((unsigned) (ex * ex + ey * ey));
+ if (!len)
+ {
+ /* fully closed: edge directions from the angle alone */
+ int a = angle + k * 65536 / BLADES + 65536 / 4 + 65536 / (2 * BLADES);
+ dx[k] = fos_cos(a); dy[k] = fos_sin(a);
+ }
+ else { dx[k] = ex * 4096 / len; dy[k] = ey * 4096 / len; }
+ }
+ for (int k = 0; k < BLADES; k++)
+ {
+ int p = (k + BLADES - 1) % BLADES;
+ int pts[6] = {
+ vx[k], vy[k],
+ vx[k] + dx[k] * reach / 16, vy[k] + dy[k] * reach / 16,
+ vx[k] + dx[p] * reach / 16, vy[k] + dy[p] * reach / 16,
+ };
+ int shade = shade0 + (k * 37 % 7) * 2;
+ fos_convex(cv, pts, 3, FC(RAMP_METAL, shade), OPAQUE);
+ }
+ /* a lit edge on every blade, and a shadow where blades overlap */
+ for (int k = 0; k < BLADES; k++)
+ {
+ int j = (k + 1) % BLADES;
+ int p = (k + BLADES - 1) % BLADES;
+ if (r > 2)
+ fos_line(cv, vx[k], vy[k], vx[j], vy[j], 384, FC(RAMP_METAL, shade0 + 72), OPAQUE);
+ /* the shadow fades into the blades: only near the opening */
+ int sl = reach < 2 * r + 60 ? reach : 2 * r + 60;
+ fos_line(cv, vx[k], vy[k], vx[k] + dx[p] * sl / 16, vy[k] + dy[p] * sl / 16,
+ 300, FC(RAMP_METAL, shade0 / 3), OPAQUE);
+ }
+}
+
+void ui_iris(int open, int angle)
+{
+ if (open >= 4096) return;
+ /* opening radius: 0 .. a bit past the corners */
+ blades(360 * 256, 240 * 256, (int) ((int64_t) 450 * open / 4096), angle, 1400, 20);
+}
+
+void ui_aperture(int cx, int cy, int R, int open, int angle)
+{
+ struct fos_canvas save = *cv;
+ fos_clip(cv, cx - R - 2, cy - R - 2, cx + R + 3, cy + R + 3);
+ blades(cx * 256 + 128, cy * 256 + 128, R * open / 4096, angle, 2 * R + 24, 24);
+ /* outside the barrel the background comes back, with a soft edge */
+ int in = (R * 16 - 8) * (R * 16 - 8), out = (R * 16 + 8) * (R * 16 + 8);
+ for (int y = cv->cy0; y < cv->cy1; y++)
+ {
+ int dy = (y - cy) * 16;
+ /* |x - cx| <= xi: inside the opening; >= xo: background only */
+ int xi = dy * dy < in ? fos_isqrt(in - dy * dy) >> 4 : -1;
+ int xo = dy * dy < out ? (fos_isqrt(out - dy * dy) >> 4) + 1 : 0;
+ for (int x = cv->cx0; x < cv->cx1; x++)
+ {
+ int ax = x < cx ? cx - x : x - cx;
+ if (ax <= xi) { x = cx + xi; continue; }
+ if (ax >= xo) { cv->px[y * cv->pitch + x] = ui_bg[y * FOS_W + x]; continue; }
+ int dx = (x - cx) * 16;
+ int d2 = dx * dx + dy * dy;
+ if (d2 <= in) continue;
+ int d = fos_isqrt(d2) - R * 16; /* 1/16 px outside */
+ int a = fos_clamp(128 + d * 16, 0, 256);
+ uint8_t bg = ui_bg[y * FOS_W + x];
+ uint8_t *p = &cv->px[y * cv->pitch + x];
+ if (a >= 256) *p = bg;
+ else
+ {
+ fcol c = fos_colour_of(bg);
+ *p = fos_mix(*p, FC_RAMP(c), LV12(FC_LEVEL(c)), a);
+ }
+ }
+ }
+ *cv = save;
+ /* the barrel */
+ fos_ring(cv, cx * 256 + 128, cy * 256 + 128, R * 256 + 256, 3 * 256, FC(RAMP_METAL, 70), OPAQUE);
+ fos_ring(cv, cx * 256 + 128, cy * 256 + 128, R * 256 + 3 * 256, 2 * 256, FC(RAMP_METAL, 28), OPAQUE);
+}
+
+/* ---------------------------------------------------------------- boot */
+
+/* power on: a lens aperture opens on the name */
+static void boot_draw(int t)
+{
+ if (t <= 40)
+ memset(ui_bg, fos_ix(FC(RAMP_GRAY, 6)), FOS_W * FOS_H);
+ fos_fill(cv, 0, 0, FOS_W, FOS_H, FC(RAMP_GRAY, 6));
+ float k = clampf((t - 150) / 900.0f, 0, 1);
+ float e = ease_out(k);
+ int open = (int) (60 + e * 2200);
+ ui_aperture(360, 186, 50, open, 2000 + (int) (e * 7000));
+ /* a warm glint through the opening */
+ fos_disc(cv, 360 * 256, 186 * 256, (int) (open * 50 / 4096) * 200, C_ACCENT, (int) (e * 120));
+ float tk = clampf((t - 450) / 700.0f, 0, 1);
+ int a = (int) (ease_out(tk) * 256);
+ int track = (int) (160 - 96 * ease_out(tk));
+ fos_text_c(cv, &fos_font_lg, 360, 290, FOS_NAME, C_TEXT, a, track);
+ fos_text_c(cv, &fos_font_xs, 360, 318, "35 MM FILM SYSTEM", C_TEXT3, (int) (ease_out(clampf((t - 750) / 600.0f, 0, 1)) * 256), 48);
+ ui_damage_all();
+}
+
+/* ---------------------------------------------------------------- navigation */
+
+void ui_go(int to, int arg, int how)
+{
+ /* keep what is on screen now; the new screen slides over it */
+ memcpy(buf_snap, cv->px, FOS_W * FOS_H);
+ screen_from = screen;
+ if (screen == SCR_SHELF) shelf_leave();
+ if (screen == SCR_DEVELOP) develop_leave();
+ if (screen == SCR_PRINTS) prints_leave();
+ screen = to;
+ tr_how = how;
+ tr_t = 0;
+ tr_len = how == GO_FADE ? 520 : 340;
+ ui_clobbered = 1; /* the new screen starts from nothing */
+ switch (to)
+ {
+ case SCR_SHELF: shelf_enter(arg); break;
+ case SCR_HOME: home_enter(arg); break;
+ case SCR_PAGE: page_enter(arg); break;
+ case SCR_ROLL: roll_enter(arg); break;
+ case SCR_DARK: dark_enter(arg); break;
+ case SCR_DEVELOP: develop_enter(arg); break;
+ case SCR_PRINTS: prints_enter(arg); break;
+ }
+ ui_damage_all();
+}
+
+int ui_settled()
+{
+ return !(tr_len && tr_t < tr_len) && !leaving && enter_t >= ENTER_LEN;
+}
+
+int ui_from()
+{
+ return screen_from;
+}
+
+void ui_leave()
+{
+ if (leaving) return;
+ leaving = 1;
+ leave_t = 0;
+}
+
+/* ---------------------------------------------------------------- the loop */
+
+static void screen_key(int k)
+{
+ switch (screen)
+ {
+ case SCR_BOOT:
+ if (boot_then_leave) ui_leave();
+ else ui_go(SCR_SHELF, 0, GO_FADE);
+ break;
+ case SCR_SHELF: shelf_key(k); break;
+ case SCR_HOME: home_key(k); break;
+ case SCR_PAGE: page_key(k); break;
+ case SCR_ROLL: roll_key(k); break;
+ case SCR_DARK: dark_key(k); break;
+ case SCR_DEVELOP: develop_key(k); break;
+ case SCR_PRINTS: prints_key(k); break;
+ }
+}
+
+static int screen_update(int dt)
+{
+ switch (screen)
+ {
+ case SCR_SHELF: return shelf_update(dt);
+ case SCR_HOME: return home_update(dt);
+ case SCR_PAGE: return page_update(dt);
+ case SCR_ROLL: return roll_update(dt);
+ case SCR_DARK: return dark_update(dt);
+ case SCR_DEVELOP: return develop_update(dt);
+ case SCR_PRINTS: return prints_update(dt);
+ }
+ return 0;
+}
+
+static void screen_draw()
+{
+ switch (screen)
+ {
+ case SCR_SHELF: shelf_draw(); break;
+ case SCR_HOME: home_draw(); break;
+ case SCR_PAGE: page_draw(); break;
+ case SCR_ROLL: roll_draw(); break;
+ case SCR_DARK: dark_draw(); break;
+ case SCR_DEVELOP: develop_draw(); break;
+ case SCR_PRINTS: prints_draw(); break;
+ }
+}
+
+/* the screen change: the old frame (snapshot) and the new one, composed a
+ * row at a time straight into the presented rows */
+static uint8_t row_buf[FOS_W];
+static uint8_t dim_lut[256];
+
+/* row_buf[x0..x1): the dimmed layer where it has pixels (u0..u1), else bg */
+static void dim_run(uint8_t *row, const uint8_t *urow, int x0, int x1, int u0, int u1, uint8_t bg)
+{
+ int a = fos_clamp(u0, x0, x1), b = fos_clamp(u1, a, x1);
+ memset(row + x0, bg, a - x0);
+ int x = a;
+ for (; x + 4 <= b; x += 4)
+ {
+ row[x] = dim_lut[urow[x]];
+ row[x + 1] = dim_lut[urow[x + 1]];
+ row[x + 2] = dim_lut[urow[x + 2]];
+ row[x + 3] = dim_lut[urow[x + 3]];
+ }
+ for (; x < b; x++)
+ row[x] = dim_lut[urow[x]];
+ memset(row + b, bg, x1 - b);
+}
+
+static void present_transition(float t)
+{
+ float e = ease_out(t);
+ int how = tr_how;
+ int shift_new, shift_old, dim;
+ if (how == GO_PUSH) { shift_new = (int) ((1 - e) * FOS_W); shift_old = -(int) (e * FOS_W * 0.3f); dim = (int) (256 - e * 150); }
+ else if (how == GO_POP) { shift_new = -(int) ((1 - e) * FOS_W * 0.3f); shift_old = (int) (e * FOS_W); dim = (int) (106 + e * 150); }
+ else { shift_new = 0; shift_old = 0; dim = 0; }
+
+ if (how == GO_FADE)
+ {
+ /* dip: the old screen sinks into the dark, the new one rises from it */
+ int k = t < 0.45f ? (int) ((1 - t / 0.45f) * 256) : (int) (ease_out((t - 0.45f) / 0.55f) * 256);
+ const uint8_t *src = t < 0.45f ? buf_snap : cv->px;
+ for (int i = 0; i < 256; i++)
+ {
+ fcol c = fos_colour_of(i);
+ dim_lut[i] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * k / 256));
+ }
+ for (int y = 0; y < FOS_H; y++)
+ {
+ for (int x = 0; x < FOS_W; x++)
+ row_buf[x] = dim_lut[src[y * FOS_W + x]];
+ fos_port_present(row_buf, FOS_W, y, y + 1);
+ }
+ return;
+ }
+
+ for (int i = 0; i < 256; i++)
+ {
+ fcol c = fos_colour_of(i);
+ dim_lut[i] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * dim / 256));
+ }
+ const uint8_t *top = how == GO_PUSH ? cv->px : buf_snap; /* the sliding layer */
+ const uint8_t *under = how == GO_PUSH ? buf_snap : cv->px;
+ int shift_top = how == GO_PUSH ? shift_new : shift_old;
+ int shift_under = how == GO_PUSH ? shift_old : shift_new;
+ uint8_t bg = fos_ix(C_BG);
+ /* the sliding layer covers [t0, t1); the dimmed one shows elsewhere
+ * where it has pixels, [u0, u1) */
+ int t0 = fos_clamp(shift_top, 0, FOS_W), t1 = fos_clamp(shift_top + FOS_W, 0, FOS_W);
+ int u0 = fos_clamp(shift_under, 0, FOS_W), u1 = fos_clamp(shift_under + FOS_W, 0, FOS_W);
+ for (int y = 0; y < FOS_H; y++)
+ {
+ const uint8_t *trow = top + y * FOS_W, *urow = under + y * FOS_W - shift_under;
+ dim_run(row_buf, urow, 0, t0, u0, u1, bg);
+ dim_run(row_buf, urow, t1, FOS_W, u0, u1, bg);
+ if (t1 > t0)
+ memcpy(row_buf + t0, trow + (t0 - shift_top), t1 - t0);
+ /* a soft shadow on the edge of the sliding layer */
+ for (int s = 1; s <= 10; s++)
+ {
+ int x = shift_top - s;
+ if (x >= 0 && x < FOS_W)
+ {
+ fcol c = fos_colour_of(row_buf[x]);
+ row_buf[x] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * (156 + s * 10) / 256));
+ }
+ }
+ fos_port_present(row_buf, FOS_W, y, y + 1);
+ }
+}
+
+static int ui_alloc()
+{
+ buf_cv = fos_port_alloc(FOS_W * FOS_H);
+ buf_bg = fos_port_alloc(FOS_W * FOS_H);
+ buf_snap = fos_port_alloc(FOS_W * FOS_H);
+ if (!buf_cv || !buf_bg || !buf_snap)
+ {
+ fos_port_free(buf_cv); fos_port_free(buf_bg); fos_port_free(buf_snap);
+ buf_cv = buf_bg = buf_snap = 0;
+ return 0;
+ }
+ fos_canvas_init(&canvas, buf_cv, FOS_W, FOS_W, FOS_H);
+ cv = &canvas;
+ ui_bg = buf_bg;
+ return 1;
+}
+
+static void ui_free()
+{
+ ui_cans_free();
+ fos_port_free(buf_plain);
+ buf_plain = 0;
+ fos_port_free(buf_cv); fos_port_free(buf_bg); fos_port_free(buf_snap);
+ buf_cv = buf_bg = buf_snap = 0;
+}
+
+void fos_ui_init()
+{
+ fos_gfx_init();
+}
+
+/* how long frames take: drawing, copying to the screen, and the rest
+ * between them. A slow camera gets simpler canisters rather than a
+ * stuttering shelf. */
+static struct fos_stat stat;
+static int stat_since, frame_end;
+
+static void frame_stats(int draw_ms, int present_ms)
+{
+ static int slow, quick;
+ stat.frames++;
+ stat.cans_ms += ui_cans_ms;
+ ui_cans_ms = 0;
+ stat.draw_ms += draw_ms;
+ stat.present_ms += present_ms;
+ if (draw_ms + present_ms > stat.worst_ms) stat.worst_ms = draw_ms + present_ms;
+ frame_end = fos_port_ms();
+ if (ui_now - stat_since < 1000) return;
+ fos_port_stat(&stat);
+ int avg = (stat.draw_ms + stat.present_ms) / stat.frames;
+ if (avg > 50) { slow++; quick = 0; }
+ else if (avg < 26) { quick++; slow = 0; }
+ else slow = quick = 0;
+ if (slow >= 1 && fos_can_quality > 0) { fos_can_quality--; slow = 0; }
+ if (quick >= 3 && fos_can_quality < 2) { fos_can_quality++; quick = 0; }
+ memset(&stat, 0, sizeof(stat));
+ stat_since = ui_now;
+}
+
+/* while animating: rest what is left of a frame (about 35 a second), but
+ * always a little, so the camera's own tasks get to run */
+#define FRAME_PERIOD 28
+static int frame_rest(int frame_start)
+{
+ return fos_clamp(FRAME_PERIOD - (fos_port_ms() - frame_start), 1, 10);
+}
+
+static int is_repeating(int k)
+{
+ return k == FK_LEFT || k == FK_RIGHT || k == FK_UP || k == FK_DOWN;
+}
+
+void fos_ui_run(int open)
+{
+ int t_open = fos_port_ms();
+ if (!ui_alloc())
+ return;
+ fos_port_roll(&ui_roll);
+ quit = 0;
+ leaving = 0;
+ held_key = 0;
+ toast_t = TOAST_LEN;
+ screen = SCR_NONE;
+ screen_from = SCR_NONE;
+ enter_t = 0;
+
+ /* what is under the shutter while it closes: LiveView */
+ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
+ ui_clobbered = 1;
+ fos_port_palette();
+
+ boot_then_leave = open == FOS_OPEN_BOOT_LV;
+ if (open == FOS_OPEN_BOOT || open == FOS_OPEN_BOOT_LV)
+ screen = SCR_BOOT, enter_t = ENTER_LEN;
+ else
+ {
+ switch (open)
+ {
+ case FOS_OPEN_HOME: screen = SCR_HOME; home_enter(0); break;
+ case FOS_OPEN_PRINTS: screen = SCR_PRINTS; prints_enter(PRINTS_ALONE); break;
+ case FOS_OPEN_END: screen = SCR_ROLL; roll_enter(1); break;
+ case FOS_OPEN_DARKROOM: screen = SCR_DARK; dark_enter(0); break;
+ default: screen = SCR_SHELF; shelf_enter(0); break;
+ }
+ }
+ tr_how = 0; tr_t = tr_len = 0;
+
+ int last = fos_port_ms();
+ int boot_t = 0;
+ int opened = 0;
+ memset(&stat, 0, sizeof(stat));
+ stat_since = frame_end = 0;
+ while (!quit)
+ {
+ int now = fos_port_ms();
+ int dt = fos_clamp(now - last, 0, 60);
+ last = now;
+ /* the rest after the last animated frame, slept or taken by others */
+ if (frame_end) { stat.rest_ms += now - frame_end; frame_end = 0; }
+ ui_now = now;
+
+ if (fos_port_abort())
+ break;
+
+ /* keys, with auto-repeat for held arrows */
+ int k;
+ while ((k = fos_port_key()) != FK_NONE)
+ {
+ if (k & FK_RELEASE)
+ {
+ if ((k & 0xFF) == held_key) held_key = 0;
+ continue;
+ }
+ if (is_repeating(k)) { held_key = k; held_since = now; held_last = now; }
+ if (leaving || enter_t < ENTER_LEN) continue;
+ screen_key(k);
+ }
+ /* a release that never came must not scroll forever */
+ if (held_key && now - held_since > 3000)
+ held_key = 0;
+ if (held_key && now - held_since > 420 && now - held_last > 95 && !leaving)
+ {
+ held_last = now;
+ screen_key(held_key);
+ }
+
+ int moving = 0;
+ if (screen == SCR_BOOT)
+ {
+ boot_t += dt;
+ boot_draw(boot_t);
+ moving = 1;
+ if (boot_t > 1700 && boot_then_leave)
+ {
+ ui_leave();
+ boot_t = -100000; /* once */
+ }
+ else if (boot_t > 1700)
+ ui_go(SCR_SHELF, 0, GO_FADE);
+ }
+ else
+ {
+ moving |= screen_update(dt);
+ if (tr_len && tr_t < tr_len) { tr_t += dt; moving = 1; }
+ }
+
+ int in_tr = tr_len && tr_t < tr_len;
+ int t_draw = fos_port_ms();
+ if (enter_t < ENTER_LEN || leaving)
+ {
+ /* the shutter: closes over LiveView, opens on us (and the
+ * reverse when leaving) */
+ int t;
+ if (leaving) { leave_t += dt; t = leave_t; }
+ else { enter_t += dt; t = enter_t; }
+ if (screen != SCR_BOOT) screen_draw();
+ int open_k;
+ int ang = (int) (t * 9);
+ if (leaving)
+ {
+ float f = clampf((float) t / LEAVE_LEN, 0, 1);
+ if (f < 0.35f) open_k = (int) ((1 - ease_out(f / 0.35f)) * 4096);
+ else
+ {
+ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
+ open_k = (int) (ease_out((f - 0.35f) / 0.65f) * 4096);
+ }
+ if (t >= LEAVE_LEN) quit = 1;
+ }
+ else
+ {
+ float f = clampf((float) t / ENTER_LEN, 0, 1);
+ if (f < 0.4f)
+ {
+ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
+ open_k = (int) ((1 - ease_out(f / 0.4f)) * 4096);
+ }
+ else open_k = (int) (ease_out((f - 0.4f) / 0.6f) * 4096);
+ }
+ ui_iris(open_k, ang);
+ ui_clobbered = 1;
+ fos_port_present(cv->px, FOS_W, 0, FOS_H);
+ if (!opened) { opened = 1; stat.open_ms = fos_port_ms() - t_open; }
+ dmg_y0 = FOS_H; dmg_y1 = 0;
+ fos_port_sleep(frame_rest(now));
+ continue;
+ }
+
+ int t_present;
+ if (in_tr)
+ {
+ screen_draw();
+ t_present = fos_port_ms();
+ present_transition((float) tr_t / tr_len);
+ ui_clobbered = 1; /* the screen only reached the panel composed */
+ dmg_y0 = FOS_H; dmg_y1 = 0;
+ }
+ else
+ {
+ if (toast_t < TOAST_LEN)
+ {
+ toast_t += dt;
+ moving = 1;
+ ui_damage(HINTS_Y - 50, HINTS_Y);
+ ui_clobbered = 1; /* the screen must paint under it again */
+ }
+ if (screen != SCR_BOOT && (dmg_y1 > dmg_y0 || moving))
+ {
+ screen_draw();
+ toast_draw();
+ }
+ t_present = fos_port_ms();
+ if (dmg_y1 > dmg_y0)
+ {
+ fos_port_present(cv->px + dmg_y0 * FOS_W, FOS_W, dmg_y0, dmg_y1);
+ if (!opened) { opened = 1; stat.open_ms = fos_port_ms() - t_open; }
+ }
+ dmg_y0 = FOS_H; dmg_y1 = 0;
+ }
+ if (moving || in_tr)
+ frame_stats(t_present - t_draw, fos_port_ms() - t_present);
+ fos_port_sleep(moving || in_tr ? frame_rest(now) : 40);
+ }
+ if (stat.frames || stat.open_ms) fos_port_stat(&stat); /* the last part second */
+ if (screen == SCR_SHELF) shelf_leave();
+ if (screen == SCR_DEVELOP) develop_leave();
+ if (screen == SCR_PRINTS) prints_leave();
+ dark_free();
+ ui_free();
+}
diff --git a/ml-dev/filmos/fos_ui.h b/ml-dev/filmos/fos_ui.h
new file mode 100644
index 0000000..b5f0d35
--- /dev/null
+++ b/ml-dev/filmos/fos_ui.h
@@ -0,0 +1,151 @@
+/* fos_ui.h: shared between the film OS screens (fos_ui.c, fos_shelf.c,
+ * fos_pages.c). Not used by the camera glue. */
+
+#ifndef _fos_ui_h_
+#define _fos_ui_h_
+
+#include "fos.h"
+
+/* ---------------------------------------------------------------- style */
+
+#define C_BG FC(RAMP_GRAY, 11)
+#define C_PANEL FC(RAMP_GRAY, 21)
+#define C_PANEL_HI FC(RAMP_GRAY, 32)
+#define C_LINE FC(RAMP_GRAY, 40)
+#define C_TEXT FC(RAMP_GRAY, 240)
+#define C_TEXT2 FC(RAMP_GRAY, 170)
+#define C_TEXT3 FC(RAMP_GRAY, 112)
+#define C_ACCENT FC(RAMP_AMBER, 186)
+#define C_ACCENT2 FC(RAMP_AMBER, 120)
+#define C_RED FC(RAMP_RED, 150)
+
+#define STATUS_H 36
+#define HINTS_Y 444
+
+/* ---------------------------------------------------------------- shared state */
+
+extern struct fos_canvas *cv; /* what the screens draw into */
+extern uint8_t *ui_bg; /* background of the current screen, same layout */
+extern int ui_now; /* ms */
+extern struct fos_roll ui_roll;
+
+/* set when something else drew over the canvas (the shutter, a screen
+ * change): screens that redraw only what moved must redraw it all */
+extern int ui_clobbered;
+
+/* rows that changed this frame (the loop presents them) */
+void ui_damage(int y0, int y1);
+void ui_damage_all();
+
+/* ---------------------------------------------------------------- animation */
+
+struct spring { float x, v; };
+
+/* steps towards target; returns 1 while still moving */
+int spring_step(struct spring *s, float target, int dt, float hz, float zeta);
+float ease_out(float t); /* cubic */
+float ease_in_out(float t);
+float clampf(float v, float lo, float hi);
+
+/* ---------------------------------------------------------------- navigation */
+
+enum { SCR_NONE, SCR_BOOT, SCR_SHELF, SCR_HOME, SCR_PAGE, SCR_ROLL, SCR_DARK, SCR_DEVELOP, SCR_PRINTS };
+enum { GO_PUSH = 1, GO_POP = -1, GO_FADE = 0 };
+
+void ui_go(int screen, int arg, int how);
+void ui_leave(); /* back to LiveView, shutter opening on it */
+int ui_from(); /* screen we came from */
+int ui_settled(); /* no screen change, shutter or iris under way */
+
+/* ---------------------------------------------------------------- widgets */
+
+void ui_bg_restore(int x, int y, int w, int h);
+void ui_to_bg(int on); /* widgets draw into ui_bg instead of the screen */
+void ui_bg_plain(); /* the usual dark backdrop into ui_bg */
+void ui_status_bar(const char *title);
+
+struct hint { const char *key; const char *label; };
+void ui_hints(const struct hint *h, int n);
+int ui_keycap(int x, int base, const char *key); /* returns width */
+
+void ui_dots(int x, int y, int n, int filled, fcol on); /* 1..5 rating */
+
+/* text over a photograph (its palette up, fos_port_photo): coverage onto
+ * the fixed greys, or the amber; align 0 left, 1 centred, 2 right of x.
+ * Returns the width. */
+int ui_photo_text(const struct fos_font *f, int x, int y, const char *s, int accent, int align);
+
+/* a short message in a pill above the hints, fading after a moment */
+void ui_toast(const char *msg);
+int ui_toast_up(); /* 1 while one is showing */
+
+/* a question sliding up from the bottom; s = 0..1 how far it is in */
+void ui_sheet(float s, const char *title, const char *body, const char *yes, const char *no);
+/* the same with a third answer on INFO */
+void ui_sheet3(float s, const char *title, const char *body, const char *yes, const char *alt, const char *no);
+
+enum { ICON_FILM, ICON_ROLL, ICON_FINDER, ICON_LENS, ICON_SYSTEM, ICON_PRINTS };
+void ui_icon(int kind, int cx, int cy, fcol c, int alpha);
+
+/* the aperture over the whole screen: 0 = closed, 4096 = gone; the
+ * opening shows what is already on the canvas */
+void ui_iris(int open, int angle);
+
+/* a lens aperture inside a barrel of radius R px (same blades, smaller) */
+void ui_aperture(int cx, int cy, int R, int open, int angle);
+
+/* ---------------------------------------------------------------- screens */
+
+void shelf_enter(int arg);
+void shelf_leave();
+void shelf_key(int key);
+int shelf_update(int dt);
+void shelf_draw();
+
+void home_enter(int arg);
+void home_key(int key);
+int home_update(int dt);
+void home_draw();
+
+void page_enter(int arg);
+void page_key(int key);
+int page_update(int dt);
+void page_draw();
+
+void roll_enter(int arg);
+void roll_key(int key);
+int roll_update(int dt);
+void roll_draw();
+
+/* the darkroom (fos_dark.c): arg is a roll number, 0 for the newest */
+void dark_enter(int arg);
+void dark_free(); /* its memory, when the film OS closes */
+void dark_key(int key);
+int dark_update(int dt);
+void dark_draw();
+
+/* developing the rolls queued with dark_queue (arg unused) */
+void dark_queue_clear();
+void dark_queue_add(int roll);
+void develop_enter(int arg);
+void develop_leave();
+void develop_key(int key);
+int develop_update(int dt);
+void develop_draw();
+
+/* prints: arg is a roll number (0: the newest developed); PRINTS_ALONE
+ * or-ed in when opened by PLAY from the camera */
+#define PRINTS_ALONE 0x10000
+void prints_enter(int arg);
+void prints_leave();
+void prints_key(int key);
+int prints_update(int dt);
+void prints_draw();
+
+/* the canisters, kept while the UI is open (fos_shelf.c) */
+struct fos_can *ui_can(int film);
+void ui_cans_free();
+extern int ui_cans_ms; /* time spent drawing canisters, for the frame stats */
+void ui_cans_exposures(int exposures);
+
+#endif
diff --git a/ml-dev/filmos/preview/boot.png b/ml-dev/filmos/preview/boot.png
new file mode 100644
index 0000000..dafbd0f
Binary files /dev/null and b/ml-dev/filmos/preview/boot.png differ
diff --git a/ml-dev/filmos/preview/darkroom.png b/ml-dev/filmos/preview/darkroom.png
new file mode 100644
index 0000000..ef529ba
Binary files /dev/null and b/ml-dev/filmos/preview/darkroom.png differ
diff --git a/ml-dev/filmos/preview/developing-line.png b/ml-dev/filmos/preview/developing-line.png
new file mode 100644
index 0000000..177ac94
Binary files /dev/null and b/ml-dev/filmos/preview/developing-line.png differ
diff --git a/ml-dev/filmos/preview/developing.png b/ml-dev/filmos/preview/developing.png
new file mode 100644
index 0000000..d6e7a26
Binary files /dev/null and b/ml-dev/filmos/preview/developing.png differ
diff --git a/ml-dev/filmos/preview/end-of-roll.png b/ml-dev/filmos/preview/end-of-roll.png
new file mode 100644
index 0000000..3cc5000
Binary files /dev/null and b/ml-dev/filmos/preview/end-of-roll.png differ
diff --git a/ml-dev/filmos/preview/home.png b/ml-dev/filmos/preview/home.png
new file mode 100644
index 0000000..8a60fd0
Binary files /dev/null and b/ml-dev/filmos/preview/home.png differ
diff --git a/ml-dev/filmos/preview/hud.png b/ml-dev/filmos/preview/hud.png
new file mode 100644
index 0000000..306a0e7
Binary files /dev/null and b/ml-dev/filmos/preview/hud.png differ
diff --git a/ml-dev/filmos/preview/lens.png b/ml-dev/filmos/preview/lens.png
new file mode 100644
index 0000000..8f7d828
Binary files /dev/null and b/ml-dev/filmos/preview/lens.png differ
diff --git a/ml-dev/filmos/preview/loaded.png b/ml-dev/filmos/preview/loaded.png
new file mode 100644
index 0000000..86e7dc4
Binary files /dev/null and b/ml-dev/filmos/preview/loaded.png differ
diff --git a/ml-dev/filmos/preview/prints-frame.png b/ml-dev/filmos/preview/prints-frame.png
new file mode 100644
index 0000000..cb9385b
Binary files /dev/null and b/ml-dev/filmos/preview/prints-frame.png differ
diff --git a/ml-dev/filmos/preview/prints-sheet.png b/ml-dev/filmos/preview/prints-sheet.png
new file mode 100644
index 0000000..3bfede5
Binary files /dev/null and b/ml-dev/filmos/preview/prints-sheet.png differ
diff --git a/ml-dev/filmos/preview/rewind.png b/ml-dev/filmos/preview/rewind.png
new file mode 100644
index 0000000..37b6b1b
Binary files /dev/null and b/ml-dev/filmos/preview/rewind.png differ
diff --git a/ml-dev/filmos/preview/roll.png b/ml-dev/filmos/preview/roll.png
new file mode 100644
index 0000000..6cdcae6
Binary files /dev/null and b/ml-dev/filmos/preview/roll.png differ
diff --git a/ml-dev/filmos/preview/sample.png b/ml-dev/filmos/preview/sample.png
new file mode 100644
index 0000000..020ae17
Binary files /dev/null and b/ml-dev/filmos/preview/sample.png differ
diff --git a/ml-dev/filmos/preview/screen.png b/ml-dev/filmos/preview/screen.png
new file mode 100644
index 0000000..689a5df
Binary files /dev/null and b/ml-dev/filmos/preview/screen.png differ
diff --git a/ml-dev/filmos/preview/shelf-gliding.png b/ml-dev/filmos/preview/shelf-gliding.png
new file mode 100644
index 0000000..24d8a98
Binary files /dev/null and b/ml-dev/filmos/preview/shelf-gliding.png differ
diff --git a/ml-dev/filmos/preview/shelf.gif b/ml-dev/filmos/preview/shelf.gif
new file mode 100644
index 0000000..8a2b067
Binary files /dev/null and b/ml-dev/filmos/preview/shelf.gif differ
diff --git a/ml-dev/filmos/preview/shelf.png b/ml-dev/filmos/preview/shelf.png
new file mode 100644
index 0000000..7aa9a0f
Binary files /dev/null and b/ml-dev/filmos/preview/shelf.png differ
diff --git a/ml-dev/filmos/preview/shutter.png b/ml-dev/filmos/preview/shutter.png
new file mode 100644
index 0000000..0c7022b
Binary files /dev/null and b/ml-dev/filmos/preview/shutter.png differ
diff --git a/ml-dev/filmos/preview/system.png b/ml-dev/filmos/preview/system.png
new file mode 100644
index 0000000..c5945a6
Binary files /dev/null and b/ml-dev/filmos/preview/system.png differ
diff --git a/ml-dev/filmos/preview/viewfinder.png b/ml-dev/filmos/preview/viewfinder.png
new file mode 100644
index 0000000..72cdec3
Binary files /dev/null and b/ml-dev/filmos/preview/viewfinder.png differ
diff --git a/ml-dev/filmos/sim/Makefile b/ml-dev/filmos/sim/Makefile
new file mode 100644
index 0000000..147d78e
--- /dev/null
+++ b/ml-dev/filmos/sim/Makefile
@@ -0,0 +1,31 @@
+# film OS simulator: make && ./out/sim scenes/shelf.txt out/frames/shelf
+SRC = sim.c port_files.c fonts.c films.c ../fos_gfx.c ../fos_film.c ../fos_ui.c ../fos_shelf.c ../fos_pages.c ../fos_hud.c \
+ ../fos_dark.c ../fos_dev.c ../fos_lab.c ../fos_looks.c ../fos_jpeg.c
+CFLAGS = -O2 -g -Wall -Wextra -Wno-unused-parameter -Wdouble-promotion -std=gnu99
+# M-Film's version, as the camera build gets it (VERSION at the top of the repository)
+CFLAGS += -DMFILM_VERSION='"$(shell tr -d " \r\n" < ../../../VERSION)"'
+
+out/sim: $(SRC) ../*.h out/FOSFONT.BIN out/FOSFILMS.BIN
+ mkdir -p out
+ $(CC) $(CFLAGS) -o $@ $(SRC) -lm
+
+# the fonts, as the camera finds them on its card (ML/DATA/FOSFONT.BIN)
+out/FOSFONT.BIN: ../fos_font.c ../tools/fontblob.c ../fos_gfx.h
+ mkdir -p out
+ $(CC) -O2 -I.. -o out/fontblob ../tools/fontblob.c
+ ./out/fontblob $@
+
+# the films beyond the built-in ones (ML/DATA/FOSFILMS.BIN) and the tables
+# baked from their LUTs (films/getluts.py fetches those)
+out/FOSFILMS.BIN: ../tools/genfilms.py ../tools/catalog.py ../../films/films.py ../../films/filmluts.py ../fos_film.c
+ mkdir -p out
+ python3 ../tools/genfilms.py $@ --tables out/lut
+
+clean:
+ rm -rf out
+
+# developing film: ./out/devtest [-f film] [-r raw.u16] in.CR2 out.FOP out.ppm
+DEV = devtest.c port_files.c films.c ../fos_dev.c ../fos_looks.c ../fos_film.c ../fos_gfx.c ../fos_jpeg.c
+out/devtest: $(DEV) ../*.h out/FOSFILMS.BIN
+ mkdir -p out
+ $(CC) $(CFLAGS) -DFOS_DEV_TEST -o $@ $(DEV) -lm
diff --git a/ml-dev/filmos/sim/bench.c b/ml-dev/filmos/sim/bench.c
new file mode 100644
index 0000000..2500ebb
--- /dev/null
+++ b/ml-dev/filmos/sim/bench.c
@@ -0,0 +1,44 @@
+/* bench: how long one shelf frame takes to draw (host), for budgeting */
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "../fos_ui.h"
+
+void sim_fonts(); /* fonts.c */
+void sim_films(); /* films.c */
+void *fos_port_alloc(int size) { return malloc(size); }
+void fos_port_free(void *p) { free(p); }
+int fos_port_get(int s) { return 0; }
+void fos_port_set(int s, int v) {}
+void fos_port_action(int a, int x, int y) {}
+void fos_port_roll(struct fos_roll *r) { r->loaded = 0; }
+void fos_port_clock(char *b, int n) { snprintf(b, n, "09:41"); }
+int fos_port_ms() { return 0; }
+void fos_port_sleep(int ms) {}
+int fos_port_key() { return 0; }
+int fos_port_abort() { return 1; }
+void fos_port_present(const uint8_t *r, int p, int a, int b) {}
+void fos_port_palette() {}
+int fos_port_lens_manual() { return 1; }
+const char *fos_port_lens_name() { return ""; }
+const char *fos_port_version() { return ""; }
+void fos_port_stat(const struct fos_stat *s) { }
+static double now() { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec * 1e3 + t.tv_nsec / 1e6; }
+int main()
+{
+ static uint8_t a[FOS_W * FOS_H], b[FOS_W * FOS_H];
+ static struct fos_canvas c;
+ fos_gfx_init();
+ sim_fonts();
+ sim_films();
+ fos_canvas_init(&c, a, FOS_W, FOS_W, FOS_H);
+ cv = &c; ui_bg = b;
+ shelf_enter(1);
+ for (int i = 0; i < fos_nfilms; i++) ui_can(i);
+ double t0 = now();
+ int n = getenv("N") ? atoi(getenv("N")) : 300;
+ for (int i = 0; i < n; i++) { if (i % 24 == 0) shelf_key(i % 48 ? FK_WHEEL_R : FK_WHEEL_L); shelf_update(16); shelf_draw(); }
+ double t1 = now();
+ printf("shelf frame: %.3f ms on this PC\n", (t1 - t0) / n);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/cantest.c b/ml-dev/filmos/sim/cantest.c
new file mode 100644
index 0000000..8803242
--- /dev/null
+++ b/ml-dev/filmos/sim/cantest.c
@@ -0,0 +1,44 @@
+/* cantest: every canister, front and turned, for checking the label art */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../fos.h"
+
+void sim_fonts(); /* fonts.c */
+void sim_films(); /* films.c */
+
+void *fos_port_alloc(int size) { return malloc(size); }
+void fos_port_free(void *p) { free(p); }
+
+int main(int argc, char **argv)
+{
+ static uint8_t px[FOS_W * FOS_H];
+ struct fos_canvas cv;
+ fos_gfx_init();
+ sim_fonts();
+ sim_films();
+ fos_canvas_init(&cv, px, FOS_W, FOS_W, FOS_H);
+ int page = argc > 1 ? atoi(argv[1]) : 0;
+ int rot = argc > 2 ? atoi(argv[2]) * 65536 / 360 : 0;
+
+ fos_vgrad(&cv, 0, 0, FOS_W, 300, RAMP_GRAY, LV12(30), LV12(12));
+ fos_vgrad(&cv, 0, 300, FOS_W, 180, RAMP_GRAY, LV12(16), LV12(5));
+
+ /* four stocks per page */
+ for (int i = 0; i < 4; i++)
+ {
+ int film = (page * 4 + i) % fos_nfilms;
+ struct fos_can *c = fos_can_new(film, 36);
+ struct fos_can_pose p = { (100 + i * 175) * 256, 300, 256, rot, 256, 256, 70, 0 };
+ fos_can_draw(&cv, c, &p);
+ fos_text_c(&cv, &fos_font_sm, 100 + i * 175, 380, fos_films[film].name, FC(RAMP_GRAY, 200), OPAQUE, 0);
+ fos_can_free(c);
+ }
+ FILE *f = fopen("out/cantest.idx", "wb");
+ fwrite(px, 1, sizeof(px), f);
+ fclose(f);
+ f = fopen("out/pal.bin", "wb");
+ fwrite(fos_pal, 4, 256, f);
+ fclose(f);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/devtest.c b/ml-dev/filmos/sim/devtest.c
new file mode 100644
index 0000000..d5715bb
--- /dev/null
+++ b/ml-dev/filmos/sim/devtest.c
@@ -0,0 +1,150 @@
+/* devtest: develops CR2 files the way the camera does, on a PC.
+ *
+ * ./out/devtest [-f film] [-r frame.u16] in.CR2 out.FOP [out.ppm]
+ * ./out/devtest -S in.CR2 dir the shelf's samples: in.CR2 with every film, dir/Fnnn.BMP
+ *
+ * -r checks the RAW decoder against the samples mkcr2 wrote (--raw);
+ * out.ppm is the print as the screen would show it.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "../fos.h"
+#include "../fos_dev.h"
+
+int fos_port_ms()
+{
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return (int) (t.tv_sec * 1000 + t.tv_nsec / 1000000);
+}
+void *fos_port_alloc(int size) { return malloc(size); }
+int fos_port_dev_cap() { return 0; }
+void fos_port_log(const char *msg) { fprintf(stderr, "%s\n", msg); }
+void fos_port_free(void *p) { free(p); }
+
+/* the decoder's samples, to compare with mkcr2's */
+static uint16_t *raw;
+static int raw_w, raw_h;
+static long bad, seen;
+
+void fos_dev_test_sample(int x, int y, int v)
+{
+ seen++;
+ if (!raw) return;
+ if (x >= raw_w || y >= raw_h || raw[(long) y * raw_w + x] != v)
+ {
+ if (bad++ < 5) fprintf(stderr, "sample %d,%d: %d, expected %d\n", x, y, v,
+ x < raw_w && y < raw_h ? raw[(long) y * raw_w + x] : -1);
+ }
+}
+
+static int load_u16(const char *path)
+{
+ FILE *f = fopen(path, "rb");
+ if (!f) { perror(path); return 0; }
+ /* mkcr2 --raw: just the samples, of the full or the --small sensor */
+ fseek(f, 0, SEEK_END);
+ long n = ftell(f) / 2;
+ fseek(f, 0, SEEK_SET);
+ if (n == 5280L * 3528) { raw_w = 5280; raw_h = 3528; }
+ else if (n == 2640L * 1764) { raw_w = 2640; raw_h = 1764; }
+ else if (n == 1320L * 882) { raw_w = 1320; raw_h = 882; }
+ else
+ {
+ /* mkcr2 --sensor: the other cameras' sensors (LibRaw's identify.cpp) */
+ static const int other[][2] = { { 5568, 3708 }, { 5920, 3950 }, { 5792, 3804 }, { 5344, 3516 },
+ { 5360, 3516 }, { 4832, 3204 }, { 4832, 3228 }, { 4352, 2874 } };
+ for (unsigned i = 0; i < sizeof(other) / sizeof(other[0]); i++)
+ if (n == (long) other[i][0] * other[i][1]) { raw_w = other[i][0]; raw_h = other[i][1]; }
+ }
+ if (!raw_w) { fprintf(stderr, "%s: unknown size\n", path); fclose(f); return 0; }
+ raw = malloc((size_t) n * 2);
+ size_t got = fread(raw, 2, (size_t) n, f);
+ fclose(f);
+ return got == (size_t) n;
+}
+
+static int film_index(const char *key)
+{
+ for (int i = 0; i < fos_nfilms; i++)
+ if (!strcmp(fos_films[i].key, key)) return i;
+ fprintf(stderr, "no film %s\n", key);
+ exit(2);
+}
+
+void sim_films(); /* films.c */
+
+int main(int argc, char **argv)
+{
+ sim_films();
+ int film = 0, a = 1;
+ const char *rawpath = 0;
+ if (argc == 3 && !strcmp(argv[1], "-T"))
+ {
+ /* -T dir: every film's table into dir, as the camera keeps them */
+ fos_dev_cache(argv[2]);
+ for (int i = 0; i < fos_nfilms; i++)
+ if (!fos_dev_table(i)) return 1;
+ return 0;
+ }
+ if (argc == 4 && !strcmp(argv[1], "-S"))
+ {
+ /* FOS_LUT_DIR: the tables the camera will use (made with -T, then baked from LUTs) */
+ if (getenv("FOS_LUT_DIR")) fos_dev_cache(getenv("FOS_LUT_DIR"));
+ for (int i = 0; i < fos_nfilms; i++)
+ {
+ char out[512];
+ snprintf(out, sizeof(out), "%s/F%03d.BMP", argv[3], i);
+ struct fos_dev *d = fos_dev_start(argv[2], out, i, 1, "", "");
+ int p;
+ while ((p = fos_dev_step(d, 40)) >= 0 && p < 1000) {}
+ if (p < 0) { fprintf(stderr, "%s, %s: %s\n", argv[2], fos_films[i].key, fos_dev_error(d)); fos_dev_free(d); return 1; }
+ fos_dev_free(d);
+ }
+ return 0;
+ }
+ for (; a < argc && argv[a][0] == '-'; a += 2)
+ {
+ if (a + 1 >= argc) break;
+ if (!strcmp(argv[a], "-f")) film = film_index(argv[a + 1]);
+ else if (!strcmp(argv[a], "-r")) rawpath = argv[a + 1];
+ }
+ if (argc - a < 2) { fprintf(stderr, "usage: devtest [-f film] [-r frame.u16] in.CR2 out.FOP [out.ppm]\n"
+ " devtest -T dir (the films' tables)\n"
+ " devtest -S in.CR2 dir (the shelf's samples)\n"); return 2; }
+ if (rawpath && !load_u16(rawpath)) return 1;
+
+ /* FOS_LUT_DIR: keep the film tables there, as the camera does */
+ if (getenv("FOS_LUT_DIR")) fos_dev_cache(getenv("FOS_LUT_DIR"));
+ int t0 = fos_port_ms(), steps = 0, p = 0;
+ struct fos_dev *d = fos_dev_start(argv[a], argv[a + 1], film, 1, "2026-10-22 17:45", "2.8");
+ while ((p = fos_dev_step(d, 40)) >= 0 && p < 1000) steps++;
+ if (p < 0) { fprintf(stderr, "%s: %s\n", argv[a], fos_dev_error(d)); fos_dev_free(d); return 1; }
+ printf("%s: %d ms, %d steps\n", argv[a], fos_port_ms() - t0, steps);
+ fos_dev_free(d);
+ if (rawpath)
+ {
+ printf("decoder: %ld samples, %ld wrong (of %ld)\n", seen, bad, (long) raw_w * raw_h);
+ if (bad || seen != (long) raw_w * raw_h) return 1;
+ }
+
+ if (argc - a >= 3)
+ {
+ struct fos_print pr;
+ if (!fos_print_load(argv[a + 1], &pr)) { fprintf(stderr, "can't load the print\n"); return 1; }
+ FILE *f = fopen(argv[a + 2], "wb");
+ fprintf(f, "P6\n%d %d\n255\n", FOS_PRINT_W, FOS_PRINT_H);
+ for (int i = 0; i < FOS_PRINT_W * FOS_PRINT_H; i++)
+ {
+ int k = pr.px[i];
+ uint8_t black[3] = { 0, 0, 0 };
+ fwrite(k >= 1 && k <= FOS_PRINT_COLOURS ? pr.pal[k - 1] : black, 1, 3, f);
+ }
+ fclose(f);
+ fos_print_free(&pr);
+ }
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/films.c b/ml-dev/filmos/sim/films.c
new file mode 100644
index 0000000..837ada3
--- /dev/null
+++ b/ml-dev/filmos/sim/films.c
@@ -0,0 +1,24 @@
+/* the films beyond the built-in ones from out/FOSFILMS.BIN (make), loaded
+ * as the camera loads them from its card; without the file, the built-in
+ * films only */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../fos.h"
+
+void sim_films()
+{
+ const char *path = getenv("FOS_FILMS") ? getenv("FOS_FILMS") : "out/" FOS_FILM_FILE;
+ FILE *f = fopen(path, "rb");
+ if (!f) return;
+ fseek(f, 0, SEEK_END);
+ long n = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ uint8_t *blob = malloc((size_t) n); /* kept: the films point into it */
+ if (!blob || fread(blob, 1, (size_t) n, f) != (size_t) n || !fos_films_load(blob, (int) n))
+ {
+ fprintf(stderr, "%s: not a film file\n", path);
+ free(blob);
+ }
+ fclose(f);
+}
diff --git a/ml-dev/filmos/sim/fonts.c b/ml-dev/filmos/sim/fonts.c
new file mode 100644
index 0000000..69ed296
--- /dev/null
+++ b/ml-dev/filmos/sim/fonts.c
@@ -0,0 +1,23 @@
+/* the film OS fonts from out/FOSFONT.BIN (make), loaded as the camera
+ * loads them from its card */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../fos_gfx.h"
+
+void sim_fonts()
+{
+ const char *path = getenv("FOS_FONT") ? getenv("FOS_FONT") : "out/" FOS_FONT_FILE;
+ FILE *f = fopen(path, "rb");
+ if (!f) { perror(path); exit(1); }
+ fseek(f, 0, SEEK_END);
+ long n = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ uint8_t *blob = malloc((size_t) n); /* kept: the fonts point into it */
+ if (!blob || fread(blob, 1, (size_t) n, f) != (size_t) n || !fos_fonts_load(blob, (int) n))
+ {
+ fprintf(stderr, "%s: not a font file\n", path);
+ exit(1);
+ }
+ fclose(f);
+}
diff --git a/ml-dev/filmos/sim/gfxtest.c b/ml-dev/filmos/sim/gfxtest.c
new file mode 100644
index 0000000..8eb8e6c
--- /dev/null
+++ b/ml-dev/filmos/sim/gfxtest.c
@@ -0,0 +1,68 @@
+/* gfxtest: draws the palette and every primitive once, for eyeballing.
+ * make gfxtest && ./gfxtest out/gfxtest.idx && python3 topng.py out/gfxtest.idx */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../fos_gfx.h"
+
+void sim_fonts(); /* fonts.c */
+
+int main(int argc, char **argv)
+{
+ static uint8_t px[FOS_W * FOS_H];
+ struct fos_canvas cv;
+ fos_gfx_init();
+ sim_fonts();
+ fos_canvas_init(&cv, px, FOS_W, FOS_W, FOS_H);
+
+ fos_fill(&cv, 0, 0, FOS_W, FOS_H, FC(RAMP_GRAY, 10));
+
+ /* palette strip */
+ for (int i = 1; i < 255; i++)
+ fos_fill_ix(&cv, 8 + (i - 1) % 127 * 5, 8 + (i - 1) / 127 * 14, 5, 12, i);
+
+ /* dithered gradients per ramp */
+ for (int r = 0; r < RAMP_COUNT; r++)
+ for (int x = 0; x < 340; x++)
+ for (int y = 0; y < 14; y++)
+ px[(40 + r * 16 + y) * FOS_W + 8 + x] = fos_ix_dither(r, x * LV_MAX / 339, 8 + x, 40 + r * 16 + y);
+
+ /* dark background gradient, like the stage */
+ fos_vgrad(&cv, 360, 40, 352, 160, RAMP_GRAY, LV12(26), LV12(6));
+
+ /* shapes */
+ fos_rrect(&cv, 380, 60, 140, 44, 12, FC(RAMP_GRAY, 34), OPAQUE);
+ fos_rrect_line(&cv, 530, 60, 160, 44, 22, 2, FC(RAMP_AMBER, 185), OPAQUE);
+ fos_text_c(&cv, &fos_font_mdb, 610, 89, "36 EXP", FC(RAMP_AMBER, 185), OPAQUE, 16);
+ fos_text_c(&cv, &fos_font_md, 450, 89, "Load roll", FC(RAMP_GRAY, 236), OPAQUE, 0);
+ fos_disc(&cv, 420 * 256, 150 * 256, 30 * 256 + 128, FC(RAMP_RED, 150), OPAQUE);
+ fos_ring(&cv, 500 * 256, 150 * 256, 30 * 256, 3 * 256, FC(RAMP_GRAY, 200), OPAQUE);
+ fos_line(&cv, 560 * 256, 120 * 256, 640 * 256, 185 * 256, 3 * 256, FC(RAMP_GRAY, 230), OPAQUE);
+ fos_tri(&cv, 670, 150, 18, 0, FC(RAMP_AMBER, 185), OPAQUE);
+ fos_tri(&cv, 700, 150, 18, 2, FC(RAMP_AMBER, 185), 160);
+
+ /* text in every size */
+ int y = 230;
+ const struct fos_font *fonts[] = { &fos_font_xs, &fos_font_sm, &fos_font_md, &fos_font_mdb, &fos_font_lg, &fos_font_xl };
+ const char *names[] = { "xs 13 KODAK" T_DOT "PORTRA 400" T_DOT "C-41", "sm 16 Soft warm skin, gentle highlights",
+ "md 20 Viewfinder LEDs on half-press", "mdb 20 ROLL 012 14/36", "lg 27 Choose your film",
+ "xl 50 Portra 400 AVATAR To" };
+ for (int i = 0; i < 6; i++)
+ {
+ y += fonts[i]->ascent + 4;
+ fos_text(&cv, fonts[i], 12, y, names[i], FC(RAMP_GRAY, 236), OPAQUE, i == 0 ? 24 : 0);
+ y += fonts[i]->descent;
+ }
+ fos_text(&cv, &fos_font_num, 520, 460, "24", FC(RAMP_AMBER, 185), OPAQUE, 0);
+ fos_text(&cv, &fos_font_lg, 400, 300, "Amber on grey", FC(RAMP_AMBER, 185), OPAQUE, 0);
+ fos_rrect(&cv, 395, 318, 220, 40, 8, FC(RAMP_AMBER, 185), OPAQUE);
+ fos_text(&cv, &fos_font_lg, 405, 347, "White on amber", FC(RAMP_GRAY, 250), OPAQUE, 0);
+
+ FILE *f = fopen(argc > 1 ? argv[1] : "out/gfxtest.idx", "wb");
+ fwrite(px, 1, sizeof(px), f);
+ fclose(f);
+ f = fopen("out/pal.bin", "wb");
+ fwrite(fos_pal, 4, 256, f);
+ fclose(f);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/hudtest.c b/ml-dev/filmos/sim/hudtest.c
new file mode 100644
index 0000000..a824d96
--- /dev/null
+++ b/ml-dev/filmos/sim/hudtest.c
@@ -0,0 +1,65 @@
+/* hudtest: the viewfinder HUD over a made-up LiveView picture, with a
+ * stand-in for Canon's palette (white 1, black 2, red 8, dark red 12,
+ * greys 38..79)
+ * hudtest [1|0|e] [liveview.ppm] the picture: a 720 x 480 binary PPM */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "../fos.h"
+
+void sim_fonts(); /* fonts.c */
+
+void *fos_port_alloc(int size) { return malloc(size); }
+void fos_port_free(void *p) { free(p); }
+
+static uint8_t ov[480 * 960];
+
+int main(int argc, char **argv)
+{
+ struct fos_hud_palette p = { 0, 2, 1, 8, 12, { 0 } };
+ for (int i = 0; i <= 100; i++) p.gray[i] = 38 + i * 41 / 100;
+ struct fos_hud h = { 1, 1, 1, 13, 6, 15, "125", 12, 36, 0, 1, 1, "PORTRA 400" };
+ if (argc > 1 && argv[1][0] == '0') { h.lit = 0; h.need_wind = 1; }
+ if (argc > 1 && argv[1][0] == 'e') { h.finished = 1; strcpy(h.shutter, "0.5\""); h.want = 30; }
+ fos_gfx_init();
+ sim_fonts();
+ fos_hud_draw(ov, 960, &h, &p);
+
+ static uint8_t lv[480 * 720 * 3];
+ int have_lv = 0;
+ if (argc > 2)
+ {
+ FILE *pf = fopen(argv[2], "rb");
+ int w = 0, ht = 0, mx = 0;
+ if (pf && fscanf(pf, "P6 %d %d %d", &w, &ht, &mx) == 3 && w == 720 && ht == 480 && mx == 255 && fgetc(pf) != EOF)
+ have_lv = fread(lv, 1, sizeof(lv), pf) == sizeof(lv);
+ if (!have_lv) fprintf(stderr, "%s: not a 720 x 480 PPM, using the made-up picture\n", argv[2]);
+ if (pf) fclose(pf);
+ }
+
+ /* a dusk street as LiveView: sky gradient, a sun, dark buildings */
+ FILE *f = fopen("out/hud.ppm", "wb");
+ fprintf(f, "P6 720 480 255\n");
+ for (int y = 0; y < 480; y++)
+ for (int x = 0; x < 720; x++)
+ {
+ int r, g, b;
+ float t = y / 480.0f;
+ r = (int) (230 - 120 * t); g = (int) (150 - 70 * t); b = (int) (120 + 40 * t);
+ float d = sqrtf((x - 250.0f) * (x - 250.0f) + (y - 230.0f) * (y - 230.0f));
+ if (d < 40) { r = 255; g = 230; b = 190; }
+ int roof = 300 + (int) (30 * sinf(x / 37.0f)) + ((x / 90) % 2) * 40;
+ if (y > roof) { r = 40; g = 34; b = 38; }
+ if (have_lv) { const uint8_t *q = lv + (y * 720 + x) * 3; r = q[0]; g = q[1]; b = q[2]; }
+ int k = ov[y * 960 + x];
+ if (k == 1) r = g = b = 255;
+ else if (k == 2) r = g = b = 0;
+ else if (k == 8) { r = 240; g = 30; b = 30; }
+ else if (k == 12) { r = 120; g = 12; b = 12; }
+ else if (k >= 38 && k <= 79) r = g = b = (k - 38) * 255 / 41;
+ fputc(r, f); fputc(g, f); fputc(b, f);
+ }
+ fclose(f);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/mkcard.sh b/ml-dev/filmos/sim/mkcard.sh
new file mode 100755
index 0000000..7a3bfe7
--- /dev/null
+++ b/ml-dev/filmos/sim/mkcard.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+# A memory card for the simulator's darkroom: rolls of half-size test CR2s and
+# their logs, as the camera writes them (out/card/DCIM/100CANON).
+# ./mkcard.sh
+# PHOTOS=dir ./mkcard.sh the frames are the photos in dir (*.pfm: linear sRGB, 0.18 = mid grey,
+# taller than wide = shot on its side), in turn, instead of test scenes
+set -euo pipefail
+cd "$(dirname "$0")"
+mkdir -p out
+gcc -O2 -o out/mkcr2 tools/mkcr2.c -lm
+CARD=out/card
+rm -rf "$CARD" && mkdir -p "$CARD/DCIM/100CANON" "$CARD/ML"
+DIR="$CARD/DCIM/100CANON"
+file=100
+photos=()
+[ -n "${PHOTOS:-}" ] && photos=("$PHOTOS"/*.pfm)
+
+# roll <number> <film> <exposures> <frames> <loaded> [nofiles]
+roll() {
+ local n=$1 film=$2 exp=$3 frames=$4 loaded=$5 nofiles=${6:-} log
+ log="$DIR/ROLL_$(printf %03d "$n").TXT"
+ printf '# ML film mode roll log (filmroll module)\nroll = %03d\nfilm = %s\nexposures = %d\nloaded = %s:00\n\n' \
+ "$n" "$film" "$exp" "$loaded" > "$log"
+ for ((i = 1; i <= frames; i++)); do
+ file=$((file + 1))
+ local name; name=$(printf IMG_%04d.CR2 "$file")
+ local scene=chart extra=""
+ (( i % 2 == 0 )) && scene=street
+ (( i % 5 == 3 )) && extra="--portrait"
+ local ev; ev=$(python3 -c "print(round(-0.7 + 0.35 * ($i % 5), 2))")
+ if [ ${#photos[@]} -gt 0 ]; then
+ local p=${photos[$(( (file - 101) % ${#photos[@]} ))]}
+ extra=""; ev=0
+ [ "$(head -c 64 "$p" | sed -n 2p | awk '{ print ($2 > $1) }')" = 1 ] && extra="--portrait"
+ scene="chart --image $p"
+ fi
+ [ -z "$nofiles" ] && out/mkcr2 "$DIR/$name" --half --scene $scene $extra --ev "$ev" --seed $((n * 100 + i)) 2>/dev/null
+ local t; t=$(printf '%02d:%02d:%02d' $((9 + i / 4)) $(((i * 7) % 60)) $(((i * 13) % 60)))
+ printf '%d %s %s %s f/%s\n' "$i" "$name" "${loaded%% *}" "$t" "$( ((i % 3)) && echo 2.8 || echo 5.6)" >> "$log"
+ done
+ [ "$frames" -lt "$exp" ] && printf '\n# rewound %s after %d of %d frames\n' "$loaded" "$frames" "$exp" >> "$log"
+ return 0
+}
+
+roll 9 ektar100 12 12 "2026-10-12 08:30"
+roll 10 portra400 12 12 "2026-10-18 10:05"
+roll 11 gold200 12 8 "2026-10-20 19:40"
+roll 12 cinestill800t 36 14 "2026-10-21 18:02" nofiles # the one in the camera
+echo "card: $(find "$CARD" -name '*.CR2' | wc -l) CR2 files, $(du -sh "$CARD" | cut -f1)"
diff --git a/ml-dev/filmos/sim/port_files.c b/ml-dev/filmos/sim/port_files.c
new file mode 100644
index 0000000..2b5aedb
--- /dev/null
+++ b/ml-dev/filmos/sim/port_files.c
@@ -0,0 +1,53 @@
+/* the film OS's card on a PC: a folder (FOS_CARD, else out/card/) and stdio */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include "../fos.h"
+
+void *fos_port_open(const char *path, int write) { return fopen(path, write ? "wb" : "rb"); }
+int fos_port_read(void *f, void *buf, int size) { return (int) fread(buf, 1, size, f); }
+int fos_port_write(void *f, const void *buf, int size) { return (int) fwrite(buf, 1, size, f); }
+int fos_port_seek(void *f, int offset) { return fseek(f, offset, SEEK_SET); }
+void fos_port_close(void *f) { if (f) fclose(f); }
+
+const char *fos_port_model() { return "Canon EOS M"; }
+
+const char *fos_port_card()
+{
+ const char *c = getenv("FOS_CARD");
+ return c ? c : "out/card/";
+}
+
+int fos_port_list(const char *dir, int (*fn)(void *ctx, const char *name, int is_dir), void *ctx)
+{
+ DIR *d = opendir(dir);
+ if (!d) return -1;
+ struct dirent *e;
+ int n = 0;
+ while ((e = readdir(d)))
+ {
+ if (e->d_name[0] == '.') continue;
+ char path[512];
+ struct stat st;
+ snprintf(path, sizeof(path), "%s/%s", dir, e->d_name);
+ int is_dir = !stat(path, &st) && S_ISDIR(st.st_mode);
+ n++;
+ if (!fn(ctx, e->d_name, is_dir)) break;
+ }
+ closedir(d);
+ return n;
+}
+
+int fos_port_mkdir(const char *path)
+{
+ struct stat st;
+ if (!stat(path, &st)) return S_ISDIR(st.st_mode) ? 0 : -1;
+ /* FOS_SHORT_NAMES: a card that takes 8.3 names only */
+ const char *name = strrchr(path, '/');
+ name = name ? name + 1 : path;
+ if (getenv("FOS_SHORT_NAMES") && (strlen(name) > 8 || strchr(name, ' '))) return -1;
+ return mkdir(path, 0777);
+}
diff --git a/ml-dev/filmos/sim/previews.sh b/ml-dev/filmos/sim/previews.sh
new file mode 100755
index 0000000..b5b789a
--- /dev/null
+++ b/ml-dev/filmos/sim/previews.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+# Render the preview images in ../preview from the scripted scenes.
+# make && ./previews.sh
+# PHOTOS=dir ./previews.sh the darkroom screens show your own photos (mkcard.sh says how)
+# LIVEVIEW=pic.ppm and the HUD is drawn over this picture (720 x 480) for LiveView
+set -euo pipefail
+cd "$(dirname "$0")"
+OUT=../preview
+mkdir -p "$OUT" out/frames
+
+run() { rm -rf "out/frames/$1"; ./out/sim "scenes/$1.txt" "out/frames/$1" 2>/dev/null; }
+# the frame on screen at <ms>: the last one presented at or before it
+at() { ls out/frames/$1/*.idx | awk -F_ -v t="$2" '{ split($3, a, "."); if (a[1] + 0 <= t) f = $0 } END { print f }'; }
+still() { python3 topng.py "$(at "$1" "$2")" >/dev/null; cp "$(at "$1" "$2" | sed 's/idx$/png/')" "$OUT/$3.png"; }
+last() { local f; f=$(ls out/frames/$1/*.idx | tail -1); python3 topng.py "$f" >/dev/null; cp "${f%.idx}.png" "$OUT/$2.png"; }
+
+# the shelf's samples on the card, as the EOS M build makes them (PLAY on the shelf)
+make -s out/devtest
+mkdir -p out/card/ML/SAMPLES
+FOS_LUT_DIR=out/lut ./out/devtest -S ../../films/sample/SAMPLE.CR2 out/card/ML/SAMPLES
+
+run shelf; still shelf 660 shelf; still shelf 1110 shelf-gliding
+run sample; still sample 1600 sample
+run load; still load 1300 boot; still load 5300 loaded; still load 5800 shutter
+run home; still home 1250 home
+run roll; still roll 2400 roll; still roll 3000 rewind
+run pages; still pages 1330 viewfinder; still pages 6190 lens; last pages system
+run screen; last screen screen # its palette has the warmth it ends with
+
+# the darkroom, on a card of test rolls (mkcard.sh): the list, developing, the prints
+./mkcard.sh >/dev/null
+run endroll; last endroll end-of-roll
+run darkroom; still darkroom 2900 darkroom; still darkroom 12400 developing; still darkroom 22500 developing-line
+run prints; still prints 1300 prints-sheet; still prints 3500 prints-frame
+
+# the HUD over a made-up LiveView picture
+gcc -O2 -std=gnu99 -o out/hudtest hudtest.c fonts.c ../fos_gfx.c ../fos_film.c ../fos_hud.c -lm
+./out/hudtest 1 ${LIVEVIEW:-} && python3 -c "from PIL import Image; Image.open('out/hud.ppm').save('$OUT/hud.png')"
+
+# browsing the shelf, half size
+run browse
+python3 - <<'PY'
+from pathlib import Path
+from PIL import Image
+import numpy as np
+pal = np.fromfile("out/pal.bin", dtype="<u4")
+rgb = np.stack([(pal >> 16) & 255, (pal >> 8) & 255, pal & 255], axis=1).astype(np.uint8)
+frames = sorted(Path("out/frames/browse").glob("*.idx"))
+imgs, times = [], []
+for f in frames:
+ idx = np.fromfile(f, dtype=np.uint8).reshape(480, 720)
+ imgs.append(Image.fromarray(rgb[idx], "RGB").resize((360, 240), Image.LANCZOS))
+ times.append(int(f.stem.split("_")[-1]))
+durs = [max(20, b - a) for a, b in zip(times, times[1:])] + [600]
+pal_img = imgs[len(imgs) // 2].quantize(colors=255, method=Image.MEDIANCUT)
+q = [im.quantize(palette=pal_img, dither=Image.NONE) for im in imgs]
+q[0].save("../preview/shelf.gif", save_all=True, append_images=q[1:], duration=durs, loop=0)
+print(len(q), "frames")
+PY
+ls -la "$OUT"
diff --git a/ml-dev/filmos/sim/scenes/browse.txt b/ml-dev/filmos/sim/scenes/browse.txt
new file mode 100644
index 0000000..6c9e656
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/browse.txt
@@ -0,0 +1,11 @@
+# for the preview GIF: glide through the shelf and back
+noroll
+open shelf
+700 wr
+950 wr
+1200 wr
+1900 down
+2500 wl
+2750 wl
+3000 wl
+3800 end
diff --git a/ml-dev/filmos/sim/scenes/darkroom.txt b/ml-dev/filmos/sim/scenes/darkroom.txt
new file mode 100644
index 0000000..26cb9dd
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/darkroom.txt
@@ -0,0 +1,10 @@
+# home -> darkroom: mark roll 010, develop it; the darkroom scene runs
+roll 1 14 36
+open home
+600 down
+900 down
+1300 set
+2300 down
+2600 set
+3200 info
+36000 end
diff --git a/ml-dev/filmos/sim/scenes/darkroom2.txt b/ml-dev/filmos/sim/scenes/darkroom2.txt
new file mode 100644
index 0000000..8a7548f
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/darkroom2.txt
@@ -0,0 +1,5 @@
+# the darkroom after developing roll 010; the end of roll sheet
+open darkroom
+1200 down
+1500 down
+2200 end
diff --git a/ml-dev/filmos/sim/scenes/darkroom_redo.txt b/ml-dev/filmos/sim/scenes/darkroom_redo.txt
new file mode 100644
index 0000000..afd5b84
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/darkroom_redo.txt
@@ -0,0 +1,5 @@
+# the darkroom: a developed roll missing JPEGs is waiting again; develop all
+noroll
+open darkroom
+1500 info
+40000 end
diff --git a/ml-dev/filmos/sim/scenes/endroll.txt b/ml-dev/filmos/sim/scenes/endroll.txt
new file mode 100644
index 0000000..298bd45
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/endroll.txt
@@ -0,0 +1,4 @@
+# the last frame shot: the film OS opens on the roll, asking
+roll 1 36 36
+open end
+1600 end
diff --git a/ml-dev/filmos/sim/scenes/endroll_dev.txt b/ml-dev/filmos/sim/scenes/endroll_dev.txt
new file mode 100644
index 0000000..c80c33f
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/endroll_dev.txt
@@ -0,0 +1,9 @@
+# the end of roll sheet: develop now; then stop half way
+roll 1 36 36
+open end
+1200 set
+6000 menu
+6600 menu
+7400 menu
+8000 set
+9500 end
diff --git a/ml-dev/filmos/sim/scenes/home.txt b/ml-dev/filmos/sim/scenes/home.txt
new file mode 100644
index 0000000..3271905
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/home.txt
@@ -0,0 +1,19 @@
+# home -> viewfinder settings -> toggle -> back -> roll page -> rewind cancel
+roll 1 14 36
+open home
+900 down
+1200 down
+1450 down
+1700 set
+2600 down
+2900 set
+3400 down
+3700 down
+3900 right
+4600 menu
+5400 up
+5700 up
+6000 set
+7600 set
+8400 menu
+9200 end
diff --git a/ml-dev/filmos/sim/scenes/idle.txt b/ml-dev/filmos/sim/scenes/idle.txt
new file mode 100644
index 0000000..a7572ca
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/idle.txt
@@ -0,0 +1,4 @@
+# leave the shelf alone: the middle canister sways
+noroll
+open shelf
+7000 end
diff --git a/ml-dev/filmos/sim/scenes/load.txt b/ml-dev/filmos/sim/scenes/load.txt
new file mode 100644
index 0000000..1e90dc6
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/load.txt
@@ -0,0 +1,7 @@
+# boot, then pick Ektar and load it
+noroll
+open boot
+2600 wr
+2900 wr
+3800 set
+6600 end
diff --git a/ml-dev/filmos/sim/scenes/pages.txt b/ml-dev/filmos/sim/scenes/pages.txt
new file mode 100644
index 0000000..af9edcf
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/pages.txt
@@ -0,0 +1,21 @@
+# the three settings pages with their previews
+roll 1 14 36
+open home
+500 down
+700 down
+900 down
+1100 set
+1800 set
+2300 down
+2500 set
+3200 menu
+3900 down
+4300 set
+5000 down
+5300 right
+5600 right
+6000 right
+6700 menu
+7400 down
+7800 set
+8600 end
diff --git a/ml-dev/filmos/sim/scenes/prints.txt b/ml-dev/filmos/sim/scenes/prints.txt
new file mode 100644
index 0000000..f8a8054
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/prints.txt
@@ -0,0 +1,13 @@
+# after developing (darkroom scene): PLAY opens the newest prints
+open prints
+1400 right
+1700 right
+2000 down
+2600 set
+3600 right
+4600 info
+5400 wr
+6400 menu
+7400 wr
+8600 menu
+9600 end
diff --git a/ml-dev/filmos/sim/scenes/prints_none.txt b/ml-dev/filmos/sim/scenes/prints_none.txt
new file mode 100644
index 0000000..b049aed
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/prints_none.txt
@@ -0,0 +1,3 @@
+# PLAY with nothing developed yet
+open prints
+1500 end
diff --git a/ml-dev/filmos/sim/scenes/roll.txt b/ml-dev/filmos/sim/scenes/roll.txt
new file mode 100644
index 0000000..21f1bb3
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/roll.txt
@@ -0,0 +1,8 @@
+# home -> roll page: the counter turns from S to 14; rewind it
+roll 1 14 36
+open home
+700 down
+1000 set
+2600 set
+3300 set
+5600 end
diff --git a/ml-dev/filmos/sim/scenes/sample.txt b/ml-dev/filmos/sim/scenes/sample.txt
new file mode 100644
index 0000000..d13c0df
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/sample.txt
@@ -0,0 +1,10 @@
+# the shelf's sample: PLAY shows the film's photo full screen, the arrows the next films, PLAY back
+noroll
+open shelf
+900 play
+2000 right
+3000 wr
+4000 info
+4600 info
+5400 play
+6400 end
diff --git a/ml-dev/filmos/sim/scenes/screen.txt b/ml-dev/filmos/sim/scenes/screen.txt
new file mode 100644
index 0000000..3252253
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/screen.txt
@@ -0,0 +1,17 @@
+# home -> System -> Screen colour, a little warmer, then back
+roll 2 8 36
+open home
+800 down
+1000 down
+1200 down
+1400 down
+1600 down
+1900 set
+2700 down
+2900 down
+3300 set
+4200 down
+4500 down
+4800 right
+5100 right
+6000 end
diff --git a/ml-dev/filmos/sim/scenes/shelf.txt b/ml-dev/filmos/sim/scenes/shelf.txt
new file mode 100644
index 0000000..cbd3d20
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/shelf.txt
@@ -0,0 +1,11 @@
+# browse the shelf, change exposures
+noroll
+open shelf
+900 wr
+1150 wr
+1300 wr
+2300 wl
+3200 down
+3900 right
+4200 right
+5200 end
diff --git a/ml-dev/filmos/sim/scenes/shelves.txt b/ml-dev/filmos/sim/scenes/shelves.txt
new file mode 100644
index 0000000..7dbaf6e
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/shelves.txt
@@ -0,0 +1,12 @@
+# the shelves: browse colour, then slide, B&W, cine
+noroll
+open shelf
+900 wr
+1300 wr
+2200 down
+3400 wr
+4400 down
+5600 down
+6800 wl
+7800 up
+9000 end
diff --git a/ml-dev/filmos/sim/scenes/support.txt b/ml-dev/filmos/sim/scenes/support.txt
new file mode 100644
index 0000000..5078829
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/support.txt
@@ -0,0 +1,17 @@
+# Settings > System > Support: the donation codes
+roll 1 14 36
+open home
+500 down
+700 down
+900 down
+1100 down
+1200 down
+1300 set
+2000 down
+2200 down
+2400 down
+2600 down
+2800 down
+3000 down
+3200 down
+4400 end
diff --git a/ml-dev/filmos/sim/scenes/toast.txt b/ml-dev/filmos/sim/scenes/toast.txt
new file mode 100644
index 0000000..69e51c4
--- /dev/null
+++ b/ml-dev/filmos/sim/scenes/toast.txt
@@ -0,0 +1,10 @@
+# System > Re-apply shows a toast
+roll 1 14 36
+open home
+600 up
+900 set
+1700 down
+1900 down
+2100 down
+2500 set
+4800 end
diff --git a/ml-dev/filmos/sim/sim.c b/ml-dev/filmos/sim/sim.c
new file mode 100644
index 0000000..c719277
--- /dev/null
+++ b/ml-dev/filmos/sim/sim.c
@@ -0,0 +1,237 @@
+/* sim: runs the film OS on a PC with a scripted dial, and saves what the
+ * camera screen would show, frame by frame.
+ *
+ * ./sim script.txt out/frames/name (scripts in scenes/)
+ *
+ * A script line is "<ms> <key>" (key names below) or "<ms> end"; "#" starts
+ * a comment. "roll <film> <shot> <exp>" before the first event puts a roll in
+ * the camera, "open home|shelf|boot" picks the first screen.
+ * Time is simulated: every presented frame costs FRAME_MS, so the result
+ * plays at roughly the pace the camera would manage.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "../fos.h"
+#include "../fos_ui.h"
+#include "../fos_dev.h"
+
+void sim_fonts(); /* fonts.c */
+void sim_films(); /* films.c */
+
+#define FRAME_MS 22
+
+static int now_ms;
+static int frame_no;
+static int frame_dirty;
+static int last_dump = -1000;
+static const char *outdir;
+static uint8_t screen[FOS_W * FOS_H];
+
+struct ev { int t; int key; };
+static struct ev evs[256];
+static int nev, next_ev, end_t = 4000;
+
+static int settings[FS_COUNT] = {
+ [FS_HUD] = 1, [FS_LEDS] = 1, [FS_FOCUS] = 1, [FS_WIND] = 1,
+ [FS_APKEYS] = 0, [FS_LENS_WIDE] = 6, [FS_FSTOP] = 10,
+ [FS_STARTUP] = 2, [FS_PLAYLOCK] = 1, [FS_BOOTANIM] = 1, [FS_DEBUG] = 0,
+ [FS_FILM] = 0, [FS_EXP] = 0,
+};
+static struct fos_roll roll = { 1, 12, 1, 36, 14, 0, "2026-10-21 18:02", 3,
+ { { 14, "21:47", "2" }, { 13, "21:40", "2" }, { 12, "21:33", "2.8" } } };
+
+int fos_port_ms() { return now_ms; }
+
+/* the palette on the screen now, 0xRRGGBB; each dumped frame gets a copy */
+static uint32_t cur_pal[256];
+
+static void dump()
+{
+ char path[512];
+ if (!strcmp(outdir, "-")) { frame_no++; last_dump = now_ms; return; } /* measuring only */
+ snprintf(path, sizeof(path), "%s/f_%05d_%06d.idx", outdir, frame_no, now_ms);
+ FILE *f = fopen(path, "wb");
+ if (!f) { perror(path); exit(1); }
+ fwrite(screen, 1, sizeof(screen), f);
+ fclose(f);
+ snprintf(path, sizeof(path), "%s/f_%05d_%06d.pal", outdir, frame_no++, now_ms);
+ f = fopen(path, "wb");
+ if (f) { fwrite(cur_pal, 4, 256, f); fclose(f); }
+ last_dump = now_ms;
+}
+
+void fos_port_sleep(int ms)
+{
+ /* FOS_FULL=1: every frame redrawn whole, to check the partial redraws */
+ static int full = -1;
+ if (full < 0) full = getenv("FOS_FULL") != 0;
+ if (full) ui_clobbered = 1;
+ if (frame_dirty)
+ {
+ now_ms += FRAME_MS;
+ if (now_ms - last_dump >= 30) dump();
+ frame_dirty = 0;
+ }
+ now_ms += ms;
+}
+
+int fos_port_key()
+{
+ if (next_ev < nev && evs[next_ev].t <= now_ms)
+ return evs[next_ev++].key;
+ return FK_NONE;
+}
+
+int fos_port_abort()
+{
+ return now_ms > end_t;
+}
+
+void fos_port_present(const uint8_t *rows, int pitch, int y0, int y1)
+{
+ for (int y = y0; y < y1; y++)
+ memcpy(&screen[y * FOS_W], &rows[(y - y0) * pitch], FOS_W);
+ frame_dirty = 1;
+}
+
+/* the palette as the camera would show it: through the screen colour
+ * settings and Canon's conversion, and back */
+void fos_port_palette()
+{
+ char path[512];
+ if (!strcmp(outdir, "-")) return;
+ uint32_t pal[256];
+ for (int i = 0; i < 256; i++)
+ pal[i] = i == 0 || i == 255 ? fos_pal[i] :
+ settings[FS_SCR_STD] == 1 ? fos_pal[i] : /* Rec.709: what a BT.601 screen shows is not modelled */
+ fos_screen_rgb(fos_screen_yuv(i, 235, 0, settings[FS_SCR_SAT], settings[FS_SCR_WARM], settings[FS_SCR_BRIGHT]), 235);
+ memcpy(cur_pal, pal, sizeof(cur_pal));
+ frame_dirty = 1;
+ snprintf(path, sizeof(path), "%s/../../pal.bin", outdir);
+ FILE *f = fopen(path, "wb");
+ if (f) { fwrite(pal, 4, 256, f); fclose(f); }
+}
+
+void fos_port_photo(const uint8_t (*pal)[3], int n, int k)
+{
+ for (int i = 1; i < 255; i++)
+ {
+ const uint8_t *c = i <= n ? pal[i - 1] : i >= FOS_FIXED_BASE && i < FOS_FIXED_BASE + FOS_FIXED_N ?
+ fos_fixed_rgb[i - FOS_FIXED_BASE] : (const uint8_t *) "\0\0\0";
+ uint32_t rgb = (uint32_t) (c[0] * k >> 8) << 16 | (uint32_t) (c[1] * k >> 8) << 8 | (uint32_t) (c[2] * k >> 8);
+ cur_pal[i] = settings[FS_SCR_STD] == 1 ? rgb :
+ fos_screen_rgb(fos_screen_yuv_rgb(rgb, 235, 0, settings[FS_SCR_SAT], settings[FS_SCR_WARM], settings[FS_SCR_BRIGHT]), 235);
+ }
+ frame_dirty = 1;
+}
+
+void fos_port_log(const char *msg) { fprintf(stderr, "[%6d ms] %s\n", now_ms, msg); }
+int fos_port_dev_cap() { return 12; }
+
+void *fos_port_alloc(int size) { return malloc(size); }
+void fos_port_free(void *p) { free(p); }
+
+void fos_port_roll(struct fos_roll *r) { *r = roll; }
+int fos_port_get(int s) { return s >= 0 && s < FS_COUNT ? settings[s] : 0; }
+void fos_port_set(int s, int v)
+{
+ if (s >= 0 && s < FS_COUNT) settings[s] = v;
+ if (s == FS_SCR_STD || s == FS_SCR_SAT || s == FS_SCR_WARM || s == FS_SCR_BRIGHT) fos_port_palette();
+}
+
+void fos_port_action(int a, int x, int y)
+{
+ fprintf(stderr, "[%6d ms] action %d (%d, %d)\n", now_ms, a, x, y);
+ if (a == FA_LOAD)
+ {
+ roll.loaded = 1; roll.number++; roll.film = x; roll.exposures = fos_exposure_choices[y];
+ roll.shot = 0; roll.nrecent = 0;
+ strcpy(roll.loaded_at, "2026-10-22 09:41");
+ }
+ if (a == FA_REWIND) roll.loaded = 0;
+ if (a == FA_BUSY) fprintf(stderr, "[%6d ms] %s\n", now_ms, x ? "busy: developing" : "busy: done");
+}
+
+void fos_port_clock(char *buf, int size) { snprintf(buf, size, "09:41"); }
+int fos_port_lens_manual() { return 1; }
+const char *fos_port_lens_name() { return "Manual lens"; }
+#ifndef MFILM_VERSION
+#define MFILM_VERSION "dev"
+#endif
+const char *fos_port_version() { return MFILM_VERSION; }
+void fos_port_stat(const struct fos_stat *s) { }
+
+static int key_of(const char *s)
+{
+ static const struct { const char *n; int k; } names[] = {
+ { "left", FK_LEFT }, { "right", FK_RIGHT }, { "up", FK_UP }, { "down", FK_DOWN },
+ { "wl", FK_WHEEL_L }, { "wr", FK_WHEEL_R }, { "set", FK_SET }, { "menu", FK_MENU },
+ { "info", FK_INFO }, { "play", FK_PLAY }, { "home", FK_HOME },
+ };
+ for (unsigned i = 0; i < sizeof(names) / sizeof(names[0]); i++)
+ if (!strcmp(s, names[i].n)) return names[i].k;
+ fprintf(stderr, "unknown key %s\n", s);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 3) { fprintf(stderr, "usage: sim script outdir\n"); return 1; }
+ outdir = argv[2];
+ if (strcmp(outdir, "-")) mkdir(outdir, 0755);
+ int open = FOS_OPEN_SHELF;
+ FILE *f = fopen(argv[1], "r");
+ if (!f) { perror(argv[1]); return 1; }
+ char line[256];
+ int hold = 0;
+ while (fgets(line, sizeof(line), f))
+ {
+ char a[64], b[64];
+ int t, n1, n2, n3;
+ if (line[0] == '#' || line[0] == '\n') continue;
+ if (sscanf(line, "roll %d %d %d", &n1, &n2, &n3) == 3)
+ {
+ roll.loaded = 1; roll.film = n1; roll.shot = n2; roll.exposures = n3;
+ continue;
+ }
+ if (!strncmp(line, "noroll", 6)) { roll.loaded = 0; continue; }
+ if (sscanf(line, "open %63s", a) == 1)
+ {
+ open = !strcmp(a, "home") ? FOS_OPEN_HOME : !strcmp(a, "boot") ? FOS_OPEN_BOOT :
+ !strcmp(a, "darkroom") ? FOS_OPEN_DARKROOM : !strcmp(a, "prints") ? FOS_OPEN_PRINTS :
+ !strcmp(a, "end") ? FOS_OPEN_END : FOS_OPEN_SHELF;
+ continue;
+ }
+ if (sscanf(line, "%d %63s", &t, b) == 2)
+ {
+ if (!strcmp(b, "end")) { end_t = t; continue; }
+ int k = key_of(b);
+ evs[nev].t = t; evs[nev].key = k; nev++;
+ /* the dial's presses come with a release, like on the camera;
+ * "hold" before a key keeps it down for 1.5 s */
+ if (k >= FK_LEFT && k <= FK_DOWN)
+ {
+ evs[nev].t = t + (hold ? 1500 : 110); evs[nev].key = k | FK_RELEASE; nev++;
+ }
+ hold = 0;
+ }
+ else if (sscanf(line, "%d hold", &t) == 1) hold = 1;
+ }
+ fclose(f);
+ for (int i = 1; i < nev; i++)
+ for (int j = i; j > 0 && evs[j].t < evs[j - 1].t; j--)
+ {
+ struct ev tmp = evs[j]; evs[j] = evs[j - 1]; evs[j - 1] = tmp;
+ }
+ fos_ui_init();
+ sim_fonts();
+ sim_films();
+ fos_port_palette();
+ fos_ui_run(open);
+ if (frame_dirty) dump();
+ fprintf(stderr, "%d frames, %d ms\n", frame_no, now_ms);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/textest.c b/ml-dev/filmos/sim/textest.c
new file mode 100644
index 0000000..8ec1471
--- /dev/null
+++ b/ml-dev/filmos/sim/textest.c
@@ -0,0 +1,32 @@
+/* textest: the label textures unrolled, for checking the art */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../fos.h"
+
+void sim_fonts(); /* fonts.c */
+void *fos_port_alloc(int size) { return malloc(size); }
+void fos_port_free(void *p) { free(p); }
+/* fos_film.c's private layout */
+struct can_view { int film, exposures; uint16_t *tex; uint8_t ink_ramp[16]; uint16_t ink_lv[16]; int ninks; };
+int main()
+{
+ fos_gfx_init();
+ sim_fonts();
+ FILE *f = fopen("out/tex.ppm", "wb");
+ fprintf(f, "P6 320 %d 255\n", 150 * fos_nfilms);
+ for (int film = 0; film < fos_nfilms; film++)
+ {
+ struct can_view *c = (struct can_view *) fos_can_new(film, 36);
+ for (int v = 0; v < 150; v++)
+ for (int u = 0; u < 320; u++)
+ {
+ uint16_t t = c->tex[u * 150 + v];
+ int k = (t >> 8) & 15 ? ((t >> 4) & 15) : (t & 15);
+ uint32_t rgb = fos_pal[fos_ix(FC(c->ink_ramp[k], c->ink_lv[k] * 255 / 4095))];
+ fputc(rgb >> 16, f); fputc((rgb >> 8) & 255, f); fputc(rgb & 255, f);
+ }
+ }
+ fclose(f);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/tools/armcount.py b/ml-dev/filmos/sim/tools/armcount.py
new file mode 100644
index 0000000..6228831
--- /dev/null
+++ b/ml-dev/filmos/sim/tools/armcount.py
@@ -0,0 +1,91 @@
+"""Count ARM instructions executed, per function, from qemu-arm's log.
+
+ qemu-arm -d in_asm,exec,nochain -D /dev/stderr ./prog 2>&1 >/dev/null | python3 armcount.py
+
+The camera has no profiler; this gives the instruction budget of the
+same code compiled for ARMv5TE."""
+
+import bisect
+import re
+import subprocess
+import sys
+from collections import Counter
+
+# qemu leaves some blocks unnamed; name them from the binary's symbols
+syms = []
+if len(sys.argv) > 1:
+ for l in subprocess.run(["arm-linux-gnueabi-nm", "-n", sys.argv[1]], capture_output=True, text=True).stdout.splitlines():
+ parts = l.split()
+ if len(parts) == 3 and parts[1] in "tTwW":
+ syms.append((int(parts[0], 16), parts[2]))
+addrs = [a for a, _ in syms]
+
+def name_of(pc):
+ i = bisect.bisect_right(addrs, pc) - 1
+ return syms[i][1] if i >= 0 else "?"
+
+tb_size = {}
+tb_func = {}
+execs = Counter()
+cur_func, cur_start, cur_n = None, None, 0
+insn = re.compile(r"^0x([0-9a-f]+):\s")
+trace = re.compile(r"^Trace \d+: 0x[0-9a-f]+ \[[0-9a-f]+/([0-9a-f]+)/")
+
+for line in sys.stdin:
+ if line.startswith("Trace"):
+ m = trace.match(line)
+ if m:
+ execs[int(m.group(1), 16)] += 1
+ continue
+ if line.startswith("IN:"):
+ cur_func = line[3:].strip() or "?"
+ cur_start, cur_n = None, 0
+ continue
+ m = insn.match(line)
+ if m and cur_func is not None and cur_start is None:
+ cur_start = int(m.group(1), 16)
+ continue
+ if line.startswith("OBJD-T:") and cur_start is not None:
+ # no disassembler in this qemu: raw bytes, 4 per ARM instruction
+ cur_n += len(line[7:].strip()) // 8
+ tb_size[cur_start] = cur_n
+ tb_func[cur_start] = cur_func
+
+total = 0
+per = Counter()
+for pc, n in execs.items():
+ k = n * tb_size.get(pc, 0)
+ total += k
+ f = tb_func.get(pc, "?")
+ if f == "?" and syms:
+ f = name_of(pc)
+ per[f] += k
+print(f"total {total:,} ARM instructions")
+if len(sys.argv) > 2 and sys.argv[2] == "--bylines":
+ # every block attributed to the source line of its first instruction
+ pcs = list(execs)
+ res = subprocess.run(["arm-linux-gnueabi-addr2line", "-e", sys.argv[1], "-s"], input="\n".join(hex(pc) for pc in pcs),
+ capture_output=True, text=True).stdout.splitlines()
+ by = Counter()
+ for pc, where in zip(pcs, res):
+ by[where.split(" ")[0]] += execs[pc] * tb_size.get(pc, 0)
+ for w, k in by.most_common(60):
+ print(f"{k:14,} {100.0 * k / total:5.1f}% {w}")
+ sys.exit(0)
+if len(sys.argv) > 2 and sys.argv[2] == "--lines":
+ # the hottest blocks, with their source lines
+ hot = sorted(((n * tb_size.get(pc, 0), pc) for pc, n in execs.items()), reverse=True)[:40]
+ pcs = [hex(pc) for _, pc in hot]
+ lines = subprocess.run(["arm-linux-gnueabi-addr2line", "-e", sys.argv[1], "-f", "-s", "-i"] + pcs,
+ capture_output=True, text=True).stdout.splitlines()
+ # -i may print several frames per address; keep the first two lines of each
+ out, i = [], 0
+ res = subprocess.run(["arm-linux-gnueabi-addr2line", "-e", sys.argv[1], "-s"] + pcs, capture_output=True, text=True).stdout.splitlines()
+ for (k, pc), where in zip(hot, res):
+ print(f"{k:14,} {100.0 * k / total:5.1f}% {hex(pc)} {tb_func.get(pc, name_of(pc) if syms else '?')} {where}")
+ sys.exit(0)
+for f, k in per.most_common(25):
+ try:
+ print(f"{k:14,} {100.0 * k / total:5.1f}% {f}")
+ except BrokenPipeError:
+ break
diff --git a/ml-dev/filmos/sim/tools/checkcr2.py b/ml-dev/filmos/sim/tools/checkcr2.py
new file mode 100644
index 0000000..fc2aff6
--- /dev/null
+++ b/ml-dev/filmos/sim/tools/checkcr2.py
@@ -0,0 +1,27 @@
+"""Check test CR2 files from mkcr2 with LibRaw (rawpy): the camera is
+recognised, the raw samples are exactly the ones written, and the picture
+develops to the expected colours.
+
+ python3 checkcr2.py file.CR2 file.u16 [out.png]
+"""
+import sys
+
+import numpy as np
+import rawpy
+
+cr2, u16 = sys.argv[1], sys.argv[2]
+with rawpy.imread(cr2) as r:
+ s = r.sizes
+ ref = np.fromfile(u16, dtype="<u2").reshape(s.raw_height, s.raw_width)
+ got = r.raw_image
+ same = np.array_equal(got, ref)
+ print(f"{cr2}: raw {s.raw_width}x{s.raw_height} margins {s.left_margin},{s.top_margin} "
+ f"image {s.width}x{s.height} flip {s.flip} pattern {r.raw_pattern.tolist()} "
+ f"colours {r.color_desc.decode()} black {r.black_level_per_channel} white {r.white_level}")
+ print(f" raw samples identical: {same}" + ("" if same else f" ({np.count_nonzero(got != ref)} differ)"))
+ if len(sys.argv) > 3:
+ d = list(r.daylight_whitebalance)
+ rgb = r.postprocess(user_wb=d, output_bps=8, no_auto_bright=True, bright=4.0)
+ from PIL import Image
+ Image.fromarray(rgb).save(sys.argv[3])
+ print(" developed ->", sys.argv[3])
diff --git a/ml-dev/filmos/sim/tools/mkcr2.c b/ml-dev/filmos/sim/tools/mkcr2.c
new file mode 100644
index 0000000..9f8c3a2
--- /dev/null
+++ b/ml-dev/filmos/sim/tools/mkcr2.c
@@ -0,0 +1,546 @@
+/* mkcr2: write test CR2 files shaped like the EOS M's, for the in-camera
+ * development engine (fos_dev.c) and its simulator runs.
+ *
+ * mkcr2 out.CR2 [--scene chart|street] [--small|--half] [--clrs 2|4] [--slices N,W,LAST] [--fold]
+ * [--sensor W,H,LEFT,TOP] another camera's sensor (LibRaw's identify.cpp table)
+ * [--portrait] [--ev 0] [--raw out.u16]
+ * [--image photo.pfm] a photo instead of a made-up scene: linear sRGB,
+ * 0.18 = mid grey (Portable Float Map, 3 channels)
+ *
+ * The scene is made in linear sRGB, turned into what the sensor would
+ * record (the EOS M's colour matrix and daylight balance from LibRaw, an
+ * RGGB mosaic, 14 bits with black at 2048, noise, optical black borders),
+ * and written as Canon does: a TIFF with the raw in its own IFD as a
+ * lossless JPEG cut into vertical slices, and the sensor's borders in the
+ * Canon maker note. LibRaw reads the result (sim/tools/checkcr2.py).
+ */
+
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* ---------------------------------------------------------------- the camera */
+
+static int RAW_W = 5280, RAW_H = 3528; /* the whole sensor read out */
+static int CROP_L = 84, CROP_T = 64, CROP_W = 5184, CROP_H = 3456; /* the picture */
+#define BLACK 2048
+#define WHITE 13600
+
+/* XYZ -> camera, EOS M (LibRaw colordata, same as the 650D) */
+static const double xyz_cam[3][3] = {
+ { 0.6602, -0.0841, -0.0939 }, { -0.4472, 1.2458, 0.2247 }, { -0.0975, 0.2039, 0.6148 } };
+static const double rgb_xyz[3][3] = {
+ { 0.4124564, 0.3575761, 0.1804375 }, { 0.2126729, 0.7151522, 0.0721750 }, { 0.0193339, 0.1191920, 0.9503041 } };
+static double cam_rgb[3][3], pre_mul[3];
+
+static void camera_init()
+{
+ /* as dcraw: camera <- sRGB, rows normalised to 1; their sums are the
+ * daylight multipliers */
+ for (int i = 0; i < 3; i++)
+ {
+ double sum = 0;
+ for (int j = 0; j < 3; j++)
+ {
+ cam_rgb[i][j] = 0;
+ for (int k = 0; k < 3; k++) cam_rgb[i][j] += xyz_cam[i][k] * rgb_xyz[k][j];
+ sum += cam_rgb[i][j];
+ }
+ for (int j = 0; j < 3; j++) cam_rgb[i][j] /= sum;
+ pre_mul[i] = 1 / sum;
+ }
+ for (int i = 0; i < 3; i++) pre_mul[i] /= pre_mul[1] ? pre_mul[1] : 1;
+}
+
+/* ---------------------------------------------------------------- scenes */
+
+static double srgb_to_lin(double v)
+{
+ v /= 255;
+ return v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4);
+}
+
+static const unsigned char checker[24][3] = {
+ { 115, 82, 68 }, { 194, 150, 130 }, { 98, 122, 157 }, { 87, 108, 67 }, { 133, 128, 177 }, { 103, 189, 170 },
+ { 214, 126, 44 }, { 80, 91, 166 }, { 193, 90, 99 }, { 94, 60, 108 }, { 157, 188, 64 }, { 224, 163, 46 },
+ { 56, 61, 150 }, { 70, 148, 73 }, { 175, 54, 60 }, { 231, 199, 31 }, { 187, 86, 149 }, { 8, 133, 161 },
+ { 243, 243, 242 }, { 200, 200, 200 }, { 160, 160, 160 }, { 122, 122, 121 }, { 85, 85, 85 }, { 52, 52, 52 },
+};
+
+static int scene_kind = 0; /* 0 chart, 1 street */
+static float *photo; /* --image: linear sRGB, rows top to bottom */
+static int photo_w, photo_h;
+static int fold = 0; /* --fold */
+
+static double hash01(unsigned x, unsigned y)
+{
+ unsigned h = x * 374761393u + y * 668265263u;
+ h = (h ^ (h >> 13)) * 1274126177u;
+ return ((h ^ (h >> 16)) & 0xFFFFFF) / 16777216.0;
+}
+
+/* linear sRGB at (u, v) in 0..1 across the picture; 0.18 = mid grey */
+static int load_pfm(const char *path)
+{
+ FILE *f = fopen(path, "rb");
+ char kind[3] = { 0 };
+ double scale;
+ if (!f || fscanf(f, "%2s %d %d %lf", kind, &photo_w, &photo_h, &scale) != 4 || strcmp(kind, "PF") || fgetc(f) == EOF)
+ {
+ fprintf(stderr, "%s: not a colour PFM\n", path);
+ return 0;
+ }
+ size_t n = (size_t) photo_w * photo_h * 3;
+ float *rows = malloc(n * sizeof(float));
+ photo = malloc(n * sizeof(float));
+ if (fread(rows, sizeof(float), n, f) != n) { fprintf(stderr, "%s: too short\n", path); return 0; }
+ fclose(f);
+ /* PFM rows go bottom to top; little endian (scale < 0) is all this reads */
+ for (int y = 0; y < photo_h; y++)
+ memcpy(photo + (size_t) y * photo_w * 3, rows + (size_t) (photo_h - 1 - y) * photo_w * 3, photo_w * 3 * sizeof(float));
+ free(rows);
+ return 1;
+}
+
+static void scene(double u, double v, double rgb[3])
+{
+ if (photo)
+ {
+ /* bilinear, so a smaller photo still gives a smooth mosaic */
+ double x = u * photo_w - 0.5, y = v * photo_h - 0.5;
+ int x0 = (int) floor(x), y0 = (int) floor(y);
+ double fx = x - x0, fy = y - y0;
+ for (int i = 0; i < 3; i++) rgb[i] = 0;
+ for (int dy = 0; dy < 2; dy++)
+ for (int dx = 0; dx < 2; dx++)
+ {
+ int px = x0 + dx < 0 ? 0 : x0 + dx >= photo_w ? photo_w - 1 : x0 + dx;
+ int py = y0 + dy < 0 ? 0 : y0 + dy >= photo_h ? photo_h - 1 : y0 + dy;
+ double w = (dx ? fx : 1 - fx) * (dy ? fy : 1 - fy);
+ const float *p = photo + ((size_t) py * photo_w + px) * 3;
+ for (int i = 0; i < 3; i++) rgb[i] += w * p[i];
+ }
+ return;
+ }
+ if (scene_kind == 0)
+ {
+ /* a colour checker on a grey card, a step wedge under it, sky above */
+ if (v < 0.22)
+ {
+ double t = v / 0.22;
+ rgb[0] = 0.10 + 0.15 * t; rgb[1] = 0.20 + 0.15 * t; rgb[2] = 0.45 + 0.08 * t;
+ /* the sun, burnt out, top right */
+ double dx = u - 0.86, dy = v - 0.09, d = sqrt(dx * dx + dy * dy * 2.25);
+ if (d < 0.035) rgb[0] = rgb[1] = rgb[2] = 30;
+ return;
+ }
+ double gx = (u - 0.12) / 0.76, gy = (v - 0.27) / 0.48;
+ if (gx >= 0 && gx < 1 && gy >= 0 && gy < 1)
+ {
+ int cx = (int) (gx * 6), cy = (int) (gy * 4);
+ double fx = gx * 6 - cx, fy = gy * 4 - cy;
+ if (fx > 0.08 && fx < 0.92 && fy > 0.08 && fy < 0.92)
+ {
+ const unsigned char *c = checker[cy * 6 + cx];
+ for (int i = 0; i < 3; i++) rgb[i] = srgb_to_lin(c[i]);
+ return;
+ }
+ rgb[0] = rgb[1] = rgb[2] = 0.035; /* the chart's black frame */
+ return;
+ }
+ if (v > 0.82 && v < 0.94 && u > 0.08 && u < 0.92)
+ {
+ int step = (int) ((u - 0.08) / 0.84 * 11);
+ rgb[0] = rgb[1] = rgb[2] = 0.18 * pow(2, step - 6.5); /* -6.5 .. +3.5 stops */
+ return;
+ }
+ rgb[0] = rgb[1] = rgb[2] = 0.18 * (0.9 + 0.2 * u); /* grey card, a little uneven */
+ return;
+ }
+ /* street at golden hour: sky, a warm wall with windows, a red door,
+ * green plants, a shadowed pavement */
+ double horizon = 0.38;
+ if (v < horizon)
+ {
+ double t = v / horizon;
+ rgb[0] = 0.25 + 0.55 * t; rgb[1] = 0.35 + 0.35 * t; rgb[2] = 0.65 - 0.15 * t;
+ double dx = u - 0.2, dy = v - 0.28, d = sqrt(dx * dx + dy * dy);
+ if (d < 0.03) rgb[0] = rgb[1] = rgb[2] = 40; /* low sun */
+ else if (d < 0.12) { double g = (0.12 - d) / 0.09; rgb[0] += 2 * g; rgb[1] += 1.2 * g; rgb[2] += 0.4 * g; }
+ return;
+ }
+ double wall[3] = { 0.55, 0.32, 0.18 };
+ for (int i = 0; i < 3; i++) rgb[i] = wall[i] * (0.8 + 0.4 * hash01((unsigned) (u * 400), (unsigned) (v * 300)));
+ if (u > 0.55 && u < 0.65 && v > 0.5 && v < 0.85) { rgb[0] = 0.32; rgb[1] = 0.03; rgb[2] = 0.035; } /* door */
+ for (int k = 0; k < 3; k++)
+ {
+ double wx = 0.1 + k * 0.15;
+ if (u > wx && u < wx + 0.08 && v > 0.45 && v < 0.6) { rgb[0] = 0.04; rgb[1] = 0.05; rgb[2] = 0.07; }
+ }
+ if (v > 0.72 && (u < 0.5 || u > 0.7))
+ {
+ double n = hash01((unsigned) (u * 900), (unsigned) (v * 700));
+ rgb[0] = 0.03 + 0.03 * n; rgb[1] = 0.09 + 0.08 * n; rgb[2] = 0.03 + 0.02 * n; /* plants */
+ }
+ if (v > 0.9) { rgb[0] = 0.05; rgb[1] = 0.055; rgb[2] = 0.07; } /* shade */
+}
+
+/* ---------------------------------------------------------------- the sensor */
+
+static uint16_t *raw;
+
+static double gauss()
+{
+ double u = (rand() + 1.0) / (RAND_MAX + 2.0), v = (rand() + 1.0) / (RAND_MAX + 2.0);
+ return sqrt(-2 * log(u)) * cos(6.283185307 * v);
+}
+
+static void expose(int portrait, double ev)
+{
+ raw = malloc((size_t) RAW_W * RAW_H * 2);
+ double gain = 1400 * pow(2, ev); /* mid grey ~ 3 stops under white */
+ for (int y = 0; y < RAW_H; y++)
+ for (int x = 0; x < RAW_W; x++)
+ {
+ double val = 0;
+ /* as on the EOS M, light reaches 12 columns and rows outside
+ * the picture area Canon names */
+ if (x >= CROP_L - 12 * RAW_W / 5280 && y >= CROP_T - 12 * RAW_H / 3528)
+ {
+ double u = (x - CROP_L + 0.5) / CROP_W, v = (y - CROP_T + 0.5) / CROP_H;
+ if (portrait)
+ {
+ /* the camera on its side (orientation 6: the picture is
+ * the sensor turned a quarter clockwise) */
+ double t = u; u = 1 - v; v = t;
+ }
+ double lin[3], cam[3];
+ scene(u, v, lin);
+ for (int i = 0; i < 3; i++)
+ {
+ cam[i] = 0;
+ for (int j = 0; j < 3; j++) cam[i] += cam_rgb[i][j] * lin[j];
+ cam[i] /= pre_mul[i];
+ }
+ int c = (y & 1) * 2 + (x & 1); /* RGGB */
+ double e = (c == 0 ? cam[0] : c == 3 ? cam[2] : cam[1]) / 0.18 * gain;
+ if (e < 0) e = 0;
+ val = e + sqrt(e + 1) * 0.6 * gauss();
+ }
+ double dn = BLACK + val + 6 * gauss(); /* read noise; borders: optical black */
+ raw[(size_t) y * RAW_W + x] = (uint16_t) (dn < 0 ? 0 : dn > 16383 ? 16383 : dn > WHITE + 300 ? WHITE + 300 : dn);
+ }
+}
+
+/* ---------------------------------------------------------------- lossless JPEG */
+
+static unsigned char *out;
+static size_t out_len, out_cap;
+
+static void put8(int b)
+{
+ if (out_len == out_cap) out = realloc(out, out_cap = out_cap ? out_cap * 2 : 1 << 20);
+ out[out_len++] = (unsigned char) b;
+}
+
+static uint64_t bitacc;
+static int bitn;
+
+static void putbits(unsigned v, int n)
+{
+ bitacc = (bitacc << n) | (v & ((1u << n) - 1));
+ bitn += n;
+ while (bitn >= 8)
+ {
+ int b = (int) (bitacc >> (bitn - 8)) & 0xFF;
+ put8(b);
+ if (b == 0xFF) put8(0); /* byte stuffing */
+ bitn -= 8;
+ }
+}
+
+static void flushbits()
+{
+ if (bitn) putbits(0x7F, 8 - bitn); /* pad with ones */
+}
+
+struct huff { unsigned char bits[17], vals[17]; int nvals; unsigned code[17]; int len[17]; };
+
+/* JPEG Annex K.2: code lengths from frequencies, at most 16 bits */
+static void huff_build(struct huff *h, const long freq_in[17])
+{
+ long freq[18];
+ int codesize[18] = { 0 }, others[18];
+ for (int i = 0; i < 17; i++) freq[i] = freq_in[i];
+ freq[17] = 1; /* reserved: no code is all ones */
+ for (int i = 0; i < 18; i++) others[i] = -1;
+ for (;;)
+ {
+ int v1 = -1, v2 = -1;
+ for (int i = 0; i < 18; i++)
+ if (freq[i] && (v1 < 0 || freq[i] <= freq[v1])) v1 = i;
+ for (int i = 0; i < 18; i++)
+ if (freq[i] && i != v1 && (v2 < 0 || freq[i] <= freq[v2])) v2 = i;
+ if (v2 < 0) break;
+ freq[v1] += freq[v2];
+ freq[v2] = 0;
+ codesize[v1]++;
+ while (others[v1] >= 0) { v1 = others[v1]; codesize[v1]++; }
+ others[v1] = v2;
+ codesize[v2]++;
+ while (others[v2] >= 0) { v2 = others[v2]; codesize[v2]++; }
+ }
+ int bits[40] = { 0 };
+ for (int i = 0; i < 18; i++) if (codesize[i]) bits[codesize[i]]++;
+ for (int i = 39; i > 16; i--)
+ while (bits[i] > 0)
+ {
+ int j = i - 2;
+ while (!bits[j]) j--;
+ bits[i] -= 2; bits[i - 1]++; bits[j + 1] += 2; bits[j]--;
+ }
+ int i = 16;
+ while (!bits[i]) i--;
+ bits[i]--; /* drop the reserved code */
+ memset(h, 0, sizeof(*h));
+ for (int l = 1; l <= 16; l++) h->bits[l] = (unsigned char) bits[l];
+ /* symbols by code size, then value */
+ int n = 0;
+ for (int l = 1; l <= 32; l++)
+ for (int s = 0; s < 17; s++)
+ if (codesize[s] == l) h->vals[n++] = (unsigned char) s;
+ h->nvals = n;
+ unsigned code = 0;
+ int k = 0;
+ for (int l = 1; l <= 16; l++, code <<= 1)
+ for (int c = 0; c < h->bits[l]; c++, k++)
+ {
+ h->code[h->vals[k]] = code++;
+ h->len[h->vals[k]] = l;
+ }
+}
+
+static int ssss(int d)
+{
+ int a = d < 0 ? -d : d, n = 0;
+ while (a) { n++; a >>= 1; }
+ return n;
+}
+
+/* the Huffman table of component c: LibRaw (and so Canon) take table c,
+ * or the last one defined, whatever the scan header says */
+#define TABLE(c) ((c) < 1 ? 0 : 1)
+
+static void ljpeg_write(int clrs, const int slices[3])
+{
+ /* --fold: the frame twice as wide and half as high, as some cameras
+ * store it (the samples run the same) */
+ int jwide = fold ? 2 * RAW_W : RAW_W, wide = jwide / clrs, high = fold ? RAW_H / 2 : RAW_H;
+ size_t n = (size_t) RAW_W * RAW_H;
+ /* the samples in the order Canon stores them: slice by slice */
+ uint16_t *seq = malloc(n * 2);
+ size_t k = 0;
+ for (int s = 0; s <= slices[0]; s++)
+ {
+ int x0 = s * slices[1], w = s < slices[0] ? slices[1] : slices[2];
+ for (int y = 0; y < RAW_H; y++)
+ for (int x = 0; x < w; x++)
+ seq[k++] = raw[(size_t) y * RAW_W + x0 + x];
+ }
+ /* differences, as the decoder will predict them */
+ int *diff = malloc(n * sizeof(int));
+ int vpred[4];
+ for (int c = 0; c < clrs; c++) vpred[c] = 1 << 13;
+ long freq[4][17];
+ memset(freq, 0, sizeof(freq));
+ for (int r = 0; r < high; r++)
+ for (int col = 0; col < wide; col++)
+ for (int c = 0; c < clrs; c++)
+ {
+ size_t i = (size_t) r * jwide + col * clrs + c;
+ int pred = col ? seq[i - clrs] : vpred[c];
+ int d = (int) seq[i] - pred;
+ if (!col) vpred[c] = seq[i];
+ diff[i] = d;
+ freq[TABLE(c)][ssss(d)]++;
+ }
+ struct huff h[2];
+ huff_build(&h[0], freq[0]);
+ huff_build(&h[1], freq[1]);
+ int ntab = clrs > 1 ? 2 : 1;
+
+ put8(0xFF); put8(0xD8);
+ for (int t = 0; t < ntab; t++)
+ {
+ put8(0xFF); put8(0xC4);
+ int len = 2 + 1 + 16 + h[t].nvals;
+ put8(len >> 8); put8(len & 0xFF);
+ put8(t);
+ for (int l = 1; l <= 16; l++) put8(h[t].bits[l]);
+ for (int v = 0; v < h[t].nvals; v++) put8(h[t].vals[v]);
+ }
+ put8(0xFF); put8(0xC3);
+ int len = 8 + 3 * clrs;
+ put8(len >> 8); put8(len & 0xFF);
+ put8(14); put8(high >> 8); put8(high & 0xFF); put8(wide >> 8); put8(wide & 0xFF); put8(clrs);
+ for (int c = 0; c < clrs; c++) { put8(c + 1); put8(0x11); put8(0); }
+ put8(0xFF); put8(0xDA);
+ len = 6 + 2 * clrs;
+ put8(len >> 8); put8(len & 0xFF);
+ put8(clrs);
+ for (int c = 0; c < clrs; c++) { put8(c + 1); put8(TABLE(c) << 4); }
+ put8(1); put8(0); put8(0); /* predictor 1, Pt 0 */
+ for (size_t i = 0; i < n; i++)
+ {
+ int c = (int) (i % jwide) % clrs, d = diff[i], s = ssss(d);
+ const struct huff *t = &h[ntab > 1 ? TABLE(c) : 0];
+ putbits(t->code[s], t->len[s]);
+ if (s && s < 16) putbits(d < 0 ? (unsigned) (d + (1 << s) - 1) : (unsigned) d, s);
+ }
+ flushbits();
+ put8(0xFF); put8(0xD9);
+ free(seq);
+ free(diff);
+}
+
+/* ---------------------------------------------------------------- TIFF */
+
+static unsigned char *tif;
+static size_t tif_len;
+
+static void w16(size_t at, int v) { tif[at] = v & 0xFF; tif[at + 1] = (v >> 8) & 0xFF; }
+static void w32(size_t at, unsigned v) { for (int i = 0; i < 4; i++) tif[at + i] = (v >> (8 * i)) & 0xFF; }
+
+struct entry { int tag, type; unsigned count, value; };
+
+/* an IFD at `at`; returns its size */
+static size_t ifd(size_t at, const struct entry *e, int n, unsigned next)
+{
+ w16(at, n);
+ for (int i = 0; i < n; i++)
+ {
+ size_t p = at + 2 + 12 * i;
+ w16(p, e[i].tag); w16(p + 2, e[i].type); w32(p + 4, e[i].count);
+ if (e[i].type == 3 && e[i].count == 1) { w16(p + 8, e[i].value); w16(p + 10, 0); }
+ else w32(p + 8, e[i].value);
+ }
+ w32(at + 2 + 12 * n, next);
+ return 2 + 12 * (size_t) n + 4;
+}
+
+static size_t put_bytes(size_t at, const void *p, size_t n)
+{
+ memcpy(tif + at, p, n);
+ return at + n;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2)
+ {
+ fprintf(stderr, "usage: mkcr2 out.CR2 [--scene chart|street] [--small|--half] [--clrs 2|4] "
+ "[--slices N,W,LAST] [--portrait] [--ev x] [--raw out.u16] [--seed n] [--image photo.pfm]\n");
+ return 1;
+ }
+ int clrs = 2, portrait = 0, slices[3] = { 2, 1760, 1760 };
+ double ev = 0;
+ const char *raw_out = 0;
+ unsigned seed = 1;
+ for (int i = 2; i < argc; i++)
+ {
+ if (!strcmp(argv[i], "--small"))
+ {
+ /* a quarter of the size in each direction, same layout */
+ RAW_W = 1320; RAW_H = 882; CROP_L = 20; CROP_T = 16; CROP_W = 1296; CROP_H = 864;
+ slices[0] = 2; slices[1] = 440; slices[2] = 440;
+ }
+ else if (!strcmp(argv[i], "--half"))
+ {
+ /* half the size each way: enough samples per screen pixel for every colour */
+ RAW_W = 2640; RAW_H = 1764; CROP_L = 42; CROP_T = 32; CROP_W = 2592; CROP_H = 1728;
+ slices[0] = 2; slices[1] = 880; slices[2] = 880;
+ }
+ else if (!strcmp(argv[i], "--sensor") && i + 1 < argc)
+ {
+ /* the raw frame and where the picture starts in it; three slices as wide as they can be */
+ sscanf(argv[++i], "%d,%d,%d,%d", &RAW_W, &RAW_H, &CROP_L, &CROP_T);
+ CROP_W = (RAW_W - CROP_L) & ~1; CROP_H = (RAW_H - CROP_T) & ~1;
+ slices[0] = 2; slices[1] = (RAW_W / 3) & ~3; slices[2] = RAW_W - 2 * slices[1];
+ }
+ else if (!strcmp(argv[i], "--clrs") && i + 1 < argc) clrs = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "--slices") && i + 1 < argc)
+ sscanf(argv[++i], "%d,%d,%d", &slices[0], &slices[1], &slices[2]);
+ else if (!strcmp(argv[i], "--portrait")) portrait = 1;
+ else if (!strcmp(argv[i], "--fold")) fold = 1;
+ else if (!strcmp(argv[i], "--ev") && i + 1 < argc) ev = atof(argv[++i]);
+ else if (!strcmp(argv[i], "--raw") && i + 1 < argc) raw_out = argv[++i];
+ else if (!strcmp(argv[i], "--seed") && i + 1 < argc) seed = (unsigned) atoi(argv[++i]);
+ else if (!strcmp(argv[i], "--scene") && i + 1 < argc) scene_kind = !strcmp(argv[++i], "street");
+ else if (!strcmp(argv[i], "--image") && i + 1 < argc) { if (!load_pfm(argv[++i])) return 1; }
+ }
+ if (slices[0] * slices[1] + slices[2] != RAW_W || RAW_W % clrs)
+ {
+ fprintf(stderr, "slices %d x %d + %d don't make %d columns\n", slices[0], slices[1], slices[2], RAW_W);
+ return 1;
+ }
+ srand(seed);
+ camera_init();
+ expose(portrait, ev);
+ ljpeg_write(clrs, slices);
+
+ tif = calloc(1, out_len + 65536);
+ /* header, the CR2 signature and where the raw IFD is */
+ tif[0] = 'I'; tif[1] = 'I'; w16(2, 42); w32(4, 16);
+ tif[8] = 'C'; tif[9] = 'R'; tif[10] = 2; tif[11] = 0;
+ size_t ifd0 = 16, exif = 512, mnote = 1024, ifd3 = 2048, data = 4096;
+ /* strings and arrays */
+ size_t make = data, model = data + 16, date = data + 48, sinfo = data + 80, thumb = data + 128;
+ put_bytes(make, "Canon", 6);
+ put_bytes(model, "Canon EOS M", 12);
+ put_bytes(date, "2026:10:22 17:45:00", 20);
+ int si[17] = { 34, RAW_W, RAW_H, 1, 1, CROP_L, CROP_T, CROP_L + CROP_W - 1, CROP_T + CROP_H - 1,
+ 0, 0, 0, 0, 0, 0, 0, 0 }; /* no black mask: the EOS M gives none */
+ for (int i = 0; i < 17; i++) w16(sinfo + 2 * i, si[i]);
+ static const unsigned char tiny_jpeg[] = { 0xFF, 0xD8, 0xFF, 0xD9 };
+ put_bytes(thumb, tiny_jpeg, sizeof(tiny_jpeg));
+ size_t rawdata = data + 256;
+ put_bytes(rawdata, out, out_len);
+ tif_len = rawdata + out_len;
+
+ struct entry e0[] = {
+ { 0x0100, 4, 1, CROP_W }, { 0x0101, 4, 1, CROP_H }, { 0x0102, 3, 1, 8 }, { 0x0103, 3, 1, 6 },
+ { 0x010F, 2, 6, (unsigned) make }, { 0x0110, 2, 12, (unsigned) model },
+ { 0x0111, 4, 1, (unsigned) thumb }, { 0x0112, 3, 1, portrait ? 6 : 1 },
+ { 0x0117, 4, 1, sizeof(tiny_jpeg) }, { 0x0132, 2, 20, (unsigned) date }, { 0x8769, 4, 1, (unsigned) exif },
+ };
+ ifd(ifd0, e0, sizeof(e0) / sizeof(e0[0]), (unsigned) ifd3);
+ struct entry ex[] = {
+ { 0x8827, 3, 1, 400 }, { 0x9003, 2, 20, (unsigned) date }, { 0x927C, 7, 2 + 12 * 2 + 4, (unsigned) mnote },
+ };
+ ifd(exif, ex, sizeof(ex) / sizeof(ex[0]), 0);
+ struct entry mn[] = { { 0x0010, 4, 1, 0x80000331 }, { 0x00E0, 3, 17, (unsigned) sinfo } };
+ ifd(mnote, mn, 2, 0);
+ w32(12, (unsigned) ifd3);
+ struct entry e3[] = {
+ { 0x0103, 3, 1, 6 }, { 0x0111, 4, 1, (unsigned) rawdata }, { 0x0117, 4, 1, (unsigned) out_len },
+ { 0xC5D8, 4, 1, 1 }, { 0xC5E0, 4, 1, 1 }, { 0xC640, 3, 3, (unsigned) (sinfo + 64) },
+ };
+ w16(sinfo + 64, slices[0]); w16(sinfo + 66, slices[1]); w16(sinfo + 68, slices[2]);
+ ifd(ifd3, e3, sizeof(e3) / sizeof(e3[0]), 0);
+
+ FILE *f = fopen(argv[1], "wb");
+ if (!f) { perror(argv[1]); return 1; }
+ fwrite(tif, 1, tif_len, f);
+ fclose(f);
+ if (raw_out)
+ {
+ f = fopen(raw_out, "wb");
+ fwrite(raw, 2, (size_t) RAW_W * RAW_H, f);
+ fclose(f);
+ }
+ fprintf(stderr, "%s: %dx%d raw, %d components, slices %d x %d + %d, %.1f MB\n", argv[1], RAW_W, RAW_H,
+ clrs, slices[0], slices[1], slices[2], tif_len / 1048576.0);
+ return 0;
+}
diff --git a/ml-dev/filmos/sim/topng.py b/ml-dev/filmos/sim/topng.py
new file mode 100644
index 0000000..81c8435
--- /dev/null
+++ b/ml-dev/filmos/sim/topng.py
@@ -0,0 +1,64 @@
+"""Convert simulator frames (8-bit indices + their .pal, else out/pal.bin) to PNG / GIF.
+
+ python3 topng.py out/gfxtest.idx # -> out/gfxtest.png
+ python3 topng.py --gif out/anim.gif out/frames/*.idx
+ python3 topng.py --sheet out/sheet.png out/frames/*.idx
+"""
+
+import sys
+from pathlib import Path
+
+import numpy as np
+from PIL import Image
+
+W, H = 720, 480
+OUT = Path(__file__).resolve().parent / "out"
+
+
+def palette():
+ p = np.fromfile(OUT / "pal.bin", dtype="<u4")
+ rgb = np.stack([(p >> 16) & 255, (p >> 8) & 255, p & 255], axis=1).astype(np.uint8)
+ rgb[0] = (40, 70, 60) # index 0 is "LiveView shows through": a dull green stands in
+ return rgb
+
+
+def load(path, pal):
+ idx = np.fromfile(path, dtype=np.uint8)[: W * H].reshape(H, W)
+ own = Path(path).with_suffix(".pal")
+ if own.exists():
+ # the palette the frame was shown with (photographs bring their own)
+ p = np.fromfile(own, dtype="<u4")
+ pal = np.stack([(p >> 16) & 255, (p >> 8) & 255, p & 255], axis=1).astype(np.uint8)
+ pal[0] = (40, 70, 60)
+ return Image.fromarray(pal[idx], "RGB")
+
+
+def main(argv):
+ pal = palette()
+ if argv[0] == "--gif":
+ out, frames = argv[1], argv[2:]
+ imgs = [load(f, pal) for f in frames]
+ # frame names end in _<ms>.idx: keep the real timing
+ times = [int(Path(f).stem.split("_")[-1]) for f in frames]
+ durs = [max(20, b - a) for a, b in zip(times, times[1:])] + [800]
+ imgs[0].save(out, save_all=True, append_images=imgs[1:], duration=durs, loop=0, optimize=False)
+ print(out, len(imgs), "frames")
+ elif argv[0] == "--sheet":
+ out, frames = argv[1], argv[2:]
+ cols = 3
+ imgs = [load(f, pal) for f in frames]
+ rows = (len(imgs) + cols - 1) // cols
+ sheet = Image.new("RGB", (cols * W // 2, rows * H // 2))
+ for i, im in enumerate(imgs):
+ sheet.paste(im.resize((W // 2, H // 2), Image.LANCZOS), (i % cols * W // 2, i // cols * H // 2))
+ sheet.save(out)
+ print(out)
+ else:
+ for f in argv:
+ out = Path(f).with_suffix(".png")
+ load(f, pal).save(out)
+ print(out)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
diff --git a/ml-dev/filmos/tools/catalog.py b/ml-dev/filmos/tools/catalog.py
new file mode 100644
index 0000000..b40385d
--- /dev/null
+++ b/ml-dev/filmos/tools/catalog.py
@@ -0,0 +1,175 @@
+"""What the camera shows of the films beyond the built-in eight: the line
+under the name on the shelf, and the canister label (struct fos_label).
+The look itself comes from films/films.py; genfilms.py puts both together.
+
+A label: style (band, cap or stripes), inks as (ramp, level), the small
+line on top, the name, the big number (digits and H, P, T only) and the
+small line under it. A B&W film's leader is grey.
+"""
+
+GRAY, METAL, AMBER, RED, ORANGE, CRIMSON, GREEN, VIOLET, BLUE = range(9)
+BAND, CAP, STRIPES = range(3)
+
+DESC = {
+ "cinestill400t": "Your own LUT, cine colour",
+ "portra160": "Fine grain, natural skin tones",
+ "portra800": "Low light portraits, warm grain",
+ "portra160nc": "Natural colour, soft contrast",
+ "portra160vc": "Vivid colour for portraits",
+ "portra400nc": "Neutral skin, quiet colour",
+ "portra400vc": "More colour, same skin tones",
+ "portra400uc": "Ultra colour, punchy everyday",
+ "elite200": "Bright consumer colour",
+ "elite400": "Everyday colour, more speed",
+ "pro160c": "Crisp colour, cool and clean",
+ "pro400h": "Airy pastels, fourth colour layer",
+ "pro800z": "Night portraits, soft palette",
+ "reala100": "True-to-life colour, fine grain",
+ "superia100": "Clean daylight colour",
+ "superia200": "Fuji greens, everyday snaps",
+ "superia800": "Indoor speed, Fuji colour",
+ "superia1600": "Night snaps, bold grain",
+ "xtra800": "Fast all-rounder, cool shadows",
+ "vista200": "Warm reds, holiday colour",
+ "ultra100": "Saturated, punchy Agfa colour",
+ "redscale100": "Shot through the back: red-orange",
+ "velvia100": "Rich colour, softer than the 50",
+ "provia100f": "Neutral slide, faithful colour",
+ "provia400f": "Fast slide, clean colour",
+ "provia400x": "Fast slide, finer grain",
+ "astia100f": "Soft slide film for skin",
+ "sensia100": "Bright consumer slide",
+ "kodachrome25": "Legendary fine grain, deep reds",
+ "kodachrome64": "Magazine colour of the 70s",
+ "kodachrome200": "Faster Kodachrome, warm grain",
+ "e100gx": "Warm, gentle Ektachrome",
+ "e100vs": "Very saturated Ektachrome",
+ "elitechrome200": "Everyday Kodak slide",
+ "elitechrome400": "Fast Kodak slide, more grain",
+ "extracolor100": "Extra saturated Kodak slide",
+ "precisa100": "Cool, crisp Agfa slide",
+ "elite100xpro": "Slide in C-41: wild contrast",
+ "superia200xpro": "Cross-processed, yellow highlights",
+ "xproslide200": "Cross-process blues and yellows",
+ "tmax100": "Ultra fine grain, smooth tones",
+ "tmax400": "Sharp, modern B&W",
+ "tmax3200": "Push-ready, grainy nights",
+ "bw400cn": "Chromogenic B&W, smooth grain",
+ "hie": "Infrared: white leaves, dark skies",
+ "delta100": "Fine, sharp modern B&W",
+ "delta400": "Smooth grain at 400",
+ "delta3200": "Pushes into the dark",
+ "fp4": "Classic medium speed B&W",
+ "panf50": "Slow, super fine grain",
+ "hps800": "Fast classic Ilford",
+ "xp2": "C-41 B&W, smooth tones",
+ "acros100": "Fine grain, deep blacks",
+ "neopan1600": "Fast and contrasty B&W",
+ "apx25": "Very fine, slow Agfa B&W",
+ "apx100": "Classic Agfa B&W",
+ "retro80s": "Extended red, dark skies",
+ "retro100": "Soft tonal B&W",
+ "ortho25": "Orthochromatic: reds go dark",
+ "ir400": "Infrared touch, glowing foliage",
+ "kodak2383": "Cinema print: teal shadows",
+ "kodak2393": "Cinema print, richer blacks",
+ "fuji3510": "Fuji print film, soft colour",
+ "fuji3513": "Fuji print for digital masters",
+}
+
+
+def L(style, bg, band, accent, text, num, top, word, num_s, sub="", leader=0):
+ return dict(style=style, bg=bg, band=band, accent=accent, text=text, num=num,
+ top=top, word=word, num_s=num_s, sub=sub, leader=leader)
+
+
+W, K = (GRAY, 238), (GRAY, 22) # white and black ink
+YEL, KRED = (AMBER, 190), (RED, 150)
+
+
+def portra(num, sub=""):
+ return L(CAP, (GRAY, 226), YEL, KRED, K, K, "KODAK PROFESSIONAL", "PORTRA", num, sub)
+
+
+def superia(num, band, word="SUPERIA", sub=""):
+ return L(BAND, (GREEN, 140), band, W, W, W, "FUJIFILM", word, num, sub)
+
+
+def ilford(word, num, accent, sub=""):
+ return L(BAND, (GRAY, 236), (GRAY, 20), accent, W, (GRAY, 20), "ILFORD", word, num, sub, leader=52)
+
+
+def rollei(word, num, band, sub=""):
+ return L(BAND, K, band, (GRAY, 230), W, (GRAY, 230), "ROLLEI", word, num, sub, leader=50)
+
+
+def provia(num, bg, sub):
+ return L(STRIPES, bg, bg, (GREEN, 170), W, (GREEN, 190), "FUJICHROME", "PROVIA", num, sub)
+
+
+LABELS = {
+ "cinestill400t": L(STRIPES, (GRAY, 20), (GRAY, 20), KRED, W, W, "", "CINESTILL", "400T", "CINE"),
+ "portra160": portra("160"),
+ "portra800": portra("800"),
+ "portra160nc": portra("160", "NC"),
+ "portra160vc": portra("160", "VC"),
+ "portra400nc": portra("400", "NC"),
+ "portra400vc": portra("400", "VC"),
+ "portra400uc": portra("400", "UC"),
+ "elite200": L(BAND, YEL, (RED, 148), (RED, 148), W, K, "KODAK", "ELITE", "200", "COLOR"),
+ "elite400": L(BAND, YEL, (RED, 148), (RED, 148), W, K, "KODAK", "ELITE", "400", "COLOR"),
+ "pro160c": L(BAND, (GRAY, 236), (GREEN, 110), (GREEN, 110), W, (GREEN, 90), "FUJICOLOR", "PRO", "160", "160C"),
+ "pro400h": L(BAND, (GRAY, 236), (GREEN, 110), (GREEN, 110), W, (GREEN, 90), "FUJICOLOR", "PRO", "400", "400H"),
+ "pro800z": L(BAND, (GRAY, 236), (GREEN, 110), (GREEN, 110), W, (GREEN, 90), "FUJICOLOR", "PRO", "800", "800Z"),
+ "reala100": L(STRIPES, (BLUE, 110), (BLUE, 110), (GREEN, 150), W, W, "FUJICOLOR", "REALA", "100"),
+ "superia100": superia("100", (RED, 140)),
+ "superia200": superia("200", (GREEN, 70)),
+ "superia800": superia("800", (VIOLET, 100)),
+ "superia1600": superia("1600", (GRAY, 24)),
+ "xtra800": superia("800", (VIOLET, 100), "X-TRA", "SUPERIA"),
+ "vista200": L(BAND, (RED, 150), (ORANGE, 175), W, K, W, "AGFA", "VISTA", "200"),
+ "ultra100": L(BAND, (CRIMSON, 120), (ORANGE, 175), W, K, W, "AGFA", "ULTRA", "100", "COLOR"),
+ "redscale100": L(BAND, (RED, 150), K, (ORANGE, 185), W, K, "LOMOGRAPHY", "REDSCALE", "100"),
+ "velvia100": L(STRIPES, (VIOLET, 140), (VIOLET, 140), (VIOLET, 225), W, (VIOLET, 225), "FUJICHROME", "VELVIA", "100", "RVP 100"),
+ "provia100f": provia("100", (BLUE, 140), "RDP III"),
+ "provia400f": provia("400", (BLUE, 110), "RHP III"),
+ "provia400x": provia("400", (BLUE, 80), "RXP"),
+ "astia100f": L(STRIPES, (ORANGE, 150), (ORANGE, 150), (AMBER, 215), W, (AMBER, 215), "FUJICHROME", "ASTIA", "100", "RAP F"),
+ "sensia100": L(STRIPES, (GREEN, 110), (GREEN, 110), (AMBER, 200), W, (AMBER, 200), "FUJICHROME", "SENSIA", "100"),
+ "kodachrome25": L(BAND, YEL, (RED, 148), (RED, 148), W, K, "KODAK", "KODACHROME", "25", "KM"),
+ "kodachrome64": L(BAND, YEL, (RED, 148), (RED, 148), W, K, "KODAK", "KODACHROME", "64", "KR"),
+ "kodachrome200": L(BAND, YEL, (RED, 148), (RED, 148), W, K, "KODAK", "KODACHROME", "200", "KL"),
+ "e100gx": L(STRIPES, K, K, YEL, W, W, "KODAK PROFESSIONAL", "EKTACHROME", "100", "E100GX"),
+ "e100vs": L(STRIPES, K, K, (RED, 160), W, W, "KODAK PROFESSIONAL", "EKTACHROME", "100", "E100VS"),
+ "elitechrome200": L(STRIPES, (BLUE, 120), (BLUE, 120), YEL, W, YEL, "KODAK", "ELITE", "200", "CHROME"),
+ "elitechrome400": L(STRIPES, (BLUE, 95), (BLUE, 95), YEL, W, YEL, "KODAK", "ELITE", "400", "CHROME"),
+ "extracolor100": L(STRIPES, (BLUE, 120), (BLUE, 120), YEL, W, W, "KODAK ELITE", "EXTRACOLOR", "100"),
+ "precisa100": L(STRIPES, (BLUE, 100), (BLUE, 100), (ORANGE, 180), W, (ORANGE, 190), "AGFA", "PRECISA", "100", "CT"),
+ "elite100xpro": L(BAND, K, (CRIMSON, 120), KRED, W, W, "KODAK", "ELITE", "100", "X-PRO"),
+ "superia200xpro": L(BAND, (GREEN, 70), (CRIMSON, 120), W, W, W, "FUJIFILM", "SUPERIA", "200", "X-PRO"),
+ "xproslide200": L(STRIPES, K, K, (VIOLET, 170), W, (VIOLET, 190), "LOMOGRAPHY", "X-PRO", "200", "SLIDE"),
+ "tmax100": L(BAND, YEL, K, K, YEL, K, "KODAK PROFESSIONAL", "T-MAX", "100", "TMX", leader=50),
+ "tmax400": L(BAND, YEL, K, K, YEL, K, "KODAK PROFESSIONAL", "T-MAX", "400", "TMY", leader=50),
+ "tmax3200": L(BAND, YEL, K, K, YEL, K, "KODAK PROFESSIONAL", "T-MAX", "3200", "P3200", leader=50),
+ "bw400cn": L(STRIPES, (GRAY, 232), (GRAY, 232), YEL, K, K, "KODAK PROFESSIONAL", "BW400CN", "400", "C-41", leader=50),
+ "hie": L(STRIPES, (GRAY, 20), (GRAY, 20), KRED, W, (RED, 160), "KODAK", "INFRARED", "400", "HIE", leader=50),
+ "delta100": ilford("DELTA", "100", (BLUE, 160), "PROFESSIONAL"),
+ "delta400": ilford("DELTA", "400", (GREEN, 150), "PROFESSIONAL"),
+ "delta3200": ilford("DELTA", "3200", (VIOLET, 150), "PROFESSIONAL"),
+ "fp4": ilford("FP4", "125", KRED, "PLUS"),
+ "panf50": ilford("PAN F", "50", (BLUE, 200), "PLUS"),
+ "hps800": ilford("HPS", "800", (ORANGE, 170)),
+ "xp2": ilford("XP2", "400", YEL, "SUPER"),
+ "acros100": L(STRIPES, K, K, (GRAY, 200), W, W, "FUJIFILM", "ACROS", "100", "NEOPAN", leader=50),
+ "neopan1600": L(BAND, (GRAY, 236), K, K, W, K, "FUJIFILM", "NEOPAN", "1600", "SUPER PRESTO", leader=50),
+ "apx25": L(BAND, (GRAY, 236), (RED, 140), (RED, 140), W, K, "AGFA", "APX", "25", leader=50),
+ "apx100": L(BAND, (GRAY, 236), (BLUE, 110), (BLUE, 110), W, K, "AGFA", "APX", "100", leader=50),
+ "retro80s": rollei("RETRO", "80", (RED, 150), "80S"),
+ "retro100": rollei("RETRO", "100", (AMBER, 180), "TONAL"),
+ "ortho25": rollei("ORTHO", "25", (BLUE, 130), "PLUS"),
+ "ir400": rollei("INFRARED", "400", (CRIMSON, 110), "IR"),
+ "kodak2383": L(STRIPES, K, K, YEL, W, YEL, "KODAK", "VISION", "2383", "COLOR PRINT"),
+ "kodak2393": L(STRIPES, K, K, YEL, W, YEL, "KODAK", "VISION", "2393", "PREMIER"),
+ "fuji3510": L(STRIPES, (GREEN, 60), (GREEN, 60), (GRAY, 220), W, (GRAY, 220), "FUJIFILM", "ETERNA", "3510", "COLOR PRINT"),
+ "fuji3513": L(STRIPES, (GREEN, 60), (GREEN, 60), (GRAY, 220), W, (GRAY, 220), "FUJIFILM", "ETERNA", "3513", "DI"),
+}
diff --git a/ml-dev/filmos/tools/fontblob.c b/ml-dev/filmos/tools/fontblob.c
new file mode 100644
index 0000000..341fb04
--- /dev/null
+++ b/ml-dev/filmos/tools/fontblob.c
@@ -0,0 +1,65 @@
+/* fontblob: the film OS fonts (fos_font.c) as the file the camera loads at
+ * start, ML/DATA/FOSFONT.BIN (format: fos_fonts_load in fos_gfx.c). They
+ * stay out of autoexec.bin, whose every byte the EOS M takes from Canon's
+ * own memory at boot.
+ *
+ * cc -I.. -o fontblob fontblob.c && ./fontblob FOSFONT.BIN
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "../fos_font.c"
+
+static void put32(FILE *f, uint32_t v)
+{
+ uint8_t b[4] = { (uint8_t) v, (uint8_t) (v >> 8), (uint8_t) (v >> 16), (uint8_t) (v >> 24) };
+ fwrite(b, 1, 4, f);
+}
+
+static void pad(FILE *f, long n)
+{
+ static const uint8_t z[4];
+ fwrite(z, 1, (size_t) ((4 - n % 4) % 4), f);
+}
+
+static void font(FILE *f, const struct fos_font *ft, const uint8_t *bits, uint32_t nbits, uint32_t nglyphs)
+{
+ put32(f, nbits);
+ put32(f, nglyphs);
+ put32(f, (uint32_t) ft->nkern);
+ put32(f, (uint32_t) ft->ascent);
+ put32(f, (uint32_t) ft->descent);
+ fwrite(bits, 1, nbits, f);
+ pad(f, nbits);
+ for (uint32_t i = 0; i < nglyphs; i++)
+ {
+ const struct fos_glyph *g = &ft->glyphs[i];
+ uint8_t b[8] = { (uint8_t) g->off, (uint8_t) (g->off >> 8), g->w, g->h, (uint8_t) g->ox, (uint8_t) g->oy,
+ (uint8_t) g->adv, (uint8_t) (g->adv >> 8) };
+ fwrite(b, 1, 8, f);
+ }
+ fwrite(ft->lut, 1, 256, f);
+ for (int i = 0; i < ft->nkern; i++)
+ {
+ uint8_t b[3] = { ft->kern[i].a, ft->kern[i].b, (uint8_t) ft->kern[i].k };
+ fwrite(b, 1, 3, f);
+ }
+ pad(f, (long) ft->nkern * 3);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) { fprintf(stderr, "usage: fontblob FOSFONT.BIN\n"); return 2; }
+ FILE *f = fopen(argv[1], "wb");
+ if (!f) { perror(argv[1]); return 1; }
+ fwrite("FOSF", 1, 4, f);
+ put32(f, 1);
+#define COUNT(n) + 1
+ put32(f, 0 FOS_FONTS(COUNT));
+#define FONT(n) font(f, &fos_font_##n##_data, n##_bits, sizeof(n##_bits), sizeof(n##_glyphs) / sizeof(n##_glyphs[0]));
+ FOS_FONTS(FONT)
+ long size = ftell(f);
+ fclose(f);
+ printf("%s: %ld bytes\n", argv[1], size);
+ return 0;
+}
diff --git a/ml-dev/filmos/tools/genfilms.py b/ml-dev/filmos/tools/genfilms.py
new file mode 100644
index 0000000..63946ae
--- /dev/null
+++ b/ml-dev/filmos/tools/genfilms.py
@@ -0,0 +1,139 @@
+"""The films beyond the built-in eight, for the card:
+
+ python3 genfilms.py ML/DATA/FOSFILMS.BIN [--tables ML/DARKROOM]
+
+FOSFILMS.BIN: every film of films/films.py that fos_film.c doesn't have
+built in, with what the shelf shows (tools/catalog.py), the picture style
+for LiveView and the look, packed as struct film_rec in fos_film.c.
+
+--tables: the film tables (LOOKnn.LUT) of the films whose colour comes
+from a LUT in films/luts/, baked here from the .cube, the way the lab
+applies it: the camera's grid of Cineon codes decoded to light, through
+the LUT. Films whose LUT isn't there are left to the camera, which mixes
+their table from the look the first time (a plain print).
+Needs numpy (the lab's).
+"""
+
+import argparse
+import re
+import struct
+import sys
+from pathlib import Path
+
+HERE = Path(__file__).resolve().parent
+LAB = HERE.parents[1] / "films"
+sys.path.insert(0, str(LAB))
+sys.path.insert(0, str(HERE))
+from films import FILMS, short_name # noqa: E402
+from catalog import DESC, LABELS # noqa: E402
+
+HUES = ["red", "orange", "yellow", "green", "cyan", "blue", "magenta"]
+GROUP = {"neg": 0, "slide": 1, "xpro": 1, "bw": 2, "cine": 3, "print": 3}
+PS_STANDARD, PS_LANDSCAPE, PS_MONO = 0x81, 0x83, 0x86
+GRID = 33
+LOOK_MODEL = 1 # as fos_dev.c
+LOOK = struct.Struct("<ii ff 3f3f3f3f i" + "bbxxff" * 4 + "ff 3f ff i 3f")
+REC = struct.Struct("<16s16s24s8s48s24s 10i 4B i BB10B20s14s8s18s %ds" % LOOK.size)
+
+
+def builtin_keys():
+ src = (HERE.parent / "fos_film.c").read_text()
+ table = src[src.index("static const struct fos_film builtin[]"):]
+ return re.findall(r'\{ "(\w+)", "', table[:table.index("};")])
+
+
+def cstr(s, n):
+ b = s.encode("ascii")
+ assert len(b) < n, (s, n)
+ return b
+
+
+def look_bytes(f):
+ hues = f.get("hues", [])
+ hv = []
+ for a, b, amt, ch in hues[:4]:
+ hv += [HUES.index(a), HUES.index(b), amt, ch]
+ hv += [0, 0, 0.0, 0.0] * (4 - len(hues[:4]))
+ tri = lambda v: list(v) + [v[0]] * (3 - len(v)) # noqa: E731
+ mono = f.get("mono")
+ return LOOK.pack(int(f.get("balance", 5500)), int(bool(f.get("slide"))), f.get("ev", 0), f.get("sat", 1.0),
+ *tri(f["contrast"]), *tri(f["pivot"]), *tri(f["black"]), *tri(f["white"]),
+ min(len(hues), 4), *hv,
+ f.get("halation", 0), f.get("hal_thr", 0.75), *f.get("hal_tint", (1.0, 0.28, 0.06)),
+ f.get("grain", 0), f.get("grain_size", 1.0), int(bool(mono)), *tri(mono or (0, 0, 0)))
+
+
+def camera_iso(iso):
+ return max(100, iso) # the EOS M starts at 100
+
+
+def record(key):
+ f = FILMS[key]
+ kind = f["kind"]
+ brand, name = f["name"].split(" ", 1)
+ process = {"neg": "C-41", "slide": "E-6", "xpro": "X-PRO", "bw": "B&W", "cine": "C-41", "print": "ECP"}[kind]
+ if key.startswith("kodachrome"):
+ process = "K-14"
+ if key in ("xp2", "bw400cn"):
+ process = "C-41"
+ iso = f["iso"]
+ style = {"neg": (PS_STANDARD, 0, 0, 0), "slide": (PS_LANDSCAPE, 2, 2, 0), "xpro": (PS_LANDSCAPE, 3, 3, 0),
+ "bw": (PS_MONO, 1, 0, 0), "cine": (PS_STANDARD, 1, 1, -1), "print": (PS_STANDARD, 1, -1, 0)}[kind]
+ grain = 1 if iso <= 64 else 2 if iso <= 160 else 3 if iso <= 400 else 4 if iso <= 800 else 5
+ punch = {"neg": 2, "slide": 4, "xpro": 5, "bw": 3, "cine": 3, "print": 3}[kind]
+ colour = {"neg": 3, "slide": 4, "xpro": 5, "bw": 0, "cine": 3, "print": 3}[kind]
+ lab = LABELS[key]
+ return REC.pack(cstr(key, 16), cstr(brand.upper(), 16), cstr(name, 24), cstr(process, 8),
+ cstr(DESC[key], 48), cstr(short_name(key), 24),
+ iso, camera_iso(iso), style[0], style[1], style[2], style[3], 2, 5200, 0, 0,
+ grain, punch, colour, 3, GROUP[kind],
+ lab["style"], lab["leader"], *lab["bg"], *lab["band"], *lab["accent"], *lab["text"], *lab["num"],
+ cstr(lab["top"], 20), cstr(lab["word"], 14), cstr(lab["num_s"], 8), cstr(lab["sub"], 18),
+ look_bytes(f))
+
+
+def look_hash(key, look):
+ h = 2166136261 ^ (GRID * 256 + LOOK_MODEL)
+ for b in key.encode("ascii") + look:
+ h = ((h ^ b) * 16777619) & 0xFFFFFFFF
+ return h
+
+
+def bake(key, index, out_dir):
+ """LOOKnn.LUT from the film's LUT, or None when it isn't there."""
+ import numpy as np
+ import lut as luts
+ path = luts.find(key)
+ if not path:
+ return None
+ table = luts.load(str(path), FILMS[key].get("lut_space") if path.name.split(".")[0] != key else None)
+ g = np.arange(GRID, dtype=np.float32) / (GRID - 1)
+ b, gg, r = np.meshgrid(g, g, g, indexing="ij") # red changes fastest, as the camera's grid
+ lin = luts.decode(np.stack([r, gg, b], -1).reshape(-1, 3), "cineon")
+ rgb = np.clip(table.apply(lin), 0, 1)
+ data = (rgb * 255 + 0.5).astype(np.uint8).tobytes()
+ dst = out_dir / f"LOOK{index:02d}.LUT"
+ dst.write_bytes(b"FOL1" + struct.pack("<I", look_hash(key, look_bytes(FILMS[key]))) + data)
+ return dst
+
+
+def main():
+ ap = argparse.ArgumentParser(description="FOSFILMS.BIN and the LUT films' tables for the card.")
+ ap.add_argument("out")
+ ap.add_argument("--tables", help="the card's ML/DARKROOM, for LOOKnn.LUT")
+ a = ap.parse_args()
+ built = builtin_keys()
+ more = [k for k in FILMS if k not in built]
+ recs = b"".join(record(k) for k in more)
+ Path(a.out).write_bytes(b"FOSM" + struct.pack("<BBHI", 1, 0, REC.size, len(more)) + recs)
+ print(f"{a.out}: {len(more)} films after the {len(built)} built in")
+ if a.tables:
+ out = Path(a.tables)
+ out.mkdir(parents=True, exist_ok=True)
+ baked = [k for i, k in enumerate(more) if bake(k, len(built) + i, out)]
+ missing = [k for k in more if k not in baked and FILMS[k].get("lut")]
+ print(f" {len(baked)} tables baked from LUTs" + (f"; LUT not found for {', '.join(missing)}" if missing else ""))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ml-dev/filmos/tools/genlooks.py b/ml-dev/filmos/tools/genlooks.py
new file mode 100644
index 0000000..df08f14
--- /dev/null
+++ b/ml-dev/filmos/tools/genlooks.py
@@ -0,0 +1,61 @@
+"""Write fos_looks.c, the film looks the camera develops with, from
+ml-dev/films/films.py, so the camera and the desktop darkroom can't drift apart.
+
+ python3 genlooks.py # -> ../fos_looks.c
+
+Run it again after changing a film in films/films.py.
+"""
+
+import sys
+from pathlib import Path
+
+HERE = Path(__file__).resolve().parent
+sys.path.insert(0, str(HERE.parents[1] / "films"))
+from films import FILMS # noqa: E402
+
+HUES = ["red", "orange", "yellow", "green", "cyan", "blue", "magenta"]
+
+
+def f(v):
+ s = f"{float(v):.6g}"
+ if not any(c in s for c in ".e"):
+ s += ".0"
+ return s + "f"
+
+
+def triple(v, n=3):
+ v = list(v) + [v[0]] * (n - len(v))
+ return "{ " + ", ".join(f(x) for x in v[:n]) + " }"
+
+
+def look(key, d):
+ hues = d.get("hues", [])
+ assert len(hues) <= 4, key
+ hue_c = ", ".join(f"{{ {HUES.index(a)}, {HUES.index(b)}, {f(amt)}, {f(ch)} }}" for a, b, amt, ch in hues) or "{ 0 }"
+ mono = d.get("mono")
+ return (f' {{ "{key}", {int(d.get("balance", 5500))}, {int(bool(d.get("slide")))}, {f(d.get("ev", 0))}, '
+ f'{f(d.get("sat", 1.0))},\n'
+ f' {triple(d["contrast"])}, {triple(d["pivot"])}, {triple(d["black"])}, {triple(d["white"])},\n'
+ f' {len(hues)}, {{ {hue_c} }},\n'
+ f' {f(d.get("halation", 0))}, {f(d.get("hal_thr", 0.75))}, {triple(d.get("hal_tint", (1.0, 0.28, 0.06)))}, '
+ f'{f(d.get("grain", 0))}, {f(d.get("grain_size", 1.0))},\n'
+ f' {int(bool(mono))}, {triple(mono or (0, 0, 0))} }},')
+
+
+def main():
+ out = ['/* fos_looks: the film looks the camera develops with.',
+ ' * Generated from films/films.py by tools/genlooks.py: edit those, not this. */',
+ '',
+ '#include "fos_dev.h"',
+ '',
+ 'const struct fos_look fos_looks[] =',
+ '{']
+ out += [look(k, d) for k, d in FILMS.items()]
+ out += ['};', 'const int fos_nlooks = sizeof(fos_looks) / sizeof(fos_looks[0]);', '']
+ dst = HERE.parent / "fos_looks.c"
+ dst.write_text("\n".join(out))
+ print("->", dst)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ml-dev/filmos/tools/genqr.py b/ml-dev/filmos/tools/genqr.py
new file mode 100644
index 0000000..fca0455
--- /dev/null
+++ b/ml-dev/filmos/tools/genqr.py
@@ -0,0 +1,46 @@
+"""The donation links as QR codes for the camera's Support panel:
+
+ python3 genqr.py ../../donate.txt ML/DATA/FOSQR.BIN
+
+donate.txt: up to two lines "Label URL" (lines starting with # are
+ignored). With no links, no file: the panel just says thanks.
+
+FOSQR.BIN: "FOSQ", count, then per code: label[48], url[80], its size in
+modules, and the modules row by row, 8 to a byte (most significant first).
+Needs segno (pip install segno).
+"""
+
+import struct
+import sys
+from pathlib import Path
+
+
+def main(src, dst):
+ links = []
+ for line in Path(src).read_text(encoding="utf-8").splitlines():
+ line = line.strip()
+ if line and not line.startswith("#"):
+ label, _, url = line.rpartition(" ")
+ links.append((label.strip() or "Donate", url))
+ links = links[:2]
+ out = Path(dst)
+ if not links:
+ out.unlink(missing_ok=True)
+ print(f"{src}: no links, no {out.name}")
+ return
+ import segno
+ blob = b"FOSQ" + struct.pack("<I", len(links))
+ for label, url in links:
+ qr = segno.make(url, error="m", micro=False)
+ rows = [list(r) for r in qr.matrix]
+ n = len(rows)
+ bits = [b for r in rows for b in r]
+ data = bytes(sum(bits[i + k] << (7 - k) for k in range(8) if i + k < len(bits)) for i in range(0, len(bits), 8))
+ blob += label.encode("ascii")[:47].ljust(48, b"\0") + url.encode("ascii")[:79].ljust(80, b"\0")
+ blob += struct.pack("<I", n) + data
+ print(f" {label}: {url} ({n} x {n})")
+ out.write_bytes(blob)
+
+
+if __name__ == "__main__":
+ main(*sys.argv[1:3])
diff --git a/ml-dev/filmos/tools/mkfont.py b/ml-dev/filmos/tools/mkfont.py
new file mode 100644
index 0000000..dcbb79e
--- /dev/null
+++ b/ml-dev/filmos/tools/mkfont.py
@@ -0,0 +1,186 @@
+"""Rasterise the film OS fonts into fos_font.c.
+
+ python3 mkfont.py # writes ../fos_font.c and ../sim/out/fonts.png
+
+Glyphs are 4-bit anti-aliased coverage, run-length coded (fos_gfx.c
+decodes them). Advances and kerning are kept in 1/16 px so spacing comes
+out like the real font even at small sizes. Needs Pillow with raqm
+(for GPOS kerning) and the Barlow TTFs in ../fonts (SIL OFL 1.1).
+"""
+
+from pathlib import Path
+
+from PIL import Image, ImageDraw, ImageFont
+
+HERE = Path(__file__).resolve().parent
+FONTS = HERE.parent / "fonts"
+OUT_C = HERE.parent / "fos_font.c"
+OUT_PNG = HERE.parent / "sim" / "out" / "fonts.png"
+
+ASCII = "".join(chr(c) for c in range(32, 127))
+
+# bytes 0x80.. in our strings; see FOS_T_* in fos_gfx.h
+EXTRAS = ["·", "°", "×", "–", "—", "’", "…", "•", "‹", "›"]
+
+UPPER = " !\"#%&'()*+,-./0123456789:;?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+# name, file, px size, characters
+SPECS = [
+ ("xs", "Barlow-SemiBold.ttf", 13, ASCII),
+ ("sm", "Barlow-Medium.ttf", 16, ASCII),
+ ("md", "Barlow-Medium.ttf", 20, ASCII),
+ ("mdb", "Barlow-SemiBold.ttf", 20, ASCII),
+ ("lg", "Barlow-SemiBold.ttf", 27, ASCII),
+ ("xl", "BarlowCondensed-SemiBold.ttf", 50, ASCII),
+ ("num", "BarlowCondensed-Medium.ttf", 84, " 0123456789/:-.S"),
+ # canister label art (drawn into the label textures)
+ ("lbig", "BarlowCondensed-ExtraBold.ttf", 54, " 0123456789HPT"),
+ ("lname", "BarlowCondensed-Bold.ttf", 25, UPPER),
+ ("lsm", "BarlowCondensed-SemiBold.ttf", 13, UPPER),
+]
+
+
+def kern_pairs(font, chars, scale):
+ """Kerning that raqm applies between two characters, in 1/16 px.
+ Measured on a big unhinted copy of the font and scaled down, so the
+ rounding of small sizes doesn't show up as fake kerning."""
+ adv = {c: font.getlength(c) for c in chars}
+ out = []
+ letters = [c for c in chars if c.isalnum() or c in ".,'-" or ord(c) >= 0x80]
+ for a in letters:
+ for b in letters:
+ k = (font.getlength(a + b) - adv[a] - adv[b]) * scale
+ k16 = max(-127, min(127, round(k * 16)))
+ if abs(k16) >= 4: # a quarter pixel or more
+ out.append((a, b, k16))
+ return out
+
+
+def rle(values):
+ """4-bit coverage -> bytes. 0x00-0x7F: (count-1) << 4 | value, a run of
+ 1..8 equal values; zero runs use 0x80 | (count-1), 1..128 zeros."""
+ out = bytearray()
+ i = 0
+ n = len(values)
+ while i < n:
+ v = values[i]
+ j = i
+ if v == 0:
+ while j < n and values[j] == 0 and j - i < 128:
+ j += 1
+ out.append(0x80 | (j - i - 1))
+ else:
+ while j < n and values[j] == v and j - i < 8:
+ j += 1
+ out.append(((j - i - 1) << 4) | v)
+ i = j
+ return out
+
+
+def build(name, file, size, chars):
+ font = ImageFont.truetype(str(FONTS / file), size)
+ big = ImageFont.truetype(str(FONTS / file), 512)
+ scale = size / 512
+ ascent, descent = font.getmetrics()
+ chars = sorted(set(chars), key=ord)
+ allchars = chars + (EXTRAS if chars is not None and len(chars) > 80 else [])
+ glyphs = []
+ data = bytearray()
+ for ch in allchars:
+ code = ord(ch) if ord(ch) < 128 else 0x80 + EXTRAS.index(ch)
+ x0, y0, x1, y1 = font.getbbox(ch)
+ w, h = max(0, x1 - x0), max(0, y1 - y0)
+ adv16 = round(big.getlength(ch) * scale * 16)
+ if w and h:
+ img = Image.new("L", (w, h), 0)
+ ImageDraw.Draw(img).text((-x0, -y0), ch, font=font, fill=255)
+ px = list(img.tobytes())
+ # trim empty rows / columns the bbox may include
+ vals = [round(p * 15 / 255) for p in px]
+ else:
+ vals = []
+ glyphs.append(dict(code=code, ch=ch, off=len(data), w=w, h=h,
+ ox=x0, oy=y0 - ascent, adv=adv16))
+ data += rle(vals)
+ kerns = kern_pairs(big, allchars, scale)
+ codes = {g["ch"]: g["code"] for g in glyphs}
+ kerns = sorted((codes[a], codes[b], k) for a, b, k in kerns)
+ return dict(name=name, size=size, ascent=ascent, descent=descent,
+ glyphs=sorted(glyphs, key=lambda g: g["code"]), data=data, kerns=kerns, font=font)
+
+
+def c_bytes(data):
+ lines = []
+ for i in range(0, len(data), 24):
+ lines.append(" " + ",".join(str(b) for b in data[i:i + 24]) + ",")
+ return "\n".join(lines)
+
+
+def emit(fonts):
+ out = [
+ "/* generated by tools/mkfont.py from Barlow (SIL Open Font License 1.1,",
+ " * see fonts/OFL.txt) - do not edit. Not linked into the camera: it goes",
+ " * on the card as ML/DATA/FOSFONT.BIN (tools/fontblob.c) */",
+ "",
+ '#include "fos_gfx.h"',
+ "",
+ ]
+ total = 0
+ for f in fonts:
+ n = f["name"]
+ # glyph lookup by byte value: index into the glyph table, 0xFF = missing
+ lut = [255] * 256
+ for i, g in enumerate(f["glyphs"]):
+ lut[g["code"]] = i
+ out.append(f"static const uint8_t {n}_bits[] = {{\n{c_bytes(f['data'])}\n}};")
+ out.append(f"static const struct fos_glyph {n}_glyphs[] = {{")
+ for g in f["glyphs"]:
+ out.append(f" {{ {g['off']:5d}, {g['w']:3d}, {g['h']:3d}, {g['ox']:3d}, {g['oy']:4d}, {g['adv']:5d} }},"
+ f" /* {g['code']:#04x} */")
+ out.append("};")
+ out.append(f"static const uint8_t {n}_lut[256] = {{\n{c_bytes(lut)}\n}};")
+ if f["kerns"]:
+ out.append(f"static const struct fos_kern {n}_kern[] = {{")
+ row = []
+ for a, b, k in f["kerns"]:
+ row.append(f"{{{a},{b},{k}}}")
+ if len(row) == 8:
+ out.append(" " + ",".join(row) + ",")
+ row = []
+ if row:
+ out.append(" " + ",".join(row) + ",")
+ out.append("};")
+ kern_ref, nk = f"{n}_kern", len(f["kerns"])
+ else:
+ kern_ref, nk = "0", 0
+ out.append(f"const struct fos_font fos_font_{n}_data = {{ {n}_bits, {n}_glyphs, {n}_lut, {kern_ref}, {nk}, "
+ f"{f['ascent']}, {f['descent']} }};")
+ out.append("")
+ total += len(f["data"]) + 8 * len(f["glyphs"]) + 256 + 3 * nk
+ OUT_C.write_text("\n".join(out))
+ return total
+
+
+def preview(fonts):
+ OUT_PNG.parent.mkdir(parents=True, exist_ok=True)
+ rows = []
+ for f in fonts:
+ sample = "".join(g["ch"] for g in f["glyphs"] if g["ch"].strip())
+ rows.append((f, f"{f['name']} {f['size']}px {sample[:60]}"))
+ h = sum(f["ascent"] + f["descent"] + 8 for f, _ in rows)
+ img = Image.new("L", (1400, h), 0)
+ d = ImageDraw.Draw(img)
+ y = 0
+ for f, text in rows:
+ d.text((4, y), text, font=f["font"], fill=255)
+ y += f["ascent"] + f["descent"] + 8
+ img.save(OUT_PNG)
+
+
+if __name__ == "__main__":
+ fonts = [build(*s) for s in SPECS]
+ size = emit(fonts)
+ preview(fonts)
+ for f in fonts:
+ print(f"{f['name']:6s} {f['size']:3d}px glyphs {len(f['glyphs']):3d} data {len(f['data']):6d} B kern {len(f['kerns'])}")
+ print(f"total ~{size} bytes -> {OUT_C}")
diff --git a/ml-dev/filmroll/Makefile b/ml-dev/filmroll/Makefile
new file mode 100644
index 0000000..0908d20
--- /dev/null
+++ b/ml-dev/filmroll/Makefile
@@ -0,0 +1,8 @@
+# define the module name - make sure name is max 8 characters
+MODULE_NAME = filmroll
+MODULE_OBJS = $(BUILD_DIR)/filmroll.o
+TOP_DIR = ../..
+
+# include modules environment
+include $(TOP_DIR)/modules/Makefile
+.DEFAULT_GOAL := $(BUILD_DIR)/module_complete
diff --git a/ml-dev/filmroll/README.rst b/ml-dev/filmroll/README.rst
new file mode 100644
index 0000000..2acc5b1
--- /dev/null
+++ b/ml-dev/filmroll/README.rst
@@ -0,0 +1,11 @@
+Film roll
+=========
+
+Shoot like a film camera: pick a film stock, load a roll and shoot a fixed
+number of frames. Loading a roll applies picture style, white balance and
+ISO for that stock and writes a roll log (ROLL_nnn.TXT) next to the images,
+which the PC film lab develops.
+
+:Author: hengz
+:License: GPL
+:Summary: Film stocks, rolls and a roll log for the PC film lab
diff --git a/ml-dev/filmroll/filmroll.c b/ml-dev/filmroll/filmroll.c
new file mode 100644
index 0000000..a83e280
--- /dev/null
+++ b/ml-dev/filmroll/filmroll.c
@@ -0,0 +1,1145 @@
+/* filmroll: shoot the EOS M like a film camera.
+ *
+ * Pick a film stock, load a roll and shoot a fixed number of frames.
+ * Loading a roll sets picture style, contrast / saturation / colour tone,
+ * white balance and ISO for that stock, and starts a roll log next to the
+ * images (DCIM/xxxCANON/ROLL_nnn.TXT) that the PC film lab reads
+ * (lab/roll.py). Film keys must match lab/films.py.
+ *
+ * v2 adds:
+ * - a full-screen film picker (runs on top of the ML menu, like Arkanoid)
+ * - an SLR-viewfinder HUD in LiveView: exposure needle, red LED readout
+ * that lights on half-shutter, frame counter, wind reminder
+ * - PLAY locked until the roll is finished
+ *
+ * Shots are detected by watching the file number, so every frame is
+ * logged even in burst mode.
+ */
+
+#include <module.h>
+#include <dryos.h>
+#include <property.h>
+#include <menu.h>
+#include <config.h>
+#include <lens.h>
+#include <picstyle.h>
+#include <beep.h>
+#include <bmp.h>
+#include <fio-ml.h>
+#include <fileprefix.h>
+#include <notify_box.h>
+#include <zebra.h>
+#include <propvalues.h>
+
+#include <stdarg.h>
+
+extern int menu_redraw_blocked;
+extern int ml_started;
+
+/* raw PROP_PICTURE_STYLE values */
+#define PS_STANDARD 0x81
+#define PS_LANDSCAPE 0x83
+#define PS_MONO 0x86
+
+struct film
+{
+ const char *key; /* must match lab/films.py */
+ const char *brand;
+ const char *name;
+ const char *type;
+ const char *desc;
+ int band, ink; /* canister label colours (ML palette) */
+ int rated_iso; /* box speed */
+ int iso; /* what the camera is set to (EOS M has no ISO 50) */
+ int picstyle;
+ int contrast, saturation, color_tone, sharpness;
+ int kelvin;
+ int wbs_gm; /* + green, - magenta (-9..9) */
+ int wbs_ba; /* + amber, - blue (-9..9) */
+};
+
+/* Picture style values are starting points for the in-camera JPEG
+ * preview only; the real look comes from the lab. Mono stocks leave
+ * saturation / tone alone because the Monochrome style uses those slots
+ * for filter and toning effects. */
+static const struct film films[] =
+{
+ { "portra400", "KODAK", "Portra 400", "COLOR NEG C-41", "Soft warm skin, gentle highlights",
+ COLOR_ORANGE, COLOR_BLACK, 400, 400, PS_STANDARD, -1, -1, 1, 2, 5500, 0, 1 },
+ { "cinestill800t", "CINESTILL", "800T", "COLOR NEG C-41", "Tungsten cine film, night goes blue",
+ COLOR_RED, COLOR_WHITE, 800, 800, PS_STANDARD, 1, 1, -1, 2, 3200, 0, 0 },
+ { "ektar100", "KODAK", "Ektar 100", "COLOR NEG C-41", "Punchy colour, ultra fine grain",
+ COLOR_DARK_RED, COLOR_WHITE, 100, 100, PS_LANDSCAPE, 1, 2, 0, 3, 5200, 0, 0 },
+ { "gold200", "KODAK", "Gold 200", "COLOR NEG C-41", "Golden hour, all day long",
+ COLOR_YELLOW, COLOR_BLACK, 200, 200, PS_STANDARD, 1, 1, 2, 2, 5600, 0, 2 },
+ { "superia400", "FUJIFILM", "Superia 400", "COLOR NEG C-41", "Green shadows, everyday snaps",
+ COLOR_GREEN2, COLOR_WHITE, 400, 400, PS_STANDARD, 1, 1, 0, 2, 5200, 1, 0 },
+ { "velvia50", "FUJIFILM", "Velvia 50", "SLIDE E-6", "Vivid slide film, hard contrast",
+ COLOR_MAGENTA, COLOR_WHITE, 50, 100, PS_LANDSCAPE, 3, 4, 0, 3, 5200, 0, 0 },
+ { "hp5", "ILFORD", "HP5 Plus", "B&W", "Classic B&W, forgiving latitude",
+ COLOR_ALMOST_BLACK, COLOR_WHITE, 400, 400, PS_MONO, 1, 0, 0, 2, 5200, 0, 0 },
+ { "trix400", "KODAK", "Tri-X 400", "B&W", "Gritty contrast, street classic",
+ COLOR_DARK_ORANGE_MOD, COLOR_WHITE, 400, 400, PS_MONO, 3, 0, 0, 2, 5200, 0, 0 },
+};
+#define NUM_FILMS ((int) COUNT(films))
+
+static const int exposure_choices[] = { 36, 24, 12 };
+#define NUM_EXPOSURE_CHOICES ((int) COUNT(exposure_choices))
+
+/* f-numbers x100 in 1/3 stops; index i sits (i - 1) thirds above f/1
+ * (f/0.95 is close enough to f/1 to share the bottom of the scale) */
+static const int fstops[] = {
+ 95, 100, 110, 120, 140, 160, 180, 200, 220, 250,
+ 280, 320, 350, 400, 450, 500, 560, 630, 710, 800,
+ 900, 1000, 1100, 1300, 1400, 1600, 1800, 2000, 2200,
+};
+#define NUM_FSTOPS ((int) COUNT(fstops))
+#define FSTOP_CHOICES CHOICES("0.95", "1.0", "1.1", "1.2", "1.4", "1.6", "1.8", "2.0", "2.2", "2.5", \
+ "2.8", "3.2", "3.5", "4", "4.5", "5.0", "5.6", "6.3", "7.1", "8", \
+ "9", "10", "11", "13", "14", "16", "18", "20", "22")
+
+/* user settings */
+static CONFIG_INT("filmroll.film", film_sel, 0);
+static CONFIG_INT("filmroll.exp", exp_sel, 0);
+static CONFIG_INT("filmroll.hud", hud_enabled, 1);
+static CONFIG_INT("filmroll.focus", focus_screen, 1);
+static CONFIG_INT("filmroll.leds", leds_on_half, 1);
+static CONFIG_INT("filmroll.wind", wind_mode, 1); /* 0 off, 1 reminder, 2 block shutter */
+static CONFIG_INT("filmroll.playlock", play_lock, 1);
+static CONFIG_INT("filmroll.startup", startup_picker, 2); /* 0 off, 1 when no film, 2 always */
+static CONFIG_INT("filmroll.debug", debug_log, 1);
+static CONFIG_INT("filmroll.lens_wide", lens_widest, 6); /* index into fstops: f/1.8 */
+static CONFIG_INT("filmroll.fstop", manual_fstop, 6);
+static CONFIG_INT("filmroll.ap_keys", aperture_keys, 0); /* 0 wheel in Av, 1 up/down, 2 menu only */
+
+/* roll state, kept across power cycles */
+static CONFIG_INT("filmroll.loaded", roll_loaded, 0);
+static CONFIG_INT("filmroll.roll", roll_number, 0);
+static CONFIG_INT("filmroll.roll_film", roll_film, 0);
+static CONFIG_INT("filmroll.roll_exp", roll_exposures, 36);
+static CONFIG_INT("filmroll.shot", frames_shot, 0);
+static CONFIG_INT("filmroll.lastfile", last_file_number, -1);
+static CONFIG_INT("filmroll.logdir", roll_folder, 0);
+static CONFIG_INT("filmroll.needwind", need_wind, 0);
+
+static char log_path[64];
+
+static volatile int leds_until = 0; /* keep LEDs lit until this ms clock */
+static volatile int hud_dirty = 1;
+
+#define ROLL_FINISHED (roll_loaded && frames_shot >= roll_exposures)
+#define ROLL_IN_PROGRESS (roll_loaded && frames_shot < roll_exposures)
+
+/* ---------------------------------------------------------------- debug log */
+
+/* field-test trace in ML/FILMROLL.LOG; turn off in the menu once things work */
+static void dbg(const char *fmt, ...)
+{
+ if (!debug_log)
+ return;
+
+ char buf[192];
+ int n = snprintf(buf, sizeof(buf), "%7d ", get_ms_clock());
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf + n, sizeof(buf) - n, fmt, ap);
+ va_end(ap);
+
+ FILE *f = FIO_CreateFileOrAppend("ML/FILMROLL.LOG");
+ if (!f)
+ return;
+ my_fprintf(f, "%s\n", buf);
+ FIO_CloseFile(f);
+}
+
+#define DBG_STATE(what) dbg("%s: ml=%d lv=%d idle=%d menu=%d movie=%d mode=%d", what, \
+ ml_started, lv, display_idle(), gui_menu_shown(), is_movie_mode(), shooting_mode)
+
+/* ---------------------------------------------------------------- log file */
+
+static void update_log_path()
+{
+ snprintf(log_path, sizeof(log_path), "%s:/DCIM/%03d%s/ROLL_%03d.TXT",
+ get_shooting_card()->drive_letter, roll_folder, get_dcim_dir_suffix(),
+ roll_number);
+}
+
+static void log_append(const char *text)
+{
+ FILE *f = FIO_CreateFileOrAppend(log_path);
+ if (!f)
+ {
+ NotifyBox(3000, "filmroll: can't write %s", log_path);
+ return;
+ }
+ my_fprintf(f, "%s", text);
+ FIO_CloseFile(f);
+}
+
+static void format_now(char *buf, int size)
+{
+ struct tm now;
+ LoadCalendarFromRTC(&now);
+ snprintf(buf, size, "%04d-%02d-%02d %02d:%02d:%02d",
+ now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
+ now.tm_hour, now.tm_min, now.tm_sec);
+}
+
+static void write_header(const char *note)
+{
+ char when[32];
+ char header[320];
+ format_now(when, sizeof(when));
+ snprintf(header, sizeof(header),
+ "# ML film mode roll log (filmroll module)%s\n"
+ "roll = %03d\nfilm = %s\nexposures = %d\nloaded = %s\n\n",
+ note, roll_number, films[roll_film].key, roll_exposures, when);
+ log_append(header);
+}
+
+/* ---------------------------------------------------------------- camera settings */
+
+static int iso_to_raw(int iso)
+{
+ int raw = 72; /* ISO 100 */
+ for (int i = 100; i < iso; i *= 2)
+ raw += 8; /* one stop */
+ return raw;
+}
+
+static void apply_film(int index)
+{
+ const struct film *f = &films[index];
+
+ int ps = f->picstyle;
+ prop_request_change_wait(PROP_PICTURE_STYLE, &ps, 4, 1000);
+ msleep(100);
+
+ /* these change the current picture style, so it must be selected first */
+ lens_set_contrast(f->contrast);
+ msleep(50);
+ lens_set_sharpness(f->sharpness);
+ msleep(50);
+ if (f->picstyle != PS_MONO)
+ {
+ lens_set_saturation(f->saturation);
+ msleep(50);
+ lens_set_color_tone(f->color_tone);
+ msleep(50);
+ }
+
+ lens_set_kelvin(f->kelvin);
+ lens_set_wbs_gm(f->wbs_gm);
+ lens_set_wbs_ba(f->wbs_ba);
+ lens_set_rawiso(iso_to_raw(f->iso));
+}
+
+/* ---------------------------------------------------------------- aperture */
+
+/* manual (adapted) lenses report no aperture; the user dials it in instead */
+static int lens_is_manual()
+{
+ return !lens_info.raw_aperture;
+}
+
+/* index into fstops for the aperture in use */
+static int current_fstop()
+{
+ if (lens_is_manual())
+ return COERCE(manual_fstop, lens_widest, NUM_FSTOPS - 1);
+
+ int f100 = lens_info.aperture * 10; /* lens_info.aperture is f x10 */
+ int best = 0;
+ for (int i = 1; i < NUM_FSTOPS; i++)
+ if (ABS(fstops[i] - f100) < ABS(fstops[best] - f100))
+ best = i;
+ return best;
+}
+
+static void format_fstop(char *buf, int size, int index)
+{
+ int v = fstops[COERCE(index, 0, NUM_FSTOPS - 1)];
+ if (v < 100)
+ snprintf(buf, size, "0.%02d", v);
+ else if (v % 100 == 0 || v >= 1000)
+ snprintf(buf, size, "%d", v / 100);
+ else
+ snprintf(buf, size, "%d.%d", v / 100, (v / 10) % 10);
+}
+
+static void step_manual_fstop(int dir)
+{
+ manual_fstop = COERCE(current_fstop() + dir, lens_widest, NUM_FSTOPS - 1);
+}
+
+/* ---------------------------------------------------------------- rolls */
+
+static void load_roll(int film, int exposures)
+{
+ roll_number = roll_number % 999 + 1;
+ roll_film = film;
+ roll_exposures = exposures;
+ roll_folder = get_shooting_card()->folder_number;
+ frames_shot = 0;
+ need_wind = 0;
+ last_file_number = get_shooting_card()->file_number;
+ roll_loaded = 1;
+ update_log_path();
+
+ apply_film(roll_film);
+ write_header("");
+
+ hud_dirty = 1;
+ beep();
+ NotifyBox(3000, "ROLL %03d loaded: %s %s, %d exp", roll_number,
+ films[roll_film].brand, films[roll_film].name, roll_exposures);
+}
+
+static void load_roll_task(int unused)
+{
+ load_roll(film_sel, exposure_choices[exp_sel]);
+}
+
+static void reapply_task(int unused)
+{
+ if (!roll_loaded) return;
+ apply_film(roll_film);
+ NotifyBox(2000, "%s settings applied", films[roll_film].name);
+}
+
+static void record_frame(int file_number)
+{
+ if (frames_shot >= roll_exposures)
+ {
+ NotifyBox(3000, "END OF ROLL - press SET for a new roll (not logged)");
+ beep();
+ return;
+ }
+
+ frames_shot++;
+
+ char when[32];
+ char aperture[8];
+ char line[112];
+ format_now(when, sizeof(when));
+ format_fstop(aperture, sizeof(aperture), current_fstop());
+ snprintf(line, sizeof(line), "%d %s%04d.CR2 %s f/%s\n",
+ frames_shot, get_file_prefix(), file_number, when, aperture);
+ log_append(line);
+
+ leds_until = get_ms_clock() + 2500;
+ hud_dirty = 1;
+
+ if (frames_shot == roll_exposures)
+ {
+ need_wind = 0;
+ NotifyBox(4000, "END OF ROLL %d/%d - SET: load a new roll", frames_shot, roll_exposures);
+ beep_times(2);
+ return;
+ }
+
+ if (wind_mode)
+ need_wind = 1;
+ if (!hud_enabled)
+ NotifyBox(1500, "%s %d/%d", films[roll_film].name, frames_shot, roll_exposures);
+}
+
+/* polled from the shoot task: log every new file number since the last poll */
+static unsigned int filmroll_poll(unsigned int ctx)
+{
+ if (!roll_loaded)
+ return CBR_RET_CONTINUE;
+
+ int now = get_shooting_card()->file_number;
+ if (now == last_file_number)
+ return CBR_RET_CONTINUE;
+
+ int prev = last_file_number;
+ last_file_number = now;
+
+ int count = now - prev;
+ if (count < 0)
+ count += 9999; /* IMG_9999 -> IMG_0001 */
+ if (prev < 0 || count > 50)
+ return CBR_RET_CONTINUE; /* card swap or counter reset: just resync */
+
+ if (get_shooting_card()->folder_number != roll_folder)
+ {
+ /* Canon started a new folder; start a log there too so each folder
+ * develops on its own (frame numbers keep counting) */
+ roll_folder = get_shooting_card()->folder_number;
+ update_log_path();
+ write_header(" - continued from the previous DCIM folder");
+ }
+
+ for (int i = 1; i <= count; i++)
+ record_frame((prev + i - 1) % 9999 + 1);
+
+ return CBR_RET_CONTINUE;
+}
+
+/* ---------------------------------------------------------------- drawing helpers */
+
+#define SCREEN_W 720
+#define SCREEN_H 480
+
+#define FONT_BIG(fg, bg) FONT(FONT_LARGE, fg, bg)
+#define FONT_MID(fg, bg) FONT(FONT_MED, fg, bg)
+#define FONT_TINY(fg, bg) FONT(FONT_SMALL, fg, bg)
+
+static void print_centered(uint32_t font, int cx, int y, const char *text)
+{
+ bmp_printf(font, cx - bmp_string_width(font, text) / 2, y, "%s", text);
+}
+
+/* film canister; w = body width, height is 1.5 w */
+static void draw_can(const struct film *f, int x, int y, int w, int labels)
+{
+ int h = w * 3 / 2;
+ int cap_w = w * 2 / 5;
+ int cap_x = x + (w - cap_w) / 2;
+ int cap_h = MAX(3, h / 16);
+ int body = COLOR_ALMOST_WHITE;
+ int band_y = y + h * 2 / 5;
+ int band_h = h / 4;
+
+ bmp_fill(COLOR_GRAY(60), cap_x, y, cap_w, cap_h);
+ bmp_fill(body, x, y + cap_h, w, h - 2 * cap_h);
+ bmp_fill(f->band, x, band_y, w, band_h);
+ bmp_fill(COLOR_GRAY(60), cap_x, y + h - cap_h, cap_w, cap_h);
+
+ if (!labels)
+ return;
+
+ char iso[8];
+ snprintf(iso, sizeof(iso), "%d", f->rated_iso);
+ print_centered(FONT_TINY(COLOR_GRAY(30), body), x + w / 2, y + h / 5, f->brand);
+ print_centered(FONT_BIG(f->ink, f->band), x + w / 2, band_y + (band_h - 32) / 2, iso);
+ print_centered(FONT_TINY(COLOR_GRAY(40), body), x + w / 2, y + h * 3 / 4, "35mm");
+}
+
+/* ---------------------------------------------------------------- film picker */
+
+enum { PICK_NONE, PICK_LOAD, PICK_EXIT };
+
+static volatile int picker_running = 0;
+static volatile int picker_film = 0;
+static volatile int picker_exp = 0;
+static volatile int picker_action = PICK_NONE;
+static volatile int picker_dirty = 0;
+static volatile int picker_confirm = 0;
+static volatile int picker_home = 0;
+
+static const char *picstyle_name(int ps)
+{
+ switch (ps)
+ {
+ case PS_STANDARD: return "Standard";
+ case PS_LANDSCAPE: return "Landscape";
+ case PS_MONO: return "Mono";
+ }
+ return "?";
+}
+
+static void picker_draw()
+{
+ const struct film *f = &films[picker_film];
+ const int bg = COLOR_BLACK;
+
+ bmp_fill(bg, 0, 0, SCREEN_W, SCREEN_H);
+
+ /* header */
+ int x = bmp_printf(FONT_BIG(COLOR_ORANGE, bg), 24, 12, "FILM");
+ bmp_printf(FONT_MID(COLOR_GRAY(60), bg), 24 + x + 20, 18, "choose a roll");
+ bmp_fill(COLOR_GRAY(30), 24, 56, SCREEN_W - 48, 1);
+
+ /* big canister */
+ draw_can(f, 60, 82, 130, 1);
+
+ /* details */
+ int tx = 240;
+ bmp_printf(FONT_TINY(COLOR_ORANGE, bg), tx, 84, "%s", f->type);
+ bmp_printf(FONT_MID(COLOR_GRAY(60), bg), tx, 104, "%s", f->brand);
+ bmp_printf(FONT_BIG(COLOR_WHITE, bg), tx, 130, "%s", f->name);
+ if (f->iso != f->rated_iso)
+ bmp_printf(FONT_MID(COLOR_WHITE, bg), tx, 172, "ISO %d (camera %d) %d exp",
+ f->rated_iso, f->iso, exposure_choices[picker_exp]);
+ else
+ bmp_printf(FONT_MID(COLOR_WHITE, bg), tx, 172, "ISO %d %d exp",
+ f->rated_iso, exposure_choices[picker_exp]);
+ bmp_printf(FONT_MID(COLOR_GRAY(70), bg), tx, 206, "%s", f->desc);
+ if (f->picstyle == PS_MONO)
+ bmp_printf(FONT_TINY(COLOR_GRAY(50), bg), tx, 244, "%s C%+d %dK",
+ picstyle_name(f->picstyle), f->contrast, f->kelvin);
+ else
+ bmp_printf(FONT_TINY(COLOR_GRAY(50), bg), tx, 244, "%s C%+d S%+d T%+d %dK",
+ picstyle_name(f->picstyle), f->contrast, f->saturation, f->color_tone, f->kelvin);
+
+ /* strip of canisters */
+ int can_w = 30, gap = 52;
+ int strip_w = NUM_FILMS * can_w + (NUM_FILMS - 1) * gap;
+ int sx = (SCREEN_W - strip_w) / 2;
+ for (int i = 0; i < NUM_FILMS; i++)
+ {
+ int cx = sx + i * (can_w + gap);
+ int lift = (i == picker_film) ? 10 : 0;
+ draw_can(&films[i], cx, 330 - lift, can_w, 0);
+ if (i == picker_film)
+ bmp_fill(COLOR_ORANGE, cx - 4, 330 + can_w * 3 / 2 + 4, can_w + 8, 4);
+ }
+
+ /* film in the camera, top right */
+ if (ROLL_IN_PROGRESS)
+ {
+ char status[48];
+ snprintf(status, sizeof(status), "IN CAMERA: %s %d/%d",
+ films[roll_film].name, frames_shot, roll_exposures);
+ bmp_printf(FONT_MID(COLOR_ORANGE, bg),
+ SCREEN_W - 24 - bmp_string_width(FONT_MID(COLOR_ORANGE, bg), status), 18, "%s", status);
+ }
+
+ /* loading over a roll in progress needs a second SET */
+ if (picker_confirm)
+ {
+ bmp_fill(COLOR_DARK_RED, 0, SCREEN_H - 96, SCREEN_W, 48);
+ bmp_printf(FONT_MID(COLOR_WHITE, COLOR_DARK_RED), 24, SCREEN_H - 84,
+ "Roll %03d has %d left. SET again to rewind it.",
+ roll_number, roll_exposures - frames_shot);
+ }
+
+ /* footer */
+ int fb = COLOR_GRAY(15);
+ bmp_fill(fb, 0, SCREEN_H - 44, SCREEN_W, 44);
+ bmp_printf(FONT_MID(COLOR_WHITE, fb), 24, SCREEN_H - 36,
+ picker_home ? "< > film INFO: exp SET: load MENU: camera"
+ : "< > film INFO: exp SET: load MENU: back");
+}
+
+/* home: opened from LiveView (startup, PLAY, end of roll) rather than
+ * from the ML menu, so leaving it goes straight back to the camera */
+static void picker_run(int home)
+{
+ picker_film = ROLL_IN_PROGRESS ? roll_film : film_sel;
+ picker_exp = exp_sel;
+ picker_action = PICK_NONE;
+ picker_confirm = 0;
+ picker_home = home;
+ picker_dirty = 1;
+ picker_running = 1;
+ menu_redraw_blocked = 1;
+ dbg("picker: start (home %d)", home);
+
+ while (gui_menu_shown() && picker_action == PICK_NONE)
+ {
+ if (picker_dirty)
+ {
+ picker_dirty = 0;
+ picker_draw();
+ }
+ msleep(40);
+ }
+
+ int action = picker_action;
+ picker_running = 0;
+ menu_redraw_blocked = 0;
+ dbg("picker: end (action %d, menu still shown %d)", action, gui_menu_shown());
+
+ if (action == PICK_LOAD)
+ {
+ film_sel = picker_film;
+ exp_sel = picker_exp;
+ clrscr();
+ gui_stop_menu();
+ msleep(300);
+ load_roll(film_sel, exposure_choices[exp_sel]);
+ }
+ else if (gui_menu_shown())
+ {
+ if (home)
+ {
+ clrscr();
+ gui_stop_menu();
+ }
+ else
+ {
+ menu_redraw();
+ }
+ }
+ hud_dirty = 1;
+}
+
+static void picker_task(void *unused)
+{
+ picker_run(0);
+}
+
+/* from LiveView: open the ML menu and cover it with the picker */
+static void picker_home_task(int unused)
+{
+ if (picker_running)
+ return;
+
+ /* keep the ML menu from drawing itself, so the picker appears directly */
+ menu_redraw_blocked = 1;
+ gui_open_menu();
+ for (int i = 0; i < 20 && !gui_menu_shown(); i++)
+ msleep(50);
+ if (!gui_menu_shown())
+ {
+ menu_redraw_blocked = 0;
+ DBG_STATE("picker: ML menu did not open");
+ return;
+ }
+ picker_run(1);
+}
+
+/* the picker is the camera's start screen */
+static void startup_task(void *unused)
+{
+ /* wait (up to ~15 s) for ML to finish booting and LiveView to settle */
+ for (int i = 0; i < 150; i++)
+ {
+ if (ml_started && lv && display_idle() && !gui_menu_shown())
+ break;
+ if (i % 10 == 0 && ml_started)
+ DBG_STATE("startup waiting");
+ msleep(100);
+ }
+ msleep(800);
+
+ DBG_STATE("startup check");
+ if (!ml_started || !lv || !display_idle() || gui_menu_shown() || is_movie_mode())
+ {
+ dbg("startup: not on the LiveView screen, picker skipped");
+ return;
+ }
+ if (startup_picker == 2 || (startup_picker == 1 && !ROLL_IN_PROGRESS))
+ picker_home_task(0);
+ else
+ dbg("startup: picker not wanted (setting %d, roll in progress %d)", startup_picker, ROLL_IN_PROGRESS);
+}
+
+static unsigned int picker_key(unsigned int key)
+{
+ /* anything but a second SET cancels a pending "rewind this roll?" */
+ if (picker_confirm && key != MODULE_KEY_PRESS_SET && key != MODULE_KEY_UNPRESS_SET)
+ {
+ picker_confirm = 0;
+ picker_dirty = 1;
+ }
+
+ switch (key)
+ {
+ case MODULE_KEY_WHEEL_LEFT:
+ case MODULE_KEY_PRESS_LEFT:
+ picker_film = (picker_film + NUM_FILMS - 1) % NUM_FILMS;
+ picker_dirty = 1;
+ return 0;
+
+ case MODULE_KEY_WHEEL_RIGHT:
+ case MODULE_KEY_PRESS_RIGHT:
+ picker_film = (picker_film + 1) % NUM_FILMS;
+ picker_dirty = 1;
+ return 0;
+
+ case MODULE_KEY_INFO:
+ case MODULE_KEY_PRESS_UP:
+ case MODULE_KEY_PRESS_DOWN:
+ picker_exp = (picker_exp + 1) % NUM_EXPOSURE_CHOICES;
+ picker_dirty = 1;
+ return 0;
+
+ case MODULE_KEY_PRESS_SET:
+ if (ROLL_IN_PROGRESS && !picker_confirm)
+ {
+ picker_confirm = 1;
+ picker_dirty = 1;
+ }
+ else
+ {
+ picker_action = PICK_LOAD;
+ }
+ return 0;
+
+ case MODULE_KEY_MENU:
+ case MODULE_KEY_TRASH:
+ picker_action = PICK_EXIT;
+ return 0;
+
+ /* swallow the rest of the navigation so the menu underneath stays put */
+ case MODULE_KEY_UNPRESS_SET:
+ case MODULE_KEY_UNPRESS_UDLR:
+ case MODULE_KEY_JOY_CENTER:
+ case MODULE_KEY_PLAY:
+ case MODULE_KEY_Q:
+ return 0;
+ }
+ return 1; /* e.g. half-shutter closes the menu, which ends the picker */
+}
+
+/* ---------------------------------------------------------------- viewfinder HUD */
+
+#define STRIP_W 64 /* meter strip on the right */
+#define BAR_H 42 /* LED readout at the bottom */
+#define VIEW_W (SCREEN_W - STRIP_W)
+#define VIEW_H (SCREEN_H - BAR_H)
+#define THIRD_PX 14 /* scale spacing per 1/3 stop */
+#define SCALE_TOP 22 /* y of f/22; f/1 sits 27 thirds below */
+
+/* y on the aperture scale for fstops[index] (f/22 at the top, like an AE-1) */
+static int fstop_y(int index)
+{
+ return SCALE_TOP + (NUM_FSTOPS - 1 - index) * THIRD_PX;
+}
+
+static int hud_visible()
+{
+ return hud_enabled && roll_loaded && lv && !gui_menu_shown() && display_idle()
+ && !is_movie_mode() && !picker_running;
+}
+
+static void draw_needle(int y, int color)
+{
+ int x0 = SCREEN_W - STRIP_W + 4;
+ for (int r = -7; r <= 7; r++)
+ bmp_fill(color, x0, y + r, 16 - 2 * ABS(r), 1);
+}
+
+static void hud_draw(int lit, int blink)
+{
+ const int on = COLOR_RED;
+ const int off = COLOR_GRAY(10);
+ const int bg = COLOR_BLACK;
+
+ /* aperture scale: f/22 at the top, full stops labelled, red zone above
+ * f/22 (too much light) and below the lens' widest stop (too little) */
+ int sx = SCREEN_W - STRIP_W;
+ int cur = current_fstop();
+ int widest = lens_is_manual() ? lens_widest : 0;
+ char label[8];
+
+ bmp_fill(bg, sx, 0, STRIP_W, VIEW_H);
+ bmp_fill(COLOR_DARK_RED, sx + 26, 2, 5, SCALE_TOP - 8);
+ bmp_fill(COLOR_DARK_RED, sx + 26, fstop_y(widest) + 8, 5, 18);
+
+ for (int i = 1; i < NUM_FSTOPS; i += 3) /* f/1, 1.4, 2 ... 22 */
+ {
+ int y = fstop_y(i);
+ int usable = i >= widest;
+ format_fstop(label, sizeof(label), i);
+ bmp_fill(COLOR_GRAY(usable ? 50 : 20), sx + 24, y, 8, 1);
+ bmp_printf(FONT_TINY(i == cur ? COLOR_WHITE : COLOR_GRAY(usable ? 60 : 25), bg),
+ sx + 35, y - 6, "%s", label);
+ }
+
+ /* the aperture you set: white tick */
+ bmp_fill(COLOR_WHITE, sx + 20, fstop_y(cur) - 1, 14, 3);
+
+ /* the needle points at the aperture the meter asks for */
+ if (lit)
+ {
+ int ev8 = get_ae_value(); /* meter reading, 1/8 EV, + = too bright */
+ int want = cur + (ev8 * 3 + (ev8 >= 0 ? 4 : -4)) / 8;
+ int y;
+ int out_of_range = want > NUM_FSTOPS - 1 || want < widest;
+ if (want > NUM_FSTOPS - 1)
+ y = SCALE_TOP - 10;
+ else if (want < widest)
+ y = fstop_y(widest) + 16;
+ else
+ y = fstop_y(want);
+ if (!out_of_range || blink)
+ draw_needle(y, on);
+ }
+
+ /* LED readout */
+ int by = VIEW_H;
+ bmp_fill(bg, 0, by, SCREEN_W, BAR_H);
+ int ty = by + (BAR_H - 32) / 2;
+
+ /* the wind reminder blinks whether or not the meter is on */
+ int wind_col = !need_wind ? off : (blink ? on : COLOR_DARK_RED);
+ bmp_printf(FONT_BIG(wind_col, bg), 16, ty, "WIND");
+
+ bmp_printf(FONT_BIG(lit ? on : off, bg), 170, ty, "%s",
+ lens_info.raw_shutter ? lens_format_shutter(lens_info.raw_shutter) : "--");
+ format_fstop(label, sizeof(label), cur);
+ bmp_printf(FONT_BIG(lit ? on : off, bg), 330, ty, "f%s", label);
+ fill_circle(480, by + BAR_H / 2, 7, lit ? on : off);
+
+ int fc = (lit || ROLL_FINISHED) ? on : off;
+ if (ROLL_FINISHED)
+ bmp_printf(FONT_BIG(blink ? fc : off, bg), 560, ty, "END");
+ else
+ bmp_printf(FONT_BIG(fc, bg), 560, ty, "No.%d", frames_shot + 1);
+
+ /* focusing screen: microprism collar and split-image circle */
+ if (focus_screen)
+ {
+ int cx = VIEW_W / 2, cy = VIEW_H / 2;
+ draw_circle(cx, cy, 62, COLOR_GRAY(70));
+ draw_circle(cx, cy, 28, COLOR_WHITE);
+ draw_line(cx - 28, cy, cx + 28, cy, COLOR_WHITE);
+ }
+}
+
+/* make our strips transparent again so LiveView shows through */
+static void hud_clear()
+{
+ bmp_fill(COLOR_EMPTY, SCREEN_W - STRIP_W, 0, STRIP_W, VIEW_H);
+ bmp_fill(COLOR_EMPTY, 0, VIEW_H, SCREEN_W, BAR_H);
+ bmp_fill(COLOR_EMPTY, VIEW_W / 2 - 64, VIEW_H / 2 - 64, 129, 129);
+}
+
+static void hud_task(void *unused)
+{
+ int last_sig = -1;
+ int last_draw = 0;
+ int drawn = 0;
+ int was_visible = -1;
+
+ while (1)
+ {
+ msleep(100);
+
+ int visible = hud_visible();
+ if (visible != was_visible)
+ {
+ dbg("hud: visible %d (enabled %d roll %d lv %d menu %d idle %d movie %d picker %d)",
+ visible, hud_enabled, roll_loaded, lv, gui_menu_shown(), display_idle(),
+ is_movie_mode(), picker_running);
+ was_visible = visible;
+ }
+
+ if (!visible)
+ {
+ /* HUD switched off: wipe it once we're back on the LiveView screen */
+ if (drawn && !hud_enabled && lv && !gui_menu_shown() && display_idle())
+ {
+ hud_clear();
+ drawn = 0;
+ }
+ last_sig = -1;
+ continue;
+ }
+ drawn = 1;
+
+ int now = get_ms_clock();
+ int lit = !leds_on_half || get_halfshutter_pressed() || now < leds_until;
+ int blink = (now / 400) % 2;
+ int ev8 = lit ? get_ae_value() : 0;
+
+ int sig = lit | blink << 1 | need_wind << 2 | (frames_shot & 0xFF) << 3
+ | lens_info.raw_shutter << 11 | (ev8 & 0xFF) << 19 | (current_fstop() & 0x1F) << 27;
+
+ /* redraw on change, and every second to win over Canon's overlays */
+ if (sig != last_sig || hud_dirty || now - last_draw > 1000)
+ {
+ hud_dirty = 0;
+ last_sig = sig;
+ last_draw = now;
+ hud_draw(lit, blink);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------- keys */
+
+static unsigned int filmroll_keypress(unsigned int key)
+{
+ if (picker_running)
+ return picker_key(key);
+
+ /* only on the plain LiveView screen: never steal keys from Canon's menus or dialogs */
+ if (gui_menu_shown() || !lv || !roll_loaded || !display_idle())
+ return 1;
+
+ if (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_UNPRESS_HALFSHUTTER)
+ hud_dirty = 1;
+
+ /* aperture ring for manual lenses: the wheel in Av mode (where it has
+ * nothing to adjust without a lens), or up/down if the user prefers */
+ if (lens_is_manual() && !ROLL_FINISHED)
+ {
+ int dir = 0;
+ if (aperture_keys == 0 && shooting_mode == SHOOTMODE_AV)
+ dir = (key == MODULE_KEY_WHEEL_RIGHT) ? 1 : (key == MODULE_KEY_WHEEL_LEFT) ? -1 : 0;
+ else if (aperture_keys == 1)
+ dir = (key == MODULE_KEY_PRESS_UP) ? 1 : (key == MODULE_KEY_PRESS_DOWN) ? -1 : 0;
+ if (dir)
+ {
+ step_manual_fstop(dir);
+ leds_until = get_ms_clock() + 2000;
+ hud_dirty = 1;
+ return 0;
+ }
+ }
+
+ if (ROLL_FINISHED)
+ {
+ if (key == MODULE_KEY_PRESS_SET)
+ {
+ run_in_separate_task(picker_home_task, 0);
+ return 0;
+ }
+ return 1;
+ }
+
+ /* no peeking during a roll: PLAY brings up the film picker instead */
+ if (key == MODULE_KEY_PLAY && play_lock)
+ {
+ dbg("key: PLAY -> picker");
+ run_in_separate_task(picker_home_task, 0);
+ return 0;
+ }
+
+ if (need_wind)
+ {
+ if (key == MODULE_KEY_PRESS_SET)
+ {
+ need_wind = 0;
+ leds_until = get_ms_clock() + 1500;
+ hud_dirty = 1;
+ return 0;
+ }
+ if (wind_mode == 2 && (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_PRESS_FULLSHUTTER))
+ {
+ NotifyBox(1500, "Wind on first (SET)");
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+/* ---------------------------------------------------------------- menu */
+
+static MENU_UPDATE_FUNC(filmroll_main_upd)
+{
+ if (roll_loaded)
+ MENU_SET_VALUE("%s %d/%d", films[roll_film].name, frames_shot, roll_exposures);
+ else
+ MENU_SET_VALUE("no roll");
+}
+
+static MENU_UPDATE_FUNC(filmroll_status_upd)
+{
+ if (!roll_loaded)
+ {
+ MENU_SET_VALUE("no roll loaded");
+ return;
+ }
+ MENU_SET_VALUE("ROLL %03d", roll_number);
+ MENU_SET_RINFO("%d left", roll_exposures - frames_shot);
+ MENU_SET_HELP("Log: %s", log_path);
+}
+
+static MENU_UPDATE_FUNC(lens_widest_upd)
+{
+ manual_fstop = MAX(manual_fstop, lens_widest);
+ if (!lens_is_manual())
+ MENU_SET_WARNING(MENU_WARN_INFO, "Electronic lens attached: its own aperture is used.");
+}
+
+static MENU_UPDATE_FUNC(manual_fstop_upd)
+{
+ manual_fstop = MAX(manual_fstop, lens_widest);
+ if (!lens_is_manual())
+ MENU_SET_WARNING(MENU_WARN_INFO, "Electronic lens attached: its own aperture is used.");
+}
+
+static MENU_SELECT_FUNC(picker_select)
+{
+ if (!picker_running)
+ task_create("film_pick", 0x1c, 0x2000, picker_task, 0);
+}
+
+static MENU_SELECT_FUNC(load_roll_select)
+{
+ run_in_separate_task(load_roll_task, 0);
+}
+
+static MENU_SELECT_FUNC(reapply_select)
+{
+ run_in_separate_task(reapply_task, 0);
+}
+
+static struct menu_entry filmroll_menu[] =
+{
+ {
+ .name = "Film roll",
+ .select = menu_open_submenu,
+ .update = filmroll_main_upd,
+ .help = "Shoot like a film camera: pick a stock, load a roll, shoot it out.",
+ .help2 = "Set RAW (or RAW+JPEG) so the PC lab can develop the roll.",
+ .submenu_width = 720,
+ .children = (struct menu_entry[]) {
+ {
+ .name = "Choose film...",
+ .select = picker_select,
+ .icon_type = IT_ACTION,
+ .help = "Full-screen film picker. SET loads the roll.",
+ },
+ {
+ .name = "Film stock",
+ .priv = &film_sel,
+ .max = NUM_FILMS - 1,
+ .choices = CHOICES("Portra 400", "CineStill 800T", "Ektar 100", "Gold 200",
+ "Superia 400", "Velvia 50", "HP5 Plus 400", "Tri-X 400"),
+ .help = "Film for the next roll. Takes effect when you load a roll.",
+ },
+ {
+ .name = "Exposures",
+ .priv = &exp_sel,
+ .max = NUM_EXPOSURE_CHOICES - 1,
+ .choices = CHOICES("36", "24", "12"),
+ .help = "Frames on the next roll.",
+ },
+ {
+ .name = "Load new roll",
+ .select = load_roll_select,
+ .icon_type = IT_ACTION,
+ .help = "Applies the film settings and starts a new roll log.",
+ .help2 = "Any roll in progress ends here.",
+ },
+ {
+ .name = "Viewfinder HUD",
+ .priv = &hud_enabled,
+ .max = 1,
+ .help = "SLR-style meter needle and red LED readout in LiveView.",
+ .help2 = "Works best with Canon's clean display (INFO) and Global Draw off.",
+ },
+ {
+ .name = "LEDs on half-press",
+ .priv = &leds_on_half,
+ .max = 1,
+ .help = "Like a real SLR: the readout lights only while metering.",
+ },
+ {
+ .name = "Focusing screen",
+ .priv = &focus_screen,
+ .max = 1,
+ .help = "Draws a split-image circle and microprism collar (decoration only).",
+ },
+ {
+ .name = "Lens widest aperture",
+ .priv = &lens_widest,
+ .max = NUM_FSTOPS - 1,
+ .choices = FSTOP_CHOICES,
+ .update = lens_widest_upd,
+ .help = "Manual lenses only: the widest f-stop of your lens (e.g. 1.8).",
+ .help2 = "The aperture ring won't go wider than this.",
+ },
+ {
+ .name = "Manual aperture",
+ .priv = &manual_fstop,
+ .max = NUM_FSTOPS - 1,
+ .choices = FSTOP_CHOICES,
+ .update = manual_fstop_upd,
+ .help = "Manual lenses only: the f-stop set on the lens ring.",
+ .help2 = "Shown in the HUD and written to the roll log for the lab.",
+ },
+ {
+ .name = "Aperture ring",
+ .priv = &aperture_keys,
+ .max = 2,
+ .choices = CHOICES("Wheel in Av", "Up / Down", "Menu only"),
+ .help = "How to change Manual aperture in LiveView.",
+ .help2 = "Wheel in Av: in Av mode the wheel is free with a manual lens.",
+ },
+ {
+ .name = "Wind lever",
+ .priv = &wind_mode,
+ .max = 2,
+ .choices = CHOICES("OFF", "Reminder", "Block shutter"),
+ .help = "After each shot press SET to wind on.",
+ .help2 = "Block shutter is experimental: it may not stop a full press.",
+ },
+ {
+ .name = "Picker at startup",
+ .priv = &startup_picker,
+ .max = 2,
+ .choices = CHOICES("OFF", "No film loaded", "Always"),
+ .help = "Show the film picker when the camera turns on.",
+ .help2 = "MENU or half-shutter leaves it and keeps the film in the camera.",
+ },
+ {
+ .name = "Lock PLAY",
+ .priv = &play_lock,
+ .max = 1,
+ .help = "No peeking: during a roll PLAY opens the film picker instead.",
+ .help2 = "Playback works again once the roll is finished.",
+ },
+ {
+ .name = "Debug log",
+ .priv = &debug_log,
+ .max = 1,
+ .help = "Writes ML/FILMROLL.LOG for troubleshooting. Turn off when all works.",
+ },
+ {
+ .name = "Re-apply film settings",
+ .select = reapply_select,
+ .icon_type = IT_ACTION,
+ .help = "Use after changing picture style, WB or ISO by hand.",
+ },
+ {
+ .name = "Current roll",
+ .update = filmroll_status_upd,
+ .icon_type = IT_ALWAYS_ON,
+ },
+ MENU_EOL,
+ },
+ },
+};
+
+static unsigned int filmroll_init()
+{
+ if (roll_loaded)
+ update_log_path();
+ menu_add("Shoot", filmroll_menu, COUNT(filmroll_menu));
+ task_create("film_hud", 0x1e, 0x1000, hud_task, 0);
+ if (startup_picker)
+ task_create("film_start", 0x1e, 0x1000, startup_task, 0);
+ dbg("init: v2 build %s %s, roll %d loaded %d shot %d/%d, startup %d hud %d",
+ __DATE__, __TIME__, roll_number, roll_loaded, frames_shot, roll_exposures,
+ startup_picker, hud_enabled);
+ return 0;
+}
+
+static unsigned int filmroll_deinit()
+{
+ return 0;
+}
+
+MODULE_INFO_START()
+ MODULE_INIT(filmroll_init)
+ MODULE_DEINIT(filmroll_deinit)
+MODULE_INFO_END()
+
+MODULE_CBRS_START()
+ MODULE_CBR(CBR_SHOOT_TASK, filmroll_poll, 0)
+ MODULE_CBR(CBR_KEYPRESS, filmroll_keypress, 0)
+MODULE_CBRS_END()
+
+MODULE_CONFIGS_START()
+ MODULE_CONFIG(film_sel)
+ MODULE_CONFIG(exp_sel)
+ MODULE_CONFIG(hud_enabled)
+ MODULE_CONFIG(focus_screen)
+ MODULE_CONFIG(leds_on_half)
+ MODULE_CONFIG(wind_mode)
+ MODULE_CONFIG(play_lock)
+ MODULE_CONFIG(startup_picker)
+ MODULE_CONFIG(debug_log)
+ MODULE_CONFIG(lens_widest)
+ MODULE_CONFIG(manual_fstop)
+ MODULE_CONFIG(aperture_keys)
+ MODULE_CONFIG(roll_loaded)
+ MODULE_CONFIG(roll_number)
+ MODULE_CONFIG(roll_film)
+ MODULE_CONFIG(roll_exposures)
+ MODULE_CONFIG(frames_shot)
+ MODULE_CONFIG(last_file_number)
+ MODULE_CONFIG(roll_folder)
+ MODULE_CONFIG(need_wind)
+MODULE_CONFIGS_END()
diff --git a/ml-dev/films/filmluts.py b/ml-dev/films/filmluts.py
new file mode 100644
index 0000000..dfe53ad
--- /dev/null
+++ b/ml-dev/films/filmluts.py
@@ -0,0 +1,126 @@
+"""Film stocks whose colour comes from the G'MIC film LUTs collected in
+https://github.com/YahiaAngelo/Film-Luts (fetch them with getluts.py).
+
+Every entry: key, the LUT's path in that repository (without .cube),
+brand, name, box speed, and kind:
+
+ neg colour negative, C-41 slide colour reversal, E-6 / K-14
+ xpro cross-processed bw black and white
+ print motion-picture print stock (the look of a cinema print)
+
+films.py turns them into lab films: the colour from the LUT, the rest
+(scanner exposure, halation, grain, softness) from the kind and speed.
+The LUTs take ordinary sRGB pictures as input.
+"""
+
+REPO = "https://github.com/YahiaAngelo/Film-Luts"
+ZIP = "https://codeload.github.com/YahiaAngelo/Film-Luts/zip/refs/heads/main"
+DIR = "filmluts" # under films/luts/
+
+STOCKS = [
+ # colour negative
+ ("portra160", "negative_new/kodak_portra_160", "Kodak", "Portra 160", 160, "neg"),
+ ("portra800", "negative_new/kodak_portra_800", "Kodak", "Portra 800", 800, "neg"),
+ ("portra160nc", "negative_old/kodak_portra_160_nc", "Kodak", "Portra 160NC", 160, "neg"),
+ ("portra160vc", "negative_old/kodak_portra_160_vc", "Kodak", "Portra 160VC", 160, "neg"),
+ ("portra400nc", "negative_old/kodak_portra_400_nc", "Kodak", "Portra 400NC", 400, "neg"),
+ ("portra400vc", "negative_old/kodak_portra_400_vc", "Kodak", "Portra 400VC", 400, "neg"),
+ ("portra400uc", "negative_old/kodak_portra_400_uc", "Kodak", "Portra 400UC", 400, "neg"),
+ ("elite200", "negative_color/kodak_elite_color_200", "Kodak", "Elite Color 200", 200, "neg"),
+ ("elite400", "negative_color/kodak_elite_color_400", "Kodak", "Elite Color 400", 400, "neg"),
+ ("pro160c", "negative_new/fuji_160c", "Fujifilm", "Pro 160C", 160, "neg"),
+ ("pro400h", "negative_new/fuji_400h", "Fujifilm", "Pro 400H", 400, "neg"),
+ ("pro800z", "negative_new/fuji_800z", "Fujifilm", "Pro 800Z", 800, "neg"),
+ ("reala100", "negative_color/fuji_superia_reala_100", "Fujifilm", "Reala 100", 100, "neg"),
+ ("superia100", "negative_old/fuji_superia_100", "Fujifilm", "Superia 100", 100, "neg"),
+ ("superia200", "negative_color/fuji_superia_200", "Fujifilm", "Superia 200", 200, "neg"),
+ ("superia800", "negative_old/fuji_superia_800", "Fujifilm", "Superia 800", 800, "neg"),
+ ("superia1600", "negative_old/fuji_superia_1600", "Fujifilm", "Superia 1600", 1600, "neg"),
+ ("xtra800", "negative_color/fuji_superia_x-tra_800", "Fujifilm", "X-TRA 800", 800, "neg"),
+ ("vista200", "negative_color/agfa_vista_200", "Agfa", "Vista 200", 200, "neg"),
+ ("ultra100", "negative_color/agfa_ultra_color_100", "Agfa", "Ultra 100", 100, "neg"),
+ ("redscale100", "negative_color/lomography_redscale_100", "Lomography", "Redscale 100", 100, "neg"),
+ # colour reversal
+ ("velvia100", "colorslide/fuji_velvia_100_generic", "Fujifilm", "Velvia 100", 100, "slide"),
+ ("provia100f", "colorslide/fuji_provia_100f", "Fujifilm", "Provia 100F", 100, "slide"),
+ ("provia400f", "colorslide/fuji_provia_400f", "Fujifilm", "Provia 400F", 400, "slide"),
+ ("provia400x", "colorslide/fuji_provia_400x", "Fujifilm", "Provia 400X", 400, "slide"),
+ ("astia100f", "colorslide/fuji_astia_100f", "Fujifilm", "Astia 100F", 100, "slide"),
+ ("sensia100", "colorslide/fuji_sensia_100", "Fujifilm", "Sensia 100", 100, "slide"),
+ ("kodachrome25", "colorslide/kodak_kodachrome_25", "Kodak", "Kodachrome 25", 25, "slide"),
+ ("kodachrome64", "colorslide/kodak_kodachrome_64", "Kodak", "Kodachrome 64", 64, "slide"),
+ ("kodachrome200", "colorslide/kodak_kodachrome_200", "Kodak", "Kodachrome 200", 200, "slide"),
+ ("e100gx", "colorslide/kodak_e-100_gx_ektachrome_100", "Kodak", "Ektachrome E100GX", 100, "slide"),
+ ("e100vs", "colorslide/kodak_ektachrome_100_vs", "Kodak", "Ektachrome E100VS", 100, "slide"),
+ ("elitechrome200", "colorslide/kodak_elite_chrome_200", "Kodak", "Elite Chrome 200", 200, "slide"),
+ ("elitechrome400", "colorslide/kodak_elite_chrome_400", "Kodak", "Elite Chrome 400", 400, "slide"),
+ ("extracolor100", "colorslide/kodak_elite_extracolor_100", "Kodak", "ExtraColor 100", 100, "slide"),
+ ("precisa100", "colorslide/agfa_precisa_100", "Agfa", "Precisa 100", 100, "slide"),
+ # cross-processed
+ ("elite100xpro", "negative_color/kodak_elite_100_xpro", "Kodak", "Elite 100 X-Pro", 100, "xpro"),
+ ("superia200xpro", "colorslide/fuji_superia_200_xpro", "Fujifilm", "Superia 200 X-Pro", 200, "xpro"),
+ ("xproslide200", "colorslide/lomography_x-pro_slide_200", "Lomography", "X-Pro Slide 200", 200, "xpro"),
+ # black and white
+ ("tmax100", "bw/kodak_t-max_100", "Kodak", "T-MAX 100", 100, "bw"),
+ ("tmax400", "bw/kodak_t-max_400", "Kodak", "T-MAX 400", 400, "bw"),
+ ("tmax3200", "bw/kodak_t-max_3200", "Kodak", "T-MAX P3200", 3200, "bw"),
+ ("bw400cn", "bw/kodak_bw_400_cn", "Kodak", "BW400CN", 400, "bw"),
+ ("hie", "bw/kodak_hie_hs_infra", "Kodak", "HIE Infrared", 400, "bw"),
+ ("delta100", "bw/ilford_delta_100", "Ilford", "Delta 100", 100, "bw"),
+ ("delta400", "bw/ilford_delta_400", "Ilford", "Delta 400", 400, "bw"),
+ ("delta3200", "bw/ilford_delta_3200", "Ilford", "Delta 3200", 3200, "bw"),
+ ("fp4", "bw/ilford_fp_4_plus_125", "Ilford", "FP4 Plus", 125, "bw"),
+ ("panf50", "bw/ilford_pan_f_plus_50", "Ilford", "Pan F Plus", 50, "bw"),
+ ("hps800", "bw/ilford_hps_800", "Ilford", "HPS 800", 800, "bw"),
+ ("xp2", "bw/ilford_xp_2", "Ilford", "XP2 Super", 400, "bw"),
+ ("acros100", "bw/fuji_neopan_acros_100", "Fujifilm", "Acros 100", 100, "bw"),
+ ("neopan1600", "bw/fuji_neopan_1600", "Fujifilm", "Neopan 1600", 1600, "bw"),
+ ("apx25", "bw/agfa_apx_25", "Agfa", "APX 25", 25, "bw"),
+ ("apx100", "bw/agfa_apx_100", "Agfa", "APX 100", 100, "bw"),
+ ("retro80s", "bw/rollei_retro_80s", "Rollei", "Retro 80S", 80, "bw"),
+ ("retro100", "bw/rollei_retro_100_tonal", "Rollei", "Retro 100 Tonal", 100, "bw"),
+ ("ortho25", "bw/rollei_ortho_25", "Rollei", "Ortho 25", 25, "bw"),
+ ("ir400", "bw/rollei_ir_400", "Rollei", "Infrared 400", 400, "bw"),
+ # cinema print stocks
+ ("kodak2383", "print/kodak_2383_constlmap", "Kodak", "Vision 2383", 200, "print"),
+ ("kodak2393", "print/kodak_2393_constlmap", "Kodak", "Vision 2393", 200, "print"),
+ ("fuji3510", "print/fuji_3510_constlmap", "Fujifilm", "Eterna 3510", 200, "print"),
+ ("fuji3513", "print/fuji_3513_constlmap", "Fujifilm", "Eterna 3513", 200, "print"),
+]
+
+
+def grain_for(iso, kind):
+ """Grain amplitude and clump size for a box speed: the faster, the coarser."""
+ steps = {25: 0, 50: 1, 64: 1.3, 80: 1.6, 100: 2, 125: 2.3, 160: 2.7, 200: 3,
+ 400: 4, 800: 5, 1600: 6, 3200: 7}[iso]
+ amount = 0.006 + 0.0045 * steps
+ if kind == "slide":
+ amount *= 0.7
+ if kind == "print":
+ amount = 0.008
+ return round(amount, 4), round(0.7 + 0.11 * steps, 2)
+
+
+def film(key, path, brand, name, iso, kind):
+ amount, size = grain_for(iso, kind)
+ f = dict(
+ name=f"{brand} {name}", iso=iso, kind=kind, balance=5500,
+ lut=f"{DIR}/{path}.cube", lut_space="srgb",
+ # the film's own colour when the LUT isn't there: a plain print
+ ev=0.2 if kind == "neg" else 0.0, sat=1.0,
+ contrast=(0.18, 0.18, 0.18), pivot=(0.0, 0.0, 0.0),
+ black=(0.03, 0.03, 0.03), white=(0.96, 0.96, 0.96),
+ halation=0.8, grain=amount, grain_size=size, soft=0.7,
+ )
+ if kind in ("slide", "xpro"):
+ f.update(slide=True, contrast=(0.22, 0.22, 0.22), black=(0.015,) * 3, white=(0.98,) * 3,
+ halation=0.4, soft=0.5)
+ if kind == "bw":
+ f.update(mono=(0.30, 0.59, 0.11), contrast=(0.19,), pivot=(0.0,), black=(0.03,), white=(0.96,),
+ halation=0.4)
+ if kind == "print":
+ f.update(halation=0.5, soft=0.5)
+ return f
+
+
+FILMS = {s[0]: film(*s) for s in STOCKS}
diff --git a/ml-dev/films/films.py b/ml-dev/films/films.py
new file mode 100644
index 0000000..fd0acc4
--- /dev/null
+++ b/ml-dev/films/films.py
@@ -0,0 +1,122 @@
+"""Film stock definitions for the lab.
+
+Every number here is an artistic starting point, not measured data.
+Tune each stock by comparing against real scans of that film.
+
+Keys
+ balance colour temperature the film is balanced for (K). Daylight
+ film = 5500, tungsten film = 3200.
+ slide reversal film: no lab scanner exposure correction.
+ ev exposure offset in stops (negative film likes extra light).
+ sat saturation in linear light, 1.0 = unchanged.
+ contrast curve slope per channel, in display units per stop.
+ pivot per-channel shift of the curve centre, in stops. Small
+ differences between channels give colour crossovers
+ (e.g. warm highlights with cool shadows).
+ black/white per-channel base fog and maximum density of the print.
+ hues selective hue tweaks: (from, toward, amount, chroma_mult).
+ halation strength of the red glow around bright highlights.
+ grain grain amplitude in display units at mid-tones.
+ grain_size grain clump size in full-resolution pixels.
+ soft optical softness (gaussian sigma, full-res pixels).
+ mono channel mix for black and white stocks (acts like a filter).
+ kind neg, slide, xpro, bw, cine or print: the shelf it stands on in
+ the camera.
+ short the film in folder names ("Sep0906 Portra400").
+ lut a .cube under luts/ for the colour (lut_space: its input),
+ used when luts/ has no <key>.*.cube of its own. The rest of
+ the entry still gives halation, grain and softness, and the
+ colour when the file is missing.
+
+The stocks in filmluts.py (colour from the Film-Luts collection) are
+added at the end.
+"""
+
+import re
+
+from filmluts import FILMS as FILM_LUTS
+
+FILMS = {
+ "portra400": dict(
+ name="Kodak Portra 400", iso=400, kind="neg", short="Portra400", balance=5500, ev=0.3, sat=0.85,
+ contrast=(0.165, 0.17, 0.158), pivot=(-0.15, 0.0, 0.1),
+ black=(0.03, 0.026, 0.028), white=(0.97, 0.955, 0.92),
+ hues=[("orange", "red", 0.06, 1.05), ("green", "yellow", 0.12, 0.85),
+ ("blue", "cyan", 0.08, 0.85)],
+ halation=1.0, grain=0.018, grain_size=1.1, soft=0.7,
+ ),
+ "cinestill800t": dict(
+ name="CineStill 800T", iso=800, kind="cine", short="CineStill800T", balance=3200, ev=0.0, sat=0.95,
+ contrast=(0.18, 0.18, 0.172), pivot=(-0.05, 0.0, -0.05),
+ black=(0.02, 0.032, 0.045), white=(0.97, 0.96, 0.95),
+ hues=[("cyan", "blue", 0.1, 1.0), ("red", "orange", 0.08, 1.05)],
+ halation=6.0, hal_thr=0.6, grain=0.026, grain_size=1.4, soft=0.8,
+ ),
+ "ektar100": dict(
+ name="Kodak Ektar 100", iso=100, kind="neg", short="Ektar100", balance=5500, ev=0.0, sat=1.25,
+ contrast=(0.19, 0.19, 0.186), pivot=(-0.05, 0.0, 0.05),
+ black=(0.025, 0.02, 0.025), white=(0.98, 0.97, 0.95),
+ hues=[("red", "magenta", 0.05, 1.1), ("blue", "blue", 0.0, 1.15)],
+ halation=0.6, grain=0.009, grain_size=0.8, soft=0.5,
+ ),
+ "gold200": dict(
+ name="Kodak Gold 200", iso=200, kind="neg", short="Gold200", balance=5500, ev=0.2, sat=1.08,
+ contrast=(0.185, 0.18, 0.168), pivot=(-0.25, -0.05, 0.2),
+ black=(0.035, 0.028, 0.022), white=(0.98, 0.95, 0.86),
+ hues=[("yellow", "orange", 0.1, 1.1), ("green", "yellow", 0.15, 0.9)],
+ halation=1.0, grain=0.016, grain_size=1.1, soft=0.7,
+ ),
+ "superia400": dict(
+ name="Fujicolor Superia 400", iso=400, kind="neg", short="Superia400", balance=5500, ev=0.1, sat=1.05,
+ contrast=(0.18, 0.183, 0.178), pivot=(0.05, -0.1, 0.0),
+ black=(0.022, 0.036, 0.032), white=(0.96, 0.97, 0.95),
+ hues=[("green", "cyan", 0.18, 1.05), ("red", "magenta", 0.06, 1.0),
+ ("yellow", "green", 0.06, 0.95)],
+ halation=1.0, grain=0.02, grain_size=1.2, soft=0.7,
+ ),
+ "velvia50": dict(
+ name="Fujichrome Velvia 50", iso=50, kind="slide", short="Velvia50", balance=5500, slide=True, ev=-0.3, sat=1.45,
+ contrast=(0.25, 0.25, 0.25), pivot=(0.0, 0.0, -0.05),
+ black=(0.01, 0.01, 0.015), white=(0.98, 0.98, 0.98),
+ hues=[("green", "green", 0.0, 1.15), ("blue", "magenta", 0.06, 1.15),
+ ("red", "magenta", 0.06, 1.1)],
+ halation=0.3, grain=0.007, grain_size=0.7, soft=0.5,
+ ),
+ "hp5": dict(
+ name="Ilford HP5 Plus 400", iso=400, kind="bw", short="HP5", balance=5500, ev=0.2,
+ mono=(0.30, 0.60, 0.10),
+ contrast=(0.175,), pivot=(0.0,), black=(0.03,), white=(0.96,),
+ halation=0.4, grain=0.028, grain_size=1.3, soft=0.7,
+ ),
+ "trix400": dict(
+ name="Kodak Tri-X 400", iso=400, kind="bw", short="TriX400", balance=5500, ev=0.0,
+ mono=(0.42, 0.48, 0.10),
+ contrast=(0.205,), pivot=(0.1,), black=(0.02,), white=(0.97,),
+ halation=0.4, grain=0.036, grain_size=1.3, soft=0.6,
+ ),
+}
+
+# CineStill 400T: the colour from your own LUT, luts/cinestill400t.slog3.cube
+# (a Resolve LUT for S-Log3 footage, so the lab hands it S-Log3). Daylight
+# balance, so the LUT gets the white balance it was graded for; 3200 gives
+# the tungsten film's blue in daylight. Without the file, a softer 800T.
+FILMS["cinestill400t"] = dict(
+ name="CineStill 400T", iso=400, kind="cine", short="CineStill400T", balance=5500, ev=0.0, sat=0.95,
+ contrast=(0.175, 0.175, 0.168), pivot=(-0.05, 0.0, -0.05),
+ black=(0.02, 0.03, 0.04), white=(0.97, 0.96, 0.95),
+ hues=[("cyan", "blue", 0.1, 1.0), ("red", "orange", 0.08, 1.05)],
+ halation=3.0, hal_thr=0.65, grain=0.022, grain_size=1.3, soft=0.75,
+ lut="cinestill400t.slog3.cube", lut_space="slog3",
+)
+
+FILMS.update(FILM_LUTS)
+
+
+def short_name(key):
+ """'Portra400': the film's name without brand, spaces or punctuation."""
+ f = FILMS[key]
+ if "short" in f:
+ return f["short"]
+ name = f["name"].split(" ", 1)[1] if " " in f["name"] else f["name"]
+ return re.sub(r"[^A-Za-z0-9]", "", name)
+
diff --git a/ml-dev/films/getluts.py b/ml-dev/films/getluts.py
new file mode 100644
index 0000000..6186e75
--- /dev/null
+++ b/ml-dev/films/getluts.py
@@ -0,0 +1,85 @@
+"""Fetch the Film-Luts LUTs the films in filmluts.py use, into luts/filmluts/.
+
+ python getluts.py # once; again only to update them
+ python getluts.py --from ~/Film-Luts # from a clone you already have
+
+Downloads the collection (about 40 MB) and keeps only the LUTs a film
+names. They are not part of this repository: the collection is shared
+as-is and some LUTs may carry their makers' rights.
+"""
+
+import argparse
+import io
+import shutil
+import subprocess
+import sys
+import tempfile
+import urllib.request
+import zipfile
+from pathlib import Path
+
+from filmluts import DIR, REPO, STOCKS, ZIP
+
+HERE = Path(__file__).resolve().parent
+
+
+def download(url):
+ # curl first: Python from python.org on a Mac often can't check
+ # certificates until "Install Certificates.command" has been run
+ if shutil.which("curl"):
+ r = subprocess.run(["curl", "-fsSL", url], capture_output=True)
+ if r.returncode == 0:
+ return r.stdout
+ with urllib.request.urlopen(url) as resp:
+ return resp.read()
+
+
+def from_zip(want):
+ """{path in the repository: bytes} for the wanted LUTs, from GitHub's zip."""
+ data = zipfile.ZipFile(io.BytesIO(download(ZIP)))
+ out = {}
+ for name in data.namelist():
+ rel = name.split("/", 1)[1] if "/" in name else name # drop "Film-Luts-main/"
+ if rel in want:
+ out[rel] = data.read(name)
+ return out
+
+
+def from_dir(root, want):
+ root = Path(root).expanduser()
+ return {rel: (root / rel).read_bytes() for rel in want if (root / rel).is_file()}
+
+
+def from_git(want):
+ with tempfile.TemporaryDirectory() as tmp:
+ subprocess.run(["git", "clone", "--depth", "1", "-q", REPO, tmp], check=True)
+ return from_dir(tmp, want)
+
+
+def main():
+ ap = argparse.ArgumentParser(description="Fetch the Film-Luts LUTs the lab's films use.")
+ ap.add_argument("--from", dest="src", help="a Film-Luts clone already on this computer")
+ a = ap.parse_args()
+ dest = HERE / "luts" / DIR
+ want = {f"luts/{path}.cube" for _, path, *_ in STOCKS}
+ if a.src:
+ files = from_dir(a.src, want)
+ else:
+ print(f"downloading {REPO} ...")
+ try:
+ files = from_zip(want)
+ except Exception as e: # no zip: try git
+ print(f" zip download failed ({e}); trying git clone")
+ files = from_git(want)
+ for rel, data in files.items():
+ dst = dest / rel[len("luts/"):]
+ dst.parent.mkdir(parents=True, exist_ok=True)
+ dst.write_bytes(data)
+ print(f"{len(files)} of {len(want)} LUTs -> {dest}")
+ if len(files) < len(want):
+ print("missing:", ", ".join(sorted(want - set(files))))
+ sys.exit(1)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ml-dev/films/lut.py b/ml-dev/films/lut.py
new file mode 100644
index 0000000..414d8cf
--- /dev/null
+++ b/ml-dev/films/lut.py
@@ -0,0 +1,275 @@
+"""LUTs for the films: read and apply .cube files (the camera build bakes
+each film's colour table from its LUT with these).
+
+ python lut.py info luts/MyPortra.logc3.cube # what is in a LUT
+
+A 3D LUT expects its input in one colour encoding, usually the log curve
+of the camera it was made for. The lab starts from RAW, so it can give it
+exactly that. Name the encoding in the file name, <name>.<space>.cube, or
+pass --lut-space:
+
+ logc3 ARRI LogC3 (EI 800) in ARRI Wide Gamut 3. Most film emulation
+ LUTs are made for it ("LogC to Rec709", "Alexa")
+ slog3 Sony S-Log3 in S-Gamut3.Cine, what most LUTs for Sony footage
+ expect ("Slog3", "SGamut3Cine")
+ slog3sg3 Sony S-Log3 in the wider S-Gamut3
+ cineon Cineon log, the density of a film scan, Rec.709 primaries
+ rec709 the Rec.709 camera curve, highlights rolled off
+ srgb the sRGB display curve, highlights rolled off (LUTs made on
+ ordinary photos, e.g. exported from Lightroom or Photoshop)
+ linear scene linear, only for LUTs that bring their own shaper
+
+The output of every LUT is taken as an sRGB / Rec.709 display image.
+"""
+
+import argparse
+import functools
+from pathlib import Path
+
+import numpy as np
+
+LUT_DIR = Path(__file__).parent / "luts"
+SPACES = ("logc3", "slog3", "slog3sg3", "cineon", "rec709", "srgb", "linear")
+
+# ---------------------------------------------------------------- encodings
+
+# linear Rec.709 / sRGB primaries (D65) <-> ARRI Wide Gamut 3, through XYZ
+_709_TO_XYZ = np.array([[0.4124564, 0.3575761, 0.1804375],
+ [0.2126729, 0.7151522, 0.0721750],
+ [0.0193339, 0.1191920, 0.9503041]])
+_AWG3_TO_XYZ = np.array([[0.638008, 0.214704, 0.097744],
+ [0.291954, 0.823841, -0.115795],
+ [0.002798, -0.067034, 1.153294]])
+M_709_TO_AWG3 = (np.linalg.inv(_AWG3_TO_XYZ) @ _709_TO_XYZ).astype(np.float32)
+M_AWG3_TO_709 = np.linalg.inv(M_709_TO_AWG3).astype(np.float32)
+
+# Sony S-Gamut3.Cine and S-Gamut3 (Sony's published primaries, D65)
+_SG3C_TO_XYZ = np.array([[0.5990839208, 0.2489255161, 0.1024464902],
+ [0.2150758201, 0.8850685017, -0.1001443219],
+ [-0.0320658495, -0.0276583907, 1.1487819910]])
+_SG3_TO_XYZ = np.array([[0.7064827132, 0.1288010498, 0.1151721641],
+ [0.2709796708, 0.7866064112, -0.0575860820],
+ [-0.0096778454, 0.0046000375, 1.0941355587]])
+M_709_TO_SG3C = (np.linalg.inv(_SG3C_TO_XYZ) @ _709_TO_XYZ).astype(np.float32)
+M_709_TO_SG3 = (np.linalg.inv(_SG3_TO_XYZ) @ _709_TO_XYZ).astype(np.float32)
+M_SG3C_TO_709 = np.linalg.inv(M_709_TO_SG3C).astype(np.float32)
+M_SG3_TO_709 = np.linalg.inv(M_709_TO_SG3).astype(np.float32)
+
+# ARRI LogC3 at EI 800
+LOGC_CUT, LOGC_A, LOGC_B, LOGC_C = 0.010591, 5.555556, 0.052272, 0.247190
+LOGC_D, LOGC_E, LOGC_F = 0.385537, 5.367655, 0.092809
+
+# Cineon: 0.002 density per code value, negative gamma 0.6, white at 685, black at 95
+CIN_BLACK = 10 ** ((95 - 685) * 0.002 / 0.6)
+
+KNEE = 0.8 # display curves: highlights above this roll off towards 1
+
+
+def _rolloff(x):
+ x = np.maximum(x, 0)
+ over = x - KNEE
+ soft = KNEE + (1 - KNEE) * (1 - np.exp(-np.maximum(over, 0) / (1 - KNEE)))
+ return np.where(over > 0, soft, x)
+
+
+def _rolloff_inv(y):
+ y = np.clip(y, 0, 1 - 1e-6)
+ over = y - KNEE
+ hard = KNEE - (1 - KNEE) * np.log(1 - np.maximum(over, 0) / (1 - KNEE))
+ return np.where(over > 0, hard, y)
+
+
+def _slog3(x):
+ """Sony S-Log3: scene linear (0.18 = mid grey) -> code 0..1."""
+ return np.where(x >= 0.01125,
+ (420 + np.log10(np.maximum(x + 0.01, 1e-6) / 0.19) * 261.5) / 1023,
+ (x * (171.2102946929 - 95) / 0.01125 + 95) / 1023)
+
+
+def _slog3_inv(v):
+ return np.where(v >= 171.2102946929 / 1023,
+ np.power(10, (v * 1023 - 420) / 261.5) * 0.19 - 0.01,
+ (v * 1023 - 95) * 0.01125 / (171.2102946929 - 95))
+
+
+def encode(lin, space):
+ """Scene-linear Rec.709 (0.18 = mid grey) -> what a LUT for `space` expects."""
+ lin = np.asarray(lin, np.float32)
+ if space in ("slog3", "slog3sg3"):
+ return _slog3(lin @ (M_709_TO_SG3C if space == "slog3" else M_709_TO_SG3).T)
+ if space == "logc3":
+ x = lin @ M_709_TO_AWG3.T
+ return np.where(x > LOGC_CUT,
+ LOGC_C * np.log10(np.maximum(LOGC_A * x + LOGC_B, 1e-6)) + LOGC_D,
+ LOGC_E * x + LOGC_F)
+ if space == "cineon":
+ x = np.maximum(lin, 0) * (1 - CIN_BLACK) + CIN_BLACK
+ return (685 + 300 * np.log10(x)) / 1023
+ if space == "rec709":
+ x = _rolloff(lin)
+ return np.where(x < 0.018, 4.5 * x, 1.099 * np.power(x, 0.45) - 0.099)
+ if space == "srgb":
+ x = _rolloff(lin)
+ return np.where(x <= 0.0031308, 12.92 * x, 1.055 * np.power(x, 1 / 2.4) - 0.055)
+ if space == "linear":
+ return lin
+ raise ValueError(f"unknown LUT input space '{space}' (one of {', '.join(SPACES)})")
+
+
+def decode(v, space):
+ """The inverse of encode(): back to scene-linear Rec.709."""
+ v = np.asarray(v, np.float32)
+ if space in ("slog3", "slog3sg3"):
+ return _slog3_inv(v) @ (M_SG3C_TO_709 if space == "slog3" else M_SG3_TO_709).T
+ if space == "logc3":
+ x = np.where(v > LOGC_E * LOGC_CUT + LOGC_F,
+ (np.power(10, (v - LOGC_D) / LOGC_C) - LOGC_B) / LOGC_A,
+ (v - LOGC_F) / LOGC_E)
+ return x @ M_AWG3_TO_709.T
+ if space == "cineon":
+ x = np.power(10, (v * 1023 - 685) / 300)
+ return (x - CIN_BLACK) / (1 - CIN_BLACK)
+ if space == "rec709":
+ x = np.where(v < 0.081, v / 4.5, np.power(np.maximum(v + 0.099, 0) / 1.099, 1 / 0.45))
+ return _rolloff_inv(x)
+ if space == "srgb":
+ x = np.where(v <= 0.04045, v / 12.92, np.power(np.maximum(v + 0.055, 0) / 1.055, 2.4))
+ return _rolloff_inv(x)
+ if space == "linear":
+ return v
+ raise ValueError(f"unknown LUT input space '{space}' (one of {', '.join(SPACES)})")
+
+
+# ---------------------------------------------------------------- .cube files
+
+def space_from_name(path):
+ """'Kodak 2383.logc3.cube' -> 'logc3'; None when the name says nothing."""
+ suffixes = [s.lower().lstrip(".") for s in Path(path).suffixes[:-1]]
+ return suffixes[-1] if suffixes and suffixes[-1] in SPACES else None
+
+
+class Lut:
+ """A .cube file: an optional 1D shaper, then a 3D table (Resolve's layout)."""
+
+ def __init__(self, path, space=None):
+ self.path = Path(path)
+ self.title = self.path.stem
+ self.space = space or space_from_name(path) or "srgb"
+ encode(np.zeros(3, np.float32), self.space) # a bad space fails here
+ size1 = size3 = 0
+ dom = {"1": [np.zeros(3), np.ones(3)], "3": [np.zeros(3), np.ones(3)]}
+ rows = []
+ for line in self.path.read_text(encoding="utf-8-sig", errors="replace").splitlines():
+ line = line.split("#", 1)[0].strip()
+ if not line:
+ continue
+ key, _, rest = line.partition(" ")
+ key = key.upper()
+ if key == "TITLE":
+ self.title = rest.strip().strip('"') or self.title
+ elif key == "LUT_1D_SIZE":
+ size1 = int(rest)
+ elif key == "LUT_3D_SIZE":
+ size3 = int(rest)
+ elif key in ("DOMAIN_MIN", "DOMAIN_MAX"):
+ v = np.array(rest.split(), float)
+ for d in ("1", "3"):
+ dom[d][key == "DOMAIN_MAX"] = v
+ elif key in ("LUT_1D_INPUT_RANGE", "LUT_3D_INPUT_RANGE"):
+ lo, hi = (float(t) for t in rest.split())
+ dom[key[4]] = [np.full(3, lo), np.full(3, hi)]
+ elif key[0].isdigit() or key[0] in "-+.":
+ rows.append(line.split())
+ data = np.array(rows, np.float32)
+ if data.ndim != 2 or data.shape[1] != 3 or len(data) != size1 + size3 ** 3:
+ raise ValueError(f"{self.path.name}: expected {size1} + {size3}^3 rows of 3 numbers, "
+ f"found {len(data)}")
+ self.table1 = data[:size1] if size1 else None
+ self.table3 = data[size1:].reshape(size3, size3, size3, 3) if size3 else None # [b][g][r]
+ self.dom1 = [np.float32(v) for v in dom["1"]]
+ self.dom3 = [np.float32(v) for v in dom["3"]]
+
+ def describe(self):
+ parts = [f"'{self.title}'"]
+ if self.table1 is not None:
+ parts.append(f"1D shaper {len(self.table1)}")
+ if self.table3 is not None:
+ parts.append(f"3D {self.table3.shape[0]}^3")
+ return ", ".join(parts) + f", input {self.space}"
+
+ def apply_encoded(self, v):
+ """v: values already in the LUT's input encoding, (..., 3)."""
+ out = np.asarray(v, np.float32)
+ if self.table1 is not None:
+ n = len(self.table1)
+ x = (out - self.dom1[0]) / (self.dom1[1] - self.dom1[0]) * (n - 1)
+ grid = np.arange(n, dtype=np.float32)
+ out = np.stack([np.interp(x[..., c], grid, self.table1[:, c]) for c in range(3)], -1)
+ if self.table3 is not None:
+ n = self.table3.shape[0]
+ x = np.clip((out - self.dom3[0]) / (self.dom3[1] - self.dom3[0]), 0, 1) * (n - 1)
+ out = _trilinear(self.table3, x)
+ return out.astype(np.float32)
+
+ def apply(self, lin, chunk=1 << 20):
+ """Scene-linear Rec.709 in, display sRGB out, a slice at a time so a
+ full-size frame doesn't need gigabytes."""
+ flat = lin.reshape(-1, 3)
+ out = np.empty_like(flat, dtype=np.float32)
+ for i in range(0, len(flat), chunk):
+ out[i:i + chunk] = self.apply_encoded(encode(flat[i:i + chunk], self.space))
+ return out.reshape(lin.shape)
+
+
+def _trilinear(table, x):
+ n = table.shape[0]
+ flat = table.reshape(-1, 3)
+ i = np.clip(np.floor(x).astype(np.int32), 0, n - 2)
+ f = x - i
+ fr, fg, fb = f[..., 0:1], f[..., 1:2], f[..., 2:3]
+ base = (i[..., 2] * n + i[..., 1]) * n + i[..., 0]
+ def at(db, dg, dr):
+ return flat[base + (db * n + dg) * n + dr]
+ c00 = at(0, 0, 0) + (at(0, 0, 1) - at(0, 0, 0)) * fr
+ c01 = at(0, 1, 0) + (at(0, 1, 1) - at(0, 1, 0)) * fr
+ c10 = at(1, 0, 0) + (at(1, 0, 1) - at(1, 0, 0)) * fr
+ c11 = at(1, 1, 0) + (at(1, 1, 1) - at(1, 1, 0)) * fr
+ c0 = c00 + (c01 - c00) * fg
+ c1 = c10 + (c11 - c10) * fg
+ return c0 + (c1 - c0) * fb
+
+
[email protected]_cache(maxsize=8)
+def load(path, space=None):
+ return Lut(path, space)
+
+
+def find(film):
+ """The LUT for a film key: luts/<film>.cube or luts/<film>.<space>.cube,
+ else the one the film names in films.py (its "lut") if it is there."""
+ if not LUT_DIR.is_dir():
+ return None
+ hits = sorted(p for p in LUT_DIR.glob(f"{film}*.cube")
+ if p.name.split(".")[0].lower() == film.lower())
+ if hits:
+ return hits[0]
+ from films import FILMS
+ named = FILMS.get(film, {}).get("lut")
+ return LUT_DIR / named if named and (LUT_DIR / named).is_file() else None
+
+
+# ---------------------------------------------------------------- command line
+
+def main():
+ ap = argparse.ArgumentParser(description="Film LUTs: inspect .cube files.")
+ sub = ap.add_subparsers(dest="cmd", required=True)
+ i = sub.add_parser("info", help="what is in a .cube file")
+ i.add_argument("cube")
+ i.add_argument("--lut-space", choices=SPACES)
+ a = ap.parse_args()
+ if a.cmd == "info":
+ print(Lut(a.cube, a.lut_space).describe())
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ml-dev/films/luts/README.md b/ml-dev/films/luts/README.md
new file mode 100644
index 0000000..b12d4f6
--- /dev/null
+++ b/ml-dev/films/luts/README.md
@@ -0,0 +1,12 @@
+# LUTs
+
+วางไฟล์ `.cube` ไว้ที่นี่ แล้วตั้งชื่อตามฟิล์มใน `films.py` ตามด้วยสิ่งที่ LUT ต้องการเป็นอินพุต:
+
+ portra400.logc3.cube ใช้กับทุกม้วนที่เป็น Portra 400 อัตโนมัติ, อินพุต ARRI LogC3
+ cinestill800t.cineon.cube อินพุต Cineon log
+ hp5.srgb.cube อินพุตภาพปกติ (LUT ที่ทำจาก Lightroom / Photoshop)
+
+อินพุตที่รองรับ: `logc3`, `cineon`, `rec709`, `srgb`, `linear` (รายละเอียดใน `../lut.py`)
+ถ้าไม่ระบุในชื่อไฟล์ จะถือว่าเป็น `srgb`
+
+ไฟล์ `.cube` ไม่ถูกเก็บใน git (LUT ส่วนใหญ่มีลิขสิทธิ์)
diff --git a/ml-dev/films/sample/SAMPLE.CR2 b/ml-dev/films/sample/SAMPLE.CR2
new file mode 100644
index 0000000..f0e2ae8
Binary files /dev/null and b/ml-dev/films/sample/SAMPLE.CR2 differ
diff --git a/ml-dev/fork/apply_fork.py b/ml-dev/fork/apply_fork.py
new file mode 100644
index 0000000..89c8971
--- /dev/null
+++ b/ml-dev/fork/apply_fork.py
@@ -0,0 +1,134 @@
+"""Apply the film-mode fork changes to a magiclantern_simplified checkout.
+
+ python3 apply_fork.py ~/ml/magiclantern_simplified [PLATFORM ...]
+
+PLATFORM is a folder under platform/ (EOSM.202, 100D.101, 650D.104, 700D.115 ...);
+the default is EOSM.202. The source changes are shared, the platform ones are per camera.
+
+Idempotent: running it twice changes nothing. src/filmroll.c and .h, and
+the film OS sources (ml-dev/filmos/fos*.c, .h), are copied separately by
+build_fork.sh.
+"""
+
+import re
+import sys
+from pathlib import Path
+
+root = Path(sys.argv[1])
+PLATFORMS = sys.argv[2:] or ["EOSM.202"]
+
+
+def edit(rel, old, new, marker):
+ p = root / rel
+ text = p.read_text()
+ if marker in text:
+ print(f" {rel}: already applied")
+ return
+ if old not in text:
+ sys.exit(f" {rel}: anchor not found, ML source changed?")
+ p.write_text(text.replace(old, new, 1))
+ print(f" {rel}: patched")
+
+
+# key hook, ahead of modules so the picker owns the buttons while it is up
+edit("src/gui-common.c",
+ " if (handle_module_keys(event) == 0) return 0;\n",
+ "#ifdef FEATURE_FILMROLL\n"
+ " if (handle_filmroll_keys(event) == 0) return 0;\n"
+ "#endif\n"
+ " if (handle_module_keys(event) == 0) return 0;\n",
+ "handle_filmroll_keys")
+edit("src/gui-common.c",
+ "#include <zebra.h>\n",
+ "#include <zebra.h>\n#include <filmroll.h>\n",
+ "#include <filmroll.h>")
+
+# ML's LiveView overlays step aside while the picker or the HUD is up
+edit("src/zebra.c",
+ "int get_global_draw() // menu setting, or off if \n{\n",
+ "int get_global_draw() // menu setting, or off if \n{\n"
+ "#ifdef FEATURE_FILMROLL\n"
+ " if (filmroll_overlays_active()) return 0;\n"
+ "#endif\n",
+ "filmroll_overlays_active")
+edit("src/zebra.c",
+ '#include "zebra.h"\n',
+ '#include "zebra.h"\n#include "filmroll.h"\n',
+ '#include "filmroll.h"')
+
+# the Magic Lantern menu never opens: whatever asks for it (buttons,
+# modules, scripts) gets the film OS home instead
+edit("src/menu.c",
+ "static void menu_open() \n{ \n if (menu_shown)\n return;\n",
+ "static void menu_open() \n{ \n#ifdef FEATURE_FILMROLL\n"
+ " filmroll_menu_requested();\n"
+ " return;\n"
+ "#endif\n"
+ " if (menu_shown)\n return;\n",
+ "filmroll_menu_requested")
+edit("src/menu.c",
+ '#include "powersave.h"\n',
+ '#include "powersave.h"\n#include "filmroll.h"\n',
+ '#include "filmroll.h"')
+
+# lua doesn't build with this toolchain (newlib header clash) and isn't needed
+edit("modules/Makefile",
+ " img_name \\\n lua \\\n",
+ " img_name \\\n",
+ "lua dropped by film-mode fork")
+p = root / "modules/Makefile"
+if "lua dropped by film-mode fork" not in p.read_text():
+ p.write_text(p.read_text().replace(
+ "ML_MODULES = \\\n", "# lua dropped by film-mode fork (newlib header clash with gcc 14)\nML_MODULES = \\\n", 1))
+
+def platform(name):
+ """FEATURE_FILMROLL, our objects, and no lua, for one camera."""
+ # build it in
+ p = root / f"platform/{name}/features.h"
+ if "FEATURE_FILMROLL" not in p.read_text():
+ p.write_text(p.read_text().rstrip("\n") + "\n\n/* film camera mode (src/filmroll.c) */\n#define FEATURE_FILMROLL\n")
+ print(f" platform/{name}/features.h: patched")
+ else:
+ print(f" platform/{name}/features.h: already applied")
+ # our objects. Rewritten every time (older versions of this fork
+ # listed only filmroll.o), so the list always matches the sources.
+ # (no fos_font: the fonts go on the card as ML/DATA/FOSFONT.BIN, see fos_gfx.h)
+ FOS_OBJS = ["filmroll", "fos_gfx", "fos_film", "fos_ui", "fos_shelf", "fos_pages", "fos_hud",
+ "fos_dark", "fos_dev", "fos_lab", "fos_looks", "fos_jpeg"]
+ p = root / f"platform/{name}/Makefile"
+ lines = p.read_text().split("\n")
+ out, skip = [], False
+ for line in lines:
+ if skip:
+ skip = line.rstrip().endswith("\\")
+ continue
+ if line.startswith("ML_SRC_EXTRA_OBJS +=") and ("filmroll" in line or "fos_" in line):
+ skip = line.rstrip().endswith("\\")
+ continue
+ out.append(line)
+ text = "\n".join(out)
+ block = "ML_SRC_EXTRA_OBJS += " + " ".join(f"$(BUILD_DIR)/{o}.o" for o in FOS_OBJS) + "\n"
+ m = re.search(r"^include[ \t]+\.\./Makefile[ \t]*\n", text, re.M)
+ anchor = m.group(0) if m else None
+ if anchor is None:
+ sys.exit(f" platform/{name}/Makefile: anchor not found, ML source changed?")
+ text = text.replace("\n\n" + anchor, "\n" + anchor).replace(anchor, block + "\n" + anchor, 1)
+ if p.read_text() != text:
+ p.write_text(text)
+ print(f" platform/{name}/Makefile: patched")
+ else:
+ print(f" platform/{name}/Makefile: already applied")
+
+ p = root / f"platform/{name}/modules.included"
+ mods = p.read_text().splitlines()
+ if "lua" in mods:
+ p.write_text("\n".join(m for m in mods if m != "lua") + "\n")
+ print(f" {name}/modules.included: lua removed")
+ else:
+ print(f" {name}/modules.included: already applied")
+
+
+for name in PLATFORMS:
+ if not (root / "platform" / name).is_dir():
+ sys.exit(f" platform/{name}: no such camera in this Magic Lantern")
+ platform(name)
diff --git a/ml-dev/fork/film-mode.patch b/ml-dev/fork/film-mode.patch
new file mode 100644
index 0000000..0fb357e
--- /dev/null
+++ b/ml-dev/fork/film-mode.patch
@@ -0,0 +1,16470 @@
+diff --git a/platform/100D.101/Makefile b/platform/100D.101/Makefile
+index 05832de0d..4ca45d79b 100644
+--- a/platform/100D.101/Makefile
++++ b/platform/100D.101/Makefile
+@@ -15,6 +15,7 @@ PLATFORM_ARCH = armv5te
+ RESTARTSTART = 0x44C100
+ ML_BOOT_OBJ = boot-d45-am.o
+ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/reloc.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/100D.101/features.h b/platform/100D.101/features.h
+index 18fa340fe..0a9fb2e00 100644
+--- a/platform/100D.101/features.h
++++ b/platform/100D.101/features.h
+@@ -12,3 +12,6 @@
+ /* Not working */
+ #undef FEATURE_TRAP_FOCUS
+ #undef FEATURE_MAGIC_ZOOM_FULL_SCREEN // https://bitbucket.org/hudson/magic-lantern/issues/2842
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/100D.101/modules.included b/platform/100D.101/modules.included
+index 8428d3c4b..a3be71e80 100644
+--- a/platform/100D.101/modules.included
++++ b/platform/100D.101/modules.included
+@@ -10,7 +10,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/1100D.105/Makefile b/platform/1100D.105/Makefile
+index 474a5bd7b..08d281014 100644
+--- a/platform/1100D.105/Makefile
++++ b/platform/1100D.105/Makefile
+@@ -21,6 +21,7 @@ RESTARTSTART = 0xC80100
+ ML_BOOT_OBJ = boot-d45-am.o
+
+ FIRMWARE_ID_1100D = 0x80000288
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/1100D.105/features.h b/platform/1100D.105/features.h
+index 81cc3db68..21ccd11c0 100644
+--- a/platform/1100D.105/features.h
++++ b/platform/1100D.105/features.h
+@@ -32,3 +32,6 @@
+ #undef FEATURE_FLEXINFO
+ #undef FEATURE_SHOW_FREE_MEMORY
+ #undef CONFIG_TSKMON
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/1100D.105/modules.included b/platform/1100D.105/modules.included
+index 70260051d..eb4ce352c 100644
+--- a/platform/1100D.105/modules.included
++++ b/platform/1100D.105/modules.included
+@@ -8,7 +8,6 @@ dual_iso
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_play
+ mlv_snd
+ pic_view
+diff --git a/platform/500D.111/Makefile b/platform/500D.111/Makefile
+index cfd4478d6..2a74c6055 100644
+--- a/platform/500D.111/Makefile
++++ b/platform/500D.111/Makefile
+@@ -17,6 +17,7 @@ PLATFORM_ARCH = armv5te
+ RESTARTSTART = 0x4D000
+
+ ML_PICSTYLE_AUTO = n
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/500D.111/features.h b/platform/500D.111/features.h
+index e1f7c07c8..ba9306a96 100644
+--- a/platform/500D.111/features.h
++++ b/platform/500D.111/features.h
+@@ -16,3 +16,6 @@
+ #undef FEATURE_MOVIE_RESTART /* https://bitbucket.org/hudson/magic-lantern/issue/1008/500d-movie-restart-function-is-not-working */
+
+ #define FEATURE_REC_NOTIFY_BEEP
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/500D.111/modules.included b/platform/500D.111/modules.included
+index edc1dfbba..b8ec816ba 100644
+--- a/platform/500D.111/modules.included
++++ b/platform/500D.111/modules.included
+@@ -9,7 +9,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/50D.109/Makefile b/platform/50D.109/Makefile
+index d94cf18cd..ef4b2a9a4 100644
+--- a/platform/50D.109/Makefile
++++ b/platform/50D.109/Makefile
+@@ -24,6 +24,7 @@ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/misc.o $(BUILD_DIR)/afma.o
+ # video_hacks.o
+ # reloc.o \
+ # af_patterns.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/50D.109/features.h b/platform/50D.109/features.h
+index 0ee71ea71..c2484e477 100644
+--- a/platform/50D.109/features.h
++++ b/platform/50D.109/features.h
+@@ -21,3 +21,5 @@
+
+ #undef FEATURE_UPSIDE_DOWN // not working, http://www.magiclantern.fm/forum/index.php?topic=4430
+
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/50D.109/modules.included b/platform/50D.109/modules.included
+index 9412f9301..6c9da4f53 100644
+--- a/platform/50D.109/modules.included
++++ b/platform/50D.109/modules.included
+@@ -10,7 +10,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ pic_view
+diff --git a/platform/550D.109/Makefile b/platform/550D.109/Makefile
+index d7b8d6f03..6658f9d0e 100644
+--- a/platform/550D.109/Makefile
++++ b/platform/550D.109/Makefile
+@@ -22,6 +22,7 @@ ML_BOOT_OBJ = boot-d45-am.o
+ ML_PICSTYLE_AUTO = n
+
+ CONFIG_LVAPP_HACK_RELOC = y
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/550D.109/features.h b/platform/550D.109/features.h
+index fd2485377..104598425 100644
+--- a/platform/550D.109/features.h
++++ b/platform/550D.109/features.h
+@@ -12,3 +12,6 @@
+ #undef FEATURE_LV_BUTTON_RATE_UPDOWN // Canon uses up/down in play mode
+
+ #undef FEATURE_BULB_TIMER_SHOW_PREVIOUS_PIC // screen remains black
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/550D.109/modules.included b/platform/550D.109/modules.included
+index edc1dfbba..b8ec816ba 100644
+--- a/platform/550D.109/modules.included
++++ b/platform/550D.109/modules.included
+@@ -9,7 +9,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/5D2.212/Makefile b/platform/5D2.212/Makefile
+index c70b6b12b..07da09631 100644
+--- a/platform/5D2.212/Makefile
++++ b/platform/5D2.212/Makefile
+@@ -20,6 +20,7 @@ RESTARTSTART = 0x4E000
+ ML_PICSTYLE_AUTO = n
+
+ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/afma.o $(BUILD_DIR)/asm.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/5D2.212/features.h b/platform/5D2.212/features.h
+index 51957a6ab..d6d5139d4 100644
+--- a/platform/5D2.212/features.h
++++ b/platform/5D2.212/features.h
+@@ -7,3 +7,6 @@
+
+
+ #define FEATURE_LV_FOCUS_BOX_SNAP_TO_X5_RAW
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/5D2.212/modules.included b/platform/5D2.212/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/5D2.212/modules.included
++++ b/platform/5D2.212/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/5D3.113/Makefile b/platform/5D3.113/Makefile
+index ee6ae21d4..35dea4aea 100644
+--- a/platform/5D3.113/Makefile
++++ b/platform/5D3.113/Makefile
+@@ -19,6 +19,7 @@ ML_BITRATE_OBJ = bitrate-5d3.o
+ ML_AF_PATTERNS_OBJ = n
+
+ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/video_hacks.o $(BUILD_DIR)/afma.o $(BUILD_DIR)/asm.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/5D3.113/features.h b/platform/5D3.113/features.h
+index 7f59c54dd..226f49cbf 100644
+--- a/platform/5D3.113/features.h
++++ b/platform/5D3.113/features.h
+@@ -27,3 +27,6 @@
+ #define FEATURE_UNMOUNT_SD_CARD
+
+ //~ #define FEATURE_JUNKIE_MENU
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/5D3.113/modules.included b/platform/5D3.113/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/5D3.113/modules.included
++++ b/platform/5D3.113/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/5D3.123/Makefile b/platform/5D3.123/Makefile
+index dd4efea17..9d092fb21 100644
+--- a/platform/5D3.123/Makefile
++++ b/platform/5D3.123/Makefile
+@@ -21,6 +21,7 @@ ML_BITRATE_OBJ = bitrate-5d3.o
+ ML_AF_PATTERNS_OBJ = n
+
+ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/video_hacks.o $(BUILD_DIR)/afma.o $(BUILD_DIR)/asm.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/5D3.123/features.h b/platform/5D3.123/features.h
+index ed5e98f32..fdc799fd8 100644
+--- a/platform/5D3.123/features.h
++++ b/platform/5D3.123/features.h
+@@ -64,3 +64,6 @@
+
+ /* Swap UV works (anybody using it?), extreme chroma doesn't */
+ #undef FEATURE_LV_CRAZY_COLORS
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/5D3.123/modules.included b/platform/5D3.123/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/5D3.123/modules.included
++++ b/platform/5D3.123/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/600D.102/Makefile b/platform/600D.102/Makefile
+index 1cd54b6a0..21596556b 100644
+--- a/platform/600D.102/Makefile
++++ b/platform/600D.102/Makefile
+@@ -19,6 +19,7 @@ ML_BOOT_OBJ = boot-d45-ch.o
+ ML_AUDIO_OBJ = audio-lapis.o
+
+ CONFIG_LVAPP_HACK_RELOC = y
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/600D.102/features.h b/platform/600D.102/features.h
+index 7e3229a7b..ec518efec 100644
+--- a/platform/600D.102/features.h
++++ b/platform/600D.102/features.h
+@@ -17,3 +17,6 @@
+ #undef FEATURE_SHOW_EDMAC_INFO
+
+ #undef CONFIG_TSKMON
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/600D.102/modules.included b/platform/600D.102/modules.included
+index edc1dfbba..b8ec816ba 100644
+--- a/platform/600D.102/modules.included
++++ b/platform/600D.102/modules.included
+@@ -9,7 +9,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/60D.111/Makefile b/platform/60D.111/Makefile
+index aea8e0b83..29408bd01 100644
+--- a/platform/60D.111/Makefile
++++ b/platform/60D.111/Makefile
+@@ -24,6 +24,7 @@ ML_BOOT_OBJ = boot-d45-ch.o
+ ML_PICSTYLE_AUTO = n
+
+ CONFIG_LVAPP_HACK_RELOC = y
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/60D.111/features.h b/platform/60D.111/features.h
+index b2c8b03e8..ae383506f 100644
+--- a/platform/60D.111/features.h
++++ b/platform/60D.111/features.h
+@@ -10,3 +10,6 @@
+ #undef FLEXINFO_DEVELOPER_MENU
+
+ #undef FEATURE_WIND_FILTER // problems with external mic
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/60D.111/modules.included b/platform/60D.111/modules.included
+index edc1dfbba..b8ec816ba 100644
+--- a/platform/60D.111/modules.included
++++ b/platform/60D.111/modules.included
+@@ -9,7 +9,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/650D.104/Makefile b/platform/650D.104/Makefile
+index 9e9650596..4d3b26d96 100644
+--- a/platform/650D.104/Makefile
++++ b/platform/650D.104/Makefile
+@@ -14,6 +14,7 @@ PLATFORM_ARCH = armv5te
+ # RESTARTSTART is selected to be just above the end of the bss
+ #
+ RESTARTSTART = 0x7E100
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/650D.104/features.h b/platform/650D.104/features.h
+index 0c94cb713..cbe511db9 100644
+--- a/platform/650D.104/features.h
++++ b/platform/650D.104/features.h
+@@ -29,3 +29,6 @@
+ #define FEATURE_FOCUS_PEAK_DISP_FILTER
+
+ #define FEATURE_CROP_MODE_HACK
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/650D.104/modules.included b/platform/650D.104/modules.included
+index 8428d3c4b..a3be71e80 100644
+--- a/platform/650D.104/modules.included
++++ b/platform/650D.104/modules.included
+@@ -10,7 +10,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/6D.116/Makefile b/platform/6D.116/Makefile
+index 8ba969fae..c8569b9ba 100644
+--- a/platform/6D.116/Makefile
++++ b/platform/6D.116/Makefile
+@@ -19,6 +19,7 @@ ML_BITRATE_OBJ = bitrate-5d3.o
+ ML_SOUND_CODEC_OBJ = ak4646.o
+
+ ML_SRC_EXTRA_OBJS = $(BUILD_DIR)/afma.o $(BUILD_DIR)/reloc.o $(BUILD_DIR)/gps.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/6D.116/features.h b/platform/6D.116/features.h
+index c9d1fb870..415989d7d 100644
+--- a/platform/6D.116/features.h
++++ b/platform/6D.116/features.h
+@@ -21,3 +21,6 @@
+ #define FEATURE_GPS_TWEAKS
+
+ #define FEATURE_AUDIO_REMOTE_SHOT
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/6D.116/modules.included b/platform/6D.116/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/6D.116/modules.included
++++ b/platform/6D.116/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/700D.115/Makefile b/platform/700D.115/Makefile
+index af9eb604f..e48f7bddd 100644
+--- a/platform/700D.115/Makefile
++++ b/platform/700D.115/Makefile
+@@ -15,6 +15,7 @@ PLATFORM_ARCH = armv5te
+ #
+ MAIN_FIRMWARE_ADDR = 0xFF0C0000
+ RESTARTSTART = 0x7EC00
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/700D.115/features.h b/platform/700D.115/features.h
+index 42be326e4..9eee68b47 100644
+--- a/platform/700D.115/features.h
++++ b/platform/700D.115/features.h
+@@ -23,3 +23,6 @@
+ #define FEATURE_FOCUS_PEAK_DISP_FILTER
+ #define FEATURE_CROP_MODE_HACK
+ #define FEATURE_EYEFI_TRICKS
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/700D.115/modules.included b/platform/700D.115/modules.included
+index 8428d3c4b..a3be71e80 100644
+--- a/platform/700D.115/modules.included
++++ b/platform/700D.115/modules.included
+@@ -10,7 +10,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/70D.112/Makefile b/platform/70D.112/Makefile
+index 508e2c952..b0de6158c 100644
+--- a/platform/70D.112/Makefile
++++ b/platform/70D.112/Makefile
+@@ -20,6 +20,7 @@ ML_BITRATE_OBJ = bitrate-5d3.o
+ # default 0x44C000 - 0xD3C000, patched to 0x4E0000 - 0xD3C000 (592K for us).
+ RESTARTSTART = 0x44C100
+ ML_BOOT_OBJ = boot-d45-am.o
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/70D.112/features.h b/platform/70D.112/features.h
+index 5095eea7d..7db47a65b 100644
+--- a/platform/70D.112/features.h
++++ b/platform/70D.112/features.h
+@@ -33,3 +33,6 @@
+ /* Audio Features */
+ #define FEATURE_AUDIO_METERS
+ #define FEATURE_AUDIO_REMOTE_SHOT
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/70D.112/modules.included b/platform/70D.112/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/70D.112/modules.included
++++ b/platform/70D.112/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/7D.203/Makefile b/platform/7D.203/Makefile
+index 01a525ba4..eb4f9e8e0 100644
+--- a/platform/7D.203/Makefile
++++ b/platform/7D.203/Makefile
+@@ -1,6 +1,7 @@
+ #Makefile for 7D
+
+ MODEL=7D
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
+
+ include ../Makefile
+
+diff --git a/platform/7D.203/features.h b/platform/7D.203/features.h
+index 2b37c0834..01b8ecc0b 100644
+--- a/platform/7D.203/features.h
++++ b/platform/7D.203/features.h
+@@ -19,3 +19,6 @@
+ #define FEATURE_AUDIO_REMOTE_SHOT
+
+ #undef FEATURE_VIGNETTING_CORRECTION // requires master code
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/7D.203/modules.included b/platform/7D.203/modules.included
+index eddc7617e..6bfdee970 100644
+--- a/platform/7D.203/modules.included
++++ b/platform/7D.203/modules.included
+@@ -11,7 +11,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/platform/EOSM.202/Makefile b/platform/EOSM.202/Makefile
+index 7e11d12a2..f463352ee 100644
+--- a/platform/EOSM.202/Makefile
++++ b/platform/EOSM.202/Makefile
+@@ -19,5 +19,7 @@ RESTARTSTART = 0x9E1E0
+
+ ML_AF_PATTERNS_OBJ = n
+
++ML_SRC_EXTRA_OBJS += $(BUILD_DIR)/filmroll.o $(BUILD_DIR)/fos_gfx.o $(BUILD_DIR)/fos_film.o $(BUILD_DIR)/fos_ui.o $(BUILD_DIR)/fos_shelf.o $(BUILD_DIR)/fos_pages.o $(BUILD_DIR)/fos_hud.o $(BUILD_DIR)/fos_dark.o $(BUILD_DIR)/fos_dev.o $(BUILD_DIR)/fos_lab.o $(BUILD_DIR)/fos_looks.o $(BUILD_DIR)/fos_jpeg.o
++
+ include ../Makefile
+ .DEFAULT_GOAL := $(BUILD_DIR)/cam_complete
+diff --git a/platform/EOSM.202/features.h b/platform/EOSM.202/features.h
+index dfead95de..3fe30a780 100644
+--- a/platform/EOSM.202/features.h
++++ b/platform/EOSM.202/features.h
+@@ -37,3 +37,6 @@
+ #undef FEATURE_MAGIC_ZOOM_FULL_SCREEN // https://bitbucket.org/hudson/magic-lantern/issue/2272/full-screen-magic-zoom-is-garbled-on-700d
+
+ #define FEATURE_EYEFI_TRICKS
++
++/* film camera mode (src/filmroll.c) */
++#define FEATURE_FILMROLL
+diff --git a/platform/EOSM.202/modules.included b/platform/EOSM.202/modules.included
+index 8428d3c4b..a3be71e80 100644
+--- a/platform/EOSM.202/modules.included
++++ b/platform/EOSM.202/modules.included
+@@ -10,7 +10,6 @@ edmac
+ ettr
+ file_man
+ img_name
+-lua
+ mlv_lite
+ mlv_play
+ mlv_snd
+diff --git a/src/filmroll.c b/src/filmroll.c
+new file mode 100644
+index 000000000..50b8ffb83
+--- /dev/null
++++ b/src/filmroll.c
+@@ -0,0 +1,1387 @@
++/* filmroll: a Canon camera as a film camera (built into this ML fork).
++ * Made on the EOS M; 100D, 650D, 700D and others build from the same code.
++ *
++ * The camera side of the film OS (ml-dev/filmos): rolls, the roll log the
++ * PC lab reads, film settings, the viewfinder HUD, and the fos_port_*
++ * functions through which the film OS takes the screen and the buttons.
++ *
++ * - the film OS is the camera's own interface: the film shelf at start
++ * up, home and its settings pages instead of the Magic Lantern menu.
++ * The ML menu is gone: what used to open it (two-finger tap, long
++ * press on DOWN, modules) opens home.
++ * - an SLR-viewfinder HUD in LiveView: aperture scale with meter needle,
++ * red LED readout that lights on half-shutter, frame counter, wind
++ * - PLAY opens the prints the camera has developed, never Canon's
++ * playback of undeveloped frames
++ * - a finished roll is developed in the camera (fos_dev.c): its RAWs
++ * become prints in ML/DARKROOM, shown on their own palettes
++ * - manual lenses: the f-stop is dialled in and logged for the lab
++ *
++ * Loading a roll sets picture style, contrast / saturation / colour tone,
++ * white balance and ISO for that stock, and starts a roll log next to the
++ * images (DCIM/xxxCANON/ROLL_nnn.TXT) that the PC film lab reads
++ * (the desktop darkroom, Darkrooms). Film keys must match films/films.py.
++ *
++ * Shots are detected by watching the file number, so every frame is
++ * logged even in burst mode.
++ */
++
++#include <dryos.h>
++#include <module.h>
++#include <property.h>
++#include <menu.h>
++#include <config.h>
++#include <lens.h>
++#include <picstyle.h>
++#include <beep.h>
++#include <bmp.h>
++#include <fio-ml.h>
++#include <fileprefix.h>
++#include <notify_box.h>
++#include <zebra.h>
++#include <propvalues.h>
++#include <gui-common.h>
++#include <tasks.h>
++#include <mem.h>
++#include <powersave.h>
++#include "filmroll.h"
++#include "fos.h"
++#include "fos_dev.h"
++
++#include <stdarg.h>
++
++extern int ml_started;
++extern void CancelDateTimer();
++
++/* user settings */
++static CONFIG_INT("filmroll.film", film_sel, 0);
++static CONFIG_INT("filmroll.exp", exp_sel, 0);
++static CONFIG_INT("filmroll.hud", hud_enabled, 1);
++static CONFIG_INT("filmroll.focus", focus_screen, 1);
++static CONFIG_INT("filmroll.leds", leds_on_half, 1);
++static CONFIG_INT("filmroll.wind", wind_mode, 1); /* 0 off, 1 reminder, 2 block shutter */
++static CONFIG_INT("filmroll.playlock", play_lock, 1);
++static CONFIG_INT("filmroll.startup", startup_picker, 2); /* 0 off, 1 when no film, 2 always */
++static CONFIG_INT("filmroll.bootanim", boot_anim, 1);
++static CONFIG_INT("filmroll.debug", debug_log, 1);
++static CONFIG_INT("filmroll.lens_wide", lens_widest, 6); /* index into fos_fstops: f/1.8 */
++static CONFIG_INT("filmroll.fstop", manual_fstop, 6);
++static CONFIG_INT("filmroll.ap_keys", aperture_keys, 0); /* 0 wheel in Av, 1 up/down, 2 menu only */
++static CONFIG_INT("filmroll.scr_std", scr_std, 0); /* screen colour: 0 Canon, 1 Rec.709 */
++static CONFIG_INT("filmroll.scr_sat", scr_sat, 0); /* -6..6 */
++static CONFIG_INT("filmroll.scr_warm", scr_warm, 0);
++static CONFIG_INT("filmroll.scr_bright", scr_bright, 0);
++
++/* roll state, kept across power cycles */
++static CONFIG_INT("filmroll.loaded", roll_loaded, 0);
++static CONFIG_INT("filmroll.roll", roll_number, 0);
++static CONFIG_INT("filmroll.roll_film", roll_film, 0);
++static CONFIG_INT("filmroll.roll_exp", roll_exposures, 36);
++static CONFIG_INT("filmroll.shot", frames_shot, 0);
++static CONFIG_INT("filmroll.lastfile", last_file_number, -1);
++static CONFIG_INT("filmroll.logdir", roll_folder, 0);
++static CONFIG_INT("filmroll.needwind", need_wind, 0);
++
++static char log_path[64];
++
++static volatile int leds_until = 0; /* keep LEDs lit until this ms clock */
++static volatile int hud_dirty = 1;
++
++#define ROLL_FINISHED (roll_loaded && frames_shot >= roll_exposures)
++#define ROLL_IN_PROGRESS (roll_loaded && frames_shot < roll_exposures)
++
++static volatile int end_due = 0; /* the roll was just finished: ms when to ask about it */
++static volatile int dev_busy = 0; /* developing: keep the camera awake */
++
++/* the last frames, for the roll page (also read back from the log) */
++static struct { int no; char time[6]; char fstop[6]; } recent[FOS_RECENT];
++static int nrecent = 0;
++static char loaded_at[20];
++static int recent_valid = 0;
++
++/* ---------------------------------------------------------------- debug log */
++
++/* field-test trace in ML/FILMROLL.LOG; turn off in System once things work */
++static void dbg(const char *fmt, ...)
++{
++ if (!debug_log)
++ return;
++
++ char buf[192];
++ int n = snprintf(buf, sizeof(buf), "%7d ", get_ms_clock());
++ va_list ap;
++ va_start(ap, fmt);
++ vsnprintf(buf + n, sizeof(buf) - n, fmt, ap);
++ va_end(ap);
++
++ FILE *f = FIO_CreateFileOrAppend("ML/FILMROLL.LOG");
++ if (!f)
++ return;
++ my_fprintf(f, "%s\n", buf);
++ FIO_CloseFile(f);
++}
++
++/* The camera waiting for a picture, the screen the film OS opens from.
++ * On the EOS M that is LiveView; a DSLR (100D, 650D, 700D ...) is mostly
++ * shot through its optical viewfinder, so there it is also Canon's shooting
++ * screen with LiveView off. */
++#ifdef CONFIG_EOSM
++#define FOS_LV_ONLY 1
++#else
++#define FOS_LV_ONLY 0
++#endif
++static int shooting_screen()
++{
++ return (lv || !FOS_LV_ONLY) && display_idle() && !is_movie_mode();
++}
++
++#define DBG_STATE(what) dbg("%s: ml=%d lv=%d idle=%d movie=%d mode=%d gui=%d", what, \
++ ml_started, lv, display_idle(), is_movie_mode(), shooting_mode, CURRENT_GUI_MODE)
++
++/* ---------------------------------------------------------------- log file */
++
++static void update_log_path()
++{
++ snprintf(log_path, sizeof(log_path), "%s:/DCIM/%03d%s/ROLL_%03d.TXT",
++ get_shooting_card()->drive_letter, roll_folder, get_dcim_dir_suffix(),
++ roll_number);
++}
++
++static void log_append(const char *text)
++{
++ FILE *f = FIO_CreateFileOrAppend(log_path);
++ if (!f)
++ {
++ NotifyBox(3000, "filmroll: can't write %s", log_path);
++ return;
++ }
++ my_fprintf(f, "%s", text);
++ FIO_CloseFile(f);
++}
++
++static void format_now(char *buf, int size)
++{
++ struct tm now;
++ LoadCalendarFromRTC(&now);
++ snprintf(buf, size, "%04d-%02d-%02d %02d:%02d:%02d",
++ now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
++ now.tm_hour, now.tm_min, now.tm_sec);
++}
++
++static void write_header(const char *note)
++{
++ char when[32];
++ char header[320];
++ format_now(when, sizeof(when));
++ snprintf(header, sizeof(header),
++ "# ML film mode roll log (filmroll module)%s\n"
++ "roll = %03d\nfilm = %s\nexposures = %d\nloaded = %s\n\n",
++ note, roll_number, fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].key, roll_exposures, when);
++ log_append(header);
++}
++
++/* the roll page wants the loading time and the last frames: after a power
++ * cycle they only exist in the log, so read them back once */
++static void read_back_log()
++{
++ recent_valid = 1;
++ nrecent = 0;
++ loaded_at[0] = 0;
++ int size = 0;
++ char *buf = (char *) read_entire_file(log_path, &size);
++ if (!buf)
++ return;
++ for (char *line = buf; line && *line; )
++ {
++ char *next = strchr(line, '\n');
++ if (next) *next++ = 0;
++ if (!strncmp(line, "loaded = ", 9))
++ fos_copy(loaded_at, sizeof(loaded_at), line + 9, 16);
++ else if (line[0] >= '0' && line[0] <= '9')
++ {
++ /* "12 IMG_0012.CR2 2026-08-08 09:15:15 f/2.8" */
++ char *tok[5];
++ int n = 0;
++ for (char *p = line; *p && n < 5; )
++ {
++ while (*p == ' ') p++;
++ if (!*p) break;
++ tok[n++] = p;
++ while (*p && *p != ' ') p++;
++ if (*p) *p++ = 0;
++ }
++ if (n >= 4)
++ {
++ /* newest first, keep FOS_RECENT */
++ for (int i = MIN(nrecent, FOS_RECENT - 1); i > 0; i--)
++ recent[i] = recent[i - 1];
++ recent[0].no = atoi(tok[0]);
++ fos_copy(recent[0].time, sizeof(recent[0].time), tok[3], 5);
++ snprintf(recent[0].fstop, sizeof(recent[0].fstop), "%s",
++ n >= 5 && !strncmp(tok[4], "f/", 2) ? tok[4] + 2 : "?");
++ nrecent = MIN(nrecent + 1, FOS_RECENT);
++ }
++ }
++ line = next;
++ }
++ fio_free(buf);
++}
++
++/* ---------------------------------------------------------------- camera settings */
++
++static int iso_to_raw(int iso)
++{
++ int raw = 72; /* ISO 100 */
++ for (int i = 100; i < iso; i *= 2)
++ raw += 8; /* one stop */
++ return raw;
++}
++
++static void apply_film(int index)
++{
++ const struct fos_film *f = &fos_films[COERCE(index, 0, fos_nfilms - 1)];
++
++ int ps = f->picstyle;
++ prop_request_change_wait(PROP_PICTURE_STYLE, &ps, 4, 1000);
++ msleep(100);
++
++ /* these change the current picture style, so it must be selected first */
++ lens_set_contrast(f->contrast);
++ msleep(50);
++ lens_set_sharpness(f->sharpness);
++ msleep(50);
++ if (f->picstyle != PS_MONO)
++ {
++ lens_set_saturation(f->saturation);
++ msleep(50);
++ lens_set_color_tone(f->color_tone);
++ msleep(50);
++ }
++
++ lens_set_kelvin(f->kelvin);
++ lens_set_wbs_gm(f->wbs_gm);
++ lens_set_wbs_ba(f->wbs_ba);
++ lens_set_rawiso(iso_to_raw(f->iso));
++}
++
++/* Film is shot blind: the darkroom develops the RAWs, and there is no
++ * image review to peek at. ML doesn't change these Canon settings itself
++ * (writing the picture quality property can upset Canon's firmware), so
++ * it asks for them. */
++static void film_capture_check()
++{
++ if (!roll_loaded) return;
++ int raw = (pic_quality & 0xFE00FF) == (PICQ_RAW & 0xFE00FF);
++ int review_off = image_review_time == 0;
++ if (raw && review_off) return;
++ dbg("capture: quality %x, review %d", pic_quality, image_review_time);
++ NotifyBox(6000, "Film: in Canon's menu set %s%s%s", raw ? "" : "Image quality RAW",
++ !raw && !review_off ? " and " : "", review_off ? "" : "Image review Off");
++}
++
++/* ---------------------------------------------------------------- aperture */
++
++/* manual (adapted) lenses report no aperture; the user dials it in instead */
++static int lens_is_manual()
++{
++ return !lens_info.raw_aperture;
++}
++
++/* index into fos_fstops for the aperture in use */
++static int current_fstop()
++{
++ if (lens_is_manual())
++ return COERCE(manual_fstop, lens_widest, fos_nfstops - 1);
++
++ int f100 = lens_info.aperture * 10; /* lens_info.aperture is f x10 */
++ int best = 0;
++ for (int i = 1; i < fos_nfstops; i++)
++ if (ABS(fos_fstops[i] - f100) < ABS(fos_fstops[best] - f100))
++ best = i;
++ return best;
++}
++
++static void step_manual_fstop(int dir)
++{
++ manual_fstop = COERCE(current_fstop() + dir, lens_widest, fos_nfstops - 1);
++}
++
++/* ---------------------------------------------------------------- rolls */
++
++/* start a roll: state and log now, camera settings once the film OS has
++ * let go of the screen (apply_film blocks for a while) */
++static void load_roll(int film, int exposures)
++{
++ roll_film = COERCE(film, 0, fos_nfilms - 1);
++ roll_exposures = exposures;
++ roll_folder = get_shooting_card()->folder_number;
++
++ /* next roll number whose log doesn't exist yet, so a reset counter
++ * (new settings file, card from another camera) never mixes two rolls */
++ for (int tries = 0; tries < 999; tries++)
++ {
++ roll_number = roll_number % 999 + 1;
++ update_log_path();
++ if (!is_file(log_path))
++ break;
++ }
++ frames_shot = 0;
++ need_wind = 0;
++ last_file_number = get_shooting_card()->file_number;
++ roll_loaded = 1;
++ update_log_path();
++ write_header("");
++
++ char when[32];
++ format_now(when, sizeof(when));
++ fos_copy(loaded_at, sizeof(loaded_at), when, 16);
++ nrecent = 0;
++ recent_valid = 1;
++
++ hud_dirty = 1;
++ dbg("roll %03d loaded: %s, %d exp", roll_number, fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].key, roll_exposures);
++}
++
++static void rewind_roll()
++{
++ if (!roll_loaded) return;
++ char when[32], line[80];
++ format_now(when, sizeof(when));
++ snprintf(line, sizeof(line), "\n# rewound %s after %d of %d frames\n", when, frames_shot, roll_exposures);
++ log_append(line);
++ roll_loaded = 0;
++ need_wind = 0;
++ hud_dirty = 1;
++ dbg("roll %03d rewound at %d/%d", roll_number, frames_shot, roll_exposures);
++}
++
++static void record_frame(int file_number)
++{
++ if (frames_shot >= roll_exposures)
++ {
++ beep();
++ return;
++ }
++
++ frames_shot++;
++
++ char when[32];
++ char aperture[8];
++ char line[112];
++ format_now(when, sizeof(when));
++ fos_format_fstop(aperture, sizeof(aperture), current_fstop());
++ snprintf(line, sizeof(line), "%d %s%04d.CR2 %s f/%s\n",
++ frames_shot, get_file_prefix(), file_number, when, aperture);
++ log_append(line);
++
++ for (int i = MIN(nrecent, FOS_RECENT - 1); i > 0; i--)
++ recent[i] = recent[i - 1];
++ recent[0].no = frames_shot;
++ fos_copy(recent[0].time, sizeof(recent[0].time), when + 11, 5);
++ snprintf(recent[0].fstop, sizeof(recent[0].fstop), "%s", aperture);
++ nrecent = MIN(nrecent + 1, FOS_RECENT);
++
++ leds_until = get_ms_clock() + 2500;
++ hud_dirty = 1;
++
++ if (frames_shot == roll_exposures)
++ {
++ need_wind = 0;
++ beep_times(2);
++ end_due = get_ms_clock() + 1500; /* then ask: develop it now? */
++ return;
++ }
++
++ if (wind_mode)
++ need_wind = 1;
++}
++
++/* log every new file number since the last poll */
++static void poll_frames()
++{
++ if (!roll_loaded)
++ return;
++
++ int now = get_shooting_card()->file_number;
++ if (now == last_file_number)
++ return;
++
++ int prev = last_file_number;
++ last_file_number = now;
++
++ int count = now - prev;
++ if (count < 0)
++ count += 9999; /* IMG_9999 -> IMG_0001 */
++ if (prev < 0 || count > 50)
++ return; /* card swap or counter reset: just resync */
++
++ if (get_shooting_card()->folder_number != roll_folder)
++ {
++ /* Canon started a new folder; start a log there too so each folder
++ * develops on its own (frame numbers keep counting) */
++ roll_folder = get_shooting_card()->folder_number;
++ update_log_path();
++ write_header(" - continued from the previous DCIM folder");
++ }
++
++ dbg("frames: file %d -> %d, logging %d", prev, now, count);
++ for (int i = 1; i <= count; i++)
++ record_frame((prev + i - 1) % 9999 + 1);
++}
++
++/* ---------------------------------------------------------------- the film OS host */
++
++static volatile int ui_running = 0; /* the film OS owns the screen and the buttons */
++static volatile int ui_abort = 0;
++static int ui_after = 0; /* what to do once it has let go */
++static int ui_last_mode_poke = 0;
++static int ui_last_palette = 0;
++
++enum { AFTER_APPLY = 1, AFTER_CANON_MENU = 2 };
++
++/* buttons, from the GUI task to the film OS task */
++#define KEYQ 32
++static volatile int keyq[KEYQ];
++static volatile int keyq_in = 0, keyq_out = 0;
++
++static void keyq_push(int k)
++{
++ int next = (keyq_in + 1) % KEYQ;
++ if (next != keyq_out)
++ {
++ keyq[keyq_in] = k;
++ keyq_in = next;
++ }
++}
++
++/* Our palette is fos_pal (RGB); the bitmap overlay wants Y, Cb, Cr and
++ * an opacity code, which we copy from Canon's own white. One entry is
++ * remembered so we notice when other code puts Canon's palette back. */
++#define PALETTE_PROBE 200
++static uint32_t palette_probe = 0;
++
++/* a photograph on the screen: its colours in 1..photo_n, at photo_k/256 */
++static int photo_mode = 0, photo_n = 0, photo_k = 256;
++static uint8_t photo_pal[FOS_PRINT_COLOURS][3];
++
++static void palette_ours()
++{
++ if (!DISPLAY_IS_ON) return;
++ /* Canon's white tells the opacity and where white sits in luma
++ * (its own conversion puts it at 235, not 255) */
++ uint32_t white = LCD_Palette[3 * COLOR_WHITE + 2];
++ uint32_t opaque = white & 0xFF000000;
++ if ((opaque >> 24) < 2) opaque = 0x03000000;
++ int white_y = (white >> 16) & 0xFF;
++ if (white_y < 180) white_y = 235;
++ for (int i = 1; i < 255; i++)
++ {
++ uint32_t entry;
++ if (!photo_mode)
++ entry = opaque | fos_screen_yuv(i, white_y, scr_std, scr_sat, scr_warm, scr_bright);
++ else
++ {
++ const uint8_t *c = i <= photo_n ? photo_pal[i - 1] :
++ i >= FOS_FIXED_BASE && i < FOS_FIXED_BASE + FOS_FIXED_N ? fos_fixed_rgb[i - FOS_FIXED_BASE] : 0;
++ uint32_t rgb = c ? (uint32_t) (c[0] * photo_k >> 8) << 16 | (uint32_t) (c[1] * photo_k >> 8) << 8 | (uint32_t) (c[2] * photo_k >> 8) : 0;
++ entry = opaque | fos_screen_yuv_rgb(rgb, white_y, scr_std, scr_sat, scr_warm, scr_bright);
++ }
++ if (i == PALETTE_PROBE) palette_probe = entry;
++ EngDrvOut(LCD_Palette[3 * i], entry);
++ EngDrvOut(LCD_Palette[3 * i + 0x300], entry);
++ }
++}
++
++static void palette_canon()
++{
++ for (int i = 1; i < 255; i++)
++ {
++ EngDrvOut(LCD_Palette[3 * i], LCD_Palette[3 * i + 2]);
++ EngDrvOut(LCD_Palette[3 * i + 0x300], LCD_Palette[3 * i + 2]);
++ }
++}
++
++/* Take the display from Canon's GUI the same way the ML menu does:
++ * switch Canon to the ML menu GUI mode (LiveView stops drawing its
++ * overlays and stops handling keys), stop Canon from flipping its own
++ * bitmap buffer, then turn the bitmap layer back on for us. */
++static void film_ui_open()
++{
++ NotifyBoxHide();
++ if (lv) bmp_off();
++ SetGUIRequestMode(GUIMODE_ML_MENU);
++ msleep(200);
++ canon_gui_disable_front_buffer();
++ CancelDateTimer();
++ clrscr();
++ bmp_on();
++ ui_last_mode_poke = get_ms_clock();
++}
++
++static void film_ui_close()
++{
++ palette_canon();
++ if (lv) bmp_off();
++ SetGUIRequestMode(0);
++ msleep(100);
++ canon_gui_enable_front_buffer(0);
++ clrscr();
++ redraw();
++ if (lv) bmp_on();
++}
++
++/* frame times are kept while the film OS runs and logged when it closes:
++ * writing the card in the middle of an animation would stall it */
++static struct fos_stat stat_all;
++
++static void ui_task(int open)
++{
++ keyq_in = keyq_out = 0;
++ ui_abort = 0;
++ ui_after = 0;
++ film_ui_open();
++ DBG_STATE("film os: open");
++ memset(&stat_all, 0, sizeof(stat_all));
++
++ fos_ui_run(open);
++
++ film_ui_close();
++ ui_running = 0;
++ hud_dirty = 1;
++ DBG_STATE("film os: closed");
++ if (stat_all.frames)
++ {
++ struct fos_stat *s = &stat_all;
++ int n = s->frames, total = s->draw_ms + s->present_ms + s->rest_ms;
++ dbg("film os: %d frames in %d ms = %d/s; per frame %d ms draw (%d canisters) + %d present + %d rest, worst %d, open %d ms, quality %d",
++ n, total, total ? n * 1000 / total : 0, s->draw_ms / n, s->cans_ms / n, s->present_ms / n, s->rest_ms / n,
++ s->worst_ms, s->open_ms, fos_can_quality);
++ }
++
++ if (ui_after & AFTER_APPLY)
++ {
++ apply_film(roll_film);
++ beep();
++ film_capture_check();
++ }
++ if (dev_busy)
++ {
++ /* left in the middle of developing */
++ dev_busy = 0;
++ powersave_permit();
++ }
++ if (ui_after & AFTER_CANON_MENU)
++ fake_simple_button(BGMT_MENU);
++}
++
++static void open_ui(int screen)
++{
++ if (ui_running)
++ return;
++ if (!fos_fonts_ready())
++ {
++ NotifyBox(5000, "Film OS: ML/DATA/" FOS_FONT_FILE " is missing");
++ return;
++ }
++ ui_running = 1;
++ /* the same priority as ML's own menu redraw: Canon's tasks still come
++ * first, and the film OS rests between frames */
++ task_create("film_os", 0x1a, 0x4000, ui_task, (void *) screen);
++}
++
++/* ---- what the film OS asks of the camera (see fos.h) */
++
++int fos_port_ms()
++{
++ return get_ms_clock();
++}
++
++void fos_port_sleep(int ms)
++{
++ msleep(ms);
++ int now = get_ms_clock();
++
++ /* the Canon dialog under us times out unless poked (CONFIG_MENU_TIMEOUT_FIX) */
++ if (lv && now - ui_last_mode_poke > 2000)
++ {
++ SetGUIRequestMode(GUIMODE_ML_MENU);
++ ui_last_mode_poke = now;
++ }
++ /* other code (ML's powersave, clear overlays) may put Canon's palette
++ * back: check one entry every frame, rewrite all of them now and then */
++ static int last_wake = 0;
++ if (dev_busy && now - last_wake > 5000)
++ {
++ idle_wakeup_reset_counters(-10);
++ last_wake = now;
++ }
++ uint32_t probe = shamem_read(LCD_Palette[3 * PALETTE_PROBE]);
++ if ((probe && probe != palette_probe) || now - ui_last_palette > 1000)
++ {
++ palette_ours();
++ ui_last_palette = now;
++ }
++}
++
++int fos_port_key()
++{
++ if (keyq_out == keyq_in)
++ return FK_NONE;
++ int k = keyq[keyq_out];
++ keyq_out = (keyq_out + 1) % KEYQ;
++ return k;
++}
++
++int fos_port_abort()
++{
++ if (ui_abort || ml_shutdown_requested || !DISPLAY_IS_ON)
++ return 1;
++ if (get_halfshutter_pressed())
++ return 1;
++ /* a Canon dialog took over (low battery, card door...): give the mode
++ * request time to land, then let go if Canon keeps something else up */
++ static int mismatch_since = 0;
++ int now = get_ms_clock();
++ if (CURRENT_GUI_MODE == GUIMODE_ML_MENU)
++ mismatch_since = 0;
++ else if (!mismatch_since)
++ mismatch_since = now;
++ else if (now - mismatch_since > 1500)
++ {
++ dbg("film os: Canon GUI mode %d, leaving", CURRENT_GUI_MODE);
++ mismatch_since = 0;
++ return 1;
++ }
++ return 0;
++}
++
++void fos_port_present(const uint8_t *rows, int pitch, int y0, int y1)
++{
++ uint8_t *vram = bmp_vram_real();
++ if (!vram || !DISPLAY_IS_ON)
++ return;
++ y0 = COERCE(y0, 0, FOS_H);
++ y1 = COERCE(y1, y0, FOS_H);
++ for (int y = y0; y < y1; y++)
++ memcpy(vram + y * BMPPITCH, rows + (y - y0) * pitch, FOS_W);
++}
++
++void fos_port_palette()
++{
++ /* once: Canon's own entries, to check the colour conversion against */
++ static int logged = 0;
++ if (!logged && debug_log)
++ {
++ logged = 1;
++ dbg("canon palette 1-7: %08x %08x %08x %08x %08x %08x %08x",
++ LCD_Palette[3 * 1 + 2], LCD_Palette[3 * 2 + 2], LCD_Palette[3 * 3 + 2], LCD_Palette[3 * 4 + 2],
++ LCD_Palette[3 * 5 + 2], LCD_Palette[3 * 6 + 2], LCD_Palette[3 * 7 + 2]);
++ dbg("canon palette 8-15: %08x %08x %08x %08x %08x %08x %08x %08x",
++ LCD_Palette[3 * 8 + 2], LCD_Palette[3 * 9 + 2], LCD_Palette[3 * 10 + 2], LCD_Palette[3 * 11 + 2],
++ LCD_Palette[3 * 12 + 2], LCD_Palette[3 * 13 + 2], LCD_Palette[3 * 14 + 2], LCD_Palette[3 * 15 + 2]);
++ }
++ photo_mode = 0;
++ palette_ours();
++ ui_last_palette = get_ms_clock();
++}
++
++void fos_port_photo(const uint8_t (*pal)[3], int n, int k)
++{
++ photo_n = COERCE(n, 0, FOS_PRINT_COLOURS);
++ memcpy(photo_pal, pal, photo_n * 3);
++ photo_k = COERCE(k, 0, 256);
++ photo_mode = 1;
++ palette_ours();
++ ui_last_palette = get_ms_clock();
++}
++
++void fos_port_log(const char *msg)
++{
++ dbg("%s", msg);
++}
++
++int fos_port_dev_cap()
++{
++ return 0;
++}
++
++/* ---- the card */
++
++const char *fos_port_card()
++{
++ static char root[8];
++ snprintf(root, sizeof(root), "%s:/", get_shooting_card()->drive_letter);
++ return root;
++}
++
++void *fos_port_open(const char *path, int write)
++{
++ return write ? FIO_CreateFile(path) : FIO_OpenFile(path, O_RDONLY | O_SYNC);
++}
++
++/* Canon reads files by DMA: into memory the CPU caches, it goes through
++ * an uncached buffer */
++#define BOUNCE (64 * 1024)
++
++int fos_port_read(void *f, void *buf, int size)
++{
++ if (buf != CACHEABLE(buf))
++ return FIO_ReadFile(f, buf, size);
++ static uint8_t *bounce = 0;
++ if (!bounce) bounce = fio_malloc(BOUNCE);
++ if (!bounce) return -1;
++ int done = 0;
++ while (done < size)
++ {
++ int n = MIN(size - done, BOUNCE);
++ int got = FIO_ReadFile(f, UNCACHEABLE(bounce), n);
++ if (got <= 0) break;
++ memcpy((uint8_t *) buf + done, UNCACHEABLE(bounce), got);
++ done += got;
++ if (got < n) break;
++ }
++ return done;
++}
++
++int fos_port_write(void *f, const void *buf, int size)
++{
++ return FIO_WriteFile(f, buf, size);
++}
++
++int fos_port_seek(void *f, int offset)
++{
++ return FIO_SeekSkipFile(f, offset, SEEK_SET) == offset ? 0 : -1;
++}
++
++void fos_port_close(void *f)
++{
++ if (f) FIO_CloseFile(f);
++}
++
++int fos_port_list(const char *dir, int (*fn)(void *ctx, const char *name, int is_dir), void *ctx)
++{
++ char path[FIO_MAX_PATH_LENGTH];
++ int len = snprintf(path, sizeof(path), "%s", dir);
++ if (len > 0 && len < (int) sizeof(path) - 1 && path[len - 1] != '/') strcat(path, "/");
++ struct fio_file file;
++ struct fio_dirent *d = FIO_FindFirstEx(path, &file);
++ if (IS_ERROR(d)) return -1;
++ int n = 0;
++ do
++ {
++ if (file.name[0] == '.') continue;
++ n++;
++ if (!fn(ctx, file.name, (file.mode & ATTR_DIRECTORY) != 0)) break;
++ }
++ while (FIO_FindNextEx(d, &file) == 0);
++ FIO_FindClose(d);
++ return n;
++}
++
++int fos_port_mkdir(const char *path)
++{
++ if (is_dir(path)) return 0;
++ FIO_CreateDirectory(path);
++ return is_dir(path) ? 0 : -1;
++}
++
++void *fos_port_alloc(int size)
++{
++ void *p = tmp_malloc(size);
++ if (!p) dbg("alloc: %d bytes failed", size);
++ return p;
++}
++
++void fos_port_free(void *p)
++{
++ if (p) free(p);
++}
++
++void fos_port_roll(struct fos_roll *r)
++{
++ if (roll_loaded && !recent_valid)
++ {
++ update_log_path();
++ read_back_log();
++ }
++ memset(r, 0, sizeof(*r));
++ r->loaded = roll_loaded;
++ r->number = roll_number;
++ r->film = COERCE(roll_film, 0, fos_nfilms - 1);
++ r->exposures = roll_exposures;
++ r->shot = frames_shot;
++ r->need_wind = need_wind;
++ snprintf(r->loaded_at, sizeof(r->loaded_at), "%s", loaded_at);
++ r->nrecent = nrecent;
++ for (int i = 0; i < nrecent && i < FOS_RECENT; i++)
++ {
++ r->recent[i].no = recent[i].no;
++ memcpy(r->recent[i].time, recent[i].time, sizeof(r->recent[i].time));
++ memcpy(r->recent[i].fstop, recent[i].fstop, sizeof(r->recent[i].fstop));
++ }
++}
++
++static int *setting_var(int s)
++{
++ switch (s)
++ {
++ case FS_HUD: return &hud_enabled;
++ case FS_LEDS: return &leds_on_half;
++ case FS_FOCUS: return &focus_screen;
++ case FS_WIND: return &wind_mode;
++ case FS_APKEYS: return &aperture_keys;
++ case FS_LENS_WIDE: return &lens_widest;
++ case FS_FSTOP: return &manual_fstop;
++ case FS_STARTUP: return &startup_picker;
++ case FS_PLAYLOCK: return &play_lock;
++ case FS_BOOTANIM: return &boot_anim;
++ case FS_DEBUG: return &debug_log;
++ case FS_FILM: return &film_sel;
++ case FS_EXP: return &exp_sel;
++ case FS_SCR_STD: return &scr_std;
++ case FS_SCR_SAT: return &scr_sat;
++ case FS_SCR_WARM: return &scr_warm;
++ case FS_SCR_BRIGHT: return &scr_bright;
++ }
++ return 0;
++}
++
++int fos_port_get(int s)
++{
++ int *v = setting_var(s);
++ if (s == FS_FSTOP) return current_fstop();
++ return v ? *v : 0;
++}
++
++void fos_port_set(int s, int value)
++{
++ int *v = setting_var(s);
++ if (v) *v = value;
++ hud_dirty = 1;
++ /* screen colour: the whole film OS changes at once */
++ if (s == FS_SCR_STD || s == FS_SCR_SAT || s == FS_SCR_WARM || s == FS_SCR_BRIGHT)
++ {
++ palette_ours();
++ ui_last_palette = get_ms_clock();
++ }
++}
++
++void fos_port_action(int action, int a, int b)
++{
++ switch (action)
++ {
++ case FA_LOAD:
++ if (ROLL_IN_PROGRESS) rewind_roll();
++ load_roll(a, fos_exposure_choices[COERCE(b, 0, FOS_NEXP - 1)]);
++ ui_after |= AFTER_APPLY;
++ break;
++ case FA_REWIND:
++ rewind_roll();
++ break;
++ case FA_BUSY:
++ if (a && !dev_busy) powersave_prohibit();
++ if (!a && dev_busy) powersave_permit();
++ dev_busy = a;
++ dbg("darkroom: %s", a ? "developing" : "done");
++ break;
++ case FA_REAPPLY:
++ if (roll_loaded) ui_after |= AFTER_APPLY;
++ break;
++ case FA_CANON_MENU:
++ ui_after |= AFTER_CANON_MENU;
++ break;
++ }
++}
++
++void fos_port_clock(char *buf, int size)
++{
++ /* screens ask every frame; the RTC is read once a second */
++ static char cached[8];
++ static int last = -100000;
++ int now_ms = get_ms_clock();
++ if (now_ms - last > 1000)
++ {
++ struct tm now;
++ LoadCalendarFromRTC(&now);
++ snprintf(cached, sizeof(cached), "%02d:%02d", now.tm_hour, now.tm_min);
++ last = now_ms;
++ }
++ snprintf(buf, size, "%s", cached);
++}
++
++int fos_port_lens_manual()
++{
++ return lens_is_manual();
++}
++
++const char *fos_port_lens_name()
++{
++ return lens_info.name[0] ? lens_info.name : "Lens";
++}
++
++/* M-Film's version (VERSION at the top of the repository; build_fork.sh writes fos_version.h) */
++#if defined(__has_include)
++#if __has_include("fos_version.h")
++#include "fos_version.h"
++#endif
++#endif
++#ifndef MFILM_VERSION
++#define MFILM_VERSION "dev"
++#endif
++
++const char *fos_port_model()
++{
++ /* "Canon EOS 650D": as the camera reports itself */
++ return camera_model[0] ? camera_model : "Canon camera";
++}
++
++const char *fos_port_version()
++{
++ return MFILM_VERSION;
++}
++
++
++void fos_port_stat(const struct fos_stat *s)
++{
++ stat_all.frames += s->frames;
++ stat_all.draw_ms += s->draw_ms;
++ stat_all.present_ms += s->present_ms;
++ stat_all.rest_ms += s->rest_ms;
++ stat_all.cans_ms += s->cans_ms;
++ if (s->worst_ms > stat_all.worst_ms) stat_all.worst_ms = s->worst_ms;
++ if (s->open_ms) stat_all.open_ms = s->open_ms;
++}
++
++/* ---------------------------------------------------------------- viewfinder HUD */
++
++static volatile int hud_showing = 0; /* HUD drawn on the LiveView screen */
++
++static int hud_visible()
++{
++ return hud_enabled && roll_loaded && lv && display_idle() && !is_movie_mode() && !ui_running;
++}
++
++/* Magic Lantern's own LiveView overlays never draw: the film OS (or
++ * Canon's clean screen) is all you see */
++int filmroll_overlays_active()
++{
++ return 1;
++}
++
++/* the HUD draws with Canon's palette */
++static struct fos_hud_palette hud_pal;
++
++static void hud_palette_init()
++{
++ hud_pal.clear = COLOR_EMPTY;
++ hud_pal.black = COLOR_BLACK;
++ hud_pal.white = COLOR_WHITE;
++ hud_pal.red = COLOR_RED;
++ hud_pal.dark_red = COLOR_DARK_RED;
++ for (int i = 0; i <= 100; i++)
++ hud_pal.gray[i] = COLOR_GRAY(i);
++}
++
++/* the shutter speed as the LEDs show it: 1/125 is 125, slow ones keep the " */
++static void shutter_led(char *buf, int size)
++{
++ if (!lens_info.raw_shutter)
++ {
++ snprintf(buf, size, "--");
++ return;
++ }
++ const char *s = lens_format_shutter(lens_info.raw_shutter);
++ int n = 0;
++ for (; *s && n < size - 1; s++)
++ if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '"')
++ buf[n++] = *s;
++ buf[n] = 0;
++}
++
++static void hud_draw(int lit, int blink)
++{
++ struct fos_hud h;
++ memset(&h, 0, sizeof(h));
++ h.lit = lit;
++ h.blink = blink;
++ h.fstop = current_fstop();
++ h.widest = lens_is_manual() ? lens_widest : 0;
++ if (lit)
++ {
++ int ev8 = get_ae_value(); /* meter reading, 1/8 EV, + = too bright */
++ h.meter = 1;
++ h.want = h.fstop + (ev8 * 3 + (ev8 >= 0 ? 4 : -4)) / 8;
++ }
++ shutter_led(h.shutter, sizeof(h.shutter));
++ h.frame = frames_shot + 1;
++ h.exposures = roll_exposures;
++ h.finished = ROLL_FINISHED;
++ h.need_wind = need_wind;
++ h.focus_screen = focus_screen;
++ h.film = fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].name;
++ uint8_t *vram = bmp_vram();
++ if (vram)
++ fos_hud_draw(vram, BMPPITCH, &h, &hud_pal);
++}
++
++static void hud_clear()
++{
++ uint8_t *vram = bmp_vram();
++ if (vram)
++ fos_hud_clear(vram, BMPPITCH, &hud_pal);
++}
++
++/* one HUD refresh; called from the main loop */
++static void hud_step()
++{
++ static int last_sig = -1;
++ static int last_draw = 0;
++ static int drawn = 0;
++ static int was_visible = -1;
++
++ int visible = hud_visible();
++ if (visible != was_visible)
++ {
++ dbg("hud: visible %d (enabled %d roll %d lv %d movie %d ui %d)",
++ visible, hud_enabled, roll_loaded, lv, is_movie_mode(), ui_running);
++ was_visible = visible;
++ }
++ hud_showing = visible;
++
++ if (!visible)
++ {
++ /* HUD switched off or roll rewound: wipe it once we're back on the LiveView screen */
++ if (drawn && (!hud_enabled || !roll_loaded) && lv && display_idle() && !ui_running)
++ {
++ hud_clear();
++ drawn = 0;
++ }
++ last_sig = -1;
++ return;
++ }
++ drawn = 1;
++
++ int now = get_ms_clock();
++ int lit = !leds_on_half || get_halfshutter_pressed() || now < leds_until;
++ int blink = (now / 400) % 2;
++ int ev8 = lit ? get_ae_value() : 0;
++
++ int sig = lit | blink << 1 | need_wind << 2 | (frames_shot & 0xFF) << 3
++ | lens_info.raw_shutter << 11 | (ev8 & 0xFF) << 19 | (current_fstop() & 0x1F) << 27;
++
++ /* redraw on change, and every second to win over Canon's overlays */
++ if (sig != last_sig || hud_dirty || now - last_draw > 1000)
++ {
++ hud_dirty = 0;
++ last_sig = sig;
++ last_draw = now;
++ hud_draw(lit, blink);
++ }
++}
++
++/* ---------------------------------------------------------------- keys */
++
++/* while the film OS is up it gets the dial and the buttons; anything it
++ * doesn't use goes on to Canon, like the ML menu does */
++static int ui_key(struct event *event, int key)
++{
++ int dir = 0;
++ switch (key)
++ {
++ case MODULE_KEY_PRESS_HALFSHUTTER:
++ case MODULE_KEY_PRESS_FULLSHUTTER:
++ case MODULE_KEY_REC:
++ ui_abort = 1; /* back to the camera, ready to shoot */
++ return 1;
++ case MODULE_KEY_UNPRESS_HALFSHUTTER:
++ case MODULE_KEY_UNPRESS_FULLSHUTTER:
++ return 1; /* Canon must see the shutter let go */
++
++ case MODULE_KEY_WHEEL_LEFT: dir = FK_WHEEL_L; break;
++ case MODULE_KEY_WHEEL_RIGHT: dir = FK_WHEEL_R; break;
++ case MODULE_KEY_WHEEL_UP: dir = FK_WHEEL_L; break;
++ case MODULE_KEY_WHEEL_DOWN: dir = FK_WHEEL_R; break;
++
++ case MODULE_KEY_PRESS_LEFT: keyq_push(FK_LEFT); return 0;
++ case MODULE_KEY_PRESS_RIGHT: keyq_push(FK_RIGHT); return 0;
++ case MODULE_KEY_PRESS_UP: keyq_push(FK_UP); return 0;
++ case MODULE_KEY_PRESS_DOWN: keyq_push(FK_DOWN); return 0;
++ case MODULE_KEY_UNPRESS_UDLR:
++ keyq_push(FK_RELEASE | FK_LEFT);
++ keyq_push(FK_RELEASE | FK_RIGHT);
++ keyq_push(FK_RELEASE | FK_UP);
++ keyq_push(FK_RELEASE | FK_DOWN);
++ return 0;
++
++ case MODULE_KEY_PRESS_SET:
++ case MODULE_KEY_Q:
++ case MODULE_KEY_JOY_CENTER: keyq_push(FK_SET); return 0;
++ case MODULE_KEY_UNPRESS_SET: return 0;
++ case MODULE_KEY_MENU: keyq_push(FK_MENU); return 0;
++ case MODULE_KEY_INFO: keyq_push(FK_INFO); return 0;
++ case MODULE_KEY_PLAY: keyq_push(FK_PLAY); return 0;
++ case MODULE_KEY_TRASH:
++ case MODULE_KEY_TOUCH_2_FINGER: keyq_push(FK_HOME); return 0;
++
++ case 0:
++ return 1; /* not a button: Canon's business */
++ default:
++ return 0;
++ }
++
++ /* newer firmware may group several wheel clicks into one event */
++ int count = MAX(1, MIN(event->arg, 8));
++ for (int i = 0; i < count; i++)
++ keyq_push(dir);
++ return 0;
++}
++
++static unsigned int lv_key(unsigned int key)
++{
++ /* what used to open the Magic Lantern menu opens home instead */
++ if (key == MODULE_KEY_TRASH || key == MODULE_KEY_TOUCH_2_FINGER)
++ {
++ if (shooting_screen())
++ {
++ dbg("key: home");
++ open_ui(FOS_OPEN_HOME);
++ }
++ return 0;
++ }
++
++ /* PLAY: the developed prints, never Canon's playback of what the
++ * darkroom hasn't seen yet */
++ if (key == MODULE_KEY_PLAY && play_lock && shooting_screen())
++ {
++ dbg("key: PLAY -> prints");
++ open_ui(FOS_OPEN_PRINTS);
++ return 0;
++ }
++
++ /* only on the plain LiveView screen: never steal keys from Canon's menus or dialogs */
++ if (!lv || !roll_loaded || !display_idle())
++ return 1;
++
++ if (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_UNPRESS_HALFSHUTTER)
++ hud_dirty = 1;
++
++ /* aperture ring for manual lenses: the wheel in Av mode (where it has
++ * nothing to adjust without a lens), or up/down if the user prefers */
++ if (lens_is_manual() && !ROLL_FINISHED)
++ {
++ int dir = 0;
++ if (aperture_keys == 0 && shooting_mode == SHOOTMODE_AV)
++ dir = (key == MODULE_KEY_WHEEL_RIGHT) ? 1 : (key == MODULE_KEY_WHEEL_LEFT) ? -1 : 0;
++ else if (aperture_keys == 1)
++ dir = (key == MODULE_KEY_PRESS_UP) ? 1 : (key == MODULE_KEY_PRESS_DOWN) ? -1 : 0;
++ if (dir)
++ {
++ step_manual_fstop(dir);
++ leds_until = get_ms_clock() + 2000;
++ hud_dirty = 1;
++ return 0;
++ }
++ }
++
++ if (ROLL_FINISHED)
++ {
++ if (key == MODULE_KEY_PRESS_SET)
++ {
++ open_ui(FOS_OPEN_END);
++ return 0;
++ }
++ return 1;
++ }
++
++ if (need_wind)
++ {
++ if (key == MODULE_KEY_PRESS_SET)
++ {
++ need_wind = 0;
++ leds_until = get_ms_clock() + 1500;
++ hud_dirty = 1;
++ return 0;
++ }
++ if (wind_mode == 2 && (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_PRESS_FULLSHUTTER))
++ return 0;
++ }
++
++ return 1;
++}
++
++int handle_filmroll_keys(struct event *event)
++{
++ int key = module_translate_key(event->param, MODULE_KEY_PORTABLE);
++ if (ui_running)
++ {
++#ifdef BGMT_UNPRESS_LEFT
++ /* the EOS M reports each direction's release on its own, and the
++ * portable key codes have no name for those */
++ switch (event->param)
++ {
++ case BGMT_UNPRESS_LEFT: keyq_push(FK_RELEASE | FK_LEFT); return 0;
++ case BGMT_UNPRESS_RIGHT: keyq_push(FK_RELEASE | FK_RIGHT); return 0;
++ case BGMT_UNPRESS_UP: keyq_push(FK_RELEASE | FK_UP); return 0;
++ case BGMT_UNPRESS_DOWN: keyq_push(FK_RELEASE | FK_DOWN); return 0;
++ }
++#endif
++ return ui_key(event, key);
++ }
++
++ if (!key)
++ return 1;
++
++ /* newer firmware may group several wheel clicks into one event */
++ int count = 1;
++ if (key == MODULE_KEY_WHEEL_LEFT || key == MODULE_KEY_WHEEL_RIGHT)
++ count = MAX(1, event->arg);
++
++ int pass = 1;
++ for (int i = 0; i < count; i++)
++ pass = lv_key(key);
++ return pass;
++}
++
++/* ---------------------------------------------------------------- the ML menu, replaced */
++
++void filmroll_menu_requested()
++{
++ if (shooting_screen())
++ open_ui(FOS_OPEN_HOME);
++}
++
++static void filmroll_init()
++{
++ if (roll_loaded)
++ update_log_path();
++ fos_ui_init();
++ hud_palette_init();
++ dbg("init: M-Film " MFILM_VERSION ", fork build %s %s, roll %d loaded %d shot %d/%d, startup %d hud %d",
++ __DATE__, __TIME__, roll_number, roll_loaded, frames_shot, roll_exposures,
++ startup_picker, hud_enabled);
++}
++
++/* The film OS's fonts are a file on the card (see fos_gfx.h): kept in
++ * memory taken after boot, not in autoexec.bin */
++static void load_fonts()
++{
++ int size = 0;
++ uint8_t *raw = read_entire_file("ML/DATA/" FOS_FONT_FILE, &size);
++ if (!raw)
++ {
++ dbg("fonts: ML/DATA/%s not found", FOS_FONT_FILE);
++ return;
++ }
++ uint8_t *blob = malloc(size); /* cached memory, for drawing */
++ if (blob)
++ {
++ memcpy(blob, raw, size);
++ if (!fos_fonts_load(blob, size))
++ {
++ free(blob);
++ blob = 0;
++ }
++ }
++ fio_free(raw);
++ dbg("fonts: %d bytes, %s", size, blob ? "loaded" : "not usable");
++}
++
++/* the films beyond the built-in ones, from the card; the file stays in
++ * memory (the films point into it) */
++static void load_films()
++{
++ int size = 0;
++ uint8_t *raw = read_entire_file("ML/DATA/" FOS_FILM_FILE, &size);
++ if (!raw)
++ {
++ dbg("films: ML/DATA/%s not found, the built-in ones only", FOS_FILM_FILE);
++ return;
++ }
++ uint8_t *blob = malloc(size);
++ if (blob)
++ {
++ memcpy(blob, raw, size);
++ if (!fos_films_load(blob, size))
++ {
++ free(blob);
++ blob = 0;
++ }
++ }
++ fio_free(raw);
++ dbg("films: %d (%d bytes, %s)", fos_nfilms, size, blob ? "loaded" : "not usable");
++}
++
++/* the film OS is the camera's start screen */
++static void startup_task()
++{
++ /* wait (up to ~15 s) for ML to finish booting and LiveView to settle */
++ for (int i = 0; i < 150; i++)
++ {
++ if (ml_started && shooting_screen())
++ break;
++ if (i % 10 == 0 && ml_started)
++ DBG_STATE("startup waiting");
++ msleep(100);
++ }
++ msleep(300);
++
++ DBG_STATE("startup check");
++ if (!ml_started || !shooting_screen())
++ {
++ dbg("startup: not on the shooting screen, film OS skipped");
++ return;
++ }
++ int shelf = startup_picker == 2 || (startup_picker == 1 && !ROLL_IN_PROGRESS);
++ if (boot_anim && startup_picker)
++ open_ui(shelf ? FOS_OPEN_BOOT : FOS_OPEN_BOOT_LV);
++ else if (shelf)
++ open_ui(FOS_OPEN_SHELF);
++}
++
++/* Everything runs from one task that waits for ML to finish booting, so
++ * nothing touches Canon's GUI state before it exists: start screen first,
++ * then frame logging and the HUD. */
++static void filmroll_task()
++{
++ while (!ml_started)
++ msleep(100);
++ dbg("main: started");
++
++ load_fonts();
++ load_films();
++ startup_task();
++ film_capture_check();
++
++ int last_alive = 0;
++ TASK_LOOP
++ {
++ poll_frames();
++
++ /* the roll has just been finished: once the camera is quiet, ask
++ * whether to develop it now or load a new one first */
++ if (end_due && get_ms_clock() > end_due && ROLL_FINISHED)
++ {
++ if (!ui_running && shooting_screen() && !get_halfshutter_pressed() && job_state_ready_to_take_pic())
++ {
++ end_due = 0;
++ dbg("roll %03d finished: asking", roll_number);
++ open_ui(FOS_OPEN_END);
++ }
++ }
++ else if (end_due && !ROLL_FINISHED) end_due = 0;
++ if (k % 2 == 0)
++ hud_step(); /* every 100 ms */
++
++ int now = get_ms_clock();
++ if (now - last_alive > 60000)
++ {
++ dbg("main: alive, roll %d loaded %d shot %d/%d file %d",
++ roll_number, roll_loaded, frames_shot, roll_exposures, last_file_number);
++ last_alive = now;
++ }
++ msleep(50);
++ }
++}
++
++INIT_FUNC("filmroll", filmroll_init);
++TASK_CREATE("film_main", filmroll_task, 0, 0x1e, 0x2000);
+diff --git a/src/filmroll.h b/src/filmroll.h
+new file mode 100644
+index 000000000..f43cb73ad
+--- /dev/null
++++ b/src/filmroll.h
+@@ -0,0 +1,16 @@
++#ifndef _filmroll_h_
++#define _filmroll_h_
++
++struct event;
++
++/* button hook, called from handle_common_events_by_feature; 0 = handled */
++int handle_filmroll_keys(struct event *event);
++
++/* called instead of opening the Magic Lantern menu (menu.c) */
++void filmroll_menu_requested();
++
++/* ML's own LiveView overlays stay out of the way of the film OS and the
++ * viewfinder HUD (always, in this fork) */
++int filmroll_overlays_active();
++
++#endif
+diff --git a/src/fos.h b/src/fos.h
+new file mode 100644
+index 000000000..f11c0a056
+--- /dev/null
++++ b/src/fos.h
+@@ -0,0 +1,235 @@
++/* fos: the film OS - the EOS M's own user interface on top of Magic Lantern.
++ *
++ * Everything the user sees (film shelf, home, settings, roll status,
++ * transitions) lives in fos_ui.c and draws with fos_gfx. It talks to the
++ * camera only through the fos_port_* functions below, which filmroll.c
++ * implements on the camera and sim/sim.c implements on a PC.
++ */
++
++#ifndef _fos_h_
++#define _fos_h_
++
++#include "fos_gfx.h"
++#include <stdio.h>
++#include <string.h>
++
++#define FOS_NAME "M" T_DOT "FILM"
++
++/* the first n characters of src (fewer if it is shorter) into dst: the
++ * camera's snprintf is Canon's, which doesn't know "%.5s" */
++static inline char *fos_copy(char *dst, int size, const char *src, int n)
++{
++ int i = 0;
++ for (; i < n && i < size - 1 && src[i]; i++) dst[i] = src[i];
++ if (size > 0) dst[i] = 0;
++ return dst;
++}
++
++/* ---------------------------------------------------------------- films */
++
++#define PS_STANDARD 0x81 /* raw PROP_PICTURE_STYLE values */
++#define PS_LANDSCAPE 0x83
++#define PS_MONO 0x86
++
++/* the shelves the films stand on */
++enum { FOS_GROUP_COLOUR, FOS_GROUP_SLIDE, FOS_GROUP_BW, FOS_GROUP_CINE, FOS_NGROUPS };
++extern const char *const fos_group_names[FOS_NGROUPS];
++
++/* a canister label drawn from parts (the films from ML/DATA/FOSFILMS.BIN;
++ * the built-in ones have their own painting in fos_film.c). An ink is a
++ * ramp and a level. */
++enum { FOS_LABEL_BAND, FOS_LABEL_CAP, FOS_LABEL_STRIPES };
++struct fos_label
++{
++ uint8_t style;
++ uint8_t leader; /* level of a grey (B&W) leader, 0 = colour film */
++ uint8_t bg[2], band[2], accent[2], text[2], num[2];
++ char top[20]; /* small, above the name */
++ char word[14]; /* the name */
++ char num_s[8]; /* big: digits and H, P, T */
++ char sub[18]; /* small, under the number */
++};
++
++struct fos_film
++{
++ const char *key; /* must match films/films.py */
++ const char *brand;
++ const char *name;
++ const char *process; /* "C-41", "E-6", "B&W" */
++ const char *desc;
++ int box_iso; /* rated speed */
++ int iso; /* what the camera is set to (EOS M has no ISO 50) */
++ int picstyle; /* in-camera preview only; the look comes from the lab */
++ int contrast, saturation, color_tone, sharpness;
++ int kelvin;
++ int wbs_gm; /* + green, - magenta (-9..9) */
++ int wbs_ba; /* + amber, - blue (-9..9) */
++ uint8_t grain, punch, colour, warmth; /* 1..5, for the shelf */
++ const char *shortname; /* in folder names: "Portra400" */
++ int group; /* FOS_GROUP_* */
++ const struct fos_label *label; /* NULL: painted by hand */
++};
++
++/* the built-in films, then those from ML/DATA/FOSFILMS.BIN once loaded */
++extern const struct fos_film *fos_films;
++extern int fos_nfilms;
++#define FOS_FILM_FILE "FOSFILMS.BIN"
++/* blob: the file's contents, kept while the films are used; 1 when usable */
++int fos_films_load(const uint8_t *blob, int size);
++
++extern const int fos_exposure_choices[]; /* 36, 24, 12 */
++#define FOS_NEXP 3
++
++/* f-numbers x100 in 1/3 stops; see fos_film.c */
++extern const int fos_fstops[];
++extern const int fos_nfstops;
++void fos_format_fstop(char *buf, int size, int index);
++
++/* ---------------------------------------------------------------- keys */
++
++enum
++{
++ FK_NONE,
++ FK_LEFT, FK_RIGHT, FK_UP, FK_DOWN, /* the four presses of the rear dial */
++ FK_WHEEL_L, FK_WHEEL_R, /* turning it */
++ FK_SET, FK_MENU, FK_INFO, FK_PLAY,
++ FK_HOME, /* what used to open the ML menu */
++ FK_RELEASE = 0x100, /* or-ed in: a press above ended */
++};
++
++/* ---------------------------------------------------------------- settings */
++
++enum
++{
++ FS_HUD, FS_LEDS, FS_FOCUS, FS_WIND,
++ FS_APKEYS, FS_LENS_WIDE, FS_FSTOP,
++ FS_STARTUP, FS_PLAYLOCK, FS_BOOTANIM, FS_DEBUG,
++ FS_FILM, FS_EXP,
++ FS_SCR_STD, /* screen colour: 0 Canon's conversion, 1 Rec.709 */
++ FS_SCR_SAT, FS_SCR_WARM, FS_SCR_BRIGHT, /* -FOS_SCR_STEPS..FOS_SCR_STEPS */
++ FS_COUNT
++};
++#define FOS_SCR_STEPS 6
++
++enum
++{
++ FA_LOAD, /* a = film, b = exposure choice */
++ FA_REWIND, /* end the roll in the camera */
++ FA_REAPPLY, /* film settings again (after changing WB by hand) */
++ FA_CANON_MENU, /* leave and open Canon's menu */
++ FA_BUSY, /* a = 1: long work (developing) begins, keep the camera awake; 0: done */
++};
++
++#define FOS_RECENT 5
++struct fos_roll
++{
++ int loaded;
++ int number;
++ int film;
++ int exposures;
++ int shot;
++ int need_wind;
++ char loaded_at[20]; /* "2026-08-08 09:10" */
++ int nrecent; /* newest first */
++ struct { int no; char time[6]; char fstop[6]; } recent[FOS_RECENT];
++};
++
++/* screens fos_ui_run can open on; BOOT_LV plays the boot animation and
++ * goes straight back to the camera */
++enum { FOS_OPEN_SHELF, FOS_OPEN_HOME, FOS_OPEN_BOOT, FOS_OPEN_BOOT_LV,
++ FOS_OPEN_PRINTS, /* PLAY: the latest prints */
++ FOS_OPEN_END, /* the roll has just been finished */
++ FOS_OPEN_DARKROOM };
++
++/* ---------------------------------------------------------------- the port */
++
++int fos_port_ms();
++void fos_port_sleep(int ms);
++int fos_port_key(); /* next key event, FK_NONE if none */
++int fos_port_abort(); /* leave right away (half-shutter, power off) */
++void fos_port_present(const uint8_t *rows, int pitch, int y0, int y1); /* rows = row y0 */
++void fos_port_palette(); /* load fos_pal[1..254] */
++void *fos_port_alloc(int size); /* big, temporary buffers */
++void fos_port_free(void *p);
++/* files on the card, for developing; fos_port_open returns NULL on failure */
++void *fos_port_open(const char *path, int write);
++int fos_port_read(void *f, void *buf, int size); /* bytes read */
++int fos_port_write(void *f, const void *buf, int size); /* bytes written */
++int fos_port_seek(void *f, int offset); /* from the start; < 0 on failure */
++void fos_port_close(void *f);
++const char *fos_port_card(); /* the card's root, ending in '/' */
++/* every entry of a directory, until fn returns 0; < 0 if it can't be read */
++int fos_port_list(const char *dir, int (*fn)(void *ctx, const char *name, int is_dir), void *ctx);
++int fos_port_mkdir(const char *path); /* 0 on success or if it exists */
++
++void fos_port_roll(struct fos_roll *r);
++int fos_port_get(int setting);
++void fos_port_set(int setting, int value);
++void fos_port_action(int action, int a, int b);
++void fos_port_clock(char *buf, int size); /* "14:32" */
++int fos_port_lens_manual();
++const char *fos_port_lens_name();
++const char *fos_port_version();
++const char *fos_port_model(); /* "Canon EOS M": the camera it runs on */
++/* photographs: palette entries 1..n become pal's colours at k/256 of
++ * their brightness, FOS_FIXED_BASE.. the fixed overlay colours (fos_dev.h);
++ * fos_port_palette() goes back to the film OS's own */
++void fos_port_photo(const uint8_t (*pal)[3], int n, int k);
++void fos_port_log(const char *msg); /* the debug log, if it is on */
++/* developing works in slices until a time budget is spent; the simulator's
++ * clock stands still meanwhile, so it caps the slices instead (0: no cap) */
++int fos_port_dev_cap();
++
++/* frame times, summed over about a second of animation; open_ms is how
++ * long the film OS took to show its first frame (first report only) */
++struct fos_stat { int frames, draw_ms, present_ms, rest_ms, worst_ms, open_ms, cans_ms; }; /* cans_ms: part of draw_ms */
++void fos_port_stat(const struct fos_stat *s); /* keep it, don't log while animating */
++
++/* ---------------------------------------------------------------- the viewfinder HUD */
++
++/* what the HUD shows; fos_hud.c draws it with Canon's palette */
++struct fos_hud
++{
++ int lit; /* LEDs on (half-press, or always) */
++ int blink; /* 0/1, toggles a few times a second */
++ int meter; /* the meter has a reading */
++ int fstop, widest, want; /* indices into fos_fstops; want = what the meter asks for */
++ char shutter[12]; /* "125", "2\"", "0.5\"" */
++ int frame, exposures, finished, need_wind;
++ int focus_screen;
++ const char *film;
++};
++
++struct fos_hud_palette
++{
++ uint8_t clear, black, white, red, dark_red;
++ uint8_t gray[101]; /* percent -> index */
++};
++
++void fos_hud_draw(uint8_t *vram, int pitch, const struct fos_hud *h, const struct fos_hud_palette *p);
++void fos_hud_clear(uint8_t *vram, int pitch, const struct fos_hud_palette *p);
++
++/* ---------------------------------------------------------------- the UI */
++
++void fos_ui_init();
++void fos_ui_run(int screen);
++
++/* canister art, fos_film.c; quality 2 = everything, 1 = no texture
++ * filtering, 0 = no reflections either (the UI lowers it on a slow camera) */
++extern int fos_can_quality;
++struct fos_can;
++struct fos_can *fos_can_new(int film, int exposures);
++void fos_can_free(struct fos_can *c);
++void fos_can_set_exposures(struct fos_can *c, int exposures);
++
++/* draw a canister standing on floor_y, centred on cx (1/256 px);
++ * scale 256 = full size, rot = turn (0..65535, 0 = label to the front),
++ * light 0..256 dims it for depth, leader 0 = none, 256 = the usual tongue,
++ * more = pulled further out, reflect 0..256 = its mirror image in the floor,
++ * fast = moving too quickly to need the label filtered between texels */
++struct fos_can_pose { int cx8, floor_y, scale, rot, light, leader, reflect, fast; };
++void fos_can_draw(struct fos_canvas *cv, struct fos_can *c, const struct fos_can_pose *p);
++int fos_can_height(int scale);
++int fos_can_width(int scale);
++
++#endif
+diff --git a/src/fos_dark.c b/src/fos_dark.c
+new file mode 100644
+index 000000000..639b3d968
+--- /dev/null
++++ b/src/fos_dark.c
+@@ -0,0 +1,1327 @@
++/* fos_dark: the darkroom.
++ *
++ * Rolls that have been shot and rewound wait here to be developed. The
++ * camera develops them itself (fos_dev.c), a slice at a time between the
++ * frames of a darkroom scene under the red safelight: the latent image
++ * comes up on the paper in the tray, the print darkens to its full depth,
++ * and goes up on the line to dry. The prints are looked at here as well,
++ * each on its own palette, and PLAY comes here too: nothing undeveloped is
++ * ever shown.
++ */
++
++#include "fos_ui.h"
++#include "fos_dev.h"
++#include <string.h>
++
++#define MAX_ROLLS 48
++
++/* The darkroom's lists live in memory taken while the film OS is up, not
++ * in autoexec.bin: on the EOS M every byte of that is taken from Canon's
++ * own memory at boot. */
++static struct dark_mem
++{
++ struct fos_lab_roll rolls[MAX_ROLLS];
++ uint8_t marked[MAX_ROLLS];
++ int queue[MAX_ROLLS];
++ struct fos_lab_frame frames[FOS_MAX_FRAMES], meta[FOS_MAX_FRAMES];
++ char paths[FOS_MAX_FRAMES][64];
++ struct fos_print print;
++} *dm;
++#define rolls (dm->rolls)
++#define marked (dm->marked)
++#define queue (dm->queue)
++#define pv_meta (dm->meta)
++#define pv_print (dm->print)
++
++static int nrolls;
++
++static int dark_mem()
++{
++ if (!dm && (dm = fos_port_alloc(sizeof(*dm)))) memset(dm, 0, sizeof(*dm));
++ return dm != 0;
++}
++
++void dark_free()
++{
++ fos_port_free(dm);
++ dm = 0;
++}
++
++static void rescan()
++{
++ nrolls = dm ? fos_lab_scan(rolls, MAX_ROLLS) : 0;
++}
++
++static int roll_index(int number)
++{
++ for (int i = 0; i < nrolls; i++)
++ if (rolls[i].number == number) return i;
++ return -1;
++}
++
++/* developed: every frame has its print and the contact sheet is there;
++ * waiting: shot, out of the camera, and a print or the sheet missing
++ * (developing again skips the prints already made) */
++/* developed: every frame printed, and every print in DCIM as a JPEG */
++static int is_developed(const struct fos_lab_roll *r) { return r->sheet && r->developed >= r->shot && r->jpegs >= r->developed; }
++static int is_waiting(const struct fos_lab_roll *r) { return !is_developed(r) && !r->in_camera && r->shot > 0; }
++static int has_prints(const struct fos_lab_roll *r) { return r->sheet || r->developed > 0; }
++
++/* about how long a frame takes, measured while developing */
++static int ms_per_frame = 15000;
++
++static void format_eta(char *buf, int size, int frames, int extra_ms)
++{
++ int s = (int) (((int64_t) frames * ms_per_frame + extra_ms) / 1000);
++ if (s < 60) snprintf(buf, size, "under a minute");
++ else if (s < 90 * 60) snprintf(buf, size, "about %d min", (s + 30) / 60);
++ else snprintf(buf, size, "about %d h %02d min", s / 3600, (s % 3600 + 30) / 60);
++}
++
++static const char *short_date(const char *when)
++{
++ /* "2026-10-22 17:45" -> "22 Oct 2026" */
++ static const char *const mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
++ static char b[16];
++ int m = (when[5] - '0') * 10 + (when[6] - '0');
++ if (strlen(when) < 10 || m < 1 || m > 12) return "";
++ char year[5];
++ snprintf(b, sizeof(b), "%c%c %s %s", when[8] == '0' ? ' ' : when[8], when[9], mon[m - 1], fos_copy(year, sizeof(year), when, 4));
++ return b[0] == ' ' ? b + 1 : b;
++}
++
++/* ================================================================ the list */
++
++static int dk_sel;
++static struct spring dk_hl, dk_scroll;
++static int dk_hints_for = -1; /* the hints show what SET does on this row */
++
++#define DK_X 24
++#define DK_W 672
++#define DK_Y 124
++#define DK_ROW 60
++#define DK_ROWS 5
++
++static int count_waiting(int *frames)
++{
++ int n = 0, f = 0;
++ for (int i = 0; i < nrolls; i++)
++ if (is_waiting(&rolls[i])) { n++; f += rolls[i].shot - (rolls[i].jpegs < rolls[i].developed ? rolls[i].jpegs : rolls[i].developed); }
++ if (frames) *frames = f;
++ return n;
++}
++
++static int count_marked()
++{
++ int n = 0;
++ for (int i = 0; i < nrolls; i++) n += marked[i] && is_waiting(&rolls[i]);
++ return n;
++}
++
++static void dark_bake()
++{
++ ui_bg_plain();
++ ui_to_bg(1);
++ ui_status_bar("DARKROOM");
++ fos_text(cv, &fos_font_lg, DK_X, 82, "Darkroom", C_TEXT, OPAQUE, 0);
++ char b[96], eta[32];
++ int frames, waiting = count_waiting(&frames);
++ if (!nrolls)
++ snprintf(b, sizeof(b), "No rolls yet " T_MDASH " finish one, rewind it, and it waits here.");
++ else if (waiting)
++ {
++ format_eta(eta, sizeof(eta), frames, 0);
++ snprintf(b, sizeof(b), "%d roll%s to develop " T_DOT " %d frames " T_DOT " %s", waiting, waiting > 1 ? "s" : "", frames, eta);
++ }
++ else
++ snprintf(b, sizeof(b), "Everything is developed " T_DOT " %d roll%s of prints", nrolls, nrolls > 1 ? "s" : "");
++ int w = fos_text(cv, &fos_font_sm, DK_X, 106, b, C_TEXT3, OPAQUE, 0);
++ /* the camera takes its time; a computer doesn't */
++ if (waiting && w + 260 < DK_W)
++ fos_text_r(cv, &fos_font_sm, DK_X + DK_W, 106, "Faster: Darkrooms on a computer", C_ACCENT2, OPAQUE, 0);
++ ui_to_bg(0);
++}
++
++static void dark_hints()
++{
++ const struct fos_lab_roll *r = nrolls ? &rolls[dk_sel] : 0;
++ int nm = count_marked();
++ char dev[32];
++ if (nm) snprintf(dev, sizeof(dev), "Develop %d", nm);
++ else snprintf(dev, sizeof(dev), "Develop all");
++ struct hint h[4];
++ int n = 0;
++ if (r && is_waiting(r)) h[n++] = (struct hint) { "SET", marked[dk_sel] ? "Unmark" : "Mark" };
++ else if (r && has_prints(r)) h[n++] = (struct hint) { "SET", "Prints" };
++ if (count_waiting(0)) h[n++] = (struct hint) { "INFO", dev };
++ h[n++] = (struct hint) { "PLAY", "Prints" };
++ h[n++] = (struct hint) { "MENU", "Back" };
++ ui_bg_restore(0, HINTS_Y, FOS_W, FOS_H - HINTS_Y);
++ ui_hints(h, n);
++ dk_hints_for = dk_sel * 2 + marked[dk_sel];
++}
++
++void dark_enter(int arg)
++{
++ fos_port_roll(&ui_roll);
++ dark_mem();
++ rescan();
++ if (dm) memset(marked, 0, sizeof(marked));
++ int i = arg ? roll_index(arg) : -1;
++ if (i < 0)
++ {
++ /* the newest roll waiting, else the newest */
++ i = 0;
++ for (int k = 0; k < nrolls; k++)
++ if (is_waiting(&rolls[k])) { i = k; break; }
++ }
++ dk_sel = i;
++ dk_hl.x = (float) dk_sel; dk_hl.v = 0;
++ dk_scroll.x = (float) fos_clamp(dk_sel - DK_ROWS / 2, 0, nrolls > DK_ROWS ? nrolls - DK_ROWS : 0);
++ dk_scroll.v = 0;
++ dk_hints_for = -1;
++ dark_bake();
++}
++
++void dark_queue_clear();
++void dark_queue_add(int roll);
++
++static void dark_develop()
++{
++ /* the marked rolls, or every one waiting; oldest first */
++ int nm = count_marked();
++ dark_queue_clear();
++ for (int i = nrolls - 1; i >= 0; i--)
++ if (is_waiting(&rolls[i]) && (!nm || marked[i])) dark_queue_add(rolls[i].number);
++ ui_go(SCR_DEVELOP, 0, GO_FADE);
++}
++
++void dark_key(int k)
++{
++ if (!dm)
++ {
++ if (k == FK_MENU) ui_go(SCR_HOME, 2, GO_POP);
++ return;
++ }
++ const struct fos_lab_roll *r = nrolls ? &rolls[dk_sel] : 0;
++ switch (k)
++ {
++ case FK_UP: case FK_WHEEL_L:
++ if (dk_sel > 0) dk_sel--;
++ break;
++ case FK_DOWN: case FK_WHEEL_R:
++ if (dk_sel < nrolls - 1) dk_sel++;
++ break;
++ case FK_SET: case FK_RIGHT:
++ if (!r) break;
++ if (r->in_camera) ui_toast("Still in the camera " T_MDASH " rewind it first");
++ else if (is_waiting(r) && k == FK_SET) marked[dk_sel] ^= 1;
++ else if (has_prints(r)) ui_go(SCR_PRINTS, r->number, GO_FADE);
++ break;
++ case FK_INFO:
++ if (count_waiting(0)) dark_develop();
++ else ui_toast(nrolls ? "Nothing to develop" : "No rolls yet");
++ break;
++ case FK_PLAY:
++ ui_go(SCR_PRINTS, r && has_prints(r) ? r->number : 0, GO_FADE);
++ break;
++ case FK_MENU:
++ ui_go(SCR_HOME, 2, GO_POP);
++ break;
++ case FK_HOME:
++ ui_leave();
++ break;
++ }
++ ui_damage(DK_Y - 4, FOS_H);
++}
++
++int dark_update(int dt)
++{
++ int moving = 0;
++ float top = (float) fos_clamp(dk_sel - DK_ROWS / 2, 0, nrolls > DK_ROWS ? nrolls - DK_ROWS : 0);
++ moving |= spring_step(&dk_hl, (float) dk_sel, dt, 3.4f, 0.82f);
++ moving |= spring_step(&dk_scroll, top, dt, 2.6f, 0.9f);
++ if (moving) ui_damage(DK_Y - 4, DK_Y + DK_ROWS * DK_ROW + 4);
++ return moving;
++}
++
++/* a round mark: empty, or filled with a tick */
++static void mark_dot(int cx, int cy, int on)
++{
++ if (on)
++ {
++ fos_disc(cv, cx * 256, cy * 256, 10 * 256, C_ACCENT, OPAQUE);
++ fos_line(cv, (cx - 5) * 256, cy * 256, (cx - 1) * 256, (cy + 4) * 256, 2 * 256, FC(RAMP_GRAY, 12), OPAQUE);
++ fos_line(cv, (cx - 1) * 256, (cy + 4) * 256, (cx + 6) * 256, (cy - 4) * 256, 2 * 256, FC(RAMP_GRAY, 12), OPAQUE);
++ }
++ else fos_ring(cv, cx * 256, cy * 256, 10 * 256, 2 * 256, FC(RAMP_GRAY, 90), OPAQUE);
++}
++
++static void dark_row(int i, int y)
++{
++ const struct fos_lab_roll *r = &rolls[i];
++ int sel = i == dk_sel;
++ int x = DK_X + 20;
++ if (is_waiting(r)) mark_dot(x + 12, y + DK_ROW / 2, marked[i]);
++ else ui_icon(r->in_camera ? ICON_FILM : ICON_PRINTS, x + 12, y + DK_ROW / 2, sel ? C_TEXT2 : C_TEXT3, OPAQUE);
++ char b[96];
++ fos_text(cv, &fos_font_mdb, x + 42, y + 27, fos_films[r->film].name, sel ? C_TEXT : C_TEXT2, OPAQUE, 0);
++ const char *when = r->last[0] ? r->last : r->loaded;
++ snprintf(b, sizeof(b), "Roll %03d " T_DOT " %d frame%s " T_DOT " %s", r->number, r->shot, r->shot == 1 ? "" : "s", short_date(when));
++ fos_text(cv, &fos_font_sm, x + 42, y + 48, b, C_TEXT3, OPAQUE, 0);
++ fcol c;
++ if (r->in_camera) { snprintf(b, sizeof(b), "IN CAMERA"); c = C_TEXT3; }
++ else if (is_developed(r)) { snprintf(b, sizeof(b), "DEVELOPED"); c = C_TEXT3; }
++ else if (r->developed) { snprintf(b, sizeof(b), "%d OF %d DEVELOPED", r->developed, r->shot); c = C_ACCENT; }
++ else { snprintf(b, sizeof(b), "TO DEVELOP"); c = C_ACCENT; }
++ fos_text_r(cv, &fos_font_xs, DK_X + DK_W - 24, y + 36, b, c, OPAQUE, 48);
++}
++
++void dark_draw()
++{
++ if (ui_clobbered)
++ {
++ ui_clobbered = 0;
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ ui_damage_all();
++ dk_hints_for = -1;
++ }
++ if (!dm)
++ {
++ fos_text_c(cv, &fos_font_md, 360, DK_Y + 120, "Not enough memory for the darkroom.", C_TEXT3, OPAQUE, 0);
++ return;
++ }
++ if (dk_hints_for != dk_sel * 2 + marked[dk_sel]) dark_hints();
++
++ int y0 = DK_Y - 4, y1 = DK_Y + DK_ROWS * DK_ROW + 4;
++ struct fos_canvas save = *cv;
++ ui_bg_restore(0, y0, FOS_W, y1 - y0);
++ fos_clip(cv, 0, DK_Y, FOS_W, DK_Y + DK_ROWS * DK_ROW);
++ if (!nrolls)
++ {
++ fos_text_c(cv, &fos_font_md, 360, DK_Y + 120, "Shot rolls appear here once they are rewound.", C_TEXT3, OPAQUE, 0);
++ *cv = save;
++ return;
++ }
++ float top = dk_scroll.x;
++ int hy = DK_Y + (int) ((dk_hl.x - top) * DK_ROW + 0.5f);
++ fos_rrect(cv, DK_X, hy, DK_W, DK_ROW, 12, FC(RAMP_GRAY, 27), OPAQUE);
++ fos_rrect(cv, DK_X, hy + 10, 3, DK_ROW - 20, 1, C_ACCENT, OPAQUE);
++ for (int i = (int) top; i < nrolls && i <= (int) top + DK_ROWS; i++)
++ dark_row(i, DK_Y + (int) ((i - top) * DK_ROW + 0.5f));
++ *cv = save;
++ /* the list goes on: a hint at the edge */
++ if (top > 0.05f) fos_tri(cv, DK_X + DK_W - 14, DK_Y - 8, 8, 3, C_TEXT3, OPAQUE);
++ if (top < nrolls - DK_ROWS - 0.05f) fos_tri(cv, DK_X + DK_W - 14, DK_Y + DK_ROWS * DK_ROW + 6, 8, 1, C_TEXT3, OPAQUE);
++ ui_damage(y0, y1 + 8);
++}
++
++/* ================================================================ developing */
++
++/* the scene, under the safelight */
++#define SL(level) FC(RAMP_RED, level)
++#define SL_TEXT SL(222)
++#define SL_TEXT2 SL(160)
++#define SL_TEXT3 SL(104)
++#define SL_ACCENT FC(RAMP_ORANGE, 200)
++
++/* the tray, the paper in it and the picture on the paper */
++#define TRAY_X 24
++#define TRAY_Y 128
++#define TRAY_W 400
++#define TRAY_H 284
++#define BATH_X (TRAY_X + 12)
++#define BATH_Y (TRAY_Y + 12)
++#define BATH_W (TRAY_W - 24)
++#define BATH_H (TRAY_H - 24)
++#define PAPER_W 348
++#define PAPER_H 240
++#define PAPER_X (TRAY_X + (TRAY_W - PAPER_W) / 2)
++#define PAPER_Y (TRAY_Y + (TRAY_H - PAPER_H) / 2)
++#define IMG_W 324
++#define IMG_H 216
++#define IMG_X (PAPER_X + (PAPER_W - IMG_W) / 2)
++#define IMG_Y (PAPER_Y + (PAPER_H - IMG_H) / 2)
++#define GHOST_W (IMG_W / 2)
++#define GHOST_H (IMG_H / 2)
++#define PAPER_LV 124 /* white paper under the safelight */
++#define BLACK_LV 9
++
++/* the line the prints dry on */
++#define LINE_Y 52
++#define DRY_W 66
++#define DRY_H 44
++#define DRY_STEP 92
++#define DRY_X0 36
++#define DRY_N 7
++
++/* the panel and its timer */
++#define PANEL_CX 572
++#define DIAL_CY2 282
++#define DIAL_R2 58
++
++#define EMERGE_MS 1700
++#define HOLD_MS 900
++#define LIFT_MS 450
++#define SLIDE_MS 450
++#define STEP_MS 60 /* developing per frame while the scene moves */
++#define CALM_MS 250 /* and while it is still: the dial's hand ticks */
++
++static int nqueue, qi;
++static char dcim_dir[128]; /* the roll's JPEG folder, or "" */
++static int nframes, fi, roll_ready;
++static int cur_roll, cur_film, cur_frame;
++static struct fos_dev *dev;
++static int frame_t0;
++static int total_frames, done_frames, failed_frames, rolls_done;
++static int finished, asking_stop;
++static struct spring stop_sheet;
++static int dv_t;
++
++/* the tray: what the paper shows */
++enum { TRAY_LATENT, TRAY_EMERGE, TRAY_HOLD, TRAY_LIFT, TRAY_IN, TRAY_EMPTY };
++static int tray, tray_t;
++static uint8_t *ghost; /* GHOST_W x GHOST_H: the latent image */
++static uint8_t *img; /* IMG_W x IMG_H: the finished print */
++static int ghost_t; /* ms since the latent image was read */
++static int ghost_final; /* read once more when the RAW is through */
++static int pending_frame; /* a print waiting for the tray, 0 = none */
++static char pending_path[64];
++static int tray_dirty = 1, line_dirty = 1, panel_dirty = 1;
++static int last_doing = -1;
++static char last_error[72]; /* why the last frame that failed did */
++
++/* the line: newest first */
++static uint8_t *dry; /* DRY_N x DRY_W x DRY_H */
++static int ndry, dry_t = 100000; /* dry_t: ms since the newest went up */
++
++void dark_queue_clear() { nqueue = 0; }
++void dark_queue_add(int roll) { if (dark_mem() && nqueue < MAX_ROLLS) queue[nqueue++] = roll; }
++
++static int file_exists(const char *path)
++{
++ void *f = fos_port_open(path, 0);
++ if (f) fos_port_close(f);
++ return f != 0;
++}
++
++/* the print's picture, small and grey, for the tray */
++static void load_tray_image(const char *path)
++{
++ struct fos_print p;
++ memset(img, 255, IMG_W * IMG_H);
++ if (!fos_print_load(path, &p)) return;
++ uint8_t lum[FOS_PRINT_COLOURS + 1];
++ lum[0] = 0;
++ for (int i = 0; i < FOS_PRINT_COLOURS; i++)
++ lum[i + 1] = (uint8_t) ((p.pal[i][0] * 77 + p.pal[i][1] * 150 + p.pal[i][2] * 29) >> 8);
++ for (int y = 0; y < IMG_H; y++)
++ {
++ int sy = (2 * y + 1) * FOS_PRINT_H / (2 * IMG_H);
++ for (int x = 0; x < IMG_W; x++)
++ {
++ int sx = (2 * x + 1) * FOS_PRINT_W / (2 * IMG_W);
++ /* the borders of a portrait frame stay white paper */
++ if (sx < p.x0 || sx >= p.x0 + p.w) continue;
++ const uint8_t *s = p.px + sy * FOS_PRINT_W + sx;
++ int k0 = s[0], k1 = s[1], k2 = s[FOS_PRINT_W], k3 = s[FOS_PRINT_W + 1];
++ img[y * IMG_W + x] = (uint8_t) ((lum[k0 > 240 ? 0 : k0] + lum[k1 > 240 ? 0 : k1] + lum[k2 > 240 ? 0 : k2]
++ + lum[k3 > 240 ? 0 : k3]) >> 2);
++ }
++ }
++ fos_print_free(&p);
++}
++
++/* a finished frame's thumbnail onto the line; a portrait frame's sides
++ * are white paper */
++static void hang(const uint8_t *thumb, int x0, int w)
++{
++ if (!dry || !thumb) return;
++ memmove(dry + DRY_W * DRY_H, dry, (DRY_N - 1) * DRY_W * DRY_H);
++ for (int y = 0; y < DRY_H; y++)
++ for (int x = 0; x < DRY_W; x++)
++ {
++ int px = (2 * x + 1) * FOS_PRINT_W / (2 * DRY_W);
++ const uint8_t *s = thumb + 3 * ((y * FOS_THUMB_H / DRY_H) * FOS_THUMB_W + x * FOS_THUMB_W / DRY_W);
++ dry[y * DRY_W + x] = px < x0 || px >= x0 + w ? 255 : (uint8_t) ((s[0] * 77 + s[1] * 150 + s[2] * 29) >> 8);
++ }
++ if (ndry < DRY_N) ndry++;
++ dry_t = 0;
++ line_dirty = 1;
++}
++
++/* the next frame to develop, or the next roll's; the contact sheet when a
++ * roll is through */
++static void next_job()
++{
++ char path[64];
++ while (qi < nqueue)
++ {
++ if (!roll_ready)
++ {
++ cur_roll = queue[qi];
++ int ri = roll_index(cur_roll);
++ cur_film = ri >= 0 ? rolls[ri].film : 0;
++ nframes = fos_lab_frames(cur_roll, dm->frames, FOS_MAX_FRAMES);
++ {
++ char msg[96];
++ int raws = 0;
++ for (int i = 0; i < nframes; i++) raws += !dm->frames[i].missing;
++ snprintf(msg, sizeof(msg), "darkroom: roll %03d (%s): %d frames, %d RAW files", cur_roll,
++ fos_films[cur_film].key, nframes, raws);
++ fos_port_log(msg);
++ }
++ fos_lab_prepare(cur_roll);
++ /* the roll's JPEGs go in DCIM, in a folder named for the day
++ * its first frame was shot and the film */
++ const char *first = 0;
++ for (int i = 0; i < nframes; i++)
++ if (dm->frames[i].when[0] && (!first || strcmp(dm->frames[i].when, first) < 0)) first = dm->frames[i].when;
++ if (fos_lab_dcim_dir(dcim_dir, sizeof(dcim_dir), cur_roll, cur_film, first) < 0)
++ {
++ dcim_dir[0] = 0;
++ fos_port_log("darkroom: no folder for the JPEGs in DCIM");
++ }
++ else
++ {
++ char msg[160];
++ snprintf(msg, sizeof(msg), "darkroom: JPEGs in %s", dcim_dir);
++ fos_port_log(msg);
++ }
++ fi = 0;
++ roll_ready = 1;
++ panel_dirty = 1;
++ }
++ while (fi < nframes)
++ {
++ const struct fos_lab_frame *f = &dm->frames[fi++];
++ fos_lab_print_path(path, sizeof(path), cur_roll, f->no);
++ /* its JPEG in DCIM: IMG_0102.CR2 -> IMG_0102.JPG */
++ char jpeg[160] = "";
++ if (dcim_dir[0])
++ {
++ const char *base = strrchr(f->cr2, '/');
++ char name[9];
++ snprintf(jpeg, sizeof(jpeg), "%s/%s.JPG", dcim_dir, fos_copy(name, sizeof(name), base ? base + 1 : f->cr2, 8));
++ }
++ /* developed before (and, by this version, written to DCIM too) */
++ if (file_exists(path) && (!jpeg[0] || f->missing || file_exists(jpeg))) continue;
++ if (f->missing)
++ {
++ char msg[120];
++ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d: no RAW file %s", cur_roll, f->no, f->cr2);
++ fos_port_log(msg);
++ snprintf(last_error, sizeof(last_error), "No RAW file " T_MDASH " shoot with Image quality RAW");
++ failed_frames++;
++ done_frames++;
++ continue;
++ }
++ cur_frame = f->no;
++ dev = fos_dev_start(f->cr2, path, cur_film, f->no, f->when, f->fstop);
++ if (dev && jpeg[0]) fos_dev_jpeg(dev, jpeg);
++ frame_t0 = ui_now;
++ ghost_t = 100000;
++ ghost_final = 0;
++ memset(ghost, 255, GHOST_W * GHOST_H); /* fresh paper */
++ panel_dirty = 1;
++ if (dev) return;
++ snprintf(last_error, sizeof(last_error), "Not enough memory");
++ failed_frames++;
++ done_frames++;
++ }
++ /* the roll is through: its contact sheet */
++ const char *pp[FOS_MAX_FRAMES];
++ for (int i = 0; i < nframes; i++)
++ {
++ fos_lab_print_path(dm->paths[i], sizeof(dm->paths[i]), cur_roll, i + 1);
++ pp[i] = dm->paths[i];
++ }
++ fos_lab_print_path(path, sizeof(path), cur_roll, 0);
++ if (!fos_dev_sheet(path, cur_film, pp, nframes)) fos_port_log("darkroom: can't write the contact sheet");
++ rolls_done++;
++ qi++;
++ roll_ready = 0;
++ }
++ finished = 1;
++ cur_frame = 0;
++ panel_dirty = 1;
++ fos_dev_release();
++ fos_port_action(FA_BUSY, 0, 0);
++}
++
++static void frame_finished(int ok)
++{
++ char msg[160];
++ int took = ui_now - frame_t0;
++ if (ok)
++ {
++ /* a running mean, the first frames counting fully */
++ ms_per_frame = done_frames - failed_frames < 3 ? took : (ms_per_frame * 3 + took) / 4;
++ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d developed in %d ms", cur_roll, cur_frame, took);
++ fos_port_log(msg);
++ if (!pending_frame)
++ {
++ pending_frame = cur_frame;
++ fos_lab_print_path(pending_path, sizeof(pending_path), cur_roll, cur_frame);
++ }
++ int x0, w;
++ fos_dev_picture(dev, &x0, &w);
++ hang(fos_dev_thumb(dev), x0, w);
++ }
++ else
++ {
++ const char *why = fos_dev_error(dev) && fos_dev_error(dev)[0] ? fos_dev_error(dev) : "stopped without a reason";
++ snprintf(msg, sizeof(msg), "darkroom: roll %03d frame %d: %s", cur_roll, cur_frame, why);
++ fos_port_log(msg);
++ snprintf(last_error, sizeof(last_error), "Frame %d: %s", cur_frame, why);
++ failed_frames++;
++ }
++ done_frames++;
++ fos_dev_free(dev);
++ dev = 0;
++ panel_dirty = 1;
++}
++
++static void develop_bake()
++{
++ ui_to_bg(1);
++ /* the room: dark, the safelight from above */
++ fos_vgrad(cv, 0, 0, FOS_W, FOS_H, RAMP_RED, LV12(30), LV12(7));
++ fos_text(cv, &fos_font_xs, 24, 26, "DARKROOM", SL_TEXT2, OPAQUE, 64);
++ /* the line */
++ fos_fill(cv, 12, LINE_Y, FOS_W - 24, 2, SL(70));
++ /* the tray and the developer in it */
++ fos_rrect(cv, TRAY_X, TRAY_Y, TRAY_W, TRAY_H, 16, SL(26), OPAQUE);
++ fos_rrect_line(cv, TRAY_X, TRAY_Y, TRAY_W, TRAY_H, 16, 2, SL(48), OPAQUE);
++ fos_rrect(cv, BATH_X, BATH_Y, BATH_W, BATH_H, 10, SL(15), OPAQUE);
++ ui_to_bg(0);
++}
++
++void develop_enter(int arg)
++{
++ if (!dark_mem()) nqueue = 0;
++ rescan();
++ total_frames = done_frames = failed_frames = rolls_done = 0;
++ for (int i = 0; i < nqueue; i++)
++ {
++ int ri = roll_index(queue[i]);
++ if (ri >= 0) total_frames += rolls[ri].shot - rolls[ri].developed;
++ }
++ qi = 0; roll_ready = 0; dev = 0;
++ last_error[0] = 0;
++ finished = nqueue == 0;
++ asking_stop = 0;
++ stop_sheet.x = stop_sheet.v = 0;
++ cur_frame = 0;
++ dv_t = 0;
++ tray = TRAY_LATENT; tray_t = 0;
++ pending_frame = 0;
++ ndry = 0; dry_t = 100000;
++ ghost = fos_port_alloc(GHOST_W * GHOST_H);
++ img = fos_port_alloc(IMG_W * IMG_H);
++ dry = fos_port_alloc(DRY_N * DRY_W * DRY_H);
++ if (ghost) memset(ghost, 255, GHOST_W * GHOST_H);
++ tray_dirty = line_dirty = panel_dirty = 1;
++ last_doing = -1;
++ char dir[64];
++ fos_lab_cache_dir(dir, sizeof(dir));
++ fos_dev_cache(dir);
++ if (!finished) fos_port_action(FA_BUSY, 1, 0);
++ develop_bake();
++}
++
++void develop_leave()
++{
++ if (dev) { fos_dev_free(dev); dev = 0; }
++ if (!finished) fos_port_action(FA_BUSY, 0, 0);
++ finished = 1;
++ fos_dev_release();
++ fos_port_free(ghost); ghost = 0;
++ fos_port_free(img); img = 0;
++ fos_port_free(dry); dry = 0;
++}
++
++void develop_key(int k)
++{
++ if (asking_stop)
++ {
++ if (k == FK_SET) { asking_stop = 0; ui_go(SCR_DARK, cur_roll, GO_FADE); }
++ else if (k == FK_MENU) asking_stop = 0;
++ ui_clobbered = 1;
++ return;
++ }
++ switch (k)
++ {
++ case FK_MENU:
++ if (finished) ui_go(SCR_DARK, cur_roll, GO_FADE);
++ else asking_stop = 1;
++ ui_clobbered = 1;
++ break;
++ case FK_SET: case FK_PLAY:
++ if (finished) ui_go(SCR_PRINTS, nqueue ? queue[0] : 0, GO_FADE);
++ break;
++ case FK_HOME:
++ ui_leave();
++ break;
++ }
++}
++
++int develop_update(int dt)
++{
++ dv_t += dt;
++ if (!ghost || !img || !dry || !dm)
++ {
++ /* no memory for the scene: say so and stop */
++ if (!finished) { finished = 1; fos_port_action(FA_BUSY, 0, 0); ui_toast("Not enough memory to develop"); }
++ return 0;
++ }
++ /* the work: only once the screen has settled, and not while asking */
++ if (!finished && !asking_stop && ui_settled())
++ {
++ if (!dev) next_job();
++ if (dev)
++ {
++ /* the work takes nearly all of a frame when nothing on the
++ * screen moves but the dial's hand */
++ int calm = (tray == TRAY_LATENT || tray == TRAY_EMPTY) && dry_t >= SLIDE_MS + 100
++ && stop_sheet.x < 0.002f;
++ int p = fos_dev_step(dev, calm ? CALM_MS : STEP_MS);
++ if (p >= 0 && p < 1000 && !ghost_final && fos_dev_doing(dev) == FOS_DEV_FIXING)
++ {
++ /* the whole latent image, while it can still be read */
++ ghost_final = 1;
++ if (fos_dev_preview(dev, ghost, GHOST_W, GHOST_H) && (tray == TRAY_LATENT || tray == TRAY_IN)) tray_dirty = 1;
++ }
++ else if (p >= 0 && p < 1000 && ghost_t > 600 && fos_dev_preview(dev, ghost, GHOST_W, GHOST_H))
++ {
++ /* the latent image so far; the paper shows it when it is in the bath */
++ ghost_t = 0;
++ if (tray == TRAY_LATENT || tray == TRAY_IN) tray_dirty = 1;
++ }
++ if (p >= 1000) frame_finished(1);
++ else if (p < 0) frame_finished(0);
++ }
++ }
++
++ /* the tray */
++ tray_t += dt;
++ ghost_t += dt;
++ switch (tray)
++ {
++ case TRAY_LATENT:
++ if (pending_frame)
++ {
++ load_tray_image(pending_path);
++ tray = TRAY_EMERGE; tray_t = 0;
++ tray_dirty = 1;
++ }
++ break;
++ case TRAY_EMERGE:
++ tray_dirty = 1;
++ if (tray_t > EMERGE_MS) { tray = TRAY_HOLD; tray_t = 0; }
++ break;
++ case TRAY_HOLD:
++ if (tray_t > HOLD_MS) { tray = TRAY_LIFT; tray_t = 0; }
++ break;
++ case TRAY_LIFT:
++ tray_dirty = 1;
++ if (tray_t > LIFT_MS)
++ {
++ pending_frame = 0;
++ tray = finished ? TRAY_EMPTY : TRAY_IN;
++ tray_t = 0;
++ ghost_t = 100000;
++ }
++ break;
++ case TRAY_IN:
++ tray_dirty = 1;
++ if (tray_t > SLIDE_MS) { tray = TRAY_LATENT; tray_t = 0; }
++ break;
++ case TRAY_EMPTY:
++ break;
++ }
++ if (finished && tray == TRAY_LATENT && !pending_frame) { tray = TRAY_EMPTY; tray_dirty = 1; }
++ if (dry_t < SLIDE_MS + 100) { dry_t += dt; line_dirty = 1; }
++ else dry_t += dt;
++ int moving = spring_step(&stop_sheet, asking_stop ? 1 : 0, dt, 3.0f, 0.95f);
++ if (moving) ui_clobbered = 1;
++ return 1; /* the timer's hand keeps going */
++}
++
++/* grey levels (paper 255 .. black 0) at density k/256 of their own, as
++ * dithered positions on the red ramp */
++static void density_table(int16_t *pos, int k)
++{
++ for (int l = 0; l < 256; l++)
++ {
++ int d = (255 - l) * k >> 8; /* density 0..255 */
++ int lv = LV12(PAPER_LV) - (LV12(PAPER_LV) - LV12(BLACK_LV)) * d / 255;
++ pos[l] = (int16_t) fos_ramp_pos(RAMP_RED, lv);
++ }
++}
++
++/* the paper and what is on it, its top edge dy below where it rests */
++static void draw_paper(int dy)
++{
++ struct fos_canvas save = *cv;
++ fos_clip(cv, BATH_X, BATH_Y, BATH_X + BATH_W, BATH_Y + BATH_H);
++ ui_bg_restore(BATH_X, BATH_Y, BATH_W, BATH_H);
++ int px = PAPER_X, py = PAPER_Y + dy;
++ /* a soft shadow under it in the bath */
++ fos_rrect(cv, px + 3, py + 4, PAPER_W, PAPER_H, 3, SL(10), 160);
++ fos_fill(cv, px, py, PAPER_W, PAPER_H, SL(PAPER_LV));
++ int16_t pos[256];
++ const uint8_t *src = 0;
++ int half = 0;
++ if (tray == TRAY_LATENT || tray == TRAY_IN)
++ {
++ /* the latent image, faint */
++ density_table(pos, 90);
++ src = ghost;
++ half = 1;
++ }
++ else
++ {
++ /* the darks first, then the rest, to the print's full depth */
++ float t = tray == TRAY_EMERGE ? clampf((float) tray_t / EMERGE_MS, 0, 1) : 1;
++ for (int l = 0; l < 256; l++)
++ {
++ float dfull = (255 - l) / 255.0f;
++ float k = t >= 1 ? 1 : ease_out(clampf(t * (0.7f + dfull) * 1.3f, 0, 1));
++ int d = (int) ((255 - l) * (0.35f + 0.65f * k));
++ int lv = LV12(PAPER_LV) - (LV12(PAPER_LV) - LV12(BLACK_LV)) * d / 255;
++ pos[l] = (int16_t) fos_ramp_pos(RAMP_RED, lv);
++ }
++ src = img;
++ }
++ int y0 = IMG_Y + dy;
++ int ya = fos_clamp(y0, cv->cy0, cv->cy1), yb = fos_clamp(y0 + IMG_H, cv->cy0, cv->cy1);
++ const int base = fos_ramp_base[RAMP_RED], last = fos_ramp_last[RAMP_RED];
++ for (int y = ya; y < yb; y++)
++ {
++ int sy = y - y0;
++ const uint8_t *s = half ? src + (sy >> 1) * GHOST_W : src + sy * IMG_W;
++ uint8_t *o = &cv->px[y * cv->pitch + IMG_X];
++ const uint8_t *bay = fos_bayer[y & 3];
++ for (int x = 0; x < IMG_W; x++)
++ {
++ int p = (pos[s[half ? x >> 1 : x]] + bay[x & 3]) >> 4;
++ o[x] = (uint8_t) (base + (p > last ? last : p));
++ }
++ }
++ *cv = save;
++ ui_damage(BATH_Y, BATH_Y + BATH_H);
++}
++
++static void draw_tray()
++{
++ switch (tray)
++ {
++ case TRAY_LIFT:
++ {
++ /* lifted out of the bath: up and away */
++ float t = clampf((float) tray_t / LIFT_MS, 0, 1);
++ draw_paper(-(int) (t * t * (PAPER_H + 40)));
++ break;
++ }
++ case TRAY_IN:
++ {
++ /* fresh paper slides in */
++ float t = ease_out(clampf((float) tray_t / SLIDE_MS, 0, 1));
++ draw_paper((int) ((1 - t) * (BATH_H + 10)));
++ break;
++ }
++ case TRAY_EMPTY:
++ ui_bg_restore(BATH_X, BATH_Y, BATH_W, BATH_H);
++ ui_damage(BATH_Y, BATH_Y + BATH_H);
++ break;
++ default:
++ draw_paper(0);
++ }
++}
++
++/* the prints drying, newest on the left; a new one drops in */
++static void draw_line()
++{
++ int y0 = LINE_Y - 8, y1 = LINE_Y + DRY_H + 22;
++ ui_bg_restore(0, y0, FOS_W, y1 - y0);
++ int16_t pos[256];
++ density_table(pos, 256);
++ const int base = fos_ramp_base[RAMP_RED], last = fos_ramp_last[RAMP_RED];
++ struct fos_canvas save = *cv;
++ fos_clip(cv, 0, y0, FOS_W, y1);
++ for (int i = 0; i < ndry; i++)
++ {
++ /* the older ones move along a place, then the new one comes */
++ float shift = ease_out(clampf((float) dry_t / (SLIDE_MS / 2), 0, 1));
++ float drop = ease_out(clampf((float) (dry_t - SLIDE_MS / 2) / (SLIDE_MS / 2), 0, 1));
++ if (i == 0 && drop <= 0) continue;
++ float slot = i == 0 ? 0 : i - (1 - shift);
++ int x = DRY_X0 + (int) (slot * DRY_STEP);
++ int y = LINE_Y + 8 - (i == 0 ? (int) ((1 - drop) * 70) : 0);
++ if (x > FOS_W) continue;
++ fos_fill(cv, x - 3, y - 3, DRY_W + 6, DRY_H + 6, SL(PAPER_LV));
++ int ya = fos_clamp(y, cv->cy0, cv->cy1), yb = fos_clamp(y + DRY_H, cv->cy0, cv->cy1);
++ const uint8_t *src = dry + i * DRY_W * DRY_H;
++ for (int yy = ya; yy < yb; yy++)
++ {
++ const uint8_t *s = src + (yy - y) * DRY_W;
++ uint8_t *o = &cv->px[yy * cv->pitch + x];
++ const uint8_t *bay = fos_bayer[yy & 3];
++ for (int k = 0; k < DRY_W && x + k < FOS_W; k++)
++ {
++ int p = (pos[s[k]] + bay[k & 3]) >> 4;
++ o[k] = (uint8_t) (base + (p > last ? last : p));
++ }
++ }
++ /* the peg */
++ fos_rrect(cv, x + DRY_W / 2 - 4, y - 12, 8, 14, 2, FC(RAMP_METAL, 60), OPAQUE);
++ }
++ *cv = save;
++ ui_damage(y0, y1);
++}
++
++/* the darkroom timer: a frame a turn, the roll's frames round its face */
++static void draw_dial(float frac)
++{
++ int cx = PANEL_CX, cy = DIAL_CY2, R = DIAL_R2;
++ ui_bg_restore(cx - R - 6, cy - R - 6, 2 * R + 12, 2 * R + 12);
++ fos_disc(cv, cx * 256, cy * 256, (R + 4) * 256, SL(20), OPAQUE);
++ fos_ring(cv, cx * 256, cy * 256, (R + 4) * 256, 2 * 256, SL(56), OPAQUE);
++ for (int i = 0; i < 60; i++)
++ {
++ int a = i * 65536 / 60 - 16384, r0 = i % 5 ? R - 6 : R - 11;
++ fos_line(cv, cx * 256 + fos_cos(a) * r0 / 16, cy * 256 + fos_sin(a) * r0 / 16,
++ cx * 256 + fos_cos(a) * (R - 1) / 16, cy * 256 + fos_sin(a) * (R - 1) / 16, i % 5 ? 200 : 360, SL(i % 5 ? 70 : 120), OPAQUE);
++ }
++ /* the roll's frames as dots: developed, this one, to come */
++ int n = nframes > 0 ? nframes : 1;
++ for (int i = 0; i < n && nframes; i++)
++ {
++ int a = i * 65536 / n - 16384, r = R - 22;
++ int no = i + 1;
++ fcol c = finished || no < cur_frame ? SL(190) : no == cur_frame ? SL_ACCENT : SL(64);
++ fos_disc(cv, cx * 256 + fos_cos(a) * r / 16, cy * 256 + fos_sin(a) * r / 16, n > 24 ? 480 : 640, c, OPAQUE);
++ }
++ /* the hand */
++ int a = (int) (frac * 65536) - 16384;
++ fos_line(cv, cx * 256 - fos_cos(a) * 12 / 16, cy * 256 - fos_sin(a) * 12 / 16,
++ cx * 256 + fos_cos(a) * (R - 8) / 16, cy * 256 + fos_sin(a) * (R - 8) / 16, 2 * 256, SL_ACCENT, OPAQUE);
++ fos_disc(cv, cx * 256, cy * 256, 4 * 256, SL_ACCENT, OPAQUE);
++ ui_damage(cy - R - 6, cy + R + 6);
++}
++
++static const char *stage_name()
++{
++ switch (fos_dev_doing(dev))
++ {
++ case FOS_DEV_MIXING: return "Mixing the chemistry";
++ case FOS_DEV_DEVELOPING: return "Exposing the paper";
++ case FOS_DEV_FIXING: return "Developer";
++ case FOS_DEV_DRYING: return "Fixer " T_DOT " wash";
++ }
++ return "";
++}
++
++static void draw_panel()
++{
++ int x0 = 440, x1 = FOS_W - 12;
++ char b[96], eta[32];
++ ui_bg_restore(x0, 120, x1 - x0, 112);
++ ui_bg_restore(x0, 346, x1 - x0, 72);
++ if (finished)
++ {
++ fos_text_c(cv, &fos_font_xs, PANEL_CX, 150, "DONE", SL_ACCENT, OPAQUE, 64);
++ snprintf(b, sizeof(b), "%d roll%s", rolls_done, rolls_done == 1 ? "" : "s");
++ fos_text_c(cv, &fos_font_lg, PANEL_CX, 182, b, SL_TEXT, OPAQUE, 0);
++ snprintf(b, sizeof(b), "%d print%s", done_frames - failed_frames, done_frames - failed_frames == 1 ? "" : "s");
++ fos_text_c(cv, &fos_font_sm, PANEL_CX, 206, b, SL_TEXT2, OPAQUE, 0);
++ if (failed_frames)
++ {
++ snprintf(b, sizeof(b), "%d frame%s could not be developed", failed_frames, failed_frames == 1 ? "" : "s");
++ fos_text_c(cv, &fos_font_sm, PANEL_CX, 372, b, SL_TEXT2, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_xs, PANEL_CX, 394, last_error, SL_TEXT3, OPAQUE, 0);
++ }
++ }
++ else
++ {
++ snprintf(b, sizeof(b), "ROLL %03d", cur_roll);
++ fos_text_c(cv, &fos_font_xs, PANEL_CX, 150, b, SL_ACCENT, OPAQUE, 64);
++ fos_text_c(cv, &fos_font_lg, PANEL_CX, 182, fos_films[cur_film].name, SL_TEXT, OPAQUE, 0);
++ if (cur_frame) snprintf(b, sizeof(b), "Frame %d of %d", cur_frame, nframes);
++ else b[0] = 0;
++ fos_text_c(cv, &fos_font_sm, PANEL_CX, 206, b, SL_TEXT2, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_md, PANEL_CX, 376, dev ? stage_name() : "", SL_TEXT, OPAQUE, 0);
++ int left = total_frames - done_frames;
++ int spent = dev ? ui_now - frame_t0 : 0;
++ format_eta(eta, sizeof(eta), left, -(spent < ms_per_frame ? spent : ms_per_frame));
++ snprintf(b, sizeof(b), "%d to go " T_DOT " %s", left, eta);
++ fos_text_c(cv, &fos_font_sm, PANEL_CX, 400, b, SL_TEXT3, OPAQUE, 0);
++ }
++ ui_damage(120, 232);
++ ui_damage(346, 418);
++}
++
++static void develop_hints()
++{
++ ui_bg_restore(0, HINTS_Y, FOS_W, FOS_H - HINTS_Y);
++ int base = HINTS_Y + 23, x = 24;
++ if (finished)
++ {
++ x += ui_keycap(x, base, "SET") + 8;
++ x += fos_text(cv, &fos_font_sm, x, base - 1, "See the prints", SL_TEXT2, OPAQUE, 0) + 22;
++ x += ui_keycap(x, base, "MENU") + 8;
++ fos_text(cv, &fos_font_sm, x, base - 1, "Darkroom", SL_TEXT2, OPAQUE, 0);
++ }
++ else
++ {
++ x += ui_keycap(x, base, "MENU") + 8;
++ x += fos_text(cv, &fos_font_sm, x, base - 1, "Stop", SL_TEXT2, OPAQUE, 0) + 22;
++ fos_text_r(cv, &fos_font_sm, FOS_W - 24, base - 1, "Keep the camera on " T_DOT " faster with Darkrooms on a computer", SL_TEXT3, OPAQUE, 0);
++ }
++ ui_damage(HINTS_Y, FOS_H);
++}
++
++void develop_draw()
++{
++ static int was_finished = -1;
++ if (ui_clobbered)
++ {
++ ui_clobbered = 0;
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ ui_damage_all();
++ tray_dirty = line_dirty = panel_dirty = 1;
++ was_finished = -1;
++ }
++ if (tray_dirty) { draw_tray(); tray_dirty = 0; }
++ if (line_dirty) { draw_line(); line_dirty = 0; }
++ if (panel_dirty) { draw_panel(); panel_dirty = 0; }
++ if (was_finished != finished) { develop_hints(); was_finished = finished; }
++ /* the panel's stage name follows the work */
++ int doing = fos_dev_doing(dev);
++ if (dev && doing != last_doing) { last_doing = doing; draw_panel(); }
++ int p = dev ? fos_dev_progress(dev) : 0;
++ draw_dial(p > 0 ? p / 1000.0f : 0);
++ if (stop_sheet.x > 0.002f)
++ ui_sheet(stop_sheet.x, "Stop developing?", "The prints made so far are kept; the rest wait in the darkroom.", "Stop", "Keep going");
++}
++
++/* ================================================================ the prints */
++
++/* While a print is up the palette is the print's own: entries 1..240 its
++ * colours, the overlay drawn with the fixed ones (PX_*). Changing what is
++ * shown goes through black, so the screen never shows one picture in
++ * another's colours. */
++
++enum { PV_WAIT, PV_IN, PV_SHOW, PV_OUT, PV_NONE };
++enum { NEXT_LOAD, NEXT_BACK };
++
++static int pv_roll; /* index into rolls */
++static int pv_alone;
++static int pv_mode; /* 0 the contact sheet, 1 a frame */
++static int pv_cur; /* the frame (1..), also the sheet's cursor */
++static int pv_state, pv_t, pv_next;
++static int pv_info, pv_info_t;
++static int pv_frames; /* frames on the roll */
++static int pv_have; /* pv_print holds a picture */
++static int pv_dirty; /* the picture or the overlay changed */
++
++#define FADE_MS 180
++#define INFO_H 44
++
++static int prints_roll_at(int from, int dir)
++{
++ for (int i = from; i >= 0 && i < nrolls; i += dir)
++ if (has_prints(&rolls[i])) return i;
++ return -1;
++}
++
++static void pv_load()
++{
++ char path[64];
++ if (pv_have) fos_print_free(&pv_print);
++ pv_have = 0;
++ if (pv_roll < 0) return;
++ const struct fos_lab_roll *r = &rolls[pv_roll];
++ fos_lab_print_path(path, sizeof(path), r->number, pv_mode ? pv_cur : 0);
++ pv_have = fos_print_load(path, &pv_print);
++ if (!pv_have)
++ {
++ char msg[96];
++ snprintf(msg, sizeof(msg), "prints: can't load %s", path);
++ fos_port_log(msg);
++ }
++ pv_dirty = 1;
++}
++
++static void pv_palette(int k)
++{
++ static const uint8_t black[1][3] = { { 0, 0, 0 } };
++ if (pv_have) fos_port_photo((const uint8_t (*)[3]) pv_print.pal, FOS_PRINT_COLOURS, k);
++ else fos_port_photo(black, 1, k);
++}
++
++void prints_enter(int arg)
++{
++ pv_alone = (arg & PRINTS_ALONE) != 0;
++ arg &= ~PRINTS_ALONE;
++ pv_have = 0;
++ dark_mem();
++ rescan();
++ int i = arg ? roll_index(arg) : -1;
++ if (i < 0 || !has_prints(&rolls[i])) i = prints_roll_at(0, 1);
++ pv_roll = i;
++ pv_mode = 0;
++ pv_cur = 1;
++ pv_frames = i >= 0 ? rolls[i].shot : 0;
++ if (i >= 0) fos_lab_frames(rolls[i].number, pv_meta, FOS_MAX_FRAMES);
++ pv_have = 0;
++ pv_state = i >= 0 ? PV_WAIT : PV_NONE;
++ pv_t = 0;
++ pv_info = 1;
++ pv_info_t = 0;
++ pv_dirty = 1;
++ if (pv_state == PV_NONE)
++ {
++ ui_bg_plain();
++ ui_to_bg(1);
++ ui_status_bar("PRINTS");
++ fos_text_c(cv, &fos_font_lg, 360, 220, "No prints yet", C_TEXT, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_sm, 360, 248, "Develop a roll in the darkroom and its prints show here.", C_TEXT3, OPAQUE, 0);
++ struct hint h[] = { { "SET", "Darkroom" }, { "MENU", "Back" } };
++ ui_hints(h, 2);
++ ui_to_bg(0);
++ }
++ else memset(ui_bg, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
++}
++
++void prints_leave()
++{
++ if (pv_have) fos_print_free(&pv_print);
++ pv_have = 0;
++ if (pv_state != PV_NONE) fos_port_palette();
++}
++
++static void pv_go(int next)
++{
++ if (pv_state == PV_OUT) return;
++ pv_next = next;
++ pv_state = PV_OUT;
++ pv_t = 0;
++}
++
++static void pv_back()
++{
++ if (pv_alone) ui_leave();
++ else if (ui_from() == SCR_DARK || ui_from() == SCR_DEVELOP)
++ ui_go(SCR_DARK, pv_roll >= 0 ? rolls[pv_roll].number : 0, GO_FADE);
++ else ui_go(SCR_HOME, 2, GO_FADE);
++}
++
++void prints_key(int k)
++{
++ if (pv_state == PV_NONE)
++ {
++ if (k == FK_SET) ui_go(SCR_DARK, 0, GO_FADE);
++ else if (k == FK_MENU || k == FK_PLAY) { if (pv_alone) ui_leave(); else ui_go(SCR_HOME, 2, GO_FADE); }
++ return;
++ }
++ if (pv_state != PV_SHOW) return;
++ int n = pv_frames;
++ switch (k)
++ {
++ case FK_LEFT: case FK_RIGHT: case FK_UP: case FK_DOWN:
++ {
++ int d = k == FK_LEFT ? -1 : k == FK_RIGHT ? 1 : k == FK_UP ? -6 : 6;
++ if (pv_mode && (k == FK_UP || k == FK_DOWN)) break;
++ int to = pv_cur + d;
++ if (to < 1 || to > n) break;
++ pv_cur = to;
++ if (pv_mode) pv_go(NEXT_LOAD);
++ else pv_dirty = 1;
++ break;
++ }
++ case FK_WHEEL_L: case FK_WHEEL_R:
++ if (pv_mode)
++ {
++ int to = pv_cur + (k == FK_WHEEL_L ? -1 : 1);
++ if (to >= 1 && to <= n) { pv_cur = to; pv_go(NEXT_LOAD); }
++ }
++ else
++ {
++ /* the other rolls: newer to the left */
++ int to = prints_roll_at(pv_roll + (k == FK_WHEEL_L ? -1 : 1), k == FK_WHEEL_L ? -1 : 1);
++ if (to >= 0)
++ {
++ pv_roll = to;
++ pv_frames = rolls[to].shot;
++ pv_cur = 1;
++ fos_lab_frames(rolls[to].number, pv_meta, FOS_MAX_FRAMES);
++ pv_go(NEXT_LOAD);
++ }
++ }
++ break;
++ case FK_SET:
++ pv_mode = !pv_mode;
++ pv_go(NEXT_LOAD);
++ break;
++ case FK_INFO:
++ pv_info = !pv_info;
++ pv_info_t = 0;
++ pv_dirty = 1;
++ break;
++ case FK_MENU:
++ if (pv_mode) { pv_mode = 0; pv_go(NEXT_LOAD); }
++ else pv_go(NEXT_BACK);
++ break;
++ case FK_PLAY:
++ pv_go(NEXT_BACK);
++ break;
++ case FK_HOME:
++ pv_go(NEXT_BACK);
++ break;
++ }
++ if (pv_state == PV_SHOW && (k == FK_SET || k == FK_LEFT || k == FK_RIGHT)) pv_info_t = 0;
++ if (pv_dirty) ui_damage_all();
++}
++
++int prints_update(int dt)
++{
++ if (pv_state == PV_NONE) return 0;
++ pv_t += dt;
++ switch (pv_state)
++ {
++ case PV_WAIT:
++ if (!ui_settled()) return 1;
++ pv_load();
++ pv_palette(0);
++ pv_state = PV_IN;
++ pv_t = 0;
++ pv_info_t = 0;
++ return 1;
++ case PV_IN:
++ pv_palette(fos_clamp(pv_t * 256 / FADE_MS, 0, 256));
++ if (pv_t >= FADE_MS) pv_state = PV_SHOW;
++ return 1;
++ case PV_OUT:
++ pv_palette(fos_clamp(256 - pv_t * 256 / FADE_MS, 0, 256));
++ if (pv_t < FADE_MS) return 1;
++ if (pv_next == NEXT_LOAD)
++ {
++ pv_load();
++ pv_state = PV_IN;
++ pv_t = 0;
++ return 1;
++ }
++ /* back to the film OS's colours, on black */
++ pv_state = PV_NONE;
++ if (pv_have) fos_print_free(&pv_print);
++ pv_have = 0;
++ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
++ fos_port_present(cv->px, FOS_W, 0, FOS_H);
++ fos_port_palette();
++ memset(ui_bg, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
++ pv_back();
++ return 1;
++ case PV_SHOW:
++ /* the details go after a while on their own */
++ if (pv_info && pv_info_t < 3000)
++ {
++ pv_info_t += dt;
++ if (pv_info_t >= 3000) { pv_info = 0; pv_dirty = 1; ui_damage_all(); }
++ }
++ return 0;
++ }
++ return 0;
++}
++
++/* overlay text: coverage onto the panel greys, or the accent */
++static int pv_text(const struct fos_font *f, int x, int y, const char *s, int accent, int align)
++{
++ static const uint8_t grey[16] = { 0, PX_G1, PX_G1, PX_G2, PX_G2, PX_G3, PX_G3, PX_G3, PX_G4, PX_G4,
++ PX_G5, PX_G5, PX_G5, PX_WHITE, PX_WHITE, PX_WHITE };
++ static const uint8_t amber[16] = { 0, PX_G1, PX_G1, PX_G2, PX_AMBER2, PX_AMBER2, PX_AMBER2, PX_AMBER2,
++ PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER, PX_AMBER };
++ int w = fos_text_w(f, s, accent ? 40 : 0);
++ if (align == 1) x -= w / 2;
++ else if (align == 2) x -= w;
++ fos_text_map(cv->px, cv->pitch, FOS_W, FOS_H, f, x, y, s, accent ? amber : grey, accent ? 40 : 0);
++ return w;
++}
++
++static void sheet_cell(int i, int *x, int *y)
++{
++ int rows = (pv_frames + 5) / 6;
++ int y0 = (FOS_PRINT_H - rows * FOS_THUMB_H) / 2;
++ *x = (i % 6) * FOS_THUMB_W + FOS_SHEET_FX;
++ *y = y0 + (i / 6) * FOS_THUMB_H + FOS_SHEET_FY;
++}
++
++static void frame_rect(int x, int y, int w, int h, uint8_t ix)
++{
++ for (int k = 0; k < 2; k++)
++ {
++ memset(&cv->px[(y + k) * cv->pitch + x], ix, w);
++ memset(&cv->px[(y + h - 1 - k) * cv->pitch + x], ix, w);
++ }
++ for (int j = y; j < y + h; j++)
++ {
++ cv->px[j * cv->pitch + x] = cv->px[j * cv->pitch + x + 1] = ix;
++ cv->px[j * cv->pitch + x + w - 1] = cv->px[j * cv->pitch + x + w - 2] = ix;
++ }
++}
++
++void prints_draw()
++{
++ if (pv_state == PV_NONE)
++ {
++ if (ui_clobbered) { ui_clobbered = 0; ui_bg_restore(0, 0, FOS_W, FOS_H); ui_damage_all(); }
++ return;
++ }
++ if (pv_state == PV_WAIT)
++ {
++ /* black, in the film OS's colours, until the screen has settled */
++ memset(cv->px, fos_ix(FC(RAMP_GRAY, 0)), FOS_W * FOS_H);
++ ui_clobbered = 0;
++ return;
++ }
++ if (pv_state == PV_OUT) return; /* what is fading out stays as it was */
++ if (!pv_dirty && !ui_clobbered) return;
++ pv_dirty = 0;
++ ui_clobbered = 0;
++ /* the picture */
++ if (pv_have) memcpy(cv->px, pv_print.px, FOS_W * FOS_H);
++ else
++ {
++ memset(cv->px, PX_BLACK, FOS_W * FOS_H);
++ char b[64];
++ snprintf(b, sizeof(b), pv_mode ? "Frame %d was not developed" : "No contact sheet", pv_cur);
++ pv_text(&fos_font_md, 360, 244, b, 0, 1);
++ }
++ const struct fos_lab_roll *r = &rolls[pv_roll];
++ if (!pv_mode)
++ {
++ int x, y;
++ sheet_cell(pv_cur - 1, &x, &y);
++ frame_rect(x - 4, y - 4, FOS_SHEET_FW + 8, FOS_SHEET_FH + 8, PX_AMBER);
++ }
++ if (pv_info)
++ {
++ char b[96], c[64];
++ int y = FOS_H - INFO_H;
++ memset(&cv->px[y * cv->pitch], PX_PANEL, FOS_W * INFO_H);
++ memset(&cv->px[y * cv->pitch], PX_LINE, FOS_W);
++ const struct fos_lab_frame *m = pv_cur >= 1 && pv_cur <= FOS_MAX_FRAMES ? &pv_meta[pv_cur - 1] : 0;
++ snprintf(b, sizeof(b), "ROLL %03d", r->number);
++ int x = 20 + pv_text(&fos_font_xs, 20, y + 28, b, 1, 0);
++ snprintf(b, sizeof(b), "%s " T_DOT " frame %d of %d", fos_films[r->film].name, pv_cur, pv_frames);
++ x += 14 + pv_text(&fos_font_sm, x + 14, y + 28, b, 0, 0);
++ if (m && m->when[0])
++ {
++ snprintf(c, sizeof(c), "%s%s%s", m->when, m->fstop[0] ? " f/" : "", m->fstop);
++ pv_text(&fos_font_sm, x + 14, y + 28, c, 0, 0);
++ }
++ pv_text(&fos_font_xs, FOS_W - 20, y + 28, pv_mode ? "SET SHEET INFO HIDE" : "SET OPEN WHEEL ROLLS", 0, 2);
++ }
++ ui_damage_all();
++}
+diff --git a/src/fos_dev.c b/src/fos_dev.c
+new file mode 100644
+index 000000000..83672d714
+--- /dev/null
++++ b/src/fos_dev.c
+@@ -0,0 +1,2145 @@
++/* fos_dev: developing film in the camera, a frame at a time.
++ *
++ * The frame's CR2 is read a chunk at a time and its lossless JPEG decoded;
++ * every sample is added straight into the print pixel it falls in, so the
++ * 18 million sample mosaic becomes a 720 x 480 picture without ever being
++ * held: a box filter and the demosaic in one. The print then gets what
++ * the desktop darkroom (Darkrooms) does: daylight balance, the camera's colours
++ * to sRGB, the scanner's exposure, the film's balance, vignette and
++ * halation, the film's colour (a 3D table built from the same film model),
++ * and grain. Finally it is reduced to FOS_PRINT_COLOURS colours with error
++ * diffusion, its own palette, for the 8-bit screen.
++ *
++ * Everything runs in steps that stop after a time budget, so the film OS
++ * keeps animating on the same task: no threads, no locks.
++ */
++
++#include "fos.h"
++#include "fos_dev.h"
++#include "fos_jpeg.h"
++#include <math.h>
++#include <string.h>
++
++#ifdef FOS_DEV_TEST
++void fos_dev_test_sample(int x, int y, int v);
++#endif
++
++static int u16le(const uint8_t *p) { return p[0] | p[1] << 8; }
++static unsigned u32le(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (unsigned) p[3] << 24; }
++static void put32(uint8_t *p, uint32_t v) { p[0] = (uint8_t) v; p[1] = (uint8_t) (v >> 8); p[2] = (uint8_t) (v >> 16); p[3] = (uint8_t) (v >> 24); }
++
++/* ---------------------------------------------------------------- the film model */
++
++static const float LUMA[3] = { 0.2126f, 0.7152f, 0.0722f };
++static const float REF[7][3] = { /* red orange yellow green cyan blue magenta */
++ { 1, 0, 0 }, { 1, 0.5f, 0 }, { 1, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 1, 0, 1 } };
++#define PI_F 3.14159265f
++
++const struct fos_look *fos_look_of(const char *key)
++{
++ for (int i = 0; i < fos_nlooks; i++)
++ if (!strcmp(fos_looks[i].key, key)) return &fos_looks[i];
++ for (int i = 0; i < fos_nmore_looks; i++)
++ if (!strcmp(fos_more_looks[i].key, key)) return &fos_more_looks[i];
++ return &fos_looks[0];
++}
++
++static float dot3(const float a[3], const float b[3])
++{
++ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
++}
++
++static float hue_angle(int i)
++{
++ static float angle[7];
++ static int ready;
++ if (!ready)
++ {
++ for (int k = 0; k < 7; k++)
++ {
++ float y = dot3(REF[k], LUMA);
++ angle[k] = atan2f((REF[k][0] - y) / 1.5748f, (REF[k][2] - y) / 1.8556f);
++ }
++ ready = 1;
++ }
++ return angle[i];
++}
++
++static float wrap(float a)
++{
++ a = fmodf(a + PI_F, 2 * PI_F);
++ if (a < 0) a += 2 * PI_F;
++ return a - PI_F;
++}
++
++/* the characteristic curve: logistic in log2 exposure around mid grey */
++static float curve(float x, float slope, float pivot, float black, float white)
++{
++ float xx = log2f((x > 1e-6f ? x : 1e-6f) / 0.18f) - pivot;
++ float k = 4 * slope / (white - black);
++ return black + (white - black) / (1 + expf(-k * xx));
++}
++
++static void shift_hues(const struct fos_look *f, float rgb[3])
++{
++ float y = dot3(rgb, LUMA);
++ float cb = (rgb[2] - y) / 1.8556f, cr = (rgb[0] - y) / 1.5748f;
++ float h = atan2f(cr, cb), c = sqrtf(cb * cb + cr * cr);
++ float gate = c / 0.04f > 1 ? 1 : c / 0.04f;
++ float dh = 0, cm = 1;
++ const float sigma = 35 * PI_F / 180;
++ for (int i = 0; i < f->nhues; i++)
++ {
++ const struct fos_hue_shift *s = &f->hues[i];
++ float hs = hue_angle(s->from);
++ float d = wrap(h - hs) / sigma;
++ float w = expf(-0.5f * d * d) * gate;
++ if (s->from != s->to) dh += w * s->amount * wrap(hue_angle(s->to) - hs);
++ cm *= 1 + w * (s->chroma - 1);
++ }
++ h += dh;
++ c *= cm;
++ cb = c * cosf(h); cr = c * sinf(h);
++ rgb[0] = y + 1.5748f * cr;
++ rgb[2] = y + 1.8556f * cb;
++ rgb[1] = (y - LUMA[0] * rgb[0] - LUMA[2] * rgb[2]) / LUMA[1];
++}
++
++void fos_film_color(const struct fos_look *f, const float in[3], float out[3])
++{
++ if (f->mono)
++ {
++ float v = curve(dot3(in, f->mono_mix), f->contrast[0], f->pivot[0], f->black[0], f->white[0]);
++ out[0] = out[1] = out[2] = v;
++ return;
++ }
++ float y = dot3(in, LUMA), lin[3];
++ for (int c = 0; c < 3; c++)
++ {
++ lin[c] = y + (in[c] - y) * f->sat;
++ if (lin[c] < 0) lin[c] = 0;
++ out[c] = curve(lin[c], f->contrast[c], f->pivot[c], f->black[c], f->white[c]);
++ }
++ if (f->nhues) shift_hues(f, out);
++}
++
++/* linear sRGB of a blackbody at t kelvin (as cct_to_rgb in the lab) */
++static void cct_rgb(float t, float out[3])
++{
++ float x, y;
++ if (t <= 4000) x = -0.2661239e9f / (t * t * t) - 0.2343589e6f / (t * t) + 0.8776956e3f / t + 0.179910f;
++ else x = -3.0258469e9f / (t * t * t) + 2.1070379e6f / (t * t) + 0.2226347e3f / t + 0.240390f;
++ if (t <= 2222) y = -1.1063814f * x * x * x - 1.34811020f * x * x + 2.18555832f * x - 0.20219683f;
++ else if (t <= 4000) y = -0.9549476f * x * x * x - 1.37418593f * x * x + 2.09137015f * x - 0.16748867f;
++ else y = 3.0817580f * x * x * x - 5.87338670f * x * x + 3.75112997f * x - 0.37001483f;
++ float X = x / y, Y = 1, Z = (1 - x - y) / y;
++ out[0] = 3.2406f * X - 1.5372f * Y - 0.4986f * Z;
++ out[1] = -0.9689f * X + 1.8758f * Y + 0.0415f * Z;
++ out[2] = 0.0557f * X - 0.2040f * Y + 1.0570f * Z;
++}
++
++/* ---------------------------------------------------------------- the film's table */
++
++/* The film's colour as a 3D table over Cineon log code (the density of a
++ * film scan): the same thing `lut.py export` writes, and as close to the
++ * lab's model. Building it takes the camera a few seconds, so it is kept
++ * in memory and on the card. */
++#define GRID 33
++#define NGRID (GRID * GRID * GRID)
++#define LOOK_MODEL 1 /* bump when fos_film_color changes */
++#define CIN_BLACK 0.0108f /* 10^((95 - 685) * 0.002 / 0.6) */
++
++static struct
++{
++ uint8_t lut[NGRID][3];
++ /* linear (4096 = 1.0) -> grid position (1/256) of its Cineon code:
++ * 0..4095 one by one, then up to 65535 in steps of 16 */
++ uint16_t cin[4096 + 3841];
++} *tab;
++static int lut_film = -1, lut_built; /* lut_built: grid points done */
++static char cache_dir[128];
++
++void fos_dev_cache(const char *dir)
++{
++ snprintf(cache_dir, sizeof(cache_dir), "%s", dir ? dir : "");
++}
++
++void fos_dev_release()
++{
++ fos_port_free(tab);
++ tab = 0;
++ lut_film = -1;
++}
++
++static float cineon_decode(float v)
++{
++ float x = powf(10, (v * 1023 - 685) / 300);
++ return (x - CIN_BLACK) / (1 - CIN_BLACK);
++}
++
++static int cineon_encode(float lin)
++{
++ float x = (lin > 0 ? lin : 0) * (1 - CIN_BLACK) + CIN_BLACK;
++ float v = (685 + 300 * log10f(x)) / 1023;
++ return v < 0 ? 0 : v > 1 ? 65535 : (int) (v * 65535 + 0.5f);
++}
++
++static int tables_ready()
++{
++ if (tab) return 1;
++ tab = fos_port_alloc(sizeof(*tab));
++ if (!tab) return 0;
++ for (int i = 0; i < 4096 + 3841; i++)
++ {
++ int code = cineon_encode((i < 4096 ? i : 4096 + (i - 4096) * 16) / 4096.0f);
++ tab->cin[i] = (uint16_t) ((code * ((GRID - 1) * 256)) >> 16);
++ }
++ lut_film = -1;
++ return 1;
++}
++
++/* linear 0..65535 (4096 = 1.0, up to 16) -> grid position in 1/256 */
++FOS_INLINE int cin_pos(const uint16_t *cin, int lin)
++{
++ return cin[lin < 4096 ? lin : lin > 65535 ? 4096 + 3840 : 4096 + ((lin - 4096) >> 4)];
++}
++
++/* the look's numbers, so a table on the card is only used for the same look */
++/* the look's numbers and its film, so a table on the card is only used
++ * for the same look (tools/genfilms.py works it out the same way for the
++ * tables it bakes from LUTs) */
++static uint32_t look_hash(const struct fos_look *f)
++{
++ const uint8_t *p = (const uint8_t *) &f->balance;
++ const uint8_t *e = (const uint8_t *) f->mono_mix + sizeof(f->mono_mix);
++ uint32_t h = 2166136261u ^ (GRID * 256 + LOOK_MODEL);
++ for (const char *k = f->key; *k; k++) h = (h ^ (uint8_t) *k) * 16777619u;
++ for (; p < e; p++) h = (h ^ *p) * 16777619u;
++ return h;
++}
++
++static void *lut_file(int film, int write)
++{
++ if (!cache_dir[0]) return 0;
++ char path[160];
++ snprintf(path, sizeof(path), "%s/LOOK%02d.LUT", cache_dir, film);
++ return fos_port_open(path, write);
++}
++
++static int lut_load(const struct fos_look *f, int film)
++{
++ void *fp = lut_file(film, 0);
++ if (!fp) return 0;
++ uint8_t h[8];
++ int ok = fos_port_read(fp, h, 8) == 8 && !memcmp(h, "FOL1", 4) && u32le(h + 4) == look_hash(f)
++ && fos_port_read(fp, tab->lut, sizeof(tab->lut)) == (int) sizeof(tab->lut);
++ fos_port_close(fp);
++ return ok;
++}
++
++static void lut_save(const struct fos_look *f, int film)
++{
++ void *fp = lut_file(film, 1);
++ if (!fp) return;
++ uint8_t h[8] = { 'F', 'O', 'L', '1' };
++ put32(h + 4, look_hash(f));
++ fos_port_write(fp, h, 8);
++ fos_port_write(fp, tab->lut, sizeof(tab->lut));
++ fos_port_close(fp);
++}
++
++/* build up to `count` more grid points; 1 when the table is complete */
++static __attribute__((noinline)) int lut_build(const struct fos_look *f, int film, int count)
++{
++ if (lut_film != film)
++ {
++ lut_film = film;
++ lut_built = lut_load(f, film) ? NGRID : 0;
++ }
++ if (lut_built >= NGRID) return 1;
++ for (; lut_built < NGRID && count-- > 0; lut_built++)
++ {
++ int i = lut_built, r = i % GRID, g = (i / GRID) % GRID, b = i / (GRID * GRID);
++ float lin[3] = { cineon_decode(r / (float) (GRID - 1)), cineon_decode(g / (float) (GRID - 1)),
++ cineon_decode(b / (float) (GRID - 1)) }, out[3];
++ fos_film_color(f, lin, out);
++ for (int c = 0; c < 3; c++)
++ {
++ int v = (int) (out[c] * 255 + 0.5f);
++ tab->lut[i][c] = (uint8_t) (v < 0 ? 0 : v > 255 ? 255 : v);
++ }
++ }
++ if (lut_built < NGRID) return 0;
++ lut_save(f, film);
++ return 1;
++}
++
++/* the film's table, into the cache now: the build puts every film's on
++ * the card, so the camera never has to mix one */
++int fos_dev_table(int film)
++{
++ if (!tables_ready()) return 0;
++ film = fos_clamp(film, 0, fos_nfilms - 1);
++ lut_film = -1;
++ while (!lut_build(fos_look_of(fos_films[film].key), film, NGRID)) {}
++ return 1;
++}
++
++/* tetrahedral lookup at grid positions in 1/256: the four corners of the
++ * cell's tetrahedron the point is in, weighted */
++FOS_INLINE void lut_apply(const uint8_t (*lut)[3], int pr, int pg, int pb, uint8_t out[3])
++{
++ int fr = pr & 255, fg = pg & 255, fb = pb & 255;
++ const uint8_t *p = lut[((pb >> 8) * GRID + (pg >> 8)) * GRID + (pr >> 8)];
++ const int R = 3, G = 3 * GRID, B = 3 * GRID * GRID;
++ int o1, o2, w0, w1, w2, w3;
++ if (fr >= fg)
++ {
++ if (fg >= fb) { o1 = R; o2 = R + G; w0 = 256 - fr; w1 = fr - fg; w2 = fg - fb; w3 = fb; }
++ else if (fr >= fb) { o1 = R; o2 = R + B; w0 = 256 - fr; w1 = fr - fb; w2 = fb - fg; w3 = fg; }
++ else { o1 = B; o2 = R + B; w0 = 256 - fb; w1 = fb - fr; w2 = fr - fg; w3 = fg; }
++ }
++ else
++ {
++ if (fb >= fg) { o1 = B; o2 = G + B; w0 = 256 - fb; w1 = fb - fg; w2 = fg - fr; w3 = fr; }
++ else if (fb >= fr) { o1 = G; o2 = G + B; w0 = 256 - fg; w1 = fg - fb; w2 = fb - fr; w3 = fr; }
++ else { o1 = G; o2 = R + G; w0 = 256 - fg; w1 = fg - fr; w2 = fr - fb; w3 = fb; }
++ }
++ const int o3 = R + G + B;
++ for (int c = 0; c < 3; c++, p++)
++ out[c] = (uint8_t) ((w0 * p[0] + w1 * p[o1] + w2 * p[o2] + w3 * p[o3] + 128) >> 8);
++}
++
++/* ---------------------------------------------------------------- the frame */
++
++#define CHUNK (192 * 1024) /* read from the card at a time */
++#define GW (FOS_PRINT_W / 4) /* the halation's grid */
++#define GH (FOS_PRINT_H / 4)
++#define FAST_BITS 9
++#define DIFF_BITS 11
++#define UNPACK 2688 /* samples decoded at a time: an EOS M slice's row */
++
++enum { ST_OPEN, ST_DECODE, ST_KEY, ST_EXPOSE, ST_GLOW, ST_FINISH, ST_JPEG, ST_QUANT, ST_DITHER, ST_WRITE, ST_DONE, ST_FAIL };
++
++struct huff
++{
++ /* a code and its difference bits together, when they fit in
++ * DIFF_BITS: difference << 4 | bits used; 0 = the slower way (small,
++ * so it stays in the camera's data cache) */
++ int16_t fastd[1 << DIFF_BITS];
++ uint16_t fast[1 << FAST_BITS]; /* len << 8 | symbol, 0 = longer than FAST_BITS */
++ int maxcode[18], valptr[17], mincode[17];
++ uint8_t vals[256];
++};
++
++struct box { int lo[3], hi[3]; long count; };
++
++struct fos_dev
++{
++ char cr2[128], print[128], when[20], fstop[8];
++ char jpeg[160]; /* the full-colour frame as a JPEG too, or "" */
++ int film, frame;
++ const struct fos_look *look;
++ int stage, row; /* row: progress through a per-row stage */
++ const char *err;
++ char errbuf[48];
++ void *f;
++
++ /* the file, destuffed into whole bytes of entropy data */
++ uint8_t *buf;
++ const uint8_t *bp, *be, *safe, *ff; /* the next byte, the end, see fill() */
++ int file_pos, file_end;
++ uint32_t bitbuf;
++ int vbits;
++
++ /* the raw */
++ int raw_w, raw_h, orient;
++ int crop_l, crop_t, crop_w, crop_h, ob_l, ob_r;
++ int slices[3];
++ int clrs, wide, high, bits, psv;
++ struct huff *huff[4];
++ struct huff tables[4];
++
++ /* decoding */
++ int jcol, comp, vpred[4];
++ uint16_t samples[4 + UNPACK];
++ int sl, sx, sy, sw, sx0; /* where the next sample goes: slice, column in it, row */
++ long done, total;
++
++ /* the print being built */
++ int ow, oh, ox0; /* picture size and its left edge on the print */
++ int32_t *rowoff; /* raw row -> its place in the print's sums, or < 0 */
++ uint16_t *seg_of, *seg_x0; /* raw column -> its segment; a segment's first column */
++ int32_t *seg_off; /* segment -> its place in the print's sums */
++ uint8_t *seg_desc; /* a row's pieces: pairs (<= 4) | 0x40 a last even column | 0x80 an odd first */
++ int32_t *desc_off; /* a piece's place in the print's sums */
++ int32_t *seg_piece; /* a segment's first piece */
++ uint8_t *rowob, *colob; /* optical black */
++ uint16_t *ne_r, *no_r, *ne_c, *no_c; /* raw rows / columns per print line, even and odd */
++ int rows_axis_x; /* raw rows run along the print's x (portrait) */
++ uint32_t *sums; /* 3 per print pixel */
++ int64_t black_sum;
++ long black_n;
++ int black16; /* black level, 1/16 raw units */
++ int pre[3]; /* daylight balance and white level, raw/16 -> 1/4096, << 14 */
++ int mat[3][3]; /* camera -> linear sRGB, 1/4096 */
++ int mul[3]; /* exposure and film balance, 1/4096 */
++ uint16_t *lin; /* in place of sums: linear sRGB, 4096 = 1.0 */
++ int32_t *glow; /* halation, a quarter of the print each way */
++ uint8_t *rgb; /* the finished print, RGB */
++ uint8_t thumb[FOS_THUMB_W * FOS_THUMB_H * 3];
++ int16_t vig_x[FOS_PRINT_W], vig_y[FOS_PRINT_H];
++ uint8_t gx[FOS_PRINT_W], fx[FOS_PRINT_W]; /* glow cell and weight (1/8) per column */
++ unsigned seed;
++ uint16_t pos[3 * FOS_PRINT_W]; /* a row's positions on the film's grid */
++
++ /* palette */
++ uint32_t *hist;
++ uint8_t *inv;
++ uint8_t pal[FOS_PRINT_COLOURS][3];
++ int npal;
++ struct box boxes[FOS_PRINT_COLOURS];
++ uint8_t by_green[FOS_PRINT_COLOURS]; /* the palette in order of green */
++ int16_t *err_rows;
++ uint8_t *idx;
++};
++
++/* The sensor's colours, XYZ -> camera, and its white level: LibRaw's
++ * colordata.cpp (the Adobe matrices), per camera the fork is built for.
++ * The EOS M's is the default (and the 650D's, 700D's and 100D's: one sensor). */
++#define M3(a, b, c, d, e, f, g, h, i) { { a / 10000.f, b / 10000.f, c / 10000.f }, { d / 10000.f, e / 10000.f, f / 10000.f }, \
++ { g / 10000.f, h / 10000.f, i / 10000.f } }
++#if defined(CONFIG_6D) || defined(CONFIG_70D)
++static const float XYZ_CAM[3][3] = M3(7034, -804, -1014, -4420, 12564, 2058, -851, 1994, 5758);
++#elif defined(CONFIG_5D3)
++static const float XYZ_CAM[3][3] = M3(6722, -635, -963, -4287, 12460, 2028, -908, 2162, 5668);
++#elif defined(CONFIG_5D2)
++static const float XYZ_CAM[3][3] = M3(4716, 603, -830, -7798, 15474, 2480, -1496, 1937, 6651);
++#elif defined(CONFIG_7D)
++static const float XYZ_CAM[3][3] = M3(6844, -996, -856, -3876, 11761, 2396, -593, 1772, 6198);
++#elif defined(CONFIG_50D)
++static const float XYZ_CAM[3][3] = M3(4920, 616, -593, -6493, 13964, 2784, -1774, 3178, 7005);
++#elif defined(CONFIG_60D)
++static const float XYZ_CAM[3][3] = M3(6719, -994, -925, -4408, 12426, 2211, -887, 2129, 6051);
++#elif defined(CONFIG_500D)
++static const float XYZ_CAM[3][3] = M3(4763, 712, -646, -6821, 14399, 2640, -1921, 3276, 6561);
++#elif defined(CONFIG_550D)
++static const float XYZ_CAM[3][3] = M3(6941, -1164, -857, -3825, 11597, 2534, -416, 1540, 6039);
++#elif defined(CONFIG_600D)
++static const float XYZ_CAM[3][3] = M3(6461, -907, -882, -4300, 12184, 2378, -819, 1944, 5931);
++#elif defined(CONFIG_1100D)
++static const float XYZ_CAM[3][3] = M3(6444, -904, -893, -4563, 12308, 2535, -903, 2016, 6728);
++#else /* EOS M, 100D, 650D, 700D */
++static const float XYZ_CAM[3][3] = { { 0.6602f, -0.0841f, -0.0939f }, { -0.4472f, 1.2458f, 0.2247f }, { -0.0975f, 0.2039f, 0.6148f } };
++#endif
++static const float RGB_XYZ[3][3] = { { 0.4124564f, 0.3575761f, 0.1804375f }, { 0.2126729f, 0.7151522f, 0.0721750f },
++ { 0.0193339f, 0.1191920f, 0.9503041f } };
++/* raw value of a full pixel (LibRaw's maximum); the EOS M's measured 13600 */
++#if defined(CONFIG_6D)
++#define WHITE_LEVEL 15490
++#elif defined(CONFIG_70D)
++#define WHITE_LEVEL 15303
++#elif defined(CONFIG_5D3)
++#define WHITE_LEVEL 15488
++#elif defined(CONFIG_5D2)
++#define WHITE_LEVEL 15600
++#elif defined(CONFIG_7D) || defined(CONFIG_600D) || defined(CONFIG_1100D)
++#define WHITE_LEVEL 13584
++#elif defined(CONFIG_50D)
++#define WHITE_LEVEL 15763
++#elif defined(CONFIG_60D)
++#define WHITE_LEVEL 12279
++#elif defined(CONFIG_500D)
++#define WHITE_LEVEL 13433
++#elif defined(CONFIG_550D)
++#define WHITE_LEVEL 15831
++#elif defined(CONFIG_700D)
++#define WHITE_LEVEL 15360
++#elif defined(CONFIG_100D)
++#define WHITE_LEVEL 13583
++#elif defined(CONFIG_650D)
++#define WHITE_LEVEL 13645
++#else
++#define WHITE_LEVEL 13600
++#endif
++
++static int fail(struct fos_dev *d, const char *why)
++{
++ d->err = why;
++ d->stage = ST_FAIL;
++ return -1;
++}
++
++/* a buffer couldn't be had: which one, for the log */
++static int fail_mem(struct fos_dev *d, int size)
++{
++ snprintf(d->errbuf, sizeof(d->errbuf), "out of memory (%d KB)", (size + 1023) / 1024);
++ return fail(d, d->errbuf);
++}
++
++/* ---- reading */
++
++static int read_at(struct fos_dev *d, int offset, void *buf, int size)
++{
++ if (fos_port_seek(d->f, offset) < 0) return 0;
++ return fos_port_read(d->f, buf, size) == size;
++}
++
++
++/* the value of TIFF tag `tag` in the IFD at `ifd` (offset for anything
++ * longer than 4 bytes); -1 when absent */
++static long tiff_tag(struct fos_dev *d, unsigned ifd, int tag, int *count)
++{
++ uint8_t n2[2], e[12];
++ if (!read_at(d, (int) ifd, n2, 2)) return -1;
++ int n = u16le(n2);
++ for (int i = 0; i < n && i < 400; i++)
++ {
++ if (!read_at(d, (int) ifd + 2 + 12 * i, e, 12)) return -1;
++ if (u16le(e) != tag) continue;
++ int type = u16le(e + 2);
++ unsigned cnt = u32le(e + 4);
++ if (count) *count = (int) cnt;
++ if (type == 3 && cnt <= 2) return u16le(e + 8);
++ return (long) u32le(e + 8);
++ }
++ return -1;
++}
++
++static int parse_tiff(struct fos_dev *d)
++{
++ uint8_t h[16];
++ if (!read_at(d, 0, h, 16)) return fail(d, "can't read the file");
++ if (h[0] != 'I' || h[1] != 'I' || h[8] != 'C' || h[9] != 'R') return fail(d, "not a CR2 file");
++ unsigned ifd0 = u32le(h + 4), raw_ifd = u32le(h + 12);
++ long o = tiff_tag(d, ifd0, 0x0112, 0);
++ d->orient = o > 0 ? (int) o : 1;
++
++ /* the sensor's picture area from the Canon maker note, if it says */
++ d->crop_l = -1;
++ long exif = tiff_tag(d, ifd0, 0x8769, 0);
++ long mn = exif > 0 ? tiff_tag(d, (unsigned) exif, 0x927C, 0) : -1;
++ int cnt = 0;
++ long si = mn > 0 ? tiff_tag(d, (unsigned) mn, 0x00E0, &cnt) : -1;
++ if (si > 0 && cnt >= 13)
++ {
++ uint8_t s[26];
++ if (read_at(d, (int) si, s, 26))
++ {
++ d->crop_l = u16le(s + 10); d->crop_t = u16le(s + 12);
++ d->crop_w = u16le(s + 14) - d->crop_l + 1; d->crop_h = u16le(s + 16) - d->crop_t + 1;
++ d->ob_l = u16le(s + 18); d->ob_r = u16le(s + 22);
++ }
++ }
++
++ long off = tiff_tag(d, raw_ifd, 0x0111, 0);
++ if (off <= 0) return fail(d, "no RAW in this file");
++ d->file_pos = (int) off;
++ long len = tiff_tag(d, raw_ifd, 0x0117, 0);
++ d->file_end = len > 0 ? (int) (off + len) : 0x7fffffff;
++ d->slices[0] = 0;
++ long sl = tiff_tag(d, raw_ifd, 0xC640, &cnt);
++ if (sl > 0 && cnt == 3)
++ {
++ uint8_t s[6];
++ if (read_at(d, (int) sl, s, 6))
++ {
++ d->slices[0] = u16le(s); d->slices[1] = u16le(s + 2); d->slices[2] = u16le(s + 4);
++ }
++ }
++ return 1;
++}
++
++static int build_huff(struct huff *h, const uint8_t *counts, const uint8_t *vals, int nvals)
++{
++ memset(h, 0, sizeof(*h));
++ memcpy(h->vals, vals, nvals > 256 ? 256 : nvals);
++ int code = 0, k = 0;
++ for (int len = 1; len <= 16; len++)
++ {
++ h->valptr[len] = k;
++ h->mincode[len] = code;
++ for (int i = 0; i < counts[len - 1]; i++, k++, code++)
++ if (len <= FAST_BITS)
++ {
++ int shift = FAST_BITS - len;
++ for (int j = 0; j < 1 << shift; j++)
++ h->fast[(code << shift) | j] = (uint16_t) (len << 8 | vals[k]);
++ }
++ h->maxcode[len] = counts[len - 1] ? code - 1 : -1;
++ code <<= 1;
++ }
++ h->maxcode[17] = 0x7fffffff;
++ /* the common short code and difference in one lookup */
++ for (int i = 0; i < 1 << DIFF_BITS; i++)
++ {
++ int e = h->fast[i >> (DIFF_BITS - FAST_BITS)], len = e >> 8, s = e & 0xFF;
++ if (!e || s == 16 || len + s > DIFF_BITS) continue;
++ int diff = 0;
++ if (s)
++ {
++ diff = (i >> (DIFF_BITS - len - s)) & ((1 << s) - 1);
++ if (!(diff >> (s - 1))) diff -= (1 << s) - 1;
++ }
++ h->fastd[i] = (int16_t) (diff * 16 + len + s);
++ }
++ return k == nvals;
++}
++
++/* the lossless JPEG's header, up to the scan */
++static int parse_ljpeg_in(struct fos_dev *d, uint8_t *hdr, int size);
++
++static int parse_ljpeg(struct fos_dev *d)
++{
++ const int HDR = 2048;
++ uint8_t *hdr = fos_port_alloc(HDR); /* not on the film OS task's small stack */
++ if (!hdr) return fail_mem(d, HDR);
++ int r = parse_ljpeg_in(d, hdr, HDR);
++ fos_port_free(hdr);
++ return r;
++}
++
++static int parse_ljpeg_in(struct fos_dev *d, uint8_t *hdr, int size)
++{
++ int n = d->file_end - d->file_pos < size ? d->file_end - d->file_pos : size;
++ if (n < 64 || !read_at(d, d->file_pos, hdr, n)) return fail(d, "can't read the RAW");
++ if (hdr[0] != 0xFF || hdr[1] != 0xD8) return fail(d, "the RAW is not a lossless JPEG");
++ int p = 2, have_sof = 0, ntab = 0;
++ while (p + 4 <= n)
++ {
++ if (hdr[p] != 0xFF) return fail(d, "broken RAW header");
++ int tag = hdr[p + 1], len = hdr[p + 2] << 8 | hdr[p + 3];
++ const uint8_t *s = hdr + p + 4;
++ if (p + 2 + len > n) return fail(d, "RAW header too long");
++ if (tag == 0xC3)
++ {
++ d->bits = s[0];
++ d->high = s[1] << 8 | s[2];
++ d->wide = s[3] << 8 | s[4];
++ d->clrs = s[5];
++ if (((s[7] >> 4) * (s[7] & 15) - 1) & 3) return fail(d, "sRAW / mRAW: shoot full RAW");
++ have_sof = 1;
++ }
++ else if (tag == 0xC4)
++ {
++ for (const uint8_t *q = s; q < s + len - 2;)
++ {
++ int id = *q++;
++ if (id & ~3) return fail(d, "unexpected Huffman table");
++ int total = 0;
++ for (int i = 0; i < 16; i++) total += q[i];
++ if (!build_huff(&d->tables[id], q, q + 16, total)) return fail(d, "bad Huffman table");
++ if (id + 1 > ntab) ntab = id + 1;
++ q += 16 + total;
++ }
++ }
++ else if (tag == 0xDD && (s[0] | s[1]))
++ return fail(d, "unsupported RAW: restart markers");
++ else if (tag == 0xDA)
++ {
++ d->psv = s[1 + s[0] * 2];
++ d->bits -= s[3 + s[0] * 2] & 15;
++ d->file_pos += p + 2 + len;
++ if (!have_sof || !ntab) return fail(d, "RAW header incomplete");
++ /* LibRaw's rule, which Canon follows: component c takes table c,
++ * or the last one defined */
++ for (int c = 0; c < 4; c++) d->huff[c] = &d->tables[c < ntab ? c : ntab - 1];
++ /* the same table twice (the EOS M's): one copy, half the cache */
++ for (int c = 1; c < 4; c++)
++ if (d->huff[c] != d->huff[0] && !memcmp(d->huff[c], d->huff[0], sizeof(struct huff))) d->huff[c] = d->huff[0];
++ if (d->clrs < 1 || d->clrs > 4 || d->bits < 8 || d->bits > 16) return fail(d, "unsupported RAW layout");
++ if (d->psv != 1) return fail(d, "unsupported RAW predictor");
++ return 1;
++ }
++ p += 2 + len;
++ }
++ return fail(d, "RAW header not found");
++}
++
++/* the next chunk of the file after the keep bytes not yet used (at bp);
++ * past the end, zeros. The JPEG's byte stuffing stays in: the bit reader
++ * takes it out as it goes, rather than in a pass of its own. Returns the
++ * buffer's length. */
++static int refill(struct fos_dev *d, const uint8_t *bp, int keep)
++{
++ memmove(d->buf, bp, keep);
++ int n = d->file_end - d->file_pos;
++ if (n > CHUNK) n = CHUNK;
++ if (n > 0 && fos_port_seek(d->f, d->file_pos) >= 0 && (n = fos_port_read(d->f, d->buf + keep, n)) > 0)
++ d->file_pos += n;
++ else
++ {
++ d->file_pos = d->file_end;
++ n = 8;
++ memset(d->buf + keep, 0, 8);
++ }
++ return keep + n;
++}
++
++/* ---- the print's geometry: which raw rows and columns land where */
++
++static int setup_maps(struct fos_dev *d)
++{
++ d->raw_w = d->wide * d->clrs;
++ d->raw_h = d->high;
++ if (!(d->clrs & 1) && d->raw_w > 4 * d->raw_h)
++ {
++ /* some cameras store the sensor as a frame twice as wide and half
++ * as high (as dcraw and LibRaw read it): the samples run the same */
++ d->raw_w /= 2;
++ d->raw_h *= 2;
++ }
++ if (d->slices[0] && d->slices[0] * d->slices[1] + d->slices[2] != d->raw_w)
++ return fail(d, "RAW slices don't add up");
++ if (d->crop_l < 0 || d->crop_l + d->crop_w > d->raw_w || d->crop_t + d->crop_h > d->raw_h || d->crop_w < 64)
++ {
++ /* no sensor info: the EOS M's picture area, scaled to this sensor */
++ d->crop_l = d->raw_w * 84 / 5280; d->crop_t = d->raw_h * 64 / 3528;
++ d->crop_w = d->raw_w - d->crop_l - d->raw_w * 12 / 5280;
++ d->crop_h = d->raw_h - d->crop_t - d->raw_h * 8 / 3528;
++ d->ob_l = 0; d->ob_r = d->crop_l - 12;
++ }
++ if (d->ob_r - d->ob_l < 16)
++ {
++ /* No black mask given (the EOS M gives none): the masked columns
++ * left of the picture, well clear of it. The picture area Canon
++ * names starts at 84, but light already reaches column 72. */
++ d->ob_l = 0; d->ob_r = d->crop_l - 1;
++ }
++ if (d->ob_r > d->crop_l - 20) d->ob_r = d->crop_l - 20;
++ int portrait = d->orient == 6 || d->orient == 8;
++ d->rows_axis_x = portrait;
++ d->oh = FOS_PRINT_H;
++ d->ow = portrait ? FOS_PRINT_H * FOS_PRINT_H / FOS_PRINT_W : FOS_PRINT_W;
++ d->ox0 = (FOS_PRINT_W - d->ow) / 2;
++
++ d->rowoff = fos_port_alloc(d->raw_h * 4);
++ d->seg_of = fos_port_alloc(d->raw_w * 2);
++ d->seg_x0 = fos_port_alloc((FOS_PRINT_W + 1) * 2);
++ d->seg_off = fos_port_alloc(FOS_PRINT_W * 4);
++ d->rowob = fos_port_alloc(d->raw_h);
++ d->colob = fos_port_alloc(d->raw_w);
++ d->ne_r = fos_port_alloc(FOS_PRINT_W * 2 * 2);
++ d->ne_c = fos_port_alloc(FOS_PRINT_W * 2 * 2);
++ if (!d->rowoff || !d->seg_of || !d->seg_x0 || !d->seg_off || !d->rowob || !d->colob || !d->ne_r || !d->ne_c)
++ return fail_mem(d, d->raw_w * 10 + d->raw_h * 5);
++ d->no_r = d->ne_r + FOS_PRINT_W;
++ d->no_c = d->ne_c + FOS_PRINT_W;
++ memset(d->ne_r, 0, FOS_PRINT_W * 4);
++ memset(d->ne_c, 0, FOS_PRINT_W * 4);
++
++ /* raw rows: across the picture's height (landscape) or width (portrait) */
++ int rlen = portrait ? d->ow : d->oh, clen = portrait ? d->oh : d->ow;
++ int rflip = d->orient == 6 || d->orient == 3, cflip = d->orient == 8 || d->orient == 3;
++ const int32_t OUT = -1;
++ for (int y = 0; y < d->raw_h; y++)
++ {
++ int a = y - d->crop_t;
++ d->rowob[y] = a >= 0 && a < d->crop_h;
++ if (a < 0 || a >= d->crop_h) { d->rowoff[y] = OUT; continue; }
++ int o = (int) ((long) a * rlen / d->crop_h);
++ if (rflip) o = rlen - 1 - o;
++ if (y & 1) d->no_r[o]++; else d->ne_r[o]++;
++ d->rowoff[y] = 3 * (portrait ? d->ox0 + o : o * FOS_PRINT_W);
++ }
++ /* raw columns: segment k of them (in raw order) makes print line o */
++ for (int k = 0; k <= clen; k++) d->seg_x0[k] = (uint16_t) d->crop_w;
++ for (int x = 0; x < d->raw_w; x++)
++ {
++ int a = x - d->crop_l;
++ d->colob[x] = x >= d->ob_l + 4 && x <= d->ob_r - 4;
++ d->seg_of[x] = 0;
++ if (a < 0 || a >= d->crop_w) continue;
++ int k = (int) ((long) a * clen / d->crop_w);
++ if (d->seg_x0[k] > a) d->seg_x0[k] = (uint16_t) a;
++ d->seg_of[x] = (uint16_t) k;
++ int o = cflip ? clen - 1 - k : k;
++ if (x & 1) d->no_c[o]++; else d->ne_c[o]++;
++ d->seg_off[k] = 3 * (portrait ? o * FOS_PRINT_W : d->ox0 + o);
++ }
++ for (int k = 0; k <= clen; k++) d->seg_x0[k] = (uint16_t) (d->seg_x0[k] + d->crop_l);
++ /* the segments' shapes, the same on every row, for sum_row: when the
++ * samples fit word halves four times and every segment has two */
++ if (d->bits <= 14 && d->crop_w >= 2 * clen && d->crop_w <= 32 * clen)
++ {
++ d->seg_desc = fos_port_alloc(4 * clen);
++ d->desc_off = fos_port_alloc(4 * clen * 4);
++ d->seg_piece = fos_port_alloc((clen + 1) * 4);
++ if (!d->seg_desc || !d->desc_off || !d->seg_piece) return fail_mem(d, 24 * clen);
++ int n = 0;
++ for (int k = 0; k < clen; k++)
++ {
++ d->seg_piece[k] = n;
++ int s0 = d->seg_x0[k], len = d->seg_x0[k + 1] - s0, odd = s0 & 1, pairs = (len - odd) >> 1;
++ /* four pairs at most a piece; a longer segment (portrait) in more */
++ do
++ {
++ int p = pairs < 4 ? pairs : 4;
++ pairs -= p;
++ d->seg_desc[n] = (uint8_t) (p | (!pairs && ((len - odd) & 1)) << 6 | odd << 7);
++ d->desc_off[n++] = d->seg_off[k];
++ odd = 0;
++ }
++ while (pairs > 0);
++ }
++ d->seg_piece[clen] = n;
++ }
++
++ d->sums = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
++ if (!d->sums) return fail_mem(d, FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
++ memset(d->sums, 0, FOS_PRINT_W * FOS_PRINT_H * 3 * 4);
++ d->total = (long) d->raw_w * d->raw_h;
++ d->sl = 0; d->sx = 0; d->sy = 0; d->sx0 = 0;
++ d->sw = d->slices[0] ? d->slices[1] : d->raw_w;
++ for (int c = 0; c < 4; c++) d->vpred[c] = 1 << (d->bits - 1);
++ return 1;
++}
++
++/* ---- decoding */
++
++/* a code longer than FAST_BITS, a bit at a time (vbits >= 16):
++ * len << 8 | symbol, or 0 for a code that doesn't exist */
++static int slow_symbol(const struct huff *h, uint32_t bitbuf, int vbits)
++{
++ int len = FAST_BITS;
++ int code = (int) ((bitbuf >> (vbits - len)) & ((1 << len) - 1));
++ while (len < 16 && code > h->maxcode[len])
++ {
++ len++;
++ code = (int) ((bitbuf >> (vbits - len)) & ((1u << len) - 1));
++ }
++ if (code > h->maxcode[len]) return 0;
++ return len << 8 | h->vals[h->valptr[len] + code - h->mincode[len]];
++}
++
++typedef uint32_t __attribute__((may_alias)) word;
++
++/* a byte of w is 0xFF: a zero byte of ~w, (~w - 0x01010101) & w & 0x80808080,
++ * and ~w - k is ~(w + k) */
++#define FF_IN(w) ((w) & ~((w) + 0x01010101u))
++
++/* the first 0xFF at or after p, or be: the bytes before it are taken
++ * without looking at each, sixteen at a time here */
++static __attribute__((noinline)) const uint8_t *next_ff(const uint8_t *p, const uint8_t *be)
++{
++ for (; p < be && ((uintptr_t) p & 3); p++)
++ if (*p == 0xFF) return p;
++ for (; be - p >= 16; p += 16)
++ {
++ const word *q = (const word *) p;
++ if ((FF_IN(q[0]) | FF_IN(q[1]) | FF_IN(q[2]) | FF_IN(q[3])) & 0x80808080u) break;
++ }
++ while (p < be && *p != 0xFF) p++;
++ return p;
++}
++
++/* The bit reader keeps its state in d between the decoder's calls, and in
++ * registers in its loop, which hands it over to these for what is rare:
++ * the buffer's end, the 0xFF bytes, codes longer than the one lookup. */
++
++/* at least 25 bits, the careful way: a stuffed 0xFF 0x00 is one 0xFF; any
++ * other marker ends the data, and zeros follow. Then where the next 0xFF
++ * is: below safe, the next three bytes are data in the buffer and no 0xFF. */
++static __attribute__((noinline)) void fill(struct fos_dev *d)
++{
++ uint32_t bitbuf = d->bitbuf;
++ int vbits = d->vbits;
++ const uint8_t *bp = d->bp, *be = d->be, *ff = d->ff;
++ while (vbits <= 24)
++ {
++ if (be - bp < 2)
++ {
++ int len = refill(d, bp, (int) (be - bp));
++ bp = d->buf; be = bp + len;
++ ff = 0;
++ }
++ uint32_t c = *bp++;
++ if (c == 0xFF)
++ {
++ if (!*bp) bp++;
++ else { c = 0; bp = be; d->file_pos = d->file_end; }
++ }
++ bitbuf = bitbuf << 8 | c;
++ vbits += 8;
++ }
++ d->bitbuf = bitbuf; d->vbits = vbits;
++ d->bp = bp; d->be = be;
++ if (!ff || bp > ff)
++ {
++ d->ff = next_ff(bp, be);
++ d->safe = d->ff - 2;
++ }
++}
++
++/* a difference the one lookup doesn't cover: the code, then its bits */
++static __attribute__((noinline)) int slow_diff(struct fos_dev *d, const struct huff *h)
++{
++ fill(d);
++ int e = h->fast[(d->bitbuf >> (d->vbits - FAST_BITS)) & ((1 << FAST_BITS) - 1)];
++ if (!e) e = slow_symbol(h, d->bitbuf, d->vbits);
++ d->vbits -= e >> 8;
++ int s = e & 0xFF, diff = 0;
++ if (s == 16) diff = -32768;
++ else if (s)
++ {
++ if (d->vbits < s) fill(d);
++ d->vbits -= s;
++ diff = (int) ((d->bitbuf >> d->vbits) & ((1u << s) - 1));
++ if (!(diff >> (s - 1))) diff -= (1 << s) - 1;
++ }
++ fill(d);
++ return diff;
++}
++
++#define LOAD() (bitbuf = d->bitbuf, vbits = d->vbits, bp = d->bp, safe = d->safe)
++#define SAVE() (d->bitbuf = bitbuf, d->vbits = vbits, d->bp = bp)
++
++/* at least 24 bits: two short codes' worth */
++#define FILL() \
++ do \
++ { \
++ if (__builtin_expect(bp < safe, 1)) \
++ { \
++ if (vbits <= 16) { bitbuf = bitbuf << 16 | (uint32_t) bp[0] << 8 | bp[1]; bp += 2; vbits += 16; } \
++ if (vbits <= 24) { bitbuf = bitbuf << 8 | *bp++; vbits += 8; } \
++ } \
++ else { SAVE(); fill(d); LOAD(); } \
++ } while (0)
++
++/* a difference from table h (its lookup t, read at the byte offset the
++ * mask leaves); bitbuf must hold DIFF_BITS + 1:
++ * the code and its bits in one lookup, as nearly always (99.8 % on the
++ * EOS M's files) */
++#define DIFF_OR(t, h, diff, also) \
++ do \
++ { \
++ diff = *(const int16_t *) ((const uint8_t *) (t) + ((bitbuf >> (vbits - DIFF_BITS - 1)) & ((2 << DIFF_BITS) - 2))); \
++ if (__builtin_expect(diff & 15, 1)) { vbits -= diff & 15; diff >>= 4; } \
++ else { SAVE(); diff = slow_diff(d, h); LOAD(); also; } \
++ } while (0)
++#define DIFF(t, h, diff) DIFF_OR(t, h, diff, (void) 0)
++
++/* n pairs of the two components (the EOS M's layout), each from the one
++ * to its left: on its own, so all it works with stays in registers */
++static __attribute__((noinline)) void pairs(struct fos_dev *d, uint16_t *out, int n)
++{
++ const struct huff *h0 = d->huff[0], *h1 = d->huff[1];
++ const int16_t *t0 = h0->fastd, *t1 = h1->fastd;
++ uint32_t bitbuf;
++ int vbits;
++ const uint8_t *bp, *safe;
++ LOAD();
++ int p0 = out[-2], p1 = out[-1], diff;
++ uint16_t *stop = out + 2 * n;
++ while (out < stop)
++ {
++ /* a pair takes three bytes at most: as many as safe leaves room
++ * for, without looking (until a long code, which reads on) */
++ int room = (int) (safe - bp) >> 2, left = (int) (stop - out) >> 1;
++ if (room <= 0)
++ {
++ FILL();
++ DIFF(t0, h0, diff); p0 += diff; out[0] = (uint16_t) p0;
++ DIFF(t1, h1, diff); p1 += diff; out[1] = (uint16_t) p1;
++ out += 2;
++ continue;
++ }
++ uint16_t *block = out + 2 * (room < left ? room : left);
++ for (; out < block; out += 2)
++ {
++ if (vbits <= 16) { bitbuf = bitbuf << 16 | (uint32_t) bp[0] << 8 | bp[1]; bp += 2; vbits += 16; }
++ if (vbits <= 24) { bitbuf = bitbuf << 8 | *bp++; vbits += 8; }
++ DIFF_OR(t0, h0, diff, block = out + 2); p0 += diff; out[0] = (uint16_t) p0;
++ DIFF_OR(t1, h1, diff, block = out + 2); p1 += diff; out[1] = (uint16_t) p1;
++ }
++ }
++ SAVE();
++}
++
++/* the next count samples of the lossless JPEG into out[0..count-1];
++ * out[-clrs..-1] hold the ones before */
++static __attribute__((noinline)) void unpack(struct fos_dev *d, uint16_t *out, int count)
++{
++ const int clrs = d->clrs, wide = d->wide;
++ uint32_t bitbuf;
++ int vbits;
++ const uint8_t *bp, *safe;
++ int comp = d->comp, jcol = d->jcol;
++ uint16_t *end = out + count;
++ while (out < end)
++ {
++ int diff;
++ if (jcol && !comp && end - out >= clrs && (clrs == 2 || clrs == 4))
++ {
++ /* whole groups of the components, each from the one to its
++ * left, kept in registers */
++ int n = wide - jcol;
++ if (n > (int) (end - out) / clrs) n = (int) (end - out) / clrs;
++ jcol += n;
++ if (jcol == wide) jcol = 0;
++ if (clrs == 2)
++ {
++ pairs(d, out, n);
++ out += 2 * n;
++ }
++ else
++ {
++ const struct huff *h0 = d->huff[0], *h1 = d->huff[1], *h2 = d->huff[2], *h3 = d->huff[3];
++ uint16_t *stop = out + 4 * n;
++ int p0 = out[-4], p1 = out[-3], p2 = out[-2], p3 = out[-1];
++ LOAD();
++ for (; out < stop; out += 4)
++ {
++ FILL();
++ DIFF(h0->fastd, h0, diff); p0 += diff; out[0] = (uint16_t) p0;
++ DIFF(h1->fastd, h1, diff); p1 += diff; out[1] = (uint16_t) p1;
++ FILL();
++ DIFF(h2->fastd, h2, diff); p2 += diff; out[2] = (uint16_t) p2;
++ DIFF(h3->fastd, h3, diff); p3 += diff; out[3] = (uint16_t) p3;
++ }
++ SAVE();
++ }
++ continue;
++ }
++ /* one at a time: a row's first group (predicted from above), odd
++ * layouts, the ends of the count */
++ const struct huff *h = d->huff[comp];
++ LOAD();
++ FILL();
++ DIFF(h->fastd, h, diff);
++ SAVE();
++ if (jcol) *out = (uint16_t) (out[-clrs] + diff);
++ else *out = (uint16_t) (d->vpred[comp] += diff);
++ out++;
++ if (++comp == clrs)
++ {
++ comp = 0;
++ if (++jcol == wide) jcol = 0;
++ }
++ }
++ d->comp = comp; d->jcol = jcol;
++}
++
++/* a raw row's samples v..vend-1 into its print pixels: segment by segment
++ * (next: where the next starts, at[] the sample of a column; off: where
++ * the segment goes in row), its even and odd columns apart */
++static __attribute__((noinline)) void sum_samples(const uint16_t *at, const uint16_t *v, const uint16_t *vend,
++ const uint16_t *next, const int32_t *off, uint32_t *row)
++{
++ while (v < vend)
++ {
++ const uint16_t *ve = at + *next++;
++ if (ve > vend) ve = vend;
++ uint32_t a = 0, b = 0;
++ if ((v - at) & 1) b = *v++;
++ for (; ve - v >= 2; v += 2) { a += v[0]; b += v[1]; }
++ if (v < ve) a += *v++;
++ uint32_t *p = row + *off++;
++ p[0] += a;
++ p[1] += b;
++ }
++}
++
++/* a whole row of the picture the same way, in the pieces seg_desc gives
++ * (n of them; off: where each goes in row), with the even columns 4-byte
++ * aligned: a pair of samples as one word, and up to four pairs of 14 bits
++ * summed in its halves */
++static __attribute__((noinline)) void sum_row(const uint16_t *v, const uint8_t *desc, int n, const int32_t *off, uint32_t *row)
++{
++ for (const uint8_t *e = desc + n; desc < e; desc++, off++)
++ {
++ int k = *desc;
++ uint32_t b = 0;
++ if (k & 0x80) b = *v++;
++ const word *q = (const word *) v;
++ uint32_t w = 0;
++ switch (k & 7)
++ {
++ case 4: w += q[3]; /* fall through */
++ case 3: w += q[2]; /* fall through */
++ case 2: w += q[1]; /* fall through */
++ case 1: w += q[0]; /* fall through */
++ default: break;
++ }
++ v += 2 * (k & 7);
++ uint32_t a = w & 0xFFFF;
++ if (k & 0x40) a += *v++;
++ uint32_t *p = row + *off;
++ p[0] += a;
++ p[1] += b + (w >> 16);
++ }
++}
++
++/* count samples to where they fall in the print, slice by slice, top to
++ * bottom: a print pixel's run of samples along a raw row is summed in
++ * registers, even and odd columns (two colours of the mosaic) apart, and
++ * added once. The masked columns left of the picture give the black. */
++static __attribute__((noinline)) void scatter(struct fos_dev *d, const uint16_t *src, int n)
++{
++ uint32_t *sums = d->sums;
++ const uint16_t *seg_x0 = d->seg_x0, *seg_of = d->seg_of;
++ const int32_t *seg_off = d->seg_off;
++ const uint8_t *colob = d->colob;
++ const int pic0 = d->crop_l, pic1 = d->crop_l + d->crop_w;
++ const uint8_t *desc = d->seg_desc;
++ int sx = d->sx, sy = d->sy, sw = d->sw, sx0 = d->sx0;
++ int64_t black_sum = d->black_sum;
++ long black_n = d->black_n;
++ while (n > 0)
++ {
++ int run = sw - sx < n ? sw - sx : n;
++ n -= run;
++ const int ro = d->rowoff[sy];
++#ifdef FOS_DEV_TEST
++ for (int k = 0; k < run; k++) fos_dev_test_sample(sx0 + sx + k, sy, src[k]);
++#endif
++ if (ro >= 0)
++ {
++ const int x0 = sx0 + sx, x1 = x0 + run;
++ const int pa = x0 > pic0 ? x0 : pic0, pb = x1 < pic1 ? x1 : pic1;
++ for (int x = x0; x < x1 && x < pa; x++)
++ if (colob[x]) { black_sum += src[x - x0]; black_n++; }
++ if (pa < pb)
++ {
++ /* sample of raw column x at at[x]; RGGB at the sensor's top
++ * left: the even columns' colour, then the odd ones' */
++ const uint16_t *at = src - x0;
++ uint32_t *row = sums + ro + (sy & 1);
++ /* the segments it touches, and those it has whole (a row
++ * of the picture is in two of Canon's slices) */
++ int k0 = seg_of[pa], k1 = seg_of[pb - 1] + 1;
++ int w0 = seg_x0[k0] < pa ? k0 + 1 : k0, w1 = seg_x0[k1] > pb ? k1 - 1 : k1;
++ if (!desc || ((uintptr_t) at & 3) || w0 >= w1)
++ sum_samples(at, at + pa, at + pb, seg_x0 + k0 + 1, seg_off + k0, row);
++ else
++ {
++ if (w0 > k0) sum_samples(at, at + pa, at + seg_x0[w0], seg_x0 + k0 + 1, seg_off + k0, row);
++ const int i0 = d->seg_piece[w0];
++ sum_row(at + seg_x0[w0], desc + i0, d->seg_piece[w1] - i0, d->desc_off + i0, row);
++ if (w1 < k1) sum_samples(at, at + seg_x0[w1], at + pb, seg_x0 + w1 + 1, seg_off + w1, row);
++ }
++ }
++ }
++ src += run;
++ sx += run;
++ if (sx == sw)
++ {
++ sx = 0;
++ if (++sy == d->raw_h)
++ {
++ sy = 0;
++ sx0 += sw;
++ d->sl++;
++ sw = d->sl < d->slices[0] ? d->slices[1] : d->slices[2];
++ }
++ }
++ }
++ d->sx = sx; d->sy = sy; d->sw = sw; d->sx0 = sx0;
++ d->black_sum = black_sum; d->black_n = black_n;
++}
++
++/* decode about n samples straight into the print's sums */
++static void decode(struct fos_dev *d, long n)
++{
++ uint16_t *s = d->samples + 4;
++ while (n > 0 && d->done < d->total)
++ {
++ /* to the end of a raw row, so scatter has it whole */
++ int k = d->sw - d->sx;
++ if (k > UNPACK) k = UNPACK;
++ if (k > d->total - d->done) k = (int) (d->total - d->done);
++ unpack(d, s, k);
++ scatter(d, s, k);
++ /* the last of each component, for the next ones' prediction */
++ memmove(s - d->clrs, s + k - d->clrs, d->clrs * 2);
++ d->done += k;
++ n -= k;
++ }
++}
++
++/* ---- finishing */
++
++/* 65536 / n for the samples a print pixel's channel got */
++static uint32_t recip[64];
++
++/* scene-linear sRGB of print pixel i (4096 = 1.0), clipped as the lab's
++ * RAW converter does, times d->mul; 0 where the picture isn't */
++FOS_INLINE void pixel_linear(const struct fos_dev *d, int x, int y, int lin[3])
++{
++ int i = y * FOS_PRINT_W + x;
++ int xr, xc; /* print line fed by raw rows / columns */
++ if (d->rows_axis_x) { xr = x - d->ox0; xc = y; if (xr < 0 || xr >= d->ow) { lin[0] = lin[1] = lin[2] = 0; return; } }
++ else { xr = y; xc = x; }
++ int er = d->ne_r[xr], or_ = d->no_r[xr], ec = d->ne_c[xc], oc = d->no_c[xc];
++ int n[3] = { er * ec, er * oc + or_ * ec, or_ * oc };
++ int cam[3];
++ for (int c = 0; c < 3; c++)
++ {
++ /* the mean (sums <= 16383 n, so this fits), less black, balanced */
++ int m = n[c] < 64 ? (int) (d->sums[3 * i + c] * recip[n[c]] >> 12) - d->black16 : 0;
++ int v = m > 0 ? (int) (((int64_t) m * d->pre[c]) >> 14) : 0;
++ cam[c] = v < 0 ? 0 : v > 4096 ? 4096 : v;
++ }
++ for (int c = 0; c < 3; c++)
++ {
++ int v = (d->mat[c][0] * cam[0] + d->mat[c][1] * cam[1] + d->mat[c][2] * cam[2]) >> 12;
++ v = v < 0 ? 0 : v > 4096 ? 4096 : v;
++ v = (v * d->mul[c]) >> 12;
++ lin[c] = v > 65535 ? 65535 : v;
++ }
++}
++
++/* camera -> sRGB with daylight balance, and the black and white levels */
++static void setup_colour(struct fos_dev *d)
++{
++ float cam_rgb[3][3], pre[3];
++ for (int i = 0; i < 3; i++)
++ {
++ float sum = 0;
++ for (int j = 0; j < 3; j++)
++ {
++ cam_rgb[i][j] = 0;
++ for (int k = 0; k < 3; k++) cam_rgb[i][j] += XYZ_CAM[i][k] * RGB_XYZ[k][j];
++ sum += cam_rgb[i][j];
++ }
++ for (int j = 0; j < 3; j++) cam_rgb[i][j] /= sum;
++ pre[i] = 1 / sum;
++ }
++ float green = pre[1];
++ for (int i = 0; i < 3; i++) pre[i] /= green;
++ /* rgb_cam = inverse(cam_rgb) */
++ float (*m)[3] = cam_rgb, inv[3][3];
++ float det = m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
++ + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
++ inv[0][0] = (m[1][1] * m[2][2] - m[1][2] * m[2][1]) / det;
++ inv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) / det;
++ inv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) / det;
++ inv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) / det;
++ inv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) / det;
++ inv[1][2] = (m[0][2] * m[1][0] - m[0][0] * m[1][2]) / det;
++ inv[2][0] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) / det;
++ inv[2][1] = (m[0][1] * m[2][0] - m[0][0] * m[2][1]) / det;
++ inv[2][2] = (m[0][0] * m[1][1] - m[0][1] * m[1][0]) / det;
++
++ float black = d->black_n ? (float) d->black_sum / (float) d->black_n : 2048;
++ if (black < 0 || black > WHITE_LEVEL / 2) black = 2048; /* a damaged file */
++ d->black16 = (int) (black * 16 + 0.5f);
++ /* raw/16 above black -> 4096 at the white level, balanced, << 14 */
++ for (int c = 0; c < 3; c++)
++ {
++ d->pre[c] = (int) (pre[c] * 4096 * 16384 / ((WHITE_LEVEL - black) * 16) + 0.5f);
++ d->mul[c] = 4096;
++ for (int j = 0; j < 3; j++) d->mat[c][j] = (int) (inv[c][j] * 4096 + (inv[c][j] < 0 ? -0.5f : 0.5f));
++ }
++ for (int k = 1; k < 64; k++) recip[k] = 65536 / k;
++}
++
++/* small, fast noise */
++FOS_INLINE int rnd(unsigned *s)
++{
++ *s = *s * 1664525u + 1013904223u;
++ return (int) (*s >> 16 & 0xFFFF) - 32768;
++}
++
++/* ---------------------------------------------------------------- palette */
++
++/* median cut over a 5-5-5 histogram (struct box: with struct fos_dev) */
++
++static void box_shrink(const uint32_t *hist, struct box *b)
++{
++ int lo[3] = { 31, 31, 31 }, hi[3] = { 0, 0, 0 };
++ long count = 0;
++ for (int r = b->lo[0]; r <= b->hi[0]; r++)
++ for (int g = b->lo[1]; g <= b->hi[1]; g++)
++ for (int bl = b->lo[2]; bl <= b->hi[2]; bl++)
++ {
++ uint32_t n = hist[r << 10 | g << 5 | bl];
++ if (!n) continue;
++ count += n;
++ if (r < lo[0]) lo[0] = r;
++ if (r > hi[0]) hi[0] = r;
++ if (g < lo[1]) lo[1] = g;
++ if (g > hi[1]) hi[1] = g;
++ if (bl < lo[2]) lo[2] = bl;
++ if (bl > hi[2]) hi[2] = bl;
++ }
++ if (count) { memcpy(b->lo, lo, sizeof(lo)); memcpy(b->hi, hi, sizeof(hi)); }
++ b->count = count;
++}
++
++static void median_cut(struct fos_dev *d)
++{
++ struct box *boxes = d->boxes;
++ int n = 1;
++ boxes[0].lo[0] = boxes[0].lo[1] = boxes[0].lo[2] = 0;
++ boxes[0].hi[0] = boxes[0].hi[1] = boxes[0].hi[2] = 31;
++ box_shrink(d->hist, &boxes[0]);
++ while (n < FOS_PRINT_COLOURS)
++ {
++ /* the box with the most pixels that can still be split, weighted
++ * by its size so big smooth areas get their share */
++ int best = -1;
++ long best_score = 0;
++ for (int i = 0; i < n; i++)
++ {
++ struct box *b = &boxes[i];
++ int span = 0;
++ for (int c = 0; c < 3; c++) if (b->hi[c] - b->lo[c] > span) span = b->hi[c] - b->lo[c];
++ if (!span) continue;
++ long score = b->count * (span + 1);
++ if (score > best_score) { best_score = score; best = i; }
++ }
++ if (best < 0) break;
++ struct box *b = &boxes[best];
++ int axis = 0, span = -1;
++ for (int c = 0; c < 3; c++) if (b->hi[c] - b->lo[c] > span) { span = b->hi[c] - b->lo[c]; axis = c; }
++ /* the median along that axis */
++ long half = b->count / 2, acc = 0;
++ int cut = b->lo[axis];
++ for (int v = b->lo[axis]; v < b->hi[axis]; v++)
++ {
++ int lo[3] = { b->lo[0], b->lo[1], b->lo[2] }, hi[3] = { b->hi[0], b->hi[1], b->hi[2] };
++ lo[axis] = hi[axis] = v;
++ for (int r = lo[0]; r <= hi[0]; r++)
++ for (int g = lo[1]; g <= hi[1]; g++)
++ for (int bl = lo[2]; bl <= hi[2]; bl++)
++ acc += d->hist[r << 10 | g << 5 | bl];
++ cut = v;
++ if (acc >= half) break;
++ }
++ struct box nb = *b;
++ b->hi[axis] = cut;
++ nb.lo[axis] = cut + 1;
++ box_shrink(d->hist, b);
++ box_shrink(d->hist, &nb);
++ boxes[n++] = nb;
++ }
++ /* each box's colour: the mean of its pixels */
++ d->npal = n;
++ for (int i = 0; i < n; i++)
++ {
++ const struct box *b = &boxes[i];
++ int64_t s[3] = { 0, 0, 0 }, cnt = 0;
++ for (int r = b->lo[0]; r <= b->hi[0]; r++)
++ for (int g = b->lo[1]; g <= b->hi[1]; g++)
++ for (int bl = b->lo[2]; bl <= b->hi[2]; bl++)
++ {
++ uint32_t k = d->hist[r << 10 | g << 5 | bl];
++ s[0] += (int64_t) k * (r * 8 + 4); s[1] += (int64_t) k * (g * 8 + 4); s[2] += (int64_t) k * (bl * 8 + 4);
++ cnt += k;
++ }
++ for (int c = 0; c < 3; c++)
++ d->pal[i][c] = (uint8_t) (cnt ? (s[c] + cnt / 2) / cnt : 0);
++ }
++}
++
++/* the palette in order of green, to search outwards from the nearest
++ * green and stop once green alone is further than the best so far */
++static void sort_palette(struct fos_dev *d)
++{
++ uint8_t *by_green = d->by_green;
++ for (int i = 0; i < d->npal; i++)
++ {
++ int j = i;
++ for (; j > 0 && d->pal[by_green[j - 1]][1] > d->pal[i][1]; j--) by_green[j] = by_green[j - 1];
++ by_green[j] = (uint8_t) i;
++ }
++}
++
++/* the nearest palette entry for a 5-5-5 cell, worked out when first needed */
++static __attribute__((noinline)) int nearest(struct fos_dev *d, int cell)
++{
++ int v = d->inv[cell];
++ if (v) return v - 1;
++ int r = (cell >> 10) * 8 + 4, g = (cell >> 5 & 31) * 8 + 4, b = (cell & 31) * 8 + 4;
++ const uint8_t *by_green = d->by_green;
++ int lo = 0, hi = d->npal;
++ while (lo < hi)
++ {
++ int mid = (lo + hi) >> 1;
++ if (d->pal[by_green[mid]][1] < g) lo = mid + 1; else hi = mid;
++ }
++ int best = by_green[lo < d->npal ? lo : d->npal - 1], bd = 1 << 30;
++ for (int up = lo, down = lo - 1; up < d->npal || down >= 0; )
++ {
++ int done = 1;
++ if (up < d->npal)
++ {
++ const uint8_t *p = d->pal[by_green[up]];
++ int dg = p[1] - g;
++ if (4 * dg * dg < bd)
++ {
++ int dr = r - p[0], db = b - p[2], dd = 3 * dr * dr + 4 * dg * dg + 2 * db * db;
++ if (dd < bd) { bd = dd; best = by_green[up]; }
++ up++;
++ done = 0;
++ }
++ else up = d->npal;
++ }
++ if (down >= 0)
++ {
++ const uint8_t *p = d->pal[by_green[down]];
++ int dg = g - p[1];
++ if (4 * dg * dg < bd)
++ {
++ int dr = r - p[0], db = b - p[2], dd = 3 * dr * dr + 4 * dg * dg + 2 * db * db;
++ if (dd < bd) { bd = dd; best = by_green[down]; }
++ down--;
++ done = 0;
++ }
++ else down = -1;
++ }
++ if (done) break;
++ }
++ d->inv[cell] = (uint8_t) (best + 1);
++ return best;
++}
++
++/* ---------------------------------------------------------------- files */
++
++/* the overlay's colours over a photograph: black, a panel, greys up to
++ * white for text on it, the accent, red, a line, and a dim grey */
++const uint8_t fos_fixed_rgb[FOS_FIXED_N][3] =
++{
++ { 0, 0, 0 }, { 22, 21, 20 }, { 52, 50, 48 }, { 88, 85, 82 }, { 128, 124, 120 }, { 170, 166, 160 },
++ { 210, 206, 200 }, { 244, 241, 236 }, { 236, 168, 52 }, { 150, 104, 34 }, { 214, 64, 52 }, { 60, 58, 56 },
++ { 112, 108, 104 }, { 0, 0, 0 },
++};
++
++/* A print is an 8-bit BMP, so it also opens on a PC: the file and info
++ * headers, 256 palette entries (1..240 the print's), our own header with
++ * the frame's details, the pixels top row first, then the thumbnail. */
++#define BMP_PAL (14 + 40)
++#define BMP_META (BMP_PAL + 256 * 4)
++#define META_SIZE 64
++#define BMP_PIXELS (BMP_META + META_SIZE)
++#define BMP_THUMB (BMP_PIXELS + FOS_PRINT_W * FOS_PRINT_H)
++#define THUMB_SIZE (FOS_THUMB_W * FOS_THUMB_H * 3)
++#define BMP_SIZE (BMP_THUMB + THUMB_SIZE)
++
++
++static int write_print(const char *path, int film, int frame, const char *when, const char *fstop,
++ const uint8_t pal[][3], int npal, const uint8_t *px, const uint8_t *thumb, int x0, int w)
++{
++ static uint8_t h[BMP_PIXELS];
++ memset(h, 0, sizeof(h));
++ h[0] = 'B'; h[1] = 'M';
++ put32(h + 2, BMP_SIZE);
++ put32(h + 10, BMP_PIXELS);
++ put32(h + 14, 40);
++ put32(h + 18, FOS_PRINT_W);
++ put32(h + 22, (uint32_t) -FOS_PRINT_H); /* top-down */
++ h[26] = 1; h[28] = 8;
++ put32(h + 34, FOS_PRINT_W * FOS_PRINT_H);
++ put32(h + 38, 2835); put32(h + 42, 2835); /* 72 dpi */
++ put32(h + 46, 256);
++ for (int i = 0; i < npal && i < FOS_PRINT_COLOURS; i++)
++ {
++ uint8_t *q = h + BMP_PAL + 4 * (i + 1);
++ q[0] = pal[i][2]; q[1] = pal[i][1]; q[2] = pal[i][0];
++ }
++ uint8_t *m = h + BMP_META;
++ memcpy(m, "FOP2", 4);
++ m[4] = (uint8_t) film;
++ m[6] = (uint8_t) frame; m[7] = (uint8_t) (frame >> 8);
++ if (when) memcpy(m + 8, when, strlen(when) < 19 ? strlen(when) : 19);
++ if (fstop) memcpy(m + 28, fstop, strlen(fstop) < 7 ? strlen(fstop) : 7);
++ m[36] = (uint8_t) x0; m[37] = (uint8_t) (x0 >> 8); /* the picture's columns */
++ m[38] = (uint8_t) w; m[39] = (uint8_t) (w >> 8);
++
++ void *f = fos_port_open(path, 1);
++ if (!f) return 0;
++ int ok = fos_port_write(f, h, BMP_PIXELS) == BMP_PIXELS
++ && fos_port_write(f, px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H
++ && fos_port_write(f, thumb, THUMB_SIZE) == THUMB_SIZE;
++ fos_port_close(f);
++ return ok;
++}
++
++static int is_print(const uint8_t *h)
++{
++ return h[0] == 'B' && h[1] == 'M' && u32le(h + 10) == BMP_PIXELS && u32le(h + 18) == FOS_PRINT_W
++ && !memcmp(h + BMP_META, "FOP2", 4);
++}
++
++int fos_print_thumb(const char *path, uint8_t *thumb)
++{
++ void *f = fos_port_open(path, 0);
++ if (!f) return 0;
++ static uint8_t h[BMP_PIXELS];
++ int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h)
++ && fos_port_seek(f, BMP_THUMB) >= 0 && fos_port_read(f, thumb, THUMB_SIZE) == THUMB_SIZE;
++ fos_port_close(f);
++ return ok;
++}
++
++int fos_print_load(const char *path, struct fos_print *p)
++{
++ memset(p, 0, sizeof(*p));
++ void *f = fos_port_open(path, 0);
++ if (!f) return 0;
++ static uint8_t h[BMP_PIXELS];
++ int ok = fos_port_read(f, h, BMP_PIXELS) == BMP_PIXELS && is_print(h);
++ if (ok)
++ {
++ const uint8_t *m = h + BMP_META;
++ p->film = m[4];
++ p->frame = u16le(m + 6);
++ memcpy(p->when, m + 8, 19);
++ memcpy(p->fstop, m + 28, 7);
++ p->x0 = u16le(m + 36);
++ p->w = u16le(m + 38);
++ if (!p->w || p->x0 + p->w > FOS_PRINT_W) p->x0 = 0, p->w = FOS_PRINT_W;
++ for (int i = 0; i < FOS_PRINT_COLOURS; i++)
++ {
++ const uint8_t *q = h + BMP_PAL + 4 * (i + 1);
++ p->pal[i][0] = q[2]; p->pal[i][1] = q[1]; p->pal[i][2] = q[0];
++ }
++ p->px = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
++ ok = p->px && fos_port_read(f, p->px, FOS_PRINT_W * FOS_PRINT_H) == FOS_PRINT_W * FOS_PRINT_H;
++ }
++ fos_port_close(f);
++ if (!ok) fos_print_free(p);
++ return ok;
++}
++
++void fos_print_free(struct fos_print *p)
++{
++ fos_port_free(p->px);
++ p->px = 0;
++}
++
++/* ---------------------------------------------------------------- quantize an RGB print */
++
++/* histogram, palette, error diffusion: rows y0..y1-1 of the dithering per
++ * call (the histogram and palette when y0 == 0) */
++static int quant_alloc(struct fos_dev *d)
++{
++ d->hist = fos_port_alloc(32768 * 4);
++ d->inv = fos_port_alloc(32768);
++ d->err_rows = fos_port_alloc((FOS_PRINT_W + 2) * 3 * 2 * 2);
++ if (!d->idx) d->idx = fos_port_alloc(FOS_PRINT_W * FOS_PRINT_H);
++ if (!d->hist || !d->inv || !d->err_rows || !d->idx) return 0;
++ memset(d->hist, 0, 32768 * 4);
++ memset(d->inv, 0, 32768);
++ memset(d->err_rows, 0, (FOS_PRINT_W + 2) * 3 * 2 * 2);
++ for (int i = 0; i < FOS_PRINT_W * FOS_PRINT_H; i++)
++ {
++ const uint8_t *p = d->rgb + 3 * i;
++ d->hist[(p[0] >> 3) << 10 | (p[1] >> 3) << 5 | p[2] >> 3]++;
++ }
++ median_cut(d);
++ sort_palette(d);
++ return 1;
++}
++
++static __attribute__((noinline)) void dither_rows(struct fos_dev *d, int y0, int y1)
++{
++ const int W = FOS_PRINT_W;
++ const uint8_t *inv = d->inv;
++ const uint8_t (*pal)[3] = d->pal;
++ for (int y = y0; y < y1; y++)
++ {
++ /* serpentine: every other row right to left */
++ const int dir = y & 1 ? -1 : 1, st = 3 * dir;
++ int16_t *cur = d->err_rows + ((y & 1) ? (W + 2) * 3 : 0);
++ int16_t *nxt = d->err_rows + ((y & 1) ? 0 : (W + 2) * 3);
++ memset(nxt, 0, (W + 2) * 3 * 2);
++ const int x = dir > 0 ? 0 : W - 1;
++ const uint8_t *p = d->rgb + 3 * (y * W + x);
++ uint8_t *o = d->idx + y * W + x;
++ int16_t *c = cur + (x + 1) * 3, *n = nxt + (x + 1) * 3;
++ for (int k = 0; k < W; k++, p += st, o += dir, c += st, n += st)
++ {
++ int r = p[0] + (c[0] >> 4), g = p[1] + (c[1] >> 4), b = p[2] + (c[2] >> 4);
++ r = r < 0 ? 0 : r > 255 ? 255 : r;
++ g = g < 0 ? 0 : g > 255 ? 255 : g;
++ b = b < 0 ? 0 : b > 255 ? 255 : b;
++ int cell = (r >> 3) << 10 | (g >> 3) << 5 | b >> 3;
++ int i = inv[cell] ? inv[cell] - 1 : nearest(d, cell);
++ *o = (uint8_t) (i + 1);
++ const uint8_t *q = pal[i];
++ /* Floyd-Steinberg, in 1/16 */
++ int e = r - q[0];
++ c[st] = (int16_t) (c[st] + e * 7); n[-st] = (int16_t) (n[-st] + e * 3); n[0] = (int16_t) (n[0] + e * 5); n[st] = (int16_t) (n[st] + e);
++ e = g - q[1];
++ c[st + 1] = (int16_t) (c[st + 1] + e * 7); n[1 - st] = (int16_t) (n[1 - st] + e * 3); n[1] = (int16_t) (n[1] + e * 5); n[st + 1] = (int16_t) (n[st + 1] + e);
++ e = b - q[2];
++ c[st + 2] = (int16_t) (c[st + 2] + e * 7); n[2 - st] = (int16_t) (n[2 - st] + e * 3); n[2] = (int16_t) (n[2] + e * 5); n[st + 2] = (int16_t) (n[st + 2] + e);
++ }
++ }
++}
++
++/* ---------------------------------------------------------------- one frame */
++
++struct fos_dev *fos_dev_start(const char *cr2, const char *print, int film, int frame,
++ const char *when, const char *fstop)
++{
++ struct fos_dev *d = fos_port_alloc(sizeof(struct fos_dev));
++ if (!d) return 0;
++ memset(d, 0, sizeof(*d));
++ snprintf(d->cr2, sizeof(d->cr2), "%s", cr2);
++ snprintf(d->print, sizeof(d->print), "%s", print);
++ snprintf(d->when, sizeof(d->when), "%s", when ? when : "");
++ snprintf(d->fstop, sizeof(d->fstop), "%s", fstop ? fstop : "");
++ d->film = fos_clamp(film, 0, fos_nfilms - 1);
++ d->frame = frame;
++ d->look = fos_look_of(fos_films[d->film].key);
++ d->seed = 12345u + (unsigned) frame * 7919u;
++ d->stage = ST_OPEN;
++ return d;
++}
++
++void fos_dev_jpeg(struct fos_dev *d, const char *path)
++{
++ if (d) snprintf(d->jpeg, sizeof(d->jpeg), "%s", path ? path : "");
++}
++
++void fos_dev_free(struct fos_dev *d)
++{
++ if (!d) return;
++ if (d->f) fos_port_close(d->f);
++ fos_port_free(d->buf); fos_port_free(d->rowoff); fos_port_free(d->seg_of);
++ fos_port_free(d->seg_x0); fos_port_free(d->seg_off); fos_port_free(d->seg_desc); fos_port_free(d->desc_off); fos_port_free(d->seg_piece);
++ fos_port_free(d->rowob); fos_port_free(d->colob); fos_port_free(d->ne_r); fos_port_free(d->ne_c);
++ fos_port_free(d->sums); fos_port_free(d->glow); fos_port_free(d->rgb);
++ fos_port_free(d->hist); fos_port_free(d->inv); fos_port_free(d->err_rows); fos_port_free(d->idx);
++ fos_port_free(d);
++}
++
++const uint8_t *fos_dev_thumb(const struct fos_dev *d)
++{
++ return d && d->stage == ST_DONE ? d->thumb : 0;
++}
++
++const char *fos_dev_error(const struct fos_dev *d)
++{
++ return d ? d->err : "out of memory";
++}
++
++int fos_dev_doing(const struct fos_dev *d)
++{
++ if (!d) return FOS_DEV_FAILED;
++ switch (d->stage)
++ {
++ case ST_OPEN: return FOS_DEV_MIXING;
++ case ST_DECODE: return lut_film == d->film && lut_built >= NGRID ? FOS_DEV_DEVELOPING : FOS_DEV_MIXING;
++ case ST_KEY: case ST_EXPOSE: case ST_GLOW: case ST_FINISH: return FOS_DEV_FIXING;
++ case ST_JPEG: case ST_QUANT: case ST_DITHER: case ST_WRITE: return FOS_DEV_DRYING;
++ case ST_DONE: return FOS_DEV_DONE;
++ }
++ return FOS_DEV_FAILED;
++}
++
++/* how far along, 0..1000: decoding is most of the work */
++static int progress(const struct fos_dev *d)
++{
++ const int H = FOS_PRINT_H;
++ switch (d->stage)
++ {
++ case ST_OPEN: return 0;
++ case ST_DECODE: return d->total ? (int) ((int64_t) d->done * 800 / d->total) : 0; /* 64 bits: long is 32 on the camera */
++ case ST_KEY: return 800;
++ case ST_EXPOSE: return 805 + d->row * 60 / H;
++ case ST_GLOW: return 865;
++ case ST_FINISH: return 870 + d->row * 64 / H;
++ case ST_JPEG: return 934;
++ case ST_QUANT: return 940;
++ case ST_DITHER: return 950 + d->row * 45 / H;
++ case ST_WRITE: return 995;
++ case ST_DONE: return 1000;
++ }
++ return -1;
++}
++
++void fos_dev_picture(const struct fos_dev *d, int *x0, int *w)
++{
++ *x0 = d && d->rows_axis_x ? d->ox0 : 0;
++ *w = d && d->rows_axis_x ? d->ow : FOS_PRINT_W;
++}
++
++int fos_dev_progress(const struct fos_dev *d)
++{
++ return d ? progress(d) : -1;
++}
++
++/* the lab scanner: the log-average luminance to a fixed key (negatives),
++ * or what was exposed (slides); then the film's balance */
++static void stage_key(struct fos_dev *d)
++{
++ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
++ float ev = 1.0f;
++ if (!d->look->slide)
++ {
++ /* counted in a histogram so the logs are few */
++ uint32_t *hist = (uint32_t *) d->rgb; /* free until ST_FINISH */
++ memset(hist, 0, 4097 * 4);
++ int n = 0;
++ for (int y = 0; y < H; y += 4) /* as the lab: every fourth pixel */
++ for (int x = 0; x < W; x += 4)
++ {
++ int lin[3];
++ if (d->rows_axis_x && (x < d->ox0 || x >= d->ox0 + d->ow)) continue;
++ pixel_linear(d, x, y, lin);
++ hist[(871 * lin[0] + 2929 * lin[1] + 296 * lin[2]) >> 12]++;
++ n++;
++ }
++ float acc = 0;
++ for (int v = 0; v <= 4096; v++)
++ if (hist[v]) acc += (float) hist[v] * logf(v / 4096.0f + 1e-4f);
++ float key = n ? expf(acc / (float) n) : 0.11f;
++ ev = log2f(0.11f / key);
++ ev = ev < -2 ? -2 : ev > 3.5f ? 3.5f : ev;
++#ifdef FOS_DEV_TEST
++ fprintf(stderr, "scanner: key %.4f, %.3f EV; black %d/16, pre %d %d %d\n", (double) key, (double) ev, d->black16, d->pre[0], d->pre[1], d->pre[2]);
++#endif
++ }
++ float k = exp2f(ev + d->look->ev);
++ float bal[3] = { 1, 1, 1 };
++ if (d->look->balance != 5500)
++ {
++ float a[3], b[3];
++ cct_rgb(5500, a);
++ cct_rgb((float) d->look->balance, b);
++ for (int c = 0; c < 3; c++) bal[c] = a[c] / b[c];
++ for (int c = 0; c < 3; c++) bal[c] /= a[1] / b[1];
++ }
++ for (int c = 0; c < 3; c++) d->mul[c] = (int) (k * bal[c] * 4096 + 0.5f);
++}
++
++/* Exposing a row goes in two passes, each small enough for the
++ * registers: the camera's colours, then linear sRGB. */
++
++/* n pixels' sums to camera colour (4096 = white): the means (of counts
++ * fixed a, b times along x ra[], rb[]: the even and odd raw rows and
++ * columns), less black, balanced */
++static __attribute__((noinline)) void expose_cam(const struct fos_dev *d, const uint32_t *sm, uint16_t *cam, int n,
++ int a, int b, const uint16_t *ra, const uint16_t *rb)
++{
++ const int black = d->black16, p0 = d->pre[0], p1 = d->pre[1], p2 = d->pre[2];
++ for (const uint16_t *e = ra + n; ra < e; ra++, rb++, sm += 3, cam += 3)
++ {
++ int n0 = a * *ra, n1 = a * *rb + b * *ra, n2 = b * *rb;
++ int c0 = 0, c1 = 0, c2 = 0;
++ /* (sums <= 16383 n, so this fits) */
++ if (n0 < 64) { int m = (int) (sm[0] * recip[n0] >> 12) - black; if (m > 0) { c0 = (m * p0) >> 14; if (c0 > 4096) c0 = 4096; } }
++ if (n1 < 64) { int m = (int) (sm[1] * recip[n1] >> 12) - black; if (m > 0) { c1 = (m * p1) >> 14; if (c1 > 4096) c1 = 4096; } }
++ if (n2 < 64) { int m = (int) (sm[2] * recip[n2] >> 12) - black; if (m > 0) { c2 = (m * p2) >> 14; if (c2 > 4096) c2 = 4096; } }
++ cam[0] = (uint16_t) c0; cam[1] = (uint16_t) c1; cam[2] = (uint16_t) c2;
++ }
++}
++
++/* n pixels' camera colour to linear sRGB (4096 = 1.0) at o, exposed and
++ * balanced for the film; the highlights into the glow row g from x */
++static __attribute__((noinline)) void expose_lin(const struct fos_dev *d, const uint16_t *cam, uint16_t *o, int n,
++ int32_t *g, int x)
++{
++ const int m00 = d->mat[0][0], m01 = d->mat[0][1], m02 = d->mat[0][2];
++ const int m10 = d->mat[1][0], m11 = d->mat[1][1], m12 = d->mat[1][2];
++ const int m20 = d->mat[2][0], m21 = d->mat[2][1], m22 = d->mat[2][2];
++ const int u0 = d->mul[0], u1 = d->mul[1], u2 = d->mul[2];
++ const int thr = (int) (d->look->hal_thr * 4096);
++ for (const uint16_t *e = cam + 3 * n; cam < e; cam += 3, o += 3, x++)
++ {
++ int c0 = cam[0], c1 = cam[1], c2 = cam[2];
++ int r = (m00 * c0 + m01 * c1 + m02 * c2) >> 12;
++ int gg = (m10 * c0 + m11 * c1 + m12 * c2) >> 12;
++ int bb = (m20 * c0 + m21 * c1 + m22 * c2) >> 12;
++ r = r < 0 ? 0 : r > 4096 ? 4096 : r;
++ gg = gg < 0 ? 0 : gg > 4096 ? 4096 : gg;
++ bb = bb < 0 ? 0 : bb > 4096 ? 4096 : bb;
++ r = (r * u0) >> 12; gg = (gg * u1) >> 12; bb = (bb * u2) >> 12;
++ if (r > 65535) r = 65535;
++ if (gg > 65535) gg = 65535;
++ if (bb > 65535) bb = 65535;
++ o[0] = (uint16_t) r; o[1] = (uint16_t) gg; o[2] = (uint16_t) bb;
++ if (g)
++ {
++ int l = (871 * r + 2929 * gg + 296 * bb) >> 12;
++ if (l > thr) g[x >> 2] += l - thr;
++ }
++ }
++}
++
++/* rows y0..y1-1 to linear sRGB, in place over the sums (a row's sums are
++ * read before it is written, and its values only ever overwrite sums
++ * already read); the highlights go into the halation grid on the way. The
++ * same sums as pixel_linear, walked along the row. */
++static __attribute__((noinline)) void stage_expose(struct fos_dev *d, int y0, int y1)
++{
++ const int W = FOS_PRINT_W;
++ uint16_t *lin = (uint16_t *) d->sums;
++ for (int y = y0; y < y1; y++)
++ {
++ int32_t *g = d->glow ? d->glow + (y >> 2) * GW : 0;
++ int xa = 0, xb = W;
++ /* the counts of the samples summed: rows fixed and columns along the
++ * row (landscape), or the other way round (portrait) */
++ int a, b;
++ const uint16_t *ra, *rb;
++ if (d->rows_axis_x)
++ {
++ xa = d->ox0; xb = d->ox0 + d->ow;
++ a = d->ne_c[y]; b = d->no_c[y]; ra = d->ne_r; rb = d->no_r;
++ }
++ else { a = d->ne_r[y]; b = d->no_r[y]; ra = d->ne_c; rb = d->no_c; }
++ expose_cam(d, d->sums + 3 * (y * W + xa), d->pos, xb - xa, a, b, ra, rb);
++ memset(lin + 3 * y * W, 0, 6 * xa);
++ memset(lin + 3 * (y * W + xb), 0, 6 * (W - xb));
++ expose_lin(d, d->pos, lin + 3 * (y * W + xa), xb - xa, g, xa);
++ }
++ d->lin = lin;
++}
++
++/* halation: the highlights' glow, spread about as the lab's gaussian
++ * (0.6 % of the frame) by two [1 2 1] passes each way on the grid */
++static void stage_glow(struct fos_dev *d)
++{
++ int32_t *g = d->glow, tmp[GW > GH ? GW : GH];
++ for (int i = 0; i < GW * GH; i++) g[i] >>= 4; /* the cell's mean */
++ for (int pass = 0; pass < 2; pass++)
++ {
++ for (int y = 0; y < GH; y++)
++ {
++ int32_t *r = g + y * GW;
++ for (int x = 0; x < GW; x++)
++ tmp[x] = (r[x > 0 ? x - 1 : 0] + 2 * r[x] + r[x < GW - 1 ? x + 1 : GW - 1]) >> 2;
++ memcpy(r, tmp, sizeof(int32_t) * GW);
++ }
++ for (int x = 0; x < GW; x++)
++ {
++ for (int y = 0; y < GH; y++)
++ tmp[y] = (g[(y > 0 ? y - 1 : 0) * GW + x] + 2 * g[y * GW + x] + g[(y < GH - 1 ? y + 1 : GH - 1) * GW + x]) >> 2;
++ for (int y = 0; y < GH; y++) g[y * GW + x] = tmp[y];
++ }
++ }
++}
++
++/* a cell of the glow grid and the weight of the next, in 1/8, for print
++ * line p: cell centres sit at 4j + 1.5 */
++static void glow_pos(int p, int n, uint8_t *cell, uint8_t *frac)
++{
++ int t = 2 * p - 3;
++ if (t < 0) { *cell = 0; *frac = 0; return; }
++ int j = t >> 3;
++ if (j >= n - 1) { *cell = (uint8_t) (n - 2); *frac = 8; return; }
++ *cell = (uint8_t) j;
++ *frac = (uint8_t) (t & 7);
++}
++
++/* Finishing a row of the print goes in three passes, each small enough
++ * for the registers: where its pixels fall on the film's table, the
++ * table, the grain. */
++
++/* n pixels from lin: the vignette (vig[x] for pixel x, in 1/4096) and the
++ * halation (the glow row grow mixed along it by gx, fx; hal: its colour)
++ * on the linear light, then its place on the grid */
++static __attribute__((noinline)) void finish_pos(const uint16_t *lin, uint16_t *pos, int n, int vy, const int16_t *vx,
++ const int32_t *grow, const uint8_t *gx, const uint8_t *fx, const int *hal)
++{
++ const uint16_t *cin = tab->cin;
++ if (!grow)
++ {
++ for (const uint16_t *e = lin + 3 * n; lin < e; lin += 3, pos += 3, vx++)
++ {
++ int vig = vy - *vx;
++ pos[0] = cin_pos(cin, (lin[0] * vig) >> 12);
++ pos[1] = cin_pos(cin, (lin[1] * vig) >> 12);
++ pos[2] = cin_pos(cin, (lin[2] * vig) >> 12);
++ }
++ return;
++ }
++ const int h0 = hal[0], h1 = hal[1], h2 = hal[2];
++ for (const uint16_t *e = lin + 3 * n; lin < e; lin += 3, pos += 3, vx++, gx++, fx++)
++ {
++ int vig = vy - *vx;
++ int a = *gx, f = *fx;
++ int glow = (grow[a] * (8 - f) + grow[a + 1] * f) >> 6;
++ pos[0] = cin_pos(cin, ((lin[0] * vig) >> 12) + ((glow * h0) >> 8));
++ pos[1] = cin_pos(cin, ((lin[1] * vig) >> 12) + ((glow * h1) >> 8));
++ pos[2] = cin_pos(cin, ((lin[2] * vig) >> 12) + ((glow * h2) >> 8));
++ }
++}
++
++static __attribute__((noinline)) void finish_lut(const uint16_t *pos, uint8_t *o, int n)
++{
++ const uint8_t (*lut)[3] = tab->lut;
++ for (const uint16_t *e = pos + 3 * n; pos < e; pos += 3, o += 3)
++ lut_apply(lut, pos[0], pos[1], pos[2], o);
++}
++
++/* grain at screen size: the lab's, softened by the downscale (grain: its
++ * strength), strongest in the mid tones */
++static __attribute__((noinline)) unsigned finish_grain(uint8_t *o, int n, unsigned seed, int grain, int mono)
++{
++ for (uint8_t *e = o + 3 * n; o < e; o += 3)
++ {
++ int l = (o[0] * 54 + o[1] * 183 + o[2] * 19) >> 8;
++ int wgt = (l * (255 - l)) >> 6;
++ int shared = rnd(&seed);
++ for (int c = 0; c < 3; c++)
++ {
++ int k = mono ? shared : (shared * 3 + rnd(&seed) * 2) / 4;
++ int v = o[c] + (int) (((long) k * grain >> 15) * wgt >> 16);
++ o[c] = (uint8_t) (v < 0 ? 0 : v > 255 ? 255 : v);
++ }
++ }
++ return seed;
++}
++
++/* row y of the print: vignette, halation, the film's table, grain */
++static __attribute__((noinline)) void stage_finish(struct fos_dev *d, int y)
++{
++ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
++ const struct fos_look *L = d->look;
++ int pw = d->rows_axis_x ? d->ow : W, px0 = d->rows_axis_x ? d->ox0 : 0;
++ if (y == 0)
++ {
++ /* vignette, as the lab: 1 - 0.12 r^2, r^2 = (x^2 + y^2) / 2 over
++ * -1..1; the x and y parts, in 1/4096 */
++ for (int x = 0; x < pw; x++) { float t = 2.0f * x / (pw - 1) - 1; d->vig_x[x] = (int16_t) (0.06f * t * t * 4096); }
++ for (int k = 0; k < H; k++) { float t = 2.0f * k / (H - 1) - 1; d->vig_y[k] = (int16_t) (0.06f * t * t * 4096); }
++ for (int x = 0; x < W; x++) glow_pos(x, GW, &d->gx[x], &d->fx[x]);
++ }
++ int hal[3];
++ for (int c = 0; c < 3; c++) hal[c] = d->glow ? (int) (L->halation * L->hal_tint[c] * 256) : 0;
++ /* the glow between the grid's two rows about this one, in 1/8 */
++ int32_t grow[GW];
++ if (d->glow)
++ {
++ uint8_t gy, fy;
++ glow_pos(y, GH, &gy, &fy);
++ const int32_t *g0 = d->glow + gy * GW, *g1 = g0 + GW;
++ for (int j = 0; j < GW; j++) grow[j] = g0[j] * (8 - fy) + g1[j] * fy;
++ }
++ uint8_t *o = d->rgb + 3 * y * W;
++ memset(o, 0, 3 * px0);
++ memset(o + 3 * (px0 + pw), 0, 3 * (W - px0 - pw));
++ finish_pos(d->lin + 3 * (y * W + px0), d->pos, pw, 4096 - d->vig_y[y], d->vig_x,
++ d->glow ? grow : 0, d->gx + px0, d->fx + px0, hal);
++ finish_lut(d->pos, o + 3 * px0, pw);
++ int grain = (int) (L->grain * 255 * 0.55f * 256);
++ if (grain) d->seed = finish_grain(o + 3 * px0, pw, d->seed, grain, L->mono);
++}
++
++/* the thumbnail: 6 x 6 boxes, a row of them at a time */
++static void make_thumb(struct fos_dev *d)
++{
++ const int W = FOS_PRINT_W;
++ int acc[FOS_THUMB_W * 3];
++ for (int ty = 0; ty < FOS_THUMB_H; ty++)
++ {
++ memset(acc, 0, sizeof(acc));
++ for (int j = 0; j < 6; j++)
++ {
++ const uint8_t *p = d->rgb + 3 * (ty * 6 + j) * W;
++ for (int tx = 0; tx < FOS_THUMB_W; tx++, p += 18)
++ {
++ int *a = acc + 3 * tx;
++ a[0] += p[0] + p[3] + p[6] + p[9] + p[12] + p[15];
++ a[1] += p[1] + p[4] + p[7] + p[10] + p[13] + p[16];
++ a[2] += p[2] + p[5] + p[8] + p[11] + p[14] + p[17];
++ }
++ }
++ for (int i = 0; i < FOS_THUMB_W * 3; i++)
++ d->thumb[3 * ty * FOS_THUMB_W + i] = (uint8_t) ((acc[i] * 455 + 8192) >> 14); /* / 36 */
++ }
++}
++
++int fos_dev_step(struct fos_dev *d, int budget_ms)
++{
++ if (!d) return -1;
++ int t0 = fos_port_ms(), cap = fos_port_dev_cap(), slices = 0;
++ const int W = FOS_PRINT_W, H = FOS_PRINT_H, N = W * H;
++ while ((fos_port_ms() - t0 < budget_ms || d->stage == ST_OPEN) && (!cap || slices++ < cap))
++ {
++ switch (d->stage)
++ {
++ case ST_OPEN:
++ if (!tables_ready()) return fail_mem(d, (int) sizeof(*tab));
++ d->f = fos_port_open(d->cr2, 0);
++ if (!d->f) return fail(d, "can't open the RAW file");
++ if (parse_tiff(d) < 0 || parse_ljpeg(d) < 0 || setup_maps(d) < 0) return -1;
++ {
++ char msg[320];
++ const char *name = strrchr(d->cr2, '/');
++ snprintf(msg, sizeof(msg), "dev: %s raw %dx%d (ljpeg %dx%d, %d comps, %d bits) slices %d x %d + %d, "
++ "picture %d,%d %dx%d, black cols %d..%d, orientation %d",
++ name ? name + 1 : d->cr2, d->raw_w, d->raw_h, d->wide, d->high, d->clrs, d->bits,
++ d->slices[0], d->slices[1], d->slices[2], d->crop_l, d->crop_t, d->crop_w, d->crop_h,
++ d->ob_l, d->ob_r, d->orient);
++ fos_port_log(msg);
++ }
++ d->buf = fos_port_alloc(CHUNK + 16);
++ if (!d->buf) return fail_mem(d, CHUNK + 16);
++ d->bp = d->be = d->buf;
++ d->safe = d->buf; /* the first read fills it */
++ d->ff = 0;
++ d->stage = ST_DECODE;
++ break;
++ case ST_DECODE:
++ /* the film's table first, a little at a time */
++ if (!lut_build(d->look, d->film, 64)) break;
++ decode(d, 1 << 14);
++ if (d->done >= d->total)
++ {
++ fos_port_close(d->f);
++ d->f = 0;
++ fos_port_free(d->buf); d->buf = 0;
++ d->rgb = fos_port_alloc(N * 3);
++ if (!d->rgb) return fail_mem(d, N * 3);
++ if (d->look->halation > 0)
++ {
++ d->glow = fos_port_alloc(GW * GH * 4);
++ if (d->glow) memset(d->glow, 0, GW * GH * 4);
++ }
++ setup_colour(d);
++ d->stage = ST_KEY;
++ return progress(d); /* the latent image can be read once more */
++ }
++ break;
++ case ST_KEY:
++ stage_key(d);
++ d->stage = ST_EXPOSE;
++ d->row = 0;
++ break;
++ case ST_EXPOSE:
++ stage_expose(d, d->row, d->row + 8);
++ d->row += 8;
++ if (d->row >= H) d->stage = d->glow ? ST_GLOW : ST_FINISH, d->row = 0;
++ break;
++ case ST_GLOW:
++ stage_glow(d);
++ d->stage = ST_FINISH;
++ d->row = 0;
++ break;
++ case ST_FINISH:
++ stage_finish(d, d->row);
++ if (++d->row == H)
++ {
++ make_thumb(d);
++ fos_port_free(d->sums); d->sums = 0; d->lin = 0;
++ fos_port_free(d->glow); d->glow = 0;
++ d->stage = d->jpeg[0] ? ST_JPEG : ST_QUANT;
++ }
++ break;
++ case ST_JPEG:
++ {
++ /* the picture only: a portrait frame without the print's sides */
++ int x0 = d->rows_axis_x ? d->ox0 : 0, w = d->rows_axis_x ? d->ow : W;
++ char desc[48];
++ snprintf(desc, sizeof(desc), "%s %s", fos_films[d->film].brand, fos_films[d->film].name);
++ struct fos_jpeg_meta m = { d->when, desc, d->fstop };
++ if (!fos_jpeg_write(d->jpeg, d->rgb + 3 * x0, 3 * W, w, H, 92, &m))
++ {
++ char msg[200];
++ snprintf(msg, sizeof(msg), "dev: can't write %s", d->jpeg);
++ fos_port_log(msg);
++ }
++ d->stage = ST_QUANT;
++ break;
++ }
++ case ST_QUANT:
++ if (!quant_alloc(d)) return fail_mem(d, 32768 * 5 + FOS_PRINT_W * FOS_PRINT_H);
++ d->stage = ST_DITHER;
++ d->row = 0;
++ break;
++ case ST_DITHER:
++ dither_rows(d, d->row, d->row + 8);
++ d->row += 8;
++ if (d->row >= H) d->stage = ST_WRITE;
++ break;
++ case ST_WRITE:
++ if (!write_print(d->print, d->film, d->frame, d->when, d->fstop, d->pal, d->npal, d->idx, d->thumb,
++ d->rows_axis_x ? d->ox0 : 0, d->rows_axis_x ? d->ow : W))
++ return fail(d, "can't write the print");
++ d->stage = ST_DONE;
++ return 1000;
++ case ST_DONE:
++ return 1000;
++ default:
++ return -1;
++ }
++ }
++ return progress(d);
++}
++
++/* ---------------------------------------------------------------- the contact sheet */
++
++int fos_dev_sheet(const char *sheet, int film, const char *const *prints, int frames)
++{
++ struct fos_dev *d = fos_dev_start("", sheet, film, 0, "", "");
++ if (!d) return 0;
++ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
++ d->rgb = fos_port_alloc(W * H * 3);
++ uint8_t *thumb = fos_port_alloc(FOS_THUMB_W * FOS_THUMB_H * 3);
++ if (!d->rgb || !thumb) { fos_port_free(thumb); fos_dev_free(d); return 0; }
++ /* strips of six frames on black, each frame inset by its rebate */
++ memset(d->rgb, 0, W * H * 3);
++ int rows = (frames + 5) / 6;
++ int y0 = (H - rows * FOS_THUMB_H) / 2;
++ for (int i = 0; i < frames; i++)
++ {
++ if (!prints[i] || !fos_print_thumb(prints[i], thumb)) continue;
++ int cx = (i % 6) * FOS_THUMB_W + FOS_SHEET_FX, cy = y0 + (i / 6) * FOS_THUMB_H + FOS_SHEET_FY;
++ for (int y = 0; y < FOS_SHEET_FH; y++)
++ for (int x = 0; x < FOS_SHEET_FW; x++)
++ {
++ int sx = x * FOS_THUMB_W / FOS_SHEET_FW, sy = y * FOS_THUMB_H / FOS_SHEET_FH;
++ memcpy(d->rgb + 3 * ((cy + y) * W + cx + x), thumb + 3 * (sy * FOS_THUMB_W + sx), 3);
++ }
++ if (i == 0) memcpy(d->thumb, thumb, sizeof(d->thumb)); /* the roll's own thumbnail */
++ }
++ fos_port_free(thumb);
++ int ok = quant_alloc(d);
++ if (ok)
++ {
++ dither_rows(d, 0, H);
++ ok = write_print(sheet, film, 0, "", "", d->pal, d->npal, d->idx, d->thumb, 0, W);
++ }
++ fos_dev_free(d);
++ return ok;
++}
++
++/* ---------------------------------------------------------------- the latent image */
++
++/* where print pixel (px, py) comes from on the sensor: its middle */
++static void raw_of(const struct fos_dev *d, int px, int py, int *rx, int *ry)
++{
++ int rlen, clen, a, b;
++ if (d->rows_axis_x) { rlen = d->ow; clen = d->oh; a = px - d->ox0; b = py; }
++ else { rlen = d->oh; clen = d->ow; a = py; b = px; }
++ if (d->orient == 6 || d->orient == 3) a = rlen - 1 - a;
++ if (d->orient == 8 || d->orient == 3) b = clen - 1 - b;
++ *ry = d->crop_t + (int) ((long) (2 * a + 1) * d->crop_h / (2 * rlen));
++ *rx = d->crop_l + (int) ((long) (2 * b + 1) * d->crop_w / (2 * clen));
++}
++
++int fos_dev_preview(const struct fos_dev *d, uint8_t *lum, int w, int h)
++{
++ if (!d || (d->stage != ST_DECODE && d->stage != ST_KEY) || !d->sums) return 0;
++ const int W = FOS_PRINT_W, H = FOS_PRINT_H;
++ for (int ty = 0; ty < h; ty++)
++ {
++ int py = (2 * ty + 1) * H / (2 * h);
++ for (int tx = 0; tx < w; tx++)
++ {
++ int px = (2 * tx + 1) * W / (2 * w);
++ uint8_t *o = &lum[ty * w + tx];
++ *o = 255; /* blank paper */
++ if (d->rows_axis_x && (px < d->ox0 || px >= d->ox0 + d->ow)) continue;
++ int rx, ry;
++ raw_of(d, px, py, &rx, &ry);
++ int reached = d->done >= d->total || rx < d->sx0 || (rx < d->sx0 + d->sw && ry < d->sy);
++ if (!reached) continue;
++ /* green, roughly exposed: enough to see the picture come */
++ int xr = d->rows_axis_x ? px - d->ox0 : py, xc = d->rows_axis_x ? py : px;
++ int n = d->ne_r[xr] * d->no_c[xc] + d->no_r[xr] * d->ne_c[xc];
++ if (!n) continue;
++ int g = (int) (d->sums[3 * (py * W + px) + 1] / n) - 2048;
++ int v = g <= 0 ? 0 : g >= 2900 ? 4096 : g * 4096 / 2900;
++ *o = (uint8_t) (fos_isqrt((unsigned) v * 16) * 255 / 256);
++ }
++ }
++ return 1;
++}
+diff --git a/src/fos_dev.h b/src/fos_dev.h
+new file mode 100644
+index 000000000..63938354c
+--- /dev/null
++++ b/src/fos_dev.h
+@@ -0,0 +1,153 @@
++/* fos_dev: developing film in the camera.
++ *
++ * A frame's CR2 RAW becomes a print for the screen: 720 x 480 in its own
++ * palette of FOS_PRINT_COLOURS colours. Developing runs in steps of a few
++ * tens of ms, so the film OS keeps animating on the same task while the
++ * camera works through a roll.
++ */
++
++#ifndef _fos_dev_h_
++#define _fos_dev_h_
++
++#include <stdint.h>
++
++/* ---------------------------------------------------------------- looks */
++
++/* a film's look, from films/films.py (see fos_looks.c; Darkrooms on the desktop uses the same) */
++struct fos_hue_shift { int8_t from, to; float amount, chroma; };
++struct fos_look
++{
++ const char *key; /* matches fos_films[].key */
++ int balance; /* K the film is balanced for */
++ int slide; /* reversal film: no scanner exposure */
++ float ev, sat;
++ float contrast[3], pivot[3], black[3], white[3];
++ int nhues;
++ struct fos_hue_shift hues[4];
++ float halation, hal_thr, hal_tint[3];
++ float grain, grain_size;
++ int mono;
++ float mono_mix[3];
++};
++extern const struct fos_look fos_looks[];
++extern const int fos_nlooks;
++/* the looks of the films from ML/DATA/FOSFILMS.BIN (fos_films_load) */
++extern const struct fos_look *fos_more_looks;
++extern int fos_nmore_looks;
++const struct fos_look *fos_look_of(const char *key);
++
++/* the film's colour for one scene-linear sRGB value (0.18 = mid grey):
++ * the print, display sRGB 0..1. Same model as film_color() in the lab. */
++void fos_film_color(const struct fos_look *f, const float lin[3], float out[3]);
++
++/* ---------------------------------------------------------------- prints */
++
++#define FOS_PRINT_W 720
++#define FOS_PRINT_H 480
++#define FOS_PRINT_COLOURS 240 /* palette indices 1..240 */
++#define FOS_FIXED_BASE 241 /* 241..254: the same in every palette */
++#define FOS_FIXED_N 14 /* 241..254 */
++#define FOS_THUMB_W 120
++#define FOS_THUMB_H 80
++
++struct fos_print
++{
++ int frame; /* 0 = the roll's contact sheet */
++ int film; /* index into fos_films */
++ char when[20]; /* "2026-10-22 17:45" */
++ char fstop[8];
++ int x0, w; /* the picture's columns (a portrait frame is narrower) */
++ uint8_t pal[FOS_PRINT_COLOURS][3];
++ uint8_t *px; /* FOS_PRINT_W x FOS_PRINT_H */
++};
++
++/* while a photograph is up, the overlay draws with these */
++enum { PX_BLACK = FOS_FIXED_BASE, PX_PANEL, PX_G1, PX_G2, PX_G3, PX_G4, PX_G5, PX_WHITE,
++ PX_AMBER, PX_AMBER2, PX_RED, PX_LINE, PX_DIM, PX_SPARE };
++extern const uint8_t fos_fixed_rgb[FOS_FIXED_N][3];
++
++int fos_print_load(const char *path, struct fos_print *p); /* allocates p->px; 0 on failure */
++void fos_print_free(struct fos_print *p);
++int fos_print_thumb(const char *path, uint8_t *thumb); /* FOS_THUMB_W x FOS_THUMB_H RGB */
++
++/* ---------------------------------------------------------------- developing */
++
++struct fos_dev;
++
++/* where the film tables are kept between sessions (NULL: not kept) */
++void fos_dev_cache(const char *dir);
++/* build film's table into the cache now (the build makes the card's copies) */
++int fos_dev_table(int film);
++/* also write the frame in full colour as a JPEG at path (before the first step) */
++void fos_dev_jpeg(struct fos_dev *d, const char *path);
++/* forget the film table (leaving the darkroom) */
++void fos_dev_release();
++
++/* develop one frame: cr2 in, a print file out */
++struct fos_dev *fos_dev_start(const char *cr2, const char *print, int film, int frame,
++ const char *when, const char *fstop);
++/* work for about budget_ms; returns progress 0..1000, 1000 when the print
++ * is written, or < 0 when the frame can't be developed */
++int fos_dev_step(struct fos_dev *d, int budget_ms);
++/* the finished frame, small, RGB: for the contact sheet and the animation */
++const uint8_t *fos_dev_thumb(const struct fos_dev *d);
++const char *fos_dev_error(const struct fos_dev *d);
++/* what it is doing, for the darkroom's animation */
++enum { FOS_DEV_MIXING, FOS_DEV_DEVELOPING, FOS_DEV_FIXING, FOS_DEV_DRYING, FOS_DEV_DONE, FOS_DEV_FAILED };
++int fos_dev_doing(const struct fos_dev *d);
++int fos_dev_progress(const struct fos_dev *d); /* 0..1000, as fos_dev_step returned */
++void fos_dev_picture(const struct fos_dev *d, int *x0, int *w); /* the picture's columns on the print */
++void fos_dev_free(struct fos_dev *d);
++
++/* the print in progress, w x h, as the latent image coming up: a rough
++ * luminance, 255 (paper) where nothing has been read yet; 0 if there is
++ * nothing to show (not reading the RAW) */
++int fos_dev_preview(const struct fos_dev *d, uint8_t *lum, int w, int h);
++
++/* the roll's contact sheet from its frames' prints (NULL: not
++ * developed); written as a print with frame 0. Frame i sits in cell
++ * (i % 6, i / 6) of FOS_THUMB_W x FOS_THUMB_H cells, rows centred */
++#define FOS_SHEET_FX 6
++#define FOS_SHEET_FY 4
++#define FOS_SHEET_FW 108
++#define FOS_SHEET_FH 72
++int fos_dev_sheet(const char *sheet, int film, const char *const *prints, int frames);
++
++/* ---------------------------------------------------------------- the rolls on the card (fos_lab.c) */
++
++#define FOS_MAX_FRAMES 40
++
++struct fos_lab_roll
++{
++ int number;
++ int film; /* index into fos_films */
++ int exposures;
++ int shot; /* frames in its logs */
++ int developed; /* frames with a print */
++ int sheet; /* its contact sheet is there */
++ int jpegs; /* JPEGs in its folder in DCIM */
++ int in_camera; /* still loaded: rewind it before developing */
++ char loaded[17]; /* "2026-10-22 17:45" */
++ char last[17]; /* its last frame */
++};
++
++struct fos_lab_frame
++{
++ int no;
++ char cr2[64];
++ int missing; /* the file isn't there (deleted, or shot as JPEG) */
++ char when[17];
++ char fstop[6];
++};
++
++int fos_lab_scan(struct fos_lab_roll *rolls, int max); /* newest first; how many */
++int fos_lab_frames(int roll, struct fos_lab_frame *frames, int max); /* frame order; how many */
++void fos_lab_print_path(char *buf, int size, int roll, int frame); /* frame 0: the contact sheet */
++int fos_lab_prepare(int roll); /* its print folder; 0 = ok */
++void fos_lab_cache_dir(char *buf, int size); /* where film tables are kept */
++/* the roll's folder of JPEGs in DCIM, made if need be: "Sep0906 Portra400"
++ * (month, month number, day of its first frame; when: "2026-09-06 10:15")
++ * or SEP0906 where the card takes no long names. 0 = ok */
++int fos_lab_dcim_dir(char *buf, int size, int roll, int film, const char *when);
++
++#endif
+diff --git a/src/fos_film.c b/src/fos_film.c
+new file mode 100644
+index 000000000..b95883d66
+--- /dev/null
++++ b/src/fos_film.c
+@@ -0,0 +1,1132 @@
++/* fos_film: the film stocks, and their 35 mm canisters drawn as small 3D
++ * objects - a lithographed steel cylinder with crimped caps, the spool end
++ * on top, the felt light trap and the film leader sticking out of it.
++ *
++ * Each stock's label is painted once into a texture that wraps around the
++ * cylinder, a ramp and a level per texel with the anti-aliased edges
++ * already blended. Light on a cylinder only scales and lifts levels, so
++ * each column of the drawing folds its shading into a gain and an offset
++ * per ramp, and a label pixel costs a lookup, a multiply and a dither.
++ */
++
++#include "fos.h"
++#include "fos_dev.h"
++#include <math.h>
++#include <stddef.h>
++#include <string.h>
++
++/* ---------------------------------------------------------------- the stocks */
++
++/* Picture style values are starting points for the in-camera JPEG preview
++ * only; the real look comes from the lab. Mono stocks leave saturation and
++ * tone alone because the Monochrome style uses those for filter / toning. */
++static const struct fos_film builtin[] =
++{
++ { "portra400", "KODAK", "Portra 400", "C-41", "Soft warm skin, gentle highlights",
++ 400, 400, PS_STANDARD, -1, -1, 1, 2, 5500, 0, 1, 2, 2, 2, 4, "Portra400", FOS_GROUP_COLOUR, 0 },
++ { "cinestill800t", "CINESTILL", "800T", "C-41", "Tungsten cine film, night goes blue",
++ 800, 800, PS_STANDARD, 1, 1, -1, 2, 3200, 0, 0, 4, 3, 3, 1, "CineStill800T", FOS_GROUP_CINE, 0 },
++ { "ektar100", "KODAK", "Ektar 100", "C-41", "Punchy colour, ultra fine grain",
++ 100, 100, PS_LANDSCAPE, 1, 2, 0, 3, 5200, 0, 0, 1, 4, 5, 3, "Ektar100", FOS_GROUP_COLOUR, 0 },
++ { "gold200", "KODAK", "Gold 200", "C-41", "Golden hour, all day long",
++ 200, 200, PS_STANDARD, 1, 1, 2, 2, 5600, 0, 2, 3, 3, 4, 5, "Gold200", FOS_GROUP_COLOUR, 0 },
++ { "superia400", "FUJIFILM", "Superia 400", "C-41", "Green shadows, everyday snaps",
++ 400, 400, PS_STANDARD, 1, 1, 0, 2, 5200, 1, 0, 3, 3, 3, 2, "Superia400", FOS_GROUP_COLOUR, 0 },
++ { "velvia50", "FUJIFILM", "Velvia 50", "E-6", "Vivid slide film, hard contrast",
++ 50, 100, PS_LANDSCAPE, 3, 4, 0, 3, 5200, 0, 0, 1, 5, 5, 3, "Velvia50", FOS_GROUP_SLIDE, 0 },
++ { "hp5", "ILFORD", "HP5 Plus", "B&W", "Classic B&W, forgiving latitude",
++ 400, 400, PS_MONO, 1, 0, 0, 2, 5200, 0, 0, 4, 2, 0, 0, "HP5", FOS_GROUP_BW, 0 },
++ { "trix400", "KODAK", "Tri-X 400", "B&W", "Gritty contrast, street classic",
++ 400, 400, PS_MONO, 3, 0, 0, 2, 5200, 0, 0, 5, 4, 0, 0, "TriX400", FOS_GROUP_BW, 0 },
++};
++#define NBUILTIN ((int) (sizeof(builtin) / sizeof(builtin[0])))
++
++const struct fos_film *fos_films = builtin;
++int fos_nfilms = NBUILTIN;
++
++const char *const fos_group_names[FOS_NGROUPS] = { "COLOUR", "SLIDE", "B&W", "CINE" };
++
++const struct fos_look *fos_more_looks;
++int fos_nmore_looks;
++
++/* A film in ML/DATA/FOSFILMS.BIN (written by tools/genfilms.py, which
++ * packs the same layout): after a 12-byte header ("FOSM", version, record
++ * size, count), one of these each. The look is struct fos_look from its
++ * balance on, as the camera lays it out. */
++#define LOOK_FROM offsetof(struct fos_look, balance)
++#define LOOK_BYTES (offsetof(struct fos_look, mono_mix) + sizeof(((struct fos_look *) 0)->mono_mix) - LOOK_FROM)
++struct film_rec
++{
++ char key[16], brand[16], name[24], process[8], desc[48], shortname[24];
++ int32_t box_iso, iso, picstyle, contrast, saturation, color_tone, sharpness, kelvin, wbs_gm, wbs_ba;
++ uint8_t grain, punch, colour, warmth;
++ int32_t group;
++ struct fos_label label;
++ uint8_t look[LOOK_BYTES];
++};
++
++int fos_films_load(const uint8_t *blob, int size)
++{
++ if (!blob || size < 12 || memcmp(blob, "FOSM", 4) || blob[4] != 1) return 0;
++ int rs = blob[6] | blob[7] << 8, n = (int) (blob[8] | blob[9] << 8);
++ if (rs != (int) sizeof(struct film_rec) || size < 12 + n * rs || n <= 0) return 0;
++ struct fos_film *all = fos_port_alloc((NBUILTIN + n) * (int) sizeof(*all));
++ struct fos_look *looks = fos_port_alloc(n * (int) sizeof(*looks));
++ if (!all || !looks) { fos_port_free(all); fos_port_free(looks); return 0; }
++ memcpy(all, builtin, sizeof(builtin));
++ for (int i = 0; i < n; i++)
++ {
++ struct film_rec *r = (struct film_rec *) (blob + 12 + i * rs);
++ r->key[15] = r->brand[15] = r->name[23] = r->process[7] = r->desc[47] = r->shortname[23] = 0;
++ r->label.top[19] = r->label.word[13] = r->label.num_s[7] = r->label.sub[17] = 0;
++ struct fos_film *f = &all[NBUILTIN + i];
++ *f = (struct fos_film) { r->key, r->brand, r->name, r->process, r->desc, r->box_iso, r->iso, r->picstyle,
++ r->contrast, r->saturation, r->color_tone, r->sharpness, r->kelvin, r->wbs_gm, r->wbs_ba,
++ r->grain, r->punch, r->colour, r->warmth, r->shortname,
++ fos_clamp(r->group, 0, FOS_NGROUPS - 1), &r->label };
++ memset(&looks[i], 0, sizeof(looks[i]));
++ looks[i].key = r->key;
++ memcpy((uint8_t *) &looks[i] + LOOK_FROM, r->look, LOOK_BYTES);
++ looks[i].nhues = fos_clamp(looks[i].nhues, 0, 4);
++ }
++ fos_films = all;
++ fos_nfilms = NBUILTIN + n;
++ fos_more_looks = looks;
++ fos_nmore_looks = n;
++ return 1;
++}
++
++const int fos_exposure_choices[FOS_NEXP] = { 36, 24, 12 };
++
++/* f-numbers x100 in 1/3 stops; index i sits (i - 1) thirds above f/1
++ * (f/0.95 is close enough to f/1 to share the bottom of the scale) */
++const int fos_fstops[] =
++{
++ 95, 100, 110, 120, 140, 160, 180, 200, 220, 250,
++ 280, 320, 350, 400, 450, 500, 560, 630, 710, 800,
++ 900, 1000, 1100, 1300, 1400, 1600, 1800, 2000, 2200,
++};
++const int fos_nfstops = sizeof(fos_fstops) / sizeof(fos_fstops[0]);
++
++void fos_format_fstop(char *buf, int size, int index)
++{
++ int v = fos_fstops[fos_clamp(index, 0, fos_nfstops - 1)];
++ if (v < 100)
++ snprintf(buf, size, "0.%02d", v);
++ else if (v % 100 == 0 || v >= 1000)
++ snprintf(buf, size, "%d", v / 100);
++ else
++ snprintf(buf, size, "%d.%d", v / 100, (v / 10) % 10);
++}
++
++/* ---------------------------------------------------------------- geometry */
++
++/* full-size canister, px */
++#define R 50 /* body radius */
++#define RC 53 /* caps stick out a little */
++#define RS 19 /* spool end */
++#define HB 150 /* body (label) height */
++#define TB 9 /* top crimp band */
++#define BB 8 /* bottom crimp band */
++#define HS 12 /* spool end above the cap */
++#define TILT 56 /* ellipse height / width, 1/256: we look down ~13 degrees */
++
++/* label texture: 360 degrees across, body height down */
++#define TW 320
++#define TH HB
++#define U_FRONT (TW / 2) /* texture column facing us at rot 0 */
++#define U_LIP (U_FRONT + TW * 82 / 360) /* the felt lip, on the right */
++
++int fos_can_quality = 2;
++
++struct fos_can
++{
++ int film;
++ int exposures;
++ uint16_t *tex; /* ramp << 12 | 12-bit level, column by column */
++ int ramps; /* bit mask of the ramps in it */
++ int gloss; /* 0..256 */
++ int leader_ramp, leader_lv;
++};
++
++int fos_can_height(int scale)
++{
++ int e = RC * TILT / 256;
++ return (HS + RS * TILT / 256 + e + TB + HB + BB + e) * scale / 256;
++}
++
++int fos_can_width(int scale)
++{
++ return 2 * RC * scale / 256;
++}
++
++/* ---------------------------------------------------------------- shading profiles */
++
++/* sampled across the cylinder, x / radius from -1 to +1 */
++#define NPROF 256
++static int16_t prof_ang[NPROF]; /* surface angle, 1/65536 turn (+ = right) */
++static int16_t prof_light[NPROF]; /* printed label: diffuse, 0..256 */
++static int16_t prof_spec[NPROF]; /* printed label: gloss highlight, 0..256 */
++static int16_t prof_metal[NPROF]; /* steel caps: 12-bit level */
++static int16_t prof_dark[NPROF]; /* black plastic spool: 12-bit level */
++static int prof_ready = 0;
++
++static float smooth(float a, float b, float x)
++{
++ float t = (x - a) / (b - a);
++ t = t < 0 ? 0 : t > 1 ? 1 : t;
++ return t * t * (3 - 2 * t);
++}
++
++static float lobe(float th, float centre, float width)
++{
++ float d = (th - centre) / width;
++ return expf(-d * d);
++}
++
++static void build_profiles()
++{
++ const float deg = 3.14159265f / 180;
++ for (int i = 0; i < NPROF; i++)
++ {
++ float xn = (i + 0.5f) / NPROF * 2 - 1;
++ float th = asinf(xn); /* -90..90 degrees */
++ prof_ang[i] = (int16_t) (th / (2 * 3.14159265f) * 65536);
++
++ /* softbox up-left in front, a rim light behind on the right */
++ float key = cosf(th + 38 * deg);
++ key = (key + 0.35f) / 1.35f;
++ key = key < 0 ? 0 : key;
++ float rim = smooth(55 * deg, 86 * deg, th) * 0.55f;
++ float edge = 0.62f + 0.38f * sqrtf(cosf(th));
++ float light = (0.16f + 0.84f * key) * edge + rim;
++ prof_light[i] = (int16_t) (light * 256);
++
++ float sheen = lobe(th, -24 * deg, 16 * deg) * 0.22f + lobe(th, -21 * deg, 3.0f * deg) * 0.55f
++ + lobe(th, 74 * deg, 6 * deg) * 0.25f;
++ prof_spec[i] = (int16_t) (sheen * 256);
++
++ /* brushed steel: dark body with sharp reflections of the studio */
++ float m = 0.24f + 0.30f * key
++ + 0.55f * lobe(th, -22 * deg, 9 * deg)
++ + 0.30f * lobe(th, -55 * deg, 14 * deg)
++ + 0.18f * lobe(th, 30 * deg, 18 * deg)
++ + 0.45f * lobe(th, 80 * deg, 7 * deg);
++ m *= edge;
++ prof_metal[i] = (int16_t) fos_clamp((int) (m * LV_MAX), 0, LV_MAX);
++
++ float p = 0.06f + 0.10f * key + 0.22f * lobe(th, -25 * deg, 8 * deg) + 0.12f * lobe(th, 78 * deg, 8 * deg);
++ prof_dark[i] = (int16_t) fos_clamp((int) (p * LV_MAX), 0, LV_MAX);
++ }
++ prof_ready = 1;
++}
++
++/* profile index for d (1/256 px from the left edge) with inv = NPROF * 65536 / diameter */
++#define PROF(d, inv) fos_clamp(((d) * (inv)) >> 16, 0, NPROF - 1)
++
++/* ---------------------------------------------------------------- label painting */
++
++/* an ink is the texel it paints */
++static int ink(struct fos_can *c, int ramp, int level)
++{
++ c->ramps |= 1 << ramp;
++ return ramp << 12 | LV12(level);
++}
++
++/* texture column for u, which is never more than a turn out */
++FOS_INLINE int wrap_u(int u)
++{
++ return u < 0 ? u + TW : u >= TW ? u - TW : u;
++}
++
++/* put ink k with coverage cov (0..15) on texel (u, v) */
++static void tex_put(struct fos_can *c, int u, int v, int k, int cov)
++{
++ if (cov <= 0 || v < 0 || v >= TH) return;
++ uint16_t *t = &c->tex[wrap_u(u) * TH + v];
++ if (cov >= 15) { *t = k; return; }
++ int r, lv;
++ fos_lerp2(*t >> 12, *t & 0xFFF, k >> 12, k & 0xFFF, cov * 17, &r, &lv);
++ *t = r << 12 | lv;
++}
++
++static void tex_rect(struct fos_can *c, int u, int v, int w, int h, int k)
++{
++ if (v < 0) { h += v; v = 0; }
++ if (v + h > TH) h = TH - v;
++ for (int i = u; i < u + w && h > 0; i++)
++ {
++ uint16_t *t = &c->tex[wrap_u(i) * TH + v];
++ for (int j = 0; j < h; j++)
++ t[j] = k;
++ }
++}
++
++/* glyph coverage straight from the font, optionally turned 90 degrees
++ * counter-clockwise (text reading upwards) */
++static void tex_glyph(struct fos_can *c, const struct fos_font *f, const struct fos_glyph *g,
++ int u, int v, int k, int vertical)
++{
++ const uint8_t *p = f->bits + g->off;
++ int col = 0, row = 0;
++ while (row < g->h)
++ {
++ int b = *p++;
++ int run, val;
++ if (b & 0x80) { run = (b & 0x7F) + 1; val = 0; }
++ else { run = (b >> 4) + 1; val = b & 15; }
++ while (run--)
++ {
++ if (val)
++ {
++ int gx = g->ox + col, gy = g->oy + row;
++ if (vertical) tex_put(c, u + gy, v - gx, k, val);
++ else tex_put(c, u + gx, v + gy, k, val);
++ }
++ if (++col == g->w) { col = 0; row++; }
++ }
++ }
++}
++
++/* text along the label; align -1 left, 0 centre, 1 right; returns width */
++static int tex_text(struct fos_can *c, const struct fos_font *f, int u, int base, const char *s,
++ int k, int track, int align)
++{
++ int w = fos_text_w(f, s, track);
++ int pen = (u - (align + 1) * w / 2) * 16;
++ for (const char *q = s; *q; q++)
++ {
++ int i = f->lut[(uint8_t) *q];
++ if (i == 0xFF) continue;
++ const struct fos_glyph *g = &f->glyphs[i];
++ tex_glyph(c, f, g, (pen + 8) >> 4, base, k, 0);
++ pen += g->adv + track;
++ }
++ return w;
++}
++
++/* text reading upwards, centred on (u, v); the baseline is at u */
++static void tex_vtext(struct fos_can *c, const struct fos_font *f, int u, int v, const char *s, int k, int track)
++{
++ int w = fos_text_w(f, s, track);
++ int pen = (v + w / 2) * 16;
++ for (const char *q = s; *q; q++)
++ {
++ int i = f->lut[(uint8_t) *q];
++ if (i == 0xFF) continue;
++ const struct fos_glyph *g = &f->glyphs[i];
++ tex_glyph(c, f, g, u, (pen + 8) >> 4, k, 1);
++ pen -= g->adv + track;
++ }
++}
++
++/* DX CAS code: two rows of six cells, bare steel (conducts) or painted.
++ * The first cell of each row is always bare; the rest come from the box
++ * speed and the exposure count, like the real thing (close enough). */
++static void tex_dx(struct fos_can *c, int u, int v, int iso, int exposures, int steel, int paint)
++{
++ static const int isos[] = { 25, 50, 64, 100, 125, 160, 200, 400, 800, 1600, 3200 };
++ int code = 0;
++ for (int i = 0; i < (int) (sizeof(isos) / sizeof(isos[0])); i++)
++ if (isos[i] == iso) code = i + 3;
++ int row1 = 1 | (code << 1);
++ int row2 = 1 | ((exposures == 36 ? 5 : exposures == 24 ? 3 : 2) << 1) | 0x20;
++ for (int i = 0; i < 6; i++)
++ {
++ tex_rect(c, u + i * 7, v, 6, 8, (row1 >> i) & 1 ? steel : paint);
++ tex_rect(c, u + i * 7, v + 9, 6, 8, (row2 >> i) & 1 ? steel : paint);
++ }
++}
++
++/* a UPC-ish barcode, the same for the same stock, about 50 texels wide */
++static void tex_barcode(struct fos_can *c, int u, int v, int h, const char *seed, int ink_bar)
++{
++ unsigned int x = 2166136261u;
++ for (const char *s = seed; *s; s++) x = (x ^ (uint8_t) *s) * 16777619u;
++ int pos = u;
++ for (int i = 0; i < 18; i++)
++ {
++ x = x * 1103515245u + 12345u;
++ int bar = 1 + (x >> 16) % 2, gap = 1 + (x >> 20) % 2;
++ int hh = (i == 0 || i == 9 || i == 17) ? h + 3 : h;
++ tex_rect(c, pos, v, bar, hh, ink_bar);
++ pos += bar + gap;
++ }
++}
++
++/* the parts every canister shares: the felt lip, and the back with the
++ * DX code, the barcode and the small print. Going round from the lip:
++ * DX code and exposures, barcode, then "PROCESS" reading upwards, all
++ * clear of the front panel (about U_FRONT +- 65). */
++static void paint_common(struct fos_can *c, int body, int text, const char *process)
++{
++ const struct fos_film *f = &fos_films[c->film];
++ int steel = ink(c, RAMP_METAL, 205);
++ int black = ink(c, RAMP_GRAY, 16);
++ int felt = ink(c, RAMP_GRAY, 9);
++
++ /* the light trap: a strip of black velvet between two folded edges */
++ tex_rect(c, U_LIP - 5, 0, 10, TH, felt);
++ tex_rect(c, U_LIP - 7, 0, 2, TH, steel);
++ tex_rect(c, U_LIP + 5, 0, 2, TH, steel);
++
++ char buf[32];
++ int u_dx = U_LIP + 22; /* 255 */
++ tex_rect(c, u_dx - 3, TH / 2 - 12, 48, 24, black);
++ tex_dx(c, u_dx, TH / 2 - 9, f->box_iso, c->exposures, steel, black);
++ snprintf(buf, sizeof(buf), "135-%d", c->exposures);
++ tex_text(c, &fos_font_lsm, u_dx + 21, TH / 2 - 20, buf, text, 16, 0);
++
++ tex_barcode(c, U_LIP + 76, TH - 52, 26, f->key, text); /* 309, round the seam */
++
++ snprintf(buf, sizeof(buf), "PROCESS %s", process);
++ tex_vtext(c, &fos_font_lsm, 64, TH / 2, buf, text, 16);
++ (void) body;
++}
++
++/* text that fits the front of the canister: the widest tracking that does,
++ * squeezed a little if even none is too wide */
++static void tex_text_fit(struct fos_can *c, const struct fos_font *f, int u, int base, const char *s, int k, int track)
++{
++ const int room = 108;
++ while (track > -32 && fos_text_w(f, s, track) > room) track -= 4;
++ tex_text(c, f, u, base, s, k, track, 0);
++}
++
++static int label_ink(struct fos_can *c, const uint8_t ink2[2])
++{
++ return ink(c, ink2[0] < RAMP_COUNT ? ink2[0] : RAMP_GRAY, ink2[1]);
++}
++
++/* a label from its parts (struct fos_label): the films from the card */
++static void paint_parts(struct fos_can *c, const struct fos_film *f)
++{
++ const struct fos_label *l = f->label;
++ const int u = U_FRONT - 4;
++ int bg = label_ink(c, l->bg), band = label_ink(c, l->band), acc = label_ink(c, l->accent);
++ int txt = label_ink(c, l->text), num = label_ink(c, l->num);
++ char bottom[40];
++ if (l->sub[0]) snprintf(bottom, sizeof(bottom), "%s 135-%d", l->sub, c->exposures);
++ else snprintf(bottom, sizeof(bottom), "135-%d", c->exposures);
++ tex_rect(c, 0, 0, TW, TH, bg);
++ const struct fos_font *word = fos_text_w(&fos_font_lname, l->word, -32) <= 108 ? &fos_font_lname : &fos_font_lsm;
++ switch (l->style)
++ {
++ case FOS_LABEL_CAP: /* a coloured cap over the top (Portra) */
++ tex_rect(c, 0, 0, TW, 24, band);
++ tex_rect(c, 0, 24, TW, 4, acc);
++ tex_text_fit(c, &fos_font_lsm, u, 17, l->top, acc, 24);
++ tex_text_fit(c, word, u, 58, l->word, txt, 40);
++ tex_text(c, &fos_font_lbig, u, 112, l->num_s, num, 0, 0);
++ tex_rect(c, 0, 120, TW, 3, acc);
++ tex_rect(c, 0, 125, TW, 9, band);
++ tex_text_fit(c, &fos_font_lsm, u, 147, bottom, txt, 16);
++ break;
++ case FOS_LABEL_STRIPES: /* thin stripes top and bottom (Ektar) */
++ tex_rect(c, 0, 6, TW, 5, acc);
++ tex_rect(c, 0, TH - 11, TW, 5, acc);
++ tex_text_fit(c, &fos_font_lsm, u, 30, l->top, acc, 24);
++ tex_text_fit(c, word, u, 60, l->word, txt, 40);
++ tex_text(c, &fos_font_lbig, u, 116, l->num_s, num, 0, 0);
++ tex_text_fit(c, &fos_font_lsm, u, 133, bottom, txt, 16);
++ break;
++ default: /* a band the name sits on (Gold) */
++ tex_rect(c, 0, 36, TW, 34, band);
++ tex_text_fit(c, &fos_font_lsm, u, 26, l->top, acc, 40);
++ tex_text_fit(c, word, u, 63, l->word, txt, 48);
++ tex_text(c, &fos_font_lbig, u, 122, l->num_s, num, 0, 0);
++ tex_text_fit(c, &fos_font_lsm, u, 140, bottom, num, 16);
++ break;
++ }
++ paint_common(c, bg, txt, f->process);
++ if (l->leader)
++ {
++ c->leader_ramp = RAMP_GRAY;
++ c->leader_lv = LV12(l->leader);
++ }
++}
++
++static void paint_label(struct fos_can *c)
++{
++ const struct fos_film *f = &fos_films[c->film];
++ const int u = U_FRONT - 4; /* optical centre of the front panel */
++ char exp[16];
++ snprintf(exp, sizeof(exp), "135-%d", c->exposures);
++ c->ramps = 1 << RAMP_GRAY; /* what an unpainted texel is */
++ c->gloss = 220;
++ c->leader_ramp = RAMP_LEADER;
++ c->leader_lv = LV12(120);
++
++ if (f->label)
++ paint_parts(c, f);
++ else if (!strcmp(f->key, "portra400"))
++ {
++ int cream = ink(c, RAMP_GRAY, 226), yel = ink(c, RAMP_AMBER, 188), org = ink(c, RAMP_ORANGE, 160);
++ int red = ink(c, RAMP_RED, 150), blk = ink(c, RAMP_GRAY, 22);
++ tex_rect(c, 0, 0, TW, TH, cream);
++ tex_rect(c, 0, 0, TW, 24, yel);
++ tex_rect(c, 0, 24, TW, 4, org);
++ tex_text(c, &fos_font_lsm, u, 17, "KODAK PROFESSIONAL", red, 24, 0);
++ tex_text(c, &fos_font_lname, u, 58, "PORTRA", blk, 40, 0);
++ tex_text(c, &fos_font_lbig, u, 112, "400", blk, 0, 0);
++ tex_rect(c, 0, 120, TW, 3, org);
++ tex_rect(c, 0, 125, TW, 9, yel);
++ tex_text(c, &fos_font_lsm, u, 147, exp, blk, 16, 0);
++ tex_vtext(c, &fos_font_lname, u - 62, 76, "KODAK", red, 24);
++ paint_common(c, cream, blk, f->process);
++ }
++ else if (!strcmp(f->key, "cinestill800t"))
++ {
++ int blk = ink(c, RAMP_GRAY, 20), red = ink(c, RAMP_RED, 150), wht = ink(c, RAMP_GRAY, 238);
++ tex_rect(c, 0, 0, TW, TH, blk);
++ tex_rect(c, 0, 10, TW, 3, red);
++ tex_rect(c, 0, TH - 13, TW, 3, red);
++ tex_text(c, &fos_font_lname, u, 44, "CINESTILL", wht, 24, 0);
++ int w = fos_text_w(&fos_font_lbig, "800T", 0);
++ int x0 = u - w / 2;
++ int w8 = tex_text(c, &fos_font_lbig, x0, 104, "800", wht, 0, -1);
++ tex_text(c, &fos_font_lbig, x0 + w8, 104, "T", red, 0, -1);
++ tex_text(c, &fos_font_lsm, u, 124, "TUNGSTEN 3200K", red, 24, 0);
++ tex_text(c, &fos_font_lsm, u, 139, exp, wht, 16, 0);
++ paint_common(c, blk, wht, f->process);
++ }
++ else if (!strcmp(f->key, "ektar100"))
++ {
++ int crim = ink(c, RAMP_CRIMSON, 128), yel = ink(c, RAMP_AMBER, 188), wht = ink(c, RAMP_GRAY, 240);
++ tex_rect(c, 0, 0, TW, TH, crim);
++ tex_rect(c, 0, 6, TW, 5, yel);
++ tex_rect(c, 0, TH - 11, TW, 5, yel);
++ tex_text(c, &fos_font_lsm, u, 30, "KODAK PROFESSIONAL", yel, 24, 0);
++ tex_text(c, &fos_font_lname, u, 60, "EKTAR", wht, 48, 0);
++ tex_text(c, &fos_font_lbig, u, 116, "100", yel, 0, 0);
++ tex_text(c, &fos_font_lsm, u, 132, exp, wht, 16, 0);
++ paint_common(c, crim, wht, f->process);
++ }
++ else if (!strcmp(f->key, "gold200"))
++ {
++ int yel = ink(c, RAMP_AMBER, 190), red = ink(c, RAMP_RED, 148), blk = ink(c, RAMP_GRAY, 22);
++ int wht = ink(c, RAMP_GRAY, 240);
++ tex_rect(c, 0, 0, TW, TH, yel);
++ tex_rect(c, 0, 36, TW, 32, red);
++ tex_text(c, &fos_font_lsm, u, 24, "KODAK", red, 48, 0);
++ tex_text(c, &fos_font_lname, u, 62, "GOLD", wht, 56, 0);
++ tex_text(c, &fos_font_lbig, u, 122, "200", blk, 0, 0);
++ tex_text(c, &fos_font_lsm, u, 140, exp, blk, 16, 0);
++ tex_vtext(c, &fos_font_lsm, u - 60, 96, "COLOR", red, 24);
++ paint_common(c, yel, blk, f->process);
++ }
++ else if (!strcmp(f->key, "superia400"))
++ {
++ int grn = ink(c, RAMP_GREEN, 140), wht = ink(c, RAMP_GRAY, 240), red = ink(c, RAMP_RED, 150);
++ int dk = ink(c, RAMP_GREEN, 70);
++ tex_rect(c, 0, 0, TW, TH, grn);
++ tex_rect(c, 0, 72, TW, 52, dk);
++ tex_rect(c, 0, 124, TW, 3, red);
++ tex_text(c, &fos_font_lsm, u, 24, "FUJIFILM", wht, 48, 0);
++ tex_text(c, &fos_font_lname, u, 58, "SUPERIA", wht, 24, 0);
++ tex_text(c, &fos_font_lbig, u, 118, "400", wht, 0, 0);
++ tex_text(c, &fos_font_lsm, u, 142, exp, wht, 16, 0);
++ paint_common(c, grn, wht, f->process);
++ }
++ else if (!strcmp(f->key, "velvia50"))
++ {
++ int vio = ink(c, RAMP_VIOLET, 118), wht = ink(c, RAMP_GRAY, 240), lil = ink(c, RAMP_VIOLET, 225);
++ tex_rect(c, 0, 0, TW, TH, vio);
++ tex_rect(c, 0, 0, TW, 6, lil);
++ tex_rect(c, 0, TH - 6, TW, 6, lil);
++ tex_text(c, &fos_font_lsm, u, 28, "FUJICHROME", wht, 32, 0);
++ tex_text(c, &fos_font_lname, u, 58, "VELVIA", wht, 40, 0);
++ tex_text(c, &fos_font_lbig, u, 116, "50", lil, 0, 0);
++ tex_text(c, &fos_font_lsm, u, 134, "RVP 50 " , wht, 24, 0);
++ paint_common(c, vio, wht, f->process);
++ c->leader_lv = LV12(70);
++ }
++ else if (!strcmp(f->key, "hp5"))
++ {
++ int wht = ink(c, RAMP_GRAY, 236), blk = ink(c, RAMP_GRAY, 20), blu = ink(c, RAMP_BLUE, 160);
++ tex_rect(c, 0, 0, TW, TH, wht);
++ tex_rect(c, 0, 40, TW, 76, blk);
++ tex_rect(c, 0, 116, TW, 3, blu);
++ tex_text(c, &fos_font_lname, u, 32, "ILFORD", blk, 48, 0);
++ tex_text(c, &fos_font_lbig, u, 92, "HP5", wht, 0, 0);
++ tex_text(c, &fos_font_lsm, u, 108, "PLUS", blu, 64, 0);
++ tex_text(c, &fos_font_lname, u - 16, 142, "400", blk, 24, 0);
++ tex_text(c, &fos_font_lsm, u + 30, 141, exp, blk, 0, 0);
++ paint_common(c, wht, blk, f->process);
++ c->leader_ramp = RAMP_GRAY;
++ c->leader_lv = LV12(52);
++ }
++ else if (!strcmp(f->key, "trix400"))
++ {
++ int blk = ink(c, RAMP_GRAY, 18), yel = ink(c, RAMP_AMBER, 190), wht = ink(c, RAMP_GRAY, 238);
++ int red = ink(c, RAMP_RED, 150);
++ tex_rect(c, 0, 0, TW, TH, blk);
++ tex_rect(c, 0, 14, TW, 50, yel);
++ tex_text(c, &fos_font_lsm, u, 30, "KODAK", blk, 48, 0);
++ tex_text(c, &fos_font_lname, u, 56, "TRI-X", blk, 40, 0);
++ tex_text(c, &fos_font_lbig, u, 120, "400", wht, 0, 0);
++ tex_text(c, &fos_font_lsm, u - 30, 138, "TX", red, 16, 0);
++ tex_text(c, &fos_font_lsm, u + 14, 138, exp, wht, 16, 0);
++ paint_common(c, blk, wht, f->process);
++ c->leader_ramp = RAMP_GRAY;
++ c->leader_lv = LV12(48);
++ }
++}
++
++struct fos_can *fos_can_new(int film, int exposures)
++{
++ if (!prof_ready) build_profiles();
++ struct fos_can *c = fos_port_alloc(sizeof(struct fos_can));
++ if (!c) return 0;
++ memset(c, 0, sizeof(*c));
++ c->tex = fos_port_alloc(TW * TH * sizeof(uint16_t));
++ if (!c->tex) { fos_port_free(c); return 0; }
++ c->film = fos_clamp(film, 0, fos_nfilms - 1);
++ c->exposures = exposures;
++ memset(c->tex, 0, TW * TH * sizeof(uint16_t));
++ paint_label(c);
++ return c;
++}
++
++void fos_can_free(struct fos_can *c)
++{
++ if (!c) return;
++ fos_port_free(c->tex);
++ fos_port_free(c);
++}
++
++void fos_can_set_exposures(struct fos_can *c, int exposures)
++{
++ if (!c || c->exposures == exposures) return;
++ c->exposures = exposures;
++ memset(c->tex, 0, TW * TH * sizeof(uint16_t));
++ paint_label(c);
++}
++
++
++/* ---------------------------------------------------------------- drawing */
++
++/* ellipse half-height of a circle of radius r8 at offset dx8 (all 1/256 px) */
++static int arc8(int dx8, int r8)
++{
++ int q = r8 * r8 - dx8 * dx8;
++ if (q <= 0) return 0;
++ return fos_isqrt((unsigned) q >> 8) * 16 * TILT / 256;
++}
++
++/* one column of the canister, worked out once per frame */
++struct can_col
++{
++ int16_t body; /* column crosses the body (not only the caps) */
++ int16_t u, uf; /* label texture column and its fraction (0..255) */
++ int16_t cov; /* silhouette coverage 0..256 */
++ int16_t metal; /* caps, 12-bit, lit */
++ int16_t spool; /* spool side, 12-bit, lit; -1 outside it */
++ int16_t ex, sx; /* x across the cap / the spool, 4096 = edge */
++ int32_t ex2, sx2; /* ... squared */
++ int32_t gain, offs; /* the label's light here: lv * gain / 65536 + offs */
++ int32_t top8; /* y of the top band's upper edge, 1/256 px */
++ int32_t cap8; /* the highest the cap or the spool reaches */
++ int32_t sp_top8, sp_bot8; /* spool side, 1/256 px */
++};
++
++#define MAX_COLS 176
++#define MAX_CAP_ROWS 64
++static struct can_col cols[MAX_COLS];
++
++
++FOS_INLINE int lit(int lv, int light)
++{
++ return (lv * light) >> 8;
++}
++
++FOS_INLINE void put(struct fos_canvas *cv, int x, int y, int ramp, int lv, int cov)
++{
++ uint8_t *px = &cv->px[y * cv->pitch + x];
++ if (cov >= 256) *px = fos_ixd(ramp, fos_ramp_pos(ramp, lv), x, y);
++ else if (cov > 0) *px = fos_mix(*px, ramp, lv, cov);
++}
++
++#define ABS16(v) ((v) < 0 ? -(v) : (v))
++
++/* ramp position (1/16 entries) -> palette index, clamped at the light end */
++static uint8_t ix_tab[RAMP_COUNT][256];
++static int ix_tab_ready;
++
++static void build_ix_tab()
++{
++ for (int r = 0; r < RAMP_COUNT; r++)
++ for (int q = 0; q < 256; q++)
++ ix_tab[r][q] = fos_ramp_base[r] + (q > fos_ramp_last[r] ? fos_ramp_last[r] : q);
++ ix_tab_ready = 1;
++}
++
++/* n rows of the leader fully inside its edges; v (0..4096 across the
++ * film) steps by dv, holes are the v ranges [h, h + 480) */
++__attribute__((noinline))
++static void leader_run(uint8_t *px, int pitch, int n, int v, int dv, int lv_along, int sheen_k, int lmul,
++ const uint8_t *tab, const uint8_t *bay, int h1, int h2)
++{
++ for (int i = 0; i < n; i++, v += dv, px += pitch)
++ {
++ if ((unsigned) (v - h1) < 480 || (unsigned) (v - h2) < 480) continue;
++ /* glossy emulsion: a soft sheen a third of the way down */
++ int sheen = 4096 - ABS16(v - 1300) * 5;
++ int lv = lv_along + (sheen > 0 ? (sheen * sheen_k) >> 20 : 0);
++ int q = (((lv * lmul) >> 16) + bay[i & 3]) >> 4;
++ *px = tab[q & 255];
++ }
++}
++
++/* the film leader coming out of the lip: full width at first, then the
++ * cut-down tongue, perforated along its edges. It leaves the lip heading
++ * away from us, so it tapers a little and rises with distance. */
++static void draw_leader(struct fos_canvas *cv, const struct fos_can *c, const struct fos_can_pose *p,
++ int y_body_top, int s)
++{
++ int lip = (U_LIP - U_FRONT) * 65536 / TW - p->rot; /* lip angle on screen */
++ int sn = fos_sin(lip); /* 4096 = right edge */
++ if (sn < 900) return;
++ /* p->leader: 256 = the usual tongue, more = pulled out further */
++ int len = (70 * s >> 8) * p->leader / 256 * sn / 4096; /* foreshortened as it turns */
++ int tongue = 50 * s / 256 * sn / 4096;
++ if (len < 4) return;
++ int x0 = (p->cx8 >> 8) + (R * s / 256) * sn / 4096 - 3 * s / 256;
++ int fw8 = 112 * s; /* film width, 1/256 px */
++ int mid8 = y_body_top * 256 + HB * s / 2;
++ int full = len - tongue > len * 28 / 100 ? len - tongue : len * 28 / 100; /* full width before the cut */
++ int curve = 12 * s / 256 + 1;
++ int perf_w = fos_clamp(8 * s / 256, 2, 20), pitch = fos_clamp(15 * s / 256, 4, 40);
++ int end_r = 9 * s / 256 + 1;
++ int ramp = c->leader_ramp;
++ int lmul = (p->light * fos_ramp_mul[ramp]) >> 8; /* light and ramp position in one */
++ int inv_len = 65536 / len;
++ if (!ix_tab_ready) build_ix_tab();
++ int xa = fos_clamp(x0, cv->cx0, cv->cx1), xb = fos_clamp(x0 + len, cv->cx0, cv->cx1);
++
++ for (int x = xa; x < xb; x++)
++ {
++ int t = x - x0;
++ int depth = (t * inv_len) >> 8; /* 0 at the lip, 256 at the tip */
++ int hw8 = (fw8 / 2) * (256 - depth * 40 / 256) >> 8;
++ int cy8 = mid8 - depth * s / 64;
++ int top8 = cy8 - hw8, bot8 = cy8 + hw8;
++ if (t > full)
++ {
++ /* the tongue keeps the lower half; the cut curves down to it */
++ int k = t - full;
++ int f = k >= curve ? 4096 : (4096 - fos_cos(k * 32768 / curve)) / 2;
++ top8 = cy8 - hw8 + ((hw8 * f) >> 12);
++ int rem = len - t;
++ if (rem < end_r)
++ {
++ int dy = fos_isqrt((unsigned) (end_r * end_r - (end_r - rem) * (end_r - rem))) * 256;
++ int c8 = (top8 + bot8) / 2;
++ if (top8 < c8 - dy) top8 = c8 - dy;
++ if (bot8 > c8 + dy) bot8 = c8 + dy;
++ }
++ }
++ if (bot8 <= top8) continue;
++ int ph = (t + pitch / 2) % pitch;
++ int perf_col = ph < perf_w && t > 2;
++ /* darker where it disappears into the lip and towards the tip */
++ int along = 3000 + 1100 * fos_sin(depth * 128 + 0x2000) / 4096 - (t < 3 ? 1400 : 0);
++ int lv_along = lit(c->leader_lv, along * 256 / 4096);
++ int sheen_k = (LV_MAX - lv_along) * 60;
++ int ya = fos_clamp(top8 >> 8, cv->cy0, cv->cy1), yb = fos_clamp((bot8 >> 8) + 1, cv->cy0, cv->cy1);
++ /* position across the film, 0..4096 from its top edge, stepped per row */
++ int dv = 4096 * 256 / (2 * hw8 > 0 ? 2 * hw8 : 1);
++ int v = ((ya * 256 + 128 - (cy8 - hw8)) * dv) >> 8;
++ /* sprocket holes, as ranges of v: the background shows */
++ int h1 = perf_col && t <= full ? 300 : 1 << 20, h2 = perf_col ? 3316 : 1 << 20;
++ /* whole rows inside the edges go through the quick loop */
++ int yf0 = fos_clamp((top8 + 255) >> 8, ya, yb), yf1 = fos_clamp(bot8 >> 8, yf0, yb);
++ uint8_t *px = &cv->px[ya * cv->pitch + x];
++ for (int y = ya; y < yb; y++, v += dv, px += cv->pitch)
++ {
++ if (y == yf0 && yf1 > yf0)
++ {
++ uint8_t bay[4];
++ for (int j = 0; j < 4; j++) bay[j] = fos_bayer[(y + j) & 3][x & 3];
++ leader_run(px, cv->pitch, yf1 - yf0, v, dv, lv_along, sheen_k, lmul, &ix_tab[ramp][0], bay, h1, h2);
++ int n = yf1 - yf0 - 1;
++ y += n; v += n * dv; px += n * cv->pitch;
++ continue;
++ }
++ int yc = y * 256 + 128;
++ int cov = fos_clamp(128 + (yc - top8), 0, 256) * fos_clamp(128 + (bot8 - yc), 0, 256) >> 8;
++ if (cov <= 0) continue;
++ if ((unsigned) (v - h1) < 480 || (unsigned) (v - h2) < 480) continue;
++ /* glossy emulsion: a soft sheen a third of the way down */
++ int sheen = 4096 - ABS16(v - 1300) * 5;
++ int lv = lv_along + (sheen > 0 ? (sheen * sheen_k) >> 20 : 0);
++ *px = fos_mix(*px, ramp, lit(lv, p->light), cov);
++ }
++ }
++}
++
++/* geometry of one pose, shared by the parts */
++struct can_geo
++{
++ int s, r8, rc8, rs8, cx8;
++ int e_c, e_s; /* cap / spool ellipse half heights */
++ int tb8, hb8, bb8, hs8;
++ int yc8; /* cap ellipse centre */
++ int xl, xr; /* the canister's columns */
++ int x0, x1; /* ... those inside the clip */
++};
++
++static int prepare(const struct fos_canvas *cv, const struct fos_can *c, const struct fos_can_pose *p,
++ struct can_geo *g)
++{
++ int s = p->scale;
++ if (s <= 0) return 0;
++ g->s = s;
++ g->r8 = R * s; g->rc8 = RC * s; g->rs8 = RS * s;
++ g->cx8 = p->cx8;
++ g->e_c = g->rc8 * TILT / 256;
++ g->e_s = g->rs8 * TILT / 256;
++ g->tb8 = TB * s; g->hb8 = HB * s; g->bb8 = BB * s; g->hs8 = HS * s;
++ g->yc8 = p->floor_y * 256 - (g->e_c + g->tb8 + g->hb8 + g->bb8);
++ g->xl = (g->cx8 - g->rc8) >> 8;
++ g->xr = (g->cx8 + g->rc8 + 255) >> 8;
++ if (g->xr - g->xl > MAX_COLS) return 0;
++ g->x0 = fos_clamp(g->xl, cv->cx0, cv->cx1);
++ g->x1 = fos_clamp(g->xr, cv->cx0, cv->cx1);
++
++ /* reciprocals instead of divisions in the loop */
++ int inv_pb = (NPROF << 16) / (2 * g->r8), inv_pc = (NPROF << 16) / (2 * g->rc8);
++ int inv_ps = (NPROF << 16) / (2 * g->rs8);
++ int inv_ec = (1 << 28) / g->rc8, inv_es = (1 << 28) / g->rs8;
++ int fade = p->light;
++ for (int x = g->x0; x < g->x1; x++)
++ {
++ struct can_col *k = &cols[x - g->xl];
++ int dx8 = x * 256 + 128 - g->cx8;
++ int adx = dx8 < 0 ? -dx8 : dx8;
++ k->body = adx < g->r8;
++ int pi = k->body ? PROF(dx8 + g->r8, inv_pb) : PROF(dx8 + g->rc8, inv_pc);
++ int u16 = ((prof_ang[pi] + p->rot) & 0xFFFF) * TW + U_FRONT * 65536;
++ k->u = wrap_u(u16 >> 16);
++ k->uf = (u16 >> 8) & 0xFF;
++ k->cov = fos_clamp(128 + (g->rc8 - adx), 0, 256);
++ k->metal = lit(prof_metal[PROF(dx8 + g->rc8, inv_pc)], fade);
++ int arc_c = arc8(dx8, g->rc8);
++ k->top8 = g->yc8 + arc_c;
++ k->cap8 = g->yc8 - arc_c - 512;
++ k->ex = fos_clamp((dx8 * inv_ec) >> 16, -8192, 8192);
++ k->sx = fos_clamp((fos_clamp(dx8, -4 * g->rs8, 4 * g->rs8) * inv_es) >> 16, -16384, 16384);
++ k->ex2 = k->ex * k->ex;
++ k->sx2 = k->sx * k->sx;
++ if (adx < g->rs8)
++ {
++ int arc_s = arc8(dx8, g->rs8);
++ k->spool = lit(prof_dark[PROF(dx8 + g->rs8, inv_ps)], fade);
++ k->sp_top8 = g->yc8 - g->hs8 + arc_s;
++ k->sp_bot8 = g->yc8 + arc_s;
++ if (g->yc8 - g->hs8 - arc_s - 256 < k->cap8) k->cap8 = g->yc8 - g->hs8 - arc_s - 256;
++ }
++ else k->spool = -1;
++ /* diffuse light, then the gloss over it, all faded */
++ int sp = (prof_spec[pi] * c->gloss) >> 8;
++ k->gain = ((prof_light[pi] * (256 - sp)) >> 8) * fade;
++ k->offs = (sp * LV_MAX * fade) >> 16;
++ }
++ return 1;
++}
++
++/* the cap seen from above: rolled rim, recessed disc, the spool end */
++static void draw_cap(struct fos_canvas *cv, const struct can_geo *g, int rot, int fade)
++{
++ if (!ix_tab_ready) build_ix_tab();
++ int ya = fos_clamp(((g->yc8 - g->hs8 - g->e_s) >> 8) - 2, cv->cy0, cv->cy1);
++ int yb = fos_clamp(((g->yc8 + g->e_c) >> 8) + 2, ya, cv->cy1);
++ if (yb - ya > MAX_CAP_ROWS) yb = ya + MAX_CAP_ROWS;
++ /* per row: y across the cap and the spool top (4096 = edge), squared,
++ * and the rim's and the disc's light falling off towards us */
++ struct { int ey2, sy, sy2, rim, disc, inv; } rows[MAX_CAP_ROWS];
++ int ec = g->e_c ? g->e_c : 1, es = g->e_s ? g->e_s : 1;
++ int inv_e = (1 << 28) / ec, inv_s = (1 << 28) / es;
++ for (int y = ya; y < yb; y++)
++ {
++ int yc = y * 256 + 128, j = y - ya;
++ int ey = (fos_clamp(yc - g->yc8, -4 * ec, 4 * ec) * inv_e) >> 16;
++ int sy = (fos_clamp(yc - (g->yc8 - g->hs8), -4 * es, 4 * es) * inv_s) >> 16;
++ rows[j].ey2 = ey * ey;
++ rows[j].sy = sy;
++ rows[j].sy2 = sy * sy;
++ rows[j].rim = LV12(150) - ey * LV12(60) / 4096;
++ rows[j].disc = LV12(96) - ey * LV12(22) / 4096;
++ /* how fast rho2 changes per px going down: the edge is that soft */
++ int gy = 2 * (ey < 0 ? -ey : ey) * 256 / ec;
++ rows[j].inv = (1 << 24) / (gy > 64 ? gy : 64);
++ }
++ int cs = fos_cos(rot * 2), sn = fos_sin(rot * 2);
++ for (int x = g->x0; x < g->x1; x++)
++ {
++ const struct can_col *k = &cols[x - g->xl];
++ if (k->cov <= 0) continue;
++ /* ... and going across: the edge's anti-aliasing follows the steeper */
++ int gx = 2 * (k->ex < 0 ? -k->ex : k->ex) * 256 / g->rc8;
++ int inv_x = (1 << 24) / (gx > 64 ? gx : 64);
++ int y0 = fos_clamp(k->cap8 >> 8, ya, yb);
++ int rim_x = k->ex * LV12(40) / 4096, disc_x = k->ex * LV12(30) / 4096;
++ int spool_top = LV12(34) - k->sx * LV12(14) / 4096, slot_x = cs * k->sx;
++ uint8_t bay[4];
++ for (int j = 0; j < 4; j++) bay[j] = fos_bayer[j][x & 3];
++ uint8_t *px = &cv->px[y0 * cv->pitch + x];
++ for (int y = y0; y < yb; y++, px += cv->pitch)
++ {
++ int yc = y * 256 + 128, j = y - ya;
++ if (yc >= k->top8) break;
++ int rho2 = (k->ex2 + rows[j].ey2) >> 12; /* 4096 = edge */
++ if (rho2 > 4096 + 400) continue;
++ int inv = rows[j].inv < inv_x ? rows[j].inv : inv_x;
++ int cov = 128 + (((4096 - rho2) * inv) >> 16);
++ if (cov <= 0) continue;
++ if (cov > 256) cov = 256;
++ if (k->cov < 256) cov = cov * k->cov >> 8;
++ int ramp = RAMP_METAL, lv;
++ int srho2 = (k->sx2 + rows[j].sy2) >> 12;
++ if (srho2 <= 4096)
++ {
++ /* top of the spool: black plastic with the key slot */
++ ramp = RAMP_GRAY;
++ int along = (slot_x + sn * rows[j].sy) >> 12;
++ int slot = along > -1000 && along < 1000 && srho2 < 3000;
++ lv = slot ? LV12(8) : srho2 > 3300 ? LV12(48) : spool_top;
++ }
++ else if (k->spool >= 0 && yc >= k->sp_top8 && yc < k->sp_bot8)
++ {
++ ramp = RAMP_GRAY;
++ lv = k->spool;
++ goto out;
++ }
++ else if (rho2 > 3250)
++ {
++ /* rolled rim: catches the light, brighter at the back */
++ lv = rows[j].rim - rim_x - (rho2 > 3900 ? LV12(40) : 0);
++ }
++ else
++ {
++ /* recessed disc: a soft gradient, a ring round the spool */
++ lv = srho2 < 4096 * 5 / 3 ? LV12(60) : rows[j].disc - disc_x;
++ }
++ lv = fos_clamp(lit(lv, fade), 0, LV_MAX);
++ out:
++ if (cov >= 256) *px = ix_tab[ramp][((fos_ramp_pos(ramp, lv) + bay[y & 3]) >> 4) & 255];
++ else if (cov > 0) *px = fos_mix(*px, ramp, lv, cov);
++ }
++ }
++}
++
++/* Label pixels down a column (the canvas is FOS_W wide). v8 is the
++ * texture row in 1/256, stepping by ds. For each ramp gb holds 8 words:
++ * this column's gain, then its offset with the dither threshold of rows
++ * 0..3 of the run already added. Kept apart from the rest of the drawing
++ * so the loop has the registers to itself. */
++#define LABEL_TEXEL(j) \
++ { \
++ int t = *(const uint16_t *) ((const uint8_t *) b0 + ((v8 >> 7) & ~1)); \
++ int r = t >> 12; \
++ const int32_t *k = &gb[r * 8]; \
++ int q = ((((t & 0xFFF) * k[0]) >> 16) + k[1 + (j)]) >> 4; \
++ *px = tab[r << 8 | (q & 255)]; \
++ px += FOS_W; v8 += ds; \
++ }
++
++__attribute__((noinline))
++static void label_run(uint8_t *px, int n, int v8, int ds, const uint16_t *b0, const int32_t *gb)
++{
++ const uint8_t *tab = &ix_tab[0][0];
++ for (; n >= 4; n -= 4)
++ {
++ LABEL_TEXEL(0) LABEL_TEXEL(1) LABEL_TEXEL(2) LABEL_TEXEL(3)
++ }
++ if (n > 0) LABEL_TEXEL(0)
++ if (n > 1) LABEL_TEXEL(1)
++ if (n > 2) LABEL_TEXEL(2)
++}
++
++/* the same between two texture columns, a fraction uf of the way to b1:
++ * levels of one ramp blend, different inks dither (thr: thresholds) */
++#define LABEL_TEXEL2(j) \
++ { \
++ int o = (v8 >> 7) & ~1; \
++ int t = *(const uint16_t *) ((const uint8_t *) b0 + o); \
++ int t1 = *(const uint16_t *) ((const uint8_t *) b1 + o); \
++ if (t1 != t) \
++ { \
++ if ((t ^ t1) >> 12) { if (uf > thr[j]) t = t1; } \
++ else t += (((t1 & 0xFFF) - (t & 0xFFF)) * uf) >> 8; \
++ } \
++ int r = t >> 12; \
++ const int32_t *k = &gb[r * 8]; \
++ int q = ((((t & 0xFFF) * k[0]) >> 16) + k[1 + (j)]) >> 4; \
++ *px = tab[r << 8 | (q & 255)]; \
++ px += FOS_W; v8 += ds; \
++ }
++
++__attribute__((noinline))
++static void label_run_filtered(uint8_t *px, int n, int v8, int ds, const uint16_t *b0, const uint16_t *b1,
++ int uf, const int32_t *gb, const uint8_t *thr)
++{
++ const uint8_t *tab = &ix_tab[0][0];
++ for (; n >= 4; n -= 4)
++ {
++ LABEL_TEXEL2(0) LABEL_TEXEL2(1) LABEL_TEXEL2(2) LABEL_TEXEL2(3)
++ }
++ if (n > 0) LABEL_TEXEL2(0)
++ if (n > 1) LABEL_TEXEL2(1)
++ if (n > 2) LABEL_TEXEL2(2)
++}
++
++/* first row whose centre is at least a below edge8 (1/256 px) */
++FOS_INLINE int row_at(int edge8, int a)
++{
++ return (edge8 + a - 128 + 255) >> 8;
++}
++
++/* the bands and the label, a column at a time: the texture row just steps */
++static void draw_body(struct fos_canvas *cv, const struct fos_can *c, const struct can_geo *g, int fade, int fast)
++{
++ int ds = 65536 / g->s; /* texels per row, 8.8 */
++ int band_t = g->tb8, body_b = g->tb8 + g->hb8, band_b = body_b + g->bb8;
++ int step_t = 65536 / (band_t ? band_t : 1), step_b = 65536 / (g->bb8 ? g->bb8 : 1);
++ int lip_hi = lit(LV12(40), fade), groove = lit(LV12(70), fade), ridge = lit(LV12(30), fade);
++ int filter = fos_can_quality > 1;
++ int pitch = cv->pitch;
++ if (!ix_tab_ready) build_ix_tab();
++
++ for (int x = g->x0; x < g->x1; x++)
++ {
++ const struct can_col *k = &cols[x - g->xl];
++ if (k->cov <= 0) continue;
++ int ya = fos_clamp(row_at(k->top8, 0), cv->cy0, cv->cy1);
++ int yb = fos_clamp(row_at(k->top8, band_t), cv->cy0, cv->cy1);
++ int yc_ = fos_clamp(row_at(k->top8, body_b), cv->cy0, cv->cy1);
++ int yd = fos_clamp(row_at(k->top8, band_b), cv->cy0, cv->cy1);
++ int y;
++
++ /* top crimp: a rolled lip above, a groove below; f = 0..256 down the band */
++ int f = ((ya * 256 + 128 - k->top8) * step_t) >> 8;
++ for (y = ya; y < yb; y++, f += step_t)
++ {
++ int lv = k->metal + (f < 70 ? lip_hi : 0) - (f > 210 ? groove : 0);
++ put(cv, x, y, RAMP_METAL, fos_clamp(lv, 0, LV_MAX), k->cov);
++ }
++
++ /* the printed label */
++ if (k->body && yb < yc_)
++ {
++ const uint16_t *b0 = &c->tex[k->u * TH];
++ const uint16_t *b1 = &c->tex[(k->u + 1 < TW ? k->u + 1 : 0) * TH];
++ int v8 = ((yb * 256 + 128 - k->top8 - band_t) * ds) >> 8;
++ /* keep the texture row inside the label */
++ int ye = yc_;
++ if (v8 < 0) v8 = 0;
++ if (((v8 + (ye - yb - 1) * ds) >> 8) >= TH) ye = yb + ((TH * 256 - 1 - v8) / ds) + 1;
++ uint8_t *px = &cv->px[yb * pitch + x];
++ if (k->cov >= 256 && ye > yb && pitch == FOS_W)
++ {
++ /* this column's light, folded into each ramp's position
++ * scale, with the dither of the run's rows 0..3 */
++ int32_t gb[RAMP_COUNT * 8];
++ uint8_t thr[4];
++ int g4 = k->gain >> 4;
++ int bay[4];
++ for (int j = 0; j < 4; j++)
++ {
++ int yy = (yb + j) & 3;
++ bay[j] = fos_bayer[yy][x & 3];
++ thr[j] = fos_bayer[(yy + 2) & 3][(x + 1) & 3] * 16 + 8;
++ }
++ for (int r = 0; r < RAMP_COUNT; r++)
++ {
++ if (!(c->ramps & (1 << r))) continue;
++ int32_t *e = &gb[r * 8];
++ int o = (k->offs * fos_ramp_mul[r]) >> 16;
++ e[0] = (g4 * fos_ramp_mul[r]) >> 12;
++ e[1] = o + bay[0]; e[2] = o + bay[1]; e[3] = o + bay[2]; e[4] = o + bay[3];
++ }
++ if (filter && k->uf && !fast)
++ label_run_filtered(px, ye - yb, v8, ds, b0, b1, k->uf, gb, thr);
++ else
++ label_run(px, ye - yb, v8, ds, b0, gb);
++ }
++ else
++ {
++ /* the silhouette's edge columns, blended with what is behind */
++ for (y = yb; y < ye; y++, v8 += ds, px += pitch)
++ {
++ int t = b0[v8 >> 8];
++ int lv = (((t & 0xFFF) * k->gain) >> 16) + k->offs;
++ *px = fos_mix(*px, t >> 12, lv > LV_MAX ? LV_MAX : lv, k->cov);
++ }
++ }
++ }
++
++ /* bottom crimp, its lower edge following the cap ellipse */
++ int rel = yc_ * 256 + 128 - k->top8;
++ f = ((rel - body_b) * step_b) >> 8;
++ for (y = yc_; y < yd; y++, rel += 256, f += step_b)
++ {
++ int lv = k->metal - (f < 50 ? groove : 0) + (f > 140 && f < 200 ? ridge : 0);
++ int cov = k->cov;
++ int below = rel - (band_b - 256);
++ if (below > 0) cov = cov * (256 - below) >> 8;
++ put(cv, x, y, RAMP_METAL, fos_clamp(lv, 0, LV_MAX), cov);
++ }
++ }
++}
++
++/* the canister mirrored in the glossy floor, fading out below it: a little
++ * of each pixel above the bottom edge glazed over the floor below it */
++static void draw_reflection(struct fos_canvas *cv, const struct fos_can_pose *p, const struct can_geo *g)
++{
++ int depth = 38 * g->s / 256;
++ if (depth <= 0) return;
++ int y0 = fos_clamp(p->floor_y, cv->cy0, cv->cy1), y1 = fos_clamp(p->floor_y + depth, cv->cy0, cv->cy1);
++ if (y1 - y0 > 64) y1 = y0 + 64;
++ int kk[64];
++ for (int y = y0; y < y1; y++)
++ {
++ int k = p->reflect * (depth - (y - p->floor_y)) / depth;
++ kk[y - y0] = (k * k / 256) * 200 >> 8; /* the print a little darker in the floor */
++ if (kk[y - y0] < 2) { y1 = y; break; } /* fainter than a level step */
++ }
++ int edge_off = g->tb8 + g->hb8 + g->bb8; /* from the band's top edge to the bottom outline */
++ int pitch = cv->pitch;
++ for (int x = g->x0; x < g->x1; x++)
++ {
++ const struct can_col *col = &cols[x - g->xl];
++ if (col->cov < 128) continue;
++ int edge8 = col->top8 + edge_off;
++ int reach = col->body ? 1 << 30 : g->bb8; /* past the body only the band shows */
++ for (int y = y0; y < y1; y++)
++ {
++ int up = y * 256 + 128 - edge8; /* below the edge = above it in the mirror */
++ if (up < 0) continue;
++ if (up >= reach) break;
++ int sy = (edge8 - up) >> 8;
++ if (sy < cv->cy0) break;
++ int k = kk[y - y0];
++ if (k <= 0) break;
++ uint8_t *px = &cv->px[y * pitch + x];
++ *px = fos_glaze(*px, cv->px[sy * pitch + x], k, x, y);
++ }
++ }
++}
++
++void fos_can_draw(struct fos_canvas *cv, struct fos_can *c, const struct fos_can_pose *p)
++{
++ struct can_geo g;
++ if (!c || !prepare(cv, c, p, &g)) return;
++ if (g.xr <= cv->cx0 || g.xl >= cv->cx1) return;
++ if (p->leader)
++ draw_leader(cv, c, p, (g.yc8 + g.tb8) >> 8, g.s);
++ draw_cap(cv, &g, p->rot, p->light);
++ draw_body(cv, c, &g, p->light, p->fast);
++ if (p->reflect && fos_can_quality > 0)
++ draw_reflection(cv, p, &g);
++}
+diff --git a/src/fos_font.c b/src/fos_font.c
+new file mode 100644
+index 000000000..ba76a9ed0
+--- /dev/null
++++ b/src/fos_font.c
+@@ -0,0 +1,4254 @@
++/* generated by tools/mkfont.py from Barlow (SIL Open Font License 1.1,
++ * see fonts/OFL.txt) - do not edit. Not linked into the camera: it goes
++ * on the card as ML/DATA/FOSFONT.BIN (tools/fontblob.c) */
++
++#include "fos_gfx.h"
++
++static const uint8_t xs_bits[] = {
++ 128,8,14,129,8,14,129,8,13,129,7,13,129,7,13,129,6,12,133,2,3,129,9,13,
++ 128,11,10,6,14,26,6,14,9,8,5,12,151,129,6,15,2,3,15,5,130,8,14,128,
++ 5,15,2,129,12,95,1,128,4,14,12,5,12,13,5,130,14,8,128,27,130,2,15,8,
++ 1,13,10,1,128,4,95,9,128,1,8,15,22,15,8,2,129,8,14,128,5,15,3,129,
++ 130,15,4,130,1,7,15,10,2,129,12,15,13,15,14,2,4,15,4,128,2,14,9,4,
++ 15,4,129,23,128,11,15,9,3,131,7,13,15,10,1,131,6,15,9,6,15,130,10,11,
++ 3,15,9,3,4,14,8,128,5,13,15,14,9,1,130,15,5,129,128,6,14,13,5,129,
++ 13,3,130,14,8,9,13,128,7,10,131,10,31,8,1,14,2,132,3,2,128,9,8,135,
++ 3,13,1,135,11,6,5,30,4,131,4,12,128,14,6,7,13,131,12,4,128,14,7,8,
++ 13,130,6,10,129,5,14,13,3,128,128,1,11,15,13,6,131,10,14,7,10,15,2,130,
++ 10,13,128,5,15,4,130,3,15,10,14,12,131,2,13,15,12,1,130,1,14,12,8,15,
++ 6,5,10,128,6,15,2,128,7,31,8,128,5,15,10,6,10,31,3,129,8,13,14,12,
++ 6,11,13,1,27,10,11,25,139,129,10,13,129,2,15,7,129,8,15,2,129,11,14,130,
++ 14,11,130,15,10,130,15,10,130,14,11,130,12,13,130,8,15,2,129,3,15,7,130,10,
++ 13,128,128,11,12,130,5,15,4,129,1,15,10,130,12,13,130,10,15,1,129,9,15,2,
++ 129,9,15,2,129,10,15,1,129,12,13,129,1,15,9,129,5,15,4,129,27,129,2,1,
++ 13,1,3,5,12,14,12,7,5,12,14,12,6,2,1,13,1,3,152,129,7,12,131,7,
++ 12,129,17,7,13,17,9,63,14,2,4,9,13,20,129,7,12,135,128,14,5,2,15,1,
++ 4,12,128,65,9,47,12,2,36,3,142,131,1,15,8,129,3,1,128,130,9,13,131,14,
++ 8,130,5,15,2,130,11,12,130,1,15,6,130,7,15,1,130,12,11,130,3,15,5,130,
++ 8,14,131,128,3,12,14,13,7,128,1,14,12,6,9,15,5,4,15,4,129,13,9,4,
++ 15,3,129,13,10,4,15,3,129,13,10,4,15,3,129,13,10,3,15,4,129,13,9,1,
++ 14,12,6,9,15,5,128,3,12,14,13,7,128,2,10,15,10,128,5,10,14,10,130,12,
++ 10,130,12,10,130,12,10,130,12,10,130,12,10,130,12,10,130,12,10,128,128,5,13,15,
++ 12,5,128,3,15,11,6,11,15,2,6,15,2,128,3,15,5,131,9,15,1,130,5,15,
++ 7,130,4,15,10,130,3,14,11,130,2,13,14,6,21,3,5,79,8,5,79,18,21,7,
++ 15,13,1,129,2,29,2,130,13,15,10,2,130,20,28,132,5,15,2,6,15,2,128,6,
++ 15,18,15,11,6,29,129,5,13,15,12,3,128,129,3,15,6,132,11,13,132,3,15,6,
++ 132,10,13,128,5,15,2,128,3,15,7,2,6,15,4,128,7,79,14,128,2,36,8,15,
++ 6,132,5,15,3,132,5,15,2,128,5,79,1,5,15,7,37,128,5,15,3,1,130,5,
++ 15,12,15,14,6,128,5,15,11,5,11,15,2,1,2,129,3,15,5,3,10,3,128,4,
++ 15,5,1,14,12,6,12,14,1,128,3,12,15,12,4,128,128,6,13,14,12,5,128,3,
++ 15,11,6,12,15,1,5,15,3,128,2,6,1,5,15,12,15,14,6,128,5,15,11,5,
++ 11,15,2,5,15,4,128,4,15,5,4,15,4,128,4,15,5,1,14,12,6,12,14,1,
++ 128,4,12,15,12,4,128,10,79,2,10,11,21,11,15,1,2,1,129,14,10,131,5,15,
++ 4,131,10,13,131,1,15,8,131,7,15,2,131,13,11,131,3,15,5,130,128,5,12,14,
++ 12,4,128,2,15,10,6,11,15,1,3,15,7,2,8,15,2,128,10,47,8,128,1,14,
++ 11,5,11,14,1,5,15,3,128,4,15,4,6,15,4,128,4,15,4,2,14,12,6,12,
++ 14,1,128,4,13,15,12,4,128,128,7,13,15,11,3,128,4,15,10,6,12,13,128,7,
++ 15,1,128,6,15,2,6,15,6,2,10,15,3,128,11,31,13,15,3,129,19,5,15,3,
++ 4,14,3,128,5,15,3,2,15,12,6,13,14,1,128,5,13,15,12,4,128,133,7,15,
++ 1,129,1,3,140,7,15,1,129,1,3,129,128,11,12,129,12,14,1,140,9,10,129,11,
++ 7,129,13,3,128,131,1,7,129,2,9,14,13,3,10,15,12,6,128,9,15,8,130,2,
++ 9,15,13,7,1,129,1,8,30,131,1,6,8,63,14,1,51,2,8,63,14,1,51,2,
++ 139,5,3,131,8,15,11,5,130,3,10,15,13,6,130,4,30,128,5,11,15,12,5,8,
++ 15,10,3,129,4,2,131,128,7,13,14,11,2,128,5,15,9,6,13,12,128,8,14,129,
++ 8,15,131,2,13,12,130,2,29,3,130,10,14,2,131,23,132,3,2,132,12,11,130,141,
++ 7,13,31,12,3,131,11,14,8,5,6,11,15,3,129,8,12,1,131,10,11,128,1,14,
++ 3,2,12,14,13,4,3,14,128,4,12,128,9,8,2,15,3,1,15,128,6,10,128,13,
++ 2,128,15,1,2,14,128,5,11,128,13,4,5,15,2,8,9,128,2,15,2,6,14,12,
++ 9,14,11,1,129,9,13,5,18,5,1,131,1,9,47,13,3,133,1,4,2,132,130,13,
++ 15,4,132,3,15,14,10,132,8,13,7,14,132,13,8,2,15,4,130,3,15,4,128,13,
++ 9,130,8,14,129,8,14,130,13,79,4,128,3,15,7,35,14,9,128,7,15,1,130,10,
++ 14,128,1,63,12,4,128,1,15,10,5,6,12,14,17,15,7,129,4,15,3,1,15,7,
++ 1,2,9,13,17,79,6,128,1,15,9,20,10,15,2,1,15,7,129,3,15,5,1,15,
++ 10,5,6,11,15,2,1,63,12,5,128,128,2,10,30,10,2,129,29,23,14,13,128,3,
++ 15,5,129,5,15,3,4,15,4,132,4,15,4,132,4,15,4,130,1,128,3,15,5,129,
++ 5,15,3,128,29,23,14,13,129,2,11,30,10,2,128,1,63,12,4,128,1,15,10,5,
++ 6,12,15,2,1,15,7,129,3,15,5,1,15,7,129,2,15,6,1,15,7,129,2,15,
++ 6,1,15,7,129,2,15,6,1,15,7,129,3,15,5,1,15,10,5,6,12,15,2,1,
++ 63,12,4,128,1,95,2,1,15,10,53,128,1,15,7,132,1,15,7,33,129,1,63,10,
++ 129,1,15,9,20,2,129,1,15,7,132,1,15,10,53,128,1,95,2,1,95,17,15,10,
++ 53,128,1,15,7,132,1,15,7,33,129,1,63,10,129,1,15,9,20,2,129,1,15,7,
++ 132,1,15,7,132,1,15,7,132,128,2,10,30,10,2,129,13,14,7,6,29,128,3,15,
++ 5,129,4,13,3,4,15,4,128,33,128,4,15,4,1,47,3,4,15,4,128,4,7,15,
++ 19,15,5,129,5,15,2,128,13,14,7,6,13,11,129,2,11,30,10,1,128,1,15,7,
++ 129,1,15,6,1,15,7,129,1,15,6,1,15,7,129,1,15,6,1,15,7,17,2,15,
++ 6,1,95,6,1,15,9,20,5,15,6,1,15,7,129,1,15,6,1,15,7,129,1,15,
++ 6,1,15,7,129,1,15,6,1,15,7,1,15,7,1,15,7,1,15,7,1,15,7,1,
++ 15,7,1,15,7,1,15,7,1,15,7,132,13,9,133,13,9,133,13,9,133,13,9,133,
++ 13,9,128,9,10,130,13,9,128,10,13,130,14,9,128,6,15,10,6,11,15,4,129,7,
++ 13,15,13,6,129,1,15,7,129,6,15,4,1,15,7,128,4,15,7,128,1,15,7,3,
++ 14,10,129,1,15,8,13,12,1,129,1,47,13,1,129,1,15,13,3,14,9,129,1,15,
++ 7,128,7,15,4,128,1,15,7,129,12,13,17,15,7,129,3,15,8,1,15,7,132,1,
++ 15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,15,7,132,1,
++ 15,10,53,128,1,95,128,1,15,11,130,7,15,5,1,31,6,128,2,31,5,1,15,30,
++ 2,12,14,15,5,1,15,8,13,14,15,6,15,5,1,15,7,4,15,9,2,15,5,1,
++ 15,7,128,3,1,2,15,5,1,15,7,130,2,15,5,1,15,7,130,2,15,5,1,15,
++ 7,130,2,15,5,1,15,10,130,27,128,1,31,4,129,27,128,1,31,13,1,128,27,128,
++ 1,15,8,14,8,128,27,128,1,15,23,15,2,27,128,1,15,7,128,12,43,128,1,15,
++ 7,128,3,31,11,128,1,15,7,129,9,15,11,128,1,15,7,129,1,14,11,128,128,2,
++ 10,30,10,2,129,12,14,23,29,128,3,15,6,129,4,15,20,15,4,129,2,15,5,4,
++ 15,4,129,2,15,5,4,15,4,129,2,15,5,3,15,5,129,4,15,4,128,12,14,7,
++ 6,29,129,2,10,30,11,2,128,2,63,13,5,128,2,15,9,5,6,12,15,18,15,6,
++ 129,3,15,5,2,15,6,1,2,9,15,3,2,79,9,128,2,15,8,20,2,129,2,15,
++ 6,132,2,15,6,132,2,15,6,132,128,2,11,30,8,130,29,6,8,15,8,128,4,15,
++ 4,129,9,14,128,6,15,2,129,7,15,128,6,15,2,129,7,15,128,6,15,2,129,7,
++ 15,128,6,15,2,129,8,15,128,3,15,8,128,1,13,12,129,10,15,30,15,5,130,5,
++ 15,12,3,132,14,9,130,1,63,13,5,128,1,15,10,21,11,15,2,1,15,7,129,3,
++ 15,5,1,15,7,17,8,15,3,1,79,9,128,1,15,9,4,28,129,1,15,7,128,4,
++ 15,4,128,1,15,7,129,12,11,128,1,15,7,129,5,15,4,128,4,12,30,9,1,128,
++ 2,15,11,6,7,14,11,128,4,15,4,129,7,14,128,1,29,5,132,1,9,30,8,130,
++ 1,129,6,14,11,128,6,15,1,129,7,15,1,3,15,12,22,29,129,5,12,15,14,10,
++ 2,128,8,95,1,3,5,6,15,10,21,131,15,7,133,15,7,133,15,7,133,15,7,133,
++ 15,7,133,15,7,133,15,7,130,2,15,6,129,1,15,6,2,15,6,129,2,15,6,2,
++ 15,6,129,2,15,6,2,15,6,129,2,15,6,2,15,6,129,2,15,6,2,15,6,129,
++ 2,15,6,1,15,7,129,3,15,5,128,11,14,7,6,13,14,1,128,1,10,30,11,3,
++ 128,7,15,2,129,2,15,6,3,15,6,129,6,15,2,128,13,10,129,11,12,129,8,14,
++ 128,1,15,7,129,4,15,20,15,2,130,14,8,9,13,131,9,29,8,131,4,31,3,132,
++ 14,13,130,8,15,1,128,3,15,9,129,8,14,128,4,15,4,128,6,15,13,129,12,11,
++ 128,1,15,8,128,10,14,15,2,1,15,7,129,11,12,128,14,8,15,6,4,15,3,129,
++ 7,15,3,15,3,12,9,8,14,130,3,15,10,15,128,9,13,12,11,131,14,15,11,128,
++ 5,31,7,131,10,15,8,128,1,31,3,131,6,15,4,129,13,14,130,5,15,4,129,4,
++ 15,5,128,11,13,129,13,11,129,2,15,23,15,2,130,8,30,8,131,1,31,1,131,8,
++ 30,8,130,2,15,23,15,2,129,11,13,129,13,11,128,5,15,4,129,4,15,5,6,15,
++ 3,129,6,15,3,128,13,11,128,1,14,10,129,5,15,3,7,15,2,130,12,11,14,9,
++ 131,5,31,2,132,13,10,133,13,10,133,13,10,133,13,10,130,8,79,10,3,37,8,15,
++ 8,131,28,131,9,14,2,130,4,15,6,130,1,14,10,131,11,13,1,130,6,15,9,37,
++ 3,8,79,10,49,128,8,31,9,128,8,15,4,2,128,8,14,130,8,14,130,8,14,130,
++ 8,14,130,8,14,130,8,14,130,8,14,130,8,14,130,8,14,17,128,8,31,9,128,2,
++ 20,2,128,1,15,6,131,11,12,131,5,15,2,130,1,14,8,131,9,13,131,4,15,4,
++ 131,13,9,131,8,14,131,2,15,5,129,33,128,6,31,12,128,1,4,28,130,11,12,130,
++ 11,12,130,11,12,130,11,12,130,11,12,130,11,12,130,11,12,130,11,12,129,1,11,12,
++ 128,6,31,12,128,1,20,3,129,21,130,1,30,1,129,5,29,5,129,11,24,11,128,1,
++ 15,3,2,15,1,6,13,129,12,6,151,81,128,11,79,5,3,68,1,17,128,4,14,2,
++ 128,3,2,148,128,6,13,15,12,3,128,4,15,10,6,29,129,1,128,1,7,15,17,10,
++ 63,1,7,15,7,4,9,15,1,7,15,23,13,15,17,11,14,13,10,15,1,3,15,5,
++ 131,3,15,5,131,3,15,10,30,6,128,3,15,14,6,11,15,19,15,7,128,1,15,7,
++ 3,15,6,129,14,9,3,15,7,128,1,15,7,3,15,14,6,11,15,19,15,10,30,6,
++ 128,128,3,12,14,12,5,128,1,14,12,6,11,15,3,4,15,4,128,1,8,3,5,15,
++ 2,131,4,15,4,128,1,7,2,1,14,12,6,11,15,3,128,3,12,15,13,5,128,131,
++ 1,15,6,131,1,15,7,128,4,12,14,10,15,7,1,14,13,6,12,15,7,4,15,5,
++ 128,3,15,7,5,15,3,128,2,15,7,3,15,5,128,3,15,7,1,14,13,6,12,15,
++ 7,128,4,12,14,10,15,6,128,3,12,14,12,4,128,1,14,12,6,11,14,1,4,15,
++ 5,1,4,15,21,79,7,3,15,7,36,2,128,13,12,6,8,13,2,128,3,11,15,13,
++ 7,128,128,3,13,15,6,128,8,15,6,2,9,47,6,3,11,14,5,2,128,9,14,130,
++ 9,14,130,9,14,130,9,14,130,9,14,129,128,4,13,14,11,15,6,1,14,12,6,12,
++ 15,6,5,15,4,128,3,15,22,15,2,128,2,15,6,5,15,4,128,3,15,6,2,15,
++ 12,6,12,15,6,128,5,13,14,11,15,6,131,4,15,4,129,4,6,13,14,1,129,13,
++ 14,11,3,128,3,15,5,131,3,15,5,131,3,15,10,30,6,128,3,15,13,6,12,15,
++ 2,3,15,5,128,4,15,4,3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,
++ 5,128,3,15,5,3,15,5,128,3,15,5,2,14,7,128,4,1,2,15,6,2,15,6,
++ 2,15,6,2,15,6,2,15,6,2,15,6,2,15,6,128,2,14,6,129,4,1,128,2,
++ 15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,15,5,128,2,
++ 15,5,128,2,15,5,3,10,15,3,10,14,8,128,3,15,5,131,3,15,5,131,3,15,
++ 5,1,12,13,1,3,15,5,10,14,3,128,3,15,12,15,9,129,3,31,12,14,1,128,
++ 3,15,8,2,15,6,128,3,15,5,128,10,13,128,3,15,5,128,4,15,5,3,15,5,
++ 3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,3,15,5,
++ 3,15,10,13,14,6,7,14,13,5,128,3,15,12,6,12,15,11,6,29,128,3,15,5,
++ 128,5,15,3,128,7,15,1,3,15,5,128,5,15,3,128,7,15,1,3,15,5,128,5,
++ 15,3,128,7,15,1,3,15,5,128,5,15,3,128,7,15,1,3,15,5,128,5,15,2,
++ 128,7,15,1,3,15,10,30,6,128,3,15,13,6,12,15,2,3,15,5,128,4,15,4,
++ 3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,5,128,3,15,5,3,15,5,
++ 128,3,15,5,128,3,12,14,13,5,128,1,14,13,6,11,15,2,4,15,4,128,1,15,
++ 7,5,15,2,129,14,9,4,15,4,128,1,15,7,128,29,6,11,15,2,128,3,11,14,
++ 13,4,128,2,15,10,30,7,128,2,15,14,6,10,15,4,2,15,8,128,1,15,9,2,
++ 15,6,129,13,10,2,15,8,128,1,15,9,2,15,14,6,10,15,4,2,15,10,30,7,
++ 128,2,15,6,131,2,15,6,131,2,15,6,131,128,3,12,14,10,15,6,1,14,13,6,
++ 12,15,7,3,15,5,128,3,15,7,5,15,3,128,2,15,7,4,15,5,128,3,15,7,
++ 1,14,13,6,12,15,7,128,4,13,14,10,15,7,131,1,15,7,131,1,15,7,131,1,
++ 15,6,3,15,10,14,9,3,15,13,6,19,15,6,129,3,15,5,129,3,15,5,129,3,
++ 15,5,129,3,15,5,129,128,8,14,15,11,2,4,15,8,6,13,11,4,15,7,1,2,
++ 3,128,6,13,15,11,18,5,128,3,28,5,15,9,6,13,12,128,8,14,15,12,3,128,
++ 5,6,130,10,12,129,9,47,5,3,12,13,5,2,128,10,12,130,10,12,130,10,12,130,
++ 9,14,6,1,128,4,13,15,3,4,15,3,128,4,15,3,4,15,4,128,4,15,20,15,
++ 4,128,4,15,20,15,4,128,4,15,20,15,4,128,5,15,4,2,15,12,6,12,15,4,
++ 128,6,30,10,15,3,8,15,1,128,8,15,2,4,15,5,128,28,129,14,9,1,15,7,
++ 129,9,13,5,15,3,129,5,15,12,13,131,14,15,8,131,10,15,4,129,8,14,129,14,
++ 10,128,1,15,7,4,15,3,2,15,14,128,5,15,3,1,15,7,6,14,15,3,9,13,
++ 129,11,42,13,7,13,9,129,7,30,6,9,12,15,5,129,3,31,2,5,31,1,130,29,
++ 128,1,15,11,129,7,15,3,128,8,15,3,128,28,3,15,8,129,3,15,14,13,131,10,
++ 15,6,130,3,15,14,13,130,12,13,3,14,8,128,7,15,4,128,7,15,3,9,14,129,
++ 8,14,128,5,15,3,128,12,10,128,1,15,7,1,15,5,129,27,5,15,1,129,6,14,
++ 9,11,130,1,31,6,131,12,15,2,131,10,12,130,2,7,15,6,130,6,14,10,131,9,
++ 63,7,3,21,11,15,5,129,4,15,8,129,2,14,11,130,12,13,1,129,8,15,8,21,
++ 3,10,63,8,130,1,129,5,31,2,128,10,15,5,129,10,13,130,10,13,130,10,12,129,
++ 5,15,8,129,6,15,7,130,11,12,130,10,13,130,10,13,130,10,14,2,129,7,31,2,
++ 129,3,4,128,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,8,15,
++ 8,15,17,130,8,15,12,129,2,10,15,3,129,4,15,3,129,4,15,3,129,4,15,4,
++ 129,1,14,13,1,128,1,29,1,128,4,15,4,129,4,15,3,129,4,15,3,128,1,8,
++ 15,3,128,8,15,14,1,128,2,4,1,129,134,2,13,15,8,2,7,1,4,9,5,12,
++ 15,13,1,131,3,1,142,130,4,15,4,128,3,134,129,1,129,1,12,15,11,1,9,11,
++ 5,11,7,10,8,2,10,8,3,14,15,13,2,128,1,3,1,158,128,4,129,4,128,5,
++ 15,6,10,14,1,128,7,15,14,3,129,10,31,6,128,4,14,3,7,14,1,128,1,129,
++ 1,134,81,9,63,10,2,52,2,139,113,128,9,111,4,2,100,1,145,5,15,2,9,11,
++ 128,12,5,146,138,1,15,8,128,6,15,3,128,28,129,3,1,128,1,3,129,18,128,3,
++ 29,3,8,31,9,2,29,3,135,128,3,15,4,128,12,9,128,4,15,2,129,12,9,129,
++ 3,15,3,131,128,11,10,130,2,15,4,130,10,11,129,2,15,4,129,11,10,134,
++};
++static const struct fos_glyph xs_glyphs[] = {
++ { 0, 3, 0, 0, 0, 42 }, /* 0x20 */
++ { 0, 4, 9, 0, -9, 70 }, /* 0x21 */
++ { 25, 4, 9, 0, -9, 68 }, /* 0x22 */
++ { 37, 9, 9, 0, -9, 141 }, /* 0x23 */
++ { 96, 7, 12, 0, -11, 118 }, /* 0x24 */
++ { 162, 11, 9, 0, -9, 173 }, /* 0x25 */
++ { 226, 9, 9, 0, -9, 143 }, /* 0x26 */
++ { 292, 2, 9, 0, -9, 32 }, /* 0x27 */
++ { 297, 5, 12, -1, -11, 66 }, /* 0x28 */
++ { 338, 5, 12, 0, -11, 66 }, /* 0x29 */
++ { 382, 5, 9, 0, -9, 83 }, /* 0x2a */
++ { 403, 6, 7, 0, -7, 102 }, /* 0x2b */
++ { 426, 3, 3, 0, -2, 55 }, /* 0x2c */
++ { 435, 5, 6, 0, -6, 84 }, /* 0x2d */
++ { 443, 4, 3, 0, -2, 57 }, /* 0x2e */
++ { 451, 6, 9, 0, -9, 93 }, /* 0x2f */
++ { 483, 7, 9, 0, -9, 118 }, /* 0x30 */
++ { 541, 5, 9, 0, -9, 73 }, /* 0x31 */
++ { 572, 7, 9, 0, -9, 115 }, /* 0x32 */
++ { 619, 7, 9, 0, -9, 110 }, /* 0x33 */
++ { 661, 8, 9, 0, -9, 122 }, /* 0x34 */
++ { 706, 7, 9, 0, -9, 110 }, /* 0x35 */
++ { 760, 7, 9, 0, -9, 110 }, /* 0x36 */
++ { 823, 7, 9, 0, -9, 102 }, /* 0x37 */
++ { 860, 7, 9, 0, -9, 111 }, /* 0x38 */
++ { 921, 7, 9, 0, -9, 110 }, /* 0x39 */
++ { 981, 5, 7, 0, -7, 74 }, /* 0x3a */
++ { 996, 4, 8, 0, -7, 65 }, /* 0x3b */
++ { 1013, 6, 7, 0, -7, 102 }, /* 0x3c */
++ { 1044, 6, 6, 0, -6, 102 }, /* 0x3d */
++ { 1057, 6, 7, 0, -7, 102 }, /* 0x3e */
++ { 1087, 7, 9, 0, -9, 104 }, /* 0x3f */
++ { 1127, 11, 12, 0, -10, 171 }, /* 0x40 */
++ { 1222, 9, 9, 0, -9, 135 }, /* 0x41 */
++ { 1274, 8, 9, 0, -9, 129 }, /* 0x42 */
++ { 1331, 8, 9, 0, -9, 126 }, /* 0x43 */
++ { 1383, 8, 9, 0, -9, 129 }, /* 0x44 */
++ { 1444, 8, 9, 0, -9, 123 }, /* 0x45 */
++ { 1483, 8, 9, 0, -9, 117 }, /* 0x46 */
++ { 1521, 8, 9, 0, -9, 128 }, /* 0x47 */
++ { 1581, 8, 9, 0, -9, 132 }, /* 0x48 */
++ { 1640, 3, 9, 0, -9, 54 }, /* 0x49 */
++ { 1667, 8, 9, 0, -9, 121 }, /* 0x4a */
++ { 1709, 8, 9, 0, -9, 129 }, /* 0x4b */
++ { 1771, 8, 9, 0, -9, 119 }, /* 0x4c */
++ { 1807, 9, 9, 0, -9, 149 }, /* 0x4d */
++ { 1877, 9, 9, 0, -9, 139 }, /* 0x4e */
++ { 1942, 8, 9, 0, -9, 129 }, /* 0x4f */
++ { 2001, 8, 9, 0, -9, 124 }, /* 0x50 */
++ { 2050, 8, 11, 0, -9, 122 }, /* 0x51 */
++ { 2119, 8, 9, 0, -9, 128 }, /* 0x52 */
++ { 2177, 8, 9, 0, -9, 123 }, /* 0x53 */
++ { 2234, 8, 9, 0, -9, 120 }, /* 0x54 */
++ { 2265, 8, 9, 0, -9, 132 }, /* 0x55 */
++ { 2329, 8, 9, 0, -9, 127 }, /* 0x56 */
++ { 2379, 12, 9, 0, -9, 183 }, /* 0x57 */
++ { 2467, 8, 9, 0, -9, 128 }, /* 0x58 */
++ { 2518, 8, 9, 0, -9, 125 }, /* 0x59 */
++ { 2561, 7, 9, 0, -9, 115 }, /* 0x5a */
++ { 2596, 5, 14, 0, -11, 84 }, /* 0x5b */
++ { 2643, 6, 9, 0, -9, 93 }, /* 0x5c */
++ { 2674, 5, 14, 0, -11, 84 }, /* 0x5d */
++ { 2720, 6, 10, 0, -10, 97 }, /* 0x5e */
++ { 2747, 7, 3, 0, -2, 106 }, /* 0x5f */
++ { 2755, 3, 10, 0, -10, 46 }, /* 0x60 */
++ { 2764, 7, 7, 0, -7, 109 }, /* 0x61 */
++ { 2805, 7, 9, 0, -9, 116 }, /* 0x62 */
++ { 2857, 7, 7, 0, -7, 110 }, /* 0x63 */
++ { 2903, 7, 9, 0, -9, 116 }, /* 0x64 */
++ { 2960, 7, 7, 0, -7, 113 }, /* 0x65 */
++ { 3002, 5, 9, 0, -9, 78 }, /* 0x66 */
++ { 3036, 7, 10, 0, -7, 114 }, /* 0x67 */
++ { 3100, 7, 9, 0, -9, 113 }, /* 0x68 */
++ { 3156, 3, 9, 0, -9, 53 }, /* 0x69 */
++ { 3183, 4, 12, -1, -9, 52 }, /* 0x6a */
++ { 3230, 7, 9, 0, -9, 109 }, /* 0x6b */
++ { 3285, 3, 9, 0, -9, 50 }, /* 0x6c */
++ { 3312, 11, 7, 0, -7, 172 }, /* 0x6d */
++ { 3388, 7, 7, 0, -7, 113 }, /* 0x6e */
++ { 3436, 7, 7, 0, -7, 116 }, /* 0x6f */
++ { 3483, 7, 10, 0, -7, 117 }, /* 0x70 */
++ { 3541, 7, 10, 0, -7, 117 }, /* 0x71 */
++ { 3602, 5, 7, 0, -7, 78 }, /* 0x72 */
++ { 3631, 6, 7, 0, -7, 103 }, /* 0x73 */
++ { 3671, 5, 9, 0, -9, 78 }, /* 0x74 */
++ { 3705, 7, 7, 0, -7, 113 }, /* 0x75 */
++ { 3750, 7, 7, 0, -7, 105 }, /* 0x76 */
++ { 3788, 10, 7, 0, -7, 158 }, /* 0x77 */
++ { 3845, 7, 7, 0, -7, 107 }, /* 0x78 */
++ { 3885, 7, 10, 0, -7, 102 }, /* 0x79 */
++ { 3935, 6, 7, 0, -7, 95 }, /* 0x7a */
++ { 3964, 5, 14, 0, -11, 73 }, /* 0x7b */
++ { 4012, 2, 11, 0, -10, 40 }, /* 0x7c */
++ { 4034, 5, 14, 0, -11, 73 }, /* 0x7d */
++ { 4092, 7, 6, 0, -6, 109 }, /* 0x7e */
++ { 4111, 3, 5, 0, -5, 47 }, /* 0x80 */
++ { 4118, 5, 12, 0, -12, 79 }, /* 0x81 */
++ { 4146, 6, 7, 0, -7, 91 }, /* 0x82 */
++ { 4178, 6, 5, 0, -5, 97 }, /* 0x83 */
++ { 4186, 9, 5, 0, -5, 139 }, /* 0x84 */
++ { 4195, 3, 9, 0, -9, 38 }, /* 0x85 */
++ { 4204, 11, 3, 0, -2, 173 }, /* 0x86 */
++ { 4223, 4, 5, 0, -5, 65 }, /* 0x87 */
++ { 4233, 4, 6, 0, -6, 72 }, /* 0x88 */
++ { 4252, 5, 6, 0, -6, 77 }, /* 0x89 */
++};
++static const uint8_t xs_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern xs_kern[] = {
++ {39,45,-10},{39,52,-4},{39,65,-16},{39,74,-10},{39,99,-10},{39,100,-10},{39,101,-10},{39,103,-7},
++ {39,111,-10},{39,113,-7},{39,115,-5},{44,48,-6},{44,84,-12},{44,86,-6},{44,87,-6},{44,89,-12},
++ {44,118,-8},{44,119,-8},{44,121,-8},{45,39,-5},{45,45,-29},{45,55,-13},{45,84,-7},{45,118,-5},
++ {45,119,-5},{45,120,-5},{45,121,-5},{45,133,-5},{46,48,-6},{46,84,-12},{46,86,-6},{46,87,-6},
++ {46,89,-12},{46,118,-8},{46,119,-8},{46,121,-8},{48,49,-4},{52,39,-6},{52,49,-20},{52,55,-12},
++ {53,49,-4},{55,44,-12},{55,46,-12},{56,49,-4},{57,49,-4},{65,39,-19},{65,67,-4},{65,71,-4},
++ {65,79,-4},{65,81,-4},{65,83,-9},{65,84,-16},{65,86,-6},{65,87,-6},{65,89,-17},{65,102,-5},
++ {65,103,-4},{65,113,-4},{65,116,-5},{65,118,-9},{65,119,-9},{65,121,-9},{65,133,-14},{66,65,-7},
++ {66,86,-5},{66,87,-5},{66,88,-5},{66,89,-7},{67,89,-5},{68,65,-7},{68,86,-5},{68,87,-5},
++ {68,88,-5},{68,89,-7},{70,44,-17},{70,45,-11},{70,46,-17},{70,65,-14},{70,74,-11},{70,97,-9},
++ {70,99,-11},{70,100,-11},{70,101,-11},{70,103,-7},{70,109,-5},{70,110,-5},{70,111,-11},{70,112,-5},
++ {70,113,-7},{70,114,-5},{70,115,-9},{70,117,-6},{70,118,-10},{70,119,-10},{70,120,-9},{70,121,-10},
++ {70,122,-5},{71,89,-5},{75,45,-6},{75,65,4},{75,67,-5},{75,71,-5},{75,74,-4},{75,79,-5},
++ {75,81,-5},{75,83,-4},{75,99,-6},{75,100,-6},{75,101,-6},{75,103,-5},{75,111,-6},{75,113,-5},
++ {75,118,-8},{75,119,-8},{75,121,-8},{76,39,-16},{76,65,5},{76,84,-18},{76,86,-8},{76,87,-8},
++ {76,89,-9},{76,118,-5},{76,119,-5},{76,121,-5},{76,133,-10},{79,89,-5},{80,44,-5},{80,45,-5},
++ {80,46,-5},{80,65,-9},{80,74,-5},{80,88,-6},{80,89,-6},{80,99,-5},{80,100,-5},{80,101,-5},
++ {80,111,-5},{81,65,-5},{81,86,-6},{81,87,-6},{81,88,-6},{81,89,-10},{82,65,5},{82,86,-4},
++ {82,87,-4},{82,89,-5},{83,88,-7},{83,89,-5},{84,44,-12},{84,45,-16},{84,46,-12},{84,65,-13},
++ {84,67,-7},{84,71,-7},{84,74,-8},{84,79,-7},{84,81,-7},{84,97,-6},{84,99,-16},{84,100,-16},
++ {84,101,-16},{84,103,-13},{84,109,-12},{84,110,-12},{84,111,-16},{84,112,-12},{84,113,-13},{84,114,-12},
++ {84,115,-12},{84,117,-10},{84,118,-10},{84,119,-10},{84,120,-11},{84,121,-10},{86,44,-12},{86,45,-12},
++ {86,46,-12},{86,65,-20},{86,67,-6},{86,71,-6},{86,74,-8},{86,75,-4},{86,79,-6},{86,81,-6},
++ {86,83,-4},{86,97,-12},{86,99,-12},{86,100,-12},{86,101,-12},{86,103,-11},{86,111,-12},{86,113,-11},
++ {86,115,-8},{87,44,-12},{87,45,-12},{87,46,-12},{87,65,-20},{87,67,-6},{87,71,-6},{87,74,-8},
++ {87,75,-4},{87,79,-6},{87,81,-6},{87,83,-4},{87,97,-12},{87,99,-12},{87,100,-12},{87,101,-12},
++ {87,103,-11},{87,111,-12},{87,113,-11},{87,115,-8},{88,45,-6},{88,67,-5},{88,71,-5},{88,79,-5},
++ {88,81,-5},{88,83,-5},{88,99,-6},{88,100,-6},{88,101,-6},{88,103,-7},{88,111,-6},{88,113,-7},
++ {88,118,-6},{88,119,-6},{88,121,-6},{89,44,-19},{89,45,-15},{89,46,-19},{89,65,-23},{89,67,-7},
++ {89,71,-7},{89,74,-11},{89,79,-7},{89,81,-7},{89,83,-5},{89,97,-12},{89,99,-15},{89,100,-15},
++ {89,101,-15},{89,102,-8},{89,103,-17},{89,109,-11},{89,110,-11},{89,111,-15},{89,112,-11},{89,113,-17},
++ {89,114,-11},{89,115,-9},{89,116,-8},{89,117,-8},{89,118,-7},{89,119,-7},{89,120,-8},{89,121,-7},
++ {89,122,-5},{97,39,-5},{97,84,-6},{97,89,-7},{97,133,-4},{98,39,-8},{98,118,-4},{98,119,-4},
++ {98,121,-4},{99,39,-5},{99,44,-5},{99,46,-5},{99,120,-4},{99,133,-4},{101,39,-7},{101,44,-4},
++ {101,46,-4},{101,118,-5},{101,119,-5},{101,120,-4},{101,121,-5},{101,133,-5},{102,44,-11},{102,45,-7},
++ {102,46,-11},{102,99,-7},{102,100,-7},{102,101,-7},{102,103,-6},{102,111,-7},{102,113,-6},{104,39,-8},
++ {104,118,-4},{104,119,-4},{104,121,-4},{107,45,-7},{107,97,-4},{107,99,-7},{107,100,-7},{107,101,-7},
++ {107,103,-5},{107,111,-7},{107,113,-5},{109,39,-8},{109,118,-4},{109,119,-4},{109,121,-4},{110,39,-8},
++ {110,118,-4},{110,119,-4},{110,121,-4},{111,39,-5},{111,55,-13},{111,84,-7},{111,118,-5},{111,119,-5},
++ {111,120,-5},{111,121,-5},{111,133,-5},{112,39,-8},{112,118,-4},{112,119,-4},{112,121,-4},{114,39,5},
++ {114,44,-8},{114,46,-8},{114,103,-4},{114,113,-4},{114,118,4},{114,119,4},{114,121,4},{114,133,10},
++ {115,39,-4},{115,118,-7},{115,119,-7},{115,121,-7},{115,133,-5},{118,44,-8},{118,45,-6},{118,46,-8},
++ {118,97,-5},{118,99,-6},{118,100,-6},{118,101,-6},{118,103,-6},{118,111,-6},{118,113,-6},{118,115,-7},
++ {118,133,8},{119,44,-8},{119,45,-6},{119,46,-8},{119,97,-5},{119,99,-6},{119,100,-6},{119,101,-6},
++ {119,103,-6},{119,111,-6},{119,113,-6},{119,115,-7},{119,133,8},{120,45,-6},{120,99,-6},{120,100,-6},
++ {120,101,-6},{120,103,-5},{120,111,-6},{120,113,-5},{121,44,-8},{121,45,-6},{121,46,-8},{121,97,-5},
++ {121,99,-6},{121,100,-6},{121,101,-6},{121,103,-6},{121,111,-6},{121,113,-6},{121,115,-7},{121,133,8},
++ {133,45,-17},{133,65,-14},{133,97,-4},{133,99,-17},{133,100,-17},{133,101,-17},{133,103,-16},{133,111,-17},
++ {133,113,-16},{133,115,-14},{133,118,-4},{133,119,-4},{133,121,-4},
++};
++const struct fos_font fos_font_xs_data = { xs_bits, xs_glyphs, xs_lut, xs_kern, 389, 13, 3 };
++
++static const uint8_t sm_bits[] = {
++ 128,2,15,6,129,1,15,6,129,1,15,5,129,1,15,5,129,1,15,5,130,15,5,130,
++ 15,4,139,4,14,6,129,4,14,6,128,8,13,1,15,5,8,12,128,15,5,7,11,128,
++ 14,3,167,130,10,13,129,12,11,132,13,10,129,15,8,130,6,111,10,129,2,7,15,7,
++ 4,8,15,6,3,130,6,15,3,128,7,15,1,130,1,8,15,2,1,10,14,1,130,127,
++ 2,129,3,13,12,20,14,10,3,131,14,9,128,1,15,7,131,2,15,6,128,3,15,4,
++ 130,130,3,13,1,133,6,15,4,131,4,14,47,13,3,129,13,12,2,1,4,29,128,1,
++ 15,7,130,6,15,1,128,28,2,129,1,2,129,1,11,15,10,4,133,3,10,15,11,2,
++ 129,1,130,2,11,13,128,3,15,3,130,4,15,3,1,15,10,1,129,9,15,1,128,7,
++ 31,13,14,15,7,130,3,8,15,9,3,132,2,15,3,130,129,9,14,12,2,129,1,14,
++ 2,130,7,13,5,9,12,129,9,8,131,10,5,129,14,1,3,13,1,131,8,10,2,5,
++ 14,128,11,6,132,1,12,31,20,12,135,3,1,128,13,4,137,6,10,128,9,15,14,3,
++ 132,1,14,2,6,13,5,7,14,132,8,9,128,8,7,129,13,2,130,2,14,1,128,5,
++ 13,5,8,13,131,10,6,130,8,14,13,3,128,129,5,13,15,13,5,132,3,15,11,5,
++ 10,15,3,131,6,15,3,128,1,15,7,131,2,15,8,128,7,15,4,132,7,15,11,15,
++ 8,133,5,31,8,133,7,15,9,11,14,3,128,5,2,128,1,15,9,128,1,11,14,6,
++ 15,6,128,3,15,5,129,1,13,15,10,129,1,14,13,22,10,31,11,130,3,11,30,12,
++ 5,3,14,9,128,8,14,8,13,7,12,143,129,6,15,2,129,1,14,10,130,6,15,5,
++ 130,10,15,1,130,29,131,15,11,131,15,11,131,15,11,131,29,131,10,15,1,130,6,15,
++ 5,130,1,14,10,131,6,15,2,128,128,7,14,2,129,1,14,10,130,10,15,1,129,6,
++ 15,5,129,3,15,8,129,1,15,10,130,15,11,129,1,15,10,129,3,15,8,129,6,15,
++ 5,129,10,15,1,128,1,14,9,129,7,14,2,128,1,128,4,9,128,1,5,13,9,11,
++ 26,128,4,31,9,128,5,13,9,27,10,1,128,4,9,128,1,163,130,10,9,133,11,9,
++ 131,17,11,10,17,128,6,95,5,1,20,12,11,20,1,130,11,9,133,10,9,138,128,7,
++ 13,129,10,9,129,13,5,129,15,1,128,128,65,6,63,12,1,52,3,145,128,9,13,1,
++ 128,10,13,1,131,13,9,131,4,15,4,131,9,14,132,14,9,131,5,15,3,131,10,13,
++ 131,1,14,8,131,6,15,3,131,11,12,131,1,15,7,131,6,15,2,131,129,7,13,14,
++ 13,7,130,7,15,9,5,8,15,8,129,13,10,130,9,14,129,15,8,130,7,15,1,128,
++ 15,8,130,7,15,1,128,15,8,130,7,15,1,128,15,8,130,7,15,1,128,15,8,130,
++ 7,15,1,128,13,10,130,9,14,129,7,15,8,5,8,15,8,130,7,13,14,13,7,129,
++ 128,5,12,15,5,128,3,15,13,15,5,129,2,3,15,5,130,3,15,5,130,3,15,5,
++ 130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,
++ 128,128,1,9,30,12,4,130,12,14,7,5,11,15,3,128,2,15,7,129,1,15,8,128,
++ 1,8,3,129,2,15,7,133,9,15,2,132,6,15,7,132,4,15,10,132,2,14,12,1,
++ 131,1,29,1,132,12,15,7,52,128,2,95,13,128,2,95,5,128,36,6,14,15,3,130,
++ 1,12,15,5,130,1,11,15,5,131,5,31,11,3,131,3,2,11,14,1,132,3,15,5,
++ 2,8,2,129,1,15,7,3,15,6,129,4,15,4,128,11,14,22,29,1,128,1,9,30,
++ 11,2,128,130,4,15,5,133,11,13,133,3,15,7,133,10,14,1,132,2,15,8,128,3,
++ 15,4,129,8,15,2,128,3,15,5,128,1,14,11,17,4,15,6,128,5,111,3,1,52,
++ 6,15,7,1,132,3,15,5,133,3,15,5,128,1,95,3,1,15,9,52,17,15,7,132,
++ 1,15,7,132,1,15,11,13,15,13,6,128,1,15,14,6,4,10,15,4,128,6,3,129,
++ 1,15,8,133,14,9,128,14,9,129,1,15,8,128,9,15,7,5,12,15,2,129,8,13,
++ 14,12,4,128,128,1,9,14,15,12,4,129,11,14,7,5,12,15,2,1,15,8,129,3,
++ 15,6,1,15,7,132,1,15,10,13,15,14,6,128,1,31,7,5,11,15,3,1,15,9,
++ 129,1,15,8,1,15,7,130,14,9,128,14,10,129,1,15,8,128,9,15,8,5,11,15,
++ 2,129,8,13,15,12,4,128,7,95,6,8,13,36,9,15,4,1,2,130,11,14,132,2,
++ 15,8,132,7,15,2,132,13,12,132,4,15,6,132,9,15,1,131,1,14,10,132,6,15,
++ 4,132,11,13,131,129,8,30,11,2,129,8,15,8,6,29,1,128,14,10,129,4,15,5,
++ 128,15,9,129,2,15,6,128,10,14,4,2,10,15,2,128,1,14,47,7,129,11,14,6,
++ 4,10,15,18,15,7,129,1,15,8,2,15,7,129,1,15,8,128,12,14,7,5,11,15,
++ 3,128,1,10,14,15,12,5,128,128,1,9,30,11,2,129,11,15,7,6,13,14,1,2,
++ 15,7,129,4,15,5,4,15,4,129,1,15,7,3,15,6,129,3,15,7,128,29,4,2,
++ 11,15,7,128,3,14,31,11,15,7,130,3,2,1,15,7,128,13,8,129,2,15,6,128,
++ 11,14,7,5,12,14,2,128,1,10,30,12,4,128,128,2,14,8,130,2,14,8,148,2,
++ 14,8,130,2,14,8,129,128,5,14,6,129,7,15,8,130,1,140,2,15,3,129,4,15,
++ 130,6,12,130,8,9,129,140,4,11,5,130,5,12,15,11,2,1,7,13,15,9,3,129,
++ 7,15,10,1,131,3,12,15,11,4,132,3,10,15,13,6,1,131,2,9,15,5,133,1,
++ 2,6,95,5,1,83,1,143,6,95,5,1,83,1,143,135,6,11,4,132,3,12,15,12,
++ 5,132,3,10,15,13,6,1,131,2,11,15,5,130,5,11,15,11,2,1,7,13,15,10,
++ 3,129,7,14,8,2,131,2,1,133,128,3,11,30,9,1,128,1,14,12,5,7,14,11,
++ 128,6,15,3,129,8,15,1,2,6,130,9,14,132,8,15,8,131,9,15,7,131,2,15,
++ 8,132,2,12,4,140,4,14,5,132,4,14,5,130,144,7,12,31,14,9,2,131,2,29,
++ 8,5,4,6,12,14,3,129,1,13,9,1,130,1,128,8,12,129,8,11,128,3,13,15,
++ 10,13,129,14,2,128,13,4,128,12,10,4,27,129,13,4,1,15,128,1,15,1,128,7,
++ 9,128,1,14,18,15,128,2,15,19,13,10,2,9,13,129,15,2,128,11,31,7,14,15,
++ 14,3,129,26,129,18,128,1,3,1,130,2,14,11,4,1,2,4,8,133,2,11,47,14,
++ 8,135,1,19,133,130,1,31,2,133,6,31,7,133,11,12,11,12,132,1,15,23,15,2,
++ 131,6,15,3,2,15,7,131,11,13,129,28,130,1,15,8,129,8,15,2,129,6,15,4,
++ 129,3,15,7,129,11,95,12,128,1,15,10,51,9,15,2,5,15,4,131,3,15,6,128,
++ 10,63,13,7,130,10,13,20,5,10,15,7,129,10,13,131,12,11,129,10,13,131,27,129,
++ 10,13,33,6,15,4,129,10,79,10,130,10,13,36,8,15,9,129,10,13,131,10,14,129,
++ 10,13,131,10,13,129,10,13,20,5,8,15,8,129,10,63,13,7,129,129,5,12,30,11,
++ 3,130,5,15,11,5,6,12,15,3,129,28,130,1,14,10,129,15,8,131,23,129,15,8,
++ 135,15,8,135,15,8,135,15,8,131,23,129,28,130,1,14,10,129,5,15,11,5,6,12,
++ 15,3,130,5,12,30,11,3,129,128,10,63,12,6,130,10,13,20,5,9,15,7,129,10,
++ 13,131,11,13,129,10,13,131,8,15,129,10,13,131,8,15,129,10,13,131,8,15,129,10,
++ 13,131,8,15,129,10,13,131,8,15,129,10,13,131,11,13,129,10,13,20,5,9,15,7,
++ 129,10,63,12,6,129,128,10,95,11,129,10,13,68,3,129,10,13,135,10,13,135,10,13,
++ 49,131,10,63,14,131,10,13,36,3,131,10,13,135,10,13,135,10,13,68,3,129,10,95,
++ 11,128,128,10,95,11,128,10,13,68,3,128,10,13,134,10,13,134,10,13,49,130,10,63,
++ 14,130,10,13,36,3,130,10,13,134,10,13,134,10,13,134,10,12,133,129,5,12,30,11,
++ 4,130,5,15,11,5,6,12,15,4,129,28,130,1,14,10,129,15,9,131,5,6,129,15,
++ 8,129,49,129,15,8,128,2,47,12,129,15,8,129,3,4,28,129,15,9,131,11,12,129,
++ 28,130,1,14,9,129,5,15,11,5,6,12,14,3,130,5,12,30,11,3,129,128,10,12,
++ 131,7,15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,
++ 1,128,10,13,49,8,15,1,128,10,111,1,128,10,13,52,9,15,1,128,10,13,131,7,
++ 15,1,128,10,13,131,7,15,1,128,10,13,131,7,15,1,128,10,12,131,7,15,1,128,
++ 10,12,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,10,13,129,
++ 10,13,129,10,13,129,10,12,128,133,8,14,134,9,14,134,9,14,134,9,14,134,9,14,
++ 134,9,14,128,5,8,131,9,14,128,9,14,131,9,14,128,7,15,2,130,28,128,2,14,
++ 13,6,5,10,15,6,129,2,10,30,12,5,129,128,10,12,130,1,12,13,1,128,10,13,
++ 130,11,14,2,129,10,13,129,9,15,4,130,10,13,128,8,15,6,131,10,13,6,15,9,
++ 132,10,14,15,14,12,132,10,15,9,4,15,8,131,10,13,129,8,15,3,130,10,13,130,
++ 29,1,129,10,13,130,3,15,8,129,10,12,131,7,15,4,128,10,12,134,10,13,134,10,
++ 13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,134,10,13,69,3,
++ 128,10,95,9,128,10,15,3,131,11,15,2,128,10,15,12,130,6,31,2,128,10,31,8,
++ 128,2,14,31,2,128,10,13,9,15,3,11,14,8,15,2,128,10,13,1,13,14,15,5,
++ 6,15,2,128,10,13,128,4,15,10,128,6,15,2,128,10,13,129,3,1,128,6,15,2,
++ 128,10,13,132,6,15,2,128,10,13,132,6,15,2,128,10,13,132,6,15,2,128,10,12,
++ 132,6,15,2,128,10,14,2,130,1,15,6,129,10,15,11,130,1,15,7,129,10,31,5,
++ 129,1,15,7,129,10,12,11,13,1,128,1,15,7,129,10,12,2,15,8,128,1,15,7,
++ 129,10,13,128,8,15,3,1,15,7,129,10,13,129,13,12,1,15,7,129,10,13,129,4,
++ 15,8,15,7,129,10,13,130,9,31,7,129,10,13,130,1,14,15,7,129,10,12,131,5,
++ 15,6,128,129,4,11,30,11,3,130,4,15,11,22,12,15,3,129,12,13,130,1,13,11,
++ 129,14,9,131,10,13,129,15,8,131,9,14,129,15,8,131,9,14,129,15,8,131,9,14,
++ 129,14,9,131,10,13,129,12,13,130,1,13,11,129,4,15,11,22,12,15,3,130,4,11,
++ 30,11,3,129,128,12,63,13,8,129,28,20,5,9,15,8,128,12,11,131,11,13,128,12,
++ 11,131,10,14,128,28,33,5,15,10,128,12,79,11,1,128,28,20,3,2,130,12,11,134,
++ 12,11,134,12,11,134,12,11,133,129,6,12,15,13,9,1,129,7,15,9,5,7,14,11,
++ 129,14,10,130,5,15,4,2,15,6,130,1,15,7,3,15,6,130,1,15,7,3,15,6,
++ 130,1,15,7,3,15,6,130,1,15,7,2,15,6,130,1,15,7,1,15,8,130,3,15,
++ 5,128,10,14,5,1,3,12,14,1,128,1,11,47,13,3,131,3,15,8,133,1,13,5,
++ 130,128,10,63,14,8,130,10,13,20,5,8,15,8,129,10,13,131,10,13,129,10,13,131,
++ 9,14,129,10,13,33,5,14,10,129,10,79,11,1,129,10,13,20,10,14,131,10,13,129,
++ 2,15,6,130,10,13,130,10,13,130,10,13,130,2,15,6,129,10,12,131,10,13,128,128,
++ 1,8,13,15,14,10,2,129,10,14,7,5,7,13,14,1,128,15,8,130,3,15,7,128,
++ 14,10,131,7,4,128,5,15,12,6,1,132,3,10,15,14,9,1,132,1,7,30,18,9,
++ 2,130,2,15,8,3,15,6,130,1,14,9,128,12,15,8,5,6,11,15,4,128,1,8,
++ 13,15,14,11,4,128,6,111,9,2,20,7,15,8,20,2,130,4,15,4,133,4,15,4,
++ 133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,133,4,15,4,
++ 133,3,15,4,130,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,12,11,131,7,
++ 15,1,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,12,11,131,7,15,1,128,
++ 12,11,131,7,15,1,128,12,11,131,8,15,1,128,9,14,1,130,12,13,129,3,14,12,
++ 6,5,10,15,6,130,3,11,30,12,5,129,5,15,4,131,9,14,128,1,15,8,131,13,
++ 10,129,11,13,130,3,15,5,129,6,15,2,129,8,15,1,129,1,15,7,129,12,10,131,
++ 28,128,2,15,5,131,7,15,1,6,15,1,131,2,15,6,27,133,12,11,15,6,133,7,
++ 31,1,133,2,15,11,131,7,15,2,130,29,130,1,15,8,3,15,6,129,2,31,3,129,
++ 4,15,4,128,14,10,129,6,31,7,129,8,14,129,10,14,129,10,28,11,129,12,11,129,
++ 6,15,3,128,14,24,14,128,1,15,7,129,1,15,7,3,15,20,15,4,5,15,2,130,
++ 12,11,6,15,1,128,15,8,9,13,131,8,14,11,12,129,11,12,13,9,131,4,31,8,
++ 129,7,31,5,132,14,15,4,129,3,31,1,132,10,15,1,130,14,12,130,3,15,6,131,
++ 12,13,129,9,14,1,129,6,15,4,129,1,14,10,128,1,14,10,131,6,15,4,9,14,
++ 2,132,11,13,15,7,133,4,15,14,134,10,14,15,5,132,5,15,5,10,14,1,130,1,
++ 13,11,128,2,14,9,130,9,14,2,129,6,15,4,128,3,15,7,131,12,13,128,4,15,
++ 6,130,1,14,9,128,11,13,130,9,15,2,128,3,15,7,128,2,15,8,130,10,14,1,
++ 10,14,1,130,2,15,10,15,7,132,8,15,13,133,2,15,7,133,1,15,7,133,1,15,
++ 7,133,1,15,7,133,1,15,6,130,5,111,17,52,5,14,13,133,8,15,4,132,3,15,
++ 9,133,12,13,1,132,8,15,4,132,3,15,8,133,29,1,132,8,15,3,132,3,15,11,
++ 68,128,5,111,1,128,33,129,7,47,3,128,7,15,20,1,128,7,15,1,130,7,15,1,
++ 130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,
++ 130,7,15,1,130,7,15,1,130,7,15,2,1,129,7,47,3,128,1,36,1,128,128,12,
++ 11,132,7,15,1,131,2,15,6,132,11,12,132,6,15,2,131,1,15,7,132,11,13,132,
++ 5,15,3,131,1,14,8,132,10,13,132,4,15,3,129,49,129,14,31,11,129,3,4,13,
++ 12,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,131,28,129,17,28,
++ 129,14,31,12,129,3,20,2,129,3,15,8,131,9,13,14,130,1,14,4,14,5,129,7,
++ 13,128,8,11,129,13,7,128,2,15,2,4,15,1,129,11,8,162,128,81,128,9,95,8,
++ 2,84,2,4,14,2,128,9,10,154,128,2,10,30,11,3,129,13,14,6,5,12,14,1,
++ 128,4,3,128,1,4,15,4,128,4,12,63,5,2,15,12,5,4,6,15,21,15,3,129,
++ 5,15,5,3,15,10,5,7,14,15,5,128,6,13,14,12,7,15,4,128,13,10,134,13,
++ 10,134,13,10,134,13,11,10,14,13,7,130,13,15,10,5,10,15,6,129,13,14,130,13,
++ 12,129,13,11,130,10,14,129,13,11,130,10,14,129,13,14,130,13,11,129,13,15,10,5,
++ 10,15,5,129,13,11,10,14,13,6,129,129,7,13,15,12,5,129,8,15,8,5,10,15,
++ 5,128,14,9,130,11,8,1,15,7,132,1,15,7,133,14,10,130,11,7,128,8,15,8,
++ 5,10,15,5,129,7,13,15,12,5,128,133,12,11,134,12,11,134,12,11,130,8,30,9,
++ 13,11,129,8,15,9,5,12,15,11,129,14,11,129,2,15,11,128,1,15,8,130,14,11,
++ 128,1,15,7,130,14,11,129,14,11,129,1,15,11,129,7,15,9,5,12,15,11,130,8,
++ 30,9,13,11,128,129,8,13,14,13,6,130,8,14,7,5,10,15,4,129,14,9,33,13,
++ 9,128,1,95,11,128,1,15,9,52,2,129,14,10,130,3,130,7,15,9,5,8,15,6,
++ 130,7,13,15,13,7,129,129,7,13,15,4,128,1,15,12,5,1,128,3,15,5,129,7,
++ 63,3,2,7,15,8,4,1,128,3,15,5,130,3,15,5,130,3,15,5,130,3,15,5,
++ 130,3,15,5,130,3,15,5,129,128,1,9,30,9,13,10,129,10,15,8,5,11,15,10,
++ 128,1,15,10,129,1,15,10,128,2,15,6,130,13,10,128,2,15,6,130,13,10,128,1,
++ 15,9,129,1,15,10,129,10,15,8,5,11,15,10,129,1,9,30,9,14,10,133,1,15,
++ 8,130,1,5,6,12,15,3,130,4,15,13,10,3,129,128,13,10,134,13,10,134,13,10,
++ 134,13,11,10,14,13,7,130,13,15,9,5,11,15,4,129,13,12,129,1,15,8,129,13,
++ 10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,
++ 10,130,14,9,128,128,11,13,129,11,12,133,11,12,129,11,12,129,11,12,129,11,12,129,
++ 11,12,129,11,12,129,11,12,129,11,12,128,129,13,11,130,12,11,135,12,10,130,12,11,
++ 130,12,11,130,12,11,130,12,11,130,12,11,130,12,11,130,12,11,130,13,10,128,3,8,
++ 15,7,128,10,14,9,1,128,128,13,10,133,13,10,133,13,10,133,13,10,129,10,14,2,
++ 128,13,10,128,9,15,4,129,13,10,8,15,8,130,13,14,15,13,10,130,13,15,6,5,
++ 15,3,129,13,10,129,13,10,129,13,10,129,7,15,2,128,13,10,129,1,14,9,128,13,
++ 10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,10,129,13,
++ 10,129,13,10,129,13,10,128,128,13,11,10,30,7,3,12,15,12,4,129,13,15,8,5,
++ 12,15,14,7,6,13,14,129,13,11,129,3,15,8,129,6,15,2,128,13,10,129,2,15,
++ 6,129,5,15,3,128,13,10,129,2,15,6,129,5,15,3,128,13,10,129,2,15,6,129,
++ 5,15,3,128,13,10,129,2,15,6,129,5,15,3,128,13,10,129,1,15,6,129,4,15,
++ 3,128,13,11,10,14,13,7,130,13,15,9,5,11,15,4,129,13,12,129,1,15,8,129,
++ 13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,13,10,130,14,9,129,
++ 13,10,130,14,9,128,129,7,13,15,12,5,130,7,15,8,5,10,15,5,129,14,10,130,
++ 28,128,2,15,7,130,9,14,128,2,15,7,130,10,14,129,14,10,130,28,129,7,15,8,
++ 5,10,15,5,130,7,13,15,12,5,129,128,28,10,14,13,7,130,12,15,11,5,9,15,
++ 6,129,12,14,1,129,12,13,129,28,130,8,15,129,28,130,9,15,129,12,14,1,129,12,
++ 13,129,12,15,11,5,10,15,7,129,28,10,14,13,8,130,12,11,134,12,11,134,12,11,
++ 133,129,8,30,9,13,11,129,7,15,9,5,12,15,11,129,14,11,129,1,15,11,128,1,
++ 15,7,130,14,11,128,1,15,8,130,14,11,129,14,11,129,2,15,11,129,8,15,9,5,
++ 12,15,11,130,8,30,9,13,11,134,12,11,134,12,11,134,12,11,128,128,13,11,10,14,
++ 8,128,13,15,9,5,3,128,13,12,131,13,10,131,13,10,131,13,10,131,13,10,131,13,
++ 10,130,128,3,11,30,10,2,129,14,12,5,6,13,12,128,2,15,7,129,3,7,129,8,
++ 15,12,7,2,131,2,7,12,15,8,128,2,8,2,129,8,15,17,14,12,5,6,13,14,
++ 129,4,11,30,11,3,128,128,4,15,3,130,4,15,3,129,7,63,18,7,15,6,4,129,
++ 4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,3,15,10,4,130,9,14,15,
++ 1,128,15,8,130,15,7,129,15,8,130,15,7,129,15,8,130,15,7,129,15,8,130,15,
++ 7,129,15,8,130,15,7,129,14,9,129,2,15,7,129,11,15,7,5,12,15,7,129,2,
++ 10,30,8,15,7,128,6,15,3,129,6,15,4,1,15,8,129,10,14,129,11,13,129,14,
++ 9,129,6,15,2,5,15,4,129,1,15,7,9,14,131,11,12,14,9,131,6,31,4,131,
++ 1,15,14,130,7,15,2,129,14,11,129,3,15,5,2,15,6,128,3,31,129,8,15,1,
++ 128,13,10,128,7,14,15,4,128,12,11,129,8,14,128,11,9,12,8,1,15,6,129,4,
++ 15,3,15,5,8,12,5,15,2,130,14,11,15,1,3,15,11,12,131,10,15,11,129,14,
++ 15,8,131,5,15,7,129,9,15,3,129,5,15,5,129,6,15,5,128,10,14,1,2,14,
++ 10,129,1,13,10,11,13,1,130,4,31,4,131,3,31,3,130,1,13,12,11,13,1,129,
++ 9,14,18,14,9,128,5,15,6,129,5,15,5,8,15,2,129,6,15,18,15,6,129,11,
++ 12,129,12,11,128,1,15,7,129,7,15,1,5,15,2,129,2,15,5,10,11,131,12,10,
++ 14,6,131,6,31,1,131,1,15,10,132,2,15,5,130,1,4,12,13,131,3,15,12,3,
++ 131,6,79,10,2,36,10,15,7,130,3,15,10,130,1,13,12,1,130,11,14,2,130,8,
++ 15,4,130,5,15,10,36,3,8,79,10,130,17,128,1,13,15,11,128,6,15,8,2,128,
++ 6,15,2,129,6,15,2,129,6,15,2,129,7,15,1,128,4,14,12,129,5,14,9,130,
++ 8,15,1,129,6,15,2,129,6,15,2,129,6,15,2,129,6,15,5,1,128,2,14,15,
++ 11,129,1,3,2,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,
++ 15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,5,15,3,128,1,130,7,
++ 15,14,4,128,1,5,15,10,130,13,10,130,13,10,130,13,10,130,13,11,130,8,15,7,
++ 129,6,15,8,129,28,130,13,10,130,13,10,130,13,10,129,2,15,10,128,7,31,6,128,
++ 1,3,2,129,135,1,10,15,13,6,2,8,19,11,5,7,14,15,14,2,131,1,3,1,
++ 152,2,14,8,128,2,14,8,144,134,8,14,15,9,128,5,14,21,13,6,8,7,129,7,
++ 9,6,12,3,2,12,7,128,10,31,10,130,18,171,2,11,1,128,2,10,17,12,13,4,
++ 13,11,1,128,1,12,15,12,1,129,2,13,15,13,2,128,2,13,11,2,12,13,17,8,
++ 1,128,1,7,142,128,81,6,79,12,1,68,3,148,128,113,1,128,6,127,15,4,1,116,
++ 4,1,160,2,15,6,8,13,128,12,7,152,128,9,13,1,128,4,14,5,128,1,13,9,
++ 129,10,13,1,128,5,14,5,128,1,14,9,128,128,10,14,10,128,5,47,21,47,5,128,
++ 10,14,10,138,129,9,13,1,129,6,14,3,129,1,14,8,131,6,14,2,131,9,13,1,
++ 140,128,4,15,4,131,7,14,2,131,13,10,130,7,14,2,129,4,15,4,141,
++};
++static const struct fos_glyph sm_glyphs[] = {
++ { 0, 3, 0, 0, 0, 51 }, /* 0x20 */
++ { 0, 5, 11, 0, -11, 84 }, /* 0x21 */
++ { 35, 5, 11, 0, -11, 76 }, /* 0x22 */
++ { 51, 11, 10, 0, -10, 171 }, /* 0x23 */
++ { 121, 9, 14, 0, -13, 144 }, /* 0x24 */
++ { 208, 13, 11, 0, -11, 215 }, /* 0x25 */
++ { 301, 11, 11, 0, -11, 173 }, /* 0x26 */
++ { 389, 2, 11, 0, -11, 37 }, /* 0x27 */
++ { 396, 6, 13, -1, -11, 74 }, /* 0x28 */
++ { 442, 5, 13, 0, -11, 74 }, /* 0x29 */
++ { 494, 6, 11, 0, -11, 102 }, /* 0x2a */
++ { 522, 8, 8, 0, -8, 127 }, /* 0x2b */
++ { 550, 4, 4, 0, -3, 68 }, /* 0x2c */
++ { 563, 6, 6, 0, -6, 102 }, /* 0x2d */
++ { 572, 4, 2, 0, -2, 70 }, /* 0x2e */
++ { 580, 7, 11, 0, -11, 109 }, /* 0x2f */
++ { 620, 9, 11, 0, -11, 145 }, /* 0x30 */
++ { 696, 6, 11, 0, -11, 90 }, /* 0x31 */
++ { 745, 9, 11, 0, -11, 139 }, /* 0x32 */
++ { 806, 8, 11, 0, -11, 134 }, /* 0x33 */
++ { 867, 9, 11, 0, -11, 146 }, /* 0x34 */
++ { 925, 8, 11, 0, -11, 134 }, /* 0x35 */
++ { 988, 8, 11, 0, -11, 134 }, /* 0x36 */
++ { 1064, 8, 11, 0, -11, 123 }, /* 0x37 */
++ { 1109, 8, 11, 0, -11, 135 }, /* 0x38 */
++ { 1185, 8, 11, 0, -11, 134 }, /* 0x39 */
++ { 1262, 6, 7, 0, -7, 89 }, /* 0x3a */
++ { 1279, 5, 9, 0, -8, 80 }, /* 0x3b */
++ { 1303, 8, 9, 0, -9, 127 }, /* 0x3c */
++ { 1345, 8, 8, 0, -8, 127 }, /* 0x3d */
++ { 1359, 8, 9, 0, -9, 127 }, /* 0x3e */
++ { 1402, 8, 11, 0, -11, 123 }, /* 0x3f */
++ { 1454, 13, 13, 0, -11, 211 }, /* 0x40 */
++ { 1565, 10, 11, 0, -11, 161 }, /* 0x41 */
++ { 1631, 10, 11, 0, -11, 160 }, /* 0x42 */
++ { 1699, 10, 11, 0, -11, 155 }, /* 0x43 */
++ { 1761, 10, 11, 0, -11, 158 }, /* 0x44 */
++ { 1830, 10, 11, 0, -11, 153 }, /* 0x45 */
++ { 1874, 9, 11, 0, -11, 145 }, /* 0x46 */
++ { 1915, 10, 11, 0, -11, 157 }, /* 0x47 */
++ { 1989, 10, 11, 0, -11, 165 }, /* 0x48 */
++ { 2063, 4, 11, 0, -11, 67 }, /* 0x49 */
++ { 2097, 9, 11, 0, -11, 148 }, /* 0x4a */
++ { 2149, 10, 11, 0, -11, 158 }, /* 0x4b */
++ { 2224, 9, 11, 0, -11, 146 }, /* 0x4c */
++ { 2260, 11, 11, 0, -11, 183 }, /* 0x4d */
++ { 2356, 11, 11, 0, -11, 172 }, /* 0x4e */
++ { 2451, 10, 11, 0, -11, 159 }, /* 0x4f */
++ { 2524, 9, 11, 0, -11, 152 }, /* 0x50 */
++ { 2577, 9, 13, 0, -11, 149 }, /* 0x51 */
++ { 2665, 10, 11, 0, -11, 157 }, /* 0x52 */
++ { 2735, 9, 11, 0, -11, 151 }, /* 0x53 */
++ { 2814, 9, 11, 0, -11, 147 }, /* 0x54 */
++ { 2861, 10, 11, 0, -11, 164 }, /* 0x55 */
++ { 2940, 10, 11, 0, -11, 154 }, /* 0x56 */
++ { 3007, 14, 11, 0, -11, 225 }, /* 0x57 */
++ { 3116, 10, 11, 0, -11, 155 }, /* 0x58 */
++ { 3190, 9, 11, 0, -11, 150 }, /* 0x59 */
++ { 3250, 9, 11, 0, -11, 141 }, /* 0x5a */
++ { 3293, 6, 16, 0, -13, 101 }, /* 0x5b */
++ { 3358, 7, 11, 0, -11, 109 }, /* 0x5c */
++ { 3398, 6, 16, 0, -13, 101 }, /* 0x5d */
++ { 3440, 7, 11, 0, -11, 117 }, /* 0x5e */
++ { 3474, 8, 3, 0, -2, 127 }, /* 0x5f */
++ { 3483, 3, 11, 0, -11, 54 }, /* 0x60 */
++ { 3490, 8, 8, 0, -8, 132 }, /* 0x61 */
++ { 3547, 9, 11, 0, -11, 142 }, /* 0x62 */
++ { 3611, 8, 8, 0, -8, 135 }, /* 0x63 */
++ { 3659, 9, 11, 0, -11, 142 }, /* 0x64 */
++ { 3725, 9, 8, 0, -8, 137 }, /* 0x65 */
++ { 3775, 6, 11, 0, -11, 94 }, /* 0x66 */
++ { 3825, 9, 11, 0, -8, 139 }, /* 0x67 */
++ { 3903, 9, 11, 0, -11, 139 }, /* 0x68 */
++ { 3965, 4, 11, 0, -11, 65 }, /* 0x69 */
++ { 3996, 5, 14, -1, -11, 63 }, /* 0x6a */
++ { 4040, 8, 11, 0, -11, 131 }, /* 0x6b */
++ { 4102, 4, 11, 0, -11, 60 }, /* 0x6c */
++ { 4136, 13, 8, 0, -8, 211 }, /* 0x6d */
++ { 4225, 9, 8, 0, -8, 139 }, /* 0x6e */
++ { 4278, 9, 8, 0, -8, 142 }, /* 0x6f */
++ { 4331, 9, 11, 0, -8, 143 }, /* 0x70 */
++ { 4393, 9, 11, 0, -8, 143 }, /* 0x71 */
++ { 4459, 6, 8, 0, -8, 95 }, /* 0x72 */
++ { 4490, 8, 8, 0, -8, 125 }, /* 0x73 */
++ { 4543, 6, 10, 0, -10, 94 }, /* 0x74 */
++ { 4585, 9, 8, 0, -8, 138 }, /* 0x75 */
++ { 4638, 8, 8, 0, -8, 126 }, /* 0x76 */
++ { 4684, 12, 8, 0, -8, 190 }, /* 0x77 */
++ { 4763, 8, 8, 0, -8, 128 }, /* 0x78 */
++ { 4813, 8, 11, 0, -8, 122 }, /* 0x79 */
++ { 4873, 7, 8, 0, -8, 115 }, /* 0x7a */
++ { 4907, 5, 16, 0, -13, 84 }, /* 0x7b */
++ { 4973, 3, 13, 0, -12, 46 }, /* 0x7c */
++ { 5012, 5, 16, 0, -13, 84 }, /* 0x7d */
++ { 5068, 8, 7, 0, -7, 131 }, /* 0x7e */
++ { 5089, 4, 6, 0, -6, 56 }, /* 0x80 */
++ { 5097, 6, 14, 0, -14, 97 }, /* 0x81 */
++ { 5126, 7, 8, 0, -8, 110 }, /* 0x82 */
++ { 5165, 7, 6, 0, -6, 118 }, /* 0x83 */
++ { 5174, 11, 6, 0, -6, 173 }, /* 0x84 */
++ { 5187, 3, 11, 0, -11, 42 }, /* 0x85 */
++ { 5196, 13, 2, 0, -2, 209 }, /* 0x86 */
++ { 5221, 5, 6, 0, -6, 80 }, /* 0x87 */
++ { 5236, 6, 7, 0, -7, 90 }, /* 0x88 */
++ { 5257, 6, 7, 0, -7, 98 }, /* 0x89 */
++};
++static const uint8_t sm_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern sm_kern[] = {
++ {39,45,-13},{39,65,-18},{39,74,-10},{39,99,-13},{39,100,-13},{39,101,-13},{39,103,-9},{39,109,-4},
++ {39,110,-4},{39,111,-13},{39,112,-4},{39,113,-9},{39,114,-4},{39,115,-7},{44,45,-4},{44,48,-8},
++ {44,84,-12},{44,86,-6},{44,87,-6},{44,89,-12},{44,99,-4},{44,100,-4},{44,101,-4},{44,103,-4},
++ {44,111,-4},{44,113,-4},{44,118,-10},{44,119,-10},{44,121,-10},{45,39,-5},{45,45,-32},{45,55,-13},
++ {45,84,-11},{45,118,-6},{45,119,-6},{45,120,-4},{45,121,-6},{45,133,-6},{46,45,-4},{46,48,-8},
++ {46,84,-12},{46,86,-6},{46,87,-6},{46,89,-12},{46,99,-4},{46,100,-4},{46,101,-4},{46,103,-4},
++ {46,111,-4},{46,113,-4},{46,118,-10},{46,119,-10},{46,121,-10},{48,49,-6},{52,39,-6},{52,49,-24},
++ {52,55,-12},{53,49,-6},{54,49,-4},{55,44,-13},{55,46,-13},{56,49,-6},{57,49,-5},{65,39,-21},
++ {65,45,-4},{65,67,-4},{65,71,-4},{65,79,-4},{65,81,-4},{65,83,-10},{65,84,-18},{65,86,-10},
++ {65,87,-10},{65,89,-20},{65,90,4},{65,99,-4},{65,100,-4},{65,101,-4},{65,102,-5},{65,103,-5},
++ {65,111,-4},{65,113,-5},{65,116,-5},{65,118,-9},{65,119,-9},{65,121,-9},{65,133,-16},{66,65,-7},
++ {66,86,-6},{66,87,-6},{66,88,-5},{66,89,-6},{66,103,-4},{66,113,-4},{66,115,-4},{67,74,4},
++ {67,89,-4},{68,65,-7},{68,86,-6},{68,87,-6},{68,88,-5},{68,89,-6},{68,103,-4},{68,113,-4},
++ {68,115,-4},{70,44,-20},{70,45,-12},{70,46,-20},{70,65,-15},{70,74,-12},{70,97,-10},{70,99,-12},
++ {70,100,-12},{70,101,-12},{70,103,-7},{70,109,-5},{70,110,-5},{70,111,-12},{70,112,-5},{70,113,-7},
++ {70,114,-5},{70,115,-9},{70,117,-6},{70,118,-11},{70,119,-11},{70,120,-9},{70,121,-11},{70,122,-5},
++ {71,74,4},{71,89,-4},{75,45,-6},{75,65,6},{75,67,-5},{75,71,-5},{75,74,-4},{75,79,-5},
++ {75,81,-5},{75,99,-6},{75,100,-6},{75,101,-6},{75,103,-5},{75,111,-6},{75,113,-5},{75,118,-8},
++ {75,119,-8},{75,121,-8},{76,39,-16},{76,65,8},{76,84,-23},{76,86,-9},{76,87,-9},{76,89,-8},
++ {76,102,-4},{76,116,-4},{76,118,-5},{76,119,-5},{76,121,-5},{76,133,-9},{79,74,4},{79,89,-4},
++ {80,44,-7},{80,45,-6},{80,46,-7},{80,65,-9},{80,74,-5},{80,88,-6},{80,89,-6},{80,99,-6},
++ {80,100,-6},{80,101,-6},{80,111,-6},{81,65,-4},{81,74,4},{81,86,-6},{81,87,-6},{81,88,-6},
++ {81,89,-11},{82,65,7},{82,89,-5},{83,84,-4},{83,88,-7},{83,89,-4},{84,44,-12},{84,45,-19},
++ {84,46,-12},{84,65,-15},{84,67,-10},{84,71,-10},{84,74,-8},{84,79,-10},{84,81,-10},{84,97,-6},
++ {84,99,-19},{84,100,-19},{84,101,-19},{84,103,-15},{84,109,-14},{84,110,-14},{84,111,-19},{84,112,-14},
++ {84,113,-15},{84,114,-14},{84,115,-14},{84,117,-11},{84,118,-11},{84,119,-11},{84,120,-13},{84,121,-11},
++ {86,44,-15},{86,45,-14},{86,46,-15},{86,65,-25},{86,67,-7},{86,71,-7},{86,74,-8},{86,75,-6},
++ {86,79,-7},{86,81,-7},{86,97,-13},{86,99,-14},{86,100,-14},{86,101,-14},{86,103,-12},{86,111,-14},
++ {86,113,-12},{86,115,-8},{87,44,-15},{87,45,-14},{87,46,-15},{87,65,-25},{87,67,-7},{87,71,-7},
++ {87,74,-8},{87,75,-6},{87,79,-7},{87,81,-7},{87,97,-13},{87,99,-14},{87,100,-14},{87,101,-14},
++ {87,103,-12},{87,111,-14},{87,113,-12},{87,115,-8},{88,45,-6},{88,67,-5},{88,71,-5},{88,79,-5},
++ {88,81,-5},{88,83,-6},{88,99,-6},{88,100,-6},{88,101,-6},{88,103,-7},{88,111,-6},{88,113,-7},
++ {88,118,-6},{88,119,-6},{88,121,-6},{89,44,-23},{89,45,-17},{89,46,-23},{89,65,-25},{89,67,-7},
++ {89,71,-7},{89,74,-11},{89,79,-7},{89,81,-7},{89,83,-5},{89,97,-13},{89,99,-17},{89,100,-17},
++ {89,101,-17},{89,102,-8},{89,103,-20},{89,109,-13},{89,110,-13},{89,111,-17},{89,112,-13},{89,113,-20},
++ {89,114,-13},{89,115,-9},{89,116,-8},{89,117,-8},{89,118,-9},{89,119,-9},{89,120,-8},{89,121,-9},
++ {89,122,-5},{97,39,-7},{97,84,-6},{97,89,-7},{98,39,-8},{98,44,-4},{98,46,-4},{98,118,-4},
++ {98,119,-4},{98,121,-4},{99,39,-5},{99,44,-7},{99,46,-7},{101,39,-7},{101,44,-5},{101,46,-5},
++ {101,118,-5},{101,119,-5},{101,120,-5},{101,121,-5},{101,133,-5},{102,44,-13},{102,45,-10},{102,46,-13},
++ {102,97,-4},{102,99,-10},{102,100,-10},{102,101,-10},{102,103,-9},{102,111,-10},{102,113,-9},{102,115,-4},
++ {102,133,4},{104,39,-8},{104,44,-4},{104,46,-4},{104,118,-4},{104,119,-4},{104,121,-4},{107,45,-7},
++ {107,99,-7},{107,100,-7},{107,101,-7},{107,103,-5},{107,111,-7},{107,113,-5},{109,39,-8},{109,44,-4},
++ {109,46,-4},{109,118,-4},{109,119,-4},{109,121,-4},{110,39,-8},{110,44,-4},{110,46,-4},{110,118,-4},
++ {110,119,-4},{110,121,-4},{111,39,-5},{111,55,-13},{111,84,-11},{111,118,-6},{111,119,-6},{111,120,-4},
++ {111,121,-6},{111,133,-6},{112,39,-8},{112,44,-4},{112,46,-4},{112,118,-4},{112,119,-4},{112,121,-4},
++ {114,39,7},{114,44,-9},{114,46,-9},{114,103,-4},{114,113,-4},{114,118,6},{114,119,6},{114,121,6},
++ {114,133,13},{115,39,-6},{115,118,-8},{115,119,-8},{115,121,-8},{115,133,-5},{118,44,-10},{118,45,-6},
++ {118,46,-10},{118,97,-4},{118,99,-6},{118,100,-6},{118,101,-6},{118,103,-7},{118,111,-6},{118,113,-7},
++ {118,115,-8},{118,133,13},{119,44,-10},{119,45,-6},{119,46,-10},{119,97,-4},{119,99,-6},{119,100,-6},
++ {119,101,-6},{119,103,-7},{119,111,-6},{119,113,-7},{119,115,-8},{119,133,13},{120,45,-7},{120,99,-7},
++ {120,100,-7},{120,101,-7},{120,103,-4},{120,111,-7},{120,113,-4},{121,44,-10},{121,45,-6},{121,46,-10},
++ {121,97,-4},{121,99,-6},{121,100,-6},{121,101,-6},{121,103,-7},{121,111,-6},{121,113,-7},{121,115,-8},
++ {121,133,13},{133,45,-20},{133,65,-16},{133,97,-6},{133,99,-20},{133,100,-20},{133,101,-20},{133,103,-17},
++ {133,111,-20},{133,113,-17},{133,115,-16},
++};
++const struct fos_font fos_font_sm_data = { sm_bits, sm_glyphs, sm_lut, sm_kern, 427, 16, 4 };
++
++static const uint8_t md_bits[] = {
++ 129,9,15,4,131,9,15,4,131,9,15,3,131,9,15,3,131,9,15,3,131,8,15,2,
++ 131,8,15,2,131,8,15,2,131,7,15,1,146,1,132,13,15,5,131,11,14,4,129,7,
++ 15,21,15,23,15,4,5,15,22,15,3,4,15,21,15,2,3,15,4,187,131,5,8,1,
++ 129,6,7,133,14,15,129,1,15,13,132,2,15,12,129,4,15,10,131,127,31,1,129,9,
++ 12,15,12,25,13,15,11,9,1,130,9,15,5,129,12,15,2,132,11,15,3,129,14,15,
++ 1,132,13,15,1,128,1,15,14,131,11,127,15,5,129,6,11,15,13,25,11,15,12,9,
++ 3,130,5,15,9,129,7,15,6,132,8,15,6,129,10,15,4,132,10,15,4,129,12,15,
++ 2,130,131,4,15,6,134,1,7,15,9,1,132,8,79,9,1,129,6,15,10,2,1,3,
++ 10,15,9,129,11,15,1,131,13,15,1,128,12,15,1,131,9,14,2,128,8,15,11,2,
++ 134,1,12,31,10,4,133,1,7,14,31,12,4,134,5,12,31,6,135,5,31,17,15,11,
++ 132,9,15,4,128,30,1,131,10,15,2,128,9,15,11,3,17,6,15,12,129,1,10,79,
++ 12,2,131,2,8,15,11,4,134,3,15,7,131,129,2,11,14,13,4,131,11,10,132,1,
++ 13,14,10,12,15,3,129,4,15,2,132,4,14,1,129,12,8,129,12,9,133,4,14,1,
++ 129,12,8,128,6,14,1,133,1,13,14,10,12,15,3,1,13,7,135,2,11,15,13,4,
++ 128,7,13,141,1,14,5,141,9,12,141,3,15,4,128,1,7,9,5,136,27,128,2,14,
++ 47,8,134,4,15,2,128,9,12,2,1,7,15,1,133,12,9,129,10,9,129,2,15,3,
++ 132,6,14,1,129,5,15,11,10,14,12,133,13,7,131,6,13,14,11,2,129,130,6,13,
++ 15,13,9,1,134,7,15,14,10,12,15,12,134,14,15,2,129,11,15,4,133,14,15,130,
++ 9,15,5,133,9,15,7,128,3,15,14,1,133,1,13,15,8,14,15,6,135,6,31,14,
++ 5,135,5,47,13,2,134,5,15,14,5,7,15,12,1,128,22,130,13,15,4,129,8,15,
++ 11,4,15,12,130,15,14,131,9,31,14,3,130,14,15,2,130,6,31,9,131,8,15,14,
++ 26,13,15,14,13,15,4,131,6,12,14,15,12,8,1,2,30,2,128,7,15,6,7,15,
++ 5,6,15,21,15,3,157,129,1,13,14,1,130,7,15,8,131,14,15,2,130,4,15,12,
++ 131,9,15,8,131,12,15,5,131,14,15,3,131,31,2,130,1,31,2,131,31,2,131,14,
++ 15,3,131,12,15,5,131,9,15,8,131,5,15,12,132,14,15,2,131,8,15,8,131,1,
++ 13,14,1,128,128,2,15,11,131,10,15,5,130,5,15,12,131,14,15,2,130,11,15,6,
++ 130,8,15,9,130,6,15,12,130,5,15,13,130,4,15,13,130,5,15,13,130,6,15,12,
++ 130,8,15,9,130,11,15,6,129,1,14,15,2,129,5,15,11,130,11,15,5,129,2,15,
++ 11,129,130,9,8,130,2,8,1,9,8,1,8,1,3,12,14,28,14,12,2,129,9,31,
++ 8,129,2,11,14,29,14,11,18,8,1,9,8,1,9,2,130,9,8,194,131,13,11,135,
++ 13,12,135,13,12,131,4,127,3,2,41,30,41,2,131,13,12,135,13,12,135,13,11,151,
++ 128,1,15,9,129,4,15,5,129,7,15,1,129,9,13,130,12,8,129,2,89,2,4,95,
++ 4,167,129,2,131,6,15,12,130,5,14,10,129,132,12,15,1,132,3,15,11,133,8,15,
++ 6,133,13,15,1,132,3,15,11,133,9,15,5,133,14,15,1,132,4,15,10,133,9,15,
++ 5,133,30,1,132,4,15,10,133,10,15,4,133,30,133,5,15,9,133,129,1,9,13,15,
++ 14,10,3,130,1,13,15,13,10,12,31,3,129,7,15,10,130,6,15,12,129,11,15,4,
++ 131,14,15,129,11,15,2,131,13,15,1,128,12,15,2,131,13,15,1,128,12,15,2,131,
++ 13,15,1,128,12,15,2,131,13,15,1,128,12,15,2,131,13,15,1,128,11,15,2,131,
++ 13,15,1,128,11,15,4,131,14,15,129,7,15,10,130,6,15,12,129,1,13,15,13,10,
++ 12,31,3,130,1,9,13,15,14,10,3,129,128,1,7,14,15,6,129,14,47,7,129,9,
++ 5,8,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,
++ 131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,7,131,7,15,6,
++ 128,129,3,10,14,15,12,7,131,3,31,11,10,14,15,10,130,11,15,6,129,1,13,15,
++ 4,129,14,15,131,8,15,7,129,23,131,10,15,5,134,2,15,14,1,134,12,15,7,134,
++ 9,15,11,134,7,15,13,1,133,5,15,14,3,133,3,14,15,4,133,2,14,15,6,134,
++ 12,15,14,73,8,129,14,111,13,128,128,14,111,3,128,8,57,12,31,2,132,4,14,15,
++ 7,132,3,14,15,8,132,2,14,15,9,133,11,31,11,5,132,3,8,7,13,15,7,134,
++ 1,30,1,134,10,15,4,1,7,6,131,9,15,5,1,15,14,131,11,15,4,128,11,15,
++ 6,129,3,15,14,129,3,14,15,11,10,14,15,6,130,3,10,30,12,5,129,131,5,15,
++ 10,135,12,15,4,134,4,15,12,135,11,15,5,134,3,15,13,135,10,15,6,134,2,15,
++ 13,130,12,15,2,129,9,15,7,130,12,15,2,128,1,31,59,14,15,11,3,2,127,15,
++ 4,134,12,15,2,135,12,15,2,135,12,15,2,135,11,15,2,128,128,12,111,1,128,13,
++ 15,10,73,129,13,15,1,134,13,15,1,134,13,15,1,134,13,15,2,6,9,7,3,130,
++ 13,15,14,63,7,129,13,15,11,2,128,4,14,15,2,128,5,6,1,130,8,15,6,134,
++ 6,15,8,128,8,11,2,130,7,15,7,128,8,15,9,129,1,13,15,4,128,1,13,15,
++ 12,10,13,15,10,130,2,9,13,14,13,7,129,129,2,10,13,15,12,7,130,3,31,12,
++ 10,14,15,9,129,10,15,7,129,2,14,15,2,128,13,15,2,130,10,15,4,128,13,15,
++ 1,130,17,129,13,15,1,6,9,8,3,130,13,15,13,63,7,129,13,15,12,3,128,5,
++ 31,2,128,13,15,4,130,8,15,7,128,13,15,1,130,6,15,8,128,12,15,2,130,7,
++ 15,7,128,8,15,8,129,1,13,15,4,128,1,13,15,12,10,13,15,10,130,2,9,13,
++ 15,13,8,129,5,127,3,6,15,10,57,14,15,3,4,11,2,130,2,15,13,134,8,15,
++ 8,134,13,15,2,133,4,15,12,134,10,15,6,133,1,14,15,1,133,6,15,10,134,12,
++ 15,4,133,2,15,14,134,8,15,8,134,13,15,3,133,4,15,12,132,129,1,9,14,15,
++ 12,6,131,1,13,15,12,10,14,15,7,130,7,15,9,129,2,30,1,129,11,15,3,130,
++ 10,15,3,129,10,15,4,130,11,15,3,129,5,15,12,3,1,7,15,13,131,9,63,14,
++ 2,130,2,13,15,11,10,14,15,8,130,10,15,6,129,1,13,15,3,129,14,15,131,7,
++ 15,7,129,14,15,131,8,15,7,129,11,15,7,129,1,13,15,3,129,3,31,11,10,14,
++ 15,10,131,3,10,14,15,13,7,130,129,3,11,30,12,5,131,3,14,15,11,10,14,15,
++ 6,130,11,15,6,129,2,30,1,129,15,14,131,10,15,4,128,1,15,13,131,9,15,5,
++ 129,15,14,131,10,15,5,129,11,15,6,129,2,14,15,5,129,4,31,11,10,14,31,5,
++ 130,4,12,14,13,25,15,5,135,8,15,5,129,9,12,2,130,9,15,5,129,10,15,7,
++ 129,1,13,15,3,129,3,31,11,10,14,15,10,131,3,11,30,12,7,130,130,2,132,10,
++ 15,8,131,8,14,7,160,2,132,10,15,8,131,8,14,7,129,129,9,11,2,129,3,31,
++ 9,129,1,12,14,4,148,10,15,1,130,12,13,131,14,9,130,1,15,6,130,2,15,3,
++ 129,144,6,13,3,131,1,7,14,15,14,2,129,2,8,14,15,13,7,1,128,1,10,31,
++ 11,5,131,4,15,14,4,133,2,12,15,14,9,3,133,4,11,31,11,4,133,2,9,31,
++ 13,2,133,2,8,14,3,135,1,128,3,125,2,4,127,3,147,3,125,2,4,127,3,157,
++ 137,4,12,5,134,3,31,13,6,1,132,1,8,14,15,14,8,1,133,6,12,31,9,1,
++ 133,5,31,3,131,3,10,31,11,1,129,5,12,31,10,3,129,3,13,15,14,9,2,131,
++ 4,14,7,1,133,1,136,129,5,12,30,11,3,130,7,15,14,10,11,31,3,128,1,15,
++ 14,2,129,6,15,11,128,4,15,10,130,1,15,13,128,1,6,4,130,4,15,12,133,2,
++ 13,15,6,132,3,14,15,10,132,2,14,15,7,133,7,15,9,134,8,15,7,134,1,3,
++ 1,135,2,135,10,15,8,134,9,14,6,131,132,3,8,12,30,13,8,2,133,1,9,31,
++ 12,26,12,31,6,131,1,12,15,7,1,131,2,11,15,4,130,10,14,3,128,2,24,2,
++ 9,1,128,28,129,3,15,5,128,3,14,31,14,15,1,128,4,15,2,128,9,13,129,11,
++ 13,2,1,12,14,129,1,15,4,128,12,9,129,14,6,129,8,12,129,1,15,5,128,14,
++ 7,128,2,15,3,129,26,129,4,15,2,128,13,8,128,3,15,4,128,2,14,11,129,11,
++ 13,129,27,129,14,13,10,13,14,15,11,12,15,6,129,6,15,4,128,4,12,15,10,1,
++ 9,14,13,7,131,12,14,5,132,1,134,2,13,15,13,10,9,10,12,15,4,134,1,7,
++ 12,14,15,13,10,5,132,131,1,31,9,136,6,31,14,136,11,15,13,15,4,134,1,15,
++ 14,5,15,9,134,5,15,9,1,15,14,134,10,15,4,128,11,15,4,132,1,30,129,6,
++ 15,9,132,5,15,10,129,2,15,13,132,10,15,5,130,12,15,3,131,14,15,1,130,7,
++ 15,8,130,4,127,13,130,9,15,10,72,13,15,3,129,14,15,2,132,8,15,8,128,4,
++ 15,12,133,3,15,12,128,128,5,79,13,11,4,130,5,15,13,41,12,31,5,129,5,15,
++ 8,131,6,15,13,129,5,15,8,132,14,15,129,5,15,8,132,30,129,5,15,8,131,5,
++ 15,8,129,5,15,12,41,11,15,8,130,5,111,13,3,129,5,15,8,130,2,9,15,13,
++ 129,5,15,8,132,13,15,2,128,5,15,8,132,12,15,3,128,5,15,8,131,3,15,14,
++ 1,128,5,15,12,41,11,31,7,129,5,79,14,11,4,129,130,5,11,30,12,7,1,131,
++ 9,15,14,11,10,13,15,13,1,129,4,15,13,2,130,10,15,9,129,9,15,5,131,1,
++ 15,13,129,11,15,3,132,8,9,129,11,15,3,136,11,15,3,136,11,15,3,136,11,15,
++ 3,136,11,15,3,132,24,129,9,15,5,131,1,15,13,129,4,15,13,2,130,10,15,9,
++ 130,9,15,14,11,10,13,15,12,1,131,5,11,30,12,7,1,129,128,5,79,14,11,4,
++ 130,5,15,13,41,11,31,5,129,5,15,8,131,5,15,14,129,5,15,8,132,12,15,3,
++ 128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,
++ 128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,128,5,15,8,132,10,15,4,
++ 128,5,15,8,132,12,15,3,128,5,15,8,131,5,15,14,129,5,15,12,41,11,31,5,
++ 129,5,79,14,11,4,129,128,5,127,14,129,5,15,13,89,8,129,5,15,8,136,5,15,
++ 8,136,5,15,8,136,5,15,8,136,5,15,12,57,6,131,5,95,11,131,5,15,8,136,
++ 5,15,8,136,5,15,8,136,5,15,8,136,5,15,12,89,8,129,5,127,14,128,128,5,
++ 127,14,128,5,15,13,89,8,128,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,
++ 135,5,15,12,57,6,130,5,95,10,130,5,15,8,135,5,15,8,135,5,15,8,135,5,
++ 15,8,135,5,15,8,135,5,15,8,134,130,5,11,30,12,7,132,9,15,14,11,10,14,
++ 15,12,1,129,4,15,13,2,129,1,11,15,8,129,9,15,5,131,2,15,13,129,11,15,
++ 3,132,28,129,11,15,3,136,11,15,3,136,11,15,3,129,13,63,129,11,15,3,129,8,
++ 25,31,129,11,15,3,132,14,15,129,9,15,6,132,15,14,129,4,15,13,2,130,8,15,
++ 9,130,9,15,14,11,10,13,15,13,2,131,5,11,14,15,13,8,1,129,128,5,15,8,
++ 132,8,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,
++ 132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,12,
++ 73,13,15,5,129,5,127,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,
++ 5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,5,129,5,15,8,132,9,15,
++ 5,129,5,15,8,132,8,15,5,128,128,5,15,8,129,5,15,8,129,5,15,8,129,5,
++ 15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,
++ 15,8,129,5,15,8,129,5,15,8,129,5,15,8,129,5,15,8,128,135,30,137,15,14,
++ 137,15,14,137,15,14,137,15,14,137,15,14,137,15,14,137,15,14,129,6,13,5,132,15,
++ 14,129,7,15,6,132,15,14,129,6,15,8,131,2,15,13,129,2,15,14,2,130,10,15,
++ 8,130,7,31,11,10,13,15,13,1,131,5,11,14,15,13,8,1,130,128,5,15,8,131,
++ 1,13,15,4,128,5,15,8,130,1,12,15,6,129,5,15,8,130,11,15,9,130,5,15,
++ 8,129,9,15,11,131,5,15,8,128,7,15,12,1,131,5,15,8,6,15,14,2,132,5,
++ 15,12,31,14,2,132,5,31,14,10,15,10,132,5,31,4,128,12,15,5,131,5,15,9,
++ 129,3,15,14,1,130,5,15,8,130,8,15,10,130,5,15,8,131,12,15,5,129,5,15,
++ 8,131,3,15,14,1,128,5,15,8,132,8,15,9,128,5,15,8,135,5,15,8,135,5,
++ 15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,
++ 15,8,135,5,15,8,135,5,15,8,135,5,15,8,135,5,15,13,90,7,128,5,127,11,
++ 128,5,15,12,133,8,15,10,129,5,31,8,131,3,31,10,129,5,47,3,130,13,31,10,
++ 129,5,15,14,15,12,129,8,15,13,15,10,129,5,15,8,11,15,8,3,15,14,5,15,
++ 10,129,5,15,8,2,14,15,13,15,5,4,15,10,129,5,15,8,128,6,31,10,128,4,
++ 15,10,129,5,15,8,129,10,14,1,128,4,15,10,129,5,15,8,133,4,15,10,129,5,
++ 15,8,133,4,15,10,129,5,15,8,133,4,15,10,129,5,15,8,133,4,15,10,129,5,
++ 15,8,133,4,15,10,129,5,15,8,133,4,15,10,128,128,5,15,11,132,2,15,12,129,
++ 5,31,6,131,2,15,12,129,5,31,14,1,130,2,15,12,129,5,15,14,15,9,130,2,
++ 15,12,129,5,15,9,12,15,3,129,2,15,12,129,5,15,8,4,15,12,129,2,15,12,
++ 129,5,15,8,128,9,15,7,128,2,15,12,129,5,15,8,128,1,30,18,15,12,129,5,
++ 15,8,129,6,15,10,2,15,12,129,5,15,8,130,12,15,6,15,12,129,5,15,8,130,
++ 3,15,14,15,12,129,5,15,8,131,8,31,12,129,5,15,8,131,1,13,15,12,129,5,
++ 15,8,132,5,15,12,128,130,5,11,30,13,8,1,131,8,31,11,10,13,15,13,1,129,
++ 3,15,14,2,130,9,15,9,129,9,15,6,131,1,14,15,129,11,15,3,132,12,15,2,
++ 128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,
++ 128,11,15,3,132,12,15,2,128,11,15,3,132,12,15,2,128,9,15,6,131,1,14,15,
++ 129,3,15,14,2,130,9,15,9,130,8,31,11,10,13,15,13,1,131,5,11,14,15,13,
++ 8,1,129,128,7,79,14,12,5,130,7,15,12,41,11,31,6,129,7,15,7,131,4,15,
++ 14,129,7,15,7,132,12,15,2,128,7,15,7,132,12,15,2,128,7,15,7,131,4,15,
++ 14,129,7,15,12,41,11,31,6,129,7,79,14,11,5,130,7,15,7,136,7,15,7,136,
++ 7,15,7,136,7,15,7,136,7,15,7,136,7,15,6,135,130,7,12,30,11,4,132,12,
++ 15,13,10,11,31,7,130,7,15,10,1,129,2,14,15,2,129,12,15,2,131,7,15,7,
++ 129,14,15,132,5,15,9,129,30,132,5,15,9,129,30,132,5,15,9,129,30,132,5,15,
++ 9,129,30,132,5,15,9,129,14,15,132,6,15,9,129,12,15,4,131,10,15,7,129,6,
++ 15,14,5,1,2,8,31,2,130,10,95,5,132,5,10,15,14,8,2,134,2,15,12,136,
++ 2,15,11,132,128,5,79,14,12,5,130,5,15,13,41,11,31,6,129,5,15,8,131,3,
++ 15,14,129,5,15,8,132,12,15,3,128,5,15,8,132,12,15,3,128,5,15,8,131,3,
++ 15,14,129,5,15,12,41,10,31,6,129,5,95,13,5,130,5,15,8,129,3,15,11,131,
++ 5,15,8,130,10,15,3,130,5,15,8,130,3,15,11,130,5,15,8,131,11,15,3,129,
++ 5,15,8,131,4,15,11,129,5,15,8,132,11,15,3,129,2,9,13,30,11,6,131,2,
++ 14,15,12,10,11,14,15,10,130,9,15,7,130,1,12,15,6,129,12,15,2,131,5,15,
++ 9,129,10,15,6,131,1,7,5,129,3,31,9,3,135,3,12,31,12,6,135,4,10,31,
++ 13,5,135,1,8,31,4,129,8,6,132,6,15,10,129,15,13,132,3,15,11,129,12,15,
++ 7,131,9,15,9,129,3,14,15,13,26,13,15,13,1,130,2,9,13,30,12,7,1,129,
++ 3,127,15,11,2,41,11,15,13,41,6,131,4,15,9,135,4,15,9,135,4,15,9,135,
++ 4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,4,15,9,135,
++ 4,15,9,135,4,15,9,135,4,15,9,131,128,7,15,6,132,9,15,4,129,8,15,6,
++ 132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,
++ 132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,132,9,15,5,129,8,15,6,
++ 132,9,15,5,129,8,15,6,132,9,15,5,129,7,15,7,132,9,15,4,129,5,15,9,
++ 132,12,15,3,129,1,14,15,4,130,6,15,13,131,5,31,12,10,12,15,14,3,132,3,
++ 10,14,15,13,9,2,130,4,15,12,133,10,15,4,128,14,15,1,131,1,30,129,9,15,
++ 6,131,4,15,10,129,5,15,10,131,9,15,5,129,1,30,131,13,14,1,130,10,15,4,
++ 129,3,15,10,131,6,15,9,129,7,15,6,131,1,15,13,129,12,15,1,132,11,15,3,
++ 1,15,11,133,6,15,7,6,15,6,133,2,15,12,10,15,2,134,12,31,12,135,7,31,
++ 7,135,2,31,2,131,6,15,9,131,5,15,12,132,30,128,2,15,13,131,9,31,2,130,
++ 4,15,10,129,13,15,2,130,13,31,6,130,8,15,6,129,9,15,6,129,1,15,14,15,
++ 9,130,12,15,2,129,5,15,10,129,5,15,7,14,13,129,1,15,13,130,1,15,14,129,
++ 9,15,3,11,15,2,128,5,15,9,131,11,15,3,128,12,14,128,7,15,6,128,9,15,
++ 5,131,7,15,7,1,15,11,128,3,15,10,128,13,15,1,131,3,15,11,5,15,7,129,
++ 30,2,15,12,133,30,9,15,4,129,10,15,9,15,8,133,10,47,130,6,47,4,133,6,
++ 31,11,130,3,47,1,133,1,31,8,131,14,15,11,135,12,15,4,131,10,15,7,131,2,
++ 15,14,1,131,1,13,15,3,128,8,15,9,131,8,15,9,130,13,15,3,129,2,15,14,
++ 1,130,4,15,12,129,11,15,5,132,10,15,6,5,15,11,133,2,30,13,15,2,134,7,
++ 31,8,135,6,31,7,134,1,46,15,2,133,10,15,6,5,15,11,132,4,15,12,129,11,
++ 15,5,131,13,15,3,129,2,15,13,1,129,8,15,9,131,8,15,8,128,2,15,14,1,
++ 131,1,13,15,3,2,15,13,132,3,15,13,129,9,15,6,131,11,15,5,129,2,15,14,
++ 1,129,4,15,12,131,9,15,7,129,12,15,4,131,1,30,1,5,15,11,133,8,15,8,
++ 12,15,3,133,1,14,31,10,135,7,31,2,135,2,15,12,136,2,15,12,136,2,15,12,
++ 136,2,15,12,136,2,15,12,136,2,15,12,132,3,127,15,17,89,10,31,1,134,10,15,
++ 8,134,5,15,12,134,1,14,15,3,134,10,15,8,134,5,15,13,134,1,14,15,3,134,
++ 10,15,8,134,4,15,13,1,133,1,13,15,4,134,9,15,9,134,2,31,10,89,1,3,
++ 127,15,1,3,57,2,129,5,63,4,129,5,15,9,132,5,15,9,132,5,15,9,132,5,
++ 15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,
++ 15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,9,132,5,15,13,25,2,
++ 129,5,63,4,129,128,8,15,5,133,3,15,10,134,13,15,1,133,8,15,6,133,3,15,
++ 11,134,13,15,1,133,7,15,6,133,2,15,12,134,12,15,2,133,7,15,7,133,2,15,
++ 12,134,11,15,2,133,6,15,7,133,1,15,12,128,129,4,57,2,129,6,63,3,132,11,
++ 15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,
++ 15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,15,3,132,11,
++ 15,3,132,11,15,3,129,4,25,13,15,3,129,6,63,3,130,2,8,3,133,10,15,12,
++ 132,1,15,13,15,3,131,7,15,2,14,9,131,13,11,128,9,14,1,129,4,15,5,128,
++ 3,15,7,129,11,14,130,12,13,128,2,15,8,130,6,15,4,181,4,121,4,7,127,6,
++ 2,8,3,129,12,13,129,3,15,6,171,129,4,11,30,12,6,130,6,31,11,10,14,15,
++ 8,129,10,14,5,129,1,14,15,1,134,12,15,2,128,1,7,12,14,63,2,128,11,15,
++ 14,10,25,14,15,18,15,13,1,130,12,15,18,15,12,130,3,31,2,128,13,15,12,10,
++ 11,47,2,128,2,10,14,15,12,5,11,15,2,128,8,15,5,135,9,15,5,135,9,15,
++ 5,135,9,15,5,135,9,15,7,10,30,10,2,130,9,31,14,10,13,15,13,1,129,9,
++ 15,14,1,129,11,15,8,129,9,15,8,130,3,15,12,129,9,15,6,130,1,15,14,129,
++ 9,15,6,130,1,15,14,129,9,15,8,130,3,15,12,129,9,15,14,1,129,10,15,7,
++ 129,9,31,13,10,12,15,13,1,129,8,15,6,10,15,14,10,2,129,129,1,8,13,15,
++ 13,8,1,130,1,13,15,12,10,13,15,13,1,129,7,15,9,130,9,15,8,129,12,15,
++ 3,130,2,8,4,129,13,15,1,135,13,15,1,135,12,15,3,130,2,7,3,129,7,15,
++ 9,130,10,15,7,129,1,12,15,12,10,13,15,13,1,130,1,8,13,15,13,8,1,129,
++ 134,4,15,9,135,4,15,10,135,4,15,10,135,4,15,10,130,2,9,13,15,11,6,15,
++ 10,129,1,13,15,13,10,13,31,10,129,7,15,11,129,1,13,15,10,129,11,15,4,130,
++ 7,15,10,129,13,15,2,130,5,15,10,129,13,15,2,130,5,15,10,129,11,15,4,130,
++ 7,15,10,129,6,15,10,129,1,13,15,10,129,1,13,15,12,10,13,31,10,130,1,9,
++ 30,11,6,15,9,128,129,1,9,13,15,14,9,1,130,1,13,15,12,10,13,15,12,130,
++ 8,15,8,130,10,15,5,129,12,15,2,130,4,15,9,129,13,111,10,129,13,15,89,6,
++ 129,11,15,2,135,6,15,9,130,4,11,2,130,12,15,13,10,11,15,14,3,130,1,8,
++ 13,15,14,9,2,129,130,9,13,15,8,129,7,15,14,10,5,129,10,15,5,131,11,15,
++ 3,129,5,79,8,3,9,14,15,10,9,5,129,12,15,2,131,12,15,2,131,12,15,2,
++ 131,12,15,2,131,12,15,2,131,12,15,2,131,12,15,2,131,11,15,2,129,129,2,10,
++ 30,10,7,15,8,129,2,14,15,12,10,13,31,9,129,9,15,9,129,1,12,15,9,129,
++ 13,15,2,130,7,15,9,129,14,15,131,5,15,9,129,14,15,131,5,15,9,129,13,15,
++ 2,130,6,15,9,129,9,15,9,130,12,15,9,129,2,14,15,12,10,13,31,9,130,2,
++ 10,30,11,8,15,9,135,8,15,7,134,2,14,15,4,131,6,9,11,31,10,132,9,15,
++ 14,11,6,130,128,9,15,4,135,9,15,5,135,9,15,5,135,9,15,5,135,9,15,7,
++ 11,30,10,2,130,9,31,13,10,13,15,13,1,129,9,15,11,129,1,12,15,5,129,9,
++ 15,5,130,7,15,7,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,
++ 15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,
++ 15,4,130,6,15,7,128,128,7,14,8,129,8,15,10,130,2,135,6,15,7,129,7,15,
++ 7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,7,129,7,15,
++ 7,129,7,15,7,129,6,15,7,128,129,8,14,6,130,10,15,8,131,2,137,8,15,5,
++ 130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,6,
++ 130,8,15,6,130,8,15,6,130,8,15,6,130,8,15,5,130,12,15,4,128,8,13,15,
++ 14,129,13,14,10,2,129,128,9,15,4,134,9,15,5,134,9,15,5,134,9,15,5,134,
++ 9,15,5,129,4,15,14,1,128,9,15,5,128,3,30,3,129,9,15,5,2,14,15,5,
++ 130,9,15,6,13,15,12,131,9,47,13,15,3,130,9,31,5,4,15,10,130,9,15,7,
++ 129,12,15,2,129,9,15,5,129,5,15,9,129,9,15,5,130,13,15,2,128,9,15,4,
++ 130,6,15,8,128,9,15,4,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,
++ 129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,129,9,15,5,
++ 129,9,15,5,129,9,15,5,129,9,15,4,128,128,9,15,6,10,30,10,2,3,11,30,
++ 10,1,130,9,31,12,10,14,15,13,14,12,10,14,15,11,130,9,15,10,129,1,14,15,
++ 10,129,1,14,15,2,129,9,15,5,130,10,15,5,130,10,15,4,129,9,15,5,130,10,
++ 15,4,130,10,15,4,129,9,15,5,130,10,15,4,130,10,15,4,129,9,15,5,130,10,
++ 15,4,130,10,15,4,129,9,15,5,130,10,15,4,130,10,15,4,129,9,15,5,130,10,
++ 15,4,130,10,15,4,129,9,15,4,130,9,15,4,130,9,15,4,128,128,9,15,7,11,
++ 30,10,2,130,9,31,13,10,13,15,13,1,129,9,15,11,129,1,12,15,5,129,9,15,
++ 5,130,7,15,7,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,
++ 5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,5,130,6,15,8,129,9,15,
++ 4,130,6,15,7,128,129,1,8,13,15,13,8,1,130,1,12,15,13,10,12,15,12,1,
++ 129,7,15,10,130,9,15,8,129,12,15,3,130,2,15,12,129,13,15,1,131,15,14,129,
++ 13,15,1,131,15,14,129,11,15,3,130,2,15,12,129,7,15,10,130,9,15,8,129,1,
++ 12,15,13,10,12,15,13,1,130,1,8,13,15,13,9,1,129,128,7,15,8,10,30,10,
++ 2,130,7,31,14,10,11,15,14,2,129,7,15,14,2,129,8,15,9,129,7,15,10,130,
++ 2,15,13,129,7,15,7,131,14,15,129,7,15,7,131,14,15,129,7,15,10,130,2,15,
++ 14,129,7,15,14,2,129,10,15,9,129,7,31,14,10,12,15,14,2,129,7,15,8,10,
++ 30,10,3,130,7,15,7,135,7,15,7,135,7,15,7,135,7,15,6,134,129,1,9,13,
++ 15,11,6,15,9,129,1,13,15,12,10,13,31,10,129,6,15,10,129,1,13,15,10,129,
++ 11,15,4,130,7,15,10,129,13,15,2,130,5,15,10,129,13,15,2,130,5,15,10,129,
++ 11,15,4,130,7,15,10,129,7,15,11,129,1,13,15,10,129,1,13,15,13,10,13,31,
++ 10,130,2,10,30,11,6,15,10,135,4,15,10,135,4,15,10,135,4,15,10,135,4,15,
++ 9,128,128,9,15,6,10,14,13,1,128,9,31,13,10,9,129,9,15,11,132,9,15,6,
++ 132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,5,132,9,15,4,
++ 131,129,7,12,30,11,4,130,9,15,14,26,14,15,5,129,30,1,129,3,15,11,129,12,
++ 15,5,130,17,129,3,12,15,14,10,5,1,132,5,9,14,15,13,3,129,18,130,6,15,
++ 11,129,15,14,1,129,3,15,13,129,9,15,14,26,14,15,8,130,7,12,30,12,6,129,
++ 129,6,7,132,13,15,132,13,15,130,5,79,6,3,9,14,15,25,4,129,13,15,132,13,
++ 15,132,13,15,132,13,15,132,13,15,132,13,15,2,131,10,15,13,9,3,129,2,11,14,
++ 15,4,128,11,15,2,130,8,15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,
++ 15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,15,5,129,11,15,2,130,8,
++ 15,5,129,11,15,3,130,9,15,5,129,10,15,8,129,1,13,15,5,129,3,31,12,10,
++ 14,31,5,130,4,11,30,10,9,15,5,128,5,15,11,131,14,15,2,1,14,15,1,129,
++ 4,15,12,129,10,15,6,129,8,15,7,129,5,15,10,129,13,15,2,130,30,1,3,15,
++ 12,131,9,15,5,7,15,7,131,4,15,9,12,15,2,132,30,15,12,133,9,31,7,133,
++ 4,31,2,130,5,15,9,130,9,15,5,130,11,15,3,1,15,13,130,14,15,10,129,1,
++ 15,13,129,11,15,2,128,3,31,14,129,5,15,9,129,7,15,6,128,7,15,12,15,3,
++ 128,9,15,4,129,2,15,10,128,11,14,4,15,7,128,13,14,131,13,14,1,14,10,128,
++ 14,11,2,15,10,131,8,15,7,15,6,128,9,15,7,15,6,131,4,15,14,15,2,128,
++ 5,15,14,15,1,132,14,15,12,129,1,31,12,133,10,15,8,130,11,15,7,130,4,15,
++ 12,130,1,13,15,4,128,9,15,7,129,9,15,8,129,1,13,15,3,4,15,13,131,3,
++ 15,12,13,15,3,132,8,31,7,133,6,31,6,132,2,30,13,14,2,131,12,15,5,4,
++ 15,12,130,8,15,9,129,8,15,8,128,4,15,13,1,130,12,15,3,7,15,9,130,1,
++ 30,128,2,15,13,130,5,15,10,129,12,15,3,129,9,15,4,129,7,15,7,129,13,14,
++ 130,2,15,12,128,3,15,9,131,11,15,1,7,15,4,131,6,15,6,12,13,132,1,15,
++ 12,15,8,133,11,31,3,133,6,15,13,134,5,15,8,134,11,15,2,132,8,12,15,10,
++ 132,1,15,14,9,1,132,4,111,4,2,57,10,31,4,132,11,15,9,132,8,15,11,132,
++ 5,15,13,1,131,2,14,15,3,131,1,12,15,6,132,10,15,9,132,5,31,73,3,6,
++ 111,5,129,1,7,9,8,130,11,31,13,130,31,3,131,15,14,132,15,14,132,15,14,132,
++ 15,14,131,2,15,13,130,3,13,15,8,130,4,31,4,131,5,15,12,131,1,15,13,132,
++ 15,14,132,15,14,132,15,14,132,15,14,132,14,15,12,8,130,5,13,15,13,128,2,15,
++ 11,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,
++ 12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,12,128,2,15,
++ 12,128,2,15,12,128,2,15,12,128,2,15,11,128,3,25,5,130,5,47,5,131,9,15,
++ 8,131,5,15,9,131,5,15,9,131,5,15,9,131,5,15,9,131,4,15,11,131,1,13,
++ 15,9,131,9,15,13,130,3,15,13,1,130,5,15,9,131,5,15,9,131,5,15,9,131,
++ 5,15,9,131,6,15,9,129,3,9,14,15,7,129,5,31,11,1,129,128,1,7,9,6,
++ 1,129,5,128,1,12,47,14,10,13,15,5,1,10,5,1,4,10,30,7,168,128,17,129,
++ 13,15,5,128,12,14,4,139,129,5,9,8,2,130,9,47,14,4,128,4,15,7,1,2,
++ 28,128,7,13,130,4,15,1,6,14,2,129,8,14,128,1,13,14,10,11,15,8,129,2,
++ 11,14,13,7,201,128,8,5,130,9,3,128,1,13,15,5,128,10,15,9,129,2,13,15,
++ 12,15,9,131,2,31,11,132,10,47,5,130,10,15,9,2,13,15,5,128,1,12,9,129,
++ 2,13,6,155,2,105,20,111,7,172,2,121,41,7,128,4,127,47,12,198,128,13,14,1,
++ 3,15,9,128,8,15,3,128,12,11,169,129,2,131,17,131,2,130,6,15,12,129,1,14,
++ 15,4,129,9,15,9,129,5,14,10,129,1,12,14,3,129,8,14,7,128,128,5,13,14,
++ 7,128,1,14,47,20,63,7,1,14,47,4,128,5,13,14,7,146,129,1,13,14,1,130,
++ 9,15,5,130,5,15,9,131,12,15,1,131,5,15,9,132,9,15,5,131,1,13,14,1,
++ 142,128,1,14,13,1,132,4,15,10,133,8,15,6,132,1,30,132,8,15,6,131,4,15,
++ 10,131,1,14,13,1,146,
++};
++static const struct fos_glyph md_glyphs[] = {
++ { 0, 4, 0, 0, 0, 64 }, /* 0x20 */
++ { 0, 7, 14, 0, -14, 105 }, /* 0x21 */
++ { 47, 6, 14, 0, -14, 95 }, /* 0x22 */
++ { 68, 13, 13, 0, -13, 214 }, /* 0x23 */
++ { 170, 11, 17, 0, -15, 180 }, /* 0x24 */
++ { 277, 17, 14, 0, -14, 268 }, /* 0x25 */
++ { 405, 14, 14, 0, -14, 216 }, /* 0x26 */
++ { 523, 3, 14, 0, -14, 46 }, /* 0x27 */
++ { 535, 7, 17, -1, -15, 93 }, /* 0x28 */
++ { 604, 6, 17, 0, -15, 93 }, /* 0x29 */
++ { 674, 8, 15, 0, -15, 127 }, /* 0x2a */
++ { 716, 10, 10, 0, -10, 158 }, /* 0x2b */
++ { 744, 5, 5, 0, -3, 84 }, /* 0x2c */
++ { 763, 8, 7, 0, -7, 128 }, /* 0x2d */
++ { 770, 6, 3, 0, -2, 88 }, /* 0x2e */
++ { 781, 9, 14, 0, -14, 136 }, /* 0x2f */
++ { 835, 11, 14, 0, -14, 181 }, /* 0x30 */
++ { 948, 7, 14, 0, -14, 113 }, /* 0x31 */
++ { 1009, 11, 14, 0, -14, 174 }, /* 0x32 */
++ { 1090, 10, 14, 0, -14, 168 }, /* 0x33 */
++ { 1173, 11, 14, 0, -14, 182 }, /* 0x34 */
++ { 1242, 10, 14, 0, -14, 167 }, /* 0x35 */
++ { 1333, 10, 14, 0, -14, 167 }, /* 0x36 */
++ { 1444, 10, 14, 0, -14, 154 }, /* 0x37 */
++ { 1507, 11, 14, 0, -14, 169 }, /* 0x38 */
++ { 1618, 11, 14, 0, -14, 168 }, /* 0x39 */
++ { 1724, 7, 10, 0, -9, 111 }, /* 0x3a */
++ { 1745, 6, 11, 0, -9, 100 }, /* 0x3b */
++ { 1777, 10, 11, 0, -11, 158 }, /* 0x3c */
++ { 1834, 10, 9, 0, -9, 158 }, /* 0x3d */
++ { 1848, 10, 11, 0, -11, 158 }, /* 0x3e */
++ { 1903, 10, 14, 0, -14, 154 }, /* 0x3f */
++ { 1980, 16, 14, 0, -12, 263 }, /* 0x40 */
++ { 2143, 13, 14, 0, -14, 202 }, /* 0x41 */
++ { 2239, 12, 14, 0, -14, 200 }, /* 0x42 */
++ { 2344, 12, 14, 0, -14, 194 }, /* 0x43 */
++ { 2442, 12, 14, 0, -14, 198 }, /* 0x44 */
++ { 2551, 12, 14, 0, -14, 191 }, /* 0x45 */
++ { 2614, 11, 14, 0, -14, 181 }, /* 0x46 */
++ { 2675, 12, 14, 0, -14, 196 }, /* 0x47 */
++ { 2780, 13, 14, 0, -14, 206 }, /* 0x48 */
++ { 2890, 5, 14, 0, -14, 83 }, /* 0x49 */
++ { 2947, 12, 14, 0, -14, 185 }, /* 0x4a */
++ { 3019, 12, 14, 0, -14, 197 }, /* 0x4b */
++ { 3134, 11, 14, 0, -14, 182 }, /* 0x4c */
++ { 3192, 14, 14, 0, -14, 229 }, /* 0x4d */
++ { 3327, 13, 14, 0, -14, 215 }, /* 0x4e */
++ { 3463, 12, 14, 0, -14, 199 }, /* 0x4f */
++ { 3579, 12, 14, 0, -14, 190 }, /* 0x50 */
++ { 3664, 12, 16, 0, -14, 186 }, /* 0x51 */
++ { 3772, 12, 14, 0, -14, 196 }, /* 0x52 */
++ { 3879, 12, 14, 0, -14, 188 }, /* 0x53 */
++ { 3984, 11, 14, 0, -14, 184 }, /* 0x54 */
++ { 4044, 13, 14, 0, -14, 205 }, /* 0x55 */
++ { 4159, 12, 14, 0, -14, 192 }, /* 0x56 */
++ { 4254, 18, 14, 0, -14, 281 }, /* 0x57 */
++ { 4415, 12, 14, 0, -14, 193 }, /* 0x58 */
++ { 4517, 12, 14, 0, -14, 187 }, /* 0x59 */
++ { 4597, 11, 14, 0, -14, 176 }, /* 0x5a */
++ { 4659, 8, 18, 0, -16, 126 }, /* 0x5b */
++ { 4733, 9, 14, 0, -14, 136 }, /* 0x5c */
++ { 4790, 8, 18, 0, -16, 126 }, /* 0x5d */
++ { 4864, 9, 14, 0, -14, 147 }, /* 0x5e */
++ { 4914, 10, 2, 0, -2, 159 }, /* 0x5f */
++ { 4920, 4, 14, 0, -14, 67 }, /* 0x60 */
++ { 4931, 10, 10, 0, -10, 165 }, /* 0x61 */
++ { 5005, 11, 14, 0, -14, 177 }, /* 0x62 */
++ { 5107, 11, 10, 0, -10, 168 }, /* 0x63 */
++ { 5184, 11, 14, 0, -14, 177 }, /* 0x64 */
++ { 5286, 11, 10, 0, -10, 172 }, /* 0x65 */
++ { 5358, 7, 14, 0, -14, 117 }, /* 0x66 */
++ { 5421, 11, 14, 0, -10, 174 }, /* 0x67 */
++ { 5524, 11, 14, 0, -14, 173 }, /* 0x68 */
++ { 5623, 5, 14, 0, -14, 82 }, /* 0x69 */
++ { 5674, 6, 18, -1, -14, 79 }, /* 0x6a */
++ { 5743, 10, 14, 0, -14, 164 }, /* 0x6b */
++ { 5836, 5, 14, 0, -14, 75 }, /* 0x6c */
++ { 5893, 17, 10, 0, -10, 264 }, /* 0x6d */
++ { 6019, 11, 10, 0, -10, 173 }, /* 0x6e */
++ { 6102, 11, 10, 0, -10, 178 }, /* 0x6f */
++ { 6185, 11, 14, 0, -10, 179 }, /* 0x70 */
++ { 6284, 11, 14, 0, -10, 179 }, /* 0x71 */
++ { 6386, 8, 10, 0, -10, 119 }, /* 0x72 */
++ { 6433, 10, 10, 0, -10, 156 }, /* 0x73 */
++ { 6504, 7, 13, 0, -13, 118 }, /* 0x74 */
++ { 6554, 11, 10, 0, -10, 172 }, /* 0x75 */
++ { 6636, 10, 10, 0, -10, 157 }, /* 0x76 */
++ { 6700, 15, 10, 0, -10, 238 }, /* 0x77 */
++ { 6814, 10, 10, 0, -10, 160 }, /* 0x78 */
++ { 6883, 10, 14, 0, -10, 152 }, /* 0x79 */
++ { 6967, 9, 10, 0, -10, 144 }, /* 0x7a */
++ { 7010, 7, 18, 0, -16, 105 }, /* 0x7b */
++ { 7078, 4, 16, 0, -14, 57 }, /* 0x7c */
++ { 7142, 7, 18, 0, -16, 105 }, /* 0x7d */
++ { 7219, 10, 7, 0, -7, 164 }, /* 0x7e */
++ { 7245, 4, 6, 0, -6, 70 }, /* 0x80 */
++ { 7256, 8, 16, 0, -16, 121 }, /* 0x81 */
++ { 7301, 9, 10, 0, -10, 138 }, /* 0x82 */
++ { 7348, 9, 7, 0, -7, 147 }, /* 0x83 */
++ { 7354, 14, 7, 0, -7, 216 }, /* 0x84 */
++ { 7364, 4, 14, 0, -14, 52 }, /* 0x85 */
++ { 7379, 16, 3, 0, -2, 261 }, /* 0x86 */
++ { 7412, 6, 8, 0, -8, 100 }, /* 0x87 */
++ { 7434, 7, 9, 0, -9, 113 }, /* 0x88 */
++ { 7465, 8, 9, 0, -9, 123 }, /* 0x89 */
++};
++static const uint8_t md_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern md_kern[] = {
++ {39,45,-16},{39,52,-4},{39,65,-23},{39,74,-13},{39,99,-16},{39,100,-16},{39,101,-16},{39,103,-12},
++ {39,109,-5},{39,110,-5},{39,111,-16},{39,112,-5},{39,113,-12},{39,114,-5},{39,115,-8},{44,45,-5},
++ {44,48,-10},{44,84,-14},{44,86,-7},{44,87,-7},{44,89,-14},{44,99,-5},{44,100,-5},{44,101,-5},
++ {44,102,-4},{44,103,-5},{44,111,-5},{44,113,-5},{44,116,-4},{44,117,-4},{44,118,-13},{44,119,-13},
++ {44,121,-13},{45,39,-6},{45,44,-4},{45,45,-40},{45,46,-4},{45,55,-16},{45,84,-14},{45,118,-7},
++ {45,119,-7},{45,120,-5},{45,121,-7},{45,133,-8},{46,45,-5},{46,48,-10},{46,84,-14},{46,86,-7},
++ {46,87,-7},{46,89,-14},{46,99,-5},{46,100,-5},{46,101,-5},{46,102,-4},{46,103,-5},{46,111,-5},
++ {46,113,-5},{46,116,-4},{46,117,-4},{46,118,-13},{46,119,-13},{46,121,-13},{48,49,-7},{50,49,-4},
++ {52,39,-7},{52,49,-30},{52,55,-14},{53,49,-7},{54,49,-4},{55,44,-17},{55,46,-17},{56,49,-7},
++ {57,49,-6},{65,39,-26},{65,45,-4},{65,67,-5},{65,71,-5},{65,74,4},{65,79,-5},{65,81,-5},
++ {65,83,-12},{65,84,-23},{65,86,-12},{65,87,-12},{65,89,-25},{65,90,5},{65,99,-4},{65,100,-4},
++ {65,101,-4},{65,102,-6},{65,103,-7},{65,111,-4},{65,113,-7},{65,116,-6},{65,118,-12},{65,119,-12},
++ {65,121,-12},{65,133,-20},{66,44,-4},{66,46,-4},{66,65,-9},{66,84,-4},{66,86,-7},{66,87,-7},
++ {66,88,-6},{66,89,-8},{66,102,-4},{66,103,-5},{66,113,-5},{66,115,-5},{66,116,-4},{66,117,-4},
++ {67,74,5},{67,89,-5},{68,44,-4},{68,46,-4},{68,65,-9},{68,84,-4},{68,86,-7},{68,87,-7},
++ {68,88,-6},{68,89,-8},{68,102,-4},{68,103,-5},{68,113,-5},{68,115,-5},{68,116,-4},{68,117,-4},
++ {69,86,4},{69,87,4},{70,44,-25},{70,45,-15},{70,46,-25},{70,65,-19},{70,74,-15},{70,97,-12},
++ {70,99,-15},{70,100,-15},{70,101,-15},{70,103,-9},{70,109,-6},{70,110,-6},{70,111,-15},{70,112,-6},
++ {70,113,-9},{70,114,-6},{70,115,-12},{70,117,-7},{70,118,-13},{70,119,-13},{70,120,-11},{70,121,-13},
++ {70,122,-6},{71,74,5},{71,89,-5},{74,44,-4},{74,46,-4},{74,65,-4},{74,67,-4},{74,71,-4},
++ {74,79,-4},{74,81,-4},{75,45,-7},{75,65,7},{75,67,-6},{75,71,-6},{75,74,-4},{75,79,-6},
++ {75,81,-6},{75,83,-4},{75,88,4},{75,99,-7},{75,100,-7},{75,101,-7},{75,103,-6},{75,111,-7},
++ {75,113,-6},{75,118,-10},{75,119,-10},{75,121,-10},{76,39,-20},{76,65,11},{76,84,-28},{76,86,-11},
++ {76,87,-11},{76,89,-10},{76,102,-4},{76,116,-4},{76,118,-6},{76,119,-6},{76,121,-6},{76,133,-12},
++ {78,66,-4},{78,68,-4},{78,69,-4},{78,70,-4},{78,78,-4},{78,80,-4},{79,74,5},{79,89,-5},
++ {80,44,-9},{80,45,-7},{80,46,-9},{80,65,-11},{80,74,-6},{80,86,-4},{80,87,-4},{80,88,-7},
++ {80,89,-7},{80,99,-7},{80,100,-7},{80,101,-7},{80,103,-4},{80,111,-7},{80,113,-4},{80,115,-4},
++ {81,65,-5},{81,74,5},{81,86,-7},{81,87,-7},{81,88,-7},{81,89,-14},{82,65,9},{82,86,-4},
++ {82,87,-4},{82,88,4},{82,89,-6},{83,44,-4},{83,46,-4},{83,84,-5},{83,86,-4},{83,87,-4},
++ {83,88,-9},{83,89,-5},{84,44,-14},{84,45,-24},{84,46,-14},{84,65,-19},{84,67,-13},{84,71,-13},
++ {84,74,-10},{84,79,-13},{84,81,-13},{84,97,-7},{84,99,-24},{84,100,-24},{84,101,-24},{84,103,-19},
++ {84,105,-4},{84,109,-17},{84,110,-17},{84,111,-24},{84,112,-17},{84,113,-19},{84,114,-17},{84,115,-17},
++ {84,117,-14},{84,118,-13},{84,119,-13},{84,120,-16},{84,121,-13},{85,44,-4},{85,46,-4},{85,65,-4},
++ {85,67,-4},{85,71,-4},{85,79,-4},{85,81,-4},{86,44,-19},{86,45,-17},{86,46,-19},{86,65,-31},
++ {86,66,-4},{86,67,-8},{86,68,-4},{86,69,-4},{86,70,-4},{86,71,-8},{86,74,-10},{86,75,-7},
++ {86,78,-4},{86,79,-8},{86,80,-4},{86,81,-8},{86,83,-4},{86,97,-17},{86,99,-17},{86,100,-17},
++ {86,101,-17},{86,103,-15},{86,109,-4},{86,110,-4},{86,111,-17},{86,112,-4},{86,113,-15},{86,114,-4},
++ {86,115,-10},{86,117,-4},{86,118,-4},{86,119,-4},{86,121,-4},{87,44,-19},{87,45,-17},{87,46,-19},
++ {87,65,-31},{87,66,-4},{87,67,-8},{87,68,-4},{87,69,-4},{87,70,-4},{87,71,-8},{87,74,-10},
++ {87,75,-7},{87,78,-4},{87,79,-8},{87,80,-4},{87,81,-8},{87,83,-4},{87,97,-17},{87,99,-17},
++ {87,100,-17},{87,101,-17},{87,103,-15},{87,109,-4},{87,110,-4},{87,111,-17},{87,112,-4},{87,113,-15},
++ {87,114,-4},{87,115,-10},{87,117,-4},{87,118,-4},{87,119,-4},{87,121,-4},{88,45,-8},{88,67,-6},
++ {88,71,-6},{88,79,-6},{88,81,-6},{88,83,-8},{88,97,-4},{88,99,-8},{88,100,-8},{88,101,-8},
++ {88,103,-8},{88,111,-8},{88,113,-8},{88,118,-7},{88,119,-7},{88,121,-7},{89,44,-28},{89,45,-22},
++ {89,46,-28},{89,65,-31},{89,66,-4},{89,67,-9},{89,68,-4},{89,69,-4},{89,70,-4},{89,71,-9},
++ {89,74,-13},{89,78,-4},{89,79,-9},{89,80,-4},{89,81,-9},{89,83,-6},{89,97,-17},{89,99,-22},
++ {89,100,-22},{89,101,-22},{89,102,-11},{89,103,-25},{89,109,-16},{89,110,-16},{89,111,-22},{89,112,-16},
++ {89,113,-25},{89,114,-16},{89,115,-11},{89,116,-11},{89,117,-11},{89,118,-11},{89,119,-11},{89,120,-11},
++ {89,121,-11},{89,122,-6},{97,39,-8},{97,84,-7},{97,89,-9},{97,133,-4},{98,39,-11},{98,44,-5},
++ {98,46,-5},{98,118,-4},{98,119,-4},{98,121,-4},{99,39,-6},{99,44,-8},{99,46,-8},{99,120,-4},
++ {99,133,-4},{101,39,-9},{101,44,-6},{101,46,-6},{101,118,-6},{101,119,-6},{101,120,-6},{101,121,-6},
++ {101,133,-6},{102,39,4},{102,44,-16},{102,45,-13},{102,46,-16},{102,97,-4},{102,99,-13},{102,100,-13},
++ {102,101,-13},{102,103,-11},{102,111,-13},{102,113,-11},{102,115,-5},{102,133,5},{103,39,-4},{104,39,-11},
++ {104,44,-5},{104,46,-5},{104,118,-4},{104,119,-4},{104,121,-4},{107,45,-9},{107,97,-4},{107,99,-9},
++ {107,100,-9},{107,101,-9},{107,103,-7},{107,111,-9},{107,113,-7},{109,39,-11},{109,44,-5},{109,46,-5},
++ {109,118,-4},{109,119,-4},{109,121,-4},{110,39,-11},{110,44,-5},{110,46,-5},{110,118,-4},{110,119,-4},
++ {110,121,-4},{111,39,-6},{111,44,-4},{111,46,-4},{111,55,-16},{111,84,-14},{111,118,-7},{111,119,-7},
++ {111,120,-5},{111,121,-7},{111,133,-8},{112,39,-11},{112,44,-5},{112,46,-5},{112,118,-4},{112,119,-4},
++ {112,121,-4},{113,39,-4},{114,39,9},{114,44,-12},{114,46,-12},{114,102,4},{114,103,-5},{114,113,-5},
++ {114,116,4},{114,118,7},{114,119,7},{114,121,7},{114,133,16},{115,39,-7},{115,115,-4},{115,118,-10},
++ {115,119,-10},{115,121,-10},{115,133,-6},{116,45,-4},{116,99,-4},{116,100,-4},{116,101,-4},{116,111,-4},
++ {118,44,-13},{118,45,-7},{118,46,-13},{118,97,-5},{118,99,-7},{118,100,-7},{118,101,-7},{118,103,-8},
++ {118,111,-7},{118,113,-8},{118,115,-10},{118,133,16},{119,44,-13},{119,45,-7},{119,46,-13},{119,97,-5},
++ {119,99,-7},{119,100,-7},{119,101,-7},{119,103,-8},{119,111,-7},{119,113,-8},{119,115,-10},{119,133,16},
++ {120,45,-8},{120,99,-8},{120,100,-8},{120,101,-8},{120,103,-5},{120,111,-8},{120,113,-5},{121,44,-13},
++ {121,45,-7},{121,46,-13},{121,97,-5},{121,99,-7},{121,100,-7},{121,101,-7},{121,103,-8},{121,111,-7},
++ {121,113,-8},{121,115,-10},{121,133,16},{133,45,-25},{133,65,-20},{133,97,-7},{133,99,-25},{133,100,-25},
++ {133,101,-25},{133,103,-21},{133,111,-25},{133,113,-21},{133,115,-20},{133,118,-4},{133,119,-4},{133,121,-4},
++};
++const struct fos_font fos_font_md_data = { md_bits, md_glyphs, md_lut, md_kern, 544, 20, 4 };
++
++static const uint8_t mdb_bits[] = {
++ 129,11,15,8,131,11,15,8,131,11,15,7,131,11,15,7,131,10,15,7,131,10,15,6,
++ 131,10,15,6,131,9,15,6,131,9,15,5,131,8,15,5,145,10,14,4,130,1,31,10,
++ 131,11,14,4,129,8,15,9,1,31,1,8,15,9,128,31,1,7,15,8,128,31,128,7,
++ 15,7,128,14,15,128,6,15,6,128,13,14,198,131,14,15,5,128,1,31,4,132,2,31,
++ 3,128,3,31,2,132,4,31,1,128,5,31,131,2,127,31,6,129,2,127,31,6,130,2,
++ 12,15,10,18,13,15,9,2,132,13,15,8,129,14,15,6,133,14,15,6,129,31,5,131,
++ 1,2,31,6,2,3,31,5,1,130,13,127,15,10,130,13,127,15,10,131,7,15,13,129,
++ 8,15,12,133,10,15,10,129,11,15,9,133,12,15,8,129,13,15,6,131,131,6,15,9,
++ 135,6,15,9,133,3,11,47,11,4,130,3,14,95,5,129,10,15,12,3,1,3,12,15,
++ 14,1,128,13,15,4,130,1,31,4,128,13,15,5,131,11,13,4,128,9,15,14,5,134,
++ 1,13,31,12,6,133,1,9,47,13,6,133,2,8,14,31,8,134,1,9,31,18,30,132,
++ 13,15,6,1,31,3,131,13,15,6,128,13,15,13,4,17,7,31,3,128,4,111,10,130,
++ 4,12,47,14,8,133,6,15,11,135,5,15,10,131,129,3,12,15,12,4,131,13,11,132,
++ 2,14,10,3,9,15,2,129,6,15,4,132,7,14,130,14,8,128,1,14,11,133,7,14,
++ 130,14,8,128,7,15,3,133,3,15,7,1,7,15,3,1,14,11,135,6,14,15,14,6,
++ 128,8,15,3,137,2,1,128,1,14,10,141,8,15,2,140,1,14,9,141,9,15,2,128,
++ 6,13,14,10,2,134,2,15,9,128,6,15,6,4,28,134,9,15,2,128,12,10,129,3,
++ 15,3,132,2,15,8,129,12,10,129,3,15,3,132,10,14,1,129,6,15,6,3,12,13,
++ 132,2,15,8,131,7,13,14,11,2,129,130,6,12,15,14,10,2,134,7,79,14,1,133,
++ 14,15,11,2,4,14,15,8,132,1,31,4,129,10,15,10,133,14,15,8,128,1,13,15,
++ 8,133,7,31,5,12,31,2,134,11,63,5,134,1,11,47,4,134,1,13,31,14,15,10,
++ 129,2,1,130,10,15,14,20,31,8,1,13,14,4,129,31,6,129,6,31,13,15,13,1,
++ 128,2,31,4,130,9,47,3,130,14,15,11,19,7,14,31,14,1,130,8,95,14,13,15,
++ 11,131,5,11,14,15,12,8,1,3,14,15,7,128,8,15,11,8,15,10,7,15,9,7,
++ 15,9,5,15,8,157,130,11,15,8,130,5,31,2,130,12,15,10,130,3,31,5,130,7,
++ 31,1,130,10,15,14,131,13,15,11,131,14,15,10,131,31,9,131,31,9,131,14,15,10,
++ 131,13,15,11,131,11,15,13,131,7,31,1,130,3,31,5,131,12,15,10,131,6,31,2,
++ 131,12,15,8,128,128,3,31,2,131,11,15,11,131,5,31,2,130,1,31,8,131,12,15,
++ 12,131,9,31,1,130,6,31,3,130,5,31,4,130,4,31,5,130,4,31,5,130,5,31,
++ 4,130,6,31,3,130,9,31,131,12,15,12,130,1,31,7,130,6,31,2,130,12,15,10,
++ 130,3,15,14,2,129,130,26,130,1,5,128,11,10,128,5,128,5,15,60,15,5,128,5,
++ 13,31,13,4,129,5,13,31,13,4,128,5,15,12,13,28,15,4,1,5,128,11,10,128,
++ 6,131,26,194,130,1,15,13,134,1,15,14,134,1,15,14,132,18,3,15,14,34,128,5,
++ 127,2,5,127,2,130,1,15,14,134,1,15,14,134,1,15,13,151,128,4,15,11,129,7,
++ 15,7,129,10,15,3,129,12,14,130,14,10,129,128,82,128,5,95,6,5,95,6,167,128,
++ 5,14,10,129,11,31,129,5,14,9,128,132,10,15,9,132,1,14,15,5,132,5,15,14,
++ 133,10,15,9,132,1,14,15,4,132,5,15,14,133,10,15,9,132,1,31,4,132,5,15,
++ 14,133,11,15,9,132,1,31,4,132,6,15,14,133,11,15,9,132,1,31,4,132,5,15,
++ 13,133,129,1,8,13,15,14,10,3,130,1,13,95,4,129,8,31,7,2,4,13,15,13,
++ 129,12,15,9,130,4,31,2,128,13,15,7,130,1,31,4,128,14,15,6,130,1,31,4,
++ 128,14,15,6,130,1,31,4,128,14,15,6,130,1,31,4,128,14,15,6,130,1,31,4,
++ 128,14,15,6,130,1,31,4,128,13,15,7,130,1,31,4,128,12,15,9,130,4,31,2,
++ 128,7,31,7,2,4,13,15,13,129,1,12,95,4,130,1,8,13,15,14,10,3,129,128,
++ 1,8,31,10,128,1,14,47,10,128,1,15,29,15,10,129,2,128,10,15,10,131,10,15,
++ 10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,
++ 10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,128,129,2,10,14,15,13,
++ 8,1,130,3,14,79,12,130,12,15,14,5,2,7,31,6,129,31,6,130,11,15,10,128,
++ 1,30,4,130,10,15,11,134,1,14,15,7,134,10,15,14,1,133,6,31,7,133,3,31,
++ 11,133,2,14,15,13,1,132,1,12,15,14,3,133,10,31,4,133,8,31,8,66,129,127,
++ 15,1,128,127,15,1,128,127,7,129,127,7,129,1,34,3,14,31,4,132,1,12,31,5,
++ 132,1,12,31,6,133,11,31,12,2,133,11,63,5,132,1,5,2,9,15,14,1,135,14,
++ 15,6,135,12,15,8,128,2,14,13,2,130,12,15,8,128,1,31,5,129,1,14,15,7,
++ 129,11,15,13,4,2,10,31,2,129,2,14,79,7,131,2,10,30,12,5,130,131,8,15,
++ 14,135,1,14,15,8,135,6,31,1,135,12,15,10,135,4,31,3,135,10,15,12,135,2,
++ 31,6,129,12,15,7,130,8,15,14,130,12,15,8,130,14,15,10,35,13,15,9,2,128,
++ 3,127,15,10,128,3,127,15,10,135,12,15,8,136,12,15,8,136,12,15,8,136,12,15,
++ 7,129,128,14,111,4,129,14,111,4,129,14,15,7,66,130,14,15,5,135,14,15,5,135,
++ 14,15,9,12,14,13,8,1,130,14,95,12,130,14,15,14,5,2,7,31,6,129,9,10,
++ 5,130,12,15,9,135,9,15,11,129,21,2,130,9,15,11,129,13,15,9,130,13,15,9,
++ 129,8,31,6,2,8,31,4,129,1,12,79,10,131,1,8,13,14,13,7,130,129,3,10,
++ 14,15,13,7,131,3,95,10,130,11,15,14,5,3,10,31,3,129,14,15,7,130,14,15,
++ 7,129,31,5,130,8,9,4,129,31,5,128,1,133,31,9,13,31,11,2,130,111,14,1,
++ 129,31,14,4,1,6,31,7,129,31,7,130,10,15,11,129,14,15,5,130,8,15,12,129,
++ 13,15,8,130,11,15,10,129,8,15,14,5,2,7,31,6,129,1,13,79,12,131,1,9,
++ 13,15,13,8,1,129,7,127,6,7,127,6,7,15,8,34,4,31,4,3,7,3,130,8,
++ 15,14,134,13,15,9,133,4,31,3,133,9,15,13,134,14,15,8,133,5,31,2,133,10,
++ 15,12,133,1,14,15,7,133,5,31,2,133,11,15,11,133,1,31,6,133,6,15,14,1,
++ 131,129,2,9,14,15,13,7,131,2,14,79,10,130,9,15,14,5,2,8,31,3,129,13,
++ 15,8,130,13,15,7,129,13,15,7,130,12,15,7,129,9,15,14,5,2,8,31,3,129,
++ 1,13,79,7,130,2,13,79,9,130,10,15,13,3,1,6,31,5,129,31,6,130,11,15,
++ 9,128,1,31,4,130,9,15,11,129,31,7,130,12,15,9,129,11,15,14,5,3,8,31,
++ 5,129,2,14,79,11,131,2,10,14,15,13,7,130,129,3,11,30,12,5,131,4,95,7,
++ 130,13,15,12,3,2,9,31,2,128,2,31,4,130,14,15,6,128,4,31,1,130,12,15,
++ 8,128,3,31,3,130,14,15,8,129,14,15,12,2,1,9,31,8,129,7,111,8,130,7,
++ 14,31,9,13,15,8,132,1,129,12,15,8,129,8,9,3,130,12,15,8,129,13,15,8,
++ 130,14,15,8,129,10,15,14,5,2,9,31,4,129,3,14,79,11,131,2,10,14,15,13,
++ 7,130,129,7,14,8,131,13,15,13,131,7,14,7,152,7,14,8,131,13,15,13,131,7,
++ 14,7,136,128,1,12,14,5,129,6,31,11,129,1,12,14,5,154,12,15,3,130,14,15,
++ 130,1,15,12,130,3,15,8,130,4,15,5,129,135,1,134,2,8,14,2,131,3,10,47,
++ 2,129,5,11,47,10,3,128,3,13,31,13,7,1,130,5,31,9,133,3,14,31,12,6,
++ 1,131,1,6,13,31,14,8,2,132,5,11,47,2,133,3,10,15,2,135,2,1,5,127,
++ 2,5,127,2,147,5,127,2,5,127,2,157,1,136,5,14,7,1,133,5,31,14,9,2,
++ 132,5,11,47,10,3,132,2,9,14,31,11,1,132,1,11,31,2,130,1,7,13,31,13,
++ 1,128,3,10,47,11,5,129,5,47,10,3,131,5,14,9,2,133,17,135,129,4,11,14,
++ 15,12,5,130,6,95,7,128,1,14,15,11,19,11,31,1,4,31,1,129,2,31,4,3,
++ 10,9,130,2,31,4,133,11,15,14,1,131,1,11,31,6,131,1,12,31,6,132,6,31,
++ 4,133,8,15,12,134,3,7,5,144,6,14,8,134,12,15,14,134,6,14,8,131,132,2,
++ 7,12,30,13,8,2,134,7,111,14,5,132,9,31,9,5,18,5,10,31,3,130,6,15,
++ 13,3,133,6,15,12,129,1,30,2,135,11,15,2,128,7,15,6,129,8,30,10,15,4,
++ 128,6,15,5,128,11,14,129,8,15,6,4,14,15,2,128,4,15,6,128,14,11,129,14,
++ 9,129,10,15,129,4,15,6,1,15,9,128,2,15,5,129,12,13,129,7,15,3,128,15,
++ 9,128,4,15,6,128,2,15,13,129,12,14,129,14,12,128,1,15,14,10,13,31,10,12,
++ 15,6,129,10,15,2,128,5,13,14,11,3,10,14,13,7,130,5,15,12,1,140,11,15,
++ 13,7,3,2,4,6,11,2,133,1,12,95,14,4,135,6,12,14,15,13,8,2,132,131,
++ 2,47,1,135,6,47,6,135,11,47,10,134,1,31,11,15,14,134,5,31,2,31,4,133,
++ 9,15,11,128,12,15,9,133,14,15,6,128,7,15,13,132,3,31,2,128,3,31,3,131,
++ 8,15,12,130,13,15,7,131,12,15,7,130,8,15,12,130,2,31,78,31,1,129,6,127,
++ 15,6,129,11,15,10,132,10,15,10,128,1,31,6,132,7,15,14,128,4,31,2,132,3,
++ 31,4,128,8,79,14,11,4,130,8,127,5,129,8,15,12,34,4,13,15,13,129,8,15,
++ 12,131,4,31,1,128,8,15,12,131,3,31,1,128,8,15,12,130,2,12,15,13,129,8,
++ 111,14,3,129,8,111,9,130,8,15,12,34,4,13,15,9,129,8,15,12,131,3,31,2,
++ 128,8,15,12,131,1,31,4,128,8,15,12,131,3,31,4,128,8,15,12,34,4,13,15,
++ 14,1,128,8,127,6,129,8,79,14,11,4,129,130,5,11,30,12,7,1,131,9,95,13,
++ 1,129,5,31,10,19,7,31,9,129,10,15,12,131,8,15,14,129,12,15,7,131,3,31,
++ 1,128,13,15,7,136,13,15,7,136,13,15,7,136,13,15,7,136,13,15,7,136,12,15,
++ 7,131,3,31,1,128,10,15,12,131,8,15,14,129,5,31,10,19,7,31,9,130,9,95,
++ 12,1,131,5,11,30,12,7,1,129,128,8,79,14,10,3,130,8,127,4,129,8,15,12,
++ 34,5,13,15,14,129,8,15,12,131,4,31,3,128,8,15,12,132,31,5,128,8,15,12,
++ 132,31,5,128,8,15,12,132,31,5,128,8,15,12,132,31,5,128,8,15,12,132,31,5,
++ 128,8,15,12,132,31,5,128,8,15,12,132,31,5,128,8,15,12,131,4,31,3,128,8,
++ 15,12,34,5,13,15,14,129,8,127,4,129,8,79,14,10,3,129,128,8,127,14,129,8,
++ 127,14,129,8,15,12,82,1,129,8,15,12,136,8,15,12,136,8,15,12,136,8,15,12,
++ 50,1,131,8,95,10,131,8,95,10,131,8,15,12,136,8,15,12,136,8,15,12,136,8,
++ 15,12,82,1,129,8,127,14,129,8,127,14,128,128,8,127,14,128,8,127,14,128,8,15,
++ 12,82,1,128,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,50,1,130,8,95,
++ 10,130,8,95,10,130,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,
++ 12,135,8,15,11,134,130,5,11,30,12,7,132,9,95,12,1,129,4,31,10,19,7,31,
++ 9,129,10,15,12,131,7,15,14,129,12,15,8,131,3,31,1,128,13,15,7,136,13,15,
++ 7,129,1,50,129,13,15,7,129,79,2,128,13,15,7,129,79,2,128,13,15,7,131,3,
++ 31,2,128,12,15,8,131,3,31,1,128,10,15,12,131,7,15,14,129,4,31,11,4,2,
++ 6,14,15,8,130,9,95,12,1,131,5,11,14,15,13,8,1,129,128,8,15,11,132,14,
++ 15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,
++ 15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,66,14,
++ 15,6,129,8,127,15,6,129,8,127,15,6,129,8,15,12,132,14,15,6,129,8,15,12,
++ 132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,132,14,15,6,129,8,15,12,
++ 132,14,15,6,129,8,15,11,132,14,15,6,128,128,8,15,11,129,8,15,12,129,8,15,
++ 12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,
++ 12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,12,129,8,15,
++ 11,128,134,2,31,2,135,2,31,2,135,2,31,2,135,2,31,2,135,2,31,2,135,2,
++ 31,2,135,2,31,2,135,2,31,2,128,3,5,4,131,2,31,2,128,8,15,12,131,2,
++ 31,2,128,8,15,12,131,3,31,2,128,6,15,14,1,130,7,31,129,1,31,12,4,2,
++ 6,14,15,10,130,6,95,13,1,131,4,11,14,15,13,8,1,130,128,8,15,11,131,3,
++ 14,15,7,128,8,15,12,130,1,13,15,11,129,8,15,12,130,11,15,14,1,129,8,15,
++ 12,129,8,31,4,130,8,15,12,128,4,31,7,131,8,15,12,2,14,15,11,132,8,15,
++ 28,31,2,132,8,79,9,132,8,47,10,31,3,131,8,31,5,128,13,15,12,131,8,15,
++ 12,129,4,31,6,130,8,15,12,130,10,15,14,1,129,8,15,12,130,1,14,15,9,129,
++ 8,15,12,131,6,31,3,128,8,15,11,132,12,15,12,128,8,15,11,135,8,15,12,135,
++ 8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,
++ 8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,135,8,15,12,82,1,128,8,127,
++ 12,128,8,127,12,128,8,15,14,1,132,11,15,12,129,8,31,9,131,5,31,13,129,8,
++ 47,4,129,1,13,31,13,129,8,47,12,129,8,47,13,129,8,15,14,31,7,3,31,13,
++ 15,13,129,8,15,12,8,15,14,12,15,12,7,15,13,129,8,15,12,128,13,47,3,7,
++ 15,13,129,8,15,12,128,4,31,9,128,7,15,13,129,8,15,12,129,8,11,1,128,7,
++ 15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,
++ 15,13,129,8,15,12,133,7,15,13,129,8,15,12,133,7,15,13,129,8,15,11,133,7,
++ 15,12,128,128,8,15,13,1,131,6,15,14,129,8,31,8,131,6,15,14,129,8,31,14,
++ 2,130,6,15,14,129,8,47,10,130,6,15,14,129,8,63,3,129,6,15,14,129,8,15,
++ 27,15,11,129,6,15,14,129,8,15,11,3,31,5,128,6,15,14,129,8,15,11,128,9,
++ 15,13,128,6,15,14,129,8,15,11,128,1,14,15,7,6,15,14,129,8,15,11,129,7,
++ 15,14,7,15,14,129,8,15,11,130,13,15,14,15,14,129,8,15,11,130,4,47,14,129,
++ 8,15,12,131,11,31,14,129,8,15,12,131,2,31,14,129,8,15,11,132,8,15,14,128,
++ 130,4,11,30,13,7,1,131,7,95,12,1,129,3,31,11,4,3,7,31,10,129,9,15,
++ 12,131,7,31,1,128,12,15,8,131,2,31,3,128,13,15,7,132,31,4,128,13,15,7,
++ 132,31,4,128,13,15,7,132,31,4,128,13,15,7,132,31,4,128,13,15,7,132,31,4,
++ 128,12,15,8,131,2,31,3,128,10,15,12,131,6,31,1,128,4,31,11,4,3,7,14,
++ 15,10,130,8,95,13,1,131,4,11,30,13,7,1,129,128,10,79,14,11,4,130,10,127,
++ 5,129,10,15,11,34,4,13,15,13,129,10,15,10,131,4,31,3,128,10,15,10,131,1,
++ 31,4,128,10,15,10,131,3,31,3,128,10,15,11,34,4,13,15,13,129,10,127,5,129,
++ 10,79,14,11,4,130,10,15,10,136,10,15,10,136,10,15,10,136,10,15,10,136,10,15,
++ 10,136,10,15,10,135,130,6,12,30,11,4,132,11,95,7,130,7,31,8,19,11,31,3,
++ 129,12,15,10,131,13,15,8,129,31,5,131,9,15,11,128,1,31,4,131,8,15,12,128,
++ 1,31,4,131,8,15,12,128,1,31,4,131,8,15,12,128,1,31,4,131,8,15,12,128,
++ 1,31,4,131,8,15,12,129,31,5,131,9,15,11,129,13,15,9,131,12,15,9,129,7,
++ 31,6,1,2,9,31,3,129,1,11,95,8,132,7,13,31,12,5,134,4,31,1,135,4,
++ 31,1,131,128,8,79,14,12,4,130,8,127,5,129,8,15,12,34,4,12,15,13,129,8,
++ 15,12,131,3,31,3,128,8,15,12,132,31,5,128,8,15,12,131,3,31,3,128,8,15,
++ 12,34,4,12,15,14,1,128,8,127,6,129,8,95,13,5,130,8,15,12,129,6,15,13,
++ 131,8,15,12,130,14,15,5,130,8,15,12,130,7,15,13,130,8,15,12,130,1,14,15,
++ 5,129,8,15,12,131,8,15,12,129,8,15,11,131,2,31,4,129,1,9,13,15,14,11,
++ 6,131,2,14,95,10,130,10,15,14,5,2,3,10,31,6,129,13,15,7,131,11,15,11,
++ 129,13,15,7,131,6,14,11,129,9,15,14,6,135,1,13,31,13,8,2,133,1,8,14,
++ 47,9,1,133,1,6,12,31,13,2,135,5,14,15,10,128,2,31,1,131,7,15,13,128,
++ 1,31,5,131,8,15,13,129,12,15,14,7,3,2,6,14,15,9,129,2,14,95,13,1,
++ 130,1,8,13,14,15,13,8,1,129,4,127,15,13,128,5,127,15,14,129,34,8,15,13,
++ 34,1,132,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,
++ 15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,7,15,13,136,6,
++ 15,13,132,128,10,15,10,132,14,15,5,129,10,15,10,132,14,15,6,129,10,15,10,132,
++ 14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,
++ 14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,14,15,6,129,10,15,10,132,
++ 14,15,6,129,10,15,10,132,14,15,6,129,9,15,11,132,31,5,129,7,15,14,1,130,
++ 5,31,2,129,1,14,15,12,4,2,6,14,15,12,131,5,95,14,2,132,3,10,14,15,
++ 13,9,2,130,4,31,2,132,13,15,8,1,31,6,131,2,31,4,128,11,15,10,131,6,
++ 15,14,129,7,15,14,131,10,15,10,129,2,31,3,130,14,15,5,130,13,15,7,129,3,
++ 31,1,130,9,15,11,129,7,15,12,131,4,31,1,128,11,15,7,131,1,31,4,1,31,
++ 3,132,11,15,8,4,15,13,133,6,15,12,8,15,9,133,2,31,13,15,5,134,13,47,
++ 1,134,8,31,11,135,4,31,6,131,6,15,14,1,130,7,31,1,130,5,15,14,128,3,
++ 31,4,130,11,31,4,130,9,15,11,129,14,15,7,130,14,31,8,130,13,15,8,129,10,
++ 15,11,129,3,47,12,129,1,31,4,129,6,15,14,129,6,63,129,4,31,1,129,3,31,
++ 3,128,9,15,12,31,4,128,8,15,12,131,14,15,6,128,13,15,6,13,15,7,128,11,
++ 15,8,131,10,15,10,1,31,3,10,15,11,128,14,15,5,131,6,15,13,5,15,14,128,
++ 6,15,14,3,31,1,131,3,31,10,15,11,128,2,31,9,15,13,133,14,47,7,129,14,
++ 47,9,133,10,47,3,129,10,47,5,133,6,47,130,6,47,2,133,3,31,11,130,2,31,
++ 13,135,13,15,8,131,13,15,9,131,2,31,6,131,1,14,15,7,128,9,15,14,1,130,
++ 10,15,13,1,128,2,14,15,8,129,3,31,6,130,8,31,2,128,12,15,12,131,1,14,
++ 15,11,6,31,4,132,6,63,11,134,13,47,3,134,6,31,11,135,12,47,2,133,5,63,
++ 10,133,13,15,11,6,31,3,131,7,31,2,128,12,15,12,130,1,14,15,8,129,4,31,
++ 5,129,9,15,14,1,130,10,15,13,128,2,31,5,131,1,14,15,7,3,31,4,131,4,
++ 31,3,128,11,15,11,131,11,15,11,129,4,31,3,129,3,31,4,130,12,15,10,129,10,
++ 15,12,131,5,31,18,31,5,132,13,15,8,9,15,12,133,5,15,14,31,5,134,13,31,
++ 13,135,6,31,6,135,3,31,2,135,3,31,2,135,3,31,2,135,3,31,2,135,3,31,
++ 2,135,3,31,2,131,4,127,15,3,4,127,15,3,128,82,10,15,14,1,133,4,31,6,
++ 133,1,13,15,11,134,8,15,14,2,133,3,31,7,134,12,15,12,134,7,31,3,133,2,
++ 31,7,134,12,15,12,134,6,31,3,133,1,14,15,10,82,128,4,127,15,3,4,127,15,
++ 3,4,63,8,129,5,63,8,129,5,31,18,1,129,5,31,132,5,31,132,5,31,132,5,
++ 31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,31,132,5,
++ 31,132,5,31,132,5,31,132,5,31,18,1,129,5,63,9,129,4,63,8,129,128,10,15,
++ 8,133,6,15,14,133,1,31,4,133,11,15,9,133,6,15,14,133,1,31,4,133,10,15,
++ 9,133,5,15,14,133,1,31,4,133,10,15,9,133,5,15,14,133,1,14,15,4,133,10,
++ 15,9,133,5,15,14,133,1,14,15,4,129,7,63,5,129,7,63,6,129,1,18,14,15,
++ 6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,
++ 6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,6,132,14,15,
++ 6,132,14,15,6,132,14,15,6,129,1,18,14,15,6,129,7,63,6,129,7,63,5,130,
++ 3,8,5,133,11,15,14,132,1,47,5,131,6,15,10,15,10,131,12,15,2,13,15,1,
++ 129,2,15,12,128,8,15,6,129,7,15,7,128,3,15,11,129,13,15,2,129,13,15,2,
++ 3,15,12,130,7,15,7,181,1,114,1,8,127,11,8,127,11,128,2,1,128,2,30,1,
++ 128,4,15,9,175,129,4,11,30,12,6,130,6,95,9,129,14,15,12,3,2,8,31,2,
++ 128,2,4,2,130,31,5,129,7,12,14,63,5,128,11,111,5,3,31,10,3,18,14,15,
++ 21,31,1,129,1,31,5,3,31,7,2,4,12,31,5,128,12,111,5,128,2,10,14,15,
++ 12,4,14,15,5,128,11,15,8,135,11,15,9,135,11,15,9,135,11,15,9,135,11,15,
++ 25,30,10,2,130,11,95,14,2,129,11,31,9,3,6,31,10,129,11,15,14,130,9,15,
++ 14,129,11,15,11,130,4,31,2,128,11,15,10,130,3,31,3,128,11,15,11,130,4,31,
++ 2,128,11,15,14,130,8,15,14,129,11,31,10,3,6,31,9,129,11,95,14,2,129,11,
++ 15,25,30,10,2,129,129,1,8,13,14,13,8,1,130,1,12,79,12,1,129,7,31,6,
++ 2,6,14,15,9,129,13,15,9,130,8,15,11,129,31,5,135,31,5,135,31,5,135,12,
++ 15,9,130,7,12,8,129,7,31,6,2,5,14,15,9,129,1,12,79,13,1,130,1,8,
++ 13,15,13,8,1,129,134,6,15,13,135,6,15,14,135,6,15,14,135,6,15,14,130,1,
++ 9,13,14,10,8,15,14,129,1,13,95,14,129,7,31,8,3,7,31,14,129,12,15,11,
++ 130,11,15,14,129,14,15,7,130,8,15,14,129,31,6,130,7,15,14,129,14,15,7,130,
++ 8,15,14,129,12,15,10,130,12,15,14,129,7,31,7,3,8,31,14,129,1,13,95,14,
++ 130,1,9,30,10,7,15,13,128,129,1,8,13,15,13,9,1,130,1,12,79,13,1,129,
++ 7,15,14,4,2,5,14,15,7,129,13,15,7,130,8,15,11,129,127,13,129,127,14,129,
++ 14,15,6,66,1,129,11,15,9,130,1,4,130,6,31,7,2,3,11,15,5,130,11,95,
++ 4,131,7,13,15,14,10,2,129,130,9,13,15,11,130,8,47,11,130,11,15,12,3,1,
++ 130,13,15,8,130,6,79,12,128,6,79,12,129,2,13,15,8,2,1,130,13,15,7,132,
++ 13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,13,15,7,132,
++ 12,15,7,130,129,2,10,30,10,9,15,12,129,2,14,95,12,129,9,31,6,2,7,31,
++ 12,129,14,15,9,130,11,15,12,129,31,5,130,8,15,12,128,1,31,4,130,8,15,12,
++ 129,31,5,130,8,15,12,129,14,15,8,130,11,15,12,129,10,31,6,2,7,31,12,129,
++ 2,14,95,12,130,2,10,30,26,15,12,135,11,15,10,131,1,2,3,9,31,5,131,11,
++ 63,11,132,11,15,14,11,6,130,128,11,15,8,135,12,15,8,135,12,15,8,135,12,15,
++ 8,135,12,15,25,14,15,11,3,130,12,95,14,1,129,12,31,7,2,7,31,7,129,12,
++ 15,11,130,12,15,10,129,12,15,9,130,9,15,11,129,12,15,8,130,9,15,11,129,12,
++ 15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,
++ 15,8,130,9,15,11,129,11,15,8,130,9,15,10,128,128,7,14,8,129,12,15,14,129,
++ 7,14,8,134,9,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,
++ 10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,10,15,10,129,9,15,10,128,
++ 130,8,14,7,131,14,15,13,131,8,14,7,138,10,15,9,131,10,15,10,131,10,15,10,
++ 131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,131,10,15,10,
++ 131,10,15,10,131,10,15,10,131,11,15,9,129,2,6,31,7,129,47,14,2,129,15,14,
++ 11,3,129,128,11,15,8,134,12,15,8,134,12,15,8,134,12,15,8,134,12,15,8,129,
++ 6,31,5,128,12,15,8,128,4,31,9,129,12,15,8,2,14,15,12,130,12,15,9,13,
++ 31,2,130,12,79,4,130,12,47,12,15,10,130,12,31,5,4,31,2,129,12,15,9,129,
++ 13,15,8,129,12,15,8,129,6,15,14,1,128,12,15,8,129,1,14,15,6,128,11,15,
++ 8,130,9,15,12,128,11,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,
++ 8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,8,129,12,15,
++ 8,129,12,15,8,129,12,15,8,129,12,15,8,129,11,15,8,128,128,11,15,25,30,11,
++ 3,1,9,30,11,2,130,12,95,14,11,63,13,130,12,31,6,2,9,47,6,2,9,31,
++ 4,129,12,15,10,130,14,15,10,130,14,15,6,129,12,15,8,130,12,15,8,130,13,15,
++ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,12,15,8,130,12,15,8,130,13,15,
++ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,12,15,8,130,12,15,8,130,13,15,
++ 7,129,12,15,8,130,12,15,8,130,13,15,7,129,11,15,8,130,12,15,7,130,12,15,
++ 7,128,128,11,15,25,14,15,11,3,130,12,95,14,1,129,12,31,7,2,7,31,7,129,
++ 12,15,11,130,12,15,10,129,12,15,9,130,9,15,11,129,12,15,8,130,9,15,11,129,
++ 12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,12,15,8,130,9,15,11,129,
++ 12,15,8,130,9,15,11,129,11,15,8,130,9,15,10,128,129,1,7,13,14,13,8,1,
++ 130,1,12,79,12,1,129,7,31,6,2,5,14,15,8,129,12,15,9,130,7,15,14,129,
++ 31,5,130,4,31,17,31,4,130,3,31,2,128,31,5,130,4,31,1,128,12,15,9,130,
++ 8,15,13,129,6,31,6,2,6,31,7,130,11,79,12,1,130,1,7,13,15,13,8,1,
++ 129,128,10,15,10,8,30,11,3,130,10,95,14,3,129,10,31,10,3,5,14,15,11,129,
++ 10,31,1,129,7,31,1,128,10,15,12,130,3,31,3,128,10,15,11,130,2,31,4,128,
++ 10,15,12,130,3,31,3,128,10,31,1,129,7,31,1,128,10,31,10,3,5,14,15,11,
++ 129,10,95,14,3,129,10,15,10,8,30,11,3,130,10,15,10,135,10,15,10,135,10,15,
++ 10,135,10,15,10,134,129,1,9,30,10,7,15,13,129,1,13,95,14,129,7,31,6,2,
++ 8,31,14,129,12,15,10,130,12,15,14,129,14,15,7,130,8,15,14,129,31,6,130,7,
++ 15,14,129,14,15,7,130,8,15,14,129,12,15,11,130,11,15,14,129,7,31,7,3,7,
++ 31,14,129,1,13,95,14,130,2,9,14,15,10,8,15,14,135,6,15,14,135,6,15,14,
++ 135,6,15,14,135,6,15,13,128,128,11,15,25,14,13,2,128,12,79,1,128,12,31,7,
++ 18,129,12,15,11,132,12,15,9,132,12,15,8,132,12,15,8,132,12,15,8,132,12,15,
++ 8,132,12,15,8,132,11,15,8,131,129,6,12,30,11,5,130,8,95,6,129,31,9,2,
++ 3,10,15,13,129,31,4,129,1,8,7,129,9,31,10,5,1,132,8,14,31,14,9,1,
++ 131,1,5,10,14,15,11,128,1,25,1,129,4,31,17,31,9,19,10,31,1,128,8,95,
++ 9,130,6,12,30,12,6,129,129,7,8,2,131,14,15,4,131,14,15,4,129,6,79,10,
++ 6,79,10,128,2,14,15,6,2,1,129,14,15,4,131,14,15,4,131,14,15,4,131,14,
++ 15,4,131,14,15,5,131,13,15,10,2,1,129,11,47,7,129,2,11,14,15,7,128,13,
++ 15,6,130,11,15,8,129,13,15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,
++ 15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,15,7,130,11,15,9,129,13,
++ 15,7,130,11,15,9,129,13,15,9,130,13,15,9,129,11,15,14,5,2,9,31,9,129,
++ 4,111,9,130,4,12,30,8,11,15,8,128,6,31,2,129,1,14,15,7,2,31,6,129,
++ 5,31,3,128,12,15,10,129,9,15,13,129,8,15,14,129,13,15,9,129,3,31,3,2,
++ 31,4,130,13,15,7,6,15,14,131,9,15,11,10,15,10,131,4,15,30,15,5,132,14,
++ 47,1,132,10,31,11,133,5,31,6,130,6,15,14,130,9,15,10,130,11,15,9,2,31,
++ 3,129,13,15,14,130,31,5,128,13,15,6,128,2,47,3,128,4,31,1,128,9,15,10,
++ 128,6,47,7,128,7,15,12,129,5,15,13,128,9,15,12,15,10,128,11,15,8,129,1,
++ 31,2,13,15,4,15,14,128,14,15,4,130,12,15,6,15,14,128,12,15,6,15,14,131,
++ 8,15,13,15,10,128,8,15,13,15,11,131,4,47,6,128,4,47,6,132,14,31,2,128,
++ 1,47,2,132,10,15,13,130,11,15,13,130,5,15,14,2,129,1,13,15,10,128,11,15,
++ 11,129,9,15,14,1,128,2,14,15,6,3,31,6,130,7,15,14,13,15,12,132,12,47,
++ 2,132,5,31,10,133,12,47,2,131,7,31,12,15,11,130,2,14,15,8,2,14,15,6,
++ 129,11,15,13,1,128,7,15,14,1,5,31,4,130,12,15,9,7,15,14,130,1,31,4,
++ 3,31,3,129,5,15,14,129,13,15,7,129,9,15,10,129,8,15,11,129,13,15,5,129,
++ 4,31,128,2,15,14,1,130,14,15,4,6,15,10,131,9,15,8,10,15,6,131,4,15,
++ 12,14,15,1,132,14,31,11,133,10,31,6,133,5,31,2,133,7,15,11,132,1,4,14,
++ 15,6,131,1,47,13,132,1,15,14,10,2,132,5,111,6,5,111,6,128,50,11,15,14,
++ 2,131,6,31,5,131,3,31,9,131,1,13,15,12,132,11,15,14,2,131,8,31,4,131,
++ 4,31,9,50,1,7,111,7,6,111,7,129,3,12,31,4,129,11,47,5,129,14,15,11,
++ 2,130,14,15,6,131,14,15,6,131,14,15,6,131,14,15,6,131,31,5,130,6,31,3,
++ 129,4,31,10,130,4,31,12,131,5,31,4,131,31,5,131,14,15,6,131,14,15,6,131,
++ 14,15,6,131,14,15,6,131,14,15,11,2,130,11,47,5,129,3,12,31,4,3,31,1,
++ 4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,
++ 4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,4,31,1,
++ 4,31,1,4,31,12,3,129,5,47,11,130,2,11,15,14,131,6,15,14,131,6,15,14,
++ 131,6,15,14,131,6,15,14,131,5,31,131,4,31,6,131,11,31,4,130,12,31,4,129,
++ 4,31,5,130,5,31,131,6,15,14,131,6,15,14,131,6,15,14,131,6,15,14,130,2,
++ 11,15,14,129,5,47,11,129,4,31,12,3,129,130,1,134,4,13,15,14,8,3,5,12,
++ 3,2,127,8,1,9,7,1,3,9,30,8,168,128,10,14,5,128,1,31,10,129,10,14,
++ 4,148,130,1,132,3,12,31,8,129,1,14,63,8,128,6,15,8,1,2,13,14,128,8,
++ 15,1,129,7,15,1,6,15,9,2,4,13,14,128,1,13,63,7,129,2,10,14,13,7,
++ 209,128,8,9,129,1,11,4,128,2,14,15,9,1,11,15,12,129,4,14,15,14,15,13,
++ 2,130,5,31,14,2,130,1,11,47,9,129,1,11,15,13,6,14,15,9,128,1,12,13,
++ 2,128,4,14,8,129,17,130,2,147,128,98,1,5,111,10,5,111,10,172,128,114,34,1,
++ 5,127,47,11,5,127,47,11,192,128,13,15,6,2,31,1,6,15,11,128,9,15,6,128,
++ 13,14,1,168,128,5,14,10,130,10,14,5,129,3,14,12,130,11,31,129,1,31,10,129,
++ 8,31,3,129,5,14,9,130,10,14,4,129,3,14,12,129,128,5,13,14,8,128,2,63,
++ 6,5,63,9,2,63,5,128,4,13,14,7,146,129,2,14,15,2,130,11,15,7,130,6,
++ 15,12,131,14,15,4,131,7,15,11,132,12,15,6,131,2,30,2,142,128,3,15,14,1,
++ 131,9,15,10,131,1,13,15,4,131,5,15,12,131,12,15,5,130,8,15,10,130,3,15,
++ 14,1,143,
++};
++static const struct fos_glyph mdb_glyphs[] = {
++ { 0, 4, 0, 0, 0, 64 }, /* 0x20 */
++ { 0, 7, 15, 0, -15, 107 }, /* 0x21 */
++ { 53, 7, 15, 0, -15, 104 }, /* 0x22 */
++ { 85, 14, 14, 0, -14, 217 }, /* 0x23 */
++ { 188, 11, 19, 0, -17, 181 }, /* 0x24 */
++ { 302, 17, 15, 0, -15, 267 }, /* 0x25 */
++ { 443, 14, 15, 0, -15, 220 }, /* 0x26 */
++ { 566, 3, 15, 0, -15, 50 }, /* 0x27 */
++ { 582, 7, 18, -1, -16, 101 }, /* 0x28 */
++ { 653, 7, 18, 0, -16, 101 }, /* 0x29 */
++ { 726, 8, 16, 0, -16, 127 }, /* 0x2a */
++ { 772, 10, 11, 0, -11, 157 }, /* 0x2b */
++ { 810, 5, 5, 0, -3, 85 }, /* 0x2c */
++ { 829, 8, 8, 0, -8, 129 }, /* 0x2d */
++ { 839, 5, 3, 0, -3, 87 }, /* 0x2e */
++ { 851, 9, 15, 0, -15, 143 }, /* 0x2f */
++ { 914, 11, 15, 0, -15, 182 }, /* 0x30 */
++ { 1031, 7, 15, 0, -15, 113 }, /* 0x31 */
++ { 1098, 11, 15, 0, -15, 176 }, /* 0x32 */
++ { 1182, 11, 15, 0, -15, 170 }, /* 0x33 */
++ { 1269, 12, 15, 0, -15, 187 }, /* 0x34 */
++ { 1346, 11, 15, 0, -15, 170 }, /* 0x35 */
++ { 1437, 11, 15, 0, -15, 169 }, /* 0x36 */
++ { 1542, 10, 15, 0, -15, 156 }, /* 0x37 */
++ { 1609, 11, 15, 0, -15, 171 }, /* 0x38 */
++ { 1718, 11, 15, 0, -15, 169 }, /* 0x39 */
++ { 1826, 7, 10, 0, -10, 114 }, /* 0x3a */
++ { 1851, 6, 12, 0, -10, 100 }, /* 0x3b */
++ { 1885, 10, 11, 0, -11, 157 }, /* 0x3c */
++ { 1942, 10, 9, 0, -9, 157 }, /* 0x3d */
++ { 1956, 10, 11, 0, -11, 157 }, /* 0x3e */
++ { 2012, 10, 15, 0, -15, 160 }, /* 0x3f */
++ { 2086, 16, 16, 0, -14, 263 }, /* 0x40 */
++ { 2255, 13, 15, 0, -15, 207 }, /* 0x41 */
++ { 2354, 12, 15, 0, -15, 199 }, /* 0x42 */
++ { 2461, 12, 15, 0, -15, 195 }, /* 0x43 */
++ { 2554, 12, 15, 0, -15, 198 }, /* 0x44 */
++ { 2658, 12, 15, 0, -15, 189 }, /* 0x45 */
++ { 2725, 11, 15, 0, -15, 180 }, /* 0x46 */
++ { 2790, 12, 15, 0, -15, 196 }, /* 0x47 */
++ { 2898, 13, 15, 0, -15, 204 }, /* 0x48 */
++ { 3013, 5, 15, 0, -15, 84 }, /* 0x49 */
++ { 3074, 12, 15, 0, -15, 186 }, /* 0x4a */
++ { 3162, 12, 15, 0, -15, 198 }, /* 0x4b */
++ { 3279, 11, 15, 0, -15, 183 }, /* 0x4c */
++ { 3341, 14, 15, 0, -15, 229 }, /* 0x4d */
++ { 3483, 13, 15, 0, -15, 214 }, /* 0x4e */
++ { 3624, 12, 15, 0, -15, 199 }, /* 0x4f */
++ { 3735, 12, 15, 0, -15, 190 }, /* 0x50 */
++ { 3822, 12, 17, 0, -15, 188 }, /* 0x51 */
++ { 3939, 12, 15, 0, -15, 196 }, /* 0x52 */
++ { 4049, 12, 15, 0, -15, 189 }, /* 0x53 */
++ { 4162, 12, 15, 0, -15, 185 }, /* 0x54 */
++ { 4227, 13, 15, 0, -15, 204 }, /* 0x55 */
++ { 4348, 12, 15, 0, -15, 195 }, /* 0x56 */
++ { 4450, 18, 15, 0, -15, 281 }, /* 0x57 */
++ { 4618, 12, 15, 0, -15, 197 }, /* 0x58 */
++ { 4723, 12, 15, 0, -15, 192 }, /* 0x59 */
++ { 4806, 11, 15, 0, -15, 177 }, /* 0x5a */
++ { 4873, 8, 20, 0, -17, 129 }, /* 0x5b */
++ { 4941, 9, 15, 0, -15, 143 }, /* 0x5c */
++ { 5003, 8, 20, 0, -17, 129 }, /* 0x5d */
++ { 5087, 9, 15, 0, -15, 149 }, /* 0x5e */
++ { 5144, 10, 3, 0, -3, 163 }, /* 0x5f */
++ { 5153, 4, 15, 0, -15, 70 }, /* 0x60 */
++ { 5165, 10, 11, 0, -11, 167 }, /* 0x61 */
++ { 5237, 11, 15, 0, -15, 179 }, /* 0x62 */
++ { 5334, 11, 11, 0, -11, 170 }, /* 0x63 */
++ { 5406, 11, 15, 0, -15, 179 }, /* 0x64 */
++ { 5505, 11, 11, 0, -11, 173 }, /* 0x65 */
++ { 5577, 8, 15, 0, -15, 120 }, /* 0x66 */
++ { 5644, 11, 15, 0, -11, 176 }, /* 0x67 */
++ { 5745, 11, 15, 0, -15, 174 }, /* 0x68 */
++ { 5847, 5, 15, 0, -15, 82 }, /* 0x69 */
++ { 5904, 7, 19, -2, -15, 80 }, /* 0x6a */
++ { 5979, 10, 15, 0, -15, 167 }, /* 0x6b */
++ { 6077, 5, 15, 0, -15, 76 }, /* 0x6c */
++ { 6138, 17, 11, 0, -11, 265 }, /* 0x6d */
++ { 6266, 11, 11, 0, -11, 174 }, /* 0x6e */
++ { 6352, 11, 11, 0, -11, 178 }, /* 0x6f */
++ { 6433, 11, 15, 0, -11, 180 }, /* 0x70 */
++ { 6534, 11, 15, 0, -11, 180 }, /* 0x71 */
++ { 6633, 8, 11, 0, -11, 120 }, /* 0x72 */
++ { 6682, 10, 11, 0, -11, 158 }, /* 0x73 */
++ { 6752, 7, 14, 0, -14, 120 }, /* 0x74 */
++ { 6814, 11, 11, 0, -11, 173 }, /* 0x75 */
++ { 6900, 10, 11, 0, -11, 161 }, /* 0x76 */
++ { 6971, 15, 11, 0, -11, 244 }, /* 0x77 */
++ { 7092, 10, 11, 0, -11, 165 }, /* 0x78 */
++ { 7169, 10, 15, 0, -11, 156 }, /* 0x79 */
++ { 7261, 9, 11, 0, -11, 146 }, /* 0x7a */
++ { 7307, 7, 20, 0, -17, 112 }, /* 0x7b */
++ { 7389, 4, 18, 0, -16, 61 }, /* 0x7c */
++ { 7443, 7, 20, 0, -17, 112 }, /* 0x7d */
++ { 7525, 10, 8, 0, -8, 167 }, /* 0x7e */
++ { 7549, 5, 7, 0, -7, 72 }, /* 0x80 */
++ { 7562, 8, 18, 0, -18, 121 }, /* 0x81 */
++ { 7609, 9, 10, 0, -10, 140 }, /* 0x82 */
++ { 7666, 9, 8, 0, -8, 149 }, /* 0x83 */
++ { 7676, 13, 8, 0, -8, 214 }, /* 0x84 */
++ { 7689, 4, 15, 0, -15, 58 }, /* 0x85 */
++ { 7708, 17, 3, 0, -3, 266 }, /* 0x86 */
++ { 7744, 6, 8, 0, -8, 100 }, /* 0x87 */
++ { 7765, 7, 9, 0, -9, 110 }, /* 0x88 */
++ { 7795, 7, 9, 0, -9, 118 }, /* 0x89 */
++};
++static const uint8_t mdb_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern mdb_kern[] = {
++ {39,45,-16},{39,52,-5},{39,65,-25},{39,74,-16},{39,97,-4},{39,99,-16},{39,100,-16},{39,101,-16},
++ {39,103,-11},{39,109,-4},{39,110,-4},{39,111,-16},{39,112,-4},{39,113,-11},{39,114,-4},{39,115,-8},
++ {44,45,-4},{44,48,-9},{44,84,-18},{44,86,-9},{44,87,-9},{44,89,-18},{44,99,-4},{44,100,-4},
++ {44,101,-4},{44,103,-4},{44,111,-4},{44,113,-4},{44,118,-13},{44,119,-13},{44,121,-13},{45,39,-7},
++ {45,44,-4},{45,45,-45},{45,46,-4},{45,55,-20},{45,84,-11},{45,102,-4},{45,116,-4},{45,118,-8},
++ {45,119,-8},{45,120,-7},{45,121,-8},{45,133,-8},{46,45,-4},{46,48,-9},{46,84,-18},{46,86,-9},
++ {46,87,-9},{46,89,-18},{46,99,-4},{46,100,-4},{46,101,-4},{46,103,-4},{46,111,-4},{46,113,-4},
++ {46,118,-13},{46,119,-13},{46,121,-13},{48,49,-5},{50,51,-4},{52,39,-9},{52,49,-30},{52,55,-18},
++ {53,49,-5},{54,49,-4},{55,44,-19},{55,46,-19},{56,49,-5},{57,49,-6},{65,39,-28},{65,45,-5},
++ {65,67,-6},{65,71,-6},{65,79,-6},{65,81,-6},{65,83,-13},{65,84,-25},{65,85,-4},{65,86,-9},
++ {65,87,-9},{65,89,-26},{65,90,4},{65,99,-5},{65,100,-5},{65,101,-5},{65,102,-7},{65,103,-7},
++ {65,111,-5},{65,113,-7},{65,116,-7},{65,118,-14},{65,119,-14},{65,121,-14},{65,133,-21},{66,65,-11},
++ {66,84,-5},{66,86,-8},{66,87,-8},{66,88,-7},{66,89,-10},{66,103,-4},{66,113,-4},{66,115,-4},
++ {67,74,4},{67,86,-4},{67,87,-4},{67,89,-7},{68,65,-11},{68,84,-5},{68,86,-8},{68,87,-8},
++ {68,88,-7},{68,89,-10},{68,103,-4},{68,113,-4},{68,115,-4},{70,44,-27},{70,45,-17},{70,46,-27},
++ {70,65,-22},{70,74,-17},{70,97,-14},{70,99,-17},{70,100,-17},{70,101,-17},{70,103,-12},{70,109,-7},
++ {70,110,-7},{70,111,-17},{70,112,-7},{70,113,-12},{70,114,-7},{70,115,-14},{70,117,-9},{70,118,-15},
++ {70,119,-15},{70,120,-14},{70,121,-15},{70,122,-7},{71,74,4},{71,86,-4},{71,87,-4},{71,89,-7},
++ {74,65,-5},{75,45,-9},{75,65,5},{75,67,-7},{75,71,-7},{75,74,-6},{75,79,-7},{75,81,-7},
++ {75,83,-5},{75,99,-9},{75,100,-9},{75,101,-9},{75,103,-7},{75,111,-9},{75,113,-7},{75,115,-4},
++ {75,118,-12},{75,119,-12},{75,121,-12},{76,39,-25},{76,65,8},{76,84,-28},{76,86,-12},{76,87,-12},
++ {76,89,-13},{76,102,-5},{76,116,-5},{76,118,-7},{76,119,-7},{76,121,-7},{76,122,4},{76,133,-15},
++ {79,74,4},{79,86,-4},{79,87,-4},{79,89,-7},{80,44,-7},{80,45,-8},{80,46,-7},{80,65,-14},
++ {80,74,-7},{80,86,-5},{80,87,-5},{80,88,-9},{80,89,-9},{80,99,-8},{80,100,-8},{80,101,-8},
++ {80,103,-5},{80,111,-8},{80,113,-5},{80,115,-5},{81,65,-7},{81,74,4},{81,84,-4},{81,86,-9},
++ {81,87,-9},{81,88,-9},{81,89,-15},{82,65,7},{82,86,-5},{82,87,-5},{82,89,-7},{83,84,-4},
++ {83,86,-5},{83,87,-5},{83,88,-11},{83,89,-7},{84,44,-18},{84,45,-25},{84,46,-18},{84,65,-20},
++ {84,67,-11},{84,71,-11},{84,74,-13},{84,79,-11},{84,81,-11},{84,97,-9},{84,99,-25},{84,100,-25},
++ {84,101,-25},{84,103,-20},{84,109,-18},{84,110,-18},{84,111,-25},{84,112,-18},{84,113,-20},{84,114,-18},
++ {84,115,-18},{84,117,-15},{84,118,-15},{84,119,-15},{84,120,-17},{84,121,-15},{85,65,-5},{86,44,-19},
++ {86,45,-18},{86,46,-19},{86,65,-31},{86,67,-9},{86,71,-9},{86,74,-13},{86,75,-5},{86,79,-9},
++ {86,81,-9},{86,83,-5},{86,97,-18},{86,99,-18},{86,100,-18},{86,101,-18},{86,103,-17},{86,109,-4},
++ {86,110,-4},{86,111,-18},{86,112,-4},{86,113,-17},{86,114,-4},{86,115,-12},{86,117,-5},{86,118,-5},
++ {86,119,-5},{86,121,-5},{87,44,-19},{87,45,-18},{87,46,-19},{87,65,-31},{87,67,-9},{87,71,-9},
++ {87,74,-13},{87,75,-5},{87,79,-9},{87,81,-9},{87,83,-5},{87,97,-18},{87,99,-18},{87,100,-18},
++ {87,101,-18},{87,103,-17},{87,109,-4},{87,110,-4},{87,111,-18},{87,112,-4},{87,113,-17},{87,114,-4},
++ {87,115,-12},{87,117,-5},{87,118,-5},{87,119,-5},{87,121,-5},{88,45,-9},{88,67,-7},{88,71,-7},
++ {88,74,-4},{88,79,-7},{88,81,-7},{88,83,-8},{88,97,-5},{88,99,-9},{88,100,-9},{88,101,-9},
++ {88,103,-11},{88,111,-9},{88,113,-11},{88,118,-9},{88,119,-9},{88,121,-9},{89,44,-29},{89,45,-23},
++ {89,46,-29},{89,65,-35},{89,67,-10},{89,71,-10},{89,74,-17},{89,79,-10},{89,81,-10},{89,83,-7},
++ {89,97,-19},{89,99,-23},{89,100,-23},{89,101,-23},{89,102,-12},{89,103,-27},{89,109,-16},{89,110,-16},
++ {89,111,-23},{89,112,-16},{89,113,-27},{89,114,-16},{89,115,-14},{89,116,-12},{89,117,-12},{89,118,-12},
++ {89,119,-12},{89,120,-12},{89,121,-12},{89,122,-7},{97,39,-8},{97,84,-9},{97,89,-11},{97,118,-4},
++ {97,119,-4},{97,121,-4},{97,133,-5},{98,39,-12},{98,44,-4},{98,46,-4},{98,118,-6},{98,119,-6},
++ {98,121,-6},{98,133,-4},{99,39,-7},{99,44,-8},{99,46,-8},{99,120,-5},{99,133,-5},{101,39,-11},
++ {101,44,-6},{101,46,-6},{101,118,-7},{101,119,-7},{101,120,-6},{101,121,-7},{101,133,-7},{102,44,-16},
++ {102,45,-12},{102,46,-16},{102,97,-4},{102,99,-12},{102,100,-12},{102,101,-12},{102,103,-9},{102,111,-12},
++ {102,113,-9},{102,115,-4},{102,133,4},{104,39,-12},{104,44,-4},{104,46,-4},{104,118,-6},{104,119,-6},
++ {104,121,-6},{104,133,-4},{107,45,-12},{107,97,-5},{107,99,-12},{107,100,-12},{107,101,-12},{107,103,-8},
++ {107,111,-12},{107,113,-8},{109,39,-12},{109,44,-4},{109,46,-4},{109,118,-6},{109,119,-6},{109,121,-6},
++ {109,133,-4},{110,39,-12},{110,44,-4},{110,46,-4},{110,118,-6},{110,119,-6},{110,121,-6},{110,133,-4},
++ {111,39,-7},{111,44,-4},{111,46,-4},{111,55,-20},{111,84,-11},{111,102,-4},{111,116,-4},{111,118,-8},
++ {111,119,-8},{111,120,-7},{111,121,-8},{111,133,-8},{112,39,-12},{112,44,-4},{112,46,-4},{112,118,-6},
++ {112,119,-6},{112,121,-6},{112,133,-4},{114,39,7},{114,44,-12},{114,46,-12},{114,103,-6},{114,113,-6},
++ {114,118,5},{114,119,5},{114,121,5},{114,133,16},{115,39,-5},{115,118,-11},{115,119,-11},{115,120,-4},
++ {115,121,-11},{115,133,-7},{118,44,-12},{118,45,-9},{118,46,-12},{118,97,-7},{118,99,-9},{118,100,-9},
++ {118,101,-9},{118,103,-9},{118,111,-9},{118,113,-9},{118,115,-11},{118,133,12},{119,44,-12},{119,45,-9},
++ {119,46,-12},{119,97,-7},{119,99,-9},{119,100,-9},{119,101,-9},{119,103,-9},{119,111,-9},{119,113,-9},
++ {119,115,-11},{119,133,12},{120,45,-10},{120,99,-10},{120,100,-10},{120,101,-10},{120,103,-7},{120,111,-10},
++ {120,113,-7},{121,44,-12},{121,45,-9},{121,46,-12},{121,97,-7},{121,99,-9},{121,100,-9},{121,101,-9},
++ {121,103,-9},{121,111,-9},{121,113,-9},{121,115,-11},{121,133,12},{133,45,-27},{133,65,-22},{133,97,-5},
++ {133,99,-27},{133,100,-27},{133,101,-27},{133,102,-4},{133,103,-24},{133,111,-27},{133,113,-24},{133,115,-22},
++ {133,116,-4},{133,118,-5},{133,119,-5},{133,120,-4},{133,121,-5},
++};
++const struct fos_font fos_font_mdb_data = { mdb_bits, mdb_glyphs, mdb_lut, mdb_kern, 501, 20, 4 };
++
++static const uint8_t lg_bits[] = {
++ 130,14,31,1,132,47,1,132,14,31,1,132,14,31,1,132,14,31,133,13,31,133,13,31,
++ 133,13,15,14,133,12,15,14,133,12,15,14,133,11,15,13,133,11,15,13,133,10,15,12,
++ 150,1,11,14,9,132,6,47,3,131,6,47,3,131,1,11,14,9,130,6,31,7,128,10,
++ 31,3,6,31,7,128,10,31,3,5,31,6,128,9,31,2,4,31,6,128,8,31,1,3,
++ 31,5,128,7,31,1,2,31,4,128,6,15,14,245,132,2,20,3,130,3,20,1,134,8,
++ 31,9,130,14,31,4,134,11,31,7,129,1,47,1,134,13,31,4,129,3,31,14,135,47,
++ 2,129,6,31,12,132,7,127,79,11,130,7,127,79,11,130,5,11,13,31,13,43,47,12,
++ 11,7,132,10,31,8,130,47,2,134,12,31,5,129,2,47,135,14,31,3,129,4,31,13,
++ 132,5,27,47,43,12,31,14,11,8,130,7,127,79,12,130,7,127,79,11,132,8,31,9,
++ 130,14,31,3,134,11,31,6,129,1,47,1,134,13,31,4,129,3,31,14,135,47,2,129,
++ 6,31,11,135,35,130,1,19,2,132,133,12,15,14,139,12,15,14,137,1,5,14,15,14,
++ 6,2,134,7,111,9,1,131,9,127,15,11,130,3,47,7,2,1,3,9,47,6,129,7,
++ 31,8,132,7,31,12,129,8,31,6,132,1,31,14,129,7,31,10,133,9,10,9,129,2,
++ 47,10,2,137,8,63,10,4,136,7,14,63,13,6,135,1,8,14,63,13,3,136,6,12,
++ 47,14,2,137,5,13,31,10,129,9,27,133,2,47,129,13,31,1,133,13,31,1,128,11,
++ 31,8,132,2,47,129,6,47,9,3,17,4,12,31,11,130,12,127,31,3,130,1,10,111,
++ 13,4,133,3,8,14,31,9,5,1,136,11,31,139,11,31,133,130,2,10,30,11,4,132,
++ 1,13,15,4,133,2,14,31,14,31,5,131,8,15,12,134,11,15,9,129,6,15,14,130,
++ 2,14,15,3,134,15,14,131,12,15,3,129,9,15,10,135,14,15,1,130,12,15,3,128,
++ 3,31,2,135,10,15,10,2,1,8,15,13,129,11,15,8,136,2,13,63,14,4,128,4,
++ 15,14,1,137,1,8,28,9,2,129,12,15,7,145,6,15,13,145,1,13,15,5,145,7,
++ 15,12,145,1,14,15,4,129,7,13,15,13,7,138,9,15,10,129,10,31,14,31,10,136,
++ 2,31,2,128,5,15,13,2,128,2,13,15,5,135,11,15,9,129,9,15,6,130,6,15,
++ 9,134,4,15,14,1,129,9,15,6,130,6,15,9,134,12,15,7,130,5,15,13,2,128,
++ 2,13,15,5,133,5,15,13,1,131,10,31,14,31,10,134,13,15,5,133,7,13,15,13,
++ 7,130,131,2,9,13,15,14,11,6,138,4,14,95,11,1,135,1,14,31,14,11,12,47,
++ 8,135,5,31,14,2,129,6,31,14,135,6,31,11,130,1,47,1,134,4,31,14,1,129,
++ 5,31,14,136,13,31,11,128,4,14,31,9,136,3,47,12,47,13,1,137,6,79,12,2,
++ 137,1,9,63,11,138,2,13,79,14,3,130,2,133,13,31,14,6,10,31,14,2,128,2,
++ 14,12,3,130,7,31,14,3,129,11,31,13,2,12,31,9,130,11,31,7,130,1,12,79,
++ 13,1,130,12,31,6,131,1,13,47,14,2,131,11,31,12,1,129,1,6,14,47,10,132,
++ 6,47,14,11,12,14,95,6,132,9,127,12,8,47,3,132,4,10,13,15,14,13,9,4,
++ 129,8,31,13,1,128,6,31,10,6,31,10,5,31,9,4,31,8,3,31,7,2,31,6,
++ 179,130,1,13,31,2,132,8,31,11,132,2,47,4,132,8,31,13,133,13,31,8,132,3,
++ 47,3,132,7,47,133,10,31,12,133,13,31,10,133,14,31,9,133,47,8,133,47,7,133,
++ 47,8,133,14,31,9,133,13,31,10,133,10,31,12,133,7,47,133,4,47,3,133,14,31,
++ 8,133,8,31,13,133,2,47,3,133,8,31,11,133,1,13,31,3,129,129,10,31,7,132,
++ 3,47,2,132,10,31,10,132,5,47,1,131,1,14,31,7,132,10,31,12,132,7,47,1,
++ 131,4,47,4,131,2,47,6,131,1,47,7,132,47,8,132,14,31,9,132,47,8,131,1,
++ 47,7,131,2,47,6,131,4,47,3,131,7,31,14,132,10,31,11,131,1,14,31,6,131,
++ 5,47,1,131,11,31,9,131,3,31,14,2,131,9,31,6,130,131,8,15,4,132,2,129,
++ 8,15,4,128,17,128,1,14,12,3,8,15,4,5,13,10,128,2,13,31,14,15,14,31,
++ 11,130,6,14,47,12,4,131,6,14,47,12,4,129,2,13,31,14,15,13,31,11,128,1,
++ 14,12,3,8,15,4,5,13,10,129,2,129,8,15,4,128,17,132,8,15,4,252,132,10,
++ 15,14,137,11,31,137,11,31,137,11,31,137,11,31,132,2,127,47,5,2,127,47,5,1,
++ 10,43,14,31,59,3,132,11,31,137,11,31,137,11,31,137,10,15,14,158,129,10,31,1,
++ 130,13,15,13,131,31,9,130,2,31,5,130,5,31,1,130,7,15,13,131,9,15,8,130,
++ 1,10,107,10,128,2,127,15,128,2,127,15,205,129,9,14,11,1,129,4,47,6,129,4,
++ 47,6,130,9,14,11,1,128,134,11,31,5,134,2,31,14,1,134,7,31,10,135,12,31,
++ 4,134,3,31,14,135,8,31,9,135,13,31,3,134,4,31,13,135,9,31,7,134,1,14,
++ 31,2,134,5,31,12,135,11,31,6,134,1,47,1,134,6,31,10,135,12,31,5,134,2,
++ 31,14,135,8,31,9,135,13,31,4,134,3,31,13,135,131,5,11,14,15,14,12,7,1,
++ 132,1,11,111,13,3,131,9,47,14,11,13,47,13,1,129,2,47,8,130,4,47,7,129,
++ 6,31,13,132,8,31,11,129,7,31,10,132,5,31,12,129,8,31,9,132,4,31,13,129,
++ 8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,
++ 8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,8,31,9,132,4,31,13,129,
++ 7,31,10,132,5,31,12,129,6,31,13,132,8,31,11,129,2,47,8,130,4,47,6,130,
++ 9,47,14,11,13,47,13,1,131,11,111,13,2,133,5,11,14,15,14,12,7,1,130,129,
++ 1,7,14,31,9,130,6,14,63,10,130,12,79,10,130,11,12,8,10,31,10,133,7,31,
++ 10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,
++ 10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,10,133,7,31,
++ 10,133,7,31,10,133,7,31,9,129,130,1,7,12,14,15,13,9,3,133,3,14,111,8,
++ 131,1,14,47,12,11,14,47,6,130,7,31,14,4,129,1,11,31,13,130,10,31,9,131,
++ 2,47,1,129,11,31,6,131,1,47,2,129,2,20,1,131,5,31,14,137,1,13,31,9,
++ 137,10,31,14,2,136,7,47,6,136,5,47,10,136,3,14,31,12,136,2,14,31,13,1,
++ 135,1,13,31,14,2,135,1,11,31,14,3,136,10,47,4,136,8,47,14,107,6,129,10,
++ 127,47,9,129,9,127,47,9,128,128,9,127,31,11,129,10,127,31,12,129,6,91,13,47,
++ 11,135,3,14,31,14,3,134,4,14,31,14,3,134,4,14,31,14,3,134,4,14,31,14,
++ 3,135,14,63,11,5,134,6,95,8,134,6,1,128,6,47,3,137,9,31,9,137,5,31,
++ 13,129,3,20,132,3,31,14,129,14,31,4,131,4,31,13,129,11,31,8,131,8,31,11,
++ 129,6,31,14,3,129,3,14,31,7,130,13,47,28,47,13,131,2,13,95,13,3,132,1,
++ 7,12,30,12,7,1,130,133,13,31,6,138,5,31,14,1,138,12,31,8,138,4,47,1,
++ 138,11,31,9,138,3,47,3,138,9,31,11,138,1,47,4,129,4,31,12,132,8,31,12,
++ 130,5,31,12,131,1,14,31,5,130,5,31,12,131,6,31,13,131,5,31,12,131,13,31,
++ 14,60,13,47,12,5,129,127,79,6,129,14,127,63,6,137,5,31,13,139,5,31,12,139,
++ 5,31,12,139,5,31,12,139,4,31,12,130,128,8,127,31,8,129,9,127,31,8,129,9,
++ 31,13,107,5,129,9,31,8,137,9,31,8,137,9,31,8,137,9,31,8,137,9,31,8,
++ 7,12,14,13,11,4,131,9,127,15,9,130,9,63,12,11,14,47,6,129,9,47,4,130,
++ 10,31,13,129,3,22,4,131,2,47,2,137,47,3,128,2,20,2,132,47,3,128,8,31,
++ 12,131,4,47,1,128,3,47,6,129,1,12,31,12,130,10,47,13,11,14,47,4,130,1,
++ 11,111,6,133,5,11,30,13,9,3,130,130,1,8,12,30,13,9,3,132,3,14,111,6,
++ 130,1,14,47,28,63,3,129,6,47,4,129,2,13,31,9,129,9,31,10,131,7,31,12,
++ 129,9,31,8,131,2,24,6,129,9,31,8,137,9,31,8,7,13,15,14,11,5,131,9,
++ 127,15,9,130,9,63,12,11,14,47,6,129,9,47,5,129,1,11,31,12,129,9,31,11,
++ 131,3,47,1,128,9,31,8,132,14,31,3,128,9,31,8,132,14,31,3,128,7,31,11,
++ 131,3,47,1,128,2,47,5,129,1,11,31,11,130,10,47,12,11,14,47,4,130,1,11,
++ 111,7,133,6,11,14,15,13,10,3,130,4,127,47,10,4,127,47,11,4,31,12,75,14,
++ 31,10,4,31,4,132,13,31,6,1,22,1,131,4,47,1,135,10,31,10,135,1,47,4,
++ 135,6,31,14,136,12,31,8,135,3,47,2,135,8,31,12,136,14,31,6,135,5,47,1,
++ 135,10,31,10,135,1,47,4,135,7,31,14,136,12,31,8,135,3,47,2,135,8,31,12,
++ 133,131,7,12,14,15,13,9,3,132,2,13,111,6,131,12,47,12,11,14,47,2,129,4,
++ 47,4,129,1,12,31,9,129,7,31,10,131,4,31,12,129,7,31,10,131,4,31,12,129,
++ 4,47,4,129,1,12,31,8,130,11,47,28,14,31,14,2,130,1,13,111,3,131,7,127,
++ 12,130,2,47,8,1,128,4,14,31,8,129,8,31,11,131,5,31,13,129,11,31,7,131,
++ 1,47,1,128,12,31,7,131,1,47,2,128,10,31,10,131,4,47,129,6,47,4,129,1,
++ 12,31,11,130,13,47,12,11,14,47,4,130,2,13,111,6,132,1,7,12,14,15,13,9,
++ 3,130,130,2,8,12,30,12,7,1,132,4,14,95,13,2,130,1,14,47,11,12,47,13,
++ 130,8,31,13,2,129,2,14,31,6,129,12,31,6,131,8,31,11,129,14,31,3,131,4,
++ 31,12,129,14,31,3,131,5,31,13,129,13,31,6,131,8,31,13,129,9,31,13,2,129,
++ 3,14,31,13,129,3,63,11,12,63,13,130,6,95,14,31,13,131,3,10,14,15,13,9,
++ 5,31,13,137,4,31,13,129,4,24,5,131,4,31,13,129,8,31,11,131,6,31,12,129,
++ 6,47,4,129,2,13,31,10,129,1,14,47,28,63,3,130,3,14,111,6,132,1,8,12,
++ 30,13,9,3,130,130,7,14,12,2,132,1,47,8,132,1,47,8,133,7,14,12,2,173,
++ 7,14,12,2,132,1,47,8,132,1,47,8,133,7,14,12,2,140,129,3,12,14,9,131,
++ 12,47,5,130,12,47,5,130,3,12,14,9,163,1,31,10,131,3,31,8,131,4,31,4,
++ 131,6,31,1,131,8,15,13,132,9,15,10,132,10,15,6,130,137,2,8,4,135,3,9,
++ 31,5,133,4,11,63,5,131,5,12,63,14,8,1,128,1,7,13,63,12,5,130,1,14,
++ 47,14,9,3,132,2,47,10,1,134,2,63,12,5,134,4,11,63,13,7,1,133,3,10,
++ 79,9,3,133,2,8,14,63,4,134,1,7,13,31,5,137,5,12,5,140,1,125,45,4,
++ 2,127,47,5,2,127,47,5,166,1,125,45,4,2,127,47,5,2,127,47,5,179,1,9,
++ 3,137,2,31,11,4,135,2,63,12,6,134,6,12,63,13,7,1,133,4,10,63,14,8,
++ 2,133,2,8,14,63,4,135,7,47,5,133,4,10,63,5,131,6,12,63,13,6,129,2,
++ 8,14,63,11,4,130,1,79,10,3,132,2,31,14,8,2,134,2,13,7,1,149,130,3,
++ 9,13,30,12,8,1,132,8,111,14,3,130,6,47,14,11,12,47,13,1,129,13,31,10,
++ 1,129,4,47,5,128,1,47,2,131,11,31,8,128,1,29,12,132,11,31,8,136,3,47,
++ 5,135,4,14,31,12,135,8,47,13,2,134,8,47,9,1,134,2,47,7,136,4,31,13,
++ 137,4,31,12,165,2,12,14,6,137,10,47,137,10,31,14,137,2,13,14,6,133,135,5,
++ 9,12,30,13,11,7,1,138,6,13,127,15,6,135,1,10,31,12,6,3,1,128,2,5,
++ 11,31,10,133,1,12,15,14,5,135,6,31,7,132,10,15,14,2,137,7,31,2,130,4,
++ 31,3,129,2,9,12,11,6,11,13,3,129,13,15,7,130,12,15,8,129,3,14,95,2,
++ 129,9,15,11,129,2,31,2,129,12,15,10,18,12,31,130,7,15,13,129,6,15,12,129,
++ 2,15,14,1,129,6,15,13,130,6,15,13,129,9,15,9,129,6,15,11,130,7,15,11,
++ 130,7,15,12,129,11,15,8,129,8,15,8,130,9,15,9,130,11,15,9,129,11,15,7,
++ 129,9,15,8,130,13,15,9,129,1,14,15,5,129,10,15,9,129,7,15,13,2,128,8,
++ 31,13,2,1,11,15,13,130,8,15,12,129,2,14,63,14,79,14,4,130,4,31,2,129,
++ 3,11,30,10,2,4,12,15,14,11,3,132,13,15,11,146,3,31,10,1,134,2,137,7,
++ 31,13,7,3,18,3,7,12,14,2,137,5,14,127,13,4,138,1,7,11,14,15,14,13,
++ 10,5,1,134,133,5,47,12,140,10,63,2,138,1,79,7,138,5,79,12,138,10,31,11,
++ 47,2,137,14,31,4,13,31,7,136,4,31,14,128,8,31,12,136,9,31,10,128,3,47,
++ 1,135,14,31,6,129,14,31,6,134,4,47,1,129,9,31,11,134,9,31,11,130,5,47,
++ 1,133,13,31,7,130,1,14,31,6,132,3,47,2,131,10,31,10,132,8,47,71,11,31,
++ 14,1,131,13,127,63,5,130,2,127,79,10,130,7,31,14,134,6,31,14,130,12,31,9,
++ 134,1,47,4,128,1,47,3,135,11,31,9,128,129,111,14,13,10,4,133,127,47,9,132,
++ 47,59,12,63,6,131,47,2,131,2,12,31,12,131,47,2,132,3,31,14,131,47,2,132,
++ 1,47,131,47,2,132,5,31,12,131,47,2,130,1,5,14,31,6,131,127,47,7,132,127,
++ 31,12,2,132,47,59,12,14,31,14,3,131,47,2,131,1,10,31,12,131,47,2,132,1,
++ 47,2,130,47,2,133,13,31,4,130,47,2,132,1,47,3,130,47,2,131,1,10,31,14,
++ 1,130,47,75,14,47,8,131,127,47,10,132,127,13,10,4,131,131,2,7,12,14,15,13,
++ 10,5,134,5,14,111,12,2,131,4,63,12,11,14,47,13,1,130,13,31,12,2,130,6,
++ 47,7,129,4,31,14,2,132,8,31,12,129,6,31,11,133,3,47,129,7,31,10,134,22,
++ 5,129,7,31,10,139,7,31,10,139,7,31,10,139,7,31,10,139,7,31,10,139,7,31,
++ 10,134,5,6,5,129,6,31,11,133,3,31,14,129,4,31,14,2,132,8,31,12,130,13,
++ 31,12,2,130,6,47,7,130,4,63,12,11,14,47,12,1,131,5,14,111,12,2,133,2,
++ 7,12,14,15,13,10,5,131,129,111,14,13,8,2,133,127,47,7,132,47,59,12,63,6,
++ 131,47,2,131,2,12,31,13,131,47,2,132,3,47,3,130,47,2,133,14,31,4,130,47,
++ 2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,
++ 31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,47,2,133,12,31,5,130,
++ 47,2,133,14,31,4,130,47,2,132,3,47,3,130,47,2,131,2,12,31,13,131,47,59,
++ 12,63,6,131,127,47,7,132,111,14,13,9,3,131,129,127,63,11,130,127,63,12,130,47,
++ 123,11,8,130,47,2,139,47,2,139,47,2,139,47,2,139,47,2,139,127,15,11,133,127,
++ 15,11,133,47,91,7,133,47,2,139,47,2,139,47,2,139,47,2,139,47,2,139,47,123,
++ 11,8,130,127,63,12,130,127,63,11,128,129,127,63,11,129,127,63,11,129,47,123,11,7,
++ 129,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,127,15,11,132,127,15,11,132,
++ 47,91,7,132,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,
++ 138,47,1,136,131,2,7,12,14,15,13,11,5,135,5,14,111,12,2,132,4,63,13,11,
++ 13,47,13,1,131,13,31,12,2,130,5,14,31,8,130,4,31,14,2,132,6,31,13,130,
++ 6,31,11,133,2,47,130,7,31,10,134,33,130,7,31,10,140,7,31,10,130,9,75,10,
++ 130,7,31,10,130,13,95,130,7,31,10,130,13,95,130,7,31,10,133,2,47,130,7,31,
++ 10,133,1,47,130,6,31,11,133,3,31,14,130,3,31,14,1,132,7,31,11,131,13,31,
++ 12,3,130,5,14,31,5,131,4,63,13,11,13,47,11,133,5,14,111,11,1,134,2,7,
++ 12,14,15,14,11,5,132,129,47,1,133,10,31,5,130,47,2,133,11,31,6,130,47,2,
++ 133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,
++ 6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,127,79,6,130,127,79,6,130,
++ 47,107,14,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,
++ 31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,47,2,133,11,31,6,130,
++ 47,2,133,11,31,6,130,47,1,133,11,31,5,128,129,47,1,130,47,2,130,47,2,130,
++ 47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,
++ 47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,2,130,47,1,128,
++ 137,5,31,10,139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,
++ 139,6,31,11,139,6,31,11,139,6,31,11,139,6,31,11,130,33,133,6,31,11,129,6,
++ 31,11,133,6,31,11,129,6,31,11,133,6,31,11,129,5,31,12,133,7,31,10,129,3,
++ 47,2,132,11,31,8,130,13,31,12,2,130,8,47,3,130,5,63,12,11,14,47,9,132,
++ 6,127,10,134,2,8,12,30,13,10,4,132,129,47,1,132,1,13,31,8,130,47,2,132,
++ 12,31,12,131,47,2,131,10,31,14,1,131,47,2,130,7,47,3,132,47,2,129,5,47,
++ 6,133,47,2,128,3,14,31,9,134,47,18,13,31,11,135,47,2,12,31,13,1,135,47,
++ 12,47,10,136,127,4,135,63,14,11,31,13,1,134,63,4,1,14,31,8,134,47,6,129,
++ 5,47,3,133,47,2,130,11,31,12,133,47,2,130,2,14,31,7,132,47,2,131,6,47,
++ 2,131,47,2,132,12,31,11,131,47,2,132,2,47,6,130,47,1,133,7,31,14,1,129,
++ 47,1,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,
++ 47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,47,2,138,
++ 47,123,11,6,129,127,63,9,129,127,63,9,129,47,5,134,2,14,31,4,130,47,14,1,
++ 133,10,47,5,130,63,10,132,5,63,5,130,79,5,130,1,14,63,5,130,79,13,1,129,
++ 10,79,5,130,47,14,31,9,128,5,47,14,31,5,130,47,5,47,5,13,31,8,12,31,
++ 5,130,47,2,9,79,13,128,12,31,5,130,47,2,1,13,63,4,128,12,31,5,130,47,
++ 2,128,4,47,9,129,12,31,5,130,47,2,129,9,15,13,1,129,12,31,5,130,47,2,
++ 130,2,1,130,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,5,130,47,2,
++ 135,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,5,130,47,2,135,12,31,
++ 5,130,47,1,135,12,31,4,128,129,47,4,134,47,1,130,47,12,133,1,47,1,130,63,
++ 7,132,1,47,1,130,63,14,2,131,1,47,1,130,79,10,131,1,47,1,130,95,4,130,
++ 1,47,1,130,47,8,31,13,131,47,1,130,47,1,13,31,7,130,47,1,130,47,1,4,
++ 31,14,2,129,47,1,130,47,1,128,10,31,10,129,47,1,130,47,1,128,2,14,31,4,
++ 128,47,1,130,47,1,129,7,31,13,1,47,1,130,47,1,130,12,31,8,47,1,130,47,
++ 1,130,4,95,1,130,47,1,131,9,79,1,130,47,1,131,1,14,63,1,130,47,1,132,
++ 6,63,1,130,47,2,133,12,47,1,130,47,1,133,3,14,31,1,128,131,1,7,12,14,
++ 15,13,11,5,135,4,14,111,12,2,132,3,63,12,11,13,47,13,1,131,12,31,13,2,
++ 130,4,14,31,8,130,3,47,2,132,5,31,14,130,6,31,11,134,47,2,129,7,31,10,
++ 134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,
++ 134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,134,13,31,4,129,7,31,10,
++ 134,13,31,3,129,6,31,11,134,47,2,129,3,47,2,132,5,31,14,131,12,31,12,2,
++ 130,4,14,31,8,131,3,63,12,11,13,47,13,1,132,4,14,111,12,2,134,1,7,12,
++ 14,15,13,11,6,132,128,2,127,13,10,4,131,3,127,47,8,130,3,47,59,12,14,47,
++ 5,129,3,31,14,132,2,12,31,12,129,3,31,14,133,2,47,2,128,3,31,14,134,14,
++ 31,4,128,3,31,14,134,14,31,3,128,3,31,14,133,4,47,1,128,3,31,14,131,1,
++ 5,14,31,11,129,3,127,47,14,3,129,3,127,31,13,4,130,3,47,59,10,9,5,1,
++ 131,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,139,3,31,14,
++ 139,2,31,14,138,131,3,9,13,30,12,8,2,134,7,111,14,5,132,6,47,14,11,12,
++ 63,4,130,1,47,10,1,129,1,12,31,13,130,6,31,13,1,131,2,14,31,4,129,9,
++ 31,8,133,11,31,7,129,11,31,6,133,8,31,8,129,11,31,6,133,8,31,9,129,11,
++ 31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,
++ 31,6,133,8,31,9,129,11,31,6,133,8,31,9,129,11,31,7,133,9,31,8,129,9,
++ 31,9,133,11,31,7,129,5,31,14,2,131,4,47,3,130,13,31,13,4,17,5,14,31,
++ 11,131,3,14,127,13,2,132,3,12,95,11,2,135,3,12,31,10,2,138,9,31,8,139,
++ 9,31,7,133,129,127,14,11,5,133,127,47,9,132,47,75,14,47,7,131,47,2,131,1,
++ 10,31,14,131,47,2,132,1,47,3,130,47,2,133,13,31,4,130,47,2,132,1,47,3,
++ 130,47,2,131,1,10,31,14,1,130,47,75,14,47,8,131,127,47,10,132,127,15,13,5,
++ 133,47,2,129,3,31,13,134,47,2,130,11,31,6,133,47,2,130,4,31,13,133,47,2,
++ 131,12,31,6,132,47,2,131,5,31,13,132,47,2,132,13,31,6,131,47,2,132,6,31,
++ 13,131,47,1,133,13,31,5,128,131,6,11,14,15,14,12,8,3,133,2,12,127,9,132,
++ 12,47,13,11,12,63,9,130,5,31,14,4,130,1,9,47,3,129,8,31,9,133,11,31,
++ 7,129,7,31,9,133,7,31,9,129,5,31,14,3,132,1,20,2,130,12,47,10,3,137,
++ 1,12,63,13,7,2,136,6,13,79,10,2,136,4,10,63,14,4,137,1,7,14,31,14,
++ 2,129,4,21,1,132,2,13,31,8,129,13,31,3,133,6,31,11,129,11,31,7,133,8,
++ 31,10,129,7,47,6,131,4,14,31,7,129,1,13,47,14,12,11,13,47,14,1,130,2,
++ 12,127,13,3,133,5,10,13,14,15,14,11,6,1,130,1,127,79,10,128,1,127,79,11,
++ 128,1,10,59,14,31,12,59,7,134,13,31,4,139,13,31,4,139,13,31,4,139,13,31,
++ 4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,
++ 4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,13,31,4,139,12,31,
++ 4,133,128,2,31,14,134,11,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
++ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
++ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
++ 31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,31,5,129,3,31,14,134,12,
++ 31,5,129,3,31,14,134,12,31,5,129,1,47,1,133,13,31,4,130,14,31,6,132,4,
++ 47,2,130,9,31,14,5,130,3,13,31,11,131,1,13,47,13,11,13,47,14,3,132,2,
++ 12,111,14,4,135,6,11,13,15,14,12,7,1,131,1,47,3,134,10,31,9,128,12,31,
++ 8,134,14,31,5,128,8,31,12,133,4,31,14,129,3,47,1,132,8,31,10,130,13,31,
++ 5,132,12,31,5,130,9,31,10,131,1,47,1,130,4,31,14,131,6,31,11,132,14,31,
++ 3,130,10,31,6,132,10,31,8,130,14,31,2,132,5,31,12,129,3,31,12,133,1,47,
++ 1,128,8,31,7,134,11,31,5,128,12,31,3,134,6,31,10,1,31,13,135,2,31,14,
++ 5,31,8,136,12,31,13,31,3,136,7,63,14,137,3,63,9,138,13,47,4,138,8,31,
++ 14,133,3,47,1,132,13,31,8,132,3,31,14,129,14,31,5,131,2,47,12,132,7,31,
++ 11,129,11,31,8,131,5,63,1,131,11,31,7,129,7,31,12,131,9,63,5,131,14,31,
++ 3,129,3,47,1,130,13,63,8,130,3,31,14,131,14,31,4,129,1,31,14,31,12,130,
++ 7,31,10,131,10,31,8,129,5,31,9,14,31,1,129,11,31,7,131,6,31,12,129,8,
++ 31,5,10,31,5,129,14,31,3,131,2,47,1,128,12,31,2,7,31,9,128,3,31,14,
++ 133,13,31,4,1,31,13,128,3,31,12,128,6,31,10,133,9,31,8,4,31,10,129,14,
++ 31,1,10,31,6,133,5,31,12,7,31,6,129,11,31,5,14,31,2,133,1,47,12,31,
++ 3,129,7,31,11,31,14,135,12,63,14,130,3,79,10,135,8,63,11,131,14,63,6,135,
++ 4,63,7,131,11,63,2,136,14,47,4,131,7,47,13,137,11,47,132,4,47,10,137,6,
++ 31,11,133,14,31,5,132,128,14,31,7,134,12,31,8,129,6,31,14,1,132,6,31,14,
++ 1,130,12,31,10,131,1,14,31,6,131,3,47,3,130,9,31,12,133,9,31,12,129,3,
++ 47,3,133,1,14,31,6,128,11,31,9,135,6,31,14,6,31,14,1,136,12,79,7,137,
++ 4,63,13,139,11,47,6,138,3,63,12,138,12,79,6,136,6,31,14,7,31,14,1,134,
++ 1,14,31,6,128,12,31,9,134,9,31,12,129,3,47,3,132,3,47,3,130,9,31,12,
++ 132,11,31,9,131,1,14,31,6,130,5,31,14,1,132,6,31,14,1,129,13,31,6,134,
++ 12,31,8,128,1,14,31,5,133,2,14,31,3,128,8,31,12,133,10,31,11,129,1,14,
++ 31,5,131,2,47,3,130,7,31,12,131,10,31,10,131,1,14,31,5,129,2,47,3,132,
++ 7,31,12,129,10,31,10,133,1,14,31,4,2,47,2,134,7,31,12,10,31,9,135,1,
++ 14,79,2,136,6,63,9,138,13,47,2,138,8,31,10,139,8,31,10,139,8,31,10,139,
++ 8,31,10,139,8,31,10,139,8,31,10,139,8,31,10,139,7,31,9,133,128,127,63,12,
++ 129,127,63,12,129,10,123,14,31,12,137,3,47,5,136,1,13,31,10,137,9,31,13,1,
++ 136,4,47,4,136,1,14,31,8,137,10,31,12,137,6,47,3,136,2,14,31,7,137,11,
++ 31,12,137,7,31,14,2,136,3,47,6,137,12,31,10,137,8,31,14,1,137,47,13,123,
++ 8,129,127,63,12,129,127,63,12,128,1,95,7,130,1,95,8,130,1,47,43,5,130,1,
++ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
++ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
++ 47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,47,1,133,1,
++ 47,1,133,1,47,43,5,130,1,95,8,130,1,95,8,130,128,4,31,12,136,14,31,2,
++ 135,9,31,8,135,4,31,13,136,13,31,3,135,8,31,9,135,2,31,14,136,12,31,5,
++ 135,7,31,10,135,1,47,1,135,11,31,6,135,6,31,11,135,1,14,31,2,135,10,31,
++ 7,135,4,31,12,136,14,31,3,135,9,31,8,135,3,31,13,136,13,31,3,130,9,79,
++ 14,131,9,95,131,6,27,12,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,
++ 134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,
++ 134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,134,3,47,131,6,43,47,131,9,
++ 95,131,9,79,14,128,131,4,31,11,136,10,47,2,134,1,14,47,8,134,6,31,12,15,
++ 13,134,11,15,12,4,31,4,132,2,31,7,128,14,15,9,132,7,31,2,128,9,15,14,
++ 1,131,13,15,12,129,3,31,6,130,3,31,6,130,13,15,11,130,9,31,1,130,8,31,
++ 2,129,14,15,11,131,2,31,7,232,4,123,43,10,1,6,127,63,2,6,127,63,2,1,
++ 14,15,12,130,4,31,6,130,7,15,14,1,223,130,3,9,13,15,14,12,8,2,132,7,
++ 111,14,4,130,4,47,14,27,14,31,14,1,129,10,31,13,1,129,1,13,31,7,130,2,
++ 4,3,131,8,31,9,131,2,7,26,27,13,31,10,130,9,127,15,10,129,8,127,31,10,
++ 129,14,31,11,4,1,129,8,31,10,128,2,47,2,131,9,31,10,128,1,47,5,130,5,
++ 14,31,10,129,13,47,12,11,13,63,10,129,4,111,12,31,10,130,3,10,14,15,14,10,
++ 3,7,31,9,128,128,4,31,12,138,4,31,12,138,4,31,12,138,4,31,12,138,4,31,
++ 12,138,4,31,12,2,10,30,12,7,1,131,4,31,30,79,12,1,130,4,63,14,11,13,
++ 47,10,130,4,47,12,1,129,8,47,3,129,4,47,5,131,14,31,7,129,4,47,132,9,
++ 31,10,129,4,31,14,132,7,31,11,129,4,31,14,132,7,31,11,129,4,47,132,9,31,
++ 10,129,4,47,4,131,13,31,7,129,4,47,12,1,129,7,47,2,129,4,63,14,11,13,
++ 47,10,130,4,31,30,79,12,1,130,4,31,12,2,10,30,12,7,131,131,5,11,14,15,
++ 14,10,4,133,10,111,10,131,9,47,13,11,13,47,9,129,2,47,7,130,8,47,2,128,
++ 7,31,12,132,13,15,14,4,128,9,31,8,132,2,1,130,10,31,7,137,10,31,7,137,
++ 9,31,8,132,1,131,6,31,12,132,14,15,12,3,128,2,47,7,130,8,47,1,129,8,
++ 47,13,11,13,47,9,131,9,111,10,133,5,11,14,15,14,10,5,130,137,11,31,5,138,
++ 12,31,5,138,12,31,5,138,12,31,5,138,12,31,5,132,6,12,30,11,3,12,31,5,
++ 130,1,11,79,30,31,5,130,9,47,13,11,14,63,5,129,2,47,9,129,1,11,47,5,
++ 129,6,31,14,1,130,3,47,5,129,9,31,10,132,14,31,5,129,10,31,9,132,13,31,
++ 5,129,10,31,8,132,13,31,5,129,8,31,10,132,14,31,5,129,6,31,14,131,3,47,
++ 5,129,1,47,8,129,1,11,47,5,130,9,47,13,11,14,63,5,130,1,11,95,14,31,
++ 5,132,6,12,30,11,3,11,31,5,128,131,5,11,14,15,14,10,4,134,10,111,9,132,
++ 9,47,12,11,13,47,6,130,2,47,4,130,8,31,13,130,7,31,10,132,14,31,2,129,
++ 9,31,13,75,14,31,5,129,10,127,47,6,129,9,127,47,6,129,8,31,8,138,5,31,
++ 12,132,1,2,131,1,14,31,8,130,2,12,14,4,131,6,47,14,11,12,47,13,132,8,
++ 111,13,3,133,4,10,13,15,14,12,7,1,130,131,6,11,14,31,1,130,6,79,2,130,
++ 13,47,12,10,1,130,47,5,132,1,47,1,130,3,127,2,3,127,3,2,27,47,43,2,
++ 129,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,
++ 132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,1,132,1,47,131,130,1,8,12,
++ 30,11,3,13,31,3,130,1,13,127,15,4,130,11,47,13,11,14,63,4,129,4,47,7,
++ 129,1,11,47,4,129,8,31,12,131,3,47,4,129,10,31,8,132,14,31,4,129,11,31,
++ 7,132,13,31,4,129,11,31,6,132,13,31,4,129,10,31,8,132,14,31,4,129,9,31,
++ 11,131,2,47,4,129,5,47,7,129,1,10,47,4,130,13,47,13,11,14,63,4,130,2,
++ 13,127,15,4,131,1,7,12,30,11,3,14,31,3,137,2,47,1,136,1,11,31,12,133,
++ 6,27,12,63,4,133,10,79,14,5,134,9,31,14,11,7,1,131,128,4,31,12,138,5,
++ 31,12,138,5,31,12,138,5,31,12,138,5,31,12,138,5,31,12,2,10,14,15,13,8,
++ 1,131,5,31,30,79,13,1,130,5,63,13,11,14,47,9,130,5,47,9,129,1,11,31,
++ 14,130,5,31,14,131,3,47,1,129,5,31,12,131,1,47,1,129,5,31,12,132,47,1,
++ 129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,
++ 12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,4,31,12,132,47,
++ 1,128,129,3,7,3,130,3,31,14,2,129,6,47,5,129,3,31,14,2,130,3,7,3,
++ 137,2,31,14,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,
++ 47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,47,130,2,31,14,129,131,4,7,
++ 2,132,4,31,14,1,131,8,47,3,131,4,31,14,1,132,4,7,2,141,3,31,13,132,
++ 3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
++ 3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
++ 3,31,14,132,4,31,13,131,1,11,31,12,129,4,11,14,47,8,129,6,63,13,1,129,
++ 5,15,14,12,7,1,130,128,4,31,12,137,5,31,12,137,5,31,12,137,5,31,12,137,
++ 5,31,12,137,5,31,12,130,1,12,31,10,129,5,31,12,130,11,31,13,1,129,5,31,
++ 12,129,10,31,14,3,130,5,31,12,128,8,47,5,131,5,31,12,6,47,9,132,5,31,
++ 14,63,9,132,5,127,2,131,5,63,7,8,31,8,131,5,47,9,128,2,31,14,1,130,
++ 5,31,13,130,10,31,7,130,5,31,12,130,4,31,14,130,5,31,12,131,12,31,6,129,
++ 5,31,12,131,6,31,13,129,4,31,12,132,13,31,5,128,4,31,12,129,5,31,12,129,
++ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,
++ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,
++ 5,31,12,129,5,31,12,129,5,31,12,129,5,31,12,129,4,31,12,128,128,4,31,12,
++ 2,10,14,15,13,8,1,128,2,10,14,15,13,8,1,130,5,31,30,79,12,3,14,79,
++ 12,1,129,5,63,13,11,14,79,13,11,14,47,7,129,5,47,7,129,2,13,47,8,129,
++ 1,13,31,11,129,5,31,14,131,7,31,14,131,6,31,13,129,5,31,12,131,4,31,13,
++ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
++ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
++ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,5,31,12,131,4,31,12,
++ 131,4,31,13,129,5,31,12,131,4,31,12,131,4,31,13,129,4,31,12,131,4,31,12,
++ 131,3,31,13,128,128,4,31,12,3,10,14,15,13,8,1,131,5,31,30,79,13,1,130,
++ 5,63,13,11,14,47,9,130,5,47,9,129,1,11,31,14,130,5,31,14,131,3,47,1,
++ 129,5,31,12,131,1,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,
++ 31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,47,1,129,5,31,12,132,
++ 47,1,129,5,31,12,132,47,1,129,4,31,12,132,47,1,128,131,5,11,14,15,14,11,
++ 4,134,9,111,9,132,8,47,13,11,13,47,7,130,2,47,8,130,8,31,14,1,129,6,
++ 31,13,132,13,31,6,129,9,31,8,132,8,31,9,129,11,31,7,132,7,31,10,129,10,
++ 31,7,132,7,31,10,129,9,31,8,132,9,31,9,129,6,31,13,132,13,31,5,129,1,
++ 14,31,8,130,8,31,14,1,130,7,47,13,11,13,47,7,132,9,111,8,134,4,10,14,
++ 15,14,11,4,131,128,2,31,14,2,10,30,12,7,1,131,3,47,14,79,13,1,130,3,
++ 63,14,11,13,47,11,130,3,47,13,2,129,6,47,4,129,3,47,6,131,12,31,8,129,
++ 3,47,2,131,7,31,11,129,3,47,1,131,6,31,12,129,3,47,1,131,6,31,12,129,
++ 3,47,2,131,8,31,11,129,3,47,6,131,13,31,9,129,3,47,13,2,129,7,47,4,
++ 129,3,63,14,11,13,47,12,130,3,47,13,79,13,2,130,3,31,14,2,10,30,12,8,
++ 1,131,3,31,14,138,3,31,14,138,3,31,14,138,3,31,14,138,2,31,14,137,131,6,
++ 12,30,11,3,11,31,5,130,1,11,95,14,31,5,130,9,47,13,11,14,63,5,129,1,
++ 47,8,129,1,11,47,5,129,6,31,14,131,3,47,5,129,8,31,10,132,14,31,5,129,
++ 10,31,8,132,13,31,5,129,10,31,9,132,13,31,5,129,9,31,10,132,14,31,5,129,
++ 6,31,14,1,130,3,47,5,129,2,47,9,129,1,11,47,5,130,9,47,13,11,14,63,
++ 5,130,1,12,79,30,31,5,132,6,12,30,11,3,12,31,5,138,12,31,5,138,12,31,
++ 5,138,12,31,5,138,12,31,5,138,11,31,5,128,128,4,31,12,3,11,30,9,128,5,
++ 31,30,47,9,128,5,63,14,11,12,5,128,5,47,10,132,5,47,1,132,5,31,13,133,
++ 5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,5,31,12,133,
++ 5,31,12,133,4,31,12,132,130,5,11,14,15,14,12,7,132,10,111,13,1,129,6,47,
++ 13,11,12,47,10,129,10,31,8,130,3,47,1,128,10,31,6,131,6,24,1,128,5,47,
++ 10,5,1,134,7,79,11,6,133,2,8,13,63,13,3,134,2,7,13,31,13,1,128,7,
++ 25,1,131,13,31,4,128,12,31,8,130,3,14,31,4,128,7,47,14,11,12,47,14,1,
++ 129,10,127,5,131,5,10,13,15,14,13,9,2,129,129,1,7,8,5,133,3,31,12,133,
++ 3,31,12,133,3,31,12,131,3,111,14,128,3,127,128,2,11,12,31,14,27,10,130,3,
++ 31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,31,12,133,3,
++ 31,12,133,3,31,14,1,132,2,47,14,11,8,131,12,63,12,131,1,9,13,31,11,128,
++ 128,7,31,9,131,2,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
++ 130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
++ 130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,130,7,31,10,131,3,31,14,
++ 130,7,31,12,131,5,31,14,130,6,47,5,129,2,13,31,14,130,1,63,12,11,14,47,
++ 14,131,6,95,13,31,14,132,4,10,14,15,13,8,3,31,14,129,3,47,2,131,8,31,
++ 12,129,14,31,7,131,13,31,8,129,9,31,11,130,2,47,3,129,4,47,1,129,6,31,
++ 13,131,14,31,5,129,11,31,9,131,9,31,9,129,14,31,4,131,5,31,13,128,4,31,
++ 14,133,14,31,2,8,31,9,133,10,31,7,13,31,4,133,5,31,13,31,14,134,1,14,
++ 63,10,135,10,63,5,135,5,47,14,136,1,14,31,10,132,3,31,14,131,5,31,10,131,
++ 6,31,11,129,14,31,3,130,10,31,14,131,10,31,7,129,10,31,7,130,13,47,4,130,
++ 14,31,3,129,6,31,11,129,2,63,7,129,3,31,13,130,2,31,14,129,6,63,11,129,
++ 7,31,9,131,12,31,3,128,10,31,13,31,1,128,11,31,5,131,8,31,7,128,14,15,
++ 12,7,31,4,128,14,31,1,131,4,31,10,3,31,8,3,31,8,4,31,11,133,14,15,
++ 14,7,31,4,128,13,15,12,8,31,7,133,10,31,13,31,1,128,9,31,13,31,2,133,
++ 6,63,11,129,5,63,13,134,1,63,7,129,1,63,9,135,12,47,3,130,11,47,4,135,
++ 7,31,14,131,7,31,14,1,131,3,31,14,3,131,6,47,2,128,8,31,12,130,2,14,
++ 31,7,129,1,13,31,7,129,10,31,12,131,3,31,14,2,5,47,3,132,8,31,11,14,
++ 31,7,133,1,13,63,12,135,3,63,3,135,2,47,14,2,135,12,63,11,134,7,31,14,
++ 13,31,6,132,3,47,6,4,31,14,2,131,12,31,10,129,9,31,12,130,8,31,14,1,
++ 129,1,13,31,7,128,2,47,5,131,3,47,2,5,31,13,132,9,31,8,1,47,3,131,
++ 14,31,3,128,10,31,7,130,3,31,13,129,5,31,12,130,8,31,8,129,1,47,1,129,
++ 12,31,3,130,10,31,5,128,1,31,13,131,5,31,10,128,5,31,8,131,1,14,15,14,
++ 128,10,31,3,132,10,31,3,14,15,13,133,5,31,11,31,8,133,1,14,63,3,134,10,
++ 47,13,135,5,47,8,135,1,47,3,135,3,31,12,136,11,31,6,133,7,10,13,31,14,
++ 1,133,12,63,5,134,11,14,13,10,3,134,1,127,31,5,2,127,31,5,1,10,75,13,
++ 47,5,133,1,13,31,11,134,12,31,13,1,133,10,31,14,2,133,7,47,4,133,5,47,
++ 6,133,3,14,31,9,133,1,13,31,11,134,11,31,13,1,133,3,47,13,91,20,127,31,
++ 7,3,127,31,6,130,2,11,14,31,8,130,12,63,8,129,2,47,14,11,5,129,3,47,
++ 2,131,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,4,31,
++ 13,132,10,31,11,130,1,14,47,5,130,1,47,10,131,1,12,47,6,132,9,31,12,132,
++ 4,31,13,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,3,31,14,132,
++ 3,47,2,131,2,47,14,11,5,130,12,63,8,130,2,11,14,31,8,128,47,2,128,47,
++ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,
++ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,
++ 2,128,47,2,128,47,2,128,47,2,128,47,2,128,47,2,1,47,13,6,130,1,79,4,
++ 129,1,10,12,47,8,132,11,31,10,132,7,31,10,132,7,31,10,132,7,31,10,132,7,
++ 31,10,132,7,31,10,132,7,31,11,132,5,47,3,131,1,13,47,6,131,4,47,8,130,
++ 1,14,31,14,5,130,5,31,14,1,131,7,31,11,132,7,31,10,132,7,31,10,132,7,
++ 31,10,132,7,31,10,132,7,31,10,132,11,31,10,130,10,12,47,8,129,1,79,4,129,
++ 1,47,13,6,130,129,5,12,14,13,9,3,129,4,10,2,129,6,95,28,31,14,1,128,
++ 14,31,11,12,95,8,129,3,11,3,129,2,8,13,15,13,6,213,128,3,13,14,5,129,
++ 11,31,13,129,11,31,13,129,3,13,14,5,164,129,3,10,30,11,4,130,4,95,6,129,
++ 13,15,11,3,2,8,31,2,4,15,13,131,11,15,7,6,15,11,131,8,15,8,4,15,
++ 13,131,11,15,6,128,13,15,11,3,2,8,31,2,128,4,14,79,6,130,3,10,30,11,
++ 4,255,131,129,4,1,131,18,130,5,15,12,1,129,2,13,14,2,129,13,31,12,1,2,
++ 13,31,10,129,2,13,31,12,13,31,11,1,130,2,13,63,11,1,132,3,63,2,132,2,
++ 13,63,12,1,130,2,13,31,12,13,31,12,1,129,12,31,11,1,2,13,31,9,129,3,
++ 14,11,1,129,2,29,2,130,3,1,131,17,165,1,10,123,11,7,128,2,127,31,11,128,
++ 2,127,31,11,206,1,10,123,91,10,1,2,127,127,3,2,127,127,2,235,128,6,31,9,
++ 128,11,31,4,1,31,13,128,4,31,7,128,9,31,2,128,12,15,10,194,129,9,14,11,
++ 1,130,2,12,14,6,131,8,14,12,1,129,4,47,6,130,10,47,130,2,47,7,129,4,
++ 47,6,130,10,31,14,130,2,47,7,130,9,14,11,1,130,2,13,14,6,131,8,14,11,
++ 1,128,129,7,13,15,11,2,129,7,63,13,1,128,14,79,6,2,95,8,128,14,79,6,
++ 128,7,63,13,1,129,7,13,14,11,2,160,130,1,13,15,14,1,131,10,31,5,131,6,
++ 31,9,131,2,14,15,13,1,131,9,31,5,132,2,14,15,12,133,6,31,9,133,10,31,
++ 5,132,1,13,15,14,1,155,129,10,31,5,133,1,14,15,14,1,133,4,31,10,134,9,
++ 31,6,133,1,31,13,133,8,31,6,132,4,31,11,132,1,13,15,14,1,132,9,31,5,
++ 161,
++};
++static const struct fos_glyph lg_glyphs[] = {
++ { 0, 5, 0, 0, 0, 86 }, /* 0x20 */
++ { 0, 9, 19, 0, -19, 145 }, /* 0x21 */
++ { 67, 9, 19, 0, -19, 140 }, /* 0x22 */
++ { 110, 18, 19, 0, -19, 292 }, /* 0x23 */
++ { 250, 15, 24, 0, -22, 245 }, /* 0x24 */
++ { 401, 22, 19, 0, -19, 360 }, /* 0x25 */
++ { 602, 19, 19, 0, -19, 297 }, /* 0x26 */
++ { 774, 4, 19, 0, -19, 67 }, /* 0x27 */
++ { 793, 10, 23, -1, -20, 137 }, /* 0x28 */
++ { 883, 9, 23, 0, -20, 137 }, /* 0x29 */
++ { 977, 11, 21, 0, -21, 172 }, /* 0x2a */
++ { 1054, 13, 14, 0, -14, 212 }, /* 0x2b */
++ { 1100, 7, 7, 0, -5, 114 }, /* 0x2c */
++ { 1128, 11, 10, 0, -10, 175 }, /* 0x2d */
++ { 1141, 7, 4, 0, -4, 118 }, /* 0x2e */
++ { 1160, 12, 19, 0, -19, 193 }, /* 0x2f */
++ { 1239, 15, 19, 0, -19, 245 }, /* 0x30 */
++ { 1391, 10, 19, 0, -19, 152 }, /* 0x31 */
++ { 1474, 15, 19, 0, -19, 238 }, /* 0x32 */
++ { 1593, 14, 19, 0, -19, 229 }, /* 0x33 */
++ { 1711, 16, 19, 0, -19, 253 }, /* 0x34 */
++ { 1812, 14, 19, 0, -19, 229 }, /* 0x35 */
++ { 1931, 14, 19, 0, -19, 229 }, /* 0x36 */
++ { 2075, 13, 19, 0, -19, 211 }, /* 0x37 */
++ { 2161, 14, 19, 0, -19, 230 }, /* 0x38 */
++ { 2306, 14, 19, 0, -19, 228 }, /* 0x39 */
++ { 2453, 10, 13, 0, -13, 153 }, /* 0x3a */
++ { 2490, 8, 15, 0, -13, 136 }, /* 0x3b */
++ { 2537, 13, 14, 0, -14, 212 }, /* 0x3c */
++ { 2612, 13, 13, 0, -13, 212 }, /* 0x3d */
++ { 2638, 13, 14, 0, -14, 212 }, /* 0x3e */
++ { 2710, 14, 19, 0, -19, 216 }, /* 0x3f */
++ { 2806, 22, 20, 0, -18, 355 }, /* 0x40 */
++ { 3052, 18, 19, 0, -19, 280 }, /* 0x41 */
++ { 3181, 17, 19, 0, -19, 269 }, /* 0x42 */
++ { 3305, 16, 19, 0, -19, 263 }, /* 0x43 */
++ { 3440, 17, 19, 0, -19, 267 }, /* 0x44 */
++ { 3566, 16, 19, 0, -19, 256 }, /* 0x45 */
++ { 3635, 15, 19, 0, -19, 243 }, /* 0x46 */
++ { 3700, 17, 19, 0, -19, 265 }, /* 0x47 */
++ { 3847, 17, 19, 0, -19, 275 }, /* 0x48 */
++ { 3974, 7, 19, 0, -19, 113 }, /* 0x49 */
++ { 4032, 16, 19, 0, -19, 251 }, /* 0x4a */
++ { 4140, 17, 19, 0, -19, 268 }, /* 0x4b */
++ { 4271, 15, 19, 0, -19, 247 }, /* 0x4c */
++ { 4332, 19, 19, 0, -19, 309 }, /* 0x4d */
++ { 4497, 18, 19, 0, -19, 289 }, /* 0x4e */
++ { 4651, 17, 19, 0, -19, 268 }, /* 0x4f */
++ { 4806, 16, 19, 0, -19, 257 }, /* 0x50 */
++ { 4925, 16, 22, 0, -19, 254 }, /* 0x51 */
++ { 5092, 17, 19, 0, -19, 265 }, /* 0x52 */
++ { 5217, 16, 19, 0, -19, 255 }, /* 0x53 */
++ { 5367, 16, 19, 0, -19, 250 }, /* 0x54 */
++ { 5450, 17, 19, 0, -19, 275 }, /* 0x55 */
++ { 5606, 16, 19, 0, -19, 264 }, /* 0x56 */
++ { 5738, 24, 19, 0, -19, 379 }, /* 0x57 */
++ { 5959, 17, 19, 0, -19, 266 }, /* 0x58 */
++ { 6100, 16, 19, 0, -19, 259 }, /* 0x59 */
++ { 6212, 15, 19, 0, -19, 239 }, /* 0x5a */
++ { 6298, 11, 25, 0, -21, 174 }, /* 0x5b */
++ { 6400, 12, 19, 0, -19, 193 }, /* 0x5c */
++ { 6477, 11, 25, 0, -21, 174 }, /* 0x5d */
++ { 6558, 13, 19, 0, -19, 201 }, /* 0x5e */
++ { 6634, 14, 3, 0, -3, 220 }, /* 0x5f */
++ { 6647, 6, 19, 0, -19, 95 }, /* 0x60 */
++ { 6661, 14, 14, 0, -14, 226 }, /* 0x61 */
++ { 6773, 15, 19, 0, -19, 241 }, /* 0x62 */
++ { 6907, 14, 14, 0, -14, 229 }, /* 0x63 */
++ { 7003, 15, 19, 0, -19, 241 }, /* 0x64 */
++ { 7139, 15, 14, 0, -14, 234 }, /* 0x65 */
++ { 7237, 10, 19, 0, -19, 162 }, /* 0x66 */
++ { 7316, 15, 19, 0, -14, 237 }, /* 0x67 */
++ { 7458, 15, 19, 0, -19, 235 }, /* 0x68 */
++ { 7586, 7, 20, 0, -20, 110 }, /* 0x69 */
++ { 7653, 9, 25, -2, -20, 108 }, /* 0x6a */
++ { 7759, 14, 19, 0, -19, 226 }, /* 0x6b */
++ { 7887, 6, 19, 0, -19, 103 }, /* 0x6c */
++ { 7964, 22, 14, 0, -14, 358 }, /* 0x6d */
++ { 8141, 15, 14, 0, -14, 235 }, /* 0x6e */
++ { 8249, 15, 14, 0, -14, 240 }, /* 0x6f */
++ { 8357, 15, 19, 0, -14, 243 }, /* 0x70 */
++ { 8494, 15, 19, 0, -14, 243 }, /* 0x71 */
++ { 8630, 10, 14, 0, -14, 162 }, /* 0x72 */
++ { 8696, 13, 14, 0, -14, 213 }, /* 0x73 */
++ { 8798, 10, 18, 0, -18, 162 }, /* 0x74 */
++ { 8880, 15, 14, 0, -14, 234 }, /* 0x75 */
++ { 8994, 14, 14, 0, -14, 218 }, /* 0x76 */
++ { 9088, 21, 14, 0, -14, 329 }, /* 0x77 */
++ { 9249, 14, 14, 0, -14, 223 }, /* 0x78 */
++ { 9349, 13, 19, 0, -14, 211 }, /* 0x79 */
++ { 9468, 12, 14, 0, -14, 197 }, /* 0x7a */
++ { 9533, 9, 25, 0, -21, 151 }, /* 0x7b */
++ { 9643, 5, 23, 0, -21, 82 }, /* 0x7c */
++ { 9712, 9, 25, 0, -21, 151 }, /* 0x7d */
++ { 9821, 14, 10, 0, -10, 226 }, /* 0x7e */
++ { 9858, 6, 10, 0, -10, 98 }, /* 0x80 */
++ { 9877, 10, 22, 0, -22, 163 }, /* 0x81 */
++ { 9939, 12, 14, 0, -14, 189 }, /* 0x82 */
++ { 10021, 13, 9, 0, -9, 202 }, /* 0x83 */
++ { 10037, 18, 9, 0, -9, 289 }, /* 0x84 */
++ { 10052, 5, 19, 0, -19, 78 }, /* 0x85 */
++ { 10076, 22, 4, 0, -4, 359 }, /* 0x86 */
++ { 10130, 8, 11, 0, -11, 136 }, /* 0x87 */
++ { 10164, 9, 12, 0, -12, 149 }, /* 0x88 */
++ { 10208, 10, 12, 0, -12, 159 }, /* 0x89 */
++};
++static const uint8_t lg_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern lg_kern[] = {
++ {39,45,-22},{39,52,-7},{39,65,-34},{39,74,-22},{39,97,-5},{39,99,-22},{39,100,-22},{39,101,-22},
++ {39,103,-15},{39,109,-6},{39,110,-6},{39,111,-22},{39,112,-6},{39,113,-15},{39,114,-6},{39,115,-10},
++ {44,45,-6},{44,48,-13},{44,84,-25},{44,86,-12},{44,87,-12},{44,89,-25},{44,99,-6},{44,100,-6},
++ {44,101,-6},{44,102,-4},{44,103,-6},{44,111,-6},{44,113,-6},{44,116,-4},{44,118,-17},{44,119,-17},
++ {44,121,-17},{45,39,-10},{45,44,-6},{45,45,-60},{45,46,-6},{45,55,-27},{45,84,-14},{45,102,-5},
++ {45,116,-5},{45,118,-11},{45,119,-11},{45,120,-10},{45,121,-11},{45,133,-11},{46,45,-6},{46,48,-13},
++ {46,84,-25},{46,86,-12},{46,87,-12},{46,89,-25},{46,99,-6},{46,100,-6},{46,101,-6},{46,102,-4},
++ {46,103,-6},{46,111,-6},{46,113,-6},{46,116,-4},{46,118,-17},{46,119,-17},{46,121,-17},{48,49,-7},
++ {50,49,-4},{50,51,-5},{52,39,-12},{52,49,-41},{52,55,-25},{53,49,-7},{54,49,-5},{55,44,-25},
++ {55,46,-25},{56,49,-7},{57,49,-9},{65,39,-38},{65,45,-7},{65,67,-8},{65,71,-8},{65,79,-8},
++ {65,81,-8},{65,83,-18},{65,84,-34},{65,85,-5},{65,86,-13},{65,87,-13},{65,89,-35},{65,90,6},
++ {65,99,-7},{65,100,-7},{65,101,-7},{65,102,-10},{65,103,-9},{65,111,-7},{65,113,-9},{65,116,-10},
++ {65,118,-19},{65,119,-19},{65,121,-19},{65,133,-29},{66,44,-4},{66,46,-4},{66,65,-14},{66,84,-7},
++ {66,86,-10},{66,87,-10},{66,88,-10},{66,89,-14},{66,102,-4},{66,103,-6},{66,113,-6},{66,115,-5},
++ {66,116,-4},{66,117,-4},{67,65,-4},{67,74,6},{67,86,-5},{67,87,-5},{67,89,-10},{67,103,-4},
++ {67,113,-4},{68,44,-4},{68,46,-4},{68,65,-14},{68,84,-7},{68,86,-10},{68,87,-10},{68,88,-10},
++ {68,89,-14},{68,102,-4},{68,103,-6},{68,113,-6},{68,115,-5},{68,116,-4},{68,117,-4},{69,86,4},
++ {69,87,4},{70,44,-36},{70,45,-22},{70,46,-36},{70,65,-29},{70,74,-23},{70,97,-19},{70,99,-22},
++ {70,100,-22},{70,101,-22},{70,103,-16},{70,109,-10},{70,110,-10},{70,111,-22},{70,112,-10},{70,113,-16},
++ {70,114,-10},{70,115,-19},{70,117,-12},{70,118,-21},{70,119,-21},{70,120,-19},{70,121,-21},{70,122,-10},
++ {71,65,-4},{71,74,6},{71,86,-5},{71,87,-5},{71,89,-10},{71,103,-4},{71,113,-4},{74,44,-4},
++ {74,46,-4},{74,65,-6},{74,67,-4},{74,71,-4},{74,79,-4},{74,81,-4},{75,45,-12},{75,65,7},
++ {75,67,-10},{75,71,-10},{75,74,-8},{75,79,-10},{75,81,-10},{75,83,-7},{75,99,-12},{75,100,-12},
++ {75,101,-12},{75,103,-10},{75,111,-12},{75,113,-10},{75,115,-5},{75,118,-17},{75,119,-17},{75,121,-17},
++ {76,39,-34},{76,65,11},{76,84,-37},{76,86,-16},{76,87,-16},{76,89,-18},{76,102,-7},{76,116,-7},
++ {76,118,-10},{76,119,-10},{76,121,-10},{76,122,5},{76,133,-21},{78,66,-4},{78,68,-4},{78,69,-4},
++ {78,70,-4},{78,78,-4},{78,80,-4},{79,65,-4},{79,74,6},{79,86,-5},{79,87,-5},{79,89,-10},
++ {79,103,-4},{79,113,-4},{80,44,-10},{80,45,-11},{80,46,-10},{80,65,-19},{80,74,-10},{80,86,-6},
++ {80,87,-6},{80,88,-12},{80,89,-12},{80,99,-11},{80,100,-11},{80,101,-11},{80,103,-7},{80,111,-11},
++ {80,113,-7},{80,115,-6},{81,65,-10},{81,74,6},{81,84,-5},{81,86,-12},{81,87,-12},{81,88,-12},
++ {81,89,-20},{81,103,-4},{81,113,-4},{82,65,10},{82,86,-7},{82,87,-7},{82,89,-10},{83,44,-4},
++ {83,46,-4},{83,84,-6},{83,86,-7},{83,87,-7},{83,88,-14},{83,89,-10},{84,44,-25},{84,45,-34},
++ {84,46,-25},{84,65,-26},{84,67,-15},{84,71,-15},{84,74,-17},{84,79,-15},{84,81,-15},{84,97,-12},
++ {84,99,-34},{84,100,-34},{84,101,-34},{84,103,-26},{84,105,-4},{84,109,-24},{84,110,-24},{84,111,-34},
++ {84,112,-24},{84,113,-26},{84,114,-24},{84,115,-25},{84,117,-20},{84,118,-21},{84,119,-21},{84,120,-22},
++ {84,121,-21},{85,44,-4},{85,46,-4},{85,65,-6},{85,67,-4},{85,71,-4},{85,79,-4},{85,81,-4},
++ {86,44,-26},{86,45,-25},{86,46,-26},{86,65,-42},{86,66,-4},{86,67,-13},{86,68,-4},{86,69,-4},
++ {86,70,-4},{86,71,-13},{86,74,-17},{86,75,-7},{86,78,-4},{86,79,-13},{86,80,-4},{86,81,-13},
++ {86,83,-7},{86,97,-24},{86,99,-25},{86,100,-25},{86,101,-25},{86,103,-23},{86,109,-6},{86,110,-6},
++ {86,111,-25},{86,112,-6},{86,113,-23},{86,114,-6},{86,115,-16},{86,117,-7},{86,118,-7},{86,119,-7},
++ {86,121,-7},{87,44,-26},{87,45,-25},{87,46,-26},{87,65,-42},{87,66,-4},{87,67,-13},{87,68,-4},
++ {87,69,-4},{87,70,-4},{87,71,-13},{87,74,-17},{87,75,-7},{87,78,-4},{87,79,-13},{87,80,-4},
++ {87,81,-13},{87,83,-7},{87,97,-24},{87,99,-25},{87,100,-25},{87,101,-25},{87,103,-23},{87,109,-6},
++ {87,110,-6},{87,111,-25},{87,112,-6},{87,113,-23},{87,114,-6},{87,115,-16},{87,117,-7},{87,118,-7},
++ {87,119,-7},{87,121,-7},{88,45,-13},{88,67,-10},{88,71,-10},{88,74,-5},{88,79,-10},{88,81,-10},
++ {88,83,-11},{88,97,-7},{88,99,-13},{88,100,-13},{88,101,-13},{88,103,-14},{88,111,-13},{88,113,-14},
++ {88,118,-12},{88,119,-12},{88,121,-12},{89,44,-39},{89,45,-32},{89,46,-39},{89,65,-47},{89,66,-4},
++ {89,67,-14},{89,68,-4},{89,69,-4},{89,70,-4},{89,71,-14},{89,74,-23},{89,78,-4},{89,79,-14},
++ {89,80,-4},{89,81,-14},{89,83,-10},{89,97,-25},{89,99,-32},{89,100,-32},{89,101,-32},{89,102,-16},
++ {89,103,-36},{89,109,-22},{89,110,-22},{89,111,-32},{89,112,-22},{89,113,-36},{89,114,-22},{89,115,-19},
++ {89,116,-16},{89,117,-16},{89,118,-16},{89,119,-16},{89,120,-16},{89,121,-16},{89,122,-10},{97,39,-10},
++ {97,84,-12},{97,89,-15},{97,118,-5},{97,119,-5},{97,121,-5},{97,133,-7},{98,39,-16},{98,44,-6},
++ {98,46,-6},{98,118,-8},{98,119,-8},{98,121,-8},{98,133,-5},{99,39,-10},{99,44,-10},{99,46,-10},
++ {99,118,-4},{99,119,-4},{99,120,-7},{99,121,-4},{99,133,-7},{101,39,-15},{101,44,-9},{101,46,-9},
++ {101,102,-4},{101,116,-4},{101,118,-10},{101,119,-10},{101,120,-9},{101,121,-10},{101,133,-10},{102,39,4},
++ {102,44,-22},{102,45,-16},{102,46,-22},{102,97,-5},{102,99,-16},{102,100,-16},{102,101,-16},{102,103,-12},
++ {102,111,-16},{102,113,-12},{102,115,-6},{102,133,6},{103,39,-4},{104,39,-16},{104,44,-6},{104,46,-6},
++ {104,118,-8},{104,119,-8},{104,121,-8},{104,133,-5},{107,45,-16},{107,97,-7},{107,99,-16},{107,100,-16},
++ {107,101,-16},{107,103,-11},{107,111,-16},{107,113,-11},{109,39,-16},{109,44,-6},{109,46,-6},{109,118,-8},
++ {109,119,-8},{109,121,-8},{109,133,-5},{110,39,-16},{110,44,-6},{110,46,-6},{110,118,-8},{110,119,-8},
++ {110,121,-8},{110,133,-5},{111,39,-10},{111,44,-6},{111,46,-6},{111,55,-27},{111,84,-14},{111,102,-5},
++ {111,116,-5},{111,118,-11},{111,119,-11},{111,120,-10},{111,121,-11},{111,133,-11},{112,39,-16},{112,44,-6},
++ {112,46,-6},{112,118,-8},{112,119,-8},{112,121,-8},{112,133,-5},{113,39,-4},{114,39,10},{114,44,-16},
++ {114,45,-4},{114,46,-16},{114,99,-4},{114,100,-4},{114,101,-4},{114,102,4},{114,103,-8},{114,111,-4},
++ {114,113,-8},{114,116,4},{114,118,7},{114,119,7},{114,121,7},{114,133,21},{115,39,-7},{115,115,-4},
++ {115,118,-15},{115,119,-15},{115,120,-5},{115,121,-15},{115,133,-10},{116,45,-4},{116,99,-4},{116,100,-4},
++ {116,101,-4},{116,111,-4},{118,44,-17},{118,45,-12},{118,46,-17},{118,97,-10},{118,99,-12},{118,100,-12},
++ {118,101,-12},{118,103,-13},{118,111,-12},{118,113,-13},{118,115,-15},{118,133,17},{119,44,-17},{119,45,-12},
++ {119,46,-17},{119,97,-10},{119,99,-12},{119,100,-12},{119,101,-12},{119,103,-13},{119,111,-12},{119,113,-13},
++ {119,115,-15},{119,133,17},{120,45,-13},{120,99,-13},{120,100,-13},{120,101,-13},{120,103,-10},{120,111,-13},
++ {120,113,-10},{121,44,-17},{121,45,-12},{121,46,-17},{121,97,-10},{121,99,-12},{121,100,-12},{121,101,-12},
++ {121,103,-13},{121,111,-12},{121,113,-13},{121,115,-15},{121,133,17},{133,45,-36},{133,65,-29},{133,97,-7},
++ {133,99,-36},{133,100,-36},{133,101,-36},{133,102,-5},{133,103,-32},{133,111,-36},{133,113,-32},{133,115,-29},
++ {133,116,-5},{133,118,-7},{133,119,-7},{133,120,-5},{133,121,-7},
++};
++const struct fos_font fos_font_lg_data = { lg_bits, lg_glyphs, lg_lut, lg_kern, 589, 27, 6 };
++
++static const uint8_t xl_bits[] = {
++ 130,2,14,63,7,133,3,79,9,133,2,79,8,133,2,79,8,133,1,79,7,133,1,79,
++ 7,133,1,79,7,134,79,6,134,79,6,134,14,63,6,134,14,63,5,134,14,63,5,134,
++ 13,63,4,134,13,63,4,134,12,63,4,134,12,63,3,134,11,63,3,134,11,63,3,134,
++ 11,63,2,134,10,63,2,134,10,63,1,134,9,63,1,134,7,47,14,200,3,11,14,13,
++ 8,134,3,79,9,133,9,95,1,132,11,95,3,132,9,95,1,132,2,79,9,134,3,11,
++ 14,13,8,131,1,14,63,4,128,1,14,63,4,1,79,4,128,1,79,4,128,79,4,129,
++ 79,4,128,14,63,3,129,14,63,3,128,13,63,2,129,13,63,2,128,13,63,1,129,13,
++ 63,1,128,12,63,1,129,12,63,1,128,11,63,130,11,63,129,10,47,14,130,10,47,14,
++ 129,10,47,13,130,10,47,13,129,7,47,11,130,7,47,11,255,255,232,135,2,14,63,8,
++ 132,8,79,2,138,4,79,8,132,11,79,1,138,7,79,6,132,13,63,14,139,9,79,3,
++ 131,1,79,12,139,11,79,1,131,3,79,10,139,13,63,14,132,5,79,7,139,79,12,132,
++ 7,79,5,138,3,79,10,132,10,79,3,134,2,14,127,127,111,3,131,3,127,127,127,4,
++ 131,3,127,127,127,4,131,3,127,127,127,4,131,2,127,127,127,3,134,1,79,11,132,8,
++ 79,4,138,3,79,9,132,10,79,2,138,5,79,7,132,12,79,139,7,79,5,132,14,63,
++ 13,139,9,79,3,131,1,79,11,139,11,79,1,131,3,79,9,139,13,63,14,132,5,79,
++ 8,135,12,127,127,111,7,132,14,127,127,111,8,132,14,127,127,111,8,132,14,127,127,111,
++ 8,132,12,127,127,111,7,135,12,79,1,131,4,79,8,139,14,63,13,132,6,79,6,138,
++ 2,79,10,132,8,79,4,138,4,79,8,132,11,79,1,138,6,79,6,132,13,63,14,139,
++ 9,79,3,131,1,79,12,139,11,79,1,131,3,79,9,139,5,55,6,132,1,71,3,165,
++ 135,3,47,13,144,4,63,144,4,47,14,144,4,47,14,142,2,7,12,63,9,4,138,1,
++ 9,127,15,12,3,135,1,13,127,47,14,4,134,12,127,79,14,3,132,6,127,111,12,132,
++ 13,79,12,3,128,2,8,95,4,130,2,79,14,1,131,8,79,9,130,5,79,8,132,1,
++ 79,12,130,6,79,5,133,13,63,14,130,6,79,5,133,11,63,14,130,4,79,8,133,10,
++ 63,13,130,1,79,14,1,142,11,79,11,1,141,4,95,12,2,141,9,95,14,4,140,1,
++ 12,111,8,140,1,12,111,12,2,139,1,10,111,14,4,140,7,127,6,140,3,13,111,7,
++ 140,1,10,111,5,141,6,14,79,14,1,141,3,14,79,8,142,4,79,13,130,2,11,60,
++ 4,133,12,79,1,129,4,79,7,133,8,79,2,129,4,79,8,133,9,79,3,129,3,79,
++ 11,133,11,79,1,129,1,95,4,131,4,79,14,131,11,79,14,5,17,6,14,79,10,131,
++ 5,127,127,4,132,11,127,95,10,133,2,13,127,63,12,1,134,2,11,127,31,10,1,137,
++ 5,11,14,63,14,10,4,141,4,63,1,143,3,63,1,143,4,63,1,143,3,47,14,1,
++ 135,133,2,7,12,30,13,9,3,139,11,47,5,140,6,14,111,10,1,136,4,47,13,140,
++ 7,127,31,12,1,135,12,47,6,139,4,47,13,5,1,128,3,10,47,9,134,6,47,12,
++ 140,11,31,12,1,132,8,47,2,133,13,47,5,139,1,47,3,134,13,31,7,132,7,47,
++ 12,140,3,31,14,135,9,31,9,131,1,14,47,4,140,3,31,14,135,9,31,9,131,8,
++ 47,10,141,1,47,4,134,13,31,7,130,1,14,47,3,142,11,31,12,1,132,8,47,2,
++ 130,9,47,9,143,4,47,13,5,1,128,3,10,47,9,130,2,63,2,144,7,127,31,12,
++ 1,130,10,47,8,146,6,14,111,10,1,130,3,47,14,1,147,2,7,12,30,13,9,4,
++ 132,11,47,7,160,4,47,14,1,160,12,47,6,160,5,47,13,161,13,47,5,160,6,47,
++ 12,160,1,14,47,4,160,7,47,11,132,6,11,14,15,14,10,5,148,1,14,47,3,130,
++ 2,12,111,11,1,146,9,47,10,130,2,14,127,15,13,1,144,2,63,2,130,12,31,14,
++ 7,2,128,2,9,47,10,144,10,47,9,130,6,47,3,132,6,47,2,142,3,47,14,1,
++ 130,11,31,8,134,11,31,8,142,11,47,7,131,14,31,3,134,6,31,11,141,4,47,14,
++ 1,131,47,2,134,5,31,12,141,12,47,6,132,14,31,3,134,6,31,11,140,5,47,13,
++ 133,11,31,8,134,11,31,8,140,13,47,5,133,6,47,4,132,6,47,2,139,6,47,12,
++ 135,12,31,14,7,2,128,2,9,47,10,139,1,14,47,4,135,2,14,127,15,13,1,139,
++ 7,47,11,137,2,13,111,11,1,140,13,31,14,3,139,5,11,13,15,13,10,4,134,134,
++ 1,6,10,13,14,15,13,10,6,146,5,14,127,13,4,143,6,127,63,6,141,3,127,95,
++ 4,140,11,127,95,13,139,2,95,9,2,1,7,95,5,138,6,79,11,131,8,79,9,138,
++ 7,79,6,131,2,79,11,138,8,79,4,131,1,79,12,138,6,79,6,131,3,79,11,138,
++ 3,79,10,131,9,79,8,139,13,79,3,129,4,95,4,139,6,79,12,128,3,14,79,13,
++ 141,12,79,10,14,95,4,141,2,127,63,7,143,6,127,31,8,145,13,127,7,145,10,127,
++ 4,145,11,127,15,4,144,10,127,31,13,1,132,1,136,7,127,63,11,131,2,14,10,2,
++ 133,2,95,12,2,13,79,7,130,10,47,8,1,131,10,79,13,1,128,2,14,79,4,128,
++ 4,79,7,131,14,79,3,130,5,79,14,2,13,63,14,1,130,3,79,11,132,8,127,47,
++ 7,131,5,79,7,133,11,127,15,13,132,6,79,7,133,1,13,127,4,132,5,79,10,134,
++ 3,111,8,133,3,95,3,133,8,111,1,134,14,79,14,6,1,128,2,6,13,127,9,134,
++ 9,127,127,79,5,133,2,14,127,127,63,14,2,133,4,127,95,12,10,79,11,134,3,12,
++ 127,31,13,6,129,12,79,7,135,4,9,12,14,15,14,13,11,8,4,131,3,14,63,14,
++ 129,1,14,63,8,128,1,79,9,129,79,8,129,14,63,7,129,13,63,6,129,13,63,6,
++ 129,12,63,5,129,11,63,4,129,10,63,3,129,10,63,2,129,7,47,14,1,255,192,132,
++ 12,63,12,134,7,79,8,133,1,14,79,2,133,7,79,11,134,13,79,6,133,4,95,1,
++ 133,9,79,11,134,14,79,7,133,4,95,3,133,8,79,14,134,12,79,10,134,95,7,133,
++ 3,95,4,133,5,95,2,133,8,95,134,10,79,13,134,11,79,11,134,13,79,10,134,14,
++ 79,9,134,14,79,8,134,95,8,134,95,8,134,95,8,134,14,79,8,134,14,79,9,134,
++ 13,79,10,134,11,79,11,134,10,79,12,134,8,79,14,134,6,95,1,133,4,95,4,133,
++ 1,95,7,134,12,79,10,134,9,79,13,134,4,95,2,133,1,14,79,6,134,10,79,10,
++ 134,5,79,14,1,134,14,79,5,134,7,79,10,134,1,14,79,1,134,8,79,8,134,1,
++ 13,63,12,130,130,12,63,12,135,8,79,7,134,2,79,14,1,134,11,79,7,134,6,79,
++ 13,134,1,95,4,134,11,79,9,134,7,79,14,134,3,95,4,134,14,79,8,134,11,79,
++ 12,134,8,95,134,4,95,3,133,2,95,6,134,95,8,134,13,79,10,134,12,79,11,134,
++ 11,79,13,134,9,79,14,134,9,79,14,134,9,95,134,8,95,134,9,95,134,9,79,14,
++ 134,10,79,14,134,11,79,12,134,12,79,11,134,13,79,10,134,95,8,133,2,95,5,133,
++ 5,95,3,133,8,79,14,134,11,79,11,134,14,79,8,133,3,95,3,133,7,79,14,134,
++ 12,79,9,133,1,95,4,133,6,79,13,134,11,79,6,133,2,79,14,1,133,8,79,6,
++ 134,12,63,12,132,134,8,31,10,141,10,31,11,141,10,31,11,136,9,6,130,10,31,11,
++ 130,6,10,130,4,31,12,3,128,10,31,11,128,3,12,31,5,129,12,63,9,11,31,12,
++ 8,63,13,129,7,14,127,79,7,130,2,10,127,31,11,2,133,4,12,95,13,5,135,2,
++ 11,95,12,2,134,7,14,127,15,8,1,130,4,13,127,63,13,4,129,13,63,11,12,31,
++ 12,11,63,14,129,6,31,13,5,128,10,31,11,128,5,14,31,7,130,11,8,1,129,10,
++ 31,11,129,1,9,12,1,135,10,31,11,141,10,31,11,141,8,31,10,255,255,238,135,2,
++ 63,2,143,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,143,3,
++ 63,3,136,8,127,127,31,8,129,10,127,127,31,10,129,10,127,127,31,10,129,10,127,127,
++ 31,10,129,8,127,127,31,8,136,3,63,3,143,3,63,3,143,3,63,3,143,3,63,3,
++ 143,3,63,3,143,3,63,3,143,2,63,2,255,161,129,1,14,47,14,131,2,63,13,131,
++ 4,63,9,131,6,63,6,131,8,63,3,131,10,47,14,132,11,47,11,132,13,47,7,132,
++ 63,4,131,2,63,1,131,4,47,12,132,4,47,8,131,128,8,127,63,12,129,10,127,63,
++ 14,129,10,127,63,14,129,10,127,63,14,129,8,127,63,12,255,208,130,7,13,14,12,4,
++ 132,9,79,3,130,1,95,9,130,3,95,12,130,1,95,9,131,9,79,3,132,7,13,14,
++ 11,3,130,138,10,63,14,139,1,79,12,139,5,79,8,139,9,79,3,139,14,63,13,139,
++ 3,79,9,139,8,79,4,139,12,63,14,139,2,79,10,139,7,79,6,139,11,79,1,138,
++ 1,79,12,139,5,79,7,139,10,79,2,139,14,63,13,139,4,79,8,139,8,79,4,139,
++ 13,63,14,139,2,79,10,139,7,79,5,139,12,79,1,138,1,79,11,139,6,79,7,139,
++ 10,79,2,139,14,63,12,139,4,79,8,139,9,79,3,139,13,63,14,139,3,79,9,139,
++ 8,79,5,139,12,79,1,138,2,79,11,139,6,79,6,139,11,79,2,139,13,63,11,139,
++ 134,5,10,13,14,15,13,11,7,2,139,4,13,127,15,9,137,6,127,63,12,1,134,4,
++ 127,95,11,134,13,127,111,6,132,6,95,7,1,128,4,12,79,13,132,11,79,7,131,1,
++ 14,79,3,131,14,63,14,133,7,79,6,131,79,12,133,4,79,8,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,79,9,130,1,79,11,133,3,
++ 79,9,130,1,79,11,133,3,79,9,131,79,12,133,4,79,8,131,14,63,14,133,7,79,
++ 6,131,11,79,7,131,1,14,79,3,131,6,95,7,1,128,4,12,79,13,133,13,127,111,
++ 6,133,4,127,95,11,135,6,127,63,12,1,136,4,13,127,15,9,140,5,10,13,14,15,
++ 14,11,7,2,134,130,1,7,13,79,6,130,2,8,14,111,8,129,5,127,31,8,129,7,
++ 127,31,8,129,6,127,31,8,129,6,127,31,8,129,3,11,8,5,2,5,79,8,134,4,
++ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
++ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
++ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
++ 79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,79,8,134,4,
++ 79,8,134,4,79,8,134,4,79,8,134,3,79,6,129,133,2,8,12,14,15,14,12,9,
++ 3,138,9,127,15,11,1,134,1,12,127,47,13,2,133,11,127,79,12,132,5,127,111,6,
++ 131,13,79,11,3,128,3,12,79,13,130,2,79,14,1,130,1,14,79,2,129,6,79,8,
++ 132,9,79,5,129,8,79,6,132,7,79,7,129,8,79,5,132,6,79,7,129,8,79,5,
++ 132,7,79,6,129,3,72,1,132,11,79,4,140,1,14,79,1,140,6,79,12,141,13,79,
++ 7,140,5,79,14,1,140,13,79,9,140,8,79,14,1,139,3,95,6,140,12,79,12,140,
++ 7,95,3,139,3,95,7,139,1,13,79,11,140,9,79,14,2,139,5,95,5,139,2,14,
++ 79,9,140,12,79,13,1,139,8,79,14,3,139,4,95,6,139,1,14,79,10,140,6,127,
++ 127,31,2,128,7,127,127,31,3,128,7,127,127,31,3,128,7,127,127,31,3,128,5,127,
++ 127,31,2,128,1,14,127,127,3,129,2,127,127,15,4,129,2,127,127,15,4,129,2,127,
++ 127,15,4,129,1,14,127,127,3,139,1,14,79,13,140,11,79,14,3,139,7,95,6,139,
++ 4,95,10,139,1,14,79,13,1,139,11,95,3,139,7,95,6,139,4,95,10,139,1,13,
++ 95,11,5,138,1,13,127,13,3,137,2,13,127,14,2,137,2,13,10,6,9,79,11,142,
++ 4,79,4,142,11,63,9,142,7,63,13,142,5,79,1,141,4,79,3,141,3,79,4,129,
++ 1,68,133,3,79,5,129,8,79,3,132,4,79,5,129,8,79,4,132,4,79,4,129,7,
++ 79,6,132,6,79,3,129,6,79,9,132,9,79,1,129,4,79,14,1,130,1,14,63,13,
++ 130,1,14,79,12,3,1,3,12,79,9,131,9,127,111,3,131,1,14,127,79,10,133,4,
++ 14,127,47,13,1,134,3,12,127,15,11,1,137,4,9,12,14,15,14,12,9,4,133,134,
++ 1,14,63,14,143,6,79,12,143,11,79,7,142,2,95,2,142,6,79,13,143,11,79,8,
++ 142,1,95,3,142,6,79,13,143,11,79,8,142,1,95,4,142,6,79,14,143,11,79,9,
++ 142,1,95,4,142,6,79,14,143,11,79,10,131,13,63,10,132,1,95,5,131,79,12,132,
++ 6,79,14,1,131,79,12,132,11,79,10,132,79,12,131,1,95,5,132,79,12,131,6,95,
++ 1,132,79,12,131,11,79,11,133,79,12,130,1,127,127,63,14,1,2,127,127,79,18,127,
++ 127,79,18,127,127,79,2,1,14,127,127,47,14,1,141,79,12,144,79,12,144,79,12,144,
++ 79,12,144,79,12,144,79,12,144,79,12,144,79,12,144,13,63,10,130,129,14,127,127,5,
++ 129,1,127,127,15,7,129,1,127,127,15,7,129,1,127,127,15,7,129,1,127,127,15,5,
++ 129,1,79,12,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,
++ 141,1,79,11,141,1,79,11,141,1,79,11,128,2,9,13,15,14,12,7,1,132,1,79,
++ 11,7,111,13,2,131,1,127,111,13,1,130,1,127,127,9,130,1,127,127,15,1,129,1,
++ 95,13,5,17,7,95,6,129,1,95,3,131,9,79,9,130,11,60,9,132,3,79,11,142,
++ 79,13,142,13,63,14,142,12,79,142,12,79,130,7,56,5,133,13,63,14,130,14,63,13,
++ 133,14,63,13,130,13,79,2,131,2,79,12,130,10,79,8,131,8,79,9,130,6,95,7,
++ 17,7,95,6,130,1,14,127,95,14,1,131,7,127,95,7,133,10,127,63,10,135,7,127,
++ 31,7,137,1,7,11,14,31,13,11,7,1,132,133,1,7,11,13,30,13,10,6,138,7,
++ 14,127,13,4,135,10,127,63,6,133,8,127,95,3,131,2,127,111,11,131,8,79,14,6,
++ 1,2,10,95,2,130,12,79,6,131,12,79,6,130,14,63,14,132,6,79,7,130,79,12,
++ 132,4,79,8,129,1,79,12,132,2,77,6,129,1,79,12,141,1,79,12,141,1,79,12,
++ 1,8,13,15,14,12,8,2,134,79,14,13,111,7,133,127,111,7,132,127,127,4,131,127,
++ 127,12,131,111,7,17,7,95,3,130,95,8,131,9,79,8,130,95,2,131,3,79,10,130,
++ 95,133,79,12,130,79,14,133,13,63,13,130,79,13,133,13,63,14,130,79,12,133,12,79,
++ 130,79,12,133,12,79,130,14,63,13,133,13,79,130,13,63,14,133,14,79,130,11,79,2,
++ 131,3,79,13,130,8,79,8,131,9,79,11,130,4,95,7,17,8,95,7,131,13,127,111,
++ 2,131,5,127,95,8,133,8,127,63,10,135,6,14,127,15,7,137,1,7,11,13,31,14,
++ 11,7,1,132,1,14,127,127,13,128,2,127,127,31,128,3,127,127,31,128,3,127,127,31,
++ 128,3,127,127,31,128,3,63,8,133,5,79,13,128,3,63,8,133,9,79,9,128,1,9,
++ 42,4,133,13,79,4,139,2,95,1,139,7,79,11,140,11,79,6,139,1,95,2,139,4,
++ 79,13,140,9,79,9,140,13,79,4,139,2,79,14,140,7,79,11,140,11,79,6,139,1,
++ 14,79,2,139,4,79,13,140,9,79,8,140,13,79,4,139,2,79,14,140,6,79,11,140,
++ 11,79,6,140,14,79,2,139,4,79,13,140,8,79,8,140,13,79,4,139,2,79,14,140,
++ 6,79,10,140,10,79,6,140,14,79,2,139,4,79,13,140,6,79,7,136,133,2,7,11,
++ 14,15,14,13,10,5,139,8,127,15,13,4,136,11,127,63,5,134,8,127,95,3,132,2,
++ 127,111,11,132,7,79,14,5,1,2,9,95,2,131,12,79,5,131,11,79,7,131,14,63,
++ 14,132,4,79,10,130,1,79,10,132,1,79,11,130,1,79,9,133,79,11,131,14,63,11,
++ 132,1,79,10,131,12,63,14,132,4,79,8,131,7,79,6,131,10,79,3,131,2,79,14,
++ 5,1,2,9,79,13,133,7,127,95,4,134,9,127,63,8,136,11,127,31,6,136,9,127,
++ 47,12,2,134,8,127,79,14,1,132,2,79,14,6,1,2,10,79,9,132,6,79,7,131,
++ 12,79,1,131,11,79,1,131,6,79,5,131,14,63,12,132,2,79,9,131,79,10,133,79,
++ 11,130,1,79,9,133,79,12,130,1,79,10,132,1,79,11,131,14,63,12,132,2,79,10,
++ 131,12,79,1,131,5,79,8,131,9,79,6,131,11,79,4,131,4,79,14,6,1,2,9,
++ 79,14,133,12,127,95,7,133,3,127,79,13,135,6,127,47,13,2,136,4,13,127,11,2,
++ 138,1,6,11,14,15,14,13,9,4,134,132,1,6,10,13,14,15,14,11,7,2,137,6,
++ 14,127,15,8,135,9,127,63,10,133,6,127,95,7,131,1,14,127,111,1,130,5,95,9,
++ 2,1,5,14,79,7,130,9,79,11,131,5,79,11,130,11,79,4,132,14,63,13,130,12,
++ 79,1,132,12,79,130,13,79,133,11,79,1,129,13,79,133,10,79,2,129,13,79,133,10,
++ 79,2,129,12,79,2,132,11,79,2,129,11,79,3,132,12,79,2,129,9,79,5,132,14,
++ 79,2,129,7,79,10,131,4,95,3,129,3,95,9,2,1,5,14,95,3,130,12,127,127,
++ 3,130,4,127,127,3,131,7,127,111,3,132,6,111,14,13,79,3,133,1,8,12,14,15,
++ 13,9,2,10,79,3,141,10,79,3,141,10,79,3,129,2,72,2,132,10,79,3,129,6,
++ 79,6,132,10,79,3,129,6,79,7,132,11,79,3,129,5,79,9,132,13,79,2,129,3,
++ 79,14,1,130,5,79,14,131,14,79,12,2,1,5,14,79,11,131,7,127,111,4,131,1,
++ 13,127,79,11,133,3,14,127,47,12,1,134,2,12,127,15,9,1,137,4,9,13,14,15,
++ 14,11,8,2,133,131,7,13,14,12,4,134,8,79,4,133,14,79,11,132,2,95,13,133,
++ 14,79,11,133,8,79,4,134,7,13,14,12,4,255,137,7,13,14,12,4,134,8,79,4,
++ 133,14,79,11,132,2,95,13,133,14,79,11,133,8,79,4,134,7,13,14,12,4,131,130,
++ 5,13,15,12,4,132,6,79,4,131,14,79,13,130,3,111,2,129,3,111,2,130,14,79,
++ 13,131,7,79,5,132,6,13,15,13,5,232,14,63,1,131,2,63,14,132,3,63,11,132,
++ 5,63,8,132,6,63,5,132,7,63,2,132,9,47,14,133,10,47,11,133,11,47,8,133,
++ 13,47,5,133,14,47,2,133,14,31,13,132,146,20,145,4,12,15,10,143,5,12,47,10,
++ 141,6,13,79,10,138,1,7,14,111,10,136,1,8,14,127,15,8,134,2,9,127,31,11,
++ 4,133,3,10,127,15,14,9,2,133,4,11,127,15,13,7,1,134,8,127,15,12,5,137,
++ 10,111,10,3,139,10,79,9,2,141,10,79,14,7,1,140,10,127,9,3,138,4,13,127,
++ 15,11,4,138,5,12,127,15,13,6,1,137,4,11,127,15,14,8,2,137,3,10,127,31,
++ 10,2,137,2,9,127,15,10,139,2,8,14,95,10,141,1,7,14,63,10,143,1,7,13,
++ 31,10,146,6,12,9,148,1,172,128,8,127,127,31,8,129,10,127,127,31,10,129,10,127,
++ 127,31,10,129,8,127,127,31,8,239,8,127,127,31,8,129,10,127,127,31,10,129,10,127,
++ 127,31,10,129,8,127,127,31,8,255,198,128,20,147,10,15,12,4,145,10,47,12,5,143,
++ 10,79,13,6,141,10,111,14,7,1,138,8,127,15,14,8,1,137,4,11,127,31,9,2,
++ 137,2,9,14,127,15,10,3,137,1,7,13,127,15,11,4,138,5,12,127,15,8,139,3,
++ 10,111,10,141,2,9,79,10,140,1,7,14,79,10,138,3,9,127,10,136,4,11,127,15,
++ 13,4,133,1,6,13,127,15,12,5,133,2,8,14,127,15,11,4,133,2,10,127,31,10,
++ 3,135,10,127,15,9,2,137,10,95,14,8,2,139,10,63,14,7,1,141,10,31,13,7,
++ 1,143,10,12,6,146,1,191,133,3,9,12,14,15,14,12,9,3,137,1,11,127,15,11,
++ 1,134,3,13,127,47,13,2,132,1,13,127,79,12,1,131,10,127,111,7,130,3,95,9,
++ 2,128,3,12,79,14,130,8,79,10,131,1,14,79,3,129,11,79,2,132,9,79,6,129,
++ 13,63,14,133,6,79,7,129,14,63,13,133,5,79,8,129,11,61,10,133,7,79,7,141,
++ 12,79,5,140,6,95,1,139,4,95,10,139,4,111,3,138,4,111,7,138,4,111,8,138,
++ 1,14,95,8,139,9,95,7,140,14,79,8,140,2,79,13,141,3,79,9,141,4,79,8,
++ 141,3,79,8,142,4,53,1,205,4,12,14,13,7,142,3,79,8,141,10,95,1,140,12,
++ 95,2,140,10,95,141,3,79,8,142,4,12,14,13,7,136,142,1,6,9,12,30,15,14,
++ 13,10,7,3,151,4,11,127,63,12,6,147,3,12,127,127,12,3,144,8,127,127,63,6,
++ 141,1,11,95,11,6,3,1,128,1,2,4,8,13,95,7,139,1,12,79,8,1,137,5,
++ 13,79,4,137,1,12,63,12,2,140,1,10,63,14,1,136,9,63,10,144,10,63,8,135,
++ 5,63,9,145,1,13,47,14,1,133,1,14,47,11,132,5,11,30,12,6,5,43,3,131,
++ 5,63,5,133,8,47,14,1,131,9,127,31,5,132,13,47,10,132,1,14,47,6,131,6,
++ 127,47,3,132,8,47,13,132,7,47,12,132,14,47,9,1,2,12,63,1,132,5,63,132,
++ 13,47,6,131,4,47,12,130,4,47,14,133,3,63,1,130,2,47,14,1,131,7,47,7,
++ 130,3,47,12,133,3,63,1,130,6,47,10,132,9,47,4,130,5,47,10,133,3,63,131,
++ 9,47,6,132,11,47,2,130,6,47,8,133,4,63,131,12,47,4,132,13,47,131,8,47,
++ 6,133,7,47,12,131,14,47,1,132,47,14,131,10,47,4,133,11,47,9,130,1,63,132,
++ 2,47,12,131,12,47,3,132,1,14,47,5,130,1,63,132,4,47,10,131,13,47,4,132,
++ 7,63,1,130,1,63,132,5,47,9,130,1,63,9,131,3,14,47,9,132,63,1,131,4,
++ 47,12,130,6,79,7,2,1,6,14,47,14,2,132,14,47,4,131,1,63,6,1,5,14,
++ 127,79,6,133,12,47,8,132,10,127,127,47,8,134,9,47,13,132,1,12,95,12,4,13,
++ 111,14,6,135,4,63,5,133,7,12,14,15,12,7,1,128,1,7,12,14,15,14,11,7,
++ 1,137,14,47,13,1,159,7,63,11,159,1,13,63,10,1,139,2,145,5,79,13,4,136,
++ 1,8,15,8,145,7,95,12,7,3,1,128,1,2,5,10,63,2,145,8,127,127,31,8,
++ 146,5,14,127,111,10,1,147,1,8,14,127,47,10,3,151,1,5,9,12,14,15,14,13,
++ 12,9,5,1,143,135,12,79,9,142,2,95,14,142,5,111,2,141,8,111,5,141,12,111,
++ 9,141,127,12,140,3,127,15,140,6,127,15,3,139,10,63,11,63,7,139,13,47,14,5,
++ 63,10,138,1,63,11,2,63,13,138,5,63,9,128,14,63,1,137,8,63,6,128,12,63,
++ 5,137,11,63,3,128,9,63,8,137,14,63,129,6,63,11,136,3,63,13,129,3,63,14,
++ 136,6,63,10,129,1,79,3,135,9,63,7,130,13,63,6,135,13,63,4,130,10,63,9,
++ 134,1,79,1,130,7,63,13,134,4,63,14,131,4,79,1,133,7,63,11,131,1,79,4,
++ 133,11,63,8,132,13,63,8,133,14,63,5,132,11,63,11,132,2,127,127,14,132,5,127,
++ 127,15,2,131,9,127,127,15,6,131,12,127,127,15,9,130,1,127,127,31,12,130,4,79,
++ 6,134,10,79,1,129,7,79,3,134,7,79,4,129,10,79,135,4,79,7,129,13,63,12,
++ 135,2,79,10,128,2,79,9,136,14,63,14,128,3,79,6,136,10,79,1,129,3,127,15,
++ 14,12,9,5,136,4,127,79,14,6,134,4,127,111,10,133,4,127,127,9,132,4,127,127,
++ 15,3,131,4,79,8,130,2,8,95,10,131,4,79,8,132,6,79,14,131,4,79,8,133,
++ 12,79,3,130,4,79,8,133,8,79,4,130,4,79,8,133,6,79,5,130,4,79,8,133,
++ 6,79,4,130,4,79,8,133,7,79,2,130,4,79,8,133,12,63,13,131,4,79,8,132,
++ 5,79,8,131,4,79,8,130,2,8,79,14,1,131,4,127,127,4,132,4,127,95,14,3,
++ 133,4,127,95,13,3,133,4,127,111,14,4,132,4,79,8,130,2,7,14,63,13,1,131,
++ 4,79,8,132,4,79,9,131,4,79,8,133,10,79,1,130,4,79,8,133,4,79,6,130,
++ 4,79,8,133,2,79,9,130,4,79,8,133,1,79,11,130,4,79,8,133,2,79,11,130,
++ 4,79,8,133,4,79,10,130,4,79,8,133,9,79,9,130,4,79,8,132,3,95,5,130,
++ 4,79,8,130,1,6,14,95,1,130,4,127,127,15,9,131,4,127,127,13,1,131,4,127,
++ 111,13,2,132,4,127,95,10,1,133,3,127,31,13,11,8,2,133,134,4,9,12,14,15,
++ 14,12,9,4,139,3,12,127,15,12,3,136,5,127,79,6,134,3,127,111,4,133,12,127,
++ 111,13,132,4,95,9,2,128,2,8,95,5,131,9,79,10,132,8,79,10,131,12,79,2,
++ 132,1,79,13,131,13,63,14,134,13,63,14,131,14,63,14,134,13,79,131,14,63,14,134,
++ 5,56,6,131,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,
++ 14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,14,63,14,144,
++ 14,63,14,144,14,63,14,144,14,63,14,134,5,56,6,131,14,63,14,134,13,79,131,13,
++ 63,14,134,13,63,14,131,12,79,2,132,1,79,13,131,8,79,10,132,8,79,9,131,4,
++ 95,9,2,128,2,8,95,5,132,12,127,111,12,133,3,14,127,95,3,134,4,14,127,47,
++ 14,5,136,3,12,127,15,12,3,139,4,9,12,14,15,14,12,9,4,134,129,3,127,15,
++ 14,13,10,6,1,136,4,127,79,14,6,135,4,127,111,8,134,4,127,127,6,133,4,127,
++ 127,15,2,132,4,79,8,130,2,7,95,8,132,4,79,8,132,7,79,13,132,4,79,8,
++ 133,13,79,2,131,4,79,8,133,10,79,3,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,133,8,79,4,131,4,79,8,
++ 133,8,79,4,131,4,79,8,133,11,79,3,131,4,79,8,132,1,14,79,2,131,4,79,
++ 8,132,8,79,13,132,4,79,8,130,2,8,95,9,132,4,127,127,15,2,132,4,127,127,
++ 7,133,4,127,111,9,134,4,127,79,14,6,135,3,127,15,14,13,10,6,1,134,129,3,
++ 127,127,14,1,130,4,127,127,15,2,130,4,127,127,15,2,130,4,127,127,15,2,130,4,
++ 127,127,14,1,130,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,
++ 142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,127,63,
++ 10,135,4,127,63,11,135,4,127,63,11,135,4,127,63,11,135,4,127,63,10,135,4,79,
++ 8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,
++ 8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,127,127,14,1,130,4,127,127,15,
++ 2,130,4,127,127,15,2,130,4,127,127,15,2,130,3,127,127,14,1,128,129,3,127,127,
++ 14,1,129,4,127,127,15,1,129,4,127,127,15,1,129,4,127,127,15,1,129,4,127,127,
++ 14,1,129,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,
++ 79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,127,63,9,134,
++ 4,127,63,11,134,4,127,63,11,134,4,127,63,11,134,4,127,63,9,134,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,3,79,6,139,134,5,9,12,14,15,14,13,9,5,139,3,13,127,15,13,
++ 4,136,6,127,79,7,134,4,127,111,5,133,13,127,111,14,1,131,5,95,8,2,128,2,
++ 8,95,7,131,9,79,9,132,7,79,11,131,12,79,1,133,14,63,13,131,13,63,14,134,
++ 12,79,131,14,63,13,134,12,79,131,14,63,13,134,11,79,131,14,63,13,134,1,50,1,
++ 131,14,63,13,144,14,63,13,144,14,63,13,144,14,63,13,144,14,63,13,130,9,127,13,
++ 131,14,63,13,130,11,127,15,131,14,63,13,130,11,127,15,131,14,63,13,130,11,127,15,
++ 131,14,63,13,130,9,127,15,131,14,63,13,134,12,79,131,14,63,13,134,12,79,131,14,
++ 63,13,134,12,79,131,14,63,13,134,12,79,131,14,63,13,134,12,79,131,13,63,14,134,
++ 13,63,14,131,12,79,1,132,1,79,13,131,9,79,9,132,8,79,10,131,5,95,8,2,
++ 128,2,8,95,5,132,13,127,111,13,133,4,127,111,4,134,6,127,79,5,136,3,13,127,
++ 15,12,3,139,5,9,13,14,15,14,12,9,4,134,129,3,79,6,133,8,63,14,1,131,
++ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
++ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
++ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
++ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,
++ 4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,127,127,31,2,131,4,127,
++ 127,31,2,131,4,127,127,31,2,131,4,127,127,31,2,131,4,127,127,31,2,131,4,79,
++ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
++ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
++ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
++ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,8,133,10,79,2,131,4,79,
++ 8,133,10,79,2,131,4,79,8,133,10,79,2,131,3,79,6,133,8,63,14,1,129,129,
++ 2,79,6,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
++ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
++ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
++ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
++ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,
++ 4,79,8,131,4,79,8,131,4,79,8,131,4,79,8,131,3,79,6,129,140,5,79,5,
++ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
++ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
++ 142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,142,6,79,6,
++ 142,6,79,6,142,6,79,6,130,3,52,1,133,6,79,6,129,2,79,9,133,6,79,6,
++ 129,2,79,10,133,6,79,6,129,2,79,10,133,6,79,6,129,2,79,10,133,6,79,6,
++ 129,2,79,11,133,7,79,5,129,1,79,13,133,10,79,4,130,13,79,5,131,2,95,1,
++ 130,8,79,14,6,17,4,13,79,12,131,2,127,127,5,132,7,127,95,11,134,9,127,63,
++ 12,1,135,6,14,127,15,8,138,1,6,10,13,14,15,13,11,7,2,134,129,2,79,6,
++ 134,10,79,5,130,4,79,8,133,4,79,14,1,130,4,79,8,133,12,79,7,131,4,79,
++ 8,132,4,79,14,1,131,4,79,8,132,12,79,6,132,4,79,8,131,5,79,13,133,4,
++ 79,8,131,13,79,6,133,4,79,8,130,6,79,13,134,4,79,8,130,13,79,5,134,4,
++ 79,8,129,7,79,12,135,4,79,8,128,1,14,79,4,135,4,79,8,128,7,79,11,136,
++ 4,79,8,1,14,79,3,136,4,79,24,79,11,137,4,79,9,14,79,3,137,4,127,47,
++ 14,138,4,127,63,5,137,4,127,63,12,137,4,127,79,3,136,4,127,79,9,136,4,111,
++ 8,14,79,1,135,4,95,13,128,8,79,7,135,4,95,4,128,2,79,13,135,4,79,10,
++ 130,11,79,5,134,4,79,8,130,5,79,11,134,4,79,8,131,13,79,3,133,4,79,8,
++ 131,7,79,9,133,4,79,8,131,1,95,1,132,4,79,8,132,10,79,7,132,4,79,8,
++ 132,4,79,13,132,4,79,8,133,13,79,5,131,4,79,8,133,6,79,11,131,4,79,8,
++ 133,1,14,79,3,130,4,79,8,134,9,79,9,130,3,79,6,134,3,14,63,14,128,129,
++ 2,79,6,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,4,79,8,141,
++ 4,127,127,14,1,129,4,127,127,15,2,129,4,127,127,15,2,129,4,127,127,15,2,129,
++ 3,127,127,14,1,129,4,79,7,136,9,79,4,131,7,95,2,134,3,95,5,131,7,95,
++ 9,134,11,95,5,131,7,111,3,132,4,111,5,131,7,111,11,132,12,111,5,131,7,127,
++ 4,130,5,127,5,131,7,127,12,130,12,127,5,131,7,127,15,5,128,6,127,15,5,131,
++ 7,127,15,13,1,13,127,15,5,131,7,127,31,13,127,31,5,131,7,127,127,79,5,131,
++ 7,79,7,127,14,8,79,5,131,7,79,5,8,111,23,79,5,131,7,79,5,1,14,79,
++ 13,128,7,79,5,131,7,79,5,128,7,79,5,128,7,79,5,131,7,79,5,129,13,47,
++ 12,129,7,79,5,131,7,79,5,129,5,47,4,129,7,79,5,131,7,79,5,130,12,15,
++ 10,130,7,79,5,131,7,79,5,130,3,15,2,130,7,79,5,131,7,79,5,131,2,131,
++ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
++ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
++ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
++ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,
++ 7,79,5,131,7,79,5,136,7,79,5,131,7,79,5,136,7,79,5,131,5,79,4,136,
++ 5,79,4,129,129,2,79,14,1,134,14,63,8,131,4,95,7,133,1,79,10,131,4,95,
++ 12,133,1,79,10,131,4,111,2,132,1,79,10,131,4,111,8,132,1,79,10,131,4,111,
++ 13,132,1,79,10,131,4,127,3,131,1,79,10,131,4,127,8,131,1,79,10,131,4,127,
++ 14,131,1,79,10,131,4,127,15,4,130,1,79,10,131,4,127,15,9,130,1,79,10,131,
++ 4,127,15,14,130,1,79,10,131,4,127,31,5,129,1,79,10,131,4,79,13,63,10,129,
++ 1,79,10,131,4,79,7,14,63,1,128,1,79,10,131,4,79,6,9,63,6,128,1,79,
++ 10,131,4,79,6,4,63,11,128,1,79,10,131,4,79,6,128,13,63,2,1,79,10,131,
++ 4,79,6,128,8,63,7,1,79,10,131,4,79,6,128,3,63,12,1,79,10,131,4,79,
++ 6,129,13,63,4,79,10,131,4,79,6,129,7,63,10,79,10,131,4,79,6,129,2,127,
++ 31,10,131,4,79,6,130,12,127,15,10,131,4,79,6,130,6,127,15,10,131,4,79,6,
++ 130,1,127,15,10,131,4,79,7,131,11,127,10,131,4,79,7,131,5,127,10,131,4,79,
++ 7,131,1,14,111,10,131,4,79,7,132,9,111,10,131,4,79,7,132,4,111,10,131,4,
++ 79,7,133,14,95,10,131,4,79,7,133,8,95,10,131,4,79,7,133,3,95,10,131,3,
++ 79,5,134,12,79,8,129,134,3,8,12,14,15,14,13,9,5,139,2,11,127,15,13,5,
++ 136,4,14,127,63,7,134,2,14,127,95,6,133,11,127,111,14,1,131,3,95,10,3,128,
++ 2,7,95,8,131,8,79,10,132,5,79,13,131,11,79,3,133,12,79,1,130,13,63,14,
++ 134,9,79,3,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
++ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
++ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
++ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
++ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,
++ 134,8,79,4,130,14,63,14,134,8,79,4,130,14,63,14,134,8,79,4,130,13,63,14,
++ 134,9,79,3,130,11,79,3,133,12,79,1,130,8,79,10,132,5,79,13,131,3,95,10,
++ 3,128,2,7,95,8,132,11,127,111,14,1,132,2,14,127,95,6,134,4,14,127,63,8,
++ 136,2,11,127,15,13,5,139,3,8,12,14,15,14,13,10,5,134,129,4,127,31,14,12,
++ 8,2,135,5,127,95,9,134,5,127,111,11,1,132,5,127,127,9,132,5,127,127,15,4,
++ 131,5,79,7,130,1,7,14,79,11,131,5,79,7,132,4,95,1,130,5,79,7,133,10,
++ 79,5,130,5,79,7,133,6,79,7,130,5,79,7,133,4,79,8,130,5,79,7,133,3,
++ 79,8,130,5,79,7,133,5,79,7,130,5,79,7,133,10,79,6,130,5,79,7,132,4,
++ 95,2,130,5,79,7,130,1,6,14,79,13,131,5,127,127,15,6,131,5,127,127,12,132,
++ 5,127,111,13,2,132,5,127,95,11,1,133,5,127,31,14,13,9,4,135,5,79,7,143,
++ 5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,
++ 5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,5,79,7,143,
++ 5,79,7,143,4,79,5,141,134,4,9,12,14,15,14,12,7,2,139,2,11,127,15,8,
++ 137,3,13,127,47,11,1,134,1,13,127,79,10,134,9,127,111,5,132,2,95,9,2,128,
++ 3,12,79,12,132,6,79,10,131,1,13,79,3,131,10,79,3,132,7,79,6,131,12,79,
++ 133,4,79,8,131,13,63,14,133,2,79,9,131,14,63,14,133,2,79,10,131,14,63,14,
++ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
++ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
++ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
++ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,
++ 133,2,79,10,131,14,63,14,133,2,79,10,131,14,63,14,133,2,79,10,131,13,63,14,
++ 133,2,79,10,131,13,79,133,4,79,9,131,11,79,3,132,7,79,7,131,7,79,10,131,
++ 1,13,79,3,131,2,95,9,2,128,3,12,79,13,133,10,127,111,6,133,2,14,127,79,
++ 12,135,4,14,127,47,13,2,136,3,12,127,15,11,1,139,6,13,79,11,4,142,8,79,
++ 4,143,8,79,4,143,8,79,4,143,8,79,4,143,7,79,3,135,129,3,127,31,14,12,
++ 8,3,135,4,127,95,9,1,133,4,127,111,12,1,132,4,127,127,10,132,4,127,127,15,
++ 5,131,4,79,8,130,1,6,14,79,12,131,4,79,8,132,4,95,2,130,4,79,8,133,
++ 9,79,6,130,4,79,8,133,5,79,8,130,4,79,8,133,3,79,9,130,4,79,8,133,
++ 3,79,10,130,4,79,8,133,5,79,9,130,4,79,8,133,9,79,7,130,4,79,8,132,
++ 3,95,3,130,4,79,8,130,1,6,14,79,13,131,4,127,127,15,7,131,4,127,127,12,
++ 132,4,127,111,13,2,132,4,127,95,10,1,133,4,127,95,1,134,4,79,8,129,4,79,
++ 5,134,4,79,8,130,14,63,10,134,4,79,8,130,10,79,1,133,4,79,8,130,6,79,
++ 5,133,4,79,8,130,1,79,10,133,4,79,8,131,12,63,14,133,4,79,8,131,7,79,
++ 5,132,4,79,8,131,3,79,10,132,4,79,8,132,13,63,14,132,4,79,8,132,9,79,
++ 4,131,4,79,8,132,4,79,9,131,4,79,8,133,14,63,14,131,4,79,8,133,10,79,
++ 4,130,4,79,8,133,6,79,9,130,3,79,6,133,1,14,63,12,128,133,3,8,12,14,
++ 15,14,13,9,5,138,1,10,127,15,12,3,135,2,13,127,63,5,134,12,127,79,14,3,
++ 132,6,127,111,12,132,13,79,12,3,128,2,8,95,4,130,2,79,14,1,131,8,79,9,
++ 130,5,79,8,132,1,79,12,130,6,79,5,133,13,63,13,130,6,79,5,133,11,63,14,
++ 130,4,79,8,133,10,63,13,130,1,79,14,1,142,11,79,12,1,141,3,95,13,2,141,
++ 9,95,14,5,140,1,12,111,9,1,139,1,12,111,13,3,139,1,10,111,14,5,140,6,
++ 127,8,140,3,13,111,8,140,1,9,111,6,141,5,14,79,14,2,141,3,14,79,8,142,
++ 4,79,13,130,2,11,60,4,133,12,79,1,129,4,79,7,133,8,79,2,129,4,79,8,
++ 133,9,79,2,129,3,79,11,133,11,79,1,129,1,95,4,131,4,79,13,131,11,79,14,
++ 5,17,6,14,79,8,131,4,127,127,2,132,10,127,95,7,134,11,127,63,9,136,8,14,
++ 127,14,6,138,1,7,11,13,15,14,13,10,6,1,133,128,7,127,127,47,3,129,9,127,
++ 127,47,4,129,9,127,127,47,4,129,9,127,127,47,4,129,7,127,127,47,3,136,12,79,
++ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
++ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
++ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
++ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,
++ 1,143,11,79,1,143,11,79,1,143,11,79,1,143,11,79,1,143,10,63,14,136,129,6,
++ 79,3,133,5,79,5,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,79,4,133,6,79,6,131,8,
++ 79,4,133,6,79,6,131,7,79,5,133,6,79,6,131,6,79,6,133,8,79,4,131,4,
++ 79,10,133,11,79,2,132,95,3,131,4,79,14,133,10,79,13,5,17,6,14,79,8,133,
++ 3,127,111,14,1,134,8,127,95,6,136,9,127,63,8,138,7,14,127,14,5,140,1,7,
++ 11,13,30,13,10,6,1,134,128,8,79,8,135,12,79,2,129,6,79,11,134,1,79,14,
++ 130,3,79,14,134,4,79,11,131,95,1,133,6,79,8,131,12,79,4,133,9,79,5,131,
++ 9,79,7,133,11,79,2,131,5,79,9,133,14,63,14,132,2,79,12,132,1,79,10,133,
++ 14,63,14,132,4,79,7,133,11,79,2,131,6,79,4,133,8,79,5,131,9,79,1,133,
++ 5,79,7,131,11,63,13,134,1,79,10,131,14,63,9,135,13,63,12,130,1,79,6,135,
++ 10,79,130,4,79,3,135,7,79,2,129,6,79,136,4,79,5,129,9,63,12,136,1,79,
++ 8,129,11,63,8,137,12,63,10,129,14,63,5,137,9,63,13,128,1,79,2,137,6,79,
++ 128,4,63,14,138,3,79,3,6,63,11,139,14,63,5,9,63,7,139,12,63,8,11,63,
++ 4,139,8,63,11,14,63,1,139,5,127,15,13,140,2,127,15,10,141,14,127,7,141,11,
++ 127,3,141,8,127,142,4,111,12,142,1,111,9,143,13,95,6,143,10,95,2,143,6,79,
++ 13,136,128,11,63,14,2,133,12,63,5,133,10,63,14,1,128,10,79,5,132,1,79,8,
++ 133,13,63,14,129,7,79,7,132,3,79,11,132,1,79,11,129,4,79,10,132,5,79,13,
++ 132,3,79,8,129,1,79,12,132,7,95,1,131,5,79,6,130,13,79,132,10,95,3,131,
++ 7,79,3,130,10,79,2,131,12,95,5,131,10,79,131,7,79,5,131,14,95,8,131,12,
++ 63,12,131,4,79,7,130,1,111,10,131,14,63,9,131,1,79,10,130,4,111,13,130,1,
++ 79,7,132,13,63,12,130,6,127,130,4,79,4,132,10,63,14,130,8,127,2,129,6,79,
++ 1,132,7,79,2,129,10,127,5,129,8,63,13,133,4,79,5,129,13,47,10,63,7,129,
++ 10,63,10,133,1,79,7,129,63,5,14,47,10,129,13,63,7,134,13,63,10,128,2,63,
++ 3,12,47,12,129,79,5,134,10,63,12,128,4,63,1,10,47,14,128,2,79,2,134,7,
++ 63,14,128,7,47,14,128,7,63,2,4,63,14,135,4,79,2,9,47,12,128,5,63,4,
++ 7,63,11,135,1,79,5,11,47,9,128,2,63,7,9,63,8,136,14,63,7,13,47,7,
++ 129,63,9,11,63,6,136,11,63,11,63,5,129,13,47,12,14,63,3,136,8,127,15,3,
++ 129,10,127,15,137,5,127,15,1,129,8,127,12,137,2,127,14,130,6,127,9,138,14,111,
++ 11,130,3,127,6,138,11,111,9,130,1,127,4,138,8,111,7,131,14,111,1,138,5,111,
++ 5,131,11,95,13,139,2,111,3,131,9,95,10,140,14,95,132,6,95,7,140,11,79,13,
++ 132,4,95,5,140,8,79,11,132,2,95,2,140,5,79,9,133,14,63,14,141,2,14,63,
++ 6,133,11,63,10,134,128,6,79,5,134,4,79,6,129,2,79,11,134,10,79,2,130,11,
++ 79,2,132,1,79,11,131,5,79,7,132,6,79,5,132,13,63,12,132,11,63,13,133,8,
++ 79,3,130,2,79,8,133,2,79,8,130,7,79,2,134,10,63,13,130,12,63,10,135,4,
++ 79,4,128,3,79,4,136,13,63,9,128,8,63,13,137,7,63,14,1,13,63,7,137,1,
++ 79,9,79,1,138,10,127,15,10,139,4,127,15,4,140,13,111,13,141,7,111,7,141,1,
++ 111,1,142,10,79,10,143,13,79,13,142,4,111,4,141,10,111,10,140,2,127,15,2,139,
++ 8,127,15,8,139,14,63,14,63,14,138,5,79,4,79,5,137,12,63,12,128,10,63,12,
++ 136,3,79,6,128,5,79,3,135,9,79,1,129,14,63,9,134,1,14,63,10,130,9,63,
++ 14,1,133,7,79,4,130,3,79,7,133,13,63,13,132,12,63,13,132,4,79,8,132,7,
++ 79,4,131,10,79,2,132,1,79,10,130,2,79,12,134,11,79,2,129,6,79,5,134,5,
++ 79,6,128,128,7,79,6,134,9,79,4,129,3,79,12,134,14,79,1,130,13,79,1,132,
++ 4,79,10,131,8,79,5,132,8,79,5,131,3,79,9,132,13,63,14,133,12,63,14,131,
++ 2,79,9,133,7,79,3,130,6,79,4,133,2,79,7,130,10,63,14,135,12,63,12,130,
++ 14,63,9,135,7,79,1,128,4,79,3,135,1,79,5,128,8,63,13,137,11,63,9,128,
++ 12,63,8,137,6,63,14,2,79,3,137,1,79,9,63,13,139,10,127,15,7,139,5,127,
++ 15,2,139,1,14,111,12,141,10,111,7,141,4,111,2,142,14,79,11,143,9,79,6,143,
++ 8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,
++ 8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,8,79,4,143,
++ 8,79,4,143,6,79,3,135,128,10,127,127,11,129,11,127,127,13,129,11,127,127,13,129,
++ 11,127,127,13,129,10,127,127,12,140,8,79,9,139,1,14,79,3,139,6,79,11,140,13,
++ 79,4,139,5,79,12,140,12,79,5,139,4,79,13,140,11,79,6,139,3,79,14,1,139,
++ 10,79,7,139,2,79,14,1,139,8,79,9,139,1,14,79,2,139,7,79,10,140,14,79,
++ 3,139,6,79,11,140,13,79,4,139,5,79,12,140,12,79,5,139,3,79,13,140,10,79,
++ 6,139,2,79,14,1,139,9,79,8,139,1,95,1,139,8,79,9,140,11,127,127,11,129,
++ 11,127,127,13,129,11,127,127,13,129,11,127,127,13,129,10,127,127,11,128,128,8,127,15,
++ 11,133,10,127,15,13,133,10,127,15,13,133,10,127,15,13,133,10,127,15,11,133,10,79,
++ 3,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
++ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
++ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
++ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
++ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,
++ 2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,2,137,10,79,3,137,10,127,
++ 15,11,133,10,127,15,13,133,10,127,15,13,133,10,127,15,13,133,8,127,15,11,132,129,
++ 10,63,14,1,139,7,79,5,139,2,79,10,140,13,63,14,140,8,79,4,139,4,79,8,
++ 140,14,63,13,140,10,79,3,139,5,79,7,139,1,79,12,140,11,79,1,139,6,79,6,
++ 139,2,79,10,140,12,63,14,140,8,79,4,139,3,79,9,140,14,63,13,140,9,79,3,
++ 139,5,79,8,139,1,14,63,12,140,11,79,2,139,6,79,6,139,1,79,11,140,12,79,
++ 1,139,7,79,5,139,3,79,9,140,13,63,14,140,9,79,4,139,4,79,8,140,14,63,
++ 13,140,10,79,2,139,5,79,7,139,1,79,11,140,11,79,1,139,6,79,4,131,4,127,
++ 15,14,1,132,5,127,31,1,132,5,127,31,1,132,5,127,31,1,132,4,127,31,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,
++ 11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,137,11,79,1,132,
++ 4,127,31,1,132,5,127,31,1,132,5,127,31,1,132,5,127,31,1,132,4,127,15,14,
++ 1,128,134,4,63,13,142,9,79,4,141,14,79,8,140,4,95,13,140,9,111,3,139,14,
++ 111,8,138,4,63,13,47,13,138,9,47,14,5,63,3,137,14,47,10,128,14,47,8,136,
++ 4,63,6,128,10,47,13,136,9,63,1,128,6,63,3,135,13,47,12,129,2,63,8,134,
++ 3,63,7,130,12,47,13,134,8,63,3,130,8,63,3,133,13,47,13,131,3,63,8,132,
++ 3,63,9,132,14,47,13,132,8,63,4,132,10,63,3,131,13,47,14,1,132,5,63,8,
++ 130,3,63,11,133,1,63,12,130,6,63,5,134,10,63,1,255,255,187,1,14,127,127,15,
++ 4,2,127,127,31,6,2,127,127,31,6,2,127,127,31,6,1,14,127,127,15,4,128,10,
++ 47,14,3,131,2,14,47,11,132,5,63,5,132,9,47,14,1,132,12,47,8,132,2,14,
++ 31,14,1,255,255,161,133,1,6,11,13,30,13,10,6,1,138,6,14,127,14,6,136,9,
++ 127,63,8,134,7,127,95,6,132,1,14,127,95,14,1,131,6,95,6,1,2,8,95,6,
++ 131,9,79,8,131,8,79,10,131,8,76,3,131,2,79,12,143,79,13,143,14,63,13,135,
++ 4,9,12,30,127,13,133,5,13,127,79,13,132,8,127,111,13,131,5,127,127,13,131,13,
++ 79,13,6,2,130,14,63,13,130,3,79,14,2,132,14,63,13,130,6,79,9,133,14,63,
++ 13,130,7,79,6,133,79,13,130,8,79,8,132,2,79,13,130,7,79,12,132,10,79,13,
++ 130,6,95,9,2,1,4,11,95,13,130,2,127,127,15,13,131,12,127,127,13,131,3,14,
++ 127,111,13,132,4,13,127,6,14,63,13,133,1,6,11,14,15,14,12,8,2,128,13,63,
++ 11,129,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,
++ 11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,2,8,12,30,13,
++ 8,2,134,11,79,7,14,111,6,133,11,127,111,5,132,11,127,111,14,1,131,11,127,127,
++ 6,131,11,95,8,2,1,6,14,79,10,131,11,79,9,131,5,79,13,131,11,79,3,132,
++ 14,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
++ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
++ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,12,63,14,131,11,79,1,132,
++ 12,63,14,131,11,79,1,132,12,63,14,131,11,79,3,132,14,63,14,131,11,79,9,131,
++ 5,79,13,131,11,95,7,2,1,6,14,79,10,131,11,127,127,6,131,11,127,111,14,1,
++ 131,11,127,111,5,132,11,79,11,127,6,133,9,63,14,1,3,10,13,15,14,13,9,2,
++ 132,133,3,8,12,14,15,14,13,10,6,1,136,1,10,127,15,14,6,134,1,13,127,63,
++ 8,133,12,127,95,6,131,5,127,111,14,1,130,11,79,14,5,1,2,9,95,5,130,14,
++ 79,4,131,9,79,8,129,1,79,13,132,4,79,10,129,1,79,11,132,2,79,8,129,1,
++ 79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,79,11,141,1,
++ 79,11,141,1,79,11,133,66,130,1,79,11,132,2,79,9,129,1,79,13,132,4,79,10,
++ 130,14,79,4,131,10,79,8,130,11,79,14,5,1,2,9,95,5,130,6,127,111,14,1,
++ 131,12,127,95,7,132,2,13,127,63,9,134,1,11,127,15,14,6,137,3,8,12,14,15,
++ 14,13,10,6,1,132,140,2,79,7,142,4,79,8,142,4,79,8,142,4,79,8,142,4,
++ 79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,134,3,9,13,30,12,
++ 7,1,4,79,8,133,8,111,13,7,79,8,132,7,127,111,8,131,2,127,127,8,131,8,
++ 127,127,8,131,12,79,13,4,1,2,10,95,8,131,95,3,131,11,79,8,130,1,79,12,
++ 132,6,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
++ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
++ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,
++ 132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,12,132,5,79,8,131,95,3,131,
++ 11,79,8,131,12,79,13,4,1,2,9,95,8,131,8,127,127,8,131,2,127,127,8,132,
++ 7,127,111,8,133,8,127,11,79,8,134,3,9,13,14,15,13,9,3,2,79,7,129,133,
++ 3,8,12,14,15,14,13,10,6,1,136,1,10,127,15,14,5,134,1,13,127,63,7,133,
++ 12,127,95,5,131,5,127,111,13,131,11,79,14,5,1,2,9,95,3,130,14,79,4,131,
++ 11,79,7,129,1,79,13,132,5,79,8,129,1,79,11,132,3,79,9,129,1,79,11,132,
++ 2,79,9,129,1,79,11,132,3,79,9,129,1,127,127,15,9,129,1,127,127,15,9,129,
++ 1,127,127,15,9,129,1,127,127,15,7,129,1,79,11,141,1,79,11,141,1,79,11,141,
++ 1,79,13,132,3,14,63,5,130,14,79,4,131,10,79,5,130,11,79,14,5,1,2,9,
++ 95,1,130,6,127,111,11,132,12,127,95,3,132,2,14,127,63,7,134,1,11,127,15,14,
++ 6,137,3,8,12,14,15,14,13,10,6,1,132,134,4,9,12,46,1,133,3,12,95,2,
++ 132,2,14,111,1,132,10,127,1,131,1,127,14,132,4,95,7,2,133,6,79,9,135,7,
++ 79,5,135,7,79,5,133,12,127,47,3,129,14,127,47,4,129,14,127,47,4,129,12,127,
++ 47,3,131,7,79,5,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
++ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
++ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,7,
++ 79,4,135,7,79,4,135,7,79,4,135,7,79,4,135,5,79,3,132,132,4,10,13,15,
++ 14,12,7,1,2,79,7,133,10,111,13,6,79,8,132,9,127,111,8,131,3,127,127,8,
++ 131,9,127,127,8,131,12,79,14,5,1,2,10,95,8,131,95,4,131,12,79,8,130,1,
++ 79,13,132,6,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
++ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
++ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,
++ 79,11,132,4,79,8,130,1,79,11,132,4,79,8,130,1,79,13,132,6,79,8,131,95,
++ 4,131,12,79,8,131,12,79,14,5,1,2,10,95,8,131,8,127,127,8,131,2,127,127,
++ 8,132,8,127,15,14,79,8,133,9,111,12,5,79,8,134,4,10,13,15,14,11,6,128,
++ 5,79,7,142,6,79,7,142,10,79,5,141,1,14,79,2,140,1,11,79,14,138,1,3,
++ 7,14,95,8,136,13,127,47,2,136,14,127,31,7,137,14,127,15,9,138,14,111,13,6,
++ 139,11,31,14,13,11,8,4,135,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,
++ 79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,
++ 79,1,128,7,12,14,15,13,10,3,134,11,79,3,13,111,7,133,11,79,14,127,15,5,
++ 132,11,127,111,14,132,11,127,127,5,131,11,95,8,17,6,14,79,8,131,11,79,10,131,
++ 7,79,11,131,11,79,4,131,2,79,12,131,11,79,2,132,79,13,131,11,79,1,132,14,
++ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
++ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
++ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
++ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
++ 63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,
++ 63,13,131,9,63,14,1,132,13,63,11,129,130,7,13,14,12,4,132,8,79,3,130,1,
++ 95,10,130,2,95,12,130,1,95,10,131,8,79,3,132,7,13,14,12,4,165,6,79,3,
++ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
++ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
++ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
++ 131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,131,8,79,4,
++ 131,6,79,3,129,132,1,8,13,14,11,3,135,10,63,14,2,133,2,95,8,133,5,95,
++ 10,133,2,95,8,134,10,63,14,2,134,1,8,13,14,11,3,191,9,63,14,1,134,11,
++ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
++ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
++ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
++ 79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,79,1,134,11,
++ 79,1,134,11,79,1,134,12,79,1,133,1,14,79,134,7,79,14,132,2,7,95,11,130,
++ 4,127,15,8,130,5,127,15,2,130,5,127,7,131,5,95,14,5,132,4,15,30,12,9,
++ 5,134,129,9,63,14,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,
++ 11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,142,11,79,1,131,3,14,63,11,
++ 131,11,79,1,131,12,79,3,131,11,79,1,130,7,79,9,132,11,79,1,129,2,14,63,
++ 13,1,132,11,79,1,129,10,79,4,133,11,79,1,128,5,79,9,134,11,79,17,13,63,
++ 14,1,134,11,79,1,8,79,5,135,11,79,4,79,10,136,11,79,14,79,9,136,11,127,
++ 47,14,136,11,127,63,5,135,11,127,63,11,135,11,127,79,1,134,11,111,4,79,7,134,
++ 11,95,8,128,10,63,12,134,11,79,13,1,128,6,79,3,133,11,79,4,129,1,79,8,
++ 133,11,79,1,130,11,63,14,133,11,79,1,130,6,79,5,132,11,79,1,130,1,79,10,
++ 132,11,79,1,131,11,79,1,131,11,79,1,131,6,79,6,131,11,79,1,131,2,79,12,
++ 131,11,79,1,132,12,79,2,130,9,63,14,1,132,6,79,6,128,129,11,63,12,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,63,14,131,14,
++ 63,14,131,14,63,14,131,14,63,14,131,12,63,12,129,129,9,63,14,128,2,8,12,30,
++ 12,8,2,131,5,10,13,15,14,11,5,134,11,79,8,111,14,4,128,1,11,111,10,133,
++ 11,127,95,14,3,11,127,15,9,132,11,127,127,127,47,3,131,11,127,127,127,47,8,131,
++ 11,95,7,17,8,111,13,3,128,3,12,79,12,131,11,79,10,131,11,95,3,130,2,95,
++ 131,11,79,4,131,5,79,12,132,12,79,1,130,11,79,1,131,3,79,10,132,10,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,11,79,1,131,2,79,9,132,9,79,2,130,11,79,1,131,2,79,9,132,9,79,2,
++ 130,9,63,14,132,1,14,63,7,132,7,63,14,1,128,129,9,63,14,17,8,12,14,15,
++ 13,10,3,134,11,79,6,14,111,7,133,11,127,111,5,132,11,127,111,14,132,11,127,127,
++ 5,131,11,95,8,17,6,14,79,8,131,11,79,10,131,7,79,11,131,11,79,4,131,2,
++ 79,12,131,11,79,2,132,79,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
++ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
++ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
++ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
++ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,
++ 13,131,11,79,1,132,14,63,13,131,11,79,1,132,14,63,13,131,9,63,14,1,132,13,
++ 63,11,129,133,3,8,12,14,15,14,13,10,6,1,137,1,10,127,15,14,6,135,1,13,
++ 127,63,9,134,12,127,95,6,132,5,127,111,14,1,131,11,79,14,5,1,2,8,95,5,
++ 131,14,79,4,131,9,79,9,130,1,79,13,132,3,79,11,130,1,79,11,132,1,79,11,
++ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
++ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
++ 130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,130,1,79,11,132,1,79,11,
++ 130,1,79,13,132,3,79,11,131,14,79,4,131,9,79,9,131,11,79,14,5,1,2,8,
++ 95,6,131,6,127,111,14,1,132,12,127,95,7,133,2,13,127,63,10,135,1,11,127,15,
++ 14,7,138,3,8,12,14,15,14,13,11,7,1,133,129,6,79,3,2,9,13,30,13,9,
++ 3,134,8,79,11,127,8,133,8,127,111,8,132,8,127,127,3,131,8,127,127,9,131,8,
++ 95,10,2,1,4,13,79,13,131,8,79,12,131,3,95,1,130,8,79,7,132,11,79,2,
++ 130,8,79,5,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
++ 130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
++ 130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,130,8,79,4,132,9,79,2,
++ 130,8,79,5,132,9,79,2,130,8,79,7,132,11,79,2,130,8,79,12,131,2,95,1,
++ 130,8,95,10,2,1,4,13,79,13,131,8,127,127,9,131,8,127,127,3,131,8,127,111,
++ 8,132,8,79,8,13,111,9,133,8,79,4,1,7,12,14,15,13,10,3,134,8,79,4,
++ 142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,142,8,79,4,
++ 142,8,79,4,142,6,79,3,140,132,3,9,13,30,13,9,18,79,7,133,8,127,11,79,
++ 8,132,7,127,111,8,131,2,127,127,8,131,8,127,127,8,131,12,79,14,5,1,2,10,
++ 95,8,131,95,3,131,11,79,8,130,1,79,12,132,6,79,8,130,1,79,10,132,4,79,
++ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
++ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
++ 8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,8,130,1,79,10,132,4,79,
++ 8,130,1,79,12,132,5,79,8,131,95,3,131,11,79,8,131,12,79,13,4,1,2,9,
++ 95,8,131,8,127,127,8,131,2,127,127,8,132,7,127,111,8,133,8,111,13,7,79,8,
++ 134,3,9,13,30,12,7,1,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,
++ 4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,4,79,8,142,3,79,7,129,
++ 129,9,63,14,1,128,6,12,30,10,130,11,79,1,9,79,2,129,11,79,6,79,14,130,
++ 11,79,14,79,11,130,11,127,47,9,130,11,127,47,6,130,11,95,14,6,2,1,3,1,
++ 130,11,95,3,135,11,79,10,136,11,79,4,136,11,79,2,136,11,79,1,136,11,79,1,
++ 136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,
++ 136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,136,11,79,1,
++ 136,9,63,14,1,134,132,1,7,11,13,30,13,11,6,1,136,6,14,127,14,5,134,7,
++ 127,63,6,132,3,127,95,3,131,11,127,95,11,130,1,95,8,2,1,5,14,79,1,129,
++ 3,79,10,131,5,79,5,129,3,79,5,132,79,6,129,3,79,7,132,7,57,3,129,1,
++ 79,14,4,140,11,95,9,2,138,4,127,11,5,137,8,127,15,13,6,136,6,14,127,15,
++ 12,2,135,2,10,127,15,14,2,136,2,8,14,111,13,138,1,6,13,95,6,139,1,12,
++ 79,10,129,3,57,8,132,3,79,12,129,7,79,1,131,1,79,12,129,6,79,6,131,4,
++ 79,10,129,2,79,14,7,2,1,5,13,79,6,130,10,127,95,13,131,1,12,127,63,14,
++ 3,132,1,9,127,31,11,2,135,2,7,11,30,15,14,12,9,3,132,130,7,63,14,135,
++ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,9,79,1,131,1,14,127,31,
++ 13,128,2,127,63,128,2,127,63,128,1,14,127,31,14,131,8,79,1,134,8,79,1,134,
++ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,
++ 8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,8,79,1,134,
++ 8,79,1,134,8,79,4,134,8,79,13,3,133,6,127,7,131,3,127,9,132,12,111,9,
++ 132,2,13,95,9,133,1,6,11,13,14,31,7,128,129,12,63,12,132,1,14,63,8,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,14,63,14,132,2,79,10,131,
++ 14,63,14,132,2,79,10,131,14,63,14,132,3,79,10,131,14,79,1,131,5,79,10,131,
++ 13,79,6,131,11,79,10,131,11,79,14,5,17,9,95,10,131,8,127,127,10,131,2,127,
++ 127,10,132,8,127,111,10,133,9,111,14,5,79,10,134,3,10,13,15,14,13,8,17,14,
++ 63,8,129,128,14,79,3,132,6,79,11,129,14,79,6,132,10,79,9,129,10,79,9,132,
++ 13,79,5,129,6,79,12,131,1,95,2,129,3,95,131,3,79,13,131,14,79,3,130,6,
++ 79,9,131,10,79,6,130,9,79,6,131,7,79,8,130,12,79,2,131,3,79,11,130,14,
++ 63,13,133,14,63,14,129,2,79,10,133,10,79,2,128,5,79,6,133,7,79,5,128,8,
++ 79,2,133,3,79,7,128,11,63,14,135,14,63,10,128,14,63,10,135,10,63,13,1,79,
++ 6,135,7,79,5,79,3,135,3,79,12,63,14,137,14,127,15,10,137,10,127,15,7,137,
++ 7,127,15,3,137,3,127,14,139,14,111,11,139,11,111,7,139,7,111,3,139,3,95,14,
++ 141,13,79,10,134,128,14,63,7,132,11,63,5,132,11,63,9,129,14,63,11,132,14,63,
++ 9,132,79,7,129,11,63,13,131,2,79,11,131,3,79,4,129,8,79,1,130,5,79,14,
++ 131,5,79,1,129,4,79,3,130,7,95,1,130,8,63,12,130,1,79,5,130,10,95,4,
++ 130,10,63,9,131,13,63,8,130,12,95,7,130,13,63,6,131,9,63,10,130,111,9,130,
++ 79,3,131,6,63,13,129,3,111,12,129,2,63,14,132,3,79,129,5,111,14,129,5,63,
++ 11,133,14,63,3,128,8,47,14,63,2,128,7,63,8,133,11,63,5,128,10,47,7,63,
++ 5,128,10,63,5,133,8,63,8,128,13,47,4,13,47,7,128,13,63,1,133,5,63,10,
++ 1,63,1,10,47,10,128,63,13,134,1,63,12,3,47,13,128,7,47,13,2,63,10,135,
++ 13,63,6,47,11,128,5,63,5,63,7,135,10,63,12,47,8,128,2,63,12,63,3,135,
++ 7,127,5,129,14,127,136,3,127,3,129,12,111,12,137,127,130,9,111,9,137,12,95,12,
++ 130,6,111,5,137,9,95,10,130,3,111,2,137,5,95,7,130,1,95,14,138,2,95,4,
++ 131,13,79,11,139,14,79,2,131,10,79,7,139,9,63,13,132,6,79,3,133,128,14,63,
++ 14,2,132,4,79,12,129,9,79,9,132,12,79,7,129,2,95,2,130,4,79,14,1,130,
++ 10,79,8,130,11,79,8,131,3,79,14,1,128,3,79,14,1,132,11,79,7,128,10,79,
++ 8,133,3,79,13,2,95,2,134,11,79,13,79,9,135,4,127,47,2,136,12,127,15,10,
++ 137,5,127,15,2,138,12,111,10,139,5,111,3,139,6,111,3,139,13,111,10,138,5,127,
++ 15,3,137,12,127,15,10,136,4,127,47,2,135,12,79,12,79,9,134,4,79,13,1,14,
++ 79,2,133,11,79,6,128,9,79,8,132,3,79,14,1,128,2,79,14,1,131,10,79,8,
++ 130,10,79,8,130,2,95,1,130,3,79,14,1,129,9,79,9,132,12,79,7,129,14,63,
++ 14,2,132,4,79,12,128,2,79,12,133,11,79,4,1,95,1,132,14,79,2,128,12,79,
++ 4,131,2,79,13,129,8,79,7,131,5,79,9,129,4,79,9,131,7,79,6,129,1,79,
++ 12,131,10,79,2,130,12,79,131,13,63,13,131,8,79,2,130,79,9,131,4,79,5,129,
++ 3,79,6,131,1,79,8,129,6,79,2,132,12,63,11,129,8,63,13,133,8,63,13,129,
++ 11,63,9,133,4,79,1,128,13,63,6,133,1,79,4,1,79,2,134,11,63,6,4,63,
++ 13,135,8,63,9,6,63,9,135,4,63,12,9,63,6,136,79,13,63,2,136,11,127,13,
++ 137,7,127,9,137,4,127,5,138,14,111,2,138,11,95,13,139,7,95,9,139,3,95,5,
++ 140,14,79,2,140,14,63,13,140,2,79,9,140,6,79,5,139,1,13,63,14,1,137,1,
++ 5,12,79,10,136,3,127,15,4,136,4,127,11,137,4,111,14,2,137,4,95,12,2,138,
++ 4,31,14,12,9,4,139,128,7,127,95,14,129,9,127,111,1,128,9,127,111,1,128,9,
++ 127,111,1,128,7,127,111,137,2,95,12,137,10,95,3,136,3,95,10,137,12,79,14,2,
++ 136,5,95,7,137,13,79,13,137,7,95,5,136,1,14,79,11,137,9,95,3,136,2,95,
++ 9,137,11,79,14,1,136,4,95,6,137,12,79,12,137,6,95,4,136,1,14,79,10,137,
++ 7,95,2,137,12,127,111,3,128,12,127,111,4,128,12,127,111,4,128,12,127,111,4,128,
++ 11,127,111,3,134,6,11,14,63,7,133,1,11,111,8,133,8,127,8,133,14,127,8,132,
++ 3,127,15,7,132,5,95,9,1,134,5,79,12,136,5,79,8,136,5,79,7,136,5,79,
++ 7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,
++ 7,136,6,79,7,136,7,79,6,136,11,79,5,135,5,95,2,133,3,11,95,12,134,10,
++ 111,4,134,10,79,14,4,135,10,95,6,135,9,111,4,134,1,6,13,79,13,136,2,14,
++ 79,2,136,10,79,5,136,7,79,6,136,5,79,7,136,5,79,7,136,5,79,7,136,5,
++ 79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,79,7,136,5,
++ 79,8,136,5,79,12,136,5,95,8,1,134,3,127,15,7,133,14,127,8,133,9,127,8,
++ 133,1,12,111,8,135,6,12,14,63,7,128,128,7,63,14,1,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,2,129,10,79,
++ 2,129,10,79,2,129,10,79,2,129,8,63,14,1,128,128,8,63,14,11,6,135,10,111,
++ 11,134,10,127,7,133,10,127,14,133,8,127,15,2,134,2,10,95,4,136,13,79,4,136,
++ 9,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,
++ 8,79,4,136,8,79,4,136,8,79,4,136,7,79,5,136,7,79,6,136,6,79,11,136,
++ 3,95,4,136,13,95,10,3,134,5,111,8,135,5,14,79,8,135,6,95,8,134,5,111,
++ 8,134,13,79,13,5,134,3,79,14,2,135,6,79,9,136,7,79,6,136,8,79,5,136,
++ 8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,8,79,4,136,
++ 8,79,4,136,8,79,4,136,9,79,4,136,13,79,4,134,2,9,95,4,132,8,127,15,
++ 3,132,10,127,14,133,10,127,7,133,10,111,11,134,8,63,14,11,6,134,131,1,7,12,
++ 30,11,5,143,3,13,95,12,4,132,8,14,6,132,3,14,127,15,10,4,17,8,47,11,
++ 2,130,12,127,127,47,5,129,5,127,127,47,10,130,4,14,47,9,2,128,3,10,127,15,
++ 13,1,131,1,10,15,6,132,4,12,95,12,1,134,1,135,5,11,14,15,13,7,1,255,
++ 255,139,130,7,13,14,12,4,132,8,79,4,131,14,79,11,130,2,95,13,131,14,79,11,
++ 131,8,79,4,132,7,13,14,12,4,251,132,3,9,13,15,14,13,9,2,136,9,127,8,
++ 134,11,127,31,11,132,8,127,63,8,130,3,63,12,4,17,5,13,63,2,129,10,47,11,
++ 132,1,12,47,9,129,14,47,2,133,3,47,13,128,1,47,12,135,13,47,128,2,47,10,
++ 135,12,47,17,47,12,135,13,47,129,14,47,2,133,3,47,13,129,10,47,11,132,1,12,
++ 47,9,129,3,63,12,4,17,5,13,63,2,130,8,127,63,7,132,11,127,31,11,134,9,
++ 127,8,136,3,9,13,31,13,9,3,255,255,255,180,130,2,9,1,135,6,5,132,2,13,
++ 15,12,1,133,7,31,5,130,1,13,47,12,1,131,7,63,5,129,4,79,12,1,129,7,
++ 79,10,130,6,79,12,1,7,79,11,1,131,6,79,13,79,11,1,133,6,127,15,11,1,
++ 135,6,111,11,1,137,10,95,2,137,7,111,12,1,135,7,127,15,12,1,133,7,79,13,
++ 79,12,1,131,7,79,11,1,6,79,12,1,129,5,79,11,1,129,6,79,11,129,1,13,
++ 47,11,1,131,6,63,5,130,2,13,15,11,1,133,6,31,5,132,2,8,1,135,5,4,
++ 255,135,128,8,127,111,7,129,10,127,111,8,129,10,127,111,8,129,10,127,111,8,129,8,
++ 127,111,7,255,228,128,8,127,127,127,31,3,129,10,127,127,127,31,4,129,10,127,127,127,
++ 31,4,129,10,127,127,127,31,4,129,8,127,127,127,31,3,255,255,232,129,10,63,14,130,
++ 14,63,11,129,2,79,6,129,6,79,1,129,9,63,11,130,12,63,6,129,1,79,1,129,
++ 4,63,11,130,7,63,6,130,10,63,1,130,12,47,10,255,219,130,7,13,14,12,4,133,
++ 2,10,30,10,2,133,4,12,14,13,7,132,9,79,3,131,1,13,63,13,132,3,79,9,
++ 130,1,95,9,131,5,95,5,131,10,95,1,129,3,95,12,131,8,95,7,131,12,95,3,
++ 129,1,95,9,131,5,95,5,131,10,95,1,130,9,79,3,131,1,13,63,12,132,3,79,
++ 8,132,7,13,14,11,3,133,2,10,30,10,1,133,4,12,14,13,7,130,131,3,10,13,
++ 15,14,10,4,134,8,111,10,132,7,127,15,9,130,2,127,47,3,129,7,127,47,9,129,
++ 9,127,47,11,129,9,127,47,11,129,6,127,47,8,129,1,14,127,31,2,130,6,127,15,
++ 8,132,7,111,8,134,3,9,13,15,13,10,4,236,133,6,63,11,135,1,14,63,5,135,
++ 9,63,11,135,2,79,3,135,10,63,9,135,4,63,14,1,135,12,63,7,135,5,63,13,
++ 136,11,63,6,136,6,63,12,137,12,63,6,136,4,63,14,1,136,11,63,8,136,2,79,
++ 2,136,9,63,11,136,1,14,63,5,136,6,63,12,205,130,13,63,4,137,7,63,13,138,
++ 13,63,6,137,4,63,14,1,137,11,63,8,137,2,79,2,137,8,63,10,137,1,14,63,
++ 3,137,8,63,9,136,1,13,63,4,136,8,63,11,136,2,79,2,136,10,63,9,136,4,
++ 63,14,1,136,12,63,7,136,7,63,13,137,13,63,4,214,
++};
++static const struct fos_glyph xl_glyphs[] = {
++ { 0, 10, 0, 0, 0, 160 }, /* 0x20 */
++ { 0, 13, 35, 0, -35, 215 }, /* 0x21 */
++ { 124, 15, 35, 0, -35, 245 }, /* 0x22 */
++ { 211, 30, 34, 0, -34, 485 }, /* 0x23 */
++ { 456, 22, 43, 0, -39, 347 }, /* 0x24 */
++ { 721, 39, 35, 0, -35, 618 }, /* 0x25 */
++ { 1103, 29, 35, 0, -35, 465 }, /* 0x26 */
++ { 1393, 8, 35, 0, -35, 122 }, /* 0x27 */
++ { 1439, 14, 43, 0, -38, 223 }, /* 0x28 */
++ { 1612, 14, 43, 0, -38, 223 }, /* 0x29 */
++ { 1781, 18, 38, 0, -38, 289 }, /* 0x2a */
++ { 1918, 22, 26, 0, -26, 351 }, /* 0x2b */
++ { 2006, 10, 12, 0, -7, 159 }, /* 0x2c */
++ { 2055, 16, 18, 0, -18, 260 }, /* 0x2d */
++ { 2082, 11, 7, 0, -7, 169 }, /* 0x2e */
++ { 2115, 19, 35, 0, -35, 309 }, /* 0x2f */
++ { 2256, 23, 35, 0, -35, 360 }, /* 0x30 */
++ { 2525, 14, 35, 0, -35, 219 }, /* 0x31 */
++ { 2679, 21, 35, 0, -35, 340 }, /* 0x32 */
++ { 2883, 21, 35, 0, -35, 341 }, /* 0x33 */
++ { 3095, 23, 35, 0, -35, 367 }, /* 0x34 */
++ { 3259, 21, 35, 0, -35, 342 }, /* 0x35 */
++ { 3469, 21, 35, 0, -35, 343 }, /* 0x36 */
++ { 3700, 20, 35, 0, -35, 314 }, /* 0x37 */
++ { 3860, 22, 35, 0, -35, 347 }, /* 0x38 */
++ { 4115, 21, 35, 0, -35, 338 }, /* 0x39 */
++ { 4373, 13, 24, 0, -24, 202 }, /* 0x3a */
++ { 4439, 11, 29, 0, -25, 174 }, /* 0x3b */
++ { 4524, 22, 26, 0, -26, 351 }, /* 0x3c */
++ { 4665, 22, 22, 0, -22, 351 }, /* 0x3d */
++ { 4715, 22, 26, 0, -26, 351 }, /* 0x3e */
++ { 4856, 21, 35, 0, -35, 330 }, /* 0x3f */
++ { 5032, 38, 36, 0, -32, 607 }, /* 0x40 */
++ { 5477, 23, 35, 0, -35, 365 }, /* 0x41 */
++ { 5708, 23, 35, 0, -35, 370 }, /* 0x42 */
++ { 5970, 23, 35, 0, -35, 366 }, /* 0x43 */
++ { 6188, 24, 35, 0, -35, 378 }, /* 0x44 */
++ { 6454, 22, 35, 0, -35, 348 }, /* 0x45 */
++ { 6620, 21, 35, 0, -35, 332 }, /* 0x46 */
++ { 6776, 23, 35, 0, -35, 370 }, /* 0x47 */
++ { 7022, 24, 35, 0, -35, 382 }, /* 0x48 */
++ { 7295, 11, 35, 0, -35, 179 }, /* 0x49 */
++ { 7436, 22, 35, 0, -35, 354 }, /* 0x4a */
++ { 7628, 24, 35, 0, -35, 382 }, /* 0x4b */
++ { 7895, 21, 35, 0, -35, 332 }, /* 0x4c */
++ { 8045, 27, 35, 0, -35, 430 }, /* 0x4d */
++ { 8356, 25, 35, 0, -35, 406 }, /* 0x4e */
++ { 8671, 23, 35, 0, -35, 374 }, /* 0x4f */
++ { 8946, 23, 35, 0, -35, 366 }, /* 0x50 */
++ { 9152, 23, 41, 0, -35, 364 }, /* 0x51 */
++ { 9450, 23, 35, 0, -35, 369 }, /* 0x52 */
++ { 9715, 22, 35, 0, -35, 347 }, /* 0x53 */
++ { 9951, 23, 35, 0, -35, 362 }, /* 0x54 */
++ { 10102, 24, 35, 0, -35, 382 }, /* 0x55 */
++ { 10376, 24, 35, 0, -35, 377 }, /* 0x56 */
++ { 10610, 33, 35, 0, -35, 532 }, /* 0x57 */
++ { 10998, 23, 35, 0, -35, 368 }, /* 0x58 */
++ { 11235, 23, 35, 0, -35, 365 }, /* 0x59 */
++ { 11432, 20, 35, 0, -35, 325 }, /* 0x5a */
++ { 11588, 17, 46, 0, -39, 264 }, /* 0x5b */
++ { 11783, 19, 35, 0, -35, 309 }, /* 0x5c */
++ { 11925, 17, 46, 0, -39, 264 }, /* 0x5d */
++ { 12122, 21, 35, 0, -35, 330 }, /* 0x5e */
++ { 12259, 20, 5, 0, -5, 324 }, /* 0x5f */
++ { 12286, 10, 35, 0, -35, 165 }, /* 0x60 */
++ { 12318, 22, 26, 0, -26, 347 }, /* 0x61 */
++ { 12506, 22, 35, 0, -35, 350 }, /* 0x62 */
++ { 12745, 21, 26, 0, -26, 338 }, /* 0x63 */
++ { 12918, 22, 35, 0, -35, 350 }, /* 0x64 */
++ { 13151, 21, 26, 0, -26, 341 }, /* 0x65 */
++ { 13333, 15, 35, 0, -35, 233 }, /* 0x66 */
++ { 13483, 22, 36, 0, -26, 345 }, /* 0x67 */
++ { 13737, 22, 35, 0, -35, 351 }, /* 0x68 */
++ { 13980, 11, 36, 0, -36, 172 }, /* 0x69 */
++ { 14117, 14, 47, -3, -37, 169 }, /* 0x6a */
++ { 14306, 22, 35, 0, -35, 346 }, /* 0x6b */
++ { 14538, 10, 35, 0, -35, 159 }, /* 0x6c */
++ { 14679, 33, 26, 0, -26, 532 }, /* 0x6d */
++ { 14991, 22, 26, 0, -26, 351 }, /* 0x6e */
++ { 15195, 22, 26, 0, -26, 346 }, /* 0x6f */
++ { 15398, 22, 35, 0, -26, 353 }, /* 0x70 */
++ { 15633, 22, 35, 0, -26, 353 }, /* 0x71 */
++ { 15864, 16, 26, 0, -26, 250 }, /* 0x72 */
++ { 15990, 20, 26, 0, -26, 318 }, /* 0x73 */
++ { 16171, 14, 32, 0, -32, 226 }, /* 0x74 */
++ { 16310, 22, 26, 0, -26, 350 }, /* 0x75 */
++ { 16515, 21, 26, 0, -26, 332 }, /* 0x76 */
++ { 16685, 30, 26, 0, -26, 474 }, /* 0x77 */
++ { 16965, 21, 26, 0, -26, 334 }, /* 0x78 */
++ { 17143, 20, 36, 0, -26, 322 }, /* 0x79 */
++ { 17359, 18, 26, 0, -26, 294 }, /* 0x7a */
++ { 17476, 16, 46, 0, -39, 255 }, /* 0x7b */
++ { 17676, 9, 42, 0, -38, 137 }, /* 0x7c */
++ { 17847, 16, 46, 0, -39, 255 }, /* 0x7d */
++ { 18044, 24, 19, 0, -19, 384 }, /* 0x7e */
++ { 18122, 11, 18, 0, -18, 172 }, /* 0x80 */
++ { 18155, 18, 41, 0, -41, 287 }, /* 0x81 */
++ { 18278, 19, 24, 0, -24, 311 }, /* 0x82 */
++ { 18410, 19, 17, 0, -17, 302 }, /* 0x83 */
++ { 18437, 30, 17, 0, -17, 474 }, /* 0x84 */
++ { 18475, 9, 35, 0, -35, 132 }, /* 0x85 */
++ { 18521, 34, 7, 0, -7, 543 }, /* 0x86 */
++ { 18620, 15, 19, 0, -19, 242 }, /* 0x87 */
++ { 18686, 15, 22, 0, -22, 238 }, /* 0x88 */
++ { 18759, 16, 22, 0, -22, 249 }, /* 0x89 */
++};
++static const uint8_t xl_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
++ 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
++ 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
++ 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,
++ 88,89,90,91,92,93,94,255,95,96,97,98,99,100,101,102,103,104,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern xl_kern[] = {
++ {39,45,-19},{39,65,-34},{39,74,-41},{39,97,-12},{39,99,-19},{39,100,-19},{39,101,-19},{39,111,-19},
++ {39,115,-16},{44,48,-32},{44,55,-25},{44,75,-7},{44,76,-7},{44,84,-41},{44,86,-26},{44,87,-26},
++ {44,88,8},{44,89,-54},{44,118,-14},{44,119,-14},{44,121,-14},{45,39,-5},{45,45,-46},{45,118,-12},
++ {45,119,-12},{45,120,-13},{45,121,-12},{46,48,-32},{46,55,-25},{46,75,-7},{46,76,-7},{46,84,-41},
++ {46,86,-26},{46,87,-26},{46,88,8},{46,89,-54},{46,118,-14},{46,119,-14},{46,121,-14},{49,49,-10},
++ {50,49,-17},{51,49,-20},{52,49,-41},{52,55,-42},{53,49,-10},{54,49,-14},{55,44,-39},{55,46,-39},
++ {56,49,-18},{57,49,-18},{65,39,-34},{65,65,18},{65,67,-13},{65,71,-13},{65,79,-13},{65,81,-13},
++ {65,83,-18},{65,84,-47},{65,86,-55},{65,87,-55},{65,89,-38},{65,102,-4},{65,116,-4},{65,117,-9},
++ {65,118,-26},{65,119,-26},{65,120,10},{65,121,-26},{65,133,-40},{66,44,-7},{66,46,-7},{66,65,-16},
++ {66,86,-17},{66,87,-17},{66,88,-18},{66,89,-22},{66,115,-7},{66,118,-5},{66,119,-5},{66,121,-5},
++ {67,45,-6},{67,65,-6},{67,88,-9},{67,89,-8},{67,99,-6},{67,100,-6},{67,101,-6},{67,111,-6},
++ {67,118,-5},{67,119,-5},{67,121,-5},{68,44,-7},{68,46,-7},{68,65,-16},{68,86,-17},{68,87,-17},
++ {68,88,-18},{68,89,-22},{68,115,-7},{68,118,-5},{68,119,-5},{68,121,-5},{69,65,15},{69,74,10},
++ {70,45,-25},{70,65,-29},{70,74,-7},{70,97,-18},{70,99,-25},{70,100,-25},{70,101,-25},{70,102,-5},
++ {70,103,-25},{70,109,-25},{70,110,-25},{70,111,-25},{70,112,-25},{70,113,-25},{70,114,-25},{70,115,-21},
++ {70,116,-5},{70,117,-13},{70,118,-14},{70,119,-14},{70,120,-14},{70,121,-14},{70,122,-14},{71,45,-6},
++ {71,65,-6},{71,88,-9},{71,89,-8},{71,99,-6},{71,100,-6},{71,101,-6},{71,111,-6},{71,118,-5},
++ {71,119,-5},{71,121,-5},{74,44,-7},{74,46,-7},{74,65,-9},{74,66,-7},{74,68,-7},{74,69,-7},
++ {74,70,-7},{74,78,-7},{74,80,-7},{75,44,7},{75,46,7},{75,65,10},{75,67,-13},{75,71,-13},
++ {75,79,-13},{75,81,-13},{75,83,-14},{76,44,7},{76,46,7},{76,65,21},{76,84,-60},{76,89,-25},
++ {76,102,-10},{76,116,-10},{79,45,-6},{79,65,-6},{79,88,-9},{79,89,-8},{79,99,-6},{79,100,-6},
++ {79,101,-6},{79,111,-6},{79,118,-5},{79,119,-5},{79,121,-5},{80,44,-21},{80,46,-21},{80,65,-25},
++ {80,74,-36},{80,86,-9},{80,87,-9},{80,88,-14},{80,89,-14},{81,45,-6},{81,65,-6},{81,88,-8},
++ {81,89,-9},{81,99,-6},{81,100,-6},{81,101,-6},{81,111,-6},{81,118,-5},{81,119,-5},{81,121,-5},
++ {82,65,6},{82,89,-18},{83,84,-7},{83,86,-10},{83,87,-10},{83,88,-21},{83,89,-18},{83,118,-5},
++ {83,119,-5},{83,121,-5},{84,44,-35},{84,45,-50},{84,46,-35},{84,65,-38},{84,67,-19},{84,71,-19},
++ {84,79,-19},{84,81,-19},{84,97,-32},{84,99,-50},{84,100,-50},{84,101,-50},{84,102,-9},{84,103,-46},
++ {84,109,-22},{84,110,-22},{84,111,-50},{84,112,-22},{84,113,-46},{84,114,-22},{84,115,-40},{84,116,-9},
++ {84,117,-13},{84,118,-24},{84,119,-24},{84,120,-10},{84,121,-24},{84,122,-18},{85,44,-7},{85,46,-7},
++ {85,65,-9},{85,66,-7},{85,68,-7},{85,69,-7},{85,70,-7},{85,78,-7},{85,80,-7},{86,44,-25},
++ {86,45,-36},{86,46,-25},{86,65,-53},{86,67,-11},{86,71,-11},{86,74,-22},{86,79,-11},{86,81,-11},
++ {86,83,-10},{86,97,-19},{86,99,-36},{86,100,-36},{86,101,-36},{86,102,-10},{86,103,-26},{86,109,-14},
++ {86,110,-14},{86,111,-36},{86,112,-14},{86,113,-26},{86,114,-14},{86,115,-30},{86,116,-10},{86,117,-5},
++ {86,118,-8},{86,119,-8},{86,120,-14},{86,121,-8},{86,122,-9},{87,44,-25},{87,45,-36},{87,46,-25},
++ {87,65,-53},{87,67,-11},{87,71,-11},{87,74,-22},{87,79,-11},{87,81,-11},{87,83,-10},{87,97,-19},
++ {87,99,-36},{87,100,-36},{87,101,-36},{87,102,-10},{87,103,-26},{87,109,-14},{87,110,-14},{87,111,-36},
++ {87,112,-14},{87,113,-26},{87,114,-14},{87,115,-30},{87,116,-10},{87,117,-5},{87,118,-8},{87,119,-8},
++ {87,120,-14},{87,121,-8},{87,122,-9},{88,45,-9},{88,67,-10},{88,71,-10},{88,74,-5},{88,79,-10},
++ {88,81,-10},{88,83,-21},{88,99,-9},{88,100,-9},{88,101,-9},{88,102,-9},{88,103,-9},{88,111,-9},
++ {88,113,-9},{88,115,-9},{88,116,-9},{88,117,-9},{88,118,-30},{88,119,-30},{88,121,-30},{89,44,-54},
++ {89,45,-42},{89,46,-54},{89,65,-50},{89,66,-10},{89,67,-14},{89,68,-10},{89,69,-10},{89,70,-10},
++ {89,71,-14},{89,74,-36},{89,78,-10},{89,79,-14},{89,80,-10},{89,81,-14},{89,82,-4},{89,83,-18},
++ {89,99,-42},{89,100,-42},{89,101,-42},{89,102,-18},{89,103,-41},{89,109,-25},{89,110,-25},{89,111,-42},
++ {89,112,-25},{89,113,-41},{89,114,-25},{89,116,-18},{89,117,-22},{89,118,-27},{89,119,-27},{89,120,-14},
++ {89,121,-27},{89,122,-14},{97,39,-10},{97,118,-9},{97,119,-9},{97,121,-9},{97,133,-10},{98,39,-4},
++ {98,44,-7},{98,46,-7},{98,118,-5},{98,119,-5},{98,120,-9},{98,121,-5},{99,102,-4},{99,116,-4},
++ {99,118,-13},{99,119,-13},{99,120,-9},{99,121,-13},{101,39,-8},{101,97,-4},{101,118,-9},{101,119,-9},
++ {101,121,-9},{101,133,-9},{102,103,-7},{102,113,-7},{102,133,16},{103,118,-7},{103,119,-7},{103,121,-7},
++ {104,39,-4},{104,44,-7},{104,46,-7},{104,118,-5},{104,119,-5},{104,120,-9},{104,121,-5},{105,106,-5},
++ {107,45,-14},{107,99,-14},{107,100,-14},{107,101,-14},{107,102,-9},{107,103,-14},{107,111,-14},{107,113,-14},
++ {107,115,-14},{107,116,-9},{109,39,-4},{109,44,-7},{109,46,-7},{109,118,-5},{109,119,-5},{109,120,-9},
++ {109,121,-5},{110,39,-4},{110,44,-7},{110,46,-7},{110,118,-5},{110,119,-5},{110,120,-9},{110,121,-5},
++ {111,39,-5},{111,118,-12},{111,119,-12},{111,120,-13},{111,121,-12},{112,39,-4},{112,44,-7},{112,46,-7},
++ {112,118,-5},{112,119,-5},{112,120,-9},{112,121,-5},{113,118,-7},{113,119,-7},{113,121,-7},{114,45,-5},
++ {114,99,-5},{114,100,-5},{114,101,-5},{114,103,-8},{114,111,-5},{114,113,-8},{114,118,6},{114,119,6},
++ {114,121,6},{114,133,18},{115,39,-10},{115,115,-12},{115,118,-14},{115,119,-14},{115,120,-9},{115,121,-14},
++ {115,133,-10},{117,133,-7},{118,44,-14},{118,45,-10},{118,46,-14},{118,97,-9},{118,99,-10},{118,100,-10},
++ {118,101,-10},{118,103,-16},{118,111,-10},{118,113,-16},{118,115,-10},{118,118,7},{118,119,7},{118,121,7},
++ {118,133,17},{119,44,-14},{119,45,-10},{119,46,-14},{119,97,-9},{119,99,-10},{119,100,-10},{119,101,-10},
++ {119,103,-16},{119,111,-10},{119,113,-16},{119,115,-10},{119,118,7},{119,119,7},{119,121,7},{119,133,17},
++ {120,45,-13},{120,99,-13},{120,100,-13},{120,101,-13},{120,111,-13},{121,44,-14},{121,45,-10},{121,46,-14},
++ {121,97,-9},{121,99,-10},{121,100,-10},{121,101,-10},{121,103,-16},{121,111,-10},{121,113,-16},{121,115,-10},
++ {121,118,7},{121,119,7},{121,121,7},{121,133,17},{133,45,-50},{133,65,-46},{133,74,-50},{133,97,-46},
++ {133,99,-50},{133,100,-50},{133,101,-50},{133,103,-33},{133,109,-21},{133,110,-21},{133,111,-50},{133,112,-21},
++ {133,113,-33},{133,114,-21},{133,115,-58},
++};
++const struct fos_font fos_font_xl_data = { xl_bits, xl_glyphs, xl_lut, xl_kern, 515, 50, 10 };
++
++static const uint8_t num_bits[] = {
++ 130,113,113,49,133,6,127,127,79,5,131,8,127,127,79,7,131,8,127,127,79,7,131,8,
++ 127,127,79,7,131,8,127,127,79,7,131,8,127,127,79,7,131,6,127,127,79,4,255,255,
++ 255,255,211,132,3,10,14,15,13,9,2,136,5,95,14,4,134,2,14,111,14,1,133,8,
++ 127,15,8,133,12,127,15,11,133,13,127,15,13,133,12,127,15,11,133,8,127,15,8,133,
++ 2,14,111,14,2,134,5,95,14,4,136,3,10,14,15,14,9,2,149,145,9,95,14,2,
++ 148,14,111,1,147,4,111,11,148,8,111,7,148,13,111,3,147,2,111,14,148,6,111,10,
++ 148,10,111,5,148,14,111,1,147,4,111,12,148,8,111,8,148,12,111,4,147,1,111,14,
++ 148,5,111,10,148,10,111,6,148,14,111,2,147,3,111,13,148,7,111,8,148,12,111,4,
++ 147,1,111,14,148,5,111,11,148,9,111,7,148,13,111,2,147,3,111,13,148,7,111,9,
++ 148,11,111,5,147,1,127,1,147,4,111,11,148,9,111,7,148,13,111,3,147,2,111,14,
++ 148,6,111,9,148,11,111,5,148,14,111,1,147,4,111,12,148,8,111,8,148,12,111,3,
++ 147,2,111,14,148,6,111,10,148,10,111,6,148,14,111,2,147,3,111,12,148,8,111,8,
++ 148,12,111,4,147,1,111,14,148,5,111,11,148,9,111,6,148,14,111,2,147,3,111,13,
++ 148,7,111,9,148,11,111,4,147,1,127,1,147,5,111,11,148,9,111,7,148,13,111,3,
++ 147,2,111,13,148,7,111,9,148,11,111,5,148,14,111,1,147,1,14,95,10,147,142,3,
++ 5,39,6,4,2,154,5,11,127,15,13,8,2,149,5,13,127,95,9,1,145,1,10,127,
++ 127,15,14,4,143,1,12,127,127,63,5,142,11,127,127,95,4,140,8,127,127,111,14,2,
++ 138,3,127,31,14,10,25,12,127,31,10,138,10,127,14,6,132,2,10,127,15,3,136,2,
++ 127,13,2,135,8,127,10,136,7,127,4,137,11,127,1,135,11,111,10,138,2,127,4,135,
++ 14,111,4,139,11,111,8,134,2,127,1,139,7,111,10,134,3,111,13,140,5,111,12,134,
++ 4,111,12,140,4,111,12,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,4,111,12,140,3,111,13,134,
++ 4,111,12,140,3,111,13,134,4,111,12,140,4,111,12,134,3,111,13,140,5,111,12,134,
++ 2,127,140,7,111,10,135,14,111,4,139,11,111,8,135,11,111,10,138,2,127,4,135,7,
++ 127,4,137,10,127,1,135,2,127,13,2,135,8,127,10,137,10,127,14,5,132,2,10,127,
++ 15,3,137,3,127,31,14,10,25,12,127,31,10,139,8,127,127,111,14,2,140,11,127,127,
++ 95,4,141,1,12,127,127,63,5,143,1,10,127,127,15,14,4,146,5,13,127,95,10,1,
++ 149,6,11,127,15,13,8,2,154,3,5,39,6,4,2,142,135,3,11,111,13,137,3,10,
++ 127,31,1,134,3,10,127,63,1,132,2,10,127,95,1,131,9,127,127,1,130,2,127,127,
++ 15,1,130,1,127,127,15,1,131,127,127,15,1,131,14,127,127,1,131,13,63,13,9,5,
++ 2,127,1,131,10,13,9,5,1,131,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,140,127,1,
++ 140,127,1,140,127,1,140,127,1,140,127,1,140,12,95,13,131,140,1,4,6,39,5,3,
++ 152,6,11,127,14,9,3,147,5,13,127,79,10,2,143,1,10,127,127,14,4,141,1,11,
++ 127,127,31,14,4,140,10,127,127,63,14,2,138,7,127,127,95,11,137,1,14,127,15,12,
++ 25,11,127,31,6,136,9,127,12,3,131,2,11,127,13,135,1,127,12,1,134,11,127,5,
++ 134,5,127,3,135,2,14,111,9,134,10,111,10,137,8,111,13,134,13,111,5,137,3,127,
++ 1,133,127,2,138,14,111,3,132,2,127,1,138,12,111,4,132,3,127,139,11,111,6,132,
++ 4,127,139,12,111,6,132,4,127,139,12,111,5,132,4,127,139,14,111,4,132,2,14,95,
++ 13,138,2,127,3,152,6,127,1,152,10,111,12,152,1,14,111,9,152,5,127,5,152,11,
++ 127,1,151,3,127,10,152,9,127,4,151,2,127,13,152,9,127,7,151,3,127,14,1,151,
++ 11,127,7,151,5,127,14,1,150,1,13,127,6,151,8,127,12,151,3,127,15,3,151,12,
++ 127,9,151,7,127,14,1,150,2,14,127,5,151,11,127,10,151,6,127,14,2,150,1,14,
++ 127,6,151,10,127,11,151,5,127,14,2,150,1,14,127,7,151,10,127,12,151,5,127,15,
++ 3,150,1,14,127,7,151,10,127,12,151,5,127,15,3,150,1,14,127,8,151,10,127,12,
++ 151,5,127,15,3,150,1,14,127,7,151,10,127,12,113,113,33,133,127,127,127,79,11,131,
++ 1,127,127,127,79,13,131,1,127,127,127,79,13,131,1,127,127,127,79,13,131,1,127,127,
++ 127,79,13,131,1,127,127,127,79,13,132,13,127,127,127,63,10,129,130,8,127,127,127,31,
++ 14,1,133,11,127,127,127,47,2,133,11,127,127,127,47,2,133,11,127,127,127,47,2,133,
++ 11,127,127,127,47,2,133,11,127,127,127,47,2,133,9,127,127,127,47,2,134,113,113,2,
++ 14,127,11,151,9,127,14,2,150,4,127,15,6,150,1,13,127,11,151,9,127,14,2,150,
++ 4,127,15,7,150,1,13,127,12,151,9,127,15,2,150,3,127,15,7,151,13,127,12,151,
++ 8,127,15,2,150,3,127,15,7,151,13,127,12,151,8,127,15,3,150,3,127,15,7,151,
++ 12,127,15,4,150,7,127,63,9,2,147,9,127,79,14,6,146,1,12,127,95,8,146,2,
++ 13,127,95,6,146,2,14,15,14,9,7,9,14,127,2,146,3,8,1,130,1,10,111,11,
++ 154,10,111,3,153,1,14,95,10,154,8,95,14,1,153,3,111,5,154,14,95,8,154,12,
++ 95,10,154,10,95,13,154,9,111,154,8,111,2,153,7,111,3,153,6,111,3,153,6,111,
++ 4,132,1,7,88,3,139,6,111,5,132,4,111,11,139,7,111,4,132,4,111,12,139,7,
++ 111,3,132,4,111,13,139,8,111,3,132,3,111,14,139,10,111,2,132,1,127,1,138,11,
++ 111,134,127,3,138,13,95,13,134,13,111,7,137,1,111,10,134,10,111,12,137,6,111,7,
++ 134,7,127,4,136,13,111,3,134,3,127,13,1,134,8,111,14,136,12,127,13,3,131,1,
++ 9,127,8,136,6,127,31,12,25,10,14,127,15,2,137,12,127,127,95,9,138,3,14,127,
++ 127,63,13,1,139,4,14,127,127,31,14,3,141,4,13,127,127,14,4,143,1,10,127,95,
++ 11,2,146,2,8,13,127,14,10,3,151,2,5,6,23,6,5,3,141,140,1,13,111,6,
++ 154,6,127,4,154,11,111,14,154,1,127,9,154,6,127,4,154,11,111,14,154,1,127,10,
++ 154,6,127,5,154,10,111,14,1,153,1,127,10,154,5,127,5,154,10,127,1,153,1,14,
++ 111,11,154,5,127,6,154,10,127,1,154,14,111,11,154,5,127,6,154,10,127,2,154,14,
++ 111,12,154,4,127,7,154,9,127,2,154,14,111,12,154,4,127,8,154,9,127,3,154,14,
++ 111,13,135,6,111,5,137,4,127,8,135,8,111,8,137,9,127,3,135,8,111,8,137,13,
++ 111,13,136,8,111,8,136,4,127,9,136,8,111,8,136,8,127,4,136,8,111,8,136,13,
++ 111,14,137,8,111,8,135,3,127,9,137,8,111,8,135,8,127,4,137,8,111,8,135,13,
++ 111,14,138,8,111,8,134,3,127,10,138,8,111,8,134,8,127,5,138,8,111,8,134,13,
++ 127,2,113,33,9,111,8,17,131,3,127,127,127,127,15,4,129,6,127,127,127,127,15,5,
++ 129,6,127,127,127,127,15,5,129,6,127,127,127,127,15,5,129,6,127,127,127,127,15,5,
++ 129,6,127,127,127,127,15,5,129,4,127,127,127,127,14,3,151,8,111,8,155,8,111,8,
++ 155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,
++ 155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,155,8,111,8,
++ 155,8,111,8,155,6,111,5,132,130,2,14,127,127,127,31,4,133,3,127,127,127,47,6,
++ 133,3,127,127,127,47,6,133,3,127,127,127,47,6,133,3,127,127,127,47,6,133,3,127,
++ 127,127,47,6,133,3,127,127,127,47,4,133,3,111,13,113,113,17,135,3,111,13,153,3,
++ 111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,
++ 111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,111,13,153,3,
++ 111,13,153,3,111,13,153,3,111,13,130,1,5,10,13,14,15,14,13,10,5,140,3,111,
++ 13,129,5,14,127,15,13,5,138,3,111,13,128,9,127,79,9,137,3,111,14,10,127,111,
++ 9,136,3,127,127,127,15,6,135,3,127,127,127,15,14,1,134,3,127,127,127,31,8,134,
++ 3,127,31,14,7,3,1,128,3,8,14,127,14,134,3,127,15,12,1,133,3,14,127,4,
++ 133,3,127,14,1,135,4,127,8,133,3,127,7,137,11,111,11,133,3,127,2,137,5,111,
++ 14,134,8,89,6,138,2,127,1,153,14,111,3,153,11,111,6,153,9,111,7,153,9,111,
++ 7,153,8,111,8,153,7,111,9,153,8,111,8,153,8,111,8,133,4,86,3,139,9,111,
++ 7,132,1,111,13,139,10,111,6,132,1,127,1,138,13,111,5,133,14,111,3,138,127,3,
++ 133,12,111,7,137,3,127,1,133,9,111,11,137,8,111,14,134,5,127,3,135,1,14,111,
++ 11,134,1,127,12,1,134,10,127,7,135,10,127,12,2,131,1,10,127,15,2,135,4,127,
++ 31,12,25,11,14,127,15,11,137,10,127,127,111,2,137,2,14,127,127,79,7,139,3,14,
++ 127,127,47,9,141,4,13,127,127,15,8,143,1,10,127,95,13,4,146,2,9,13,127,14,
++ 11,5,151,2,5,6,23,6,5,3,140,141,1,4,5,23,6,5,2,151,2,8,12,127,
++ 13,7,1,146,1,8,127,79,14,7,144,2,13,127,127,11,1,141,4,14,127,127,31,12,
++ 1,139,2,14,127,127,63,9,139,12,127,127,95,6,137,6,127,31,12,25,12,127,15,14,
++ 137,13,127,13,3,131,4,14,127,6,135,4,127,13,1,133,3,14,111,13,135,8,127,3,
++ 135,8,127,1,134,12,111,10,136,1,127,5,134,127,5,137,11,111,8,133,1,127,2,137,
++ 7,111,9,133,2,127,138,6,111,10,133,3,111,14,138,5,111,11,133,3,111,14,138,5,
++ 111,11,133,3,111,14,138,3,111,10,133,3,111,14,139,1,82,134,3,111,14,153,3,111,
++ 14,153,3,111,14,153,3,111,14,153,3,111,14,129,2,8,12,14,15,14,13,11,7,3,
++ 141,3,111,14,128,8,127,31,11,3,139,3,127,11,127,79,8,138,3,127,127,111,11,137,
++ 3,127,127,127,9,136,3,127,127,127,15,6,135,3,127,127,127,15,14,1,134,3,127,47,
++ 10,4,1,128,2,7,14,127,9,134,3,127,31,6,133,2,13,111,14,134,3,127,15,9,
++ 135,3,127,5,133,3,127,15,1,136,11,111,9,133,2,127,10,137,5,111,12,133,2,127,
++ 6,137,1,127,133,2,127,4,138,14,111,2,132,2,127,2,138,12,111,4,132,2,127,1,
++ 138,10,111,6,132,2,127,139,9,111,8,132,2,127,139,8,111,9,132,2,111,14,139,7,
++ 111,9,132,2,111,14,139,7,111,10,132,2,111,14,139,8,111,10,132,1,127,139,8,111,
++ 9,132,1,127,139,9,111,9,133,127,2,138,10,111,8,133,13,111,3,138,12,111,6,133,
++ 11,111,5,138,14,111,5,133,8,111,9,137,3,127,3,133,5,111,14,137,8,127,1,133,
++ 2,127,6,135,1,14,111,13,135,12,111,14,2,134,10,127,8,135,7,127,13,3,131,1,
++ 10,127,15,3,135,1,14,127,15,12,25,11,127,31,11,137,7,127,127,111,3,138,12,127,
++ 127,79,8,139,1,13,127,127,47,10,141,2,12,127,127,15,9,144,8,14,127,79,13,5,
++ 146,1,7,12,127,14,11,5,151,1,4,6,23,6,5,3,140,128,3,14,127,127,127,47,
++ 9,129,5,127,127,127,63,11,129,5,127,127,127,63,11,129,5,127,127,127,63,11,129,5,
++ 127,127,127,63,11,129,5,127,127,127,63,11,129,6,127,127,127,63,11,129,6,95,4,113,
++ 65,14,111,8,129,6,95,4,139,3,127,4,129,6,95,4,139,8,127,1,129,6,95,3,
++ 139,12,111,11,130,1,7,56,7,139,1,127,7,149,5,127,3,149,9,111,14,150,13,111,
++ 10,149,2,127,5,149,6,127,1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,
++ 14,150,12,111,11,149,1,127,7,149,5,127,3,149,9,111,13,150,13,111,9,149,2,127,
++ 5,149,6,127,1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,
++ 11,149,1,127,7,149,5,127,2,149,9,111,13,150,13,111,9,149,2,127,5,149,6,127,
++ 1,149,10,111,12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,11,149,1,127,
++ 6,149,5,127,2,149,9,111,13,150,13,111,9,149,2,127,5,149,6,127,1,149,10,111,
++ 12,150,14,111,8,149,3,127,4,149,8,111,14,150,12,111,10,149,1,127,6,149,5,127,
++ 2,149,9,111,13,150,13,111,9,150,13,95,14,4,142,141,2,5,6,23,6,4,2,152,
++ 2,9,13,127,13,8,2,147,1,10,127,95,9,1,144,4,14,127,127,14,3,142,5,127,
++ 127,63,4,140,3,14,127,127,63,14,2,139,13,127,127,95,12,138,7,127,31,12,25,12,
++ 127,31,6,137,13,127,12,3,131,3,12,127,13,136,5,127,12,1,133,1,12,127,4,135,
++ 9,127,3,135,4,127,8,135,13,111,11,137,11,111,12,134,1,127,5,137,4,111,14,134,
++ 3,127,1,138,127,2,133,4,111,13,139,12,111,3,133,4,111,11,139,11,111,3,133,4,
++ 111,10,139,10,111,3,133,3,111,11,139,11,111,3,133,2,111,12,139,12,111,1,134,111,
++ 14,139,14,95,14,135,12,111,2,137,3,111,12,135,8,111,7,137,7,111,8,135,3,111,
++ 13,137,13,111,3,136,12,111,6,135,6,111,12,137,4,127,4,133,4,127,4,138,10,127,
++ 9,3,17,3,9,127,10,139,1,12,127,127,63,12,1,140,1,12,127,127,31,11,1,143,
++ 8,127,127,8,145,6,127,127,7,143,1,11,127,127,31,11,1,140,1,12,127,127,63,12,
++ 140,9,127,9,3,17,4,10,127,8,138,3,127,5,133,6,127,2,137,10,111,8,135,9,
++ 111,9,136,1,111,14,1,135,1,111,14,136,6,111,9,137,11,111,4,135,9,111,5,137,
++ 6,111,8,135,13,111,1,137,3,111,12,135,111,14,139,111,14,134,2,111,12,139,13,111,
++ 1,133,3,111,11,139,12,111,2,133,4,111,10,139,11,111,3,133,4,111,10,139,11,111,
++ 4,133,4,111,11,139,12,111,3,133,4,111,12,139,12,111,3,133,2,111,13,139,14,111,
++ 2,133,1,127,1,137,1,127,135,14,111,3,137,4,111,13,135,11,111,7,137,8,111,10,
++ 135,7,111,13,137,13,111,7,135,3,127,5,135,5,127,3,136,12,111,14,2,133,2,14,
++ 111,12,137,6,127,13,3,131,3,13,127,6,138,13,127,15,12,25,12,127,15,13,139,4,
++ 127,127,95,4,140,9,127,127,63,8,142,11,127,127,31,10,144,9,127,127,9,146,5,13,
++ 127,63,13,5,148,1,6,12,127,12,6,1,152,1,4,6,23,6,4,1,141,139,1,4,
++ 5,6,7,6,5,4,1,150,1,7,12,127,15,12,6,147,7,14,127,79,14,6,143,1,
++ 11,127,127,15,10,1,140,1,13,127,127,47,11,140,11,127,127,79,9,138,6,127,127,111,
++ 4,136,1,14,127,15,14,10,9,10,13,127,15,12,136,6,127,15,8,1,131,5,14,127,
++ 3,135,11,127,7,134,4,127,9,134,1,127,12,136,9,111,14,134,4,127,5,136,2,127,
++ 2,133,6,111,14,138,12,111,5,133,8,111,11,138,8,111,7,133,9,111,8,138,6,111,
++ 9,133,10,111,7,138,5,111,11,133,11,111,6,138,4,111,12,133,12,111,6,138,3,111,
++ 13,133,12,111,5,138,3,111,13,133,12,111,5,138,2,111,14,133,12,111,5,138,3,111,
++ 14,133,12,111,6,138,3,111,14,133,11,111,6,138,4,111,14,133,10,111,7,138,4,111,
++ 14,133,8,111,9,138,6,111,14,133,6,111,11,138,8,111,14,133,3,111,13,138,10,111,
++ 14,133,1,127,2,137,14,111,14,134,13,111,7,136,4,127,14,134,8,111,14,1,135,12,
++ 127,14,134,3,127,11,1,133,9,127,15,14,135,11,127,13,6,2,128,1,5,12,127,31,
++ 14,135,3,127,127,127,15,14,136,9,127,127,127,14,137,12,127,127,111,14,137,1,12,127,
++ 127,95,14,138,1,10,127,79,11,111,14,140,5,12,127,15,14,5,2,127,142,4,8,12,
++ 14,31,14,12,7,1,128,2,127,153,2,127,153,2,127,153,2,127,153,2,127,135,97,138,
++ 2,127,134,13,95,14,138,2,127,134,127,1,137,2,127,134,14,111,2,137,2,127,134,14,
++ 111,2,137,3,111,14,134,13,111,4,137,5,111,13,134,11,111,7,137,9,111,12,134,9,
++ 111,12,137,14,111,9,134,5,127,5,135,6,127,5,134,1,127,13,1,133,3,14,127,1,
++ 135,10,127,12,2,131,5,14,127,10,136,3,127,31,11,9,10,13,127,31,2,137,9,127,
++ 127,95,9,138,1,13,127,127,63,12,140,2,14,127,127,31,13,2,141,2,12,127,127,11,
++ 1,143,1,8,127,79,14,7,147,2,9,13,127,11,7,1,151,2,5,6,7,6,5,4,
++ 1,141,134,7,12,30,12,6,139,1,12,95,10,138,10,127,7,136,2,127,15,14,136,5,
++ 127,31,3,135,7,127,31,4,135,5,127,31,3,135,2,127,15,14,137,10,127,7,137,1,
++ 12,95,10,139,1,7,12,15,14,12,6,255,255,225,7,12,30,12,6,139,1,12,95,10,
++ 138,10,127,7,136,2,127,15,14,136,5,127,31,3,135,7,127,31,4,135,5,127,31,3,
++ 135,2,127,15,14,137,10,127,7,137,1,12,95,10,139,1,7,12,15,14,12,6,154,141,
++ 3,5,6,23,6,4,1,152,6,11,14,127,12,7,1,147,5,13,127,79,14,7,145,9,
++ 127,127,15,11,1,141,1,12,127,127,47,13,2,140,10,127,127,79,13,1,138,7,127,127,
++ 111,10,137,2,127,31,13,10,9,10,13,127,31,4,136,9,127,13,4,132,4,12,127,12,
++ 135,1,14,111,13,1,134,1,12,127,4,134,4,127,3,136,1,14,111,9,134,8,111,10,
++ 138,6,111,13,134,11,111,5,138,1,14,111,1,133,12,111,1,139,11,111,3,133,13,111,
++ 140,9,111,5,133,14,95,14,140,8,111,6,133,14,111,140,7,111,6,133,13,111,2,139,
++ 7,111,6,133,11,111,6,139,6,111,5,133,8,111,11,140,3,68,3,134,4,127,4,153,
++ 1,14,111,13,2,153,8,127,13,1,152,1,14,127,13,2,152,6,127,15,14,3,152,12,
++ 127,31,5,151,2,14,127,31,9,151,3,14,127,31,12,2,150,5,127,47,14,4,150,4,
++ 14,127,47,8,150,3,13,127,47,10,1,149,1,12,127,47,13,2,150,9,127,47,14,3,
++ 150,6,14,127,31,14,5,150,3,13,127,47,5,150,1,10,127,47,3,151,6,127,31,13,
++ 1,151,4,14,127,15,10,152,2,13,127,15,3,152,2,13,127,10,153,2,14,127,1,153,
++ 6,127,5,154,12,111,8,133,7,92,10,140,7,111,11,133,12,111,1,139,3,111,12,133,
++ 12,111,1,139,1,111,12,133,12,111,2,139,1,111,12,133,12,111,3,139,2,111,11,133,
++ 10,111,6,139,4,111,10,133,8,111,10,139,8,111,8,133,5,111,14,1,138,14,111,4,
++ 133,1,127,9,137,8,127,1,134,11,127,6,135,5,127,10,135,5,127,15,9,1,131,1,
++ 8,127,15,4,136,12,127,31,11,25,11,127,31,11,137,3,127,127,111,14,2,138,6,127,
++ 127,95,5,140,8,127,127,63,6,142,6,127,127,15,14,5,144,3,11,127,95,10,2,147,
++ 3,9,14,127,14,9,3,152,2,5,39,6,5,2,141,
++};
++static const struct fos_glyph num_glyphs[] = {
++ { 0, 17, 0, 0, 0, 269 }, /* 0x20 */
++ { 0, 27, 30, 0, -30, 430 }, /* 0x2d */
++ { 51, 17, 12, 0, -12, 271 }, /* 0x2e */
++ { 115, 30, 60, 0, -60, 488 }, /* 0x2f */
++ { 358, 38, 62, 0, -61, 601 }, /* 0x30 */
++ { 856, 22, 60, 0, -60, 357 }, /* 0x31 */
++ { 1073, 35, 61, 0, -61, 558 }, /* 0x32 */
++ { 1434, 35, 61, 0, -60, 562 }, /* 0x33 */
++ { 1819, 37, 60, 0, -60, 591 }, /* 0x34 */
++ { 2145, 35, 61, 0, -60, 564 }, /* 0x35 */
++ { 2555, 35, 62, 0, -61, 564 }, /* 0x36 */
++ { 3041, 32, 60, 0, -60, 512 }, /* 0x37 */
++ { 3327, 36, 62, 0, -61, 577 }, /* 0x38 */
++ { 3813, 35, 62, 0, -61, 556 }, /* 0x39 */
++ { 4298, 20, 40, 0, -40, 315 }, /* 0x3a */
++ { 4415, 36, 62, 0, -61, 573 }, /* 0x53 */
++};
++static const uint8_t num_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,1,2,3,
++ 4,5,6,7,8,9,10,11,12,13,14,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern num_kern[] = {
++ {45,45,-65},{45,46,-8},{46,45,-8},{46,48,-51},{46,55,-39},{49,49,-23},{50,49,-36},{51,49,-43},
++ {52,49,-65},{52,55,-67},{53,49,-23},{54,49,-30},{55,46,-69},{55,49,-8},{56,49,-38},{57,49,-38},
++ {83,46,-8},
++};
++const struct fos_font fos_font_num_data = { num_bits, num_glyphs, num_lut, num_kern, 17, 84, 17 };
++
++static const uint8_t lbig_bits[] = {
++ 134,2,7,11,13,14,15,14,12,9,5,140,2,9,127,31,13,6,137,4,14,127,79,10,
++ 1,134,3,127,127,11,133,1,14,127,127,15,9,132,8,127,127,47,2,130,1,14,127,127,
++ 47,9,130,5,127,15,12,10,14,127,14,130,8,127,11,129,3,127,15,2,129,10,127,5,
++ 130,11,127,4,129,11,127,3,130,9,127,5,129,12,127,3,130,9,127,6,129,12,127,3,
++ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
++ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
++ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
++ 130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,130,9,127,6,129,12,127,3,
++ 130,9,127,6,129,12,127,3,130,9,127,6,129,11,127,3,130,9,127,5,129,10,127,5,
++ 130,11,127,4,129,8,127,11,129,3,127,15,2,129,5,127,15,12,10,14,127,14,130,1,
++ 14,127,127,47,9,131,8,127,127,47,2,131,1,14,127,127,15,9,133,3,127,127,12,135,
++ 4,14,127,79,11,1,136,2,10,127,31,14,6,140,2,7,11,13,14,15,14,12,9,5,
++ 135,130,5,10,14,127,5,128,2,9,14,127,47,6,128,8,127,79,6,128,8,127,79,6,
++ 128,8,127,79,6,128,8,127,79,6,128,7,127,79,6,128,7,127,79,6,128,1,53,11,
++ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
++ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
++ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
++ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,8,
++ 127,6,133,8,127,6,133,8,127,6,133,8,127,6,133,6,127,5,128,134,1,6,10,13,
++ 14,15,14,13,10,5,1,138,1,9,127,31,14,7,136,5,14,127,79,11,1,133,5,127,
++ 127,12,1,131,3,127,127,31,8,131,12,127,127,47,2,129,4,127,127,63,8,129,9,127,
++ 15,11,10,127,15,13,129,12,127,8,129,6,127,15,1,128,14,127,2,130,127,15,3,128,
++ 127,15,1,130,13,127,3,128,127,15,1,130,127,15,2,128,13,111,14,1,129,3,127,15,
++ 1,140,8,127,13,140,1,14,127,9,140,7,127,15,4,139,2,14,127,13,140,11,127,15,
++ 6,139,7,127,15,12,139,4,127,31,3,138,2,14,127,15,7,138,1,13,127,15,10,139,
++ 11,127,15,12,1,138,9,127,15,14,2,138,8,127,15,14,3,138,6,127,31,4,138,4,
++ 127,31,5,138,3,14,127,15,7,138,2,14,127,15,9,139,11,127,31,121,41,4,128,12,
++ 127,127,79,10,128,12,127,127,79,10,128,12,127,127,79,10,128,12,127,127,79,10,128,12,
++ 127,127,79,10,128,12,127,127,79,10,128,10,127,127,79,8,128,2,127,127,63,9,129,4,
++ 127,127,63,11,129,4,127,127,63,11,129,4,127,127,63,11,129,4,127,127,63,11,129,4,
++ 127,127,63,11,129,4,127,127,63,11,129,1,8,121,10,127,31,9,138,1,11,127,15,12,
++ 1,137,1,11,127,15,13,1,138,11,127,15,14,2,138,10,127,15,14,3,138,10,127,31,
++ 4,138,10,127,31,6,138,8,127,31,11,3,138,6,127,63,14,6,137,7,127,79,8,137,
++ 7,127,79,4,137,7,15,14,8,7,14,111,13,138,5,2,129,3,127,3,142,13,111,7,
++ 142,12,111,9,142,12,111,10,142,11,111,11,129,4,102,4,131,11,111,11,129,127,14,131,
++ 11,111,12,129,127,15,131,12,111,11,129,14,127,2,130,13,111,11,129,13,127,8,129,4,
++ 127,10,129,11,127,15,11,10,127,15,8,129,8,127,127,63,4,129,2,127,127,47,14,131,
++ 9,127,127,31,6,132,12,127,127,10,133,1,11,127,95,10,136,6,13,127,31,13,5,139,
++ 4,9,12,14,31,14,12,9,5,134,134,5,127,14,1,143,11,127,12,143,1,127,15,8,
++ 143,6,127,15,3,143,11,127,13,143,1,127,15,8,143,6,127,15,4,143,11,127,14,143,
++ 1,127,15,9,143,6,127,15,4,143,11,127,14,143,1,127,15,10,143,6,127,15,5,143,
++ 11,127,15,1,142,1,127,15,11,129,9,111,14,2,131,6,127,15,6,129,12,127,3,131,
++ 11,127,15,1,129,12,127,3,130,1,127,15,11,130,12,127,3,130,6,127,15,7,130,12,
++ 127,3,130,11,127,15,2,130,12,127,3,129,1,127,127,127,15,12,5,127,127,127,15,13,
++ 6,127,127,127,15,13,6,127,127,127,15,13,6,127,127,127,15,13,6,127,127,127,15,13,
++ 6,127,127,127,15,13,2,121,89,14,127,10,9,6,142,12,127,3,144,12,127,3,144,12,
++ 127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,12,127,3,144,10,
++ 111,14,2,129,128,9,127,127,63,14,129,11,127,127,79,1,128,11,127,127,79,1,128,11,
++ 127,127,79,1,128,11,127,127,79,1,128,11,127,127,79,1,128,11,127,127,79,1,128,11,
++ 127,11,121,41,8,129,11,127,4,141,11,127,4,141,11,127,4,141,11,127,4,141,11,127,
++ 4,141,11,127,4,1,7,12,30,13,10,5,133,11,127,7,13,111,11,1,131,11,127,127,
++ 31,13,1,130,11,127,127,47,10,130,11,127,127,63,3,129,11,127,127,63,9,129,11,127,
++ 127,63,13,129,11,127,15,11,10,14,127,15,129,11,127,9,129,4,127,15,2,128,3,119,
++ 1,130,13,127,3,141,11,127,4,141,10,127,4,141,10,127,4,128,8,127,4,130,11,127,
++ 4,128,9,127,7,130,12,127,3,128,7,127,12,129,3,127,15,2,128,4,127,15,12,10,
++ 14,127,15,1,128,1,14,127,127,47,12,130,9,127,127,47,7,130,2,127,127,31,13,1,
++ 131,6,127,127,15,4,133,7,127,95,14,4,135,3,12,127,47,10,1,138,3,8,11,13,
++ 14,15,14,13,10,7,1,133,134,4,8,11,13,14,15,14,12,9,5,139,5,13,127,31,
++ 14,7,136,10,127,95,12,1,133,10,127,127,12,1,131,6,127,127,31,9,130,1,14,127,
++ 127,47,2,129,4,127,127,63,7,129,8,127,15,12,10,127,15,10,129,10,127,10,129,7,
++ 127,12,129,10,127,5,129,2,127,13,129,10,127,5,129,2,127,13,129,10,127,5,130,6,
++ 103,4,129,10,127,5,141,10,127,5,1,8,13,15,14,13,9,3,133,10,127,10,14,111,
++ 10,1,131,10,127,127,31,12,1,130,10,127,127,47,9,130,10,127,127,63,3,129,10,127,
++ 127,63,9,129,10,127,14,4,1,9,127,13,129,10,127,8,129,1,127,15,1,128,9,127,
++ 6,130,13,127,3,128,9,127,5,130,12,127,4,128,9,127,5,130,12,127,5,128,9,127,
++ 5,130,11,127,5,128,9,127,5,130,11,127,5,128,9,127,5,130,12,127,5,128,8,127,
++ 7,130,13,127,5,128,6,127,12,129,4,127,15,4,128,4,127,15,12,10,14,127,15,2,
++ 128,1,127,127,63,14,130,10,127,127,47,9,130,3,127,127,31,14,2,131,8,127,127,15,
++ 6,133,8,127,111,6,135,4,12,127,47,11,2,138,3,8,11,13,14,15,14,13,10,7,
++ 2,133,5,127,127,79,4,7,127,127,79,5,7,127,127,79,5,7,127,127,79,5,7,127,
++ 127,79,5,7,127,127,79,5,7,127,127,79,5,8,95,14,57,10,127,15,5,8,95,11,
++ 131,6,127,15,1,7,95,10,131,10,127,12,128,1,84,1,130,1,14,127,7,139,5,127,
++ 15,2,139,9,127,13,140,14,127,8,139,3,127,15,3,139,8,127,14,140,13,127,9,139,
++ 2,127,15,4,139,7,127,14,140,11,127,10,139,1,127,15,6,139,6,127,15,1,139,10,
++ 127,11,140,14,127,7,139,4,127,15,2,139,9,127,13,140,13,127,8,139,3,127,15,3,
++ 139,8,127,14,140,12,127,9,139,2,127,15,4,139,7,127,14,140,11,127,10,139,1,127,
++ 15,5,139,5,127,15,1,139,10,127,11,140,12,127,6,136,134,3,8,11,14,31,14,12,
++ 8,4,139,3,12,127,31,13,5,136,7,127,95,9,134,7,127,127,10,132,4,127,127,31,
++ 6,131,12,127,127,31,14,130,2,127,127,63,5,129,7,127,15,11,10,127,15,9,129,9,
++ 127,8,129,7,127,12,129,11,127,3,129,2,127,13,129,11,127,1,130,127,12,129,10,127,
++ 2,130,127,11,129,8,127,4,129,2,127,8,129,4,127,12,2,1,11,127,2,130,13,127,
++ 127,31,11,131,5,127,127,15,14,2,132,10,127,111,14,3,134,8,127,95,5,135,9,127,
++ 95,14,5,133,11,127,127,15,3,131,7,127,127,31,12,131,14,111,13,18,12,127,2,129,
++ 4,127,5,129,4,127,7,129,8,127,2,129,2,127,10,129,10,127,1,130,127,12,129,11,
++ 127,1,130,14,111,13,129,11,127,2,130,127,12,129,10,127,3,129,2,127,11,129,8,127,
++ 9,129,8,127,9,129,4,127,15,27,127,15,4,129,1,127,127,47,14,1,130,9,127,127,
++ 31,8,131,1,13,127,127,13,1,132,4,14,127,95,14,3,134,4,14,127,63,13,3,136,
++ 2,10,127,31,9,1,139,2,7,11,13,31,14,11,7,2,134,133,2,7,10,13,14,15,
++ 14,13,11,8,4,138,2,10,127,47,13,5,135,6,127,111,9,133,5,127,127,15,9,131,
++ 2,14,127,127,31,5,130,8,127,127,47,12,130,13,127,127,63,2,128,1,127,31,10,12,
++ 127,15,6,128,2,127,15,4,129,10,127,8,128,3,127,14,130,5,127,10,128,4,127,13,
++ 130,4,127,11,128,4,127,13,130,4,127,11,128,4,127,13,130,4,127,11,128,3,127,13,
++ 130,4,127,11,128,2,127,14,130,4,127,11,128,1,127,15,1,129,6,127,11,129,13,127,
++ 9,1,2,13,127,11,129,9,127,127,63,11,129,3,127,127,63,11,130,9,127,127,47,11,
++ 130,1,12,127,127,31,11,131,1,10,127,11,127,11,133,3,9,12,14,15,13,9,3,4,
++ 127,11,141,4,127,12,129,1,99,2,130,4,127,12,129,11,127,2,129,4,127,12,129,12,
++ 127,3,129,4,127,12,129,11,127,4,129,5,127,12,129,10,127,10,129,10,127,11,129,8,
++ 127,15,11,12,127,15,9,129,4,127,127,63,5,130,13,127,127,31,14,1,130,6,127,127,
++ 31,7,132,9,127,127,11,134,9,127,95,10,1,135,5,13,127,31,13,6,139,4,9,12,
++ 14,15,14,13,12,8,4,134,128,1,14,111,11,131,9,127,2,129,2,127,13,131,11,127,
++ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
++ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
++ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
++ 4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,
++ 4,129,2,127,14,57,14,127,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,
++ 127,95,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,127,95,4,129,2,127,
++ 127,95,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
++ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
++ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
++ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,
++ 11,127,4,129,2,127,13,131,11,127,4,129,2,127,13,131,11,127,4,129,1,14,111,11,
++ 131,9,127,2,128,128,2,14,127,63,14,11,7,2,135,3,127,127,15,8,1,133,3,127,
++ 127,31,13,2,132,3,127,127,47,13,1,131,3,127,127,63,10,131,3,127,127,79,4,130,
++ 3,127,127,79,11,130,3,127,14,25,12,127,31,2,129,3,127,11,130,5,127,15,6,129,
++ 3,127,11,131,11,127,8,129,3,127,11,131,6,127,10,129,3,127,11,131,4,127,11,129,
++ 3,127,11,131,5,127,10,129,3,127,11,131,7,127,9,129,3,127,11,131,13,127,7,129,
++ 3,127,12,129,2,11,127,15,4,129,3,127,127,79,14,130,3,127,127,79,8,130,3,127,
++ 127,63,14,1,130,3,127,127,63,4,131,3,127,127,47,5,132,3,127,127,15,12,3,133,
++ 3,127,79,14,12,9,4,135,3,127,12,143,3,127,11,143,3,127,11,143,3,127,11,143,
++ 3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,3,127,11,143,
++ 3,127,11,143,3,127,11,143,3,127,11,143,2,14,111,10,142,128,11,127,127,95,14,129,
++ 13,127,127,111,1,128,13,127,127,111,1,128,13,127,127,111,1,128,13,127,127,111,1,128,
++ 13,127,127,111,1,128,13,127,127,111,1,128,6,89,12,127,12,89,8,136,8,127,7,143,
++ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
++ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
++ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
++ 8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,8,127,7,143,
++ 8,127,7,143,8,127,7,143,8,127,7,143,6,127,5,135,
++};
++static const struct fos_glyph lbig_glyphs[] = {
++ { 0, 11, 0, 0, 0, 173 }, /* 0x20 */
++ { 0, 25, 37, 0, -37, 394 }, /* 0x30 */
++ { 289, 16, 37, 0, -37, 254 }, /* 0x31 */
++ { 451, 24, 37, 0, -37, 390 }, /* 0x32 */
++ { 688, 24, 37, 0, -37, 385 }, /* 0x33 */
++ { 922, 27, 37, 0, -37, 439 }, /* 0x34 */
++ { 1132, 24, 37, 0, -37, 389 }, /* 0x35 */
++ { 1376, 24, 37, 0, -37, 390 }, /* 0x36 */
++ { 1658, 23, 37, 0, -37, 365 }, /* 0x37 */
++ { 1840, 24, 37, 0, -37, 385 }, /* 0x38 */
++ { 2105, 24, 37, 0, -37, 385 }, /* 0x39 */
++ { 2384, 26, 37, 0, -37, 417 }, /* 0x48 */
++ { 2669, 26, 37, 0, -37, 410 }, /* 0x50 */
++ { 2897, 26, 37, 0, -37, 419 }, /* 0x54 */
++};
++static const uint8_t lbig_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 1,2,3,4,5,6,7,8,9,10,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 11,255,255,255,255,255,255,255,12,255,255,255,13,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern lbig_kern[] = {
++ {50,49,-5},{51,49,-7},{52,49,-48},{52,55,-51},{54,49,-4},{56,49,-6},{57,49,-6},
++};
++const struct fos_font fos_font_lbig_data = { lbig_bits, lbig_glyphs, lbig_lut, lbig_kern, 7, 54, 11 };
++
++static const uint8_t lname_bits[] = {
++ 128,4,47,3,129,4,47,3,129,3,47,2,129,3,47,2,129,2,47,1,129,2,47,1,
++ 129,1,47,130,1,47,131,31,14,131,31,14,131,14,15,13,145,10,14,10,130,6,47,5,
++ 129,6,47,5,130,10,14,10,129,9,31,10,128,47,3,8,31,9,128,47,3,7,31,8,
++ 128,14,31,2,7,31,7,128,13,31,1,6,31,6,128,12,31,128,4,31,5,128,11,15,
++ 14,227,131,6,23,5,129,39,4,132,14,31,9,128,1,47,7,131,1,47,7,128,4,47,
++ 4,131,4,47,4,128,6,47,2,129,4,127,63,8,128,4,127,63,8,128,4,127,63,8,
++ 130,13,31,10,128,1,47,8,132,47,8,128,2,47,6,131,2,47,7,128,4,47,4,129,
++ 2,127,63,10,128,2,127,63,10,128,2,127,63,10,130,11,31,12,129,13,31,10,132,13,
++ 31,10,129,47,8,132,47,8,128,3,47,5,131,1,40,3,128,2,40,2,130,129,3,10,
++ 30,10,2,131,5,31,3,131,3,14,15,30,15,14,2,130,13,15,10,132,11,15,7,129,
++ 8,15,10,129,7,31,2,132,13,15,130,1,15,12,128,1,14,15,8,133,11,15,7,129,
++ 8,15,10,128,8,15,14,1,133,3,14,15,30,15,14,3,2,31,7,135,3,11,30,10,
++ 3,128,10,15,13,142,3,31,5,142,11,15,12,142,5,31,4,128,6,11,12,9,1,136,
++ 13,15,10,128,10,63,14,2,134,6,31,2,5,15,12,3,1,9,15,10,133,1,14,15,
++ 9,128,10,15,4,130,14,15,133,8,15,14,1,128,10,15,4,130,14,15,132,2,14,15,
++ 7,129,6,15,11,1,128,7,15,11,132,9,15,13,1,130,12,15,30,15,14,3,131,2,
++ 31,5,131,1,9,30,11,3,129,130,5,11,30,12,7,135,7,95,12,1,132,2,127,8,
++ 132,6,47,6,2,12,31,13,132,6,47,2,128,9,31,14,132,4,47,6,1,13,31,12,
++ 133,11,31,14,12,47,5,133,2,14,79,9,134,2,13,63,7,134,2,14,79,7,129,10,
++ 5,130,11,47,12,47,5,7,31,10,128,2,47,8,128,11,95,8,128,4,47,4,128,1,
++ 12,63,12,129,4,47,10,18,9,63,3,129,1,14,127,31,9,130,6,127,47,5,130,4,
++ 11,14,15,14,12,7,1,11,31,14,1,9,31,13,8,31,12,8,31,11,7,31,10,6,
++ 31,9,5,31,8,171,129,5,47,2,130,13,31,12,130,6,47,6,130,12,47,1,129,2,
++ 47,12,130,6,47,8,130,9,47,5,130,12,47,3,130,13,47,1,130,14,47,131,14,47,
++ 131,14,47,131,13,47,1,130,12,47,3,130,9,47,5,130,6,47,8,130,2,47,12,131,
++ 12,47,1,130,6,47,6,131,13,31,12,131,5,47,2,128,128,6,31,14,2,130,1,14,
++ 31,10,131,9,47,3,130,4,47,8,131,14,31,14,131,11,47,2,130,9,47,5,130,6,
++ 47,8,130,5,47,9,130,4,47,10,130,3,47,11,130,4,47,10,130,5,47,9,130,6,
++ 47,8,130,9,47,5,130,11,47,2,129,1,47,14,130,4,47,8,130,9,47,3,129,1,
++ 14,31,10,130,6,31,14,2,129,130,7,15,7,131,7,1,7,15,8,1,7,128,4,15,
++ 14,11,15,11,14,15,5,3,12,79,13,4,129,11,47,12,1,128,3,12,79,12,3,4,
++ 15,14,11,15,12,14,15,5,128,6,1,7,15,8,1,7,131,7,15,7,211,131,12,15,
++ 11,135,13,15,12,135,13,15,12,135,13,15,12,131,6,127,15,5,6,127,15,22,127,15,
++ 5,131,13,15,12,135,13,15,12,135,12,15,12,164,128,10,31,5,128,13,31,2,128,14,
++ 15,13,129,31,10,128,2,31,6,128,3,31,2,128,135,6,95,10,6,95,10,6,95,10,
++ 175,128,7,14,13,3,128,1,47,10,128,1,47,10,129,7,14,12,2,128,132,2,47,5,
++ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,47,1,132,12,31,11,132,2,47,6,
++ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,47,1,132,12,31,11,132,2,47,6,
++ 132,7,47,1,132,12,31,11,132,2,47,6,132,7,31,14,1,132,129,1,9,13,15,14,
++ 10,3,130,2,14,95,5,129,11,111,14,17,47,11,1,7,47,6,3,47,5,129,47,8,
++ 4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,
++ 129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,9,4,47,4,129,14,31,
++ 9,3,47,5,129,47,8,1,47,11,1,7,47,6,128,11,111,14,1,128,2,14,95,5,
++ 130,2,9,13,15,14,10,3,129,2,8,13,47,3,11,79,3,11,79,3,6,7,9,47,
++ 3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,
++ 3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,3,129,5,47,
++ 3,129,5,47,3,129,2,9,13,15,14,10,2,130,4,14,79,14,3,129,13,111,12,128,
++ 4,47,8,1,11,47,2,6,47,3,128,5,47,3,5,44,2,128,7,47,2,133,12,31,
++ 14,133,4,47,9,132,1,13,31,14,2,132,10,47,6,132,6,47,9,132,3,47,12,132,
++ 2,14,31,14,2,131,1,12,47,4,132,5,127,15,8,5,127,15,8,5,127,15,8,2,
++ 127,15,1,2,127,15,1,2,127,15,1,132,9,47,10,132,6,47,12,1,131,4,47,13,
++ 1,131,2,14,47,7,132,1,11,63,12,1,131,1,7,4,12,31,9,134,5,31,13,134,
++ 4,47,128,3,41,1,128,4,47,1,6,47,2,128,5,47,1,4,47,8,1,11,31,14,
++ 128,1,14,111,10,129,5,95,14,2,130,3,10,14,15,13,9,2,129,130,5,47,6,134,
++ 11,47,1,133,1,47,11,134,7,47,5,134,12,31,14,1,133,2,47,10,134,8,47,4,
++ 128,14,31,8,129,13,31,14,129,47,8,128,3,47,9,129,47,8,128,8,127,31,11,10,
++ 127,31,11,10,127,31,11,133,1,47,9,135,47,8,135,47,8,135,47,8,135,14,31,8,
++ 128,3,127,15,19,127,15,19,127,15,19,47,5,133,3,47,4,133,3,47,4,133,3,47,
++ 5,6,10,8,3,129,3,47,14,63,5,128,3,127,14,128,3,47,11,3,10,47,3,128,
++ 36,1,128,3,47,5,133,2,47,6,2,45,5,128,3,47,5,1,47,11,1,9,47,4,
++ 128,11,111,14,1,128,2,14,95,5,130,2,9,13,15,14,11,4,129,129,2,10,13,15,
++ 14,10,2,130,4,14,79,14,3,129,13,111,12,128,2,47,10,1,10,47,2,3,47,5,
++ 128,5,47,2,3,47,5,129,34,128,3,47,8,12,15,12,5,129,3,127,5,128,3,127,
++ 13,128,3,47,11,1,9,47,2,3,47,6,128,3,47,5,3,47,5,128,3,47,6,2,
++ 47,6,128,3,47,6,128,14,31,11,1,9,47,5,128,10,127,2,128,2,14,95,7,130,
++ 2,9,13,15,13,11,4,129,9,127,13,10,127,14,10,127,14,10,31,3,128,1,14,31,
++ 12,2,20,129,4,47,7,132,8,47,3,132,13,31,13,132,2,47,8,132,7,47,4,132,
++ 11,31,14,132,1,47,10,132,5,47,5,132,10,47,1,132,14,31,11,132,4,47,7,132,
++ 9,47,2,132,13,31,12,131,129,2,9,13,15,13,10,3,130,3,14,95,4,129,12,111,
++ 13,128,2,47,9,2,10,47,19,47,4,128,4,47,3,2,47,9,1,9,31,14,1,128,
++ 13,111,7,129,4,95,11,130,1,12,95,6,129,10,31,11,1,11,31,13,128,1,47,5,
++ 128,5,47,2,3,47,4,128,4,47,19,47,5,128,5,47,3,1,47,11,1,11,31,14,
++ 129,10,111,8,129,2,13,79,12,1,130,1,9,13,15,13,8,1,129,129,6,12,30,13,
++ 8,1,130,9,95,13,1,128,3,127,9,128,7,47,7,1,12,31,13,128,8,47,1,128,
++ 8,47,128,8,47,1,128,7,47,1,7,47,1,128,8,47,1,4,47,7,1,13,47,17,
++ 14,127,1,128,7,127,1,129,7,13,15,12,10,47,1,128,34,129,7,47,1,4,47,3,
++ 128,7,47,1,4,47,8,1,12,47,128,1,14,111,11,129,5,95,14,2,130,4,11,14,
++ 15,13,9,2,129,128,1,11,14,10,130,6,47,5,129,6,47,5,129,1,11,14,10,158,
++ 1,11,14,10,130,6,47,5,129,6,47,5,129,1,11,14,10,129,128,6,14,13,4,128,
++ 2,47,14,128,2,47,14,129,7,14,13,4,153,9,31,6,129,11,31,4,129,12,31,1,
++ 129,13,15,12,130,14,15,9,130,31,5,129,129,2,9,13,15,14,10,3,130,4,14,95,
++ 5,128,1,14,111,14,1,6,47,7,1,8,47,5,8,47,129,2,47,7,3,37,129,4,
++ 47,6,132,2,13,47,1,131,3,14,47,6,131,2,14,47,6,132,7,47,5,133,9,31,
++ 14,134,4,23,5,145,3,13,14,6,134,11,47,134,11,47,134,3,13,14,6,131,130,1,
++ 63,1,133,4,63,5,133,7,63,8,133,10,63,11,133,14,79,132,2,31,11,13,31,3,
++ 131,6,31,9,10,31,6,131,9,31,6,7,31,10,131,12,31,3,4,31,13,130,1,47,
++ 1,2,47,1,129,4,31,13,129,14,31,5,129,7,31,14,27,14,31,8,129,11,127,12,
++ 129,14,127,15,128,2,47,3,129,3,47,3,6,47,1,129,1,47,7,9,31,13,131,13,
++ 31,10,128,13,63,14,11,6,131,14,111,11,130,14,127,6,129,14,31,10,1,4,14,31,
++ 11,129,14,31,9,129,9,31,13,129,14,31,9,129,9,31,13,129,14,31,10,128,3,14,
++ 31,9,129,14,111,14,2,129,14,111,6,130,14,111,14,3,129,14,31,10,128,3,13,31,
++ 11,129,14,31,9,129,7,47,1,128,14,31,9,129,7,47,2,128,14,31,10,128,3,13,
++ 47,1,128,14,127,11,129,14,111,14,2,129,13,79,13,8,1,129,129,1,8,13,15,14,
++ 12,5,131,2,13,95,9,130,10,127,5,128,1,47,11,2,3,14,31,10,128,2,47,6,
++ 129,11,31,12,128,2,47,6,129,3,21,3,128,2,47,6,134,2,47,6,134,2,47,6,
++ 134,2,47,6,134,2,47,6,134,2,47,6,129,3,21,4,128,2,47,6,129,11,31,12,
++ 128,1,47,11,2,3,14,31,10,129,10,127,4,129,2,13,95,9,131,1,8,13,15,14,
++ 11,5,130,128,13,63,14,12,6,131,14,111,11,130,14,127,7,129,14,31,10,128,4,14,
++ 31,12,129,14,31,9,129,10,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,
++ 31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,
++ 31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,10,
++ 31,14,129,14,31,10,128,4,14,31,12,129,14,127,7,129,14,111,11,130,13,63,14,12,
++ 6,130,128,13,127,4,128,14,127,4,128,14,127,4,128,14,31,10,134,14,31,9,134,14,
++ 31,9,134,14,31,10,134,14,95,1,130,14,95,1,130,14,95,1,130,14,31,10,134,14,
++ 31,9,134,14,31,9,134,14,31,10,134,14,127,4,128,14,127,4,128,13,127,4,128,13,
++ 127,3,128,14,127,4,128,14,127,3,128,14,31,10,134,14,31,9,134,14,31,9,134,14,
++ 31,10,134,14,95,131,14,95,131,14,95,131,14,31,10,134,14,31,9,134,14,31,9,134,
++ 14,31,9,134,14,31,9,134,14,31,9,134,13,31,9,133,129,1,8,13,15,14,12,6,
++ 131,2,13,95,11,130,11,127,7,128,1,47,12,2,3,14,31,11,128,2,47,6,129,11,
++ 31,12,128,2,47,6,129,3,20,3,128,2,47,6,134,2,47,6,3,63,12,128,2,47,
++ 6,3,63,12,128,2,47,6,3,63,12,128,2,47,6,129,11,31,12,128,2,47,6,129,
++ 11,31,12,128,2,47,6,129,11,31,12,128,1,47,12,2,4,47,10,129,11,127,4,129,
++ 2,14,95,9,131,1,8,13,15,14,11,5,130,128,13,31,9,129,9,31,13,129,14,31,
++ 9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,
++ 9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,10,129,10,31,14,129,14,127,
++ 14,129,14,127,14,129,14,127,14,129,14,31,10,129,10,31,14,129,14,31,9,129,9,31,
++ 14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,14,129,14,31,9,129,9,31,
++ 14,129,14,31,9,129,9,31,14,129,13,31,9,129,9,31,13,128,128,13,31,9,129,14,
++ 31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,
++ 31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,31,9,129,14,
++ 31,9,129,14,31,9,129,14,31,9,129,13,31,9,128,133,5,47,3,133,5,47,3,133,
++ 5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,5,47,3,133,
++ 5,47,3,133,5,47,3,5,24,7,129,5,47,3,10,31,13,129,5,47,3,10,31,14,
++ 129,5,47,3,8,47,5,1,11,47,1,3,127,11,129,8,95,14,2,130,5,11,14,15,
++ 13,9,1,129,128,13,31,9,129,2,14,31,8,128,14,31,9,129,10,31,14,1,128,14,
++ 31,9,128,3,47,8,129,14,31,9,128,10,31,14,1,129,14,31,9,3,47,7,130,14,
++ 31,9,11,31,14,1,130,14,31,13,47,7,131,14,95,1,131,14,95,6,131,14,95,12,
++ 131,14,47,11,47,3,130,14,31,12,1,14,31,10,130,14,31,9,128,9,47,2,129,14,
++ 31,9,128,3,47,8,129,14,31,9,129,11,31,14,129,14,31,9,129,5,47,6,128,13,
++ 31,9,130,13,31,12,128,13,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,
++ 31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,31,9,134,14,
++ 31,9,134,14,31,9,134,14,31,9,134,14,31,10,134,14,127,4,128,14,127,4,128,13,
++ 127,4,128,14,31,11,130,2,14,31,10,129,63,5,129,9,47,10,129,63,13,128,2,63,
++ 10,129,79,7,11,63,10,129,127,47,10,129,47,14,111,10,129,47,9,13,31,9,13,31,
++ 10,129,47,8,5,15,14,1,13,31,10,129,47,8,128,11,7,128,13,31,10,129,47,8,
++ 128,2,129,13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,129,47,8,131,
++ 13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,129,47,8,131,13,31,10,
++ 129,14,31,8,131,12,31,10,128,128,13,31,14,1,129,11,31,11,129,14,47,6,129,11,
++ 31,11,129,14,47,11,129,11,31,11,129,14,63,1,128,11,31,11,129,14,63,6,128,11,
++ 31,11,129,14,63,11,128,11,31,11,129,14,79,1,11,31,11,129,14,31,13,31,6,11,
++ 31,11,129,14,31,9,14,15,27,31,11,129,14,31,25,31,12,31,11,129,14,31,9,4,
++ 79,11,129,14,31,9,128,14,63,11,129,14,31,9,128,9,63,11,129,14,31,9,128,4,
++ 63,11,129,14,31,9,129,14,47,11,129,14,31,9,129,9,47,11,129,13,31,9,129,4,
++ 47,11,128,129,1,8,13,15,14,12,6,131,1,13,95,11,130,10,127,7,129,47,12,2,
++ 3,14,31,12,128,2,47,6,129,9,31,14,128,2,47,6,129,8,47,128,2,47,6,129,
++ 8,47,128,2,47,6,129,8,47,128,2,47,6,129,8,47,128,2,47,6,129,8,47,128,
++ 2,47,6,129,8,47,128,2,47,6,129,8,47,128,2,47,6,129,9,31,14,128,1,47,
++ 12,2,3,14,31,12,129,10,127,7,129,1,13,95,11,131,1,8,13,15,14,12,6,130,
++ 128,13,79,13,7,1,130,14,111,12,130,14,127,8,129,14,31,9,128,3,13,31,13,129,
++ 14,31,9,129,7,47,1,128,14,31,9,129,7,47,1,128,14,31,9,128,3,13,31,14,
++ 129,14,127,10,129,14,111,13,2,129,14,79,14,10,2,130,14,31,9,135,14,31,9,135,
++ 14,31,9,135,14,31,9,135,14,31,9,135,14,31,9,135,14,31,9,134,130,7,12,30,
++ 11,3,132,12,95,5,130,8,111,14,1,129,14,31,12,2,5,47,7,128,1,47,6,129,
++ 13,31,9,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,
++ 13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,
++ 13,31,10,128,2,47,6,129,13,31,10,128,2,47,6,129,13,31,10,128,1,47,6,129,
++ 13,31,9,129,13,31,12,1,5,47,6,129,7,111,14,1,130,11,95,4,132,6,47,12,
++ 2,134,47,8,135,47,8,131,128,13,79,13,8,1,130,14,111,12,1,129,14,127,8,129,
++ 14,31,10,128,3,13,31,14,129,14,31,9,129,7,47,1,128,14,31,9,129,7,47,2,
++ 128,14,31,10,128,3,13,31,14,129,14,127,9,129,14,111,13,1,129,14,111,1,130,14,
++ 31,10,3,47,4,130,14,31,9,128,13,31,9,130,14,31,9,128,9,31,14,130,14,31,
++ 9,128,4,47,4,129,14,31,9,128,1,47,8,129,14,31,9,129,11,31,13,129,13,31,
++ 9,129,6,47,3,129,3,10,14,15,14,10,2,130,4,95,14,4,129,14,111,13,128,3,
++ 47,9,1,8,47,4,5,47,3,128,2,47,5,3,47,7,129,39,2,128,12,47,6,133,
++ 3,14,47,10,1,132,3,13,47,13,3,132,1,10,63,4,133,6,47,14,17,38,1,128,
++ 5,47,6,4,47,4,129,47,7,2,47,10,1,7,47,6,128,12,111,14,1,128,3,14,
++ 95,6,130,2,9,13,15,14,10,4,129,6,127,31,1,6,127,31,1,6,127,31,1,130,
++ 1,47,9,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,
++ 135,47,8,135,47,8,135,47,8,135,47,8,135,47,8,135,14,31,8,131,128,14,31,8,
++ 129,8,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,
++ 14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,
++ 8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,31,14,129,47,8,129,9,
++ 31,14,129,47,8,129,9,31,14,129,14,31,9,129,9,31,14,129,12,31,14,19,14,31,
++ 11,129,6,127,6,130,11,95,10,132,6,12,30,12,6,130,5,47,6,129,2,47,8,2,
++ 47,8,129,4,47,5,128,14,31,11,129,6,47,2,128,11,31,13,129,9,31,14,129,8,
++ 47,1,128,11,31,11,129,4,47,3,128,13,31,7,129,1,47,5,128,47,4,130,13,31,
++ 8,3,47,1,130,10,31,10,5,31,13,131,6,31,12,7,31,9,131,3,31,14,10,31,
++ 6,132,47,14,31,3,132,12,63,14,133,8,63,11,133,5,63,8,133,2,63,5,134,13,
++ 47,1,130,6,47,3,129,14,31,4,129,13,31,10,3,47,5,128,2,47,7,129,47,7,
++ 1,47,8,128,4,47,9,128,2,47,4,128,12,31,10,128,6,47,12,128,5,47,1,128,
++ 9,31,12,128,8,47,14,128,7,31,13,129,6,47,128,11,63,1,9,31,11,129,3,47,
++ 2,13,63,4,11,31,8,130,47,5,31,13,31,6,13,31,5,130,12,31,9,31,8,31,
++ 9,47,2,130,9,31,14,31,4,31,14,31,14,131,6,79,2,12,63,11,131,3,63,14,
++ 128,10,63,8,132,14,47,12,128,8,63,5,132,11,47,10,128,5,63,2,132,8,47,8,
++ 128,3,47,14,133,5,47,6,129,47,12,133,2,47,3,129,13,31,8,130,4,47,4,129,
++ 5,47,2,128,13,31,10,129,11,31,11,129,7,31,14,1,2,47,5,129,1,14,31,5,
++ 7,31,13,131,9,31,11,12,31,7,131,3,95,1,132,12,63,10,133,5,63,4,133,1,
++ 47,14,134,5,63,3,133,11,63,9,132,3,95,1,131,9,31,11,13,31,7,130,1,14,
++ 31,6,7,31,13,130,7,31,14,1,2,47,5,129,13,31,10,129,11,31,11,128,4,47,
++ 4,129,5,47,2,4,47,5,129,7,47,2,128,14,31,9,129,12,31,12,129,9,31,13,
++ 128,1,47,7,129,4,47,2,5,47,2,130,14,31,6,9,31,11,131,8,31,10,13,31,
++ 6,131,3,95,1,132,13,63,10,133,8,63,5,133,2,47,14,1,134,13,31,10,135,13,
++ 31,10,135,13,31,10,135,13,31,10,135,13,31,10,135,13,31,10,135,12,31,10,131,7,
++ 127,10,8,127,11,7,127,11,132,4,47,7,132,11,31,14,1,131,4,47,7,132,11,31,
++ 14,1,131,4,47,7,132,11,31,14,1,131,4,47,7,132,11,31,14,1,131,4,47,7,
++ 132,11,31,14,1,131,4,47,7,132,7,127,10,8,127,11,7,127,10,
++};
++static const struct fos_glyph lname_glyphs[] = {
++ { 0, 5, 0, 0, 0, 80 }, /* 0x20 */
++ { 0, 7, 17, 0, -17, 112 }, /* 0x21 */
++ { 57, 9, 17, 0, -17, 138 }, /* 0x22 */
++ { 98, 15, 17, 0, -17, 246 }, /* 0x23 */
++ { 213, 19, 17, 0, -17, 306 }, /* 0x25 */
++ { 393, 15, 17, 0, -17, 241 }, /* 0x26 */
++ { 515, 4, 17, 0, -17, 68 }, /* 0x27 */
++ { 534, 8, 21, 0, -19, 124 }, /* 0x28 */
++ { 616, 8, 21, 0, -19, 124 }, /* 0x29 */
++ { 705, 9, 18, 0, -18, 144 }, /* 0x2a */
++ { 765, 11, 13, 0, -13, 175 }, /* 0x2b */
++ { 806, 5, 6, 0, -4, 84 }, /* 0x2c */
++ { 830, 8, 10, 0, -10, 132 }, /* 0x2d */
++ { 841, 6, 4, 0, -4, 89 }, /* 0x2e */
++ { 860, 10, 17, 0, -17, 166 }, /* 0x2f */
++ { 930, 11, 17, 0, -17, 181 }, /* 0x30 */
++ { 1041, 7, 17, 0, -17, 114 }, /* 0x31 */
++ { 1109, 11, 17, 0, -17, 175 }, /* 0x32 */
++ { 1199, 11, 17, 0, -17, 174 }, /* 0x33 */
++ { 1291, 12, 17, 0, -17, 194 }, /* 0x34 */
++ { 1369, 11, 17, 0, -17, 176 }, /* 0x35 */
++ { 1459, 11, 17, 0, -17, 176 }, /* 0x36 */
++ { 1568, 10, 17, 0, -17, 163 }, /* 0x37 */
++ { 1640, 11, 17, 0, -17, 176 }, /* 0x38 */
++ { 1747, 11, 17, 0, -17, 174 }, /* 0x39 */
++ { 1853, 7, 12, 0, -12, 110 }, /* 0x3a */
++ { 1890, 6, 14, 0, -12, 93 }, /* 0x3b */
++ { 1932, 11, 17, 0, -17, 175 }, /* 0x3f */
++ { 2014, 12, 17, 0, -17, 193 }, /* 0x41 */
++ { 2114, 12, 17, 0, -17, 188 }, /* 0x42 */
++ { 2226, 12, 17, 0, -17, 186 }, /* 0x43 */
++ { 2331, 12, 17, 0, -17, 190 }, /* 0x44 */
++ { 2450, 11, 17, 0, -17, 175 }, /* 0x45 */
++ { 2518, 11, 17, 0, -17, 168 }, /* 0x46 */
++ { 2584, 12, 17, 0, -17, 187 }, /* 0x47 */
++ { 2701, 12, 17, 0, -17, 192 }, /* 0x48 */
++ { 2826, 6, 17, 0, -17, 92 }, /* 0x49 */
++ { 2895, 11, 17, 0, -17, 181 }, /* 0x4a */
++ { 2980, 12, 17, 0, -17, 196 }, /* 0x4b */
++ { 3102, 11, 17, 0, -17, 170 }, /* 0x4c */
++ { 3170, 14, 17, 0, -17, 219 }, /* 0x4d */
++ { 3297, 13, 17, 0, -17, 206 }, /* 0x4e */
++ { 3435, 12, 17, 0, -17, 189 }, /* 0x4f */
++ { 3552, 12, 17, 0, -17, 186 }, /* 0x50 */
++ { 3644, 12, 20, 0, -17, 184 }, /* 0x51 */
++ { 3776, 12, 17, 0, -17, 188 }, /* 0x52 */
++ { 3893, 11, 17, 0, -17, 178 }, /* 0x53 */
++ { 3995, 12, 17, 0, -17, 187 }, /* 0x54 */
++ { 4052, 12, 17, 0, -17, 192 }, /* 0x55 */
++ { 4168, 12, 17, 0, -17, 195 }, /* 0x56 */
++ { 4275, 17, 17, 0, -17, 276 }, /* 0x57 */
++ { 4436, 12, 17, 0, -17, 190 }, /* 0x58 */
++ { 4541, 12, 17, 0, -17, 190 }, /* 0x59 */
++ { 4631, 10, 17, 0, -17, 165 }, /* 0x5a */
++};
++static const uint8_t lname_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,255,4,5,6,7,8,9,10,11,12,13,14,
++ 15,16,17,18,19,20,21,22,23,24,25,26,255,255,255,27,255,28,29,30,31,32,33,34,
++ 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern lname_kern[] = {
++ {39,45,-9},{39,65,-20},{39,74,-26},{44,48,-17},{44,55,-14},{44,84,-22},{44,86,-16},{44,87,-16},
++ {44,88,4},{44,89,-30},{45,45,-28},{46,48,-17},{46,55,-14},{46,84,-22},{46,86,-16},{46,87,-16},
++ {46,88,4},{46,89,-30},{50,49,-6},{51,49,-6},{52,49,-22},{52,55,-22},{54,49,-4},{55,44,-18},
++ {55,46,-18},{56,49,-6},{57,49,-6},{65,39,-20},{65,65,6},{65,67,-8},{65,71,-8},{65,79,-8},
++ {65,81,-8},{65,83,-10},{65,84,-24},{65,86,-30},{65,87,-30},{65,89,-22},{66,65,-8},{66,86,-10},
++ {66,87,-10},{66,88,-11},{66,89,-14},{67,65,-4},{67,88,-6},{67,89,-5},{68,65,-8},{68,86,-10},
++ {68,87,-10},{68,88,-11},{68,89,-14},{69,65,6},{70,45,-14},{70,65,-16},{71,65,-4},{71,88,-6},
++ {71,89,-5},{74,65,-6},{75,67,-8},{75,71,-8},{75,79,-8},{75,81,-8},{75,83,-9},{76,65,7},
++ {76,84,-33},{76,89,-14},{79,65,-4},{79,88,-6},{79,89,-5},{80,44,-7},{80,46,-7},{80,65,-14},
++ {80,74,-23},{80,86,-6},{80,87,-6},{80,88,-9},{80,89,-9},{81,65,-4},{81,88,-5},{81,89,-6},
++ {82,89,-11},{83,86,-6},{83,87,-6},{83,88,-11},{83,89,-10},{84,44,-17},{84,45,-28},{84,46,-17},
++ {84,65,-22},{84,67,-8},{84,71,-8},{84,79,-8},{84,81,-8},{85,65,-6},{86,44,-14},{86,45,-20},
++ {86,46,-14},{86,65,-30},{86,67,-7},{86,71,-7},{86,74,-14},{86,79,-7},{86,81,-7},{86,83,-6},
++ {87,44,-14},{87,45,-20},{87,46,-14},{87,65,-30},{87,67,-7},{87,71,-7},{87,74,-14},{87,79,-7},
++ {87,81,-7},{87,83,-6},{88,45,-6},{88,67,-6},{88,71,-6},{88,79,-6},{88,81,-6},{88,83,-11},
++ {89,44,-30},{89,45,-24},{89,46,-30},{89,65,-28},{89,67,-9},{89,71,-9},{89,74,-23},{89,79,-9},
++ {89,81,-9},{89,83,-11},
++};
++const struct fos_font fos_font_lname_data = { lname_bits, lname_glyphs, lname_lut, lname_kern, 130, 25, 5 };
++
++static const uint8_t lsm_bits[] = {
++ 128,15,7,129,15,7,129,14,7,129,14,6,129,14,6,129,13,5,133,4,1,128,1,14,
++ 8,128,11,9,10,27,25,10,9,24,9,151,129,27,128,27,130,14,9,128,14,9,129,95,
++ 5,128,7,15,8,7,15,8,2,128,4,15,3,4,15,3,129,6,15,3,6,15,3,128,
++ 7,79,14,128,2,12,13,4,12,13,3,129,13,10,128,12,10,129,128,7,14,11,1,128,
++ 5,11,129,2,13,6,11,7,128,13,3,129,3,11,2,24,7,9,131,11,15,14,3,14,
++ 2,132,3,1,24,128,1,132,2,14,2,12,15,9,131,10,23,10,5,12,4,129,3,13,
++ 128,6,11,6,12,3,129,11,5,128,1,11,15,8,128,128,5,13,14,8,131,14,12,9,
++ 15,4,129,1,15,7,3,15,5,130,9,14,29,1,130,6,31,2,130,3,15,10,14,8,
++ 7,8,128,8,15,128,5,31,7,128,7,15,23,31,2,128,1,10,30,8,28,128,43,10,
++ 25,139,128,12,11,128,4,15,6,128,9,15,2,128,12,14,129,14,12,129,15,11,129,15,
++ 11,129,14,11,129,12,13,129,9,15,1,128,4,15,5,129,13,11,128,1,15,7,129,11,
++ 14,129,7,15,3,128,4,15,6,128,2,15,8,128,1,15,9,128,1,15,9,128,2,15,
++ 8,128,4,15,6,128,7,15,3,128,11,13,128,1,15,7,128,18,12,2,1,6,13,14,
++ 12,3,6,13,14,12,19,2,12,2,1,152,129,11,6,129,17,11,7,1,128,10,63,6,
++ 2,4,12,9,4,1,129,11,6,141,4,15,128,6,12,128,24,128,49,10,31,13,2,20,
++ 3,139,130,6,15,2,1,3,128,129,3,15,5,129,7,15,1,129,12,11,129,2,15,6,
++ 129,6,15,2,129,11,12,129,1,15,7,129,5,15,3,129,9,13,130,128,8,14,13,6,
++ 128,5,15,8,10,15,2,7,15,128,3,15,5,8,15,128,2,15,5,8,15,128,2,15,
++ 5,8,15,128,2,15,5,7,15,128,3,15,21,15,8,10,15,2,128,8,30,6,128,8,
++ 14,15,128,8,12,15,129,8,15,129,8,15,129,8,15,129,8,15,129,8,15,129,8,15,
++ 129,8,15,128,128,9,14,13,4,128,6,15,7,12,13,128,9,14,128,8,15,131,11,13,
++ 130,4,15,6,129,1,13,11,130,10,14,2,129,6,15,9,21,1,9,63,4,8,63,128,
++ 2,5,6,15,12,130,10,14,2,129,5,15,11,1,130,4,11,10,131,7,14,128,8,12,
++ 128,7,15,128,7,15,7,28,128,1,10,14,13,4,128,128,1,15,8,130,7,15,3,130,
++ 28,130,2,15,7,5,15,2,8,15,3,7,15,3,12,63,11,3,20,8,15,5,130,5,
++ 15,2,130,5,15,2,7,63,1,8,15,37,128,8,15,131,8,15,12,15,7,128,7,15,
++ 7,11,15,1,128,1,128,5,15,2,4,9,128,5,15,2,4,15,9,11,15,129,9,14,
++ 13,5,128,128,9,14,13,5,128,5,15,8,12,14,128,7,15,1,3,6,128,7,15,14,
++ 15,6,128,7,15,8,11,15,128,7,15,1,5,15,3,7,15,1,5,15,3,4,15,9,
++ 11,15,1,128,9,14,13,6,128,12,47,14,12,9,5,29,1,128,1,14,9,129,4,15,
++ 5,129,9,15,1,129,13,11,129,2,15,7,129,7,15,2,129,11,13,129,1,10,14,13,
++ 5,128,6,15,7,11,14,128,6,15,3,8,15,1,128,12,31,12,128,3,15,8,12,7,
++ 128,6,15,128,6,14,128,7,15,128,6,15,1,3,15,9,12,14,129,8,14,13,4,128,
++ 1,11,14,12,3,128,8,15,7,13,12,128,11,12,128,8,14,128,9,14,3,11,15,128,
++ 3,14,47,129,2,3,8,15,128,8,14,128,9,15,128,6,15,8,29,129,10,14,13,3,
++ 128,130,2,15,7,128,3,1,136,2,15,7,128,3,1,5,14,3,6,15,3,128,1,134,
++ 4,15,1,5,12,128,7,9,128,1,10,14,13,3,128,8,15,7,12,13,128,10,12,128,
++ 8,15,1,130,12,13,130,10,15,5,129,3,15,7,130,2,10,2,131,4,1,130,4,14,
++ 4,129,129,14,13,130,3,31,2,129,6,12,14,5,129,10,9,11,9,129,13,6,8,12,
++ 128,1,15,4,5,15,1,4,63,4,8,14,19,15,7,27,129,12,10,4,31,14,8,128,
++ 4,15,7,9,15,5,4,15,3,128,15,8,4,15,20,15,5,4,47,12,128,4,15,22,
++ 15,5,4,15,3,128,13,9,4,15,23,15,7,4,31,14,10,1,128,8,30,7,128,4,
++ 15,24,15,4,7,15,17,11,5,7,15,1,130,7,15,1,130,7,15,1,130,7,15,17,
++ 11,5,4,15,24,15,4,128,8,30,7,128,4,31,14,8,128,4,15,7,8,15,5,4,
++ 15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,8,4,
++ 15,3,1,15,8,4,15,7,9,15,5,4,31,14,8,128,4,63,3,4,15,7,21,1,
++ 4,15,3,130,4,15,4,1,129,4,47,1,128,4,15,6,4,129,4,15,3,130,4,15,
++ 7,21,1,4,63,3,4,63,3,4,15,7,21,1,4,15,3,130,4,15,4,1,129,4,
++ 47,1,128,4,15,6,4,129,4,15,3,130,4,15,3,130,4,15,3,130,128,8,30,8,
++ 128,4,15,25,15,4,7,15,17,12,5,7,15,33,128,7,15,2,31,23,15,1,5,15,
++ 23,15,17,15,7,4,15,25,15,4,128,8,30,7,128,4,15,3,128,15,7,4,15,3,
++ 128,15,8,4,15,3,128,15,8,4,15,4,1,15,8,4,63,8,4,15,6,4,15,8,
++ 4,15,3,128,15,8,4,15,3,128,15,8,4,15,3,128,15,7,4,15,3,4,15,3,
++ 4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,4,15,3,130,7,15,
++ 1,130,7,15,1,130,7,15,1,130,7,15,1,130,7,15,1,21,128,7,15,1,12,11,
++ 128,7,15,1,9,14,6,12,13,128,1,11,14,12,3,128,4,15,3,1,14,10,4,15,
++ 3,8,15,2,4,15,4,14,9,128,4,15,12,14,1,128,4,47,2,128,4,15,9,14,
++ 8,128,4,15,3,9,14,1,4,15,19,15,6,4,15,3,128,28,4,15,3,130,4,15,
++ 3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,3,130,4,15,
++ 7,21,1,4,63,3,5,15,6,128,6,15,21,15,14,2,14,15,21,31,14,31,21,15,
++ 8,15,8,15,21,15,3,8,3,15,21,15,3,128,3,15,21,15,3,128,3,15,21,15,
++ 3,128,3,15,21,15,2,128,2,15,5,4,15,7,128,9,13,128,4,15,13,128,9,13,
++ 128,4,31,3,9,13,128,4,15,14,25,13,128,4,15,8,14,9,13,128,4,15,4,30,
++ 13,128,4,15,3,10,15,13,128,4,15,3,4,15,13,128,4,15,3,128,14,13,128,128,
++ 7,30,8,128,4,15,9,8,15,5,7,15,1,128,15,8,7,15,1,128,15,8,7,15,
++ 1,128,15,8,7,15,1,128,15,8,7,15,1,128,15,8,4,15,9,8,15,5,128,7,
++ 30,8,128,5,47,9,128,5,15,7,8,15,6,5,15,3,128,14,9,5,15,20,15,7,
++ 5,47,13,1,5,15,6,3,1,128,5,15,3,130,5,15,3,130,5,15,3,130,128,7,
++ 14,13,6,128,3,15,9,10,15,2,6,15,1,3,15,5,7,15,1,2,15,6,7,15,
++ 1,2,15,6,7,15,1,2,15,6,7,15,1,2,15,22,15,3,4,15,5,1,46,13,
++ 1,128,2,29,2,130,12,10,129,4,47,9,128,4,15,7,8,15,6,4,15,3,128,14,
++ 9,4,15,20,15,8,4,47,13,1,4,15,6,14,8,128,4,15,3,9,13,128,4,15,
++ 3,4,15,3,4,15,3,128,14,8,128,10,14,13,5,128,6,15,7,11,14,1,8,14,
++ 128,4,13,2,3,15,9,131,5,14,12,2,130,2,29,128,7,12,128,4,15,3,6,15,
++ 8,10,15,1,128,9,14,13,5,128,10,63,8,3,5,14,12,5,3,129,13,10,131,13,
++ 10,131,13,10,131,13,10,131,13,10,131,13,10,131,13,10,129,5,15,2,128,14,8,5,
++ 15,2,128,14,8,5,15,2,128,14,8,5,15,2,128,14,8,5,15,2,128,14,8,5,
++ 15,2,128,14,8,5,15,3,128,14,8,2,15,10,8,15,5,128,6,13,14,8,128,8,
++ 15,1,128,13,10,5,15,3,1,15,7,2,15,6,3,15,4,128,14,8,6,15,1,128,
++ 27,8,12,129,8,14,11,9,129,4,15,14,6,129,1,31,3,130,13,14,129,9,14,128,
++ 6,15,1,3,15,4,6,15,1,8,15,4,6,15,1,3,15,4,10,15,6,8,13,128,
++ 1,15,6,29,9,10,11,129,12,9,15,9,11,13,8,129,9,14,15,4,14,15,5,129,
++ 6,15,13,2,31,2,129,3,15,10,128,30,130,1,15,8,128,12,11,129,7,15,17,15,
++ 7,1,15,23,14,1,128,10,28,9,129,3,31,3,130,14,13,130,3,31,3,129,9,28,
++ 9,128,1,15,23,14,1,7,15,17,15,7,7,15,1,2,15,6,2,15,5,6,15,1,
++ 128,12,10,27,129,6,14,15,5,129,1,15,14,1,130,12,11,131,12,11,131,12,11,131,
++ 12,11,129,10,47,14,3,21,13,12,129,3,15,5,129,11,13,129,3,15,6,129,10,14,
++ 129,2,15,7,129,9,15,6,21,10,47,14,
++};
++static const struct fos_glyph lsm_glyphs[] = {
++ { 0, 3, 0, 0, 0, 42 }, /* 0x20 */
++ { 0, 4, 9, 0, -9, 56 }, /* 0x21 */
++ { 26, 4, 9, 0, -9, 64 }, /* 0x22 */
++ { 36, 8, 9, 0, -9, 126 }, /* 0x23 */
++ { 90, 10, 9, 0, -9, 161 }, /* 0x25 */
++ { 159, 8, 9, 0, -9, 121 }, /* 0x26 */
++ { 214, 2, 9, 0, -9, 32 }, /* 0x27 */
++ { 218, 4, 12, 0, -11, 58 }, /* 0x28 */
++ { 259, 4, 12, 0, -11, 58 }, /* 0x29 */
++ { 305, 5, 9, 0, -9, 75 }, /* 0x2a */
++ { 324, 6, 7, 0, -7, 91 }, /* 0x2b */
++ { 346, 3, 3, 0, -2, 41 }, /* 0x2c */
++ { 354, 4, 6, 0, -6, 68 }, /* 0x2d */
++ { 362, 3, 3, 0, -2, 44 }, /* 0x2e */
++ { 369, 5, 9, 0, -9, 80 }, /* 0x2f */
++ { 403, 6, 9, 0, -9, 94 }, /* 0x30 */
++ { 455, 4, 9, 0, -9, 57 }, /* 0x31 */
++ { 484, 6, 9, 0, -9, 88 }, /* 0x32 */
++ { 525, 6, 9, 0, -9, 89 }, /* 0x33 */
++ { 567, 6, 9, 0, -9, 95 }, /* 0x34 */
++ { 606, 6, 9, 0, -9, 89 }, /* 0x35 */
++ { 651, 6, 9, 0, -9, 89 }, /* 0x36 */
++ { 705, 5, 9, 0, -9, 82 }, /* 0x37 */
++ { 740, 6, 9, 0, -9, 90 }, /* 0x38 */
++ { 792, 6, 9, 0, -9, 88 }, /* 0x39 */
++ { 841, 3, 8, 0, -7, 52 }, /* 0x3a */
++ { 855, 3, 8, 0, -7, 45 }, /* 0x3b */
++ { 873, 6, 9, 0, -9, 86 }, /* 0x3f */
++ { 914, 6, 9, 0, -9, 95 }, /* 0x41 */
++ { 955, 6, 9, 0, -9, 96 }, /* 0x42 */
++ { 1002, 6, 9, 0, -9, 95 }, /* 0x43 */
++ { 1044, 6, 9, 0, -9, 98 }, /* 0x44 */
++ { 1096, 6, 9, 0, -9, 90 }, /* 0x45 */
++ { 1134, 6, 9, 0, -9, 86 }, /* 0x46 */
++ { 1172, 6, 9, 0, -9, 96 }, /* 0x47 */
++ { 1215, 6, 9, 0, -9, 99 }, /* 0x48 */
++ { 1266, 3, 9, 0, -9, 47 }, /* 0x49 */
++ { 1293, 6, 9, 0, -9, 92 }, /* 0x4a */
++ { 1336, 6, 9, 0, -9, 99 }, /* 0x4b */
++ { 1386, 6, 9, 0, -9, 86 }, /* 0x4c */
++ { 1422, 7, 9, 0, -9, 112 }, /* 0x4d */
++ { 1475, 7, 9, 0, -9, 105 }, /* 0x4e */
++ { 1535, 6, 9, 0, -9, 97 }, /* 0x4f */
++ { 1587, 6, 9, 0, -9, 95 }, /* 0x50 */
++ { 1630, 6, 11, 0, -9, 95 }, /* 0x51 */
++ { 1689, 6, 9, 0, -9, 96 }, /* 0x52 */
++ { 1738, 6, 9, 0, -9, 90 }, /* 0x53 */
++ { 1786, 6, 9, 0, -9, 94 }, /* 0x54 */
++ { 1817, 6, 9, 0, -9, 99 }, /* 0x55 */
++ { 1871, 6, 9, 0, -9, 98 }, /* 0x56 */
++ { 1917, 9, 9, 0, -9, 138 }, /* 0x57 */
++ { 1988, 6, 9, 0, -9, 96 }, /* 0x58 */
++ { 2028, 6, 9, 0, -9, 95 }, /* 0x59 */
++ { 2067, 5, 9, 0, -9, 84 }, /* 0x5a */
++};
++static const uint8_t lsm_lut[256] = {
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,0,1,2,3,255,4,5,6,7,8,9,10,11,12,13,14,
++ 15,16,17,18,19,20,21,22,23,24,25,26,255,255,255,27,255,28,29,30,31,32,33,34,
++ 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
++};
++static const struct fos_kern lsm_kern[] = {
++ {39,45,-5},{39,65,-9},{39,74,-11},{44,48,-8},{44,55,-6},{44,84,-11},{44,86,-7},{44,87,-7},
++ {44,89,-14},{45,45,-12},{46,48,-8},{46,55,-6},{46,84,-11},{46,86,-7},{46,87,-7},{46,89,-14},
++ {50,49,-4},{51,49,-5},{52,49,-11},{52,55,-11},{54,49,-4},{55,44,-10},{55,46,-10},{56,49,-5},
++ {57,49,-5},{65,39,-9},{65,65,5},{65,83,-5},{65,84,-12},{65,86,-14},{65,87,-14},{65,89,-10},
++ {66,65,-4},{66,86,-4},{66,87,-4},{66,88,-5},{66,89,-6},{68,65,-4},{68,86,-4},{68,87,-4},
++ {68,88,-5},{68,89,-6},{69,65,4},{70,45,-6},{70,65,-7},{75,83,-4},{76,65,5},{76,84,-16},
++ {76,89,-6},{80,44,-5},{80,46,-5},{80,65,-6},{80,74,-9},{80,88,-4},{80,89,-4},{82,89,-5},
++ {83,88,-5},{83,89,-5},{84,44,-9},{84,45,-13},{84,46,-9},{84,65,-10},{84,67,-5},{84,71,-5},
++ {84,79,-5},{84,81,-5},{86,44,-6},{86,45,-9},{86,46,-6},{86,65,-14},{86,74,-6},{87,44,-6},
++ {87,45,-9},{87,46,-6},{87,65,-14},{87,74,-6},{88,83,-5},{89,44,-14},{89,45,-11},{89,46,-14},
++ {89,65,-13},{89,67,-4},{89,71,-4},{89,74,-9},{89,79,-4},{89,81,-4},{89,83,-5},
++};
++const struct fos_font fos_font_lsm_data = { lsm_bits, lsm_glyphs, lsm_lut, lsm_kern, 87, 13, 3 };
+diff --git a/src/fos_gfx.c b/src/fos_gfx.c
+new file mode 100644
+index 000000000..a4e0f3add
+--- /dev/null
++++ b/src/fos_gfx.c
+@@ -0,0 +1,959 @@
++/* fos_gfx: palette ramps, dithering, anti-aliased shapes and text.
++ * See fos_gfx.h for the idea. Everything here is integer maths except the
++ * one-time palette build. */
++
++#include "fos_gfx.h"
++#include <string.h>
++
++/* ---------------------------------------------------------------- ramps */
++
++struct ramp_def
++{
++ uint32_t lo, mid, hi; /* near-black, hue, light tint (0xRRGGBB) */
++ int mid_at; /* level of the hue, 0 = straight lo -> hi */
++ int n; /* palette entries */
++};
++
++/* 254 entries in all (index 0 and 255 stay Canon's) */
++static const struct ramp_def ramp_defs[RAMP_COUNT] =
++{
++ [RAMP_GRAY] = { 0x040303, 0, 0xFFFCF6, 0, 86 },
++ [RAMP_METAL] = { 0x050608, 0x878F98, 0xF4F7FA, 150, 22 },
++ [RAMP_AMBER] = { 0x080402, 0xF4A81C, 0xFFF2D2, 185, 24 },
++ [RAMP_RED] = { 0x080202, 0xDF262D, 0xFFD8D4, 150, 18 },
++ [RAMP_ORANGE] = { 0x080302, 0xEA5D1E, 0xFFDEC9, 160, 16 },
++ [RAMP_CRIMSON] = { 0x060102, 0x9C1320, 0xF6C4C8, 120, 16 },
++ [RAMP_GREEN] = { 0x020604, 0x13894B, 0xD0F5DF, 140, 18 },
++ [RAMP_VIOLET] = { 0x040208, 0x5A2D8A, 0xE9DCF7, 120, 16 },
++ [RAMP_BLUE] = { 0x020508, 0x1E77C6, 0xD5EBFF, 150, 16 },
++ [RAMP_LEADER] = { 0x050403, 0x4C3B2E, 0xDCCAB6, 130, 22 },
++};
++
++uint32_t fos_pal[256];
++
++uint8_t fos_ramp_base[RAMP_COUNT];
++uint8_t fos_ramp_last[RAMP_COUNT];
++int fos_ramp_mul[RAMP_COUNT];
++#define ramp_base fos_ramp_base
++#define ramp_mul fos_ramp_mul
++static uint8_t ramp_n[RAMP_COUNT];
++
++uint8_t fos_rev_ramp[256];
++uint16_t fos_rev_lv[256];
++uint8_t fos_luma_tab[256];
++uint8_t fos_chroma_tab[256];
++uint16_t fos_lum2lv[RAMP_COUNT][256];
++#define rev_ramp fos_rev_ramp
++#define rev_lv fos_rev_lv
++#define luma_tab fos_luma_tab
++#define chroma_tab fos_chroma_tab
++#define lum2lv fos_lum2lv
++
++const uint8_t fos_bayer[4][4] =
++{
++ { 0, 8, 2, 10 },
++ { 12, 4, 14, 6 },
++ { 3, 11, 1, 9 },
++ { 15, 7, 13, 5 },
++};
++
++static int chan(uint32_t c, int s) { return (c >> s) & 0xFF; }
++
++static uint32_t lerp_rgb(uint32_t a, uint32_t b, int t, int tmax)
++{
++ uint32_t out = 0;
++ for (int s = 0; s <= 16; s += 8)
++ {
++ int v = chan(a, s) + (chan(b, s) - chan(a, s)) * t / tmax;
++ out |= (uint32_t) fos_clamp(v, 0, 255) << s;
++ }
++ return out;
++}
++
++static int rgb_luma(uint32_t c)
++{
++ return (54 * chan(c, 16) + 183 * chan(c, 8) + 19 * chan(c, 0) + 128) >> 8;
++}
++
++static int rgb_chroma(uint32_t c)
++{
++ int r = chan(c, 16), g = chan(c, 8), b = chan(c, 0);
++ int mx = r > g ? (r > b ? r : b) : (g > b ? g : b);
++ int mn = r < g ? (r < b ? r : b) : (g < b ? g : b);
++ return mx - mn;
++}
++
++FOS_INLINE int ix_near(int ramp, int lv)
++{
++ int n = ramp_n[ramp];
++ int p = ((lv < 0 ? 0 : lv) * ramp_mul[ramp] + (8 << 16)) >> 20;
++ return ramp_base[ramp] + (p >= n ? n - 1 : p);
++}
++
++FOS_INLINE int ix_dith(int ramp, int lv, int x, int y)
++{
++ int n = ramp_n[ramp];
++ int p = (((lv < 0 ? 0 : lv) * ramp_mul[ramp] >> 16) + fos_bayer[y & 3][x & 3]) >> 4;
++ return ramp_base[ramp] + (p >= n ? n - 1 : p);
++}
++
++void fos_gfx_init()
++{
++ int ix = 1;
++ for (int r = 0; r < RAMP_COUNT; r++)
++ {
++ const struct ramp_def *d = &ramp_defs[r];
++ ramp_base[r] = ix;
++ ramp_n[r] = d->n;
++ fos_ramp_last[r] = d->n - 1;
++ ramp_mul[r] = (d->n - 1) * 16 * 65536 / LV_MAX;
++ for (int i = 0; i < d->n; i++, ix++)
++ {
++ int lv = i * 255 / (d->n - 1); /* 0..255 along the ramp */
++ uint32_t c;
++ if (!d->mid_at)
++ c = lerp_rgb(d->lo, d->hi, lv, 255);
++ else if (lv <= d->mid_at)
++ c = lerp_rgb(d->lo, d->mid, lv, d->mid_at);
++ else
++ c = lerp_rgb(d->mid, d->hi, lv - d->mid_at, 255 - d->mid_at);
++ fos_pal[ix] = c;
++ rev_ramp[ix] = r;
++ rev_lv[ix] = i * LV_MAX / (d->n - 1);
++ luma_tab[ix] = rgb_luma(c);
++ chroma_tab[ix] = rgb_chroma(c);
++ }
++ }
++
++ /* Canon's entries (and anything unused) read as black */
++ for (int i = ix; i < 256; i++)
++ rev_ramp[i] = RAMP_GRAY;
++ rev_ramp[0] = RAMP_GRAY;
++
++ /* luminance -> level, per ramp (ramps get lighter monotonically) */
++ for (int r = 0; r < RAMP_COUNT; r++)
++ {
++ int b = ramp_base[r], n = ramp_n[r];
++ int j = 0;
++ for (int l = 0; l < 256; l++)
++ {
++ while (j < n - 2 && luma_tab[b + j + 1] < l)
++ j++;
++ int l0 = luma_tab[b + j], l1 = luma_tab[b + j + 1];
++ int f = l1 > l0 ? fos_clamp((l - l0) * 256 / (l1 - l0), 0, 256) : 0;
++ int lv = (j * 256 + f) * LV_MAX / ((n - 1) * 256);
++ lum2lv[r][l] = fos_clamp(lv, 0, LV_MAX);
++ }
++ }
++}
++
++/* ---------------------------------------------------------------- screen colour */
++
++uint32_t fos_screen_yuv(int ix, int white_y, int std, int sat, int warm, int bright)
++{
++ return fos_screen_yuv_rgb(fos_pal[ix], white_y, std, sat, warm, bright);
++}
++
++uint32_t fos_screen_yuv_rgb(uint32_t rgb, int white_y, int std, int sat, int warm, int bright)
++{
++ int c[3] = { (rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF };
++ /* warmer: more red, less blue, white included */
++ c[0] = fos_clamp(c[0] * (100 + 3 * warm) / 100, 0, 255);
++ c[2] = fos_clamp(c[2] * (100 - 3 * warm) / 100, 0, 255);
++ /* brighter: the mid tones lift, black and white stay */
++ for (int i = 0; i < 3; i++)
++ c[i] = fos_clamp(c[i] + bright * 6 * c[i] * (255 - c[i]) / (100 * 255), 0, 255);
++ int r = c[0], g = c[1], b = c[2];
++ int s = 100 + 6 * sat; /* colour, % */
++ int y, u, v;
++ if (std == 1)
++ {
++ y = (217 * r + 732 * g + 73 * b) / 1024;
++ u = (-117 * r - 394 * g + 512 * b) / 1024;
++ v = (512 * r - 465 * g - 46 * b) / 1024;
++ }
++ else
++ {
++ /* BT.601 Y'CbCr, all of it scaled so white lands on Canon's white:
++ * Canon's own entries on the EOS M decode this way to clean
++ * primaries (dark red 202,0,0; blue 0,0,170; green 0,155,0) */
++ int yf = (299 * r + 587 * g + 114 * b) / 1000;
++ y = yf * white_y / 255;
++ u = (b - yf) * 564 / 1000 * white_y / 255;
++ v = (r - yf) * 713 / 1000 * white_y / 255;
++ }
++ y = fos_clamp(y, 0, 255);
++ u = fos_clamp(u * s / 100, -127, 127);
++ v = fos_clamp(v * s / 100, -127, 127);
++ return (uint32_t) y << 16 | (uint32_t) (u & 0xFF) << 8 | (uint32_t) (v & 0xFF);
++}
++
++uint32_t fos_screen_rgb(uint32_t yuv, int white_y)
++{
++ int y = (yuv >> 16) & 0xFF, u = (int8_t) ((yuv >> 8) & 0xFF), v = (int8_t) (yuv & 0xFF);
++ /* undo the scale, then BT.601 */
++ y = y * 255 / white_y; u = u * 255 / white_y; v = v * 255 / white_y;
++ int r = y + v * 1000 / 713;
++ int b = y + u * 1000 / 564;
++ int g = (1000 * y - 299 * r - 114 * b) / 587;
++ return (uint32_t) fos_clamp(r, 0, 255) << 16 | (uint32_t) fos_clamp(g, 0, 255) << 8 | (uint32_t) fos_clamp(b, 0, 255);
++}
++
++uint8_t fos_ix(fcol c)
++{
++ return ix_near(FC_RAMP(c) % RAMP_COUNT, LV12(FC_LEVEL(c)));
++}
++
++uint8_t fos_ix_dither(int ramp, int lv, int x, int y)
++{
++ return ix_dith(ramp, lv, x, y);
++}
++
++fcol fos_colour_of(uint8_t ix)
++{
++ return FC(rev_ramp[ix], rev_lv[ix] * 255 / LV_MAX);
++}
++
++int fos_luma(uint8_t ix)
++{
++ return luma_tab[ix];
++}
++
++/* the blend of (ramp, lv) over dst at opacity a: within one ramp it is a
++ * level blend; across ramps it keeps the luminance and takes the ramp that
++ * contributes more colour, so amber text on grey gets amber edges and
++ * white text on amber gets light-amber ones */
++static void mix_target(uint8_t dst, int ramp, int lv, int a, int *out_ramp, int *out_lv)
++{
++ int rd = rev_ramp[dst];
++ if (rd == ramp)
++ {
++ *out_ramp = ramp;
++ *out_lv = rev_lv[dst] + (((lv - rev_lv[dst]) * a) >> 8);
++ return;
++ }
++ int src = ix_near(ramp, lv);
++ int ld = luma_tab[dst], ls = luma_tab[src];
++ int l = ld + (((ls - ld) * a) >> 8);
++ int r = chroma_tab[src] * a >= chroma_tab[dst] * (256 - a) ? ramp : rd;
++ *out_ramp = r;
++ *out_lv = lum2lv[r][fos_clamp(l, 0, 255)];
++}
++
++void fos_lerp2(int ra, int la, int rb, int lb, int a, int *ramp, int *lv)
++{
++ if (ra == rb)
++ {
++ *ramp = ra;
++ *lv = la + (((lb - la) * a) >> 8);
++ return;
++ }
++ int ia = ix_near(ra, la), ib = ix_near(rb, lb);
++ int l = luma_tab[ia] + (((luma_tab[ib] - luma_tab[ia]) * a) >> 8);
++ int r = chroma_tab[ib] * a >= chroma_tab[ia] * (256 - a) ? rb : ra;
++ *ramp = r;
++ *lv = lum2lv[r][fos_clamp(l, 0, 255)];
++}
++
++uint8_t fos_mix(uint8_t dst, int ramp, int lv, int a)
++{
++ if (a >= OPAQUE) return ix_near(ramp, lv);
++ if (a <= 0) return dst;
++ int r, l;
++ mix_target(dst, ramp, lv, a, &r, &l);
++ return ix_near(r, l);
++}
++
++uint8_t fos_mix_dither(uint8_t dst, int ramp, int lv, int a, int x, int y)
++{
++ if (a >= OPAQUE) return ix_dith(ramp, lv, x, y);
++ if (a <= 0) return dst;
++ int r, l;
++ mix_target(dst, ramp, lv, a, &r, &l);
++ return ix_dith(r, l, x, y);
++}
++
++/* ---------------------------------------------------------------- maths */
++
++int fos_isqrt(unsigned int v)
++{
++ if (!v) return 0;
++ unsigned int r = 0, bit = 1u << ((31 - __builtin_clz(v)) & ~1);
++ while (bit)
++ {
++ if (v >= r + bit) { v -= r + bit; r = (r >> 1) + bit; }
++ else r >>= 1;
++ bit >>= 2;
++ }
++ return r;
++}
++
++/* quarter-wave sine, 4096 = 1.0 */
++static const int16_t sin_q[65] =
++{
++ 0, 101, 201, 301, 401, 501, 601, 700, 799, 897, 995, 1092, 1189, 1285, 1380, 1474,
++ 1567, 1660, 1751, 1842, 1931, 2019, 2106, 2191, 2276, 2359, 2440, 2520, 2598, 2675, 2751, 2824,
++ 2896, 2967, 3035, 3102, 3166, 3229, 3290, 3349, 3406, 3461, 3513, 3564, 3612, 3659, 3703, 3745,
++ 3784, 3822, 3857, 3889, 3920, 3948, 3973, 3996, 4017, 4036, 4052, 4065, 4076, 4085, 4091, 4095,
++ 4096,
++};
++
++int fos_sin(int a)
++{
++ a &= 0xFFFF;
++ int q = a >> 14; /* quadrant */
++ int t = a & 0x3FFF; /* 0..16383 within it */
++ if (q & 1) t = 0x4000 - t;
++ int i = t >> 8, f = t & 0xFF;
++ int v = i >= 64 ? 4096 : sin_q[i] + (((sin_q[i + 1] - sin_q[i]) * f) >> 8);
++ return q & 2 ? -v : v;
++}
++
++int fos_cos(int a)
++{
++ return fos_sin(a + 0x4000);
++}
++
++/* ---------------------------------------------------------------- canvas */
++
++void fos_canvas_init(struct fos_canvas *cv, uint8_t *px, int pitch, int w, int h)
++{
++ cv->px = px;
++ cv->pitch = pitch;
++ cv->w = w;
++ cv->h = h;
++ fos_noclip(cv);
++}
++
++void fos_noclip(struct fos_canvas *cv)
++{
++ cv->cx0 = 0; cv->cy0 = 0; cv->cx1 = cv->w; cv->cy1 = cv->h;
++}
++
++void fos_clip(struct fos_canvas *cv, int x0, int y0, int x1, int y1)
++{
++ cv->cx0 = fos_clamp(x0, 0, cv->w);
++ cv->cy0 = fos_clamp(y0, 0, cv->h);
++ cv->cx1 = fos_clamp(x1, cv->cx0, cv->w);
++ cv->cy1 = fos_clamp(y1, cv->cy0, cv->h);
++}
++
++/* clip a rectangle; returns 0 if nothing is left */
++static int clip_rect(const struct fos_canvas *cv, int *x, int *y, int *w, int *h)
++{
++ int x0 = *x, y0 = *y, x1 = *x + *w, y1 = *y + *h;
++ if (x0 < cv->cx0) x0 = cv->cx0;
++ if (y0 < cv->cy0) y0 = cv->cy0;
++ if (x1 > cv->cx1) x1 = cv->cx1;
++ if (y1 > cv->cy1) y1 = cv->cy1;
++ if (x1 <= x0 || y1 <= y0) return 0;
++ *x = x0; *y = y0; *w = x1 - x0; *h = y1 - y0;
++ return 1;
++}
++
++#define PX(cv, x, y) ((cv)->px[(y) * (cv)->pitch + (x)])
++
++void fos_fill_ix(struct fos_canvas *cv, int x, int y, int w, int h, uint8_t ix)
++{
++ if (!clip_rect(cv, &x, &y, &w, &h)) return;
++ uint32_t word = ix * 0x01010101u;
++ for (int j = 0; j < h; j++)
++ {
++ uint8_t *p = &PX(cv, x, y + j);
++ int n = w;
++ while (n && ((uintptr_t) p & 3)) { *p++ = ix; n--; }
++ while (n >= 4) { *(uint32_t *) p = word; p += 4; n -= 4; }
++ while (n--) *p++ = ix;
++ }
++}
++
++void fos_fill(struct fos_canvas *cv, int x, int y, int w, int h, fcol c)
++{
++ fos_fill_ix(cv, x, y, w, h, fos_ix(c));
++}
++
++void fos_blend(struct fos_canvas *cv, int x, int y, int w, int h, fcol c, int alpha)
++{
++ if (alpha >= OPAQUE) { fos_fill(cv, x, y, w, h, c); return; }
++ if (alpha <= 0 || !clip_rect(cv, &x, &y, &w, &h)) return;
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ for (int j = y; j < y + h; j++)
++ for (int i = x; i < x + w; i++)
++ PX(cv, i, j) = fos_mix_dither(PX(cv, i, j), ramp, lv, alpha, i, j);
++}
++
++void fos_scale_levels(struct fos_canvas *cv, int x, int y, int w, int h, int k)
++{
++ if (!clip_rect(cv, &x, &y, &w, &h)) return;
++ /* every index, darkened, for the four pixels of a 2 x 2 dither */
++ uint8_t lut[4][256];
++ for (int ph = 0; ph < 4; ph++)
++ for (int i = 0; i < 256; i++)
++ lut[ph][i] = ix_dith(rev_ramp[i], (rev_lv[i] * k) >> 8, ph & 1, ph >> 1);
++ for (int j = y; j < y + h; j++)
++ {
++ uint8_t *p = &PX(cv, x, j);
++ int n = w, i = x;
++ for (; n && ((uintptr_t) p & 3); n--, p++, i++)
++ *p = lut[(j & 1) * 2 + (i & 1)][*p];
++ const uint8_t *l0 = lut[(j & 1) * 2 + (i & 1)], *l1 = lut[(j & 1) * 2 + ((i + 1) & 1)];
++ for (; n >= 4; n -= 4, p += 4, i += 4)
++ {
++ uint32_t v = *(uint32_t *) p;
++ *(uint32_t *) p = l0[v & 0xFF] | l1[(v >> 8) & 0xFF] << 8 | l0[(v >> 16) & 0xFF] << 16 | (uint32_t) l1[v >> 24] << 24;
++ }
++ for (; n; n--, p++, i++)
++ *p = lut[(j & 1) * 2 + (i & 1)][*p];
++ }
++}
++
++void fos_vgrad(struct fos_canvas *cv, int x, int y, int w, int h, int ramp, int lv0, int lv1)
++{
++ int y_top = y, h_all = h;
++ if (h_all <= 0 || !clip_rect(cv, &x, &y, &w, &h)) return;
++ int base = ramp_base[ramp], last = ramp_n[ramp] - 1;
++ for (int j = y; j < y + h; j++)
++ {
++ int lv = lv0 + (lv1 - lv0) * (j - y_top) / (h_all > 1 ? h_all - 1 : 1);
++ int pos = ((lv < 0 ? 0 : lv) * ramp_mul[ramp]) >> 16;
++ /* the four dithered indices of this row */
++ uint8_t ix[4];
++ for (int k = 0; k < 4; k++)
++ {
++ int q = (pos + fos_bayer[j & 3][k]) >> 4;
++ ix[k] = base + (q > last ? last : q);
++ }
++ uint8_t *p = &PX(cv, x, j);
++ for (int i = x; i < x + w; i++)
++ *p++ = ix[i & 3];
++ }
++}
++
++/* ---------------------------------------------------------------- AA shapes */
++
++FOS_INLINE void put_cov(struct fos_canvas *cv, int x, int y, int ramp, int lv, int ix_solid, int cov, int alpha)
++{
++ if (cov <= 0) return;
++ int a = cov >= 256 ? alpha : (cov * alpha) >> 8;
++ if (a >= OPAQUE) PX(cv, x, y) = ix_solid;
++ else if (a > 0) PX(cv, x, y) = fos_mix(PX(cv, x, y), ramp, lv, a);
++}
++
++/* pixels x0..x1-1 of row y fully covered */
++static void put_run(struct fos_canvas *cv, int x0, int x1, int y, int ramp, int lv, int ix_solid, int alpha)
++{
++ if (x1 <= x0) return;
++ uint8_t *p = &PX(cv, x0, y);
++ if (alpha >= OPAQUE) { memset(p, ix_solid, x1 - x0); return; }
++ if (alpha <= 0) return;
++ for (int x = x0; x < x1; x++, p++)
++ *p = fos_mix(*p, ramp, lv, alpha);
++}
++
++/* coverage (0..256) of pixel (i, j) in a w x h rounded rect at the origin */
++static int rrect_cov(int i, int j, int w, int h, int r)
++{
++ if (i < 0 || j < 0 || i >= w || j >= h) return 0;
++ int cx, cy;
++ if (i < r) cx = r; else if (i >= w - r) cx = w - r; else return 256;
++ if (j < r) cy = r; else if (j >= h - r) cy = h - r; else return 256;
++ /* distance from the pixel centre to the corner circle centre, 1/16 px */
++ int dx = (i * 16 + 8) - cx * 16;
++ int dy = (j * 16 + 8) - cy * 16;
++ if ((i < r && dx > 0) || (i >= w - r && dx < 0)) dx = 0;
++ if ((j < r && dy > 0) || (j >= h - r && dy < 0)) dy = 0;
++ int d = fos_isqrt(dx * dx + dy * dy) - r * 16; /* 1/16 px, + outside */
++ return fos_clamp(128 - d * 16, 0, 256);
++}
++
++void fos_rrect(struct fos_canvas *cv, int x, int y, int w, int h, int r, fcol c, int alpha)
++{
++ if (w <= 0 || h <= 0) return;
++ r = fos_clamp(r, 0, (w < h ? w : h) / 2);
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++ /* straight middle band in one go */
++ if (alpha >= OPAQUE)
++ fos_fill_ix(cv, x, y + r, w, h - 2 * r, solid);
++ else
++ fos_blend(cv, x, y + r, w, h - 2 * r, c, alpha);
++ for (int j = 0; j < h; j++)
++ {
++ if (j >= r && j < h - r) continue;
++ int py = y + j;
++ if (py < cv->cy0 || py >= cv->cy1) continue;
++ /* the corners, then the straight part between them in one run */
++ for (int i = 0; i < w; i++)
++ {
++ if (i == r && w - r > r)
++ {
++ put_run(cv, fos_clamp(x + r, cv->cx0, cv->cx1), fos_clamp(x + w - r, cv->cx0, cv->cx1),
++ py, ramp, lv, solid, alpha);
++ i = w - r - 1;
++ continue;
++ }
++ int px = x + i;
++ if (px < cv->cx0 || px >= cv->cx1) continue;
++ put_cov(cv, px, py, ramp, lv, solid, rrect_cov(i, j, w, h, r), alpha);
++ }
++ }
++}
++
++void fos_rrect_line(struct fos_canvas *cv, int x, int y, int w, int h, int r, int t, fcol c, int alpha)
++{
++ if (w <= 0 || h <= 0 || t <= 0) return;
++ r = fos_clamp(r, 0, (w < h ? w : h) / 2);
++ int ri = r > t ? r - t : 0;
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++ for (int j = 0; j < h; j++)
++ {
++ int py = y + j;
++ if (py < cv->cy0 || py >= cv->cy1) continue;
++ int inner_row = j >= t + ri && j < h - t - ri;
++ int border_row = j < t || j >= h - t; /* straight top / bottom edge */
++ int cut = r > t ? r : t;
++ for (int i = 0; i < w; i++)
++ {
++ if (inner_row && i >= t && i < w - t) { i = w - t - 1; continue; }
++ if (!inner_row && i == cut && w - cut > cut)
++ {
++ /* between the corners the border is solid or empty */
++ if (border_row)
++ put_run(cv, fos_clamp(x + cut, cv->cx0, cv->cx1), fos_clamp(x + w - cut, cv->cx0, cv->cx1),
++ py, ramp, lv, solid, alpha);
++ i = w - cut - 1;
++ continue;
++ }
++ int px = x + i;
++ if (px < cv->cx0 || px >= cv->cx1) continue;
++ int cov = rrect_cov(i, j, w, h, r) - rrect_cov(i - t, j - t, w - 2 * t, h - 2 * t, ri);
++ put_cov(cv, px, py, ramp, lv, solid, cov, alpha);
++ }
++ }
++}
++
++/* distance (1/16 px, + outside) of a pixel at squared distance d2 (1/16 px)
++ * from a circle of radius r16: near the edge of a big circle the square
++ * root is as good as linear, d = (d2 - r^2) / 2r */
++FOS_INLINE int circle_d(int d2, int r16, int inv2r)
++{
++ if (inv2r) return ((d2 - r16 * r16) * inv2r) >> 16;
++ return fos_isqrt((unsigned) d2) - r16;
++}
++
++/* inv2r for circle_d, or 0 when the circle is too small to approximate */
++static int circle_inv(int r16)
++{
++ return r16 >= 16 * 12 ? 65536 / (2 * r16) : 0;
++}
++
++void fos_disc(struct fos_canvas *cv, int cx8, int cy8, int r8, fcol c, int alpha)
++{
++ if (r8 <= 0) return;
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++ int r16 = r8 >> 4, inv2r = circle_inv(r16);
++ int y0 = (cy8 - r8) >> 8, y1 = (cy8 + r8 + 255) >> 8;
++ int x0 = (cx8 - r8) >> 8, x1 = (cx8 + r8 + 255) >> 8;
++ y0 = fos_clamp(y0, cv->cy0, cv->cy1); y1 = fos_clamp(y1, cv->cy0, cv->cy1);
++ x0 = fos_clamp(x0, cv->cx0, cv->cx1); x1 = fos_clamp(x1, cv->cx0, cv->cx1);
++ for (int y = y0; y < y1; y++)
++ {
++ int dy = ((y * 256 + 128) - cy8) >> 4;
++ int cx16 = cx8 >> 4;
++ /* pixels whose centre is half a pixel inside the edge are solid */
++ int in = r16 - 8;
++ int half = in > 0 && in * in > dy * dy ? fos_isqrt(in * in - dy * dy) : -1;
++ int sx0 = half >= 0 ? (cx16 - half - 8 + 15) >> 4 : x1;
++ int sx1 = half >= 0 ? (cx16 + half - 8) >> 4 : x0 - 1;
++ int s0 = fos_clamp(sx0, x0, x1), s1 = fos_clamp(sx1 + 1, s0, x1);
++ /* nothing beyond half a pixel outside the edge */
++ int out = r16 + 8;
++ if (out * out <= dy * dy) continue;
++ int ohalf = fos_isqrt(out * out - dy * dy);
++ int xa = fos_clamp(((cx16 - ohalf - 8) >> 4) - 1, x0, x1), xb = fos_clamp(((cx16 + ohalf - 8) >> 4) + 2, xa, x1);
++ for (int x = xa; x < xb; x++)
++ {
++ if (x == s0 && s1 > s0)
++ {
++ put_run(cv, s0, s1, y, ramp, lv, solid, alpha);
++ x = s1 - 1;
++ continue;
++ }
++ int dx = ((x * 256 + 128) - cx8) >> 4;
++ int d = circle_d(dx * dx + dy * dy, r16, inv2r);
++ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - d * 16, 0, 256), alpha);
++ }
++ }
++}
++
++void fos_ring(struct fos_canvas *cv, int cx8, int cy8, int r8, int t8, fcol c, int alpha)
++{
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++ int ro = r8 + t8 / 2 + 256;
++ int y0 = fos_clamp((cy8 - ro) >> 8, cv->cy0, cv->cy1), y1 = fos_clamp((cy8 + ro + 255) >> 8, cv->cy0, cv->cy1);
++ int x0 = fos_clamp((cx8 - ro) >> 8, cv->cx0, cv->cx1), x1 = fos_clamp((cx8 + ro + 255) >> 8, cv->cx0, cv->cx1);
++ int r16 = r8 >> 4, h16 = t8 >> 5, inv2r = circle_inv(r16);
++ int inner = r16 - h16 - 16, outer = r16 + h16 + 16; /* nothing inside / beyond these */
++ for (int y = y0; y < y1; y++)
++ {
++ int dy = ((y * 256 + 128) - cy8) >> 4;
++ if (dy * dy >= outer * outer) continue;
++ int ox = fos_isqrt(outer * outer - dy * dy);
++ int ix = inner > 0 && dy * dy < inner * inner ? fos_isqrt(inner * inner - dy * dy) : -1;
++ int xa = fos_clamp(((cx8 - ox * 16) >> 8) - 1, x0, x1), xb = fos_clamp(((cx8 + ox * 16) >> 8) + 2, x0, x1);
++ for (int x = xa; x < xb; x++)
++ {
++ int dx = ((x * 256 + 128) - cx8) >> 4;
++ if (ix > 0 && dx > -ix && dx < ix)
++ {
++ /* across the hole */
++ x = fos_clamp(((cx8 + ix * 16 - 128 + 255) >> 8) - 1, x, xb);
++ continue;
++ }
++ int d = circle_d(dx * dx + dy * dy, r16, inv2r);
++ if (d < 0) d = -d;
++ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - (d - h16) * 16, 0, 256), alpha);
++ }
++ }
++}
++
++void fos_line(struct fos_canvas *cv, int x0_8, int y0_8, int x1_8, int y1_8, int w8, fcol c, int alpha)
++{
++ /* a thin quad: the segment pushed out by half the width both ways */
++ int dx = (x1_8 - x0_8) >> 4, dy = (y1_8 - y0_8) >> 4;
++ int len = fos_isqrt((unsigned) (dx * dx + dy * dy));
++ if (!len) return;
++ int ox = -dy * (w8 / 2) / len, oy = dx * (w8 / 2) / len;
++ int q[8] = { x0_8 + ox, y0_8 + oy, x1_8 + ox, y1_8 + oy, x1_8 - ox, y1_8 - oy, x0_8 - ox, y0_8 - oy };
++ fos_convex(cv, q, 4, c, alpha);
++}
++
++/* convex polygon, vertices in 1/256 px, either winding */
++#define MAX_POLY 12
++void fos_convex(struct fos_canvas *cv, const int *xy8, int n, fcol c, int alpha)
++{
++ if (n < 3 || n > MAX_POLY) return;
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++
++ /* signed area tells the winding, so normals can point outwards */
++ int64_t area = 0;
++ for (int i = 0; i < n; i++)
++ {
++ int j = (i + 1) % n;
++ area += (int64_t) xy8[2 * i] * xy8[2 * j + 1] - (int64_t) xy8[2 * j] * xy8[2 * i + 1];
++ }
++ int sgn = area > 0 ? 1 : -1;
++
++ /* edge lines: nx * x + ny * y - c, unit normal in 1/4096, distance in 1/256 px;
++ * inv = 2^24 / nx turns "where does this edge cross" into a multiply */
++ int nx[MAX_POLY], ny[MAX_POLY], nc[MAX_POLY], inv[MAX_POLY];
++ int ymin = 1 << 30, ymax = -(1 << 30), xmin = 1 << 30, xmax = -(1 << 30);
++ for (int i = 0; i < n; i++)
++ {
++ int j = (i + 1) % n;
++ int ex = xy8[2 * j] - xy8[2 * i], ey = xy8[2 * j + 1] - xy8[2 * i + 1];
++ /* length in 1/16 px; long edges (the shutter blades) measured coarser so
++ * the squares fit */
++ int sh = ((ex < 0 ? -ex : ex) | (ey < 0 ? -ey : ey)) >= (1 << 19) ? 7 : 4;
++ int len = fos_isqrt((unsigned) ((ex >> sh) * (ex >> sh) + (ey >> sh) * (ey >> sh))) << (sh - 4);
++ if (!len) len = 1;
++ nx[i] = sgn * (ey >> 4) * 4096 / len;
++ ny[i] = -sgn * (ex >> 4) * 4096 / len;
++ nc[i] = (int) (((int64_t) nx[i] * xy8[2 * i] + (int64_t) ny[i] * xy8[2 * i + 1]) >> 12);
++ inv[i] = nx[i] ? (1 << 24) / nx[i] : 0;
++ if (xy8[2 * i + 1] < ymin) ymin = xy8[2 * i + 1];
++ if (xy8[2 * i + 1] > ymax) ymax = xy8[2 * i + 1];
++ if (xy8[2 * i] < xmin) xmin = xy8[2 * i];
++ if (xy8[2 * i] > xmax) xmax = xy8[2 * i];
++ }
++ int py0 = fos_clamp((ymin >> 8) - 1, cv->cy0, cv->cy1), py1 = fos_clamp((ymax >> 8) + 2, cv->cy0, cv->cy1);
++ int px0 = fos_clamp((xmin >> 8) - 1, cv->cx0, cv->cx1), px1 = fos_clamp((xmax >> 8) + 2, cv->cx0, cv->cx1);
++
++ for (int y = py0; y < py1; y++)
++ {
++ int yc = y * 256 + 128;
++ /* [in0, in1]: every edge at least half a pixel inside (solid);
++ * [out0, out1]: no edge more than half a pixel outside */
++ int in0 = px0 * 256, in1 = px1 * 256, out0 = px0 * 256, out1 = px1 * 256;
++ int empty = 0, nosolid = 0;
++ for (int i = 0; i < n; i++)
++ {
++ /* d(x) = nx * x / 4096 + base (1/256 px) */
++ int base = (int) (((int64_t) ny[i] * yc) >> 12) - nc[i];
++ if (!nx[i])
++ {
++ if (base > 128) empty = 1;
++ if (base > -128) nosolid = 1;
++ continue;
++ }
++ int xa = (int) (((int64_t) (-128 - base) * inv[i]) >> 12);
++ int xb = (int) (((int64_t) (128 - base) * inv[i]) >> 12);
++ if (nx[i] > 0) { if (xa < in1) in1 = xa; if (xb < out1) out1 = xb; }
++ else { if (xa > in0) in0 = xa; if (xb > out0) out0 = xb; }
++ }
++ if (empty || out1 < out0) continue;
++ if (nosolid) in1 = in0 - 1;
++ int sx0 = fos_clamp((out0 >> 8) - 1, px0, px1), sx1 = fos_clamp((out1 >> 8) + 2, px0, px1);
++ /* whole pixels at least half a pixel inside every edge: one run */
++ int s0 = sx1, s1 = sx1;
++ if (in1 > in0)
++ {
++ s0 = fos_clamp((in0 + 255) >> 8, sx0, sx1);
++ s1 = fos_clamp(in1 >> 8, s0, sx1);
++ }
++ for (int x = sx0; x < sx1; x++)
++ {
++ int xc = x * 256 + 128;
++ if (x == s0 && s1 > s0)
++ {
++ put_run(cv, s0, s1, y, ramp, lv, solid, alpha);
++ x = s1 - 1;
++ continue;
++ }
++ /* pixel centres are on the canvas, so this fits in 32 bits */
++ int dmax = -(1 << 30);
++ for (int i = 0; i < n; i++)
++ {
++ int d = ((nx[i] * xc + ny[i] * yc) >> 12) - nc[i];
++ if (d > dmax) dmax = d;
++ }
++ put_cov(cv, x, y, ramp, lv, solid, fos_clamp(128 - dmax, 0, 256), alpha);
++ }
++ }
++}
++
++void fos_tri(struct fos_canvas *cv, int cx, int cy, int size, int dir, fcol c, int alpha)
++{
++ /* an arrow head pointing right, rotated by dir quarter turns */
++ static const int base[6] = { 1, 0, -1, -1, -1, 1 };
++ int pts[6];
++ for (int i = 0; i < 3; i++)
++ {
++ int x = base[2 * i], y = base[2 * i + 1];
++ for (int k = 0; k < dir; k++) { int t = x; x = -y; y = t; }
++ pts[2 * i] = cx * 256 + 128 + x * size * 128;
++ pts[2 * i + 1] = cy * 256 + 128 + y * size * 128;
++ }
++ fos_convex(cv, pts, 3, c, alpha);
++}
++
++/* ---------------------------------------------------------------- text */
++
++/* ---- the fonts, from the card */
++
++#define FONT_DEF(n) struct fos_font fos_font_##n;
++FOS_FONTS(FONT_DEF)
++#define FONT_SLOT(n) &fos_font_##n,
++static struct fos_font *const font_slots[] = { FOS_FONTS(FONT_SLOT) };
++#define NFONTS ((int) (sizeof(font_slots) / sizeof(font_slots[0])))
++static int fonts_ready;
++
++static uint32_t get32(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (uint32_t) p[3] << 24; }
++
++/* "FOSF", version 1, the number of fonts; each font: bits, glyphs, kerning
++ * pairs, ascent, descent (u32), then its bits, glyphs, lut and kerning,
++ * each part starting on 4 bytes */
++int fos_fonts_load(const uint8_t *b, int size)
++{
++ fonts_ready = 0;
++ if (!b || size < 12 || memcmp(b, "FOSF", 4) || get32(b + 4) != 1 || (int) get32(b + 8) != NFONTS
++ || sizeof(struct fos_glyph) != 8 || sizeof(struct fos_kern) != 3)
++ return 0;
++ int at = 12;
++ for (int i = 0; i < NFONTS; i++)
++ {
++ if (at + 20 > size) return 0;
++ uint32_t nbits = get32(b + at), nglyphs = get32(b + at + 4), nkern = get32(b + at + 8);
++ int asc = (int) get32(b + at + 12), desc = (int) get32(b + at + 16);
++ at += 20;
++ uint32_t need = ((nbits + 3) & ~3u) + nglyphs * 8 + 256 + ((nkern * 3 + 3) & ~3u);
++ if (nbits > (uint32_t) size || nglyphs > 256 || nkern > 65536 || (uint32_t) (size - at) < need) return 0;
++ struct fos_font *f = font_slots[i];
++ f->bits = b + at; at += (nbits + 3) & ~3u;
++ f->glyphs = (const struct fos_glyph *) (b + at); at += nglyphs * 8;
++ f->lut = b + at; at += 256;
++ f->kern = nkern ? (const struct fos_kern *) (b + at) : 0;
++ at += (nkern * 3 + 3) & ~3u;
++ f->nkern = (int) nkern;
++ f->ascent = asc;
++ f->descent = desc;
++ /* every glyph the lut names must exist */
++ for (int c = 0; c < 256; c++)
++ if (f->lut[c] != 0xFF && f->lut[c] >= nglyphs) { memset(f, 0, sizeof(*f)); return 0; }
++ }
++ fonts_ready = 1;
++ return 1;
++}
++
++int fos_fonts_ready()
++{
++ return fonts_ready;
++}
++
++static const struct fos_glyph *glyph_of(const struct fos_font *f, int ch)
++{
++ if (!f->lut) return 0; /* not loaded */
++ int i = f->lut[ch & 0xFF];
++ return i == 0xFF ? 0 : &f->glyphs[i];
++}
++
++static int kern_of(const struct fos_font *f, int a, int b)
++{
++ int lo = 0, hi = f->nkern - 1;
++ int key = a << 8 | b;
++ while (lo <= hi)
++ {
++ int mid = (lo + hi) / 2;
++ int k = f->kern[mid].a << 8 | f->kern[mid].b;
++ if (k == key) return f->kern[mid].k;
++ if (k < key) lo = mid + 1; else hi = mid - 1;
++ }
++ return 0;
++}
++
++static void draw_glyph(struct fos_canvas *cv, const struct fos_font *f, const struct fos_glyph *g,
++ int x, int y, int ramp, int lv, int solid, int alpha)
++{
++ int gx = x + g->ox, gy = y + g->oy;
++ int w = g->w, h = g->h;
++ if (!w || !h) return;
++ if (gx >= cv->cx1 || gy >= cv->cy1 || gx + w <= cv->cx0 || gy + h <= cv->cy0) return;
++
++ const uint8_t *p = f->bits + g->off;
++ int col = 0, row = 0;
++ int inside = gx >= cv->cx0 && gx + w <= cv->cx1 && gy >= cv->cy0 && gy + h <= cv->cy1;
++ int memo_dst = -1, memo_a = -1, memo_out = 0;
++ while (row < h)
++ {
++ int b = *p++;
++ int run, v;
++ if (b & 0x80) { run = (b & 0x7F) + 1; v = 0; }
++ else { run = (b >> 4) + 1; v = b & 15; }
++ if (!v)
++ {
++ col += run;
++ while (col >= w) { col -= w; row++; }
++ continue;
++ }
++ int a = v == 15 ? alpha : (v * 17 * alpha) >> 8;
++ if (inside)
++ {
++ /* runs never pass the end of the bitmap, but may wrap rows */
++ uint8_t *q = &PX(cv, gx + col, gy + row);
++ if (a >= OPAQUE)
++ while (run--)
++ {
++ *q++ = solid;
++ if (++col == w) { col = 0; row++; q = &PX(cv, gx, gy + row); }
++ }
++ else
++ while (run--)
++ {
++ /* the backdrop is a couple of dithered indices: remember the last blend */
++ if (*q != memo_dst || a != memo_a)
++ {
++ memo_dst = *q; memo_a = a;
++ memo_out = fos_mix(*q, ramp, lv, a);
++ }
++ *q++ = memo_out;
++ if (++col == w) { col = 0; row++; q = &PX(cv, gx, gy + row); }
++ }
++ continue;
++ }
++ while (run--)
++ {
++ int px = gx + col, py = gy + row;
++ if (px >= cv->cx0 && px < cv->cx1 && py >= cv->cy0 && py < cv->cy1)
++ {
++ if (a >= OPAQUE) PX(cv, px, py) = solid;
++ else PX(cv, px, py) = fos_mix(PX(cv, px, py), ramp, lv, a);
++ }
++ if (++col == w) { col = 0; row++; }
++ }
++ }
++}
++
++int fos_text_w(const struct fos_font *f, const char *s, int track)
++{
++ int pen = 0, prev = 0;
++ for (; *s; s++)
++ {
++ int ch = (uint8_t) *s;
++ const struct fos_glyph *g = glyph_of(f, ch);
++ if (!g) continue;
++ if (prev) pen += kern_of(f, prev, ch) + track;
++ pen += g->adv;
++ prev = ch;
++ }
++ return (pen + 8) >> 4;
++}
++
++int fos_text(struct fos_canvas *cv, const struct fos_font *f, int x, int y, const char *s, fcol c, int alpha, int track)
++{
++ if (alpha <= 0) return fos_text_w(f, s, track);
++ int ramp = FC_RAMP(c), lv = LV12(FC_LEVEL(c));
++ int solid = fos_ix(c);
++ int pen = x * 16, prev = 0;
++ for (; *s; s++)
++ {
++ int ch = (uint8_t) *s;
++ const struct fos_glyph *g = glyph_of(f, ch);
++ if (!g) continue;
++ if (prev) pen += kern_of(f, prev, ch) + track;
++ draw_glyph(cv, f, g, (pen + 8) >> 4, y, ramp, lv, solid, alpha);
++ pen += g->adv;
++ prev = ch;
++ }
++ return ((pen + 8) >> 4) - x;
++}
++
++int fos_text_c(struct fos_canvas *cv, const struct fos_font *f, int cx, int y, const char *s, fcol c, int alpha, int track)
++{
++ int w = fos_text_w(f, s, track);
++ fos_text(cv, f, cx - w / 2, y, s, c, alpha, track);
++ return w;
++}
++
++int fos_text_r(struct fos_canvas *cv, const struct fos_font *f, int rx, int y, const char *s, fcol c, int alpha, int track)
++{
++ int w = fos_text_w(f, s, track);
++ fos_text(cv, f, rx - w, y, s, c, alpha, track);
++ return w;
++}
++
++int fos_text_map(uint8_t *px, int pitch, int w, int h, const struct fos_font *f, int x, int y,
++ const char *s, const uint8_t map[16], int track)
++{
++ int pen = x * 16, prev = 0;
++ for (; *s; s++)
++ {
++ int ch = (uint8_t) *s;
++ const struct fos_glyph *g = glyph_of(f, ch);
++ if (!g) continue;
++ if (prev) pen += kern_of(f, prev, ch) + track;
++ int gx = ((pen + 8) >> 4) + g->ox, gy = y + g->oy;
++ const uint8_t *p = f->bits + g->off;
++ int col = 0, row = 0;
++ while (row < g->h)
++ {
++ int b = *p++;
++ int run, v;
++ if (b & 0x80) { run = (b & 0x7F) + 1; v = 0; }
++ else { run = (b >> 4) + 1; v = b & 15; }
++ while (run--)
++ {
++ int qx = gx + col, qy = gy + row;
++ if (v && map[v] && qx >= 0 && qx < w && qy >= 0 && qy < h)
++ px[qy * pitch + qx] = map[v];
++ if (++col == g->w) { col = 0; row++; }
++ }
++ }
++ pen += g->adv;
++ prev = ch;
++ }
++ return ((pen + 8) >> 4) - x;
++}
+diff --git a/src/fos_gfx.h b/src/fos_gfx.h
+new file mode 100644
+index 000000000..22d1f64ea
+--- /dev/null
++++ b/src/fos_gfx.h
+@@ -0,0 +1,216 @@
++/* fos_gfx: drawing for the film OS.
++ *
++ * The screen is the EOS M 8-bit bitmap overlay. Our palette is a set of
++ * tone ramps, each running from near-black through a hue to a light tint,
++ * so every colour is "a ramp and a level along it". Shading, gradients,
++ * fades and anti-aliasing all become level changes, and ordered dithering
++ * between neighbouring ramp entries keeps them smooth with 254 colours.
++ *
++ * Plain C, no ML headers: the same code runs on the camera and in the
++ * simulator (sim/).
++ */
++
++#ifndef _fos_gfx_h_
++#define _fos_gfx_h_
++
++#include <stdint.h>
++
++/* the camera build warns (and fails) when gcc declines an inline at -Os,
++ * so the few hot helpers are forced */
++#define FOS_INLINE static inline __attribute__((always_inline))
++
++#define FOS_W 720
++#define FOS_H 480
++
++enum
++{
++ RAMP_GRAY, /* warm neutral, also black and white ink */
++ RAMP_METAL, /* cool steel for canister caps */
++ RAMP_AMBER, /* UI accent and Kodak yellow */
++ RAMP_RED,
++ RAMP_ORANGE,
++ RAMP_CRIMSON,
++ RAMP_GREEN,
++ RAMP_VIOLET,
++ RAMP_BLUE,
++ RAMP_LEADER, /* unprocessed film base */
++ RAMP_COUNT
++};
++
++/* a colour: ramp in the high byte, level 0..255 in the low byte */
++typedef uint16_t fcol;
++#define FC(ramp, level) ((fcol) (((ramp) << 8) | (level)))
++#define FC_RAMP(c) ((c) >> 8)
++#define FC_LEVEL(c) ((c) & 0xFF)
++
++/* shading works with 12-bit levels */
++#define LV_MAX 4095
++#define LV12(level8) ((level8) * 4095 / 255)
++
++/* opacity 0..256 */
++#define OPAQUE 256
++
++/* palette index 0 is Canon's transparent entry: LiveView shows through */
++#define IX_CLEAR 0
++
++struct fos_canvas
++{
++ uint8_t *px;
++ int pitch;
++ int w, h;
++ int cx0, cy0, cx1, cy1; /* clip rectangle, cx1 / cy1 exclusive */
++};
++
++struct fos_glyph { uint16_t off; uint8_t w, h; int8_t ox, oy; uint16_t adv; };
++struct fos_kern { uint8_t a, b; int8_t k; };
++
++struct fos_font
++{
++ const uint8_t *bits; /* run-length coded 4-bit coverage */
++ const struct fos_glyph *glyphs;
++ const uint8_t *lut; /* byte -> glyph, 0xFF = none */
++ const struct fos_kern *kern; /* sorted by (a, b), 1/16 px */
++ int nkern;
++ int ascent, descent;
++};
++
++/* The fonts live in a file on the card (ML/DATA/FOSFONT.BIN, made from
++ * fos_font.c by tools/fontblob.c), not in autoexec.bin: on the EOS M every
++ * byte of autoexec.bin is taken from Canon's own memory at boot, and too
++ * much stops the camera from starting. Until fos_fonts_load succeeds,
++ * text draws nothing. */
++extern struct fos_font fos_font_xs, fos_font_sm, fos_font_md, fos_font_mdb,
++ fos_font_lg, fos_font_xl, fos_font_num,
++ fos_font_lbig, fos_font_lname, fos_font_lsm;
++#define FOS_FONT_FILE "FOSFONT.BIN"
++#define FOS_FONTS(X) X(xs) X(sm) X(md) X(mdb) X(lg) X(xl) X(num) X(lbig) X(lname) X(lsm) /* the file's order */
++/* blob: the file's contents, kept for as long as the fonts are used;
++ * 1 when it holds every font */
++int fos_fonts_load(const uint8_t *blob, int size);
++int fos_fonts_ready();
++
++/* characters beyond ASCII in our strings (see tools/mkfont.py) */
++#define T_DOT "\x80" /* middle dot */
++#define T_DEG "\x81"
++#define T_TIMES "\x82"
++#define T_NDASH "\x83"
++#define T_MDASH "\x84"
++#define T_APOS "\x85"
++#define T_ELLIPSIS "\x86"
++#define T_BULLET "\x87"
++#define T_LSAQUO "\x88" /* single angle quotes */
++#define T_RSAQUO "\x89"
++
++/* 0x00RRGGBB for each palette index we own (1..254) */
++extern uint32_t fos_pal[256];
++
++/* What the overlay gets for palette index ix: Y << 16 | U << 8 | V, U and
++ * V signed bytes. std 0 is Canon's own conversion (BT.601 Y'CbCr, scaled
++ * so white sits at white_y, the luma of Canon's white: 235 on the EOS M);
++ * std 1 is full-range Rec.709. sat, warm and bright are the screen colour
++ * settings, -6..6, 0 = as designed. */
++uint32_t fos_screen_yuv(int ix, int white_y, int std, int sat, int warm, int bright);
++uint32_t fos_screen_yuv_rgb(uint32_t rgb, int white_y, int std, int sat, int warm, int bright); /* any 0xRRGGBB */
++
++/* back to 0xRRGGBB, as a screen decoding Canon's way would show it */
++uint32_t fos_screen_rgb(uint32_t yuv, int white_y);
++
++void fos_gfx_init();
++
++/* palette index of a flat colour */
++uint8_t fos_ix(fcol c);
++
++/* palette index for a 12-bit level, dithered for pixel (x, y) */
++uint8_t fos_ix_dither(int ramp, int lv, int x, int y);
++
++/* the same, inline, for inner loops */
++extern uint8_t fos_ramp_base[RAMP_COUNT];
++extern uint8_t fos_ramp_last[RAMP_COUNT]; /* entries - 1 */
++extern int fos_ramp_mul[RAMP_COUNT]; /* lv * mul >> 16 = position in 1/16 entries */
++extern const uint8_t fos_bayer[4][4];
++
++FOS_INLINE int fos_ramp_pos(int ramp, int lv)
++{
++ return ((lv < 0 ? 0 : lv) * fos_ramp_mul[ramp]) >> 16;
++}
++
++FOS_INLINE uint8_t fos_ixd(int ramp, int pos16, int x, int y)
++{
++ int p = (pos16 + fos_bayer[y & 3][x & 3]) >> 4;
++ return fos_ramp_base[ramp] + (p > fos_ramp_last[ramp] ? fos_ramp_last[ramp] : p);
++}
++
++/* the colour behind a palette index, and its luminance */
++fcol fos_colour_of(uint8_t ix);
++int fos_luma(uint8_t ix);
++
++/* the same as tables, for inner loops */
++extern uint8_t fos_rev_ramp[256];
++extern uint16_t fos_rev_lv[256]; /* 12-bit */
++extern uint8_t fos_luma_tab[256];
++extern uint8_t fos_chroma_tab[256];
++extern uint16_t fos_lum2lv[RAMP_COUNT][256]; /* luminance -> level, per ramp */
++
++/* a pixel at k/256 of its brightness, dithered again */
++FOS_INLINE uint8_t fos_darken(uint8_t ix, int k, int x, int y)
++{
++ int r = fos_rev_ramp[ix];
++ return fos_ixd(r, fos_ramp_pos(r, (fos_rev_lv[ix] * k) >> 8), x, y);
++}
++
++/* dst with k/256 of src glazed over it (reflections): luminance blends,
++ * the ramp is whichever brings more colour */
++FOS_INLINE uint8_t fos_glaze(uint8_t dst, uint8_t src, int k, int x, int y)
++{
++ int ld = fos_luma_tab[dst];
++ int l = ld + (((fos_luma_tab[src] - ld) * k) >> 8);
++ int r = fos_chroma_tab[src] * k >= fos_chroma_tab[dst] * (256 - k) ? fos_rev_ramp[src] : fos_rev_ramp[dst];
++ return fos_ixd(r, fos_ramp_pos(r, fos_lum2lv[r][l]), x, y);
++}
++
++/* blend a 12-bit level of a ramp over a pixel (opacity 0..256) */
++uint8_t fos_mix(uint8_t dst, int ramp, int lv, int alpha);
++uint8_t fos_mix_dither(uint8_t dst, int ramp, int lv, int alpha, int x, int y);
++
++/* the colour a of the way from (ra, la) to (rb, lb), as a ramp and level */
++void fos_lerp2(int ra, int la, int rb, int lb, int a, int *ramp, int *lv);
++
++/* canvas */
++void fos_canvas_init(struct fos_canvas *cv, uint8_t *px, int pitch, int w, int h);
++void fos_clip(struct fos_canvas *cv, int x0, int y0, int x1, int y1);
++void fos_noclip(struct fos_canvas *cv);
++
++void fos_fill(struct fos_canvas *cv, int x, int y, int w, int h, fcol c);
++void fos_fill_ix(struct fos_canvas *cv, int x, int y, int w, int h, uint8_t ix);
++void fos_blend(struct fos_canvas *cv, int x, int y, int w, int h, fcol c, int alpha);
++void fos_scale_levels(struct fos_canvas *cv, int x, int y, int w, int h, int k); /* k/256 */
++void fos_vgrad(struct fos_canvas *cv, int x, int y, int w, int h, int ramp, int lv0, int lv1);
++
++/* anti-aliased shapes; coordinates in 1/256 px where named *8 */
++void fos_rrect(struct fos_canvas *cv, int x, int y, int w, int h, int r, fcol c, int alpha);
++void fos_rrect_line(struct fos_canvas *cv, int x, int y, int w, int h, int r, int t, fcol c, int alpha);
++void fos_disc(struct fos_canvas *cv, int cx8, int cy8, int r8, fcol c, int alpha);
++void fos_ring(struct fos_canvas *cv, int cx8, int cy8, int r8, int t8, fcol c, int alpha);
++void fos_line(struct fos_canvas *cv, int x0_8, int y0_8, int x1_8, int y1_8, int w8, fcol c, int alpha);
++void fos_convex(struct fos_canvas *cv, const int *xy8, int n, fcol c, int alpha);
++void fos_tri(struct fos_canvas *cv, int cx, int cy, int size, int dir, fcol c, int alpha); /* dir 0 right, 1 down, 2 left, 3 up */
++
++/* text: y is the baseline; track is extra spacing in 1/16 px */
++int fos_text(struct fos_canvas *cv, const struct fos_font *f, int x, int y, const char *s, fcol c, int alpha, int track);
++int fos_text_w(const struct fos_font *f, const char *s, int track);
++int fos_text_c(struct fos_canvas *cv, const struct fos_font *f, int cx, int y, const char *s, fcol c, int alpha, int track);
++int fos_text_r(struct fos_canvas *cv, const struct fos_font *f, int rx, int y, const char *s, fcol c, int alpha, int track);
++
++/* text onto any 8-bit buffer with someone else's palette: map[coverage]
++ * (1..15) is the index to write, 0 leaves the pixel alone */
++int fos_text_map(uint8_t *px, int pitch, int w, int h, const struct fos_font *f, int x, int y,
++ const char *s, const uint8_t map[16], int track);
++
++/* small integer helpers */
++int fos_isqrt(unsigned int v);
++int fos_sin(int a); /* a: 0..65535 = one turn; result -4096..4096 */
++int fos_cos(int a);
++
++FOS_INLINE int fos_clamp(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
++
++#endif
+diff --git a/src/fos_hud.c b/src/fos_hud.c
+new file mode 100644
+index 000000000..536534838
+--- /dev/null
++++ b/src/fos_hud.c
+@@ -0,0 +1,262 @@
++/* fos_hud: the SLR viewfinder over LiveView - an aperture scale with the
++ * meter needle on the right, a strip of red seven-segment LEDs below.
++ *
++ * Unlike the film OS screens this draws with Canon's palette (LiveView
++ * shows through index 0, and Canon keeps drawing its own bits), so it
++ * takes the indices it may use from the caller and draws straight into
++ * the overlay buffer.
++ */
++
++#include "fos.h"
++
++#define W 720
++#define H 480
++#define STRIP_W 64 /* meter strip on the right */
++#define BAR_H 44 /* LED readout at the bottom */
++#define VIEW_W (W - STRIP_W)
++#define VIEW_H (H - BAR_H)
++#define THIRD_PX 14 /* scale spacing per 1/3 stop */
++#define SCALE_TOP 26 /* y of f/22; f/1 sits 27 thirds below */
++
++static uint8_t *vr;
++static int vp;
++static const struct fos_hud_palette *pal;
++
++static void fill(int x, int y, int w, int h, uint8_t c)
++{
++ if (x < 0) { w += x; x = 0; }
++ if (y < 0) { h += y; y = 0; }
++ if (x + w > W) w = W - x;
++ if (y + h > H) h = H - y;
++ for (int j = 0; j < h; j++)
++ memset(vr + (y + j) * vp + x, c, w > 0 ? w : 0);
++}
++
++static int fstop_y(int index)
++{
++ return SCALE_TOP + (fos_nfstops - 1 - index) * THIRD_PX;
++}
++
++/* text through a coverage map: grey on black, or red LEDs (two levels) */
++static int text_gray(const struct fos_font *f, int x, int y, const char *s, int pct, int track)
++{
++ uint8_t map[16];
++ map[0] = 0;
++ for (int i = 1; i < 16; i++)
++ map[i] = i < 3 ? 0 : pal->gray[pct * i / 15];
++ return fos_text_map(vr, vp, W, H, f, x, y, s, map, track);
++}
++
++static int text_led(const struct fos_font *f, int x, int y, const char *s, int on, int track)
++{
++ uint8_t map[16];
++ for (int i = 0; i < 16; i++)
++ map[i] = i < 5 ? 0 : !on ? pal->gray[i < 10 ? 6 : 9] : i < 10 ? pal->dark_red : pal->red;
++ return fos_text_map(vr, vp, W, H, f, x, y, s, map, track);
++}
++
++/* ---------------------------------------------------------------- seven segments */
++
++/* segments a..g as bits 0..6 */
++static int seg_bits(int ch)
++{
++ static const uint8_t digits[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F };
++ if (ch >= '0' && ch <= '9') return digits[ch - '0'];
++ switch (ch)
++ {
++ case '-': return 0x40;
++ case 'E': return 0x79;
++ case 'n': return 0x54;
++ case 'd': return 0x5E;
++ case 'F': return 0x71;
++ case 'b': return 0x7C;
++ case 'u': return 0x1C;
++ case 'L': return 0x38;
++ case 'S': return 0x6D;
++ }
++ return 0;
++}
++
++#define DIG_W 15
++#define DIG_H 26
++#define SEG_T 3
++#define DIG_GAP 6
++
++/* one slanted digit; off segments are drawn faintly, like the unlit LEDs
++ * you can just see behind a real viewfinder mask */
++static void seg_digit(int x, int y, int bits, uint8_t on, uint8_t off)
++{
++ int half = DIG_H / 2;
++ for (int r = 0; r < DIG_H; r++)
++ {
++ int slant = (DIG_H - 1 - r) * 3 / DIG_H; /* leans right like the real ones */
++ int yy = y + r;
++ /* horizontals: a at the top, g in the middle, d at the bottom */
++ int hseg = -1;
++ if (r < SEG_T) hseg = 0;
++ else if (r >= half - 1 && r < half - 1 + SEG_T) hseg = 6;
++ else if (r >= DIG_H - SEG_T) hseg = 3;
++ if (hseg >= 0)
++ {
++ /* chamfered ends: shorter where the segment meets the verticals */
++ int inset = hseg == 6 ? 2 : (r == 0 || r == DIG_H - 1) ? 2 : 1;
++ fill(x + slant + inset + 1, yy, DIG_W - 2 * inset - 2, 1, (bits >> hseg) & 1 ? on : off);
++ }
++ /* verticals: f and b above the middle, e and c below */
++ int upper = r < half;
++ if (r > 1 && r < DIG_H - 2 && r != half - 1 + SEG_T / 2)
++ {
++ int left = upper ? 5 : 4, right = upper ? 1 : 2;
++ fill(x + slant, yy, SEG_T - (r == 2 || r == DIG_H - 3 ? 1 : 0), 1, (bits >> left) & 1 ? on : off);
++ fill(x + slant + DIG_W - SEG_T, yy, SEG_T, 1, (bits >> right) & 1 ? on : off);
++ }
++ }
++}
++
++/* a string of digits; '.' is a dot after the previous digit, '"' the
++ * seconds mark; returns the width */
++static int seg_text(int x, int y, const char *s, int lit)
++{
++ uint8_t on = lit ? pal->red : pal->gray[9], off = pal->gray[4];
++ int x0 = x;
++ for (; *s; s++)
++ {
++ if (*s == '.')
++ {
++ fill(x - DIG_GAP + 1, y + DIG_H - SEG_T, SEG_T, SEG_T, on);
++ x += 2;
++ continue;
++ }
++ if (*s == '"')
++ {
++ fill(x - 2, y, 2, 6, on);
++ fill(x + 2, y, 2, 6, on);
++ x += 8;
++ continue;
++ }
++ seg_digit(x, y, seg_bits(*s), on, off);
++ x += DIG_W + DIG_GAP;
++ }
++ return x - x0;
++}
++
++/* the meter's pointer: a red wedge pointing at the scale */
++static void needle(int y, uint8_t c)
++{
++ int x0 = W - STRIP_W + 4;
++ for (int r = -7; r <= 7; r++)
++ fill(x0, y + r, 16 - 2 * (r < 0 ? -r : r), 1, c);
++}
++
++/* ---------------------------------------------------------------- the HUD */
++
++void fos_hud_draw(uint8_t *vram, int pitch, const struct fos_hud *h, const struct fos_hud_palette *p)
++{
++ vr = vram; vp = pitch; pal = p;
++ uint8_t bg = p->black;
++ char label[8];
++
++ /* the meter strip */
++ int sx = W - STRIP_W;
++ fill(sx, 0, STRIP_W, VIEW_H, bg);
++ fill(sx, 0, 1, VIEW_H, p->gray[18]);
++ /* red zones: more light than f/22 can take, less than the lens can open to */
++ fill(sx + 27, 4, 4, SCALE_TOP - 11, p->dark_red);
++ fill(sx + 27, fstop_y(h->widest) + 9, 4, 20, p->dark_red);
++ for (int i = 1; i < fos_nfstops; i++)
++ {
++ int y = fstop_y(i);
++ int usable = i >= h->widest;
++ if ((i - 1) % 3)
++ {
++ fill(sx + 27, y, 4, 1, p->gray[usable ? 30 : 14]); /* thirds */
++ continue;
++ }
++ fos_format_fstop(label, sizeof(label), i);
++ fill(sx + 24, y, 8, 1, p->gray[usable ? 55 : 22]);
++ text_gray(&fos_font_xs, sx + 36, y + 5, label, i == h->fstop ? 100 : usable ? 62 : 26, 0);
++ }
++ /* the aperture you set: white tick */
++ fill(sx + 20, fstop_y(h->fstop) - 1, 14, 3, p->white);
++ /* the needle points at the aperture the meter asks for, and blinks
++ * at either end when that is out of reach */
++ if (h->lit && h->meter)
++ {
++ int y;
++ int out = h->want > fos_nfstops - 1 || h->want < h->widest;
++ if (h->want > fos_nfstops - 1) y = SCALE_TOP - 12;
++ else if (h->want < h->widest) y = fstop_y(h->widest) + 18;
++ else y = fstop_y(h->want);
++ if (!out || h->blink)
++ needle(y, p->red);
++ }
++
++ /* the LED strip */
++ int by = VIEW_H;
++ fill(0, by, W, BAR_H, bg);
++ fill(0, by, W, 1, p->gray[18]);
++ int ty = by + (BAR_H - DIG_H) / 2 + 1;
++ int base = ty + DIG_H;
++
++ /* wind reminder: blinks whether or not the meter is on */
++ text_led(&fos_font_mdb, 20, base - 3, "WIND", h->need_wind && h->blink, 24);
++
++ /* shutter speed: 1/125 shows as 125, slow speeds keep their seconds mark */
++ seg_text(132, ty, h->shutter, h->lit);
++
++ /* aperture */
++ text_gray(&fos_font_xs, 262, base - 4, "f", h->lit ? 70 : 30, 0);
++ fos_format_fstop(label, sizeof(label), h->fstop);
++ seg_text(274, ty, label, h->lit);
++
++ /* meter on */
++ for (int r = -6; r <= 6; r++)
++ {
++ int w2 = fos_isqrt(36 - r * r);
++ fill(392 - w2, by + BAR_H / 2 + r, 2 * w2 + 1, 1, h->lit ? p->red : p->gray[9]);
++ }
++
++ /* the frame counter, END at the end */
++ int lit_count = h->lit || h->finished;
++ if (h->finished)
++ seg_text(452, ty, h->blink ? "End" : " ", 1);
++ else
++ {
++ char n[8];
++ snprintf(n, sizeof(n), "%d", h->frame);
++ int w = seg_text(452, ty, n, lit_count);
++ snprintf(n, sizeof(n), "/%d", h->exposures);
++ text_gray(&fos_font_sm, 452 + w + 2, base - 2, n, lit_count ? 55 : 28, 0);
++ }
++
++ /* which film, quietly */
++ if (h->film)
++ {
++ int w = fos_text_w(&fos_font_xs, h->film, 32);
++ text_gray(&fos_font_xs, W - 22 - w, base - 6, h->film, 40, 32);
++ }
++
++ /* focusing screen: microprism collar and split-image circle */
++ if (h->focus_screen)
++ {
++ int cx = VIEW_W / 2, cy = VIEW_H / 2;
++ for (int a = 0; a < 360; a += 2)
++ {
++ int c = fos_cos(a * 65536 / 360), s = fos_sin(a * 65536 / 360);
++ int x = cx + c * 62 / 4096, y = cy + s * 62 / 4096;
++ fill(x, y, 1, 1, p->gray[70]);
++ x = cx + c * 28 / 4096; y = cy + s * 28 / 4096;
++ fill(x, y, 1, 1, p->white);
++ }
++ fill(cx - 28, cy, 57, 1, p->white);
++ }
++}
++
++/* make our strips transparent again so LiveView shows through */
++void fos_hud_clear(uint8_t *vram, int pitch, const struct fos_hud_palette *p)
++{
++ vr = vram; vp = pitch; pal = p;
++ fill(W - STRIP_W, 0, STRIP_W, VIEW_H, p->clear);
++ fill(0, VIEW_H, W, BAR_H, p->clear);
++ fill(VIEW_W / 2 - 64, VIEW_H / 2 - 64, 129, 129, p->clear);
++}
+diff --git a/src/fos_jpeg.c b/src/fos_jpeg.c
+new file mode 100644
+index 000000000..a46bf4e98
+--- /dev/null
++++ b/src/fos_jpeg.c
+@@ -0,0 +1,358 @@
++/* fos_jpeg: a small baseline JPEG writer for the developed frames - 4:2:0,
++ * the standard Huffman tables, integer DCT (the camera has no FPU), and
++ * EXIF with the date, the film and the f-stop.
++ */
++
++#include "fos_jpeg.h"
++#include "fos.h"
++#include <string.h>
++
++/* ---------------------------------------------------------------- tables */
++
++static const uint8_t zigzag[64] =
++{
++ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
++ 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
++ 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
++ 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63,
++};
++
++/* the example tables of the standard (K.1, K.2), in natural order */
++static const uint8_t std_q[2][64] =
++{
++ { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56,
++ 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92,
++ 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99 },
++ { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99,
++ 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
++ 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 },
++};
++
++/* the standard's Huffman tables (K.3): code counts by length, then values */
++static const uint8_t dc_bits[2][16] = { { 0, 1, 5, 1, 1, 1, 1, 1, 1 }, { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
++static const uint8_t dc_vals[12] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
++static const uint8_t ac_bits[2][16] =
++{
++ { 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d },
++ { 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 },
++};
++static const uint8_t ac_vals[2][162] =
++{
++ { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
++ 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
++ 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
++ 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
++ 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
++ 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
++ 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
++ 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
++ 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
++ 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
++ 0xf9, 0xfa },
++ { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
++ 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
++ 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
++ 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
++ 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
++ 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
++ 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
++ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
++ 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
++ 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
++ 0xf9, 0xfa },
++};
++
++/* ---------------------------------------------------------------- output */
++
++struct jw
++{
++ void *f;
++ uint8_t buf[2048];
++ int n, ok;
++ uint32_t bits;
++ int nbits;
++ uint16_t dc_code[2][12], ac_code[2][256];
++ uint8_t dc_len[2][12], ac_len[2][256];
++ int32_t recip[2][64]; /* 65536 / (8 q), zigzag order */
++ uint8_t q[2][64]; /* zigzag order, as written */
++};
++
++static void flush(struct jw *w)
++{
++ if (w->n && fos_port_write(w->f, w->buf, w->n) != w->n) w->ok = 0;
++ w->n = 0;
++}
++
++static void put8(struct jw *w, int b)
++{
++ if (w->n == (int) sizeof(w->buf)) flush(w);
++ w->buf[w->n++] = (uint8_t) b;
++}
++
++static void put16(struct jw *w, int v) { put8(w, v >> 8); put8(w, v); }
++
++static void put_bits(struct jw *w, uint32_t code, int len)
++{
++ w->bits = w->bits << len | (code & ((1u << len) - 1));
++ w->nbits += len;
++ while (w->nbits >= 8)
++ {
++ int b = (int) (w->bits >> (w->nbits - 8)) & 0xFF;
++ put8(w, b);
++ if (b == 0xFF) put8(w, 0); /* stuffed */
++ w->nbits -= 8;
++ }
++}
++
++static void huff_codes(const uint8_t *bits, const uint8_t *vals, uint16_t *code, uint8_t *len)
++{
++ int c = 0, k = 0;
++ for (int l = 1; l <= 16; l++)
++ {
++ for (int i = 0; i < bits[l - 1]; i++, k++)
++ {
++ code[vals[k]] = (uint16_t) c++;
++ len[vals[k]] = (uint8_t) l;
++ }
++ c <<= 1;
++ }
++}
++
++/* ---------------------------------------------------------------- one block */
++
++/* forward DCT, integer (libjpeg's islow, its constants in 1/8192): the
++ * output 8 times too large */
++enum { C0298 = 2446, C0390 = 3196, C0541 = 4433, C0765 = 6270, C0899 = 7373, C1175 = 9633,
++ C1501 = 12299, C1847 = 15137, C1961 = 16069, C2053 = 16819, C2562 = 20995, C3072 = 25172 };
++static void fdct(int32_t *d)
++{
++ for (int pass = 0; pass < 2; pass++)
++ {
++ for (int i = 0; i < 8; i++)
++ {
++ int32_t *p = pass ? d + i : d + i * 8;
++ const int s = pass ? 8 : 1;
++ int32_t t0 = p[0] + p[7 * s], t7 = p[0] - p[7 * s], t1 = p[s] + p[6 * s], t6 = p[s] - p[6 * s];
++ int32_t t2 = p[2 * s] + p[5 * s], t5 = p[2 * s] - p[5 * s], t3 = p[3 * s] + p[4 * s], t4 = p[3 * s] - p[4 * s];
++ int32_t t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2;
++ const int sh = pass ? 15 : 11;
++ if (pass) { p[0] = (t10 + t11 + 2) >> 2; p[4 * s] = (t10 - t11 + 2) >> 2; }
++ else { p[0] = (t10 + t11) * 4; p[4 * s] = (t10 - t11) * 4; }
++ int32_t z1 = (t12 + t13) * C0541;
++ p[2 * s] = (z1 + t13 * C0765 + (1 << (sh - 1))) >> sh;
++ p[6 * s] = (z1 - t12 * C1847 + (1 << (sh - 1))) >> sh;
++ int32_t a = t4 + t7, b = t5 + t6, c = t4 + t6, e = t5 + t7;
++ int32_t z5 = (c + e) * C1175;
++ t4 *= C0298; t5 *= C2053; t6 *= C3072; t7 *= C1501;
++ a *= -C0899; b *= -C2562; c = c * -C1961 + z5; e = e * -C0390 + z5;
++ p[7 * s] = (t4 + a + c + (1 << (sh - 1))) >> sh;
++ p[5 * s] = (t5 + b + e + (1 << (sh - 1))) >> sh;
++ p[3 * s] = (t6 + b + c + (1 << (sh - 1))) >> sh;
++ p[s] = (t7 + a + e + (1 << (sh - 1))) >> sh;
++ }
++ }
++}
++
++static int bit_size(int v)
++{
++ int n = 0;
++ if (v < 0) v = -v;
++ while (v) { n++; v >>= 1; }
++ return n;
++}
++
++/* a block of samples (level-shifted) to the file; t: 0 luma, 1 chroma */
++static void block(struct jw *w, int32_t *d, int t, int *dc_prev)
++{
++ fdct(d);
++ int q[64];
++ for (int i = 0; i < 64; i++)
++ {
++ int32_t v = d[zigzag[i]], r = w->recip[t][i];
++ q[i] = v >= 0 ? (int) ((v * r + 32768) >> 16) : -(int) ((-v * r + 32768) >> 16);
++ }
++ int diff = q[0] - *dc_prev, n = bit_size(diff);
++ *dc_prev = q[0];
++ put_bits(w, w->dc_code[t][n], w->dc_len[t][n]);
++ if (n) put_bits(w, (uint32_t) (diff < 0 ? diff - 1 : diff), n);
++ int run = 0;
++ for (int i = 1; i < 64; i++)
++ {
++ if (!q[i]) { run++; continue; }
++ while (run > 15) { put_bits(w, w->ac_code[t][0xF0], w->ac_len[t][0xF0]); run -= 16; }
++ int s = bit_size(q[i]), sym = run << 4 | s;
++ put_bits(w, w->ac_code[t][sym], w->ac_len[t][sym]);
++ put_bits(w, (uint32_t) (q[i] < 0 ? q[i] - 1 : q[i]), s);
++ run = 0;
++ }
++ if (run) put_bits(w, w->ac_code[t][0], w->ac_len[t][0]);
++}
++
++/* ---------------------------------------------------------------- EXIF */
++
++/* a tiny TIFF: IFD0 (description, make, model, software, date) and the
++ * EXIF IFD (date taken, f-number) */
++static int exif(uint8_t *out, const struct fos_jpeg_meta *m)
++{
++ char date[20] = "";
++ if (m->when && strlen(m->when) >= 16)
++ {
++ /* "2026-10-22 17:45" -> "2026:10:22 17:45:00" */
++ memcpy(date, m->when, 16);
++ date[4] = date[7] = ':';
++ memcpy(date + 16, ":00", 4);
++ }
++ int fnum = 0; /* x10 */
++ if (m->fstop && *m->fstop)
++ {
++ const char *s = m->fstop;
++ while (*s >= '0' && *s <= '9') fnum = fnum * 10 + (*s++ - '0');
++ fnum *= 10;
++ if (*s == '.' && s[1] >= '0' && s[1] <= '9') fnum += s[1] - '0';
++ }
++ struct { int tag, type; const char *s; } ifd0[] =
++ {
++ { 0x010E, 2, m->desc }, { 0x010F, 2, "Canon" }, { 0x0110, 2, fos_port_model() },
++ { 0x0131, 2, "M-FILM darkroom" }, { 0x0132, 2, date },
++ };
++ const int n0 = 6, n1 = 1 + (fnum > 0);
++ int p = 8, data = 8 + 2 + n0 * 12 + 4 + 2 + n1 * 12 + 4;
++ memcpy(out, "II*\0\x08\0\0\0", 8);
++#define W16(v) (out[p] = (uint8_t) (v), out[p + 1] = (uint8_t) ((v) >> 8), p += 2)
++#define W32(v) (W16((v) & 0xFFFF), W16((uint32_t) (v) >> 16))
++ W16(n0);
++ for (int i = 0; i < n0 - 1; i++)
++ {
++ const char *s = ifd0[i].s && *ifd0[i].s ? ifd0[i].s : " ";
++ int len = (int) strlen(s) + 1;
++ W16(ifd0[i].tag); W16(2); W32(len);
++ if (len <= 4) { memset(out + p, 0, 4); memcpy(out + p, s, len); p += 4; }
++ else { W32(data); memcpy(out + data, s, len); data += (len + 1) & ~1; }
++ }
++ int exif_at = 8 + 2 + n0 * 12 + 4;
++ W16(0x8769); W16(4); W32(1); W32(exif_at);
++ W32(0);
++ W16(n1); /* tags in ascending order */
++ if (fnum > 0)
++ {
++ W16(0x829D); W16(5); W32(1); W32(data);
++ int q = data;
++ out[q] = (uint8_t) fnum; out[q + 1] = (uint8_t) (fnum >> 8); out[q + 2] = out[q + 3] = 0;
++ out[q + 4] = 10; out[q + 5] = out[q + 6] = out[q + 7] = 0;
++ data += 8;
++ }
++ W16(0x9003); W16(2); W32(20); W32(data);
++ memcpy(out + data, date[0] ? date : " ", 20);
++ data += 20;
++ W32(0);
++#undef W16
++#undef W32
++ return data;
++}
++
++/* ---------------------------------------------------------------- the file */
++
++int fos_jpeg_write(const char *path, const uint8_t *rgb, int stride, int width, int height,
++ int quality, const struct fos_jpeg_meta *meta)
++{
++ struct jw *w = fos_port_alloc(sizeof(struct jw));
++ if (!w) return 0;
++ memset(w, 0, sizeof(*w));
++ w->ok = 1;
++ int scale = quality < 50 ? 5000 / quality : 200 - quality * 2;
++ for (int t = 0; t < 2; t++)
++ {
++ for (int i = 0; i < 64; i++)
++ {
++ int v = (std_q[t][zigzag[i]] * scale + 50) / 100;
++ v = v < 1 ? 1 : v > 255 ? 255 : v;
++ w->q[t][i] = (uint8_t) v;
++ w->recip[t][i] = 65536 / (8 * v);
++ }
++ huff_codes(dc_bits[t], dc_vals, w->dc_code[t], w->dc_len[t]);
++ huff_codes(ac_bits[t], ac_vals[t], w->ac_code[t], w->ac_len[t]);
++ }
++ w->f = fos_port_open(path, 1);
++ if (!w->f) { fos_port_free(w); return 0; }
++
++ put16(w, 0xFFD8);
++ /* JFIF */
++ put16(w, 0xFFE0); put16(w, 16);
++ static const uint8_t jfif[14] = { 'J', 'F', 'I', 'F', 0, 1, 1, 0, 0, 1, 0, 1, 0, 0 };
++ for (int i = 0; i < 14; i++) put8(w, jfif[i]);
++ /* EXIF */
++ if (meta)
++ {
++ uint8_t ex[512];
++ memset(ex, 0, sizeof(ex));
++ int n = exif(ex, meta);
++ put16(w, 0xFFE1); put16(w, n + 8);
++ static const uint8_t tag[6] = { 'E', 'x', 'i', 'f', 0, 0 };
++ for (int i = 0; i < 6; i++) put8(w, tag[i]);
++ for (int i = 0; i < n; i++) put8(w, ex[i]);
++ }
++ /* quantisation, frame, Huffman tables */
++ for (int t = 0; t < 2; t++)
++ {
++ put16(w, 0xFFDB); put16(w, 67); put8(w, t);
++ for (int i = 0; i < 64; i++) put8(w, w->q[t][i]);
++ }
++ put16(w, 0xFFC0); put16(w, 17); put8(w, 8); put16(w, height); put16(w, width); put8(w, 3);
++ put8(w, 1); put8(w, 0x22); put8(w, 0);
++ put8(w, 2); put8(w, 0x11); put8(w, 1);
++ put8(w, 3); put8(w, 0x11); put8(w, 1);
++ for (int t = 0; t < 2; t++)
++ {
++ int nd = 0, na = 0;
++ for (int i = 0; i < 16; i++) { nd += dc_bits[t][i]; na += ac_bits[t][i]; }
++ put16(w, 0xFFC4); put16(w, 2 + 17 + nd + 17 + na);
++ put8(w, t);
++ for (int i = 0; i < 16; i++) put8(w, dc_bits[t][i]);
++ for (int i = 0; i < nd; i++) put8(w, dc_vals[i]);
++ put8(w, 0x10 | t);
++ for (int i = 0; i < 16; i++) put8(w, ac_bits[t][i]);
++ for (int i = 0; i < na; i++) put8(w, ac_vals[t][i]);
++ }
++ put16(w, 0xFFDA); put16(w, 12); put8(w, 3);
++ put8(w, 1); put8(w, 0x00); put8(w, 2); put8(w, 0x11); put8(w, 3); put8(w, 0x11);
++ put8(w, 0); put8(w, 63); put8(w, 0);
++
++ /* the picture, 16 x 16 at a time: four luma blocks, then Cb and Cr
++ * from the means of 2 x 2 pixels; the edges repeat the last pixel */
++ int dc[3] = { 0, 0, 0 };
++ int32_t blk[64], cb[64], cr[64];
++ for (int my = 0; my < height; my += 16)
++ for (int mx = 0; mx < width; mx += 16)
++ {
++ memset(cb, 0, sizeof(cb));
++ memset(cr, 0, sizeof(cr));
++ for (int b = 0; b < 4; b++)
++ {
++ int bx = mx + (b & 1) * 8, by = my + (b >> 1) * 8;
++ for (int y = 0; y < 8; y++)
++ {
++ const uint8_t *row = rgb + (by + y < height ? by + y : height - 1) * stride;
++ for (int x = 0; x < 8; x++)
++ {
++ const uint8_t *px = row + 3 * (bx + x < width ? bx + x : width - 1);
++ int r = px[0], g = px[1], bl = px[2];
++ blk[y * 8 + x] = ((19595 * r + 38470 * g + 7471 * bl + 32768) >> 16) - 128;
++ int k = ((b >> 1) * 4 + (y >> 1)) * 8 + (b & 1) * 4 + (x >> 1);
++ cb[k] += -11059 * r - 21709 * g + 32768 * bl;
++ cr[k] += 32768 * r - 27439 * g - 5329 * bl;
++ }
++ }
++ block(w, blk, 0, &dc[0]);
++ }
++ for (int i = 0; i < 64; i++) { cb[i] = (cb[i] + 131072) >> 18; cr[i] = (cr[i] + 131072) >> 18; }
++ block(w, cb, 1, &dc[1]);
++ block(w, cr, 1, &dc[2]);
++ }
++ if (w->nbits) put_bits(w, 0x7F, 8 - w->nbits); /* pad with ones */
++ put16(w, 0xFFD9);
++ flush(w);
++ fos_port_close(w->f);
++ int ok = w->ok;
++ fos_port_free(w);
++ return ok;
++}
+diff --git a/src/fos_jpeg.h b/src/fos_jpeg.h
+new file mode 100644
+index 000000000..ae60ddb83
+--- /dev/null
++++ b/src/fos_jpeg.h
+@@ -0,0 +1,19 @@
++#ifndef _fos_jpeg_h_
++#define _fos_jpeg_h_
++
++#include <stdint.h>
++
++/* what goes into the JPEG's EXIF (any may be NULL) */
++struct fos_jpeg_meta
++{
++ const char *when; /* "2026-10-22 17:45" */
++ const char *desc; /* the film */
++ const char *fstop; /* "2.8" */
++};
++
++/* width x height RGB pixels (rows stride bytes apart) as a baseline JPEG
++ * at path; quality 1..100. 1 when written. */
++int fos_jpeg_write(const char *path, const uint8_t *rgb, int stride, int width, int height,
++ int quality, const struct fos_jpeg_meta *meta);
++
++#endif
+diff --git a/src/fos_lab.c b/src/fos_lab.c
+new file mode 100644
+index 000000000..b6a5312bf
+--- /dev/null
++++ b/src/fos_lab.c
+@@ -0,0 +1,358 @@
++/* fos_lab: the rolls on the card and their prints, for the darkroom.
++ *
++ * A roll is what its logs say: DCIM/xxxCANON/ROLL_nnn.TXT, written by the
++ * camera frame by frame (a roll that ran into a new DCIM folder has a log
++ * in each). Its prints are kept in ML/DARKROOM/Rnnn/, Fnn.BMP for frame nn
++ * and SHEET.BMP for the contact sheet; a roll is developed when they are
++ * all there.
++ */
++
++#include "fos.h"
++#include "fos_dev.h"
++#include <string.h>
++#include <stdlib.h>
++
++#define LOG_MAX (16 * 1024)
++
++void fos_lab_print_path(char *buf, int size, int roll, int frame)
++{
++ if (frame) snprintf(buf, size, "%sML/DARKROOM/R%03d/F%02d.BMP", fos_port_card(), roll, frame);
++ else snprintf(buf, size, "%sML/DARKROOM/R%03d/SHEET.BMP", fos_port_card(), roll);
++}
++
++void fos_lab_cache_dir(char *buf, int size)
++{
++ snprintf(buf, size, "%sML/DARKROOM", fos_port_card());
++}
++
++static int first_only(void *ctx, const char *name, int is_dir) { return 0; }
++
++static int dir_exists(const char *path)
++{
++ return fos_port_list(path, first_only, 0) >= 0;
++}
++
++/* a folder of ours: it holds the roll's tag file */
++static int tagged(const char *dir, int roll)
++{
++ char path[128];
++ snprintf(path, sizeof(path), "%s/ROLL%03d.TXT", dir, roll);
++ void *f = fos_port_open(path, 0);
++ if (f) fos_port_close(f);
++ return f != 0;
++}
++
++static int make_tagged(const char *dir, int roll, int film)
++{
++ if (fos_port_mkdir(dir) < 0) return 0;
++ char path[128], text[96];
++ snprintf(path, sizeof(path), "%s/ROLL%03d.TXT", dir, roll);
++ void *f = fos_port_open(path, 1);
++ if (!f) return 0;
++ int n = snprintf(text, sizeof(text), "roll = %03d\nfilm = %s\n", roll, fos_films[film].key);
++ fos_port_write(f, text, n);
++ fos_port_close(f);
++ return 1;
++}
++
++int fos_lab_dcim_dir(char *buf, int size, int roll, int film, const char *when)
++{
++ static const char *const months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
++ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
++ int m = when && strlen(when) >= 10 ? atoi(when + 5) : 0, d = m ? atoi(when + 8) : 0;
++ if (m < 1 || m > 12 || d < 1 || d > 31) return -1;
++ film = fos_clamp(film, 0, fos_nfilms - 1);
++ const char *film_name = fos_films[film].shortname ? fos_films[film].shortname : fos_films[film].key;
++ /* "Sep0906 Portra400", "Sep0906 Portra400 2" for another roll that day */
++ for (int k = 1; k < 10; k++)
++ {
++ if (k == 1) snprintf(buf, size, "%sDCIM/%s%02d%02d %s", fos_port_card(), months[m - 1], m, d, film_name);
++ else snprintf(buf, size, "%sDCIM/%s%02d%02d %s %d", fos_port_card(), months[m - 1], m, d, film_name, k);
++ if (dir_exists(buf)) { if (tagged(buf, roll)) return 0; continue; }
++ if (make_tagged(buf, roll, film) && dir_exists(buf)) return 0;
++ break; /* no long names on this card */
++ }
++ /* SEP0906, SEP0906B, ... */
++ char up[4] = { months[m - 1][0], (char) (months[m - 1][1] - 32), (char) (months[m - 1][2] - 32), 0 };
++ for (int k = 0; k < 26; k++)
++ {
++ char suffix[2] = { (char) (k ? 'A' + k : 0), 0 };
++ snprintf(buf, size, "%sDCIM/%s%02d%02d%s", fos_port_card(), up, m, d, suffix);
++ if (dir_exists(buf)) { if (tagged(buf, roll)) return 0; continue; }
++ if (make_tagged(buf, roll, film)) return 0;
++ return -1;
++ }
++ return -1;
++}
++
++int fos_lab_prepare(int roll)
++{
++ char path[64];
++ snprintf(path, sizeof(path), "%sML/DARKROOM", fos_port_card());
++ if (fos_port_mkdir(path)) return -1;
++ snprintf(path, sizeof(path), "%sML/DARKROOM/R%03d", fos_port_card(), roll);
++ return fos_port_mkdir(path);
++}
++
++static int film_index(const char *key)
++{
++ for (int i = 0; i < fos_nfilms; i++)
++ if (!strcmp(fos_films[i].key, key)) return i;
++ return 0;
++}
++
++/* ---------------------------------------------------------------- reading logs */
++
++/* one log, a line at a time: header lines ("film = portra400") and
++ * frames ("12 IMG_0012.CR2 2026-08-08 09:15:15 f/2.8") */
++struct log_reader
++{
++ void (*header)(void *ctx, const char *key, const char *value);
++ void (*frame)(void *ctx, int no, const char *file, const char *when, const char *fstop);
++ void *ctx;
++};
++
++static void read_log(const char *path, const struct log_reader *r)
++{
++ char *buf = fos_port_alloc(LOG_MAX + 1);
++ if (!buf) return;
++ void *f = fos_port_open(path, 0);
++ int n = f ? fos_port_read(f, buf, LOG_MAX) : 0;
++ if (f) fos_port_close(f);
++ buf[n > 0 ? n : 0] = 0;
++ for (char *line = buf; *line; )
++ {
++ char *next = strchr(line, '\n');
++ if (next) *next++ = 0;
++ else next = line + strlen(line);
++ char *cr = strchr(line, '\r');
++ if (cr) *cr = 0;
++ while (*line == ' ') line++;
++ char *eq = strchr(line, '=');
++ if (*line == '#' || !*line) { line = next; continue; }
++ if (eq && !(line[0] >= '0' && line[0] <= '9'))
++ {
++ char *k = line, *v = eq + 1, *e = eq;
++ while (e > k && e[-1] == ' ') e--;
++ *e = 0;
++ while (*v == ' ') v++;
++ if (r->header) r->header(r->ctx, k, v);
++ }
++ else if (line[0] >= '0' && line[0] <= '9')
++ {
++ char *tok[5];
++ int nt = 0;
++ for (char *p = line; *p && nt < 5; )
++ {
++ while (*p == ' ' || *p == '\t') p++;
++ if (!*p) break;
++ tok[nt++] = p;
++ while (*p && *p != ' ' && *p != '\t') p++;
++ if (*p) *p++ = 0;
++ }
++ if (nt >= 2 && r->frame)
++ {
++ char when[20] = "";
++ char hm[6];
++ if (nt >= 4) snprintf(when, sizeof(when), "%s %s", tok[2], fos_copy(hm, sizeof(hm), tok[3], 5));
++ r->frame(r->ctx, atoi(tok[0]), tok[1], when, nt >= 5 && !strncmp(tok[4], "f/", 2) ? tok[4] + 2 : "");
++ }
++ }
++ line = next;
++ }
++ fos_port_free(buf);
++}
++
++/* every ROLL_nnn.TXT on the card: fn(ctx, folder, file name, roll number) */
++struct each_log { void (*fn)(void *ctx, const char *folder, const char *name, int number); void *ctx; const char *folder; };
++
++static int log_entry(void *ctx, const char *name, int is_dir)
++{
++ struct each_log *e = ctx;
++ if (!is_dir && !strncmp(name, "ROLL_", 5) && strlen(name) == 12
++ && (!strcmp(name + 8, ".TXT") || !strcmp(name + 8, ".txt")))
++ e->fn(e->ctx, e->folder, name, atoi(name + 5));
++ return 1;
++}
++
++static int folder_entry(void *ctx, const char *name, int is_dir)
++{
++ struct each_log *e = ctx;
++ /* DCIM folders: three digits and five characters, "100CANON" */
++ if (!is_dir || strlen(name) != 8 || name[0] < '1' || name[0] > '9') return 1;
++ char dir[64];
++ snprintf(dir, sizeof(dir), "%sDCIM/%s", fos_port_card(), name);
++ struct each_log sub = *e;
++ sub.folder = name;
++ fos_port_list(dir, log_entry, &sub);
++ return 1;
++}
++
++static void each_log(void (*fn)(void *, const char *, const char *, int), void *ctx)
++{
++ char dir[64];
++ snprintf(dir, sizeof(dir), "%sDCIM", fos_port_card());
++ struct each_log e = { fn, ctx, 0 };
++ fos_port_list(dir, folder_entry, &e);
++}
++
++/* ---------------------------------------------------------------- the catalogue */
++
++struct scan { struct fos_lab_roll *rolls; int n, max; struct fos_lab_roll *cur; };
++
++static void scan_header(void *ctx, const char *k, const char *v)
++{
++ struct fos_lab_roll *r = ((struct scan *) ctx)->cur;
++ if (!strcmp(k, "film")) r->film = film_index(v);
++ else if (!strcmp(k, "exposures")) r->exposures = atoi(v);
++ else if (!strcmp(k, "loaded") && (!r->loaded[0] || strncmp(v, r->loaded, 16) < 0))
++ fos_copy(r->loaded, sizeof(r->loaded), v, 16);
++}
++
++static void scan_frame(void *ctx, int no, const char *file, const char *when, const char *fstop)
++{
++ struct fos_lab_roll *r = ((struct scan *) ctx)->cur;
++ if (no > r->shot) r->shot = no;
++ if (strcmp(when, r->last) > 0) snprintf(r->last, sizeof(r->last), "%s", when);
++}
++
++static void scan_log(void *ctx, const char *folder, const char *name, int number)
++{
++ struct scan *s = ctx;
++ struct fos_lab_roll *r = 0;
++ for (int i = 0; i < s->n; i++)
++ if (s->rolls[i].number == number) r = &s->rolls[i];
++ if (!r)
++ {
++ if (s->n >= s->max) return;
++ r = &s->rolls[s->n++];
++ memset(r, 0, sizeof(*r));
++ r->number = number;
++ r->exposures = 36;
++ }
++ char path[64];
++ snprintf(path, sizeof(path), "%sDCIM/%s/%s", fos_port_card(), folder, name);
++ s->cur = r;
++ struct log_reader rd = { scan_header, scan_frame, s };
++ read_log(path, &rd);
++}
++
++static int print_entry(void *ctx, const char *name, int is_dir)
++{
++ struct fos_lab_roll *r = ctx;
++ if (is_dir) return 1;
++ if (!strcmp(name, "SHEET.BMP")) r->sheet = 1;
++ else if (name[0] == 'F' && strlen(name) == 7 && !strcmp(name + 3, ".BMP"))
++ {
++ int no = atoi(name + 1);
++ if (no >= 1 && no <= r->shot) r->developed++;
++ }
++ return 1;
++}
++
++/* our folders in DCIM (not Canon's "100CANON"): which roll each holds, by
++ * its tag file, and how many JPEGs */
++struct jpeg_scan { struct fos_lab_roll *rolls; int n; int roll, count; };
++
++static int jpeg_file(void *ctx, const char *name, int is_dir)
++{
++ struct jpeg_scan *s = ctx;
++ int len = (int) strlen(name);
++ if (is_dir) return 1;
++ if (len == 11 && !strncmp(name, "ROLL", 4) && !strcmp(name + 7, ".TXT")) s->roll = atoi(name + 4);
++ else if (len > 4 && !strcmp(name + len - 4, ".JPG")) s->count++;
++ return 1;
++}
++
++static int jpeg_folder(void *ctx, const char *name, int is_dir)
++{
++ struct jpeg_scan *s = ctx;
++ if (!is_dir || (strlen(name) == 8 && name[0] >= '1' && name[0] <= '9')) return 1;
++ char dir[128];
++ snprintf(dir, sizeof(dir), "%sDCIM/%s", fos_port_card(), name);
++ s->roll = -1;
++ s->count = 0;
++ fos_port_list(dir, jpeg_file, s);
++ for (int i = 0; i < s->n; i++)
++ if (s->rolls[i].number == s->roll) s->rolls[i].jpegs += s->count;
++ return 1;
++}
++
++int fos_lab_scan(struct fos_lab_roll *rolls, int max)
++{
++ struct scan s = { rolls, 0, max, 0 };
++ each_log(scan_log, &s);
++ struct fos_roll cam;
++ fos_port_roll(&cam);
++ for (int i = 0; i < s.n; i++)
++ {
++ struct fos_lab_roll *r = &rolls[i];
++ char dir[64];
++ snprintf(dir, sizeof(dir), "%sML/DARKROOM/R%03d", fos_port_card(), r->number);
++ fos_port_list(dir, print_entry, r);
++ r->in_camera = cam.loaded && cam.number == r->number;
++ }
++ char dcim[64];
++ snprintf(dcim, sizeof(dcim), "%sDCIM", fos_port_card());
++ struct jpeg_scan js = { rolls, s.n, -1, 0 };
++ fos_port_list(dcim, jpeg_folder, &js);
++ /* newest first */
++ for (int i = 1; i < s.n; i++)
++ for (int j = i; j > 0; j--)
++ {
++ struct fos_lab_roll *a = &rolls[j - 1], *b = &rolls[j];
++ int c = strcmp(a->loaded, b->loaded);
++ if (c > 0 || (c == 0 && a->number > b->number)) break;
++ struct fos_lab_roll t = *a; *a = *b; *b = t;
++ }
++ return s.n;
++}
++
++/* ---------------------------------------------------------------- one roll's frames */
++
++struct frames { struct fos_lab_frame *frames; int max, roll; const char *folder; };
++
++static void frames_frame(void *ctx, int no, const char *file, const char *when, const char *fstop)
++{
++ struct frames *s = ctx;
++ if (no < 1 || no > s->max) return;
++ struct fos_lab_frame *f = &s->frames[no - 1];
++ f->no = no;
++ snprintf(f->cr2, sizeof(f->cr2), "%sDCIM/%s/%s", fos_port_card(), s->folder, file);
++ snprintf(f->when, sizeof(f->when), "%s", when);
++ snprintf(f->fstop, sizeof(f->fstop), "%s", fstop);
++}
++
++static void frames_log(void *ctx, const char *folder, const char *name, int number)
++{
++ struct frames *s = ctx;
++ if (number != s->roll) return;
++ char path[64];
++ snprintf(path, sizeof(path), "%sDCIM/%s/%s", fos_port_card(), folder, name);
++ s->folder = folder;
++ struct log_reader rd = { 0, frames_frame, s };
++ read_log(path, &rd);
++}
++
++int fos_lab_frames(int roll, struct fos_lab_frame *frames, int max)
++{
++ memset(frames, 0, sizeof(*frames) * max);
++ struct frames s = { frames, max, roll, 0 };
++ each_log(frames_log, &s);
++ int n = 0;
++ for (int i = 0; i < max; i++)
++ {
++ if (frames[i].no) n = i + 1;
++ else frames[i].no = i + 1;
++ }
++ /* a frame whose file has gone (deleted on the camera, or never a RAW)
++ * can't be developed */
++ for (int i = 0; i < n; i++)
++ {
++ if (!frames[i].cr2[0]) { frames[i].missing = 1; continue; }
++ void *f = fos_port_open(frames[i].cr2, 0);
++ if (f) fos_port_close(f);
++ else frames[i].missing = 1;
++ }
++ return n;
++}
+diff --git a/src/fos_looks.c b/src/fos_looks.c
+new file mode 100644
+index 000000000..c041267ef
+--- /dev/null
++++ b/src/fos_looks.c
+@@ -0,0 +1,49 @@
++/* fos_looks: the film looks the camera develops with.
++ * Generated from films/films.py by tools/genlooks.py: edit those, not this. */
++
++#include "fos_dev.h"
++
++const struct fos_look fos_looks[] =
++{
++ { "portra400", 5500, 0, 0.3f, 0.85f,
++ { 0.165f, 0.17f, 0.158f }, { -0.15f, 0.0f, 0.1f }, { 0.03f, 0.026f, 0.028f }, { 0.97f, 0.955f, 0.92f },
++ 3, { { 1, 0, 0.06f, 1.05f }, { 3, 2, 0.12f, 0.85f }, { 5, 4, 0.08f, 0.85f } },
++ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.018f, 1.1f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "cinestill800t", 3200, 0, 0.0f, 0.95f,
++ { 0.18f, 0.18f, 0.172f }, { -0.05f, 0.0f, -0.05f }, { 0.02f, 0.032f, 0.045f }, { 0.97f, 0.96f, 0.95f },
++ 2, { { 4, 5, 0.1f, 1.0f }, { 0, 1, 0.08f, 1.05f } },
++ 6.0f, 0.6f, { 1.0f, 0.28f, 0.06f }, 0.026f, 1.4f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "ektar100", 5500, 0, 0.0f, 1.25f,
++ { 0.19f, 0.19f, 0.186f }, { -0.05f, 0.0f, 0.05f }, { 0.025f, 0.02f, 0.025f }, { 0.98f, 0.97f, 0.95f },
++ 2, { { 0, 6, 0.05f, 1.1f }, { 5, 5, 0.0f, 1.15f } },
++ 0.6f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.009f, 0.8f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "gold200", 5500, 0, 0.2f, 1.08f,
++ { 0.185f, 0.18f, 0.168f }, { -0.25f, -0.05f, 0.2f }, { 0.035f, 0.028f, 0.022f }, { 0.98f, 0.95f, 0.86f },
++ 2, { { 2, 1, 0.1f, 1.1f }, { 3, 2, 0.15f, 0.9f } },
++ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.016f, 1.1f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "superia400", 5500, 0, 0.1f, 1.05f,
++ { 0.18f, 0.183f, 0.178f }, { 0.05f, -0.1f, 0.0f }, { 0.022f, 0.036f, 0.032f }, { 0.96f, 0.97f, 0.95f },
++ 3, { { 3, 4, 0.18f, 1.05f }, { 0, 6, 0.06f, 1.0f }, { 2, 3, 0.06f, 0.95f } },
++ 1.0f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.02f, 1.2f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "velvia50", 5500, 1, -0.3f, 1.45f,
++ { 0.25f, 0.25f, 0.25f }, { 0.0f, 0.0f, -0.05f }, { 0.01f, 0.01f, 0.015f }, { 0.98f, 0.98f, 0.98f },
++ 3, { { 3, 3, 0.0f, 1.15f }, { 5, 6, 0.06f, 1.15f }, { 0, 6, 0.06f, 1.1f } },
++ 0.3f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.007f, 0.7f,
++ 0, { 0.0f, 0.0f, 0.0f } },
++ { "hp5", 5500, 0, 0.2f, 1.0f,
++ { 0.175f, 0.175f, 0.175f }, { 0.0f, 0.0f, 0.0f }, { 0.03f, 0.03f, 0.03f }, { 0.96f, 0.96f, 0.96f },
++ 0, { { 0 } },
++ 0.4f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.028f, 1.3f,
++ 1, { 0.3f, 0.6f, 0.1f } },
++ { "trix400", 5500, 0, 0.0f, 1.0f,
++ { 0.205f, 0.205f, 0.205f }, { 0.1f, 0.1f, 0.1f }, { 0.02f, 0.02f, 0.02f }, { 0.97f, 0.97f, 0.97f },
++ 0, { { 0 } },
++ 0.4f, 0.75f, { 1.0f, 0.28f, 0.06f }, 0.036f, 1.3f,
++ 1, { 0.42f, 0.48f, 0.1f } },
++};
++const int fos_nlooks = sizeof(fos_looks) / sizeof(fos_looks[0]);
+diff --git a/src/fos_pages.c b/src/fos_pages.c
+new file mode 100644
+index 000000000..597cc06c9
+--- /dev/null
++++ b/src/fos_pages.c
+@@ -0,0 +1,1100 @@
++/* fos_pages: home, the settings pages and the roll in the camera.
++ *
++ * Home is the film OS's main menu: the roll you are shooting on the left
++ * (its canister slowly turning), the places you can go on the right. The
++ * settings pages replace the Magic Lantern menu; every row is a toggle,
++ * a choice or an action, and the highlight glides between rows.
++ */
++
++#include "fos_ui.h"
++#include <string.h>
++#include <math.h>
++
++static float absf(float v) { return v < 0 ? -v : v; }
++
++static int roll_active()
++{
++ return ui_roll.loaded && ui_roll.shot < ui_roll.exposures;
++}
++
++/* the highlight behind the selected row of a list */
++static void row_highlight(int x, int w, float y, int h)
++{
++ int yi = (int) (y + 0.5f);
++ fos_rrect(cv, x, yi, w, h, 12, FC(RAMP_GRAY, 27), OPAQUE);
++ fos_rrect(cv, x, yi + 10, 3, h - 20, 1, C_ACCENT, OPAQUE);
++}
++
++/* ---------------------------------------------------------------- the film card */
++
++#define CARD_X 24
++#define CARD_Y 52
++#define CARD_W 268
++#define CARD_H 378
++
++#define CAN_FLOOR (CARD_Y + 210)
++#define CAN_SCALE 186
++
++/* the canister in the card, turning slowly (a turn every 24 s) */
++static void card_canister(int t_ms)
++{
++ if (!ui_roll.loaded) return;
++ struct fos_can *c = ui_can(ui_roll.film);
++ struct fos_can_pose p = { (CARD_X + CARD_W / 2) * 256, CAN_FLOOR, CAN_SCALE, 0, 256, 256, 70, 0 };
++ p.rot = (int) ((int64_t) t_ms * 65536 / 24000);
++ fos_can_draw(cv, c, &p);
++}
++
++/* the box the turning canister lives in */
++static void card_canister_box(int *x0, int *y0, int *x1, int *y1)
++{
++ int cx = CARD_X + CARD_W / 2;
++ int w = fos_can_width(CAN_SCALE), h = fos_can_height(CAN_SCALE);
++ *x0 = cx - w / 2 - 50; *x1 = cx + w / 2 + 56;
++ *y0 = CAN_FLOOR - h - 4; *y1 = CAN_FLOOR + 34;
++}
++
++/* the roll in the camera, everything but the canister: a counter and a
++ * strip of frames */
++static void film_card()
++{
++ fos_rrect(cv, CARD_X, CARD_Y, CARD_W, CARD_H, 18, FC(RAMP_GRAY, 15), OPAQUE);
++ int cx = CARD_X + CARD_W / 2;
++ char b[64];
++ if (!ui_roll.loaded)
++ {
++ /* an empty chamber */
++ fos_rrect_line(cv, cx - 40, CARD_Y + 60, 80, 132, 14, 2, FC(RAMP_GRAY, 48), OPAQUE);
++ fos_text_c(cv, &fos_font_lg, cx, CARD_Y + 240, "No film", C_TEXT, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_sm, cx, CARD_Y + 266, "Load a roll to start shooting", C_TEXT3, OPAQUE, 0);
++ return;
++ }
++
++ fos_text_c(cv, &fos_font_xs, cx, CARD_Y + 26, "IN CAMERA", C_TEXT3, OPAQUE, 48);
++ int y = CARD_Y + 250;
++ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
++ fos_text_c(cv, &fos_font_xs, cx, y, b, C_ACCENT, OPAQUE, 64);
++ fos_text_c(cv, &fos_font_lg, cx, y + 30, fos_films[ui_roll.film].name, C_TEXT, OPAQUE, 0);
++
++ /* frames as a strip: shot ones lit */
++ int n = ui_roll.exposures, shot = ui_roll.shot;
++ int fw = n > 24 ? 5 : n > 12 ? 7 : 12, gap = 1;
++ int sw = n * (fw + gap) - gap;
++ int sx = cx - sw / 2, sy = y + 46;
++ fos_rrect(cv, sx - 6, sy - 6, sw + 12, 24, 4, FC(RAMP_GRAY, 8), OPAQUE);
++ for (int i = 0; i < n; i++)
++ fos_fill(cv, sx + i * (fw + gap), sy, fw, 12, i < shot ? C_ACCENT2 : FC(RAMP_GRAY, 30));
++ if (shot < n)
++ fos_fill(cv, sx + shot * (fw + gap), sy, fw, 12, C_ACCENT);
++ int left = n - shot;
++ if (left > 0)
++ snprintf(b, sizeof(b), "%d shot " T_DOT " %d left", shot, left);
++ else
++ snprintf(b, sizeof(b), "End of roll " T_DOT " rewind to load");
++ fos_text_c(cv, &fos_font_sm, cx, sy + 36, b, left > 0 ? C_TEXT2 : C_RED, OPAQUE, 0);
++}
++
++/* ---------------------------------------------------------------- home */
++
++enum { H_FILM, H_ROLL, H_DARK, H_FINDER, H_LENS, H_SYSTEM, H_COUNT };
++
++static int home_sel;
++static struct spring home_hl;
++static int home_t, home_spun;
++static int home_spin; /* the canister's turn is due */
++static int home_full = 1; /* next frame redraws everything */
++static int home_list = 1; /* ... the list on the right */
++
++#define LIST_X 312
++#define LIST_W 384
++#define LIST_Y 56
++#define ROW_H 64
++
++static void home_bake()
++{
++ ui_bg_plain();
++ ui_to_bg(1);
++ ui_status_bar("HOME");
++ struct hint h[] = { { "^v", "Select" }, { "SET", "Open" }, { "PLAY", "Prints" }, { "MENU", "Back to camera" } };
++ ui_hints(h, 4);
++ film_card();
++ ui_to_bg(0);
++}
++
++void home_enter(int arg)
++{
++ fos_port_roll(&ui_roll);
++ if (arg >= 0 && arg < H_COUNT) home_sel = arg;
++ home_hl.x = home_sel; home_hl.v = 0;
++ home_t = home_spun = 0;
++ home_full = 1;
++ if (ui_roll.loaded) ui_can(ui_roll.film);
++ home_bake();
++}
++
++static void home_open(int i)
++{
++ switch (i)
++ {
++ case H_FILM: ui_go(SCR_SHELF, 1, GO_PUSH); break;
++ case H_ROLL: ui_go(SCR_ROLL, 0, GO_PUSH); break;
++ case H_DARK: ui_go(SCR_DARK, 0, GO_PUSH); break;
++ case H_FINDER: ui_go(SCR_PAGE, 0, GO_PUSH); break;
++ case H_LENS: ui_go(SCR_PAGE, 1, GO_PUSH); break;
++ case H_SYSTEM: ui_go(SCR_PAGE, 2, GO_PUSH); break;
++ }
++}
++
++void home_key(int k)
++{
++ switch (k)
++ {
++ case FK_UP: case FK_WHEEL_L:
++ home_sel = (home_sel + H_COUNT - 1) % H_COUNT;
++ break;
++ case FK_DOWN: case FK_WHEEL_R:
++ home_sel = (home_sel + 1) % H_COUNT;
++ break;
++ case FK_SET: case FK_RIGHT:
++ home_open(home_sel);
++ break;
++ case FK_MENU: case FK_HOME:
++ ui_leave();
++ break;
++ case FK_PLAY:
++ ui_go(SCR_PRINTS, 0, GO_FADE);
++ break;
++ }
++ home_list = 1;
++ ui_damage(LIST_Y, LIST_Y + H_COUNT * ROW_H);
++}
++
++int home_update(int dt)
++{
++ int moving = 0;
++ home_t += dt;
++ if (spring_step(&home_hl, home_sel, dt, 3.4f, 0.82f))
++ {
++ home_list = 1;
++ ui_damage(LIST_Y, LIST_Y + H_COUNT * ROW_H);
++ moving = 1;
++ }
++ /* the canister keeps turning, slowly enough that a dozen frames a
++ * second of only its corner of the screen look smooth */
++ if (ui_roll.loaded && home_t - home_spun >= 80)
++ {
++ int x0, y0, x1, y1;
++ card_canister_box(&x0, &y0, &x1, &y1);
++ home_spun = home_t;
++ home_spin = 1;
++ ui_damage(y0, y1);
++ moving = 1;
++ }
++ return moving;
++}
++
++static void home_row(int i, int y, int selected)
++{
++ static const char *titles[H_COUNT] = { "Film", "Roll", "Darkroom", "Viewfinder", "Lens", "System" };
++ static const int icons[H_COUNT] = { ICON_FILM, ICON_ROLL, ICON_PRINTS, ICON_FINDER, ICON_LENS, ICON_SYSTEM };
++ char sub[80];
++ char ap[8];
++ switch (i)
++ {
++ case H_FILM:
++ snprintf(sub, sizeof(sub), "%s", roll_active() ? "Change film (rewinds this roll)" : "Choose a stock and load a roll");
++ break;
++ case H_ROLL:
++ if (ui_roll.loaded)
++ snprintf(sub, sizeof(sub), "Roll %03d " T_DOT " %d of %d", ui_roll.number, ui_roll.shot, ui_roll.exposures);
++ else
++ snprintf(sub, sizeof(sub), "No film in the camera");
++ break;
++ case H_DARK:
++ snprintf(sub, sizeof(sub), "Develop your rolls " T_DOT " your prints");
++ break;
++ case H_FINDER:
++ snprintf(sub, sizeof(sub), "HUD %s " T_DOT " wind %s", fos_port_get(FS_HUD) ? "on" : "off",
++ fos_port_get(FS_WIND) == 0 ? "off" : fos_port_get(FS_WIND) == 1 ? "reminder" : "locks shutter");
++ break;
++ case H_LENS:
++ fos_format_fstop(ap, sizeof(ap), fos_port_get(FS_FSTOP));
++ if (fos_port_lens_manual())
++ snprintf(sub, sizeof(sub), "Manual lens " T_DOT " f/%s", ap);
++ else
++ snprintf(sub, sizeof(sub), "%s", fos_port_lens_name());
++ break;
++ case H_SYSTEM:
++ snprintf(sub, sizeof(sub), "Screen colour, start screen, Canon menu");
++ break;
++ }
++ int x = LIST_X + 20;
++ fcol ic = selected ? C_ACCENT : C_TEXT3;
++ ui_icon(icons[i], x + 14, y + ROW_H / 2, ic, OPAQUE);
++ fos_text(cv, &fos_font_mdb, x + 46, y + 28, titles[i], selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
++ fos_text(cv, &fos_font_sm, x + 46, y + 49, sub, C_TEXT3, OPAQUE, 0);
++ fos_tri(cv, LIST_X + LIST_W - 22, y + ROW_H / 2, 8, 0, selected ? C_TEXT2 : FC(RAMP_GRAY, 60), OPAQUE);
++}
++
++void home_draw()
++{
++ int x0, y0, x1, y1;
++ card_canister_box(&x0, &y0, &x1, &y1);
++ if (ui_clobbered) home_full = 1;
++ if (!home_full)
++ {
++ /* the card and the list sit side by side: each is redrawn alone */
++ struct fos_canvas save = *cv;
++ if (home_spin)
++ {
++ home_spin = 0;
++ ui_bg_restore(x0, y0, x1 - x0, y1 - y0);
++ fos_clip(cv, x0, y0, x1, y1);
++ card_canister(home_t);
++ *cv = save;
++ ui_damage(y0, y1);
++ }
++ if (home_list)
++ {
++ int ly1 = LIST_Y + H_COUNT * ROW_H;
++ ui_bg_restore(LIST_X, LIST_Y, LIST_W, ly1 - LIST_Y);
++ fos_clip(cv, LIST_X, LIST_Y, LIST_X + LIST_W, ly1);
++ row_highlight(LIST_X, LIST_W, LIST_Y + home_hl.x * ROW_H, ROW_H);
++ for (int i = 0; i < H_COUNT; i++)
++ home_row(i, LIST_Y + i * ROW_H, i == home_sel);
++ *cv = save;
++ ui_damage(LIST_Y, ly1);
++ home_list = 0;
++ }
++ return;
++ }
++ home_full = 0;
++ home_list = 0;
++ home_spin = 0;
++ ui_clobbered = 0;
++ ui_damage_all();
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ card_canister(home_t);
++ row_highlight(LIST_X, LIST_W, LIST_Y + home_hl.x * ROW_H, ROW_H);
++ for (int i = 0; i < H_COUNT; i++)
++ home_row(i, LIST_Y + i * ROW_H, i == home_sel);
++}
++
++/* ---------------------------------------------------------------- settings pages */
++
++enum { IT_TOGGLE, IT_CHOICE, IT_FSTOP, IT_ACTION, IT_INFO, IT_LEVEL, IT_PAGE };
++
++#define PAGE_SYSTEM 2
++#define PAGE_SCREEN 3
++#define SYS_SCREEN_ROW 2 /* where Screen colour sits in System */
++#define ACT_SCR_RESET 100 /* handled here, not by the port */
++
++struct item
++{
++ const char *label;
++ int kind;
++ int setting; /* FS_*, or FA_* for actions */
++ const char *const *choices;
++ int n;
++ const char *help;
++};
++
++static const char *const wind_choices[] = { "Off", "Reminder", "Locks shutter" };
++static const char *const apkey_choices[] = { "Dial in Av", "Up / Down", "Menu only" };
++static const char *const start_choices[] = { "Off", "When no film", "Always" };
++
++static const struct item finder_items[] =
++{
++ { "Viewfinder HUD", IT_TOGGLE, FS_HUD, 0, 0, "SLR-style meter needle and LED readout over LiveView." },
++ { "LEDs on half-press", IT_TOGGLE, FS_LEDS, 0, 0, "Like a real SLR: the readout lights only while metering." },
++ { "Focusing screen", IT_TOGGLE, FS_FOCUS, 0, 0, "A split-image circle and microprism collar (decoration only)." },
++ { "Wind lever", IT_CHOICE, FS_WIND, wind_choices, 3, "After each frame press SET to wind on. Locking is experimental." },
++};
++
++static const struct item lens_items[] =
++{
++ { "Lens", IT_INFO, -1, 0, 0, "Adapted manual lenses report no aperture: set it here." },
++ { "Aperture", IT_FSTOP, FS_FSTOP, 0, 0, "The f-stop on the lens ring. Shown in the HUD, logged for the lab." },
++ { "Widest aperture", IT_FSTOP, FS_LENS_WIDE, 0, 0, "Your manual lens' widest f-stop: the ring stops there." },
++ { "Aperture control", IT_CHOICE, FS_APKEYS, apkey_choices, 3, "How to turn the aperture ring in LiveView." },
++};
++
++static const struct item system_items[] =
++{
++ { "Start screen", IT_CHOICE, FS_STARTUP, start_choices, 3, "The film shelf when the camera turns on." },
++ { "Boot animation", IT_TOGGLE, FS_BOOTANIM, 0, 0, "The aperture opening on the name at power on." },
++ { "Screen colour", IT_PAGE, PAGE_SCREEN, 0, 0, "Match these colours to what you see around you." },
++ { "PLAY shows prints only", IT_TOGGLE, FS_PLAYLOCK, 0, 0, "Canon's playback would show frames the darkroom hasn't developed." },
++ { "Re-apply film settings", IT_ACTION, FA_REAPPLY, 0, 0, "After changing picture style, white balance or ISO by hand." },
++ { "Canon menu", IT_ACTION, FA_CANON_MENU, 0, 0, "Leave and open the camera's own menu (format card, RAW...)." },
++ { "Debug log", IT_TOGGLE, FS_DEBUG, 0, 0, "Writes ML/FILMROLL.LOG for troubleshooting." },
++ { "Support " FOS_NAME, IT_INFO, -3, 0, 0, "Scan the code with your phone to buy the developer a coffee." },
++ { "About", IT_INFO, -2, 0, 0, FOS_NAME " " T_DOT " Barlow typeface by Jeremy Tribby (SIL OFL)" },
++};
++
++static const char *const std_choices[] = { "Canon", "Rec.709" };
++
++static const struct item screen_items[] =
++{
++ { "Conversion", IT_CHOICE, FS_SCR_STD, std_choices, 2, "How colours are sent to the screen. Canon's way suits the EOS M." },
++ { "Colour", IT_LEVEL, FS_SCR_SAT, 0, 0, "Less or more saturated." },
++ { "Warmth", IT_LEVEL, FS_SCR_WARM, 0, 0, "Towards blue or towards amber, white included." },
++ { "Brightness", IT_LEVEL, FS_SCR_BRIGHT, 0, 0, "Deeper or lighter mid tones; black and white stay." },
++ { "Reset", IT_ACTION, ACT_SCR_RESET, 0, 0, "Back to the colours as designed." },
++};
++
++static const struct { const char *title; const char *sub; const struct item *items; int n; } pages[] =
++{
++ { "Viewfinder", "What you see in LiveView while you shoot", finder_items, 4 },
++ { "Lens", "Aperture for manual lenses", lens_items, 4 },
++ { "System", "Screen colour, start up and the Canon menu", system_items, 9 },
++ { "Screen colour", "Live: the whole film OS changes as you go", screen_items, 5 },
++};
++
++static int page, page_sel, page_top;
++static struct spring page_hl, page_scroll, knob[8];
++static int help_fade; /* ms since the selection changed */
++
++#define P_LIST_Y 118
++#define P_ROW_H 46
++#define P_ROWS 6
++#define P_X 24
++#define P_W 404
++
++/* the preview panel beside the list */
++#define PV_X 444
++#define PV_Y P_LIST_Y
++#define PV_W 252
++#define PV_H (P_ROWS * P_ROW_H)
++
++static struct spring lens_open; /* the aperture in the lens preview, 0..1 */
++
++/* what the next frame redraws */
++enum { D_LIST = 1, D_PREV = 2, D_HELP = 4, D_ALL = 8 };
++static int pg_dirty = D_ALL;
++#define LIST_RECT_Y0 (P_LIST_Y - 4)
++#define LIST_RECT_Y1 (P_LIST_Y + P_ROWS * P_ROW_H + 16)
++#define HELP_RECT_Y0 (HINTS_Y - 32)
++
++/* how open the blades look for fos_fstops[index]: a stop closes the
++ * opening by a constant factor, slower than real so f/16 still shows */
++static float fstop_open(int index)
++{
++ float stops = (index - 1) / 3.0f;
++ return 0.94f * expf(-0.30f * stops);
++}
++
++static void page_bake()
++{
++ ui_bg_plain();
++ ui_to_bg(1);
++ ui_status_bar("SETTINGS");
++ fos_text(cv, &fos_font_lg, P_X + 4, 80, pages[page].title, C_TEXT, OPAQUE, 0);
++ fos_text(cv, &fos_font_sm, P_X + 4, 104, pages[page].sub, C_TEXT3, OPAQUE, 0);
++ struct hint h[] = { { "^v", "Select" }, { "<>", "Change" }, { "SET", "Toggle" }, { "MENU", "Back" } };
++ struct hint hs[] = { { "^v", "Select" }, { "<>", "Adjust" }, { "MENU", "Back" } };
++ if (page == PAGE_SCREEN) ui_hints(hs, 3);
++ else ui_hints(h, 4);
++ fos_rrect(cv, PV_X, PV_Y, PV_W, PV_H, 16, FC(RAMP_GRAY, 15), OPAQUE);
++ static const char *captions[] = { "LIVEVIEW PREVIEW", "APERTURE", 0, "TEST CHART" };
++ if (captions[page]) /* System's panel captions itself */
++ fos_text_c(cv, &fos_font_xs, PV_X + PV_W / 2, PV_Y + PV_H - 14, captions[page], C_TEXT3, OPAQUE, 48);
++ ui_to_bg(0);
++}
++
++static int item_value(const struct item *it)
++{
++ return it->setting >= 0 && it->kind != IT_ACTION && it->kind != IT_PAGE ? fos_port_get(it->setting) : 0;
++}
++
++/* where an item's knob springs to: a switch 0 / 1, a slider its value */
++static float knob_target(const struct item *it)
++{
++ if (it->kind == IT_LEVEL) return item_value(it);
++ return it->kind == IT_TOGGLE && item_value(it) ? 1 : 0;
++}
++
++void page_enter(int arg)
++{
++ /* from home: a page; between pages: page | row << 4 */
++ if (ui_from() == SCR_HOME || ui_from() == SCR_PAGE)
++ {
++ page = fos_clamp(arg & 15, 0, PAGE_SCREEN);
++ page_sel = fos_clamp(arg >> 4, 0, pages[page].n - 1);
++ }
++ page_top = page_sel >= P_ROWS ? page_sel - P_ROWS + 1 : 0;
++ page_hl.x = page_sel; page_hl.v = 0;
++ page_scroll.x = page_top; page_scroll.v = 0;
++ for (int i = 0; i < pages[page].n && i < 8; i++)
++ {
++ knob[i].x = knob_target(&pages[page].items[i]);
++ knob[i].v = 0;
++ }
++ help_fade = 1000;
++ lens_open.x = fstop_open(fos_port_get(FS_FSTOP)); lens_open.v = 0;
++ pg_dirty = D_ALL;
++ page_bake();
++}
++
++static void change(const struct item *it, int dir)
++{
++ int v = fos_port_get(it->setting);
++ switch (it->kind)
++ {
++ case IT_TOGGLE:
++ fos_port_set(it->setting, !v);
++ break;
++ case IT_CHOICE:
++ fos_port_set(it->setting, fos_clamp(v + dir, 0, it->n - 1));
++ break;
++ case IT_LEVEL:
++ fos_port_set(it->setting, fos_clamp(v + dir, -FOS_SCR_STEPS, FOS_SCR_STEPS));
++ break;
++ case IT_FSTOP:
++ {
++ int lo = it->setting == FS_FSTOP ? fos_port_get(FS_LENS_WIDE) : 0;
++ fos_port_set(it->setting, fos_clamp(v + dir, lo, fos_nfstops - 1));
++ if (it->setting == FS_LENS_WIDE && fos_port_get(FS_FSTOP) < fos_port_get(FS_LENS_WIDE))
++ fos_port_set(FS_FSTOP, fos_port_get(FS_LENS_WIDE));
++ break;
++ }
++ }
++}
++
++static void page_damage(int what)
++{
++ pg_dirty |= what;
++ if (what & D_ALL) ui_damage_all();
++ if (what & (D_LIST | D_PREV)) ui_damage(LIST_RECT_Y0, LIST_RECT_Y1);
++ if (what & D_HELP) ui_damage(HELP_RECT_Y0, HINTS_Y);
++}
++
++void page_key(int k)
++{
++ const struct item *items = pages[page].items;
++ int n = pages[page].n;
++ const struct item *it = &items[page_sel];
++ /* moving the selection redraws the list and the help (and the lens,
++ * which shows the selected f-stop); changing a value, list and preview */
++ int dirty = k == FK_UP || k == FK_DOWN || k == FK_WHEEL_L || k == FK_WHEEL_R
++ ? D_LIST | D_HELP | (page == 1 || page == PAGE_SYSTEM ? D_PREV : 0)
++ : k == FK_LEFT || k == FK_RIGHT || k == FK_SET ? D_LIST | D_PREV : D_ALL;
++ switch (k)
++ {
++ case FK_UP: case FK_WHEEL_L:
++ if (page_sel > 0) { page_sel--; help_fade = 0; }
++ break;
++ case FK_DOWN: case FK_WHEEL_R:
++ if (page_sel < n - 1) { page_sel++; help_fade = 0; }
++ break;
++ case FK_LEFT: case FK_RIGHT:
++ if (it->kind == IT_TOGGLE) change(it, 0);
++ else if (it->kind == IT_CHOICE || it->kind == IT_FSTOP || it->kind == IT_LEVEL)
++ change(it, k == FK_RIGHT ? 1 : -1);
++ else if (it->kind == IT_PAGE && k == FK_RIGHT)
++ ui_go(SCR_PAGE, it->setting, GO_PUSH);
++ break;
++ case FK_SET:
++ if (it->kind == IT_TOGGLE) change(it, 0);
++ else if (it->kind == IT_CHOICE)
++ fos_port_set(it->setting, (fos_port_get(it->setting) + 1) % it->n);
++ else if (it->kind == IT_FSTOP) change(it, 1);
++ else if (it->kind == IT_PAGE) ui_go(SCR_PAGE, it->setting, GO_PUSH);
++ else if (it->kind == IT_ACTION && it->setting == ACT_SCR_RESET)
++ {
++ fos_port_set(FS_SCR_STD, 0);
++ fos_port_set(FS_SCR_SAT, 0);
++ fos_port_set(FS_SCR_WARM, 0);
++ fos_port_set(FS_SCR_BRIGHT, 0);
++ ui_toast("Screen colour as designed");
++ }
++ else if (it->kind == IT_ACTION)
++ {
++ fos_port_action(it->setting, 0, 0);
++ if (it->setting == FA_CANON_MENU) ui_leave();
++ if (it->setting == FA_REAPPLY)
++ ui_toast(ui_roll.loaded ? "Film settings go in when you return to the camera" : "No film loaded");
++ }
++ break;
++ case FK_MENU:
++ if (page == PAGE_SCREEN) ui_go(SCR_PAGE, PAGE_SYSTEM | SYS_SCREEN_ROW << 4, GO_POP);
++ else ui_go(SCR_HOME, page + H_FINDER, GO_POP);
++ break;
++ case FK_HOME: case FK_PLAY:
++ ui_leave();
++ break;
++ }
++ if (page_sel < page_top) page_top = page_sel;
++ if (page_sel >= page_top + P_ROWS) page_top = page_sel - P_ROWS + 1;
++ page_damage(dirty);
++}
++
++int page_update(int dt)
++{
++ int dirty = 0;
++ if (spring_step(&page_hl, page_sel, dt, 3.6f, 0.82f)) dirty |= D_LIST;
++ if (spring_step(&page_scroll, page_top, dt, 3.0f, 0.95f)) dirty |= D_LIST;
++ for (int i = 0; i < pages[page].n && i < 8; i++)
++ if (spring_step(&knob[i], knob_target(&pages[page].items[i]), dt, 4.0f, 0.75f))
++ dirty |= D_LIST | (page == 0 ? D_PREV : 0); /* the viewfinder preview follows the switches */
++ if (help_fade < 400) { help_fade += dt; dirty |= D_HELP; }
++ if (page == 1)
++ {
++ const struct item *it = &pages[page].items[page_sel];
++ int idx = it->setting == FS_LENS_WIDE ? fos_port_get(FS_LENS_WIDE) : fos_port_get(FS_FSTOP);
++ if (spring_step(&lens_open, fstop_open(idx), dt, 2.6f, 0.72f)) dirty |= D_PREV;
++ }
++ page_damage(dirty);
++ return dirty != 0;
++}
++
++/* ---- the previews */
++
++/* a dusk scene through the viewfinder, with the HUD as set */
++static void preview_finder()
++{
++ int sx = PV_X + 12, sy = PV_Y + 14, sw = PV_W - 24, sh = 152;
++ int horizon = sy + sh * 64 / 100;
++ fos_vgrad(cv, sx, sy, sw, horizon - sy, RAMP_AMBER, LV12(64), LV12(178));
++ fos_vgrad(cv, sx, horizon, sw, sy + sh - horizon, RAMP_GRAY, LV12(16), LV12(8));
++ fos_disc(cv, (sx + 74) * 256, (horizon - 26) * 256, 24 * 256, FC(RAMP_AMBER, 214), 110);
++ fos_disc(cv, (sx + 74) * 256, (horizon - 26) * 256, 15 * 256, FC(RAMP_GRAY, 246), OPAQUE);
++ /* hills */
++ int hills[][6] = {
++ { sx - 20, horizon + 8, sx + 70, horizon - 16, sx + 150, horizon + 8 },
++ { sx + 90, horizon + 8, sx + 170, horizon - 28, sx + sw + 30, horizon + 8 },
++ };
++ for (int i = 0; i < 2; i++)
++ {
++ int q[6];
++ for (int j = 0; j < 6; j++) q[j] = hills[i][j] * 256;
++ fos_convex(cv, q, 3, FC(RAMP_GRAY, 12), OPAQUE);
++ }
++ fos_fill(cv, sx, horizon + 8, sw, sy + sh - horizon - 8, FC(RAMP_GRAY, 12));
++
++ float hud = knob[0].x, leds_half = knob[1].x, focus = knob[2].x;
++ int wind = fos_port_get(FS_WIND);
++ if (focus > 0.01f)
++ {
++ int cx = (sx + (sw - 20) / 2) * 256, cy = (sy + (sh - 14) / 2) * 256;
++ fos_ring(cv, cx, cy, 21 * 256, 256, FC(RAMP_GRAY, 210), (int) (focus * 150));
++ fos_ring(cv, cx, cy, 9 * 256, 300, FC(RAMP_GRAY, 250), (int) (focus * 230));
++ fos_line(cv, cx - 9 * 256, cy, cx + 9 * 256, cy, 300, FC(RAMP_GRAY, 250), (int) (focus * 230));
++ }
++ if (hud > 0.01f)
++ {
++ int a = (int) (hud * 256);
++ /* meter strip and LED strip, as on the camera but small */
++ fos_blend(cv, sx + sw - 20, sy, 20, sh - 14, FC(RAMP_GRAY, 0), a);
++ fos_blend(cv, sx, sy + sh - 14, sw, 14, FC(RAMP_GRAY, 0), a);
++ for (int i = 0; i < 10; i++)
++ fos_fill(cv, sx + sw - 12, sy + 8 + i * 12, 5, 1, FC(RAMP_GRAY, 120 * a / 256));
++ fos_tri(cv, sx + sw - 16, sy + 8 + 5 * 12, 6, 0, FC(RAMP_RED, 150), a);
++ int lit = (int) (150 - leds_half * 100);
++ fos_text(cv, &fos_font_xs, sx + 50, sy + sh - 3, "125 f4 12", FC(RAMP_RED, lit), a, 16);
++ if (wind)
++ fos_text(cv, &fos_font_xs, sx + 6, sy + sh - 3, "WIND", FC(RAMP_RED, 150), a, 16);
++ }
++ /* what that means */
++ const char *l1 = !fos_port_get(FS_HUD) ? "Canon's own screen only" :
++ fos_port_get(FS_LEDS) ? "LEDs light on half-press" : "LEDs always lit";
++ const char *l2 = wind == 0 ? "No wind lever" : wind == 1 ? "SET winds on after each frame" : "Shutter locked until you wind";
++ fos_text_c(cv, &fos_font_sm, PV_X + PV_W / 2, sy + sh + 32, l1, C_TEXT2, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_sm, PV_X + PV_W / 2, sy + sh + 54, l2, C_TEXT3, OPAQUE, 0);
++}
++
++static void preview_lens()
++{
++ int cx = PV_X + PV_W / 2, cy = PV_Y + 90;
++ int open = (int) (clampf(lens_open.x, 0.02f, 1) * 4096);
++ ui_aperture(cx, cy, 68, open, 3000 + (4096 - open) * 3);
++ const struct item *it = &pages[page].items[page_sel];
++ int idx = it->setting == FS_LENS_WIDE ? fos_port_get(FS_LENS_WIDE) : fos_port_get(FS_FSTOP);
++ char ap[8], b[24];
++ fos_format_fstop(ap, sizeof(ap), idx);
++ snprintf(b, sizeof(b), "f/%s", ap);
++ fos_text_c(cv, &fos_font_xl, cx, cy + 126, b, C_TEXT, OPAQUE, 0);
++ if (it->setting == FS_LENS_WIDE)
++ snprintf(b, sizeof(b), "WIDEST THE LENS OPENS");
++ else
++ snprintf(b, sizeof(b), "SET ON THE RING");
++ fos_text_c(cv, &fos_font_xs, cx, cy + 148, b, C_ACCENT2, OPAQUE, 32);
++}
++
++/* swatches of the labels' inks and a grey wedge: compare with the boxes */
++static void preview_chart()
++{
++ static const struct { int ramp, level; const char *name; } inks[8] =
++ {
++ { RAMP_AMBER, 190, "GOLD" }, { RAMP_RED, 150, "RED" }, { RAMP_ORANGE, 160, "PORTRA" }, { RAMP_CRIMSON, 128, "EKTAR" },
++ { RAMP_GREEN, 140, "FUJI" }, { RAMP_VIOLET, 118, "VELVIA" }, { RAMP_BLUE, 160, "ILFORD" }, { RAMP_LEADER, 120, "FILM" },
++ };
++ int x0 = PV_X + 14, y0 = PV_Y + 16, sw = 50, gap = 6;
++ for (int i = 0; i < 8; i++)
++ {
++ int x = x0 + (i % 4) * (sw + gap), y = y0 + (i / 4) * 74;
++ fos_rrect(cv, x, y, sw, 44, 8, FC(inks[i].ramp, inks[i].level), OPAQUE);
++ fos_text_c(cv, &fos_font_xs, x + sw / 2, y + 60, inks[i].name, C_TEXT3, OPAQUE, 16);
++ }
++ /* eleven steps from black to white: the darkest two should still differ */
++ int wy = y0 + 160, ww = PV_W - 28;
++ for (int i = 0; i < 11; i++)
++ {
++ int xa = x0 + i * ww / 11, xb = x0 + (i + 1) * ww / 11;
++ fos_fill(cv, xa, wy, xb - xa, 36, FC(RAMP_GRAY, i * 255 / 10));
++ }
++ fos_rrect_line(cv, x0 - 1, wy - 1, ww + 2, 38, 2, 1, FC(RAMP_GRAY, 60), OPAQUE);
++ fos_text(cv, &fos_font_xs, x0, wy + 54, "0", C_TEXT3, OPAQUE, 0);
++ fos_text_r(cv, &fos_font_xs, x0 + ww, wy + 54, "100%", C_TEXT3, OPAQUE, 0);
++}
++
++/* the donation links as QR codes (ML/DATA/FOSQR.BIN, see tools/genqr.py),
++ * read the first time they are shown */
++struct qr { char label[48], url[80]; int n; const uint8_t *bits; };
++static struct qr qrs[2];
++static int nqr = -1;
++
++static void qr_load()
++{
++ char path[64];
++ snprintf(path, sizeof(path), "%sML/DATA/FOSQR.BIN", fos_port_card());
++ nqr = 0;
++ void *f = fos_port_open(path, 0);
++ if (!f) return;
++ static uint8_t blob[1024];
++ int size = fos_port_read(f, blob, sizeof(blob));
++ fos_port_close(f);
++ if (size < 8 || memcmp(blob, "FOSQ", 4)) return;
++ int n = blob[4], p = 8;
++ for (int i = 0; i < n && i < 2; i++)
++ {
++ if (p + 132 > size) break;
++ struct qr *q = &qrs[nqr];
++ memcpy(q->label, blob + p, 48); q->label[47] = 0;
++ memcpy(q->url, blob + p + 48, 80); q->url[79] = 0;
++ q->n = blob[p + 128] | blob[p + 129] << 8;
++ q->bits = blob + p + 132;
++ p += 132 + (q->n * q->n + 7) / 8;
++ if (q->n < 21 || q->n > 61 || p > size) break;
++ nqr++;
++ }
++}
++
++/* a code centred on (cx, cy), its label at base */
++static void draw_qr(const struct qr *q, int cx, int cy, int mod, int base)
++{
++ int quiet = 2, side = (q->n + 2 * quiet) * mod, x0 = cx - side / 2, y = cy - side / 2;
++ fos_fill(cv, x0, y, side, side, FC(RAMP_GRAY, 245));
++ for (int r = 0; r < q->n; r++)
++ for (int c = 0; c < q->n; c++)
++ {
++ int i = r * q->n + c;
++ if (q->bits[i >> 3] >> (7 - (i & 7)) & 1)
++ fos_fill(cv, x0 + (quiet + c) * mod, y + (quiet + r) * mod, mod, mod, FC(RAMP_GRAY, 8));
++ }
++ const struct fos_font *f = fos_text_w(&fos_font_mdb, q->label, 0) <= PV_W - 24 ? &fos_font_mdb : &fos_font_sm;
++ fos_text_c(cv, f, cx, base, q->label, C_TEXT, OPAQUE, 0);
++}
++
++static void preview_support()
++{
++ int cx = PV_X + PV_W / 2;
++ if (nqr < 0) qr_load();
++ if (nqr == 0)
++ {
++ ui_aperture(cx, PV_Y + 80, 40, 1700, 5000);
++ fos_text_c(cv, &fos_font_lg, cx, PV_Y + 162, "Thank you", C_TEXT, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_sm, cx, PV_Y + 186, "for shooting film with " FOS_NAME, C_TEXT2, OPAQUE, 0);
++ }
++ else if (nqr == 1)
++ draw_qr(&qrs[0], cx, PV_Y + 116, 200 / (qrs[0].n + 4), PV_Y + 238);
++ else
++ for (int i = 0; i < 2; i++)
++ draw_qr(&qrs[i], cx + (i ? 62 : -62), PV_Y + 116, 112 / (qrs[i].n + 4), PV_Y + 190);
++ fos_text_c(cv, &fos_font_xs, cx, PV_Y + PV_H - 14, "SUPPORT", C_TEXT3, OPAQUE, 48);
++}
++
++static void preview_about()
++{
++ int cx = PV_X + PV_W / 2;
++ fos_text_c(cv, &fos_font_xs, cx, PV_Y + PV_H - 14, "ABOUT", C_TEXT3, OPAQUE, 48);
++ ui_aperture(cx, PV_Y + 64, 40, 1700, 5000);
++ fos_text_c(cv, &fos_font_lg, cx, PV_Y + 142, FOS_NAME, C_TEXT, OPAQUE, 64);
++ char m[48];
++ snprintf(m, sizeof(m), "Film OS for the %s", fos_port_model());
++ fos_text_c(cv, &fos_font_sm, cx, PV_Y + 166, m, C_TEXT2, OPAQUE, 0);
++ char b[48];
++ snprintf(b, sizeof(b), "VERSION %s " T_DOT " %s", fos_port_version(), __DATE__);
++ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 196, b, C_TEXT3, OPAQUE, 24);
++ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 214, "MAGIC LANTERN INSIDE", C_TEXT3, OPAQUE, 24);
++ fos_text_c(cv, &fos_font_xs, cx, PV_Y + 232, "BARLOW TYPEFACE " T_DOT " SIL OFL", C_TEXT3, OPAQUE, 24);
++}
++
++/* an on / off switch; k = 0..1 where the knob is */
++static void toggle_switch(int rx, int cy, float k)
++{
++ int w = 44, h = 24;
++ int x = rx - w, y = cy - h / 2;
++ int on_lv = (int) (k * 186);
++ fos_rrect(cv, x, y, w, h, h / 2, k > 0.5f ? FC(RAMP_AMBER, 40 + on_lv * 146 / 186) : FC(RAMP_GRAY, 40 + (int) ((1 - k) * 12)), OPAQUE);
++ int kx = x + 12 + (int) (k * (w - 24));
++ fos_disc(cv, kx * 256, cy * 256, 9 * 256, FC(RAMP_GRAY, 244), OPAQUE);
++}
++
++/* a -6..6 slider ending at rx: notches, a knob at k, the value beside it */
++static void level_slider(int rx, int cy, float k, int value, int selected)
++{
++ int w = 150, x0 = rx - w;
++ fos_fill(cv, x0, cy, w, 2, FC(RAMP_GRAY, 40));
++ for (int i = -FOS_SCR_STEPS; i <= FOS_SCR_STEPS; i++)
++ {
++ int x = x0 + (i + FOS_SCR_STEPS) * w / (2 * FOS_SCR_STEPS);
++ int big = i == 0;
++ fos_fill(cv, x, cy - (big ? 6 : 3), 1, big ? 13 : 7, FC(RAMP_GRAY, big ? 120 : 60));
++ }
++ /* from the middle to the knob, lit */
++ int kx = x0 + (int) ((k + FOS_SCR_STEPS) * w / (2 * FOS_SCR_STEPS));
++ int mid = x0 + w / 2;
++ if (kx != mid)
++ fos_fill(cv, kx < mid ? kx : mid, cy, kx < mid ? mid - kx : kx - mid, 2, selected ? C_ACCENT : C_ACCENT2);
++ fos_disc(cv, kx * 256 + 128, cy * 256 + 128, 8 * 256, selected ? FC(RAMP_GRAY, 244) : FC(RAMP_GRAY, 170), OPAQUE);
++ char b[16];
++ if (value > 0) snprintf(b, sizeof(b), "+%d", value);
++ else if (value < 0) snprintf(b, sizeof(b), T_NDASH "%d", -value);
++ else snprintf(b, sizeof(b), "0");
++ fos_text_r(cv, &fos_font_mdb, x0 - 16, cy + 7, b, selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
++}
++
++static void page_row(const struct item *it, int i, int y, int selected)
++{
++ int base = y + 30;
++ fos_text(cv, &fos_font_md, P_X + 22, base, it->label, selected ? C_TEXT : C_TEXT2, OPAQUE, 0);
++ int rx = P_X + P_W - 20;
++ char b[48];
++ switch (it->kind)
++ {
++ case IT_TOGGLE:
++ toggle_switch(rx, y + P_ROW_H / 2, knob[i].x);
++ break;
++ case IT_CHOICE:
++ case IT_FSTOP:
++ {
++ int v = fos_port_get(it->setting);
++ if (it->kind == IT_CHOICE)
++ snprintf(b, sizeof(b), "%s", it->choices[fos_clamp(v, 0, it->n - 1)]);
++ else
++ {
++ char ap[8];
++ fos_format_fstop(ap, sizeof(ap), v);
++ snprintf(b, sizeof(b), "f/%s", ap);
++ }
++ int w = fos_text_w(&fos_font_mdb, b, 0);
++ fcol vc = selected ? C_ACCENT : C_TEXT2;
++ if (selected)
++ {
++ fos_tri(cv, rx - w - 18, y + P_ROW_H / 2 - 1, 7, 2, C_TEXT3, OPAQUE);
++ fos_tri(cv, rx - 4, y + P_ROW_H / 2 - 1, 7, 0, C_TEXT3, OPAQUE);
++ rx -= 14;
++ }
++ fos_text_r(cv, &fos_font_mdb, rx, base, b, vc, OPAQUE, 0);
++ break;
++ }
++ case IT_ACTION:
++ case IT_PAGE:
++ fos_tri(cv, rx - 4, y + P_ROW_H / 2 - 1, 8, 0, selected ? C_ACCENT : C_TEXT3, OPAQUE);
++ break;
++ case IT_LEVEL:
++ level_slider(rx, y + P_ROW_H / 2, knob[i].x, fos_port_get(it->setting), selected);
++ break;
++ case IT_INFO:
++ if (it->setting == -1)
++ snprintf(b, sizeof(b), "%s", fos_port_lens_manual() ? "Manual" : fos_port_lens_name());
++ else if (it->setting == -3)
++ {
++ if (nqr < 0) qr_load();
++ snprintf(b, sizeof(b), "%s", nqr > 0 ? "Scan the code" : "");
++ }
++ else
++ snprintf(b, sizeof(b), "%s", fos_port_version());
++ fos_text_r(cv, &fos_font_md, rx, base, b, C_TEXT3, OPAQUE, 0);
++ break;
++ }
++}
++
++void page_draw()
++{
++ const struct item *items = pages[page].items;
++ int n = pages[page].n;
++ int what = ui_clobbered ? D_ALL : pg_dirty;
++ pg_dirty = 0;
++ struct fos_canvas save = *cv;
++ if (what & D_ALL)
++ {
++ ui_clobbered = 0;
++ ui_damage_all();
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ what = D_LIST | D_PREV | D_HELP;
++ }
++ else
++ {
++ /* only the parts that change, each from the background */
++ if (what & D_LIST) ui_bg_restore(0, LIST_RECT_Y0, PV_X - 4, LIST_RECT_Y1 - LIST_RECT_Y0);
++ if (what & D_PREV) ui_bg_restore(PV_X, PV_Y, PV_W, PV_H);
++ if (what & D_HELP) ui_bg_restore(0, HELP_RECT_Y0, FOS_W, HINTS_Y - HELP_RECT_Y0);
++ }
++ if (what & D_PREV)
++ {
++ fos_clip(cv, PV_X, PV_Y, PV_X + PV_W, PV_Y + PV_H);
++ if (page == 0) preview_finder();
++ else if (page == 1) preview_lens();
++ else if (page == PAGE_SCREEN) preview_chart();
++ else if (items[page_sel].setting == -3 && items[page_sel].kind == IT_INFO) preview_support();
++ else preview_about();
++ *cv = save;
++ }
++ if (what & D_HELP)
++ {
++ /* help for the selected row, fading in */
++ float a = clampf(help_fade / 260.0f, 0, 1);
++ if (!ui_toast_up())
++ fos_text(cv, &fos_font_sm, P_X + 22, HINTS_Y - 14, items[page_sel].help, C_TEXT3, (int) (ease_out(a) * 256), 0);
++ }
++ if (!(what & D_LIST)) return;
++ fos_clip(cv, 0, P_LIST_Y - 2, PV_X - 4, P_LIST_Y + P_ROWS * P_ROW_H + 2);
++ float top = page_scroll.x;
++ row_highlight(P_X, P_W, P_LIST_Y + (page_hl.x - top) * P_ROW_H, P_ROW_H);
++ for (int i = 0; i < n; i++)
++ {
++ float y = P_LIST_Y + (i - top) * P_ROW_H;
++ if (y < P_LIST_Y - P_ROW_H || y > P_LIST_Y + P_ROWS * P_ROW_H) continue;
++ page_row(&items[i], i, (int) (y + 0.5f), i == page_sel);
++ if (i < n - 1 && i != page_sel && i + 1 != page_sel)
++ fos_fill(cv, P_X + 22, (int) (y + 0.5f) + P_ROW_H, P_W - 44, 1, FC(RAMP_GRAY, 22));
++ }
++ *cv = save;
++ /* more below / above */
++ if (page_top + P_ROWS < n)
++ fos_tri(cv, P_X + P_W / 2, P_LIST_Y + P_ROWS * P_ROW_H + 8, 8, 1, C_TEXT3, OPAQUE);
++}
++
++/* ---------------------------------------------------------------- the roll */
++
++static struct spring dial; /* frames shown on the counter */
++static int asking_rewind;
++static struct spring sheet;
++static int rewinding, rewind_t;
++static int rewind_then; /* after rewinding: 1 develop it, 0 load a new roll */
++static int rewind_number;
++static int roll_sheet_drawn; /* the last frame had the sheet on it */
++
++#define DIAL_CX 176
++#define DIAL_CY 244
++#define DIAL_R 118
++
++static void roll_bake()
++{
++ ui_bg_plain();
++ ui_to_bg(1);
++ ui_status_bar("ROLL");
++ struct hint h1[] = { { "SET", "Rewind roll" }, { "MENU", "Back" } };
++ struct hint h2[] = { { "SET", "Load film" }, { "MENU", "Back" } };
++ if (ui_roll.loaded) ui_hints(h1, 2); else ui_hints(h2, 2);
++ ui_to_bg(0);
++}
++
++void roll_enter(int arg)
++{
++ fos_port_roll(&ui_roll);
++ dial.x = -1.5f; dial.v = 0; /* from "S", like a fresh counter */
++ roll_sheet_drawn = 0;
++ asking_rewind = arg == 1 && ui_roll.loaded; /* the roll has just been finished */
++ sheet.x = 0; sheet.v = 0;
++ rewinding = 0;
++ roll_bake();
++}
++
++void roll_key(int k)
++{
++ if (rewinding) return;
++ if (asking_rewind)
++ {
++ if (k == FK_SET || k == FK_INFO)
++ {
++ asking_rewind = 0;
++ rewinding = 1;
++ rewind_t = 0;
++ rewind_then = k == FK_SET;
++ rewind_number = ui_roll.number;
++ fos_port_action(FA_REWIND, 0, 0);
++ }
++ else if (k == FK_MENU) asking_rewind = 0;
++ ui_damage_all();
++ return;
++ }
++ switch (k)
++ {
++ case FK_SET:
++ if (ui_roll.loaded) asking_rewind = 1;
++ else ui_go(SCR_SHELF, 1, GO_PUSH);
++ break;
++ case FK_MENU:
++ ui_go(SCR_HOME, H_ROLL, GO_POP);
++ break;
++ case FK_HOME: case FK_PLAY:
++ ui_leave();
++ break;
++ }
++ ui_damage_all();
++}
++
++int roll_update(int dt)
++{
++ int moving = 0;
++ float target = ui_roll.loaded ? ui_roll.shot : -1.5f;
++ if (rewinding)
++ {
++ rewind_t += dt;
++ target = -1.5f;
++ moving = 1;
++ if (rewind_t > 1500)
++ {
++ fos_port_roll(&ui_roll);
++ if (rewind_then)
++ {
++ dark_queue_clear();
++ dark_queue_add(rewind_number);
++ ui_go(SCR_DEVELOP, 0, GO_FADE);
++ }
++ else ui_go(SCR_SHELF, 1, GO_PUSH);
++ return 1;
++ }
++ }
++ moving |= spring_step(&dial, target, dt, rewinding ? 1.2f : 0.9f, rewinding ? 1.0f : 0.78f);
++ moving |= spring_step(&sheet, asking_rewind ? 1 : 0, dt, 3.0f, 0.95f);
++ if (moving) ui_damage_all();
++ return moving;
++}
++
++/* the box the dial turns in */
++#define DIAL_BOX_X0 (DIAL_CX - DIAL_R - 18)
++#define DIAL_BOX_X1 (DIAL_CX + DIAL_R + 18)
++#define DIAL_BOX_Y0 (DIAL_CY - DIAL_R - 22)
++#define DIAL_BOX_Y1 (DIAL_CY + DIAL_R + 18)
++
++/* the frame counter: a dial of numbers turning under a fixed mark, like
++ * the little window on top of a film camera */
++static void counter_dial(float frames)
++{
++ int cx = DIAL_CX * 256, cy = DIAL_CY * 256;
++ fos_disc(cv, cx, cy, (DIAL_R + 14) * 256, FC(RAMP_GRAY, 15), OPAQUE);
++ fos_disc(cv, cx, cy, DIAL_R * 256, FC(RAMP_METAL, 26), OPAQUE);
++ fos_ring(cv, cx, cy, DIAL_R * 256, 512, FC(RAMP_METAL, 60), OPAQUE);
++ fos_ring(cv, cx, cy, (DIAL_R - 30) * 256, 256, FC(RAMP_METAL, 40), OPAQUE);
++ /* 7.5 degrees a frame; frame "frames" sits at the top */
++ const int per = 65536 * 75 / 3600;
++ for (int f = -2; f <= 40; f++)
++ {
++ float rel = f - frames;
++ if (absf(rel) > 22) continue;
++ int a = -16384 + (int) (rel * per);
++ int r = f % 2 == 0 || f < 0 ? DIAL_R - 16 : DIAL_R - 10;
++ int x = cx + fos_cos(a) * r / 16, y = cy + fos_sin(a) * r / 16;
++ float near = clampf(1 - absf(rel) / 3.0f, 0, 1);
++ if (f == -2)
++ fos_text_c(cv, &fos_font_mdb, x >> 8, (y >> 8) + 7, "S", FC(RAMP_RED, 140 + (int) (near * 40)), OPAQUE, 0);
++ else if (f >= 0 && f % 2 == 0)
++ {
++ char b[4];
++ snprintf(b, sizeof(b), "%d", f);
++ fcol c = near > 0.5f ? C_TEXT : FC(RAMP_GRAY, 120 + (int) (near * 100));
++ fos_text_c(cv, &fos_font_mdb, x >> 8, (y >> 8) + 7, b, c, OPAQUE, 0);
++ }
++ else if (f > 0)
++ fos_disc(cv, x, y, 2 * 256, FC(RAMP_GRAY, 120), OPAQUE);
++ int t0 = DIAL_R - 4, t1 = DIAL_R;
++ fos_line(cv, cx + fos_cos(a) * t0 / 16, cy + fos_sin(a) * t0 / 16, cx + fos_cos(a) * t1 / 16,
++ cy + fos_sin(a) * t1 / 16, 300, FC(RAMP_METAL, 90), OPAQUE);
++ }
++ /* the fixed mark */
++ fos_tri(cv, DIAL_CX, DIAL_CY - DIAL_R - 6, 12, 1, C_ACCENT, OPAQUE);
++ /* the middle: what the counter means */
++ char b[16];
++ int shown = (int) (frames + 0.5f);
++ if (frames < -0.75f) snprintf(b, sizeof(b), "S");
++ else snprintf(b, sizeof(b), "%d", shown < 0 ? 0 : shown);
++ fos_text_c(cv, &fos_font_num, DIAL_CX, DIAL_CY + 26, b, C_TEXT, OPAQUE, 0);
++ fos_text_c(cv, &fos_font_xs, DIAL_CX, DIAL_CY + 52, "FRAMES", C_TEXT3, OPAQUE, 48);
++}
++
++void roll_draw()
++{
++ if (!ui_clobbered && sheet.x <= 0 && !roll_sheet_drawn && !rewinding)
++ {
++ /* only the dial turns */
++ struct fos_canvas save = *cv;
++ ui_bg_restore(DIAL_BOX_X0, DIAL_BOX_Y0, DIAL_BOX_X1 - DIAL_BOX_X0, DIAL_BOX_Y1 - DIAL_BOX_Y0);
++ fos_clip(cv, DIAL_BOX_X0, DIAL_BOX_Y0, DIAL_BOX_X1, DIAL_BOX_Y1);
++ counter_dial(dial.x);
++ *cv = save;
++ return;
++ }
++ ui_clobbered = 0;
++ roll_sheet_drawn = sheet.x > 0;
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ counter_dial(dial.x);
++ int x = 336;
++ char b[96];
++ if (!ui_roll.loaded)
++ {
++ fos_text(cv, &fos_font_xs, x, 96, "NO ROLL", C_ACCENT, OPAQUE, 64);
++ fos_text(cv, &fos_font_lg, x, 132, "The camera is empty", C_TEXT, OPAQUE, 0);
++ fos_text(cv, &fos_font_sm, x, 160, "Load a roll from the film shelf.", C_TEXT3, OPAQUE, 0);
++ return;
++ }
++ const struct fos_film *f = &fos_films[ui_roll.film];
++ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
++ fos_text(cv, &fos_font_xs, x, 96, b, C_ACCENT, OPAQUE, 64);
++ fos_text(cv, &fos_font_lg, x, 132, f->name, C_TEXT, OPAQUE, 0);
++ snprintf(b, sizeof(b), "%s " T_DOT " ISO %d " T_DOT " %d exposures", f->process, f->box_iso, ui_roll.exposures);
++ fos_text(cv, &fos_font_sm, x, 158, b, C_TEXT2, OPAQUE, 0);
++ if (ui_roll.loaded_at[0])
++ {
++ snprintf(b, sizeof(b), "Loaded %s", ui_roll.loaded_at);
++ fos_text(cv, &fos_font_sm, x, 180, b, C_TEXT3, OPAQUE, 0);
++ }
++
++ /* the last frames, newest first */
++ int y = 220;
++ fos_text(cv, &fos_font_xs, x, y, "LAST FRAMES", C_TEXT3, OPAQUE, 48);
++ fos_fill(cv, x, y + 8, 340, 1, C_LINE);
++ y += 34;
++ if (!ui_roll.nrecent)
++ fos_text(cv, &fos_font_sm, x, y, "Nothing shot yet " T_MDASH " the roll is fresh.", C_TEXT3, OPAQUE, 0);
++ for (int i = 0; i < ui_roll.nrecent && i < FOS_RECENT; i++, y += 30)
++ {
++ snprintf(b, sizeof(b), "%d", ui_roll.recent[i].no);
++ fos_text_r(cv, &fos_font_mdb, x + 30, y, b, i == 0 ? C_TEXT : C_TEXT2, OPAQUE, 0);
++ fos_text(cv, &fos_font_md, x + 54, y, ui_roll.recent[i].time, C_TEXT2, OPAQUE, 0);
++ snprintf(b, sizeof(b), "f/%s", ui_roll.recent[i].fstop);
++ fos_text(cv, &fos_font_md, x + 140, y, b, C_TEXT3, OPAQUE, 0);
++ }
++
++ if (rewinding)
++ {
++ float t = clampf(rewind_t / 900.0f, 0, 1);
++ fos_text_c(cv, &fos_font_lg, 360, 420, "Rewinding" T_ELLIPSIS, FC(RAMP_GRAY, (int) (240 * ease_out(t))), OPAQUE, 0);
++ }
++ char body[96];
++ int left = ui_roll.exposures - ui_roll.shot;
++ if (left > 0)
++ {
++ snprintf(b, sizeof(b), "Rewind roll %03d?", ui_roll.number);
++ snprintf(body, sizeof(body), "%d frames stay unexposed. Develop it now, or load a new roll first.", left);
++ }
++ else
++ {
++ snprintf(b, sizeof(b), "Roll %03d is finished", ui_roll.number);
++ snprintf(body, sizeof(body), "Rewind it, then develop it now or load a new roll first.");
++ }
++ ui_sheet3(sheet.x, b, body, "Develop now", "New roll", left > 0 ? "Cancel" : "Not now");
++}
+diff --git a/src/fos_shelf.c b/src/fos_shelf.c
+new file mode 100644
+index 000000000..1d9d34341
+--- /dev/null
++++ b/src/fos_shelf.c
+@@ -0,0 +1,707 @@
++/* fos_shelf: the film shelf - the canisters on a dark stage, turning
++ * towards you as they glide past - and loading a roll.
++ *
++ * The carousel position is a spring that chases the selected film, so
++ * quick turns of the dial pile up into one smooth glide, and every
++ * canister's place, size, light and turn follow from how far it is from
++ * that position. The text below follows the same position: it slides out
++ * with the film leaving the middle and in with the one arriving.
++ *
++ * The films stand on shelves by kind (colour, slide, B&W, cine): up and
++ * down change shelf, and the canisters of the next one drop in.
++ */
++
++#include "fos_ui.h"
++#include <string.h>
++
++#define FLOOR_Y 262
++#define DOTS_Y 290
++#define BRAND_Y 320
++#define NAME_Y 366
++#define DESC_Y 392
++#define CHIPS_Y 406
++
++#define TABS_Y 56
++#define MAX_CANS 10 /* labels painted at a time: the shelf's middle and a few around */
++#define MAX_LIST 96 /* films on a shelf */
++
++/* everything that moves on the shelf is between these rows */
++#define MOVING_Y0 (STATUS_H - 8)
++#define MOVING_Y1 HINTS_Y
++
++static struct { int film; struct fos_can *c; unsigned used; } cans[MAX_CANS];
++static unsigned can_clock;
++static uint8_t *info_mask; /* the name block for fading, see info_build() */
++static int info_film = -1, info_x0, info_x1;
++static int16_t info_row0[128], info_row1[128]; /* inked span of each row */
++
++static struct spring pos; /* carousel, in places on the shelf */
++static int target; /* the selected film's place on the shelf */
++static int group; /* the shelf: FOS_GROUP_* */
++static int list[MAX_LIST], nlist; /* its films */
++static int group_at[FOS_NGROUPS]; /* the place last chosen on each shelf */
++static struct spring drop; /* a new shelf's canisters dropping in, 1 -> 0 */
++static int drop_dir;
++static int exp_sel;
++static struct spring exp_roll; /* the exposures chip rolls to the new number */
++static int exp_prev;
++static int nudge; /* bump at either end */
++
++/* rewind-and-load question */
++static int asking;
++static struct spring sheet;
++
++/* loading a roll */
++static int loading, load_t;
++
++static int sheet_drawn; /* the last frame had the sheet on it */
++
++static char baked_clock[16];
++static void bake();
++
++/* ---------------------------------------------------------------- canisters */
++
++/* a film's canister: kept painted for the last few asked for */
++struct fos_can *ui_can(int film)
++{
++ if (film < 0 || film >= fos_nfilms) return 0;
++ int slot = 0;
++ for (int i = 0; i < MAX_CANS; i++)
++ {
++ if (cans[i].c && cans[i].film == film)
++ {
++ cans[i].used = ++can_clock;
++ return cans[i].c;
++ }
++ if (!cans[i].c || (cans[slot].c && cans[i].used < cans[slot].used)) slot = i;
++ }
++ fos_can_free(cans[slot].c);
++ cans[slot].c = fos_can_new(film, fos_exposure_choices[exp_sel]);
++ cans[slot].film = film;
++ cans[slot].used = ++can_clock;
++ return cans[slot].c;
++}
++
++void ui_cans_free()
++{
++ fos_port_free(info_mask);
++ info_mask = 0;
++ info_film = -1;
++ for (int i = 0; i < MAX_CANS; i++)
++ {
++ fos_can_free(cans[i].c);
++ cans[i].c = 0;
++ }
++}
++
++void ui_cans_exposures(int exposures)
++{
++ for (int i = 0; i < MAX_CANS; i++)
++ if (cans[i].c) fos_can_set_exposures(cans[i].c, exposures);
++}
++
++/* the films of shelf g, and the place of film on it (0 if not there) */
++static int shelf_list(int g, int film)
++{
++ int at = 0;
++ group = g;
++ nlist = 0;
++ for (int i = 0; i < fos_nfilms && nlist < MAX_LIST; i++)
++ if (fos_films[i].group == g)
++ {
++ if (i == film) at = nlist;
++ list[nlist++] = i;
++ }
++ return at;
++}
++
++/* the labels the shelf will show first, painted now rather than mid-glide */
++static void paint_around(int at)
++{
++ for (int d = 0; d <= 3; d++)
++ {
++ if (at + d < nlist) ui_can(list[at + d]);
++ if (d && at - d >= 0) ui_can(list[at - d]);
++ }
++}
++
++/* ---------------------------------------------------------------- the stage */
++
++static float absf(float v) { return v < 0 ? -v : v; }
++
++#ifndef ABS
++#define ABS(v) ((v) < 0 ? -(v) : (v))
++#endif
++
++/* the stage's light at (x, y), 12-bit */
++static int stage_lv(int x, int y)
++{
++ int dx = x - 360;
++ int lv;
++ if (y < FLOOR_Y - 6)
++ {
++ /* backdrop: a soft spotlight behind the middle canister */
++ int dy = (y - 150) * 3 / 2;
++ int d2 = (dx * dx + dy * dy) >> 4;
++ int spot = d2 < 9000 ? (9000 - d2) * (9000 - d2) / 9000 * LV12(20) / 9000 : 0;
++ lv = LV12(10) + spot + (FLOOR_Y - y) * LV12(3) / FLOOR_Y;
++ }
++ else
++ {
++ /* floor: a lit ellipse under the canister fading into the dark */
++ int dy = (y - (FLOOR_Y + 4)) * 5;
++ int d2 = (dx * dx + dy * dy) >> 4;
++ int pool = d2 < 7000 ? (7000 - d2) * LV12(13) / 7000 : 0;
++ int fall = fos_clamp((y - FLOOR_Y) * LV12(6) / 60, 0, LV12(6));
++ lv = LV12(13) + pool - fall;
++ if (y > FLOOR_Y + 40) lv = lv * (FOS_H - y) / (FOS_H - FLOOR_Y - 40);
++ lv = fos_clamp(lv, LV12(4), LV_MAX);
++ }
++ /* the seam between backdrop and floor, very soft */
++ if (y >= FLOOR_Y - 6 && y < FLOOR_Y + 2)
++ lv = lv * (256 - (4 - ABS(y - (FLOOR_Y - 2))) * 10) / 256;
++ return lv;
++}
++
++/* the stage: a backdrop lit from above, a floor, a pool of light in the
++ * middle. The light changes slowly, so it is worked out every 8 px and
++ * stepped in between; rows y0..y1-1 only */
++static void stage_bg(int y0, int y1)
++{
++ const int mul = fos_ramp_mul[RAMP_GRAY];
++ const int base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
++ for (int y = y0; y < y1; y++)
++ {
++ uint8_t *row = &ui_bg[y * FOS_W];
++ const uint8_t *bay = fos_bayer[y & 3];
++ int p1 = stage_lv(0, y) * mul;
++ for (int x = 0; x < FOS_W; x += 8)
++ {
++ int p0 = p1;
++ p1 = stage_lv(x + 8, y) * mul;
++ int p = p0, dp = (p1 - p0) >> 3;
++ for (int i = 0; i < 8; i++, p += dp)
++ {
++ int q = ((p >> 16) + bay[i & 3]) >> 4;
++ row[x + i] = base + (q > last ? last : q);
++ }
++ }
++ }
++}
++
++/* where film i stands for carousel offset d (films from the middle) */
++static void pose_of(float d, struct fos_can_pose *p, float lift, float spread)
++{
++ float ad = absf(d);
++ float n = clampf(ad, 0, 1), f = clampf(ad - 1, 0, 1.8f);
++ float sx = d < 0 ? -1 : 1;
++ float x = 360 + sx * (n * 192 + f * 122) * spread;
++ float scale = 1.0f - n * 0.27f - f * 0.17f;
++ float light = 1.0f - n * 0.42f - f * 0.30f;
++ float rot = d * 0.085f; /* turns: faces the middle */
++ p->cx8 = (int) (x * 256);
++ p->floor_y = (int) (FLOOR_Y - n * 12 - f * 8 - lift);
++ p->scale = (int) (scale * 256);
++ p->rot = (int) (rot * 65536);
++ p->light = (int) (clampf(light, 0, 1) * 256);
++ p->leader = 256;
++ p->fast = absf(pos.v) > 1.2f; /* films a second: too quick to see the fine print */
++ /* the middle one is mirrored in the floor, fading as it leaves */
++ p->reflect = (int) (64 * clampf(1.25f - absf(d), 0, 1));
++}
++
++/* a soft contact shadow under a canister */
++static void contact_shadow(int cx, int y, int rx, int ry, int strength)
++{
++ if (rx <= 0 || ry <= 0) return;
++ int x0 = fos_clamp(cx - rx, cv->cx0, cv->cx1), x1 = fos_clamp(cx + rx, cv->cx0, cv->cx1);
++ int y0 = fos_clamp(y - ry, cv->cy0, cv->cy1), y1 = fos_clamp(y + ry, cv->cy0, cv->cy1);
++ int sx = 65536 / rx, sy = 65536 / ry; /* 1/256 of the radius per px */
++ for (int j = y0; j < y1; j++)
++ {
++ int dy = ((j - y) * sy) >> 8;
++ if (dy * dy >= 65536) continue;
++ /* only the part of the row inside the ellipse */
++ int half = (fos_isqrt(65536 - dy * dy) * rx >> 8) + 1;
++ int xa = fos_clamp(cx - half, x0, x1), xb = fos_clamp(cx + half + 1, xa, x1);
++ int dx8 = (xa - cx) * sx;
++ uint8_t *p = &cv->px[j * cv->pitch + xa];
++ for (int i = xa; i < xb; i++, p++, dx8 += sx)
++ {
++ int dx = dx8 >> 8;
++ int d2 = (dx * dx + dy * dy) >> 8;
++ if (d2 >= 256) continue;
++ int k = 256 - ((strength * (((256 - d2) * (256 - d2)) >> 8)) >> 8);
++ *p = fos_darken(*p, k, i, j);
++ }
++ }
++}
++
++/* ---------------------------------------------------------------- screen */
++
++void shelf_enter(int arg)
++{
++ exp_sel = fos_clamp(fos_port_get(FS_EXP), 0, FOS_NEXP - 1);
++ exp_prev = exp_sel;
++ exp_roll.x = 1; exp_roll.v = 0;
++ int film = ui_roll.loaded && ui_roll.shot < ui_roll.exposures ? ui_roll.film : fos_port_get(FS_FILM);
++ film = fos_clamp(film, 0, fos_nfilms - 1);
++ target = shelf_list(fos_films[film].group, film);
++ for (int g = 0; g < FOS_NGROUPS; g++) group_at[g] = 0;
++ group_at[group] = target;
++ drop.x = 0; drop.v = 0;
++ pos.x = target; pos.v = 0;
++ /* arriving from elsewhere: the shelf glides in from one film over */
++ if (arg == 0) pos.x = target - 0.6f;
++ nudge = 0;
++ asking = 0;
++ sheet.x = 0; sheet.v = 0;
++ loading = 0;
++ sheet_drawn = 0;
++ paint_around(target);
++ ui_cans_exposures(fos_exposure_choices[exp_sel]);
++ bake();
++}
++
++void shelf_leave()
++{
++}
++
++static int roll_in_progress()
++{
++ return ui_roll.loaded && ui_roll.shot < ui_roll.exposures;
++}
++
++static void start_loading()
++{
++ loading = 1;
++ load_t = 0;
++ asking = 0;
++ bake();
++ fos_port_set(FS_FILM, list[target]);
++ fos_port_set(FS_EXP, exp_sel);
++ fos_port_action(FA_LOAD, list[target], exp_sel);
++ fos_port_roll(&ui_roll);
++}
++
++/* what the next frame changes: the whole screen while the sheet or the
++ * loading animation is up, else the band between status bar and hints */
++static void shelf_damage()
++{
++ if (loading || asking || sheet.x > 0 || sheet_drawn) ui_damage_all();
++ else ui_damage(MOVING_Y0, MOVING_Y1);
++}
++
++void shelf_key(int k)
++{
++ if (loading) return;
++ if (asking)
++ {
++ if (k == FK_SET) start_loading();
++ else if (k == FK_MENU || k == FK_LEFT || k == FK_RIGHT || k == FK_WHEEL_L || k == FK_WHEEL_R)
++ asking = 0;
++ shelf_damage();
++ return;
++ }
++ switch (k)
++ {
++ case FK_LEFT: case FK_WHEEL_L:
++ if (target > 0) target--; else nudge = -1;
++ break;
++ case FK_RIGHT: case FK_WHEEL_R:
++ if (target < nlist - 1) target++; else nudge = 1;
++ break;
++ case FK_UP: case FK_DOWN:
++ {
++ /* the next shelf (skipping empty ones), at the film last chosen there */
++ int dir = k == FK_DOWN ? 1 : -1, from = group, g = group;
++ group_at[group] = target;
++ do
++ {
++ g = (g + dir + FOS_NGROUPS) % FOS_NGROUPS;
++ shelf_list(g, -1);
++ }
++ while (!nlist && g != from);
++ target = fos_clamp(group_at[g], 0, nlist - 1);
++ pos.x = target; pos.v = 0;
++ drop.x = 1; drop.v = 0;
++ drop_dir = dir;
++ paint_around(target);
++ bake();
++ ui_clobbered = 1;
++ break;
++ }
++ case FK_INFO:
++ exp_prev = exp_sel;
++ exp_sel = (exp_sel + (k == FK_UP ? FOS_NEXP - 1 : 1)) % FOS_NEXP;
++ exp_roll.x = 0; exp_roll.v = 0;
++ ui_cans_exposures(fos_exposure_choices[exp_sel]);
++ break;
++ case FK_SET:
++ if (roll_in_progress()) asking = 1;
++ else start_loading();
++ break;
++ case FK_MENU:
++ if (ui_from() == SCR_HOME) ui_go(SCR_HOME, 0, GO_POP);
++ else ui_leave();
++ break;
++ case FK_HOME: case FK_PLAY:
++ ui_go(SCR_HOME, 0, GO_POP);
++ break;
++ }
++ shelf_damage();
++}
++
++int shelf_update(int dt)
++{
++ int moving = 0;
++ char clock[16];
++ fos_port_clock(clock, sizeof(clock));
++ if (strcmp(clock, baked_clock))
++ {
++ /* a new minute: only the status bar changes */
++ stage_bg(0, STATUS_H);
++ ui_to_bg(1);
++ ui_status_bar("FILM");
++ ui_to_bg(0);
++ memcpy(baked_clock, clock, sizeof(baked_clock));
++ ui_damage(0, STATUS_H);
++ ui_clobbered = 1;
++ }
++ float goal = target + (nudge ? nudge * 0.18f : 0);
++ moving |= spring_step(&pos, goal, dt, 2.1f, 0.86f);
++ if (nudge && absf(pos.x - goal) < 0.05f) nudge = 0;
++ moving |= spring_step(&exp_roll, 1, dt, 3.2f, 0.9f);
++ moving |= spring_step(&sheet, asking ? 1 : 0, dt, 3.0f, 0.95f);
++ moving |= spring_step(&drop, 0, dt, 2.6f, 0.9f);
++ if (loading)
++ {
++ load_t += dt;
++ moving = 1;
++ if (load_t > 1900) ui_leave();
++ }
++ if (moving)
++ shelf_damage();
++ return moving;
++}
++
++/* ---------------------------------------------------------------- drawing */
++
++static void draw_canisters(float lift_mid, float spread, float fade_sides, int leader_mid)
++{
++ int t0 = fos_port_ms();
++ struct { int i; float d; } order[8];
++ int n = 0;
++ for (int i = 0; i < nlist && n < 8; i++)
++ {
++ float d = i - pos.x;
++ if (absf(d) > 2.7f) continue;
++ order[n].i = i; order[n].d = d; n++;
++ }
++ /* far ones first */
++ for (int a = 0; a < n; a++)
++ for (int b = a + 1; b < n; b++)
++ if (absf(order[b].d) > absf(order[a].d))
++ {
++ int ti = order[a].i; float td = order[a].d;
++ order[a] = order[b];
++ order[b].i = ti; order[b].d = td;
++ }
++
++ for (int k = 0; k < n; k++)
++ {
++ int i = list[order[k].i];
++ float d = order[k].d;
++ struct fos_can_pose p;
++ int mid = absf(d) < 0.5f;
++ pose_of(d, &p, mid ? lift_mid : 0, spread);
++ if (!mid) p.light = (int) (p.light * (1 - fade_sides));
++ if (drop.x > 0.002f)
++ {
++ /* a new shelf: its canisters drop in from above (or rise from below), the far ones a little later */
++ float t = clampf(drop.x * (1 + absf(d) * 0.25f), 0, 1);
++ p.floor_y -= (int) (t * 90 * drop_dir);
++ p.light = (int) (p.light * (1 - t));
++ p.reflect = (int) (p.reflect * (1 - t));
++ }
++ if (mid && leader_mid) p.leader = leader_mid;
++ if (p.light <= 4) continue;
++ struct fos_can *c = ui_can(i);
++ int w = fos_can_width(p.scale);
++ contact_shadow(p.cx8 >> 8, p.floor_y, w * 6 / 10, 7 * p.scale / 256 + 2, 150 * p.light / 256);
++ fos_can_draw(cv, c, &p);
++
++ /* the film that is in the camera wears a tag */
++ if (roll_in_progress() && i == ui_roll.film && !loading)
++ {
++ int cx = p.cx8 >> 8;
++ int top = p.floor_y - fos_can_height(p.scale) - 14;
++ int a = (int) (p.light * 1.0f);
++ const char *t = "IN CAMERA";
++ int tw = fos_text_w(&fos_font_xs, t, 24);
++ fos_rrect(cv, cx - tw / 2 - 10, top - 13, tw + 20, 20, 10, FC(RAMP_AMBER, 186 * a / 256), OPAQUE);
++ fos_text_c(cv, &fos_font_xs, cx, top + 2, t, FC(RAMP_GRAY, 14), OPAQUE, 24);
++ }
++ }
++ ui_cans_ms += fos_port_ms() - t0;
++}
++
++/* chips under the name: fixed sizes, so only the values change */
++#define CHIP_H 26
++static const char *chip_labels[3] = { "ISO", "PROCESS", "EXP" };
++static const char *chip_widest[3] = { "800", "C-41", "36" };
++static int chip_x[3], chip_w[3], chip_vx[3];
++
++static void chips_layout()
++{
++ int total = 0;
++ for (int i = 0; i < 3; i++)
++ {
++ int lw = fos_text_w(&fos_font_xs, chip_labels[i], 24);
++ int vw = fos_text_w(&fos_font_mdb, chip_widest[i], 0);
++ chip_w[i] = lw + vw + 32;
++ total += chip_w[i] + (i ? 10 : 0);
++ }
++ int x = 360 - total / 2;
++ for (int i = 0; i < 3; i++)
++ {
++ chip_x[i] = x;
++ chip_vx[i] = x + 12 + fos_text_w(&fos_font_xs, chip_labels[i], 24) + 8;
++ x += chip_w[i] + 10;
++ }
++}
++
++static void draw_static(int alpha)
++{
++ struct hint h[] = { { "<>", "Film" }, { "^v", "Shelf" }, { "INFO", "Exposures" },
++ { "SET", roll_in_progress() ? "Rewind & load" : "Load" }, { "MENU", "Back" } };
++ if (alpha >= OPAQUE) ui_hints(h, 5);
++ /* the shelves, this one lit */
++ int tw = 0;
++ for (int g = 0; g < FOS_NGROUPS; g++) tw += fos_text_w(&fos_font_xs, fos_group_names[g], 64) + (g ? 30 : 0);
++ int tx = 360 - tw / 2;
++ for (int g = 0; g < FOS_NGROUPS; g++)
++ {
++ int w = fos_text_w(&fos_font_xs, fos_group_names[g], 64);
++ fos_text(cv, &fos_font_xs, tx, TABS_Y, fos_group_names[g], g == group ? C_ACCENT : C_TEXT3, alpha, 64);
++ if (g == group) fos_rrect(cv, tx + w / 2 - 8, TABS_Y + 6, 16, 3, 1, C_ACCENT, alpha);
++ tx += w + 30;
++ }
++ for (int i = 0; i < 3; i++)
++ {
++ int exp = i == 2;
++ fos_rrect(cv, chip_x[i], CHIPS_Y, chip_w[i], CHIP_H, CHIP_H / 2, exp ? FC(RAMP_GRAY, 24) : FC(RAMP_GRAY, 17), alpha);
++ fos_rrect_line(cv, chip_x[i], CHIPS_Y, chip_w[i], CHIP_H, CHIP_H / 2, 1, exp ? C_ACCENT2 : FC(RAMP_GRAY, 46), alpha);
++ fos_text(cv, &fos_font_xs, chip_x[i] + 12, CHIPS_Y + 18, chip_labels[i], C_TEXT3, alpha, 24);
++ }
++ int n = nlist, x0 = 360 - n * 6;
++ for (int i = 0; i < n; i++)
++ fos_disc(cv, (x0 + i * 12 + 6) * 256, DOTS_Y * 256, 2 * 256, FC(RAMP_GRAY, 60), alpha);
++}
++
++/* the stage and everything that doesn't move, drawn once; while a roll
++ * loads, only the stage stays */
++static void bake()
++{
++ stage_bg(0, FOS_H);
++ ui_to_bg(1);
++ ui_status_bar("FILM");
++ chips_layout();
++ if (!loading) draw_static(OPAQUE);
++ ui_to_bg(0);
++ fos_port_clock(baked_clock, sizeof(baked_clock));
++}
++
++static void draw_dot_marker()
++{
++ /* the current film: a short amber bar sliding with the carousel */
++ int x0 = 360 - nlist * 6;
++ float px = x0 + clampf(pos.x, 0, nlist - 1) * 12 + 6;
++ fos_rrect(cv, (int) px - 7, DOTS_Y - 2, 14, 4, 2, C_ACCENT, OPAQUE);
++}
++
++/* The film's name block, kept for fading: per pixel its ink (high
++ * nibble) and coverage (low nibble), so a frame of the glide blends the
++ * pixels without decoding the glyphs again. */
++#define INFO_Y0 (BRAND_Y - 16)
++#define INFO_Y1 (DESC_Y + 8)
++#define INFO_H (INFO_Y1 - INFO_Y0)
++
++static void info_build(int film)
++{
++ const struct fos_film *f = &fos_films[film];
++ const struct { const struct fos_font *font; int y; const char *s; int track; } part[3] =
++ {
++ { &fos_font_xs, BRAND_Y, f->brand, 64 },
++ { &fos_font_xl, NAME_Y, f->name, 0 },
++ { &fos_font_sm, DESC_Y, f->desc, 0 },
++ };
++ memset(info_mask, 0, FOS_W * INFO_H);
++ info_x0 = FOS_W; info_x1 = 0;
++ for (int i = 0; i < 3; i++)
++ {
++ uint8_t map[16];
++ map[0] = 0;
++ for (int v = 1; v < 16; v++) map[v] = (i + 1) << 4 | v;
++ int w = fos_text_w(part[i].font, part[i].s, part[i].track);
++ int x = 360 - w / 2;
++ fos_text_map(info_mask, FOS_W, FOS_W, INFO_H, part[i].font, x, part[i].y - INFO_Y0, part[i].s, map, part[i].track);
++ if (x - 4 < info_x0) info_x0 = fos_clamp(x - 4, 0, FOS_W);
++ if (x + w + 4 > info_x1) info_x1 = fos_clamp(x + w + 4, 0, FOS_W);
++ }
++ for (int j = 0; j < INFO_H; j++)
++ {
++ const uint8_t *m = &info_mask[j * FOS_W];
++ int a = info_x0, b = info_x1;
++ while (a < b && !m[a]) a++;
++ while (b > a && !m[b - 1]) b--;
++ info_row0[j] = a; info_row1[j] = b;
++ }
++ info_film = film;
++}
++
++/* the block at opacity alpha, moved xo px. Grey ink over the grey stage
++ * blends as levels of one ramp, which is cheap; the few pixels of the
++ * amber brand take the full blend. */
++static void info_fade(int alpha, int xo)
++{
++ const fcol inks[4] = { 0, C_ACCENT, C_TEXT, C_TEXT2 };
++ int ink_lv[4];
++ for (int i = 1; i < 4; i++)
++ ink_lv[i] = FC_RAMP(inks[i]) == RAMP_GRAY ? LV12(FC_LEVEL(inks[i])) : -1;
++ const int mul = fos_ramp_mul[RAMP_GRAY], base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
++ int ka = alpha * 17; /* coverage 15 at full opacity -> 255 */
++ for (int j = 0; j < INFO_H; j++)
++ {
++ int y = INFO_Y0 + j;
++ if (y < cv->cy0 || y >= cv->cy1) continue;
++ int xa = fos_clamp(info_row0[j], cv->cx0 - xo, cv->cx1 - xo), xb = fos_clamp(info_row1[j], xa, cv->cx1 - xo);
++ const uint8_t *m = &info_mask[j * FOS_W];
++ uint8_t *row = &cv->px[y * cv->pitch + xo];
++ uint8_t bay[4];
++ for (int k = 0; k < 4; k++)
++ bay[k] = fos_bayer[y & 3][(k + xo) & 3];
++ for (int x = xa; x < xb; x++)
++ {
++ int v = m[x];
++ if (!v) continue;
++ int op = ((v & 15) * ka) >> 8;
++ int k = v >> 4, d = row[x];
++ if (ink_lv[k] >= 0 && fos_rev_ramp[d] == RAMP_GRAY)
++ {
++ int lv = fos_rev_lv[d] + (((ink_lv[k] - fos_rev_lv[d]) * op) >> 8);
++ int q = (((lv * mul) >> 16) + bay[x & 3]) >> 4;
++ row[x] = base + (q > last ? last : q);
++ }
++ else
++ row[x] = fos_mix(d, FC_RAMP(inks[k]), LV12(FC_LEVEL(inks[k])), op);
++ }
++ }
++}
++
++static void draw_info()
++{
++ int place = (int) (pos.x + 100.5f) - 100;
++ place = fos_clamp(place, 0, nlist - 1);
++ int ni = list[place];
++ float frac = pos.x - place;
++ float a = clampf(1 - absf(frac) * 2.2f, 0, 1) * (1 - drop.x);
++ a = a * a * (3 - 2 * a);
++ int alpha = (int) (a * 256);
++ int xo = (int) (-frac * 70);
++ const struct fos_film *f = &fos_films[ni];
++
++ if (alpha > 0)
++ {
++ if (!info_mask) info_mask = fos_port_alloc(FOS_W * INFO_H);
++ if (alpha < OPAQUE && info_mask)
++ {
++ if (info_film != ni) info_build(ni);
++ info_fade(alpha, xo);
++ }
++ else
++ {
++ fos_text_c(cv, &fos_font_xs, 360 + xo, BRAND_Y, f->brand, C_ACCENT, alpha, 64);
++ fos_text_c(cv, &fos_font_xl, 360 + xo, NAME_Y, f->name, C_TEXT, alpha, 0);
++ fos_text_c(cv, &fos_font_sm, 360 + xo, DESC_Y, f->desc, C_TEXT2, alpha, 0);
++ }
++ char b[16];
++ snprintf(b, sizeof(b), "%d", f->box_iso);
++ fos_text(cv, &fos_font_mdb, chip_vx[0], CHIPS_Y + 19, b, C_TEXT, alpha, 0);
++ fos_text(cv, &fos_font_mdb, chip_vx[1], CHIPS_Y + 19, f->process, C_TEXT, alpha, 0);
++ }
++
++ /* exposures: the number rolls up or down when it changes */
++ struct fos_canvas save = *cv;
++ fos_clip(cv, chip_vx[2] - 4, CHIPS_Y + 3, chip_x[2] + chip_w[2] - 8, CHIPS_Y + CHIP_H - 3);
++ char nb[8], ob[8];
++ snprintf(nb, sizeof(nb), "%d", fos_exposure_choices[exp_sel]);
++ snprintf(ob, sizeof(ob), "%d", fos_exposure_choices[exp_prev]);
++ int dy = (int) ((1 - exp_roll.x) * 20);
++ fos_text(cv, &fos_font_mdb, chip_vx[2], CHIPS_Y + 19 + dy, nb, C_ACCENT, OPAQUE, 0);
++ if (exp_roll.x < 1)
++ fos_text(cv, &fos_font_mdb, chip_vx[2], CHIPS_Y + 19 + dy - 20, ob, C_ACCENT, OPAQUE, 0);
++ *cv = save;
++}
++
++static void draw_sheet()
++{
++ char t[48], b[96];
++ snprintf(t, sizeof(t), "Rewind roll %03d?", ui_roll.number);
++ snprintf(b, sizeof(b), "%d of %d frames on %s are still unexposed. They will be lost.",
++ ui_roll.exposures - ui_roll.shot, ui_roll.exposures, fos_films[ui_roll.film].name);
++ ui_sheet(sheet.x, t, b, "Rewind and load", "Keep shooting");
++}
++
++/* SET: the leader is drawn out of the canister across the stage, the
++ * other stocks step aside, and the roll number is stamped */
++static void draw_loading()
++{
++ float t = load_t;
++ float aside = ease_in_out(clampf(t / 450.0f, 0, 1));
++ float lift = 10 * ease_out(clampf(t / 400.0f, 0, 1));
++ float pull = ease_in_out(clampf((t - 250) / 850.0f, 0, 1));
++ int leader = 256 + (int) (pull * 256 * 7);
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ /* the chips and dots fade away with the other stocks */
++ if (aside < 1) draw_static((int) (256 * (1 - aside)));
++ draw_canisters(lift, 1 + aside * 0.8f, aside, leader);
++
++ float ta = ease_out(clampf((t - 900) / 450.0f, 0, 1));
++ if (ta > 0)
++ {
++ int a = (int) (ta * 256);
++ char b[48];
++ snprintf(b, sizeof(b), "ROLL %03d", ui_roll.number);
++ fos_text_c(cv, &fos_font_xs, 360, BRAND_Y + 8, b, C_ACCENT, a, 64);
++ fos_text_c(cv, &fos_font_xl, 360, NAME_Y + 8 - (int) ((1 - ta) * 12), "Loaded", C_TEXT, a, 0);
++ snprintf(b, sizeof(b), "%s " T_DOT " %d exposures", fos_films[list[target]].name, fos_exposure_choices[exp_sel]);
++ fos_text_c(cv, &fos_font_sm, 360, DESC_Y + 8, b, C_TEXT2, a, 0);
++ }
++}
++
++void shelf_draw()
++{
++ if (loading)
++ {
++ draw_loading();
++ return;
++ }
++ if (ui_clobbered || sheet.x > 0 || sheet_drawn)
++ {
++ ui_clobbered = 0;
++ ui_damage_all();
++ ui_bg_restore(0, 0, FOS_W, FOS_H);
++ }
++ else
++ {
++ /* the status bar and the key hints never move here */
++ ui_bg_restore(0, MOVING_Y0, FOS_W, MOVING_Y1 - MOVING_Y0);
++ ui_damage(MOVING_Y0, MOVING_Y1);
++ }
++ draw_canisters(0, 1, 0, 0);
++ draw_dot_marker();
++ draw_info();
++ draw_sheet();
++ sheet_drawn = sheet.x > 0;
++}
+diff --git a/src/fos_ui.c b/src/fos_ui.c
+new file mode 100644
+index 000000000..443e2e75d
+--- /dev/null
++++ b/src/fos_ui.c
+@@ -0,0 +1,907 @@
++/* fos_ui: the loop, navigation, transitions and shared widgets of the
++ * film OS. The screens themselves are in fos_shelf.c and fos_pages.c.
++ *
++ * One loop reads keys, steps every animation by the time that really
++ * passed and redraws only while something moves, so a quiet screen costs
++ * nothing. Screens draw into our own canvas; the port copies the rows
++ * that changed to the camera's bitmap overlay.
++ */
++
++#include "fos_ui.h"
++#include <string.h>
++
++struct fos_canvas *cv;
++uint8_t *ui_bg;
++int ui_now;
++struct fos_roll ui_roll;
++int ui_clobbered = 1;
++int ui_cans_ms;
++
++static struct fos_canvas canvas;
++static uint8_t *buf_cv, *buf_bg, *buf_snap;
++
++static int screen, screen_from;
++static int dmg_y0 = FOS_H, dmg_y1 = 0;
++
++/* screen change in progress */
++static int tr_how, tr_t, tr_len; /* tr_t counts up to tr_len (ms) */
++static int leaving; /* 1 while the shutter opens on LiveView */
++static int leave_t;
++static int quit;
++static int boot_then_leave;
++
++/* opening: the shutter closes over LiveView, then opens on us */
++static int enter_t;
++#define ENTER_LEN 420
++#define LEAVE_LEN 380
++
++/* the toast */
++static char toast_msg[80];
++static int toast_t = 100000;
++#define TOAST_LEN 1800
++
++/* held keys repeat */
++static int held_key, held_since, held_last;
++
++/* ---------------------------------------------------------------- animation */
++
++float clampf(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }
++
++float ease_out(float t)
++{
++ t = clampf(t, 0, 1);
++ float u = 1 - t;
++ return 1 - u * u * u;
++}
++
++float ease_in_out(float t)
++{
++ t = clampf(t, 0, 1);
++ return t < 0.5f ? 4 * t * t * t : 1 - (-2 * t + 2) * (-2 * t + 2) * (-2 * t + 2) / 2;
++}
++
++int spring_step(struct spring *s, float target, int dt, float hz, float zeta)
++{
++ float w = 6.2831853f * hz;
++ while (dt > 0)
++ {
++ float h = (dt > 8 ? 8 : dt) / 1000.0f;
++ float a = w * w * (target - s->x) - 2 * zeta * w * s->v;
++ s->v += a * h;
++ s->x += s->v * h;
++ dt -= 8;
++ }
++ float d = target - s->x;
++ if (d < 0.0015f && d > -0.0015f && s->v < 0.02f && s->v > -0.02f)
++ {
++ s->x = target;
++ s->v = 0;
++ return 0;
++ }
++ return 1;
++}
++
++/* ---------------------------------------------------------------- damage */
++
++void ui_damage(int y0, int y1)
++{
++ if (y0 < dmg_y0) dmg_y0 = fos_clamp(y0, 0, FOS_H);
++ if (y1 > dmg_y1) dmg_y1 = fos_clamp(y1, 0, FOS_H);
++}
++
++void ui_damage_all()
++{
++ ui_damage(0, FOS_H);
++}
++
++/* ---------------------------------------------------------------- widgets */
++
++void ui_bg_restore(int x, int y, int w, int h)
++{
++ x = fos_clamp(x, 0, FOS_W); y = fos_clamp(y, 0, FOS_H);
++ w = fos_clamp(w, 0, FOS_W - x); h = fos_clamp(h, 0, FOS_H - y);
++ for (int j = y; j < y + h; j++)
++ memcpy(&cv->px[j * cv->pitch + x], &ui_bg[j * FOS_W + x], w);
++}
++
++/* static parts of a screen are drawn once into its background */
++void ui_to_bg(int on)
++{
++ static struct fos_canvas bgcv, *saved;
++ if (on && cv != &bgcv)
++ {
++ saved = cv;
++ fos_canvas_init(&bgcv, ui_bg, FOS_W, FOS_W, FOS_H);
++ cv = &bgcv;
++ }
++ else if (!on && cv == &bgcv)
++ cv = saved;
++}
++
++/* a dark backdrop with a little light from above */
++static int plain_lv(int x, int y)
++{
++ int dx = (x - 360) * 2 / 3, dy = y - 40;
++ int d2 = (dx * dx + dy * dy) >> 6; /* soft pool of light */
++ return LV12(9) + (d2 < 2400 ? (2400 - d2) * LV12(9) / 2400 : 0);
++}
++
++static uint8_t *buf_plain; /* the backdrop, worked out once a session */
++
++void ui_bg_plain()
++{
++ if (buf_plain)
++ {
++ memcpy(ui_bg, buf_plain, FOS_W * FOS_H);
++ return;
++ }
++ /* the light changes slowly: worked out on an 8 px grid, stepped between */
++ const int mul = fos_ramp_mul[RAMP_GRAY];
++ const int base = fos_ramp_base[RAMP_GRAY], last = fos_ramp_last[RAMP_GRAY];
++ static int grid[2][FOS_W / 8 + 1];
++ for (int i = 0; i <= FOS_W / 8; i++)
++ grid[1][i] = plain_lv(i * 8, 0) * mul;
++ for (int y = 0; y < FOS_H; y++)
++ {
++ if (!(y & 7))
++ for (int i = 0; i <= FOS_W / 8; i++)
++ {
++ grid[0][i] = grid[1][i];
++ grid[1][i] = plain_lv(i * 8, y + 8) * mul;
++ }
++ int fy = y & 7;
++ uint8_t *row = &ui_bg[y * FOS_W];
++ const uint8_t *bay = fos_bayer[y & 3];
++ for (int x = 0, i = 0; x < FOS_W; x += 8, i++)
++ {
++ int p0 = grid[0][i] + ((grid[1][i] - grid[0][i]) >> 3) * fy;
++ int p1 = grid[0][i + 1] + ((grid[1][i + 1] - grid[0][i + 1]) >> 3) * fy;
++ int p = p0, dp = (p1 - p0) >> 3;
++ for (int k = 0; k < 8; k++, p += dp)
++ {
++ int q = ((p >> 16) + bay[k & 3]) >> 4;
++ row[x + k] = base + (q > last ? last : q);
++ }
++ }
++ }
++ /* keep it for the next page, if there is room */
++ buf_plain = fos_port_alloc(FOS_W * FOS_H);
++ if (buf_plain) memcpy(buf_plain, ui_bg, FOS_W * FOS_H);
++}
++
++void ui_status_bar(const char *title)
++{
++ /* wordmark: a small aperture and the name */
++ int y = 24;
++ for (int i = 0; i < 6; i++)
++ {
++ int a = i * 65536 / 6 + 3000;
++ int x0 = 26 * 256 + fos_cos(a) * 7 / 16, y0 = 18 * 256 + fos_sin(a) * 7 / 16;
++ int x1 = 26 * 256 + fos_cos(a + 65536 / 6) * 7 / 16, y1 = 18 * 256 + fos_sin(a + 65536 / 6) * 7 / 16;
++ fos_line(cv, x0, y0, x1, y1, 400, C_ACCENT, OPAQUE);
++ }
++ int x = fos_text(cv, &fos_font_xs, 42, y, FOS_NAME, C_TEXT2, OPAQUE, 40) + 42;
++ if (title && *title)
++ {
++ fos_fill(cv, x + 12, 12, 1, 14, C_LINE);
++ fos_text(cv, &fos_font_xs, x + 25, y, title, C_TEXT3, OPAQUE, 40);
++ }
++
++ /* right: the roll in the camera and the time */
++ char clock[16], buf[48];
++ fos_port_clock(clock, sizeof(clock));
++ int rx = FOS_W - 24;
++ rx -= fos_text_r(cv, &fos_font_mdb, rx, y + 1, clock, C_TEXT, OPAQUE, 0) + 18;
++ if (ui_roll.loaded)
++ {
++ int left = ui_roll.exposures - ui_roll.shot;
++ if (left > 0)
++ snprintf(buf, sizeof(buf), "%s %d/%d", fos_films[ui_roll.film].name, ui_roll.shot, ui_roll.exposures);
++ else
++ snprintf(buf, sizeof(buf), "%s END OF ROLL", fos_films[ui_roll.film].name);
++ int w = fos_text_w(&fos_font_xs, buf, 16);
++ fos_rrect(cv, rx - w - 24, 9, w + 24, 20, 10, C_PANEL, OPAQUE);
++ fos_disc(cv, (rx - w - 14) * 256, 19 * 256, 3 * 256, left > 0 ? C_ACCENT : C_RED, OPAQUE);
++ fos_text(cv, &fos_font_xs, rx - w - 6, y - 1, buf, C_TEXT2, OPAQUE, 16);
++ }
++}
++
++int ui_keycap(int x, int base, const char *key)
++{
++ /* arrows are drawn, words are written */
++ int w;
++ if (!strcmp(key, "<>") || !strcmp(key, "^v"))
++ {
++ w = 34;
++ fos_rrect_line(cv, x, base - 15, w, 20, 6, 1, FC(RAMP_GRAY, 90), OPAQUE);
++ int vert = key[0] == '^';
++ fos_tri(cv, x + 11, base - 5, 7, vert ? 3 : 2, C_TEXT2, OPAQUE);
++ fos_tri(cv, x + 23, base - 5, 7, vert ? 1 : 0, C_TEXT2, OPAQUE);
++ return w;
++ }
++ w = fos_text_w(&fos_font_xs, key, 16) + 14;
++ fos_rrect_line(cv, x, base - 15, w, 20, 6, 1, FC(RAMP_GRAY, 90), OPAQUE);
++ fos_text(cv, &fos_font_xs, x + 7, base - 1, key, C_TEXT2, OPAQUE, 16);
++ return w;
++}
++
++void ui_hints(const struct hint *h, int n)
++{
++ int base = HINTS_Y + 23;
++ int x = 24;
++ for (int i = 0; i < n; i++)
++ {
++ x += ui_keycap(x, base, h[i].key) + 8;
++ x += fos_text(cv, &fos_font_sm, x, base - 1, h[i].label, C_TEXT3, OPAQUE, 0) + 22;
++ }
++}
++
++void ui_dots(int x, int y, int n, int filled, fcol on)
++{
++ for (int i = 0; i < n; i++)
++ {
++ if (i < filled)
++ fos_rrect(cv, x + i * 13, y, 10, 4, 2, on, OPAQUE);
++ else
++ fos_rrect(cv, x + i * 13, y, 10, 4, 2, FC(RAMP_GRAY, 46), OPAQUE);
++ }
++}
++
++void ui_toast(const char *msg)
++{
++ snprintf(toast_msg, sizeof(toast_msg), "%s", msg);
++ toast_t = 0;
++}
++
++int ui_toast_up()
++{
++ return toast_t < TOAST_LEN;
++}
++
++static void toast_draw()
++{
++ if (toast_t >= TOAST_LEN) return;
++ float in = clampf(toast_t / 180.0f, 0, 1), out = clampf((TOAST_LEN - toast_t) / 300.0f, 0, 1);
++ float k = ease_out(in) * out;
++ int a = (int) (k * 256);
++ int w = fos_text_w(&fos_font_sm, toast_msg, 0) + 36;
++ int y = HINTS_Y - 38 + (int) ((1 - ease_out(in)) * 10);
++ fos_rrect(cv, 360 - w / 2, y, w, 32, 16, FC(RAMP_GRAY, 34), a);
++ fos_rrect_line(cv, 360 - w / 2, y, w, 32, 16, 1, FC(RAMP_GRAY, 58), a);
++ fos_text_c(cv, &fos_font_sm, 360, y + 21, toast_msg, C_TEXT, a, 0);
++}
++
++void ui_sheet(float s, const char *title, const char *body, const char *yes, const char *no)
++{
++ ui_sheet3(s, title, body, yes, 0, no);
++}
++
++void ui_sheet3(float s, const char *title, const char *body, const char *yes, const char *alt, const char *no)
++{
++ if (s <= 0.002f) return;
++ int sh = 150;
++ int y = FOS_H - (int) (sh * ease_out(s)) + 6;
++ fos_scale_levels(cv, 0, 0, FOS_W, y + 18, (int) (256 - s * 130)); /* what shows above it */
++ fos_rrect(cv, 12, y, FOS_W - 24, sh + 20, 18, FC(RAMP_GRAY, 24), OPAQUE);
++ fos_rrect_line(cv, 12, y, FOS_W - 24, sh + 20, 18, 1, FC(RAMP_GRAY, 48), OPAQUE);
++ fos_text(cv, &fos_font_lg, 40, y + 44, title, C_TEXT, OPAQUE, 0);
++ fos_text(cv, &fos_font_sm, 40, y + 74, body, C_TEXT2, OPAQUE, 0);
++ int base = y + 118;
++ int x = 40;
++ x += ui_keycap(x, base, "SET") + 8;
++ x += fos_text(cv, &fos_font_md, x, base, yes, C_ACCENT, OPAQUE, 0) + 28;
++ if (alt)
++ {
++ x += ui_keycap(x, base, "INFO") + 8;
++ x += fos_text(cv, &fos_font_md, x, base, alt, C_TEXT, OPAQUE, 0) + 28;
++ }
++ x += ui_keycap(x, base, "MENU") + 8;
++ fos_text(cv, &fos_font_md, x, base, no, C_TEXT2, OPAQUE, 0);
++}
++
++/* small line icons, about 26 px */
++void ui_icon(int kind, int cx, int cy, fcol c, int a)
++{
++ int X = cx * 256, Y = cy * 256;
++ int w = 2 * 256;
++ switch (kind)
++ {
++ case ICON_FILM: /* a canister from the side, leader out */
++ fos_rrect_line(cv, cx - 8, cy - 10, 13, 21, 3, 2, c, a);
++ fos_fill(cv, cx - 5, cy - 13, 7, 3, c);
++ fos_rrect(cv, cx + 5, cy - 4, 8, 9, 1, c, a);
++ break;
++ case ICON_ROLL: /* a strip of two frames */
++ fos_rrect_line(cv, cx - 12, cy - 9, 24, 18, 2, 2, c, a);
++ for (int i = 0; i < 4; i++)
++ {
++ fos_fill(cv, cx - 9 + i * 6, cy - 7, 3, 2, c);
++ fos_fill(cv, cx - 9 + i * 6, cy + 5, 3, 2, c);
++ }
++ fos_fill(cv, cx - 1, cy - 4, 2, 8, c);
++ break;
++ case ICON_FINDER: /* the focusing screen */
++ fos_rrect_line(cv, cx - 12, cy - 9, 24, 18, 2, 2, c, a);
++ fos_ring(cv, X, Y, 5 * 256, w, c, a);
++ fos_line(cv, X - 5 * 256, Y, X + 5 * 256, Y, 300, c, a);
++ break;
++ case ICON_LENS: /* an aperture */
++ for (int i = 0; i < 6; i++)
++ {
++ int t = i * 65536 / 6 + 4000;
++ fos_line(cv, X + fos_cos(t) * 11 / 16, Y + fos_sin(t) * 11 / 16,
++ X + fos_cos(t + 65536 / 6) * 11 / 16, Y + fos_sin(t + 65536 / 6) * 11 / 16, w, c, a);
++ fos_line(cv, X + fos_cos(t) * 11 / 16, Y + fos_sin(t) * 11 / 16,
++ X + fos_cos(t + 65536 / 3) * 5 / 16, Y + fos_sin(t + 65536 / 3) * 5 / 16, 350, c, a);
++ }
++ break;
++ case ICON_PRINTS: /* two prints, the front one with a hill and a sun */
++ fos_fill(cv, cx - 13, cy - 11, 2, 14, c);
++ fos_fill(cv, cx - 13, cy - 11, 18, 2, c);
++ fos_rrect_line(cv, cx - 8, cy - 6, 21, 16, 2, 2, c, a);
++ fos_tri(cv, cx + 1, cy + 5, 7, 3, c, a);
++ fos_disc(cv, (cx + 8) * 256, (cy - 1) * 256, 2 * 256, c, a);
++ break;
++ case ICON_SYSTEM: /* a gear */
++ fos_ring(cv, X, Y, 7 * 256, 3 * 256, c, a);
++ for (int i = 0; i < 8; i++)
++ {
++ int t = i * 65536 / 8;
++ fos_line(cv, X + fos_cos(t) * 8 / 16, Y + fos_sin(t) * 8 / 16,
++ X + fos_cos(t) * 12 / 16, Y + fos_sin(t) * 12 / 16, 3 * 256, c, a);
++ }
++ break;
++ }
++}
++
++/* ---------------------------------------------------------------- the aperture */
++
++#define BLADES 7
++
++/* the blades around an opening of radius r px centred on (cx8, cy8):
++ * each blade is the region beyond one edge of the opening, wedged between
++ * the extended edges of its neighbours */
++static void blades(int cx8, int cy8, int r, int angle, int reach, int shade0)
++{
++ int vx[BLADES], vy[BLADES], dx[BLADES], dy[BLADES];
++ for (int k = 0; k < BLADES; k++)
++ {
++ int a = angle + k * 65536 / BLADES;
++ vx[k] = cx8 + fos_cos(a) * r / 16;
++ vy[k] = cy8 + fos_sin(a) * r / 16;
++ }
++ for (int k = 0; k < BLADES; k++)
++ {
++ int j = (k + 1) % BLADES;
++ int ex = (vx[j] - vx[k]) >> 8, ey = (vy[j] - vy[k]) >> 8;
++ int len = fos_isqrt((unsigned) (ex * ex + ey * ey));
++ if (!len)
++ {
++ /* fully closed: edge directions from the angle alone */
++ int a = angle + k * 65536 / BLADES + 65536 / 4 + 65536 / (2 * BLADES);
++ dx[k] = fos_cos(a); dy[k] = fos_sin(a);
++ }
++ else { dx[k] = ex * 4096 / len; dy[k] = ey * 4096 / len; }
++ }
++ for (int k = 0; k < BLADES; k++)
++ {
++ int p = (k + BLADES - 1) % BLADES;
++ int pts[6] = {
++ vx[k], vy[k],
++ vx[k] + dx[k] * reach / 16, vy[k] + dy[k] * reach / 16,
++ vx[k] + dx[p] * reach / 16, vy[k] + dy[p] * reach / 16,
++ };
++ int shade = shade0 + (k * 37 % 7) * 2;
++ fos_convex(cv, pts, 3, FC(RAMP_METAL, shade), OPAQUE);
++ }
++ /* a lit edge on every blade, and a shadow where blades overlap */
++ for (int k = 0; k < BLADES; k++)
++ {
++ int j = (k + 1) % BLADES;
++ int p = (k + BLADES - 1) % BLADES;
++ if (r > 2)
++ fos_line(cv, vx[k], vy[k], vx[j], vy[j], 384, FC(RAMP_METAL, shade0 + 72), OPAQUE);
++ /* the shadow fades into the blades: only near the opening */
++ int sl = reach < 2 * r + 60 ? reach : 2 * r + 60;
++ fos_line(cv, vx[k], vy[k], vx[k] + dx[p] * sl / 16, vy[k] + dy[p] * sl / 16,
++ 300, FC(RAMP_METAL, shade0 / 3), OPAQUE);
++ }
++}
++
++void ui_iris(int open, int angle)
++{
++ if (open >= 4096) return;
++ /* opening radius: 0 .. a bit past the corners */
++ blades(360 * 256, 240 * 256, (int) ((int64_t) 450 * open / 4096), angle, 1400, 20);
++}
++
++void ui_aperture(int cx, int cy, int R, int open, int angle)
++{
++ struct fos_canvas save = *cv;
++ fos_clip(cv, cx - R - 2, cy - R - 2, cx + R + 3, cy + R + 3);
++ blades(cx * 256 + 128, cy * 256 + 128, R * open / 4096, angle, 2 * R + 24, 24);
++ /* outside the barrel the background comes back, with a soft edge */
++ int in = (R * 16 - 8) * (R * 16 - 8), out = (R * 16 + 8) * (R * 16 + 8);
++ for (int y = cv->cy0; y < cv->cy1; y++)
++ {
++ int dy = (y - cy) * 16;
++ /* |x - cx| <= xi: inside the opening; >= xo: background only */
++ int xi = dy * dy < in ? fos_isqrt(in - dy * dy) >> 4 : -1;
++ int xo = dy * dy < out ? (fos_isqrt(out - dy * dy) >> 4) + 1 : 0;
++ for (int x = cv->cx0; x < cv->cx1; x++)
++ {
++ int ax = x < cx ? cx - x : x - cx;
++ if (ax <= xi) { x = cx + xi; continue; }
++ if (ax >= xo) { cv->px[y * cv->pitch + x] = ui_bg[y * FOS_W + x]; continue; }
++ int dx = (x - cx) * 16;
++ int d2 = dx * dx + dy * dy;
++ if (d2 <= in) continue;
++ int d = fos_isqrt(d2) - R * 16; /* 1/16 px outside */
++ int a = fos_clamp(128 + d * 16, 0, 256);
++ uint8_t bg = ui_bg[y * FOS_W + x];
++ uint8_t *p = &cv->px[y * cv->pitch + x];
++ if (a >= 256) *p = bg;
++ else
++ {
++ fcol c = fos_colour_of(bg);
++ *p = fos_mix(*p, FC_RAMP(c), LV12(FC_LEVEL(c)), a);
++ }
++ }
++ }
++ *cv = save;
++ /* the barrel */
++ fos_ring(cv, cx * 256 + 128, cy * 256 + 128, R * 256 + 256, 3 * 256, FC(RAMP_METAL, 70), OPAQUE);
++ fos_ring(cv, cx * 256 + 128, cy * 256 + 128, R * 256 + 3 * 256, 2 * 256, FC(RAMP_METAL, 28), OPAQUE);
++}
++
++/* ---------------------------------------------------------------- boot */
++
++/* power on: a lens aperture opens on the name */
++static void boot_draw(int t)
++{
++ if (t <= 40)
++ memset(ui_bg, fos_ix(FC(RAMP_GRAY, 6)), FOS_W * FOS_H);
++ fos_fill(cv, 0, 0, FOS_W, FOS_H, FC(RAMP_GRAY, 6));
++ float k = clampf((t - 150) / 900.0f, 0, 1);
++ float e = ease_out(k);
++ int open = (int) (60 + e * 2200);
++ ui_aperture(360, 186, 50, open, 2000 + (int) (e * 7000));
++ /* a warm glint through the opening */
++ fos_disc(cv, 360 * 256, 186 * 256, (int) (open * 50 / 4096) * 200, C_ACCENT, (int) (e * 120));
++ float tk = clampf((t - 450) / 700.0f, 0, 1);
++ int a = (int) (ease_out(tk) * 256);
++ int track = (int) (160 - 96 * ease_out(tk));
++ fos_text_c(cv, &fos_font_lg, 360, 290, FOS_NAME, C_TEXT, a, track);
++ fos_text_c(cv, &fos_font_xs, 360, 318, "35 MM FILM SYSTEM", C_TEXT3, (int) (ease_out(clampf((t - 750) / 600.0f, 0, 1)) * 256), 48);
++ ui_damage_all();
++}
++
++/* ---------------------------------------------------------------- navigation */
++
++void ui_go(int to, int arg, int how)
++{
++ /* keep what is on screen now; the new screen slides over it */
++ memcpy(buf_snap, cv->px, FOS_W * FOS_H);
++ screen_from = screen;
++ if (screen == SCR_SHELF) shelf_leave();
++ if (screen == SCR_DEVELOP) develop_leave();
++ if (screen == SCR_PRINTS) prints_leave();
++ screen = to;
++ tr_how = how;
++ tr_t = 0;
++ tr_len = how == GO_FADE ? 520 : 340;
++ ui_clobbered = 1; /* the new screen starts from nothing */
++ switch (to)
++ {
++ case SCR_SHELF: shelf_enter(arg); break;
++ case SCR_HOME: home_enter(arg); break;
++ case SCR_PAGE: page_enter(arg); break;
++ case SCR_ROLL: roll_enter(arg); break;
++ case SCR_DARK: dark_enter(arg); break;
++ case SCR_DEVELOP: develop_enter(arg); break;
++ case SCR_PRINTS: prints_enter(arg); break;
++ }
++ ui_damage_all();
++}
++
++int ui_settled()
++{
++ return !(tr_len && tr_t < tr_len) && !leaving && enter_t >= ENTER_LEN;
++}
++
++int ui_from()
++{
++ return screen_from;
++}
++
++void ui_leave()
++{
++ if (leaving) return;
++ leaving = 1;
++ leave_t = 0;
++}
++
++/* ---------------------------------------------------------------- the loop */
++
++static void screen_key(int k)
++{
++ switch (screen)
++ {
++ case SCR_BOOT:
++ if (boot_then_leave) ui_leave();
++ else ui_go(SCR_SHELF, 0, GO_FADE);
++ break;
++ case SCR_SHELF: shelf_key(k); break;
++ case SCR_HOME: home_key(k); break;
++ case SCR_PAGE: page_key(k); break;
++ case SCR_ROLL: roll_key(k); break;
++ case SCR_DARK: dark_key(k); break;
++ case SCR_DEVELOP: develop_key(k); break;
++ case SCR_PRINTS: prints_key(k); break;
++ }
++}
++
++static int screen_update(int dt)
++{
++ switch (screen)
++ {
++ case SCR_SHELF: return shelf_update(dt);
++ case SCR_HOME: return home_update(dt);
++ case SCR_PAGE: return page_update(dt);
++ case SCR_ROLL: return roll_update(dt);
++ case SCR_DARK: return dark_update(dt);
++ case SCR_DEVELOP: return develop_update(dt);
++ case SCR_PRINTS: return prints_update(dt);
++ }
++ return 0;
++}
++
++static void screen_draw()
++{
++ switch (screen)
++ {
++ case SCR_SHELF: shelf_draw(); break;
++ case SCR_HOME: home_draw(); break;
++ case SCR_PAGE: page_draw(); break;
++ case SCR_ROLL: roll_draw(); break;
++ case SCR_DARK: dark_draw(); break;
++ case SCR_DEVELOP: develop_draw(); break;
++ case SCR_PRINTS: prints_draw(); break;
++ }
++}
++
++/* the screen change: the old frame (snapshot) and the new one, composed a
++ * row at a time straight into the presented rows */
++static uint8_t row_buf[FOS_W];
++static uint8_t dim_lut[256];
++
++/* row_buf[x0..x1): the dimmed layer where it has pixels (u0..u1), else bg */
++static void dim_run(uint8_t *row, const uint8_t *urow, int x0, int x1, int u0, int u1, uint8_t bg)
++{
++ int a = fos_clamp(u0, x0, x1), b = fos_clamp(u1, a, x1);
++ memset(row + x0, bg, a - x0);
++ int x = a;
++ for (; x + 4 <= b; x += 4)
++ {
++ row[x] = dim_lut[urow[x]];
++ row[x + 1] = dim_lut[urow[x + 1]];
++ row[x + 2] = dim_lut[urow[x + 2]];
++ row[x + 3] = dim_lut[urow[x + 3]];
++ }
++ for (; x < b; x++)
++ row[x] = dim_lut[urow[x]];
++ memset(row + b, bg, x1 - b);
++}
++
++static void present_transition(float t)
++{
++ float e = ease_out(t);
++ int how = tr_how;
++ int shift_new, shift_old, dim;
++ if (how == GO_PUSH) { shift_new = (int) ((1 - e) * FOS_W); shift_old = -(int) (e * FOS_W * 0.3f); dim = (int) (256 - e * 150); }
++ else if (how == GO_POP) { shift_new = -(int) ((1 - e) * FOS_W * 0.3f); shift_old = (int) (e * FOS_W); dim = (int) (106 + e * 150); }
++ else { shift_new = 0; shift_old = 0; dim = 0; }
++
++ if (how == GO_FADE)
++ {
++ /* dip: the old screen sinks into the dark, the new one rises from it */
++ int k = t < 0.45f ? (int) ((1 - t / 0.45f) * 256) : (int) (ease_out((t - 0.45f) / 0.55f) * 256);
++ const uint8_t *src = t < 0.45f ? buf_snap : cv->px;
++ for (int i = 0; i < 256; i++)
++ {
++ fcol c = fos_colour_of(i);
++ dim_lut[i] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * k / 256));
++ }
++ for (int y = 0; y < FOS_H; y++)
++ {
++ for (int x = 0; x < FOS_W; x++)
++ row_buf[x] = dim_lut[src[y * FOS_W + x]];
++ fos_port_present(row_buf, FOS_W, y, y + 1);
++ }
++ return;
++ }
++
++ for (int i = 0; i < 256; i++)
++ {
++ fcol c = fos_colour_of(i);
++ dim_lut[i] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * dim / 256));
++ }
++ const uint8_t *top = how == GO_PUSH ? cv->px : buf_snap; /* the sliding layer */
++ const uint8_t *under = how == GO_PUSH ? buf_snap : cv->px;
++ int shift_top = how == GO_PUSH ? shift_new : shift_old;
++ int shift_under = how == GO_PUSH ? shift_old : shift_new;
++ uint8_t bg = fos_ix(C_BG);
++ /* the sliding layer covers [t0, t1); the dimmed one shows elsewhere
++ * where it has pixels, [u0, u1) */
++ int t0 = fos_clamp(shift_top, 0, FOS_W), t1 = fos_clamp(shift_top + FOS_W, 0, FOS_W);
++ int u0 = fos_clamp(shift_under, 0, FOS_W), u1 = fos_clamp(shift_under + FOS_W, 0, FOS_W);
++ for (int y = 0; y < FOS_H; y++)
++ {
++ const uint8_t *trow = top + y * FOS_W, *urow = under + y * FOS_W - shift_under;
++ dim_run(row_buf, urow, 0, t0, u0, u1, bg);
++ dim_run(row_buf, urow, t1, FOS_W, u0, u1, bg);
++ if (t1 > t0)
++ memcpy(row_buf + t0, trow + (t0 - shift_top), t1 - t0);
++ /* a soft shadow on the edge of the sliding layer */
++ for (int s = 1; s <= 10; s++)
++ {
++ int x = shift_top - s;
++ if (x >= 0 && x < FOS_W)
++ {
++ fcol c = fos_colour_of(row_buf[x]);
++ row_buf[x] = fos_ix(FC(FC_RAMP(c), FC_LEVEL(c) * (156 + s * 10) / 256));
++ }
++ }
++ fos_port_present(row_buf, FOS_W, y, y + 1);
++ }
++}
++
++static int ui_alloc()
++{
++ buf_cv = fos_port_alloc(FOS_W * FOS_H);
++ buf_bg = fos_port_alloc(FOS_W * FOS_H);
++ buf_snap = fos_port_alloc(FOS_W * FOS_H);
++ if (!buf_cv || !buf_bg || !buf_snap)
++ {
++ fos_port_free(buf_cv); fos_port_free(buf_bg); fos_port_free(buf_snap);
++ buf_cv = buf_bg = buf_snap = 0;
++ return 0;
++ }
++ fos_canvas_init(&canvas, buf_cv, FOS_W, FOS_W, FOS_H);
++ cv = &canvas;
++ ui_bg = buf_bg;
++ return 1;
++}
++
++static void ui_free()
++{
++ ui_cans_free();
++ fos_port_free(buf_plain);
++ buf_plain = 0;
++ fos_port_free(buf_cv); fos_port_free(buf_bg); fos_port_free(buf_snap);
++ buf_cv = buf_bg = buf_snap = 0;
++}
++
++void fos_ui_init()
++{
++ fos_gfx_init();
++}
++
++/* how long frames take: drawing, copying to the screen, and the rest
++ * between them. A slow camera gets simpler canisters rather than a
++ * stuttering shelf. */
++static struct fos_stat stat;
++static int stat_since, frame_end;
++
++static void frame_stats(int draw_ms, int present_ms)
++{
++ static int slow, quick;
++ stat.frames++;
++ stat.cans_ms += ui_cans_ms;
++ ui_cans_ms = 0;
++ stat.draw_ms += draw_ms;
++ stat.present_ms += present_ms;
++ if (draw_ms + present_ms > stat.worst_ms) stat.worst_ms = draw_ms + present_ms;
++ frame_end = fos_port_ms();
++ if (ui_now - stat_since < 1000) return;
++ fos_port_stat(&stat);
++ int avg = (stat.draw_ms + stat.present_ms) / stat.frames;
++ if (avg > 50) { slow++; quick = 0; }
++ else if (avg < 26) { quick++; slow = 0; }
++ else slow = quick = 0;
++ if (slow >= 1 && fos_can_quality > 0) { fos_can_quality--; slow = 0; }
++ if (quick >= 3 && fos_can_quality < 2) { fos_can_quality++; quick = 0; }
++ memset(&stat, 0, sizeof(stat));
++ stat_since = ui_now;
++}
++
++/* while animating: rest what is left of a frame (about 35 a second), but
++ * always a little, so the camera's own tasks get to run */
++#define FRAME_PERIOD 28
++static int frame_rest(int frame_start)
++{
++ return fos_clamp(FRAME_PERIOD - (fos_port_ms() - frame_start), 1, 10);
++}
++
++static int is_repeating(int k)
++{
++ return k == FK_LEFT || k == FK_RIGHT || k == FK_UP || k == FK_DOWN;
++}
++
++void fos_ui_run(int open)
++{
++ int t_open = fos_port_ms();
++ if (!ui_alloc())
++ return;
++ fos_port_roll(&ui_roll);
++ quit = 0;
++ leaving = 0;
++ held_key = 0;
++ toast_t = TOAST_LEN;
++ screen = SCR_NONE;
++ screen_from = SCR_NONE;
++ enter_t = 0;
++
++ /* what is under the shutter while it closes: LiveView */
++ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
++ ui_clobbered = 1;
++ fos_port_palette();
++
++ boot_then_leave = open == FOS_OPEN_BOOT_LV;
++ if (open == FOS_OPEN_BOOT || open == FOS_OPEN_BOOT_LV)
++ screen = SCR_BOOT, enter_t = ENTER_LEN;
++ else
++ {
++ switch (open)
++ {
++ case FOS_OPEN_HOME: screen = SCR_HOME; home_enter(0); break;
++ case FOS_OPEN_PRINTS: screen = SCR_PRINTS; prints_enter(PRINTS_ALONE); break;
++ case FOS_OPEN_END: screen = SCR_ROLL; roll_enter(1); break;
++ case FOS_OPEN_DARKROOM: screen = SCR_DARK; dark_enter(0); break;
++ default: screen = SCR_SHELF; shelf_enter(0); break;
++ }
++ }
++ tr_how = 0; tr_t = tr_len = 0;
++
++ int last = fos_port_ms();
++ int boot_t = 0;
++ int opened = 0;
++ memset(&stat, 0, sizeof(stat));
++ stat_since = frame_end = 0;
++ while (!quit)
++ {
++ int now = fos_port_ms();
++ int dt = fos_clamp(now - last, 0, 60);
++ last = now;
++ /* the rest after the last animated frame, slept or taken by others */
++ if (frame_end) { stat.rest_ms += now - frame_end; frame_end = 0; }
++ ui_now = now;
++
++ if (fos_port_abort())
++ break;
++
++ /* keys, with auto-repeat for held arrows */
++ int k;
++ while ((k = fos_port_key()) != FK_NONE)
++ {
++ if (k & FK_RELEASE)
++ {
++ if ((k & 0xFF) == held_key) held_key = 0;
++ continue;
++ }
++ if (is_repeating(k)) { held_key = k; held_since = now; held_last = now; }
++ if (leaving || enter_t < ENTER_LEN) continue;
++ screen_key(k);
++ }
++ /* a release that never came must not scroll forever */
++ if (held_key && now - held_since > 3000)
++ held_key = 0;
++ if (held_key && now - held_since > 420 && now - held_last > 95 && !leaving)
++ {
++ held_last = now;
++ screen_key(held_key);
++ }
++
++ int moving = 0;
++ if (screen == SCR_BOOT)
++ {
++ boot_t += dt;
++ boot_draw(boot_t);
++ moving = 1;
++ if (boot_t > 1700 && boot_then_leave)
++ {
++ ui_leave();
++ boot_t = -100000; /* once */
++ }
++ else if (boot_t > 1700)
++ ui_go(SCR_SHELF, 0, GO_FADE);
++ }
++ else
++ {
++ moving |= screen_update(dt);
++ if (tr_len && tr_t < tr_len) { tr_t += dt; moving = 1; }
++ }
++
++ int in_tr = tr_len && tr_t < tr_len;
++ int t_draw = fos_port_ms();
++ if (enter_t < ENTER_LEN || leaving)
++ {
++ /* the shutter: closes over LiveView, opens on us (and the
++ * reverse when leaving) */
++ int t;
++ if (leaving) { leave_t += dt; t = leave_t; }
++ else { enter_t += dt; t = enter_t; }
++ if (screen != SCR_BOOT) screen_draw();
++ int open_k;
++ int ang = (int) (t * 9);
++ if (leaving)
++ {
++ float f = clampf((float) t / LEAVE_LEN, 0, 1);
++ if (f < 0.35f) open_k = (int) ((1 - ease_out(f / 0.35f)) * 4096);
++ else
++ {
++ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
++ open_k = (int) (ease_out((f - 0.35f) / 0.65f) * 4096);
++ }
++ if (t >= LEAVE_LEN) quit = 1;
++ }
++ else
++ {
++ float f = clampf((float) t / ENTER_LEN, 0, 1);
++ if (f < 0.4f)
++ {
++ memset(buf_cv, IX_CLEAR, FOS_W * FOS_H);
++ open_k = (int) ((1 - ease_out(f / 0.4f)) * 4096);
++ }
++ else open_k = (int) (ease_out((f - 0.4f) / 0.6f) * 4096);
++ }
++ ui_iris(open_k, ang);
++ ui_clobbered = 1;
++ fos_port_present(cv->px, FOS_W, 0, FOS_H);
++ if (!opened) { opened = 1; stat.open_ms = fos_port_ms() - t_open; }
++ dmg_y0 = FOS_H; dmg_y1 = 0;
++ fos_port_sleep(frame_rest(now));
++ continue;
++ }
++
++ int t_present;
++ if (in_tr)
++ {
++ screen_draw();
++ t_present = fos_port_ms();
++ present_transition((float) tr_t / tr_len);
++ ui_clobbered = 1; /* the screen only reached the panel composed */
++ dmg_y0 = FOS_H; dmg_y1 = 0;
++ }
++ else
++ {
++ if (toast_t < TOAST_LEN)
++ {
++ toast_t += dt;
++ moving = 1;
++ ui_damage(HINTS_Y - 50, HINTS_Y);
++ ui_clobbered = 1; /* the screen must paint under it again */
++ }
++ if (screen != SCR_BOOT && (dmg_y1 > dmg_y0 || moving))
++ {
++ screen_draw();
++ toast_draw();
++ }
++ t_present = fos_port_ms();
++ if (dmg_y1 > dmg_y0)
++ {
++ fos_port_present(cv->px + dmg_y0 * FOS_W, FOS_W, dmg_y0, dmg_y1);
++ if (!opened) { opened = 1; stat.open_ms = fos_port_ms() - t_open; }
++ }
++ dmg_y0 = FOS_H; dmg_y1 = 0;
++ }
++ if (moving || in_tr)
++ frame_stats(t_present - t_draw, fos_port_ms() - t_present);
++ fos_port_sleep(moving || in_tr ? frame_rest(now) : 40);
++ }
++ if (stat.frames || stat.open_ms) fos_port_stat(&stat); /* the last part second */
++ if (screen == SCR_DEVELOP) develop_leave();
++ if (screen == SCR_PRINTS) prints_leave();
++ dark_free();
++ ui_free();
++}
+diff --git a/src/fos_ui.h b/src/fos_ui.h
+new file mode 100644
+index 000000000..cc38d6e71
+--- /dev/null
++++ b/src/fos_ui.h
+@@ -0,0 +1,146 @@
++/* fos_ui.h: shared between the film OS screens (fos_ui.c, fos_shelf.c,
++ * fos_pages.c). Not used by the camera glue. */
++
++#ifndef _fos_ui_h_
++#define _fos_ui_h_
++
++#include "fos.h"
++
++/* ---------------------------------------------------------------- style */
++
++#define C_BG FC(RAMP_GRAY, 11)
++#define C_PANEL FC(RAMP_GRAY, 21)
++#define C_PANEL_HI FC(RAMP_GRAY, 32)
++#define C_LINE FC(RAMP_GRAY, 40)
++#define C_TEXT FC(RAMP_GRAY, 240)
++#define C_TEXT2 FC(RAMP_GRAY, 170)
++#define C_TEXT3 FC(RAMP_GRAY, 112)
++#define C_ACCENT FC(RAMP_AMBER, 186)
++#define C_ACCENT2 FC(RAMP_AMBER, 120)
++#define C_RED FC(RAMP_RED, 150)
++
++#define STATUS_H 36
++#define HINTS_Y 444
++
++/* ---------------------------------------------------------------- shared state */
++
++extern struct fos_canvas *cv; /* what the screens draw into */
++extern uint8_t *ui_bg; /* background of the current screen, same layout */
++extern int ui_now; /* ms */
++extern struct fos_roll ui_roll;
++
++/* set when something else drew over the canvas (the shutter, a screen
++ * change): screens that redraw only what moved must redraw it all */
++extern int ui_clobbered;
++
++/* rows that changed this frame (the loop presents them) */
++void ui_damage(int y0, int y1);
++void ui_damage_all();
++
++/* ---------------------------------------------------------------- animation */
++
++struct spring { float x, v; };
++
++/* steps towards target; returns 1 while still moving */
++int spring_step(struct spring *s, float target, int dt, float hz, float zeta);
++float ease_out(float t); /* cubic */
++float ease_in_out(float t);
++float clampf(float v, float lo, float hi);
++
++/* ---------------------------------------------------------------- navigation */
++
++enum { SCR_NONE, SCR_BOOT, SCR_SHELF, SCR_HOME, SCR_PAGE, SCR_ROLL, SCR_DARK, SCR_DEVELOP, SCR_PRINTS };
++enum { GO_PUSH = 1, GO_POP = -1, GO_FADE = 0 };
++
++void ui_go(int screen, int arg, int how);
++void ui_leave(); /* back to LiveView, shutter opening on it */
++int ui_from(); /* screen we came from */
++int ui_settled(); /* no screen change, shutter or iris under way */
++
++/* ---------------------------------------------------------------- widgets */
++
++void ui_bg_restore(int x, int y, int w, int h);
++void ui_to_bg(int on); /* widgets draw into ui_bg instead of the screen */
++void ui_bg_plain(); /* the usual dark backdrop into ui_bg */
++void ui_status_bar(const char *title);
++
++struct hint { const char *key; const char *label; };
++void ui_hints(const struct hint *h, int n);
++int ui_keycap(int x, int base, const char *key); /* returns width */
++
++void ui_dots(int x, int y, int n, int filled, fcol on); /* 1..5 rating */
++
++/* a short message in a pill above the hints, fading after a moment */
++void ui_toast(const char *msg);
++int ui_toast_up(); /* 1 while one is showing */
++
++/* a question sliding up from the bottom; s = 0..1 how far it is in */
++void ui_sheet(float s, const char *title, const char *body, const char *yes, const char *no);
++/* the same with a third answer on INFO */
++void ui_sheet3(float s, const char *title, const char *body, const char *yes, const char *alt, const char *no);
++
++enum { ICON_FILM, ICON_ROLL, ICON_FINDER, ICON_LENS, ICON_SYSTEM, ICON_PRINTS };
++void ui_icon(int kind, int cx, int cy, fcol c, int alpha);
++
++/* the aperture over the whole screen: 0 = closed, 4096 = gone; the
++ * opening shows what is already on the canvas */
++void ui_iris(int open, int angle);
++
++/* a lens aperture inside a barrel of radius R px (same blades, smaller) */
++void ui_aperture(int cx, int cy, int R, int open, int angle);
++
++/* ---------------------------------------------------------------- screens */
++
++void shelf_enter(int arg);
++void shelf_leave();
++void shelf_key(int key);
++int shelf_update(int dt);
++void shelf_draw();
++
++void home_enter(int arg);
++void home_key(int key);
++int home_update(int dt);
++void home_draw();
++
++void page_enter(int arg);
++void page_key(int key);
++int page_update(int dt);
++void page_draw();
++
++void roll_enter(int arg);
++void roll_key(int key);
++int roll_update(int dt);
++void roll_draw();
++
++/* the darkroom (fos_dark.c): arg is a roll number, 0 for the newest */
++void dark_enter(int arg);
++void dark_free(); /* its memory, when the film OS closes */
++void dark_key(int key);
++int dark_update(int dt);
++void dark_draw();
++
++/* developing the rolls queued with dark_queue (arg unused) */
++void dark_queue_clear();
++void dark_queue_add(int roll);
++void develop_enter(int arg);
++void develop_leave();
++void develop_key(int key);
++int develop_update(int dt);
++void develop_draw();
++
++/* prints: arg is a roll number (0: the newest developed); PRINTS_ALONE
++ * or-ed in when opened by PLAY from the camera */
++#define PRINTS_ALONE 0x10000
++void prints_enter(int arg);
++void prints_leave();
++void prints_key(int key);
++int prints_update(int dt);
++void prints_draw();
++
++/* the canisters, kept while the UI is open (fos_shelf.c) */
++struct fos_can *ui_can(int film);
++void ui_cans_free();
++extern int ui_cans_ms; /* time spent drawing canisters, for the frame stats */
++void ui_cans_exposures(int exposures);
++
++#endif
+diff --git a/src/gui-common.c b/src/gui-common.c
+index 992e8f692..13f631291 100644
+--- a/src/gui-common.c
++++ b/src/gui-common.c
+@@ -8,6 +8,7 @@
+ #include <boot-hack.h>
+ #include <fps.h>
+ #include <zebra.h>
++#include <filmroll.h>
+ #include <lens.h>
+ #include <config.h>
+ #include <lvinfo.h>
+@@ -505,6 +506,9 @@ int handle_common_events_by_feature(struct event * event)
+ if (handle_zoom_overlay(event) == 0) return 0;
+ #endif
+
++#ifdef FEATURE_FILMROLL
++ if (handle_filmroll_keys(event) == 0) return 0;
++#endif
+ if (handle_module_keys(event) == 0) return 0;
+ if (handle_flexinfo_keys(event) == 0) return 0;
+
+diff --git a/src/menu.c b/src/menu.c
+index a83f43e1b..57405de9d 100755
+--- a/src/menu.c
++++ b/src/menu.c
+@@ -39,6 +39,7 @@
+ #include "debug.h"
+ #include "lvinfo.h"
+ #include "powersave.h"
++#include "filmroll.h"
+
+ #define CONFIG_MENU_ICONS
+ //~ #define CONFIG_MENU_DIM_HACKS
+@@ -5648,6 +5649,10 @@ static void close_canon_menu()
+
+ static void menu_open()
+ {
++#ifdef FEATURE_FILMROLL
++ filmroll_menu_requested();
++ return;
++#endif
+ if (menu_shown)
+ return;
+
+diff --git a/src/zebra.c b/src/zebra.c
+index ee713a6ca..9b74b2e6e 100644
+--- a/src/zebra.c
++++ b/src/zebra.c
+@@ -23,6 +23,7 @@
+ */
+
+ #include "zebra.h"
++#include "filmroll.h"
+ #include "vectorscope.h"
+ #include "electronic_level.h"
+ #include "dryos.h"
+@@ -408,6 +409,9 @@ extern int idle_globaldraw_disable;
+
+ int get_global_draw() // menu setting, or off if
+ {
++#ifdef FEATURE_FILMROLL
++ if (filmroll_overlays_active()) return 0;
++#endif
+ #ifdef FEATURE_GLOBAL_DRAW
+
+ #ifdef LV_OVERLAYS_MODE
diff --git a/ml-dev/fork/src/filmroll.c b/ml-dev/fork/src/filmroll.c
new file mode 100644
index 0000000..50b8ffb
--- /dev/null
+++ b/ml-dev/fork/src/filmroll.c
@@ -0,0 +1,1387 @@
+/* filmroll: a Canon camera as a film camera (built into this ML fork).
+ * Made on the EOS M; 100D, 650D, 700D and others build from the same code.
+ *
+ * The camera side of the film OS (ml-dev/filmos): rolls, the roll log the
+ * PC lab reads, film settings, the viewfinder HUD, and the fos_port_*
+ * functions through which the film OS takes the screen and the buttons.
+ *
+ * - the film OS is the camera's own interface: the film shelf at start
+ * up, home and its settings pages instead of the Magic Lantern menu.
+ * The ML menu is gone: what used to open it (two-finger tap, long
+ * press on DOWN, modules) opens home.
+ * - an SLR-viewfinder HUD in LiveView: aperture scale with meter needle,
+ * red LED readout that lights on half-shutter, frame counter, wind
+ * - PLAY opens the prints the camera has developed, never Canon's
+ * playback of undeveloped frames
+ * - a finished roll is developed in the camera (fos_dev.c): its RAWs
+ * become prints in ML/DARKROOM, shown on their own palettes
+ * - manual lenses: the f-stop is dialled in and logged for the lab
+ *
+ * Loading a roll sets picture style, contrast / saturation / colour tone,
+ * white balance and ISO for that stock, and starts a roll log next to the
+ * images (DCIM/xxxCANON/ROLL_nnn.TXT) that the PC film lab reads
+ * (the desktop darkroom, Darkrooms). Film keys must match films/films.py.
+ *
+ * Shots are detected by watching the file number, so every frame is
+ * logged even in burst mode.
+ */
+
+#include <dryos.h>
+#include <module.h>
+#include <property.h>
+#include <menu.h>
+#include <config.h>
+#include <lens.h>
+#include <picstyle.h>
+#include <beep.h>
+#include <bmp.h>
+#include <fio-ml.h>
+#include <fileprefix.h>
+#include <notify_box.h>
+#include <zebra.h>
+#include <propvalues.h>
+#include <gui-common.h>
+#include <tasks.h>
+#include <mem.h>
+#include <powersave.h>
+#include "filmroll.h"
+#include "fos.h"
+#include "fos_dev.h"
+
+#include <stdarg.h>
+
+extern int ml_started;
+extern void CancelDateTimer();
+
+/* user settings */
+static CONFIG_INT("filmroll.film", film_sel, 0);
+static CONFIG_INT("filmroll.exp", exp_sel, 0);
+static CONFIG_INT("filmroll.hud", hud_enabled, 1);
+static CONFIG_INT("filmroll.focus", focus_screen, 1);
+static CONFIG_INT("filmroll.leds", leds_on_half, 1);
+static CONFIG_INT("filmroll.wind", wind_mode, 1); /* 0 off, 1 reminder, 2 block shutter */
+static CONFIG_INT("filmroll.playlock", play_lock, 1);
+static CONFIG_INT("filmroll.startup", startup_picker, 2); /* 0 off, 1 when no film, 2 always */
+static CONFIG_INT("filmroll.bootanim", boot_anim, 1);
+static CONFIG_INT("filmroll.debug", debug_log, 1);
+static CONFIG_INT("filmroll.lens_wide", lens_widest, 6); /* index into fos_fstops: f/1.8 */
+static CONFIG_INT("filmroll.fstop", manual_fstop, 6);
+static CONFIG_INT("filmroll.ap_keys", aperture_keys, 0); /* 0 wheel in Av, 1 up/down, 2 menu only */
+static CONFIG_INT("filmroll.scr_std", scr_std, 0); /* screen colour: 0 Canon, 1 Rec.709 */
+static CONFIG_INT("filmroll.scr_sat", scr_sat, 0); /* -6..6 */
+static CONFIG_INT("filmroll.scr_warm", scr_warm, 0);
+static CONFIG_INT("filmroll.scr_bright", scr_bright, 0);
+
+/* roll state, kept across power cycles */
+static CONFIG_INT("filmroll.loaded", roll_loaded, 0);
+static CONFIG_INT("filmroll.roll", roll_number, 0);
+static CONFIG_INT("filmroll.roll_film", roll_film, 0);
+static CONFIG_INT("filmroll.roll_exp", roll_exposures, 36);
+static CONFIG_INT("filmroll.shot", frames_shot, 0);
+static CONFIG_INT("filmroll.lastfile", last_file_number, -1);
+static CONFIG_INT("filmroll.logdir", roll_folder, 0);
+static CONFIG_INT("filmroll.needwind", need_wind, 0);
+
+static char log_path[64];
+
+static volatile int leds_until = 0; /* keep LEDs lit until this ms clock */
+static volatile int hud_dirty = 1;
+
+#define ROLL_FINISHED (roll_loaded && frames_shot >= roll_exposures)
+#define ROLL_IN_PROGRESS (roll_loaded && frames_shot < roll_exposures)
+
+static volatile int end_due = 0; /* the roll was just finished: ms when to ask about it */
+static volatile int dev_busy = 0; /* developing: keep the camera awake */
+
+/* the last frames, for the roll page (also read back from the log) */
+static struct { int no; char time[6]; char fstop[6]; } recent[FOS_RECENT];
+static int nrecent = 0;
+static char loaded_at[20];
+static int recent_valid = 0;
+
+/* ---------------------------------------------------------------- debug log */
+
+/* field-test trace in ML/FILMROLL.LOG; turn off in System once things work */
+static void dbg(const char *fmt, ...)
+{
+ if (!debug_log)
+ return;
+
+ char buf[192];
+ int n = snprintf(buf, sizeof(buf), "%7d ", get_ms_clock());
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf + n, sizeof(buf) - n, fmt, ap);
+ va_end(ap);
+
+ FILE *f = FIO_CreateFileOrAppend("ML/FILMROLL.LOG");
+ if (!f)
+ return;
+ my_fprintf(f, "%s\n", buf);
+ FIO_CloseFile(f);
+}
+
+/* The camera waiting for a picture, the screen the film OS opens from.
+ * On the EOS M that is LiveView; a DSLR (100D, 650D, 700D ...) is mostly
+ * shot through its optical viewfinder, so there it is also Canon's shooting
+ * screen with LiveView off. */
+#ifdef CONFIG_EOSM
+#define FOS_LV_ONLY 1
+#else
+#define FOS_LV_ONLY 0
+#endif
+static int shooting_screen()
+{
+ return (lv || !FOS_LV_ONLY) && display_idle() && !is_movie_mode();
+}
+
+#define DBG_STATE(what) dbg("%s: ml=%d lv=%d idle=%d movie=%d mode=%d gui=%d", what, \
+ ml_started, lv, display_idle(), is_movie_mode(), shooting_mode, CURRENT_GUI_MODE)
+
+/* ---------------------------------------------------------------- log file */
+
+static void update_log_path()
+{
+ snprintf(log_path, sizeof(log_path), "%s:/DCIM/%03d%s/ROLL_%03d.TXT",
+ get_shooting_card()->drive_letter, roll_folder, get_dcim_dir_suffix(),
+ roll_number);
+}
+
+static void log_append(const char *text)
+{
+ FILE *f = FIO_CreateFileOrAppend(log_path);
+ if (!f)
+ {
+ NotifyBox(3000, "filmroll: can't write %s", log_path);
+ return;
+ }
+ my_fprintf(f, "%s", text);
+ FIO_CloseFile(f);
+}
+
+static void format_now(char *buf, int size)
+{
+ struct tm now;
+ LoadCalendarFromRTC(&now);
+ snprintf(buf, size, "%04d-%02d-%02d %02d:%02d:%02d",
+ now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
+ now.tm_hour, now.tm_min, now.tm_sec);
+}
+
+static void write_header(const char *note)
+{
+ char when[32];
+ char header[320];
+ format_now(when, sizeof(when));
+ snprintf(header, sizeof(header),
+ "# ML film mode roll log (filmroll module)%s\n"
+ "roll = %03d\nfilm = %s\nexposures = %d\nloaded = %s\n\n",
+ note, roll_number, fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].key, roll_exposures, when);
+ log_append(header);
+}
+
+/* the roll page wants the loading time and the last frames: after a power
+ * cycle they only exist in the log, so read them back once */
+static void read_back_log()
+{
+ recent_valid = 1;
+ nrecent = 0;
+ loaded_at[0] = 0;
+ int size = 0;
+ char *buf = (char *) read_entire_file(log_path, &size);
+ if (!buf)
+ return;
+ for (char *line = buf; line && *line; )
+ {
+ char *next = strchr(line, '\n');
+ if (next) *next++ = 0;
+ if (!strncmp(line, "loaded = ", 9))
+ fos_copy(loaded_at, sizeof(loaded_at), line + 9, 16);
+ else if (line[0] >= '0' && line[0] <= '9')
+ {
+ /* "12 IMG_0012.CR2 2026-08-08 09:15:15 f/2.8" */
+ char *tok[5];
+ int n = 0;
+ for (char *p = line; *p && n < 5; )
+ {
+ while (*p == ' ') p++;
+ if (!*p) break;
+ tok[n++] = p;
+ while (*p && *p != ' ') p++;
+ if (*p) *p++ = 0;
+ }
+ if (n >= 4)
+ {
+ /* newest first, keep FOS_RECENT */
+ for (int i = MIN(nrecent, FOS_RECENT - 1); i > 0; i--)
+ recent[i] = recent[i - 1];
+ recent[0].no = atoi(tok[0]);
+ fos_copy(recent[0].time, sizeof(recent[0].time), tok[3], 5);
+ snprintf(recent[0].fstop, sizeof(recent[0].fstop), "%s",
+ n >= 5 && !strncmp(tok[4], "f/", 2) ? tok[4] + 2 : "?");
+ nrecent = MIN(nrecent + 1, FOS_RECENT);
+ }
+ }
+ line = next;
+ }
+ fio_free(buf);
+}
+
+/* ---------------------------------------------------------------- camera settings */
+
+static int iso_to_raw(int iso)
+{
+ int raw = 72; /* ISO 100 */
+ for (int i = 100; i < iso; i *= 2)
+ raw += 8; /* one stop */
+ return raw;
+}
+
+static void apply_film(int index)
+{
+ const struct fos_film *f = &fos_films[COERCE(index, 0, fos_nfilms - 1)];
+
+ int ps = f->picstyle;
+ prop_request_change_wait(PROP_PICTURE_STYLE, &ps, 4, 1000);
+ msleep(100);
+
+ /* these change the current picture style, so it must be selected first */
+ lens_set_contrast(f->contrast);
+ msleep(50);
+ lens_set_sharpness(f->sharpness);
+ msleep(50);
+ if (f->picstyle != PS_MONO)
+ {
+ lens_set_saturation(f->saturation);
+ msleep(50);
+ lens_set_color_tone(f->color_tone);
+ msleep(50);
+ }
+
+ lens_set_kelvin(f->kelvin);
+ lens_set_wbs_gm(f->wbs_gm);
+ lens_set_wbs_ba(f->wbs_ba);
+ lens_set_rawiso(iso_to_raw(f->iso));
+}
+
+/* Film is shot blind: the darkroom develops the RAWs, and there is no
+ * image review to peek at. ML doesn't change these Canon settings itself
+ * (writing the picture quality property can upset Canon's firmware), so
+ * it asks for them. */
+static void film_capture_check()
+{
+ if (!roll_loaded) return;
+ int raw = (pic_quality & 0xFE00FF) == (PICQ_RAW & 0xFE00FF);
+ int review_off = image_review_time == 0;
+ if (raw && review_off) return;
+ dbg("capture: quality %x, review %d", pic_quality, image_review_time);
+ NotifyBox(6000, "Film: in Canon's menu set %s%s%s", raw ? "" : "Image quality RAW",
+ !raw && !review_off ? " and " : "", review_off ? "" : "Image review Off");
+}
+
+/* ---------------------------------------------------------------- aperture */
+
+/* manual (adapted) lenses report no aperture; the user dials it in instead */
+static int lens_is_manual()
+{
+ return !lens_info.raw_aperture;
+}
+
+/* index into fos_fstops for the aperture in use */
+static int current_fstop()
+{
+ if (lens_is_manual())
+ return COERCE(manual_fstop, lens_widest, fos_nfstops - 1);
+
+ int f100 = lens_info.aperture * 10; /* lens_info.aperture is f x10 */
+ int best = 0;
+ for (int i = 1; i < fos_nfstops; i++)
+ if (ABS(fos_fstops[i] - f100) < ABS(fos_fstops[best] - f100))
+ best = i;
+ return best;
+}
+
+static void step_manual_fstop(int dir)
+{
+ manual_fstop = COERCE(current_fstop() + dir, lens_widest, fos_nfstops - 1);
+}
+
+/* ---------------------------------------------------------------- rolls */
+
+/* start a roll: state and log now, camera settings once the film OS has
+ * let go of the screen (apply_film blocks for a while) */
+static void load_roll(int film, int exposures)
+{
+ roll_film = COERCE(film, 0, fos_nfilms - 1);
+ roll_exposures = exposures;
+ roll_folder = get_shooting_card()->folder_number;
+
+ /* next roll number whose log doesn't exist yet, so a reset counter
+ * (new settings file, card from another camera) never mixes two rolls */
+ for (int tries = 0; tries < 999; tries++)
+ {
+ roll_number = roll_number % 999 + 1;
+ update_log_path();
+ if (!is_file(log_path))
+ break;
+ }
+ frames_shot = 0;
+ need_wind = 0;
+ last_file_number = get_shooting_card()->file_number;
+ roll_loaded = 1;
+ update_log_path();
+ write_header("");
+
+ char when[32];
+ format_now(when, sizeof(when));
+ fos_copy(loaded_at, sizeof(loaded_at), when, 16);
+ nrecent = 0;
+ recent_valid = 1;
+
+ hud_dirty = 1;
+ dbg("roll %03d loaded: %s, %d exp", roll_number, fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].key, roll_exposures);
+}
+
+static void rewind_roll()
+{
+ if (!roll_loaded) return;
+ char when[32], line[80];
+ format_now(when, sizeof(when));
+ snprintf(line, sizeof(line), "\n# rewound %s after %d of %d frames\n", when, frames_shot, roll_exposures);
+ log_append(line);
+ roll_loaded = 0;
+ need_wind = 0;
+ hud_dirty = 1;
+ dbg("roll %03d rewound at %d/%d", roll_number, frames_shot, roll_exposures);
+}
+
+static void record_frame(int file_number)
+{
+ if (frames_shot >= roll_exposures)
+ {
+ beep();
+ return;
+ }
+
+ frames_shot++;
+
+ char when[32];
+ char aperture[8];
+ char line[112];
+ format_now(when, sizeof(when));
+ fos_format_fstop(aperture, sizeof(aperture), current_fstop());
+ snprintf(line, sizeof(line), "%d %s%04d.CR2 %s f/%s\n",
+ frames_shot, get_file_prefix(), file_number, when, aperture);
+ log_append(line);
+
+ for (int i = MIN(nrecent, FOS_RECENT - 1); i > 0; i--)
+ recent[i] = recent[i - 1];
+ recent[0].no = frames_shot;
+ fos_copy(recent[0].time, sizeof(recent[0].time), when + 11, 5);
+ snprintf(recent[0].fstop, sizeof(recent[0].fstop), "%s", aperture);
+ nrecent = MIN(nrecent + 1, FOS_RECENT);
+
+ leds_until = get_ms_clock() + 2500;
+ hud_dirty = 1;
+
+ if (frames_shot == roll_exposures)
+ {
+ need_wind = 0;
+ beep_times(2);
+ end_due = get_ms_clock() + 1500; /* then ask: develop it now? */
+ return;
+ }
+
+ if (wind_mode)
+ need_wind = 1;
+}
+
+/* log every new file number since the last poll */
+static void poll_frames()
+{
+ if (!roll_loaded)
+ return;
+
+ int now = get_shooting_card()->file_number;
+ if (now == last_file_number)
+ return;
+
+ int prev = last_file_number;
+ last_file_number = now;
+
+ int count = now - prev;
+ if (count < 0)
+ count += 9999; /* IMG_9999 -> IMG_0001 */
+ if (prev < 0 || count > 50)
+ return; /* card swap or counter reset: just resync */
+
+ if (get_shooting_card()->folder_number != roll_folder)
+ {
+ /* Canon started a new folder; start a log there too so each folder
+ * develops on its own (frame numbers keep counting) */
+ roll_folder = get_shooting_card()->folder_number;
+ update_log_path();
+ write_header(" - continued from the previous DCIM folder");
+ }
+
+ dbg("frames: file %d -> %d, logging %d", prev, now, count);
+ for (int i = 1; i <= count; i++)
+ record_frame((prev + i - 1) % 9999 + 1);
+}
+
+/* ---------------------------------------------------------------- the film OS host */
+
+static volatile int ui_running = 0; /* the film OS owns the screen and the buttons */
+static volatile int ui_abort = 0;
+static int ui_after = 0; /* what to do once it has let go */
+static int ui_last_mode_poke = 0;
+static int ui_last_palette = 0;
+
+enum { AFTER_APPLY = 1, AFTER_CANON_MENU = 2 };
+
+/* buttons, from the GUI task to the film OS task */
+#define KEYQ 32
+static volatile int keyq[KEYQ];
+static volatile int keyq_in = 0, keyq_out = 0;
+
+static void keyq_push(int k)
+{
+ int next = (keyq_in + 1) % KEYQ;
+ if (next != keyq_out)
+ {
+ keyq[keyq_in] = k;
+ keyq_in = next;
+ }
+}
+
+/* Our palette is fos_pal (RGB); the bitmap overlay wants Y, Cb, Cr and
+ * an opacity code, which we copy from Canon's own white. One entry is
+ * remembered so we notice when other code puts Canon's palette back. */
+#define PALETTE_PROBE 200
+static uint32_t palette_probe = 0;
+
+/* a photograph on the screen: its colours in 1..photo_n, at photo_k/256 */
+static int photo_mode = 0, photo_n = 0, photo_k = 256;
+static uint8_t photo_pal[FOS_PRINT_COLOURS][3];
+
+static void palette_ours()
+{
+ if (!DISPLAY_IS_ON) return;
+ /* Canon's white tells the opacity and where white sits in luma
+ * (its own conversion puts it at 235, not 255) */
+ uint32_t white = LCD_Palette[3 * COLOR_WHITE + 2];
+ uint32_t opaque = white & 0xFF000000;
+ if ((opaque >> 24) < 2) opaque = 0x03000000;
+ int white_y = (white >> 16) & 0xFF;
+ if (white_y < 180) white_y = 235;
+ for (int i = 1; i < 255; i++)
+ {
+ uint32_t entry;
+ if (!photo_mode)
+ entry = opaque | fos_screen_yuv(i, white_y, scr_std, scr_sat, scr_warm, scr_bright);
+ else
+ {
+ const uint8_t *c = i <= photo_n ? photo_pal[i - 1] :
+ i >= FOS_FIXED_BASE && i < FOS_FIXED_BASE + FOS_FIXED_N ? fos_fixed_rgb[i - FOS_FIXED_BASE] : 0;
+ uint32_t rgb = c ? (uint32_t) (c[0] * photo_k >> 8) << 16 | (uint32_t) (c[1] * photo_k >> 8) << 8 | (uint32_t) (c[2] * photo_k >> 8) : 0;
+ entry = opaque | fos_screen_yuv_rgb(rgb, white_y, scr_std, scr_sat, scr_warm, scr_bright);
+ }
+ if (i == PALETTE_PROBE) palette_probe = entry;
+ EngDrvOut(LCD_Palette[3 * i], entry);
+ EngDrvOut(LCD_Palette[3 * i + 0x300], entry);
+ }
+}
+
+static void palette_canon()
+{
+ for (int i = 1; i < 255; i++)
+ {
+ EngDrvOut(LCD_Palette[3 * i], LCD_Palette[3 * i + 2]);
+ EngDrvOut(LCD_Palette[3 * i + 0x300], LCD_Palette[3 * i + 2]);
+ }
+}
+
+/* Take the display from Canon's GUI the same way the ML menu does:
+ * switch Canon to the ML menu GUI mode (LiveView stops drawing its
+ * overlays and stops handling keys), stop Canon from flipping its own
+ * bitmap buffer, then turn the bitmap layer back on for us. */
+static void film_ui_open()
+{
+ NotifyBoxHide();
+ if (lv) bmp_off();
+ SetGUIRequestMode(GUIMODE_ML_MENU);
+ msleep(200);
+ canon_gui_disable_front_buffer();
+ CancelDateTimer();
+ clrscr();
+ bmp_on();
+ ui_last_mode_poke = get_ms_clock();
+}
+
+static void film_ui_close()
+{
+ palette_canon();
+ if (lv) bmp_off();
+ SetGUIRequestMode(0);
+ msleep(100);
+ canon_gui_enable_front_buffer(0);
+ clrscr();
+ redraw();
+ if (lv) bmp_on();
+}
+
+/* frame times are kept while the film OS runs and logged when it closes:
+ * writing the card in the middle of an animation would stall it */
+static struct fos_stat stat_all;
+
+static void ui_task(int open)
+{
+ keyq_in = keyq_out = 0;
+ ui_abort = 0;
+ ui_after = 0;
+ film_ui_open();
+ DBG_STATE("film os: open");
+ memset(&stat_all, 0, sizeof(stat_all));
+
+ fos_ui_run(open);
+
+ film_ui_close();
+ ui_running = 0;
+ hud_dirty = 1;
+ DBG_STATE("film os: closed");
+ if (stat_all.frames)
+ {
+ struct fos_stat *s = &stat_all;
+ int n = s->frames, total = s->draw_ms + s->present_ms + s->rest_ms;
+ dbg("film os: %d frames in %d ms = %d/s; per frame %d ms draw (%d canisters) + %d present + %d rest, worst %d, open %d ms, quality %d",
+ n, total, total ? n * 1000 / total : 0, s->draw_ms / n, s->cans_ms / n, s->present_ms / n, s->rest_ms / n,
+ s->worst_ms, s->open_ms, fos_can_quality);
+ }
+
+ if (ui_after & AFTER_APPLY)
+ {
+ apply_film(roll_film);
+ beep();
+ film_capture_check();
+ }
+ if (dev_busy)
+ {
+ /* left in the middle of developing */
+ dev_busy = 0;
+ powersave_permit();
+ }
+ if (ui_after & AFTER_CANON_MENU)
+ fake_simple_button(BGMT_MENU);
+}
+
+static void open_ui(int screen)
+{
+ if (ui_running)
+ return;
+ if (!fos_fonts_ready())
+ {
+ NotifyBox(5000, "Film OS: ML/DATA/" FOS_FONT_FILE " is missing");
+ return;
+ }
+ ui_running = 1;
+ /* the same priority as ML's own menu redraw: Canon's tasks still come
+ * first, and the film OS rests between frames */
+ task_create("film_os", 0x1a, 0x4000, ui_task, (void *) screen);
+}
+
+/* ---- what the film OS asks of the camera (see fos.h) */
+
+int fos_port_ms()
+{
+ return get_ms_clock();
+}
+
+void fos_port_sleep(int ms)
+{
+ msleep(ms);
+ int now = get_ms_clock();
+
+ /* the Canon dialog under us times out unless poked (CONFIG_MENU_TIMEOUT_FIX) */
+ if (lv && now - ui_last_mode_poke > 2000)
+ {
+ SetGUIRequestMode(GUIMODE_ML_MENU);
+ ui_last_mode_poke = now;
+ }
+ /* other code (ML's powersave, clear overlays) may put Canon's palette
+ * back: check one entry every frame, rewrite all of them now and then */
+ static int last_wake = 0;
+ if (dev_busy && now - last_wake > 5000)
+ {
+ idle_wakeup_reset_counters(-10);
+ last_wake = now;
+ }
+ uint32_t probe = shamem_read(LCD_Palette[3 * PALETTE_PROBE]);
+ if ((probe && probe != palette_probe) || now - ui_last_palette > 1000)
+ {
+ palette_ours();
+ ui_last_palette = now;
+ }
+}
+
+int fos_port_key()
+{
+ if (keyq_out == keyq_in)
+ return FK_NONE;
+ int k = keyq[keyq_out];
+ keyq_out = (keyq_out + 1) % KEYQ;
+ return k;
+}
+
+int fos_port_abort()
+{
+ if (ui_abort || ml_shutdown_requested || !DISPLAY_IS_ON)
+ return 1;
+ if (get_halfshutter_pressed())
+ return 1;
+ /* a Canon dialog took over (low battery, card door...): give the mode
+ * request time to land, then let go if Canon keeps something else up */
+ static int mismatch_since = 0;
+ int now = get_ms_clock();
+ if (CURRENT_GUI_MODE == GUIMODE_ML_MENU)
+ mismatch_since = 0;
+ else if (!mismatch_since)
+ mismatch_since = now;
+ else if (now - mismatch_since > 1500)
+ {
+ dbg("film os: Canon GUI mode %d, leaving", CURRENT_GUI_MODE);
+ mismatch_since = 0;
+ return 1;
+ }
+ return 0;
+}
+
+void fos_port_present(const uint8_t *rows, int pitch, int y0, int y1)
+{
+ uint8_t *vram = bmp_vram_real();
+ if (!vram || !DISPLAY_IS_ON)
+ return;
+ y0 = COERCE(y0, 0, FOS_H);
+ y1 = COERCE(y1, y0, FOS_H);
+ for (int y = y0; y < y1; y++)
+ memcpy(vram + y * BMPPITCH, rows + (y - y0) * pitch, FOS_W);
+}
+
+void fos_port_palette()
+{
+ /* once: Canon's own entries, to check the colour conversion against */
+ static int logged = 0;
+ if (!logged && debug_log)
+ {
+ logged = 1;
+ dbg("canon palette 1-7: %08x %08x %08x %08x %08x %08x %08x",
+ LCD_Palette[3 * 1 + 2], LCD_Palette[3 * 2 + 2], LCD_Palette[3 * 3 + 2], LCD_Palette[3 * 4 + 2],
+ LCD_Palette[3 * 5 + 2], LCD_Palette[3 * 6 + 2], LCD_Palette[3 * 7 + 2]);
+ dbg("canon palette 8-15: %08x %08x %08x %08x %08x %08x %08x %08x",
+ LCD_Palette[3 * 8 + 2], LCD_Palette[3 * 9 + 2], LCD_Palette[3 * 10 + 2], LCD_Palette[3 * 11 + 2],
+ LCD_Palette[3 * 12 + 2], LCD_Palette[3 * 13 + 2], LCD_Palette[3 * 14 + 2], LCD_Palette[3 * 15 + 2]);
+ }
+ photo_mode = 0;
+ palette_ours();
+ ui_last_palette = get_ms_clock();
+}
+
+void fos_port_photo(const uint8_t (*pal)[3], int n, int k)
+{
+ photo_n = COERCE(n, 0, FOS_PRINT_COLOURS);
+ memcpy(photo_pal, pal, photo_n * 3);
+ photo_k = COERCE(k, 0, 256);
+ photo_mode = 1;
+ palette_ours();
+ ui_last_palette = get_ms_clock();
+}
+
+void fos_port_log(const char *msg)
+{
+ dbg("%s", msg);
+}
+
+int fos_port_dev_cap()
+{
+ return 0;
+}
+
+/* ---- the card */
+
+const char *fos_port_card()
+{
+ static char root[8];
+ snprintf(root, sizeof(root), "%s:/", get_shooting_card()->drive_letter);
+ return root;
+}
+
+void *fos_port_open(const char *path, int write)
+{
+ return write ? FIO_CreateFile(path) : FIO_OpenFile(path, O_RDONLY | O_SYNC);
+}
+
+/* Canon reads files by DMA: into memory the CPU caches, it goes through
+ * an uncached buffer */
+#define BOUNCE (64 * 1024)
+
+int fos_port_read(void *f, void *buf, int size)
+{
+ if (buf != CACHEABLE(buf))
+ return FIO_ReadFile(f, buf, size);
+ static uint8_t *bounce = 0;
+ if (!bounce) bounce = fio_malloc(BOUNCE);
+ if (!bounce) return -1;
+ int done = 0;
+ while (done < size)
+ {
+ int n = MIN(size - done, BOUNCE);
+ int got = FIO_ReadFile(f, UNCACHEABLE(bounce), n);
+ if (got <= 0) break;
+ memcpy((uint8_t *) buf + done, UNCACHEABLE(bounce), got);
+ done += got;
+ if (got < n) break;
+ }
+ return done;
+}
+
+int fos_port_write(void *f, const void *buf, int size)
+{
+ return FIO_WriteFile(f, buf, size);
+}
+
+int fos_port_seek(void *f, int offset)
+{
+ return FIO_SeekSkipFile(f, offset, SEEK_SET) == offset ? 0 : -1;
+}
+
+void fos_port_close(void *f)
+{
+ if (f) FIO_CloseFile(f);
+}
+
+int fos_port_list(const char *dir, int (*fn)(void *ctx, const char *name, int is_dir), void *ctx)
+{
+ char path[FIO_MAX_PATH_LENGTH];
+ int len = snprintf(path, sizeof(path), "%s", dir);
+ if (len > 0 && len < (int) sizeof(path) - 1 && path[len - 1] != '/') strcat(path, "/");
+ struct fio_file file;
+ struct fio_dirent *d = FIO_FindFirstEx(path, &file);
+ if (IS_ERROR(d)) return -1;
+ int n = 0;
+ do
+ {
+ if (file.name[0] == '.') continue;
+ n++;
+ if (!fn(ctx, file.name, (file.mode & ATTR_DIRECTORY) != 0)) break;
+ }
+ while (FIO_FindNextEx(d, &file) == 0);
+ FIO_FindClose(d);
+ return n;
+}
+
+int fos_port_mkdir(const char *path)
+{
+ if (is_dir(path)) return 0;
+ FIO_CreateDirectory(path);
+ return is_dir(path) ? 0 : -1;
+}
+
+void *fos_port_alloc(int size)
+{
+ void *p = tmp_malloc(size);
+ if (!p) dbg("alloc: %d bytes failed", size);
+ return p;
+}
+
+void fos_port_free(void *p)
+{
+ if (p) free(p);
+}
+
+void fos_port_roll(struct fos_roll *r)
+{
+ if (roll_loaded && !recent_valid)
+ {
+ update_log_path();
+ read_back_log();
+ }
+ memset(r, 0, sizeof(*r));
+ r->loaded = roll_loaded;
+ r->number = roll_number;
+ r->film = COERCE(roll_film, 0, fos_nfilms - 1);
+ r->exposures = roll_exposures;
+ r->shot = frames_shot;
+ r->need_wind = need_wind;
+ snprintf(r->loaded_at, sizeof(r->loaded_at), "%s", loaded_at);
+ r->nrecent = nrecent;
+ for (int i = 0; i < nrecent && i < FOS_RECENT; i++)
+ {
+ r->recent[i].no = recent[i].no;
+ memcpy(r->recent[i].time, recent[i].time, sizeof(r->recent[i].time));
+ memcpy(r->recent[i].fstop, recent[i].fstop, sizeof(r->recent[i].fstop));
+ }
+}
+
+static int *setting_var(int s)
+{
+ switch (s)
+ {
+ case FS_HUD: return &hud_enabled;
+ case FS_LEDS: return &leds_on_half;
+ case FS_FOCUS: return &focus_screen;
+ case FS_WIND: return &wind_mode;
+ case FS_APKEYS: return &aperture_keys;
+ case FS_LENS_WIDE: return &lens_widest;
+ case FS_FSTOP: return &manual_fstop;
+ case FS_STARTUP: return &startup_picker;
+ case FS_PLAYLOCK: return &play_lock;
+ case FS_BOOTANIM: return &boot_anim;
+ case FS_DEBUG: return &debug_log;
+ case FS_FILM: return &film_sel;
+ case FS_EXP: return &exp_sel;
+ case FS_SCR_STD: return &scr_std;
+ case FS_SCR_SAT: return &scr_sat;
+ case FS_SCR_WARM: return &scr_warm;
+ case FS_SCR_BRIGHT: return &scr_bright;
+ }
+ return 0;
+}
+
+int fos_port_get(int s)
+{
+ int *v = setting_var(s);
+ if (s == FS_FSTOP) return current_fstop();
+ return v ? *v : 0;
+}
+
+void fos_port_set(int s, int value)
+{
+ int *v = setting_var(s);
+ if (v) *v = value;
+ hud_dirty = 1;
+ /* screen colour: the whole film OS changes at once */
+ if (s == FS_SCR_STD || s == FS_SCR_SAT || s == FS_SCR_WARM || s == FS_SCR_BRIGHT)
+ {
+ palette_ours();
+ ui_last_palette = get_ms_clock();
+ }
+}
+
+void fos_port_action(int action, int a, int b)
+{
+ switch (action)
+ {
+ case FA_LOAD:
+ if (ROLL_IN_PROGRESS) rewind_roll();
+ load_roll(a, fos_exposure_choices[COERCE(b, 0, FOS_NEXP - 1)]);
+ ui_after |= AFTER_APPLY;
+ break;
+ case FA_REWIND:
+ rewind_roll();
+ break;
+ case FA_BUSY:
+ if (a && !dev_busy) powersave_prohibit();
+ if (!a && dev_busy) powersave_permit();
+ dev_busy = a;
+ dbg("darkroom: %s", a ? "developing" : "done");
+ break;
+ case FA_REAPPLY:
+ if (roll_loaded) ui_after |= AFTER_APPLY;
+ break;
+ case FA_CANON_MENU:
+ ui_after |= AFTER_CANON_MENU;
+ break;
+ }
+}
+
+void fos_port_clock(char *buf, int size)
+{
+ /* screens ask every frame; the RTC is read once a second */
+ static char cached[8];
+ static int last = -100000;
+ int now_ms = get_ms_clock();
+ if (now_ms - last > 1000)
+ {
+ struct tm now;
+ LoadCalendarFromRTC(&now);
+ snprintf(cached, sizeof(cached), "%02d:%02d", now.tm_hour, now.tm_min);
+ last = now_ms;
+ }
+ snprintf(buf, size, "%s", cached);
+}
+
+int fos_port_lens_manual()
+{
+ return lens_is_manual();
+}
+
+const char *fos_port_lens_name()
+{
+ return lens_info.name[0] ? lens_info.name : "Lens";
+}
+
+/* M-Film's version (VERSION at the top of the repository; build_fork.sh writes fos_version.h) */
+#if defined(__has_include)
+#if __has_include("fos_version.h")
+#include "fos_version.h"
+#endif
+#endif
+#ifndef MFILM_VERSION
+#define MFILM_VERSION "dev"
+#endif
+
+const char *fos_port_model()
+{
+ /* "Canon EOS 650D": as the camera reports itself */
+ return camera_model[0] ? camera_model : "Canon camera";
+}
+
+const char *fos_port_version()
+{
+ return MFILM_VERSION;
+}
+
+
+void fos_port_stat(const struct fos_stat *s)
+{
+ stat_all.frames += s->frames;
+ stat_all.draw_ms += s->draw_ms;
+ stat_all.present_ms += s->present_ms;
+ stat_all.rest_ms += s->rest_ms;
+ stat_all.cans_ms += s->cans_ms;
+ if (s->worst_ms > stat_all.worst_ms) stat_all.worst_ms = s->worst_ms;
+ if (s->open_ms) stat_all.open_ms = s->open_ms;
+}
+
+/* ---------------------------------------------------------------- viewfinder HUD */
+
+static volatile int hud_showing = 0; /* HUD drawn on the LiveView screen */
+
+static int hud_visible()
+{
+ return hud_enabled && roll_loaded && lv && display_idle() && !is_movie_mode() && !ui_running;
+}
+
+/* Magic Lantern's own LiveView overlays never draw: the film OS (or
+ * Canon's clean screen) is all you see */
+int filmroll_overlays_active()
+{
+ return 1;
+}
+
+/* the HUD draws with Canon's palette */
+static struct fos_hud_palette hud_pal;
+
+static void hud_palette_init()
+{
+ hud_pal.clear = COLOR_EMPTY;
+ hud_pal.black = COLOR_BLACK;
+ hud_pal.white = COLOR_WHITE;
+ hud_pal.red = COLOR_RED;
+ hud_pal.dark_red = COLOR_DARK_RED;
+ for (int i = 0; i <= 100; i++)
+ hud_pal.gray[i] = COLOR_GRAY(i);
+}
+
+/* the shutter speed as the LEDs show it: 1/125 is 125, slow ones keep the " */
+static void shutter_led(char *buf, int size)
+{
+ if (!lens_info.raw_shutter)
+ {
+ snprintf(buf, size, "--");
+ return;
+ }
+ const char *s = lens_format_shutter(lens_info.raw_shutter);
+ int n = 0;
+ for (; *s && n < size - 1; s++)
+ if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '"')
+ buf[n++] = *s;
+ buf[n] = 0;
+}
+
+static void hud_draw(int lit, int blink)
+{
+ struct fos_hud h;
+ memset(&h, 0, sizeof(h));
+ h.lit = lit;
+ h.blink = blink;
+ h.fstop = current_fstop();
+ h.widest = lens_is_manual() ? lens_widest : 0;
+ if (lit)
+ {
+ int ev8 = get_ae_value(); /* meter reading, 1/8 EV, + = too bright */
+ h.meter = 1;
+ h.want = h.fstop + (ev8 * 3 + (ev8 >= 0 ? 4 : -4)) / 8;
+ }
+ shutter_led(h.shutter, sizeof(h.shutter));
+ h.frame = frames_shot + 1;
+ h.exposures = roll_exposures;
+ h.finished = ROLL_FINISHED;
+ h.need_wind = need_wind;
+ h.focus_screen = focus_screen;
+ h.film = fos_films[COERCE(roll_film, 0, fos_nfilms - 1)].name;
+ uint8_t *vram = bmp_vram();
+ if (vram)
+ fos_hud_draw(vram, BMPPITCH, &h, &hud_pal);
+}
+
+static void hud_clear()
+{
+ uint8_t *vram = bmp_vram();
+ if (vram)
+ fos_hud_clear(vram, BMPPITCH, &hud_pal);
+}
+
+/* one HUD refresh; called from the main loop */
+static void hud_step()
+{
+ static int last_sig = -1;
+ static int last_draw = 0;
+ static int drawn = 0;
+ static int was_visible = -1;
+
+ int visible = hud_visible();
+ if (visible != was_visible)
+ {
+ dbg("hud: visible %d (enabled %d roll %d lv %d movie %d ui %d)",
+ visible, hud_enabled, roll_loaded, lv, is_movie_mode(), ui_running);
+ was_visible = visible;
+ }
+ hud_showing = visible;
+
+ if (!visible)
+ {
+ /* HUD switched off or roll rewound: wipe it once we're back on the LiveView screen */
+ if (drawn && (!hud_enabled || !roll_loaded) && lv && display_idle() && !ui_running)
+ {
+ hud_clear();
+ drawn = 0;
+ }
+ last_sig = -1;
+ return;
+ }
+ drawn = 1;
+
+ int now = get_ms_clock();
+ int lit = !leds_on_half || get_halfshutter_pressed() || now < leds_until;
+ int blink = (now / 400) % 2;
+ int ev8 = lit ? get_ae_value() : 0;
+
+ int sig = lit | blink << 1 | need_wind << 2 | (frames_shot & 0xFF) << 3
+ | lens_info.raw_shutter << 11 | (ev8 & 0xFF) << 19 | (current_fstop() & 0x1F) << 27;
+
+ /* redraw on change, and every second to win over Canon's overlays */
+ if (sig != last_sig || hud_dirty || now - last_draw > 1000)
+ {
+ hud_dirty = 0;
+ last_sig = sig;
+ last_draw = now;
+ hud_draw(lit, blink);
+ }
+}
+
+/* ---------------------------------------------------------------- keys */
+
+/* while the film OS is up it gets the dial and the buttons; anything it
+ * doesn't use goes on to Canon, like the ML menu does */
+static int ui_key(struct event *event, int key)
+{
+ int dir = 0;
+ switch (key)
+ {
+ case MODULE_KEY_PRESS_HALFSHUTTER:
+ case MODULE_KEY_PRESS_FULLSHUTTER:
+ case MODULE_KEY_REC:
+ ui_abort = 1; /* back to the camera, ready to shoot */
+ return 1;
+ case MODULE_KEY_UNPRESS_HALFSHUTTER:
+ case MODULE_KEY_UNPRESS_FULLSHUTTER:
+ return 1; /* Canon must see the shutter let go */
+
+ case MODULE_KEY_WHEEL_LEFT: dir = FK_WHEEL_L; break;
+ case MODULE_KEY_WHEEL_RIGHT: dir = FK_WHEEL_R; break;
+ case MODULE_KEY_WHEEL_UP: dir = FK_WHEEL_L; break;
+ case MODULE_KEY_WHEEL_DOWN: dir = FK_WHEEL_R; break;
+
+ case MODULE_KEY_PRESS_LEFT: keyq_push(FK_LEFT); return 0;
+ case MODULE_KEY_PRESS_RIGHT: keyq_push(FK_RIGHT); return 0;
+ case MODULE_KEY_PRESS_UP: keyq_push(FK_UP); return 0;
+ case MODULE_KEY_PRESS_DOWN: keyq_push(FK_DOWN); return 0;
+ case MODULE_KEY_UNPRESS_UDLR:
+ keyq_push(FK_RELEASE | FK_LEFT);
+ keyq_push(FK_RELEASE | FK_RIGHT);
+ keyq_push(FK_RELEASE | FK_UP);
+ keyq_push(FK_RELEASE | FK_DOWN);
+ return 0;
+
+ case MODULE_KEY_PRESS_SET:
+ case MODULE_KEY_Q:
+ case MODULE_KEY_JOY_CENTER: keyq_push(FK_SET); return 0;
+ case MODULE_KEY_UNPRESS_SET: return 0;
+ case MODULE_KEY_MENU: keyq_push(FK_MENU); return 0;
+ case MODULE_KEY_INFO: keyq_push(FK_INFO); return 0;
+ case MODULE_KEY_PLAY: keyq_push(FK_PLAY); return 0;
+ case MODULE_KEY_TRASH:
+ case MODULE_KEY_TOUCH_2_FINGER: keyq_push(FK_HOME); return 0;
+
+ case 0:
+ return 1; /* not a button: Canon's business */
+ default:
+ return 0;
+ }
+
+ /* newer firmware may group several wheel clicks into one event */
+ int count = MAX(1, MIN(event->arg, 8));
+ for (int i = 0; i < count; i++)
+ keyq_push(dir);
+ return 0;
+}
+
+static unsigned int lv_key(unsigned int key)
+{
+ /* what used to open the Magic Lantern menu opens home instead */
+ if (key == MODULE_KEY_TRASH || key == MODULE_KEY_TOUCH_2_FINGER)
+ {
+ if (shooting_screen())
+ {
+ dbg("key: home");
+ open_ui(FOS_OPEN_HOME);
+ }
+ return 0;
+ }
+
+ /* PLAY: the developed prints, never Canon's playback of what the
+ * darkroom hasn't seen yet */
+ if (key == MODULE_KEY_PLAY && play_lock && shooting_screen())
+ {
+ dbg("key: PLAY -> prints");
+ open_ui(FOS_OPEN_PRINTS);
+ return 0;
+ }
+
+ /* only on the plain LiveView screen: never steal keys from Canon's menus or dialogs */
+ if (!lv || !roll_loaded || !display_idle())
+ return 1;
+
+ if (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_UNPRESS_HALFSHUTTER)
+ hud_dirty = 1;
+
+ /* aperture ring for manual lenses: the wheel in Av mode (where it has
+ * nothing to adjust without a lens), or up/down if the user prefers */
+ if (lens_is_manual() && !ROLL_FINISHED)
+ {
+ int dir = 0;
+ if (aperture_keys == 0 && shooting_mode == SHOOTMODE_AV)
+ dir = (key == MODULE_KEY_WHEEL_RIGHT) ? 1 : (key == MODULE_KEY_WHEEL_LEFT) ? -1 : 0;
+ else if (aperture_keys == 1)
+ dir = (key == MODULE_KEY_PRESS_UP) ? 1 : (key == MODULE_KEY_PRESS_DOWN) ? -1 : 0;
+ if (dir)
+ {
+ step_manual_fstop(dir);
+ leds_until = get_ms_clock() + 2000;
+ hud_dirty = 1;
+ return 0;
+ }
+ }
+
+ if (ROLL_FINISHED)
+ {
+ if (key == MODULE_KEY_PRESS_SET)
+ {
+ open_ui(FOS_OPEN_END);
+ return 0;
+ }
+ return 1;
+ }
+
+ if (need_wind)
+ {
+ if (key == MODULE_KEY_PRESS_SET)
+ {
+ need_wind = 0;
+ leds_until = get_ms_clock() + 1500;
+ hud_dirty = 1;
+ return 0;
+ }
+ if (wind_mode == 2 && (key == MODULE_KEY_PRESS_HALFSHUTTER || key == MODULE_KEY_PRESS_FULLSHUTTER))
+ return 0;
+ }
+
+ return 1;
+}
+
+int handle_filmroll_keys(struct event *event)
+{
+ int key = module_translate_key(event->param, MODULE_KEY_PORTABLE);
+ if (ui_running)
+ {
+#ifdef BGMT_UNPRESS_LEFT
+ /* the EOS M reports each direction's release on its own, and the
+ * portable key codes have no name for those */
+ switch (event->param)
+ {
+ case BGMT_UNPRESS_LEFT: keyq_push(FK_RELEASE | FK_LEFT); return 0;
+ case BGMT_UNPRESS_RIGHT: keyq_push(FK_RELEASE | FK_RIGHT); return 0;
+ case BGMT_UNPRESS_UP: keyq_push(FK_RELEASE | FK_UP); return 0;
+ case BGMT_UNPRESS_DOWN: keyq_push(FK_RELEASE | FK_DOWN); return 0;
+ }
+#endif
+ return ui_key(event, key);
+ }
+
+ if (!key)
+ return 1;
+
+ /* newer firmware may group several wheel clicks into one event */
+ int count = 1;
+ if (key == MODULE_KEY_WHEEL_LEFT || key == MODULE_KEY_WHEEL_RIGHT)
+ count = MAX(1, event->arg);
+
+ int pass = 1;
+ for (int i = 0; i < count; i++)
+ pass = lv_key(key);
+ return pass;
+}
+
+/* ---------------------------------------------------------------- the ML menu, replaced */
+
+void filmroll_menu_requested()
+{
+ if (shooting_screen())
+ open_ui(FOS_OPEN_HOME);
+}
+
+static void filmroll_init()
+{
+ if (roll_loaded)
+ update_log_path();
+ fos_ui_init();
+ hud_palette_init();
+ dbg("init: M-Film " MFILM_VERSION ", fork build %s %s, roll %d loaded %d shot %d/%d, startup %d hud %d",
+ __DATE__, __TIME__, roll_number, roll_loaded, frames_shot, roll_exposures,
+ startup_picker, hud_enabled);
+}
+
+/* The film OS's fonts are a file on the card (see fos_gfx.h): kept in
+ * memory taken after boot, not in autoexec.bin */
+static void load_fonts()
+{
+ int size = 0;
+ uint8_t *raw = read_entire_file("ML/DATA/" FOS_FONT_FILE, &size);
+ if (!raw)
+ {
+ dbg("fonts: ML/DATA/%s not found", FOS_FONT_FILE);
+ return;
+ }
+ uint8_t *blob = malloc(size); /* cached memory, for drawing */
+ if (blob)
+ {
+ memcpy(blob, raw, size);
+ if (!fos_fonts_load(blob, size))
+ {
+ free(blob);
+ blob = 0;
+ }
+ }
+ fio_free(raw);
+ dbg("fonts: %d bytes, %s", size, blob ? "loaded" : "not usable");
+}
+
+/* the films beyond the built-in ones, from the card; the file stays in
+ * memory (the films point into it) */
+static void load_films()
+{
+ int size = 0;
+ uint8_t *raw = read_entire_file("ML/DATA/" FOS_FILM_FILE, &size);
+ if (!raw)
+ {
+ dbg("films: ML/DATA/%s not found, the built-in ones only", FOS_FILM_FILE);
+ return;
+ }
+ uint8_t *blob = malloc(size);
+ if (blob)
+ {
+ memcpy(blob, raw, size);
+ if (!fos_films_load(blob, size))
+ {
+ free(blob);
+ blob = 0;
+ }
+ }
+ fio_free(raw);
+ dbg("films: %d (%d bytes, %s)", fos_nfilms, size, blob ? "loaded" : "not usable");
+}
+
+/* the film OS is the camera's start screen */
+static void startup_task()
+{
+ /* wait (up to ~15 s) for ML to finish booting and LiveView to settle */
+ for (int i = 0; i < 150; i++)
+ {
+ if (ml_started && shooting_screen())
+ break;
+ if (i % 10 == 0 && ml_started)
+ DBG_STATE("startup waiting");
+ msleep(100);
+ }
+ msleep(300);
+
+ DBG_STATE("startup check");
+ if (!ml_started || !shooting_screen())
+ {
+ dbg("startup: not on the shooting screen, film OS skipped");
+ return;
+ }
+ int shelf = startup_picker == 2 || (startup_picker == 1 && !ROLL_IN_PROGRESS);
+ if (boot_anim && startup_picker)
+ open_ui(shelf ? FOS_OPEN_BOOT : FOS_OPEN_BOOT_LV);
+ else if (shelf)
+ open_ui(FOS_OPEN_SHELF);
+}
+
+/* Everything runs from one task that waits for ML to finish booting, so
+ * nothing touches Canon's GUI state before it exists: start screen first,
+ * then frame logging and the HUD. */
+static void filmroll_task()
+{
+ while (!ml_started)
+ msleep(100);
+ dbg("main: started");
+
+ load_fonts();
+ load_films();
+ startup_task();
+ film_capture_check();
+
+ int last_alive = 0;
+ TASK_LOOP
+ {
+ poll_frames();
+
+ /* the roll has just been finished: once the camera is quiet, ask
+ * whether to develop it now or load a new one first */
+ if (end_due && get_ms_clock() > end_due && ROLL_FINISHED)
+ {
+ if (!ui_running && shooting_screen() && !get_halfshutter_pressed() && job_state_ready_to_take_pic())
+ {
+ end_due = 0;
+ dbg("roll %03d finished: asking", roll_number);
+ open_ui(FOS_OPEN_END);
+ }
+ }
+ else if (end_due && !ROLL_FINISHED) end_due = 0;
+ if (k % 2 == 0)
+ hud_step(); /* every 100 ms */
+
+ int now = get_ms_clock();
+ if (now - last_alive > 60000)
+ {
+ dbg("main: alive, roll %d loaded %d shot %d/%d file %d",
+ roll_number, roll_loaded, frames_shot, roll_exposures, last_file_number);
+ last_alive = now;
+ }
+ msleep(50);
+ }
+}
+
+INIT_FUNC("filmroll", filmroll_init);
+TASK_CREATE("film_main", filmroll_task, 0, 0x1e, 0x2000);
diff --git a/ml-dev/fork/src/filmroll.h b/ml-dev/fork/src/filmroll.h
new file mode 100644
index 0000000..f43cb73
--- /dev/null
+++ b/ml-dev/fork/src/filmroll.h
@@ -0,0 +1,16 @@
+#ifndef _filmroll_h_
+#define _filmroll_h_
+
+struct event;
+
+/* button hook, called from handle_common_events_by_feature; 0 = handled */
+int handle_filmroll_keys(struct event *event);
+
+/* called instead of opening the Magic Lantern menu (menu.c) */
+void filmroll_menu_requested();
+
+/* ML's own LiveView overlays stay out of the way of the film OS and the
+ * viewfinder HUD (always, in this fork) */
+int filmroll_overlays_active();
+
+#endif
diff --git a/ml-dev/install_fork.ps1 b/ml-dev/install_fork.ps1
new file mode 100644
index 0000000..b0f2e23
--- /dev/null
+++ b/ml-dev/install_fork.ps1
@@ -0,0 +1,52 @@
+# Install the film-mode ML fork on the camera card.
+# powershell -File install_fork.ps1 -Card G:
+# First run backs up the official ML (autoexec.bin + ML\MODULES) to
+# ml-dev\card_backup\official\ so restore_official.ps1 can put it back.
+param([Parameter(Mandatory = $true)][string]$Card)
+
+$ErrorActionPreference = "Stop"
+$here = Split-Path -Parent $MyInvocation.MyCommand.Path
+$fork = Join-Path $here "out\fork"
+$backup = Join-Path $here "card_backup\official"
+$card = $Card.TrimEnd('\') + '\'
+
+if (-not (Test-Path (Join-Path $card "autoexec.bin"))) { throw "No autoexec.bin on $card - is this the camera card?" }
+if (-not (Test-Path (Join-Path $fork "autoexec.bin"))) { throw "Build the fork first (build_fork.sh)" }
+
+# one-time backup of the official install
+if (-not (Test-Path (Join-Path $backup "autoexec.bin"))) {
+ New-Item -ItemType Directory -Force (Join-Path $backup "ML\MODULES") | Out-Null
+ Copy-Item (Join-Path $card "autoexec.bin") $backup
+ Copy-Item (Join-Path $card "ML\MODULES\*") (Join-Path $backup "ML\MODULES")
+ Write-Output "Backed up official ML to $backup"
+}
+
+# the fork's core and the modules/symbols built against it
+Copy-Item (Join-Path $fork "autoexec.bin") $card -Force
+Copy-Item (Join-Path $fork "ML\modules\*") (Join-Path $card "ML\MODULES") -Force
+# the film OS fonts (not inside autoexec.bin, which has to stay small)
+New-Item -ItemType Directory -Force (Join-Path $card "ML\DATA") | Out-Null
+Copy-Item (Join-Path $fork "ML\data\FOSFONT.BIN") (Join-Path $card "ML\DATA") -Force
+# the films beyond the built-in ones, and the donation codes if there are any
+Copy-Item (Join-Path $fork "ML\data\FOSFILMS.BIN") (Join-Path $card "ML\DATA") -Force
+$qr = Join-Path $fork "ML\data\FOSQR.BIN"
+if (Test-Path $qr) { Copy-Item $qr (Join-Path $card "ML\DATA") -Force }
+# the films' colour tables (the darkroom's prints stay as they are)
+New-Item -ItemType Directory -Force (Join-Path $card "ML\DARKROOM") | Out-Null
+Copy-Item (Join-Path $fork "ML\DARKROOM\LOOK*.LUT") (Join-Path $card "ML\DARKROOM") -Force
+# the shelf's samples (EOS M builds only)
+$samples = Join-Path $fork "ML\SAMPLES"
+if (Test-Path $samples) {
+ New-Item -ItemType Directory -Force (Join-Path $card "ML\SAMPLES") | Out-Null
+ Copy-Item (Join-Path $samples "F*.BMP") (Join-Path $card "ML\SAMPLES") -Force
+}
+
+# filmroll is built in now; lua.mo was built for the official core
+foreach ($m in "filmroll.mo", "lua.mo") {
+ $p = Join-Path $card "ML\MODULES\$m"
+ if (Test-Path $p) { Remove-Item $p; Write-Output "Removed ML\MODULES\$m" }
+}
+
+$a = (Get-FileHash (Join-Path $fork "autoexec.bin")).Hash
+$b = (Get-FileHash (Join-Path $card "autoexec.bin")).Hash
+Write-Output ("Installed fork autoexec.bin: " + $(if ($a -eq $b) { "verified" } else { "HASH MISMATCH" }))
diff --git a/ml-dev/push_fork.ps1 b/ml-dev/push_fork.ps1
new file mode 100644
index 0000000..cc62586
--- /dev/null
+++ b/ml-dev/push_fork.ps1
@@ -0,0 +1,19 @@
+# Push the ML fork (WSL: ~/ml/magiclantern_simplified, branch film-mode) to
+# its private GitHub repo. Git in WSL has no GitHub login, so the branch goes
+# through a bare repo on the Windows side and is pushed from there with the
+# gh credentials.
+# powershell -File push_fork.ps1
+$ErrorActionPreference = "Stop"
+$here = Split-Path -Parent $MyInvocation.MyCommand.Path
+$bare = Join-Path $here "out\mlfork.git"
+$remote = "https://github.com/HNGSeries/magiclantern-eosm-film.git"
+
+if (-not (Test-Path $bare)) { git init -q --bare $bare }
+
+$bareWsl = (wsl -d Ubuntu -u root -- wslpath -a "$bare") -replace "`0", ""
+wsl -d Ubuntu -u root -- git -C /root/ml/magiclantern_simplified push -q --force "$bareWsl" film-mode:film-mode
+if ($LASTEXITCODE) { throw "WSL -> bare repo push failed" }
+
+git -C $bare push $remote film-mode:film-mode
+if ($LASTEXITCODE) { throw "push to GitHub failed" }
+Write-Output "film-mode pushed to $remote"
diff --git a/ml-dev/restore_official.ps1 b/ml-dev/restore_official.ps1
new file mode 100644
index 0000000..86d24f6
--- /dev/null
+++ b/ml-dev/restore_official.ps1
@@ -0,0 +1,14 @@
+# Put the official ML (backed up by install_fork.ps1) back on the card.
+# powershell -File restore_official.ps1 -Card G:
+param([Parameter(Mandatory = $true)][string]$Card)
+
+$ErrorActionPreference = "Stop"
+$here = Split-Path -Parent $MyInvocation.MyCommand.Path
+$backup = Join-Path $here "card_backup\official"
+$card = $Card.TrimEnd('\') + '\'
+
+if (-not (Test-Path (Join-Path $backup "autoexec.bin"))) { throw "No backup in $backup" }
+
+Copy-Item (Join-Path $backup "autoexec.bin") $card -Force
+Copy-Item (Join-Path $backup "ML\MODULES\*") (Join-Path $card "ML\MODULES") -Force
+Write-Output "Official ML restored on $card (the filmroll module from ml-dev\out can be copied back if wanted)"
diff --git a/ml-dev/setup_wsl.sh b/ml-dev/setup_wsl.sh
new file mode 100644
index 0000000..298b51a
--- /dev/null
+++ b/ml-dev/setup_wsl.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# Set up a Magic Lantern build environment inside WSL (Ubuntu) and build EOS M.
+# Run from Ubuntu: bash "/mnt/c/Users/hengz/Desktop/Claude Projects/Canon/ml-dev/setup_wsl.sh"
+set -euo pipefail
+
+# Same commit as the build on the camera (2025-06-20.EOSM.202, 2025_release_01),
+# so modules we build match the installed autoexec.bin.
+ML_COMMIT=ed3e7c0dfacfdeaf3349dee73edf9e3621217462
+SRC="$HOME/ml/magiclantern_simplified"
+
+echo "== Installing packages (asks for your Ubuntu password) =="
+sudo apt-get update
+sudo apt-get install -y build-essential make git zip python3 \
+ gcc-arm-none-eabi binutils-arm-none-eabi
+
+echo "== Getting Magic Lantern source =="
+mkdir -p "$HOME/ml"
+if [ ! -d "$SRC/.git" ]; then
+ git clone https://github.com/reticulatedpines/magiclantern_simplified.git "$SRC"
+fi
+cd "$SRC"
+git fetch origin
+git checkout -q "$ML_COMMIT"
+git switch -q -c film-mode 2>/dev/null || git switch -q film-mode
+
+echo "== Toolchain =="
+arm-none-eabi-gcc --version | head -1
+python3 --version
+
+echo "== Building EOSM.202 =="
+cd platform/EOSM.202
+make -j"$(nproc)" 2>&1 | tee "$HOME/ml/build_eosm.log"
+ls -l build/
+echo "== Done. Log: ~/ml/build_eosm.log =="
diff --git a/ml-dev/tools/cameras.py b/ml-dev/tools/cameras.py
new file mode 100644
index 0000000..430083e
--- /dev/null
+++ b/ml-dev/tools/cameras.py
@@ -0,0 +1,92 @@
+"""ml-dev/cameras.txt -> the camera tables in README.md, README.th.md and TESTING.md, and the
+cameras CI builds (.github/workflows/camera.yml). Run after changing cameras.txt:
+
+ python3 ml-dev/tools/cameras.py
+"""
+
+import re
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+STATUS = {
+ "working": "✅ **Works**",
+ "testing": "🧪 Builds, needs a tester",
+ "planned": "⏳ Planned",
+ "no": "— Not yet",
+}
+WHY_NO = "Magic Lantern itself is still experimental on these"
+# README.th.md
+STATUS_TH = {
+ "working": "✅ **ใช้ได้**",
+ "testing": "🧪 build ได้แล้ว รอคนทดสอบ",
+ "planned": "⏳ วางแผนไว้",
+}
+WHY_TH = {
+ WHY_NO: "Magic Lantern เองยังเป็นรุ่นทดลองบนกล้องเหล่านี้",
+ "Magic Lantern's current source doesn't build it": "source ปัจจุบันของ Magic Lantern build รุ่นนี้ไม่ได้",
+}
+
+
+def cameras():
+ out = []
+ for line in (ROOT / "ml-dev" / "cameras.txt").read_text(encoding="utf-8").splitlines():
+ if not line.strip() or line.startswith("#"):
+ continue
+ plat, status, limit, name = line.split(None, 3)
+ fw = plat.split(".")[1]
+ out.append({"plat": plat, "status": status, "limit": limit, "name": name,
+ "fw": ".".join(fw) if fw.isdigit() else fw})
+ return out
+
+
+def short(name):
+ """'Canon EOS 200D / Rebel SL2' -> '200D', 'Canon PowerShot SX70 HS' -> 'SX70 HS'"""
+ name = name.split(" / ", 1)[0]
+ return re.sub(r"^Canon (EOS |PowerShot )?", "", name)
+
+
+def replace(path, start, end, body):
+ text = path.read_text(encoding="utf-8")
+ a, b = text.index(start) + len(start), text.index(end)
+ path.write_text(text[:a] + "\n" + body.rstrip("\n") + "\n" + text[b:], encoding="utf-8")
+
+
+def main():
+ cams = cameras()
+ def table(head, status, not_yet, why_text, end="."):
+ rows = [head, "|---|---|---|---|"]
+ for c in cams:
+ if c["status"] in ("working", "testing", "planned"):
+ dl = f"`M-Film-camera-{c['plat']}.zip`" if c["status"] != "planned" else ""
+ rows.append(f"| {c['name']} | {c['fw']} | {status[c['status']]} | {dl} |")
+ # the ones Magic Lantern isn't ready on: one line, grouped by why
+ why = {}
+ for c in cams:
+ if c["status"] == "no":
+ name, _, reason = c["name"].partition(" (")
+ why.setdefault(reason.rstrip(")") or WHY_NO, []).append(short(name))
+ if why:
+ rows += ["", f"**{not_yet}:** " + " · ".join(f"{', '.join(n)} ({why_text(r)})" for r, n in why.items()) + end]
+ return "\n".join(rows)
+
+ rows = table("| Camera | Canon firmware | Status | Card files |", STATUS, "Not yet", lambda r: r)
+ th = table("| กล้อง | เฟิร์มแวร์ Canon | สถานะ | ไฟล์ลงการ์ด |", STATUS_TH, "ยังไม่รองรับ", lambda r: WHY_TH.get(r, r), end="")
+ replace(ROOT / "README.th.md", "<!-- cameras:start -->", "<!-- cameras:end -->", th)
+ replace(ROOT / "README.md", "<!-- cameras:start -->", "<!-- cameras:end -->", rows)
+
+ built = [c for c in cams if c["status"] in ("working", "testing")]
+ rows = ["| Camera | Canon firmware it needs | File |", "|---|---|---|"]
+ rows += [f"| {c['name']} | {c['fw']} | `M-Film-camera-{c['plat']}.zip` |" for c in built]
+ replace(ROOT / "TESTING.md", "<!-- cameras:start -->", "<!-- cameras:end -->", "\n".join(rows))
+
+ wf = ROOT / ".github" / "workflows" / "camera.yml"
+ text = wf.read_text(encoding="utf-8")
+ text = re.sub(r"( platform: )\[[^\]]*\]( *# from ml-dev/cameras.txt)?",
+ lambda m: m.group(1) + "[" + ", ".join(c["plat"] for c in built) + "] # from ml-dev/cameras.txt", text, count=1)
+ wf.write_text(text, encoding="utf-8")
+ print(f"{len(cams)} cameras: {sum(c['status'] == 'working' for c in cams)} working, "
+ f"{sum(c['status'] == 'testing' for c in cams)} testing")
+
+
+if __name__ == "__main__":
+ main()