Page 1 of 1

Converting premultiplied to non-premultiplied

Posted: Fri Sep 29, 2017 6:59 pm
by grump
Canvas:newImageData returns an image with premutliplied alpha. What is the best way to convert to an image that is not premultiplied? This is how I'm currently doing it:

Code: Select all

local img = canvas:newImageData()
img:mapPixel(function(x, y, r, g, b, a)
	return r / a * 255, g / a * 255, b / a * 255, a
end)
Is there a better/easier/faster way to achieve this?