Пример #1
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.");
        }
Пример #2
0
 public static void KillEsrgan(bool cleanup = true)
 {
     if (currentEsrganProcess == null || currentEsrganProcess.HasExited)
     {
         return;
     }
     cancelled = true;
     OSUtils.KillProcessTree(currentEsrganProcess.Id);
     if (cleanup)
     {
         IOUtils.ClearDir(Paths.imgInPath);
         IOUtils.ClearDir(Paths.imgOutPath);
         IOUtils.ClearDir(Paths.imgOutNcnnPath);
     }
 }
Пример #3
0
 public static void Cleanup()
 {
     try
     {
         IOUtils.ClearDir(Paths.previewPath);
         IOUtils.ClearDir(Paths.previewOutPath);
         IOUtils.ClearDir(Paths.clipboardFolderPath);
         IOUtils.ClearDir(Paths.imgInPath);
         IOUtils.ClearDir(Paths.imgOutPath);
         IOUtils.ClearDir(Paths.imgOutNcnnPath);
         IOUtils.ClearDir(Paths.tempImgPath.GetParentDir());
         IOUtils.ClearDir(Path.Combine(IOUtils.GetAppDataDir(), "giftemp"));
         IOUtils.DeleteIfExists(Path.Combine(Paths.presetsPath, "lastUsed"));
         IOUtils.ClearDir(Paths.compositionOut);
     }
     catch (Exception e)
     {
         Logger.Log("Error during cleanup: " + e.Message);
     }
 }
Пример #4
0
        public static async void BeforeAfterAnim(bool save, bool h264)
        {
            string ext = "gif";

            if (h264)
            {
                ext = "mp4";
            }

            DialogForm dialogForm = new DialogForm("Creating comparison " + ext.ToUpper() + "...");

            string tempPath   = Path.Combine(IOUtils.GetAppDataDir(), "giftemp");
            string framesPath = Path.Combine(tempPath, "frames");

            IOUtils.ClearDir(tempPath);
            Directory.CreateDirectory(framesPath);

            resultPreview = (Bitmap)ImgUtils.GetImage(Directory.GetFiles(IO.Paths.previewOutPath, "*.png.*", SearchOption.AllDirectories)[0]);

            Image image1 = originalPreview;
            Image image2 = resultPreview;

            if (Config.GetInt("comparisonUseScaling") == 1)
            {
                image1 = (Bitmap)ImgUtils.GetImage(Path.Combine(IO.Paths.previewPath, "preview.png.png"));
            }

            float scale = (float)image2.Width / (float)image1.Width;

            Logger.Log("Scale for animation: " + scale);

            string outpath = Path.Combine(tempPath, "comparison." + ext);

            if (image2.Width <= 2048 && image2.Height <= 2048)
            {
                image1.Scale(scale, InterpolationMode.NearestNeighbor).Save(Path.Combine(framesPath, "0.png"));
                image2.Save(Path.Combine(framesPath, "1.png"));
                if (h264)
                {
                    await FFmpegCommands.FramesToOneFpsMp4(framesPath, false, 14, 9, "", false);

                    File.Move(Path.Combine(tempPath, "frames." + ext), outpath);
                }
                else
                {
                    await FFmpeg.RunGifski(" -r 1 -W 2048 -q -o " + outpath.Wrap() + " \"" + framesPath + "/\"*.\"png\"");
                }

                if (save)
                {
                    string comparisonSavePath = Path.ChangeExtension(Program.lastFilename, null) + "-comparison." + ext;
                    File.Copy(outpath, comparisonSavePath, true);
                    dialogForm.Close();
                    Program.ShowMessage("Saved current comparison to:\n\n" + comparisonSavePath, "Message");
                }
                else
                {
                    StringCollection paths = new StringCollection();
                    paths.Add(outpath);
                    Clipboard.SetFileDropList(paths);
                    dialogForm.Close();
                    Program.ShowMessage("The " + ext.ToUpper() + " file has been copied. You can paste it into any folder.\n" +
                                        "Please note that pasting it into Discord or other programs won't work as the clipboard can't hold animated images.", "Message");
                }
            }
            else
            {
                Program.ShowMessage("The preview is too large for making an animation. Please create a smaller cutout or choose a different comparison type.", "Error");
            }

            dialogForm.Close();
        }