Refactoring: created a OutputSettings class to contain all the output settings for writing files. Default the settings are loaded from the configuration, in a later version it will be possible to have separate settings for every destination and these can be configured at one place... the settings form.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1815 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-24 16:44:34 +00:00
parent 5902a3d236
commit e5fd88ebd3
21 changed files with 182 additions and 123 deletions

View file

@ -25,6 +25,7 @@ using System.IO;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
namespace Greenshot.Plugin {
[Serializable]
@ -73,6 +74,52 @@ namespace Greenshot.Plugin {
// Delegates for hooking up events.
public delegate void HotKeyHandler();
public class OutputSettings {
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private bool reduceColors;
public OutputSettings() {
Format = conf.OutputFileFormat;
JPGQuality = conf.OutputFileJpegQuality;
ReduceColors = conf.OutputFileReduceColors;
}
public OutputSettings(OutputFormat format) : this() {
Format = format;
}
public OutputSettings(OutputFormat format, int quality) : this(format) {
JPGQuality = quality;
}
public OutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) {
ReduceColors = reduceColors;
}
public OutputFormat Format {
get;
set;
}
public int JPGQuality {
get;
set;
}
public bool ReduceColors {
get {
// Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
if (OutputFormat.gif.Equals(Format)) {
return true;
}
return reduceColors;
}
set {
reduceColors = value;
}
}
}
/// <summary>
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
/// For Greenshot this is implmented in the PluginHelper
@ -87,29 +134,23 @@ namespace Greenshot.Plugin {
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="stream">The Stream to save to</param>
/// <param name="format">The format to save with (png, jpg etc)</param>
/// <param name="quality">Jpeg quality</param>
/// <param name="reduceColors">reduce the amount of colors to 256</param>
void SaveToStream(Image image, Stream stream, OutputFormat format, int quality, bool reduceColors);
/// <param name="outputSettings">OutputSettings</param>
void SaveToStream(Image image, Stream stream, OutputSettings outputSettings);
/// <summary>
/// Saves the image to a temp file (random name) using the specified outputformat
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="format">The format to save with (png, jpg etc)</param>
/// <param name="quality">Jpeg quality</param>
/// <param name="reduceColors">reduce the amount of colors to 256</param>
string SaveToTmpFile(Image image, OutputFormat outputFormat, int quality, bool reduceColors);
/// <param name="outputSettings">OutputSettings</param>
string SaveToTmpFile(Image image, OutputSettings outputSettings);
/// <summary>
/// Saves the image to a temp file, but the name is build with the capture details & pattern
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="captureDetails">captureDetails with the information to build the filename</param>
/// <param name="outputformat">The format to save with (png, jpg etc)</param>
/// <param name="quality">Jpeg quality</param>
/// <param name="reduceColors">reduce the amount of colors to 256</param>
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors);
/// <param name="outputSettings">OutputSettings</param>
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings);
/// <summary>
/// Return a filename for the current image format (png,jpg etc) with the default file pattern