src/Visualise.jl

changeset 34
fe9ef03a91b2
parent 27
51bb83c404a4
child 54
471f9f64ff2d
child 60
dcfc38ade15b
equal deleted inserted replaced
33:b351c5c65450 34:fe9ef03a91b2
76 grayGR = x -> begin 76 grayGR = x -> begin
77 y = round(UInt32, 0xff*clip(x)) 77 y = round(UInt32, 0xff*clip(x))
78 return 0x010101*y + 0xff000000 78 return 0x010101*y + 0xff000000
79 end 79 end
80 80
81 function do_visualise(imgs; refresh=true) 81 function fill_viewport(vp, c)
82 GR.savestate()
83 GR.selntran(0)
84 GR.setscale(0)
85 GR.setfillintstyle(GR.INTSTYLE_SOLID)
86 GR.setfillcolorind(c)
87 GR.fillrect(vp...)
88 GR.selntran(1)
89 GR.restorestate()
90 end
91
92 function do_visualise(imgs; refresh=true, fullscreen=false)
82 n = length(imgs) 93 n = length(imgs)
83 # Get device dimensions in metres and pixels 94 # Get device dimensions in metres and pixels
84 scrw, scrh, pw, ph = GR.inqdspsize() 95 scrw, scrh, pw, ph = GR.inqdspsize()
85 aspect = n > 0 ? Float64(size(imgs[1], 1))/Float64(size(imgs[1], 2)) : 1 96 imgaspect = n > 0 ? float(size(imgs[1], 1))/float(size(imgs[1], 2)) : 1
86 # Scaling to maximums ize window 97 # Scaling to maximum size window
87 sc=0.7 98 sc=0.7
88 # Set up window and transformations 99 # Set up window and transformations
89 GR.clearws() 100 GR.clearws()
90 GR.setscale(0); 101 GR.setscale(0);
91 GR.selntran(1) 102 GR.selntran(1)
92 # - First OS window size 103 # - First OS window size
93 if scrw/n>scrh 104 if fullscreen
94 GR.setwsviewport(0, sc*scrh*n, 0, sc*scrh*aspect) 105 w, h = float(scrw), float(scrh)
95 else 106 elseif scrw/n>scrh
96 GR.setwsviewport(0, sc*scrw, 0, sc*scrw/n*aspect) 107 w, h = float(sc*scrh*n), float(sc*scrh*imgaspect)
97 end 108 else
98 # - Part of normalised window shown 109 w, h = float(sc*scrw), float(sc*scrw/n*imgaspect)
99 GR.setwswindow(0, 1, 0, 1/n*aspect); 110 end
100 GR.setviewport(0, 1, 0, 1/n*aspect); 111 GR.setwsviewport(0, w, 0, h)
101 # World coordinates 112 # NDC to device
102 GR.setwindow(0, n, 0, aspect) 113 if w>h
114 canvas=[0, 1, 0, h/w]
115 else
116 canvas=[0, w/h, 0, 1]
117 end
118 GR.setwswindow(canvas...)
119 fill_viewport(canvas, 1)
120 # World coordinates to NDC
121 if imgaspect/n<h/w
122 y0 = (canvas[3]+canvas[4])/2
123 ww = (canvas[2]-canvas[1])/2
124 y1 = y0-ww*(imgaspect/n)
125 y2 = y0+ww*(imgaspect/n)
126 GR.setviewport(canvas[1], canvas[2], y1, y2)
127 else
128 x0 = (canvas[1]+canvas[2])/2
129 hh = (canvas[4]-canvas[3])/2
130 x1 = x0-hh*(n/imgaspect)
131 x2 = x0+hh*(n/imgaspect)
132 GR.setviewport(x1, x2, canvas[3], canvas[4])
133 end
134 GR.setwindow(0, n, 0, 1)
135 # Clear background
103 # Plot images 136 # Plot images
104 for i=1:n 137 for i=1:n
105 im = imgs[i]' 138 im = imgs[i]'
106 sz = size(im) 139 sz = size(im)
107 GR.drawimage(i-1, i, 0, aspect, sz[1], sz[2], grayGR.(im)) 140 GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im))
108 end 141 end
109 if refresh 142 if refresh
110 GR.updatews() 143 GR.updatews()
111 end 144 end
112 end 145 end

mercurial