Prefer integer (un)premultiply for faster RGBA resize
@ -367,11 +367,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
image = sharp::EnsureAlpha(image, 1);
|
image = sharp::EnsureAlpha(image, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VipsBandFormat premultiplyFormat = image.format();
|
||||||
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = sharp::HasAlpha(image) &&
|
||||||
(shouldResize || shouldBlur || shouldConv || shouldSharpen);
|
(shouldResize || shouldBlur || shouldConv || shouldSharpen);
|
||||||
|
|
||||||
if (shouldPremultiplyAlpha) {
|
if (shouldPremultiplyAlpha) {
|
||||||
image = image.premultiply();
|
image = image.premultiply().cast(premultiplyFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize
|
// Resize
|
||||||
@ -583,13 +584,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Reverse premultiplication after all transformations
|
// Reverse premultiplication after all transformations
|
||||||
if (shouldPremultiplyAlpha) {
|
if (shouldPremultiplyAlpha) {
|
||||||
image = image.unpremultiply();
|
image = image.unpremultiply().cast(premultiplyFormat);
|
||||||
// Cast pixel values to integer
|
|
||||||
if (sharp::Is16Bit(image.interpretation())) {
|
|
||||||
image = image.cast(VIPS_FORMAT_USHORT);
|
|
||||||
} else {
|
|
||||||
image = image.cast(VIPS_FORMAT_UCHAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
baton->premultiplied = shouldPremultiplyAlpha;
|
baton->premultiplied = shouldPremultiplyAlpha;
|
||||||
|
|
||||||
|
BIN
test/fixtures/expected/extract-alpha-16bit.png
vendored
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 255 B |
BIN
test/fixtures/expected/modulate-hue-angle-120.png
vendored
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-150.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-180.png
vendored
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-210.png
vendored
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-240.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-270.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-30.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-300.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-330.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-360.png
vendored
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-60.png
vendored
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 301 KiB |
BIN
test/fixtures/expected/modulate-hue-angle-90.png
vendored
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 301 KiB |