diff --git a/src/ImageProcessor/Colors/Color.cs b/src/ImageProcessor/Colors/Color.cs index 00906ea48..639612f4f 100644 --- a/src/ImageProcessor/Colors/Color.cs +++ b/src/ImageProcessor/Colors/Color.cs @@ -55,10 +55,7 @@ namespace ImageProcessor public Color(float r, float g, float b, float a) : this() { - this.backingVector.X = r; - this.backingVector.Y = g; - this.backingVector.Z = b; - this.backingVector.W = a; + this.backingVector = new Vector4(r, g, b, a); } /// @@ -86,7 +83,7 @@ namespace ImageProcessor float b = Convert.ToByte(hex.Substring(6, 2), 16) / 255f; float a = Convert.ToByte(hex.Substring(0, 2), 16) / 255f; - this.backingVector = Color.FromNonPremultiplied(new Color(r, g, b, a)).ToVector4(); + this.backingVector = FromNonPremultiplied(new Color(r, g, b, a)).ToVector4(); } else if (hex.Length == 6) @@ -277,7 +274,7 @@ namespace ImageProcessor /// public static Color operator +(Color left, Color right) { - return new Color(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A); + return new Color(left.backingVector + right.backingVector); } /// @@ -290,7 +287,7 @@ namespace ImageProcessor /// public static Color operator -(Color left, Color right) { - return new Color(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A); + return new Color(left.backingVector - right.backingVector); } /// @@ -360,18 +357,18 @@ namespace ImageProcessor } /// - /// Compresseses a linear color signal to its sRGB equivalent. + /// Compresses a linear color signal to its sRGB equivalent. /// /// /// /// The whose signal to compress. /// The . - public static Color Compand(Color linear) + public static Color Compress(Color linear) { // TODO: Is there a faster way to do this? - float r = Compand(linear.R); - float g = Compand(linear.G); - float b = Compand(linear.B); + float r = Compress(linear.R); + float g = Compress(linear.G); + float b = Compress(linear.B); return new Color(r, g, b, linear.A); } @@ -383,12 +380,12 @@ namespace ImageProcessor /// /// The whose signal to expand. /// The . - public static Color InverseCompand(Color gamma) + public static Color Expand(Color gamma) { // TODO: Is there a faster way to do this? - float r = InverseCompand(gamma.R); - float g = InverseCompand(gamma.G); - float b = InverseCompand(gamma.B); + float r = Expand(gamma.R); + float g = Expand(gamma.G); + float b = Expand(gamma.B); return new Color(r, g, b, gamma.A); } @@ -485,7 +482,7 @@ namespace ImageProcessor /// /// The . /// - private static float Compand(float signal) + private static float Compress(float signal) { if (signal <= 0.0031308f) { @@ -504,7 +501,7 @@ namespace ImageProcessor /// /// The . /// - private static float InverseCompand(float signal) + private static float Expand(float signal) { if (signal <= 0.04045f) { diff --git a/src/ImageProcessor/Colors/ColorTransforms.cs b/src/ImageProcessor/Colors/ColorTransforms.cs index 2cbd67269..5b7ca2a41 100644 --- a/src/ImageProcessor/Colors/ColorTransforms.cs +++ b/src/ImageProcessor/Colors/ColorTransforms.cs @@ -231,7 +231,7 @@ namespace ImageProcessor float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F); float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); - return Color.Compand(new Color(r, g, b)); + return Color.Compress(new Color(r, g, b)); } /// diff --git a/src/ImageProcessor/Colors/Colorspaces/CieLab.cs b/src/ImageProcessor/Colors/Colorspaces/CieLab.cs index 6098d40f8..953215d4e 100644 --- a/src/ImageProcessor/Colors/Colorspaces/CieLab.cs +++ b/src/ImageProcessor/Colors/Colorspaces/CieLab.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -65,7 +65,7 @@ namespace ImageProcessor /// Gets a value indicating whether this is empty. /// [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.backingVector.Equals(default(Vector4)); + public bool IsEmpty => this.backingVector.Equals(default(Vector3)); /// /// Allows the implicit conversion of an instance of to a @@ -80,7 +80,7 @@ namespace ImageProcessor public static implicit operator CieLab(Color color) { // First convert to CIE XYZ - color = Color.InverseCompand(color.Limited); + color = Color.Expand(color.Limited); float x = (color.R * 0.4124F) + (color.G * 0.3576F) + (color.B * 0.1805F); float y = (color.R * 0.2126F) + (color.G * 0.7152F) + (color.B * 0.0722F); diff --git a/src/ImageProcessor/Filters/Brightness.cs b/src/ImageProcessor/Filters/Brightness.cs index 39d5d26f8..8a6b935e9 100644 --- a/src/ImageProcessor/Filters/Brightness.cs +++ b/src/ImageProcessor/Filters/Brightness.cs @@ -66,12 +66,12 @@ namespace ImageProcessor.Filters /// private static Color AdjustBrightness(Color color, float brightness) { - color = Color.InverseCompand(color); + color = Color.Expand(color); Vector3 vector3 = color.ToVector3(); vector3 += new Vector3(brightness, brightness, brightness); - return Color.Compand(new Color(vector3, color.A)); + return Color.Compress(new Color(vector3, color.A)); } } } diff --git a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs index 9fc56e72b..d26e59197 100644 --- a/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs +++ b/src/ImageProcessor/Filters/ColorMatrix/ColorMatrixFilter.cs @@ -57,7 +57,7 @@ namespace ImageProcessor.Filters if (compand) { - color = Color.InverseCompand(color); + color = Color.Expand(color); } float sr = color.R; @@ -68,7 +68,7 @@ namespace ImageProcessor.Filters color.G = (sr * matrix.M12) + (sg * matrix.M22) + (sb * matrix.M32) + matrix.M42; color.B = (sr * matrix.M13) + (sg * matrix.M23) + (sb * matrix.M33) + matrix.M43; - return compand ? Color.Compand(color) : color; + return compand ? Color.Compress(color) : color; } } } diff --git a/src/ImageProcessor/Filters/Contrast.cs b/src/ImageProcessor/Filters/Contrast.cs index c48ca09e5..72dd0b8f0 100644 --- a/src/ImageProcessor/Filters/Contrast.cs +++ b/src/ImageProcessor/Filters/Contrast.cs @@ -65,7 +65,7 @@ namespace ImageProcessor.Filters /// private static Color AdjustContrast(Color color, float contrast) { - color = Color.InverseCompand(color); + color = Color.Expand(color); // Seems to be faster than Vector3. color.R -= 0.5f; @@ -80,7 +80,7 @@ namespace ImageProcessor.Filters color.B *= contrast; color.B += 0.5f; - return Color.Compand(color); + return Color.Compress(color); } } } diff --git a/src/ImageProcessor/Samplers/Resampler.cs b/src/ImageProcessor/Samplers/Resampler.cs index 6e95359b5..690c4cbd6 100644 --- a/src/ImageProcessor/Samplers/Resampler.cs +++ b/src/ImageProcessor/Samplers/Resampler.cs @@ -183,7 +183,7 @@ namespace ImageProcessor.Samplers foreach (Weight xw in horizontalValues) { int originX = xw.Index; - Color sourceColor = Color.InverseCompand(source[originX, originY]); + Color sourceColor = Color.Expand(source[originX, originY]); float weight = yw.Value * xw.Value; destination.R += sourceColor.R * weight; @@ -193,7 +193,7 @@ namespace ImageProcessor.Samplers } } - destination = Color.Compand(destination); + destination = Color.Compress(destination); // Round alpha values in an attempt to prevent bleed. destination.A = (float)Math.Round(destination.A, 2); @@ -302,7 +302,7 @@ namespace ImageProcessor.Samplers if (sourceRectangle.Contains(rotatedX, rotatedY)) { - Color sourceColor = Color.InverseCompand(source[rotatedX, rotatedY]); + Color sourceColor = Color.Expand(source[rotatedX, rotatedY]); float weight = yw.Value * xw.Value; destination.R += sourceColor.R * weight; destination.G += sourceColor.G * weight; @@ -312,7 +312,7 @@ namespace ImageProcessor.Samplers } } - destination = Color.Compand(destination); + destination = Color.Compress(destination); // Round alpha values in an attempt to prevent bleed. destination.A = (float)Math.Round(destination.A, 2);