From 64b35afbbc6a75d019e295f10164d179bcf48c70 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 3 Oct 2015 21:37:48 +1000 Subject: [PATCH] Stylecop fixes Former-commit-id: 1b0ef96b06ffe4ed4bcee91a237b5b3f1cd53cde Former-commit-id: a0c65ac3f0b7e1029c7344e045e8cfba0d67d6cb Former-commit-id: b81dcea8e7c8fd616816f2842b095d792afb1c0f --- src/ImageProcessor/Colors/Bgra.cs | 13 +- src/ImageProcessor/Colors/Hsv.cs | 160 ++++++++++-------- src/ImageProcessor/Colors/YCbCr.cs | 133 +++++++-------- .../Sections/GifLogicalScreenDescriptor.cs | 33 ++-- src/ImageProcessor/Numerics/Point.cs | 37 ++-- src/ImageProcessor/Numerics/Rectangle.cs | 35 ++-- src/ImageProcessor/Numerics/Size.cs | 32 ++-- 7 files changed, 208 insertions(+), 235 deletions(-) diff --git a/src/ImageProcessor/Colors/Bgra.cs b/src/ImageProcessor/Colors/Bgra.cs index c18f3eb49..ecf275a86 100644 --- a/src/ImageProcessor/Colors/Bgra.cs +++ b/src/ImageProcessor/Colors/Bgra.cs @@ -1,12 +1,7 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Represents an BGRA (blue, green, red, alpha) color. -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { @@ -131,7 +126,7 @@ namespace ImageProcessor /// Initializes a new instance of the struct. /// /// - /// The hexadecimal representation of the combined color components arranged + /// The hexadecimal representation of the combined color components arranged /// in rgb, rrggbb, or aarrggbb format to match web syntax. /// public Bgra(string hex) diff --git a/src/ImageProcessor/Colors/Hsv.cs b/src/ImageProcessor/Colors/Hsv.cs index cb71ed3ee..cd14f6fa4 100644 --- a/src/ImageProcessor/Colors/Hsv.cs +++ b/src/ImageProcessor/Colors/Hsv.cs @@ -1,12 +1,7 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness). -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { @@ -21,25 +16,7 @@ namespace ImageProcessor /// /// Represents a that has H, S, and V values set to zero. /// - public static readonly Hsv Empty = new Hsv(); - - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.0001f; - - /// - /// Initializes a new instance of the struct. - /// - /// The h hue component. - /// The s saturation component. - /// The v value (brightness) component. - public Hsv(float h, float s, float v) - { - this.H = h.Clamp(0, 360); - this.S = s.Clamp(0, 100); - this.V = v.Clamp(0, 100); - } + public static readonly Hsv Empty = default(Hsv); /// /// Gets the H hue component. @@ -60,53 +37,33 @@ namespace ImageProcessor public readonly float V; /// - /// Gets a value indicating whether this is empty. + /// The epsilon for comparing floating point numbers. /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => Math.Abs(this.H) < Epsilon - && Math.Abs(this.S) < Epsilon - && Math.Abs(this.V) < Epsilon; + private const float Epsilon = 0.0001f; /// - /// Compares two objects. The result specifies whether the values - /// of the , , and - /// properties of the two objects are equal. + /// Initializes a new instance of the struct. /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is equal to the parameter; otherwise, false. - /// - public static bool operator ==(Hsv left, Hsv right) + /// The h hue component. + /// The s saturation component. + /// The v value (brightness) component. + public Hsv(float h, float s, float v) { - return left.Equals(right); + this.H = h.Clamp(0, 360); + this.S = s.Clamp(0, 100); + this.V = v.Clamp(0, 100); } /// - /// Compares two objects. The result specifies whether the values - /// of the , , and - /// properties of the two objects are unequal. + /// Gets a value indicating whether this is empty. /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is equal to the parameter; otherwise, false. - /// - public static bool operator !=(Hsv left, Hsv right) - { - return !left.Equals(right); - } + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsEmpty => Math.Abs(this.H) < Epsilon + && Math.Abs(this.S) < Epsilon + && Math.Abs(this.V) < Epsilon; /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -133,21 +90,36 @@ namespace ImageProcessor return new Hsv(0, s * 100, v * 100); } - if (Math.Abs(chroma) < Epsilon) { h = 0; } - else if (Math.Abs(r - max) < Epsilon) { h = (g - b) / chroma; } - else if (Math.Abs(g - max) < Epsilon) { h = 2 + (b - r) / chroma; } - else if (Math.Abs(b - max) < Epsilon) { h = 4 + (r - g) / chroma; } + if (Math.Abs(chroma) < Epsilon) + { + h = 0; + } + else if (Math.Abs(r - max) < Epsilon) + { + h = (g - b) / chroma; + } + else if (Math.Abs(g - max) < Epsilon) + { + h = 2 + ((b - r) / chroma); + } + else if (Math.Abs(b - max) < Epsilon) + { + h = 4 + ((r - g) / chroma); + } h *= 60; - if (h < 0.0) { h += 360; } + if (h < 0.0) + { + h += 360; + } - s = (chroma / v); + s = chroma / v; return new Hsv(h, s * 100, v * 100); } /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -168,7 +140,7 @@ namespace ImageProcessor } float h = (Math.Abs(color.H - 360) < Epsilon) ? 0 : color.H / 60; - int i = (int)(Math.Truncate(h)); + int i = (int)Math.Truncate(h); float f = h - i; float p = v * (1.0f - s); @@ -215,7 +187,45 @@ namespace ImageProcessor break; } - return new Bgra((byte)(Math.Round(b * 255)), (byte)(Math.Round(g * 255)), (byte)(Math.Round(r * 255))); + return new Bgra((byte)Math.Round(b * 255), (byte)Math.Round(g * 255), (byte)Math.Round(r * 255)); + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are equal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + public static bool operator ==(Hsv left, Hsv right) + { + return left.Equals(right); + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are unequal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + public static bool operator !=(Hsv left, Hsv right) + { + return !left.Equals(right); } /// @@ -281,9 +291,9 @@ namespace ImageProcessor /// An object to compare with this object. public bool Equals(Hsv other) { - return this.H.Equals(other.H) - && this.S.Equals(other.S) - && this.V.Equals(other.V); + return Math.Abs(this.H - other.H) < Epsilon + && Math.Abs(this.S - other.S) < Epsilon + && Math.Abs(this.V - other.V) < Epsilon; } } } diff --git a/src/ImageProcessor/Colors/YCbCr.cs b/src/ImageProcessor/Colors/YCbCr.cs index f7d7f05b2..01a041df4 100644 --- a/src/ImageProcessor/Colors/YCbCr.cs +++ b/src/ImageProcessor/Colors/YCbCr.cs @@ -1,14 +1,7 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Represents an YCbCr (luminance, chroma, chroma) color conforming to the -// ITU-R BT.601 standard used in digital imaging systems. -// -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { @@ -16,7 +9,7 @@ namespace ImageProcessor using System.ComponentModel; /// - /// Represents an YCbCr (luminance, chroma, chroma) color conforming to the + /// Represents an YCbCr (luminance, chroma, chroma) color conforming to the /// ITU-R BT.601 standard used in digital imaging systems. /// /// @@ -25,25 +18,7 @@ namespace ImageProcessor /// /// Represents a that has Y, Cb, and Cr values set to zero. /// - public static readonly YCbCr Empty = new YCbCr(); - - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.0001f; - - /// - /// Initializes a new instance of the struct. - /// - /// The y luminance component. - /// The cb chroma component. - /// The cr chroma component. - public YCbCr(float y, float cb, float cr) - { - this.Y = y.Clamp(0, 255); - this.Cb = cb.Clamp(0, 255); - this.Cr = cr.Clamp(0, 255); - } + public static readonly YCbCr Empty = default(YCbCr); /// /// Gets the Y luminance component. @@ -64,53 +39,33 @@ namespace ImageProcessor public readonly float Cr; /// - /// Gets a value indicating whether this is empty. + /// The epsilon for comparing floating point numbers. /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => Math.Abs(this.Y) < Epsilon - && Math.Abs(this.Cb) < Epsilon - && Math.Abs(this.Cr) < Epsilon; + private const float Epsilon = 0.0001f; /// - /// Compares two objects. The result specifies whether the values - /// of the , , and - /// properties of the two objects are equal. + /// Initializes a new instance of the struct. /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is equal to the parameter; otherwise, false. - /// - public static bool operator ==(YCbCr left, YCbCr right) + /// The y luminance component. + /// The cb chroma component. + /// The cr chroma component. + public YCbCr(float y, float cb, float cr) { - return left.Equals(right); + this.Y = y.Clamp(0, 255); + this.Cb = cb.Clamp(0, 255); + this.Cr = cr.Clamp(0, 255); } /// - /// Compares two objects. The result specifies whether the values - /// of the , , and - /// properties of the two objects are unequal. + /// Gets a value indicating whether this is empty. /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is unequal to the parameter; otherwise, false. - /// - public static bool operator !=(YCbCr left, YCbCr right) - { - return !left.Equals(right); - } + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsEmpty => Math.Abs(this.Y) < Epsilon + && Math.Abs(this.Cb) < Epsilon + && Math.Abs(this.Cr) < Epsilon; /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -133,7 +88,7 @@ namespace ImageProcessor } /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -155,6 +110,44 @@ namespace ImageProcessor return new Bgra(b, g, r, 255); } + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are equal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + public static bool operator ==(YCbCr left, YCbCr right) + { + return left.Equals(right); + } + + /// + /// Compares two objects. The result specifies whether the values + /// of the , , and + /// properties of the two objects are unequal. + /// + /// + /// The on the left side of the operand. + /// + /// + /// The on the right side of the operand. + /// + /// + /// True if the current left is unequal to the parameter; otherwise, false. + /// + public static bool operator !=(YCbCr left, YCbCr right) + { + return !left.Equals(right); + } + /// /// Indicates whether this instance and a specified object are equal. /// @@ -218,9 +211,9 @@ namespace ImageProcessor /// An object to compare with this object. public bool Equals(YCbCr other) { - return this.Y.Equals(other.Y) - && this.Cb.Equals(other.Cb) - && this.Cr.Equals(other.Cr); + return Math.Abs(this.Y - other.Y) < Epsilon + && Math.Abs(this.Cb - other.Cb) < Epsilon + && Math.Abs(this.Cr - other.Cr) < Epsilon; } } } diff --git a/src/ImageProcessor/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs b/src/ImageProcessor/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs index 122288fd5..003b439c7 100644 --- a/src/ImageProcessor/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs +++ b/src/ImageProcessor/Formats/Gif/Sections/GifLogicalScreenDescriptor.cs @@ -1,39 +1,32 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// The Logical Screen Descriptor contains the parameters -// necessary to define the area of the display device -// within which the images will be rendered -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Formats { /// - /// The Logical Screen Descriptor contains the parameters - /// necessary to define the area of the display device + /// The Logical Screen Descriptor contains the parameters + /// necessary to define the area of the display device /// within which the images will be rendered /// internal sealed class GifLogicalScreenDescriptor { /// - /// Gets or sets the width, in pixels, of the Logical Screen where the images will + /// Gets or sets the width, in pixels, of the Logical Screen where the images will /// be rendered in the displaying device. /// public short Width { get; set; } /// - /// Gets or sets the height, in pixels, of the Logical Screen where the images will be + /// Gets or sets the height, in pixels, of the Logical Screen where the images will be /// rendered in the displaying device. /// public short Height { get; set; } /// - /// Gets or sets the index at the Global Color Table for the Background Color. - /// The Background Color is the color used for those + /// Gets or sets the index at the Global Color Table for the Background Color. + /// The Background Color is the color used for those /// pixels on the screen that are not covered by an image. /// public byte BackgroundColorIndex { get; set; } @@ -45,16 +38,16 @@ namespace ImageProcessor.Formats /// /// Gets or sets a value indicating whether a flag denoting the presence of a Global Color Table - /// should be set. - /// If the flag is set, the Global Color Table will immediately + /// should be set. + /// If the flag is set, the Global Color Table will immediately /// follow the Logical Screen Descriptor. /// public bool GlobalColorTableFlag { get; set; } /// /// Gets or sets the global color table size. - /// If the Global Color Table Flag is set to 1, - /// the value in this field is used to calculate the number of + /// If the Global Color Table Flag is set to 1, + /// the value in this field is used to calculate the number of /// bytes contained in the Global Color Table. /// public int GlobalColorTableSize { get; set; } diff --git a/src/ImageProcessor/Numerics/Point.cs b/src/ImageProcessor/Numerics/Point.cs index b70b1af8f..57bd0b46f 100644 --- a/src/ImageProcessor/Numerics/Point.cs +++ b/src/ImageProcessor/Numerics/Point.cs @@ -1,30 +1,28 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Represents an ordered pair of integer x- and y-coordinates that defines a point in -// a two-dimensional plane. -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { using System; using System.ComponentModel; - using System.Globalization; /// - /// Represents an ordered pair of integer x- and y-coordinates that defines a point in - /// a two-dimensional plane. + /// Represents an ordered pair of integer x- and y-coordinates that defines a point in + /// a two-dimensional plane. /// /// - /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, + /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, /// as it avoids the need to create new values for modification operations. /// public struct Point : IEquatable { + /// + /// Represents a that has X and Y values set to zero. + /// + public static readonly Point Empty = default(Point); + /// /// Initializes a new instance of the struct. /// @@ -36,11 +34,6 @@ namespace ImageProcessor this.Y = y; } - /// - /// Represents a that has X and Y values set to zero. - /// - public static readonly Point Empty = new Point(); - /// /// The x-coordinate of this . /// @@ -99,11 +92,11 @@ namespace ImageProcessor /// Indicates whether this instance and a specified object are equal. /// /// - /// The object to compare with the current instance. + /// The object to compare with the current instance. /// /// - /// true if and this instance are the same type and represent the - /// same value; otherwise, false. + /// true if and this instance are the same type and represent the + /// same value; otherwise, false. /// public override bool Equals(object obj) { @@ -142,7 +135,7 @@ namespace ImageProcessor } return - $"Point [ X={this.X.ToString(CultureInfo.CurrentCulture)}, Y={this.Y.ToString(CultureInfo.CurrentCulture)} ]"; + $"Point [ X={this.X}, Y={this.Y} ]"; } /// diff --git a/src/ImageProcessor/Numerics/Rectangle.cs b/src/ImageProcessor/Numerics/Rectangle.cs index f8549a745..ef7df4c76 100644 --- a/src/ImageProcessor/Numerics/Rectangle.cs +++ b/src/ImageProcessor/Numerics/Rectangle.cs @@ -1,28 +1,27 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Stores the location and size of a rectangular region. -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { using System; using System.ComponentModel; - using System.Globalization; /// /// Stores a set of four integers that represent the location and size of a rectangle. /// /// - /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, + /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, /// as it avoids the need to create new values for modification operations. /// public struct Rectangle : IEquatable { + /// + /// Represents a that has X, Y, Width, and Height values set to zero. + /// + public static readonly Rectangle Empty = default(Rectangle); + /// /// Initializes a new instance of the struct. /// @@ -55,11 +54,6 @@ namespace ImageProcessor this.Height = size.Height; } - /// - /// Represents a that has X, Y, Width, and Height values set to zero. - /// - public static readonly Rectangle Empty = new Rectangle(); - /// /// The x-coordinate of this . /// @@ -150,7 +144,7 @@ namespace ImageProcessor /// 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. + /// True if and this instance are the same type and represent the same value; otherwise, false. /// /// The object to compare with the current instance. public override bool Equals(object obj) @@ -191,8 +185,7 @@ namespace ImageProcessor } return - $"Rectangle [ X={this.X.ToString(CultureInfo.CurrentCulture)}, Y={this.Y.ToString(CultureInfo.CurrentCulture)}, " - + $"Width={this.Width.ToString(CultureInfo.CurrentCulture)}, Height={this.Height.ToString(CultureInfo.CurrentCulture)}]"; + $"Rectangle [ X={this.X}, Y={this.Y}, Width={this.Width}, Height={this.Height} ]"; } /// @@ -204,8 +197,10 @@ namespace ImageProcessor /// An object to compare with this object. public bool Equals(Rectangle other) { - return this.X.Equals(other.X) && this.Y.Equals(other.Y) - && this.Width.Equals(other.Width) && this.Height.Equals(other.Height); + return this.X.Equals(other.X) + && this.Y.Equals(other.Y) + && this.Width.Equals(other.Width) + && this.Height.Equals(other.Height); } /// diff --git a/src/ImageProcessor/Numerics/Size.cs b/src/ImageProcessor/Numerics/Size.cs index 17382b961..709984152 100644 --- a/src/ImageProcessor/Numerics/Size.cs +++ b/src/ImageProcessor/Numerics/Size.cs @@ -1,36 +1,35 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright © James South and contributors. -// Licensed under the Apache License, Version 2.0. +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. // -// -// Stores an ordered pair of integers, which specify a height and width. -// -// -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor { using System; using System.ComponentModel; - using System.Globalization; /// /// Stores an ordered pair of integers, which specify a height and width. /// /// - /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, + /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, /// as it avoids the need to create new values for modification operations. /// public struct Size : IEquatable { + /// + /// Represents a that has Width and Height values set to zero. + /// + public static readonly Size Empty = default(Size); + /// /// Initializes a new instance of the struct. /// /// - /// The width of the size. + /// The width of the size. /// /// - /// The height of the size. + /// The height of the size. /// public Size(int width, int height) { @@ -38,11 +37,6 @@ namespace ImageProcessor this.Height = height; } - /// - /// Represents a that has Width and Height values set to zero. - /// - public static readonly Size Empty = new Size(); - /// /// The width of this . /// @@ -101,7 +95,7 @@ namespace ImageProcessor /// 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. + /// True if and this instance are the same type and represent the same value; otherwise, false. /// /// The object to compare with the current instance. public override bool Equals(object obj) @@ -141,7 +135,7 @@ namespace ImageProcessor } return - $"Size [ Width={this.Width.ToString(CultureInfo.CurrentCulture)}, Height={this.Height.ToString(CultureInfo.CurrentCulture)} ]"; + $"Size [ Width={this.Width}, Height={this.Height} ]"; } ///