-
Notifications
You must be signed in to change notification settings - Fork 18
/
vpvrc
427 lines (389 loc) · 14.2 KB
/
vpvrc
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
SCALE = 1
WATCH = false
PRELOAD = true
CACHE_LIMIT = '2GB'
SCREENSHOT = 'screenshot_%d.png'
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 720
SHOW_HUD = true
SHOW_SVG = true
SHOW_MENUBAR = true
SHOW_WINDOWBAR = true
SHOW_HISTOGRAM = false
SHOW_MINIVIEW = true
WINDOW_BORDER = 1
DEFAULT_LAYOUT = "grid"
SATURATIONS = {0.001, 0.01, 0.1}
DEFAULT_FRAMERATE = 30.0
-- downsampling quality:
-- 0: nearest neighbor
-- 1: linear
-- 2: multiscale nearest neighbor
-- 3: multiscale linear neighbor
DOWNSAMPLING_QUALITY = 1
SMOOTH_HISTOGRAM = false
SHADERS = {}
do
scalemap = [[
uniform vec3 scale;
uniform vec3 bias;
float scalemap(float p) {
return clamp(p * scale.x + bias.x, 0.0, 1.0);
}
vec2 scalemap(vec2 p) {
return clamp(p * scale.xy + bias.xy, 0.0, 1.0);
}
vec3 scalemap(vec3 p) {
return clamp(p * scale.xyz + bias.xyz, 0.0, 1.0);
}
]]
defaultmain = [[
uniform sampler2D tex;
in vec2 f_texcoord;
out vec4 out_color;
void main()
{
vec4 p = texture(tex, f_texcoord.st);
out_color = vec4(tonemap(scalemap(p.rgb)), 1.0);
}
]]
SHADERS['default'] = scalemap .. [[
vec3 tonemap(vec3 p)
{
return p;
}
]] .. defaultmain
SHADERS['gray'] = scalemap .. [[
vec3 tonemap(vec3 p)
{
return vec3(p.x);
}
]] .. defaultmain
SHADERS['opticalFlow'] = scalemap .. [[
vec3 hsvtorgb(vec3 colo)
{
vec4 outp;
float r, g, b, h, s, v;
r=g=b=h=s=v=0.0;
h = colo.x; s = colo.y; v = colo.z;
if (s == 0.0) { r = g = b = v; }
else {
float H = mod(floor(h/60.0) , 6.0);
float p, q, t, f = h/60.0 - H;
p = v * (1.0 - s);
q = v * (1.0 - f*s);
t = v * (1.0 - (1.0 - f)*s);
if(H == 6.0 || H == 0.0) { r = v; g = t; b = p; }
else if(H == -1.0 || H == 5.0) { r = v; g = p; b = q; }
else if(H == 1.0) { r = q; g = v; b = p; }
else if(H == 2.0) { r = p; g = v; b = t; }
else if(H == 3.0) { r = p; g = q; b = v; }
else if(H == 4.0) { r = t; g = p; b = v; }
}
return vec3(r, g, b);
}
float M_PI = 3.1415926535897932;
float M_PI_2 = 1.5707963267948966;
float atan2(float x, float y)
{
if (x>0.0) { return atan(y/x); }
else if(x<0.0 && y>0.0) { return atan(y/x) + M_PI; }
else if(x<0.0 && y<=0.0 ) { return atan(y/x) - M_PI; }
else if(x==0.0 && y>0.0 ) { return M_PI_2; }
else if(x==0.0 && y<0.0 ) { return -M_PI_2; }
return 0.0;
}
// from https://github.com/gfacciol/pvflip
vec3 tonemap(vec3 p)
{
float a = (180.0/M_PI)*(atan2(-p.x, p.y) + M_PI);
float r = sqrt(p.x*p.x+p.y*p.y) * scale.x;
r = clamp(r,0.0,1.0);
vec3 q = vec3(a, r, r);
return hsvtorgb(q);
}
uniform sampler2D tex;
in vec2 f_texcoord;
in vec4 f_color;
out vec4 out_color;
void main()
{
vec4 p = texture(tex, f_texcoord.st);
out_color = f_color * vec4(tonemap(p.rgb), 1.0);
}
]]
SHADERS['jet'] = scalemap .. [[
vec3 tonemap(vec3 q)
{
float d = q.x;
if(d < 0.0) d = -0.05;
if(d > 1.0) d = 1.05;
d = d/1.15 + 0.1;
vec3 p;
p.x = 1.5 - abs(d - .75)*4.0;
p.y = 1.5 - abs(d - .50)*4.0;
p.z = 1.5 - abs(d - .25)*4.0;
return p;
}
]] .. defaultmain
end
LAYOUTS = {}
CURRENT_LAYOUT = 'grid'
CUSTOM_LAYOUT = {}
do
local function valid_layouts()
local ls = {}
for _, l in ipairs(LAYOUTS) do
if not l.disabled or not l:disabled() then
table.insert(ls, l)
end
end
return ls
end
function next_layout()
local valids = valid_layouts()
local prev = valids[#valids]
for i, l in ipairs(valids) do
if CURRENT_LAYOUT == prev.name then
CURRENT_LAYOUT = l.name
break
end
prev = l
end
if not CURRENT_LAYOUT then
CURRENT_LAYOUT = valids[1].name
end
print("current layout: ", CURRENT_LAYOUT)
end
function previous_layout()
local valids = valid_layouts()
local prev = valids[#valids]
for i, l in ipairs(valids) do
if CURRENT_LAYOUT == l.name then
CURRENT_LAYOUT = prev.name
break
end
prev = l
end
if not CURRENT_LAYOUT then
CURRENT_LAYOUT = valids[1].name
end
print("current layout: ", CURRENT_LAYOUT)
end
local function steplayout(windows, area, step)
local individual_size
if step.x ~= 0 then
individual_size = ImVec2(step.x, area:get_height())
elseif step.y ~= 0 then
individual_size = ImVec2(area:get_width(), step.y)
else
individual_size = area:get_size()
end
local cursor = area.min
for _, w in ipairs(windows) do
w.position = cursor
w.size = individual_size
w.force_geometry = true
cursor = cursor + step
end
end
table.insert(LAYOUTS, {name='grid', fn=function(windows, area)
local num = #windows
local n = math.floor(0.5+math.sqrt(num))
local _start = area.min
local _size = area:get_size()
_size.y = math.floor(_size.y / n)
local step = ImVec2(0, _size.y)
local index = 1
for i = 1, n do
local endindex = index + math.floor(num / n) - 1
if i == n then
endindex = num
end
local wins = {}
for j = index, endindex do table.insert(wins, windows[j]) end
local _step = ImVec2(math.floor(_size.x / #wins), 0)
steplayout(wins, ImRect(_start, _start + _size), _step)
_start = _start + step
index = endindex + 1
end
end})
table.insert(LAYOUTS, {name='fullscreen', fn=function(windows, area)
steplayout(windows, area, ImVec2(0, 0))
end})
table.insert(LAYOUTS, {name='horizontal', fn=function(windows, area)
local step = ImVec2(math.floor(area:get_width() / #windows), 0)
steplayout(windows, area, step)
end})
table.insert(LAYOUTS, {name='vertical', fn=function(windows, area)
local step = ImVec2(0, math.floor(area:get_height() / #windows))
steplayout(windows, area, step)
end})
table.insert(LAYOUTS, {name='custom', disabled=function() return not CUSTOM_LAYOUT[1] end, fn=function(windows, area)
-- replace -1 with valid values
local layout = {table.unpack(CUSTOM_LAYOUT)}
-- first value is the orientation (1=vertical, 0=horizontal)
local vertical = table.remove(layout, 1) == 1
local sum = 0
local negatives = 0
local last_neg = 0
for i = 1, #layout do
sum = sum + math.max(0, layout[i])
negatives = negatives + (layout[i] < 0 and 1 or 0)
last_neg = layout[i] < 0 and i or last_neg
end
if negatives > 0 then
local splitted = math.floor(math.max(0, #windows - sum) / negatives)
local rem = math.max(0, #windows - sum) % negatives
for i = 1, #layout do
if layout[i] < 0 then
layout[i] = splitted + (last_neg == i and rem or 0)
end
end
end
local n = #layout
local index = 1
local _start = area.min
local _size = area:get_size()
local step
if vertical then
_size.y = math.floor(_size.y / n)
step = ImVec2(0, _size.y)
else
_size.x = math.floor(_size.x / n)
step = ImVec2(_size.x, 0)
end
for i = 1, n do
local endindex = index + layout[i] - 1
endindex = math.min(endindex, #windows);
local wins = {}
for j = index, endindex do table.insert(wins, windows[j]) end
if #wins == 0 then
break;
end
if vertical then
local _step = ImVec2(math.floor(_size.x / #wins), 0)
steplayout(wins, ImRect(_start, _start + _size), _step)
else
local _step = ImVec2(0, math.floor(_size.y / #wins))
steplayout(wins, ImRect(_start, _start + _size), _step)
end
_start = _start + step
index = endindex + 1
end
for i = index, #windows do
windows[i].opened = false
end
end})
function relayout(windows, area)
local opened = {}
for _, w in ipairs(windows) do
if w.opened and not w.dont_layout then
table.insert(opened, w)
end
end
if #opened == 0 then return end
for _, l in ipairs(LAYOUTS) do
if l.name == CURRENT_LAYOUT then
l.fn(opened, area)
break
end
end
end
end
local function systemram()
-- only works for linux
meminfo = io.open('/proc/meminfo', 'r'):read('*a')
if meminfo then
local k = 0
meminfo:gsub('MemFree:%s*([0-9]+) kB', function(x) k = tonumber(x)/1000 end)
return k
end
return -1
end
function toMB(str)
local cache, done = 0, 0
if done == 0 then
cache, done = str:gsub('([0-9%.]+)GB', function(x) return tonumber(x)*1000 end)
end
if done == 0 then
cache, done = str:gsub('([0-9%.]+)MB', function(x) return tonumber(x) end)
end
if done == 0 then
cache, done = str:gsub('([0-9%.]+)KB', function(x) return tonumber(x)/1000 end)
end
if done == 0 then
cache, done = str:gsub('([0-9%.]+)%%', function(x) return tonumber(x)/100*systemram() end)
end
return cache
end
function setup_theme()
local style = ImGuiStyle()
-- light style from Pacôme Danhiez (user itamago) https://github.com/ocornut/imgui/pull/511#issuecomment-175719267
style.Alpha = 1.0;
style.FrameRounding = 3.0;
style.WindowRounding = 1.;
local Colors = style.Colors
Colors[ImGuiCol_Text] = ImVec4(0.00, 0.00, 0.00, 1.00);
Colors[ImGuiCol_TextDisabled] = ImVec4(0.60, 0.60, 0.60, 1.00);
Colors[ImGuiCol_WindowBg] = ImVec4(0.94, 0.94, 0.94, 0.94);
Colors[ImGuiCol_ChildBg] = ImVec4(0.00, 0.00, 0.00, 0.00);
Colors[ImGuiCol_PopupBg] = ImVec4(1.00, 1.00, 1.00, 0.94);
Colors[ImGuiCol_Border] = ImVec4(0.00, 0.00, 0.00, 0.39);
Colors[ImGuiCol_BorderShadow] = ImVec4(1.00, 1.00, 1.00, 0.10);
Colors[ImGuiCol_FrameBg] = ImVec4(1.00, 1.00, 1.00, 0.94);
Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26, 0.59, 0.98, 0.40);
Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26, 0.59, 0.98, 0.67);
Colors[ImGuiCol_TitleBg] = ImVec4(0.96, 0.96, 0.96, 1.00);
Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00, 1.00, 1.00, 0.51);
Colors[ImGuiCol_TitleBgActive] = ImVec4(0.56, 0.73, 0.98, 1.00);
Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86, 0.86, 0.86, 1.00);
Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98, 0.98, 0.98, 0.53);
Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69, 0.69, 0.69, 1.00);
Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.59, 0.59, 0.59, 1.00);
Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49, 0.49, 0.49, 1.00);
Colors[ImGuiCol_CheckMark] = ImVec4(0.26, 0.59, 0.98, 1.00);
Colors[ImGuiCol_SliderGrab] = ImVec4(0.24, 0.52, 0.88, 1.00);
Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26, 0.59, 0.98, 1.00);
Colors[ImGuiCol_Button] = ImVec4(0.26, 0.59, 0.98, 0.40);
Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26, 0.59, 0.98, 1.00);
Colors[ImGuiCol_ButtonActive] = ImVec4(0.06, 0.53, 0.98, 1.00);
Colors[ImGuiCol_Header] = ImVec4(0.26, 0.59, 0.98, 0.31);
Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26, 0.59, 0.98, 0.80);
Colors[ImGuiCol_HeaderActive] = ImVec4(0.26, 0.59, 0.98, 1.00);
Colors[ImGuiCol_Separator] = ImVec4(0.39, 0.39, 0.39, 1.00);
Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.26, 0.59, 0.98, 0.78);
Colors[ImGuiCol_SeparatorActive] = ImVec4(0.26, 0.59, 0.98, 1.00);
Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00, 1.00, 1.00, 0.50);
Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26, 0.59, 0.98, 0.67);
Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26, 0.59, 0.98, 0.95);
Colors[ImGuiCol_PlotLines] = ImVec4(0.39, 0.39, 0.39, 1.00);
Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00);
Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00);
Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00);
Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26, 0.59, 0.98, 0.35);
Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20, 0.20, 0.20, 0.35);
style.Colors = Colors
return style
end
function load_user_config()
local function loadfile_if_exists(filename)
local f = io.open(filename, 'r')
if f then
local buf = f:read('*a')
assert(load(buf, filename))()
end
end
if os.getenv('HOME') then
loadfile_if_exists(os.getenv('HOME') .. '/.vpvrc')
end
loadfile_if_exists('.vpvrc')
end
load_user_config()
-- for compatibility.. remove me one day
if os.getenv('SCALE') then SCALE = tonumber(os.getenv('SCALE')) end
if os.getenv('WATCH') then WATCH = tonumber(os.getenv('WATCH')) end
if WATCH == 0 then WATCH = false end
-- deprecated options
if SATURATION then print('SATURATION has been removed, please use SATURATIONS from now.') end
-- vim: set ft=lua: