diff --git a/Greenshot-OCR-Plugin/OCRPlugin.cs b/Greenshot-OCR-Plugin/OCRPlugin.cs
index 134b4df5b..f5f10eae5 100644
--- a/Greenshot-OCR-Plugin/OCRPlugin.cs
+++ b/Greenshot-OCR-Plugin/OCRPlugin.cs
@@ -152,7 +152,8 @@ namespace GreenshotOCR {
private const int MIN_HEIGHT = 130;
public static void DoOCR(ISurface surface) {
string filePath = null;
-
+ OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp);
+
using (Image capturedImage = surface.GetImageForExport()) {
if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
LOG.Debug("Captured image is not big enough for OCR, growing image...");
@@ -163,10 +164,10 @@ namespace GreenshotOCR {
graphics.Clear(Color.White);
graphics.DrawImage(capturedImage, Point.Empty);
}
- filePath = host.SaveToTmpFile(tmpImage, OutputFormat.bmp, 100, false);
+ filePath = host.SaveToTmpFile(tmpImage, outputSettings);
}
} else {
- filePath = host.SaveToTmpFile(capturedImage, OutputFormat.bmp, 100, false);
+ filePath = host.SaveToTmpFile(capturedImage, outputSettings);
}
}
diff --git a/Greenshot/Configuration/LanguageKeys.cs b/Greenshot/Configuration/LanguageKeys.cs
index 7d86c3d7c..6d3ec31a7 100644
--- a/Greenshot/Configuration/LanguageKeys.cs
+++ b/Greenshot/Configuration/LanguageKeys.cs
@@ -146,7 +146,7 @@ namespace Greenshot.Configuration {
jpegqualitydialog_choosejpegquality,
jpegqualitydialog_dontaskagain,
jpegqualitydialog_title,
- reduce_colors,
+ settings_reducecolors,
print_error,
printoptions_allowcenter,
printoptions_allowenlarge,
diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs
index 7500b4baa..5495f2463 100644
--- a/Greenshot/Destinations/EmailDestination.cs
+++ b/Greenshot/Destinations/EmailDestination.cs
@@ -188,7 +188,7 @@ namespace Greenshot.Destinations {
string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) {
- tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
+ tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
}
} else {
LOG.InfoFormat("Using already available file: {0}", tmpFile);
diff --git a/Greenshot/Destinations/ExcelDestination.cs b/Greenshot/Destinations/ExcelDestination.cs
index c801e6650..850b541ef 100644
--- a/Greenshot/Destinations/ExcelDestination.cs
+++ b/Greenshot/Destinations/ExcelDestination.cs
@@ -113,7 +113,7 @@ namespace Greenshot.Destinations {
string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) {
- tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
+ tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
}
}
if (workbookName != null) {
diff --git a/Greenshot/Destinations/PowerpointDestination.cs b/Greenshot/Destinations/PowerpointDestination.cs
index baa3a577f..e27f6c529 100644
--- a/Greenshot/Destinations/PowerpointDestination.cs
+++ b/Greenshot/Destinations/PowerpointDestination.cs
@@ -115,7 +115,7 @@ namespace Greenshot.Destinations {
Size imageSize = Size.Empty;
if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) {
- tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
+ tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
imageSize = image.Size;
}
}
diff --git a/Greenshot/Destinations/WordDestination.cs b/Greenshot/Destinations/WordDestination.cs
index 5a12ab229..b575f4302 100644
--- a/Greenshot/Destinations/WordDestination.cs
+++ b/Greenshot/Destinations/WordDestination.cs
@@ -115,7 +115,7 @@ namespace Greenshot.Destinations {
string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) {
- tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
+ tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
}
}
if (documentCaption != null) {
diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs
index 10c897ec0..5ac8c6d9f 100644
--- a/Greenshot/Forms/ImageEditorForm.cs
+++ b/Greenshot/Forms/ImageEditorForm.cs
@@ -451,9 +451,9 @@ namespace Greenshot {
get { return surface.CaptureDetails; }
}
- public void SaveToStream(Stream stream, OutputFormat extension, int quality, bool reduceColors) {
+ public void SaveToStream(Stream stream, OutputSettings outputSettings) {
using (Image image = surface.GetImageForExport()) {
- ImageOutput.SaveToStream(image, stream, extension, quality, reduceColors);
+ ImageOutput.SaveToStream(image, stream, outputSettings);
}
}
diff --git a/Greenshot/Forms/QualityDialog.cs b/Greenshot/Forms/QualityDialog.cs
index 5e6d44292..b8ba5e4bf 100644
--- a/Greenshot/Forms/QualityDialog.cs
+++ b/Greenshot/Forms/QualityDialog.cs
@@ -23,6 +23,7 @@ using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
+using Greenshot.Plugin;
namespace Greenshot {
///
@@ -30,31 +31,34 @@ namespace Greenshot {
///
public partial class QualityDialog : Form {
private static CoreConfiguration conf = IniConfig.GetIniSection();
- public int Quality = 0;
- public bool ReduceColors = false;
- public QualityDialog(bool isJPG) {
+ public OutputSettings Settings {
+ get;
+ set;
+ }
+ public QualityDialog(OutputSettings outputSettings) {
+ Settings = outputSettings;
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
- this.checkBox_reduceColors.Checked = conf.OutputFileReduceColors;
- this.trackBarJpegQuality.Enabled = isJPG;
- this.trackBarJpegQuality.Value = conf.OutputFileJpegQuality;
- this.textBoxJpegQuality.Enabled = isJPG;
- this.textBoxJpegQuality.Text = conf.OutputFileJpegQuality.ToString();
+ this.checkBox_reduceColors.Checked = Settings.ReduceColors;
+ this.trackBarJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
+ this.trackBarJpegQuality.Value = Settings.JPGQuality;
+ this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
+ this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
UpdateUI();
WindowDetails.ToForeground(Handle);
}
void Button_okClick(object sender, System.EventArgs e) {
- Quality = this.trackBarJpegQuality.Value;
- ReduceColors = checkBox_reduceColors.Checked;
- if(this.checkbox_dontaskagain.Checked) {
- conf.OutputFileJpegQuality = Quality;
+ Settings.JPGQuality = this.trackBarJpegQuality.Value;
+ Settings.ReduceColors = checkBox_reduceColors.Checked;
+ if (this.checkbox_dontaskagain.Checked) {
+ conf.OutputFileJpegQuality = Settings.JPGQuality;
conf.OutputFilePromptQuality = false;
- conf.OutputFileReduceColors = ReduceColors;
+ conf.OutputFileReduceColors = Settings.ReduceColors;
IniConfig.Save();
}
}
@@ -63,7 +67,7 @@ namespace Greenshot {
this.Text = Language.GetString(LangKey.jpegqualitydialog_title);
this.label_choosejpegquality.Text = Language.GetString(LangKey.jpegqualitydialog_choosejpegquality);
this.checkbox_dontaskagain.Text = Language.GetString(LangKey.jpegqualitydialog_dontaskagain);
- this.checkBox_reduceColors.Text = Language.GetString(LangKey.reduce_colors);
+ this.checkBox_reduceColors.Text = Language.GetString(LangKey.settings_reducecolors);
}
void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
diff --git a/Greenshot/Forms/SettingsForm.Designer.cs b/Greenshot/Forms/SettingsForm.Designer.cs
index 598ed9775..a4e0f2610 100644
--- a/Greenshot/Forms/SettingsForm.Designer.cs
+++ b/Greenshot/Forms/SettingsForm.Designer.cs
@@ -64,8 +64,8 @@ namespace Greenshot {
this.checkbox_copypathtoclipboard = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.groupbox_applicationsettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
this.checkbox_autostartshortcut = new GreenshotPlugin.Controls.GreenshotCheckBox();
- this.groupbox_jpegsettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
- this.checkbox_alwaysshowjpegqualitydialog = new GreenshotPlugin.Controls.GreenshotCheckBox();
+ this.groupbox_qualitysettings = new GreenshotPlugin.Controls.GreenshotGroupBox();
+ this.checkbox_alwaysshowqualitydialog = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.label_jpegquality = new GreenshotPlugin.Controls.GreenshotLabel();
this.textBoxJpegQuality = new System.Windows.Forms.TextBox();
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
@@ -134,9 +134,10 @@ namespace Greenshot {
this.checkbox_enableexpert = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.listview_clipboardformats = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.checkbox_reducecolors = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.groupbox_preferredfilesettings.SuspendLayout();
this.groupbox_applicationsettings.SuspendLayout();
- this.groupbox_jpegsettings.SuspendLayout();
+ this.groupbox_qualitysettings.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
this.groupbox_destination.SuspendLayout();
this.tabcontrol.SuspendLayout();
@@ -164,9 +165,9 @@ namespace Greenshot {
//
this.textbox_storagelocation.Location = new System.Drawing.Point(138, 18);
this.textbox_storagelocation.Name = "textbox_storagelocation";
+ this.textbox_storagelocation.PropertyName = "OutputFilePath";
this.textbox_storagelocation.Size = new System.Drawing.Size(233, 20);
this.textbox_storagelocation.TabIndex = 12;
- this.textbox_storagelocation.PropertyName = "OutputFilePath";
//
// label_storagelocation
//
@@ -327,30 +328,31 @@ namespace Greenshot {
this.checkbox_autostartshortcut.Text = "Launch Greenshot on startup";
this.checkbox_autostartshortcut.UseVisualStyleBackColor = true;
//
- // groupbox_jpegsettings
+ // groupbox_qualitysettings
//
- this.groupbox_jpegsettings.Controls.Add(this.checkbox_alwaysshowjpegqualitydialog);
- this.groupbox_jpegsettings.Controls.Add(this.label_jpegquality);
- this.groupbox_jpegsettings.Controls.Add(this.textBoxJpegQuality);
- this.groupbox_jpegsettings.Controls.Add(this.trackBarJpegQuality);
- this.groupbox_jpegsettings.LanguageKey = "settings_jpegsettings";
- this.groupbox_jpegsettings.Location = new System.Drawing.Point(2, 156);
- this.groupbox_jpegsettings.Name = "groupbox_jpegsettings";
- this.groupbox_jpegsettings.Size = new System.Drawing.Size(412, 83);
- this.groupbox_jpegsettings.TabIndex = 14;
- this.groupbox_jpegsettings.TabStop = false;
- this.groupbox_jpegsettings.Text = "JPEG settings";
+ this.groupbox_qualitysettings.Controls.Add(this.checkbox_reducecolors);
+ this.groupbox_qualitysettings.Controls.Add(this.checkbox_alwaysshowqualitydialog);
+ this.groupbox_qualitysettings.Controls.Add(this.label_jpegquality);
+ this.groupbox_qualitysettings.Controls.Add(this.textBoxJpegQuality);
+ this.groupbox_qualitysettings.Controls.Add(this.trackBarJpegQuality);
+ this.groupbox_qualitysettings.LanguageKey = "settings_jpegsettings";
+ this.groupbox_qualitysettings.Location = new System.Drawing.Point(2, 156);
+ this.groupbox_qualitysettings.Name = "groupbox_qualitysettings";
+ this.groupbox_qualitysettings.Size = new System.Drawing.Size(412, 106);
+ this.groupbox_qualitysettings.TabIndex = 14;
+ this.groupbox_qualitysettings.TabStop = false;
+ this.groupbox_qualitysettings.Text = "JPEG settings";
//
- // checkbox_alwaysshowjpegqualitydialog
+ // checkbox_alwaysshowqualitydialog
//
- this.checkbox_alwaysshowjpegqualitydialog.LanguageKey = "settings_alwaysshowjpegqualitydialog";
- this.checkbox_alwaysshowjpegqualitydialog.Location = new System.Drawing.Point(12, 50);
- this.checkbox_alwaysshowjpegqualitydialog.Name = "checkbox_alwaysshowjpegqualitydialog";
- this.checkbox_alwaysshowjpegqualitydialog.PropertyName = "OutputFilePromptQuality";
- this.checkbox_alwaysshowjpegqualitydialog.Size = new System.Drawing.Size(394, 25);
- this.checkbox_alwaysshowjpegqualitydialog.TabIndex = 16;
- this.checkbox_alwaysshowjpegqualitydialog.Text = "Show JPEG quality dialog every time a JPEG image is saved";
- this.checkbox_alwaysshowjpegqualitydialog.UseVisualStyleBackColor = true;
+ this.checkbox_alwaysshowqualitydialog.LanguageKey = "settings_alwaysshowjpegqualitydialog";
+ this.checkbox_alwaysshowqualitydialog.Location = new System.Drawing.Point(12, 50);
+ this.checkbox_alwaysshowqualitydialog.Name = "checkbox_alwaysshowqualitydialog";
+ this.checkbox_alwaysshowqualitydialog.PropertyName = "OutputFilePromptQuality";
+ this.checkbox_alwaysshowqualitydialog.Size = new System.Drawing.Size(394, 25);
+ this.checkbox_alwaysshowqualitydialog.TabIndex = 16;
+ this.checkbox_alwaysshowqualitydialog.Text = "Show quality dialog every time a JPEG image is saved";
+ this.checkbox_alwaysshowqualitydialog.UseVisualStyleBackColor = true;
//
// label_jpegquality
//
@@ -800,7 +802,7 @@ namespace Greenshot {
//
this.tab_output.BackColor = System.Drawing.Color.Transparent;
this.tab_output.Controls.Add(this.groupbox_preferredfilesettings);
- this.tab_output.Controls.Add(this.groupbox_jpegsettings);
+ this.tab_output.Controls.Add(this.groupbox_qualitysettings);
this.tab_output.LanguageKey = "settings_output";
this.tab_output.Location = new System.Drawing.Point(4, 22);
this.tab_output.Name = "tab_output";
@@ -1155,6 +1157,17 @@ namespace Greenshot {
this.columnHeader1.Text = "Destination";
this.columnHeader1.Width = 280;
//
+ // checkbox_reducecolors
+ //
+ this.checkbox_reducecolors.LanguageKey = "settings_reducecolors";
+ this.checkbox_reducecolors.Location = new System.Drawing.Point(12, 72);
+ this.checkbox_reducecolors.Name = "checkbox_reducecolors";
+ this.checkbox_reducecolors.PropertyName = "OutputFileReduceColors";
+ this.checkbox_reducecolors.Size = new System.Drawing.Size(394, 25);
+ this.checkbox_reducecolors.TabIndex = 17;
+ this.checkbox_reducecolors.Text = "Show quality dialog every time a JPEG image is saved";
+ this.checkbox_reducecolors.UseVisualStyleBackColor = true;
+ //
// SettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -1174,8 +1187,8 @@ namespace Greenshot {
this.groupbox_preferredfilesettings.ResumeLayout(false);
this.groupbox_preferredfilesettings.PerformLayout();
this.groupbox_applicationsettings.ResumeLayout(false);
- this.groupbox_jpegsettings.ResumeLayout(false);
- this.groupbox_jpegsettings.PerformLayout();
+ this.groupbox_qualitysettings.ResumeLayout(false);
+ this.groupbox_qualitysettings.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
this.groupbox_destination.ResumeLayout(false);
this.tabcontrol.ResumeLayout(false);
@@ -1256,11 +1269,11 @@ namespace Greenshot {
private System.Windows.Forms.TabControl tabcontrol;
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_autostartshortcut;
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_destination;
- private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_alwaysshowjpegqualitydialog;
+ private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_alwaysshowqualitydialog;
private System.Windows.Forms.TextBox textBoxJpegQuality;
private GreenshotPlugin.Controls.GreenshotLabel label_jpegquality;
private System.Windows.Forms.TrackBar trackBarJpegQuality;
- private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_jpegsettings;
+ private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_qualitysettings;
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_applicationsettings;
private GreenshotPlugin.Controls.GreenshotGroupBox groupbox_preferredfilesettings;
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_playsound;
@@ -1291,5 +1304,6 @@ namespace Greenshot {
private GreenshotPlugin.Controls.GreenshotTextBox textbox_footerpattern;
private GreenshotPlugin.Controls.GreenshotLabel label_counter;
private GreenshotPlugin.Controls.GreenshotTextBox textbox_counter;
+ private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_reducecolors;
}
}
diff --git a/Greenshot/Helpers/ClipboardHelper.cs b/Greenshot/Helpers/ClipboardHelper.cs
index c963f437d..cef5f3b2c 100644
--- a/Greenshot/Helpers/ClipboardHelper.cs
+++ b/Greenshot/Helpers/ClipboardHelper.cs
@@ -32,6 +32,7 @@ using Greenshot.Configuration;
using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
+using Greenshot.Plugin;
namespace Greenshot.Helpers {
///
@@ -380,7 +381,7 @@ EndSelection:<<<<<<<4
// Set the HTML
if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) {
- string tmpFile = ImageOutput.SaveToTmpFile(image, OutputFormat.png, config.OutputFileJpegQuality, config.OutputFileReduceColors);
+ string tmpFile = ImageOutput.SaveToTmpFile(image, new OutputSettings(OutputFormat.png));
string html = getHTMLString(image, tmpFile);
ido.SetText(html, TextDataFormat.Html);
} else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) {
diff --git a/Greenshot/Helpers/ImageOutput.cs b/Greenshot/Helpers/ImageOutput.cs
index 9522c37c4..4df80a71b 100644
--- a/Greenshot/Helpers/ImageOutput.cs
+++ b/Greenshot/Helpers/ImageOutput.cs
@@ -75,11 +75,11 @@ namespace Greenshot.Helpers {
///
/// Saves image to stream with specified quality
///
- public static void SaveToStream(Image imageToSave, Stream stream, OutputFormat extension, int quality, bool reduceColors) {
+ public static void SaveToStream(Image imageToSave, Stream stream, OutputSettings outputSettings) {
ImageFormat imageFormat = null;
bool disposeImage = false;
- switch (extension) {
+ switch (outputSettings.Format) {
case OutputFormat.bmp:
imageFormat = ImageFormat.Bmp;
break;
@@ -100,11 +100,6 @@ namespace Greenshot.Helpers {
break;
}
- // Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
- if (ImageFormat.Gif.Equals(imageFormat)) {
- reduceColors = true;
- }
-
// Removing transparency if it's not supported
if (imageFormat != ImageFormat.Png) {
imageToSave = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
@@ -112,11 +107,11 @@ namespace Greenshot.Helpers {
}
// check for color reduction, forced or automatically
- if (conf.OutputFileAutoReduceColors || reduceColors) {
+ if (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors) {
WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave);
int colorCount = quantizer.GetColorCount();
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
- if (reduceColors || colorCount < 256) {
+ if (outputSettings.ReduceColors || colorCount < 256) {
try {
LOG.Info("Reducing colors on bitmap to 255.");
Image tmpImage = quantizer.GetQuantizedImage(255);
@@ -147,7 +142,7 @@ namespace Greenshot.Helpers {
LOG.DebugFormat("Saving image to stream with Format {0} and PixelFormat {1}", imageFormat, imageToSave.PixelFormat);
if (imageFormat == ImageFormat.Jpeg) {
EncoderParameters parameters = new EncoderParameters(1);
- parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, quality);
+ parameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(Encoder.Quality, outputSettings.JPGQuality);
ImageCodecInfo[] ies = ImageCodecInfo.GetImageEncoders();
imageToSave.Save(stream, ies[1], parameters);
} else if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
@@ -169,7 +164,7 @@ namespace Greenshot.Helpers {
///
/// Saves image to specific path with specified quality
///
- public static void Save(Image image, string fullPath, bool allowOverwrite, int quality, bool reduceColors, bool copyPathToClipboard) {
+ public static void Save(Image image, string fullPath, bool allowOverwrite, OutputSettings outputSettings, bool copyPathToClipboard) {
fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
string path = Path.GetDirectoryName(fullPath);
@@ -198,7 +193,7 @@ namespace Greenshot.Helpers {
LOG.DebugFormat("Saving image to {0}", fullPath);
// Create the stream and call SaveToStream
using (FileStream stream = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) {
- SaveToStream(image, stream, format, quality, reduceColors);
+ SaveToStream(image, stream, outputSettings);
}
if (copyPathToClipboard) {
@@ -213,26 +208,23 @@ namespace Greenshot.Helpers {
/// the absolute destination path including file name
/// true if overwrite is allowed, false if not
public static void Save(Image img, string fullPath, bool allowOverwrite) {
- int quality;
- bool reduceColors = false;
-
// Fix for bug 2912959
string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
- bool isJPG = false;
- if (extension != null) {
- isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
+ OutputFormat format = OutputFormat.png;
+ try {
+ if (extension != null) {
+ format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
+ }
+ } catch (ArgumentException ae) {
+ LOG.Warn("Couldn't parse extension: " + extension, ae);
}
-
- if(conf.OutputFilePromptQuality) {
- QualityDialog qualityDialog = new QualityDialog(isJPG);
+ // Get output settings from the configuration
+ OutputSettings outputSettings = new OutputSettings(format);
+ if (conf.OutputFilePromptQuality) {
+ QualityDialog qualityDialog = new QualityDialog(outputSettings);
qualityDialog.ShowDialog();
- quality = qualityDialog.Quality;
- reduceColors = qualityDialog.ReduceColors;
- } else {
- quality = conf.OutputFileJpegQuality;
- reduceColors = conf.OutputFileReduceColors;
}
- Save(img, fullPath, allowOverwrite, quality, reduceColors, conf.OutputFileCopyPathToClipboard);
+ Save(img, fullPath, allowOverwrite, outputSettings, conf.OutputFileCopyPathToClipboard);
}
#endregion
@@ -261,12 +253,12 @@ namespace Greenshot.Helpers {
}
#endregion
- public static string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors) {
+ public static string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {
string pattern = conf.OutputFileFilenamePattern;
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
pattern = "greenshot ${capturetime}";
}
- string filename = FilenameHelper.GetFilenameFromPattern(pattern, outputFormat, captureDetails);
+ string filename = FilenameHelper.GetFilenameFromPattern(pattern, outputSettings.Format, captureDetails);
// Prevent problems with "other characters", which causes a problem in e.g. Outlook 2007 or break our HTML
filename = Regex.Replace(filename, @"[^\d\w\.]", "_");
// Remove multiple "_"
@@ -278,7 +270,7 @@ namespace Greenshot.Helpers {
// Catching any exception to prevent that the user can't write in the directory.
// This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218
try {
- ImageOutput.Save(image, tmpFile, true, quality, reduceColors, false);
+ ImageOutput.Save(image, tmpFile, true, outputSettings, false);
tmpFileCache.Add(tmpFile, tmpFile);
} catch (Exception e) {
// Show the problem
@@ -294,15 +286,15 @@ namespace Greenshot.Helpers {
///
///
///
- public static string SaveToTmpFile(Image image, OutputFormat outputFormat, int quality, bool reduceColors) {
- string tmpFile = Path.GetRandomFileName() + "." + outputFormat.ToString();
+ public static string SaveToTmpFile(Image image, OutputSettings outputSettings) {
+ string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
// Prevent problems with "other characters", which could cause problems
tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
string tmpPath = Path.Combine(Path.GetTempPath(), tmpFile);
LOG.Debug("Creating TMP File : " + tmpPath);
try {
- ImageOutput.Save(image, tmpPath, true, quality, reduceColors, false);
+ ImageOutput.Save(image, tmpPath, true, outputSettings, false);
tmpFileCache.Add(tmpPath, tmpPath);
} catch (Exception) {
return null;
diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs
index eab102039..b39b94e02 100644
--- a/Greenshot/Helpers/MailHelper.cs
+++ b/Greenshot/Helpers/MailHelper.cs
@@ -66,7 +66,7 @@ namespace Greenshot.Helpers {
/// The image to send
/// ICaptureDetails
public static void SendImage(Image image, ICaptureDetails captureDetails) {
- string tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
+ string tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
if (tmpFile != null) {
// Store the list of currently active windows, so we can make sure we show the email window later!
diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs
index b2ca8b2f2..52d8e54ac 100644
--- a/Greenshot/Helpers/PluginHelper.cs
+++ b/Greenshot/Helpers/PluginHelper.cs
@@ -95,16 +95,16 @@ namespace Greenshot.Helpers {
#region Implementation of IGreenshotPluginHost
private ContextMenuStrip mainMenu = null;
- public void SaveToStream(Image img, Stream stream, OutputFormat extension, int quality, bool reduceColors) {
- ImageOutput.SaveToStream(img, stream, extension, quality, reduceColors);
+ public void SaveToStream(Image img, Stream stream, OutputSettings outputSettings) {
+ ImageOutput.SaveToStream(img, stream, outputSettings);
}
- public string SaveToTmpFile(Image img, OutputFormat outputFormat, int quality, bool reduceColors) {
- return ImageOutput.SaveToTmpFile(img, outputFormat, quality, reduceColors);
+ public string SaveToTmpFile(Image img, OutputSettings outputSettings) {
+ return ImageOutput.SaveToTmpFile(img, outputSettings);
}
- public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors) {
- return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputFormat, quality, reduceColors);
+ public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {
+ return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings);
}
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
diff --git a/Greenshot/Languages/language-en-US.xml b/Greenshot/Languages/language-en-US.xml
index 5939b1b5a..119b7c7a8 100644
--- a/Greenshot/Languages/language-en-US.xml
+++ b/Greenshot/Languages/language-en-US.xml
@@ -188,25 +188,25 @@ Details about the GNU General Public License:
Greenshot Help
- JPEG settings
+ Quality settings
JPEG quality
- Show JPEG quality dialog every time a JPEG image is saved
+ Show quality dialog every time an image is saved
Greenshot quality
- Please choose the quality for your JPEG image.
+ Please choose the quality for your image.
Save as default quality and do not ask again
-
- Reduce the amount of colors to 256 (can have impact on quality!)
+
+ Reduce the amount of colors to a maximum of 256
Line color
diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs
index 32c192dfb..c8fa2de7e 100644
--- a/GreenshotConfluencePlugin/ConfluenceDestination.cs
+++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs
@@ -142,9 +142,10 @@ namespace GreenshotConfluencePlugin {
}
private bool upload(Image image, Page page, string filename, bool openPage) {
+ OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
byte[] buffer;
using (MemoryStream stream = new MemoryStream()) {
- ConfluencePlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ ConfluencePlugin.Host.SaveToStream(image, stream, outputSettings);
// COPY buffer to array
buffer = stream.ToArray();
}
diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
index 9cbe013ce..67ca677e0 100644
--- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
+++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
@@ -73,10 +73,12 @@ namespace ExternalCommand {
}
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
+ OutputSettings outputSettings = new OutputSettings();
+
string fullPath = captureDetails.Filename;
if (fullPath == null) {
using (Image image = surface.GetImageForExport()) {
- fullPath = host.SaveNamedTmpFile(image, captureDetails, OutputFormat.png, 100, false);
+ fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings);
}
}
if (presetCommand != null) {
diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs
index aa748b9a2..01677c2f3 100644
--- a/GreenshotImgurPlugin/ImgurPlugin.cs
+++ b/GreenshotImgurPlugin/ImgurPlugin.cs
@@ -130,10 +130,11 @@ namespace GreenshotImgurPlugin {
}
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
+ OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
using (MemoryStream stream = new MemoryStream()) {
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
- host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ host.SaveToStream(image, stream, outputSettings);
try {
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, captureDetails.DateTime.ToString(), filename);
@@ -170,10 +171,11 @@ namespace GreenshotImgurPlugin {
public void EditMenuClick(object sender, EventArgs eventArgs) {
ToolStripMenuItem item = (ToolStripMenuItem)sender;
IImageEditor imageEditor = (IImageEditor)item.Tag;
+ OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
using (MemoryStream stream = new MemoryStream()) {
BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, Language.GetString("imgur", LangKey.communication_wait));
- imageEditor.SaveToStream(stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ imageEditor.SaveToStream(stream, outputSettings);
try {
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, imageEditor.CaptureDetails));
ImgurInfo imgurInfo = ImgurUtils.UploadToImgur(stream.GetBuffer(), (int)stream.Length, imageEditor.CaptureDetails.Title, filename);
diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs
index 3d4bc44a1..55dbf82a0 100644
--- a/GreenshotJiraPlugin/JiraDestination.cs
+++ b/GreenshotJiraPlugin/JiraDestination.cs
@@ -104,10 +104,11 @@ namespace GreenshotJiraPlugin {
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails));
byte[] buffer;
+ OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
if (jira != null) {
using (MemoryStream stream = new MemoryStream()) {
using (Image image = surface.GetImageForExport()) {
- jiraPlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
}
// COPY stream to buffer
buffer = stream.ToArray();
@@ -134,7 +135,7 @@ namespace GreenshotJiraPlugin {
if (result == DialogResult.OK) {
using (MemoryStream stream = new MemoryStream()) {
using (Image image = surface.GetImageForExport()) {
- jiraPlugin.Host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
}
// COPY stream to buffer
buffer = stream.ToArray();
diff --git a/GreenshotPlugin/Interfaces/Forms/ImageEditor.cs b/GreenshotPlugin/Interfaces/Forms/ImageEditor.cs
index 80cf93d4f..a87416b2b 100644
--- a/GreenshotPlugin/Interfaces/Forms/ImageEditor.cs
+++ b/GreenshotPlugin/Interfaces/Forms/ImageEditor.cs
@@ -49,10 +49,8 @@ namespace Greenshot.Plugin {
/// Will save the current Image in the supplied format to the given stream
///
/// The stream the image is stored on
- /// The image type (extension), e.g. "png", "jpg", "bmp"
- /// Only needed for "jpg"
- /// reduce the amount of colors to 256
- void SaveToStream(Stream stream, OutputFormat extension, int quality, bool reduceColors);
+ /// OutputSettings
+ void SaveToStream(Stream stream, OutputSettings outputSettings);
///
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
diff --git a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs
index 572f85381..0741ff0f4 100644
--- a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs
+++ b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs
@@ -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();
+ 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;
+ }
+ }
+ }
+
///
/// 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 {
///
/// The Image to save
/// The Stream to save to
- /// The format to save with (png, jpg etc)
- /// Jpeg quality
- /// reduce the amount of colors to 256
- void SaveToStream(Image image, Stream stream, OutputFormat format, int quality, bool reduceColors);
+ /// OutputSettings
+ void SaveToStream(Image image, Stream stream, OutputSettings outputSettings);
///
/// Saves the image to a temp file (random name) using the specified outputformat
///
/// The Image to save
- /// The format to save with (png, jpg etc)
- /// Jpeg quality
- /// reduce the amount of colors to 256
- string SaveToTmpFile(Image image, OutputFormat outputFormat, int quality, bool reduceColors);
+ /// OutputSettings
+ string SaveToTmpFile(Image image, OutputSettings outputSettings);
///
/// Saves the image to a temp file, but the name is build with the capture details & pattern
///
/// The Image to save
/// captureDetails with the information to build the filename
- /// The format to save with (png, jpg etc)
- /// Jpeg quality
- /// reduce the amount of colors to 256
- string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors);
+ /// OutputSettings
+ string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings);
///
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
diff --git a/PluginExample/SimpleOutputDestination.cs b/PluginExample/SimpleOutputDestination.cs
index 0c0b47716..e4c3a9f74 100644
--- a/PluginExample/SimpleOutputDestination.cs
+++ b/PluginExample/SimpleOutputDestination.cs
@@ -63,11 +63,13 @@ namespace PluginExample {
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
CoreConfiguration config = IniConfig.GetIniSection();
+ OutputSettings outputSettings = new OutputSettings();
+
string file = host.GetFilename(OutputFormat.png, null);
string filePath = Path.Combine(config.OutputFilePath, file);
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
using (Image image = surface.GetImageForExport()) {
- host.SaveToStream(image, stream, OutputFormat.png, config.OutputFileJpegQuality, config.OutputFileReduceColors);
+ host.SaveToStream(image, stream, outputSettings);
}
}
MessageBox.Show("Saved test file to: " + filePath);