// -------------------------------------------------------------------------------------------------------------------- // // 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.Collections.Specialized; using System.Globalization; using System.Text; using System.Text.RegularExpressions; using System.Web; using ImageProcessor.Imaging.Helpers; using ImageProcessor.Processors; using ImageProcessor.Web.Helpers; /// /// 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=\d+", RegexOptions.Compiled); /// /// Initializes a new instance of the class. /// public Hue() { this.Processor = new ImageProcessor.Processors.Hue(); } /// /// Gets the regular expression to search strings for. /// public Regex RegexPattern { get { return QueryRegex; } } /// /// Gets the order in which this processor is to be used in a chain. /// public int SortOrder { get; private set; } /// /// Gets the associated graphics processor. /// public IGraphicsProcessor Processor { get; private set; } /// /// The position in the original string where the first character of the captured substring was found. /// /// The query string to search. /// /// The zero-based starting position in the original string where the captured substring was found. /// public int MatchRegexIndex(string queryString) { this.SortOrder = int.MaxValue; Match match = this.RegexPattern.Match(queryString); if (match.Success) { this.SortOrder = match.Index; NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); int degrees = QueryParamParser.Instance.ParseValue(queryCollection["hue"]); bool rotate = QueryParamParser.Instance.ParseValue(queryCollection["hue.rotate"]); degrees = ImageMaths.Clamp(degrees, 0, 360); this.Processor.DynamicParameter = new Tuple(degrees, rotate); } return this.SortOrder; } } }