diff options
author | Karl Berry <karl@freefriends.org> | 2021-03-06 21:58:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-03-06 21:58:15 +0000 |
commit | 974640d66e61e81cb197ad96fdff7b08343e4c5a (patch) | |
tree | 2e1f75f32f312b7f24ba82b4590ae230bcd6f399 /Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua | |
parent | b4fa72e61230aca75f7f6fbf988821f71edfb6b2 (diff) |
context
git-svn-id: svn://tug.org/texlive/trunk@58167 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua b/Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua index 06a913e1728..f523e870e91 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/colo-icc.lua @@ -119,3 +119,110 @@ function colors.iccprofile(filename,verbose) report_colors("profile %a loaded",fullname) return profile, true end + +-- This is just some fun stuff I decided to check out when I was making sure that +-- the 2020 metafun manual could be processed with lmtx 2021. Color conversion has +-- been part of ConTeXt from the start but it has been extended to the less commonly +-- used color spaces. We already do some CIE but didn't have lab converters to play +-- with (although I had some MetaPost done for a friend long ago). So, when we moved +-- to lmtx it made sense to also move some into the core. When searching for info +-- I ran into some formulas for lab/xyz: http://www.easyrgb.com/en/math.php and +-- http://www.brucelindbloom.com/ are useful resources. I didn't touch existing +-- code (as it works ok). +-- +-- local illuminants = { -- 2=CIE 1931 10=CIE 1964 +-- A = { [2] = { 109.850, 100, 35.585 }, [10] = { 111.144, 100, 35.200 } }, -- incandescent/tungsten +-- B = { [2] = { 99.093, 100, 85.313 }, [10] = { 99.178, 100, 84.349 } }, -- old direct sunlight at noon +-- C = { [2] = { 98.074, 100, 118.232 }, [10] = { 97.285, 100, 116.145 } }, -- old daylight +-- D50 = { [2] = { 96.422, 100, 82.521 }, [10] = { 96.720, 100, 81.427 } }, -- icc profile pcs +-- D55 = { [2] = { 95.682, 100, 92.149 }, [10] = { 95.799, 100, 90.926 } }, -- mid-morning daylight +-- D65 = { [2] = { 95.047, 100, 108.883 }, [10] = { 94.811, 100, 107.304 } }, -- daylight, srgb, adobe-rgb +-- D75 = { [2] = { 94.972, 100, 122.638 }, [10] = { 94.416, 100, 120.641 } }, -- north sky daylight +-- E = { [2] = { 100.000, 100, 100.000 }, [10] = { 100.000, 100, 100.000 } }, -- equal energy +-- F1 = { [2] = { 92.834, 100, 103.665 }, [10] = { 94.791, 100, 103.191 } }, -- daylight fluorescent +-- F2 = { [2] = { 99.187, 100, 67.395 }, [10] = { 103.280, 100, 69.026 } }, -- cool fluorescent +-- F3 = { [2] = { 103.754, 100, 49.861 }, [10] = { 108.968, 100, 51.965 } }, -- white fluorescent +-- F4 = { [2] = { 109.147, 100, 38.813 }, [10] = { 114.961, 100, 40.963 } }, -- warm white fluorescent +-- F5 = { [2] = { 90.872, 100, 98.723 }, [10] = { 93.369, 100, 98.636 } }, -- daylight fluorescent +-- F6 = { [2] = { 97.309, 100, 60.191 }, [10] = { 102.148, 100, 62.074 } }, -- lite white fluorescent +-- F7 = { [2] = { 95.044, 100, 108.755 }, [10] = { 95.792, 100, 107.687 } }, -- daylight fluorescent, d65 simulator +-- F8 = { [2] = { 96.413, 100, 82.333 }, [10] = { 97.115, 100, 81.135 } }, -- sylvania f40, d50 simulator +-- F9 = { [2] = { 100.365, 100, 67.868 }, [10] = { 102.116, 100, 67.826 } }, -- cool white fluorescent +-- F10 = { [2] = { 96.174, 100, 81.712 }, [10] = { 99.001, 100, 83.134 } }, -- ultralume 50, philips tl85 +-- F11 = { [2] = { 100.966, 100, 64.370 }, [10] = { 103.866, 100, 65.627 } }, -- ultralume 40, philips tl84 +-- F12 = { [2] = { 108.046, 100, 39.228 }, [10] = { 111.428, 100, 40.353 } }, -- ultralume 30, philips tl83 +-- } +-- +-- local D65 = illuminants.D65 +-- local D652 = { 95.047, 100, 108.883 } +-- +-- local function labref(illuminate,observer) +-- local r = illuminants[illuminant or "D65"] or D65 +-- return r[observer or 2] or r[2] or D652 +-- end +-- +-- This is hardly useful but nice for metafun demos: + +local D652 = { 95.047, 100, 108.883 } + +local function xyztolab(x,y,z,mapping) + if not mapping then + mapping = D652 + end + x = x / mapping[1] + y = y / mapping[2] + z = z / mapping[3] + x = (x > 0.008856) and x^(1/3) or (7.787 * x) + (16/116) + y = (y > 0.008856) and y^(1/3) or (7.787 * y) + (16/116) + z = (z > 0.008856) and z^(1/3) or (7.787 * z) + (16/116) + return + 116 * y - 16, + 500 * (x - y), + 200 * (y - z) +end + +local function labtoxyz(l,a,b,mapping) + if not mapping then + mapping = D652 + end + local y = (l + 16) / 116 + local x = a / 500 + y + local z = y - b / 200 + return + mapping[1] * ((x^3 > 0.008856) and x^3 or (x - 16/116) / 7.787), + mapping[2] * ((y^3 > 0.008856) and y^3 or (y - 16/116) / 7.787), + mapping[3] * ((z^3 > 0.008856) and z^3 or (z - 16/116) / 7.787) +end + +local function xyztorgb(x,y,z) -- D65/2° + local r = (x * 3.2404542 + y * -1.5371385 + z * -0.4985314) / 100 + local g = (x * -0.9692660 + y * 1.8760108 + z * 0.0415560) / 100 + local b = (x * 0.0556434 + y * -0.2040259 + z * 1.0572252) / 100 + r = (r > 0.0031308) and (1.055 * r^(1/2.4) - 0.055) or (12.92 * r) + g = (g > 0.0031308) and (1.055 * g^(1/2.4) - 0.055) or (12.92 * g) + b = (b > 0.0031308) and (1.055 * b^(1/2.4) - 0.055) or (12.92 * b) + if r < 0 then r = 0 elseif r > 1 then r = 1 end + if g < 0 then g = 0 elseif g > 1 then g = 1 end + if b < 0 then b = 0 elseif b > 1 then b = 1 end + return r, g, b +end + +local function rgbtoxyz(r,g,b) + r = 100 * ((r > 0.04045) and ((r + 0.055)/1.055)^2.4 or (r / 12.92)) + g = 100 * ((g > 0.04045) and ((g + 0.055)/1.055)^2.4 or (g / 12.92)) + b = 100 * ((b > 0.04045) and ((b + 0.055)/1.055)^2.4 or (b / 12.92)) + return + r * 0.4124 + g * 0.3576 + b * 0.1805, + r * 0.2126 + g * 0.7152 + b * 0.0722, + r * 0.0193 + g * 0.1192 + b * 0.9505 +end + +local function labtorgb(l,a,b,mapping) + return xyztorgb(labtoxyz(l,a,b,mapping)) +end + +colors.xyztolab = xyztolab +colors.labtoxyz = labtoxyz +colors.xyztorgb = xyztorgb +colors.rgbtoxyz = rgbtoxyz +colors.labtorgb = labtorgb |