Repository navigation
Fast rotation: 8-bit SWAR bilinear sampling - #74
Merged
Merged
Conversation
`RotateOptions.fast` (default true): angles that aren't multiples of 90° sample 8-bit premultiplied pixels with 8-bit weights, red+blue and green+alpha sharing a multiplication (src/util/rotate.ts). The source gets a transparent border of one pixel, so taps outside it need no checks and edges fade as before; each row only visits the span that hits the source. unpremultiply8 writes fully transparent pixels directly. 1920x1080 photo by 30°: 119 -> 51 ms (alpha: 114 -> 61 ms). Over the corpus (4 angles), opaque pixels stay within 1 of `fast: false`, what shows of translucent ones (also the faded edges) within about 2.5 steps, alpha within 2. rotate-45 targets regenerated. 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.
Adds
RotateOptions.fast, on by default likeResizeOptions.fast. Rotations by angles that aren't multiples of 90° now sample with 8-bit weights on 8-bit premultiplied pixels, so red+blue and green+alpha each share one multiplication.fast: falsekeeps the floating-point sampling.Speed (1920×1080 photo rotated by 30°)
fast: falsefast(default)How it works (
src/util/rotate.ts)span()). At 30°, about 40% of the output is empty corners.src/util/alpha.ts.unpremultiply8now writes fully transparent pixels directly instead of doing three table lookups; the result is identical.Precision
Measured over the corpus (1298 images, 4 angles),
fastagainstfast: false:tests/rotate.jschecks these limits on a photo crop, with and without an alpha gradient.rotate-45targets are regenerated. They differ from the old ones by at most 1.🤖 Generated with Claude Code
https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ