To convert an image with alpha, to premultiplied alpha, you need to loop over the texels and multiply the rgb values with the alpha.
Here’s a c++ snippet for comparison.
for (uint32_t i = 0; i < width*height; ++i)
{
uint32_t a = data[3];
data[0] = (uint8_t)( (data[0] * a) / 255 );
data[1] = (uint8_t)( (data[1] * a) / 255 );
data[2] = (uint8_t)( (data[2] * a) / 255 );
data += 4;
}
May I ask what you benefit from using imageloader
extension over our builtin image.load()
?
In any case, you need to either request a feature from the author (@sergey.lerg) or implement it your self.
Something like this (untested):
local rgba = buffer.get_stream(img_buffer, "pixels")
for y=0,height-1 do
for x=0,width-1 do
local index = y * width * 4 + x * 4 + 1
local a = rgba[index + 3]
rgba[index + 0] = (self.r * a) / 255
rgba[index + 1] = (self.g * a) / 255
rgba[index + 2] = (self.b * a) / 255
end
end