Add possibility to convert all images to ico (no restriction on size anymore)

This commit is contained in:
Tichau committed 2016-02-02 08:51:23 +01:00
1 parent ad051308e1
commit 6594d95120
2 files changed
+80

No files matched your search

@@ -0,0 +1,76 @@
// <copyright file="ConversionJob_Ico.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.ConversionJobs
{
using System;
using System.IO;
public class ConversionJob_Ico : ConversionJob
{
private string intermediateFilePath;
private ConversionJob pngConversionJob;
private ConversionJob icoConversionJob;
public ConversionJob_Ico(ConversionPreset conversionPreset) : base(conversionPreset)
{
}
protected override void Initialize()
{
base.Initialize();
if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
}
// Generate intermediate file path.
string fileName = Path.GetFileName(this.OutputFilePath);
string tempPath = Path.GetTempPath();
this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".png");
// Convert input in png file to send it to ffmpeg for the ico conversion.
ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray());
intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, "True");
intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, "256");
this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath);
this.pngConversionJob.PrepareConversion(this.InputFilePath, this.intermediateFilePath);
// Convert png file into ico.
this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset);
this.icoConversionJob.PrepareConversion(this.intermediateFilePath, this.OutputFilePath);
}
protected override void Convert()
{
if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
}
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert image to PNG (intermediate format).");
this.pngConversionJob.StartConvertion();
if (this.pngConversionJob.State != ConversionState.Done)
{
this.ConversionFailed(this.pngConversionJob.ErrorMessage);
return;
}
Diagnostics.Debug.Log(string.Empty);
Diagnostics.Debug.Log("Convert png intermediate image to ICO.");
this.icoConversionJob.StartConvertion();
if (this.icoConversionJob.State != ConversionState.Done)
{
this.ConversionFailed(this.icoConversionJob.ErrorMessage);
return;
}
Diagnostics.Debug.Log("Delete intermediate file {0}.", this.intermediateFilePath);
File.Delete(this.intermediateFilePath);
}
}
}
@@ -463,6 +463,8 @@ namespace FileConverter
switch (settingsKey)
{
case ConversionPreset.ConversionSettingKeys.ImageScale:
case ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2:
case ConversionPreset.ConversionSettingKeys.ImageMaximumSize:
return true;
}
@@ -686,6 +688,8 @@ namespace FileConverter
public const string AudioBitrate = "AudioBitrate";
public const string ImageQuality = "ImageQuality";
public const string ImageScale = "ImageScale";
public const string ImageClampSizePowerOf2 = "ImageClampSizePowerOf2";
public const string ImageMaximumSize = "ImageMaximumSize";
public const string VideoQuality = "VideoQuality";
public const string VideoEncodingSpeed = "VideoEncodingSpeed";
public const string VideoScale = "VideoScale";