Skip to content

Commit

Permalink
Merge branch 'master' into arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants authored Oct 28, 2021
2 parents b50f146 + 72904e1 commit cd7f406
Show file tree
Hide file tree
Showing 37 changed files with 154 additions and 274 deletions.
10 changes: 5 additions & 5 deletions src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void DecodeImageData(Vp8LDecoder decoder, Span<uint> pixelData)
ColorCache colorCache = decoder.Metadata.ColorCache;
int colorCacheLimit = lenCodeLimit + colorCacheSize;
int mask = decoder.Metadata.HuffmanMask;
HTreeGroup[] hTreeGroup = GetHTreeGroupForPos(decoder.Metadata, col, row);
Span<HTreeGroup> hTreeGroup = GetHTreeGroupForPos(decoder.Metadata, col, row);

int totalPixels = width * height;
int decodedPixels = 0;
Expand Down Expand Up @@ -731,7 +731,7 @@ public void DecodeAlphaData(AlphaDecoder dec)
int lastRow = height;
const int lenCodeLimit = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes;
int mask = hdr.HuffmanMask;
HTreeGroup[] htreeGroup = pos < last ? GetHTreeGroupForPos(hdr, col, row) : null;
Span<HTreeGroup> htreeGroup = pos < last ? GetHTreeGroupForPos(hdr, col, row) : null;
while (!this.bitReader.Eos && pos < last)
{
// Only update when changing tile.
Expand Down Expand Up @@ -815,7 +815,7 @@ private void UpdateDecoder(Vp8LDecoder decoder, int width, int height)
decoder.Metadata.HuffmanMask = numBits == 0 ? ~0 : (1 << numBits) - 1;
}

private uint ReadPackedSymbols(HTreeGroup[] group, Span<uint> pixelData, int decodedPixels)
private uint ReadPackedSymbols(Span<HTreeGroup> group, Span<uint> pixelData, int decodedPixels)
{
uint val = (uint)(this.bitReader.PrefetchBits() & (HuffmanUtils.HuffmanPackedTableSize - 1));
HuffmanCode code = group[0].PackedTable[val];
Expand Down Expand Up @@ -895,10 +895,10 @@ private int GetCopyDistance(int distanceSymbol)
}

[MethodImpl(InliningOptions.ShortMethod)]
private static HTreeGroup[] GetHTreeGroupForPos(Vp8LMetadata metadata, int x, int y)
private static Span<HTreeGroup> GetHTreeGroupForPos(Vp8LMetadata metadata, int x, int y)
{
uint metaIndex = GetMetaIndex(metadata.HuffmanImage, metadata.HuffmanXSize, metadata.HuffmanSubSampleBits, x, y);
return metadata.HTreeGroups.AsSpan((int)metaIndex).ToArray();
return metadata.HTreeGroups.AsSpan((int)metaIndex);
}

[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4() => new Vector4(0, 0, 0, this.PackedValue / 255F);
public readonly Vector4 ToVector4() => new(0, 0, 0, this.PackedValue / 255F);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new Vector4(255);
private static readonly Vector4 MaxBytes = new(255);

/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new Vector4(0.5F);
private static readonly Vector4 Half = new(0.5F);

/// <summary>
/// Initializes a new instance of the <see cref="Argb32"/> struct.
Expand Down Expand Up @@ -151,7 +151,7 @@ public uint PackedValue
/// <param name="source">The <see cref="Argb32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Argb32 source) => new Color(source);
public static implicit operator Color(Argb32 source) => new(source);

/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Argb32"/>.
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Bgr24(byte r, byte g, byte b)
/// <param name="source">The <see cref="Bgr24"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Bgr24 source) => new Color(source);
public static implicit operator Color(Bgr24 source) => new(source);

/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Bgr24"/>.
Expand Down Expand Up @@ -225,7 +225,7 @@ public void FromRgba64(Rgba64 source)
public override readonly bool Equals(object obj) => obj is Bgr24 other && this.Equals(other);

/// <inheritdoc />
public override readonly string ToString() => $"Bgra({this.B}, {this.G}, {this.R})";
public override readonly string ToString() => $"Bgr24({this.B}, {this.G}, {this.R})";

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
12 changes: 3 additions & 9 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void FromVector4(Vector4 vector)

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4() => new Vector4(this.ToVector3(), 1F);
public readonly Vector4 ToVector4() => new(this.ToVector3(), 1F);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -125,10 +125,7 @@ public void FromVector4(Vector4 vector)

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -144,13 +141,10 @@ public void ToRgba32(ref Rgba32 dest)
/// </summary>
/// <returns>The <see cref="Vector3"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector3 ToVector3()
{
return new Vector3(
public readonly Vector3 ToVector3() => new(
((this.PackedValue >> 11) & 0x1F) * (1F / 31F),
((this.PackedValue >> 5) & 0x3F) * (1F / 63F),
(this.PackedValue & 0x1F) * (1F / 31F));
}

/// <inheritdoc />
public override readonly bool Equals(object obj) => obj is Bgr565 other && this.Equals(other);
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new Vector4(255);
private static readonly Vector4 MaxBytes = new(255);

/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new Vector4(0.5F);
private static readonly Vector4 Half = new(0.5F);

/// <summary>
/// Initializes a new instance of the <see cref="Bgra32"/> struct.
Expand Down Expand Up @@ -104,7 +104,7 @@ public uint PackedValue
/// <param name="source">The <see cref="Bgra32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Bgra32 source) => new Color(source);
public static implicit operator Color(Bgra32 source) => new(source);

/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Bgra32"/>.
Expand Down
5 changes: 1 addition & 4 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ public readonly Vector4 ToVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
10 changes: 2 additions & 8 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ public Bgra5551(float x, float y, float z, float w)

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4()
{
return new Vector4(
public readonly Vector4 ToVector4() => new(
((this.PackedValue >> 10) & 0x1F) / 31F,
((this.PackedValue >> 5) & 0x1F) / 31F,
((this.PackedValue >> 0) & 0x1F) / 31F,
(this.PackedValue >> 15) & 0x01);
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -129,10 +126,7 @@ public readonly Vector4 ToVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
10 changes: 2 additions & 8 deletions src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ public Byte4(float x, float y, float z, float w)

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4()
{
return new Vector4(
public readonly Vector4 ToVector4() => new(
this.PackedValue & 0xFF,
(this.PackedValue >> 0x8) & 0xFF,
(this.PackedValue >> 0x10) & 0xFF,
(this.PackedValue >> 0x18) & 0xFF);
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -129,10 +126,7 @@ public readonly Vector4 ToVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public readonly Vector4 ToScaledVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4() => new Vector4(this.ToSingle(), 0, 0, 1F);
public readonly Vector4 ToVector4() => new(this.ToSingle(), 0, 0, 1F);

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -118,10 +118,7 @@ public readonly Vector4 ToScaledVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ public readonly Vector4 ToVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
10 changes: 2 additions & 8 deletions src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ public readonly Vector4 ToScaledVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4()
{
return new Vector4(
public readonly Vector4 ToVector4() => new(
HalfTypeHelper.Unpack((ushort)this.PackedValue),
HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x10)),
HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x20)),
HalfTypeHelper.Unpack((ushort)(this.PackedValue >> 0x30)));
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -137,10 +134,7 @@ public readonly Vector4 ToVector4()

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.FromScaledVector4(this.ToScaledVector4());
}
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
25 changes: 5 additions & 20 deletions src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,24 @@ public readonly Vector4 ToVector4()

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
public void FromArgb32(Argb32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
public void FromBgr24(Bgr24 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -122,23 +113,17 @@ public void FromBgra32(Bgra32 source)

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
public void FromRgb24(Rgb24 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
public void FromRgba32(Rgba32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary>
public partial struct L8 : IPixel<L8>, IPackedVector<byte>
{
private static readonly Vector4 MaxBytes = new Vector4(255F);
private static readonly Vector4 Half = new Vector4(0.5F);
private static readonly Vector4 MaxBytes = new(255F);
private static readonly Vector4 Half = new(0.5F);

/// <summary>
/// Initializes a new instance of the <see cref="L8"/> struct.
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace SixLabors.ImageSharp.PixelFormats
[StructLayout(LayoutKind.Explicit)]
public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
{
private static readonly Vector4 MaxBytes = new Vector4(255F);
private static readonly Vector4 Half = new Vector4(0.5F);
private static readonly Vector4 MaxBytes = new(255F);
private static readonly Vector4 Half = new(0.5F);

/// <summary>
/// Gets or sets the luminance component.
Expand All @@ -35,7 +35,7 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
/// Initializes a new instance of the <see cref="La16"/> struct.
/// </summary>
/// <param name="l">The luminance component.</param>
/// <param name="a">The alpha componant.</param>
/// <param name="a">The alpha component.</param>
public La16(byte l, byte a)
{
this.L = l;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
/// Initializes a new instance of the <see cref="La32"/> struct.
/// </summary>
/// <param name="l">The luminance component.</param>
/// <param name="a">The alpha componant.</param>
/// <param name="a">The alpha component.</param>
public La32(ushort l, ushort a)
{
this.L = l;
Expand Down
Loading

0 comments on commit cd7f406

Please sign in to comment.