-
Notifications
You must be signed in to change notification settings - Fork 3
/
unit1.pas
1893 lines (1542 loc) · 44.1 KB
/
unit1.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 Unit1;
//Lazzy Image Viewer
//github.com/PascalVault
//License: GNU/GPL
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, Grids,
StdCtrls, Buttons, Menus, LCLIntf, LCLType, Clipbrd, Math, {$IFDEF WINDOWS}ShellApi,{$ENDIF}
PV_Bitmap, PV_BitmapFormats, PV_Filters, Printers, PrintersDlgs, Types,
FileUtil, dlg_colors, dlg_resize, dlg_params, dlg_about, dlg_info, dlg_formats,
IntfGraphics, AsyncProcess, FPImage, FPReadJPEG;
const Levels: array of Extended = (0.1, 0.15, 0.20, 0.25, 0.3, 0.5, 0.7, 1, 1.5, 2, 3, 4, 5, 6, 7, 8);
type
TFileInfo = record
Name: String;
Size: Int64;
Ext: String;
Width: Integer;
Height: Integer;
Date: TDateTime;
Thumb: TBitmap;
end;
{ TFileList }
TFileList = class
private
FList: array of TFileInfo;
FSize: Integer;
FPos: Integer;
public
constructor Create;
procedure Clear;
procedure Add(Name: String; Size: Int64; Date: TDateTime);
procedure Edit(Index: Integer; Width,Height: Integer; Thumb: TPV_Bitmap);
function GetName(Index: Integer): String;
function Get(Index: Integer; out Info: TFileInfo): Boolean;
end;
{ TTabSheet }
TTabSheet = class(ComCtrls.TTabSheet)
public
Bmp: TPV_Bitmap;
Zoom: Extended;
Filename: String;
UndoPos: Integer;
UndoList: array[0..9] of TPV_Bitmap;
ScrollbarV: TScrollbar;
ScrollbarH: TScrollbar;
List: TFileList;
ListPos: Integer;
DG: TDrawGrid;
Panel: TPanel;
Split: TSplitter;
GridActive: Boolean;
procedure Close;
procedure ListFiles(AFilename: String);
end;
{ TForm1 }
TForm1 = class(TForm)
ImageList1: TImageList;
MainMenu1: TMainMenu;
BoxBlur_PopEl: TMenuItem;
Emboss_PopEl: TMenuItem;
Contrast_PopEl: TMenuItem;
Brightness_PopEl: TMenuItem;
Desaturate_PopEl: TMenuItem;
Formats_MenuEl: TMenuItem;
Negate_PopEl: TMenuItem;
RotateLeft_PopEl: TMenuItem;
RotateRight_PopEl: TMenuItem;
Rotate180_PopEl: TMenuItem;
FlipH_PopEl: TMenuItem;
FlipV_PopEl: TMenuItem;
Gauss_PopEl: TMenuItem;
Palette_PopEl: TMenuItem;
Grayscale_PopEl: TMenuItem;
Hicolor15_PopEl: TMenuItem;
BlackWhite_PopEl: TMenuItem;
Hicolor16_PopEl: TMenuItem;
Edit_MenuEl: TMenuItem;
Undo_MenuEl: TMenuItem;
File_MenuEl: TMenuItem;
Open_MenuEl: TMenuItem;
Close_MenuEl: TMenuItem;
Gauss5_PopEl: TMenuItem;
Exit_MenuEl: TMenuItem;
Help_MenuEl: TMenuItem;
About_MenuEl: TMenuItem;
Copy_MenuEl: TMenuItem;
Paste_MenuEl: TMenuItem;
SaveAs_MenuEl: TMenuItem;
View_MenuEl: TMenuItem;
Fullscreen_MenuEl: TMenuItem;
Next_MenuEl: TMenuItem;
Prev_MenuEl: TMenuItem;
CloseTab_PopEl: TMenuItem;
CloseOther_PopEl: TMenuItem;
CloseAll_PopEl: TMenuItem;
Next_PopEl: TMenuItem;
Prev_PopEl: TMenuItem;
Copy_PopEl: TMenuItem;
Fullscreen_PopEl: TMenuItem;
Trim_PopEl: TMenuItem;
Delete_MenuEl: TMenuItem;
Info_MenuEl: TMenuItem;
Countcolors_MenuEl: TMenuItem;
Fileinfo_MenuEl: TMenuItem;
SwitchChannel_PopEl: TMenuItem;
BGR_PopEl: TMenuItem;
GBR_PopEl: TMenuItem;
RBG_PopEl: TMenuItem;
BRG_PopEl: TMenuItem;
GRB_PopEl: TMenuItem;
ExtractChannel_PopEl: TMenuItem;
MenuItem59: TMenuItem;
MenuItem60: TMenuItem;
MenuItem61: TMenuItem;
MenuItem62: TMenuItem;
Rename_MenuEl: TMenuItem;
ZoomIn_MenuEl: TMenuItem;
Zoom100_MenuEl: TMenuItem;
ZoomOut_MenuEl: TMenuItem;
BestFit_MenuEl: TMenuItem;
CMYK_PopEl: TMenuItem;
ExtractC_PopEl: TMenuItem;
ExtractM_PopEl: TMenuItem;
ExtractY_PopEl: TMenuItem;
ExtractK_PopEl: TMenuItem;
RemoveAlpha_PopEl: TMenuItem;
Opaque_PopEl: TMenuItem;
Separator9: TMenuItem;
Separator8: TMenuItem;
Separator7: TMenuItem;
Separator6: TMenuItem;
Separator5: TMenuItem;
Separator4: TMenuItem;
Separator3: TMenuItem;
Separator2: TMenuItem;
PopupTab: TPopupMenu;
PopupImage: TPopupMenu;
Separator1: TMenuItem;
SmarterBlur_PopEl: TMenuItem;
Unsharp_PopEl: TMenuItem;
Sharpen_PopEl: TMenuItem;
Sepia_PopEl: TMenuItem;
AddNoise_PopEl: TMenuItem;
FindEdges_PopEl: TMenuItem;
OpenDialog1: TOpenDialog;
PG: TPageControl;
Panel1: TPanel;
PopupFilter: TPopupMenu;
PopupRotate: TPopupMenu;
PopupFlip: TPopupMenu;
PopupColors: TPopupMenu;
PrintDialog1: TPrintDialog;
SaveDialog1: TSaveDialog;
Open_Button: TSpeedButton;
Colors_Button: TSpeedButton;
Flip_Button: TSpeedButton;
ZoomIn_Button: TSpeedButton;
ZoomOut_Button: TSpeedButton;
Zoom100_Button: TSpeedButton;
Browse_Button: TSpeedButton;
Paste_Button: TSpeedButton;
Filter_Button: TSpeedButton;
SaveAs_Button: TSpeedButton;
Rotate_Button: TSpeedButton;
Print_Button: TSpeedButton;
Copy_Button: TSpeedButton;
Screenshot_Button: TSpeedButton;
Resize_Button: TSpeedButton;
Fullscreen_Button: TSpeedButton;
StatusBar1: TStatusBar;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure DrawGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure Formats_MenuElClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure Emboss_PopElClick(Sender: TObject);
procedure Contrast_PopElClick(Sender: TObject);
procedure Brightness_PopElClick(Sender: TObject);
procedure Desaturate_PopElClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Negate_PopElClick(Sender: TObject);
procedure RotateLeft_PopElClick(Sender: TObject);
procedure RotateRight_PopElClick(Sender: TObject);
procedure Rotate180_PopElClick(Sender: TObject);
procedure FlipH_PopElClick(Sender: TObject);
procedure FlipV_PopElClick(Sender: TObject);
procedure BoxBlur_PopElClick(Sender: TObject);
procedure Palette_PopElClick(Sender: TObject);
procedure Grayscale_PopElClick(Sender: TObject);
procedure Hicolor15_PopElClick(Sender: TObject);
procedure BlackWhite_PopElClick(Sender: TObject);
procedure Hicolor16_PopElClick(Sender: TObject);
procedure Undo_MenuElClick(Sender: TObject);
procedure Open_MenuElClick(Sender: TObject);
procedure Close_MenuElClick(Sender: TObject);
procedure Gauss_PopElClick(Sender: TObject);
procedure Exit_MenuElClick(Sender: TObject);
procedure About_MenuElClick(Sender: TObject);
procedure Copy_MenuElClick(Sender: TObject);
procedure Paste_MenuElClick(Sender: TObject);
procedure SaveAs_MenuElClick(Sender: TObject);
procedure Fullscreen_MenuElClick(Sender: TObject);
procedure Next_MenuElClick(Sender: TObject);
procedure Prev_MenuElClick(Sender: TObject);
procedure Gauss5_PopElClick(Sender: TObject);
procedure CloseTab_PopElClick(Sender: TObject);
procedure CloseOther_PopElClick(Sender: TObject);
procedure CloseAll_PopElClick(Sender: TObject);
procedure Next_PopElClick(Sender: TObject);
procedure Prev_PopElClick(Sender: TObject);
procedure Copy_PopElClick(Sender: TObject);
procedure Fullscreen_PopElClick(Sender: TObject);
procedure Trim_PopElClick(Sender: TObject);
procedure Delete_MenuElClick(Sender: TObject);
procedure SmarterBlur_PopElClick(Sender: TObject);
procedure Countcolors_MenuElClick(Sender: TObject);
procedure Fileinfo_MenuElClick(Sender: TObject);
procedure BGR_PopElClick(Sender: TObject);
procedure GBR_PopElClick(Sender: TObject);
procedure RBG_PopElClick(Sender: TObject);
procedure BRG_PopElClick(Sender: TObject);
procedure GRB_PopElClick(Sender: TObject);
procedure MenuItem59Click(Sender: TObject);
procedure Unsharp_PopElClick(Sender: TObject);
procedure MenuItem60Click(Sender: TObject);
procedure MenuItem61Click(Sender: TObject);
procedure MenuItem62Click(Sender: TObject);
procedure Rename_MenuElClick(Sender: TObject);
procedure ZoomIn_MenuElClick(Sender: TObject);
procedure Zoom100_MenuElClick(Sender: TObject);
procedure ZoomOut_MenuElClick(Sender: TObject);
procedure BestFit_MenuElClick(Sender: TObject);
procedure ExtractC_PopElClick(Sender: TObject);
procedure Sharpen_PopElClick(Sender: TObject);
procedure ExtractM_PopElClick(Sender: TObject);
procedure ExtractY_PopElClick(Sender: TObject);
procedure ExtractK_PopElClick(Sender: TObject);
procedure RemoveAlpha_PopElClick(Sender: TObject);
procedure Opaque_PopElClick(Sender: TObject);
procedure Sepia_PopElClick(Sender: TObject);
procedure AddNoise_PopElClick(Sender: TObject);
procedure FindEdges_PopElClick(Sender: TObject);
procedure PGMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ScrollBar1Change(Sender: TObject);
procedure Colors_ButtonClick(Sender: TObject);
procedure Flip_ButtonClick(Sender: TObject);
procedure ZoomIn_ButtonClick(Sender: TObject);
procedure ZoomOut_ButtonClick(Sender: TObject);
procedure Zoom100_ButtonClick(Sender: TObject);
procedure Browse_ButtonClick(Sender: TObject);
procedure Paste_ButtonClick(Sender: TObject);
procedure Filter_ButtonClick(Sender: TObject);
procedure Open_ButtonClick(Sender: TObject);
procedure SaveAs_ButtonClick(Sender: TObject);
procedure Rotate_ButtonClick(Sender: TObject);
procedure Print_ButtonClick(Sender: TObject);
procedure Copy_ButtonClick(Sender: TObject);
procedure Screenshot_ButtonClick(Sender: TObject);
procedure Resize_ButtonClick(Sender: TObject);
procedure Fullscreen_ButtonClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
procedure OnPanelPaint(Sender: TObject);
procedure OnGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure OnGridDrawCellThumb(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure OnGridSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure OnGridSelectCellThumb(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure OnGridResize(Sender: TObject);
public
IsFullscreen: Boolean;
WinSize: TRect;
procedure OpenImage(Filename: String);
function ReOpenImage(Filename: String; ASheet: TTabSheet; DoList: Boolean = True): Boolean;
procedure DrawBmp(Image: TImage; Bmp: TPV_Bitmap);
function GetBmp: TPV_Bitmap;
function GetSheet: TTabSheet;
function NoImage: Boolean;
procedure Redraw;
function ZoomIn(Val: Extended): Extended;
function ZoomOut(Val: Extended): Extended;
procedure SaveUndo;
procedure Undo;
procedure FixScrollbars;
procedure EnterFullscreen;
procedure LeaveFullscreen;
procedure ShowInfo;
procedure ShowZoom;
procedure ErrorBox(Msg: String);
procedure AddSaveFormats;
procedure SelectInGrid(Row: Integer);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
function HumanSize(V: Int64): String;
begin
if V < 1024 then Exit(IntToStr(V) + ' B');
if V < 1048576 then Exit(Format('%.02f', [V/1024]) + ' kB');
if V < 1073741824 then Exit(Format('%.02f', [V/1048576]) + ' MB');
Exit(Format('%.02f', [V/1073741824]) + ' GB');
end;
{ TFileList }
constructor TFileList.Create;
begin
inherited Create;
FPos := 0;
FSize := 1000;
SetLength(FList, FSize);
end;
procedure TFileList.Clear;
begin
FPos := 0;
end;
procedure TFileList.Add(Name: String; Size: Int64; Date: TDateTime);
begin
if FPos = FSize then begin
Inc(FSize, 1000);
SetLength(FList, FSize);
end;
FList[FPos].Name := Name;
FList[FPos].Ext := Copy(ExtractFileExt(Name), 2);
FList[FPos].Size := Size;
FList[FPos].Date := Date;
FList[FPos].Width := 0;
FList[FPos].Height := 0;
Inc(FPos);
end;
procedure TFileList.Edit(Index: Integer; Width, Height: Integer; Thumb: TPV_Bitmap);
begin
FList[Index].Width := Width;
FList[Index].Height := Height;
FList[Index].Thumb := Thumb.ToBitmap;
end;
function TFileList.GetName(Index: Integer): String;
begin
Result := FList[Index].Name;
end;
function TFileList.Get(Index: Integer; out Info: TFileInfo): Boolean;
begin
if (Index < 0) or (Index > FPos) then Exit(False);
Info := FList[Index];
Result := True;
end;
{ TTabSheet }
procedure TTabSheet.Close;
begin
Bmp.Free;
List.Free;
Self.Free;
end;
procedure TTabSheet.ListFiles(AFilename: String);
var sr: TSearchRec;
Dir: String;
FilenameLow: String;
k: Integer;
begin
Dir := ExtractFilePath(AFilename);
List.Clear;
FilenameLow := LowerCase(AFilename);
ListPos := -1;
if FindFirst(Dir + '*', faAnyFile - faDirectory, sr) <> 0 then Exit;
k := 0;
repeat
List.Add(Dir + sr.Name, sr.Size, sr.TimeStamp);
if LowerCase(Dir + sr.Name) = FilenameLow then ListPos := k;
Inc(k);
if k mod 100 = 0 then Application.ProcessMessages;
until FindNext(sr) <> 0;
FindClose(sr);
Self.DG.RowCount := 1;
end;
{ TForm1 }
procedure TForm1.OnGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
const Cols: array of String = ('Name','Size','Format','Resolution','Date');
var Sheet: TTabSheet;
Txt: String;
FInfo: TFileInfo;
FFormat, Resolution: String;
Wid,Hei,Topp: Integer;
begin
Sheet := GetSheet as TTabSheet;
if Sheet.List = nil then Exit;
if ARow > Sheet.List.FPos then Exit;
if ARow = 0 then begin //header
Txt := Cols[ACol];
Hei := Sheet.DG.Canvas.TextHeight(Txt);
Topp := (ARect.Height - Hei) div 2;
Sheet.DG.Canvas.TextOut(ARect.Left+2, ARect.Top+Topp, Txt);
Exit;
end;
Dec(ARow);
Sheet.List.Get(ARow, FInfo);
FFormat := BitmapFormats.FindName(FInfo.Ext);
if FInfo.Width > 0 then Resolution := Format('%d x %d', [FInfo.Width, FInfo.Height])
else Resolution := '';
if (not (gdSelected in aState)) and (FFormat <> '') then
Sheet.DG.Canvas.Brush.Color := $FFE3E3;
Sheet.DG.Canvas.FillRect(ARect);
case ACol of
0: Txt := ExtractFileName(FInfo.Name);
1: Txt := HumanSize(FInfo.Size);
2: Txt := FFormat;
3: Txt := Resolution;
4: Txt := FormatDateTime('YYYY-MM-DD HH:NN:SS', FInfo.Date);
end;
Hei := Sheet.DG.Canvas.TextHeight(Txt);
Wid := Sheet.DG.Canvas.TextWidth(Txt);
Topp := (ARect.Height - Hei) div 2;
Sheet.DG.Canvas.TextOut(ARect.Left+2, ARect.Top+Topp, Txt);
end;
procedure TForm1.OnGridDrawCellThumb(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var Sheet: TTabSheet;
Txt: String;
FInfo: TFileInfo;
FFormat, Resolution: String;
Wid,Hei,Topp: Integer;
Bmp: TPV_Bitmap;
Index: Integer;
Grid: TDrawGrid;
L: Integer;
begin
Sheet := GetSheet as TTabSheet;
if Sheet.List = nil then Exit;
Grid := Sheet.DG;
Index := ARow * Grid.ColCount + ACol;
if Index > Sheet.List.FPos-1 then Exit;
Sheet.List.Get(Index, FInfo);
L := (ARect.Width - FInfo.Thumb.Width) div 2;
Sheet.DG.Canvas.Draw(ARect.Left+L, ARect.Top+5, FInfo.Thumb);
Txt := ExtractFileName(FInfo.Name);
L := (ARect.Width - Sheet.DG.Canvas.TextWidth(Txt)) div 2;
Sheet.DG.Canvas.TextOut(ARect.Left+L, ARect.Top + 130, Txt);
end;
procedure TForm1.OnGridSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
var Sheet: TTabSheet;
FInfo: TFileInfo;
begin
Sheet := GetSheet;
if Sheet.GridActive = False then Exit;
if Sheet.List = nil then Exit;
if ARow > Sheet.List.FPos then Exit;
Sheet.List.Get(ARow-1, FInfo);
if Sheet.Filename <> FInfo.Name then
ReOpenImage(FInfo.Name, Sheet, False);
Sheet.ListPos := ARow-1;
end;
procedure TForm1.OnGridSelectCellThumb(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
var Sheet: TTabSheet;
FInfo: TFileInfo;
Index: Integer;
Grid: TDrawGrid;
begin
Sheet := GetSheet;
if Sheet.GridActive = False then Exit;
if Sheet.List = nil then Exit;
Grid := Sheet.DG;
Index := ARow * Grid.ColCount + ACol;
if Index > Sheet.List.FPos-1 then Exit;
Sheet.List.Get(Index, FInfo);
if Sheet.Filename <> FInfo.Name then
ReOpenImage(FInfo.Name, Sheet, False);
Sheet.ListPos := Index;
end;
procedure TForm1.OnGridResize(Sender: TObject);
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
IsFullScreen := False;
for i:=1 to ParamCount do
OpenImage(ParamStr(i));
AddSaveFormats;
{$IFNDEF WINDOWS}
//deleting to recycle bin doesn't work on Linux
Delete_MenuEl.Free;
Separator5.Free;
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
end;
procedure TForm1.DrawGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
begin
end;
procedure TForm1.Formats_MenuElClick(Sender: TObject);
begin
FormatsDlg.Show;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var i: Integer;
begin
for i:=PG.PageCount-1 downto 0 do
TTabSheet(PG.Pages[i]).Close;
end;
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
var i: Integer;
begin
for i:=0 to High(Filenames) do OpenImage(Filenames[i]);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
if Key = VK_ESCAPE then LeaveFullscreen;
end;
procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
begin
ZoomOut_Button.Click;
end;
procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
begin
ZoomIn_Button.Click;
end;
procedure TForm1.Emboss_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.Emboss;
Redraw;
end;
procedure TForm1.Contrast_PopElClick(Sender: TObject);
begin
with ParamsDlg do begin
TheMin := 0;
TheMax := 100;
TheVal := 10;
Setup;
ShowModal;
end;
SaveUndo;
GetBmp.Contrast(ParamsDlg.TheVal);
Redraw;
end;
procedure TForm1.Brightness_PopElClick(Sender: TObject);
begin
with ParamsDlg do begin
TheMin := -100;
TheMax := 100;
TheVal := 0;
Setup;
ShowModal;
end;
SaveUndo;
GetBmp.Brightness(ParamsDlg.TheVal);
Redraw;
end;
procedure TForm1.Desaturate_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.Grayscale(256, ddNone);
Redraw;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
end;
procedure TForm1.Negate_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.Negate;
Redraw;
end;
procedure TForm1.RotateLeft_PopElClick(Sender: TObject);
begin
if NoImage then Exit;
SaveUndo;
GetBmp.Rotate90;
Redraw;
end;
procedure TForm1.RotateRight_PopElClick(Sender: TObject);
begin
if NoImage then Exit;
SaveUndo;
GetBmp.Rotate270;
Redraw;
end;
procedure TForm1.Rotate180_PopElClick(Sender: TObject);
begin
if NoImage then Exit;
SaveUndo;
GetBmp.Rotate180;
Redraw;
end;
procedure TForm1.FlipH_PopElClick(Sender: TObject);
begin
if NoImage then Exit;
SaveUndo;
GetBmp.FlipH;
Redraw;
end;
procedure TForm1.FlipV_PopElClick(Sender: TObject);
begin
if NoImage then Exit;
SaveUndo;
GetBmp.FlipV;
Redraw;
end;
procedure TForm1.BoxBlur_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.BoxBlur;
Redraw;
end;
procedure TForm1.Palette_PopElClick(Sender: TObject);
begin
ColorsDlg.Show(256);
end;
procedure TForm1.Grayscale_PopElClick(Sender: TObject);
begin
ColorsDlg.Show(-256);
end;
procedure TForm1.Hicolor15_PopElClick(Sender: TObject);
begin
GetBmp.Highcolor(15);
end;
procedure TForm1.BlackWhite_PopElClick(Sender: TObject);
begin
ColorsDlg.Show(2);
end;
procedure TForm1.Hicolor16_PopElClick(Sender: TObject);
begin
GetBmp.Highcolor(16);
end;
procedure TForm1.Undo_MenuElClick(Sender: TObject);
begin
Undo;
end;
procedure TForm1.Open_MenuElClick(Sender: TObject);
begin
Open_Button.Click;
end;
procedure TForm1.Close_MenuElClick(Sender: TObject);
var Sheet: TTabSheet;
begin
Sheet := GetSheet;
if Sheet = nil then Exit;
Sheet.Close;
end;
procedure TForm1.Gauss_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.GaussBlur;
Redraw;
end;
procedure TForm1.Exit_MenuElClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.About_MenuElClick(Sender: TObject);
begin
AboutDlg.Show;
end;
procedure TForm1.Copy_MenuElClick(Sender: TObject);
begin
Copy_Button.Click;
end;
procedure TForm1.Paste_MenuElClick(Sender: TObject);
begin
Paste_Button.Click;
end;
procedure TForm1.SaveAs_MenuElClick(Sender: TObject);
begin
SaveAs_Button.Click;
end;
procedure TForm1.Fullscreen_MenuElClick(Sender: TObject);
begin
EnterFullscreen;
end;
procedure TForm1.Next_MenuElClick(Sender: TObject);
var Sheet: TTabSheet;
Pos: Integer;
i: Integer;
begin
if NoImage then Exit;
Sheet := GetSheet;
for i:=1 to 200 do begin // try 200 times
Pos := Sheet.ListPos + i;
if Pos > Sheet.List.FPos-1 then Exit;
if ReOpenImage(Sheet.List.GetName(Pos), Sheet, False) then begin
SelectInGrid(Pos+1);
break;
end;
Sheet.ListPos := Pos;
end;
Redraw;
end;
procedure TForm1.Prev_MenuElClick(Sender: TObject);
var Sheet: TTabSheet;
Pos: Integer;
i: Integer;
begin
if NoImage then Exit;
Sheet := GetSheet;
for i:=1 to 200 do begin // try 200 times
Pos := Sheet.ListPos - i;
if Pos < 0 then Exit;
if ReOpenImage(Sheet.List.GetName(Pos), Sheet, False) then begin
SelectInGrid(Pos+1);
break;
end;
Sheet.ListPos := Pos;
end;
Redraw;
end;
procedure TForm1.Gauss5_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.GaussBlur5;
Redraw;
end;
procedure TForm1.CloseTab_PopElClick(Sender: TObject);
var Cur: Integer;
begin
Cur := PopupTab.Tag;
TTabSheet(PG.Pages[Cur]).Close;
end;
procedure TForm1.CloseOther_PopElClick(Sender: TObject);
var i: Integer;
Cur: Integer;
begin
Cur := PopupTab.Tag;
for i:=PG.PageCount-1 downto 0 do begin
if i <> Cur then TTabSheet(PG.Pages[i]).Close;
end;
end;
procedure TForm1.CloseAll_PopElClick(Sender: TObject);
var i: Integer;
Cur: Integer;
begin
Cur := PopupTab.Tag;
for i:=PG.PageCount-1 downto 0 do begin
TTabSheet(PG.Pages[i]).Close;
end;
end;
procedure TForm1.Next_PopElClick(Sender: TObject);
begin
Next_MenuEl.Click;
end;
procedure TForm1.Prev_PopElClick(Sender: TObject);
begin
Prev_MenuEl.Click;
end;
procedure TForm1.Copy_PopElClick(Sender: TObject);
begin
Copy_Button.Click;
end;
procedure TForm1.Fullscreen_PopElClick(Sender: TObject);
begin
Fullscreen_Button.Click;
end;
procedure TForm1.Trim_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.Trim(0,0,0);
FixScrollbars;
Redraw;
end;
procedure TForm1.Delete_MenuElClick(Sender: TObject);
{$IFDEF WINDOWS}
var fileOpStruct: TSHFileOpStruct;
Sheet: TTabSheet;
begin
if NoImage then Exit;
fileOpStruct.Wnd := 0;
fileOpStruct.wFunc := FO_DELETE;
fileOpStruct.pFrom := PChar(TTabSheet(PG.ActivePage).Filename + #0 + #0);
fileOpStruct.fFlags := FOF_ALLOWUNDO + FOF_NOCONFIRMATION;
SHFileOperation( fileOpStruct );
Sheet := GetSheet;
Sheet.Close;
{$ENDIF}
end;
procedure TForm1.SmarterBlur_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.SmarterBlur;
Redraw;
end;
procedure TForm1.Countcolors_MenuElClick(Sender: TObject);
begin
if NoImage then Exit;
ShowMessage('There are ' + IntToStr(GetBmp.CountColors) + ' unique colors');
end;
procedure TForm1.Fileinfo_MenuElClick(Sender: TObject);
var Bmp: TPV_Bitmap;
Bpp: Integer;
begin
if NoImage then Exit;
Bmp := GetBmp;
Bpp := Bmp.CountColors;
if Bpp > 256 then Bpp := 24
else if Bpp > 16 then Bpp := 8
else if Bpp > 4 then Bpp := 4
else if Bpp > 1 then Bpp := 2
else Bpp := 1;
with InfoDlg do begin
Edit1.Text := Bmp.FormatName;
Edit2.Text := IntToStr(Bmp.Width);
Edit3.Text := IntToStr(Bmp.Height);
Edit4.Text := IntToStr(FileUtil.Filesize(GetSheet.Filename));
Edit5.Text := IntToStr(Bpp);
end;
InfoDlg.Show;
end;
procedure TForm1.BGR_PopElClick(Sender: TObject);
begin
SaveUndo;
GetBmp.BGR;
Redraw;
end;