"Merged" 0.8 with HEAD, so we can continue developing

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1282 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2011-07-17 12:05:59 +00:00
commit f3b0878b02
539 changed files with 86855 additions and 0 deletions

View file

@ -0,0 +1,117 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.Serialization;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
/// <summary>
/// Graphical filter which can be added to DrawableContainer.
/// Subclasses should fulfill INotifyPropertyChanged contract, i.e. call
/// OnPropertyChanged whenever a public property has been changed.
/// </summary>
namespace Greenshot.Drawing.Filters {
[Serializable()]
public abstract class AbstractFilter : AbstractFieldHolder, IFilter {
[NonSerialized]
private PropertyChangedEventHandler propertyChanged;
public event PropertyChangedEventHandler PropertyChanged {
add { propertyChanged += value; }
remove{ propertyChanged -= value; }
}
private bool invert = false;
public bool Invert {
get { return invert; }
set { invert=value; OnPropertyChanged("Invert"); }
}
protected BitmapBuffer bbb;
protected Rectangle applyRect;
protected DrawableContainer parent;
public DrawableContainer Parent {
get {return parent;}
set {parent = value;}
}
public AbstractFilter(DrawableContainer parent) {
this.parent = parent;
}
public DrawableContainer GetParent() {
return parent;
}
/**
* This method fixes the problem that we can't apply a filter outside the target bitmap,
* therefor the filtered-bitmap will be shifted if we try to draw it outside the target bitmap.
* It will also account for the Invert flag.
*/
protected Rectangle IntersectRectangle(Size applySize, Rectangle rect) {
Rectangle myRect;
if (Invert) {
myRect = new Rectangle(0, 0, applySize.Width, applySize.Height);
} else {
Rectangle applyRect = new Rectangle(0,0, applySize.Width, applySize.Height);
myRect = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
myRect.Intersect(applyRect);
}
return myRect;
}
public virtual void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
applyRect = IntersectRectangle(applyBitmap.Size, rect);
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) {}
protected void OnPropertyChanged(string propertyName) {
if(propertyChanged != null) propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View file

@ -0,0 +1,241 @@
/// <summary>
/// Parts of this class were taken from BlurEffect.cs of Paint.NET 3.0.1,
/// which was released under MIT license.
/// http://www.getpaint.net
/// Some of this code has been adapted for integration with Greenshot.
/// See Paint.NET copyright notice below.
/// </summary>
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET //
// Copyright (C) Rick Brewster, Tom Jackson, and past contributors. //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
// See src/Resources/Files/License.txt for full licensing and attribution //
// details. //
// . //
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.Serialization;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Drawing.Filters;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
[Serializable()]
public class BlurFilter : AbstractFilter {
public double previewQuality;
public double PreviewQuality {
get { return previewQuality; }
set { previewQuality = value; OnPropertyChanged("PreviewQuality"); }
}
public BlurFilter(DrawableContainer parent) : base(parent) {
AddField(GetType(), FieldType.BLUR_RADIUS, 3);
AddField(GetType(), FieldType.PREVIEW_QUALITY, 1.0d);
}
public static int[] CreateGaussianBlurRow(int amount) {
int size = 1 + (amount * 2);
int[] weights = new int[size];
for (int i = 0; i <= amount; ++i)
{
// 1 + aa - aa + 2ai - ii
weights[i] = 16 * (i + 1);
weights[weights.Length - i - 1] = weights[i];
}
return weights;
}
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
applyRect = IntersectRectangle(applyBitmap.Size, rect);
if (applyRect.Height <= 0 || applyRect.Width <= 0) {
return;
}
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
// do nothing when nothing can be done!
if (blurRadius < 1) {
return;
}
using (BitmapBuffer bbbDest = new BitmapBuffer(applyBitmap, applyRect)) {
bbbDest.Lock();
using (BitmapBuffer bbbSrc = new BitmapBuffer(applyBitmap, applyRect)) {
bbbSrc.Lock();
Random rand = new Random();
int r = blurRadius;
int[] w = CreateGaussianBlurRow(r);
int wlen = w.Length;
for (int y = 0; y < applyRect.Height; ++y) {
long* waSums = stackalloc long[wlen];
long* wcSums = stackalloc long[wlen];
long* aSums = stackalloc long[wlen];
long* bSums = stackalloc long[wlen];
long* gSums = stackalloc long[wlen];
long* rSums = stackalloc long[wlen];
long waSum = 0;
long wcSum = 0;
long aSum = 0;
long bSum = 0;
long gSum = 0;
long rSum = 0;
for (int wx = 0; wx < wlen; ++wx) {
int srcX = wx - r;
waSums[wx] = 0;
wcSums[wx] = 0;
aSums[wx] = 0;
bSums[wx] = 0;
gSums[wx] = 0;
rSums[wx] = 0;
if (srcX >= 0 && srcX < bbbDest.Width) {
for (int wy = 0; wy < wlen; ++wy) {
int srcY = y + wy - r;
if (srcY >= 0 && srcY < bbbDest.Height) {
int[] colors = bbbSrc.GetColorArrayAt(srcX, srcY);
int wp = w[wy];
waSums[wx] += wp;
wp *= colors[0] + (colors[0] >> 7);
wcSums[wx] += wp;
wp >>= 8;
aSums[wx] += wp * colors[0];
bSums[wx] += wp * colors[3];
gSums[wx] += wp * colors[2];
rSums[wx] += wp * colors[1];
}
}
int wwx = w[wx];
waSum += wwx * waSums[wx];
wcSum += wwx * wcSums[wx];
aSum += wwx * aSums[wx];
bSum += wwx * bSums[wx];
gSum += wwx * gSums[wx];
rSum += wwx * rSums[wx];
}
}
wcSum >>= 8;
if (waSum == 0 || wcSum == 0) {
SetColorAt(bbbDest, 0, y, new int[]{0,0,0,0});
} else {
int alpha = (int)(aSum / waSum);
int blue = (int)(bSum / wcSum);
int green = (int)(gSum / wcSum);
int red = (int)(rSum / wcSum);
SetColorAt(bbbDest, 0, y, new int[]{alpha, red, green, blue});
}
for (int x = 1; x < applyRect.Width; ++x) {
for (int i = 0; i < wlen - 1; ++i) {
waSums[i] = waSums[i + 1];
wcSums[i] = wcSums[i + 1];
aSums[i] = aSums[i + 1];
bSums[i] = bSums[i + 1];
gSums[i] = gSums[i + 1];
rSums[i] = rSums[i + 1];
}
waSum = 0;
wcSum = 0;
aSum = 0;
bSum = 0;
gSum = 0;
rSum = 0;
int wx;
for (wx = 0; wx < wlen - 1; ++wx) {
long wwx = (long)w[wx];
waSum += wwx * waSums[wx];
wcSum += wwx * wcSums[wx];
aSum += wwx * aSums[wx];
bSum += wwx * bSums[wx];
gSum += wwx * gSums[wx];
rSum += wwx * rSums[wx];
}
wx = wlen - 1;
waSums[wx] = 0;
wcSums[wx] = 0;
aSums[wx] = 0;
bSums[wx] = 0;
gSums[wx] = 0;
rSums[wx] = 0;
int srcX = x + wx - r;
if (srcX >= 0 && srcX < applyRect.Width) {
for (int wy = 0; wy < wlen; ++wy) {
int srcY = y + wy - r;
// only when in EDIT mode, ignore some pixels depending on preview quality
if ((renderMode==RenderMode.EXPORT || rand.NextDouble()<previewQuality) && srcY >= 0 && srcY < applyRect.Height) {
int[] colors = bbbSrc.GetColorArrayAt(srcX, srcY);
int wp = w[wy];
waSums[wx] += wp;
wp *= colors[0] + (colors[0] >> 7);
wcSums[wx] += wp;
wp >>= 8;
aSums[wx] += wp * (long)colors[0];
bSums[wx] += wp * (long)colors[3];
gSums[wx] += wp * (long)colors[2];
rSums[wx] += wp * (long)colors[1];
}
}
int wr = w[wx];
waSum += (long)wr * waSums[wx];
wcSum += (long)wr * wcSums[wx];
aSum += (long)wr * aSums[wx];
bSum += (long)wr * bSums[wx];
gSum += (long)wr * gSums[wx];
rSum += (long)wr * rSums[wx];
}
wcSum >>= 8;
if (waSum == 0 || wcSum == 0) {
SetColorAt(bbbDest, x, y, new int[]{0,0,0,0});
} else {
int alpha = (int)(aSum / waSum);
int blue = (int)(bSum / wcSum);
int green = (int)(gSum / wcSum);
int red = (int)(rSum / wcSum);
SetColorAt(bbbDest, x, y, new int[]{alpha, red, green, blue});
}
}
}
}
bbbDest.DrawTo(graphics, applyRect.Location);
}
}
private void SetColorAt(BitmapBuffer bbb, int x, int y, int[] colors) {
if(parent.Contains(applyRect.Left+x, applyRect.Top+y) ^ Invert) {
bbb.SetColorArrayAt(x, y, colors);
}
}
}
}

View file

@ -0,0 +1,56 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
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);
}
}
}

View file

@ -0,0 +1,231 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
[Serializable()]
public class FastSmoothFilter : AbstractFilter {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FastSmoothFilter));
public FastSmoothFilter(DrawableContainer parent) : base(parent) {
AddField(GetType(), FieldType.BLUR_RADIUS, 3);
}
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle applyRect, RenderMode renderMode) {
Rectangle sourceRect = new Rectangle(applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height);
Rectangle bitmapRect = new Rectangle(0,0, applyBitmap.Width, applyBitmap.Height);
if(sourceRect.Equals(Rectangle.Empty)) {
sourceRect = bitmapRect;
} else {
sourceRect.Intersect(bitmapRect);
}
// Does the rect have any pixels?
if (sourceRect.Height <= 0 || sourceRect.Width <= 0) {
return;
}
int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
// Calculate new sourceRect to include the matrix size if possible
int leftOffset = Math.Min(sourceRect.X, blurRadius);
int rightOffset = Math.Min(applyBitmap.Width - (sourceRect.X + sourceRect.Width), blurRadius);
int topOffset = Math.Min(sourceRect.Y, blurRadius);
int bottomOffset = Math.Min(applyBitmap.Height - (sourceRect.Y + sourceRect.Height), blurRadius);
LOG.Debug(String.Format("Offsets: {0},{1},{2},{3}", leftOffset, rightOffset, topOffset, bottomOffset));
LOG.Debug(String.Format("SourceRect before: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
sourceRect.X -= leftOffset;
sourceRect.Width += leftOffset + rightOffset;
sourceRect.Y -= topOffset;
sourceRect.Height += topOffset + bottomOffset;
LOG.Debug(String.Format("SourceRect after: {0},{1},{2},{3}", sourceRect.X, sourceRect.Width, sourceRect.Y, sourceRect.Height));
// Make a copy of the applyBitmap for reading
using (Bitmap sourceBitmap = applyBitmap.Clone(sourceRect, applyBitmap.PixelFormat)) {
ApplySmooth(sourceBitmap, applyBitmap, sourceRect, blurRadius);
}
}
public static bool ApplySmooth(Bitmap sourceBitmap, Bitmap destinationBitmap, Rectangle destRectangle, int blurRadius) {
if (blurRadius < 1) {
return false;
}
BitmapData destbitmapData = destinationBitmap.LockBits(destRectangle, ImageLockMode.WriteOnly, destinationBitmap.PixelFormat);
BitmapData srcBitmapData = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height),
ImageLockMode.ReadOnly,
sourceBitmap.PixelFormat);
int destStride = destbitmapData.Stride;
int srcStride = srcBitmapData.Stride;
IntPtr destScan0 = destbitmapData.Scan0;
IntPtr srcScan0 = srcBitmapData.Scan0;
int bIndex;
int gIndex;
int rIndex;
//int aIndex;
int bytesPerPixel;
switch(destinationBitmap.PixelFormat) {
case PixelFormat.Format32bppArgb:
// GDI+ lies to us - the return format is BGR, NOT RGB.
bIndex = 0;
gIndex = 1;
rIndex = 2;
//aIndex = 3;
bytesPerPixel = 4;
break;
case PixelFormat.Format32bppRgb:
// GDI+ lies to us - the return format is BGR, NOT RGB.
bIndex = 0;
gIndex = 1;
rIndex = 2;
bytesPerPixel = 4;
break;
case PixelFormat.Format24bppRgb:
// GDI+ lies to us - the return format is BGR, NOT RGB.
bIndex = 0;
gIndex = 1;
rIndex = 2;
bytesPerPixel = 3;
break;
default:
throw new FormatException("Bitmap.Pixelformat."+destinationBitmap.PixelFormat+" is currently not supported. Supported: Format32bpp(A)Rgb, Format24bppRgb");
}
long ticks = DateTime.Now.Ticks;
unsafe {
int width = destRectangle.Width - (blurRadius*2);
int height = destRectangle.Height - (blurRadius*2);
int diameter = (2 * blurRadius) + 1;
int mid = ((diameter-1)/2) + 1;
int midPixel = mid * bytesPerPixel;
int midLine = (mid - 1) * destStride;
int writeRPixelOffset = midLine + midPixel + rIndex;
int writeGPixelOffset = midLine + midPixel + gIndex;
int writeBPixelOffset = midLine + midPixel + bIndex;
int readRPixelOffset = diameter * bytesPerPixel + rIndex;
int readGPixelOffset = diameter * bytesPerPixel + gIndex;
int readBPixelOffset = diameter * bytesPerPixel + bIndex;
int destOffset = destStride - (width*bytesPerPixel);
int srcOffset = srcStride - (width*bytesPerPixel);
int factor = diameter * diameter;
byte *destBitmapPointer = (byte *)(void *)destScan0;
byte *srcBitmapPointer = (byte *)(void *)srcScan0;
int pixel, lineOffset;
int rTotal, gTotal, bTotal;
int [,]r = new int[diameter,diameter];
int [,]g = new int[diameter,diameter];
int [,]b = new int[diameter,diameter];
for (int y=0; y < height; y++) {
// Reset totals
rTotal = gTotal = bTotal = 0;
// Intial load: Do the complete radius, fill the arrays with their values
lineOffset = 0; // Offset relative to the srcBitmapPointer
// Vertical loop
for (int v = 0; v < diameter; v++) {
// Start at beginning of the current line
int index = lineOffset;
// Horizontal loop
for (int currentRow = 0; currentRow < diameter; currentRow++) {
// Get & add values
rTotal += r[v,currentRow] = srcBitmapPointer[index + rIndex];
gTotal += g[v,currentRow] = srcBitmapPointer[index + gIndex];
bTotal += b[v,currentRow] = srcBitmapPointer[index + bIndex];
// Move 1px to the right
index += bytesPerPixel;
}
// Move to next line
lineOffset += srcStride;
}
// Now loop the complete line from left to right
for (int x=0; x < width; x++ ) {
// Draw Pixel with calculated values
pixel = rTotal / factor;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
destBitmapPointer[writeRPixelOffset]= (byte)pixel;
pixel = gTotal / factor;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
destBitmapPointer[writeGPixelOffset]= (byte)pixel;
pixel = bTotal / factor;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
destBitmapPointer[writeBPixelOffset]= (byte)pixel;
// Update values with next "row"
int oldRow = x % diameter;
srcBitmapPointer += bytesPerPixel;
lineOffset = 0;
// Vertical Loop, subtract the stored value and add the new value
for (int v = 0; v < diameter; v++) {
// Subtrace the first value, so we can add the new later
rTotal -= r[v, oldRow];
gTotal -= g[v, oldRow];
bTotal -= b[v, oldRow];
// Get & add the next values
rTotal += r[v, oldRow] = srcBitmapPointer[readRPixelOffset + lineOffset];
gTotal += g[v, oldRow] = srcBitmapPointer[readGPixelOffset + lineOffset];
bTotal += b[v, oldRow] = srcBitmapPointer[readBPixelOffset + lineOffset];
// Goto next line
lineOffset += srcStride;
}
destBitmapPointer += bytesPerPixel;
}
srcBitmapPointer += srcOffset;
destBitmapPointer += destOffset;
}
}
LOG.Info("Ticks = " + (DateTime.Now.Ticks - ticks));
destinationBitmap.UnlockBits(destbitmapData);
sourceBitmap.UnlockBits(srcBitmapData);
return true;
}
/**
* Checks if the supplied Bitmap has a PixelFormat we support
*/
private bool SupportsPixelFormat(Bitmap bitmap) {
return (bitmap.PixelFormat.Equals(PixelFormat.Format32bppArgb) ||
bitmap.PixelFormat.Equals(PixelFormat.Format32bppRgb) ||
bitmap.PixelFormat.Equals(PixelFormat.Format24bppRgb));
}
}
}

View file

@ -0,0 +1,44 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
/// <summary>
/// Description of GrayscaleFilter.
/// </summary>
[Serializable()]
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);
}
}
}

View file

@ -0,0 +1,51 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
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);
}
}
}

View file

@ -0,0 +1,37 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
public interface IFilter : INotifyPropertyChanged, IFieldHolder {
DrawableContainer Parent {get; set; }
void Apply(Graphics graphics, Bitmap bmp, Rectangle rect, RenderMode renderMode);
DrawableContainer GetParent();
bool Invert {get; set;}
}
}

View file

@ -0,0 +1,65 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
[Serializable()]
public class MagnifierFilter : AbstractFilter {
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 = IntersectRectangle(applyBitmap.Size, rect);
bbbSrc = new BitmapBuffer(applyBitmap, applyRect);
try {
bbbSrc.Lock();
base.Apply(graphics, applyBitmap, applyRect, renderMode);
} finally {
bbbSrc.Dispose();
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);
}
}
}

View file

@ -0,0 +1,87 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using Greenshot.Configuration;
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Plugin.Drawing;
namespace Greenshot.Drawing.Filters {
[Serializable()]
public class PixelizationFilter : AbstractFilter {
public PixelizationFilter(DrawableContainer parent) : base(parent) {
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) {
// Nothing to do
return;
}
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)) {
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) {
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));
}
}
}
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++) {
bbbDest.SetColorAt(xx, yy, currentAvgColor);
}
}
}
}
}
}
bbbDest.DrawTo(graphics, rect.Location);
}
}
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
applyRect = IntersectRectangle(applyBitmap.Size, rect);
Apply(graphics, applyBitmap, applyRect, pixelSize);
}
}
}