{{newin|[[0.9.1]]|091|type=function}}
Converts a color from gamma-space (sRGB) to linear-space (RGB). This is useful when doing [[love.graphics.isGammaCorrect|gamma-correct rendering]] and you need to do math in linear RGB in the few cases where LÖVE doesn't handle conversions automatically.

Read more about gamma-correct rendering [https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch24.html here], [http://filmicgames.com/archives/299 here], and [http://renderwonk.com/blog/index.php/archive/adventures-with-gamma-correct-rendering/ here].

In versions prior to [[11.0]], color component values were within the range of 0 to 255 instead of 0 to 1.

{{notice|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.}}
== Function ==
=== Synopsis ===
<source lang="lua">
lr, lg, lb = love.math.gammaToLinear( r, g, b )
</source>
=== Arguments ===
{{param|number|r|The red channel of the sRGB color to convert.}}
{{param|number|g|The green channel of the sRGB color to convert.}}
{{param|number|b|The blue channel of the sRGB color to convert.}}
=== Returns ===
{{param|number|lr|The red channel of the converted color in linear RGB space.}}
{{param|number|lg|The green channel of the converted color in linear RGB space.}}
{{param|number|lb|The blue channel of the converted color in linear RGB space.}}
=== Notes ===
An alpha value can be passed into the function as a fourth argument, but it will be returned unchanged because alpha is always linear.

== Function ==
=== Synopsis ===
<source lang="lua">
lr, lg, lb = love.math.gammaToLinear( color )
</source>
=== Arguments ===
{{param|table|color|An array with the red, green, and blue channels of the sRGB color to convert.}}
=== Returns ===
{{param|number|lr|The red channel of the converted color in linear RGB space.}}
{{param|number|lg|The green channel of the converted color in linear RGB space.}}
{{param|number|lb|The blue channel of the converted color in linear RGB space.}}

== Function ==
=== Synopsis ===
<source lang="lua">
lc = love.math.gammaToLinear( c )
</source>
=== Arguments ===
{{param|number|c|The value of a color channel in sRGB space to convert.}}
=== Returns ===
{{param|number|lc|The value of the color channel in linear RGB space.}}

== Examples ==
=== Pre-multiply an image's alpha with its RGB values in linear RGB space ===
<source lang="lua">
local function PremultiplyLinearPixel(x, y, r, g, b, a)
   r = r * a
   g = g * a
   b = b * a
   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
   g = g * a
   b = b * a
   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")
</source>

== See Also ==
* [[parent::love.math]]
* [[love.math.linearToGamma]]
[[Category:Functions]]
{{#set:Description=Converts a color from gamma-space (sRGB) to linear-space (RGB).}}
== Other Languages ==
{{i18n|love.math.gammaToLinear}}