Browse Source

Complete web Hue

Former-commit-id: 6f97dfd92ba672efadb328c649bcade4e496667d
Former-commit-id: 6c644f61bd279d440a551bab0a90650f7571cfb4
pull/17/head
James South 12 years ago
parent
commit
5c38d3cb5c
  1. 1
      src/ImageProcessor.Web/Configuration/Resources/processing.config
  2. 1
      src/ImageProcessor.Web/ImageProcessor.Web.csproj
  3. 73
      src/ImageProcessor.Web/Processors/Hue.cs

1
src/ImageProcessor.Web/Configuration/Resources/processing.config

@ -27,6 +27,7 @@
<setting key="MaxThreshold" value="100"/> <setting key="MaxThreshold" value="100"/>
</settings> </settings>
</plugin> </plugin>
<plugin name="Hue" type="ImageProcessor.Web.Processors.Hue, ImageProcessor.Web"/>
<plugin name="Mask" type="ImageProcessor.Web.Processors.Mask, ImageProcessor.Web"> <plugin name="Mask" type="ImageProcessor.Web.Processors.Mask, ImageProcessor.Web">
<settings> <settings>
<setting key="VirtualPath" value="~/images/masks/"/> <setting key="VirtualPath" value="~/images/masks/"/>

1
src/ImageProcessor.Web/ImageProcessor.Web.csproj

@ -48,6 +48,7 @@
<Compile Include="Caching\CachedImage.cs" /> <Compile Include="Caching\CachedImage.cs" />
<Compile Include="Processors\DetectEdges.cs" /> <Compile Include="Processors\DetectEdges.cs" />
<Compile Include="Processors\EntropyCrop.cs" /> <Compile Include="Processors\EntropyCrop.cs" />
<Compile Include="Processors\Hue.cs" />
<Compile Include="Processors\Mask.cs" /> <Compile Include="Processors\Mask.cs" />
<Compile Include="Processors\Pixelate.cs" /> <Compile Include="Processors\Pixelate.cs" />
<Compile Include="Services\IImageService.cs" /> <Compile Include="Services\IImageService.cs" />

73
src/ImageProcessor.Web/Processors/Hue.cs

@ -1,30 +1,41 @@
namespace ImageProcessor.Web.Processors // --------------------------------------------------------------------------------------------------------------------
// <copyright file="Hue.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Encapsulates methods to adjust the hue component of an image.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Processors
{ {
using System; using System;
using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ImageProcessor.Processors; using ImageProcessor.Processors;
using ImageProcessor.Web.Extensions;
/// <summary>
/// Encapsulates methods to adjust the hue component of an image.
/// </summary>
public class Hue : IWebGraphicsProcessor public class Hue : IWebGraphicsProcessor
{ {
/// <summary> /// <summary>
/// The regular expression to search strings for. /// The regular expression to search strings for.
/// </summary> /// </summary>
private static readonly Regex QueryRegex = new Regex(@"(hue=|pixelrect=)[^&]+", RegexOptions.Compiled); private static readonly Regex QueryRegex = new Regex(@"(hue=|rotatehue=)[^&]+", RegexOptions.Compiled);
/// <summary> /// <summary>
/// The pixel regex. /// The hue regex.
/// </summary> /// </summary>
private static readonly Regex PixelRegex = new Regex(@"pixelate=\d+", RegexOptions.Compiled); private static readonly Regex HueRegex = new Regex(@"hue=\d+", RegexOptions.Compiled);
/// <summary> /// <summary>
/// The rectangle regex. /// The rotate regex.
/// </summary> /// </summary>
private static readonly Regex RectangleRegex = new Regex(@"pixelrect=\d+,\d+,\d+,\d+", RegexOptions.Compiled); private static readonly Regex RotateRegex = new Regex(@"rotatehue=true", RegexOptions.Compiled);
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Hue"/> class. /// Initializes a new instance of the <see cref="Hue"/> class.
@ -92,59 +103,33 @@
{ {
// Match syntax // Match syntax
string toParse = stringBuilder.ToString(); string toParse = stringBuilder.ToString();
int size = this.ParseSize(toParse); int degrees = this.ParseDegrees(toParse);
Rectangle? rectangle = this.ParseRectangle(toParse); bool rotate = RotateRegex.Match(toParse).Success;
this.Processor.DynamicParameter = new Tuple<int, Rectangle?>(size, rectangle); this.Processor.DynamicParameter = new Tuple<int, bool>(degrees, rotate);
} }
return this.SortOrder; return this.SortOrder;
} }
/// <summary> /// <summary>
/// Returns the correct size of pixels. /// Returns the angle to alter the hue.
/// </summary> /// </summary>
/// <param name="input"> /// <param name="input">
/// The input containing the value to parse. /// The input containing the value to parse.
/// </param> /// </param>
/// <returns> /// <returns>
/// The <see cref="int"/> representing the pixel size. /// The <see cref="int"/> representing the angle.
/// </returns> /// </returns>
public int ParseSize(string input) public int ParseDegrees(string input)
{ {
int size = 0; int degrees = 0;
foreach (Match match in PixelRegex.Matches(input)) foreach (Match match in HueRegex.Matches(input))
{ {
size = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); degrees = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
} }
return size; return Math.Max(0, Math.Min(360, degrees));
}
/// <summary>
/// Returns the correct <see cref="Nullable{Rectange}"/> for the given string.
/// </summary>
/// <param name="input">
/// The input string containing the value to parse.
/// </param>
/// <returns>
/// The correct <see cref="Nullable{Rectange}"/>
/// </returns>
private Rectangle? ParseRectangle(string input)
{
int[] dimensions = { };
foreach (Match match in RectangleRegex.Matches(input))
{
dimensions = match.Value.ToPositiveIntegerArray();
}
if (dimensions.Length == 4)
{
return new Rectangle(dimensions[0], dimensions[1], dimensions[2], dimensions[3]);
}
return null;
} }
} }
} }

Loading…
Cancel
Save