Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/crw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Shared CRW

on:
push:
branches: [main]
paths: ["crates/crw/**", "scripts/fetch-crw-samples.py", "Cargo.toml", "Cargo.lock", ".github/workflows/crw.yml"]
pull_request:
paths: ["crates/crw/**", "scripts/fetch-crw-samples.py", "Cargo.toml", "Cargo.lock", ".github/workflows/crw.yml"]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: shared-crw-${{ github.ref }}
cancel-in-progress: true

jobs:
native:
timeout-minutes: 20
name: CRW lint and tests (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: craft-crw-${{ matrix.os }}
- run: cargo fmt -p craft-crw --check
- run: cargo clippy -p craft-crw --all-targets --locked -- -D warnings
- run: cargo test -p craft-crw --locked

wasm:
timeout-minutes: 10
name: CRW WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: craft-crw-wasm
- run: cargo check -p craft-crw --locked --target wasm32-unknown-unknown

samples:
timeout-minutes: 20
name: CRW sample files decode exactly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
key: craft-crw-samples
- name: Cache the CC0 sample files
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/crw-samples
key: crw-samples-${{ hashFiles('crates/crw/tests/samples.json') }}
- name: Fetch the pinned CC0 sample files (raw.pixls.us)
run: python scripts/fetch-crw-samples.py "$RUNNER_TEMP/crw-samples"
- run: cargo test -p craft-crw --release --locked --test samples -- --nocapture
env:
CRAFT_CRW_SAMPLES: ${{ runner.temp }}/crw-samples
CRAFT_CRW_REQUIRE_SAMPLES: "1"
49 changes: 44 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
# AGENTS.md

Shared Rust libraries for the Craft Apps. The shared standards live in
Shared Rust libraries for the Craft Apps (LightCraft, PhotoCraft, PdfCraft, VectorCraft, FilmCraft,
DesignCraft, WordCraft and the others). The shared standards live in
[craftrules](https://github.com/storytold/craftrules) (`../../craftrules` on a dev machine): read its
`AGENTS.md`, then `standards/never-crash.md`, `standards/engineering.md` and `standards/licensing.md`.

## Start every session here

1. Read this file, then the `README.md` of each crate you touch (its boundaries, origin and tests).
2. A crate that derives or reads a format (`jpeg`, `media`, `crw`, …) follows
[`docs/clean-room.md`](docs/clean-room.md); a crate with a `clean-room/` folder keeps that record
intact (its `README.md` says what is frozen and how a change is reopened).
3. Check `git status`, `git worktree list` and unmerged branches before starting anything new; commit
small and often.

## Rules

- **Never crash.** Every crate's `lib.rs` starts with
`#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]`.
No `unsafe` (the workspace forbids it).
No `unsafe` (the workspace forbids it). Input-derived numbers are hostile: `get()` instead of
indexing for offsets that come from a file, checked or saturating arithmetic for lengths and
counts, bounded recursion (depth limits or budgets), allocations capped by a `Limits` the caller
can lower. Every crash fix lands with a regression test that panicked before it.
- **New crates** go in `crates/<name>`, named `craft-<name>`, inherit the workspace package fields
and lints, and are listed in `[workspace.dependencies]`.
and lints, and are listed in `[workspace.dependencies]`, in the root `README.md` (one entry per
library) and in a workflow of their own (`.github/workflows/<name>.yml`: fmt, clippy with
`-D warnings`, tests on Linux, Windows and macOS, and a `wasm32-unknown-unknown` check for a
crate that an app's web build can use).
- **No app code.** A crate here must be useful to more than one app and must not depend on any app.
- **Time goes through `chrono`** (workspace dependency). Never hand-roll UTC/calendar conversion (days-to-date algorithms, leap-year math); a crate owns only its output format string. The one exception is range extension: past the years chrono can represent, shift the date by whole 400-year Gregorian cycles (146,097 days, after which the calendar repeats), let chrono compute the month and day, and add the cycles back to the year (splitting seconds into hours, minutes and seconds is plain arithmetic).
App policy (colour models, UI, settings, command handling) stays in the apps; the crate's README
states its boundaries and, when the code came from an app, its origin (repository, paths,
revision) and what changed in the move. `NOTICE` → *Source provenance* records the same.
- **Clean-room.** Format code is written only from published specifications, prose documentation,
usable sample files and black-box observation of reference binaries; never from GPL/LGPL/AGPL/CDDL
sources or Adobe material, in any form. The process and the record a crate keeps are in
[`docs/clean-room.md`](docs/clean-room.md). If you have seen something you should not have, stop
and say so.
- **Assets and samples.** Nothing enters the repository without a row in `ATTRIBUTION.md` (path,
author, source, licence) and a licence text where one is required (`licenses/`). Sample media is
never committed: tests fetch pinned, SHA-256-verified, licence-checked files outside the checkout
(`scripts/fetch-*.py`) and skip cleanly when they are absent. No Adobe assets of any kind, including
Adobe's open-licensed fonts; fonts come from craft-fonts.
- **Time goes through `chrono`** (workspace dependency). Never hand-roll UTC/calendar conversion (days-to-date algorithms, leap-year math); a crate owns only its output format string. The one exception is range extension: past the years chrono can represent, shift the date by whole 400-year Gregorian cycles (146,097 days, after which the calendar repeats), let chrono compute the month and day, and add the cycles back to the year (splitting seconds into hours, minutes and seconds is plain arithmetic). A library that reads a timestamp from a file hands it on as Unix seconds and lets the app convert.
- **Tests.** Unit and property tests next to the code; every feature has a test that would fail
without it; decoders have a hostile-input sweep (truncations, byte mutations, proptest) and, for
real files, a digest-pinned sample test. A test that cannot run (no sample files, no GPU) prints
why it skipped and passes, unless a `*_REQUIRE_*` variable (set in CI) turns the skip into a
failure.
- **Before merging:** `cargo fmt --check`, `cargo clippy --workspace --all-targets -- -D warnings`,
`cargo test --workspace`.
`cargo test --workspace`. Each crate's workflow runs the same for that crate on every PR.
- **Commits:** one change per commit, only green states, messages that say what and why. Apps
consume a crate by git revision (`craft-<name> = { git = "https://github.com/storytold/craft-libs", rev = "<commit>" }`),
so a merged commit is an API contract: note breaking changes in the crate's README.
3 changes: 3 additions & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ author, source and license. Library code and original assets are under the repos
| `crates/ui/tests/fonts/NotoSansArabic-screens.ttf` (instance at weight 400 and width 100, subset to the screen test strings) | The Noto Project Authors | [google/fonts@7085eb8 `ofl/notosansarabic`](https://github.com/google/fonts/tree/7085eb89a950e85db5b166b7a58d414544b4140c/ofl/notosansarabic), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansArabic.txt`) |
| `crates/ui/tests/fonts/NotoSansCJKsc-screens.otf` (subset to printable ASCII and the screen test strings) | The Noto Project Authors (Adobe, Google) | [notofonts/noto-cjk@f8d1575 `Sans/OTF/SimplifiedChinese`](https://github.com/notofonts/noto-cjk/tree/f8d157532fbfaeda587e826d4cd5b21a49186f7c/Sans/OTF/SimplifiedChinese), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansCJK.txt`) |
| `crates/ui/tests/fonts/NotoSansThai-screens.ttf` (instance at weight 400 and width 100, subset to the screen test strings) | The Noto Project Authors | [google/fonts@8b0a1d0 `ofl/notosansthai`](https://github.com/google/fonts/tree/8b0a1d0f5983c89bc2b93f1b5fb55f9e252744b5/ofl/notosansthai), via craft-fonts | OFL-1.1 (`licenses/ui-test-fonts/OFL-NotoSansThai.txt`) |
| `crates/crw/tests/samples.json` (manifest only; the 11 raw files are not bundled, `scripts/fetch-crw-samples.py` downloads them outside the checkout) | The photographers who contributed each file to raw.pixls.us (Canon EOS D30, D60, 10D ×3, 300D ×2, Digital Rebel, PowerShot G1, G5, G6) | [raw.pixls.us](https://raw.pixls.us/), each file's `getfile.php` URL and SHA-256 in the manifest | CC0-1.0 (as published by raw.pixls.us for each file) |
| `crates/crw/src/tables.rs`, `crates/crw/clean-room/logs/table_sel*.json` | craft-crw contributors (derived in LightCraft, 2026-10, by known-plaintext alignment of the sample files' entropy streams; `crates/crw/clean-room/06-crw-format.md`) | this repository | MIT OR Apache-2.0 |
| `crates/crw/clean-room/logs/*.txt`, `*.tsv` (statistics, file names, sizes and SHA-256 of sample files; no image content) | craft-crw contributors (LightCraft derivation record) | this repository | MIT OR Apache-2.0 |

Original assets are covered by the repository licence.

Expand Down
7 changes: 6 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Read `AGENTS.md`.
# CLAUDE.md

Read [`AGENTS.md`](AGENTS.md): it is the instruction file for every agent working in this repository
(start-of-session steps, never-crash, new-crate checklist, clean-room, assets, time, tests, merge
gates). Format work also follows [`docs/clean-room.md`](docs/clean-room.md). Suite-wide standards:
[craftrules](https://github.com/storytold/craftrules).
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kurbo = "0.13"
thiserror = "2"
craft-atomic = { path = "crates/atomic" }
craft-cms = { path = "crates/cms" }
craft-crw = { path = "crates/crw" }
craft-docpath = { path = "crates/docpath" }
craft-font-catalog = { path = "crates/font-catalog" }
craft-font-manager = { path = "crates/font-manager" }
Expand Down
13 changes: 13 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,16 @@ https://github.com/storytold/craft-launcher, https://github.com/storytold/photoc
https://github.com/storytold/filmcraft, https://github.com/storytold/effectcraft.
Copyright (c) 2026 ArtCraft Team and the respective application and craft-libs contributors.
All adapted source is licensed MIT OR Apache-2.0.

The Canon CRW decoder in crates/crw (src/lib.rs, src/tables.rs, src/tests.rs, tests/) and its
derivation record (crates/crw/clean-room/) come from:
- LightCraft, crates/raw/src/vendor/crw.rs, crates/raw/src/vendor/crw_tables.rs,
crates/raw/tests/crw_oracle.rs, crates/raw/tests/it/vendor_robust.rs and clean-room/crw/,
branch clean-room-crw-format-decode, revision 6ca439b5155820d2befeacd81ec0c6a80b2bd3bc
(decoder ported at 70c755e42a65661401142819278d51b0c5977f7f; the record is identical at both).
https://github.com/storytold/lightcraft
Copyright (c) 2026 ArtCraft Team and the LightCraft contributors.
Its white-level plateau estimate (saturation_plateau) is LightCraft's vendor::white_from_data at the
same revision. The CRW compression was derived clean-room from CC0 sample files and the
maintainer's own photographs by black-box comparison with a reference decoder's command-line
output; no raw-decoder source was consulted (crates/crw/clean-room/sources.md).
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ craft-<name> = { git = "https://github.com/storytold/craft-libs", rev = "<commit
- [`craft-cms`](crates/cms/README.md): pure-Rust ICC v2/v4 colour management: profile parsing
and writing, transforms, rendering intents, black point compensation, soft proofing, gamut
checks, 3D LUTs and built-in profiles (sRGB, Display P3, synthetic coated CMYK and others).
- [`craft-crw`](crates/crw/README.md): clean-room Canon CRW (CIFF) raw decoder, from LightCraft:
the heap container, the entropy coding derived by black-box analysis (frozen code tables), sensor
black and white levels and as-shot white balance. The complete derivation record (plan, sources
log, scripts, verification) is in `crates/crw/clean-room/`. Colour stays in each app.
- [`craft-docpath`](crates/docpath/src/lib.rs): decides whether a path or `file:` URL stored in a
document may be opened. Paths stored in documents are followed only when they are local or on the
document's own network share; other network paths, device paths and non-file URLs are refused.
Expand Down
21 changes: 21 additions & 0 deletions crates/crw/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "craft-crw"
description = "Clean-room Canon CRW (CIFF) raw decoder: the heap container, the derived entropy coding, sensor levels and as-shot white balance."
version.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
thiserror = { workspace = true }

[dev-dependencies]
proptest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
# Pinned digests of the decoded CC0 sample files (tests/samples.rs); not a product dependency.
sha2 = { version = "0.10", default-features = false, features = ["std"] }
Loading
Loading