From b83179d67aff2761607dcef48ef2da269f2d1ced Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 10 Jun 2014 16:38:38 +0200 Subject: [PATCH] Moar conversions! Former-commit-id: f812ee5350b737eb4df0bccae42025c44d133065 --- .../ImageCacheSection.cs | 0 .../ImageProcessingSection.cs | 0 .../ImageProcessorConfiguration.cs | 29 +-- .../ImageSecuritySection.cs | 0 .../Resources/cache.config | 0 .../Resources/processing - Copy.config} | 0 .../Configuration/Resources/processing.config | 40 +++++ .../Resources/security.config | 0 ...ies.cs => CommonParameterParserUtility.cs} | 29 ++- .../HttpModules/ImageProcessingModule.cs | 2 +- .../NET45/ImageFactoryExtensions.cs | 8 +- .../NET45/ImageProcessor.Web_NET45.csproj | 27 ++- .../NET45/Processors/Alpha.cs | 80 +++++++++ .../NET45/Processors/BackgroundColor.cs | 2 +- .../NET45/Processors/Brightness.cs | 89 ++++++++++ .../NET45/Processors/Contrast.cs | 89 ++++++++++ .../NET45/Processors/Crop.cs | 166 ++++++++++++++++++ .../NET45/Processors/Quality.cs | 90 ++++++++++ .../NET45/Processors/Rotate.cs | 2 +- .../NET45/Processors/Saturation.cs | 92 ++++++++++ src/ImageProcessor/ImageFactory.cs | 37 +--- .../Imaging/Filters/GothamMatrixFilter.cs | 8 +- .../Imaging/Filters/LomographMatrixFilter.cs | 5 +- .../Imaging/Filters/PolaroidMatrixFilter.cs | 2 +- .../Imaging/Formats/FormatBase.cs | 2 +- .../Imaging/Formats/GifFormat.cs | 4 +- src/ImageProcessor/Processors/Alpha.cs | 68 ------- src/ImageProcessor/Processors/Brightness.cs | 98 ++--------- src/ImageProcessor/Processors/Contrast.cs | 80 +-------- src/ImageProcessor/Processors/Crop.cs | 144 +-------------- src/ImageProcessor/Processors/Quality.cs | 67 ------- src/ImageProcessor/Processors/Saturation.cs | 75 +------- .../NET45/Test_Website_NET45/Web.config | 6 +- .../config/imageprocessor/processing.config | 44 +++-- 34 files changed, 783 insertions(+), 602 deletions(-) rename src/ImageProcessor.Web/NET45/{Config => Configuration}/ImageCacheSection.cs (100%) rename src/ImageProcessor.Web/NET45/{Config => Configuration}/ImageProcessingSection.cs (100%) rename src/ImageProcessor.Web/NET45/{Config => Configuration}/ImageProcessorConfiguration.cs (91%) rename src/ImageProcessor.Web/NET45/{Config => Configuration}/ImageSecuritySection.cs (100%) rename src/ImageProcessor.Web/NET45/{Config => Configuration}/Resources/cache.config (100%) rename src/ImageProcessor.Web/NET45/{Config/Resources/processing.config => Configuration/Resources/processing - Copy.config} (100%) create mode 100644 src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config rename src/ImageProcessor.Web/NET45/{Config => Configuration}/Resources/security.config (100%) rename src/ImageProcessor.Web/NET45/Helpers/{ParameterParserUtilities.cs => CommonParameterParserUtility.cs} (76%) create mode 100644 src/ImageProcessor.Web/NET45/Processors/Alpha.cs create mode 100644 src/ImageProcessor.Web/NET45/Processors/Brightness.cs create mode 100644 src/ImageProcessor.Web/NET45/Processors/Contrast.cs create mode 100644 src/ImageProcessor.Web/NET45/Processors/Crop.cs create mode 100644 src/ImageProcessor.Web/NET45/Processors/Quality.cs create mode 100644 src/ImageProcessor.Web/NET45/Processors/Saturation.cs diff --git a/src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageCacheSection.cs similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/ImageCacheSection.cs rename to src/ImageProcessor.Web/NET45/Configuration/ImageCacheSection.cs diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessingSection.cs similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/ImageProcessingSection.cs rename to src/ImageProcessor.Web/NET45/Configuration/ImageProcessingSection.cs diff --git a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfiguration.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs similarity index 91% rename from src/ImageProcessor.Web/NET45/Config/ImageProcessorConfiguration.cs rename to src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs index 2bcf73d78..e871a5c35 100644 --- a/src/ImageProcessor.Web/NET45/Config/ImageProcessorConfiguration.cs +++ b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // @@ -18,6 +18,8 @@ namespace ImageProcessor.Web.Configuration using System.Reflection; using System.Web.Compilation; using ImageProcessor.Processors; + using ImageProcessor.Web.Processors; + #endregion /// @@ -64,8 +66,9 @@ namespace ImageProcessor.Web.Configuration #endregion #region Constructors + /// - /// Prevents a default instance of the class from being created. + /// Prevents a default instance of the class from being created. /// private ImageProcessorConfiguration() { @@ -75,7 +78,7 @@ namespace ImageProcessor.Web.Configuration #region Properties /// - /// Gets the current instance of the class. + /// Gets the current instance of the class. /// public static ImageProcessorConfiguration Instance { @@ -88,7 +91,7 @@ namespace ImageProcessor.Web.Configuration /// /// Gets the list of available GraphicsProcessors. /// - public IList GraphicsProcessors { get; private set; } + public IList GraphicsProcessors { get; private set; } /// /// Gets a value indicating whether to preserve exif meta data. @@ -292,7 +295,7 @@ namespace ImageProcessor.Web.Configuration { if (GetImageProcessingSection().Plugins.AutoLoadPlugins) { - Type type = typeof(IGraphicsProcessor); + Type type = typeof(IWebGraphicsProcessor); try { // Build a list of native IGraphicsProcessor instances. @@ -303,12 +306,12 @@ namespace ImageProcessor.Web.Configuration .ToList(); // Create them and add. - this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList(); + this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IWebGraphicsProcessor)).ToList(); // Add the available settings. - foreach (IGraphicsProcessor processor in this.GraphicsProcessors) + foreach (IWebGraphicsProcessor webProcessor in this.GraphicsProcessors) { - processor.Settings = this.GetPluginSettings(processor.GetType().Name); + webProcessor.Processor.Settings = this.GetPluginSettings(webProcessor.GetType().Name); } } catch (ReflectionTypeLoadException) @@ -332,23 +335,23 @@ namespace ImageProcessor.Web.Configuration private void LoadGraphicsProcessorsFromConfiguration() { ImageProcessingSection.PluginElementCollection pluginConfigs = imageProcessingSection.Plugins; - this.GraphicsProcessors = new List(); + this.GraphicsProcessors = new List(); foreach (ImageProcessingSection.PluginElement pluginConfig in pluginConfigs) { Type type = Type.GetType(pluginConfig.Type); if (type == null) { - throw new TypeLoadException("Couldn't load IGraphicsProcessor: " + pluginConfig.Type); + throw new TypeLoadException("Couldn't load IWebGraphicsProcessor: " + pluginConfig.Type); } - this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IGraphicsProcessor); + this.GraphicsProcessors.Add(Activator.CreateInstance(type) as IWebGraphicsProcessor); } // Add the available settings. - foreach (IGraphicsProcessor processor in this.GraphicsProcessors) + foreach (IWebGraphicsProcessor webProcessor in this.GraphicsProcessors) { - processor.Settings = this.GetPluginSettings(processor.GetType().Name); + webProcessor.Processor.Settings = this.GetPluginSettings(webProcessor.GetType().Name); } } #endregion diff --git a/src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageSecuritySection.cs similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs rename to src/ImageProcessor.Web/NET45/Configuration/ImageSecuritySection.cs diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/cache.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/cache.config similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/Resources/cache.config rename to src/ImageProcessor.Web/NET45/Configuration/Resources/cache.config diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/processing.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/Resources/processing.config rename to src/ImageProcessor.Web/NET45/Configuration/Resources/processing - Copy.config diff --git a/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config new file mode 100644 index 000000000..c29cd5db1 --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Configuration/Resources/processing.config @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/Config/Resources/security.config b/src/ImageProcessor.Web/NET45/Configuration/Resources/security.config similarity index 100% rename from src/ImageProcessor.Web/NET45/Config/Resources/security.config rename to src/ImageProcessor.Web/NET45/Configuration/Resources/security.config diff --git a/src/ImageProcessor.Web/NET45/Helpers/ParameterParserUtilities.cs b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs similarity index 76% rename from src/ImageProcessor.Web/NET45/Helpers/ParameterParserUtilities.cs rename to src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs index eb6af4357..d4039acdd 100644 --- a/src/ImageProcessor.Web/NET45/Helpers/ParameterParserUtilities.cs +++ b/src/ImageProcessor.Web/NET45/Helpers/CommonParameterParserUtility.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // @@ -18,7 +18,7 @@ namespace ImageProcessor.Web.Helpers /// /// Encapsulates methods to correctly parse querystring parameters. /// - public static class ParameterParserUtilities + public static class CommonParameterParserUtility { /// /// The regular expression to search strings for colors. @@ -30,6 +30,11 @@ namespace ImageProcessor.Web.Helpers /// private static readonly Regex AngleRegex = new Regex(@"(rotate|angle)(=|-)(?:3[0-5][0-9]|[12][0-9]{2}|[1-9][0-9]?)", RegexOptions.Compiled); + /// + /// The regular expression to search strings for values between 1 and 100. + /// + private static readonly Regex In100RangeRegex = new Regex(@"(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); + /// /// Returns the correct containing the angle for the given string. /// @@ -86,5 +91,25 @@ namespace ImageProcessor.Web.Helpers return Color.Transparent; } + + /// + /// Returns the correct for the given string. + /// + /// + /// The input string containing the value to parse. + /// + /// + /// The correct between -100 and 100. + /// + public static int ParseIn100Range(string input) + { + int value = 0; + foreach (Match match in In100RangeRegex.Matches(input)) + { + value = int.Parse(match.Value, CultureInfo.InvariantCulture); + } + + return value; + } } } diff --git a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs index 6d10a49ee..213d35b2a 100644 --- a/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs @@ -414,7 +414,7 @@ namespace ImageProcessor.Web.HttpModules .Save(cachedPath); // Store the response type in the context for later retrieval. - context.Items[CachedResponseTypeKey] = imageFactory.MimeType; + context.Items[CachedResponseTypeKey] = imageFactory.CurrentImageFormat.MimeType; // Ensure that the LastWriteTime property of the source and cached file match. Tuple creationAndLastWriteDateTimes = await cache.SetCachedLastWriteTimeAsync(); diff --git a/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs b/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs index c677149fb..704373a55 100644 --- a/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs +++ b/src/ImageProcessor.Web/NET45/ImageFactoryExtensions.cs @@ -13,8 +13,8 @@ namespace ImageProcessor.Web #region Using using System.Collections.Generic; using System.Linq; - using ImageProcessor.Processors; using ImageProcessor.Web.Configuration; + using ImageProcessor.Web.Processors; #endregion /// @@ -45,16 +45,16 @@ namespace ImageProcessor.Web lock (SyncRoot) { // Get a list of all graphics processors that have parsed and matched the query string. - List graphicsProcessors = + List graphicsProcessors = ImageProcessorConfiguration.Instance.GraphicsProcessors .Where(x => x.MatchRegexIndex(factory.QueryString) != int.MaxValue) .OrderBy(y => y.SortOrder) .ToList(); // Loop through and process the image. - foreach (IGraphicsProcessor graphicsProcessor in graphicsProcessors) + foreach (IWebGraphicsProcessor graphicsProcessor in graphicsProcessors) { - factory.CurrentImageFormat.ApplyProcessor(graphicsProcessor.ProcessImage, factory); + factory.CurrentImageFormat.ApplyProcessor(graphicsProcessor.Processor.ProcessImage, factory); } } } diff --git a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj index bdf8ba8dc..40d4d8fdd 100644 --- a/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj +++ b/src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj @@ -49,20 +49,26 @@ - - - - - + + + + + + + + + + + @@ -72,13 +78,18 @@ - + Designer - + + Designer + + + + + Designer - diff --git a/src/ImageProcessor.Web/NET45/Processors/Alpha.cs b/src/ImageProcessor.Web/NET45/Processors/Alpha.cs new file mode 100644 index 000000000..75993a702 --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Alpha.cs @@ -0,0 +1,80 @@ +namespace ImageProcessor.Web.Processors +{ + using System; + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods to change the alpha component of the image to effect its transparency. + /// + public class Alpha : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"alpha=[^&|,]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Alpha() + { + this.Processor = new ImageProcessor.Processors.Alpha(); + } + + /// + /// 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) + { + 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; + int percentage = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value)); + this.Processor.DynamicParameter = percentage; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} diff --git a/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs b/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs index 7fc0a49a5..80df3959c 100644 --- a/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs +++ b/src/ImageProcessor.Web/NET45/Processors/BackgroundColor.cs @@ -75,7 +75,7 @@ namespace ImageProcessor.Web.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - this.Processor.DynamicParameter = ParameterParserUtilities.ParseColor(match.Value); + this.Processor.DynamicParameter = CommonParameterParserUtility.ParseColor(match.Value); } index += 1; diff --git a/src/ImageProcessor.Web/NET45/Processors/Brightness.cs b/src/ImageProcessor.Web/NET45/Processors/Brightness.cs new file mode 100644 index 000000000..602d34b1c --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Brightness.cs @@ -0,0 +1,89 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to change the brightness component of the image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods to change the brightness component of the image. + /// + public class Brightness : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"brightness=[^&|,]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Brightness() + { + this.Processor = new ImageProcessor.Processors.Brightness(); + } + + /// + /// 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) + { + 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; + int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); + this.Processor.DynamicParameter = percentage; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/Processors/Contrast.cs b/src/ImageProcessor.Web/NET45/Processors/Contrast.cs new file mode 100644 index 000000000..09ec2808c --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Contrast.cs @@ -0,0 +1,89 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to change the contrast component of the image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods to change the contrast component of the image. + /// + public class Contrast : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"contrast=[^&|,]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Contrast() + { + this.Processor = new ImageProcessor.Processors.Contrast(); + } + + /// + /// 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) + { + 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; + int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); + this.Processor.DynamicParameter = percentage; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor.Web/NET45/Processors/Crop.cs b/src/ImageProcessor.Web/NET45/Processors/Crop.cs new file mode 100644 index 000000000..4ca186d5c --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Crop.cs @@ -0,0 +1,166 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Crops an image to the given directions. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System.Text; + using System.Text.RegularExpressions; + using ImageProcessor.Core.Common.Extensions; + using ImageProcessor.Imaging; + using ImageProcessor.Processors; + + /// + /// Crops an image to the given directions. + /// + public class Crop : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + /// + private static readonly Regex QueryRegex = new Regex(@"(crop=|cropmode=)[^&]*", RegexOptions.Compiled); + + /// + /// The coordinate regex. + /// + private static readonly Regex CoordinateRegex = new Regex(@"crop=\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?", RegexOptions.Compiled); + + /// + /// The mode regex. + /// + private static readonly Regex ModeRegex = new Regex(@"cropmode=(pixels|percent)", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Crop() + { + this.Processor = new ImageProcessor.Processors.Crop(); + } + + /// + /// 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) + { + int index = 0; + + // Set the sort order to max to allow filtering. + this.SortOrder = int.MaxValue; + + // First merge the matches so we can parse . + StringBuilder stringBuilder = new StringBuilder(); + + 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; + } + + stringBuilder.Append(match.Value); + + index += 1; + } + } + + if (this.SortOrder < int.MaxValue) + { + // Match syntax + string toParse = stringBuilder.ToString(); + + float[] coordinates = this.ParseCoordinates(toParse); + CropMode cropMode = this.ParseMode(toParse); + + CropLayer cropLayer = new CropLayer(coordinates[0], coordinates[1], coordinates[2], coordinates[3], cropMode); + this.Processor.DynamicParameter = cropLayer; + } + + return this.SortOrder; + } + + /// + /// Returns the correct for the given string. + /// + /// + /// The input string containing the value to parse. + /// + /// + /// The correct . + /// + private CropMode ParseMode(string input) + { + foreach (Match match in ModeRegex.Matches(input)) + { + // Split on = + string mode = match.Value.Split('=')[1]; + + switch (mode) + { + case "percent": + return CropMode.Percentage; + case "pixels": + return CropMode.Pixels; + } + } + + return CropMode.Pixels; + } + + /// + /// Returns the correct for the given string. + /// + /// + /// The input string containing the value to parse. + /// + /// + /// The correct . + /// + private float[] ParseCoordinates(string input) + { + float[] floats = { }; + + foreach (Match match in CoordinateRegex.Matches(input)) + { + floats = match.Value.ToPositiveFloatArray(); + } + + return floats; + } + } +} diff --git a/src/ImageProcessor.Web/NET45/Processors/Quality.cs b/src/ImageProcessor.Web/NET45/Processors/Quality.cs new file mode 100644 index 000000000..fa11777db --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Quality.cs @@ -0,0 +1,90 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to change the quality component of the image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System; + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods to change the quality component of the image. + /// + public class Quality : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"quality=[^&|,]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Quality() + { + this.Processor = new ImageProcessor.Processors.Quality(); + } + + /// + /// 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) + { + 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; + int percentage = Math.Abs(CommonParameterParserUtility.ParseIn100Range(match.Value)); + this.Processor.DynamicParameter = percentage; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} diff --git a/src/ImageProcessor.Web/NET45/Processors/Rotate.cs b/src/ImageProcessor.Web/NET45/Processors/Rotate.cs index 58375b179..74a707d36 100644 --- a/src/ImageProcessor.Web/NET45/Processors/Rotate.cs +++ b/src/ImageProcessor.Web/NET45/Processors/Rotate.cs @@ -82,7 +82,7 @@ namespace ImageProcessor.Web.Processors { // Set the index on the first instance only. this.SortOrder = match.Index; - this.Processor.DynamicParameter = ParameterParserUtilities.ParseAngle(match.Value); + this.Processor.DynamicParameter = CommonParameterParserUtility.ParseAngle(match.Value); } index += 1; diff --git a/src/ImageProcessor.Web/NET45/Processors/Saturation.cs b/src/ImageProcessor.Web/NET45/Processors/Saturation.cs new file mode 100644 index 000000000..469a19ba6 --- /dev/null +++ b/src/ImageProcessor.Web/NET45/Processors/Saturation.cs @@ -0,0 +1,92 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to change the saturation component of the image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Web.Processors +{ + using System.Text.RegularExpressions; + using ImageProcessor.Processors; + using ImageProcessor.Web.Helpers; + + /// + /// Encapsulates methods to change the saturation component of the image. + /// + /// + /// + /// + public class Saturation : IWebGraphicsProcessor + { + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"saturation=[^&|,]*", RegexOptions.Compiled); + + /// + /// Initializes a new instance of the class. + /// + public Saturation() + { + this.Processor = new ImageProcessor.Processors.Saturation(); + } + + /// + /// 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) + { + 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; + int percentage = CommonParameterParserUtility.ParseIn100Range(match.Value); + this.Processor.DynamicParameter = percentage; + } + + index += 1; + } + } + + return this.SortOrder; + } + } +} \ No newline at end of file diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 8d9b34f75..c0ac9062b 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -91,11 +91,6 @@ namespace ImageProcessor #endregion #region Properties - /// - /// Gets the local image for manipulation. - /// - public Image Image { get; private set; } - /// /// Gets the path to the local image for manipulation. /// @@ -126,6 +121,11 @@ namespace ImageProcessor /// public ConcurrentDictionary ExifPropertyItems { get; set; } + /// + /// Gets or sets the local image for manipulation. + /// + internal Image Image { get; set; } + /// /// Gets or sets the original extension. /// @@ -254,33 +254,6 @@ namespace ImageProcessor return this; } - /// - /// Updates the specified image. Used by the various IProcessors. - /// - /// The image. - /// - /// The current instance of the class. - /// - public ImageFactory Update(Image image) - { - if (this.ShouldProcess) - { - this.Image = image; - - // Get the correct image format for the image. - using (MemoryStream stream = new MemoryStream()) - { - image.Save(stream, image.RawFormat); - stream.Position = 0; - int quality = this.CurrentImageFormat.Quality; - this.CurrentImageFormat = FormatUtilities.GetFormat(stream); - this.CurrentImageFormat.Quality = quality; - } - } - - return this; - } - /// /// Resets the current image to its original loaded state. /// diff --git a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs index ddbb92128..abeaedf5c 100644 --- a/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/GothamMatrixFilter.cs @@ -79,13 +79,13 @@ namespace ImageProcessor.Imaging.Filters } // Add brightness and contrast to finish the effect. - factory.Update(newImage); + factory.Image = newImage; Brightness brightness = new Brightness { DynamicParameter = 5 }; - newImage = (Bitmap)brightness.ProcessImage(factory); + newImage = brightness.ProcessImage(factory); - factory.Update(newImage); + factory.Image = newImage; Contrast contrast = new Contrast { DynamicParameter = 85 }; - newImage = (Bitmap)contrast.ProcessImage(factory); + newImage = contrast.ProcessImage(factory); // Reassign the image. image.Dispose(); diff --git a/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs index c44bce5c8..253bb419a 100644 --- a/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/LomographMatrixFilter.cs @@ -50,15 +50,14 @@ namespace ImageProcessor.Imaging.Filters attributes.SetColorMatrix(this.Matrix); Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height); - graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); } } // Add a vignette to finish the effect. - factory.Update(newImage); + factory.Image = newImage; Vignette vignette = new Vignette(); - newImage = (Bitmap)vignette.ProcessImage(factory); + newImage = vignette.ProcessImage(factory); // Reassign the image. image.Dispose(); diff --git a/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs b/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs index 947c79f25..af4c5fd4f 100644 --- a/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs +++ b/src/ImageProcessor/Imaging/Filters/PolaroidMatrixFilter.cs @@ -85,7 +85,7 @@ namespace ImageProcessor.Imaging.Filters } // Add a vignette to finish the effect. - factory.Update(newImage); + factory.Image = newImage; Vignette vignette = new Vignette(); newImage = vignette.ProcessImage(factory); diff --git a/src/ImageProcessor/Imaging/Formats/FormatBase.cs b/src/ImageProcessor/Imaging/Formats/FormatBase.cs index 79c90a12b..de590aea2 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatBase.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatBase.cs @@ -73,7 +73,7 @@ namespace ImageProcessor.Imaging.Formats /// The . public virtual void ApplyProcessor(Func processor, ImageFactory factory) { - processor.Invoke(factory); + factory.Image = processor.Invoke(factory); } /// diff --git a/src/ImageProcessor/Imaging/Formats/GifFormat.cs b/src/ImageProcessor/Imaging/Formats/GifFormat.cs index b2b3cb413..87c9a0d30 100644 --- a/src/ImageProcessor/Imaging/Formats/GifFormat.cs +++ b/src/ImageProcessor/Imaging/Formats/GifFormat.cs @@ -86,14 +86,14 @@ namespace ImageProcessor.Imaging.Formats { foreach (GifFrame frame in imageInfo.GifFrames) { - factory.Update(frame.Image); + factory.Image = frame.Image; frame.Image = quantizer.Quantize(processor.Invoke(factory)); encoder.AddFrame(frame); } } stream.Position = 0; - factory.Update(Image.FromStream(stream)); + factory.Image = Image.FromStream(stream); } else { diff --git a/src/ImageProcessor/Processors/Alpha.cs b/src/ImageProcessor/Processors/Alpha.cs index 70ff57a65..6301c0e97 100644 --- a/src/ImageProcessor/Processors/Alpha.cs +++ b/src/ImageProcessor/Processors/Alpha.cs @@ -10,37 +10,15 @@ namespace ImageProcessor.Processors { - #region Using using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; - using System.Globalization; - using System.Text.RegularExpressions; - #endregion /// /// Encapsulates methods to change the alpha component of the image to effect its transparency. /// public class Alpha : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - /// - private static readonly Regex QueryRegex = new Regex(@"alpha=(?:100|[1-9]?[0-9])", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -50,15 +28,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -68,42 +37,6 @@ namespace ImageProcessor.Processors 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) - { - 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; - int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - - this.DynamicParameter = percentage; - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -152,6 +85,5 @@ namespace ImageProcessor.Processors return image; } - #endregion } } diff --git a/src/ImageProcessor/Processors/Brightness.cs b/src/ImageProcessor/Processors/Brightness.cs index 6671ec373..56a17cc2b 100644 --- a/src/ImageProcessor/Processors/Brightness.cs +++ b/src/ImageProcessor/Processors/Brightness.cs @@ -10,37 +10,15 @@ namespace ImageProcessor.Processors { - #region Using using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; - using System.Globalization; - using System.Text.RegularExpressions; - #endregion /// /// Encapsulates methods to change the brightness component of the image. /// public class Brightness : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - /// - private static readonly Regex QueryRegex = new Regex(@"brightness=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -50,15 +28,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -68,42 +37,6 @@ namespace ImageProcessor.Processors 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) - { - 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; - int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - - this.DynamicParameter = percentage; - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -125,16 +58,14 @@ namespace ImageProcessor.Processors newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb); - ColorMatrix colorMatrix = new ColorMatrix( - new float[][] - { - new float[] { 1, 0, 0, 0, 0 }, - new float[] { 0, 1, 0, 0, 0 }, - new float[] { 0, 0, 1, 0, 0 }, - new float[] { 0, 0, 0, 1, 0 }, - new float[] { brightnessFactor, brightnessFactor, brightnessFactor, 0, 1 } - }); - + ColorMatrix colorMatrix = + new ColorMatrix( + new[] + { + new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, + new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, + new[] { brightnessFactor, brightnessFactor, brightnessFactor, 0, 1 } + }); using (Graphics graphics = Graphics.FromImage(newImage)) { @@ -142,7 +73,15 @@ namespace ImageProcessor.Processors { imageAttributes.SetColorMatrix(colorMatrix); - graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes); + graphics.DrawImage( + image, + new Rectangle(0, 0, image.Width, image.Height), + 0, + 0, + image.Width, + image.Height, + GraphicsUnit.Pixel, + imageAttributes); image.Dispose(); image = newImage; @@ -159,6 +98,5 @@ namespace ImageProcessor.Processors return image; } - #endregion } -} +} \ No newline at end of file diff --git a/src/ImageProcessor/Processors/Contrast.cs b/src/ImageProcessor/Processors/Contrast.cs index 4d057d6d5..ee4557517 100644 --- a/src/ImageProcessor/Processors/Contrast.cs +++ b/src/ImageProcessor/Processors/Contrast.cs @@ -10,37 +10,15 @@ namespace ImageProcessor.Processors { - #region Using using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; - using System.Globalization; - using System.Text.RegularExpressions; - #endregion /// /// Encapsulates methods to change the contrast component of the image. /// public class Contrast : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - /// - private static readonly Regex QueryRegex = new Regex(@"contrast=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -50,15 +28,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -68,42 +37,6 @@ namespace ImageProcessor.Processors 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) - { - 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; - int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - - this.DynamicParameter = percentage; - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -130,13 +63,13 @@ namespace ImageProcessor.Processors newImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppPArgb); ColorMatrix colorMatrix = new ColorMatrix( - new float[][] + new[] { - new float[] { contrastFactor, 0, 0, 0, 0 }, - new float[] { 0, contrastFactor, 0, 0, 0 }, - new float[] { 0, 0, contrastFactor, 0, 0 }, + new[] { contrastFactor, 0, 0, 0, 0 }, + new[] { 0, contrastFactor, 0, 0, 0 }, + new[] { 0, 0, contrastFactor, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, - new float[] { factorTransform, factorTransform, factorTransform, 0, 1 } + new[] { factorTransform, factorTransform, factorTransform, 0, 1 } }); using (Graphics graphics = Graphics.FromImage(newImage)) @@ -162,6 +95,5 @@ namespace ImageProcessor.Processors return image; } - #endregion } -} +} \ No newline at end of file diff --git a/src/ImageProcessor/Processors/Crop.cs b/src/ImageProcessor/Processors/Crop.cs index 0124b0f61..abf9483ef 100644 --- a/src/ImageProcessor/Processors/Crop.cs +++ b/src/ImageProcessor/Processors/Crop.cs @@ -15,12 +15,7 @@ namespace ImageProcessor.Processors using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; - using System.Text; - using System.Text.RegularExpressions; - - using ImageProcessor.Core.Common.Extensions; using ImageProcessor.Imaging; - #endregion /// @@ -28,34 +23,6 @@ namespace ImageProcessor.Processors /// public class Crop : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - /// - private static readonly Regex QueryRegex = new Regex(@"crop=\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?|cropmode=(pixels|percent)", RegexOptions.Compiled); - - /// - /// The coordinate regex. - /// - private static readonly Regex CoordinateRegex = new Regex(@"crop=\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?[,-]\d+(.\d+)?", RegexOptions.Compiled); - - /// - /// The mode regex. - /// - private static readonly Regex ModeRegex = new Regex(@"cropmode=(pixels|percent)", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -65,15 +32,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -83,56 +41,6 @@ namespace ImageProcessor.Processors 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) - { - int index = 0; - - // Set the sort order to max to allow filtering. - this.SortOrder = int.MaxValue; - - // First merge the matches so we can parse . - StringBuilder stringBuilder = new StringBuilder(); - - 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; - } - - stringBuilder.Append(match.Value); - - index += 1; - } - } - - if (this.SortOrder < int.MaxValue) - { - // Match syntax - string toParse = stringBuilder.ToString(); - - float[] coordinates = this.ParseCoordinates(toParse); - CropMode cropMode = this.ParseMode(toParse); - - CropLayer cropLayer = new CropLayer(coordinates[0], coordinates[1], coordinates[2], coordinates[3], cropMode); - this.DynamicParameter = cropLayer; - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -159,7 +67,7 @@ namespace ImageProcessor.Processors // Work out the percentages. float left = cropLayer.Left * sourceWidth; float top = cropLayer.Top * sourceHeight; - float width = (1 - cropLayer.Left - cropLayer.Right) * sourceWidth; + float width = (1 - cropLayer.Left - cropLayer.Right) * sourceWidth; float height = (1 - cropLayer.Top - cropLayer.Bottom) * sourceHeight; rectangleF = new RectangleF(left, top, width, height); @@ -226,55 +134,5 @@ namespace ImageProcessor.Processors return image; } - #endregion - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct . - /// - private CropMode ParseMode(string input) - { - foreach (Match match in ModeRegex.Matches(input)) - { - // Split on = - string mode = match.Value.Split('=')[1]; - - switch (mode) - { - case "percent": - return CropMode.Percentage; - case "pixels": - return CropMode.Pixels; - } - } - - return CropMode.Pixels; - } - - /// - /// Returns the correct for the given string. - /// - /// - /// The input string containing the value to parse. - /// - /// - /// The correct . - /// - private float[] ParseCoordinates(string input) - { - float[] floats = { }; - - foreach (Match match in CoordinateRegex.Matches(input)) - { - floats = match.Value.ToPositiveFloatArray(); - } - - return floats; - } } } diff --git a/src/ImageProcessor/Processors/Quality.cs b/src/ImageProcessor/Processors/Quality.cs index 21995cd3c..6d4d10743 100644 --- a/src/ImageProcessor/Processors/Quality.cs +++ b/src/ImageProcessor/Processors/Quality.cs @@ -13,8 +13,6 @@ namespace ImageProcessor.Processors #region Using using System.Collections.Generic; using System.Drawing; - using System.Globalization; - using System.Text.RegularExpressions; #endregion /// @@ -22,23 +20,6 @@ namespace ImageProcessor.Processors /// public class Quality : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - private static readonly Regex QueryRegex = new Regex(@"quality=(?:100|[1-9]?[0-9])", RegexOptions.Compiled); - - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -48,15 +29,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -66,42 +38,6 @@ namespace ImageProcessor.Processors 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) - { - 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; - int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - - this.DynamicParameter = percentage; - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -114,11 +50,8 @@ namespace ImageProcessor.Processors /// public Image ProcessImage(ImageFactory factory) { - // Set the internal property. factory.CurrentImageFormat.Quality = this.DynamicParameter; - return factory.Image; } - #endregion } } diff --git a/src/ImageProcessor/Processors/Saturation.cs b/src/ImageProcessor/Processors/Saturation.cs index 268de2f4a..9e07ecbfe 100644 --- a/src/ImageProcessor/Processors/Saturation.cs +++ b/src/ImageProcessor/Processors/Saturation.cs @@ -14,9 +14,6 @@ namespace ImageProcessor.Processors using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; - using System.Globalization; - using System.Text.RegularExpressions; - #endregion /// @@ -27,24 +24,7 @@ namespace ImageProcessor.Processors /// public class Saturation : IGraphicsProcessor { - /// - /// The regular expression to search strings for. - /// - /// - private static readonly Regex QueryRegex = new Regex(@"saturation=(-?(?:100)|-?([1-9]?[0-9]))", RegexOptions.Compiled); - #region IGraphicsProcessor Members - /// - /// Gets the regular expression to search strings for. - /// - public Regex RegexPattern - { - get - { - return QueryRegex; - } - } - /// /// Gets or sets DynamicParameter. /// @@ -54,15 +34,6 @@ namespace ImageProcessor.Processors set; } - /// - /// Gets the order in which this processor is to be used in a chain. - /// - public int SortOrder - { - get; - private set; - } - /// /// Gets or sets any additional settings required by the processor. /// @@ -72,42 +43,6 @@ namespace ImageProcessor.Processors 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) - { - 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; - int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture); - - this.DynamicParameter = percentage; - } - - index += 1; - } - } - - return this.SortOrder; - } - /// /// Processes the image. /// @@ -142,19 +77,19 @@ namespace ImageProcessor.Processors ColorMatrix colorMatrix = new ColorMatrix( - new float[][] + new[] { - new float[] + new[] { saturationComplementR + saturationFactor, saturationComplementR, saturationComplementR, 0, 0 }, - new float[] + new[] { saturationComplementG, saturationComplementG + saturationFactor, saturationComplementG, 0, 0 }, - new float[] + new[] { saturationComplementB, saturationComplementB, saturationComplementB + saturationFactor, 0, 0 @@ -196,4 +131,4 @@ namespace ImageProcessor.Processors } #endregion } -} +} \ No newline at end of file diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Web.config b/src/TestWebsites/NET45/Test_Website_NET45/Web.config index a11127fee..db3f37806 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/Web.config +++ b/src/TestWebsites/NET45/Test_Website_NET45/Web.config @@ -7,9 +7,9 @@ -
-
-
+
+
+
diff --git a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config index 6aa5af4ea..6d9f621d1 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config +++ b/src/TestWebsites/NET45/Test_Website_NET45/config/imageprocessor/processing.config @@ -1,44 +1,40 @@ - - + - - - - - - - - - + + + + + + + + - + - - + + - - - + + - - - - - - + + + + + + -