Skip to content
Prev Previous commit
Next Next commit
Reintroduce readonly modifiers to pixel formats (CI fail)
This reverts commit 7de9a2d.
  • Loading branch information
Sergio0694 committed Feb 23, 2020
commit 27e93bfbbb6ab6a367cdb2aeeb8f5350575b76d1
14 changes: 7 additions & 7 deletions src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public struct A8 : IPixel<A8>, IPackedVector<byte>
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);

/// <inheritdoc />
public PixelOperations<A8> CreatePixelOperations() => new PixelOperations<A8>();
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations<A8>();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector) => this.PackedValue = Pack(vector.W);

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

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -136,25 +136,25 @@ public void ToRgba32(ref Rgba32 dest)
/// </summary>
/// <param name="obj">The object to compare.</param>
/// <returns>True if the object is equal to the packed vector.</returns>
public override bool Equals(object obj) => obj is A8 other && this.Equals(other);
public override readonly bool Equals(object obj) => obj is A8 other && this.Equals(other);

/// <summary>
/// Compares another A8 packed vector with the packed vector.
/// </summary>
/// <param name="other">The A8 packed vector to compare.</param>
/// <returns>True if the packed vectors are equal.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(A8 other) => this.PackedValue.Equals(other.PackedValue);
public readonly bool Equals(A8 other) => this.PackedValue.Equals(other.PackedValue);

/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString() => $"A8({this.PackedValue})";
public override readonly string ToString() => $"A8({this.PackedValue})";

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => this.PackedValue.GetHashCode();
public override readonly int GetHashCode() => this.PackedValue.GetHashCode();

/// <summary>
/// Packs a <see cref="float"/> into a byte.
Expand Down
21 changes: 12 additions & 9 deletions src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Argb32(uint packed)
public uint Argb
{
[MethodImpl(InliningOptions.ShortMethod)]
get => Unsafe.As<Argb32, uint>(ref this);
readonly get => Unsafe.As<Argb32, uint>(ref Unsafe.AsRef(this));

[MethodImpl(InliningOptions.ShortMethod)]
set => Unsafe.As<Argb32, uint>(ref this) = value;
Expand All @@ -138,7 +138,10 @@ public uint Argb
/// <inheritdoc/>
public uint PackedValue
{
get => this.Argb;
[MethodImpl(InliningOptions.ShortMethod)]
readonly get => this.Argb;

[MethodImpl(InliningOptions.ShortMethod)]
set => this.Argb = value;
}

Expand Down Expand Up @@ -181,23 +184,23 @@ public uint PackedValue
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);

/// <inheritdoc />
public PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();
public readonly PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector) => this.Pack(ref vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -320,21 +323,21 @@ public void FromRgba64(Rgba64 source)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Argb32 argb32 && this.Equals(argb32);
public override readonly bool Equals(object obj) => obj is Argb32 argb32 && this.Equals(argb32);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Argb32 other) => this.Argb == other.Argb;
public readonly bool Equals(Argb32 other) => this.Argb == other.Argb;

/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString() => $"Argb({this.A}, {this.R}, {this.G}, {this.B})";
public override readonly string ToString() => $"Argb({this.A}, {this.R}, {this.G}, {this.B})";

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => this.Argb.GetHashCode();
public override readonly int GetHashCode() => this.Argb.GetHashCode();

/// <summary>
/// Packs the four floats into a color.
Expand Down
14 changes: 7 additions & 7 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public Bgr24(byte r, byte g, byte b)
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);

/// <inheritdoc/>
public PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();
public readonly PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -110,7 +110,7 @@ public void FromVector4(Vector4 vector)

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToVector4() => new Rgba32(this.R, this.G, this.B, byte.MaxValue).ToVector4();
public readonly Vector4 ToVector4() => new Rgba32(this.R, this.G, this.B, byte.MaxValue).ToVector4();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -219,16 +219,16 @@ public void FromRgba64(Rgba64 source)

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Bgr24 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B);
public readonly bool Equals(Bgr24 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B);

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Bgr24 other && this.Equals(other);
public override readonly bool Equals(object obj) => obj is Bgr24 other && this.Equals(other);

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

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => HashCode.Combine(this.R, this.B, this.G);
public override readonly int GetHashCode() => HashCode.Combine(this.R, this.B, this.G);
}
}
16 changes: 8 additions & 8 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public Bgr565(float x, float y, float z)
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);

/// <inheritdoc />
public PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations<Bgr565>();
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations<Bgr565>();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
Expand All @@ -81,7 +81,7 @@ public void FromVector4(Vector4 vector)

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

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

/// <inheritdoc />
public override bool Equals(object obj) => obj is Bgr565 other && this.Equals(other);
public override readonly bool Equals(object obj) => obj is Bgr565 other && this.Equals(other);

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Bgr565 other) => this.PackedValue.Equals(other.PackedValue);
public readonly bool Equals(Bgr565 other) => this.PackedValue.Equals(other.PackedValue);

/// <inheritdoc />
public override string ToString()
public override readonly string ToString()
{
var vector = this.ToVector3();
return FormattableString.Invariant($"Bgr565({vector.Z:#0.##}, {vector.Y:#0.##}, {vector.X:#0.##})");
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => this.PackedValue.GetHashCode();
public override readonly int GetHashCode() => this.PackedValue.GetHashCode();

[MethodImpl(InliningOptions.ShortMethod)]
private static ushort Pack(ref Vector3 vector)
Expand Down
18 changes: 9 additions & 9 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Bgra32(byte r, byte g, byte b, byte a)
public uint Bgra
{
[MethodImpl(InliningOptions.ShortMethod)]
get => Unsafe.As<Bgra32, uint>(ref this);
readonly get => Unsafe.As<Bgra32, uint>(ref Unsafe.AsRef(this));

[MethodImpl(InliningOptions.ShortMethod)]
set => Unsafe.As<Bgra32, uint>(ref this) = value;
Expand All @@ -94,7 +94,7 @@ public uint Bgra
/// <inheritdoc/>
public uint PackedValue
{
get => this.Bgra;
readonly get => this.Bgra;
set => this.Bgra = value;
}

Expand Down Expand Up @@ -137,23 +137,23 @@ public uint PackedValue
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);

/// <inheritdoc/>
public PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();
public readonly PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector) => this.Pack(ref vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
Expand Down Expand Up @@ -276,16 +276,16 @@ public void FromRgba64(Rgba64 source)
}

/// <inheritdoc/>
public override bool Equals(object obj) => obj is Bgra32 other && this.Equals(other);
public override readonly bool Equals(object obj) => obj is Bgra32 other && this.Equals(other);

/// <inheritdoc/>
public bool Equals(Bgra32 other) => this.Bgra.Equals(other.Bgra);
public readonly bool Equals(Bgra32 other) => this.Bgra.Equals(other.Bgra);

/// <inheritdoc/>
public override int GetHashCode() => this.Bgra.GetHashCode();
public override readonly int GetHashCode() => this.Bgra.GetHashCode();

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

/// <summary>
/// Packs a <see cref="Vector4"/> into a color.
Expand Down
14 changes: 7 additions & 7 deletions src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ public Bgra4444(float x, float y, float z, float w)
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);

/// <inheritdoc />
public PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations<Bgra4444>();
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations<Bgra4444>();

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);

/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToScaledVector4() => this.ToVector4();
public readonly Vector4 ToScaledVector4() => this.ToVector4();

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector) => this.PackedValue = Pack(ref vector);

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ToVector4()
public readonly Vector4 ToVector4()
{
const float Max = 1 / 15F;

Expand Down Expand Up @@ -142,22 +142,22 @@ public void ToRgba32(ref Rgba32 dest)
public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4());

/// <inheritdoc />
public override bool Equals(object obj) => obj is Bgra4444 other && this.Equals(other);
public override readonly bool Equals(object obj) => obj is Bgra4444 other && this.Equals(other);

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Bgra4444 other) => this.PackedValue.Equals(other.PackedValue);
public readonly bool Equals(Bgra4444 other) => this.PackedValue.Equals(other.PackedValue);

/// <inheritdoc />
public override string ToString()
public override readonly string ToString()
{
var vector = this.ToVector4();
return FormattableString.Invariant($"Bgra4444({vector.Z:#0.##}, {vector.Y:#0.##}, {vector.X:#0.##}, {vector.W:#0.##})");
}

/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public override int GetHashCode() => this.PackedValue.GetHashCode();
public override readonly int GetHashCode() => this.PackedValue.GetHashCode();

[MethodImpl(InliningOptions.ShortMethod)]
private static ushort Pack(ref Vector4 vector)
Expand Down
Loading