-
Notifications
You must be signed in to change notification settings - Fork 7
/
MainForm.cs
696 lines (601 loc) · 27.8 KB
/
MainForm.cs
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
using ImageMagick;
using MagickUtils.Forms;
using MagickUtils.Interfaces;
using MagickUtils.MagickUtils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MagickUtils.Utils;
namespace MagickUtils
{
public partial class MainForm : Form
{
static Program.ImageFormat selectedFormat;
public MainForm ()
{
InitializeComponent();
}
private void MainForm_Load (object sender, EventArgs e)
{
if(OSUtils.IsUserAdministrator())
MessageBox.Show("MagickUtils is running as administrator. This will break Drag-n-Drop functionality from non-administrator applications.", "Warning");
CenterToScreen();
Config.Init();
Logger.textbox = logTbox;
Program.progBar = progressBar1;
progressBar1.Maximum = 100;
progressBar1.Step = 1;
progressBar1.Value = 0;
Program.currentExt = extTbox.Text.Trim();
InitCombox(formatCombox, 0);
InitCombox(colorDepthCombox, 3);
InitCombox(suffixPrefixCombox, 0);
InitCombox(inpaintColorCombox, 0);
InitCombox(inpaintScaleCombox, 1);
InitCombox(delImgsMode, 0);
InitCombox(delImgOperator, 0);
InitCombox(cropDivision, 1);
InitCombox(cropRelGrav, 1);
InitCombox(cropRelSizeMode, 0);
InitCombox(geomRotationCombox, 0);
InitCombox(geomFlipAxis, 0);
InitCombox(cropDivisibleGrav, 1);
InitCombox(cropAbsGrav, 1);
InitCombox(renameCounterMode, 0);
InitCombox(renameCounterPadding, 1);
InitCombox(tileMode, 0);
InitCombox(zeroPaddingCombox, 0);
InitCombox(ditherTypeCombox, 0);
InitCombox(scaleResampleCombox, 0);
InitCombox(scaleModeCombox, 0);
InitCombox(filterModeCombox, 0);
// Crop/Expand/Tile
InitCombox(cropRelSizeMode, 0);
InitCombox(cropAbsGrav, 1);
InitCombox(cropDivisibleGrav, 1);
InitCombox(padMode, 0);
IOUtils.recursive = recursiveCbox.Checked;
ScaleUtils.onlyDownscale = onlyDownscaleCbox.Checked;
CheckForIllegalCrossThreadCalls = false;
}
void InitCombox (ComboBox cbox, int index)
{
cbox.SelectedIndex = index;
cbox.Text = cbox.Items[index].ToString();
}
private void convertStartBtn_Click (object sender, EventArgs e)
{
if (!Program.IsPathValid(Program.currentDir))
{
Logger.Log("Path not valid!");
return;
}
ConvertTabHelper.ConvertUsingPath(qualityCombox, qualityMaxCombox, selectedFormat, delSrcCbox);
}
private void pathTextbox_TextChanged (object sender, EventArgs e)
{
Program.currentDir = pathTextbox.Text;
}
string GetFormatStr()
{
return formatCombox.Text.Trim().ToUpper();
}
private async void formatCombox_SelectedIndexChanged (object sender, EventArgs e)
{
string formatStrTrim = GetFormatStr();
qualityCombox.Enabled = true;
qualityMaxCombox.Enabled = false;
formatOptionsBtn.Visible = false;
formatQualityLabel.Text = "";
if (formatStrTrim == "JPEG")
{
await LoadQuality(formatStrTrim, 95, 0);
selectedFormat = Program.ImageFormat.JPG;
qualityMaxCombox.Enabled = true;
formatQualityLabel.Text = "JPEG Quality: 0 - 100. Default: 95";
formatOptionsBtn.Visible = true;
}
if(formatStrTrim == "PNG")
{
await LoadQuality(formatStrTrim, 30, 0);
selectedFormat = Program.ImageFormat.PNG;
formatQualityLabel.Text = "PNG Compression Strength: 0 (Raw) - 100 (Max). Default: 30";
formatOptionsBtn.Visible = true;
}
if (formatStrTrim == "WEBP")
{
await LoadQuality(formatStrTrim, 93, 0);
selectedFormat = Program.ImageFormat.WEBP;
qualityMaxCombox.Enabled = true;
formatQualityLabel.Text = "WEBP Quality: 0 - 99. 100 for Lossless. Default: 93";
}
if (formatStrTrim == "BMP")
{
ClearQuality();
selectedFormat = Program.ImageFormat.BMP;
qualityCombox.Enabled = false;
}
if (formatStrTrim == "DDS")
{
await LoadQuality(formatStrTrim, 255, 0);
selectedFormat = Program.ImageFormat.DDS;
qualityCombox.Enabled = await Config.GetInt("ddsEnc") == 2;
qualityMaxCombox.Enabled = qualityCombox.Enabled;
formatOptionsBtn.Visible = true;
formatQualityLabel.Text = "DDS Quality: 0 - 255. Default: 255. Only works with Crunch Encoder!";
}
if (formatStrTrim == "TGA")
{
ClearQuality();
selectedFormat = Program.ImageFormat.TGA;
qualityCombox.Enabled = false;
}
if(formatStrTrim == "JPEG 2000")
{
await LoadQuality(formatStrTrim, 95, 0);
selectedFormat = Program.ImageFormat.J2K;
formatQualityLabel.Text = "JPEG 2000 Quality: 0 - 100";
}
if(formatStrTrim == "FLIF")
{
await LoadQuality(formatStrTrim, 95, 0);
selectedFormat = Program.ImageFormat.FLIF;
formatOptionsBtn.Visible = true;
formatQualityLabel.Text = "FLIF Quality: 0 - 100";
}
if (formatStrTrim == "AVIF")
{
await LoadQuality(formatStrTrim, 95, 0);
selectedFormat = Program.ImageFormat.AVIF;
formatQualityLabel.Text = "AVIF Quality: 0 - 100";
}
if (formatStrTrim == "HEIF")
{
await LoadQuality(formatStrTrim, 50, 0);
selectedFormat = Program.ImageFormat.HEIF;
formatQualityLabel.Text = "HEIF Quality: 0 - 99. Default: 50. Use 100 for lossless mode.";
}
if (formatStrTrim == "JPEG XL")
{
await LoadQuality(formatStrTrim, 100, 0);
selectedFormat = Program.ImageFormat.JXL;
formatQualityLabel.Text = "100 is lossless, everything lower will use a fixed lossy quality level. WIP!";
}
CheckDelSourceFormat();
}
async Task LoadQuality(string formatStrTrim, int defaultMin, int defaultMax)
{
qualityCombox.Text = await Config.Get("qMin" + formatStrTrim, defaultMin.ToString());
qualityMaxCombox.Text = (await Config.Get("qMax" + formatStrTrim, defaultMax.ToString())).Replace("0", "");
}
void ClearQuality()
{
qualityCombox.Text = "";
qualityMaxCombox.Text = "";
}
void CheckDelSourceFormat ()
{
delSrcCbox.Enabled = true;
if(formatCombox.Text.Trim().ToLower() == Program.currentExt.ToLower())
{
delSrcCbox.Checked = false;
delSrcCbox.Enabled = false;
}
}
private void extTbox_TextChanged (object sender, EventArgs e)
{
Program.currentExt = extTbox.Text.Trim();
CheckDelSourceFormat();
}
private void DoScaleBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
if(scaleResampleCombox.SelectedIndex == 0)
ScaleTabHelper.ScaleUsingPath(minScaleCombox, maxScaleCombox, filterModeCombox);
if(scaleResampleCombox.SelectedIndex == 1)
ScaleTabHelper.ResampleUsingPath(minScaleCombox, maxScaleCombox, filterModeCombox, resampleReupscaleFilterBox);
}
private void autoLevelBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
AdjustUtils.AutoLevel(Program.currentDir, Program.currentExt, recursiveCbox.Checked);
}
private void remAlphaBlack_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
ColorUtils.RemTransparencyDir(ColorUtils.NoAlphaMode.Fill);
}
private void delSmallImagesBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
int minSize = int.Parse(delSmallImagesSizeCombox.Text);
ImageSizeFilterUtils.SizeMode sizeMode = ImageSizeFilterUtils.SizeMode.Height;
if (delImgsMode.SelectedIndex == 1) sizeMode = ImageSizeFilterUtils.SizeMode.Width;
if (delImgsMode.SelectedIndex == 2) sizeMode = ImageSizeFilterUtils.SizeMode.LongerSide;
if (delImgsMode.SelectedIndex == 3) sizeMode = ImageSizeFilterUtils.SizeMode.ShorterSide;
if (delImgsMode.SelectedIndex == 4) sizeMode = ImageSizeFilterUtils.SizeMode.EitherSide;
if (delImgsMode.SelectedIndex == 5) sizeMode = ImageSizeFilterUtils.SizeMode.BothSides;
ImageSizeFilterUtils.Operator op = ImageSizeFilterUtils.Operator.IsNot;
if (delImgOperator.SelectedIndex == 1) op = ImageSizeFilterUtils.Operator.Is;
if (delImgOperator.SelectedIndex == 2) op = ImageSizeFilterUtils.Operator.IsSmaller;
if (delImgOperator.SelectedIndex == 3) op = ImageSizeFilterUtils.Operator.IsBigger;
if (delImgOperator.SelectedIndex == 4) op = ImageSizeFilterUtils.Operator.Divisible;
if (delImgOperator.SelectedIndex == 5) op = ImageSizeFilterUtils.Operator.NotDivisible;
OtherUtils.DelSmallImgsDir(minSize, sizeMode, op);
}
private void delFilesNotMatchingExtBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
OtherUtils.DelNotMatchingWildcard(recursiveCbox.Checked);
}
private void groupNormalsBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
OtherUtils.GroupNormalsWithTex(normalSuffixCombox.Text, diffSuffixCombox.Text, lowercaseCbox.Checked);
}
private void applyColorDepthBtn_Click (object sender, EventArgs e)
{
if(!Program.IsPathValid(Program.currentDir)) return;
if(colorDepthCombox.SelectedIndex == 0) ColorUtils.SetColorDepthDir(24);
if(colorDepthCombox.SelectedIndex == 1) ColorUtils.SetColorDepthDir(16);
if(colorDepthCombox.SelectedIndex == 2) ColorUtils.SetColorDepthDir(12);
if(colorDepthCombox.SelectedIndex == 3) ColorUtils.SetColorDepthDir(8);
if(colorDepthCombox.SelectedIndex == 4) ColorUtils.SetColorDepthDir(7);
if(colorDepthCombox.SelectedIndex == 5) ColorUtils.SetColorDepthDir(6);
if(colorDepthCombox.SelectedIndex == 6) ColorUtils.SetColorDepthDir(5);
if(colorDepthCombox.SelectedIndex == 7) ColorUtils.SetColorDepthDir(4);
}
private void recursiveCbox_CheckedChanged (object sender, EventArgs e)
{
IOUtils.recursive = recursiveCbox.Checked;
}
private void formatOptionsBtn_Click (object sender, EventArgs e)
{
if (selectedFormat == Program.ImageFormat.JPG)
new JpegOptionsWindow().Show();
if (selectedFormat == Program.ImageFormat.DDS)
new DdsOptionsWindow().Show();
if(selectedFormat == Program.ImageFormat.FLIF)
new FlifOptionsWindow().Show();
if (selectedFormat == Program.ImageFormat.PNG)
new PngOptionsWindow().Show();
}
private void MainForm_Activated (object sender, EventArgs e)
{
formatCombox_SelectedIndexChanged(null, null);
scaleModeCombox_SelectedIndexChanged(null, null);
appendFilterCbox_CheckedChanged(null, null);
noOverwriteCbox_CheckedChanged(null, null);
}
private void scaleModeCombox_SelectedIndexChanged (object sender, EventArgs e)
{
onlyDownscaleCbox.Enabled = true;
if(scaleModeCombox.SelectedIndex == 0)
{
ScaleUtils.currMode = ScaleUtils.ScaleMode.Percentage;
onlyDownscaleCbox.Enabled = false;
}
if(scaleModeCombox.SelectedIndex == 1)
ScaleUtils.currMode = ScaleUtils.ScaleMode.Height;
if(scaleModeCombox.SelectedIndex == 2)
ScaleUtils.currMode = ScaleUtils.ScaleMode.Width;
if(scaleModeCombox.SelectedIndex == 3)
ScaleUtils.currMode = ScaleUtils.ScaleMode.LongerSide;
if(scaleModeCombox.SelectedIndex == 4)
ScaleUtils.currMode = ScaleUtils.ScaleMode.ShorterSide;
}
private void appendFilterCbox_CheckedChanged (object sender, EventArgs e)
{
ScaleUtils.appendFiltername = appendFilterCbox.Checked;
}
private void noOverwriteCbox_CheckedChanged (object sender, EventArgs e)
{
ScaleUtils.dontOverwrite = noOverwriteCbox.Checked;
}
private void MainForm_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void MainForm_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach(string file in files)
{
if(IOUtils.IsPathDirectory(file))
{
Logger.Log("Setting directory to " + file);
Program.currentDir = file;
pathTextbox.Text = file;
}
else
{
Logger.Log("Previewing " + file + "...");
Program.PreviewImage(file);
}
}
}
private void addNoiseBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
EffectsTabHelper.NoiseApply();
}
private void button2_Click (object sender, EventArgs e)
{
bool suffix = suffixPrefixCombox.SelectedIndex != 0;
if(String.IsNullOrWhiteSpace(suffixPrefixTbox.Text))
Logger.Log("Can't add empty text to filenames!");
else
OtherUtils.AddSuffixPrefixDir(suffixPrefixTbox.Text, suffix);
}
private void replaceBtn_Click (object sender, EventArgs e)
{
if(String.IsNullOrWhiteSpace(replaceInputTbox.Text))
Logger.Log("Can't replace an empty string!");
else
OtherUtils.ReplaceInFilenamesDir(replaceInputTbox.Text, replaceOutputTbox.Text);
}
private void nameMustContainTbox_TextChanged (object sender, EventArgs e)
{
IOUtils.nameMustContain = nameMustContainTbox.Text;
}
private void nameMustNotContainTbox_TextChanged (object sender, EventArgs e)
{
IOUtils.nameMustNotContain = nameMustNotContainTbox.Text;
}
private void alphaOffBtn_Click (object sender, EventArgs e)
{
ColorUtils.RemTransparencyDir(ColorUtils.NoAlphaMode.Off);
}
private void tabPage1_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void tabPage1_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
ConvertTabHelper.ConvertFileList(files, qualityCombox, qualityMaxCombox, selectedFormat, delSrcCbox);
}
private void tabPage2_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void tabPage2_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if(scaleResampleCombox.SelectedIndex == 0)
ScaleTabHelper.ScaleFileList(files, minScaleCombox, maxScaleCombox, filterModeCombox);
if(scaleResampleCombox.SelectedIndex == 1)
ScaleTabHelper.ResampleFileList(files, minScaleCombox, maxScaleCombox, filterModeCombox, resampleReupscaleFilterBox);
}
private void saveCfgBtn_Click (object sender, EventArgs e)
{
ConfigParser.SaveGuiElement(fileOperationsNoFilter);
ConfigParser.SaveGuiElement(filenameReplaceIncludeExt);
ConfigParser.SaveGuiElement(backgroundColor);
ConfigParser.SaveGuiElement(procThreads);
Logger.Log("Saved config file.");
}
private void tabPage6_Enter (object sender, EventArgs e)
{
ConfigParser.LoadGuiElement(fileOperationsNoFilter);
ConfigParser.LoadGuiElement(filenameReplaceIncludeExt);
ConfigParser.LoadGuiElement(backgroundColor);
ConfigParser.LoadGuiElement(procThreads);
}
private void blurPrevBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
EffectsTabHelper.BlurPreview();
}
public void SetNoiseVars ()
{
EffectsTabHelper.useGaussNoise = gaussNoiseCbox.Checked;
EffectsTabHelper.useLapNoise = lapNoiseCbox.Checked;
EffectsTabHelper.usePoiNoise = poiNoiseCbox.Checked;
EffectsTabHelper.useUniNoise = uniNoiseCbox.Checked;
EffectsTabHelper.attenMin = int.Parse(attenuateCombox.Text.Trim());
if(String.IsNullOrWhiteSpace(attenuateMaxCombox.Text.Trim()))
EffectsTabHelper.attenMax = EffectsTabHelper.attenMin;
else
EffectsTabHelper.attenMax = int.Parse(attenuateMaxCombox.Text.Trim());
EffectsTabHelper.monochrome = monoChrCbox.Checked;
}
public void SetBlurVars ()
{
EffectsTabHelper.blurRadiusMin = blurRadiusCombox.GetInt();
if(String.IsNullOrWhiteSpace(blurRadiusMaxCombox.Text.Trim()))
EffectsTabHelper.blurRadiusMax = EffectsTabHelper.blurRadiusMin;
else
EffectsTabHelper.blurRadiusMax = blurRadiusMaxCombox.GetInt();
}
public void SetMedianVars()
{
EffectsTabHelper.medianRadiusMin = medianRadiusMin.GetInt();
if (String.IsNullOrWhiteSpace(medianRadiusMax.Text.Trim()))
EffectsTabHelper.medianRadiusMax = EffectsTabHelper.medianRadiusMin;
else
EffectsTabHelper.medianRadiusMax = medianRadiusMax.GetInt();
}
private void blurBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
EffectsTabHelper.BlurApply();
}
private void noisePreviewBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
EffectsTabHelper.NoisePreview();
}
private void delMissingBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
OtherUtils.DelMissing(checkDirTbox.Text.Trim(), false);
}
private void delMissingTestBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
OtherUtils.DelMissing(checkDirTbox.Text.Trim(), true);
}
private void inpaintEraseBtn_Click(object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir)) if(Program.IsPathValid(Program.currentDir))
InpaintTabHelper.EraseDir(inpaintThinLines, inpaintThickLines, inpaintRings, inpaintBubbles, inpaintGrid, inpaintColorCombox, inpaintScaleCombox);
}
private void cropBtn_Click(object sender, EventArgs e)
{
if(cropTabControl.SelectedIndex == 0)
CropTabHelper.CropRelative(cropRelSizeMin, cropRelSizeMax, cropRelSizeMode, cropRelGrav);
if(cropTabControl.SelectedIndex == 1)
CropTabHelper.CropAbsolute(cropAbsW, cropAbsH, cropAbsGrav);
if(cropTabControl.SelectedIndex == 2)
CropTabHelper.CropDivisible(cropDivision, cropDivisibleGrav, cropDivisibleExpand);
if(cropTabControl.SelectedIndex == 3)
CropTabHelper.CropPadding(padPixMin, padPixMax, padMode);
if(cropTabControl.SelectedIndex == 4)
CropTabHelper.CropTiles(tilingW, tilingH, tileMode, tileDelSrc.Checked);
}
private void tabPage7_DragEnter (object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void tabPage7_DragDrop (object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
InpaintTabHelper.EraseFileList(files, inpaintThinLines, inpaintThickLines, inpaintRings, inpaintBubbles, inpaintGrid, inpaintColorCombox, inpaintScaleCombox);
}
private void colorLayerBtn_Click (object sender, EventArgs e)
{
if(Program.IsPathValid(Program.currentDir))
ColorUtils.LayerColorDir(colorLayerTbox.Text.Trim().Replace("#", ""));
}
private void rotateBtn_Click (object sender, EventArgs e)
{
if (!Program.IsPathValid(Program.currentDir)) return;
GeometryUtils.RotateMode rotateMode = GeometryUtils.RotateMode.Rot90;
if(geomRotationCombox.SelectedIndex == 1) rotateMode = GeometryUtils.RotateMode.Rot180;
if(geomRotationCombox.SelectedIndex == 2) rotateMode = GeometryUtils.RotateMode.Rot270;
if(geomRotationCombox.SelectedIndex == 3) rotateMode = GeometryUtils.RotateMode.Random;
if(geomRotationCombox.SelectedIndex == 4) rotateMode = GeometryUtils.RotateMode.RandomAll;
GeometryUtils.RotateDir(rotateMode);
}
private void flipBtn_Click (object sender, EventArgs e)
{
if (!Program.IsPathValid(Program.currentDir)) return;
GeometryUtils.FlipMode flipMode = GeometryUtils.FlipMode.Hor;
if(geomFlipAxis.SelectedIndex == 1) flipMode = GeometryUtils.FlipMode.Vert;
if(geomFlipAxis.SelectedIndex == 2) flipMode = GeometryUtils.FlipMode.Random;
GeometryUtils.FlipDir(flipMode);
}
private void renameCounterBtn_Click (object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
OtherUtils.RenameCounterDir(renameCounterMode.SelectedIndex, renameCounterPadding.SelectedIndex == 1, renameCounterStartAt.GetInt());
}
private void mergeAllBtn_Click (object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
CropUtils.MergeAllDir(mergeRowLength.GetInt());
}
private void edgeDetectBtn_Click (object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
EffectsUtils.EdgeDetectDir();
}
private void ditherBtn_Click (object sender, EventArgs e)
{
int colorsMin = ditherColorsMin.GetInt();
int colorsMax = colorsMin;
if(!string.IsNullOrWhiteSpace(ditherColorsMax.Text))
colorsMax = ditherColorsMax.GetInt();
if(ditherTypeCombox.SelectedIndex == 0) ColorUtils.DitherDir(colorsMin, colorsMax, ColorUtils.DitherType.FloydSteinberg);
if(ditherTypeCombox.SelectedIndex == 1) ColorUtils.DitherDir(colorsMin, colorsMax, ColorUtils.DitherType.Riemersma);
if(ditherTypeCombox.SelectedIndex == 2) ColorUtils.DitherDir(colorsMin, colorsMax, ColorUtils.DitherType.Ordered4x4);
if(ditherTypeCombox.SelectedIndex == 3) ColorUtils.DitherDir(colorsMin, colorsMax, ColorUtils.DitherType.Halftone4x4);
if (ditherTypeCombox.SelectedIndex == 4) ColorUtils.DitherDir(colorsMin, colorsMax, ColorUtils.DitherType.Random);
}
private void bgColorSelectBtn_Click (object sender, EventArgs e)
{
bgColorDialog.ShowDialog();
string colorStr = ColorTranslator.ToHtml(Color.FromArgb(bgColorDialog.Color.ToArgb())).Replace("#", "") + "FF";
backgroundColor.Text = colorStr;
}
private void zeropadBtn_Click (object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
OtherUtils.AddZeroPaddingDir(zeroPaddingCombox.GetInt());
}
private void layerColorPickerBtn_Click (object sender, EventArgs e)
{
layerColorDialog.ShowDialog();
string colorStr = ColorTranslator.ToHtml(Color.FromArgb(layerColorDialog.Color.ToArgb())).Replace("#", "") + "FF";
colorLayerTbox.Text = colorStr;
}
private void scaleResampleCombox_SelectedIndexChanged(object sender, EventArgs e)
{
SetResampleOptions(scaleResampleCombox.SelectedIndex == 1);
}
void SetResampleOptions (bool state)
{
resampleReupscaleFilterLabel.Visible = state;
resampleReupscaleFilterBox.Visible = state;
}
private void printInfoBtn_Click(object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
OtherUtils.PrintImageInfoDir();
}
private void deleteGrayscaleImgsBtn_Click(object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
ColorUtils.DeleteGrayscaleImgDir(grayscaleThreshTbox.GetFloat(), false);
}
private void deleteColorImgsBtn_Click(object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
ColorUtils.DeleteGrayscaleImgDir(grayscaleThreshTbox.GetFloat(), true);
}
private void removeBytesBtn_Click(object sender, EventArgs e)
{
if (Program.IsPathValid(Program.currentDir))
OtherUtils.RemoveBytesDir(removeBytesAmount.GetInt());
}
private void ditherTypeCombox_SelectedIndexChanged(object sender, EventArgs e)
{
bool usesColorAmount = (ditherTypeCombox.SelectedIndex == 0 || ditherTypeCombox.SelectedIndex == 1);
ditherColorsMin.Enabled = usesColorAmount;
ditherColorsMax.Enabled = usesColorAmount;
}
private void medianPreviewBtn_Click(object sender, EventArgs e)
{
EffectsTabHelper.MedianPreview();
}
private void medianFilterBtn_Click(object sender, EventArgs e)
{
EffectsTabHelper.MedianApply();
}
private void haloBtn_Click(object sender, EventArgs e)
{
int radMin = haloRadiusMin.GetInt();
int radMax = radMin;
if (!String.IsNullOrWhiteSpace(haloRadiusMax.Text.Trim()))
radMax = haloRadiusMax.GetInt();
EffectsUtils.HaloDir(radMin, radMax);
}
private void onlyDownscaleCbox_CheckedChanged(object sender, EventArgs e)
{
ScaleUtils.onlyDownscale = onlyDownscaleCbox.Checked;
}
private void SaveQuality (object sender, EventArgs e)
{
Config.Set("qMin" + GetFormatStr(), qualityCombox.GetInt().ToString());
Config.Set("qMax" + GetFormatStr(), qualityMaxCombox.GetInt().ToString());
}
}
}