Browse Source

Making color structures immutable

Former-commit-id: a3812a627992dc8b0c350d57c51f970986b808c5
af/merge-core
James South 12 years ago
parent
commit
f6335d1df5
  1. 14
      src/ImageProcessor.UnitTests/Imaging/ColorUnitTests.cs
  2. 4
      src/ImageProcessor/ImageProcessor.csproj
  3. 236
      src/ImageProcessor/Imaging/Colors/HSLAColor.cs
  4. 188
      src/ImageProcessor/Imaging/Colors/RGBAColor.cs
  5. 5
      src/ImageProcessor/Processors/Hue.cs
  6. 6
      src/ImageProcessor/Processors/HueRotate.cs
  7. 13
      src/ImageProcessorConsole/Program.cs

14
src/ImageProcessor.UnitTests/Imaging/ColorUnitTests.cs

@ -21,25 +21,25 @@ namespace ImageProcessor.UnitTests.Imaging
public class ColorUnitTests
{
/// <summary>
/// Tests the <see cref="RGBAColor"/> struct equality operators.
/// 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);
RgbaColor first = RgbaColor.FromColor(Color.White);
RgbaColor second = RgbaColor.FromColor(Color.White);
Assert.AreEqual(first, second);
}
/// <summary>
/// Tests the <see cref="RGBAColor"/> struct equality operators.
/// 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);
HslaColor first = HslaColor.FromColor(Color.White);
HslaColor second = HslaColor.FromColor(Color.White);
Assert.AreEqual(first, second);
}
@ -53,7 +53,7 @@ namespace ImageProcessor.UnitTests.Imaging
const string Hex = "#FEFFFE";
Color color = ColorTranslator.FromHtml(Hex);
HSLAColor hslaColor = new HSLAColor(color);
HslaColor hslaColor = HslaColor.FromColor(color);
string outPut = ColorTranslator.ToHtml(hslaColor);
Assert.AreEqual(Hex, outPut);
}

4
src/ImageProcessor/ImageProcessor.csproj

@ -70,8 +70,8 @@
<Compile Include="Common\Extensions\DoubleExtensions.cs" />
<Compile Include="Configuration\NativeBinaryFactory.cs" />
<Compile Include="Configuration\NativeMethods.cs" />
<Compile Include="Imaging\Colors\HSLAColor.cs" />
<Compile Include="Imaging\Colors\RGBAColor.cs" />
<Compile Include="Imaging\Colors\HslaColor.cs" />
<Compile Include="Imaging\Colors\RgbaColor.cs" />
<Compile Include="Imaging\FastBitmap.cs" />
<Compile Include="Imaging\Formats\GifInfo.cs" />
<Compile Include="Common\Extensions\IntegerExtensions.cs" />

236
src/ImageProcessor/Imaging/Colors/HSLAColor.cs

@ -14,61 +14,68 @@ namespace ImageProcessor.Imaging.Colors
/// Represents an HSLA (hue, saturation, luminosity, alpha) color.
/// Adapted from <see href="http://richnewman.wordpress.com/about/code-listings-and-diagrams/hslcolor-class/"/>
/// </summary>
public struct HSLAColor
public struct HslaColor
{
/// <summary>
/// Represents a <see cref="HslaColor"/> that is null.
/// </summary>
public static readonly HslaColor Empty = new HslaColor();
// Private data members below are on scale 0-1
// They are scaled for use externally based on scale
/// <summary>
/// The hue component.
/// </summary>
private double h;
private readonly double h;
/// <summary>
/// The luminosity component.
/// </summary>
private double l;
private readonly double l;
/// <summary>
/// The saturation component.
/// </summary>
private double s;
private readonly double s;
/// <summary>
/// The alpha component.
/// </summary>
private double a;
private readonly double a;
/// <summary>
/// Initializes a new instance of the <see cref="HSLAColor"/> struct.
/// Initializes a new instance of the <see cref="HslaColor"/> struct.
/// </summary>
/// <param name="hue">
/// The hue.
/// The hue component.
/// </param>
/// <param name="saturation">
/// The saturation.
/// The saturation component.
/// </param>
/// <param name="luminosity">
/// The luminosity.
/// The luminosity component.
/// </param>
public HSLAColor(double hue, double saturation, double luminosity)
: this()
/// <param name="alpha">
/// The alpha component.
/// </param>
private HslaColor(double hue, double saturation, double luminosity, double alpha)
{
this.H = hue;
this.S = saturation;
this.L = luminosity;
this.h = Clamp(hue);
this.s = Clamp(saturation);
this.l = Clamp(luminosity);
this.a = Clamp(alpha);
}
/// <summary>
/// Initializes a new instance of the <see cref="HSLAColor"/> struct.
/// Initializes a new instance of the <see cref="HslaColor"/> struct.
/// </summary>
/// <param name="color">
/// The <see cref="System.Drawing.Color"/> to initialize from.
/// </param>
public HSLAColor(Color color)
: this()
private HslaColor(Color color)
{
HSLAColor hslColor = color;
HslaColor hslColor = color;
this.h = hslColor.h;
this.s = hslColor.s;
this.l = hslColor.l;
@ -76,7 +83,7 @@ namespace ImageProcessor.Imaging.Colors
}
/// <summary>
/// Gets or sets the hue component.
/// Gets the hue component.
/// </summary>
public double H
{
@ -84,15 +91,10 @@ namespace ImageProcessor.Imaging.Colors
{
return this.h;
}
set
{
this.h = this.CheckRange(value);
}
}
/// <summary>
/// Gets or sets the luminosity component.
/// Gets the luminosity component.
/// </summary>
public double L
{
@ -100,15 +102,10 @@ namespace ImageProcessor.Imaging.Colors
{
return this.l;
}
set
{
this.l = this.CheckRange(value);
}
}
/// <summary>
/// Gets or sets the saturation component.
/// Gets the saturation component.
/// </summary>
public double S
{
@ -116,15 +113,10 @@ namespace ImageProcessor.Imaging.Colors
{
return this.s;
}
set
{
this.s = this.CheckRange(value);
}
}
/// <summary>
/// Gets or sets the alpha component.
/// Gets the alpha component.
/// </summary>
public double A
{
@ -132,71 +124,121 @@ namespace ImageProcessor.Imaging.Colors
{
return this.a;
}
}
set
{
this.a = this.CheckRange(value);
}
/// <summary>
/// Creates a <see cref="HslaColor"/> structure from the three 64-bit HSLA
/// components (hue, saturation, and luminosity) values.
/// </summary>
/// <param name="hue">
/// The hue component.
/// </param>
/// <param name="saturation">
/// The saturation component.
/// </param>
/// <param name="luminosity">
/// The luminosity component.
/// </param>
/// <returns>
/// The <see cref="HslaColor"/>.
/// </returns>
public static HslaColor FromHslaColor(double hue, double saturation, double luminosity)
{
return new HslaColor(hue, saturation, luminosity, 1.0);
}
/// <summary>
/// Creates a <see cref="HslaColor"/> structure from the four 64-bit HSLA
/// components (hue, saturation, luminosity, and alpha) values.
/// </summary>
/// <param name="hue">
/// The hue component.
/// </param>
/// <param name="saturation">
/// The saturation component.
/// </param>
/// <param name="luminosity">
/// The luminosity component.
/// </param>
/// <param name="alpha">
/// The alpha component.
/// </param>
/// <returns>
/// The <see cref="HslaColor"/>.
/// </returns>
public static HslaColor FromHslaColor(double hue, double saturation, double luminosity, double alpha)
{
return new HslaColor(hue, saturation, luminosity, alpha);
}
/// <summary>
/// Creates a <see cref="HslaColor"/> structure from the specified <see cref="System.Drawing.Color"/> structure
/// </summary>
/// <param name="color">
/// The <see cref="System.Drawing.Color"/> from which to create the new <see cref="HslaColor"/>.
/// </param>
/// <returns>
/// The <see cref="HslaColor"/>.
/// </returns>
public static HslaColor FromColor(Color color)
{
return new HslaColor(color);
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="System.Drawing.Color"/> to a
/// <see cref="HSLAColor"/>.
/// <see cref="HslaColor"/>.
/// </summary>
/// <param name="color">
/// The instance of <see cref="System.Drawing.Color"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="HSLAColor"/>.
/// An instance of <see cref="HslaColor"/>.
/// </returns>
public static implicit operator HSLAColor(Color color)
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
};
HslaColor hslColor = new HslaColor(
color.GetHue() / 360.0,
color.GetSaturation(),
color.GetBrightness(),
color.A / 255f);
return hslColor;
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="System.Drawing.Color"/> to a
/// <see cref="HSLAColor"/>.
/// <see cref="HslaColor"/>.
/// </summary>
/// <param name="rgbaColor">
/// The instance of <see cref="RGBAColor"/> to convert.
/// The instance of <see cref="RgbaColor"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="HSLAColor"/>.
/// An instance of <see cref="HslaColor"/>.
/// </returns>
public static implicit operator HSLAColor(RGBAColor rgbaColor)
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
};
HslaColor hslColor = new HslaColor(
color.GetHue() / 360.0,
color.GetSaturation(),
color.GetBrightness(),
color.A / 255f);
return hslColor;
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="HSLAColor"/> to a
/// Allows the implicit conversion of an instance of <see cref="HslaColor"/> to a
/// <see cref="System.Drawing.Color"/>.
/// </summary>
/// <param name="hslaColor">
/// The instance of <see cref="HSLAColor"/> to convert.
/// The instance of <see cref="HslaColor"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="System.Drawing.Color"/>.
/// </returns>
public static implicit operator Color(HSLAColor hslaColor)
public static implicit operator Color(HslaColor hslaColor)
{
double r = 0, g = 0, b = 0;
if (Math.Abs(hslaColor.l - 0) > .0001)
@ -216,20 +258,24 @@ namespace ImageProcessor.Imaging.Colors
}
}
return Color.FromArgb(Convert.ToInt32(255 * hslaColor.a), Convert.ToInt32(255 * r), Convert.ToInt32(255 * g), Convert.ToInt32(255 * b));
return Color.FromArgb(
Convert.ToInt32(255 * hslaColor.a),
Convert.ToInt32(255 * r),
Convert.ToInt32(255 * g),
Convert.ToInt32(255 * b));
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="HSLAColor"/> to a
/// <see cref="RGBAColor"/>.
/// Allows the implicit conversion of an instance of <see cref="HslaColor"/> to a
/// <see cref="RgbaColor"/>.
/// </summary>
/// <param name="hslaColor">
/// The instance of <see cref="HSLAColor"/> to convert.
/// The instance of <see cref="HslaColor"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="RGBAColor"/>.
/// An instance of <see cref="RgbaColor"/>.
/// </returns>
public static implicit operator RGBAColor(HSLAColor hslaColor)
public static implicit operator RgbaColor(HslaColor hslaColor)
{
double r = 0, g = 0, b = 0;
if (Math.Abs(hslaColor.l - 0) > .0001)
@ -249,19 +295,11 @@ namespace ImageProcessor.Imaging.Colors
}
}
return new RGBAColor(Convert.ToByte(255 * r), Convert.ToByte(255 * g), Convert.ToByte(255 * b), Convert.ToByte(255 * hslaColor.a));
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public string ToRGBAString()
{
Color color = this;
return string.Format("R={0}, G={1}, B={2}, A={3}", color.R, color.G, color.B, color.A);
return RgbaColor.FromRgba(
Convert.ToByte(255 * r),
Convert.ToByte(255 * g),
Convert.ToByte(255 * b),
Convert.ToByte(255 * hslaColor.a));
}
/// <summary>
@ -272,7 +310,12 @@ namespace ImageProcessor.Imaging.Colors
/// </returns>
public override string ToString()
{
return string.Format("H={0:#0.##}, S={1:#0.##}, L={2:#0.##}, A={3:#0.##}", this.H, this.S, this.L, this.A);
if (this.IsEmpty())
{
return "HSLAColor [Empty]";
}
return string.Format("HSLAColor [ H={0:#0.##}, S={1:#0.##}, L={2:#0.##}, A={3:#0.##}]", this.H, this.S, this.L, this.A);
}
/// <summary>
@ -284,10 +327,10 @@ namespace ImageProcessor.Imaging.Colors
/// <param name="obj">Another object to compare to. </param>
public override bool Equals(object obj)
{
if (obj is HSLAColor)
if (obj is HslaColor)
{
Color thisColor = this;
Color otherColor = (HSLAColor)obj;
Color otherColor = (HslaColor)obj;
return thisColor.Equals(otherColor);
}
@ -347,12 +390,12 @@ namespace ImageProcessor.Imaging.Colors
/// The get temp 2.
/// </summary>
/// <param name="hslColor">
/// The <see cref="HSLAColor"/> color.
/// The <see cref="HslaColor"/> color.
/// </param>
/// <returns>
/// The <see cref="double"/>.
/// </returns>
private static double GetTemp2(HSLAColor hslColor)
private static double GetTemp2(HslaColor hslColor)
{
double temp2;
if (hslColor.l <= 0.5)
@ -399,7 +442,7 @@ namespace ImageProcessor.Imaging.Colors
/// <returns>
/// The sanitized <see cref="double"/>.
/// </returns>
private double CheckRange(double value)
private static double Clamp(double value)
{
if (value < 0.0)
{
@ -412,5 +455,18 @@ namespace ImageProcessor.Imaging.Colors
return value;
}
/// <summary>
/// Returns a value indicating whether the current instance is empty.
/// </summary>
/// <returns>
/// The true if this instance is empty; otherwise, false.
/// </returns>
private bool IsEmpty()
{
const double Epsilon = .0001;
return Math.Abs(this.h - 0) <= Epsilon && Math.Abs(this.s - 0) <= Epsilon &&
Math.Abs(this.l - 0) <= Epsilon && Math.Abs(this.a - 0) <= Epsilon;
}
}
}

188
src/ImageProcessor/Imaging/Colors/RGBAColor.cs

@ -1,5 +1,5 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RGBAColor.cs" company="James South">
// <copyright file="RgbaColor.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -8,35 +8,121 @@
namespace ImageProcessor.Imaging.Colors
{
using System.Drawing;
using System.Text;
/// <summary>
/// Represents an RGBA (red, green, blue, alpha) color.
/// </summary>
public struct RGBAColor
public struct RgbaColor
{
/// <summary>
/// The alpha component.
/// Represents a <see cref="RgbaColor"/> that is null.
/// </summary>
public byte A;
public static readonly RgbaColor Empty = new RgbaColor();
/// <summary>
/// The blue component.
/// The red component.
/// </summary>
public byte B;
private readonly byte r;
/// <summary>
/// The green component.
/// </summary>
public byte G;
private readonly byte g;
/// <summary>
/// The blue component.
/// </summary>
private readonly byte b;
/// <summary>
/// The alpha component.
/// </summary>
private readonly byte a;
/// <summary>
/// Initializes a new instance of the <see cref="RgbaColor"/> struct.
/// </summary>
/// <param name="red">
/// The red component.
/// </param>
/// <param name="green">
/// The green component.
/// </param>
/// <param name="blue">
/// The blue component.
/// </param>
/// <param name="alpha">
/// The alpha component.
/// </param>
private RgbaColor(byte red, byte green, byte blue, byte alpha)
{
this.r = red;
this.g = green;
this.b = blue;
this.a = alpha;
}
/// <summary>
/// Initializes a new instance of the <see cref="RgbaColor"/> struct.
/// </summary>
/// <param name="color">
/// The <see cref="System.Drawing.Color">color.</see>
/// </param>
private RgbaColor(Color color)
{
this.r = color.R;
this.g = color.G;
this.b = color.B;
this.a = color.A;
}
/// <summary>
/// Gets the red component.
/// </summary>
public byte R;
public byte R
{
get
{
return this.r;
}
}
/// <summary>
/// Gets the green component.
/// </summary>
public byte G
{
get
{
return this.g;
}
}
/// <summary>
/// Gets the blue component.
/// </summary>
public byte B
{
get
{
return this.b;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="RGBAColor"/> struct.
/// Gets the alpha component.
/// </summary>
public byte A
{
get
{
return this.a;
}
}
/// <summary>
/// Creates a <see cref="RgbaColor"/> structure from the three 8-bit RGBA
/// components (red, green, and blue) values.
/// </summary>
/// <param name="red">
/// The red component.
@ -47,16 +133,17 @@ namespace ImageProcessor.Imaging.Colors
/// <param name="blue">
/// The blue component.
/// </param>
public RGBAColor(byte red, byte green, byte blue)
/// <returns>
/// The <see cref="RgbaColor"/>.
/// </returns>
public static RgbaColor FromRgba(byte red, byte green, byte blue)
{
this.R = red;
this.G = green;
this.B = blue;
this.A = 255;
return new RgbaColor(red, green, blue, 255);
}
/// <summary>
/// Initializes a new instance of the <see cref="RGBAColor"/> struct.
/// Creates a <see cref="RgbaColor"/> structure from the four 8-bit RGBA
/// components (red, green, blue, and alpha) values.
/// </summary>
/// <param name="red">
/// The red component.
@ -70,86 +157,86 @@ namespace ImageProcessor.Imaging.Colors
/// <param name="alpha">
/// The alpha component.
/// </param>
public RGBAColor(byte red, byte green, byte blue, byte alpha)
/// <returns>
/// The <see cref="RgbaColor"/>.
/// </returns>
public static RgbaColor FromRgba(byte red, byte green, byte blue, byte alpha)
{
this.R = red;
this.G = green;
this.B = blue;
this.A = alpha;
return new RgbaColor(red, green, blue, alpha);
}
/// <summary>
/// Initializes a new instance of the <see cref="RGBAColor"/> struct.
/// Creates a <see cref="RgbaColor"/> structure from the specified <see cref="System.Drawing.Color"/> structure
/// </summary>
/// <param name="color">
/// The <see cref="System.Drawing.Color">color.</see>
/// The <see cref="System.Drawing.Color"/> from which to create the new <see cref="RgbaColor"/>.
/// </param>
public RGBAColor(Color color)
/// <returns>
/// The <see cref="RgbaColor"/>.
/// </returns>
public static RgbaColor FromColor(Color color)
{
this.R = color.R;
this.G = color.G;
this.B = color.B;
this.A = color.A;
return new RgbaColor(color);
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="System.Drawing.Color"/> to a
/// <see cref="RGBAColor"/>.
/// <see cref="RgbaColor"/>.
/// </summary>
/// <param name="color">
/// The instance of <see cref="System.Drawing.Color"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="RGBAColor"/>.
/// An instance of <see cref="RgbaColor"/>.
/// </returns>
public static implicit operator RGBAColor(Color color)
public static implicit operator RgbaColor(Color color)
{
return new RGBAColor(color);
return new RgbaColor(color);
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="System.Drawing.Color"/> to a
/// <see cref="RGBAColor"/>.
/// <see cref="RgbaColor"/>.
/// </summary>
/// <param name="color">
/// The instance of <see cref="System.Drawing.Color"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="RGBAColor"/>.
/// An instance of <see cref="RgbaColor"/>.
/// </returns>
public static implicit operator RGBAColor(HSLAColor color)
public static implicit operator RgbaColor(HslaColor color)
{
return new RGBAColor(color);
return new RgbaColor(color);
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="RGBAColor"/> to a
/// Allows the implicit conversion of an instance of <see cref="RgbaColor"/> to a
/// <see cref="System.Drawing.Color"/>.
/// </summary>
/// <param name="rgba">
/// The instance of <see cref="RGBAColor"/> to convert.
/// The instance of <see cref="RgbaColor"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="System.Drawing.Color"/>.
/// </returns>
public static implicit operator Color(RGBAColor rgba)
public static implicit operator Color(RgbaColor rgba)
{
return Color.FromArgb(rgba.A, rgba.R, rgba.G, rgba.B);
}
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="RGBAColor"/> to a
/// <see cref="HSLAColor"/>.
/// Allows the implicit conversion of an instance of <see cref="RgbaColor"/> to a
/// <see cref="HslaColor"/>.
/// </summary>
/// <param name="rgba">
/// The instance of <see cref="RGBAColor"/> to convert.
/// The instance of <see cref="RgbaColor"/> to convert.
/// </param>
/// <returns>
/// An instance of <see cref="HSLAColor"/>.
/// An instance of <see cref="HslaColor"/>.
/// </returns>
public static implicit operator HSLAColor(RGBAColor rgba)
public static implicit operator HslaColor(RgbaColor rgba)
{
return new HSLAColor(rgba);
return HslaColor.FromColor(rgba);
}
/// <summary>
@ -160,7 +247,12 @@ namespace ImageProcessor.Imaging.Colors
/// </returns>
public override string ToString()
{
return string.Format("R={0}, G={1}, B={2}, A={3}", this.R, this.G, this.B, this.A);
if (this.R == 0 && this.G == 0 && this.B == 0 && this.A == 0)
{
return "RGBA [Empty]";
}
return string.Format("RGBA [R={0}, G={1}, B={2}, A={3}]", this.R, this.G, this.B, this.A);
}
/// <summary>
@ -172,10 +264,10 @@ namespace ImageProcessor.Imaging.Colors
/// <param name="obj">Another object to compare to. </param>
public override bool Equals(object obj)
{
if (obj is RGBAColor)
if (obj is RgbaColor)
{
Color thisColor = this;
Color otherColor = (RGBAColor)obj;
Color otherColor = (RgbaColor)obj;
return thisColor.Equals(otherColor);
}

5
src/ImageProcessor/Processors/Hue.cs

@ -69,8 +69,9 @@ namespace ImageProcessor.Processors
{
for (int j = 0; j < height; j++)
{
HSLAColor hsla = new HSLAColor(fastBitmap.GetPixel(i, j)) { H = degrees / 360f };
fastBitmap.SetPixel(i, j, hsla);
HslaColor original = HslaColor.FromColor(fastBitmap.GetPixel(i, j));
HslaColor altered = HslaColor.FromHslaColor(degrees / 360D, original.S, original.L, original.A);
fastBitmap.SetPixel(i, j, altered);
}
}
}

6
src/ImageProcessor/Processors/HueRotate.cs

@ -69,9 +69,9 @@ namespace ImageProcessor.Processors
{
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);
HslaColor original = HslaColor.FromColor(fastBitmap.GetPixel(i, j));
HslaColor altered = HslaColor.FromHslaColor((original.H + (degrees / 360f)) % 1, original.S, original.L, original.A);
fastBitmap.SetPixel(i, j, altered);
}
}
}

13
src/ImageProcessorConsole/Program.cs

@ -50,16 +50,7 @@ namespace ImageProcessorConsole
foreach (FileInfo fileInfo in files)
{
byte[] photoBytes = File.ReadAllBytes(fileInfo.FullName);
//Color color = Color.Green;
//HSLAColor hslaColor = HSLAColor.FromRGBA(color);
//Console.WriteLine("H:" + hslaColor.H + " S:" + hslaColor.S + " L:" + hslaColor.L);
//Color color2 = HSLAColor.ToRGBA(hslaColor);
//Console.WriteLine("Color Out: " + "R:" + color2.R + " G:" + color2.G + " B:" + color2.B + " A:" + color2.A);
//Console.WriteLine(color2 == Color.Green);
//Console.WriteLine("Processing: " + fileInfo.Name);
Console.WriteLine("Processing: " + fileInfo.Name);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@ -82,7 +73,7 @@ namespace ImageProcessorConsole
//.Resize(new Size((int)(size.Width * 1.1), 0))
//.ContentAwareResize(layer)
.Constrain(size)
.HueRotate(270)
.Hue(180)
.Quality(100)
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name)));

Loading…
Cancel
Save