Repository navigation
Faster blur: box blurs on 32-bit words - #69
Merged
Merged
Conversation
blur() premultiplied the image into floats, ran the three box blurs on four float channels (clamping the window to the image for every pixel) and converted back: 205 ms for a 1920x1080 photo, slower than stackblur (127 ms, 83 ms without alpha). The box blurs now run on the pixels as 32-bit words: red and blue share a sum as two 16-bit lanes, green and alpha another (a window of up to 257 pixels fits), and the average is a multiplication by 65536 / size. Each box rounds to 8 bits. Opaque images need no conversion, transparent ones are premultiplied in 8 bits first, as browsers (Skia) blur them. Radii below 2 keep the exact gaussian kernel on floats, as does sharpen(). 86 ms for the photo. Over 1298 corpus images at 5 radii: opaque results within 1 of before (2 above radius 10); with alpha, the premultiplied values (what compositing shows) within 2, the unpremultiplied color of almost transparent pixels further off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ
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.
blur()was the operation where the fastest pure-JS alternative beat us: stackblur took 127 ms on the benchmark photo (1920×1080), or 83 ms without alpha. We took 205 ms.Changes
sharpen().Results
Checked on 1298 corpus images at sigma 2, 3.5, 5, 12 and 40:
tests/targets/effects.pngis regenerated: its blur tile differs by at most 1.The changelog entry goes under 3.2.1, the same section #68 uses, so whichever is merged second has a trivial conflict there.
🤖 Generated with Claude Code
https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ