From 8e17c6f518316eea1f30361083b42800e1c874a3 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 13 May 2025 17:12:23 +0200 Subject: [PATCH] Prefer use of `vips_interpretation_max_alpha()` This also ensures we handle scRGB correctly, see: https://github.com/libvips/libvips/commit/e9c5a3155272b7328f5a0f1a21d0afcfbd1d7490 --- src/common.cc | 10 +--------- src/common.h | 6 ------ src/stats.cc | 2 +- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/common.cc b/src/common.cc index 575b54e7..b00483c5 100644 --- a/src/common.cc +++ b/src/common.cc @@ -951,14 +951,6 @@ namespace sharp { return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16; } - /* - Return the image alpha maximum. Useful for combining alpha bands. scRGB - images are 0 - 1 for image data, but the alpha is 0 - 255. - */ - double MaximumImageAlpha(VipsInterpretation const interpretation) { - return Is16Bit(interpretation) ? 65535.0 : 255.0; - } - /* Convert RGBA value to another colourspace */ @@ -1033,7 +1025,7 @@ namespace sharp { VImage EnsureAlpha(VImage image, double const value) { if (!image.has_alpha()) { std::vector alpha; - alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation())); + alpha.push_back(value * vips_interpretation_max_alpha(image.interpretation())); image = image.bandjoin_const(alpha); } return image; diff --git a/src/common.h b/src/common.h index bd942806..1a61e47d 100644 --- a/src/common.h +++ b/src/common.h @@ -357,12 +357,6 @@ namespace sharp { */ bool Is16Bit(VipsInterpretation const interpretation); - /* - Return the image alpha maximum. Useful for combining alpha bands. scRGB - images are 0 - 1 for image data, but the alpha is 0 - 255. - */ - double MaximumImageAlpha(VipsInterpretation const interpretation); - /* Convert RGBA value to another colourspace */ diff --git a/src/stats.cc b/src/stats.cc index 61df71a2..bc9b243c 100644 --- a/src/stats.cc +++ b/src/stats.cc @@ -60,7 +60,7 @@ class StatsWorker : public Napi::AsyncWorker { // Image is not opaque when alpha layer is present and contains a non-mamixa value if (image.has_alpha()) { double const minAlpha = static_cast(stats.getpoint(STAT_MIN_INDEX, bands).front()); - if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) { + if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) { baton->isOpaque = false; } }