Repository navigation
Fast resizing by default: 8-bit SWAR in both passes - #71
Merged
Merged
Conversation
Opaque images resized with bilinear or area resizing (down to about a third of the size, and enlarging) round to 8 bits between the passes, so the second pass shares its multiplications between two channels too. Halving a 1920x1080 photo: 15 -> 12 ms, doubling it: 80 -> 61 ms. Results stay within 1 of the previous ones (1313 corpus images). `ResizeOptions.fast: false` keeps the previous resampling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ
With `fast` (the default), transparent images are premultiplied to 8 bits, like browsers do, and both passes multiply red+blue and green+alpha as 16-bit lanes; a reciprocal table unpremultiplies. Halving a 1920x1080 photo with alpha: 43 -> 24 ms, doubling it: 260 -> 119 ms. Over 178 transparent corpus images the composited result stays within about 2 steps of `fast: false` (alpha within 2); colors of almost transparent pixels keep less precision. 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.
Bilinear and area resizing now use 8-bit SWAR in both passes: the intermediate image is rounded to 8 bits, so every multiplication handles two channels. This is the new default, and
ResizeOptions.fast: falsekeeps the 3.2.1 resampling.Opaque images
The second pass now also multiplies two channels at once (the first pass already did in 3.2.1).
Resampling a 1920×1080 photo:
fast, default)Compared with
fast: falseacross 1313 corpus images and 9 sizes, every result is within 1 per channel. 10–25% of the values differ by 1, versus about 1% betweenfast: falseand an exact float reference.Transparent images
Before, transparent images always took the precise premultiplied path. With
fast, they are now premultiplied to 8 bits, the way browsers and Skia do it:resize()of the same photo with alpha:fastCompared with
fast: falseacross 178 transparent corpus images and 14 size/mode combinations:blur()has done the same since 3.2.1.Limits
Changes
src/util/resample.ts:resampleOpaqueFastandresampleTransparentFast.ResizeOptions.fastis passed throughscale,resize,contain,fit,coverandAnimation.resize.tests/resize.jschecks, on a photo crop and the same crop with an alpha gradient:🤖 Generated with Claude Code
https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ