From 355d1bc6b6c64c02ecb6d40f62aa23d97475dbd9 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 Mar 2026 18:29:28 +0100 Subject: [PATCH] Implement missing methods for Rgba128 --- .../PixelImplementations/Rgb96.cs | 10 +-- .../PixelImplementations/Rgba128.cs | 87 ++++++++++++------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs index 6237d3d374..d318b067c1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb96.cs @@ -155,7 +155,7 @@ public partial struct Rgb96 : IPixel, IEquatable /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create( - PixelComponentInfo.Create(4, 16, 16, 16), + PixelComponentInfo.Create(3, 32, 32, 32), PixelColorType.RGB, PixelAlphaRepresentation.None); @@ -167,13 +167,13 @@ public partial struct Rgb96 : IPixel, IEquatable [MethodImpl(MethodImplOptions.AggressiveInlining)] public override readonly int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Equals(Rgb96 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B); - /// public override readonly string ToString() => FormattableString.Invariant($"Rgb96({this.R}, {this.G}, {this.B})"); /// public override readonly bool Equals(object? obj) => obj is Rgb96 rgb && rgb.R == this.R && rgb.G == this.G && rgb.B == this.B; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly bool Equals(Rgb96 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs index fd094be599..c748456b87 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba128.cs @@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.PixelFormats; /// /// [StructLayout(LayoutKind.Sequential)] -public partial struct Rgba128 : IPixel +public partial struct Rgba128 : IPixel, IEquatable { private const float InvMax = 1.0f / uint.MaxValue; @@ -81,58 +81,87 @@ public partial struct Rgba128 : IPixel /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ToVector4() => new( + public readonly Vector4 ToVector4() => new( this.R * InvMax, this.G * InvMax, this.B * InvMax, this.A * InvMax); - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A); + /// + public static PixelOperations CreatePixelOperations() => new(); - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Rgba128 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B) && this.A.Equals(other.A); + /// + public static Rgba128 FromScaledVector4(Vector4 source) => FromVector4(source); - /// - public override string ToString() => FormattableString.Invariant($"Rgba128({this.R}, {this.G}, {this.B}, {this.A})"); + /// + public static Rgba128 FromVector4(Vector4 source) => FromVector4(source); - public static PixelOperations CreatePixelOperations() => throw new NotImplementedException(); + /// + public static Rgba128 FromAbgr32(Abgr32 source) => new(source.R, source.G, source.B, source.A); - public static Rgba128 FromScaledVector4(Vector4 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromArgb32(Argb32 source) => new(source.R, source.G, source.B, source.A); - public static Rgba128 FromVector4(Vector4 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromBgra5551(Bgra5551 source) => FromScaledVector4(source.ToScaledVector4()); - public static Rgba128 FromAbgr32(Abgr32 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromBgr24(Bgr24 source) => new(source.R, source.G, source.B, uint.MaxValue); - public static Rgba128 FromArgb32(Argb32 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromBgra32(Bgra32 source) => new(source.R, source.G, source.B, source.A); - public static Rgba128 FromBgra5551(Bgra5551 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromL8(L8 source) + { + ushort rgb = ColorNumerics.From8BitTo16Bit(source.PackedValue); + return new Rgba128(rgb, rgb, rgb, rgb); + } - public static Rgba128 FromBgr24(Bgr24 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromL16(L16 source) => new(source.PackedValue, source.PackedValue, source.PackedValue, source.PackedValue); - public static Rgba128 FromBgra32(Bgra32 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromLa16(La16 source) => new(source.PackedValue, source.PackedValue, source.PackedValue, source.PackedValue); - public static Rgba128 FromL8(L8 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromLa32(La32 source) => new(source.L, source.L, source.L, source.L); - public static Rgba128 FromL16(L16 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromRgb24(Rgb24 source) => new(source.R, source.G, source.B, uint.MaxValue); - public static Rgba128 FromLa16(La16 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromRgba32(Rgba32 source) => new(source.R, source.G, source.B, source.A); - public static Rgba128 FromLa32(La32 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromRgb48(Rgb48 source) => new(source.R, source.G, source.B, uint.MaxValue); - public static Rgba128 FromRgb24(Rgb24 source) => throw new NotImplementedException(); + /// + public static Rgba128 FromRgba64(Rgba64 source) => new(source.R, source.G, source.B, source.A); - public static Rgba128 FromRgba32(Rgba32 source) => throw new NotImplementedException(); + /// + public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create( + PixelComponentInfo.Create(4, 32, 32, 32), + PixelColorType.RGB, + PixelAlphaRepresentation.Unassociated); - public static Rgba128 FromRgb48(Rgb48 source) => throw new NotImplementedException(); + /// + public readonly Rgba32 ToRgba32() => throw new NotImplementedException(); - public static Rgba128 FromRgba64(Rgba64 source) => throw new NotImplementedException(); + /// + public readonly Vector4 ToScaledVector4() => throw new NotImplementedException(); - public static PixelTypeInfo GetPixelTypeInfo() => throw new NotImplementedException(); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override readonly int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A); + + /// + public override readonly string ToString() => FormattableString.Invariant($"Rgba128({this.R}, {this.G}, {this.B}, {this.A})"); - public Rgba32 ToRgba32() => throw new NotImplementedException(); + /// + public override readonly bool Equals(object? obj) => obj is Rgba128 rgb && rgb.R == this.R && rgb.G == this.G && rgb.B == this.B && rgb.A == this.A; - public Vector4 ToScaledVector4() => throw new NotImplementedException(); + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public readonly bool Equals(Rgba128 other) => this.R.Equals(other.R) && this.G.Equals(other.G) && this.B.Equals(other.B) && this.A.Equals(other.A); }