Added adjusted gamma
This commit is contained in:
parent
541aff4d13
commit
d7490f464c
19
colors.lua
19
colors.lua
|
@ -7,6 +7,9 @@
|
||||||
LICENSE is BEER-WARE.
|
LICENSE is BEER-WARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local GAMMA = 2.2
|
||||||
|
local GAMMA_INV = 1/GAMMA
|
||||||
|
|
||||||
local colors = {}
|
local colors = {}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -83,13 +86,14 @@ end
|
||||||
-- Interpolation
|
-- Interpolation
|
||||||
|
|
||||||
colors.interpolate_rgb = function (c1, c2, t)
|
colors.interpolate_rgb = function (c1, c2, t)
|
||||||
assert(type(c1) == 'table' and type(c1[1]) == 'number' and type(c1[2]) == 'number' and type(c1[3]) == 'number' and (type(c1[4]) == 'number' or c1[4] == nil))
|
return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t }
|
||||||
assert(type(c2) == 'table' and type(c2[1]) == 'number' and type(c2[2]) == 'number' and type(c2[3]) == 'number' and (type(c2[4]) == 'number' or c2[4] == nil))
|
end
|
||||||
assert(type(t) == 'number')
|
|
||||||
--
|
colors.interpolate_rgb_gamma_adjusted = function (c1, c2, t)
|
||||||
local alpha = nil
|
local c1_r, c1_g, c1_b = c1[1]^GAMMA, c1[2]^GAMMA, c1[3]^GAMMA
|
||||||
if c1[4] or c2[4] then alpha = (c1[4] or 255) + ((c2[4] or 255)-(c1[4] or 255))*t end
|
local c2_r, c2_g, c2_b = c2[1]^GAMMA, c2[2]^GAMMA, c2[3]^GAMMA
|
||||||
return { c1[1]+(c2[1]-c1[1])*t, c1[2]+(c2[2]-c1[2])*t, c1[3]+(c2[3]-c1[3])*t, alpha }
|
local c3_r, c3_g, c3_b = c1_r+(c2_r-c1_r)*t, c1_g+(c2_g-c1_g)*t, c1_b+(c2_b-c1_b)*t
|
||||||
|
return c3_r^GAMMA_INV, c3_g^GAMMA_INV, c3_b^GAMMA_INV
|
||||||
end
|
end
|
||||||
|
|
||||||
local function angle_delta (a1, a2)
|
local function angle_delta (a1, a2)
|
||||||
|
@ -151,3 +155,4 @@ end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user