mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -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
|
@ -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,31 +22,50 @@ 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) {
|
||||
Color color = bbb.GetColorAt(x, y);
|
||||
int r = Convert.ToInt16(color.R*brightness);
|
||||
int g = Convert.ToInt16(color.G*brightness);
|
||||
int b = Convert.ToInt16(color.B*brightness);
|
||||
r = (r>255) ? 255 : r;
|
||||
g = (g>255) ? 255 : g;
|
||||
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);
|
||||
|
||||
/// <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);
|
||||
int b = Convert.ToInt16(color.B * brightness);
|
||||
r = (r > 255) ? 255 : r;
|
||||
g = (g > 255) ? 255 : g;
|
||||
b = (b > 255) ? 255 : b;
|
||||
bbb.SetColorAt(x, y, Color.FromArgb(color.A, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
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>
|
||||
|
@ -29,12 +31,29 @@ namespace Greenshot.Drawing.Filters {
|
|||
public class GrayscaleFilter : AbstractFilter {
|
||||
public GrayscaleFilter(DrawableContainer parent) : base(parent) {
|
||||
}
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
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);
|
||||
bbb.SetColorAt(x, y, color);
|
||||
|
||||
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);
|
||||
bbb.SetColorAt(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
using (bbbSrc = new BitmapBuffer(applyBitmap, applyRect)) {
|
||||
bbbSrc.Lock();
|
||||
base.Apply(graphics, applyBitmap, applyRect, renderMode);
|
||||
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;
|
||||
}
|
||||
int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
|
||||
|
||||
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);
|
||||
}
|
||||
bbbSrc = null;
|
||||
}
|
||||
|
||||
protected override void IteratePixel(int x, int y) {
|
||||
int halfWidth = bbb.Size.Width/2;
|
||||
int halfHeight = bbb.Size.Height/2;
|
||||
int yDistanceFromCenter = halfHeight-y;
|
||||
int xDistanceFromCenter = halfWidth-x;
|
||||
Color color = bbbSrc.GetColorAt(halfWidth-xDistanceFromCenter/magnificationFactor,halfHeight-yDistanceFromCenter/magnificationFactor);
|
||||
bbb.SetColorAt(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,35 +35,40 @@ namespace Greenshot.Drawing.Filters {
|
|||
AddField(GetType(), FieldType.PIXEL_SIZE, 5);
|
||||
}
|
||||
|
||||
public static void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, int pixelSize) {
|
||||
|
||||
if(pixelSize <= 1 || rect.Width == 0 || rect.Height == 0) {
|
||||
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();
|
||||
using(BitmapBuffer bbbSrc = new BitmapBuffer(applyBitmap, rect)) {
|
||||
using (BitmapBuffer bbbSrc = new BitmapBuffer(applyBitmap, rect)) {
|
||||
bbbSrc.Lock();
|
||||
List<Color> colors = new List<Color>();
|
||||
int halbPixelSize = pixelSize/2;
|
||||
for(int y=-halbPixelSize;y<bbbSrc.Height+halbPixelSize; y=y+pixelSize) {
|
||||
for(int x=-halbPixelSize;x<=bbbSrc.Width+halbPixelSize; x=x+pixelSize) {
|
||||
int halbPixelSize = pixelSize / 2;
|
||||
for (int y = -halbPixelSize; y < bbbSrc.Height + halbPixelSize; y = y + pixelSize) {
|
||||
for (int x = -halbPixelSize; x <= bbbSrc.Width + halbPixelSize; x = x + pixelSize) {
|
||||
colors.Clear();
|
||||
for(int yy=y;yy<y+pixelSize;yy++) {
|
||||
if (yy >=0 && yy < bbbSrc.Height) {
|
||||
for(int xx=x;xx<x+pixelSize;xx++) {
|
||||
colors.Add(bbbSrc.GetColorAt(xx,yy));
|
||||
for (int yy = y; yy < y + pixelSize; yy++) {
|
||||
if (yy >= 0 && yy < bbbSrc.Height) {
|
||||
for (int xx = x; xx < x + pixelSize; xx++) {
|
||||
colors.Add(bbbSrc.GetColorAt(xx, yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
Color currentAvgColor = Colors.Mix(colors);
|
||||
for(int yy=y;yy<=y+pixelSize;yy++) {
|
||||
if (yy >=0 && yy < bbbSrc.Height) {
|
||||
for(int xx=x;xx<=x+pixelSize;xx++) {
|
||||
for (int yy = y; yy <= y + pixelSize; yy++) {
|
||||
if (yy >= 0 && yy < bbbSrc.Height) {
|
||||
for (int xx = x; xx <= x + pixelSize; xx++) {
|
||||
bbbDest.SetColorAt(xx, yy, currentAvgColor);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue