@ -0,0 +1,61 @@ |
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
// <copyright file="ColorUnitTests.cs" company="James South">
|
|||
// Copyright (c) James South.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
// <summary>
|
|||
// Test harness for the color classes.
|
|||
// </summary>
|
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.UnitTests.Imaging |
|||
{ |
|||
using System.Drawing; |
|||
using ImageProcessor.Imaging.Colors; |
|||
using NUnit.Framework; |
|||
|
|||
/// <summary>
|
|||
/// Test harness for the color classes.
|
|||
/// </summary>
|
|||
[TestFixture] |
|||
public class ColorUnitTests |
|||
{ |
|||
/// <summary>
|
|||
/// Tests the <see cref="RGBAColor"/> struct equality operators.
|
|||
/// </summary>
|
|||
[Test] |
|||
public void TestRGBAEquality() |
|||
{ |
|||
RGBAColor first = new RGBAColor(Color.White); |
|||
RGBAColor second = new RGBAColor(Color.White); |
|||
|
|||
Assert.AreEqual(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests the <see cref="RGBAColor"/> struct equality operators.
|
|||
/// </summary>
|
|||
[Test] |
|||
public void TestHSLAEquality() |
|||
{ |
|||
HSLAColor first = new HSLAColor(Color.White); |
|||
HSLAColor second = new HSLAColor(Color.White); |
|||
|
|||
Assert.AreEqual(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Test conversion to and from a HSLA color.
|
|||
/// </summary>
|
|||
[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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
// <copyright file="HueRotate.cs" company="James South">
|
|||
// Copyright (c) James South.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
// <summary>
|
|||
// Encapsulates methods to rotate the hue component of an image.
|
|||
// </summary>
|
|||
// --------------------------------------------------------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.Processors |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Drawing; |
|||
using ImageProcessor.Common.Exceptions; |
|||
using ImageProcessor.Imaging; |
|||
using ImageProcessor.Imaging.Colors; |
|||
|
|||
/// <summary>
|
|||
/// Encapsulates methods to rotate the hue component of an image.
|
|||
/// </summary>
|
|||
public class HueRotate : IGraphicsProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="HueRotate"/> class.
|
|||
/// </summary>
|
|||
public HueRotate() |
|||
{ |
|||
this.Settings = new Dictionary<string, string>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the dynamic parameter.
|
|||
/// </summary>
|
|||
public dynamic DynamicParameter { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets any additional settings required by the processor.
|
|||
/// </summary>
|
|||
public Dictionary<string, string> Settings { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Processes the image.
|
|||
/// </summary>
|
|||
/// <param name="factory">
|
|||
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
|
|||
/// the image to process.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
|
|||
/// </returns>
|
|||
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; |
|||
} |
|||
} |
|||
} |
|||
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 41 KiB |
@ -1 +0,0 @@ |
|||
73753ca19a0818ee4a88b6e9e0eb85ca17624269 |
|||
|
Before Width: | Height: | Size: 39 KiB |
@ -1 +0,0 @@ |
|||
dff097307936637d1c43f82ca28f4582c9810de7 |
|||
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 46 KiB |