From 108260fc430b2578e2ced01030a39fe353b04631 Mon Sep 17 00:00:00 2001 From: Techpotato1 Date: Sun, 27 Jul 2025 20:27:52 -0700 Subject: [PATCH] add avif support --- .../ConversionJobs/ConversionJobFactory.cs | 3 +- .../ConversionJob_ImageMagick.cs | 9 +++++ .../ConversionPreset/ConversionPreset.cs | 8 +++++ Application/FileConverter/Helpers.cs | 4 ++- Application/FileConverter/OutputType.cs | 1 + .../FileConverter/Settings.default.xml | 34 +++++++++++++++++++ 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs index 7b20167..34886bb 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs @@ -43,7 +43,8 @@ namespace FileConverter.ConversionJobs return new ConversionJob_ImageMagick(conversionPreset, inputFilePath); } - if (conversionPreset.OutputType == OutputType.Jpg || + if (conversionPreset.OutputType == OutputType.Avif || + conversionPreset.OutputType == OutputType.Jpg || conversionPreset.OutputType == OutputType.Png || conversionPreset.OutputType == OutputType.Webp) { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs index 5bab71f..312431f 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs @@ -76,6 +76,11 @@ namespace FileConverter.ConversionJobs string inputExtension = System.IO.Path.GetExtension(this.InputFilePath).ToLowerInvariant(); switch (inputExtension) { + case ".avif": + // Explicitly set AVIF format for proper reading + readSettings.Format = MagickFormat.Avif; + break; + case ".cr2": // Requires an explicit image format otherwise the image is interpreted as a TIFF image. readSettings.Format = MagickFormat.Cr2; @@ -211,6 +216,10 @@ namespace FileConverter.ConversionJobs Debug.Log($"Convert image (output: {this.OutputFilePath})."); switch (this.ConversionPreset.OutputType) { + case OutputType.Avif: + image.Quality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality); + break; + case OutputType.Png: // http://stackoverflow.com/questions/27267073/imagemagick-lossless-max-compression-for-png image.Quality = 95; diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 1204ea6..d06d203 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -504,6 +504,14 @@ namespace FileConverter break; // Images + case OutputType.Avif: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality, "50"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale, "1"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageRotation, "0"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, "False"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, "0"); + break; + case OutputType.Gif: this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation, "0"); diff --git a/Application/FileConverter/Helpers.cs b/Application/FileConverter/Helpers.cs index a1e3b02..6387f33 100644 --- a/Application/FileConverter/Helpers.cs +++ b/Application/FileConverter/Helpers.cs @@ -20,7 +20,7 @@ namespace FileConverter public static class Helpers { public static readonly string[] CompatibleInputExtensions = { - "3gp","3gpp","aac","aiff","ape","arw","avi","bik","bmp","cda","cr2","dds","dng","doc","docx", + "3gp","3gpp","aac","aiff","ape","arw","avi","avif","bik","bmp","cda","cr2","dds","dng","doc","docx", "exr","flac","flv","gif","heic","ico","jfif","jpg","jpeg","m4a","m4b","m4v","mkv","mov","mp3","mp4", "mpg","mpeg","nef","odp","ods","odt","oga","ogg","ogv","opus","pdf","png","ppt","pptx","psd", "raf", "rm","svg","tga","tif","tiff", "ts", "vob","wav","webm","webp","wma","wmv","xls","xlsx" @@ -65,6 +65,7 @@ namespace FileConverter return InputCategoryNames.Video; case "arw": + case "avif": case "bmp": case "cr2": case "dds": @@ -212,6 +213,7 @@ namespace FileConverter case OutputType.Webm: return category == InputCategoryNames.Video || category == InputCategoryNames.AnimatedImage; + case OutputType.Avif: case OutputType.Ico: case OutputType.Jpg: case OutputType.Png: diff --git a/Application/FileConverter/OutputType.cs b/Application/FileConverter/OutputType.cs index fda2caf..294ecdf 100644 --- a/Application/FileConverter/OutputType.cs +++ b/Application/FileConverter/OutputType.cs @@ -8,6 +8,7 @@ namespace FileConverter Aac, Avi, + Avif, Flac, Gif, Ico, diff --git a/Application/FileConverter/Settings.default.xml b/Application/FileConverter/Settings.default.xml index 420de1d..136b251 100644 --- a/Application/FileConverter/Settings.default.xml +++ b/Application/FileConverter/Settings.default.xml @@ -502,6 +502,7 @@ xcf arw + avif bmp cr2 dds @@ -550,6 +551,7 @@ xcf arw + avif bmp cr2 dds @@ -577,9 +579,41 @@ (p)(f) + + xcf + arw + avif + bmp + cr2 + dds + dng + exr + heic + ico + jfif + jpg + jpeg + nef + png + psd + raf + svg + tga + tif + tiff + webp + None + + + + + + (p)(f) + xcf arw + avif bmp cr2 dds