From 0c7e16a7713cae6755858a5b635018650b74420a Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 12 Dec 2012 09:51:41 +0000 Subject: [PATCH] Applied my "patch" which refactors the complete codebase to have IEffect support, this is an interface which can be used to supply effects to a bitmap. These effects can now be passed to the OutputSettings (which now is called SurfaceOutputSettings) to control how the output is modified. This is very useful for e.g. OCR which needs a grayscale & resized image. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2377 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Destinations/FileDestination.cs | 2 +- Greenshot/Drawing/BitmapContainer.cs | 62 +++++++----- Greenshot/Drawing/Surface.cs | 54 +---------- Greenshot/Forms/ImageEditorForm.cs | 15 +-- Greenshot/Helpers/MailHelper.cs | 2 +- GreenshotBoxPlugin/BoxPlugin.cs | 2 +- .../ConfluenceDestination.cs | 2 +- GreenshotDropboxPlugin/DropboxPlugin.cs | 2 +- GreenshotDropboxPlugin/DropboxUtils.cs | 2 +- .../ExternalCommandDestination.cs | 2 +- GreenshotFlickrPlugin/FlickrPlugin.cs | 2 +- GreenshotFlickrPlugin/FlickrUtils.cs | 2 +- GreenshotImgurPlugin/ImgurPlugin.cs | 2 +- GreenshotImgurPlugin/ImgurUtils.cs | 2 +- GreenshotJiraPlugin/Jira.cs | 2 +- GreenshotJiraPlugin/JiraDestination.cs | 2 +- GreenshotOCRPlugin/OCRPlugin.cs | 17 +++- .../Destinations/ExcelDestination.cs | 2 +- .../Destinations/OutlookDestination.cs | 2 +- .../Destinations/PowerpointDestination.cs | 2 +- .../Destinations/WordDestination.cs | 2 +- .../OfficeExport/OneNoteExporter.cs | 2 +- .../PhotobucketPlugin.cs | 2 +- .../PhotobucketUtils.cs | 2 +- GreenshotPicasaPlugin/PicasaPlugin.cs | 2 +- GreenshotPicasaPlugin/PicasaUtils.cs | 2 +- GreenshotPlugin/Controls/QualityDialog.cs | 4 +- GreenshotPlugin/Core/ClipboardHelper.cs | 6 +- GreenshotPlugin/Core/ImageHelper.cs | 97 +++++++++++++++---- GreenshotPlugin/Core/ImageOutput.cs | 30 ++++-- GreenshotPlugin/Core/NetworkHelper.cs | 4 +- GreenshotPlugin/Interfaces/Generic.cs | 4 +- .../Interfaces/Plugin/PluginInterfaces.cs | 23 ++++- 33 files changed, 212 insertions(+), 148 deletions(-) diff --git a/Greenshot/Destinations/FileDestination.cs b/Greenshot/Destinations/FileDestination.cs index 5f661b25c..819fca500 100644 --- a/Greenshot/Destinations/FileDestination.cs +++ b/Greenshot/Destinations/FileDestination.cs @@ -76,7 +76,7 @@ namespace Greenshot.Destinations { bool overwrite; string fullPath; // Get output settings from the configuration - OutputSettings outputSettings = new OutputSettings(); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(); if (captureDetails != null && captureDetails.Filename != null) { // As we save a pre-selected file, allow to overwrite. diff --git a/Greenshot/Drawing/BitmapContainer.cs b/Greenshot/Drawing/BitmapContainer.cs index 73cf86540..0e5da7aca 100644 --- a/Greenshot/Drawing/BitmapContainer.cs +++ b/Greenshot/Drawing/BitmapContainer.cs @@ -29,6 +29,7 @@ using Greenshot.Helpers; using Greenshot.Plugin.Drawing; using GreenshotPlugin.Core; using System.Drawing.Drawing2D; +using Greenshot.Core; namespace Greenshot.Drawing { /// @@ -91,13 +92,8 @@ namespace Greenshot.Drawing { public Bitmap Bitmap { set { - if (bitmap != null) { - bitmap.Dispose(); - } - if (shadowBitmap != null) { - shadowBitmap.Dispose(); - shadowBitmap = null; - } + // Remove all current bitmaps + Dispose(true); bitmap = ImageHelper.Clone(value); bool shadow = GetFieldValueAsBool(FieldType.SHADOW); CheckShadow(shadow); @@ -114,29 +110,29 @@ namespace Greenshot.Drawing { get { return bitmap; } } - /** - * Destructor - */ + /// + /// Destructor + /// ~BitmapContainer() { Dispose(false); } - /** - * The public accessible Dispose - * Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice - */ + /// + /// The public accessible Dispose + /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice + /// public new void Dispose() { Dispose(true); base.Dispose(); GC.SuppressFinalize(this); } - // The bulk of the clean-up code is implemented in Dispose(bool) - - /** - * This Dispose is called from the Dispose and the Destructor. - * When disposing==true all non-managed resources should be freed too! - */ + /// + /// The bulk of the clean-up code is implemented in Dispose(bool) + /// This Dispose is called from the Dispose and the Destructor. + /// When disposing==true all non-managed resources should be freed too! + /// + /// protected virtual void Dispose(bool disposing) { if (disposing) { if (bitmap != null) { @@ -150,6 +146,10 @@ namespace Greenshot.Drawing { shadowBitmap = null; } + /// + /// + /// + /// public void Load(string filename) { if (File.Exists(filename)) { // Always make sure ImageHelper.LoadBitmap results are disposed some time, @@ -161,21 +161,35 @@ namespace Greenshot.Drawing { } } + /// + /// Rotate the bitmap + /// + /// public override void Rotate(RotateFlipType rotateFlipType) { Bitmap newBitmap = ImageHelper.RotateFlip((Bitmap)bitmap, rotateFlipType); - if (bitmap != null) { - bitmap.Dispose(); + if (newBitmap != null) { + // Remove all current bitmaps, also the shadow (will be recreated) + Dispose(true); + bitmap = newBitmap; } - bitmap = newBitmap; base.Rotate(rotateFlipType); } + /// + /// This checks if a shadow is already generated + /// + /// private void CheckShadow(bool shadow) { if (shadow && shadowBitmap == null) { - shadowBitmap = ImageHelper.CreateShadow(bitmap, 1f, 6, ref shadowOffset, PixelFormat.Format32bppArgb); + shadowBitmap = ImageHelper.ApplyEffect(bitmap, new DropShadowEffect(), out shadowOffset); } } + /// + /// Draw the actual container to the graphics object + /// + /// + /// public override void Draw(Graphics graphics, RenderMode rm) { if (bitmap != null) { bool shadow = GetFieldValueAsBool(FieldType.SHADOW); diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index ead8ea08d..0f2e876b0 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -37,6 +37,7 @@ using Greenshot.IniFile; using Greenshot.Drawing.Filters; using System.Drawing.Drawing2D; using GreenshotPlugin.Controls; +using Greenshot.Core; namespace Greenshot.Drawing { @@ -896,61 +897,14 @@ namespace Greenshot.Drawing { /// Apply a bitmap effect to the surface /// /// - public void ApplyBitmapEffect(Effects effect) { + public void ApplyBitmapEffect(IEffect effect) { BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait"); backgroundForm.Show(); Application.DoEvents(); try { Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size); - Bitmap newImage = null; - Point offset = new Point(-1,-1); - switch (effect) { - case Effects.Shadow: - newImage = ImageHelper.CreateShadow((Bitmap)Image, 1f, 9, ref offset, PixelFormat.Format32bppArgb); //Image.PixelFormat); - break; - case Effects.TornEdge: - using (Bitmap tmpImage = ImageHelper.CreateTornEdge((Bitmap)Image)) { - newImage = ImageHelper.CreateShadow(tmpImage, 1f, 7, ref offset, PixelFormat.Format32bppArgb); //Image.PixelFormat); - } - break; - case Effects.Border: - newImage = ImageHelper.CreateBorder((Bitmap)Image, 2, Color.Black, Image.PixelFormat, out offset); - break; - case Effects.Grayscale: - newImage = ImageHelper.CreateGrayscale((Bitmap)Image); - break; - case Effects.Invert: - newImage = ImageHelper.CreateNegative((Bitmap)Image); - break; - case Effects.RotateClockwise: - case Effects.RotateCounterClockwise: - RotateFlipType rotateFlipType = RotateFlipType.Rotate270FlipNone; - if (effect == Effects.RotateClockwise) { - rotateFlipType = RotateFlipType.Rotate90FlipNone; - } - // Do not rotate the drawable containers until this works! - //MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false); - //foreach (DrawableContainer drawableContainer in elements) { - // if (drawableContainer.CanRotate) { - // drawableContainer.Rotate(rotateFlipType); - // } - //} - newImage = ImageHelper.RotateFlip((Bitmap)Image, rotateFlipType); - break; - } - // The following was added to correct any unneeded pixels, had the bad effect that sometimes everything was cropped... :( - //Rectangle autoCropRectangle = ImageHelper.FindAutoCropRectangle(newImage, 0); - //if (!Size.Empty.Equals(autoCropRectangle.Size) && !autoCropRectangle.Size.Equals(newImage.Size)) { - // LOG.InfoFormat("Crop to {0}", autoCropRectangle); - // using (Bitmap tmpImage = newImage) { - // newImage = ImageHelper.CloneArea(newImage, autoCropRectangle, PixelFormat.DontCare); - // } - // // Fix offset - // offset = new Point(offset.X - autoCropRectangle.X, offset.Y - autoCropRectangle.Y); - //} else { - // LOG.DebugFormat("No cropping needed!"); - //} - + Point offset; + Bitmap newImage = ImageHelper.ApplyEffect((Bitmap)Image, effect, out offset); if (newImage != null) { // Make sure the elements move according to the offset the effect made the bitmap move elements.MoveBy(offset.X, offset.Y); diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index d9157a282..0f0d09d74 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -41,6 +41,7 @@ using Greenshot.IniFile; using System.Threading; using System.Drawing.Imaging; using Greenshot.Plugin.Drawing; +using Greenshot.Core; namespace Greenshot { /// @@ -1198,22 +1199,22 @@ namespace Greenshot { } void AddBorderToolStripMenuItemClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.Border); + surface.ApplyBitmapEffect(new BorderEffect()); updateUndoRedoSurfaceDependencies(); } void AddDropshadowToolStripMenuItemClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.Shadow); + surface.ApplyBitmapEffect(new DropShadowEffect()); updateUndoRedoSurfaceDependencies(); } void TornEdgesToolStripMenuItemClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.TornEdge); + surface.ApplyBitmapEffect(new TornEdgeEffect()); updateUndoRedoSurfaceDependencies(); } void GrayscaleToolStripMenuItemClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.Grayscale); + surface.ApplyBitmapEffect(new GrayscaleEffect()); updateUndoRedoSurfaceDependencies(); } @@ -1223,17 +1224,17 @@ namespace Greenshot { } void RotateCwToolstripButtonClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.RotateClockwise); + surface.ApplyBitmapEffect(new RotateEffect(90)); updateUndoRedoSurfaceDependencies(); } void RotateCcwToolstripButtonClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.RotateCounterClockwise); + surface.ApplyBitmapEffect(new RotateEffect(270)); updateUndoRedoSurfaceDependencies(); } void InvertToolStripMenuItemClick(object sender, EventArgs e) { - surface.ApplyBitmapEffect(Effects.Invert); + surface.ApplyBitmapEffect(new InvertEffect()); updateUndoRedoSurfaceDependencies(); } diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs index 238189be7..a5da2ef15 100644 --- a/Greenshot/Helpers/MailHelper.cs +++ b/Greenshot/Helpers/MailHelper.cs @@ -65,7 +65,7 @@ namespace Greenshot.Helpers { /// The image to send /// ICaptureDetails public static void SendImage(ISurface surface, ICaptureDetails captureDetails) { - string tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new OutputSettings()); + string tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings()); if (tmpFile != null) { // Store the list of currently active windows, so we can make sure we show the email window later! diff --git a/GreenshotBoxPlugin/BoxPlugin.cs b/GreenshotBoxPlugin/BoxPlugin.cs index 813a1bf29..477ac5837 100644 --- a/GreenshotBoxPlugin/BoxPlugin.cs +++ b/GreenshotBoxPlugin/BoxPlugin.cs @@ -111,7 +111,7 @@ namespace GreenshotBoxPlugin { /// This will be called when the menu item in the Editor is clicked /// public string Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false); try { string url = null; string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs index 55e69c68f..03d65f72b 100644 --- a/GreenshotConfluencePlugin/ConfluenceDestination.cs +++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs @@ -155,7 +155,7 @@ namespace GreenshotConfluencePlugin { } private bool upload(ISurface surfaceToUpload, Page page, string filename, out string errorMessage) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); errorMessage = null; try { new PleaseWaitForm().ShowAndWait(Description, Language.GetString("confluence", LangKey.communication_wait), diff --git a/GreenshotDropboxPlugin/DropboxPlugin.cs b/GreenshotDropboxPlugin/DropboxPlugin.cs index b00f0c53f..2b67d861e 100644 --- a/GreenshotDropboxPlugin/DropboxPlugin.cs +++ b/GreenshotDropboxPlugin/DropboxPlugin.cs @@ -113,7 +113,7 @@ namespace GreenshotDropboxPlugin { /// public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) { uploadUrl = null; - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false); try { string dropboxUrl = null; new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait), diff --git a/GreenshotDropboxPlugin/DropboxUtils.cs b/GreenshotDropboxPlugin/DropboxUtils.cs index fef8bd556..d75ec4983 100644 --- a/GreenshotDropboxPlugin/DropboxUtils.cs +++ b/GreenshotDropboxPlugin/DropboxUtils.cs @@ -36,7 +36,7 @@ namespace GreenshotDropboxPlugin { private DropboxUtils() { } - public static string UploadToDropbox(ISurface surfaceToUpload, OutputSettings outputSettings, string filename) { + public static string UploadToDropbox(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string filename) { OAuthSession oAuth = new OAuthSession(DropBoxCredentials.CONSUMER_KEY, DropBoxCredentials.CONSUMER_SECRET); oAuth.BrowserSize = new Size(1080, 650); oAuth.CheckVerifier = false; diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index 1a76e1582..52e1c7b30 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -64,7 +64,7 @@ namespace ExternalCommand { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); - OutputSettings outputSettings = new OutputSettings(); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(); if (presetCommand != null) { diff --git a/GreenshotFlickrPlugin/FlickrPlugin.cs b/GreenshotFlickrPlugin/FlickrPlugin.cs index f2909cbf6..2c55102ac 100644 --- a/GreenshotFlickrPlugin/FlickrPlugin.cs +++ b/GreenshotFlickrPlugin/FlickrPlugin.cs @@ -111,7 +111,7 @@ namespace GreenshotFlickrPlugin } public void Upload(ICaptureDetails captureDetails, ISurface surface, ExportInformation exportInformation) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, false); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false); try { string flickrUrl = null; new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("flickr", LangKey.communication_wait), diff --git a/GreenshotFlickrPlugin/FlickrUtils.cs b/GreenshotFlickrPlugin/FlickrUtils.cs index 2f6effafb..0a0a22f24 100644 --- a/GreenshotFlickrPlugin/FlickrUtils.cs +++ b/GreenshotFlickrPlugin/FlickrUtils.cs @@ -44,7 +44,7 @@ namespace GreenshotFlickrPlugin { /// /// byte[] with image data /// url to image - public static string UploadToFlickr(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) { + public static string UploadToFlickr(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename) { OAuthSession oAuth = new OAuthSession(FlickrCredentials.ConsumerKey, FlickrCredentials.ConsumerSecret); oAuth.BrowserSize = new Size(520, 800); oAuth.CheckVerifier = false; diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs index e252dfc84..4de5ff66c 100644 --- a/GreenshotImgurPlugin/ImgurPlugin.cs +++ b/GreenshotImgurPlugin/ImgurPlugin.cs @@ -152,7 +152,7 @@ namespace GreenshotImgurPlugin { /// out string for the url /// true if the upload succeeded public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); try { string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); ImgurInfo imgurInfo = null; diff --git a/GreenshotImgurPlugin/ImgurUtils.cs b/GreenshotImgurPlugin/ImgurUtils.cs index 6505145a1..19942f320 100644 --- a/GreenshotImgurPlugin/ImgurUtils.cs +++ b/GreenshotImgurPlugin/ImgurUtils.cs @@ -99,7 +99,7 @@ namespace GreenshotImgurPlugin { /// Title /// Filename /// ImgurInfo with details - public static ImgurInfo UploadToImgur(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) { + public static ImgurInfo UploadToImgur(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename) { IDictionary uploadParameters = new Dictionary(); IDictionary otherParameters = new Dictionary(); // add title diff --git a/GreenshotJiraPlugin/Jira.cs b/GreenshotJiraPlugin/Jira.cs index 58f525b71..555a138bc 100644 --- a/GreenshotJiraPlugin/Jira.cs +++ b/GreenshotJiraPlugin/Jira.cs @@ -26,7 +26,7 @@ using Greenshot.IniFile; using GreenshotJiraPlugin; using GreenshotPlugin.Controls; using GreenshotPlugin.Core; -//using GreenshotJiraPlugin.JiraSoap; +using GreenshotJiraPlugin.JiraSoap; namespace Jira { #region transport classes diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs index 6804a4ea0..a3116c6e0 100644 --- a/GreenshotJiraPlugin/JiraDestination.cs +++ b/GreenshotJiraPlugin/JiraDestination.cs @@ -102,7 +102,7 @@ namespace GreenshotJiraPlugin { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); if (jira != null) { try { // Run upload in the background diff --git a/GreenshotOCRPlugin/OCRPlugin.cs b/GreenshotOCRPlugin/OCRPlugin.cs index 0034610e5..ae4e6be06 100644 --- a/GreenshotOCRPlugin/OCRPlugin.cs +++ b/GreenshotOCRPlugin/OCRPlugin.cs @@ -27,6 +27,7 @@ using System.Windows.Forms; using Greenshot.IniFile; using Greenshot.Plugin; using GreenshotPlugin.Core; +using Greenshot.Core; //using Microsoft.Win32; @@ -137,9 +138,18 @@ namespace GreenshotOCR { private const int MIN_HEIGHT = 130; public string DoOCR(ISurface surface) { string filePath = null; - OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp, 0, true); - // TODO: Add some filter & output settings so the output image is easier to process for the MODI-OCR code + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(OutputFormat.bmp, 0, true); + outputSettings.ReduceColors = true; + // We only want the background + outputSettings.SaveBackgroundOnly = true; + // Force Grayscale output + outputSettings.Effects.Add(new GrayscaleEffect()); + // Also we need to check the size, resize if needed to 130x130 this is the minimum + if (surface.Image.Width < MIN_WIDTH || surface.Image.Height < MIN_HEIGHT) { + IEffect resizeEffect = new ResizeEffect(Math.Max(surface.Image.Width, MIN_WIDTH), Math.Max(surface.Image.Height, MIN_HEIGHT), true); + outputSettings.Effects.Add(resizeEffect); + } filePath = ImageOutput.SaveToTmpFile(surface, outputSettings, null); LOG.Debug("Saved tmp file to: " + filePath); @@ -163,11 +173,12 @@ namespace GreenshotOCR { File.Delete(filePath); } } + if (text == null || text.Trim().Length == 0) { LOG.Info("No text returned"); return null; } - + try { LOG.DebugFormat("Pasting OCR Text to Clipboard: {0}", text); // Paste to Clipboard (the Plugin currently doesn't have access to the ClipboardHelper from Greenshot diff --git a/GreenshotOfficePlugin/Destinations/ExcelDestination.cs b/GreenshotOfficePlugin/Destinations/ExcelDestination.cs index c37626c43..095999cd5 100644 --- a/GreenshotOfficePlugin/Destinations/ExcelDestination.cs +++ b/GreenshotOfficePlugin/Destinations/ExcelDestination.cs @@ -111,7 +111,7 @@ namespace GreenshotOfficePlugin { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string tmpFile = captureDetails.Filename; if (tmpFile == null || surface.Modified) { - tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new OutputSettings(OutputFormat.png)); + tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings(OutputFormat.png)); } if (workbookName != null) { ExcelExporter.InsertIntoExistingWorkbook(workbookName, tmpFile); diff --git a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs index 6616596e5..61577a75d 100644 --- a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs +++ b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs @@ -153,7 +153,7 @@ namespace GreenshotOfficePlugin { // Outlook logic string tmpFile = captureDetails.Filename; if (tmpFile == null || surface.Modified) { - tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new OutputSettings()); + tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings()); } else { LOG.InfoFormat("Using already available file: {0}", tmpFile); } diff --git a/GreenshotOfficePlugin/Destinations/PowerpointDestination.cs b/GreenshotOfficePlugin/Destinations/PowerpointDestination.cs index bd89a0777..6bbef7712 100644 --- a/GreenshotOfficePlugin/Destinations/PowerpointDestination.cs +++ b/GreenshotOfficePlugin/Destinations/PowerpointDestination.cs @@ -113,7 +113,7 @@ namespace GreenshotOfficePlugin { string tmpFile = captureDetails.Filename; Size imageSize = Size.Empty; if (tmpFile == null || surface.Modified) { - tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new OutputSettings()); + tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings()); imageSize = surface.Image.Size; } if (presentationName != null) { diff --git a/GreenshotOfficePlugin/Destinations/WordDestination.cs b/GreenshotOfficePlugin/Destinations/WordDestination.cs index c1fafe86d..49770621e 100644 --- a/GreenshotOfficePlugin/Destinations/WordDestination.cs +++ b/GreenshotOfficePlugin/Destinations/WordDestination.cs @@ -112,7 +112,7 @@ namespace GreenshotOfficePlugin { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string tmpFile = captureDetails.Filename; if (tmpFile == null || surface.Modified) { - tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new OutputSettings(OutputFormat.png)); + tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings(OutputFormat.png)); } if (documentCaption != null) { try { diff --git a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs index 138930874..2fc23820f 100644 --- a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs +++ b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs @@ -45,7 +45,7 @@ namespace Greenshot.Interop.Office { public static void ExportToPage(ISurface surfaceToUpload, OneNotePage page) { using (MemoryStream pngStream = new MemoryStream()) { - OutputSettings pngOutputSettings = new OutputSettings(OutputFormat.png, 100, false); + SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings); string base64String = Convert.ToBase64String(pngStream.GetBuffer()); string imageXmlStr = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height); diff --git a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs index a6b857a67..cd1f8418f 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs @@ -115,7 +115,7 @@ namespace GreenshotPhotobucketPlugin { /// out string for the url /// true if the upload succeeded public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); try { string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); PhotobucketInfo photobucketInfo = null; diff --git a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs index e09d8295e..5dcfbf980 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketUtils.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketUtils.cs @@ -41,7 +41,7 @@ namespace GreenshotPhotobucketPlugin { /// For more details on the available parameters, see: http://api.Photobucket.com/resources_anon /// /// PhotobucketResponse - public static PhotobucketInfo UploadToPhotobucket(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) { + public static PhotobucketInfo UploadToPhotobucket(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename) { string responseString; OAuthSession oAuth = new OAuthSession(PhotobucketCredentials.ConsumerKey, PhotobucketCredentials.ConsumerSecret); diff --git a/GreenshotPicasaPlugin/PicasaPlugin.cs b/GreenshotPicasaPlugin/PicasaPlugin.cs index 2fe916ae3..cb2b2eef5 100644 --- a/GreenshotPicasaPlugin/PicasaPlugin.cs +++ b/GreenshotPicasaPlugin/PicasaPlugin.cs @@ -110,7 +110,7 @@ namespace GreenshotPicasaPlugin { } public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) { - OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality); try { string url = null; new PleaseWaitForm().ShowAndWait(PicasaPlugin.Attributes.Name, Language.GetString("picasa", LangKey.communication_wait), diff --git a/GreenshotPicasaPlugin/PicasaUtils.cs b/GreenshotPicasaPlugin/PicasaUtils.cs index a0c097209..255d1aba7 100644 --- a/GreenshotPicasaPlugin/PicasaUtils.cs +++ b/GreenshotPicasaPlugin/PicasaUtils.cs @@ -41,7 +41,7 @@ namespace GreenshotPicasaPlugin { /// /// byte[] with image data /// PicasaResponse - public static string UploadToPicasa(ISurface surfaceToUpload, OutputSettings outputSettings, string title, string filename) { + public static string UploadToPicasa(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename) { OAuthSession oAuth = new OAuthSession(PicasaCredentials.ConsumerKey, PicasaCredentials.ConsumerSecret); oAuth.BrowserSize = new Size(1020, 590); oAuth.AccessTokenUrl = "https://www.google.com/accounts/OAuthGetAccessToken"; diff --git a/GreenshotPlugin/Controls/QualityDialog.cs b/GreenshotPlugin/Controls/QualityDialog.cs index 4dc1af9df..b12057bf4 100644 --- a/GreenshotPlugin/Controls/QualityDialog.cs +++ b/GreenshotPlugin/Controls/QualityDialog.cs @@ -30,12 +30,12 @@ namespace GreenshotPlugin.Controls { /// public partial class QualityDialog : GreenshotForm { private static CoreConfiguration conf = IniConfig.GetIniSection(); - public OutputSettings Settings { + public SurfaceOutputSettings Settings { get; set; } - public QualityDialog(OutputSettings outputSettings) { + public QualityDialog(SurfaceOutputSettings outputSettings) { Settings = outputSettings; // // The InitializeComponent() call is required for Windows Forms designer support. diff --git a/GreenshotPlugin/Core/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs index 5eda939e7..e79d5b942 100644 --- a/GreenshotPlugin/Core/ClipboardHelper.cs +++ b/GreenshotPlugin/Core/ClipboardHelper.cs @@ -388,7 +388,7 @@ EndSelection:<<<<<<<4 if (config.ClipboardFormats.Contains(ClipboardFormat.PNG) || config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) { pngStream = new MemoryStream(); // PNG works for Powerpoint - OutputSettings pngOutputSettings = new OutputSettings(OutputFormat.png, 100, false); + SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings); pngStream.Seek(0, SeekOrigin.Begin); } @@ -401,7 +401,7 @@ EndSelection:<<<<<<<4 if (config.ClipboardFormats.Contains(ClipboardFormat.DIB)) { bmpStream = new MemoryStream(); // Save image as BMP - OutputSettings bmpOutputSettings = new OutputSettings(OutputFormat.bmp, 100, false); + SurfaceOutputSettings bmpOutputSettings = new SurfaceOutputSettings(OutputFormat.bmp, 100, false); ImageOutput.SaveToStream(surface, bmpStream, bmpOutputSettings); imageStream = new MemoryStream(); @@ -414,7 +414,7 @@ EndSelection:<<<<<<<4 // Set the HTML if (config.ClipboardFormats.Contains(ClipboardFormat.HTML)) { - string tmpFile = ImageOutput.SaveToTmpFile(surface, new OutputSettings(OutputFormat.png), null); + string tmpFile = ImageOutput.SaveToTmpFile(surface, new SurfaceOutputSettings(OutputFormat.png), null); string html = getHTMLString(surface, tmpFile); ido.SetText(html, TextDataFormat.Html); } else if (config.ClipboardFormats.Contains(ClipboardFormat.HTMLDATAURL)) { diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 9f1e0c63e..6e8397fa3 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -27,6 +27,8 @@ using System.IO; using System.Runtime.InteropServices; using Greenshot.IniFile; using GreenshotPlugin.UnmanagedHelpers; +using Greenshot.Plugin; +using Greenshot.Core; namespace GreenshotPlugin.Core { /// @@ -36,9 +38,26 @@ namespace GreenshotPlugin.Core { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageHelper)); private static CoreConfiguration conf = IniConfig.GetIniSection(); + /// + /// Create a thumbnail from an image + /// + /// + /// + /// + /// public static Image CreateThumbnail(Image image, int thumbWidth, int thumbHeight) { return CreateThumbnail(image, thumbWidth, thumbHeight, -1, -1); } + + /// + /// Create a Thumbnail + /// + /// + /// + /// + /// + /// + /// public static Image CreateThumbnail(Image image, int thumbWidth, int thumbHeight, int maxWidth, int maxHeight) { int srcWidth=image.Width; int srcHeight=image.Height; @@ -90,11 +109,11 @@ namespace GreenshotPlugin.Core { } /// - /// Helper method for the FindAutoCropRectangle + /// Private helper method for the FindAutoCropRectangle /// /// /// - /// + /// Rectangle private static Rectangle FindAutoCropRectangle(BitmapBuffer buffer, Point colorPoint, int cropDifference) { Rectangle cropRectangle = Rectangle.Empty; Color referenceColor = buffer.GetColorAtWithoutAlpha(colorPoint.X,colorPoint.Y); @@ -225,19 +244,15 @@ namespace GreenshotPlugin.Core { } return fileBitmap; } - - /** - * Checks if we support the supplied PixelFormat - */ - private static bool isSupported(PixelFormat pixelformat) { - return (PixelFormat.Format32bppArgb.Equals(pixelformat)|| - PixelFormat.Format32bppRgb.Equals(pixelformat) || - PixelFormat.Format24bppRgb.Equals(pixelformat)); - } - - // Based on: http://www.codeproject.com/KB/cs/IconExtractor.aspx - // And a hint from: http://www.codeproject.com/KB/cs/IconLib.aspx - public static Bitmap ExtractVistaIcon(Stream iconStream) { + + + /// + /// Based on: http://www.codeproject.com/KB/cs/IconExtractor.aspx + /// And a hint from: http://www.codeproject.com/KB/cs/IconLib.aspx + /// + /// Stream with the icon information + /// Bitmap with the Vista Icon (256x256) + private static Bitmap ExtractVistaIcon(Stream iconStream) { const int SizeICONDIR = 6; const int SizeICONDIRENTRY = 16; Bitmap bmpPngExtracted = null; @@ -315,6 +330,44 @@ namespace GreenshotPlugin.Core { return Shell32.ExtractIconEx(location, -1, out large, out small, 0); } + /// + /// Apply the effect to the bitmap + /// + /// Bitmap + /// IEffect + /// Bitmap + public static Bitmap ApplyEffect(Bitmap sourceBitmap, IEffect effect, out Point offset) { + List effects = new List(); + effects.Add(effect); + return ApplyEffects(sourceBitmap, effects, out offset); + } + + /// + /// Apply the effects in the supplied order to the bitmap + /// + /// Bitmap + /// List + /// Bitmap + public static Bitmap ApplyEffects(Bitmap sourceBitmap, List effects, out Point offset) { + Bitmap currentBitmap = sourceBitmap; + bool disposeImage = false; + // Default out value for the offset, will be modified there where needed + offset = new Point(0, 0); + Point tmpPoint; + Bitmap tmpBitmap = null; + foreach (IEffect effect in effects) { + tmpBitmap = effect.Apply(currentBitmap, out tmpPoint); + offset.Offset(tmpPoint); + if (disposeImage) { + currentBitmap.Dispose(); + } + currentBitmap = tmpBitmap; + // Make sure the "new" image is disposed + disposeImage = true; + } + return tmpBitmap; + } + /// /// Make the picture look like it's torn /// @@ -843,9 +896,10 @@ namespace GreenshotPlugin.Core { /// What pixel format must the returning bitmap have /// How many pixels is the original image moved? /// Bitmap with the shadow, is bigger than the sourceBitmap!! - public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, ref Point offset, PixelFormat targetPixelformat) { + public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, Point shadowOffset, out Point offset, PixelFormat targetPixelformat) { // Create a new "clean" image Bitmap returnImage = null; + offset = shadowOffset; offset.X += shadowSize - 1; offset.Y += shadowSize - 1; using (Bitmap tmpImage = CreateEmpty(sourceBitmap.Width + (shadowSize * 2), sourceBitmap.Height + (shadowSize * 2), targetPixelformat, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution)) { @@ -958,9 +1012,16 @@ namespace GreenshotPlugin.Core { /// Bitmap with grayscale public static Bitmap CreateGrayscale(Bitmap sourceBitmap) { //create a blank bitmap the same size as original - Bitmap newBitmap = CreateEmptyLike(sourceBitmap, Color.Empty); + // If using 8bpp than the following exception comes: A Graphics object cannot be created from an image that has an indexed pixel format. + Bitmap newBitmap = CreateEmpty(sourceBitmap.Width, sourceBitmap.Height, PixelFormat.Format24bppRgb, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution); + //ColorPalette imagePalette = newBitmap.Palette; + //for (int i = 0; i <= 255; i++) { + // // create greyscale color table + // imagePalette.Entries[i] = Color.FromArgb(i, i, i); + //} + //newBitmap.Palette = imagePalette; - //get a graphics object from the new image + // get a graphics object from the new image using (Graphics graphics = Graphics.FromImage(newBitmap)) { // create the grayscale ColorMatrix ColorMatrix colorMatrix = new ColorMatrix( diff --git a/GreenshotPlugin/Core/ImageOutput.cs b/GreenshotPlugin/Core/ImageOutput.cs index a08be7f65..50b49b193 100644 --- a/GreenshotPlugin/Core/ImageOutput.cs +++ b/GreenshotPlugin/Core/ImageOutput.cs @@ -28,6 +28,7 @@ using System.Windows.Forms; using Greenshot.IniFile; using Greenshot.Plugin; using GreenshotPlugin.Controls; +using Greenshot.Core; namespace GreenshotPlugin.Core { /// @@ -74,7 +75,7 @@ namespace GreenshotPlugin.Core { /// To prevent problems with GDI version of before Windows 7: /// the stream is checked if it's seekable and if needed a MemoryStream as "cache" is used. /// - public static void SaveToStream(ISurface surface, Stream stream, OutputSettings outputSettings) { + public static void SaveToStream(ISurface surface, Stream stream, SurfaceOutputSettings outputSettings) { ImageFormat imageFormat = null; bool disposeImage = false; bool useMemoryStream = false; @@ -112,7 +113,7 @@ namespace GreenshotPlugin.Core { // check what image we want to save Image imageToSave = null; - if (outputSettings.Format == OutputFormat.greenshot) { + if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly) { // We save the image of the surface, this should not be disposed imageToSave = surface.Image; } else { @@ -122,7 +123,18 @@ namespace GreenshotPlugin.Core { } try { - // Removing transparency if it's not supported + // apply effects, if there are any + Point ignoreOffset; + Image tmpImage = ImageHelper.ApplyEffects((Bitmap)imageToSave, outputSettings.Effects, out ignoreOffset); + if (tmpImage != null) { + if (disposeImage) { + imageToSave.Dispose(); + } + imageToSave = tmpImage; + disposeImage = true; + } + + // Removing transparency if it's not supported in the output if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) { Image nonAlphaImage = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb); if (disposeImage) { @@ -141,7 +153,7 @@ namespace GreenshotPlugin.Core { if (outputSettings.ReduceColors || colorCount < 256) { try { LOG.Info("Reducing colors on bitmap to 255."); - Image tmpImage = quantizer.GetQuantizedImage(255); + tmpImage = quantizer.GetQuantizedImage(255); if (disposeImage) { imageToSave.Dispose(); } @@ -152,8 +164,6 @@ namespace GreenshotPlugin.Core { LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e); } } - } else { - LOG.Info("Skipping color reduction test, OutputFileAutoReduceColors is set to false."); } // Create meta-data @@ -273,7 +283,7 @@ namespace GreenshotPlugin.Core { /// /// Saves image to specific path with specified quality /// - public static void Save(ISurface surface, string fullPath, bool allowOverwrite, OutputSettings outputSettings, bool copyPathToClipboard) { + public static void Save(ISurface surface, string fullPath, bool allowOverwrite, SurfaceOutputSettings outputSettings, bool copyPathToClipboard) { fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath); string path = Path.GetDirectoryName(fullPath); @@ -334,7 +344,7 @@ namespace GreenshotPlugin.Core { if (dialogResult.Equals(DialogResult.OK)) { try { string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension; - OutputSettings outputSettings = new OutputSettings(FormatForFilename(fileNameWithExtension)); + SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension)); if (conf.OutputFilePromptQuality) { QualityDialog qualityDialog = new QualityDialog(outputSettings); qualityDialog.ShowDialog(); @@ -360,7 +370,7 @@ namespace GreenshotPlugin.Core { /// /// /// Path to image file - public static string SaveNamedTmpFile(ISurface surface, ICaptureDetails captureDetails, OutputSettings outputSettings) { + public static string SaveNamedTmpFile(ISurface surface, ICaptureDetails captureDetails, SurfaceOutputSettings outputSettings) { string pattern = conf.OutputFileFilenamePattern; if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { pattern = "greenshot ${capturetime}"; @@ -393,7 +403,7 @@ namespace GreenshotPlugin.Core { /// /// /// - public static string SaveToTmpFile(ISurface surface, OutputSettings outputSettings, string destinationPath) { + public static string SaveToTmpFile(ISurface surface, SurfaceOutputSettings outputSettings, string destinationPath) { string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString(); // Prevent problems with "other characters", which could cause problems tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", ""); diff --git a/GreenshotPlugin/Core/NetworkHelper.cs b/GreenshotPlugin/Core/NetworkHelper.cs index 5d8695792..2bf11d26e 100644 --- a/GreenshotPlugin/Core/NetworkHelper.cs +++ b/GreenshotPlugin/Core/NetworkHelper.cs @@ -415,10 +415,10 @@ namespace GreenshotPlugin.Core { /// public class SurfaceContainer : IBinaryContainer { private ISurface surface; - private OutputSettings outputSettings; + private SurfaceOutputSettings outputSettings; private string fileName; - public SurfaceContainer(ISurface surface, OutputSettings outputSettings, string filename) { + public SurfaceContainer(ISurface surface, SurfaceOutputSettings outputSettings, string filename) { this.surface = surface; this.outputSettings = outputSettings; this.fileName = filename; diff --git a/GreenshotPlugin/Interfaces/Generic.cs b/GreenshotPlugin/Interfaces/Generic.cs index df26ffd88..0545af022 100644 --- a/GreenshotPlugin/Interfaces/Generic.cs +++ b/GreenshotPlugin/Interfaces/Generic.cs @@ -26,6 +26,7 @@ using System.Windows.Forms; using Greenshot.Plugin.Drawing; using System.IO; using System.Collections.Generic; +using Greenshot.Core; namespace Greenshot.Plugin { /// @@ -33,7 +34,6 @@ namespace Greenshot.Plugin { /// //public enum HorizontalAlignment {LEFT, CENTER, RIGHT}; public enum VerticalAlignment {TOP, CENTER, BOTTOM}; - public enum Effects { Shadow, TornEdge, Border, Grayscale, RotateClockwise, RotateCounterClockwise, Invert }; public enum SurfaceMessageTyp { FileSaved, @@ -148,7 +148,7 @@ namespace Greenshot.Plugin { } void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable); void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message); - void ApplyBitmapEffect(Effects effect); + void ApplyBitmapEffect(IEffect effect); void RemoveCursor(); bool HasCursor { get; diff --git a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs index 40361554c..d6c9d7e91 100644 --- a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs +++ b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs @@ -26,6 +26,7 @@ using System.Windows.Forms; using GreenshotPlugin.Core; using Greenshot.IniFile; +using Greenshot.Core; namespace Greenshot.Plugin { [Serializable] @@ -74,25 +75,26 @@ namespace Greenshot.Plugin { // Delegates for hooking up events. public delegate void HotKeyHandler(); - public class OutputSettings { + public class SurfaceOutputSettings { private static CoreConfiguration conf = IniConfig.GetIniSection(); private bool reduceColors; + private List effects = new List(); - public OutputSettings() { + public SurfaceOutputSettings() { Format = conf.OutputFileFormat; JPGQuality = conf.OutputFileJpegQuality; ReduceColors = conf.OutputFileReduceColors; } - public OutputSettings(OutputFormat format) : this() { + public SurfaceOutputSettings(OutputFormat format) : this() { Format = format; } - public OutputSettings(OutputFormat format, int quality) : this(format) { + public SurfaceOutputSettings(OutputFormat format, int quality) : this(format) { JPGQuality = quality; } - public OutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) { + public SurfaceOutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) { ReduceColors = reduceColors; } @@ -106,6 +108,17 @@ namespace Greenshot.Plugin { set; } + public bool SaveBackgroundOnly { + get; + set; + } + + public List Effects { + get { + return effects; + } + } + public bool ReduceColors { get { // Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!