feat: adaptive background detection for dark mode support#23
Merged
Conversation
Replace hardcoded white (255,255,255) background assumption in content detection with auto-detection from image perimeter pixels. Two strategies, chosen automatically: - Alpha-only: transparent PNGs skip color-distance filtering entirely - Perimeter sampling: opaque images infer background via quantized color bucketing of edge pixels Adds backgroundColor prop as explicit override fallback.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Benchmark Comparison: main vs feat/adaptive-background-detectionThreshold: 5%+ change, >100us absolute delta, and statistically significant (p<0.05).
No regressions detected. Feature cost breakdownHow expensive are individual features? Measured on this run's HEAD commit.
Full benchmark output in the CI job logs. |
The corner-first fast path misidentified logo content as background when logos extended to the corners, causing sizing regressions. Restores the first commit's logic (full perimeter scan, alphaOnly for transparent images) with typed arrays instead of Map for bucketing.
- Inverted SVGs (transparent, light content) and JPG test logos - Dark Mode, JPG, and Comparison stories under LogoSoup group - Shared StoryLogoSoup wrapper with debug controls - Consolidated argTypes, defaults, and types in shared.tsx - alphaOnly path for transparent images, color distance for opaque - min(a, sqrt(distSq)) opacity for opaque density normalization
BackgroundColor type accepts hex, rgb(), hsl(), named colors, or [r, g, b] tuples. CSS strings are resolved via a 1×1 canvas.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the hardcoded white background assumption in content detection by auto-detecting the background color from the image itself.
Transparent images — alpha-only content detection (unchanged from current behavior)
Opaque images — background color sampled from image edges
Adds
backgroundColorprop as an explicit override fallback.Usage
Works automatically — no config needed for opaque images:
For explicit control (e.g. JPGs on a known dark page):
Also available on the hook:
Closes #2