From 5c38d3cb5c230da5caef7f89feb04b1f9f11bd7d Mon Sep 17 00:00:00 2001 From: James South Date: Sun, 2 Nov 2014 14:35:12 +0000 Subject: [PATCH] Complete web Hue Former-commit-id: 6f97dfd92ba672efadb328c649bcade4e496667d Former-commit-id: 6c644f61bd279d440a551bab0a90650f7571cfb4 --- .../Configuration/Resources/processing.config | 1 + .../ImageProcessor.Web.csproj | 1 + src/ImageProcessor.Web/Processors/Hue.cs | 73 ++++++++----------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/ImageProcessor.Web/Configuration/Resources/processing.config b/src/ImageProcessor.Web/Configuration/Resources/processing.config index 9d4a46309..c178f04cf 100644 --- a/src/ImageProcessor.Web/Configuration/Resources/processing.config +++ b/src/ImageProcessor.Web/Configuration/Resources/processing.config @@ -27,6 +27,7 @@ + diff --git a/src/ImageProcessor.Web/ImageProcessor.Web.csproj b/src/ImageProcessor.Web/ImageProcessor.Web.csproj index 98f0385af..589ef0359 100644 --- a/src/ImageProcessor.Web/ImageProcessor.Web.csproj +++ b/src/ImageProcessor.Web/ImageProcessor.Web.csproj @@ -48,6 +48,7 @@ + diff --git a/src/ImageProcessor.Web/Processors/Hue.cs b/src/ImageProcessor.Web/Processors/Hue.cs index 0662e5f94..379ccffc9 100644 --- a/src/ImageProcessor.Web/Processors/Hue.cs +++ b/src/ImageProcessor.Web/Processors/Hue.cs @@ -1,30 +1,41 @@ -namespace ImageProcessor.Web.Processors +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to adjust the hue component of an image. +// +// -------------------------------------------------------------------------------------------------------------------- + +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; + /// + /// Encapsulates methods to adjust the hue component of an image. + /// public class Hue : IWebGraphicsProcessor { /// /// The regular expression to search strings for. /// - private static readonly Regex QueryRegex = new Regex(@"(hue=|pixelrect=)[^&]+", RegexOptions.Compiled); + private static readonly Regex QueryRegex = new Regex(@"(hue=|rotatehue=)[^&]+", RegexOptions.Compiled); /// - /// The pixel regex. + /// The hue regex. /// - private static readonly Regex PixelRegex = new Regex(@"pixelate=\d+", RegexOptions.Compiled); + private static readonly Regex HueRegex = new Regex(@"hue=\d+", RegexOptions.Compiled); /// - /// The rectangle regex. + /// The rotate regex. /// - 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); /// /// Initializes a new instance of the 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(size, rectangle); + int degrees = this.ParseDegrees(toParse); + bool rotate = RotateRegex.Match(toParse).Success; + this.Processor.DynamicParameter = new Tuple(degrees, rotate); } return this.SortOrder; } /// - /// Returns the correct size of pixels. + /// Returns the angle to alter the hue. /// /// /// The input containing the value to parse. /// /// - /// The representing the pixel size. + /// The representing the angle. /// - 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; - } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct - /// - 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)); } } }