Browse Source

Minor cleanup

pull/613/head
James Jackson-South 8 years ago
parent
commit
2ad603afc1
  1. 6
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 22
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  3. 5
      src/ImageSharp/PixelFormats/Rgba32.cs
  4. 23
      src/ImageSharp/PixelFormats/Rgba64.cs
  5. 2
      tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs

6
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<Rgb24> pal = MemoryMarshal.Cast<byte, Rgb24>(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
/// <summary>
/// Reads a chunk from the stream.
/// </summary>
/// <param name="chunk">The image format chunk.</param>
/// <returns>
/// The <see cref="PngChunk"/>.
/// </returns>
@ -1255,6 +1256,7 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <summary>
/// Skips the chunk data and the cycle redundancy chunk read from the data.
/// </summary>
/// <param name="chunk">The image format chunk.</param>
private void SkipChunkDataAndCrc(in PngChunk chunk)
{
this.currentStream.Skip(chunk.Length);

22
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -87,15 +87,15 @@ namespace SixLabors.ImageSharp.PixelFormats
}
/// <inheritdoc />
internal override void ToVector4(ReadOnlySpan<Rgba32> sourceColors, Span<Vector4> destVectors, int count)
internal override void ToVector4(ReadOnlySpan<Rgba32> sourceColors, Span<Vector4> 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);
}
}
/// <inheritdoc />
internal override void PackFromVector4(ReadOnlySpan<Vector4> sourceVectors, Span<Rgba32> destColors, int count)
internal override void PackFromVector4(ReadOnlySpan<Vector4> sourceVectors, Span<Rgba32> 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<float> flatSrc = MemoryMarshal.Cast<Vector4, float>(sourceVectors.Slice(0, alignedCount));
Span<byte> flatDest = MemoryMarshal.Cast<Rgba32, byte>(destColors);
Span<byte> flatDest = MemoryMarshal.Cast<Rgba32, byte>(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]);
}
}

5
src/ImageSharp/PixelFormats/Rgba32.cs

@ -199,7 +199,10 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
public uint PackedValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.Rgba;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => this.Rgba = value;
}
@ -395,7 +398,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
public override bool Equals(object obj)
{
return (obj is Rgba32) && this.Equals((Rgba32)obj);
return obj is Rgba32 rgba32 && this.Equals(rgba32);
}
/// <inheritdoc/>

23
src/ImageSharp/PixelFormats/Rgba64.cs

@ -88,13 +88,11 @@ namespace SixLabors.ImageSharp.PixelFormats
public Rgba64(ulong packed)
: this()
{
this.Rgba = packed;
this.PackedValue = packed;
}
/// <summary>
/// Gets or sets the packed representation of the <see cref="Rgba64"/> struct.
/// </summary>
public ulong Rgba
/// <inheritdoc/>
public ulong PackedValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Unsafe.As<Rgba64, ulong>(ref this);
@ -103,13 +101,6 @@ namespace SixLabors.ImageSharp.PixelFormats
set => Unsafe.As<Rgba64, ulong>(ref this) = value;
}
/// <inheritdoc/>
public ulong PackedValue
{
get => this.Rgba;
set => this.Rgba = value;
}
/// <summary>
/// Compares two <see cref="Rgba64"/> objects for equality.
/// </summary>
@ -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;
}
/// <summary>
@ -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;
}
/// <inheritdoc />
@ -272,14 +263,14 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc />
public override bool Equals(object obj)
{
return (obj is Rgba64) && this.Equals((Rgba64)obj);
return obj is Rgba64 rgba64 && this.Equals(rgba64);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rgba64 other)
{
return this.Rgba == other.Rgba;
return this.PackedValue == other.PackedValue;
}
/// <inheritdoc />

2
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();

Loading…
Cancel
Save