diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 6412226b5..a408ead68 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -15,6 +15,9 @@ namespace ImageProcessor.UnitTests using System.Drawing; using System.IO; using System.Linq; + + using ImageProcessor.Imaging; + using NUnit.Framework; /// @@ -244,7 +247,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.Watermark(new Imaging.TextLayer + imageFactory.Watermark(new TextLayer { FontFamily = new FontFamily("Arial"), FontSize = 10, @@ -286,7 +289,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.GaussianBlur(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); + imageFactory.GaussianBlur(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -322,7 +325,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.GaussianSharpen(new Imaging.GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); + imageFactory.GaussianSharpen(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -341,43 +344,43 @@ namespace ImageProcessor.UnitTests imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.BlackWhite); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.BlackWhite); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Comic); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Comic); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Gotham); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Gotham); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.GreyScale); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.GreyScale); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.HiSatch); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.HiSatch); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Invert); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Invert); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Lomograph); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Lomograph); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.LoSatch); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.LoSatch); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Polaroid); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Polaroid); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); - imageFactory.Filter(Imaging.Filters.MatrixFilters.Sepia); + imageFactory.Filter(ImageProcessor.Imaging.Filters.MatrixFilters.Sepia); Assert.AreNotEqual(original, imageFactory.Image); imageFactory.Reset(); } @@ -396,7 +399,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5)); + imageFactory.RoundedCorners(new RoundedCornerLayer(5)); Assert.AreNotEqual(original, imageFactory.Image); } } @@ -455,7 +458,7 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); Image original = (Image)imageFactory.Image.Clone(); - imageFactory.Crop(new Imaging.CropLayer(0, 0, MaxSize, MaxSize, Imaging.CropMode.Pixels)); + imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels)); Assert.AreNotEqual(original, imageFactory.Image); Assert.AreEqual(MaxSize, imageFactory.Image.Width); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); @@ -481,7 +484,7 @@ namespace ImageProcessor.UnitTests Assert.AreEqual(original.Height, imageFactory.Image.Height); imageFactory.Reset(); - imageFactory.Flip(false); + imageFactory.Flip(); Assert.AreNotEqual(original, imageFactory.Image); Assert.AreEqual(original.Width, imageFactory.Image.Width); Assert.AreEqual(original.Height, imageFactory.Image.Height); @@ -520,7 +523,7 @@ namespace ImageProcessor.UnitTests using (ImageFactory imageFactory = new ImageFactory()) { imageFactory.Load(file.FullName); - imageFactory.Resize(new Imaging.ResizeLayer(new Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); + imageFactory.Resize(new ResizeLayer(new Size(NewSize, NewSize), ResizeMode.Stretch, AnchorPosition.Left)); Assert.AreEqual(NewSize, imageFactory.Image.Width); Assert.AreEqual(NewSize, imageFactory.Image.Height); } diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index 7fa981bcf..fdc2c8668 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -51,6 +51,7 @@ + diff --git a/src/ImageProcessor.UnitTests/Imaging/ColorUnitTests.cs b/src/ImageProcessor.UnitTests/Imaging/ColorUnitTests.cs new file mode 100644 index 000000000..512b93d6e --- /dev/null +++ b/src/ImageProcessor.UnitTests/Imaging/ColorUnitTests.cs @@ -0,0 +1,61 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Test harness for the color classes. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.UnitTests.Imaging +{ + using System.Drawing; + using ImageProcessor.Imaging.Colors; + using NUnit.Framework; + + /// + /// Test harness for the color classes. + /// + [TestFixture] + public class ColorUnitTests + { + /// + /// Tests the struct equality operators. + /// + [Test] + public void TestRGBAEquality() + { + RGBAColor first = new RGBAColor(Color.White); + RGBAColor second = new RGBAColor(Color.White); + + Assert.AreEqual(first, second); + } + + /// + /// Tests the struct equality operators. + /// + [Test] + public void TestHSLAEquality() + { + HSLAColor first = new HSLAColor(Color.White); + HSLAColor second = new HSLAColor(Color.White); + + Assert.AreEqual(first, second); + } + + /// + /// Test conversion to and from a HSLA color. + /// + [Test] + public void TestHSLAConversion() + { + const string Hex = "#FEFFFE"; + + Color color = ColorTranslator.FromHtml(Hex); + HSLAColor hslaColor = new HSLAColor(color); + string outPut = ColorTranslator.ToHtml(hslaColor); + Assert.AreEqual(Hex, outPut); + } + } +} diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index 6d7612871..1398b8c9f 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -597,11 +597,11 @@ namespace ImageProcessor } /// - /// Changes the hue of the current image. + /// Alters the hue of the current image changing the overall color. /// /// /// The angle by which to alter the images hue. - /// Any integer between 0 and 359. + /// Any integer between 0 and 360. /// /// /// The current instance of the class. @@ -623,6 +623,33 @@ namespace ImageProcessor return this; } + /// + /// Rotates the hue of the current image altering each color. + /// + /// + /// The angle by which to rotate the images hue. + /// Any integer between 0 and 360. + /// + /// + /// The current instance of the class. + /// + public ImageFactory HueRotate(int degrees) + { + // Sanitize the input. + if (degrees > 360 || degrees < 0) + { + degrees = 0; + } + + if (this.ShouldProcess) + { + HueRotate hue = new HueRotate { DynamicParameter = degrees }; + this.CurrentImageFormat.ApplyProcessor(hue.ProcessImage, this); + } + + return this; + } + /// /// Alters the output quality of the current image. /// diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 59f7a8680..7c028707d 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -121,6 +121,7 @@ + diff --git a/src/ImageProcessor/Imaging/Colors/HSLAColor.cs b/src/ImageProcessor/Imaging/Colors/HSLAColor.cs index 874abcd7a..19c12e54a 100644 --- a/src/ImageProcessor/Imaging/Colors/HSLAColor.cs +++ b/src/ImageProcessor/Imaging/Colors/HSLAColor.cs @@ -12,6 +12,7 @@ namespace ImageProcessor.Imaging.Colors /// /// Represents an HSLA (hue, saturation, luminosity, alpha) color. + /// Adapted from /// public struct HSLAColor { @@ -21,235 +22,293 @@ namespace ImageProcessor.Imaging.Colors /// /// The hue component. /// - private double hue; + private double h; /// /// The luminosity component. /// - private double luminosity; + private double l; /// /// The saturation component. /// - private double saturation; + private double s; /// /// The alpha component. /// private double a; - #region Constructors and Destructors - /// /// Initializes a new instance of the struct. /// - /// - /// The color. + /// + /// The hue. /// - public HSLAColor(Color color) + /// + /// The saturation. + /// + /// + /// The luminosity. + /// + public HSLAColor(double hue, double saturation, double luminosity) : this() { - this.SetRGBA(color.R, color.G, color.B, color.A); + this.H = hue; + this.S = saturation; + this.L = luminosity; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the struct. /// - /// - /// The red. - /// - /// - /// The green. - /// - /// - /// The blue. + /// + /// The to initialize from. /// - public HSLAColor(int red, int green, int blue, int alpha) + public HSLAColor(Color color) : this() { - this.SetRGBA(red, green, blue, alpha); + HSLAColor hslColor = color; + this.h = hslColor.h; + this.s = hslColor.s; + this.l = hslColor.l; + this.a = hslColor.a; } /// - /// Initializes a new instance of the class. + /// Gets or sets the hue component. /// - /// - /// The hue. - /// - /// - /// The saturation. - /// - /// - /// The luminosity. - /// - public HSLAColor(double hue, double saturation, double luminosity) - : this() + public double H { - this.Hue = hue; - this.Saturation = saturation; - this.Luminosity = luminosity; - } - - #endregion + get + { + return this.h; + } - #region Public Properties + set + { + this.h = this.CheckRange(value); + } + } /// - /// Gets or sets the hue. + /// Gets or sets the luminosity component. /// - public double Hue + public double L { get { - return this.hue; + return this.l; } set { - this.hue = this.CheckRange(value); + this.l = this.CheckRange(value); } } /// - /// Gets or sets the luminosity. + /// Gets or sets the saturation component. /// - public double Luminosity + public double S { get { - return this.luminosity; + return this.s; } set { - this.luminosity = this.CheckRange(value); + this.s = this.CheckRange(value); } } /// - /// Gets or sets the saturation. + /// Gets or sets the alpha component. /// - public double Saturation + public double A { get { - return this.saturation; + return this.a; } set { - this.saturation = this.CheckRange(value); + this.a = this.CheckRange(value); } } - #endregion + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator HSLAColor(Color color) + { + HSLAColor hslColor = new HSLAColor + { + h = color.GetHue() / 360.0, + l = color.GetBrightness(), + s = color.GetSaturation(), + a = color.A / 255f + }; - #region Public Methods and Operators + return hslColor; + } /// - /// The op_ implicit. + /// Allows the implicit conversion of an instance of to a + /// . /// - /// - /// The hsl color. + /// + /// The instance of to convert. /// /// + /// An instance of . /// - public static implicit operator Color(HSLAColor hslColor) + public static implicit operator HSLAColor(RGBAColor rgbaColor) + { + Color color = rgbaColor; + HSLAColor hslColor = new HSLAColor + { + h = color.GetHue() / 360.0, + l = color.GetBrightness(), + s = color.GetSaturation(), + a = color.A / 255f + }; + + return hslColor; + } + + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator Color(HSLAColor hslaColor) { double r = 0, g = 0, b = 0; - if (Math.Abs(hslColor.luminosity - 0) > .0001) + if (Math.Abs(hslaColor.l - 0) > .0001) { - if (Math.Abs(hslColor.saturation - 0) <= .0001) + if (Math.Abs(hslaColor.s - 0) <= .0001) { - r = g = b = hslColor.luminosity; + r = g = b = hslaColor.l; } else { - double temp2 = GetTemp2(hslColor); - double temp1 = (2.0 * hslColor.luminosity) - temp2; + double temp2 = GetTemp2(hslaColor); + double temp1 = (2.0 * hslaColor.l) - temp2; - r = GetColorComponent(temp1, temp2, hslColor.hue + (1.0 / 3.0)); - g = GetColorComponent(temp1, temp2, hslColor.hue); - b = GetColorComponent(temp1, temp2, hslColor.hue - (1.0 / 3.0)); + r = GetColorComponent(temp1, temp2, hslaColor.h + (1.0 / 3.0)); + g = GetColorComponent(temp1, temp2, hslaColor.h); + b = GetColorComponent(temp1, temp2, hslaColor.h - (1.0 / 3.0)); } } - return Color.FromArgb((int)(255 * r), (int)(255 * g), (int)(255 * b)); + return Color.FromArgb(Convert.ToInt32(255 * hslaColor.a), Convert.ToInt32(255 * r), Convert.ToInt32(255 * g), Convert.ToInt32(255 * b)); } /// - /// The op_ implicit. + /// Allows the implicit conversion of an instance of to a + /// . /// - /// - /// The color. + /// + /// The instance of to convert. /// /// + /// An instance of . /// - public static implicit operator HSLAColor(Color color) + public static implicit operator RGBAColor(HSLAColor hslaColor) { - HSLAColor hslColor = new HSLAColor + double r = 0, g = 0, b = 0; + if (Math.Abs(hslaColor.l - 0) > .0001) { - hue = color.GetHue() / 360.0, - luminosity = color.GetBrightness(), - saturation = color.GetSaturation() - }; + if (Math.Abs(hslaColor.s - 0) <= .0001) + { + r = g = b = hslaColor.l; + } + else + { + double temp2 = GetTemp2(hslaColor); + double temp1 = (2.0 * hslaColor.l) - temp2; - return hslColor; + r = GetColorComponent(temp1, temp2, hslaColor.h + (1.0 / 3.0)); + g = GetColorComponent(temp1, temp2, hslaColor.h); + b = GetColorComponent(temp1, temp2, hslaColor.h - (1.0 / 3.0)); + } + } + + return new RGBAColor(Convert.ToByte(255 * r), Convert.ToByte(255 * g), Convert.ToByte(255 * b), Convert.ToByte(255 * hslaColor.a)); } /// - /// The set rgb components. + /// Returns a that represents this instance. /// - /// - /// The red. - /// - /// - /// The green component. - /// - /// - /// The blue component. - /// - /// - /// The alpha component. - /// - public void SetRGBA(int red, int green, int blue, int alpha) + /// + /// A that represents this instance. + /// + public string ToRGBAString() { - HSLAColor hslColor = Color.FromArgb(alpha, red, green, blue); - this.hue = hslColor.hue; - this.saturation = hslColor.saturation; - this.luminosity = hslColor.luminosity; - this.a = hslColor.a; + Color color = this; + return string.Format("R={0}, G={1}, B={2}, A={3}", color.R, color.G, color.B, color.A); } /// - /// The to rgb string. + /// Returns a that represents this instance. /// /// - /// The . + /// A that represents this instance. /// - public string ToRGBString() + public override string ToString() { - Color color = this; - return string.Format("R: {0:#0.##} G: {1:#0.##} B: {2:#0.##}", color.R, color.G, color.B); + return string.Format("H={0:#0.##}, S={1:#0.##}, L={2:#0.##}, A={3:#0.##}", this.H, this.S, this.L, this.A); } /// - /// The to string. + /// Indicates whether this instance and a specified object are equal. /// /// - /// The . + /// true if and this instance are the same type and represent the same value; otherwise, false. /// - public override string ToString() + /// Another object to compare to. + public override bool Equals(object obj) { - return string.Format("H: {0:#0.##} S: {1:#0.##} L: {2:#0.##}", this.Hue, this.Saturation, this.Luminosity); - } + if (obj is HSLAColor) + { + Color thisColor = this; + Color otherColor = (HSLAColor)obj; + + return thisColor.Equals(otherColor); + } - #endregion + return false; + } - #region Methods + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() + { + Color thisColor = this; + return thisColor.GetHashCode(); + } /// - /// The get color component. + /// Gets the color component from the given hue values. /// /// /// The temp 1. @@ -288,7 +347,7 @@ namespace ImageProcessor.Imaging.Colors /// The get temp 2. /// /// - /// The hsl color. + /// The color. /// /// /// The . @@ -296,13 +355,13 @@ namespace ImageProcessor.Imaging.Colors private static double GetTemp2(HSLAColor hslColor) { double temp2; - if (hslColor.luminosity <= 0.5) + if (hslColor.l <= 0.5) { - temp2 = hslColor.luminosity * (1.0 + hslColor.saturation); + temp2 = hslColor.l * (1.0 + hslColor.s); } else { - temp2 = hslColor.luminosity + hslColor.saturation - (hslColor.luminosity * hslColor.saturation); + temp2 = hslColor.l + hslColor.s - (hslColor.l * hslColor.s); } return temp2; @@ -332,13 +391,13 @@ namespace ImageProcessor.Imaging.Colors } /// - /// The check range. + /// Checks the range of the given value to ensure that it remains within the acceptable boundaries. /// /// - /// The value. + /// The value to check. /// /// - /// The . + /// The sanitized . /// private double CheckRange(double value) { @@ -353,7 +412,5 @@ namespace ImageProcessor.Imaging.Colors return value; } - - #endregion } } \ No newline at end of file diff --git a/src/ImageProcessor/Imaging/Colors/RGBAColor.cs b/src/ImageProcessor/Imaging/Colors/RGBAColor.cs index 97b9048c1..a9127fae7 100644 --- a/src/ImageProcessor/Imaging/Colors/RGBAColor.cs +++ b/src/ImageProcessor/Imaging/Colors/RGBAColor.cs @@ -8,6 +8,7 @@ namespace ImageProcessor.Imaging.Colors { using System.Drawing; + using System.Text; /// /// Represents an RGBA (red, green, blue, alpha) color. @@ -91,6 +92,36 @@ namespace ImageProcessor.Imaging.Colors this.A = color.A; } + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator RGBAColor(Color color) + { + return new RGBAColor(color); + } + + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator RGBAColor(HSLAColor color) + { + return new RGBAColor(color); + } + /// /// Allows the implicit conversion of an instance of to a /// . @@ -103,7 +134,65 @@ namespace ImageProcessor.Imaging.Colors /// public static implicit operator Color(RGBAColor rgba) { - return System.Drawing.Color.FromArgb(rgba.A, rgba.R, rgba.G, rgba.B); + return Color.FromArgb(rgba.A, rgba.R, rgba.G, rgba.B); + } + + /// + /// Allows the implicit conversion of an instance of to a + /// . + /// + /// + /// The instance of to convert. + /// + /// + /// An instance of . + /// + public static implicit operator HSLAColor(RGBAColor rgba) + { + return new HSLAColor(rgba); + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return string.Format("R={0}, G={1}, B={2}, A={3}", this.R, this.G, this.B, this.A); + } + + /// + /// Indicates whether this instance and a specified object are equal. + /// + /// + /// true if and this instance are the same type and represent the same value; otherwise, false. + /// + /// Another object to compare to. + public override bool Equals(object obj) + { + if (obj is RGBAColor) + { + Color thisColor = this; + Color otherColor = (RGBAColor)obj; + + return thisColor.Equals(otherColor); + } + + return false; + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() + { + Color thisColor = this; + return thisColor.GetHashCode(); } } } \ No newline at end of file diff --git a/src/ImageProcessor/Processors/Hue.cs b/src/ImageProcessor/Processors/Hue.cs index 1dbe820f0..d13b1217f 100644 --- a/src/ImageProcessor/Processors/Hue.cs +++ b/src/ImageProcessor/Processors/Hue.cs @@ -18,7 +18,7 @@ namespace ImageProcessor.Processors using ImageProcessor.Imaging.Colors; /// - /// Encapsulates methods to rotate the hue component of an image. + /// Encapsulates methods to adjust the hue component of an image. /// public class Hue : IGraphicsProcessor { @@ -69,10 +69,8 @@ namespace ImageProcessor.Processors { for (int j = 0; j < height; j++) { - HSLAColor hsl = new HSLAColor(fastBitmap.GetPixel(i, j)); - hsl.Hue = (hsl.Hue + (degrees / 360f)) % 1; - //hsl.Hue = (degrees / 360f); - fastBitmap.SetPixel(i, j, hsl); + HSLAColor hsla = new HSLAColor(fastBitmap.GetPixel(i, j)) { H = degrees / 360f }; + fastBitmap.SetPixel(i, j, hsla); } } } diff --git a/src/ImageProcessor/Processors/HueRotate.cs b/src/ImageProcessor/Processors/HueRotate.cs new file mode 100644 index 000000000..975b681c6 --- /dev/null +++ b/src/ImageProcessor/Processors/HueRotate.cs @@ -0,0 +1,95 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) James South. +// Licensed under the Apache License, Version 2.0. +// +// +// Encapsulates methods to rotate the hue component of an image. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor.Processors +{ + using System; + using System.Collections.Generic; + using System.Drawing; + using ImageProcessor.Common.Exceptions; + using ImageProcessor.Imaging; + using ImageProcessor.Imaging.Colors; + + /// + /// Encapsulates methods to rotate the hue component of an image. + /// + public class HueRotate : IGraphicsProcessor + { + /// + /// Initializes a new instance of the class. + /// + public HueRotate() + { + this.Settings = new Dictionary(); + } + + /// + /// Gets or sets the dynamic parameter. + /// + public dynamic DynamicParameter { get; set; } + + /// + /// Gets or sets any additional settings required by the processor. + /// + public Dictionary Settings { get; set; } + + /// + /// Processes the image. + /// + /// + /// The current instance of the class containing + /// the image to process. + /// + /// + /// The processed image from the current instance of the class. + /// + public Image ProcessImage(ImageFactory factory) + { + Bitmap newImage = null; + Image image = factory.Image; + + try + { + int degrees = this.DynamicParameter; + int width = image.Width; + int height = image.Height; + + newImage = new Bitmap(image); + + using (FastBitmap fastBitmap = new FastBitmap(newImage)) + { + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height; j++) + { + HSLAColor hsla = new HSLAColor(fastBitmap.GetPixel(i, j)); + hsla.H = (hsla.H + (degrees / 360f)) % 1; + fastBitmap.SetPixel(i, j, hsla); + } + } + } + + image.Dispose(); + image = newImage; + } + catch (Exception ex) + { + if (newImage != null) + { + newImage.Dispose(); + } + + throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); + } + + return image; + } + } +} diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index ff9b50176..169eecd9e 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/src/ImageProcessorConsole/Program.cs @@ -82,7 +82,8 @@ namespace ImageProcessorConsole //.Resize(new Size((int)(size.Width * 1.1), 0)) //.ContentAwareResize(layer) .Constrain(size) - .Hue(180) + .HueRotate(270) + .Quality(100) .Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name))); stopwatch.Stop(); diff --git a/src/ImageProcessorConsole/images/output/1aaa.jpg b/src/ImageProcessorConsole/images/output/1aaa.jpg deleted file mode 100644 index a1e293443..000000000 Binary files a/src/ImageProcessorConsole/images/output/1aaa.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/2006-citybus.jpg b/src/ImageProcessorConsole/images/output/2006-citybus.jpg deleted file mode 100644 index 505463e44..000000000 Binary files a/src/ImageProcessorConsole/images/output/2006-citybus.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id deleted file mode 100644 index be943537b..000000000 --- a/src/ImageProcessorConsole/images/output/2008.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -73753ca19a0818ee4a88b6e9e0eb85ca17624269 \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/2012-citybus.jpg b/src/ImageProcessorConsole/images/output/2012-citybus.jpg deleted file mode 100644 index fe960faf1..000000000 Binary files a/src/ImageProcessorConsole/images/output/2012-citybus.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id deleted file mode 100644 index 488b8b110..000000000 --- a/src/ImageProcessorConsole/images/output/Arc-de-Triomphe-France.jpg.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -dff097307936637d1c43f82ca28f4582c9810de7 \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/IC580196.jpg b/src/ImageProcessorConsole/images/output/IC580196.jpg deleted file mode 100644 index ce638c384..000000000 Binary files a/src/ImageProcessorConsole/images/output/IC580196.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/Turtle.jpg b/src/ImageProcessorConsole/images/output/Turtle.jpg deleted file mode 100644 index eff244f04..000000000 Binary files a/src/ImageProcessorConsole/images/output/Turtle.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg b/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg deleted file mode 100644 index e0718165d..000000000 Binary files a/src/ImageProcessorConsole/images/output/arc_de_triomphe_paris_france.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/mountain.jpg b/src/ImageProcessorConsole/images/output/mountain.jpg deleted file mode 100644 index 3d19463a2..000000000 Binary files a/src/ImageProcessorConsole/images/output/mountain.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/rotate.jpg b/src/ImageProcessorConsole/images/output/rotate.jpg deleted file mode 100644 index aa68c6cab..000000000 Binary files a/src/ImageProcessorConsole/images/output/rotate.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/sample1.jpg b/src/ImageProcessorConsole/images/output/sample1.jpg deleted file mode 100644 index add729e24..000000000 Binary files a/src/ImageProcessorConsole/images/output/sample1.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg b/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg deleted file mode 100644 index 09bbbf3a0..000000000 Binary files a/src/ImageProcessorConsole/images/output/shutterstock_19173982_Arc_de_triomphe-square1.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/test.jpg b/src/ImageProcessorConsole/images/output/test.jpg deleted file mode 100644 index 3c0bc5a16..000000000 Binary files a/src/ImageProcessorConsole/images/output/test.jpg and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/tower.jpg b/src/ImageProcessorConsole/images/output/tower.jpg deleted file mode 100644 index a5644d65d..000000000 Binary files a/src/ImageProcessorConsole/images/output/tower.jpg and /dev/null differ