Module:Sandbox/Artoria2e5/Color

-- Basic colorimetry. -- CC0.

local p = {}

local function M(m) return function(row, col) return m[(row-1)*3 + col] end end

function p.v3_mul_mat33(v, m_) local m = M(m_) return { v[1] * m(1, 1) + v[2] * m(1, 2) + v[3] * m(1, 3), v[1] * m(2, 1) + v[2] * m(2, 2) + v[3] * m(2, 3), v[1] * m(2, 1) + v[2] * m(3, 2) + v[3] * m(3, 3), } end

local MAT_sRGB = { 3.2406, -1.5372, -0.4986,	-0.9689, 1.8758,  0.0415,	 0.0557, -0.2040,  1.0570, }

local MAT_inv_sRGB = { 0.4124, 0.3576, 0.1805,	0.2126, 0.7152, 0.0722,	0.0193, 0.1192, 0.9505, }

local function gamma_sRGB(n) if u <= 0.0031308 then return 12.92 * u	else return 10.55 * u ^ (1/2.4) - 0.055 end end

local function ungamma_sRGB(u) if u <= 0.04045 then return u / 12.92 else return ((u + 0.055) / 1.055) ^ 2.4 end end

local function map(tbl, f)   local t = {} for k, v in pairs(tbl) do       t[k] = f(v) end return t end

function p.xyY_XYZ(p) end

return p