-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmrl-image-view
executable file
·121 lines (100 loc) · 2.4 KB
/
mrl-image-view
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
#!/usr/bin/env luajit
local Mrg = require('mrg')
local S = require('syscall')
local mrg = Mrg.new(-1, -1);
local path = '/home/pippin/pippin.jpg'
if (#arg >= 1) then
path = arg[1]
end
function get_path(path)
local t = {}
local newp = '';
for str in string.gmatch(path, "([^/]+)") do
t[#t+1] = str
end
for i = 1,#t-1 do
newp = newp .. '/' .. t[i]
end
if newp == '' then newp = '/' end
return newp
end
function get_basename(path)
local t = {}
local last = ''
for str in string.gmatch(path, "([^/]+)") do
t[#t+1] = str
last=str
end
return last
end
function get_thumb_path(path)
return get_path(path) .. '/.thumb/' .. get_basename(path)
end
local thumb_path = get_thumb_path(path)
local initialized = false
local thumb_done = false
mrg:set_ui(
function (mrg, data)
if (initialized == false) then
local stt = S.stat(get_thumb_path(path))
if stt and stt.isreg then
path = thumb_path
thumb_done = true
print 'bbbbbb'
end
initialized = true;
end
local cr = mrg:cr()
local em = mrg:em()
local w, h;
local cr = mrg:cr()
local scale = 1.0;
local dw, dh;
cr:set_source_rgb(0,0,0)
cr:paint()
w, h = mrg:image_size(path)
scale = (mrg:width ()) / w
dw, dh = w * scale, h * scale
if dw > mrg:width() then
scale = mrg:width () / w
dw, dh = w * scale, h * scale
end
if dh > mrg:height() then
scale = mrg:height() / h
dw, dh = w * scale, h * scale
end
cr:save()
cr:translate((mrg:width() - dw)/2,
((mrg:height() - dh)/2))
mrg:image(0, 0, dw, dh, path)
cr:restore()
if (thumb_done== false) then
-- this writes a display sized preview image - but
-- only for images bigger than display size
--
-- with resizing, this cache gets size polluted
if mrg:width () < w then
os.execute('mkdir ' .. get_path(path) .. '/.thumb ') --2> /dev/null' )
cr:get_target():write_to_png(thumb_path)
print 'wwww'
thumb_done=true
end
end
mrg:add_binding("control-q", NULL, NULL,
function ()
mrg:quit()
end)
mrg:add_binding("down", NULL, NULL,
function ()
mrg:message('next')
mrg:add_timeout(0,mrg:queue_draw(nil))
end)
mrg:add_binding("up", NULL, NULL,
function ()
--mrg:message('previous')
mrg:message('fnord')
mrg:add_timeout(0,mrg:queue_draw(nil))
end)
end)
mrg:set_title(path)
mrg:main()