Browse Source

Adding vignette

Fixing losatch filter also.


Former-commit-id: 24c21fd0d7ebaae4131279f53ce33d9db099c287
af/merge-core
James South 12 years ago
parent
commit
3497060f4c
  1. 2
      src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs
  2. 1
      src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
  3. 98
      src/ImageProcessor.Web/NET45/Processors/Vignette.cs
  4. 13
      src/ImageProcessor/ImageFactory.cs
  5. 2
      src/ImageProcessor/Imaging/Filters/MatrixFilters.cs
  6. 73
      src/ImageProcessor/Processors/Vignette.cs

2
src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs

@ -25,7 +25,7 @@ namespace ImageProcessor.Web.Helpers
/// <summary>
/// The regular expression to search strings for colors.
/// </summary>
private static readonly Regex ColorRegex = new Regex(@"(bgcolor|color|tint)(=|-)(\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2})", RegexOptions.Compiled);
private static readonly Regex ColorRegex = new Regex(@"(bgcolor|color|tint|vignette)(=|-)(\d+,\d+,\d+,\d+|([0-9a-fA-F]{3}){1,2})", RegexOptions.Compiled);
/// <summary>
/// The regular expression to search strings for angles.

1
src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj

@ -77,6 +77,7 @@
<Compile Include="Processors\Rotate.cs" />
<Compile Include="Processors\Saturation.cs" />
<Compile Include="Processors\Tint.cs" />
<Compile Include="Processors\Vignette.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

98
src/ImageProcessor.Web/NET45/Processors/Vignette.cs

@ -0,0 +1,98 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Vignette.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Encapsulates methods with which to add a vignette image effect to an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Processors
{
using System.Drawing;
using System.Text.RegularExpressions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Helpers;
/// <summary>
/// Encapsulates methods with which to add a vignette image effect to an image.
/// </summary>
public class Vignette : IWebGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"vignette=(true)?[^&]*", RegexOptions.Compiled);
/// <summary>
/// Initializes a new instance of the <see cref="Vignette"/> class.
/// </summary>
public Vignette()
{
this.Processor = new ImageProcessor.Processors.Vignette();
}
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder { get; private set; }
/// <summary>
/// Gets the associated graphics processor.
/// </summary>
public IGraphicsProcessor Processor { get; private set; }
/// <summary>
/// The position in the original string where the first character of the captured substring was found.
/// </summary>
/// <param name="queryString">
/// The query string to search.
/// </param>
/// <returns>
/// The zero-based starting position in the original string where the captured substring was found.
/// </returns>
public int MatchRegexIndex(string queryString)
{
int index = 0;
// Set the sort order to max to allow filtering.
this.SortOrder = int.MaxValue;
foreach (Match match in this.RegexPattern.Matches(queryString))
{
if (match.Success)
{
if (index == 0)
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
Color color = CommonParameterParserUtility.ParseColor(match.Value);
if (color.Equals(Color.Transparent))
{
color = Color.Black;
}
this.Processor.DynamicParameter = color;
}
index += 1;
}
}
return this.SortOrder;
}
}
}

13
src/ImageProcessor/ImageFactory.cs

@ -788,14 +788,23 @@ namespace ImageProcessor
/// <summary>
/// Adds a vignette image effect to the current image.
/// </summary>
/// <param name="color">
/// The <see cref="T:System.Drawing.Color"/> to tint the image with. Defaults to black.
/// </param>
/// <returns>
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public ImageFactory Vignette()
public ImageFactory Vignette(Color? color = null)
{
if (this.ShouldProcess)
{
Vignette vignette = new Vignette();
Vignette vignette = new Vignette
{
DynamicParameter = color.HasValue && !color.Equals(Color.Transparent)
? color.Value
: Color.Black
};
this.CurrentImageFormat.ApplyProcessor(vignette.ProcessImage, this);
}

2
src/ImageProcessor/Imaging/Filters/MatrixFilters.cs

@ -101,7 +101,7 @@ namespace ImageProcessor.Imaging.Filters
{
get
{
return new LomographMatrixFilter();
return new LoSatchMatrixFilter();
}
}

73
src/ImageProcessor/Processors/Vignette.cs

@ -24,20 +24,11 @@ namespace ImageProcessor.Processors
public class Vignette : IGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// Initializes a new instance of the <see cref="Vignette"/> class.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"vignette=true", RegexOptions.Compiled);
#region IGraphicsProcessor Members
/// <summary>
/// Gets the regular expression to search strings for.
/// </summary>
public Regex RegexPattern
public Vignette()
{
get
{
return QueryRegex;
}
this.DynamicParameter = Color.Black;
}
/// <summary>
@ -49,15 +40,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// Gets the order in which this processor is to be used in a chain.
/// </summary>
public int SortOrder
{
get;
private set;
}
/// <summary>
/// Gets or sets any additional settings required by the processor.
/// </summary>
@ -67,41 +49,6 @@ namespace ImageProcessor.Processors
set;
}
/// <summary>
/// The position in the original string where the first character of the captured substring was found.
/// </summary>
/// <param name="queryString">
/// The query string to search.
/// </param>
/// <returns>
/// The zero-based starting position in the original string where the captured substring was found.
/// </returns>
public int MatchRegexIndex(string queryString)
{
int index = 0;
// Set the sort order to max to allow filtering.
this.SortOrder = int.MaxValue;
foreach (Match match in this.RegexPattern.Matches(queryString))
{
if (match.Success)
{
if (index == 0)
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
bool doVignette;
this.DynamicParameter = bool.TryParse(match.Value.Split('=')[1], out doVignette);
}
index += 1;
}
}
return this.SortOrder;
}
/// <summary>
/// Processes the image.
/// </summary>
@ -139,12 +86,15 @@ namespace ImageProcessor.Processors
path.AddEllipse(ellipsebounds);
using (PathGradientBrush brush = new PathGradientBrush(path))
{
// Fill a rectangle with an elliptical gradient brush that goes from white to black.
// Change the colour from white to pure transparent black and from black to pure opaque black.
// This has the effect of painting the far corners black and shade less on the way in to the centre.
// Fill a rectangle with an elliptical gradient brush that goes from transparent to opaque.
// This has the effect of painting the far corners with the given color and shade less on the way in to the centre.
Color baseColor = (Color)this.DynamicParameter;
Color centerColor = Color.FromArgb(0, baseColor.R, baseColor.G, baseColor.B);
Color edgeColor = Color.FromArgb(255, baseColor.R, baseColor.G, baseColor.B);
brush.WrapMode = WrapMode.Tile;
brush.CenterColor = Color.FromArgb(0, 0, 0, 0);
brush.SurroundColors = new[] { Color.FromArgb(255, 0, 0, 0) };
brush.CenterColor = centerColor;
brush.SurroundColors = new[] { edgeColor };
Blend blend = new Blend
{
@ -176,6 +126,5 @@ namespace ImageProcessor.Processors
return image;
}
#endregion
}
}
Loading…
Cancel
Save