Prefer integer (un)premultiply for faster RGBA resize

This commit is contained in:
Lovell Fuller
2023-01-24 15:24:58 +00:00
parent 802f560b9b
commit 9e2207f376
14 changed files with 3 additions and 8 deletions

View File

@@ -367,11 +367,12 @@ class PipelineWorker : public Napi::AsyncWorker {
image = sharp::EnsureAlpha(image, 1);
}
VipsBandFormat premultiplyFormat = image.format();
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
(shouldResize || shouldBlur || shouldConv || shouldSharpen);
if (shouldPremultiplyAlpha) {
image = image.premultiply();
image = image.premultiply().cast(premultiplyFormat);
}
// Resize
@@ -583,13 +584,7 @@ class PipelineWorker : public Napi::AsyncWorker {
// Reverse premultiplication after all transformations
if (shouldPremultiplyAlpha) {
image = image.unpremultiply();
// Cast pixel values to integer
if (sharp::Is16Bit(image.interpretation())) {
image = image.cast(VIPS_FORMAT_USHORT);
} else {
image = image.cast(VIPS_FORMAT_UCHAR);
}
image = image.unpremultiply().cast(premultiplyFormat);
}
baton->premultiplied = shouldPremultiplyAlpha;