rust-j2k 0.4.0

Decodes JPEG 2000 images in pure Rust, for programs that need to read them without linking a C library.
Documentation
name: CI

# Quality gates from .claude/rules/conventions.md. These run on every PR and on
# pushes to main; enable them as required status checks in branch protection.
on:
  pull_request:
  push:
    branches: [main]

# Cancel superseded runs on the same ref to save CI minutes.
concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: "0"

jobs:
  fmt:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
          components: rustfmt
      - run: cargo fmt --all -- --check

  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
          components: clippy
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
      - run: cargo clippy --all-targets -- -D warnings

  test:
    name: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
      - run: cargo test --all-targets
      - name: Doc tests
        run: cargo test --doc

  msrv:
    name: msrv
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      # Must match rust-version in Cargo.toml. The pin is only a claim until this
      # job proves the crate still builds on it, so bump both together.
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: "1.87"
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
      - run: cargo check

  deny:
    name: cargo-deny
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2
        with:
          command: check

  package-hygiene:
    name: package hygiene
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
      # The ISO/IEC 15444-4 conformance corpus is committed for tests but carries
      # a conformance-only license, so it must never ship in the packaged crate
      # (see tests/fixtures/conformance/COPYRIGHT and the `exclude` in Cargo.toml).
      # Guard that invariant against an accidental include/exclude regression.
      - name: Conformance corpus stays out of the package
        run: |
          if cargo package --list --allow-dirty | grep -q 'tests/fixtures/conformance/'; then
            echo "::error::conformance corpus is in the packaged crate; it is license-restricted and must stay excluded"
            exit 1
          fi

  fuzz-smoke:
    name: fuzz smoke
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: nightly
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
        with:
          workspaces: fuzz
      - uses: taiki-e/install-action@c509219cf42fba86913069efd0ade2458c59337b # v2
        with:
          tool: cargo-fuzz
      # Short robustness smoke over every target: the goal is to catch panics
      # on malformed input, not to find deep bugs, so keep each run bounded.
      # `cargo fuzz build` first so a target that stops compiling fails the job
      # explicitly rather than inside a run step.
      # Pin the gnu host triple: cargo-fuzz otherwise defaults to a musl target
      # whose std isn't installed on the runner.
      - name: Build all fuzz targets
        run: cargo fuzz build --target x86_64-unknown-linux-gnu
      # The codestream-reading targets take the J2K marker dictionary so
      # mutation can splice whole marker codes instead of rediscovering them.
      - name: Fuzz decode (60s)
        run: cargo fuzz run decode --target x86_64-unknown-linux-gnu -- -dict=fuzz/j2k.dict -max_total_time=60 -rss_limit_mb=4096
      - name: Fuzz tile_body (45s)
        run: cargo fuzz run tile_body --target x86_64-unknown-linux-gnu -- -dict=fuzz/j2k.dict -max_total_time=45 -rss_limit_mb=4096
      - name: Fuzz tier1_block (30s)
        run: cargo fuzz run tier1_block --target x86_64-unknown-linux-gnu -- -max_total_time=30 -rss_limit_mb=4096
      - name: Fuzz mq (15s)
        run: cargo fuzz run mq --target x86_64-unknown-linux-gnu -- -max_total_time=15 -rss_limit_mb=4096
      # Seed the JP2 targets so the short smoke reaches the colour and header code.
      - name: Seed the JP2 fuzz corpora
        run: |
          python3 scripts/gen-jp2-fuzz-seeds.py
          mkdir -p fuzz/corpus/header
          cp tests/fixtures/*.j2k tests/fixtures/jp2_*.jp2 fuzz/corpus/header/
      # The JP2 box target takes the box dictionary instead.
      - name: Fuzz jp2_boxes (30s)
        run: cargo fuzz run jp2_boxes --target x86_64-unknown-linux-gnu -- -dict=fuzz/jp2.dict -max_total_time=30 -rss_limit_mb=4096
      # The header target checks read_header against decode on the same input.
      - name: Fuzz header (30s)
        run: cargo fuzz run header --target x86_64-unknown-linux-gnu -- -dict=fuzz/jp2.dict -max_total_time=30 -rss_limit_mb=4096
      # The ICC target reads a fuzzed profile; the oracle cases' profiles seed it.
      - name: Seed the ICC fuzz corpus
        run: python3 scripts/gen-icc-oracles.py --fuzz-seeds
      - name: Fuzz icc_srgb (30s)
        run: cargo fuzz run icc_srgb --target x86_64-unknown-linux-gnu -- -dict=fuzz/icc.dict -max_total_time=30 -rss_limit_mb=4096

  # The ICC output is documented as identical on every platform where fma is
  # correctly rounded. Every job above is x86-64, so run the full suite on
  # Apple Silicon (aarch64) as well.
  test-macos:
    name: test (macos aarch64)
    runs-on: macos-15
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
      - run: cargo test

  # wasm32 does fma in software, so this covers the other side of the claim.
  # The runner maps the repo directory so the fixtures are readable.
  test-wasm:
    name: test (wasm32-wasip1)
    runs-on: ubuntu-latest
    timeout-minutes: 30
    env:
      CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run --dir=${{ github.workspace }}::${{ github.workspace }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # master
        with:
          toolchain: stable
          targets: wasm32-wasip1
      - uses: Swatinem/rust-cache@c8037a86dde8214a8310e9f54a8fc61ab362aa31 # v2
      - uses: taiki-e/install-action@c509219cf42fba86913069efd0ade2458c59337b # v2
        with:
          tool: wasmtime
      - name: math_tests
        run: cargo test --target wasm32-wasip1 --lib math_tests
      - name: jp2_icc
        run: cargo test --target wasm32-wasip1 --test jp2_icc