Skip to content

Commit 16f3c18

Browse files
RiskoZoSlovenskarolandlo
authored andcommitted
Use Lua addalpha impl. only for libvips < 8.16.0
Newer versions of libvips support `addalpha` as an operation
1 parent e33563e commit 16f3c18

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/vips/Image_methods.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,20 @@ function Image_method:hasalpha()
582582
return vips_lib.vips_image_hasalpha(self.vimage) ~= 0
583583
end
584584

585-
function Image_method:addalpha()
586-
local max_alpha
587-
if self:interpretation() == "rgb16" or self:interpretation() == "grey16" then
588-
max_alpha = 65535
589-
elseif self:interpretation() == "scrgb" then
590-
max_alpha = 1.0
591-
else
592-
max_alpha = 255
593-
end
585+
-- addalpha was made a VipsOperation in vips 8.16; earlier versions need this polyfill
586+
if not version.at_least(8, 16) then
587+
function Image_method:addalpha()
588+
local max_alpha
589+
if self:interpretation() == "rgb16" or self:interpretation() == "grey16" then
590+
max_alpha = 65535
591+
elseif self:interpretation() == "scrgb" then
592+
max_alpha = 1.0
593+
else
594+
max_alpha = 255
595+
end
594596

595-
return self:bandjoin(max_alpha)
597+
return self:bandjoin(max_alpha)
598+
end
596599
end
597600

598601
function Image_method:bandsplit()

0 commit comments

Comments
 (0)