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

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

@ -87,15 +87,15 @@ namespace SixLabors.ImageSharp.PixelFormats
} }
/// <inheritdoc /> /// <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(sourceColors, count, nameof(sourceColors));
Guard.MustBeSizedAtLeast(destVectors, count, nameof(destVectors)); Guard.MustBeSizedAtLeast(destinationVectors, count, nameof(destinationVectors));
if (count < 256 || !Vector.IsHardwareAccelerated) if (count < 256 || !Vector.IsHardwareAccelerated)
{ {
// Doesn't worth to bother with SIMD: // Doesn't worth to bother with SIMD:
base.ToVector4(sourceColors, destVectors, count); base.ToVector4(sourceColors, destinationVectors, count);
return; return;
} }
@ -104,25 +104,25 @@ namespace SixLabors.ImageSharp.PixelFormats
if (alignedCount > 0) if (alignedCount > 0)
{ {
ToVector4SimdAligned(sourceColors, destVectors, alignedCount); ToVector4SimdAligned(sourceColors, destinationVectors, alignedCount);
} }
if (remainder > 0) if (remainder > 0)
{ {
sourceColors = sourceColors.Slice(alignedCount); sourceColors = sourceColors.Slice(alignedCount);
destVectors = destVectors.Slice(alignedCount); destinationVectors = destinationVectors.Slice(alignedCount);
base.ToVector4(sourceColors, destVectors, remainder); base.ToVector4(sourceColors, destinationVectors, remainder);
} }
} }
/// <inheritdoc /> /// <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) if (!SimdUtils.IsAvx2CompatibleArchitecture)
{ {
base.PackFromVector4(sourceVectors, destColors, count); base.PackFromVector4(sourceVectors, destinationColors, count);
return; return;
} }
@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.PixelFormats
if (alignedCount > 0) if (alignedCount > 0)
{ {
ReadOnlySpan<float> flatSrc = MemoryMarshal.Cast<Vector4, float>(sourceVectors.Slice(0, alignedCount)); 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); SimdUtils.BulkConvertNormalizedFloatToByteClampOverflows(flatSrc, flatDest);
} }
@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{ {
// actually: remainder == 1 // actually: remainder == 1
int lastIdx = count - 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/> /// <inheritdoc/>
public uint PackedValue public uint PackedValue
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.Rgba; get => this.Rgba;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => this.Rgba = value; set => this.Rgba = value;
} }
@ -395,7 +398,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/> /// <inheritdoc/>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return (obj is Rgba32) && this.Equals((Rgba32)obj); return obj is Rgba32 rgba32 && this.Equals(rgba32);
} }
/// <inheritdoc/> /// <inheritdoc/>

23
src/ImageSharp/PixelFormats/Rgba64.cs

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

2
tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// arrange // arrange
var pixel = default(Rgba64); var pixel = default(Rgba64);
var short4 = new Rgba64(Vector4.One); var short4 = new Rgba64(Vector4.One);
ulong expected = 0xFFFFFFFFFFFFFFFF; const ulong expected = 0xFFFFFFFFFFFFFFFF;
// act // act
Vector4 scaled = short4.ToScaledVector4(); Vector4 scaled = short4.ToScaledVector4();

Loading…
Cancel
Save