Skip to content

Support filtering toCompositeImage() to a subset of layers - #37

Merged
philips merged 1 commit into
mainfrom
atelier-composite-subset
Jul 28, 2026
Merged

Support filtering toCompositeImage() to a subset of layers#37
philips merged 1 commit into
mainfrom
atelier-composite-subset

Conversation

@philips-clanker

Copy link
Copy Markdown
Collaborator

Summary

Fixes #35. toCompositeImage() previously always flattened every surface in the file. The Obsidian plugin's .spd viewer wants a per-layer visibility toggle (philips/supernote-obsidian-plugin#138), which needs compositing only a chosen subset of surfaces on each re-render instead of always all of them.

async toCompositeImage(visibleSurfaces?: Iterable<IAtelierSurfaceName>): Promise<Image | null>
  • undefined (the default) keeps existing behavior — every surface, via _compositeOrder().
  • When given, _compositeOrder()'s result is filtered down to just the requested surface names before compositing, so the bottom-to-top layers-based stacking order is unchanged — only which surfaces participate changes.
  • Surface names not present in the file are silently ignored, matching toImage()'s existing behavior for an unknown surface name.
  • An empty/all-excluded set (or a file with no tiles at all) returns null, same as the no-tiles case already did.

Test plan

  • npm run build (tsc) succeeds
  • npm run lint passes
  • npm test — full suite passes (39/39)
  • New tests against tests/input/real-device.spd (per the issue's request):
    • Compositing just ['surface_1', 'surface_2'] (hiding the surface_9999 "Reference Layer" background) produces an image still sized/aligned to the full file, but transparent where only the background would have shown, while the full composite is opaque there.
    • Empty subset, and a subset of only a tile-less surface, both return null.
    • A subset naming a nonexistent surface alongside a real one still composites the real one.
  • Visually inspected the "hide background" composite — shows only the two sketch layers on a transparent canvas, background fully excluded

Adds an optional visibleSurfaces parameter, closing #35: the Obsidian
plugin's .spd viewer wants a per-layer visibility toggle
(philips/supernote-obsidian-plugin#138), which needs compositing only
a chosen subset of surfaces instead of always every surface in the
file.

undefined (the default) keeps existing behavior. When given, surfaces
not in the set are dropped from _compositeOrder()'s result before
compositing, so the bottom-to-top layers-based ordering is unchanged
-- only which surfaces participate changes. Surface names not present
in the file are silently ignored, same as toImage() already does for
an unknown surface name.
@philips
philips marked this pull request as ready for review July 28, 2026 21:02
@philips
philips merged commit 3e78a51 into main Jul 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SupernoteAtelier.toCompositeImage(): support filtering to a subset of layers

2 participants