-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg.pro
2485 lines (2187 loc) · 75.6 KB
/
img.pro
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
FORWARD_FUNCTION REVERSE
function rgbTo16, r, g, b
nRBits = 5
nGBits = 6
nBBits = 5
cr = ishft(ULONG(r), -(8-nRBits))
sr = ishft(cr, (nGBits+nBBits))
cg = ishft(ULONG(g), -(8-nGBits))
sg = ishft(cg, nBBits)
cb = ishft(ULONG(b), -(8-nBBits))
sb = cb
ccomb = sr+sg+sb
return, ccomb
end
PRO calc_16bit,im,wd,ht,image=image,vmax=vmax,vmin=vmin,true=true
; With your original TIFF image data, you can do the following:
sz = size(im)
if sz(0) ne 3 then return
rimg = ULONG(REFORM(im[0,*,*]))
gimg = ULONG(REFORM(im[1,*,*]))
bimg = ULONG(REFORM(im[2,*,*]))
if keyword_set(true) then $
im2 = rimg + (gimg + bimg *256L) * 256L else begin ;24bit
img16 = rgbTo16(rimg,gimg,bimg) ;16bit
im2 = img16
end
help,im2
cmax = max(im2)
cmin = min(im2)
print,cmax,cmin
fmax=.991707
fmin = -.891682
if keyword_set(vmax) then fmax=vmax
if keyword_set(vmin) then fmin=vmin
val = fmin + (fmax-fmin)*(float(im2)-cmin)/(cmax-cmin)
image=val
plot2d,val
END
PRO calc_8bit,im,wd,ht,image=image,vmax=vmax,vmin=vmin
; the im must be obtained from a 8 bit tiff file
;
sz = size(im)
if sz(0) ne 2 then return
im2 = congrid(im,wd,ht)
cmax = max(im2)
cmin = min(im2)
fmax=.991707
fmin = -.891682
if keyword_set(vmax) then fmax=vmax
if keyword_set(vmin) then fmin=vmin
val = fmin + (fmax-fmin)*im2/float(cmax-cmin)
image=val
plot2d,val
END
pro calc_image,wd,ht,image=image,vmax=vmax,vmin=vmin
; this tvrd() screen and try to calculate the image array
; this function only works for the 8 bit color image
; not work for the 16 bit color image
; 16 bit color device
if !d.n_colors gt 256 then begin
im = tvrd(/true)
im2 = color_quan(im,1,r,g,b,get_translation=tr)
print,!d.n_colors
help,r,g,b,im2,im,tr
print,im2
tvlct,r,g,b
val = make_array(wd,ht)
for i=0,wd-1 do begin
for j=0,ht-1 do begin
c = im2(i,j)
cf = r(c) + 256L * (g(c) + 256L * b(c))
val(i,j) = cf
end
end
val = congrid(val,wd,ht)
; 8 bit color device
endif else begin
im = tvrd()
im2 = congrid(im,wd,ht)
val = im2
end
cmax = max(val)
cmin = min(val)
;tvlct,r,g,b,/get
; cval = intarr(cmax+1)
; for i=0,cmax do begin
; cval(i) = rgbTo16(r(i),g(i),b(i))
; end
;help,cval
;index = sort(cval)
;print,index
;print,cval
;print,cval(index)
;cvmin = min(cval)
;cvmax = max(cval)
fmax=.991707
fmin = -.891682
if keyword_set(vmax) then fmax=vmax
if keyword_set(vmin) then fmin=vmin
val = fmin + (fmax-fmin)*(float(val)-cmin)/(cmax-cmin)
image=val
plot2d,val,ncolors=cmax+1
end
PRO obj_cleanup
ot = obj_valid()
if n_elements(ot) gt 0 then begin
for i=0,n_elements(ot)-1 do obj_destroy, ot(i)
end
END
PRO curvePlot,window=window,view=view,curve=curve,legend=legend,data
if n_elements(data) eq 0 then data=sin(findgen(100)/10)
xr = 100
yr = 2
view = obj_new('idlgrview',viewplane_rect=[0,-1,xr,yr])
model = obj_new('idlgrmodel')
plot = obj_new('idlgrplot',data)
window = obj_new('idlgrwindow',COLOR_MODEL=1)
; add curve model
view->add,model
model->add,plot
; add legend model2
legendobj,mylegend
model2 = obj_new('idlgrmodel')
view->add,model2
model2->add,mylegend
model2->translate,10,0,0
window->draw,view
curve = model
legend = model2
; obj_destroy,window
; obj_destroy,view
END
PRO model_translation,oModel,dx,dy,dz
oModel->Translate,dx,dy,dz
oModel->getProperty,transform=newT
print,'newT=',newT
END
PRO model_rotation,oModel,Dangle,Iaxis
axis =[1,0,0] ; x-axis
if Iaxis eq 2 then axis = [0,1,0]
if Iaxis eq 3 then axis = [0,0,1]
oModel->Rotate,axis,Dangle
oModel->getProperty,transform=newT
print,'newT=',newT
END
PRO surfacePlot,data,window=oWin,surface=oSurface,view=oView,model=oModel
if n_elements(data) eq 0 then data = dist(60)
zdata = data
oView = obj_new('idlgrview', eye=6, $
viewplane_rect=[-1,-1,2,2])
oModel = obj_new('idlgrmodel')
oView->add, oModel
oSurface = obj_new('idlgrsurface',zdata, $
shading=0, $
color=[255,255,0])
oModel->add,oSurface
oSurface->getProperty,xrange=xrange,yrange=yrange,zrange=zrange
xs = [-0.5, 1/(xrange[1]-xrange[0])]
ys = [-0.5, 1/(yrange[1]-yrange[0])]
zs = [0, 1/(zrange[1]-zrange[0])]
oSurface->setProperty,xcoord_conv=xs, $
ycoord_conv=ys,zcoord_conv=zs
oModel->Rotate,[1,0,0],-90
oModel->Rotate,[0,1,0],30
oModel->Rotate,[1,0,0],30
oWin = obj_new('idlgrwindow',COLOR_MODEL=1)
oWin->draw,oView
END
PRO updatePos,newpos,plot=plotobj,window=owindow,view=oview
; newpos [x,y,0]
; x,y,z specifies the coordinate of the lower left corner of the plot object
; plotobj : specifies the model (plot object) to be moved
; oview : specifies the view object which contains the omodel
; owindow : specifies the window object to be redraw
;
if obj_valid(owindow) then begin
if n_elements(newpos) eq 2 then newpos=[newpos,0]
ctm = plotobj->getCTM()
opos = ctm(3,*)
dpos = newpos - opos
plotobj->translate,dpos(0),dpos(1),dpos(2)
owindow->draw,oview
endif else begin
str = ['updatePos, [x,y,0], plot=plotobj, window=owin, view=oview', $
'where','plotobj, owin, oview must be defined first']
print,dialog_message(str,/error)
end
END
PRO legendObj,mylegend,strings=strings
itemnamearr = ['Cows', 'Weasels']
if keyword_set(strings) then itemnamearr = strings
mytitle = obj_new('idlgrtext', 'My Legend')
mysymbol = obj_new('idlgrsymbol',4)
mypattern = obj_new('idlgrpattern',1)
mylegend = obj_new('idlgrlegend',itemnamearr,title=mytitle, $
border_gap=0.8, gap=0.5, item_type=[0,1], $
item_object=[mysymbol,mypattern],/show_outline)
END
PRO legendPlot,window=mywindow,legend=mylegend,view=myview,model=mymodel
mywindow = obj_new('idlgrwindow')
myview = obj_new('idlgrview')
mymodel = obj_new('idlgrmodel')
myview->add,mymodel
legendObj,mylegend,strings=['line1','line2','line3']
mymodel->add,mylegend
dims = mylegend->computeDimensions(mywindow)
; print,dims
mymodel->translate,-(dims[0]/2.), -(dims[1]/2.), 0
mywindow->draw,myview
END
PRO imagePlot,window=owin,view=oview,image=oimage
file = filepath('rose.jpg',subdir=['examples','data'])
read_jpeg, file, image
mywindow = obj_new('idlgrwindow',dimensions=[227,149])
myview = obj_new('idlgrview',view=[0,0,227,149])
mymodel = obj_new('idlgrmodel')
myimage = obj_new('idlgrimage',image,interleave=0)
myview->add,mymodel
mymodel->add,myimage
mywindow->draw,myview
owin = mywindow
oview = myview
oimage = myimage
END
PRO colorbarPlot,title=title,dims=dims,left=left,right=right,xypos=xypos
; default place vertical colorbar object at the center of page
; left - place colorbar at left hand side
; right - place colorbar at right hand side
; xypos=[rx,ry] - specify the normalized x,y position of the colorbar
; -1 < rx,ry < 1
mywindow = obj_new('idlgrwindow')
myview = obj_new('idlgrview')
mymodel = obj_new('idlgrmodel')
myview->add,mymodel
titlestr = 'My Colorbar'
if keyword_set(title) then titlestr = title
mytitle = obj_new('idlgrtext',titlestr)
; normalized width and height of bar dimension in xr,yr
barDims = [0.1,0.4]
if keyword_set(dims) then barDims = dims
; get color table
TVLCT,redValues,greenValues,blueValues,/GET
mycolorbar = obj_new('idlgrcolorbar',redValues,greenValues, $
blueValues,TITLE=mytitle,dimensions=barDims, $
/show_axis,/show_outline)
mymodel->add,mycolorbar
barplustextdims = mycolorbar->computeDimensions(mywindow)
; center
xpos = -bardims[0]+barplustextdims[0]/2.
ypos = -bardims[1]+barplustextdims[1]/2.
; right
if keyword_set(right) then begin
xpos = 1.-barplustextdims[0]
ypos = -barplustextdims[1]/2.
end
; legt
if keyword_set(left) then begin
xpos = -.9+barplustextdims[0]
ypos = -barplustextdims[1]/2.
end
if keyword_set(xypos) then begin
xpos = xypos(0)
ypos = xypos(1)
end
mymodel->translate,xpos,ypos, barplustextdims[2]
; mymodel->scale,2,2,2
mywindow->draw,myview
END
PRO image_data_aprox,data,xl,xr,yl,yr,v_max,v_min,width=width,height=height,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,real=real,group=group
; extract 2D image area from the 8bit tiff data
;
im = data(xl:xr-1,yl:yr-1)
sz = size(im)
wd = sz(1)
ht = sz(2)
if keyword_set(width) then wd = width
if keyword_set(height) then ht = height
im2 = congrid(im,wd,ht,/minus_one)
c_max = max(im2)
c_min = min(im2)
dm = c_max-c_min
n_im = v_min + (v_max-v_min)*(im2 - c_min)/dm
if keyword_set(real) then begin
dx = (xmax-xmin)/(wd-1)
dy = (ymax-ymin)/(ht-1)
x = xmin + dx * indgen(wd)
y = ymin + dy * indgen(ht)
colors = max(im)
plot2d,n_im,xarr=x,yarr=y ;,group=group
endif else plot2d,n_im ;,group=group
END
PRO image_read,filename,image=image,ranges=ranges,show=show,red=r,green=g,blue=b,ftype=ftype
; this program can read image data from user specified filename
; it supports tiff, png, jpg, ascii, xdr type files
;
file = 'myfile.tif'
if n_elements(filename) then file = filename
pos = strpos(file,'.',/reverse_search)
if pos gt 0 then ftype = strmid(file,pos+1,strlen(file)-pos)
ftype = strlowcase(ftype)
CASE ftype OF
'txt': begin
idata = read_ascii(file,comment_symbol=';')
nm = tag_names(idata)
if nm(0) eq 'FIELD01' then im2 = transpose(idata.field01)
if nm(0) eq 'FIELD1' then im2 = transpose(idata.field1)
if nm(0) eq 'FIELD001' then im2 = transpose(idata.field001)
loadct, 39
TVLCT,R,G,B,/GET
end
'xdr': begin
catch,error_status
if error_status ne 0 then begin
print,!err_status
goto,closexdr
end
xdr_open,unit,file
xdr_read,unit,im2
xdr_read,unit,ranges
closexdr:
xdr_close,unit
loadct, 39
TVLCT,R,G,B,/GET
end
'tiff': begin
im2 = read_tiff(file,R,G,B)
; if 16 bit tiff file r=0,g=0,b=0 is returned
if n_elements(R) gt 1 then TVLCT,R,G,B
end
'tif': begin
im2 = read_tiff(file,R,G,B)
; if 16 bit tiff file r=0,g=0,b=0 is returned
if n_elements(R) gt 1 then TVLCT,R,G,B
end
'png': begin
ok = QUERY_PNG(file,s)
IF (ok) THEN BEGIN
IF (s.HAS_PALETTE) THEN BEGIN
; READ_PNG,file,im2,R,G,B
im2 =READ_PNG(file,R,G,B)
TVLCT,R,G,B
ENDIF ELSE BEGIN
; READ_PNG,file,im2
im2 = READ_PNG(file)
ENDELSE
ENDIF
end
'jpg': begin
read_jpeg,file,im2
sz = size(im2)
if sz(0) eq 2 then begin
loadct,39
tvlct,r,g,b,/get
end
end
ELSE: begin
print,'File type "',ftype, '" not supported'
return
end
ENDCASE
image = im2
sz = size(im2)
; if sz(0) eq 3 then device,decomposed=1 else device,decomposed=0
if !d.n_colors eq 16777216 then device,decomposed=1 else device,decomposed=0
if keyword_set(show) then begin
if sz(0) eq 3 and sz(1) eq 3 then begin
window,1,xsize=sz(2),ysize=sz(3)
tv,im2,/true
end
if sz(0) eq 2 then begin
window,1,xsize=sz(1),ysize=sz(2)
tvlct,R,G,B
tv,im2
end
end
END
PRO image_write,owindow,wid=wid,image=image,filename=filename,show=show,png=png,jpg=jpg,tif=tif,model=model,reverse=reverse
; true color graphic case
; owindow - is for idlgrwindow object
; wid - is the window id for direct graphic
; im - option output image read from IDL window
; model=1 - color table mode, tvrd return 2 dim array
; tv,image
; model=0 - true color mode, tvrd(ture=1) return 3 dim array
; tv,image,/true
;
TVLCT,R,G,B,/GET
if !d.n_colors le 256 then begin
model=1
endif else model=0
; only true colors works for jpg
if keyword_set(jpg) and model eq 1 then begin
r = dialog_message(['Write JPEG for TVRD only works for true color devices.','You may write as PNG, or TIFF file for this device.'],/info)
return
end
if n_params() eq 0 then begin
; direct graphic
id = !d.window
if keyword_set(wid) then id = wid
wset,id
if keyword_set(model) then image=tvrd() else $
image = tvrd(true=1)
endif else begin
; object graphic
if obj_valid(owindow) then begin
myimage = owindow->read()
myimage->getproperty, data=image
end
end
; help,image,model
; print,max(image),min(image)
sz = size(image)
if keyword_set(show) then begin
if sz(0) eq 3 and sz(1) eq 3 then begin
window,0,xsize=sz(2),ysize=sz(3)
device,decomposed=1
tv,image,/true
device,decomposed=0
end
if sz(0) eq 2 then begin
window,0,xsize=sz(1),ysize=sz(2)
tvlct,R,G,B
tv,image
end
end
; write tif/jpeg/png file
if keyword_set(jpg) then begin
file = 'myfile.jpg'
if keyword_set(filename) then file=filename
if sz(0) eq 3 then write_jpeg,file,image,/true else $
write_jpeg,file,image
return
end
if keyword_set(png) then begin
file = 'myfile.png'
if keyword_set(filename) then file=filename
if sz(0) eq 3 then begin
device,decomposed=1
write_png,file,image
device,decomposed=0
endif else $
write_png,file,image,R,G,B
return
end
if keyword_set(tif) then begin
file = 'myfile.tif'
if keyword_set(filename) then file=filename
if keyword_set(reverse) then begin
if sz(0) eq 3 then $
write_tiff,file,reverse(image,3) else $
write_tiff,file,reverse(image,2),red=R,green=G,blue=B
endif else begin
if sz(0) eq 3 then begin
device,decomposed=1
write_tiff,file,image,1,red=R,green=G,blue=B
device,decomposed=0
endif else $
write_tiff,file,image,red=R,green=G,blue=B ;,1
end
end
END
PRO image_write_drv,image,R,G,B,filename=filename,tif=tif,png=png,jpg=jpg
help,filename,image,r,g,b
; help,tif,png,jpeg
sz = size(image)
if keyword_set(jpg) then begin
file = 'myfile.jpg'
if keyword_set(filename) then file=filename
if sz(0) eq 3 then write_jpeg,file,image,/true else $
write_jpeg,file,image
return
end
if keyword_set(png) then begin
file = 'myfile.png'
if keyword_set(filename) then file=filename
if sz(0) eq 3 then write_png,file,image else $
write_png,file,image,R,G,B
return
end
if keyword_set(tif) then begin
file = 'myfile.tif'
if keyword_set(filename) then file=filename
if sz(0) eq 3 then write_tiff,file,reverse(image,2) else $
write_tiff,file,reverse(image),red=R,green=G,blue=B ;,1
end
END
PRO oprinter_setup,myprinter,model=model,units=units,dimensions=dimensions
index = 0 ; RGB true color
if keyword_set(model) then index = 1 ; color table
if obj_valid(myprinter) eq 0 then $
myprinter = obj_new('idlgrprinter',color_model=model,units=units)
r = dialog_printersetup(myprinter)
END
;
; currently it can not assign the size of the printer output
;
PRO oprinter_job,myview,myprinter
; send the myview object to myprinter object
; myview - required input, view or scene objects
; myprinter - printer object
;
if obj_isa(myview,'IDLgrView') or obj_isa(myview,'IDLgrScene') then begin
if obj_valid(myprinter) eq 0 then $
oprinter_setup,myprinter
; r = dialog_printjob(myprinter)
; if r eq 0 then return
WIDGET_CONTROL,HOURGLASS=1
myprinter->draw,myview
myprinter->newdocument
WIDGET_CONTROL,HOURGLASS=0
end
END
;
; IDL Event Callback Procedures
; img_eventcb
;
; Generated on: 08/16/2001 11:41.28
;
; @testobj.pro
; @PS_open.pro
; @img_eventcb
; @img
;-----------------------------------------------------------------
pro OnPrinter, Event
PS_printer
end
;-----------------------------------------------------------------
pro OnPrint, Event
COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
TVLCT,red,green,blue,/get
r_orig = red
g_orig = green
b_orig = blue
; Find the draw widget, which is named Draw.
wDraw = WIDGET_INFO(Event.top, FIND_BY_UNAME='WID_DRAW_0');
; Make sure something was found.
IF(wDraw GT 0)THEN BEGIN
; Make the draw widget the current, active window.
WIDGET_CONTROL, wDraw, GET_VALUE=idDraw
WSET,idDraw
arr = TVRD()
sz = size(arr)
xs = sz(1)
ys = sz(2)
width = float(xs)/40
height = float(ys)/40
; PS_open,'idl.ps',/TV
set_plot,'PS'
device,filename='idl.ps',/color,bits=8, $
/Courier,/Bold, scale_factor=1.1, $
xsize=width,ysize=height
TV,arr
PS_close
PS_print, 'idl.ps'
END
end
;-----------------------------------------------------------------
pro OnPrinter2, Event
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
model = img_state.model
myprinter = img_state.printer
oprinter_setup,myprinter,model=model
img_state.printer = myprinter
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
end
;-----------------------------------------------------------------
pro OnPrint2, Event,original=original
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
width = img_state.xsize
height = img_state.ysize
dimensions=[width,height]
oprinter = img_state.printer
if obj_valid(oprinter) eq 0 then begin
oprinter_setup,oprinter,model=model
img_state.printer = oprinter
end
if keyword_set(original) then begin
data = *img_state.im
dimensions=[float(img_state.WD)/!d.x_px_cm,float(img_state.HT)/!d.y_px_cm]
tvlct,img_state.R,img_state.G,img_state.B
endif else begin
dimensions=[float(width)/!d.x_px_cm,float(height)/!d.y_px_cm]
data = tvrd(true=1)
end
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
oview = obj_new('idlgrview', $
units=2, $ ; centimeters
dimensions=dimensions, $
viewplane_rect=[0,0,width,height])
omodel = obj_new('idlgrmodel')
oimage = obj_new('idlgrimage',data)
omodel->add,oimage
oview->add,omodel
oprinter_job,oview,oprinter
; WIDGET_CONTROL,hourglass=1
; oprinter->draw,oview
; oprinter->newdocument
; WIDGET_CONTROL,hourglass=0
end
;-----------------------------------------------------------------
pro OnExit, Event
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
vmin = img_state.vmin
vmax = img_state.vmax
xmin = img_state.xmin
xmax = img_state.xmax
ymin = img_state.ymin
ymax = img_state.ymax
path = img_state.path
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
catch,error_status
if error_status ne 0 then goto,close_config
openw,2,'img.config'
printf,2,vmax,vmin,xmin,xmax,ymin,ymax
printf,2,path
close_config:
close,2
WIDGET_CONTROL, Event.top, /DESTROY
end
;-----------------------------------------------------------------
pro OnSavePVTColor, Event
TVLCT,red,green,blue,/GET
save,red,green,blue,file='pvtcolors.dat'
end
;-----------------------------------------------------------------
pro OnLoadPVTColor, Event
found = findfile('pvtcolors.dat')
if found(0) eq '' then begin
str = 'Error: Private color table never been saved before'
r = dialog_message(str,/error)
endif else begin
restore,'pvtcolors.dat'
TVLCT,red,green,blue
end
end
;-----------------------------------------------------------------
pro OnColor, Event
XLOADCT,GROUP=Event.top
end
;
; Empty stub procedure used for autoloading.
;
pro img_eventcb
end
;-----------------------------------------------------------------
PRO OnOverlay, Event
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
path = img_state.path
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
if !d.n_colors gt 256 then device,decompose=0
scan2d_overlay,path=path
END
;-----------------------------------------------------------------
PRO OnDrawCursor, Event
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
if Event.RELEASE eq 1 then begin
img_state.xl = Event.X
img_state.yl = Event.Y
end
if Event.RELEASE eq 4 then begin
xr = Event.X
yr = Event.Y
if xr lt img_state.xl then begin
img_state.xr = img_state.xl
img_state.xl = xr
endif else img_state.xr = xr
if yr lt img_state.yl then begin
img_state.yr = img_state.yl
img_state.yl = yr
endif else img_state.yr = yr
end
if XRegistered('image_extract') then begin
ml = widget_info(/managed)
wl = widget_info(ml,FIND_BY_UNAME='IMAGE_EXTRACT')
id = where(wl gt 0)
if id(0) ne -1 then begin
exWID = wl(id(0))
widget_control,exWID,GET_UVALUE=ex_state,/NO_COPY
widget_control,ex_state.xlWID,set_value=img_state.xl
widget_control,ex_state.ylWID,set_value=img_state.yl
widget_control,ex_state.xrWID,set_value=img_state.xr
widget_control,ex_state.yrWID,set_value=img_state.yr
widget_control,ex_state.wdWID, $
set_value=(img_state.xr - img_state.xl)+1
widget_control,ex_state.htWID, $
set_value=(img_state.yr - img_state.yl)+1
if Event.RELEASE eq 2 then begin
str = 'Pixels @ Cursor: X='+strtrim(Event.X,2) $
+', Y='+strtrim(Event.Y,2)
widget_control,ex_state.cursor,set_value=str
end
widget_control,exWID,SET_UVALUE=ex_state,/NO_COPY
end
end
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
if Event.RELEASE eq 4 and XRegistered('image_extract') eq 0 then $
OnImageCalc,Event
END
;-----------------------------------------------------------------
PRO OnImageCalc, Event
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
xl = img_state.xl
yl = img_state.yl
xr = img_state.xr
yr = img_state.yr
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
; extract raw data
imgReadScreen,im
image_extract,im,xl=xl,yl=yl,xr=xr,yr=yr, $
Group=Event.Top
END
;-----------------------------------------------------------------
PRO OnBaseResize, Event
if XRegistered('image_extract') then image_extract_destroy
; Find the draw widget, which is named Draw.
wDraw = WIDGET_INFO(Event.top, FIND_BY_UNAME='WID_DRAW_0');
imgReadScreen,im
WIDGET_CONTROL, event.top, GET_UVALUE=img_state, /NO_COPY
if n_elements(*img_state.im) gt 0 then begin
img_state.xsize = event.X
img_state.ysize = event.Y
; Make sure something was found.
IF(wDraw GT 0)THEN BEGIN
; Make the draw widget the current, active window.
WIDGET_CONTROL, wDraw, GET_VALUE=idDraw
WIDGET_CONTROL, wDraw, scr_xsize=event.x,scr_ysize=event.y
WSET,idDraw
im = CONGRID(im, event.X, event.Y)
; Display the image.
if img_state.ftype eq 'xdr' or img_state.ftype eq 'txt' then tvscl,im else $
TV, im
END
end
WIDGET_CONTROL, event.top, SET_UVALUE=img_state, /NO_COPY
END
;-----------------------------------------------------------------
PRO img_init_filelist,filename,img_state
fpath=''
l = strpos(filename,!os.file_sep,/reverse_search)
if l ge 0 then fpath = strmid(filename,0,l+1)
name = strmid(filename,l+1,strlen(filename)-l-1)
l = strpos(filename,'.',/reverse_search)
ftype = strmid(filename,l,strlen(filename)-l)
s_str = '*'+ftype
if fpath ne '' then s_str = fpath+s_str
found = findfile(s_str,count=ct)
if ct le 1 then return
fname = filename
if !d.name eq 'WIN' then fname = fpath+strupcase(name)
for i=0,ct-1 do begin
if fname eq found(i) or filename eq found(i) then begin
id = i
goto,pickid
end
end
pickid:
img_state.ifile = id
img_state.nfile = ct
img_state.file = found(id)
*img_state.files = found
; img_state.path = fpath
; img_state.ftype = ftype
widget_control,img_state.sldr1WID,set_slider_max=img_state.nfile
END
PRO OnImgFirst,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 then begin
img_state.ifile = 0
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgLast,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 then begin
img_state.ifile = img_state.nfile-1
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgPrev,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 then begin
img_state.ifile = img_state.ifile-1
if img_state.ifile lt 0 then img_state.ifile = img_state.nfile-1
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgNext,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 then begin
img_state.ifile = img_state.ifile+1
if img_state.ifile ge img_state.nfile then img_state.ifile = 0
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgSlider1,Event
widget_control,event.id,get_value=id
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 then begin
img_state.ifile = id - 1
if img_state.ifile ge img_state.nfile then img_state.ifile = 0
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
img_state.cfile = img_state.ifile
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgSlider2,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
widget_control,event.id,get_value=id
img_state.timer = id
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgStop,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
img_state.cfile = img_state.ifile
img_state.ifile = img_state.nfile
widget_control,event.top,/clear_events
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnImgStart,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.cfile gt 0 then begin
img_state.ifile = img_state.cfile
if img_state.cfile eq img_state.nfile then img_state.ifile = 0
img_state.cfile = -1
end
if img_state.nfile gt 1 then begin
img_state.ifile = img_state.ifile+1
last = img_state.nfile
timer = img_state.timer
current = img_state.ifile
if img_state.ifile ge img_state.nfile then begin
img_state.ifile = last -1 ; 0
r=dialog_message(' **End of slide show** ',/info)
end
found = *img_state.files
sfile = found(img_state.ifile)
path = img_state.path
img_displayImage,sfile,path,img_state,Event
end
if img_state.ifile lt img_state.nfile then $
widget_control,event.top,timer=timer ;,send_event=Event
WIDGET_CONTROL,event.top,SET_UVALUE=img_state,/NO_COPY
END
PRO OnAddTimer,Event
WIDGET_CONTROL,event.top,GET_UVALUE=img_state,/NO_COPY
if img_state.nfile gt 1 and img_state.ifile lt img_state.nfile then begin
img_state.ifile = img_state.ifile+1
last = img_state.nfile
timer = img_state.timer
current = img_state.ifile
img_state.cfile = current
if img_state.ifile ge img_state.nfile then begin
img_state.ifile = last -1 ; 0
r=dialog_message(' **End of slide show** ',/info)
end
found = *img_state.files
sfile = found(img_state.ifile)