-
Notifications
You must be signed in to change notification settings - Fork 4.8k
RGBA image enhancements #3934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eirikur-nc
wants to merge
10
commits into
parallax:master
Choose a base branch
from
eirikur-nc:rgba-compression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
RGBA image enhancements #3934
+481
−253
Conversation
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
eirikur-nc
commented
Dec 25, 2025
Comment on lines
76
to
-83
| it("with alpha", () => { | ||
| const c = document.createElement("canvas"); | ||
| const ctx = c.getContext("2d"); | ||
| ctx.fillStyle = "#FFFFFF"; | ||
| ctx.fillRect(0, 0, 150, 60); | ||
| ctx.fillStyle = "#AA00FF77"; | ||
| ctx.fillRect(10, 10, 130, 40); | ||
| const dataFromCanvas = ctx.getImageData(0, 0, 150, 60); |
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was flawed. It specified alpha values when drawing on the canvas object. The resulting image however only had fully opaque pixels, with the color blending taking place within the canvas element. I therefore changed it to explicitly set alpha values.
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.
What
Primary
Secondary
rgba_support.jsa bit.Closes #3933
Why
To provide a more performant path for adding images that use lossless compression.
To measure the impact of these changes, I created simple benchmark that converted a dummy html report into an image (via html2canvas) and then added that to a PDF.
image-format-benchmark.html
Here are the results of running that benchmark before and after at MEDIUM compression.
Before
After
This shows that it is now possible to use the RGBA path to add lossless images at file sizes that are comparable to PNGs while taking roughly 30% less time. This time difference is attributable to the PNG path having an additional decode stage which the RGBA path does not.
The PNG path also benefits from the filter optimizations, yielding a ~8% reduction in execution time at medium compression.
The JPEG path is still much faster, as it performs minimal processing of images. It would be interesting to see if a similar approach would be feasible for PNGs.
How
By
png_support.jsinto a new module namedcompression_utils.jsso that they can be re-used without duplication.rgba_support.jsto compress the image data when applicable.sMaskproperty, rather than asalphawhich was never read.