forked from ptrsuder/IEU.Winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
1823 lines (1518 loc) · 80.4 KB
/
MainForm.cs
File metadata and controls
1823 lines (1518 loc) · 80.4 KB
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cyotek.Windows.Forms;
using DynamicData;
using GitHubUpdate;
using ImageEnhancingUtility.Core;
using ImageEnhancingUtility.Core.Utility;
using ReactiveUI;
using Tulpep.NotificationWindow;
using Rule = ImageEnhancingUtility.Core.Rule;
using Newtonsoft.Json;
//TODO:
//ask to change all paths when changing ESRGAN path
//change VerifyPaths?
namespace ImageEnhancingUtility.Winforms
{
public partial class MainForm : Form, IViewFor<MainViewModel>
{
public readonly string AppVersion = "0.11.01";
public readonly string GitHubRepoName = "IEU.Winforms";
public MainViewModel ViewModel { get; set; }
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (MainViewModel)value;
}
private MyTreeView treeView1;
List<ModelInfo> checkedModels = new List<ModelInfo>();
readonly List<TextBox> pathsTextBoxes;
private delegate void SafeCallDelegateWithColor(LogMessage message);
private void WriteToLogsThreadSafe(LogMessage message)
{
if (richTextBox1.InvokeRequired)
{
var d = new SafeCallDelegateWithColor(WriteToLogsThreadSafe);
Invoke(d, new object[] { message });
}
else
{
richTextBox1.AppendText(message.Text, message.Color);
}
}
void WriteErrors(Exception error)
{
if (error.InnerException != null)
WriteToLogsThreadSafe(new LogMessage(error.InnerException.Message, Color.Red));
else
WriteToLogsThreadSafe(new LogMessage(error.Message, Color.Red));
}
public double ProgressBarValue
{
get => 0;
set
{
ReportProgressThreadSafe(value);
}
}
private delegate void SafeCallDelegate2(double value);
private void ReportProgressThreadSafe(double value)
{
if (progressBar1.InvokeRequired || progress_label.InvokeRequired)
{
var d = new SafeCallDelegate2(ReportProgressThreadSafe);
Invoke(d, new object[] { value });
}
else
{
progressBar1.Value = (int)value;
progress_label.Text = $@"{ViewModel.IEU.FilesDone}/{ViewModel.IEU.FilesTotal}"; //hack, change to reactive bindings
progressFiltered_label.Text = ViewModel.IEU.FilesDoneSuccesfully.ToString();
}
}
[DllImport("user32.dll")] //textbox hint
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
#region CONSTRUCTOR
public MainForm()
{
InitializeComponent();
//disable mousewheel scrolling:
outputDestinationMode_comboBox.MouseWheel += (o, e) => ((HandledMouseEventArgs)e).Handled = true;
overwriteMode_comboBox.MouseWheel += (o, e) => ((HandledMouseEventArgs)e).Handled = true;
CreateMyTreeView();
treeView_contextMenuStrip.Items[0].Click += OpenModelFolder;
treeView_contextMenuStrip.Items[1].Click += (o, e) => ViewModel.IEU.CreateModelTree();
FormClosing += MainForm_FormClosing;
profiles_listBox.DisplayMember =
profilesMainTab_listBox.DisplayMember =
ruleProfiles_comboBox.DisplayMember =
filters_listBox.DisplayMember =
ruleFilters_comboBox.DisplayMember = "Name";
ViewModel = new MainViewModel();
BindMainTab();
BindConfig();
BindRuleSystem();
modelForAlpha_comboBox.DataSource = new BindingSource(ViewModel.IEU.ModelsItems.Items, null); //initial value
profileModel_comboBox.DataSource = new BindingSource(ViewModel.IEU.ModelsItems.Items, null); //initial value
BindSettingsTab();
BindCommands();
pathsTextBoxes = new List<TextBox> { esrganPath_textBox, imgPath_textBox, modelsPath_textBox };
SetPathButtons();
appVersion_label.Text = "IEU.Winforms v" + this.AppVersion;
appCoreVersion_linkLabel.Text = "IEU.Core v" + ViewModel.IEU.AppVersion;
interpolationModelOne_comboBox.DisplayMember =
interpolationModelTwo_comboBox.DisplayMember =
modelForAlpha_comboBox.DisplayMember =
profileModel_comboBox.DisplayMember =
previewModels_comboBox.DisplayMember = "ComboBoxName";
interpolationModelOne_comboBox.ValueMember =
interpolationModelTwo_comboBox.ValueMember =
modelForAlpha_comboBox.ValueMember =
profileModel_comboBox.ValueMember =
previewModels_comboBox.ValueMember = "FullName";
if (ViewModel.IEU.ModelsItems.Count > 0)
{
this.Bind(ViewModel,
vm => vm.IEU.CurrentProfile.ModelForAlpha,
v => v.modelForAlpha_comboBox.SelectedIndex,
x => x == null ? 0 : ViewModel.IEU.ModelsItems.Items.ToList().FindIndex(y => y.FullName == x.FullName),
x => GetModel(x));
this.Bind(ViewModel,
vm => vm.IEU.CurrentProfile.Model,
v => v.profileModel_comboBox.SelectedIndex,
x => GetIndex(x),
x => GetModel(x));
}
lastUseDifferentModelAlpha = useDifferentModelForAlpha_checkBox.Checked;
#region bind references
//Observable.FromEvent<ItemCheckEventHandler, ItemCheckEventArgs>(ev => filterExtensions_checkedListBox.ItemCheck += ev, ev => filterExtensions_checkedListBox.ItemCheck -= ev)
// .Select((x,y) => filterExtensions_checkedListBox.CheckedItems)
// .BindTo(ViewModel, vm => vm.IEU.filterSelectedExtensionsList, vmToViewConverterOverride: new ListboxToListConverter());
//Observable.FromEventPattern(ev => ItemsListBox.SelectedValueChanged += ev, ev => ItemsListBox.SelectedValueChanged -= ev)
//.Select(_ => ItemsListBox.SelectedItem)
//.BindTo(_vm, vm => vm.IEU.SelectedItem);
//this.WhenActivated(d =>
//{
// d(this.Bind(ViewModel, vm => vm.IEU.esrganPath, v => v.esrganPath_textBox.Text));
//});
//var selectionChanged = Observable.FromEvent<EventHandler, EventArgs>(
// h => (_, e) => h(e),
// ev => ddsTextureType_comboBox.SelectedIndexChanged += ev,
// ev => ddsTextureType_comboBox.SelectedIndexChanged += ev);
#endregion
BindOutputFormats();
BindAdvanced();
VerifyPaths();
if (ViewModel.Config.CheckForUpdates)
{
ViewModel.IEU.WriteToLog("Checking new releases on github...");
CheckNewReleases();
}
zoomImageBox.VerticalScroll.Enabled = false;
imageA_panel.Tag = imageA_pictureBox;
imageB_panel.Tag = imageB_pictureBox;
imageA_pictureBox.SizeMode = imageB_pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
imageAName_label.Text = imageBName_label.Text = "";
originalImagesPath_textBox.Text = imgPath_textBox.Text;
resultsDestinationPath_textBox.Text = resultsMergedPath_textBox.Text;
treeView1.Enabled = !useProfileModel_checkBox.Checked;
inMemoryMode_checkBox.Checked = !inMemoryMode_checkBox.Checked; //HACK
inMemoryMode_checkBox.Checked = !inMemoryMode_checkBox.Checked; //LAZY
comparisonMod_comboBox.DataSource = new BindingSource(IEU.ResizeImageScaleFactors, null);
comparisonMod_comboBox.SelectedIndex = 3;
}
#endregion
bool VerifyPaths()
{
string message = "Some directories dont exist!";
bool allgood = true;
foreach (TextBox t in pathsTextBoxes)
{
if (t.Text == "")
allgood = false;
else
{
if (!Directory.Exists(t.Text))
message += $"\n{t.Text}";
allgood = allgood && Directory.Exists(t.Text);
}
}
if (!allgood)
MessageBox.Show(message);
main_tabPage.Enabled = allgood;
interpolation_tabPage.Enabled = allgood;
return allgood;
}
void SetPathButtons()
{
progress_label.Text = "0/0";
changeEsrganPath_button.Tag = esrganPath_textBox;
changeInputImgPath_button.Tag = imgPath_textBox;
changeMergedResultsPath_button.Tag = resultsMergedPath_textBox;
changeInputPath_button.Tag = inputPath_textBox;
changeOutputPath_button.Tag = outputPath_textBox;
changeModelsPath_button.Tag = modelsPath_textBox;
changeOriginalImagesPath_button.Tag = originalImagesPath_textBox;
changeResultsAPath_button.Tag = resultsAPath_textBox;
changeResultsBPath_button.Tag = resultsBPath_textBox;
changeResultsDestinationPath_button.Tag = resultsDestinationPath_textBox;
}
#region BINDINGS
void BindMainTab()
{
this.OneWayBind(ViewModel, vm => vm.IEU.OutputDestinationModes, v => v.outputDestinationMode_comboBox.DataSource, x => new BindingSource(x, null));
outputDestinationMode_comboBox.DisplayMember = "Key";
outputDestinationMode_comboBox.ValueMember = "Value";
this.Bind(ViewModel, vm => vm.IEU.OutputDestinationMode, v => v.outputDestinationMode_comboBox.SelectedValue, x => x, x => (int)x);
this.OneWayBind(ViewModel, vm => vm.IEU.OverwriteModes, v => v.overwriteMode_comboBox.DataSource, x => new BindingSource(x, null));
overwriteMode_comboBox.DisplayMember = "Key";
overwriteMode_comboBox.ValueMember = "Value";
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.OverwriteMode, v => v.overwriteMode_comboBox.SelectedValue);
this.OneWayBind(ViewModel, vm => vm.IEU.ProgressBarValue, v => v.ProgressBarValue);
this.Bind(ViewModel, vm => vm.IEU.UseModelChain, v => v.UseModelChain_checkBox.Checked);
}
void BindConfig()
{
this.Bind(ViewModel, vm => vm.Config.WindowOnTop, v => v.topMost_checkBox.Checked);
this.OneWayBind(ViewModel, vm => vm.Config.WindowOnTop, v => v.TopMost);
this.Bind(ViewModel, vm => vm.Config.ShowPopups, v => v.showPopups_checkBox.Checked);
this.Bind(ViewModel, vm => vm.Config.CheckForUpdates, v => v.checkForUpdates_checkBox.Checked);
}
void BindSettingsTab()
{
this.Bind(ViewModel, vm => vm.IEU.ResultsPath, v => v.outputPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.ModelsPath, v => v.modelsPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.LrPath, v => v.inputPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.InputDirectoryPath, v => v.imgPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.OutputDirectoryPath, v => v.resultsMergedPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.EsrganPath, v => v.esrganPath_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.MaxTileResolution, v => v.maxTileResolution_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.MaxTileResolutionWidth, v => v.maxTileWidth_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.MaxTileResolutionHeight, v => v.maxTileHeight_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.PreciseTileResolution, v => v.preciseTile_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.IgnoreAlpha, v => v.ignoreAlpha_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.IgnoreSingleColorAlphas, v => v.ignoreSingleColorAlpha_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.BalanceAlphas, v => v.balanceAlphas_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.BalanceRgb, v => v.balanceRgb_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.DeleteResults, v => v.deleteResults_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CreateMemoryImage, v => v.createMemoryImage_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.UseOriginalImageFormat, v => v.preserveFormat_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.SplitRGB, v => v.splitRGB_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.UseCPU, v => v.useCPU_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.UseBasicSR, v => v.useBasicSR_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.UseDifferentModelForAlpha, v => v.useDifferentModelForAlpha_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.UseFilterForAlpha, v => v.useFilterForAlpha_checkBox.Checked);
filterForAlpha_comboBox.DataSource = new BindingSource(Dictionaries.MagickFilterTypes, null);
filterForAlpha_comboBox.DisplayMember = "Value";
filterForAlpha_comboBox.ValueMember = "Key";
filterForAlpha_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.AlphaFilterType, v => v.filterForAlpha_comboBox.SelectedValue, x => x, x => (int)x);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.UseModel, v => v.useProfileModel_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.SeamlessTexture, v => v.seamlessTextures_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.OverlapSize, v => v.overlapSize_numericUpDown.Value, x => x, x => (int)x);
this.Bind(ViewModel, vm => vm.IEU.UseCondaEnv, v => v.useCondaEnv_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CondaEnv, v => v.condaEnvName_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.EnableBlend, v => v.useMblend_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.InMemoryMode, v => v.inMemoryMode_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.UseImageMagickMerge, v => v.useImMerge_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.UseOldVipsMerge, v => v.useOldVipsMerge_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.DebugMode, v => v.showDebugInfo_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.VramMonitorEnable, v => v.monitorVram_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.VramMonitorFrequency, v => v.monitorFrequency_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.AutoSetTileSizeEnable, v => v.autoSetTileSize_checkBox.Checked);
this.OneWayBind(ViewModel, vm => vm.IEU.NoNvidia, v => v.autoSetTileSize_checkBox.Enabled, x => !x);
this.OneWayBind(ViewModel, vm => vm.IEU.NoNvidia, v => v.monitorVram_checkBox.Enabled, x => !x);
}
void BindOutputFormats()
{
ddsTextureType_comboBox.DataSource = new BindingSource(Dictionaries.ddsTextureType, null);
ddsTextureType_comboBox.DisplayMember = "Key";
ddsTextureType_comboBox.ValueMember = "Value";
ddsTextureType_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.DdsTextureTypeSelectedIndex, v => v.ddsTextureType_comboBox.SelectedIndex);
ddsFileFormat_comboBox.DisplayMember = "Name";
ddsFileFormat_comboBox.ValueMember = "DdsFileFormat";
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.DdsFileFormatsCurrent, v => v.ddsFileFormat_comboBox.DataSource);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.DdsFileFormatSelectedIndex, v => v.ddsFileFormat_comboBox.SelectedIndex);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ddsGenerateMipmaps, v => v.ddsGenerateMipmaps_checkBox.Checked);
ddsCompresion_comboBox.DataSource = new List<string>() { "Fast", "Normal", "Slow (best)" };
ddsCompresion_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.DdsBC7CompressionSelected, v => v.ddsCompresion_comboBox.SelectedIndex);
outputFormat_comboBox.DataSource = new BindingSource(ViewModel.IEU.CurrentProfile.FormatInfos, null);
outputFormat_comboBox.DisplayMember = "DisplayName";
outputFormat_comboBox.ValueMember = "Extension";
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.SelectedOutputFormatIndex, v => v.outputFormat_comboBox.SelectedIndex);
tiffSettings_comboBox.DataSource = new BindingSource(Dictionaries.TiffCompressionModes, null);
tiffSettings_comboBox.DisplayMember = "Key";
tiffSettings_comboBox.ValueMember = "Value";
tiffSettings_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.tiffFormat.CompressionMethod, v => v.tiffSettings_comboBox.SelectedValue, x => x, x => (string)x);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.tiffFormat.QualityFactor, v => v.tiffJpegQuality_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
webpPreset_comboBox.DataSource = new BindingSource(Dictionaries.WebpPresets, null);
webpPreset_comboBox.DisplayMember = "Key";
webpPreset_comboBox.ValueMember = "Value";
webpPreset_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.webpFormat.CompressionMethod, v => v.webpPreset_comboBox.SelectedValue, x => x, x => (string)x);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.webpFormat.QualityFactor, v => v.webpQuality_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.pngFormat.CompressionFactor, v => v.pngCompression_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
}
void BindRuleSystem()
{
this.Bind(ViewModel, vm => vm.IEU.DisableRuleSystem, v => v.disableRuleSystem_checkBox.Checked);
ViewModel.WhenAnyValue(vm => vm.IEU.DisableRuleSystem).Subscribe(x => HideRules(x));
ViewModel.IEU.Log.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out ReadOnlyObservableCollection<LogMessage> bindingData)
.OnItemAdded(x => WriteToLogsThreadSafe(x))
.Subscribe();
ViewModel.IEU.Profiles.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out ReadOnlyObservableCollection<Profile> bindingDataProfiles)
.Subscribe(x => UpdateDataSource(profiles_listBox, ruleProfiles_comboBox, bindingDataProfiles));
ViewModel.IEU.Filters.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out ReadOnlyObservableCollection < Filter > bindingDataFilters)
.Subscribe(x => UpdateDataSource(filters_listBox, ruleFilters_comboBox, bindingDataFilters));
ViewModel.IEU.ModelsItems.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out ReadOnlyObservableCollection<ModelInfo> bindingDataModels)
.Subscribe(_ => UpdateModels(bindingDataModels));
rules_listBox.DisplayMember = "Name";
rules_listBox.DataSource = new BindingSource(ViewModel.IEU.Ruleset.Values.ToList(), null);
}
void BindCommands()
{
this.BindCommand(ViewModel, vm => vm.IEU.SplitCommand, v => v.crop_button);
this.BindCommand(ViewModel, vm => vm.IEU.UpscaleCommand, v => v.upscale_button);
this.BindCommand(ViewModel, vm => vm.IEU.MergeCommand, v => v.merge_button);
this.BindCommand(ViewModel, vm => vm.IEU.SplitUpscaleMergeCommand, v => v.runAll_button);
ViewModel.IEU.SplitCommand.ThrownExceptions.Subscribe(error => WriteErrors(error));
ViewModel.IEU.UpscaleCommand.ThrownExceptions.Subscribe(error => WriteErrors(error));
ViewModel.IEU.MergeCommand.ThrownExceptions.Subscribe(error =>
{
WriteErrors(error);
});
ViewModel.IEU.SplitUpscaleMergeCommand.ThrownExceptions.Subscribe(error => WriteErrors(error));
ViewModel.IEU.SplitCommand.Subscribe(_ => ShowNotification("\nFinished splitting images"));
ViewModel.IEU.UpscaleCommand.Subscribe(_ => ShowNotification("\nFinished upscaling images"));
ViewModel.IEU.MergeCommand.Subscribe(_ => ShowNotification("\nFinished merging images"));
ViewModel.IEU.SplitUpscaleMergeCommand.Subscribe(_ => ShowNotification("\nFinished processing images"));
}
void BindAdvanced()
{
#region #ADVANCED_TAB
this.Bind(ViewModel, vm => vm.IEU.UseResultSuffix, v => v.advancedUseSuffix_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.ResultSuffix, v => v.advancedSuffix_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FilenameCaseSensitive, v => v.filterFilenameCaseSensitive_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FilenameContainsEnabled, v => v.filterFilenameContains_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FilenameContainsPattern, v => v.filterFilenameContains_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FilenameNotContainsEnabled, v => v.filterFilenameNotContains_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FilenameNotContainsPattern, v => v.filterFilenameNotContains_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FolderNameCaseSensitive, v => v.filterFolderNameCaseSensitive_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FolderNameContainsEnabled, v => v.filterFolderNameContains_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FolderNameContainsPattern, v => v.filterFolderNameContains_textBox.Text);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FolderNameNotContainsEnabled, v => v.filterFolderNameNotContains_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.FolderNameNotContainsPattern, v => v.filterFolderNameNotContains_textBox.Text);
filterAlpha_comboBox.DataSource = Filter.FiltersAlpha;
filterAlpha_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.Alpha, v => v.filterAlpha_comboBox.SelectedIndex);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.ImageResolutionEnabled, v => v.filtersSizeOn_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.ImageResolutionOr, v => v.filterSizeOr_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.ImageResolutionMaxWidth, v => v.filterSizeWidth_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.CurrentFilter.ImageResolutionMaxHeight, v => v.filterSizeHeight_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
foreach (var item in Filter.ExtensionsList)
filterExtensions_checkedListBox.Items.Add(item);
noiseReductionType_comboBox.DataSource = IEU.NoiseReductionTypes;
noiseReductionType_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.NoiseReductionType, v => v.noiseReductionType_comboBox.SelectedIndex);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ThresholdEnabled, v => v.thresholdEnabledRbg_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ThresholdAlphaEnabled, v => v.thresholdEnabledAlpha_checkBox.Checked);
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ThresholdBlackValue, v => v.thresholdBlack_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ThresholdWhiteValue, v => v.thresholdWhite_numericUpDown.Value, x => x, y => decimal.ToInt32(y));
#region #RESIZE
resizeImageBeforeScaleFactor_comboBox.DataSource = new BindingSource(IEU.ResizeImageScaleFactors, null);
resizeImageBeforeScaleFactor_comboBox.SelectedIndex = 3;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ResizeImageBeforeScaleFactor, v => v.resizeImageBeforeScaleFactor_comboBox.Text, x => x.ToString(), x => Double.Parse(x.ToString()));
resizeImageBeforeFilterType_comboBox.DataSource = new BindingSource(Dictionaries.MagickFilterTypes, null);
resizeImageBeforeFilterType_comboBox.DisplayMember = "Value";
resizeImageBeforeFilterType_comboBox.ValueMember = "Key";
resizeImageBeforeFilterType_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ResizeImageBeforeFilterType, v => v.resizeImageBeforeFilterType_comboBox.SelectedValue, x => x, x => (int)x);
resizeImageAfterScaleFactor_comboBox.DataSource = new BindingSource(IEU.ResizeImageScaleFactors, null);
resizeImageAfterScaleFactor_comboBox.SelectedIndex = 3;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ResizeImageAfterScaleFactor, v => v.resizeImageAfterScaleFactor_comboBox.Text, x => x.ToString(), x => Double.Parse(x.ToString()));
resizeImageAfterFilterType_comboBox.DataSource = new BindingSource(Dictionaries.MagickFilterTypes, null);
resizeImageAfterFilterType_comboBox.DisplayMember = "Value";
resizeImageAfterFilterType_comboBox.ValueMember = "Key";
resizeImageAfterFilterType_comboBox.SelectedIndex = 0;
this.Bind(ViewModel, vm => vm.IEU.CurrentProfile.ResizeImageAfterFilterType, v => v.resizeImageAfterFilterType_comboBox.SelectedValue, x => x, x => (int)x);
#endregion
#endregion
}
#endregion
#region MODELS/TREEVIEW
private void CreateMyTreeView()
{
this.treeView1 = new MyTreeView
{
BorderStyle = BorderStyle.FixedSingle,
ContextMenuStrip = this.treeView_contextMenuStrip,
Dock = DockStyle.Fill,
Font = new System.Drawing.Font("Lucida Console", 10.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))),
HideSelection = false,
ItemHeight = 20,
Location = new System.Drawing.Point(0, 0),
Name = "treeView1",
Size = new System.Drawing.Size(400, 571),
TabIndex = 9
};
this.treeView1.AfterCheck += new TreeViewEventHandler(this.treeView1_AfterCheck);
this.splitContainer1.Panel1.Controls.Add(this.treeView1);
}
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
checkedModels = treeView1.Nodes.Find("", true).Where(x => x.Checked).ToList()
.ConvertAll(x => x.Tag as ModelInfo)
.Where(x => x?.GetType().ToString() == "ImageEnhancingUtility.Core.ModelInfo").ToList();
ViewModel.IEU.SelectedModelsItems = checkedModels; //hack, change to reactive bindings
DisableUseModelForAlpha();
}
void UpdateDataSource(ListBox listBox, ComboBox comboBox, ReadOnlyObservableCollection<Profile> bindingData)
{
listBox.DataSource = new BindingSource(bindingData, null);
profilesMainTab_listBox.DataSource = new BindingSource(bindingData, null);
comboBox.DataSource = new BindingSource(bindingData, null);
}
void UpdateDataSource(ListBox listBox, ComboBox comboBox, ReadOnlyObservableCollection<Filter> bindingData)
{
listBox.DataSource = new BindingSource(bindingData, null);
comboBox.DataSource = new BindingSource(bindingData, null);
}
void UpdateModels(ReadOnlyObservableCollection<ModelInfo> bindingDataModels)
{
if (bindingDataModels.Count == 0) return;
string selectedModelFullname = ViewModel.IEU.CurrentProfile.ModelForAlpha?.FullName;
modelForAlpha_comboBox.DataSource = new BindingSource(bindingDataModels, null);
int lastSelectedIndex = bindingDataModels.ToList().FindIndex(y => y.FullName == selectedModelFullname);
if (lastSelectedIndex >= bindingDataModels.Count || lastSelectedIndex < 0)
lastSelectedIndex = 0;
modelForAlpha_comboBox.SelectedIndex = lastSelectedIndex;
selectedModelFullname = ViewModel.IEU.CurrentProfile.Model?.FullName;
profileModel_comboBox.DataSource = new BindingSource(bindingDataModels, null);
lastSelectedIndex = bindingDataModels.ToList().FindIndex(y => y.FullName == selectedModelFullname);
if (lastSelectedIndex >= bindingDataModels.Count || lastSelectedIndex < 0)
lastSelectedIndex = 0;
profileModel_comboBox.SelectedIndex = lastSelectedIndex;
selectedModelFullname = (interpolationModelOne_comboBox.SelectedItem as ModelInfo)?.FullName;
interpolationModelOne_comboBox.DataSource = new BindingSource(bindingDataModels, null);
lastSelectedIndex = bindingDataModels.ToList().FindIndex(y => y.FullName == selectedModelFullname);
if (lastSelectedIndex >= bindingDataModels.Count || lastSelectedIndex < 0)
lastSelectedIndex = 0;
interpolationModelOne_comboBox.SelectedIndex = lastSelectedIndex;
selectedModelFullname = (interpolationModelTwo_comboBox.SelectedItem as ModelInfo)?.FullName;
interpolationModelTwo_comboBox.DataSource = new BindingSource(bindingDataModels, null);
lastSelectedIndex = bindingDataModels.ToList().FindIndex(y => y.FullName == selectedModelFullname);
if (lastSelectedIndex >= bindingDataModels.Count || lastSelectedIndex < 0)
lastSelectedIndex = 0;
interpolationModelTwo_comboBox.SelectedIndex = lastSelectedIndex;
selectedModelFullname = (previewModels_comboBox.SelectedItem as ModelInfo)?.FullName;
previewModels_comboBox.DataSource = new BindingSource(bindingDataModels, null);
lastSelectedIndex = bindingDataModels.ToList().FindIndex(y => y.FullName == selectedModelFullname);
if (lastSelectedIndex >= bindingDataModels.Count || lastSelectedIndex < 0)
lastSelectedIndex = 0;
previewModels_comboBox.SelectedIndex = lastSelectedIndex;
if (bindingDataModels.Count > 0)
CreateModelTree(bindingDataModels);
}
ModelInfo GetModel(int x)
{
if(x == -1)
return ViewModel.IEU.ModelsItems.Items.ToList()[0];
return ViewModel.IEU.ModelsItems.Items.ToList()[x];
}
int GetIndex(ModelInfo x)
{
int r = x == null ? 0 : ViewModel.IEU.ModelsItems.Items.ToList().FindIndex(y => y.FullName == x.FullName);
return r;
}
void CreateModelTree(IEnumerable<ModelInfo> items)
{
treeView1.Nodes.Clear();
treeView1.CheckBoxes = true;
if (modelsPath_textBox.Text == "")
return;
DirectoryInfo di = new DirectoryInfo(modelsPath_textBox.Text);
if (!di.Exists)
{
MessageBox.Show($"{di.FullName} doesn't exist!");
return;
}
List<TreeNode> folders = new List<TreeNode>();
foreach (var model in items)
{
if (model.ParentFolder != "")
{
if (folders.Where(x => x.Text == model.ParentFolder).Count() == 0)
{
TreeNode node = new TreeNode() { Text = model.ParentFolder };
node.Nodes.AddRange(items
.Where(x => x.ParentFolder == model.ParentFolder).ToList()
.ConvertAll(x => new TreeNode(x.Name) { Tag = x }).ToArray());
node.Tag = "";
folders.Add(node);
treeView1.Nodes.Add(node);
}
}
else
treeView1.Nodes.Add(new TreeNode() { Text = model.Name, Tag = model });
}
treeView1.Nodes[0].ExpandAll();
}
#endregion
#region Notification
bool notificationActive = false;
PopupNotifier popup;
void ShowNotification(string message)
{
if (ViewModel.Config.ShowPopups)
{
popup = new PopupNotifier();
popup.Delay = 300000;
popup.TitleText = "Operation completed!";
popup.ContentText = message;
popup.Click += Popup_Click;
popup.Popup();
notificationActive = true;
}
}
private void Popup_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
#endregion
async Task CheckNewReleases()
{
var checkerWinforms = new UpdateChecker("ptrsuder", GitHubRepoName, AppVersion);
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
UpdateType updateWinforms = await checkerWinforms.CheckUpdate();
string updateMessage = "";
switch (updateWinforms)
{
case UpdateType.None:
ViewModel.IEU.WriteToLog("No new update.");
break;
case UpdateType.Fail:
ViewModel.IEU.WriteToLog("Failed to check update.");
ViewModel.IEU.WriteToLog(checkerWinforms.ErrorMessage);
break;
default:
updateMessage += "New version of IEU.Winforms is available!";
using (UpdateNotifyDialog updateNotifyDialog = new UpdateNotifyDialog(checkerWinforms, updateMessage))
{
updateNotifyDialog.ShowDialog(this);
}
break;
}
}
bool lastUseDifferentModelAlpha = false;
void DisableUseModelForAlpha()
{
useDifferentModelForAlpha_checkBox.Enabled = checkedModels.Count <= 1 || useProfileModel_checkBox.Checked;
if (checkedModels.Count > 1)
if (useDifferentModelForAlpha_checkBox.Checked)
{
lastUseDifferentModelAlpha = true;
useDifferentModelForAlpha_checkBox.Checked = false;
}
else
{
if (lastUseDifferentModelAlpha)
useDifferentModelForAlpha_checkBox.Checked = lastUseDifferentModelAlpha;
}
}
void HideRules(bool on = true)
{
rules_groupBox.Visible = !on;
}
#region PREVIEW methods
Bitmap originalPreview, resultPreview;
int visibleImageWidthBeforeResize, visibleImageHeightBeforeResize;
Rectangle _minimap;
Bitmap _thumbnailBitmap;
string previewFullname;
private void UpdateStatusBar()
{
RectangleF rect = zoomImageBox.GetSourceImageRegion();
imageSizeToolStripStatusLabel.Text = $"W:{(int)rect.Width}, H:{(int)rect.Height}";
}
private void OpenImage(string fullname)
{
originalPreview = null;
resultPreview = null;
Image image = ImageOperations.LoadImageToBitmap(fullname);
previewFullname = fullname;
//zoomImageBox.BeginUpdate();
zoomImageBox.Image = image;
zoomImageBox.ZoomToFit();
//zoomImageBox.EndUpdate();
int minimumZoom = zoomImageBox.Zoom;
zoomImageBox.ActualSize();
ZoomLevelCollection levels = zoomImageBox.ZoomLevels;
levels.Clear();
levels.Add(minimumZoom);
foreach (int level in ZoomLevelCollection.Default)
{
if (level > minimumZoom && level <= 600)
{
levels.Add(level);
}
}
FillZoomLevels();
UpdateStatusBar();
zoomImageBox.ZoomToFit();
}
private void UpdatePreview()
{
if (zoomImageBox.Image == null)
return;
RectangleF visibleImageRegion = zoomImageBox.GetSourceImageRegion();
int w = Convert.ToInt32(visibleImageRegion.Width);
int h = Convert.ToInt32(visibleImageRegion.Height);
double zoomFactor = zoomImageBox.ZoomFactor;
int wOffset = Convert.ToInt32(SystemInformation.VerticalScrollBarWidth / zoomFactor);
int hOffset = Convert.ToInt32(SystemInformation.HorizontalScrollBarHeight / zoomFactor);
Size imageSize = zoomImageBox.Image.Size;
int scaledWidth = Convert.ToInt32(visibleImageRegion.Width * zoomFactor);
int scaledHeight = Convert.ToInt32(visibleImageRegion.Height * zoomFactor);
Size viewSize = zoomImageBox.GetInsideViewPort().Size;
if (scaledWidth <= viewSize.Width)
wOffset = 0;
if (scaledHeight <= viewSize.Height)
hOffset = 0;
w += wOffset;
h += hOffset;
visibleImageRegion.Width = w;
visibleImageRegion.Height = h;
Bitmap result = new Bitmap(w, h);
using (Graphics g = Graphics.FromImage(result))
{
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(zoomImageBox.Image, new Rectangle(0, 0, w, h), visibleImageRegion, GraphicsUnit.Pixel);
}
previewImageBox.Image = result;
originalPreview = result;
resultPreview = null;
}
private void UpdateMiniMap()
{
Rectangle proposedView;
Size viewSize;
Point location;
double x;
double y;
double w;
double h;
// define the initial size. We'll take the current
// size from the source imagebox's image viewport
viewSize = zoomImageBox.GetImageViewPort().
Size;
w = viewSize.Width;
h = viewSize.Height;
// next we need to scale the size to match the zoomfactor of the source imagebox
w /= zoomImageBox.ZoomFactor;
h /= zoomImageBox.ZoomFactor;
// next we scale the size again - this time by the zoomfactor the destination imagebox
w *= miniMapImageBox.ZoomFactor;
h *= miniMapImageBox.ZoomFactor;
// with the size define, we can now turn out attention to the origin
// first, we get the current auto scroll offsets, and reverse them
// to give us our origin
x = -zoomImageBox.AutoScrollPosition.X;
y = -zoomImageBox.AutoScrollPosition.Y;
// next, we need to scale that to account for the source imagebox zoom
x /= zoomImageBox.ZoomFactor;
y /= zoomImageBox.ZoomFactor;
// as with the size, we need to scale again to account for the destination imagebox
x *= miniMapImageBox.ZoomFactor;
y *= miniMapImageBox.ZoomFactor;
// and for our final action, we need to offset the origin to account
// for where the destination imagebox is painting the output image
location = miniMapImageBox.GetImageViewPort().
Location;
x += location.X;
y += location.Y;
// all done, create the final rectangle for painting
proposedView = new Rectangle(Convert.ToInt32(x), Convert.ToInt32(y), Convert.ToInt32(w), Convert.ToInt32(h));
// see if the final rectangle is different to the one already being used
// to avoid painting if we don't need to
if (proposedView != _minimap)
{
_minimap = proposedView;
// force the destination to repaint to show the new rectangle
// this has performance issues
// https://github.com/cyotek/Cyotek.Windows.Forms.ImageBox/issues/27
miniMapImageBox.Invalidate();
//imageViewPortToolStripStatusLabel.Text = "Image Viewport: " + zoomImageBox.GetImageViewPort().ToString();
//calculatedRectangleToolStripStatusLabel.Text = "Rectangle: " + _minimap.ToString();
}
}
private void RefreshMiniMap()
{
Image image;
image = zoomImageBox.Image;
if (image != null)
{
Bitmap minimap;
Size minimapSize;
// https://github.com/cyotek/Cyotek.Windows.Forms.ImageBox/issues/27
// I found that ImageBox can cause performance issues if you instruct it
// to paint a large image that is zoomed out repeatly. As the image for
// our minimap doesn't actually change or allow zooming, lets create
// a tiny version up front. To make it easy, the "mini map" ImageBox
// has its VirtualMode property set to True, and the SizeMode set to
// Fit. I then set the VirtualSize to be the size if the original
// image and it will then calculate the size I need for the thumbnail
// which saves me some manual work. However, it does mean that I need
// to manually paint the thumbnail
miniMapImageBox.VirtualSize = image.Size;
minimapSize = miniMapImageBox.GetImageViewPort().
Size;
minimap = new Bitmap(minimapSize.Width, minimapSize.Height);
// generate the thumbnail
using (Graphics g = Graphics.FromImage(minimap))
{
g.DrawImage(image, new Rectangle(Point.Empty, minimap.Size), new Rectangle(Point.Empty, image.Size), GraphicsUnit.Pixel);
}
// always clean up
if (_thumbnailBitmap != null)
{
_thumbnailBitmap.Dispose();
_thumbnailBitmap = null;
}
_thumbnailBitmap = minimap;
// force a paint of the minimap
UpdateMiniMap();
}
}
private void FillZoomLevels()
{
zoomLevelsToolStripComboBox.Items.Clear();
foreach (int zoom in zoomImageBox.ZoomLevels)
{
zoomLevelsToolStripComboBox.Items.Add(string.Format("{0}%", zoom));
}
}
private void FitImage()
{
if (zoomImageBox.Image != null)
{
double zoomFactor = zoomImageBox.ZoomFactor;
Size imageSize = zoomImageBox.Image.Size;
int scaledWidth = Convert.ToInt32(imageSize.Width * zoomFactor);
int scaledHeight = Convert.ToInt32(imageSize.Height * zoomFactor);
Size viewSize = zoomImageBox.GetInsideViewPort().Size;
if (scaledWidth < viewSize.Width && scaledHeight < viewSize.Height)
{
zoomImageBox.ZoomToFit();
}
}
}
private void PreviewInProgress(bool inProgress)
{
int progress = inProgress ? 30 : 0;
bool enabled = !inProgress;
preview_progressBar.Style = inProgress ? ProgressBarStyle.Marquee : preview_progressBar.Style = ProgressBarStyle.Continuous;
preview_progressBar.MarqueeAnimationSpeed = progress;
previewUpdate_button.Enabled = enabled;
zoomImageBox.Enabled = enabled;
previewModels_comboBox.Enabled = enabled;
button_previewSaveComparison.Enabled = enabled;
previewSave_button.Enabled = enabled;
previewSaveOutputFormat_button.Enabled = enabled;
}
private double GetColorContrast(Color background, Color text)
{
double L1 = 0.2126 * background.R /255 + 0.7152 * background.G / 255 + 0.0722 * background.B / 255;
double L2 = 0.2126 * text.R / 255 + 0.7152 * text.G / 255 + 0.0722 * text.B / 255;
if (L1 > L2)
return (L1 + 0.05) / (L2 + 0.05);
else
return (L2 + 0.05) / (L1 + 0.05);
}
#endregion
#region PREVIEW event handlers
int widthBeforeResize, heightBeforeResize;
private void zoomImageBox_ImageChanged(object sender, EventArgs e)
{
RefreshMiniMap();
}
private void zoomImageBox_Scroll(object sender, ScrollEventArgs e)
{
UpdateMiniMap();
if (!zoomImageBox.IsPanning)
UpdatePreview();
}
private void zoomImageBox_PanEnd(object sender, EventArgs e)
{
UpdatePreview();
}