Available since LÖVE 0.9.1
This function is not supported in earlier versions.
Converts a color from linear-space (RGB) to gamma-space (sRGB). This is useful when storing linear RGB color values in an image, because the linear RGB color space has less precision than sRGB for dark colors, which can result in noticeable color banding when drawing.
In general, colors chosen based on what they look like on-screen are already in gamma-space and should not be double-converted. Colors calculated using math are often in the linear RGB space.
Read more about gamma-correct rendering here, here, and here.
Gamma-correct rendering is an advanced topic and it's easy to get color-spaces mixed up. If you're not sure whether you need this, you might want to avoid it.
cr, cg, cb = love.math.linearToGamma( lr, lg, lb )
number lrnumber lgnumber lbnumber crnumber cgnumber cbAn alpha value can be passed into the function as a fourth argument, but it will be returned unchanged because alpha is always linear.
cr, cg, cb = love.math.linearToGamma( color )
table colornumber crnumber cgnumber cbc = love.math.linearToGamma( lc )
number lcnumber clocal function PremultiplyLinearPixel(x, y, r, g, b, a)
r = r * a / 255
g = g * a / 255
b = b * a / 255
return r, g, b, a
end
local function PremultiplyGammaPixel(x, y, r, g, b, a)
r, g, b = love.math.gammaToLinear(r, g, b)
r = r * a / 255
g = g * a / 255
b = b * a / 255
r, g, b = love.math.linearToGamma(r, g, b)
return r, g, b, a
end
-- Loads an image and pre-multiplies its RGB values with its alpha, for use with the ('alpha', 'premultiplied') blend mode.
-- The multiplication correctly accounts for the color-space of the image.
function NewPremultipliedImage(filepath, flags)
local imagedata = love.image.newImageData(filepath)
local mapfunction = (flags and flags.linear) and PremultiplyLinearPixel or PremultiplyGammaPixel
imagedata:mapPixel(mapfunction)
return love.graphics.newImage(imagedata, flags)
end
image = NewPremultipliedImage("pig.png")
© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.math.linearToGamma