From 2ad603afc181f3be5cb6d7d985dbb34c664fd598 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 15 Jun 2018 11:07:11 +1000 Subject: [PATCH] Minor cleanup --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 6 +++-- .../PixelFormats/Rgba32.PixelOperations.cs | 22 +++++++++--------- src/ImageSharp/PixelFormats/Rgba32.cs | 5 +++- src/ImageSharp/PixelFormats/Rgba64.cs | 23 ++++++------------- .../PixelFormats/Rgba64Tests.cs | 2 +- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index c122aa4046..c544a29ac7 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -861,7 +861,7 @@ namespace SixLabors.ImageSharp.Formats.Png var rgba = default(Rgba32); - if (this.paletteAlpha != null && this.paletteAlpha.Length > 0) + if (this.paletteAlpha?.Length > 0) { // If the alpha palette is not null and has one or more entries, this means, that the image contains an alpha // channel and we should try to read it. @@ -949,7 +949,7 @@ namespace SixLabors.ImageSharp.Formats.Png var rgba = default(Rgba32); Span pal = MemoryMarshal.Cast(this.palette); - if (this.paletteAlpha != null && this.paletteAlpha.Length > 0) + if (this.paletteAlpha?.Length > 0) { // If the alpha palette is not null and has one or more entries, this means, that the image contains an alpha // channel and we should try to read it. @@ -1165,6 +1165,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// Reads a chunk from the stream. /// + /// The image format chunk. /// /// The . /// @@ -1255,6 +1256,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// Skips the chunk data and the cycle redundancy chunk read from the data. /// + /// The image format chunk. private void SkipChunkDataAndCrc(in PngChunk chunk) { this.currentStream.Skip(chunk.Length); diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index b1eba32750..508dc1f64f 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -87,15 +87,15 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - internal override void ToVector4(ReadOnlySpan sourceColors, Span destVectors, int count) + internal override void ToVector4(ReadOnlySpan sourceColors, Span destinationVectors, int count) { Guard.MustBeSizedAtLeast(sourceColors, count, nameof(sourceColors)); - Guard.MustBeSizedAtLeast(destVectors, count, nameof(destVectors)); + Guard.MustBeSizedAtLeast(destinationVectors, count, nameof(destinationVectors)); if (count < 256 || !Vector.IsHardwareAccelerated) { // Doesn't worth to bother with SIMD: - base.ToVector4(sourceColors, destVectors, count); + base.ToVector4(sourceColors, destinationVectors, count); return; } @@ -104,25 +104,25 @@ namespace SixLabors.ImageSharp.PixelFormats if (alignedCount > 0) { - ToVector4SimdAligned(sourceColors, destVectors, alignedCount); + ToVector4SimdAligned(sourceColors, destinationVectors, alignedCount); } if (remainder > 0) { sourceColors = sourceColors.Slice(alignedCount); - destVectors = destVectors.Slice(alignedCount); - base.ToVector4(sourceColors, destVectors, remainder); + destinationVectors = destinationVectors.Slice(alignedCount); + base.ToVector4(sourceColors, destinationVectors, remainder); } } /// - internal override void PackFromVector4(ReadOnlySpan sourceVectors, Span destColors, int count) + internal override void PackFromVector4(ReadOnlySpan sourceVectors, Span destinationColors, int count) { - GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count); + GuardSpans(sourceVectors, nameof(sourceVectors), destinationColors, nameof(destinationColors), count); if (!SimdUtils.IsAvx2CompatibleArchitecture) { - base.PackFromVector4(sourceVectors, destColors, count); + base.PackFromVector4(sourceVectors, destinationColors, count); return; } @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.PixelFormats if (alignedCount > 0) { ReadOnlySpan flatSrc = MemoryMarshal.Cast(sourceVectors.Slice(0, alignedCount)); - Span flatDest = MemoryMarshal.Cast(destColors); + Span flatDest = MemoryMarshal.Cast(destinationColors); SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(flatSrc, flatDest); } @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.PixelFormats { // actually: remainder == 1 int lastIdx = count - 1; - destColors[lastIdx].PackFromVector4(sourceVectors[lastIdx]); + destinationColors[lastIdx].PackFromVector4(sourceVectors[lastIdx]); } } diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index 83ba6664f0..12bbc34b89 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -199,7 +199,10 @@ namespace SixLabors.ImageSharp.PixelFormats /// public uint PackedValue { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.Rgba; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] set => this.Rgba = value; } @@ -395,7 +398,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is Rgba32) && this.Equals((Rgba32)obj); + return obj is Rgba32 rgba32 && this.Equals(rgba32); } /// diff --git a/src/ImageSharp/PixelFormats/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs index a20a76c847..3202a5628b 100644 --- a/src/ImageSharp/PixelFormats/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -88,13 +88,11 @@ namespace SixLabors.ImageSharp.PixelFormats public Rgba64(ulong packed) : this() { - this.Rgba = packed; + this.PackedValue = packed; } - /// - /// Gets or sets the packed representation of the struct. - /// - public ulong Rgba + /// + public ulong PackedValue { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => Unsafe.As(ref this); @@ -103,13 +101,6 @@ namespace SixLabors.ImageSharp.PixelFormats set => Unsafe.As(ref this) = value; } - /// - public ulong PackedValue - { - get => this.Rgba; - set => this.Rgba = value; - } - /// /// Compares two objects for equality. /// @@ -125,7 +116,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rgba64 left, Rgba64 right) { - return left.Rgba == right.Rgba; + return left.PackedValue == right.PackedValue; } /// @@ -143,7 +134,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgba64 left, Rgba64 right) { - return left.Rgba != right.Rgba; + return left.PackedValue != right.PackedValue; } /// @@ -272,14 +263,14 @@ namespace SixLabors.ImageSharp.PixelFormats /// public override bool Equals(object obj) { - return (obj is Rgba64) && this.Equals((Rgba64)obj); + return obj is Rgba64 rgba64 && this.Equals(rgba64); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rgba64 other) { - return this.Rgba == other.Rgba; + return this.PackedValue == other.PackedValue; } /// diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs index b10fecb5f6..c04352c323 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats // arrange var pixel = default(Rgba64); var short4 = new Rgba64(Vector4.One); - ulong expected = 0xFFFFFFFFFFFFFFFF; + const ulong expected = 0xFFFFFFFFFFFFFFFF; // act Vector4 scaled = short4.ToScaledVector4();