File: test_tv.pro

package info (click to toggle)
gnudatalanguage 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,368 kB
  • sloc: cpp: 189,797; ansic: 46,721; sh: 677; python: 474; makefile: 146; xml: 69; f90: 28
file content (312 lines) | stat: -rw-r--r-- 7,338 bytes parent folder | download | duplicates (3)
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
;
; Alain C. 24/Feb/2009
; fast way to check whether TV works in all cases of permutation in [1,N,M]
;
; Modifications history :
;
; * AC 2016-03-03 : merging TEST_TV_DAMIER and TEST_TV_DAMIER_COLOR,
; adding tic/toc to check X11 bottleneck(s) on network (remote TV/plot
; are too slow)
; * AC 2017-08-17 : details when files missing, errors count, banner ...
; * AC 2018-01-09 : clarifying details, should extendable easily for bench
; * AC 2018-10-24 : should work now with X11, Win & Mac ...
;
function TITLE4TEST_TV, data, debug=debug
;
if KEYWORD_SET(debug) then print, 'Size: ', SIZE(data)
;
sep=','
if ((SIZE(data))(0) EQ 2) then begin
   x=(SIZE(data))(1)
   y=(SIZE(data))(2)
   return, STRCOMPRESS('['+STRING(x)+sep+STRING(y)+']')
endif
if ((SIZE(data))(0) EQ 3) then begin
   x=(SIZE(data))(1)
   y=(SIZE(data))(2)
   z=(SIZE(data))(3)
   sep=','
   return, STRCOMPRESS('['+STRING(x)+sep+STRING(y)+sep+STRING(z)+']')
endif
print, 'Fatal: we should never be here !'
STOP
end
; -------------------------------------
;
pro MY_WINDOW, indice, data
;
tmp_data=REFORM(data)
xdim=(SIZE(tmp_data))(1)
ydim=(SIZE(tmp_data))(2)
;
;print, xdim, ydim
yoffset=50+indice*(ydim+20)
xoffset=10
;
WINDOW, indice, title=STRING(indice)+' '+TITLE4TEST_TV(data), $
        xpos=xoffset, ypos=yoffset, xsize=xdim, ysize=ydim
TVSCL, data
;
end
;
; -------------------------------------
; We need to test that when changing the color table,
; this table will be propagated in other windows 
; when they will be active via WSET
;
pro TEST_TV_WSET, cumul_errors, test=test
;
; Read "Saturn.jpg" and return content in "image"
status=GET_IMAGE_FOR_TESTSUITE(image)
if (status eq 0) then begin
   ERRORS_CUMUL, cumul_errors, 0
   return
endif
;
xdim=(SIZE(image))(2)
ydim=(SIZE(image))(3)
; this test, as it is now, is wrong when the screen is too small (use
; Xvfb :1 -screen 0 1024x768x24 & for example)
; I return if window sizes are too big
DEVICE, get_screen_size=scrsize
scrsizex=scrsize[0]
scrsizey=scrsize[1]

if (2*xdim ge scrsizex or 3*ydim ge scrsizey) then begin
   print,"test TEST_TV_WSET not executed, screen size to small (FIXME)"
   return
end
;
image=TOTAL(image,1)
;
DEVICE, decomposed=0
;
LOADCT, 13
;
WINDOW, 0, xsize=xdim, ysize=3*ydim
WINDOW, 2, xsize=xdim, ysize=3*ydim
;
WSET, 0
;
TV, image, 0
LOADCT, 20
TV, image, 1
LOADCT, 30
TV, image, 2
;
; switching to window 2
WSET, 2
TV, image, 2
LOADCT, 20
TV, image, 1
LOADCT, 13
TV, image, 0
;
; reading contents of the 2 windows : should have the same
;
    local_error=0
if !version.os_family ne 'Windows' then begin
    content_win2=TVRD()
    ;
    WSET, 0
    content_win0=TVRD()
    ;
    if ~ARRAY_EQUAL(content_win0,content_win2) then local_error++
endif else $
  message,/continue,' TVRD() bypassed for windows machines'
;
ERRORS_CUMUL, cumul_errors, local_error
;
BANNER_FOR_TESTSUITE, "TEST_TV_WSET", local_error, /SHORT
;
if KEYWORD_SET(test) then STOP
;
end
;
; -------------------------------------
;
pro TEST_TV_DAMIER, numwin, color=color, benchmark=benchmark, $
                    nb_cells_max=nb_cells_max, silent=silent, $
                    test=test, debug=debug, help=help
;
if KEYWORD_SET(help) then begin
    print, 'pro TEST_TV_DAMIER, numwin, color=color, benchmark=benchmark, $'
    print, '                    nb_cells_max=nb_cells_max, silent=silent, $'
    print, '                    test=test, debug=debug, help=help'
    print, ''
    print, 'Three levels of time benchmarking : 0 no, =1 global, =2 detail'
    return
end
;
if ~ISA(silent) then silent=1
;
; AC 2016-04-14 : seems not to be useful
; AC 2017-01-11 : useful now ! better support of DEVICE, decomposed=0|1
if KEYWORD_SET(color) then DEVICE, decomposed=0
;
; Three levels of time benchmarking : 0 non, 1 global, 2 detail
;
if KEYWORD_SET(benchmark) then begin
    t_glob=TIC('global')
endif else begin
    benchmark=0
endelse
;
if N_PARAMS() EQ 0 then numwin=0
;
units=64
nbx=10
nby=8
WINDOW, numwin, xsi=units*nbx, ysi=units*nby
;
; AC 2016-04-14 useful to have W&B reproducible !
LOADCT, 0
;
vignette=DIST(units)
;
offset_line=0
nb_cells=nbx*nby
if KEYWORD_SET(nb_cells_max) then begin
    if (nb_cells_max GT 0) AND (nb_cells_max LT nb_cells/2) then begin
        nb_cells=nb_cells_max*2
    endif
endif
;
for ii=0, (nb_cells/2-1)  do begin
    offset_line=(ii / (nbx/2)) mod 2
    if KEYWORD_SET(debug) then print, ii, offset_line, 2*ii+offset_line
    ;;
    ;; loading here color table if needed
    if KEYWORD_SET(color) then begin
        if (benchmark GT 1) then begin
            print, 'Before loading Color Table '
            TIC
        endif
        LOADCT, ii, silent=silent
        if (benchmark GT 1) then TOC
    endif
    ;;
    if (benchmark GT 1) then begin
        print, 'Before TVSCL'
        TIC
    endif
    TVSCL, vignette, 2*ii+offset_line
    if (benchmark GT 1) then TOC
endfor
;
if KEYWORD_SET(benchmark) then TOC, t_glob
;
BANNER_FOR_TESTSUITE, "TEST_TV_DAMIER", 0, /SHORT
;
if KEYWORD_SET(test) then STOP
;;
end 
;
; -------------------------------------
;
pro TEST_TV_OVER_BOX
;
; Read "Saturn.jpg" and return content in "image"
status=GET_IMAGE_FOR_TESTSUITE(image)
if (status eq 0) then return
;
redChannel = REFORM(image[0, *, *])
greenChannel = REFORM(image[1, *, *])
blueChannel = REFORM(image[2, *, *])
;
aa=FINDGEN(32)
WINDOW,11
LOADCT,13
;
plot,aa,back=88
tv, redChannel,0,CHAN=1
tv, redChannel,0,0,/DATA,CHAN=1
tv, greenChannel,0,CHAN=2
tv, greenChannel,10,10,/DATA,CHAN=2
tv, blueChannel,0,CHAN=3
tv, blueChannel,20,20,/DATA,CHAN=3
WINDOW,12
!P.MULTI=[0,3,2]
for i=0,5 do begin
    plot,aa
    TV, image, 10,10,/DATA,/true,xsize=50
end
!P.MULTI=0
;
BANNER_FOR_TESTSUITE, "TEST_TV_OVER_BOX", 0, /SHORT
;
end
;
; -------------------------------------
; should display (from bottom on the left) 6 small windows in grey
;
pro TEST_TV_REFORM
;
DEVICE, decomposed=0
;
xdim=350
ydim=100
;
yoffset=FINDGEN(7)*ydim
xoffset=REPLICATE(0,7)
;
a=DIST(xdim, ydim)
b1=REFORM(a,1, xdim, ydim)
b2=REFORM(a,xdim, 1, ydim)
b3=REFORM(a,xdim, ydim, 1)
;

icolor=0 & loadct,icolor,/silent 
MY_WINDOW, 0, a  & loadct,++icolor,/silent 
MY_WINDOW, 1, b1 & loadct,++icolor,/silent 
MY_WINDOW, 2, REFORM(b1) & loadct,++icolor,/silent 
MY_WINDOW, 3, b2 & loadct,++icolor,/silent 
MY_WINDOW, 4, REFORM(b2) & loadct,++icolor,/silent 
MY_WINDOW, 5, b3 & loadct,++icolor,/silent 
MY_WINDOW, 6, REFORM(b3) 
loadct,0,/silent 
device,decomposed=1
;
BANNER_FOR_TESTSUITE, "TEST_TV_REFORM", 0, /SHORT
;
end
;
; -------------------------------------
;
pro TEST_TV, help=help, test=test, no_exit=no_exit
;
if KEYWORD_SET(help) then begin
    print, 'pro TEST_TV, help=help, test=test, no_exit=no_exit'
    return
endif
;
rname=ROUTINE_NAME()
;
if ~CHECK_IF_DEVICE_IS_OK(rname, /force) then begin
   if ~KEYWORD_SET(no_exit) then EXIT, status=77 else STOP
endif
;
TEST_TV_REFORM
;
TEST_TV_DAMIER, 8
TEST_TV_DAMIER, 9, /COLOR
;
TEST_TV_OVER_BOX
;
; only this test gives a feedback now
errors=0
if !version.os_family ne 'Windows' then TEST_TV_WSET, errors
;
;stop
if ~KEYWORD_SET(no_exit) then while !d.window GE 0 do WDELETE
print, 'You can use keyword /No_Exit to de-activate auto closing'
;
; ----------------- final message ----------
;
BANNER_FOR_TESTSUITE, 'TEST_TV', errors
;
if (errors GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
;
if KEYWORD_SET(test) then STOP
;
end