Skip to content

Commit

Permalink
Finished model tree, fixed support for certain formats (TGA, DDS), im…
Browse files Browse the repository at this point in the history
…proved alpha support
  • Loading branch information
N00MKRAD committed Sep 20, 2020
1 parent d00f2a3 commit 4f9cbcb
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 160 deletions.
72 changes: 28 additions & 44 deletions Code/Cupscale/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions Code/Cupscale/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public MainForm()
EsrganData.ReloadModelList();
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
MainUIHelper.Init(previewImg, modelCombox1, modelCombox2, prevOutputFormatCombox, prevOverwriteCombox);
MainUIHelper.Init(previewImg, model1TreeBtn, model2TreeBtn, prevOutputFormatCombox, prevOverwriteCombox);
BatchUpscaleUI.Init(batchOutDir, batchFileList);
Program.mainForm = this;
WindowState = FormWindowState.Maximized;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void chainRbtn_CheckedChanged(object sender, EventArgs e)

public void UpdateModelMode()
{
modelCombox2.Enabled = (interpRbtn.Checked || chainRbtn.Checked);
model2TreeBtn.Enabled = (interpRbtn.Checked || chainRbtn.Checked);
interpConfigureBtn.Visible = interpRbtn.Checked;
if (singleModelRbtn.Checked) MainUIHelper.currentMode = MainUIHelper.Mode.Single;
if (interpRbtn.Checked) MainUIHelper.currentMode = MainUIHelper.Mode.Interp;
Expand All @@ -157,12 +157,14 @@ public void UpdateModelMode()

private void interpConfigureBtn_Click(object sender, EventArgs e)
{
/*
if (modelCombox1.SelectedIndex == -1 || modelCombox2.SelectedIndex == -1)
{
MessageBox.Show("Please select two models for interpolation.", "Message");
return;
}
InterpForm interpForm = new InterpForm(modelCombox1.Text.Trim(), modelCombox2.Text.Trim());
*/
InterpForm interpForm = new InterpForm(model1TreeBtn.Text.Trim(), model1TreeBtn.Text.Trim());
}

private void batchTab_DragEnter(object sender, DragEventArgs e)
Expand Down Expand Up @@ -199,6 +201,7 @@ async Task DragNDrop (string [] array)
DialogForm loadingDialogForm = new DialogForm("Loading " + Path.GetFileName(path) +"...");
await Task.Delay(1);
MainUIHelper.ResetCachedImages();
Logger.Log("3");
if (!MainUIHelper.DroppedImageIsValid(path))
{
SetProgress(0f, "Ready.");
Expand All @@ -207,7 +210,10 @@ async Task DragNDrop (string [] array)
return;
}
File.Copy(path, Paths.tempImgPath, true);
await Upscale.Preprocessing(Paths.imgInPath);
//await Upscale.Preprocessing(Paths.tempImgPath.GetParentDir());
bool fillAlpha = !bool.Parse(Config.Get("alpha"));
await UpscaleProcessing.ConvertImageTo(path, Paths.tempImgPath, UpscaleProcessing.Format.PngFast, fillAlpha, false, false);
Logger.Log("Done Preprocessing");
previewImg.Image = IOUtils.GetImage(Paths.tempImgPath);
Program.lastFilename = path;
MainUIHelper.currentScale = 1;
Expand Down Expand Up @@ -248,7 +254,12 @@ private void copyCompToClipboardBtn_Click(object sender, EventArgs e)

private void model1TreeBtn_Click(object sender, EventArgs e)
{
new ModelSelectForm();
ModelSelectForm treeForm = new ModelSelectForm(model1TreeBtn, 1);
}

private void model2TreeBtn_Click(object sender, EventArgs e)
{
ModelSelectForm treeForm = new ModelSelectForm(model2TreeBtn, 2);
}
}
}
3 changes: 1 addition & 2 deletions Code/Cupscale/PreviewMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ public static void Merge()
offsetX *= num;
offsetY *= num;
Logger.Log("Merging " + outputCutoutPath + " onto " + Program.lastFilename + " using offset " + offsetX + "x" + offsetY);
MagickImage sourceImg = new MagickImage(Program.lastFilename);
MagickImage sourceImg = new MagickImage(Paths.tempImgPath);
MagickImage cutout = new MagickImage(outputCutoutPath);
sourceImg.FilterType = Program.currentFilter;
Logger.Log("Scaling preview-input-scaled.png with filter " + sourceImg.FilterType + " which should match " + Program.currentFilter);
sourceImg.Resize(new Percentage(num * 100));
string scaledPrevPath = Path.Combine(Paths.previewOutPath, "preview-input-scaled.png");
sourceImg.Format = MagickFormat.Png;
Expand Down
2 changes: 2 additions & 0 deletions Code/Cupscale/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal static class Program
public static string lastFilename;
public static string lastDirPath;
public static string lastModelName;
public static string currentModel1;
public static string currentModel2;
public static FilterType currentFilter = FilterType.Point;

public static List<Form> currentTemporaryForms = new List<Form>(); // Temp forms that get closed when something gets cancelled
Expand Down
19 changes: 11 additions & 8 deletions Code/Cupscale/Upscale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,31 @@ public static ModelData GetModelData()

if (currentMode == Mode.Single)
{
string mdl1 = GetMdl(model1);
string mdl1 = Program.currentModel1;
if (string.IsNullOrWhiteSpace(mdl1)) return mdl;
mdl = new ModelData(mdl1, null, ModelData.ModelMode.Single);
}
if (currentMode == Mode.Interp)
{
string mdl1 = GetMdl(model1);
string mdl2 = GetMdl(model2);
string mdl1 = Program.currentModel1;
string mdl2 = Program.currentModel2;
if (string.IsNullOrWhiteSpace(mdl1) || string.IsNullOrWhiteSpace(mdl2)) return mdl;
mdl = new ModelData(mdl1, mdl2, ModelData.ModelMode.Interp, interpValue);
}
if (currentMode == Mode.Chain)
{
string mdl1 = GetMdl(model1);
string mdl2 = GetMdl(model2);
string mdl1 = Program.currentModel1;
string mdl2 = Program.currentModel2;
if (string.IsNullOrWhiteSpace(mdl1) || string.IsNullOrWhiteSpace(mdl2)) return mdl;
mdl = new ModelData(mdl1, mdl2, ModelData.ModelMode.Chain);
}

return mdl;
}

public static async Task Preprocessing (string path)
public static async Task Preprocessing (string path, bool appendExt = false)
{
Logger.Log("Preprocessing: " + path);
bool fillAlpha = !bool.Parse(Config.Get("alpha"));
await UpscaleProcessing.ConvertImages(path, UpscaleProcessing.Format.PngFast, fillAlpha);
}
Expand Down Expand Up @@ -102,9 +103,10 @@ public static async Task FilenamePostprocessing ()
await Program.PutTaskDelay();
}

public static string GetMdl(ComboBox box)
/*
public static string GetMdl(Button btn)
{
string mdl = box.Text.Trim();
string mdl = btn.Text.Trim();
EsrganData.ReloadModelList();
if (!EsrganData.models.Contains(mdl))
{
Expand All @@ -115,5 +117,6 @@ public static string GetMdl(ComboBox box)
}
return mdl;
}
*/
}
}
37 changes: 19 additions & 18 deletions Code/Forms/ModelSelectForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f9cbcb

Please sign in to comment.