diff --git a/GreenshotPlugin/Core/Effects.cs b/GreenshotPlugin/Core/Effects.cs
new file mode 100644
index 000000000..753fcaef4
--- /dev/null
+++ b/GreenshotPlugin/Core/Effects.cs
@@ -0,0 +1,185 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Windows.Forms;
+
+using Greenshot.Plugin.Drawing;
+using System.IO;
+using System.Collections.Generic;
+using GreenshotPlugin.Core;
+
+namespace Greenshot.Core {
+ ///
+ /// Interface to describe an effect
+ ///
+ public interface IEffect {
+ Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange);
+ }
+
+ ///
+ /// DropShadowEffect
+ ///
+ public class DropShadowEffect : IEffect {
+ public DropShadowEffect() {
+ Darkness = 1f;
+ ShadowSize = 9;
+ ShadowOffset = new Point(-1, -1);
+ }
+ public float Darkness {
+ get;
+ set;
+ }
+ public int ShadowSize {
+ get;
+ set;
+ }
+ public Point ShadowOffset {
+ get;
+ set;
+ }
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ return ImageHelper.CreateShadow(sourceBitmap, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb); //Image.PixelFormat);
+ }
+ }
+
+ ///
+ /// TornEdgeEffect
+ ///
+ public class TornEdgeEffect : IEffect {
+ public TornEdgeEffect() {
+ Darkness = 1f;
+ ShadowSize = 7;
+ ShadowOffset = new Point(-1, -1);
+ }
+ public float Darkness {
+ get;
+ set;
+ }
+ public int ShadowSize {
+ get;
+ set;
+ }
+ public Point ShadowOffset {
+ get;
+ set;
+ }
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ using (Bitmap tmpTornImage = ImageHelper.CreateTornEdge(sourceBitmap)) {
+ return ImageHelper.CreateShadow(tmpTornImage, Darkness, ShadowSize, ShadowOffset, out offsetChange, PixelFormat.Format32bppArgb); //Image.PixelFormat);
+ }
+ }
+ }
+
+ ///
+ /// GrayscaleEffect
+ ///
+ public class GrayscaleEffect : IEffect {
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ offsetChange = Point.Empty;
+ return ImageHelper.CreateGrayscale(sourceBitmap);
+ }
+ }
+
+ ///
+ /// InvertEffect
+ ///
+ public class InvertEffect : IEffect {
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ offsetChange = Point.Empty;
+ return ImageHelper.CreateNegative(sourceBitmap);
+ }
+ }
+
+ ///
+ /// BorderEffect
+ ///
+ public class BorderEffect : IEffect {
+ public BorderEffect() {
+ Width = 2;
+ Color = Color.Black;
+ }
+ public Color Color {
+ get;
+ set;
+ }
+ public int Width {
+ get;
+ set;
+ }
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ return ImageHelper.CreateBorder(sourceBitmap, Width, Color, sourceBitmap.PixelFormat, out offsetChange);
+ }
+ }
+
+ ///
+ /// RotateEffect
+ ///
+ public class RotateEffect : IEffect {
+ public RotateEffect(int angle) {
+ Angle = angle;
+ }
+ public int Angle {
+ get;
+ set;
+ }
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ offsetChange = Point.Empty;
+ RotateFlipType flipType;
+ if (Angle == 90) {
+ flipType = RotateFlipType.Rotate90FlipNone;
+ } else if (Angle == -90 || Angle == 270) {
+ flipType = RotateFlipType.Rotate270FlipNone;
+ } else {
+ throw new NotSupportedException("Currently only an angle of 90 or -90 (270) is supported.");
+ }
+ return ImageHelper.RotateFlip(sourceBitmap, flipType);
+ }
+ }
+
+ ///
+ /// ResizeEffect
+ ///
+ public class ResizeEffect : IEffect {
+ public ResizeEffect(int width, int height, bool maintainAspectRatio) {
+ Width = width;
+ Height = height;
+ MaintainAspectRatio = maintainAspectRatio;
+ }
+ public int Width {
+ get;
+ set;
+ }
+ public int Height {
+ get;
+ set;
+ }
+ public bool MaintainAspectRatio {
+ get;
+ set;
+ }
+ public Bitmap Apply(Bitmap sourceBitmap, out Point offsetChange) {
+ offsetChange = Point.Empty;
+ return ImageHelper.ResizeBitmap(sourceBitmap, MaintainAspectRatio, Width, Height);
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Core/ImageOutput.cs b/GreenshotPlugin/Core/ImageOutput.cs
index 50b49b193..dcbd3bc5a 100644
--- a/GreenshotPlugin/Core/ImageOutput.cs
+++ b/GreenshotPlugin/Core/ImageOutput.cs
@@ -121,58 +121,61 @@ namespace GreenshotPlugin.Core {
imageToSave = surface.GetImageForExport();
disposeImage = true;
}
+
try {
-
- // 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();
+ // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
+ if (outputSettings.Format != OutputFormat.greenshot) {
+ // 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;
}
- 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) {
- imageToSave.Dispose();
+ // 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) {
+ imageToSave.Dispose();
+ }
+ // Make sure the image is disposed!
+ disposeImage = true;
+ imageToSave = nonAlphaImage;
}
- // Make sure the image is disposed!
- disposeImage = true;
- imageToSave = nonAlphaImage;
- }
- // check for color reduction, forced or automatically
- 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 (outputSettings.ReduceColors || colorCount < 256) {
- try {
- LOG.Info("Reducing colors on bitmap to 255.");
- tmpImage = quantizer.GetQuantizedImage(255);
- if (disposeImage) {
- imageToSave.Dispose();
+ // check for color reduction, forced or automatically
+ 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 (outputSettings.ReduceColors || colorCount < 256) {
+ try {
+ LOG.Info("Reducing colors on bitmap to 255.");
+ tmpImage = quantizer.GetQuantizedImage(255);
+ if (disposeImage) {
+ imageToSave.Dispose();
+ }
+ imageToSave = tmpImage;
+ // Make sure the "new" image is disposed
+ disposeImage = true;
+ } catch (Exception e) {
+ LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
}
- imageToSave = tmpImage;
- // Make sure the "new" image is disposed
- disposeImage = true;
- } catch (Exception e) {
- LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
}
}
- }
- // Create meta-data
- PropertyItem softwareUsedPropertyItem = CreatePropertyItem(PROPERTY_TAG_SOFTWARE_USED, "Greenshot");
- if (softwareUsedPropertyItem != null) {
- try {
- imageToSave.SetPropertyItem(softwareUsedPropertyItem);
- } catch (ArgumentException) {
- LOG.WarnFormat("Image of type {0} do not support property {1}", imageFormat, softwareUsedPropertyItem.Id);
+ // Create meta-data
+ PropertyItem softwareUsedPropertyItem = CreatePropertyItem(PROPERTY_TAG_SOFTWARE_USED, "Greenshot");
+ if (softwareUsedPropertyItem != null) {
+ try {
+ imageToSave.SetPropertyItem(softwareUsedPropertyItem);
+ } catch (ArgumentException) {
+ LOG.WarnFormat("Image of type {0} do not support property {1}", imageFormat, softwareUsedPropertyItem.Id);
+ }
}
}
LOG.DebugFormat("Saving image to stream with Format {0} and PixelFormat {1}", imageFormat, imageToSave.PixelFormat);
@@ -207,6 +210,7 @@ namespace GreenshotPlugin.Core {
if (useMemoryStream) {
memoryStream.WriteTo(stream);
}
+
// Output the surface elements, size and marker to the stream
if (outputSettings.Format == OutputFormat.greenshot) {
using (MemoryStream tmpStream = new MemoryStream()) {
diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj
index 5b4fce064..6ddf4b4d2 100644
--- a/GreenshotPlugin/GreenshotPlugin.csproj
+++ b/GreenshotPlugin/GreenshotPlugin.csproj
@@ -147,6 +147,7 @@
+