Alpha not respected in previously working utility function (0.78)
Posted: Wed Nov 11, 2020 11:03 pm
Sorry to be a pain, but I have a new problem in 0.78.
I have a function I use for tinting bitmaps, which I use to create shadows for icons and other special effects. In 0.78, the alpha is no longer respected when I use this function, even though it previously worked.
This is an example of how I might use it:
This is the function, is there a modification I can make to get back the previous behaviour? Or do I need to do something different in how I use it?
I have a function I use for tinting bitmaps, which I use to create shadows for icons and other special effects. In 0.78, the alpha is no longer respected when I use this function, even though it previously worked.
This is an example of how I might use it:
Code: Select all
dsb_bitmap_draw(bitmap_adjustHSL(icon,0,0,0), bmp, bx+x_off, by+y_off+2, false)
Code: Select all
function bitmap_adjustHSL(bmp,angle,saturation,lightness)
local width = dsb_bitmap_width(bmp)
local height = dsb_bitmap_height(bmp)
local cx = 0
local cy = 0
local count = 0
local bmp_tinted = dsb_new_bitmap(width,height)
for cx = 0,width-1 do
for cy = 0,height-1 do
count = count + 1
local rgb, alpha = dsb_get_pixel(bmp, cx, cy)
r = rgb[1]; g = rgb[2]; b = rgb[3];
-- Handle alpha / powerpink of current pixel
if (alpha == nil ) then alpha = 255 end
-- If powerpink
if (r == 255 and g == 0 and b == 255 ) then alpha = 0 end
h,s,l = rgb_to_hsl({r,g,b})
-- Adjust Hue
h = (h + angle) / 360
if(h > 1) then h = h - 1 end
-- Adjust saturation
s = s * saturation
if(s > 1) then s = 1 end
if(s < 0) then s = 0 end
-- Adjust lightness
l = l * lightness
if(l > 1) then l = 1 end
if(l < 0) then l = 0 end
r,g,b = hsl_to_rgb(h,s,l)
--push new pixel into the bitmap
dsb_set_pixel(bmp_tinted, cx, cy, {r,g,b}, alpha)
end
end
return bmp_tinted
end