예제 #1
0
 private void previewImg_MouseUp(object sender, MouseEventArgs e)
 {
     PreviewMerger.ShowOutput();
 }
예제 #2
0
파일: ESRGAN.cs 프로젝트: gri-i/cupscale
        //public static bool cacheTiling = false;

        public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, bool cacheSplitDepth, bool alpha, PreviewMode mode, Backend backend, bool showTileProgress = true)
        {
            Program.cancelled = false;      // Reset cancel flag
            try
            {
                if (backend == Backend.NCNN)
                {
                    Program.lastModelName = mdl.model1Name;
                    await RunNcnn(inpath, outpath, mdl.model1Path);
                }
                else
                {
                    Program.mainForm.SetProgress(2f, "Starting ESRGAN...");
                    File.Delete(Paths.progressLogfile);
                    string modelArg = GetModelArg(mdl);
                    await RunJoey(inpath, outpath, modelArg, cacheSplitDepth, alpha, showTileProgress);
                }

                if (mode == PreviewMode.Cutout)
                {
                    await ScalePreviewOutput();

                    Program.mainForm.SetProgress(100f, "Merging into preview...");
                    await Program.PutTaskDelay();

                    PreviewMerger.Merge();
                    Program.mainForm.SetHasPreview(true);
                }
                if (mode == PreviewMode.FullImage)
                {
                    await ScalePreviewOutput();

                    Program.mainForm.SetProgress(100f, "Merging into preview...");
                    await Program.PutTaskDelay();

                    Image outImg   = ImgUtils.GetImage(Directory.GetFiles(Paths.previewOutPath, "preview.*", SearchOption.AllDirectories)[0]);
                    Image inputImg = ImgUtils.GetImage(Paths.tempImgPath);
                    PreviewUI.previewImg.Image = outImg;
                    PreviewUI.currentOriginal  = inputImg;
                    PreviewUI.currentOutput    = outImg;
                    PreviewUI.currentScale     = ImgUtils.GetScaleFloat(inputImg, outImg);
                    PreviewUI.previewImg.ZoomToFit();
                    Program.mainForm.SetHasPreview(true);
                    //Program.mainForm.SetProgress(0f, "Done.");
                }
            }
            catch (Exception e)
            {
                Program.mainForm.SetProgress(0f, "Cancelled.");
                if (Program.cancelled)
                {
                    return;
                }
                if (e.Message.Contains("No such file"))
                {
                    Program.ShowMessage("An error occured during upscaling.\nThe upscale process seems to have exited before completion!", "Error");
                }
                else
                {
                    Program.ShowMessage("An error occured during upscaling.", "Error");
                }
                Logger.Log("[ESRGAN] Upscaling Error: " + e.Message + "\n" + e.StackTrace);
            }
        }
예제 #3
0
 private void previewImg_MouseDown(object sender, MouseEventArgs e)
 {
     PreviewMerger.ShowOriginal();
 }
예제 #4
0
        public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, string tilesize, bool alpha, PreviewMode mode, Backend backend, bool showTileProgress = true)
        {
            bool useJoey = Config.GetInt("esrganVer") == 0;

            try
            {
                if (backend == Backend.NCNN)
                {
                    Program.mainForm.SetProgress(1f, "Loading ESRGAN-NCNN...");
                    DialogForm dialogForm = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14);
                    Program.lastModelName = mdl.model1Name;
                    await RunNcnn(inpath, outpath, mdl.model1Path);
                }
                else
                {
                    Program.mainForm.SetProgress(4f, "Starting ESRGAN...");
                    File.Delete(Paths.progressLogfile);
                    string modelArg = GetModelArg(mdl, useJoey);
                    if (useJoey)
                    {
                        await RunJoey(inpath, outpath, modelArg, tilesize, alpha, showTileProgress);
                    }
                    else
                    {
                        await Run(inpath, outpath, modelArg, tilesize, alpha, showTileProgress);
                    }
                }

                if (mode == PreviewMode.Cutout)
                {
                    await ScalePreviewOutput();

                    Program.mainForm.SetProgress(100f, "Merging into preview...");
                    await Program.PutTaskDelay();

                    PreviewMerger.Merge();
                    Program.mainForm.SetHasPreview(true);
                }
                if (mode == PreviewMode.FullImage)
                {
                    await ScalePreviewOutput();

                    Program.mainForm.SetProgress(100f, "Merging into preview...");
                    await Program.PutTaskDelay();

                    Image outImg   = ImgUtils.GetImage(Directory.GetFiles(Paths.previewOutPath, "*.png.*", SearchOption.AllDirectories)[0]);
                    Image inputImg = ImgUtils.GetImage(Paths.tempImgPath);
                    MainUIHelper.previewImg.Image = outImg;
                    MainUIHelper.currentOriginal  = inputImg;
                    MainUIHelper.currentOutput    = outImg;
                    MainUIHelper.currentScale     = ImgUtils.GetScaleFloat(inputImg, outImg);
                    MainUIHelper.previewImg.ZoomToFit();
                    Program.mainForm.SetHasPreview(true);
                    //Program.mainForm.SetProgress(0f, "Done.");
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("No such file"))
                {
                    Program.ShowMessage("An error occured during upscaling.\nThe upscale process seems to have exited before completion!", "Error");
                }
                else
                {
                    Program.ShowMessage("An error occured during upscaling.", "Error");
                }
                Logger.Log("[ESRGAN] Upscaling Error: " + e.Message + "\n" + e.StackTrace);
                Program.mainForm.SetProgress(0f, "Cancelled.");
            }
        }