-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
252 lines (211 loc) · 6.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Gamma lookup table generator</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script type="text/javascript" src="//code.jquery.com/jquery-2.0.2.js"></script>
<script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<style type="text/css">
.panel-heading a:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
}
.panel-heading a.collapsed:after {
content: "\e080";
}
.input-group-addon.email {
width: auto;
}
</style>
</head>
<body>
<div class="container">
<h2>Gamma lookup table generator</h2>
<br>
<form class="form-horizontal">
<div class="form-group">
<label for="gamma" class="col-sm-2 control-label">Gamma</label>
<div class="col-sm-10">
<input id="gamma" type="text" class="form-control" placeholder="" value="2.0">
<div>
Gamma correction value (recommend between 1.5 - 3.0)
</div>
</div>
</div>
<div class="form-group">
<label for="steps" class="col-sm-2 control-label">Steps</label>
<div class="col-sm-10">
<input id="steps" type="text" class="form-control" placeholder="" value="256">
<div>
This will be the size of your array
</div>
</div>
</div>
<div class="form-group">
<label for="maxValue" class="col-sm-2 control-label">Max Value</label>
<div class="col-sm-10">
<input id="maxValue" type="text" class="form-control" placeholder="" value="1023">
<div>
Maximum PWM value. (8-bit = 255, 10-bit = 1023)
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" onclick="generate()"> Generate </button>
</div>
</div>
</form>
<hr>
<div id="chart"></div>
<br>
<h4>C++ Snippet</h4>
<pre id="output" class="well">
<div class="text-muted text-center small">
Click generate
</div>
</pre>
</div>
<footer>
<div class="footer text-center text-muted small"><a href="http://vitim.us" target="_blank">Vitim.us</a> 2019-11-17
</div>
</footer>
<script type="text/javascript">
window.onload = function () {
gamma.oninput = steps.oninput = maxValue.oninput = generate;
//generate();
}
function generateGammaTable(gamma, steps, resolution) {
var arr = new Array(steps).fill(0)
.map((x, i) => Math.pow(i, gamma))
arr = arr.map(x => x / Math.max(...arr))
.map(x => Math.min(resolution, Math.round(x * resolution)));
return arr;
}
function generate() {
var gamma = parseFloat(document.querySelector('#gamma').value);
var steps = parseFloat(document.querySelector('#steps').value);
var maxValue = parseFloat(document.querySelector('#maxValue').value);
var lookupTable = generateGammaTable(gamma, steps, maxValue);
var varName = 'gamma_lut';
var varType = maxValue < 256 ? 'uint8_t' : maxValue < 65535 ? 'uint16_t' : 'uint32_t';
var snippet = (
`// Gamma brightness lookup table <https://victornpb.github.io/gamma-table-generator>
// gamma = ${gamma.toFixed(2)} steps = ${steps} range = 0-${maxValue}
const ${varType} ${varName}[${steps}] = {
${lookupTable.map((x, i) => String(x).padStart(4, ' ') + ((i + 1) % 16 === 0 ? ',\n ' : ',')).join('')}};`);
output.innerText = snippet;
//copy(output);
plotChart(gamma, steps, maxValue, lookupTable);
}
function copy(element) {
var selection = window.getSelection();
var range = document.createRange();
range.setStartBefore(element.firstChild);
range.setEndAfter(element.lastChild);
selection.removeAllRanges();
selection.addRange(range);
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
} catch (err) { }
}
function plotChart(gamma, steps, maxValue, lookupTable) {
Highcharts.chart('chart', {
chart: {
type: 'line',
// scrollablePlotArea: {
// minWidth: 600,
// scrollPositionX: 1
// },
height: 500,
// width: 600,
},
title: {
text: 'Gamma curve'
},
subtitle: {
text: `gamma = ${gamma.toFixed(2)} steps = ${steps} range = 0-${maxValue}`
},
plotOptions: {
line: {
lineWidth: 1,
// states: {
// hover: {
// lineWidth: 1
// }
// },
marker: {
enabled: false
},
}
},
yAxis: {
title: {
enabled: true,
text: 'Corrected value',
},
type: "linear",
tickLength: 2,
tickInterval: 2,
ceiling: maxValue,
softMax: maxValue,
min: 0,
// startOnTick: true,
},
xAxis: {
title: {
enabled: true,
text: 'Input Value',
},
tickLength: 2,
tickInterval: 2,
softMax: steps,
},
tooltip: {
shared: true,
},
series: [
{
name: 'Linear',
type: "line",
step: "left",
data: lookupTable.map((y, i) => i * (maxValue / steps)),
color: '#cccccc'
},
{
name: `Gamma ${gamma}`,
type: "line",
step: "left",
data: lookupTable,
color: '#000088'
},
],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});
}
</script>
</body>
</html>