diff --git a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs index b63601c..8044751 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs @@ -12,14 +12,20 @@ namespace FileConverter.ConversionJobs extension = extension.ToLowerInvariant().Substring(1, extension.Length - 1); if (extension == "cda") { - conversionJob = new ConversionJob_ExtractCDA(conversionPreset); - } - else - { - conversionJob = new ConversionJob_FFMPEG(conversionPreset); + return new ConversionJob_ExtractCDA(conversionPreset); } - return conversionJob; + if (conversionPreset.OutputType == OutputType.Ico) + { + return new ConversionJob_Ico(conversionPreset); + } + + if (PathHelpers.GetExtensionCategory(extension) == PathHelpers.InputCategoryNames.Image) + { + return new ConversionJob_ImageMagick(conversionPreset); + } + + return new ConversionJob_FFMPEG(conversionPreset); } } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 5f21fab..047fada 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -76,6 +76,25 @@ namespace FileConverter.ConversionJobs break; + case OutputType.Avi: + { + // https://trac.ffmpeg.org/wiki/Encode/MPEG-4 + int videoEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality); + int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); + + float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); + string scaleArgs = string.Empty; + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + } + + string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), scaleArgs); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + } + + break; + case OutputType.Flac: { // http://taer-naguur.blogspot.fr/2013/11/flac-audio-encoding-with-ffmpeg.html @@ -93,6 +112,24 @@ namespace FileConverter.ConversionJobs break; + case OutputType.Jpg: + { + int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality); + + float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale); + string scaleArgs = string.Empty; + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + } + + string encoderArgs = string.Format("-q:v {0} {1}", this.JPGQualityToQualityIndex(encodingQuality), scaleArgs); + + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + } + + break; + case OutputType.Mp3: { string encoderArgs = string.Empty; @@ -117,25 +154,6 @@ namespace FileConverter.ConversionJobs break; - case OutputType.Avi: - { - // https://trac.ffmpeg.org/wiki/Encode/MPEG-4 - int videoEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality); - int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); - - float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); - string scaleArgs = string.Empty; - if (Math.Abs(scaleFactor - 1f) >= 0.005f) - { - scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); - } - - string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), scaleArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); - } - - break; - case OutputType.Mkv: { // https://trac.ffmpeg.org/wiki/Encode/H.264 @@ -183,24 +201,6 @@ namespace FileConverter.ConversionJobs break; - case OutputType.Jpg: - { - int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality); - - float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale); - string scaleArgs = string.Empty; - if (Math.Abs(scaleFactor - 1f) >= 0.005f) - { - scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); - } - - string encoderArgs = string.Format("-q:v {0} {1}", this.JPGQualityToQualityIndex(encodingQuality), scaleArgs); - - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); - } - - break; - case OutputType.Wav: { EncodingMode encodingMode = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioEncodingMode); diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs new file mode 100644 index 0000000..2b00259 --- /dev/null +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs @@ -0,0 +1,95 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +using FileConverter.Diagnostics; + +namespace FileConverter.ConversionJobs +{ + using System; + using ImageMagick; + + public class ConversionJob_ImageMagick : ConversionJob + { + public ConversionJob_ImageMagick() : base() + { + } + + public ConversionJob_ImageMagick(ConversionPreset conversionPreset) : base(conversionPreset) + { + } + + protected override void Initialize() + { + base.Initialize(); + + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + } + + protected override void Convert() + { + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + using (MagickImage image = new MagickImage(this.InputFilePath)) + { + Debug.Log("Load image {0} succeed.", this.InputFilePath); + + float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale); + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + Debug.Log("Apply scale factor: {0}%.", scaleFactor * 100); + + image.Scale(new Percentage(scaleFactor * 100f)); + } + + bool clampSizeToPowerOf2 = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2); + if (clampSizeToPowerOf2) + { + int referenceSize = System.Math.Min(image.Width, image.Height); + int size = 2; + while (size * 2 < referenceSize) + { + size *= 2; + } + + Debug.Log("Clamp size to the nearest power of 2 size (from {0}x{1} to {2}x{2}).", image.Width, image.Height, size); + + image.Scale(size, size); + } + + int maximumSize = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize); + if (maximumSize > 0) + { + int width = System.Math.Min(image.Width, maximumSize); + int height = System.Math.Min(image.Height, maximumSize); + + Debug.Log("Clamp size to maximum size of {2}x{2} (from {0}x{1} to {2}x{3}).", image.Width, image.Height, width, height); + + image.Scale(width, height); + } + + Debug.Log("Convert image (output: {0}).", this.OutputFilePath); + switch (this.ConversionPreset.OutputType) + { + case OutputType.Png: + image.Quality = 100; + break; + + case OutputType.Jpg: + image.Quality = 100; + break; + + default: + this.ConversionFailed(string.Format("Unsupported output format {0}.", this.ConversionPreset.OutputType)); + return; + } + + image.Write(this.OutputFilePath); + } + } + } +} diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 1687279..1bcdda8 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -46,16 +46,12 @@ - - ..\..\packages\Magick.NET-Q16-x64.7.0.0.0022\lib\net40-client\Magick.NET-x64.dll + + ..\..\packages\Magick.NET-Q16-AnyCPU.7.0.0.0022\lib\net40-client\Magick.NET-AnyCPU.dll True - ..\..\packages\Magick.NET-Q16-x64.7.0.0.0022\lib\net40-client\Magick.NET.Core.dll - True - - - ..\..\packages\Magick.NET-Q16-x64.7.0.0.0022\lib\net40-client\Magick.NET.Wrapper-x64.dll + ..\..\packages\Magick.NET-Q16-AnyCPU.7.0.0.0022\lib\net40-client\Magick.NET.Core.dll True @@ -103,6 +99,8 @@ + + diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs index 077aeb4..3cfc225 100644 --- a/Application/FileConverter/PathHelpers.cs +++ b/Application/FileConverter/PathHelpers.cs @@ -104,7 +104,11 @@ namespace FileConverter case "jpg": case "jpeg": case "png": + case "psd": + case "tga": case "tiff": + case "svg": + case "xcf": return InputCategoryNames.Image; } diff --git a/Application/FileConverter/packages.config b/Application/FileConverter/packages.config index b0e9377..a69981a 100644 --- a/Application/FileConverter/packages.config +++ b/Application/FileConverter/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 1abd0f2..2b6fffd 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -80,6 +80,12 @@ + + + + + + @@ -108,7 +114,7 @@ - +