Skip to content

Commit

Permalink
Added skigif for HQ gif comparisons, better DDS export options, log i…
Browse files Browse the repository at this point in the history
…s now only kept until next session
  • Loading branch information
N00MKRAD committed Sep 25, 2020
1 parent a5aec78 commit 41125c1
Show file tree
Hide file tree
Showing 27 changed files with 327 additions and 160 deletions.
7 changes: 4 additions & 3 deletions Code/Cupscale.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="HTAlt.WinForms" Version="0.1.5.1" />
<PackageReference Include="HTAlt.WinForms" Version="0.1.6" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.21.1" />
<PackageReference Include="TabControl" Version="2.1.2" />
<PackageReference Include="TeximpNet" Version="1.4.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-AnyCPU" />
Expand Down Expand Up @@ -107,4 +105,7 @@
<ItemGroup>
<Content Update="C:\Users\NMKD\.nuget\packages\ddsfiletypeplushack\1.0.4\build\\x86\DdsFileTypePlusIO_x86.dll" Link="ThirdParty\DdsFileTypePlusIO_x86.dll" />
</ItemGroup>
<ItemGroup>
<NativeLibs Remove="Resources\nvcompress.exe" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions Code/FFmpeg/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
Logger.Log("[FFmpeg] " + outLine.Data);
}

public static async Task RunGifski (string args)
{
Process ffmpeg = new Process();
ffmpeg.StartInfo.UseShellExecute = false;
ffmpeg.StartInfo.RedirectStandardOutput = true;
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.CreateNoWindow = true;
ffmpeg.StartInfo.FileName = "cmd.exe";
ffmpeg.StartInfo.Arguments = "/C cd /D " + Paths.esrganPath.WrapPath()
+ " & gifski.exe " + args;
Logger.Log("Running gifski...");
Logger.Log("cmd.exe " + ffmpeg.StartInfo.Arguments);
ffmpeg.OutputDataReceived += new DataReceivedEventHandler(OutputHandlerGifski);
ffmpeg.ErrorDataReceived += new DataReceivedEventHandler(OutputHandlerGifski);
ffmpeg.Start();
ffmpeg.BeginOutputReadLine();
ffmpeg.BeginErrorReadLine();
while (!ffmpeg.HasExited)
await Task.Delay(100);
Logger.Log("Done running gifski.");
}

static void OutputHandlerGifski (object sendingProcess, DataReceivedEventArgs outLine)
{
Logger.Log("[gifski] " + outLine.Data);
}

/*
public static string RunAndGetOutput (string args)
{
Expand Down
73 changes: 36 additions & 37 deletions Code/Forms/SettingsForm.Designer.cs

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

8 changes: 4 additions & 4 deletions Code/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void LoadSettings()

Config.LoadGuiElement(jpegQ);
Config.LoadGuiElement(webpQ);
Config.LoadGuiElement(ddsUseDxt);
Config.LoadGuiElement(ddsMipsAmount);
Config.LoadGuiElement(dxtMode);
Config.LoadGuiElement(ddsEnableMips);
}

private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
Expand All @@ -71,8 +71,8 @@ void SaveSettings()

Config.SaveGuiElement(jpegQ);
Config.SaveGuiElement(webpQ);
Config.SaveGuiElement(ddsUseDxt);
Config.SaveGuiElement(ddsMipsAmount);
Config.SaveGuiElement(dxtMode);
Config.SaveGuiElement(ddsEnableMips);
}

private void confAlphaBgColorBtn_Click(object sender, EventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions Code/IO/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private static string WriteDefaultValIfExists(string key)
"useNcnn" => WriteDefault("useNcnn", "False"),
"jpegQ" => WriteDefault("jpegQ", "95"),
"webpQ" => WriteDefault("webpQ", "95"),
"ddsUseDxt" => WriteDefault("ddsUseDxt", "True"),
"ddsMipsAmount" => WriteDefault("ddsMipsAmount", "0"),
"dxtMode" => WriteDefault("dxtMode", "BC1 (DXT1)"),
"ddsEnableMips" => WriteDefault("ddsEnableMips", "True"),
_ => null,
};
}
Expand Down
64 changes: 8 additions & 56 deletions Code/IO/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,6 @@ public static string GetExeDir()
return AppDomain.CurrentDomain.BaseDirectory;
}

public static Image GetImage(string path)
{
Logger.Log("IOUtils.GetImage: Reading Image from " + path);
using MemoryStream stream = new MemoryStream(File.ReadAllBytes(path));
Image img = Image.FromStream(stream);
Logger.Log("[OK]", true, true);
return img;
}

public static MagickImage GetMagickImage (string path)
{
Logger.Log("IOUtils.GetMagickImage: Reading Image from " + path);
MagickImage image;
if (Path.GetExtension(path).ToLower() == ".dds")
{
try
{
image = new MagickImage(path); // Try reading DDS with IM, fall back to DdsFileTypePlusHack if it fails
}
catch
{
Logger.Log("Failed to read DDS using Mackig.NET - Trying DdsFileTypePlusHack");
try
{
Surface surface = DdsFile.Load(path);
image = ConvertToMagickImage(surface);
image.HasAlpha = DdsFile.HasTransparency(surface);
}
catch (Exception e)
{
MessageBox.Show("This DDS format is incompatible.\n\n" + e.Message);
return null;
}
}
}
else
{
image = new MagickImage(path);
}
Logger.Log("[OK]", true, true);
return image;
}

public static MagickImage ConvertToMagickImage(Surface surface)
{
MagickImage result;
Bitmap bitmap = surface.CreateAliasedBitmap();
using (MemoryStream memoryStream = new MemoryStream())
{
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
memoryStream.Position = 0;
result = new MagickImage(memoryStream, new MagickReadSettings() { Format = MagickFormat.Png00 });
}
return result;
}

public static string[] ReadLines(string path)
{
List<string> lines = new List<string>();
Expand Down Expand Up @@ -174,6 +118,8 @@ private static void CopyWork(DirectoryInfo source, DirectoryInfo target, string

public static void DeleteContentsOfDir(string path)
{
if (!Directory.Exists(path))
return;
Logger.Log("Clearing " + path);
DirectoryInfo directoryInfo = new DirectoryInfo(path);
FileInfo[] files = directoryInfo.GetFiles();
Expand Down Expand Up @@ -382,5 +328,11 @@ public static int GetFilenameCounterLength(string file, string prefixToRemove =
string onlyNumbersFilename = Regex.Replace(filenameNoExt, "[^.0-9]", "");
return onlyNumbersFilename.Length;
}

public static void DeleteIfExists (string path)
{
if (File.Exists(path))
File.Delete(path);
}
}
}
2 changes: 2 additions & 0 deletions Code/IO/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class Paths
public static string imgOutPath;
public static string tempImgPath;
public static string clipboardFolderPath;
//public static string convertTempPath;
public static string progressLogfile;

public static void Init()
Expand All @@ -21,6 +22,7 @@ public static void Init()
previewOutPath = Path.Combine(IOUtils.GetAppDataDir(), "preview-out");
imgInPath = Path.Combine(IOUtils.GetAppDataDir(), "img-in");
imgOutPath = Path.Combine(IOUtils.GetAppDataDir(), "img-out");
//convertTempPath = Path.Combine(IOUtils.GetAppDataDir(), "convert-temp");
tempImgPath = Path.Combine(IOUtils.GetAppDataDir(), "loaded-img", "temp.png");
clipboardFolderPath = Path.Combine(IOUtils.GetAppDataDir(), "clipboard");
progressLogfile = Path.Combine(esrganPath, "prog");
Expand Down
7 changes: 6 additions & 1 deletion Code/IO/ShippedEsrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public static bool InstallationIsValid ()
requiredFiles.Add(Path.Combine(path, "ffmpeg.exe"));
requiredFiles.Add(Path.Combine(path, "esrgan-ncnn-vulkan.exe"));
requiredFiles.Add(Path.Combine(path, "pth2ncnn.exe"));
requiredFiles.Add(Path.Combine(path, "nvcompress.exe"));
requiredFiles.Add(Path.Combine(path, "nvtt.dll"));
requiredFiles.Add(Path.Combine(path, "gifski.exe"));

foreach(string dir in requiredDirs)
foreach (string dir in requiredDirs)
{
if (!Directory.Exists(dir))
{
Expand Down Expand Up @@ -79,6 +82,8 @@ public static async Task Install ()

path7za = Path.Combine(path, "7za.exe");
File.WriteAllBytes(path7za, Resources.x64_7za);
File.WriteAllBytes(Path.Combine(path, "nvcompress.exe"), Resources.nvcompress);
File.WriteAllBytes(Path.Combine(path, "nvtt.dll"), Resources.nvtt);
File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "esrgan.7z"), Resources.esrgan);
File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "ncnn.7z"), Resources.esrgan_ncnn);
File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "ffmpeg.7z"), Resources.ffmpeg);
Expand Down
Loading

0 comments on commit 41125c1

Please sign in to comment.