fix(anim): answer the play button in the frame it is clicked #17

Merged
ben merged 1 commit from fix/playback-responsiveness into main 2026-11-16 15:15:02 +00:00
Owner

What changed

  • A frame of the animation is dithered at the size the viewport shows, once per
    animation frame, and the frame a person stops on is dithered again at the
    picture's own size.
  • The render runs after every panel of the frame, so a click on play/pause is
    handled before anything is dithered for it.
  • The preview texture is uploaded into the handle it already has instead of a
    new load_texture per render.
  • composite borrows layer pixels instead of copying every layer per render.
  • The dither screens, the tone stage, packing and the composite run in one row
    band per core (src/par.rs, std::thread::scope, no new dependency). The
    error-diffusion families stay single-threaded: they push their error into the
    next row.
  • A perceptual palette match no longer recomputes the Oklab of every palette
    entry per pixel.
  • Every writer of a file or the clipboard calls ensure_full_render, so a
    preview can never leave the app.

Why

Fixes the reported behaviour: the play button sometimes did not stop the
animation, and playback with effects was slow.

What ran

  • cargo fmt --check clean
  • cargo test --release: 243 passed
  • --audit: 558 passed, 1 skipped
  • --controls: 62 passed
  • --uitest: 100 passed (5 new playback/texture checks)
  • --selftest: 456 renders, 0 failures
  • Windows cross build (x86_64-pc-windows-gnu, static CRT)
  • --timing at 1200x900: median 72 ms -> 16 ms per style; PNGs written before
    and after this change are byte-identical

What did not run

macOS: no machine here.

Known, not fixed

Opening a picture or a project still reads, decodes and dithers on the UI thread
(filed as #10).

## What changed - A frame of the animation is dithered at the size the viewport shows, once per *animation* frame, and the frame a person stops on is dithered again at the picture's own size. - The render runs after every panel of the frame, so a click on play/pause is handled before anything is dithered for it. - The preview texture is uploaded into the handle it already has instead of a new `load_texture` per render. - `composite` borrows layer pixels instead of copying every layer per render. - The dither screens, the tone stage, packing and the composite run in one row band per core (`src/par.rs`, `std::thread::scope`, no new dependency). The error-diffusion families stay single-threaded: they push their error into the next row. - A perceptual palette match no longer recomputes the Oklab of every palette entry per pixel. - Every writer of a file or the clipboard calls `ensure_full_render`, so a preview can never leave the app. ## Why Fixes the reported behaviour: the play button sometimes did not stop the animation, and playback with effects was slow. ## What ran - `cargo fmt --check` clean - `cargo test --release`: 243 passed - `--audit`: 558 passed, 1 skipped - `--controls`: 62 passed - `--uitest`: 100 passed (5 new playback/texture checks) - `--selftest`: 456 renders, 0 failures - Windows cross build (`x86_64-pc-windows-gnu`, static CRT) - `--timing` at 1200x900: median 72 ms -> 16 ms per style; PNGs written before and after this change are byte-identical ## What did not run macOS: no machine here. ## Known, not fixed Opening a picture or a project still reads, decodes and dithers on the UI thread (filed as #10).
A click on pause was handled one render late, because the dither ran before
the timeline was drawn. On a heavy document that looks like a dead button, so
the click gets repeated — and the second click starts playback again. The
render now runs after every panel of the frame, and a paused animation stops
rendering at all.

What made those frames expensive is fixed with it:

- A frame of the animation and a frame under a dragged slider are dithered at
  the size the viewport shows; the full-size frame follows on the pause.
- One dither per animation frame instead of one per display frame (24 fps on a
  60 Hz display dithered the same frame two and a half times).
- The preview texture is uploaded into the handle it already has instead of a
  new `load_texture` per frame.
- `composite` borrows the layer pixels instead of copying every layer.
- The dither screens, the tone stage, packing and the composite are cut into
  one band per core (`src/par.rs`, scoped threads, no new dependency). The
  error-diffusion families stay single-threaded: they push their error into the
  next row. `--timing` at 1200x900: median 72 ms -> 16 ms per style.
- A perceptual palette match no longer recomputes the Oklab of every palette
  entry for every pixel.

The picture is unchanged: `the_picture_is_the_same_in_one_band_or_many` runs
every one of the 76 styles on one thread and on sixteen and compares the
pixels, and the PNGs written before and after this commit are byte-identical.

Export safety came out of the same change: a preview render clears `dirty`, so
`save_png` could write a stretched-up small picture, and the clipboard path
checked nothing at all. Every writer calls `ensure_full_render` now; the batch
export also reports a picture that failed to load instead of writing the
previous one under its name.

Not fixed, and said so in the changelog: opening a file still reads, decodes
and dithers it on the UI thread, which is where "not responding" comes from on
a large picture.

Checks: cargo test 243, --audit 558, --controls 62, --uitest 100 (5 new
playback/texture checks), --selftest 456, fmt clean, Windows cross build.
ben merged commit 5dcd0ef8f5 into main 2026-11-16 15:15:02 +00:00
Sign in to join this conversation.
No description provided.