Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Ensure colorspaces are valid (#1388)
Browse files Browse the repository at this point in the history
Fixes #1383
  • Loading branch information
mattleibow committed Sep 25, 2020
1 parent 4d8f504 commit afec3ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Samples/Samples.Mac/Samples.Mac.csproj
Expand Up @@ -54,6 +54,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
<Reference Include="OpenTK" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter" Version="3.0.0" />
Expand Down
Expand Up @@ -11,6 +11,10 @@ public static Color ToSystemColor(this NSColor color)
if (color == null)
throw new ArgumentNullException(nameof(color));

// make sure the colorspace is valid for RGBA
// we can't check as the check will throw if it is invalid
color = color.UsingColorSpace(NSColorSpace.SRGBColorSpace);

color.GetRgba(out var red, out var green, out var blue, out var alpha);
return Color.FromArgb((int)(alpha * 255), (int)(red * 255), (int)(green * 255), (int)(blue * 255));
}
Expand Down

0 comments on commit afec3ca

Please sign in to comment.