Skip to content

Commit c7f18c8

Browse files
Use info for color conversion
1 parent db70581 commit c7f18c8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ImageSharp/Color/Color.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Numerics;
55
using System.Runtime.CompilerServices;
6+
using SixLabors.ImageSharp.Formats;
67
using SixLabors.ImageSharp.PixelFormats;
78

89
namespace SixLabors.ImageSharp;
@@ -124,7 +125,9 @@ public static Color FromPixel<TPixel>(TPixel pixel)
124125
{
125126
return new((L16)(object)pixel);
126127
}
127-
else if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>())
128+
129+
PixelTypeInfo info = TPixel.GetPixelTypeInfo();
130+
if (info.ComponentPrecision <= PixelComponentPrecision.Byte)
128131
{
129132
Rgba32 p = default;
130133
pixel.ToRgba32(ref p);

0 commit comments

Comments
 (0)