Ensure image is unpremultiplied before composite #3334

This commit is contained in:
Lovell Fuller
2022-08-21 17:51:05 +01:00
parent a44168c8c7
commit a618ce7a15
3 changed files with 37 additions and 12 deletions

View File

@@ -590,6 +590,18 @@ class PipelineWorker : public Napi::AsyncWorker {
baton->sharpenX1, baton->sharpenY2, baton->sharpenY3);
}
// 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);
}
}
baton->premultiplied = shouldPremultiplyAlpha;
// Composite
if (shouldComposite) {
std::vector<VImage> images = { image };
@@ -670,18 +682,6 @@ class PipelineWorker : public Napi::AsyncWorker {
image = VImage::composite(images, modes, VImage::option()->set("x", xs)->set("y", ys));
}
// 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);
}
}
baton->premultiplied = shouldPremultiplyAlpha;
// Gamma decoding (brighten)
if (baton->gammaOut >= 1 && baton->gammaOut <= 3) {
image = sharp::Gamma(image, baton->gammaOut);