mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 09:03:44 -07:00
Cleanup for code-analyses 2nd phase
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2483 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
157cace477
commit
5ffe3dfb42
15 changed files with 190 additions and 137 deletions
|
@ -56,10 +56,6 @@ namespace Greenshot.Drawing {
|
|||
get { return cursor; }
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
// The bulk of the clean-up code is implemented in Dispose(bool)
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,17 +44,23 @@ namespace Greenshot.Drawing.Filters {
|
|||
|
||||
private bool invert = false;
|
||||
public bool Invert {
|
||||
get { return invert; }
|
||||
set { invert=value; OnPropertyChanged("Invert"); }
|
||||
get {
|
||||
return invert;
|
||||
}
|
||||
set {
|
||||
invert = value;
|
||||
OnPropertyChanged("Invert");
|
||||
}
|
||||
}
|
||||
[NonSerialized]
|
||||
protected BitmapBuffer bbb;
|
||||
|
||||
protected Rectangle applyRect;
|
||||
protected DrawableContainer parent;
|
||||
public DrawableContainer Parent {
|
||||
get {return parent;}
|
||||
set {parent = value;}
|
||||
get {
|
||||
return parent;
|
||||
}
|
||||
set {
|
||||
parent = value;
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractFilter(DrawableContainer parent) {
|
||||
|
@ -65,36 +71,12 @@ namespace Greenshot.Drawing.Filters {
|
|||
return parent;
|
||||
}
|
||||
|
||||
public virtual void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
bbb = new BitmapBuffer(applyBitmap, applyRect);
|
||||
try {
|
||||
bbb.Lock();
|
||||
for(int y=0;y<bbb.Height; y++) {
|
||||
for(int x=0;x<bbb.Width; x++) {
|
||||
if(parent.Contains(applyRect.Left+x, applyRect.Top+y) ^ Invert) {
|
||||
IteratePixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
bbb.DrawTo(graphics, applyRect.Location);
|
||||
bbb.Dispose();
|
||||
bbb = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void IteratePixel(int x, int y) {}
|
||||
public abstract void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode);
|
||||
|
||||
protected void OnPropertyChanged(string propertyName) {
|
||||
if(propertyChanged != null) propertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
if (propertyChanged != null) {
|
||||
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,18 +22,37 @@ using System;
|
|||
using System.Drawing;
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace Greenshot.Drawing.Filters {
|
||||
[Serializable()]
|
||||
public class BrightnessFilter : AbstractFilter {
|
||||
|
||||
private double brightness;
|
||||
|
||||
public BrightnessFilter(DrawableContainer parent) : base(parent) {
|
||||
AddField(GetType(), FieldType.BRIGHTNESS, 0.9d);
|
||||
}
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
/// <summary>
|
||||
/// Implements the Apply code for the Brightness Filet
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="applyBitmap"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="renderMode"></param>
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
using (BitmapBuffer bbb = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
bbb.Lock();
|
||||
double brightness = GetFieldValueAsDouble(FieldType.BRIGHTNESS);
|
||||
for (int y = 0; y < bbb.Height; y++) {
|
||||
for (int x = 0; x < bbb.Width; x++) {
|
||||
if (parent.Contains(applyRect.Left + x, applyRect.Top + y) ^ Invert) {
|
||||
Color color = bbb.GetColorAt(x, y);
|
||||
int r = Convert.ToInt16(color.R * brightness);
|
||||
int g = Convert.ToInt16(color.G * brightness);
|
||||
|
@ -43,10 +62,10 @@ namespace Greenshot.Drawing.Filters {
|
|||
b = (b > 255) ? 255 : b;
|
||||
bbb.SetColorAt(x, y, Color.FromArgb(color.A, r, g, b));
|
||||
}
|
||||
|
||||
public override void Apply(Graphics graphics, Bitmap bmp, Rectangle rect, RenderMode renderMode) {
|
||||
brightness = GetFieldValueAsDouble(FieldType.BRIGHTNESS);
|
||||
base.Apply(graphics, bmp, rect, renderMode);
|
||||
}
|
||||
}
|
||||
bbb.DrawTo(graphics, applyRect.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
*/
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
|
||||
namespace Greenshot.Drawing.Filters {
|
||||
/// <summary>
|
||||
|
@ -30,7 +32,19 @@ namespace Greenshot.Drawing.Filters {
|
|||
public GrayscaleFilter(DrawableContainer parent) : base(parent) {
|
||||
}
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
using (BitmapBuffer bbb = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
bbb.Lock();
|
||||
for (int y = 0; y < bbb.Height; y++) {
|
||||
for (int x = 0; x < bbb.Width; x++) {
|
||||
if (parent.Contains(applyRect.Left + x, applyRect.Top + y) ^ Invert) {
|
||||
Color color = bbb.GetColorAt(x, y);
|
||||
int luma = (int)((0.3 * color.R) + (0.59 * color.G) + (0.11 * color.B));
|
||||
color = Color.FromArgb(luma, luma, luma);
|
||||
|
@ -38,3 +52,8 @@ namespace Greenshot.Drawing.Filters {
|
|||
}
|
||||
}
|
||||
}
|
||||
bbb.DrawTo(graphics, applyRect.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,26 +22,44 @@ using System;
|
|||
using System.Drawing;
|
||||
using Greenshot.Drawing.Fields;
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace Greenshot.Drawing.Filters {
|
||||
[Serializable()]
|
||||
public class HighlightFilter : AbstractFilter {
|
||||
[NonSerialized]
|
||||
private Color highlightColor;
|
||||
|
||||
public HighlightFilter(DrawableContainer parent) : base(parent) {
|
||||
AddField(GetType(), FieldType.FILL_COLOR, Color.Yellow);
|
||||
}
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
/// <summary>
|
||||
/// Implements the Apply code for the Brightness Filet
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="applyBitmap"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="renderMode"></param>
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
using (BitmapBuffer bbb = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
bbb.Lock();
|
||||
Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||
for (int y = 0; y < bbb.Height; y++) {
|
||||
for (int x = 0; x < bbb.Width; x++) {
|
||||
if (parent.Contains(applyRect.Left + x, applyRect.Top + y) ^ Invert) {
|
||||
Color color = bbb.GetColorAt(x, y);
|
||||
color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
|
||||
bbb.SetColorAt(x, y, color);
|
||||
}
|
||||
|
||||
public override void Apply(Graphics graphics, Bitmap bmp, Rectangle rect, RenderMode renderMode) {
|
||||
highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||
base.Apply(graphics, bmp, rect, renderMode);
|
||||
}
|
||||
}
|
||||
bbb.DrawTo(graphics, applyRect.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,34 +27,37 @@ using GreenshotPlugin.Core;
|
|||
namespace Greenshot.Drawing.Filters {
|
||||
[Serializable]
|
||||
public class MagnifierFilter : AbstractFilter {
|
||||
|
||||
[NonSerialized]
|
||||
private BitmapBuffer bbbSrc;
|
||||
private int magnificationFactor;
|
||||
|
||||
public MagnifierFilter(DrawableContainer parent) : base(parent) {
|
||||
AddField(GetType(), FieldType.MAGNIFICATION_FACTOR, 2);
|
||||
}
|
||||
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
|
||||
applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
using (bbbSrc = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
bbbSrc.Lock();
|
||||
base.Apply(graphics, applyBitmap, applyRect, renderMode);
|
||||
}
|
||||
bbbSrc = null;
|
||||
if (applyRect.Width == 0 || applyRect.Height == 0) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
using (BitmapBuffer bbb = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
int halfWidth = bbb.Size.Width / 2;
|
||||
int halfHeight = bbb.Size.Height / 2;
|
||||
bbb.Lock();
|
||||
using (BitmapBuffer bbbSrc = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
for (int y = 0; y < bbb.Height; y++) {
|
||||
int yDistanceFromCenter = halfHeight - y;
|
||||
for (int x = 0; x < bbb.Width; x++) {
|
||||
int xDistanceFromCenter = halfWidth - x;
|
||||
if (parent.Contains(applyRect.Left + x, applyRect.Top + y) ^ Invert) {
|
||||
Color color = bbbSrc.GetColorAt(halfWidth - xDistanceFromCenter / magnificationFactor, halfHeight - yDistanceFromCenter / magnificationFactor);
|
||||
bbb.SetColorAt(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
bbb.DrawTo(graphics, applyRect.Location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,14 +35,19 @@ namespace Greenshot.Drawing.Filters {
|
|||
AddField(GetType(), FieldType.PIXEL_SIZE, 5);
|
||||
}
|
||||
|
||||
public static void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, int pixelSize) {
|
||||
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
|
||||
Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
if (pixelSize <= 1 || rect.Width == 0 || rect.Height == 0) {
|
||||
// Nothing to do
|
||||
return;
|
||||
}
|
||||
if(rect.Width < pixelSize) pixelSize = rect.Width;
|
||||
if(rect.Height < pixelSize) pixelSize = rect.Height;
|
||||
if (rect.Width < pixelSize) {
|
||||
pixelSize = rect.Width;
|
||||
}
|
||||
if (rect.Height < pixelSize) {
|
||||
pixelSize = rect.Height;
|
||||
}
|
||||
|
||||
using (BitmapBuffer bbbDest = new BitmapBuffer(applyBitmap, rect)) {
|
||||
bbbDest.Lock();
|
||||
|
@ -74,12 +79,5 @@ namespace Greenshot.Drawing.Filters {
|
|||
bbbDest.DrawTo(graphics, rect.Location);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
|
||||
int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
|
||||
applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
|
||||
|
||||
Apply(graphics, applyBitmap, applyRect, pixelSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -434,16 +434,6 @@ namespace Greenshot.Drawing {
|
|||
captureDetails = capture.CaptureDetails;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The public accessible Dispose
|
||||
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
||||
/// </summary>
|
||||
public new void Dispose() {
|
||||
Dispose(true);
|
||||
base.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Count--;
|
||||
|
@ -464,6 +454,17 @@ namespace Greenshot.Drawing {
|
|||
while (redoStack != null && redoStack.Count > 0) {
|
||||
redoStack.Pop().Dispose();
|
||||
}
|
||||
foreach (IDrawableContainer container in elements) {
|
||||
container.Dispose();
|
||||
}
|
||||
if (undrawnElement != null) {
|
||||
undrawnElement.Dispose();
|
||||
undrawnElement = null;
|
||||
}
|
||||
if (cropContainer != null) {
|
||||
cropContainer.Dispose();
|
||||
cropContainer = null;
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
@ -909,7 +910,7 @@ namespace Greenshot.Drawing {
|
|||
ex.Data.Add("Width", Image.Width);
|
||||
ex.Data.Add("Height", Image.Height);
|
||||
ex.Data.Add("Pixelformat", Image.PixelFormat);
|
||||
throw ex;
|
||||
throw;
|
||||
}
|
||||
|
||||
Point offset = new Point(-cropRectangle.Left, -cropRectangle.Top);
|
||||
|
|
|
@ -132,7 +132,12 @@ namespace Greenshot {
|
|||
/// </summary>
|
||||
public AboutForm() {
|
||||
// Make sure our resources are removed again.
|
||||
this.Disposed += delegate { Cleanup(); };
|
||||
this.Disposed += delegate {
|
||||
Cleanup();
|
||||
};
|
||||
this.FormClosing += delegate {
|
||||
Cleanup();
|
||||
};
|
||||
|
||||
// Enable animation for this form, when we don't set this the timer doesn't start as soon as the form is loaded.
|
||||
EnableAnimation = true;
|
||||
|
@ -228,6 +233,9 @@ namespace Greenshot {
|
|||
/// Called from the AnimatingForm, for every frame
|
||||
/// </summary>
|
||||
protected override void Animate() {
|
||||
if (gBitmap == null) {
|
||||
return;
|
||||
}
|
||||
if (!isTerminalServerSession) {
|
||||
// Color cycle
|
||||
if (waitFrames != 0) {
|
||||
|
|
|
@ -35,6 +35,7 @@ using GreenshotPlugin.UnmanagedHelpers;
|
|||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using GreenshotPlugin.Controls;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace Greenshot.Forms {
|
||||
/// <summary>
|
||||
|
@ -106,6 +107,7 @@ namespace Greenshot.Forms {
|
|||
/// This should prevent childs to draw backgrounds
|
||||
/// </summary>
|
||||
protected override CreateParams CreateParams {
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
get {
|
||||
CreateParams cp = base.CreateParams;
|
||||
cp.ExStyle |= 0x02000000;
|
||||
|
|
|
@ -657,7 +657,7 @@ namespace Greenshot {
|
|||
}
|
||||
|
||||
void AboutToolStripMenuItemClick(object sender, System.EventArgs e) {
|
||||
new AboutForm().ShowDialog(this);
|
||||
MainForm.Instance.ShowAbout();
|
||||
}
|
||||
|
||||
void PreferencesToolStripMenuItemClick(object sender, System.EventArgs e) {
|
||||
|
|
|
@ -968,6 +968,10 @@ namespace Greenshot {
|
|||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void Contextmenu_aboutClick(object sender, EventArgs e) {
|
||||
ShowAbout();
|
||||
}
|
||||
|
||||
public void ShowAbout() {
|
||||
if (aboutForm != null) {
|
||||
WindowDetails.ToForeground(aboutForm.Handle);
|
||||
} else {
|
||||
|
|
|
@ -582,7 +582,9 @@ namespace Greenshot.Helpers {
|
|||
if (element.attributes.ContainsKey("greenshot") && element.attributes["greenshot"] != null) {
|
||||
string greenshotAction = element.attributes["greenshot"];
|
||||
if ("hide".Equals(greenshotAction)) {
|
||||
PixelizationFilter.Apply(graphicsTarget, returnBitmap, element.rectangle, 4);
|
||||
using (Brush brush = new SolidBrush(Color.Black)) {
|
||||
graphicsTarget.FillRectangle(brush, element.rectangle);
|
||||
}
|
||||
} else if ("red".Equals(greenshotAction)) {
|
||||
using (Brush brush = new SolidBrush(Color.Red)) {
|
||||
graphicsTarget.FillRectangle(brush, element.rectangle);
|
||||
|
|
|
@ -159,6 +159,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Provides details about a Window returned by the
|
||||
/// enumeration
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]
|
||||
public class WindowDetails : IEquatable<WindowDetails>{
|
||||
private const string METRO_WINDOWS_CLASS = "Windows.UI.Core.CoreWindow";
|
||||
private const string METRO_APPLAUNCHER_CLASS = "ImmersiveLauncher";
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public static extern IntPtr GetWindow(IntPtr hWnd, GetWindowCommand uCmd);
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern int ShowWindow(IntPtr hWnd, ShowWindowCommand nCmdShow);
|
||||
[DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public extern static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int cch);
|
||||
[DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public extern static int GetWindowTextLength(IntPtr hWnd);
|
||||
|
@ -97,7 +97,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public extern static bool IsZoomed(IntPtr hwnd);
|
||||
[DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public extern static int GetClassName (IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr GetClassLong(IntPtr hWnd, int nIndex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue