From f92e8bff8bc38c94c691c02683a78ccc8ac0d5ab Mon Sep 17 00:00:00 2001
From: Christopher Whitley <103014489+AristurtleDev@users.noreply.github.com>
Date: Wed, 10 Jul 2024 01:42:55 -0400
Subject: [PATCH] Added FromAbgr method
---
source/MonoGame.Extended/ColorExtensions.cs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/source/MonoGame.Extended/ColorExtensions.cs b/source/MonoGame.Extended/ColorExtensions.cs
index 452ad37ff..b32c5f151 100644
--- a/source/MonoGame.Extended/ColorExtensions.cs
+++ b/source/MonoGame.Extended/ColorExtensions.cs
@@ -81,5 +81,26 @@ public static HslColor ToHsl(this Color c)
return new HslColor(h, s, l);
}
+
+ ///
+ /// Returns a new value based on a packed value in the ABGR format.
+ ///
+ ///
+ /// 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
+ /// >ColorExtensions.FromAbgr(0x123456FF);
+ ///
+ /// The packed color value in ABGR format
+ /// The value created
+ 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);
+ }
}
}