Browse Source

Complete web Hue

Former-commit-id: 247c970c00fc3c227109a6ffd8eed52e03155791
Former-commit-id: 998d86f64d80e89e8a3419110eff018a24227a81
af/merge-core
James South 11 years ago
parent
commit
3d8575b851
  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"/>
</settings>
</plugin>
<plugin name="Hue" type="ImageProcessor.Web.Processors.Hue, ImageProcessor.Web"/>
<plugin name="Mask" type="ImageProcessor.Web.Processors.Mask, ImageProcessor.Web">
<settings>
<setting key="VirtualPath" value="~/images/masks/"/>

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

@ -48,6 +48,7 @@
<Compile Include="Caching\CachedImage.cs" />
<Compile Include="Processors\DetectEdges.cs" />
<Compile Include="Processors\EntropyCrop.cs" />
<Compile Include="Processors\Hue.cs" />
<Compile Include="Processors\Mask.cs" />
<Compile Include="Processors\Pixelate.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.Drawing;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Extensions;
/// <summary>
/// Encapsulates methods to adjust the hue component of an image.
/// </summary>
public class Hue : IWebGraphicsProcessor
{
/// <summary>
/// The regular expression to search strings for.
/// </summary>
private static readonly Regex QueryRegex = new Regex(@"(hue=|pixelrect=)[^&]+", RegexOptions.Compiled);
private static readonly Regex QueryRegex = new Regex(@"(hue=|rotatehue=)[^&]+", RegexOptions.Compiled);
/// <summary>
/// The pixel regex.
/// The hue regex.
/// </summary>
private static readonly Regex PixelRegex = new Regex(@"pixelate=\d+", RegexOptions.Compiled);
private static readonly Regex HueRegex = new Regex(@"hue=\d+", RegexOptions.Compiled);
/// <summary>
/// The rectangle regex.
/// The rotate regex.
/// </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>
/// Initializes a new instance of the <see cref="Hue"/> class.
@ -92,59 +103,33 @@
{
// Match syntax
string toParse = stringBuilder.ToString();
int size = this.ParseSize(toParse);
Rectangle? rectangle = this.ParseRectangle(toParse);
this.Processor.DynamicParameter = new Tuple<int, Rectangle?>(size, rectangle);
int degrees = this.ParseDegrees(toParse);
bool rotate = RotateRegex.Match(toParse).Success;
this.Processor.DynamicParameter = new Tuple<int, bool>(degrees, rotate);
}
return this.SortOrder;
}
/// <summary>
/// Returns the correct size of pixels.
/// Returns the angle to alter the hue.
/// </summary>
/// <param name="input">
/// The input containing the value to parse.
/// </param>
/// <returns>
/// The <see cref="int"/> representing the pixel size.
/// The <see cref="int"/> representing the angle.
/// </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;
}
/// <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;
return Math.Max(0, Math.Min(360, degrees));
}
}
}

Loading…
Cancel
Save