-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Accept premultiplied raw inputs #2685
Conversation
3047585
to
2f916f6
Compare
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.
Thank you very much for the PR, this looks great and it's always a pleasure to see unit tests. Please go ahead and add JSDocs for this, plus I've left one small comment inline.
src/common.cc
Outdated
@@ -96,6 +96,10 @@ namespace sharp { | |||
descriptor->rawWidth = AttrAsUint32(input, "rawWidth"); | |||
descriptor->rawHeight = AttrAsUint32(input, "rawHeight"); | |||
} | |||
// Raw pixel input is premultiplied | |||
if (HasAttr(input, "rawPremultiplied")) { |
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.
If possible, it might be better to ensure inputDescriptor.rawPremultiplied
is always set in the JavaScript code to avoid a conditional statement here.
83cb4f3
to
c0b892a
Compare
c0b892a
to
c9d5eb1
Compare
Some inputs may already be premultiplied, and it is more efficient to handle it in libvips than in javascript.
c9d5eb1
to
87c38c1
Compare
Brilliant, thank you very much, this will be in v0.28.2. |
This comment has been minimized.
This comment has been minimized.
Maplibre-native outputs premultiplied pixels values. The sharp library did not support it so we added code to cancel the alpha premultiplication. Note that this can only visible onr raster tiles (and probably static maps). The sharp library now supports premultiplied pixels with the right config. Let's use it: it should be faster and easie to maintain. Feature announced here: lovell/sharp#1599 (comment) Feature developped here by @mnutt: lovell/sharp#2685 Signed-off-by: Martin d'Allens <martin.dallens@liberty-rider.com>
Maplibre-native outputs premultiplied pixels values. The sharp library did not support it so we added code to cancel the alpha premultiplication. Note that this can only visible onr raster tiles (and probably static maps). The sharp library now supports premultiplied pixels with the right config. Let's use it: it should be faster and easie to maintain. Feature announced here: lovell/sharp#1599 (comment) Feature developped here by @mnutt: lovell/sharp#2685 Signed-off-by: Martin d'Allens <martin.dallens@liberty-rider.com>
Maplibre-native outputs premultiplied pixels values. The sharp library did not support it so we added code to cancel the alpha premultiplication. Note that this can only visible onr raster tiles (and probably static maps). The sharp library now supports premultiplied pixels with the right config. Let's use it: it should be faster and easie to maintain. Feature announced here: lovell/sharp#1599 (comment) Feature developped here by @mnutt: lovell/sharp#2685 Signed-off-by: Martin d'Allens <martin.dallens@liberty-rider.com>
Addresses #1599.
I'm using
tileserver-gl
which works around using premultiplied inputs like so: https://github.com/maptiler/tileserver-gl/blob/4036d528ec9e/src/serve_rendered.js#L280-L294. This works, but from some simple benchmarks I've run it looks like it's faster to do in libvips than in javascript, especially for large images.I ran into a bit of trouble with the unit test using
assertSimilar
, as the tests passed whether or not the image was unpremultiplied first so I ended up comparing the raw output directly.If this approach looks acceptable I can add public API documentation.