Skip to content

Instantly share code, notes, and snippets.

@hhrhhr
Last active April 12, 2019 06:04
Show Gist options
  • Save hhrhhr/827bb0509892e2d05f0fa0f264663510 to your computer and use it in GitHub Desktop.
Save hhrhhr/827bb0509892e2d05f0fa0f264663510 to your computer and use it in GitHub Desktop.
ColorChecker SG SVG generator
LGOROWLENGTH 12
ORIGINATOR "ColorCheckerSG - November2014 edition and newer"
MANUFACTURER "X-Rite - http://www.xrite.com"
5/11/2015 # Time: 16:08
"i1Pro 2 ; Serial number 1000691"
"MeasurementCondition=M0 Filter=no"
NUMBER_OF_FIELDS 4
BEGIN_DATA_FORMAT
Sample_NAME Lab_L Lab_a Lab_b
END_DATA_FORMAT
NUMBER_OF_SETS 140
BEGIN_DATA
A1 96.71 -0.62 2.06
A2 8.05 0.17 -0.69
A3 49.76 0.11 0.72
A4 96.72 -0.63 2.06
A5 8.17 0.15 -0.65
A6 49.68 0.14 0.74
A7 96.60 -0.62 2.11
A8 7.99 0.21 -0.75
A9 49.67 0.15 0.73
A10 96.51 -0.63 2.11
B1 49.70 0.12 0.68
B2 33.02 52.00 -10.30
B3 61.40 27.14 -18.42
B4 30.54 50.39 -41.79
B5 49.56 -13.90 -49.65
B6 60.62 -29.91 -27.54
B7 20.13 -24.81 -7.50
B8 60.32 -40.29 -13.25
B9 19.62 1.77 11.99
B10 49.68 0.15 0.78
C1 8.13 0.15 -0.76
C2 19.65 20.42 -18.82
C3 41.70 18.90 -37.42
C4 20.25 0.26 -36.44
C5 60.13 -17.88 -32.08
C6 19.75 -17.79 -22.37
C7 60.43 -5.12 -32.79
C8 50.46 -47.90 -11.56
C9 60.53 -40.75 19.37
C10 8.09 0.19 -0.69
D1 96.79 -0.66 1.99
D2 84.00 -1.70 -8.37
D3 85.48 15.15 0.79
D4 84.56 -19.74 -1.13
D5 85.26 13.37 7.95
D6 84.38 -11.97 27.16
D7 62.35 29.94 36.89
D8 64.17 21.34 19.36
D9 50.48 -53.21 12.65
D10 96.57 -0.64 2.00
E1 49.79 0.13 0.66
E2 32.77 19.91 22.33
E3 62.28 37.56 68.87
E4 19.92 25.07 -61.05
E5 96.78 -0.66 2.01
E6 8.07 0.12 -0.93
E7 77.37 20.28 24.27
E8 74.01 29.00 25.80
E9 20.33 -23.98 7.20
E10 49.72 0.14 0.71
F1 8.09 0.19 -0.69
F2 63.88 20.34 19.93
F3 35.28 12.93 -51.17
F4 52.75 -44.12 38.68
F5 79.65 -0.08 0.62
F6 30.32 -0.10 0.22
F7 63.46 13.53 26.37
F8 64.44 14.31 17.63
F9 60.05 -44.00 7.27
F10 8.08 0.18 -0.78
G1 96.70 -0.66 1.97
G2 45.84 -3.74 -25.32
G3 47.60 53.66 22.15
G4 36.88 65.72 41.63
G5 65.22 -0.27 0.16
G6 39.55 -0.37 -0.09
G7 44.49 16.06 26.79
G8 64.97 15.89 16.79
G9 60.77 -30.19 40.76
G10 96.71 -0.64 2.01
H1 49.74 0.14 0.68
H2 38.29 -17.44 30.22
H3 20.76 31.66 -28.04
H4 81.43 2.41 88.98
H5 49.71 0.12 0.69
H6 60.04 0.09 0.05
H7 67.60 14.47 17.12
H8 64.75 17.30 18.88
H9 51.26 -50.65 43.80
H10 49.76 0.14 0.71
I1 8.10 0.19 -0.93
I2 51.36 9.52 -26.98
I3 71.62 -24.77 64.10
I4 48.75 57.24 -14.45
I5 34.85 -0.21 0.73
I6 75.36 0.35 0.26
I7 45.14 26.38 41.24
I8 36.20 16.70 27.06
I9 61.65 -54.33 46.18
I10 7.97 0.14 -0.80
J1 96.69 -0.67 1.95
J2 68.71 -35.41 -1.11
J3 70.39 19.37 79.73
J4 47.42 -30.91 -32.27
J5 15.43 -0.24 -0.25
J6 88.85 -0.59 0.25
J7 64.00 25.09 27.14
J8 66.65 22.21 28.81
J9 62.05 16.45 51.74
J10 96.71 -0.64 2.02
K1 49.72 0.12 0.64
K2 85.68 10.75 18.39
K3 89.35 -16.38 6.41
K4 84.59 5.21 -5.87
K5 83.63 -12.47 -8.89
K6 70.60 -0.24 0.07
K7 45.14 -0.04 0.86
K8 20.33 0.40 -0.21
K9 62.33 -14.54 54.58
K10 49.74 0.14 0.69
L1 8.08 0.13 -0.81
L2 23.03 33.95 8.88
L3 44.35 67.94 50.62
L4 60.91 36.55 4.15
L5 62.20 37.45 18.18
L6 63.33 51.30 81.88
L7 73.74 -11.45 85.07
L8 62.35 1.96 57.52
L9 72.77 -29.09 71.26
L10 8.13 0.15 -0.86
M1 49.71 0.12 0.62
M2 42.52 63.55 11.43
M3 18.09 32.61 -5.90
M4 40.66 65.54 31.98
M5 53.13 68.44 49.57
M6 82.08 23.39 87.24
M7 82.50 5.29 96.68
M8 71.90 -17.32 77.72
M9 21.95 13.41 16.36
M10 49.74 0.12 0.69
N1 96.79 -0.67 1.97
N2 49.78 0.12 0.65
N3 8.23 0.18 -0.82
N4 96.73 -0.67 1.99
N5 49.80 0.11 0.67
N6 8.18 0.15 -0.84
N7 96.73 -0.65 2.01
N8 49.75 0.13 0.67
N9 8.11 0.15 -0.90
N10 96.55 -0.64 2.02
END_DATA
--[[
function lab2rgb source:
https://github.com/antimatter15/rgb-lab/blob/master/color.js
ColorCheckerSG.txt source:
https://www.xrite.com/service-support/new_color_specifications_for_colorchecker_sg_and_classic_charts
http://www.xrite.com/-/media/XRite/Files/Literature/Misc/C/ColorCheckerSG_After_Nov2014.zip
/*
* The data in this file is reported in CIE L* a* b* data for illuminant D50 and
* 2 degree observer and is being supplied by X-Rite, Inc. This information can
* be used for personal and educational but not for commercial purposes without
* license from X-rite, Inc.
*/
--]]
local datafile = arg[1] or "ColorCheckerSG_After_Nov2014.txt"
local function xy2coord(xy)
local x = xy:sub(1,1):byte() - 64
local y = tonumber(xy:sub(2))
return x, y
end
local function lab2rgb(ll, la, lb)
local y = (ll + 16) / 116
local x = la / 500 + y
local z = y - lb / 200
local x3, y3, z3 = x^3, y^3, z^3
x = 0.95047 * ((x3 > 0.008856) and x3 or (x - 16/116) / 7.787);
y = 1.00000 * ((y3 > 0.008856) and y3 or (y - 16/116) / 7.787);
z = 1.08883 * ((z3 > 0.008856) and z3 or (z - 16/116) / 7.787);
local r = x * 3.2406 + y * -1.5372 + z * -0.4986;
local g = x * -0.9689 + y * 1.8758 + z * 0.0415;
local b = x * 0.0557 + y * -0.2040 + z * 1.0570;
r = (r > 0.0031308) and (1.055 * math.pow(r, 1/2.4) - 0.055) or 12.92 * r;
g = (g > 0.0031308) and (1.055 * math.pow(g, 1/2.4) - 0.055) or 12.92 * g;
b = (b > 0.0031308) and (1.055 * math.pow(b, 1/2.4) - 0.055) or 12.92 * b;
r = math.max(0, math.min(1, r)) * 255
g = math.max(0, math.min(1, g)) * 255
b = math.max(0, math.min(1, b)) * 255
return string.format("%02x%02x%02x", r//1, g//1, b//1)
end
local function get_data(fn)
local c = {}
local r = io.open(fn, "r")
local line
while true do
line = r:read("l")
if "BEGIN_DATA" == line or not line then break end
end
while true do
line = r:read("l")
if "END_DATA" == line or not line then break end
local xy, l, a, b = line:match("([%u][%d]+)\t([%d%.%-]+)\t([%d%.%-]+)\t([%d%.%-]+)")
local x, y = xy2coord(xy)
if not c[y] then c[y] = {} end
c[y][x] = lab2rgb(l, a, b)
end
r:close()
return c
end
local function save_svg(fn, c)
local fmt_g = "<g id='%s%2d' transform='translate(%3d, %3d)'>"
local fmt_p = "<path fill='#%s' d='M 0,0 V 40 H 40 V 0 Z'/>"
local w = io.open(fn, "w+b")
w:write("<svg version='1.1' viewBox='0 0 665 477' xmlns='http://www.w3.org/2000/svg'>\n")
w:write("<path fill='#363636' d='M 0,0 V 477 H 665 V 0 Z' />\n")
w:write("<g stroke='none' transform='translate(-40, -40)'>\n")
for x = 1, 14 do
for y = 1, 10 do
w:write(fmt_g:format(string.char(x+64), y, x*47, y*47))
w:write(fmt_p:format(c[y][x]))
w:write("</g>\n")
end
end
w:write("</g>\n")
w:write("</svg>\n")
end
save_svg(datafile:gsub(".txt", ".svg"), get_data(datafile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment