Prefer use of vips_interpretation_max_alpha()

This also ensures we handle scRGB correctly, see:
e9c5a31552
This commit is contained in:
Kleis Auke Wolthuizen 2025-05-13 17:12:23 +02:00 committed by Lovell Fuller
parent 94481a967e
commit 8e17c6f518
3 changed files with 2 additions and 16 deletions

View File

@ -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<double> 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;

View File

@ -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
*/

View File

@ -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<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {
if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
baton->isOpaque = false;
}
}