Skip to content

Commit

Permalink
Added FromAbgr method
Browse files Browse the repository at this point in the history
  • Loading branch information
AristurtleDev committed Jul 10, 2024
1 parent 4beea37 commit f92e8bf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions source/MonoGame.Extended/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,26 @@ public static HslColor ToHsl(this Color c)

return new HslColor(h, s, l);
}

/// <summary>
/// Returns a new <see cref="Color"/> value based on a packed value in the ABGR format.
/// </summary>
/// <remarks>
/// This is useful for when you have HTML hex style values such as #123456 and want to use it in hex format for
/// the parameter. Since Color's standard format is RGBA, you would have to do new Color(0xFF563212) since R
/// is the LSB. With this method, you can write it the same way it is written in HTML hex by doing
/// <c>>ColorExtensions.FromAbgr(0x123456FF);</c>
/// </remarks>
/// <param name="abgr">The packed color value in ABGR format</param>
/// <returns>The <see cref="Color"/> value created</returns>
public static Color FromAbgr(uint abgr)
{
uint rgba = (abgr & 0x000000FF) << 24 | // Alpha
(abgr & 0x0000FF00) << 8 | // Blue
(abgr & 0x00FF0000) >> 8 | // Green
(abgr & 0xFF000000) >> 24; // Red

return new Color(rgba);
}
}
}

0 comments on commit f92e8bf

Please sign in to comment.