From 5313a6ea9ad8d57e12fb90167678b3ca77a61b52 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 22 Nov 2017 20:25:52 +1100 Subject: [PATCH] Move indexing to method. --- .../Dithering/Ordered/OrderedDitherBase.cs | 21 +++++++++++++-- src/ImageSharp/PixelFormats/Rgba32.cs | 26 ------------------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs b/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs index b29de4cf23..818a24d5dd 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs +++ b/src/ImageSharp/Dithering/Ordered/OrderedDitherBase.cs @@ -1,13 +1,14 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Dithering.Base { /// - /// The base class for performing ordered ditheroing using a 4x4 matrix. + /// The base class for performing ordered dithering using a 4x4 matrix. /// public abstract class OrderedDitherBase : IOrderedDither { @@ -30,7 +31,23 @@ namespace SixLabors.ImageSharp.Dithering.Base where TPixel : struct, IPixel { source.ToRgba32(ref rgba); - image[x, y] = this.matrix[y % 3, x % 3] >= rgba[index] ? lower : upper; + switch (index) + { + case 0: + image[x, y] = this.matrix[y % 3, x % 3] >= rgba.R ? lower : upper; + return; + case 1: + image[x, y] = this.matrix[y % 3, x % 3] >= rgba.G ? lower : upper; + return; + case 2: + image[x, y] = this.matrix[y % 3, x % 3] >= rgba.B ? lower : upper; + return; + case 3: + image[x, y] = this.matrix[y % 3, x % 3] >= rgba.A ? lower : upper; + return; + } + + throw new ArgumentOutOfRangeException(nameof(index), "Index should be between 0 and 3 inclusive."); } } } \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index b213de019e..51647fc1f9 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -220,32 +220,6 @@ namespace SixLabors.ImageSharp set => this.Rgba = value; } - /// - /// Gets the component value at the given index - /// - /// The component index - /// The - public byte this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - DebugGuard.MustBeGreaterThanOrEqualTo(index, 0, nameof(index)); - DebugGuard.MustBeLessThanOrEqualTo(index, 3, nameof(index)); - switch (index) - { - case 0: - return this.R; - case 1: - return this.G; - case 2: - return this.B; - default: - return this.A; - } - } - } - /// /// Compares two objects for equality. ///