-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HEIF support, GUI improvements
- Loading branch information
N00MKRAD
committed
Oct 2, 2020
1 parent
f362121
commit f2314f7
Showing
37 changed files
with
55,329 additions
and
84 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Ionic.Zip; | ||
using MagickUtils.Properties; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MagickUtils.Interfaces | ||
{ | ||
class HeifInterface | ||
{ | ||
static string heifExePath; | ||
static string heifResPath; | ||
|
||
public static void Extract(bool overwrite = false) | ||
{ | ||
GetPaths(); | ||
|
||
if (File.Exists(heifExePath) && !overwrite) | ||
return; | ||
|
||
File.WriteAllBytes(heifResPath, Resources.heif); | ||
ZipFile zip = ZipFile.Read(heifResPath); | ||
foreach (ZipEntry e in zip) | ||
e.Extract(IOUtils.GetAppDataDir(), ExtractExistingFileAction.OverwriteSilently); | ||
|
||
Program.Print("[HeifInterface] Extratced HEIF resources to " + heifExePath); | ||
} | ||
|
||
static void GetPaths() | ||
{ | ||
heifResPath = Path.Combine(IOUtils.GetAppDataDir(), "heif.zip"); | ||
heifExePath = Path.Combine(IOUtils.GetAppDataDir(), "heif", "heif-enc.exe"); | ||
} | ||
|
||
public static string EncodeImage (string path, int q, bool deleteSrc) | ||
{ | ||
Extract(); | ||
string outPath = Path.ChangeExtension(path, null) + ".heic"; | ||
ProcessStartInfo psi; | ||
string args = " -q " + q + " -o " + outPath.WrapPath(true, true) + path.WrapPath(true, true); | ||
psi = new ProcessStartInfo { FileName = heifExePath, Arguments = args }; | ||
psi.WorkingDirectory = Path.GetDirectoryName(heifExePath); | ||
Program.Print("HEIF args:" + args); | ||
psi.WindowStyle = ProcessWindowStyle.Hidden; | ||
Process heifProcess = new Process { StartInfo = psi }; | ||
heifProcess.Start(); | ||
heifProcess.WaitForExit(); | ||
Program.Print("Done converting " + path); | ||
if (deleteSrc) | ||
DelSource(path, outPath); | ||
return outPath; | ||
} | ||
|
||
static void DelSource(string sourcePath, string newPath) | ||
{ | ||
if (Path.GetExtension(sourcePath).ToLower() == Path.GetExtension(newPath).ToLower()) | ||
{ | ||
Program.Print("-> Not deleting " + Path.GetFileName(sourcePath) + " as it was overwritten"); | ||
return; | ||
} | ||
Program.Print("-> Deleting source file: " + Path.GetFileName(sourcePath) + "..."); | ||
File.Delete(sourcePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.