Пример #1
0
        private async void upscaleBtn_Click(object sender, EventArgs e)
        {
            if (Program.busy)
            {
                return;
            }

            if (!MainUIHelper.HasValidModelSelection())
            {
                Program.ShowMessage("Invalid model selection.\nMake sure you have selected a model and that the file still exists.", "Error");
                return;
            }

            bool useNcnn = (Config.Get("cudaFallback").GetInt() == 2 || Config.Get("cudaFallback").GetInt() == 3);

            if (useNcnn && !Program.mainForm.HasValidNcnnModelSelection())
            {
                Program.ShowMessage("Invalid model selection - NCNN does not support interpolation or chaining.", "Error");
                return;
            }

            if (Config.GetBool("reloadImageBeforeUpscale"))
            {
                ReloadImage();
            }
            UpdateResizeMode();
            if (htTabControl.SelectedIndex == 0)
            {
                await MainUIHelper.UpscaleImage();
            }
            if (htTabControl.SelectedIndex == 1)
            {
                await BatchUpscaleUI.Run(preprocessMode.SelectedIndex == 0);
            }
        }
Пример #2
0
 public void ResetToLastState()
 {
     previewImg.Image = resetState.image;
     previewImg.Zoom  = resetState.zoom;
     previewImg.AutoScrollPosition = resetState.autoScrollPosition;                      // This doesn't work correctly :/
     MainUIHelper.ResetCachedImages();
     resetImageOnMove = false;
 }
Пример #3
0
 private async void refreshPreviewFullBtn_Click(object sender, EventArgs e)
 {
     if (Config.GetBool("reloadImageBeforeUpscale"))
     {
         ReloadImage();
     }
     UpdateResizeMode();
     MainUIHelper.UpscalePreview(true);
 }
Пример #4
0
 public MainForm()
 {
     CheckForIllegalCrossThreadCalls = false;
     InitializeComponent();
     MainUIHelper.Init(previewImg, model1TreeBtn, model2TreeBtn, prevOutputFormatCombox, prevOverwriteCombox);
     BatchUpscaleUI.Init(batchOutDir, batchFileList);
     Program.mainForm = this;
     WindowState      = FormWindowState.Maximized;
 }
Пример #5
0
        private void interpConfigureBtn_Click(object sender, EventArgs e)
        {
            if (!MainUIHelper.HasValidModelSelection())
            {
                Program.ShowMessage("Please select two models for interpolation.", "Message");
                return;
            }

            AdvancedModelsForm interpForm = new AdvancedModelsForm(model1TreeBtn.Text.Trim(), model2TreeBtn.Text.Trim());

            interpForm.ShowDialog();
        }
Пример #6
0
        async Task DragNDrop(string [] files)
        {
            Logger.Log("[MainUI] Dropped " + files.Length + " file(s), files[0] = " + files[0]);
            IOUtils.ClearDir(Paths.tempImgPath.GetParentDir());
            string     path = files[0];
            DialogForm loadingDialogForm = null;

            if (IOUtils.IsPathDirectory(path))
            {
                htTabControl.SelectedIndex = 1;
                int compatFilesAmount = IOUtils.GetAmountOfCompatibleFiles(path, true);
                batchDirLabel.Text = "Loaded " + path.Wrap() + " - Found " + compatFilesAmount + " compatible files.";
                BatchUpscaleUI.LoadDir(path);
                upscaleBtn.Text = "Upscale " + compatFilesAmount + " Images";
                return;
            }
            if (files.Length > 1)
            {
                htTabControl.SelectedIndex = 1;
                int compatFilesAmount = IOUtils.GetAmountOfCompatibleFiles(files);
                BatchUpscaleUI.LoadImages(files);
                batchDirLabel.Text = "Loaded " + compatFilesAmount + " compatible files.";
                upscaleBtn.Text    = "Upscale " + compatFilesAmount + " Images";
                return;
            }
            upscaleBtn.Text            = "Upscale And Save";
            htTabControl.SelectedIndex = 0;
            previewImg.Text            = "";
            SetProgress(0f, "Loading image...");
            loadingDialogForm = new DialogForm("Loading " + Path.GetFileName(path) + "...");
            await Task.Delay(20);

            MainUIHelper.ResetCachedImages();
            if (!MainUIHelper.DroppedImageIsValid(path))
            {
                SetProgress(0f, "Ready.");
                await Task.Delay(1);

                Program.CloseTempForms();
                return;
            }
            Program.lastFilename = path;
            ReloadImage(false);
            if (failed)
            {
                FailReset(); return;
            }
            SetHasPreview(false);
            loadingDialogForm.Close();
            SetRefreshPreviewBtns(true);
            SetProgress(0f, "Ready.");
        }
Пример #7
0
        private async void runBtn_Click(object sender, EventArgs e)
        {
            if (MainUIHelper.previewImg.Image == null || !File.Exists(Paths.tempImgPath))
            {
                Program.ShowMessage("No image loaded!", "Error");
                return;
            }
            Enabled    = false;
            cutoutMode = cropMode.SelectedIndex == 1;
            if (cutoutMode)
            {
                MainUIHelper.SaveCurrentCutout();
                currentSourcePath = Path.Combine(Paths.previewPath, "preview.png");
            }
            else
            {
                currentSourcePath = Paths.tempImgPath;
            }
            string[] lines = Regex.Split(modelPathsBox.Text, "\r\n|\r|\n");
            if (comparisonMode.SelectedIndex == 0)
            {
                string outpath = Path.Combine(Paths.imgOutPath, "!Original.png");
                await ImageProcessing.ConvertImage(currentSourcePath, GetSaveFormat(), false, ImageProcessing.ExtMode.UseNew, false, outpath);
                await ProcessImage(outpath, "Original");
            }
            for (int i = 0; i < lines.Length; i++)
            {
                if (!File.Exists(lines[i]))
                {
                    continue;
                }
                ModelData mdl = new ModelData(lines[i], null, ModelData.ModelMode.Single);
                await DoUpscale(i, mdl, !cutoutMode);
            }
            bool        vert       = compositionMode.SelectedIndex == 1;
            MagickImage merged     = ImgUtils.MergeImages(Directory.GetFiles(Paths.imgOutPath, "*.png", SearchOption.AllDirectories), vert, true);
            string      mergedPath = Path.Combine(Paths.imgOutPath, Path.GetFileNameWithoutExtension(Program.lastFilename) + "-composition");

            mergedPath = Path.ChangeExtension(mergedPath, GetSaveExt());
            merged.Write(mergedPath);
            await Upscale.CopyImagesTo(Program.lastFilename.GetParentDir());

            IOUtils.ClearDir(Paths.previewPath);
            Enabled = true;
            Program.ShowMessage("Saved model composition to " + Program.lastFilename.GetParentDir() + "\\" + Path.GetFileName(mergedPath), "Message");
        }
Пример #8
0
 private void openOutFolderBtn_Click(object sender, EventArgs e)
 {
     MainUIHelper.OpenLastOutputFolder();
 }
Пример #9
0
 private void refreshPreviewCutoutBtn_Click(object sender, EventArgs e)
 {
     UpdateResizeMode();
     MainUIHelper.UpscalePreview();
 }
Пример #10
0
 void UpdatePreviewInfo()
 {
     MainUIHelper.UpdatePreviewLabels(prevZoomLabel, prevSizeLabel, prevCutoutLabel);
 }