-
Notifications
You must be signed in to change notification settings - Fork 24
/
mainunit.pas
executable file
·6321 lines (5948 loc) · 202 KB
/
mainunit.pas
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
unit mainunit;
{$IFDEF FPC}{$H+}{$mode delphi} {$ENDIF}
{$D-,O+,Q-,R-,S-}
{$include opts.inc}
interface
//{$IFDEF FPC}
{$DEFINE COMPILEYOKE}
//{$ENDIF}
{$IFDEF LCLcarbon}
This program does not support Carbon
Please choose Project/ProjectOptions, go to the CompilerOptions/Additions&Overrides and set the BuildMode pull-down to "MacOS"
{$ENDIF}
uses
{$IFDEF Linux} uscaledpi, {$ENDIF}
{$IFDEF COMPILEYOKE}
yokesharemem, coordinates, nii_mat, math, nifti_tiff,
{$ENDIF}
{$IFDEF DGL} dglOpenGL, {$ELSE DGL} {$IFDEF COREGL}glcorearb, {$ELSE} gl,glext, {$ENDIF} {$ENDIF DGL}
types,clipbrd,
{$IFNDEF FPC}
messages,ShellAPI, detectmsaa,{$IFDEF PNG}pngimage, JPEG,{$ENDIF}
{$ENDIF}Dialogs, ExtCtrls, Menus, shaderu, texture2raycast,
StdCtrls, Controls, ComCtrls, Reslice, glcube,glclrbar, dcm_load,
{$IFDEF USETRANSFERTEXTURE}texture_3d_unit_transfertexture, {$ELSE} texture_3d_unit,extract,{$ENDIF}
{$IFDEF FPC} FileUtil, GraphType, LCLProc,LCLtype, LCLIntf,LResources,OpenGLContext,{$ELSE}glpanel, {$ENDIF}
{$IFDEF UNIX}Process, strutils, fphttpclient,
{$ELSE}//ShellApi,
Windows,{$IFDEF FPC}uscaledpi,{$ENDIF}{$ENDIF} glmtext,
Graphics, Classes, SysUtils, Forms, Buttons, Spin, Grids, clut, define_types,
histogram2d, readint, {$IFDEF COREGL} raycast_core, {$ELSE} raycast_legacy, {$ENDIF} raycast_common, histogram, nifti_hdr, shaderui,
prefs, userdir, slices2d, autoroi, fsl_calls, drawU, dcm2nii, lut,
extractui, scaleimageintensity;
{$IFNDEF FPC}
//WARNING DELPHI USER: YOU NEED TO COMMENT OUT THE LINE "GLBox:TOpenGLControl;"
{$ENDIF}
type { TGLForm1 }
TGLForm1 = class(TForm)
CoordLabel: TLabel;
LeftBtn: TButton;
AnteriorBtn: TButton;
OnlineHelpMenu: TMenuItem;
XCoordEdit: TEdit;
ResetDefaults1: TMenuItem;
PosteriorBtn: TButton;
RightBtn: TButton;
SuperiorBtn: TButton;
InferiorBtn: TButton;
LineWidthEdit: TSpinEdit;
LineColorBtn: TButton;
LineWidthLabel: TLabel;
ReorientMenu: TMenuItem;
RadiologicalMenu: TMenuItem;
ClrbarMenu: TMenuItem;
WhiteClrbarMenu: TMenuItem;
TransWhiteClrbarMenu: TMenuItem;
BlackClrbarMenu: TMenuItem;
TransBlackClrbarMenu: TMenuItem;
Label1: TLabel;
Label2: TLabel;
LightAziTrack: TTrackBar;
LightElevTrack: TTrackBar;
ConvertForeign1: TMenuItem;
InterpolateRecentMenu: TMenuItem;
InterpolateAxialMenu: TMenuItem;
InterpolateCoronalMenu: TMenuItem;
InterpolateSagittalMenu: TMenuItem;
ShaderPanel: TPanel;
QualityTrack: TTrackBar;
S10Check: TCheckBox;
S10Label: TLabel;
S10Track: TTrackBar;
S1Check: TCheckBox;
S1Label: TLabel;
S1Track: TTrackBar;
S2Check: TCheckBox;
S2Label: TLabel;
S2Track: TTrackBar;
S3Check: TCheckBox;
S3Label: TLabel;
S3Track: TTrackBar;
S4Check: TCheckBox;
S4Label: TLabel;
S4Track: TTrackBar;
S5Check: TCheckBox;
S5Label: TLabel;
S5Track: TTrackBar;
S6Check: TCheckBox;
S6Label: TLabel;
S6Track: TTrackBar;
S7Check: TCheckBox;
S7Label: TLabel;
S7Track: TTrackBar;
S8Check: TCheckBox;
S8Label: TLabel;
S8Track: TTrackBar;
S9Check: TCheckBox;
S9Label: TLabel;
ColEdit: TSpinEdit;
ColOverlap: TTrackBar;
CopyScriptBtn: TButton;
CrossCheck: TCheckBox;
Label3: TLabel;
Label7: TLabel;
Label8: TLabel;
LabelCheck: TCheckBox;
MosaicText: TMemo;
OrientDrop: TComboBox;
MosaicPanel: TPanel;
RowEdit: TSpinEdit;
RowOverlap: TTrackBar;
RunScriptBtn: TButton;
S9Track: TTrackBar;
ShaderDrop: TComboBox;
Slice2DBox: TGroupBox;
LineBox: TGroupBox;
InterpolateDrawMenu: TMenuItem;
voiBinarize1: TMenuItem;
NearBtn: TButton;
LUTdrop: TComboBox;
Addoverlay1: TMenuItem;
InterpolateMenu: TMenuItem;
Additive1: TMenuItem;
NoneBtn: TButton;
OverlayHideZerosMenu: TMenuItem;
N100transparent2: TMenuItem;
N802: TMenuItem;
N602: TMenuItem;
N502: TMenuItem;
N402: TMenuItem;
N202: TMenuItem;
N0opaque2: TMenuItem;
ModulateMenu: TMenuItem;
N100transparent1: TMenuItem;
N801: TMenuItem;
N601: TMenuItem;
N501: TMenuItem;
N401: TMenuItem;
N201: TMenuItem;
N0Opaque1: TMenuItem;
OverlayColorFromZeroMenu: TMenuItem;
BackgroundMaskMenu: TMenuItem;
Onbackground1: TMenuItem;
Onotheroverlays1: TMenuItem;
Additive2: TMenuItem;
//Thresholdmenu: TMenuItem;
Closeoverlays1: TMenuItem;
Overlays1: TMenuItem;
OverlayBox: TGroupBox;
HideRenderToolsBtn: TButton;
Extract1: TMenuItem;
BET1: TMenuItem;
MosaicBox: TGroupBox;
Import1: TMenuItem;
ConvertDicom1: TMenuItem;
MRU8: TMenuItem;
MRU10: TMenuItem;
MRU9: TMenuItem;
MRU7: TMenuItem;
MRU4: TMenuItem;
MRU6: TMenuItem;
MRU5: TMenuItem;
MRU3: TMenuItem;
MRU2: TMenuItem;
MRU1: TMenuItem;
StringGrid1: TStringGrid;
ToolPanel: TPanel;
ClipBox: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
ClipTrack: TTrackBar;
AziTrack1: TTrackBar;
ElevTrack1: TTrackBar;
ShaderBox: TGroupBox;
ShaderMemo: TMemo;
IntensityBox: TGroupBox;
MinEdit: TEdit;
MaxEdit: TEdit;
CutoutBox: TGroupBox;
YCoordEdit: TEdit;
ZCoordEdit: TEdit;
Xx: TLabel;
XTrackBar: TTrackBar;
X2TrackBar: TTrackBar;
yY: TLabel;
YTrackBar: TTrackBar;
Y2TrackBar: TTrackBar;
zZ: TLabel;
ZTrackBar: TTrackBar;
Z2TrackBar: TTrackBar;
MainMenu1: TMainMenu;
File1: TMenuItem;
AppleMenu: TMenuItem;
AppleAbout: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
Exit1: TMenuItem;
MenuSep1: TMenuItem;
Edit1: TMenuItem;
Copy1: TMenuItem;
View1: TMenuItem;
Tool1: TMenuItem;
Orient1: TMenuItem;
Scripting1: TMenuItem;
Colors1: TMenuItem;
Scheme1: TMenuItem;
ToggleTransparency1: TMenuItem;
Backcolor1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
OpenDialog1: TOpenDialog;
ColorDialog1: TColorDialog;
UpdateTimer: TTimer;
SaveDialog1: TSaveDialog;
AutoRunTimer1: TTimer;
GradientsIdleTimer: TTimer;
Draw1: TMenuItem;
OpenVOI1: TMenuItem;
SaveVOI1: TMenuItem;
CloseVOI1: TMenuItem;
UndoVOI1: TMenuItem;
Transparency1: TMenuItem;
HideVOI1: TMenuItem;
TransparencyVOIhi: TMenuItem;
TransparencyVOImid: TMenuItem;
TransparencyVOIlo: TMenuItem;
DrawTool1: TMenuItem;
NoDraw1: TMenuItem;
Eraser1: TMenuItem;
Advanced1: TMenuItem;
OverwriteDrawColor1: TMenuItem;
PasteSlice1: TMenuItem;
CustomDrawColors1: TMenuItem;
Smooth1: TMenuItem;
Display1: TMenuItem;
Render1: TMenuItem;
Sagittal1: TMenuItem;
Coronal1: TMenuItem;
Axial1: TMenuItem;
MPR1: TMenuItem;
SaveDialogVoi: TSaveDialog;
OpenDialogVoi: TOpenDialog;
OpenDialogTxt: TOpenDialog;
Mosaic1: TMenuItem;
AutoRoi1: TMenuItem;
NewWindow1: TMenuItem;
ErrorTimer: TTimer;
Sharpen1: TMenuItem;
ApplePreferences: TMenuItem;
Preferences1: TMenuItem;
YokeSepMenu: TMenuItem;
YokeMenu: TMenuItem;
YokeTimer: TTimer;
CollapsedToolPanel: TPanel;
CollapseToolPanelBtn: TButton;
Thresholdmenu: TMenuItem;
ViewSepMenu: TMenuItem;
LeftMenu: TMenuItem;
RightMenu: TMenuItem;
PosteriorMenu: TMenuItem;
AnteriorMenu: TMenuItem;
InferiorMenu: TMenuItem;
SuperiorMenu: TMenuItem;
voiDescriptives1: TMenuItem;
VisibleClrbarMenu: TMenuItem;
ClrbarSep: TMenuItem;
procedure ConvertForeign1Click(Sender: TObject);
procedure FormChangeBounds(Sender: TObject);
procedure InterpolateDrawMenuClick(Sender: TObject);
procedure LineColorBtnClick(Sender: TObject);
procedure LineWidthEditChange(Sender: TObject);
procedure CoordEditChange(Sender: TObject);
procedure OnlineHelpMenuClick(Sender: TObject);
procedure MosaicTextChange(Sender: TObject);
function OpenVOI(lFilename: string): boolean;
procedure BackgroundMaskMenuClick(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure FormShow(Sender: TObject);
procedure InterpolateMenuClick(Sender: TObject);
procedure LUTdropChange(Sender: TObject);
procedure OrientBtnClick(Sender: TObject);
procedure OrientClick(lOrient: integer);
procedure OrientMenuClick(Sender: TObject);
procedure RadiologicalMenuClick(Sender: TObject);
procedure ReorientMenuClick(Sender: TObject);
procedure ResetDefaults1Click(Sender: TObject);
procedure SetOverlayAlpha(Sender: TObject);
//procedure StringGridSetCaption(aRow: integer);
procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure ThresholdMenuClick(Sender: TObject);
procedure UpdateOverlaySpread;
procedure UpdateFont(initialSetup: boolean);
procedure DemoteOrder(lRow: integer);
procedure ReadCell (ACol,ARow: integer; Update: boolean);
procedure RecompileShader(oldQ, newQ: integer);
procedure BlendOverlaysRGBA (var lTexture: TTexture);
procedure OverlayIdleTimerReset;
function OverlayIntensityString(Voxel: integer): string;
procedure OverlayColorFromZeroMenuClick(Sender: TObject);
procedure SetBackgroundAlpha(Sender: TObject);
procedure SetOverlayAlphaValue(NewValue: integer);
procedure SetOverlayAlphaLayerValue(Layer, NewValue: integer);
procedure SetBackgroundAlphaLayerValue(Layer, NewValue: integer);
procedure SetSubmenuWithTag (var lRootMenu: TMenuItem; lTag: Integer);
procedure SetBackgroundAlphaValue(NewValue: integer);
procedure OverlayVisible(lOverlay: integer; lVisible: boolean);
procedure ChangeOverlayUpdate;
function Addoverlay(lFilename: string; lVolume: integer): integer;
procedure Closeoverlays1Click(Sender: TObject);
procedure StringGrid1Exit(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: char);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure UpdateImageIntensity (lOverlay: integer);
procedure UpdateImageIntensityMinMax (lOverlay: integer; lMinIn,lMaxIn: double);
procedure UpdateOverlaySpreadI (lIndex: integer);
procedure UpdateLUT(lOverlay,lLUTIndex: integer; lChangeDrop: boolean);
procedure Addoverlay1Click(Sender: TObject);
//function Addoverlay(lFilename: string; lVolume: integer): integer;
procedure CollapsedToolPanelClick(Sender: TObject);
procedure HideRenderToolsBtnClick(Sender: TObject);
procedure CopyScriptClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure RunScriptClick(Sender: TObject);
procedure SetToolPanelWidth;
procedure NewWindow1Click(Sender: TObject);
procedure Preferences1Click(Sender: TObject);
function ScreenShot(Zoom: integer): TBitmap;
procedure AutoDetectVOI;
procedure AutoRoi1Click(Sender: TObject);
procedure ConvertDicom1Click(Sender: TObject);
procedure CustomDrawColors1Click(Sender: TObject);
procedure ErrorTimerTimer(Sender: TObject);
procedure Sharpen1Click(Sender: TObject);
procedure ShowmessageError(Str:string);
procedure LoadDraw;
function MouseMoveVOI (X, Y: Integer): boolean;
function MouseUpVOI (Shift: TShiftState; X, Y: Integer): boolean;
function MouseDownVOI (Shift: TShiftState; X, Y: Integer): boolean;
procedure CloseVOI1Click(Sender: TObject);
procedure Extract1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure BET1Click(Sender: TObject);
procedure GradientsIdleTimerTimer(Sender: TObject);
procedure SetColorBarPosition;
procedure Label4Click(Sender: TObject);
procedure Label5Click(Sender: TObject);
procedure Label6Click(Sender: TObject);
procedure DrawTool1Click(Sender: TObject);
procedure MinMaxEditExit(Sender: TObject);
procedure OpenVOI1Click(Sender: TObject);
procedure PasteSlice1Click(Sender: TObject);
procedure SetViewClick(Sender: TObject);
procedure ResetSliders;
procedure OrthoClick(X,Y: integer);
procedure SaveVOI1Click(Sender: TObject);
procedure ShowOrthoSliceInfo (isYoke: boolean);
procedure Quit2TextEditor;
function GLBoxBackingWidth: integer;
function GLBoxBackingHeight: integer;
procedure ClipTrackChange(Sender: TObject);
procedure AppDropFiles(Sender: TObject; const FileNames: array of String);
procedure OpenColorScheme(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Smooth1Click(Sender: TObject);
procedure ToolPanelClick(Sender: TObject);
procedure UpdateContrast (Xa,Ya, Xb, Yb: integer);
procedure GLboxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; lX, lY: Integer);
procedure GLboxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure Backcolor1Click(Sender: TObject);
procedure Orient1Click(Sender: TObject);
procedure LoadStartupImage;
procedure ShaderBoxResize(Sender: TObject);
procedure Tool1Click(Sender: TObject);
procedure TransparencyVOIClick(Sender: TObject);
procedure UndoVOI1Click(Sender: TObject);
procedure UniformChange(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure ExitButton1Click(Sender: TObject);
procedure CheckForUpdates(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OverlayBoxCreate;
procedure UpdateClrbar;
procedure ClrbarClr(i: integer);
procedure ClrbarMenuClick(Sender: TObject);
procedure DrawClrbar (lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer; ClrbarSizeFracX: single);
procedure DrawCube (lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer);
procedure TextArrow (X,Y,Sz: single; NumStr: string; orient: integer;FontColor,ArrowColor: TGLRGBQuad);
procedure GLboxMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; lX, lY: Integer);
procedure GLboxMouseMove(Sender: TObject; Shift: TShiftState; lX, lY: Integer);
procedure GLboxDblClick(Sender: TObject);
procedure OpenMRU(Sender: TObject);//open template or MRU
function LoadDatasetNIFTIvolx(lFilename: string; lStopScript: boolean): boolean;
procedure TerminateRendering;
procedure UpdateMosaic(Sender: TObject);
procedure UpdateMRU;//most-recently-used menu
function LoadDatasetNIFTIvol(lFilename: string; lStopScript: boolean; lVolume: integer): boolean;
procedure AdjustFormPos (var lForm: TForm);
procedure GLboxPaint(Sender: TObject);
procedure GLboxResize(Sender: TObject);
procedure ClrbarMenu1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
//procedure FormResize(Sender: TObject);
procedure AziElevChange(Sender: TObject);
procedure QualityTrackChange(Sender: TObject);
procedure ShaderDropChange(Sender: TObject);
procedure UpdateTimerTimer(Sender: TObject);
procedure ToggleTransparency1Click(Sender: TObject);
function CheckFilename (var lFilenameX: string; lBitmap: boolean): boolean;
procedure FormClose(Sender: TObject; var TheAction: TCloseAction);
procedure HideBtnClick(Sender: TObject);
procedure CutoutNearestSector(Sender: TObject);
procedure CutoutChange(Sender: TObject);
procedure MinMaxEditKeyPress(Sender: TObject; var Key: Char);
procedure MinMaxEditKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Overlays1Click(Sender: TObject);
function loadLabelsITK(fnm: string): boolean;
procedure loadLabelsDefault;
procedure Mosaic1Click(Sender: TObject);
procedure DrawMosaic(Str: string);
procedure SelectSliceView(lView: integer);
procedure SelectShowColorEditor(lShow: boolean);
function LoadDatasetNIFTIvol1(lFilename: string; lStopScript: boolean): boolean;
procedure SelectShowTools(lShow: boolean);
procedure SelectIntensityMinMax(lMin,lMax: single);
procedure SelectCube(lShow: boolean);
procedure StopTimers;
procedure Scripting1Click(Sender: TObject);
procedure SetFormSize(FormWidth,FormHeight: integer);
procedure Copy1Click(Sender: TObject);
procedure SavePicture (lFilename: string; lX, lY: integer); overload;
procedure SavePicture (lFilename: string); overload;
procedure Save1Click(Sender: TObject);
procedure DisplayRadiological;
procedure DisplayPrefs;
procedure StopScripts;
procedure AutoRunTimer1Timer(Sender: TObject);
procedure UpdateGL;
procedure GradientsIdleTimerReset;
procedure voiBinarize1Click(Sender: TObject);
procedure voiDescriptives1Click(Sender: TObject);
procedure YokeMenuClick(Sender: TObject);
procedure YokeTimerTimer(Sender: TObject);
procedure ClearText(ScrnWid, lScrnHt: integer);
procedure DrawText(lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer);
{$IFDEF LCLCocoa}
procedure SetFormDarkMode(var f: TForm);
procedure SetRetina;
procedure SetDarkMode;
{$ENDIF}
private
{$IFNDEF FPC} procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES; {$ENDIF}
public
{ public declarations }
M_reload: integer;
end;
const
//kCloseVOI_reload = -1;
//kOpenBlankVOI_reload = -2;
kOpenExistingVOI_reload = -3;
const
kMinOverlayIndex = 1;
kMaxOverlays = 32;
var
M_refresh: boolean;
GLForm1: TGLForm1;
gPrefs: TPrefs;
gTexture3D: TTexture;
gRendering: boolean = false;
gInitialSetup: boolean = true;
gOpenOverlays : integer = 0;
gOverlayImg : array [kMinOverlayIndex..kMaxOverlays] of TMRIcroHdr;
gTypeInCell: boolean = false;
gEnterCell: boolean = false;
gOverlayCLUTrec : array [kMinOverlayIndex..kMaxOverlays] of TCLUTrec;
gOverlayAlpha : array [kMinOverlayIndex..kMaxOverlays] of integer;
gBackgroundAlpha : array [kMinOverlayIndex..kMaxOverlays] of integer;
gPrevCol: integer = 0;
gPrevRow: integer = 0;
gRetinaScale: single = 1;
gCube : TGLCube;
gClrbar: TGLClrbar;
gText: TGLText;
implementation
{$IFDEF ENABLEOVERLAY} uses {$IFDEF LCLCocoa} UserNotification, nsappkitext, glcocoanscontext,{$ENDIF} nifti_types, savethreshold, nii_reslice {$IFDEF ENABLESCRIPT}, scriptengine{$ENDIF};{$ENDIF}
{$IFDEF FPC} {$R *.lfm} {$ENDIF}
{$IFNDEF FPC} {$R *.dfm} {$ENDIF}
var
MouseStartPt, MousePt: TPoint;
//gnClrbar: integer;
gFontSz, gFontPx: single;
{$IFDEF FPC}
GLBox:TOpenGLControl;
{$ELSE}
GLbox : TGLPanel;
{$ENDIF}
{$IFDEF LCLCocoa}
(* //the alert sheets are not modal (yet)
procedure ShowMessage(Str: string);
begin
ShowAlertSheet(GLForm1.Handle,'Note', str);
end; *)
{$ENDIF}
procedure TGLForm1.ClearText(ScrnWid, lScrnHt: integer);
const
sizeFrac = 0.035;
begin
if ScrnWid < lScrnHt then
gFontSz := round(ScrnWid * sizeFrac)
else
gFontSz := round(lScrnHt * sizeFrac);
gFontPx := gFontSz;
gFontSz := gFontSz/gText.BaseHeight;
gText.ClearText;
gText.TextColor(255,128,128);
end;
procedure TGLForm1.TextArrow (X,Y,Sz: single; NumStr: string; orient: integer;FontColor,ArrowColor: TGLRGBQuad);
begin
if (gPrefs.BackColor.rgbRed = FontColor.rgbRed) and (gPrefs.BackColor.rgbGreen = FontColor.rgbGreen) and (gPrefs.BackColor.rgbBlue = FontColor.rgbBlue) then
gText.TextColor(255-FontColor.rgbRed, 255-FontColor.rgbGreen, 255-FontColor.rgbBlue)
else
gText.TextColor(FontColor.rgbRed, FontColor.rgbGreen, FontColor.rgbBlue);
//Caption := inttostr(orient);
//1=left,2=top,3=right,4=bottom,5=above
if orient = 5 then //centered directly below XY
gText.TextOut(X- (gText.TextWidth(gFontSz,NumStr)*0.5) ,Y-(gFontPx*1.2),gFontSz,NumStr);
if orient = 6 then //left of X, Below Y
gText.TextOut(X+(gFontPx*0.1) ,Y-(gFontPx*1.2),gFontSz,NumStr)
else //??
gText.TextOut(X- (gText.TextWidth(gFontSz,NumStr)*0.5) ,Y-(gFontPx*1.2),gFontSz,NumStr);
end;
procedure TGLForm1.DrawText(lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer);
begin
(*glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho (0, Width, 0, Height, 0.1, 40);
//glTranslatef(zoom*zoomOffsetX, zoom*zoomOffsetY, 0);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0, Width div zoom , 0, Height div zoom, 0.1, 40);
glTranslatef(zoomOffsetX, zoomOffsetY, 0);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST); *)
gText.DrawText;
end;
procedure SetLutFromZero(var lMin,lMax: single);
//if both min and max are positive, returns 0..max
//if both min and max are negative, returns min..0
begin
SortSingle(lMin,lMax);
if (lMin > 0) and (lMax > 0) then
lMin := 0
else if (lMin < 0) and (lMax < 0) then
lMax := 0;
end;
procedure TGLForm1.UpdateClrbar;
var
i: integer;
lMin, lMax: single;
LUT: TLUT;
begin
(* //
for i := 0 to 255 do begin
LUT[i].rgbRed := i;
LUT[i].rgbGreen := 0;
LUT[i].rgbBlue := 0;
end;*)
if gOpenOverlays < 1 then begin
GenerateLUT(gCLUTrec, LUT);
gClrbar.SetLUT(1, LUT, gCLUTrec.min,gCLUTrec.max);
exit;
end; //
for i := 1 to gOpenOverlays do begin
lMin := gOverlayImg[i].WindowScaledMin;
lMax := gOverlayImg[i].WindowScaledMax;
SortSingle(lMin,lMax);
if gOverlayImg[i].LutFromZero then
SetLutFromZero(lMin,lMax);
gClrbar.SetLUT(i, gOverlayImg[i].LUT, lMin,lMax);
end;
end;
procedure TGLForm1.DrawClrbar (lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer; ClrbarSizeFracX: single);
begin
gClrbar.ForcedSizeFracX:= ClrbarSizeFracX;
gClrbar.Draw(max(gOpenOverlays,1),lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY);
end;
procedure TGLForm1.DrawCube (lScrnWid, lScrnHt, zoom, zoomOffsetX, zoomOffsetY: integer);
begin
gCube.Azimuth:= -gRayCast.Azimuth;
gCube.Elevation:= gRayCast.Elevation;
if (gPrefs.ColorbarPosition = 1) or (gPrefs.ColorbarPosition = 2) then
gCube.TopLeft:= true
else
gCube.TopLeft:= false;
gCube.Draw(lScrnWid, lScrnHt,zoom, zoomOffsetX, zoomOffsetY);
end;
function TGLForm1.GLBoxBackingWidth: integer;
begin
{$IFDEF LCLCocoa}
result := Round(GLBox.Width * LBackingScaleFactor(GLBox.Handle));
{$ELSE}
result := GLBox.Width;
{$ENDIF}
end;
function TGLForm1.GLBoxBackingHeight: integer;
begin
{$IFDEF LCLCocoa}
result := Round(GLBox.Height * LBackingScaleFactor(GLBox.Handle));
{$ELSE}
result := GLBox.Height;
{$ENDIF}
end;
{$IFDEF LCLCocoa}
procedure TGLForm1.SetFormDarkMode(var f: TForm);
begin
if not gPrefs.DarkMode then exit;
f.PopupMode:= pmAuto;
f.HandleNeeded;
setThemeMode(f, true);
//setThemeMode(f.Handle, true);
end;
procedure TGLForm1.SetDarkMode;
begin
setThemeMode(Self, gPrefs.DarkMode);
//setThemeMode(Self.Handle, gPrefs.DarkMode);
if gPrefs.DarkMode then begin
MosaicText.Color := clGray;
ShaderMemo.Color := clGray;
StringGrid1.Color := clGray;
StringGrid1.AlternateColor:= clGray;
StringGrid1.FixedColor:= clBlack;
(*LeftBtn.Color := clDefault;
AnteriorBtn.Color := clGray;
RightBtn.Color := clSilver;
PosteriorBtn.Color := clMedGray;
SuperiorBtn.Color := clBtnFace;
InferiorBtn.Color := clBlack; *)
end else begin
MosaicText.Color:= clDefault;
ShaderMemo.Color := clDefault;
StringGrid1.Color := clDefault;
StringGrid1.AlternateColor:= clDefault;
StringGrid1.FixedColor:= clBtnFace;
end;
end;
procedure TGLForm1.SetRetina;
begin
(*if gPrefs.RetinaDisplay then
GLBox.Options := [ocoMacRetinaMode]
else
GLBox.Options := [];
GLBox.MultiSampling:=GLBox.MultiSampling;
*)
LSetWantsBestResolutionOpenGLSurface(gPrefs.RetinaDisplay, GLBox.Handle);
//GLBox.WantsBestResolutionOpenGLSurface:=gPrefs.RetinaDisplay;
if (GLbox.Height < 1) or (GLBoxBackingHeight <= GLbox.Height) then
gRetinaScale := 1
else
gRetinaScale := GLBoxBackingHeight/GLbox.Height;
end;
{$ENDIF}
procedure TGLForm1.YokeMenuClick(Sender: TObject);
begin
{$IFDEF COMPILEYOKE}
YokeTimer.Enabled := YokeMenu.Checked;
{$ENDIF}
end;
procedure TGLForm1.YokeTimerTimer(Sender: TObject);
{$IFDEF COMPILEYOKE}
var
lAzimuth, lElevation,lXmm,lYmm,lZmm: single;
lInvMat: TMatrix ;
lOK: boolean;
begin
YokeTimer.Enabled := YokeMenu.Checked;
if not YokeMenu.Checked then exit;
if (gPrefs.SliceView = 5) then exit;//not for mosaics
if not GetShareFloats(lXmm,lYmm,lZmm, lAzimuth, lElevation) then
exit;
if (gPrefs.SliceView < 1) or (gPrefs.SliceView > 5) then begin //not 2D slice view: assume rendering
GLBox.Invalidate;
gRayCast.Azimuth := round(lAzimuth);
gRayCast.Elevation := round(lElevation);
exit;
end;
lInvMat := Hdr2InvMat (gTexture3D.NIftiHdr,lOK);
if (not lOK) or (gTexture3D.FiltDim[1] < 2) or (gTexture3D.FiltDim[2] < 2) or (gTexture3D.FiltDim[3] < 2) then exit;
mm2Voxel (lXmm,lYmm,lZmm, lInvMat);
gRayCast.OrthoX := (lXmm-1)/(gTexture3D.FiltDim[1]-1);
gRayCast.OrthoY := (lYmm-1)/(gTexture3D.FiltDim[2]-1);
gRayCast.OrthoZ := (lZmm-1)/(gTexture3D.FiltDim[3]-1);
ShowOrthoSliceInfo (true);
GLBox.Invalidate;
end;
{$ELSE}
begin
//
end;
{$ENDIF}
{$IFDEF FPC}
{$IFDEF COREGL}
Type
TFrameBuffer = record
depthBuf,frameBuf, tex: GLUint;
w, h: integer;
end;
procedure initFrame (var f : TFrameBuffer);
begin
f.tex := 0;
f.depthBuf := 0;
f.frameBuf := 0;
end;
procedure freeFrame (var f : TFrameBuffer);
begin
//Delete resources
glDeleteTextures(1, @f.tex);
glDeleteTextures(1, @f.depthBuf);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, @f.frameBuf);
//Bind 0, which means render to back buffer, as a result, frameBuf is unbound
end;
function setFrame (wid, ht: integer; var f : TFrameBuffer; isMultiSample: boolean) : boolean; //returns true if multi-sampling
//http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/
var
w,h: integer;
//drawBuf: GLenum;
drawBuf: array[0..1] of GLenum;
begin
w := wid;
h := ht;
if isMultiSample then begin
w := w * 2;
h := h * 2;
end;
result := isMultiSample;
if (w = f.w) and (h = f.h) then begin
{$IFDEF COREGL}
glBindFramebuffer(GL_FRAMEBUFFER, f.frameBuf);
{$ELSE}
glBindFramebuffer(GL_FRAMEBUFFER_EXT, f.frameBuf);
{$ENDIF}
exit;
end;
freeframe(f);
f.w := w;
f.h := h;
//https://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_render_to_texture_.282D.29
glGenTextures(1, @f.tex);
glBindTexture(GL_TEXTURE_2D, f.tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, f.w, f.h, 0,GL_RGBA, GL_UNSIGNED_BYTE, nil); //RGBA16 for AO
glGenFramebuffers(1, @f.frameBuf);
glBindFramebuffer(GL_FRAMEBUFFER, f.frameBuf);
//Attach 2D texture to this FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, f.tex, 0);
//glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, f.tex, 0);
// Create the depth buffer
glGenTextures(1, @f.depthBuf);
glBindTexture(GL_TEXTURE_2D, f.depthBuf);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, f.w, f.h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nil);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, f.depthBuf, 0);
//glDrawBuffers(1, @drawBuf); // "1" is the size of DrawBuffers
drawBuf[0] := GL_COLOR_ATTACHMENT0;
drawBuf[1] := GL_COLOR_ATTACHMENT1;
glDrawBuffers(1, @drawBuf[0]); // draw colors only
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) <> GL_FRAMEBUFFER_COMPLETE) then begin
GLForm1.ShowmessageError('Frame buffer error 0x'+inttohex(glCheckFramebufferStatus(GL_FRAMEBUFFER),4) );
exit;
end;
end;
function TGLForm1.ScreenShot(Zoom: integer): TBitmap;
var
RawImage: TRawImage;
p: array of byte;
zoom2, w, h, x, y, BytePerPixel: integer;
z:longword;
//fbuf, ftex: GLUint;
f : TFrameBuffer;
DestPtr: PInteger;
origSz : TPoint;
maxXY : array[0..1] of GLuint;
begin
GLBox.MakeCurrent;
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, @maxXY);
//caption := inttostr(maxXY[0]) +'x'+inttostr(maxXY[1]);
zoom2 := Zoom;
origSz.X := gRayCast.WINDOW_WIDTH;
origSz.Y := gRayCast.WINDOW_HEIGHT;
w := GLBoxBackingWidth * zoom2;
h := GLboxBackingHeight * zoom2;
if (w > maxXY[0]) or (h > maxXY[1]) then begin
w := GLBoxBackingWidth;
h := GLboxBackingHeight;
zoom2 := 1
end;
Result:=TBitmap.Create;
Result.Width:=w;
Result.Height:=h;
Result.PixelFormat := pf24bit; //if pf32bit the background color is wrong, e.g. when alpha = 0
RawImage := Result.RawImage;
BytePerPixel := RawImage.Description.BitsPerPixel div 8;
setlength(p, 4*w* h);
//GLBox.MakeCurrent;
(*fbuf := 0;
ftex := 0;
glGenTextures(1, @ftex);
glBindTexture(GL_TEXTURE_2D, ftex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, w, h, 0,GL_RGBA, GL_UNSIGNED_BYTE, nil); //RGBA16 for AO
glGenFramebuffers(1, @fbuf);
glBindFramebuffer(GL_FRAMEBUFFER, fbuf);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ftex, 0); *)
initFrame(f);
setFrame (w, h, f, false);
gRendering:=true;
//Attach 2D texture to this FBO
//gRayCast.ScreenCapture := true;
//gPrefs.RayCastQuality1to10 := 10;
gRayCast.WINDOW_WIDTH := w;
gRayCast.WINDOW_HEIGHT := h;
//DisplayGLz(gTexture3D,fbuf);
DisplayGLz(gTexture3D,f.frameBuf);
glFlush;
glFinish;//<-this would pause until all jobs finished: generally a bad idea! required here
GLbox.SwapBuffers;
//CreateRender(w, h, false); //draw to framebuffer fScreenShot
{$IFDEF Darwin} //http://lists.apple.com/archives/mac-opengl/2006/Nov/msg00196.html
glReadPixels(0, 0, w, h, $80E1, $8035, @p[0]); //OSX-Darwin GL_BGRA = $80E1; GL_UNSIGNED_INT_8_8_8_8_EXT = $8035;
{$ELSE}
{$IFDEF Linux}
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, @p[0]); //Linux-Windows GL_RGBA = $1908; GL_UNSIGNED_BYTE
{$ELSE}
glReadPixels(0, 0, w, h, $80E1, GL_UNSIGNED_BYTE, @p[0]); //Linux-Windows GL_RGBA = $1908; GL_UNSIGNED_BYTE
{$ENDIF}
{$ENDIF}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
freeFrame(f);
//glDeleteFramebuffers(1, @fbuf);
//glDeleteTextures(1, @ftex);
gRendering:=false;
//gRayCast.ScreenCapture := false;
gRayCast.WINDOW_WIDTH := origSz.X;
gRayCast.WINDOW_HEIGHT := origSz.Y;
GLbox.ReleaseContext;
z := 0;
if BytePerPixel <> 4 then begin
for y:= h-1 downto 0 do begin
DestPtr := PInteger(RawImage.Data);
Inc(PByte(DestPtr), y * RawImage.Description.BytesPerLine );
for x := 1 to w do begin
DestPtr^ := p[z] + (p[z+1] shl 8) + (p[z+2] shl 16);
Inc(PByte(DestPtr), BytePerPixel);
z := z + 4;
end;
end; //for y : each line in image
end else begin
for y:= h-1 downto 0 do begin
DestPtr := PInteger(RawImage.Data);
Inc(PByte(DestPtr), y * RawImage.Description.BytesPerLine );
System.Move(p[z], DestPtr^, w * BytePerPixel );
z := z + ( w * 4 );
end; //for y : each line in image
end;
setlength(p, 0);
GLbox.invalidate;
end;
{$ELSE} //not COREGL
function ScreenShotX1: TBitmap; //native resolution: no framebuffer, automatic multisampling
var
p: bytep0;
x, y: integer;
prevQ, w,h, BytePerPixel: int64;
z:longword;
RawImage: TRawImage;
DestPtr: PInteger;
maxXY: array[0..1] of GLuint;
begin
prevQ := gPrefs.RayCastQuality1to10;
gPrefs.RayCastQuality1to10 := 10;
if ((prevQ <> 10) and (gPrefs.SliceView = 0)) then
GLForm1.recompileShader(prevQ, 10);
GLBox.MakeCurrent;
DisplayGL(gTexture3D);
w := GLForm1.GLBoxBackingWidth;
h := GLForm1.GLboxBackingHeight;
Result:=TBitmap.Create;
Result.Width:=w;
Result.Height:=h;
Result.PixelFormat := pf24bit; //if pf32bit the background color is wrong, e.g. when alpha = 0
RawImage := Result.RawImage;
//GLForm1.ShowmessageError('GLSL error '+inttostr(RawImage.Description.RedShift)+' '+inttostr(RawImage.Description.GreenShift) +' '+inttostr(RawImage.Description.BlueShift));
BytePerPixel := RawImage.Description.BitsPerPixel div 8;
GetMem(p, w*h*4);
{$IFDEF Darwin} //http://lists.apple.com/archives/mac-opengl/2006/Nov/msg00196.html
glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, @p[0]); //OSX-Darwin
{$ELSE}
glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, @p[0]); //Linux-Windows
{$ENDIF}
z := 0;
if BytePerPixel <> 4 then begin
for y:= h-1 downto 0 do begin
DestPtr := PInteger(RawImage.Data);
Inc(PByte(DestPtr), y * RawImage.Description.BytesPerLine );
for x := 1 to w do begin
DestPtr^ := p[z] + (p[z+1] shl 8) + (p[z+2] shl 16);
Inc(PByte(DestPtr), BytePerPixel);
z := z + 4;
end;
end; //for y : each line in image
end else begin
for y:= h-1 downto 0 do begin
DestPtr := PInteger(RawImage.Data);
Inc(PByte(DestPtr), y * RawImage.Description.BytesPerLine );
System.Move(p[z], DestPtr^, w * BytePerPixel );
z := z + ( w * 4 );
end; //for y : each line in image
end;
FreeMem(p);
GLbox.ReleaseContext;
if ((prevQ <> 10) and (gPrefs.SliceView = 0)) then begin
gPrefs.RayCastQuality1to10 := prevQ;
GLForm1.recompileShader(10, gPrefs.RayCastQuality1to10);
end;
end;
function ScreenShotTiled(Zoom: integer): TBitmap;
var
p: bytep0;
x, y, tile: integer;
prevQ, w,h, wz,hz, tilex,tiley, BytePerPixel: int64;