How spu7nix/obamify works
Project type and purpose
• This is “obamify,” a Rust-based image-morphing application that targets two platforms:
a. A native desktop executable (Windows, macOS, Linux) built with Cargo.
b. A web version (PWA) compiled to WebAssembly via Trunk, served as static assets with a service worker.
• Purpose: take a “source” and “target” image, compute an optimal pixel‐assignment transform (optionally with GPU shaders), animate the morph, record to GIF, and offer preset assignments.
File structure
• Top-level CI/CD:
• .github/workflows/… (Rust tests, releases, GitHub/Cloudflare Pages)
• Build config:
• Cargo.toml / Cargo.lock (Rust project)
• rust-toolchain (pinned Rust version)
• Trunk.toml (web build)
• flake.nix / flake.lock (Nix development)
• Frontend assets:
• Presets: presets/*/assignments.json (precomputed transforms)
• Source code: src/
• src/main.rs (native entry point)
• src/lib.rs (shared library)
• src/app/… (core modules): calculate/, gui.rs, morph_sim.rs, preset.rs, gif_recorder.rs
• src/shaders/*.wgsl (WebGPU shaders)
• Web worker glue: worker.js (offload heavy compute in browser).
Insights from README
• UI controls a GPU/CPU algorithm with adjustable “resolution,” “proximity importance,” and “algorithm.”
• Building instructions split between native (cargo run --release) and web (trunk serve --release).
• Deployable as GitHub/Cloudflare Pages and downloadable releases (.exe, .app).
Main components and interactions
a. User Interface
• Native GUI (wgpu + window crate) via src/main.rs → src/app/gui.rs
• Web UI (index.html + Wasm) loaded by the browser; PWA shell (manifest.json, sw.js)
b. Compute Engine
• calculate module (drawing_process.rs, util.rs)
• Optional multithreading: web worker (worker.js → src/app/calculate/worker) or native threads
• GPU acceleration: WGSL shaders (jfa.wgsl, shade.wgsl, etc.) invoked via wgpu in both targets
c. Preset Loader
• Reads assignments.json files under presets/ for one-click transforms
d. GIF Recorder
• Captures frame buffers to produce animated GIFs via gif_recorder.rs
e. Build & Deployment
• Cargo workflows build native binaries and Wasm bundles
• Trunk bundles assets, HTML, Wasm, worker.js, shaders, service worker for PWA
• CI/CD pipelines publish to GitHub/Cloudflare Pages and GitHub Releases
Architectural patterns & design principles
• Modular separation: GUI ↔ Compute ↔ Presets ↔ Recorder
• Single codebase, multi-target: shared lib.rs and app/ modules reused by native and Wasm
• PWA pattern: service worker caches static assets, manifest enables installability
• Worker pattern: heavy compute offloaded asynchronously