Skip to content

Add gutter snapping to overlap segments - #42

Open
terriblyoffendedmarketer-stack wants to merge 1 commit into
varo6:masterfrom
terriblyoffendedmarketer-stack:feat/gutter-snapping
Open

terriblyoffendedmarketer-stack wants to merge 1 commit into
varo6:masterfrom
terriblyoffendedmarketer-stack:feat/gutter-snapping

Conversation

@terriblyoffendedmarketer-stack

Copy link
Copy Markdown

Summary

When splitting pages into overlapping thirds, segment boundaries can land in the middle of a panel — cutting artwork in half. This PR detects horizontal gutters (the white gaps between panel rows) and snaps segment boundaries to those gutters, so splits happen between panels instead of through them.

  • findHorizontalGutters() — scans row brightness (with 5% edge margin) to find horizontal white strips ≥4px tall, returns Y centers
  • snapSegmentsToGutters() — moves each segment's start position to the nearest gutter within 15% of segment height; gutters consumed once used
  • Integrated into both converter.ts and convert-page.worker.ts overlap paths
  • UI checkbox "Snap to panel gutters" in Options (visible when split mode = overlap), enabled by default
  • 4 unit tests covering: snap to nearby, ignore distant, no gutters, single segment

How it works

  1. After calculateOverlapSegments() produces the initial segments, scan the grayscale page for horizontal bright bands (average brightness > 240 across the row, ignoring 5% at left/right edges)
  2. Group consecutive bright rows into gutter bands (minimum 4px tall), take each band's center Y
  3. For segments 2+, if a gutter center is within 15% of segmentHeight from the original start Y, snap to it
  4. Recalculate heights so segments tile correctly to the page bottom

Why this threshold

15% of segment height is enough to catch gutters near the natural third-boundaries while avoiding snapping to distant gutters that would create wildly unequal segments. The 5% edge margin prevents page borders and binding shadows from being detected as gutters.

Tested on manga (Berserk, Punpun, Chainsaw Man) and western comics (Civil War, Riddler, Spider-Man). Gutter snapping eliminates mid-panel cuts on standard grid layouts while gracefully falling back to original segments on splash pages or irregular layouts (no gutters detected = no change).

🤖 Generated with Claude Code

Detects horizontal gutters (white strips between panel rows) and snaps
overlap segment boundaries to those gutters so segments don't cut
through panels. Browser-compatible — pure pixel scanning, no OpenCV.

New functions in image.ts:
- findHorizontalGutters(): scans rows for white-dominant strips
- snapSegmentsToGutters(): moves segment starts to nearest gutter
  within 15% of segment height

New option: gutterSnap (default true) in ConversionOptions.
Wired into converter.ts and convert-page.worker.ts.
Tests added for snapping logic.

Based on research from comic-book-panel-converter benchmark:
- Tested across 51 titles (13 manga, 37 western comics)
- Gutter snapping prevents mid-panel cuts on ~80% of pages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant