ColorBgra.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Reflection;
  7. using System.Runtime.InteropServices;
  8. namespace PaintDotNet
  9. {
  10. /// <summary>
  11. /// This is our pixel format that we will work with. It is always 32-bits / 4-bytes and is
  12. /// always laid out in BGRA order.
  13. /// Generally used with the Surface class.
  14. /// </summary>
  15. [Serializable]
  16. [StructLayout(LayoutKind.Explicit)]
  17. public struct ColorBgra
  18. {
  19. [FieldOffset(0)]
  20. public byte B;
  21. [FieldOffset(1)]
  22. public byte G;
  23. [FieldOffset(2)]
  24. public byte R;
  25. [FieldOffset(3)]
  26. public byte A;
  27. /// <summary>
  28. /// Lets you change B, G, R, and A at the same time.
  29. /// </summary>
  30. [NonSerialized]
  31. [FieldOffset(0)]
  32. public uint Bgra;
  33. public const int BlueChannel = 0;
  34. public const int GreenChannel = 1;
  35. public const int RedChannel = 2;
  36. public const int AlphaChannel = 3;
  37. public const int SizeOf = 4;
  38. public static ColorBgra ParseHexString(string hexString)
  39. {
  40. uint value = Convert.ToUInt32(hexString, 16);
  41. return ColorBgra.FromUInt32(value);
  42. }
  43. public string ToHexString()
  44. {
  45. int rgbNumber = (this.R << 16) | (this.G << 8) | this.B;
  46. string colorString = Convert.ToString(rgbNumber, 16);
  47. while (colorString.Length < 6)
  48. {
  49. colorString = "0" + colorString;
  50. }
  51. string alphaString = System.Convert.ToString(this.A, 16);
  52. while (alphaString.Length < 2)
  53. {
  54. alphaString = "0" + alphaString;
  55. }
  56. colorString = alphaString + colorString;
  57. return colorString.ToUpper();
  58. }
  59. /// <summary>
  60. /// Gets or sets the byte value of the specified color channel.
  61. /// </summary>
  62. public unsafe byte this[int channel]
  63. {
  64. get
  65. {
  66. if (channel < 0 || channel > 3)
  67. {
  68. throw new ArgumentOutOfRangeException("channel", channel, "valid range is [0,3]");
  69. }
  70. fixed (byte* p = &B)
  71. {
  72. return p[channel];
  73. }
  74. }
  75. set
  76. {
  77. if (channel < 0 || channel > 3)
  78. {
  79. throw new ArgumentOutOfRangeException("channel", channel, "valid range is [0,3]");
  80. }
  81. fixed (byte* p = &B)
  82. {
  83. p[channel] = value;
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// Gets the luminance intensity of the pixel based on the values of the red, green, and blue components. Alpha is ignored.
  89. /// </summary>
  90. /// <returns>A value in the range 0 to 1 inclusive.</returns>
  91. public double GetIntensity()
  92. {
  93. return ((0.114 * (double)B) + (0.587 * (double)G) + (0.299 * (double)R)) / 255.0;
  94. }
  95. /// <summary>
  96. /// Gets the luminance intensity of the pixel based on the values of the red, green, and blue components. Alpha is ignored.
  97. /// </summary>
  98. /// <returns>A value in the range 0 to 255 inclusive.</returns>
  99. public byte GetIntensityByte()
  100. {
  101. return (byte)((7471 * B + 38470 * G + 19595 * R) >> 16);
  102. }
  103. /// <summary>
  104. /// Returns the maximum value out of the B, G, and R values. Alpha is ignored.
  105. /// </summary>
  106. /// <returns></returns>
  107. public byte GetMaxColorChannelValue()
  108. {
  109. return Math.Max(this.B, Math.Max(this.G, this.R));
  110. }
  111. /// <summary>
  112. /// Returns the average of the B, G, and R values. Alpha is ignored.
  113. /// </summary>
  114. /// <returns></returns>
  115. public byte GetAverageColorChannelValue()
  116. {
  117. return (byte)((this.B + this.G + this.R) / 3);
  118. }
  119. /// <summary>
  120. /// Compares two ColorBgra instance to determine if they are equal.
  121. /// </summary>
  122. public static bool operator ==(ColorBgra lhs, ColorBgra rhs)
  123. {
  124. return lhs.Bgra == rhs.Bgra;
  125. }
  126. /// <summary>
  127. /// Compares two ColorBgra instance to determine if they are not equal.
  128. /// </summary>
  129. public static bool operator !=(ColorBgra lhs, ColorBgra rhs)
  130. {
  131. return lhs.Bgra != rhs.Bgra;
  132. }
  133. /// <summary>
  134. /// Compares two ColorBgra instance to determine if they are equal.
  135. /// </summary>
  136. public override bool Equals(object obj)
  137. {
  138. if (obj != null && obj is ColorBgra && ((ColorBgra)obj).Bgra == this.Bgra)
  139. {
  140. return true;
  141. }
  142. else
  143. {
  144. return false;
  145. }
  146. }
  147. /// <summary>
  148. /// Returns a hash code for this color value.
  149. /// </summary>
  150. /// <returns></returns>
  151. public override int GetHashCode()
  152. {
  153. unchecked
  154. {
  155. return (int)Bgra;
  156. }
  157. }
  158. /// <summary>
  159. /// Gets the equivalent GDI+ PixelFormat.
  160. /// </summary>
  161. /// <remarks>
  162. /// This property always returns PixelFormat.Format32bppArgb.
  163. /// </remarks>
  164. public static PixelFormat PixelFormat
  165. {
  166. get
  167. {
  168. return PixelFormat.Format32bppArgb;
  169. }
  170. }
  171. /// <summary>
  172. /// Returns a new ColorBgra with the same color values but with a new alpha component value.
  173. /// </summary>
  174. public ColorBgra NewAlpha(byte newA)
  175. {
  176. return ColorBgra.FromBgra(B, G, R, newA);
  177. }
  178. /// <summary>
  179. /// Creates a new ColorBgra instance with the given color and alpha values.
  180. /// </summary>
  181. [Obsolete("Use FromBgra() instead (make sure to swap the order of your b and r parameters)")]
  182. public static ColorBgra FromRgba(byte r, byte g, byte b, byte a)
  183. {
  184. return FromBgra(b, g, r, a);
  185. }
  186. /// <summary>
  187. /// Creates a new ColorBgra instance with the given color values, and 255 for alpha.
  188. /// </summary>
  189. [Obsolete("Use FromBgr() instead (make sure to swap the order of your b and r parameters)")]
  190. public static ColorBgra FromRgb(byte r, byte g, byte b)
  191. {
  192. return FromBgr(b, g, r);
  193. }
  194. /// <summary>
  195. /// Creates a new ColorBgra instance with the given color and alpha values.
  196. /// </summary>
  197. public static ColorBgra FromBgra(byte b, byte g, byte r, byte a)
  198. {
  199. ColorBgra color = new ColorBgra();
  200. color.Bgra = BgraToUInt32(b, g, r, a);
  201. return color;
  202. }
  203. /// <summary>
  204. /// Creates a new ColorBgra instance with the given color and alpha values.
  205. /// </summary>
  206. public static ColorBgra FromBgraClamped(int b, int g, int r, int a)
  207. {
  208. return FromBgra(
  209. Utility.ClampToByte(b),
  210. Utility.ClampToByte(g),
  211. Utility.ClampToByte(r),
  212. Utility.ClampToByte(a));
  213. }
  214. /// <summary>
  215. /// Creates a new ColorBgra instance with the given color and alpha values.
  216. /// </summary>
  217. public static ColorBgra FromBgraClamped(float b, float g, float r, float a)
  218. {
  219. return FromBgra(
  220. Utility.ClampToByte(b),
  221. Utility.ClampToByte(g),
  222. Utility.ClampToByte(r),
  223. Utility.ClampToByte(a));
  224. }
  225. /// <summary>
  226. /// Packs color and alpha values into a 32-bit integer.
  227. /// </summary>
  228. public static UInt32 BgraToUInt32(byte b, byte g, byte r, byte a)
  229. {
  230. return (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24);
  231. }
  232. /// <summary>
  233. /// Packs color and alpha values into a 32-bit integer.
  234. /// </summary>
  235. public static UInt32 BgraToUInt32(int b, int g, int r, int a)
  236. {
  237. return (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24);
  238. }
  239. /// <summary>
  240. /// Creates a new ColorBgra instance with the given color values, and 255 for alpha.
  241. /// </summary>
  242. public static ColorBgra FromBgr(byte b, byte g, byte r)
  243. {
  244. return FromBgra(b, g, r, 255);
  245. }
  246. /// <summary>
  247. /// Constructs a new ColorBgra instance with the given 32-bit value.
  248. /// </summary>
  249. public static ColorBgra FromUInt32(UInt32 bgra)
  250. {
  251. ColorBgra color = new ColorBgra();
  252. color.Bgra = bgra;
  253. return color;
  254. }
  255. /// <summary>
  256. /// Constructs a new ColorBgra instance given a 32-bit signed integer that represents an R,G,B triple.
  257. /// Alpha will be initialized to 255.
  258. /// </summary>
  259. public static ColorBgra FromOpaqueInt32(Int32 bgr)
  260. {
  261. if (bgr < 0 || bgr > 0xffffff)
  262. {
  263. throw new ArgumentOutOfRangeException("bgr", "must be in the range [0, 0xffffff]");
  264. }
  265. ColorBgra color = new ColorBgra();
  266. color.Bgra = (uint)bgr;
  267. color.A = 255;
  268. return color;
  269. }
  270. public static int ToOpaqueInt32(ColorBgra color)
  271. {
  272. if (color.A != 255)
  273. {
  274. throw new InvalidOperationException("Alpha value must be 255 for this to work");
  275. }
  276. return (int)(color.Bgra & 0xffffff);
  277. }
  278. /// <summary>
  279. /// Constructs a new ColorBgra instance from the values in the given Color instance.
  280. /// </summary>
  281. public static ColorBgra FromColor(Color c)
  282. {
  283. return FromBgra(c.B, c.G, c.R, c.A);
  284. }
  285. /// <summary>
  286. /// Converts this ColorBgra instance to a Color instance.
  287. /// </summary>
  288. public Color ToColor()
  289. {
  290. return Color.FromArgb(A, R, G, B);
  291. }
  292. /// <summary>
  293. /// Smoothly blends between two colors.
  294. /// </summary>
  295. public static ColorBgra Blend(ColorBgra ca, ColorBgra cb, byte cbAlpha)
  296. {
  297. uint caA = (uint)Utility.FastScaleByteByByte((byte)(255 - cbAlpha), ca.A);
  298. uint cbA = (uint)Utility.FastScaleByteByByte(cbAlpha, cb.A);
  299. uint cbAT = caA + cbA;
  300. uint r;
  301. uint g;
  302. uint b;
  303. if (cbAT == 0)
  304. {
  305. r = 0;
  306. g = 0;
  307. b = 0;
  308. }
  309. else
  310. {
  311. r = ((ca.R * caA) + (cb.R * cbA)) / cbAT;
  312. g = ((ca.G * caA) + (cb.G * cbA)) / cbAT;
  313. b = ((ca.B * caA) + (cb.B * cbA)) / cbAT;
  314. }
  315. return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)cbAT);
  316. }
  317. /// <summary>
  318. /// Linearly interpolates between two color values.
  319. /// </summary>
  320. /// <param name="from">The color value that represents 0 on the lerp number line.</param>
  321. /// <param name="to">The color value that represents 1 on the lerp number line.</param>
  322. /// <param name="frac">A value in the range [0, 1].</param>
  323. /// <remarks>
  324. /// This method does a simple lerp on each color value and on the alpha channel. It does
  325. /// not properly take into account the alpha channel's effect on color blending.
  326. /// </remarks>
  327. public static ColorBgra Lerp(ColorBgra from, ColorBgra to, float frac)
  328. {
  329. ColorBgra ret = new ColorBgra();
  330. ret.B = (byte)Utility.ClampToByte(Utility.Lerp(from.B, to.B, frac));
  331. ret.G = (byte)Utility.ClampToByte(Utility.Lerp(from.G, to.G, frac));
  332. ret.R = (byte)Utility.ClampToByte(Utility.Lerp(from.R, to.R, frac));
  333. ret.A = (byte)Utility.ClampToByte(Utility.Lerp(from.A, to.A, frac));
  334. return ret;
  335. }
  336. /// <summary>
  337. /// Linearly interpolates between two color values.
  338. /// </summary>
  339. /// <param name="from">The color value that represents 0 on the lerp number line.</param>
  340. /// <param name="to">The color value that represents 1 on the lerp number line.</param>
  341. /// <param name="frac">A value in the range [0, 1].</param>
  342. /// <remarks>
  343. /// This method does a simple lerp on each color value and on the alpha channel. It does
  344. /// not properly take into account the alpha channel's effect on color blending.
  345. /// </remarks>
  346. public static ColorBgra Lerp(ColorBgra from, ColorBgra to, double frac)
  347. {
  348. ColorBgra ret = new ColorBgra();
  349. ret.B = (byte)Utility.ClampToByte(Utility.Lerp(from.B, to.B, frac));
  350. ret.G = (byte)Utility.ClampToByte(Utility.Lerp(from.G, to.G, frac));
  351. ret.R = (byte)Utility.ClampToByte(Utility.Lerp(from.R, to.R, frac));
  352. ret.A = (byte)Utility.ClampToByte(Utility.Lerp(from.A, to.A, frac));
  353. return ret;
  354. }
  355. /// <summary>
  356. /// Blends four colors together based on the given weight values.
  357. /// </summary>
  358. /// <returns>The blended color.</returns>
  359. /// <remarks>
  360. /// The weights should be 16-bit fixed point numbers that add up to 65536 ("1.0").
  361. /// 4W16IP means "4 colors, weights, 16-bit integer precision"
  362. /// </remarks>
  363. public static ColorBgra BlendColors4W16IP(ColorBgra c1, uint w1, ColorBgra c2, uint w2, ColorBgra c3, uint w3, ColorBgra c4, uint w4)
  364. {
  365. #if DEBUG
  366. /*
  367. if ((w1 + w2 + w3 + w4) != 65536)
  368. {
  369. throw new ArgumentOutOfRangeException("w1 + w2 + w3 + w4 must equal 65536!");
  370. }
  371. * */
  372. #endif
  373. const uint ww = 32768;
  374. uint af = (c1.A * w1) + (c2.A * w2) + (c3.A * w3) + (c4.A * w4);
  375. uint a = (af + ww) >> 16;
  376. uint b;
  377. uint g;
  378. uint r;
  379. if (a == 0)
  380. {
  381. b = 0;
  382. g = 0;
  383. r = 0;
  384. }
  385. else
  386. {
  387. b = (uint)((((long)c1.A * c1.B * w1) + ((long)c2.A * c2.B * w2) + ((long)c3.A * c3.B * w3) + ((long)c4.A * c4.B * w4)) / af);
  388. g = (uint)((((long)c1.A * c1.G * w1) + ((long)c2.A * c2.G * w2) + ((long)c3.A * c3.G * w3) + ((long)c4.A * c4.G * w4)) / af);
  389. r = (uint)((((long)c1.A * c1.R * w1) + ((long)c2.A * c2.R * w2) + ((long)c3.A * c3.R * w3) + ((long)c4.A * c4.R * w4)) / af);
  390. }
  391. return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
  392. }
  393. /// <summary>
  394. /// Blends the colors based on the given weight values.
  395. /// </summary>
  396. /// <param name="c">The array of color values.</param>
  397. /// <param name="w">The array of weight values.</param>
  398. /// <returns>
  399. /// The weights should be fixed point numbers.
  400. /// The total summation of the weight values will be treated as "1.0".
  401. /// Each color will be blended in proportionally to its weight value respective to
  402. /// the total summation of the weight values.
  403. /// </returns>
  404. /// <remarks>
  405. /// "WAIP" stands for "weights, arbitrary integer precision"</remarks>
  406. public static ColorBgra BlendColorsWAIP(ColorBgra[] c, uint[] w)
  407. {
  408. if (c.Length != w.Length)
  409. {
  410. throw new ArgumentException("c.Length != w.Length");
  411. }
  412. if (c.Length == 0)
  413. {
  414. return ColorBgra.FromUInt32(0);
  415. }
  416. long wsum = 0;
  417. long asum = 0;
  418. for (int i = 0; i < w.Length; ++i)
  419. {
  420. wsum += w[i];
  421. asum += c[i].A * w[i];
  422. }
  423. uint a = (uint)((asum + (wsum >> 1)) / wsum);
  424. long b;
  425. long g;
  426. long r;
  427. if (a == 0)
  428. {
  429. b = 0;
  430. g = 0;
  431. r = 0;
  432. }
  433. else
  434. {
  435. b = 0;
  436. g = 0;
  437. r = 0;
  438. for (int i = 0; i < c.Length; ++i)
  439. {
  440. b += (long)c[i].A * c[i].B * w[i];
  441. g += (long)c[i].A * c[i].G * w[i];
  442. r += (long)c[i].A * c[i].R * w[i];
  443. }
  444. b /= asum;
  445. g /= asum;
  446. r /= asum;
  447. }
  448. return ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24));
  449. }
  450. /// <summary>
  451. /// Blends the colors based on the given weight values.
  452. /// </summary>
  453. /// <param name="c">The array of color values.</param>
  454. /// <param name="w">The array of weight values.</param>
  455. /// <returns>
  456. /// Each color will be blended in proportionally to its weight value respective to
  457. /// the total summation of the weight values.
  458. /// </returns>
  459. /// <remarks>
  460. /// "WAIP" stands for "weights, floating-point"</remarks>
  461. public static ColorBgra BlendColorsWFP(ColorBgra[] c, double[] w)
  462. {
  463. if (c.Length != w.Length)
  464. {
  465. throw new ArgumentException("c.Length != w.Length");
  466. }
  467. if (c.Length == 0)
  468. {
  469. return ColorBgra.Transparent;
  470. }
  471. double wsum = 0;
  472. double asum = 0;
  473. for (int i = 0; i < w.Length; ++i)
  474. {
  475. wsum += w[i];
  476. asum += (double)c[i].A * w[i];
  477. }
  478. double a = asum / wsum;
  479. double aMultWsum = a * wsum;
  480. double b;
  481. double g;
  482. double r;
  483. if (asum == 0)
  484. {
  485. b = 0;
  486. g = 0;
  487. r = 0;
  488. }
  489. else
  490. {
  491. b = 0;
  492. g = 0;
  493. r = 0;
  494. for (int i = 0; i < c.Length; ++i)
  495. {
  496. b += (double)c[i].A * c[i].B * w[i];
  497. g += (double)c[i].A * c[i].G * w[i];
  498. r += (double)c[i].A * c[i].R * w[i];
  499. }
  500. b /= aMultWsum;
  501. g /= aMultWsum;
  502. r /= aMultWsum;
  503. }
  504. return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
  505. }
  506. public static ColorBgra Blend(ColorBgra[] colors)
  507. {
  508. unsafe
  509. {
  510. fixed (ColorBgra* pColors = colors)
  511. {
  512. return Blend(pColors, colors.Length);
  513. }
  514. }
  515. }
  516. /// <summary>
  517. /// Smoothly blends the given colors together, assuming equal weighting for each one.
  518. /// </summary>
  519. /// <param name="colors"></param>
  520. /// <param name="colorCount"></param>
  521. /// <returns></returns>
  522. public unsafe static ColorBgra Blend(ColorBgra* colors, int count)
  523. {
  524. if (count < 0)
  525. {
  526. throw new ArgumentOutOfRangeException("count must be 0 or greater");
  527. }
  528. if (count == 0)
  529. {
  530. return ColorBgra.Transparent;
  531. }
  532. ulong aSum = 0;
  533. for (int i = 0; i < count; ++i)
  534. {
  535. aSum += (ulong)colors[i].A;
  536. }
  537. byte b = 0;
  538. byte g = 0;
  539. byte r = 0;
  540. byte a = (byte)(aSum / (ulong)count);
  541. if (aSum != 0)
  542. {
  543. ulong bSum = 0;
  544. ulong gSum = 0;
  545. ulong rSum = 0;
  546. for (int i = 0; i < count; ++i)
  547. {
  548. bSum += (ulong)(colors[i].A * colors[i].B);
  549. gSum += (ulong)(colors[i].A * colors[i].G);
  550. rSum += (ulong)(colors[i].A * colors[i].R);
  551. }
  552. b = (byte)(bSum / aSum);
  553. g = (byte)(gSum / aSum);
  554. r = (byte)(rSum / aSum);
  555. }
  556. return ColorBgra.FromBgra(b, g, r, a);
  557. }
  558. public override string ToString()
  559. {
  560. return "B: " + B + ", G: " + G + ", R: " + R + ", A: " + A;
  561. }
  562. /// <summary>
  563. /// Casts a ColorBgra to a UInt32.
  564. /// </summary>
  565. public static explicit operator UInt32(ColorBgra color)
  566. {
  567. return color.Bgra;
  568. }
  569. /// <summary>
  570. /// Casts a UInt32 to a ColorBgra.
  571. /// </summary>
  572. public static explicit operator ColorBgra(UInt32 uint32)
  573. {
  574. return ColorBgra.FromUInt32(uint32);
  575. }
  576. // Colors: copied from System.Drawing.Color's list (don't worry I didn't type it in
  577. // manually, I used a code generator w/ reflection ...)
  578. public static ColorBgra Transparent
  579. {
  580. get
  581. {
  582. return ColorBgra.FromBgra(255, 255, 255, 0);
  583. }
  584. }
  585. public static ColorBgra AliceBlue
  586. {
  587. get
  588. {
  589. return ColorBgra.FromBgra(255, 248, 240, 255);
  590. }
  591. }
  592. public static ColorBgra AntiqueWhite
  593. {
  594. get
  595. {
  596. return ColorBgra.FromBgra(215, 235, 250, 255);
  597. }
  598. }
  599. public static ColorBgra Aqua
  600. {
  601. get
  602. {
  603. return ColorBgra.FromBgra(255, 255, 0, 255);
  604. }
  605. }
  606. public static ColorBgra Aquamarine
  607. {
  608. get
  609. {
  610. return ColorBgra.FromBgra(212, 255, 127, 255);
  611. }
  612. }
  613. public static ColorBgra Azure
  614. {
  615. get
  616. {
  617. return ColorBgra.FromBgra(255, 255, 240, 255);
  618. }
  619. }
  620. public static ColorBgra Beige
  621. {
  622. get
  623. {
  624. return ColorBgra.FromBgra(220, 245, 245, 255);
  625. }
  626. }
  627. public static ColorBgra Bisque
  628. {
  629. get
  630. {
  631. return ColorBgra.FromBgra(196, 228, 255, 255);
  632. }
  633. }
  634. public static ColorBgra Black
  635. {
  636. get
  637. {
  638. return ColorBgra.FromBgra(0, 0, 0, 255);
  639. }
  640. }
  641. public static ColorBgra BlanchedAlmond
  642. {
  643. get
  644. {
  645. return ColorBgra.FromBgra(205, 235, 255, 255);
  646. }
  647. }
  648. public static ColorBgra Blue
  649. {
  650. get
  651. {
  652. return ColorBgra.FromBgra(255, 0, 0, 255);
  653. }
  654. }
  655. public static ColorBgra BlueViolet
  656. {
  657. get
  658. {
  659. return ColorBgra.FromBgra(226, 43, 138, 255);
  660. }
  661. }
  662. public static ColorBgra Brown
  663. {
  664. get
  665. {
  666. return ColorBgra.FromBgra(42, 42, 165, 255);
  667. }
  668. }
  669. public static ColorBgra BurlyWood
  670. {
  671. get
  672. {
  673. return ColorBgra.FromBgra(135, 184, 222, 255);
  674. }
  675. }
  676. public static ColorBgra CadetBlue
  677. {
  678. get
  679. {
  680. return ColorBgra.FromBgra(160, 158, 95, 255);
  681. }
  682. }
  683. public static ColorBgra Chartreuse
  684. {
  685. get
  686. {
  687. return ColorBgra.FromBgra(0, 255, 127, 255);
  688. }
  689. }
  690. public static ColorBgra Chocolate
  691. {
  692. get
  693. {
  694. return ColorBgra.FromBgra(30, 105, 210, 255);
  695. }
  696. }
  697. public static ColorBgra Coral
  698. {
  699. get
  700. {
  701. return ColorBgra.FromBgra(80, 127, 255, 255);
  702. }
  703. }
  704. public static ColorBgra CornflowerBlue
  705. {
  706. get
  707. {
  708. return ColorBgra.FromBgra(237, 149, 100, 255);
  709. }
  710. }
  711. public static ColorBgra Cornsilk
  712. {
  713. get
  714. {
  715. return ColorBgra.FromBgra(220, 248, 255, 255);
  716. }
  717. }
  718. public static ColorBgra Crimson
  719. {
  720. get
  721. {
  722. return ColorBgra.FromBgra(60, 20, 220, 255);
  723. }
  724. }
  725. public static ColorBgra Cyan
  726. {
  727. get
  728. {
  729. return ColorBgra.FromBgra(255, 255, 0, 255);
  730. }
  731. }
  732. public static ColorBgra DarkBlue
  733. {
  734. get
  735. {
  736. return ColorBgra.FromBgra(139, 0, 0, 255);
  737. }
  738. }
  739. public static ColorBgra DarkCyan
  740. {
  741. get
  742. {
  743. return ColorBgra.FromBgra(139, 139, 0, 255);
  744. }
  745. }
  746. public static ColorBgra DarkGoldenrod
  747. {
  748. get
  749. {
  750. return ColorBgra.FromBgra(11, 134, 184, 255);
  751. }
  752. }
  753. public static ColorBgra DarkGray
  754. {
  755. get
  756. {
  757. return ColorBgra.FromBgra(169, 169, 169, 255);
  758. }
  759. }
  760. public static ColorBgra DarkGreen
  761. {
  762. get
  763. {
  764. return ColorBgra.FromBgra(0, 100, 0, 255);
  765. }
  766. }
  767. public static ColorBgra DarkKhaki
  768. {
  769. get
  770. {
  771. return ColorBgra.FromBgra(107, 183, 189, 255);
  772. }
  773. }
  774. public static ColorBgra DarkMagenta
  775. {
  776. get
  777. {
  778. return ColorBgra.FromBgra(139, 0, 139, 255);
  779. }
  780. }
  781. public static ColorBgra DarkOliveGreen
  782. {
  783. get
  784. {
  785. return ColorBgra.FromBgra(47, 107, 85, 255);
  786. }
  787. }
  788. public static ColorBgra DarkOrange
  789. {
  790. get
  791. {
  792. return ColorBgra.FromBgra(0, 140, 255, 255);
  793. }
  794. }
  795. public static ColorBgra DarkOrchid
  796. {
  797. get
  798. {
  799. return ColorBgra.FromBgra(204, 50, 153, 255);
  800. }
  801. }
  802. public static ColorBgra DarkRed
  803. {
  804. get
  805. {
  806. return ColorBgra.FromBgra(0, 0, 139, 255);
  807. }
  808. }
  809. public static ColorBgra DarkSalmon
  810. {
  811. get
  812. {
  813. return ColorBgra.FromBgra(122, 150, 233, 255);
  814. }
  815. }
  816. public static ColorBgra DarkSeaGreen
  817. {
  818. get
  819. {
  820. return ColorBgra.FromBgra(139, 188, 143, 255);
  821. }
  822. }
  823. public static ColorBgra DarkSlateBlue
  824. {
  825. get
  826. {
  827. return ColorBgra.FromBgra(139, 61, 72, 255);
  828. }
  829. }
  830. public static ColorBgra DarkSlateGray
  831. {
  832. get
  833. {
  834. return ColorBgra.FromBgra(79, 79, 47, 255);
  835. }
  836. }
  837. public static ColorBgra DarkTurquoise
  838. {
  839. get
  840. {
  841. return ColorBgra.FromBgra(209, 206, 0, 255);
  842. }
  843. }
  844. public static ColorBgra DarkViolet
  845. {
  846. get
  847. {
  848. return ColorBgra.FromBgra(211, 0, 148, 255);
  849. }
  850. }
  851. public static ColorBgra DeepPink
  852. {
  853. get
  854. {
  855. return ColorBgra.FromBgra(147, 20, 255, 255);
  856. }
  857. }
  858. public static ColorBgra DeepSkyBlue
  859. {
  860. get
  861. {
  862. return ColorBgra.FromBgra(255, 191, 0, 255);
  863. }
  864. }
  865. public static ColorBgra DimGray
  866. {
  867. get
  868. {
  869. return ColorBgra.FromBgra(105, 105, 105, 255);
  870. }
  871. }
  872. public static ColorBgra DodgerBlue
  873. {
  874. get
  875. {
  876. return ColorBgra.FromBgra(255, 144, 30, 255);
  877. }
  878. }
  879. public static ColorBgra Firebrick
  880. {
  881. get
  882. {
  883. return ColorBgra.FromBgra(34, 34, 178, 255);
  884. }
  885. }
  886. public static ColorBgra FloralWhite
  887. {
  888. get
  889. {
  890. return ColorBgra.FromBgra(240, 250, 255, 255);
  891. }
  892. }
  893. public static ColorBgra ForestGreen
  894. {
  895. get
  896. {
  897. return ColorBgra.FromBgra(34, 139, 34, 255);
  898. }
  899. }
  900. public static ColorBgra Fuchsia
  901. {
  902. get
  903. {
  904. return ColorBgra.FromBgra(255, 0, 255, 255);
  905. }
  906. }
  907. public static ColorBgra Gainsboro
  908. {
  909. get
  910. {
  911. return ColorBgra.FromBgra(220, 220, 220, 255);
  912. }
  913. }
  914. public static ColorBgra GhostWhite
  915. {
  916. get
  917. {
  918. return ColorBgra.FromBgra(255, 248, 248, 255);
  919. }
  920. }
  921. public static ColorBgra Gold
  922. {
  923. get
  924. {
  925. return ColorBgra.FromBgra(0, 215, 255, 255);
  926. }
  927. }
  928. public static ColorBgra Goldenrod
  929. {
  930. get
  931. {
  932. return ColorBgra.FromBgra(32, 165, 218, 255);
  933. }
  934. }
  935. public static ColorBgra Gray
  936. {
  937. get
  938. {
  939. return ColorBgra.FromBgra(128, 128, 128, 255);
  940. }
  941. }
  942. public static ColorBgra Green
  943. {
  944. get
  945. {
  946. return ColorBgra.FromBgra(0, 128, 0, 255);
  947. }
  948. }
  949. public static ColorBgra GreenYellow
  950. {
  951. get
  952. {
  953. return ColorBgra.FromBgra(47, 255, 173, 255);
  954. }
  955. }
  956. public static ColorBgra Honeydew
  957. {
  958. get
  959. {
  960. return ColorBgra.FromBgra(240, 255, 240, 255);
  961. }
  962. }
  963. public static ColorBgra HotPink
  964. {
  965. get
  966. {
  967. return ColorBgra.FromBgra(180, 105, 255, 255);
  968. }
  969. }
  970. public static ColorBgra IndianRed
  971. {
  972. get
  973. {
  974. return ColorBgra.FromBgra(92, 92, 205, 255);
  975. }
  976. }
  977. public static ColorBgra Indigo
  978. {
  979. get
  980. {
  981. return ColorBgra.FromBgra(130, 0, 75, 255);
  982. }
  983. }
  984. public static ColorBgra Ivory
  985. {
  986. get
  987. {
  988. return ColorBgra.FromBgra(240, 255, 255, 255);
  989. }
  990. }
  991. public static ColorBgra Khaki
  992. {
  993. get
  994. {
  995. return ColorBgra.FromBgra(140, 230, 240, 255);
  996. }
  997. }
  998. public static ColorBgra Lavender
  999. {
  1000. get
  1001. {
  1002. return ColorBgra.FromBgra(250, 230, 230, 255);
  1003. }
  1004. }
  1005. public static ColorBgra LavenderBlush
  1006. {
  1007. get
  1008. {
  1009. return ColorBgra.FromBgra(245, 240, 255, 255);
  1010. }
  1011. }
  1012. public static ColorBgra LawnGreen
  1013. {
  1014. get
  1015. {
  1016. return ColorBgra.FromBgra(0, 252, 124, 255);
  1017. }
  1018. }
  1019. public static ColorBgra LemonChiffon
  1020. {
  1021. get
  1022. {
  1023. return ColorBgra.FromBgra(205, 250, 255, 255);
  1024. }
  1025. }
  1026. public static ColorBgra LightBlue
  1027. {
  1028. get
  1029. {
  1030. return ColorBgra.FromBgra(230, 216, 173, 255);
  1031. }
  1032. }
  1033. public static ColorBgra LightCoral
  1034. {
  1035. get
  1036. {
  1037. return ColorBgra.FromBgra(128, 128, 240, 255);
  1038. }
  1039. }
  1040. public static ColorBgra LightCyan
  1041. {
  1042. get
  1043. {
  1044. return ColorBgra.FromBgra(255, 255, 224, 255);
  1045. }
  1046. }
  1047. public static ColorBgra LightGoldenrodYellow
  1048. {
  1049. get
  1050. {
  1051. return ColorBgra.FromBgra(210, 250, 250, 255);
  1052. }
  1053. }
  1054. public static ColorBgra LightGreen
  1055. {
  1056. get
  1057. {
  1058. return ColorBgra.FromBgra(144, 238, 144, 255);
  1059. }
  1060. }
  1061. public static ColorBgra LightGray
  1062. {
  1063. get
  1064. {
  1065. return ColorBgra.FromBgra(211, 211, 211, 255);
  1066. }
  1067. }
  1068. public static ColorBgra LightPink
  1069. {
  1070. get
  1071. {
  1072. return ColorBgra.FromBgra(193, 182, 255, 255);
  1073. }
  1074. }
  1075. public static ColorBgra LightSalmon
  1076. {
  1077. get
  1078. {
  1079. return ColorBgra.FromBgra(122, 160, 255, 255);
  1080. }
  1081. }
  1082. public static ColorBgra LightSeaGreen
  1083. {
  1084. get
  1085. {
  1086. return ColorBgra.FromBgra(170, 178, 32, 255);
  1087. }
  1088. }
  1089. public static ColorBgra LightSkyBlue
  1090. {
  1091. get
  1092. {
  1093. return ColorBgra.FromBgra(250, 206, 135, 255);
  1094. }
  1095. }
  1096. public static ColorBgra LightSlateGray
  1097. {
  1098. get
  1099. {
  1100. return ColorBgra.FromBgra(153, 136, 119, 255);
  1101. }
  1102. }
  1103. public static ColorBgra LightSteelBlue
  1104. {
  1105. get
  1106. {
  1107. return ColorBgra.FromBgra(222, 196, 176, 255);
  1108. }
  1109. }
  1110. public static ColorBgra LightYellow
  1111. {
  1112. get
  1113. {
  1114. return ColorBgra.FromBgra(224, 255, 255, 255);
  1115. }
  1116. }
  1117. public static ColorBgra Lime
  1118. {
  1119. get
  1120. {
  1121. return ColorBgra.FromBgra(0, 255, 0, 255);
  1122. }
  1123. }
  1124. public static ColorBgra LimeGreen
  1125. {
  1126. get
  1127. {
  1128. return ColorBgra.FromBgra(50, 205, 50, 255);
  1129. }
  1130. }
  1131. public static ColorBgra Linen
  1132. {
  1133. get
  1134. {
  1135. return ColorBgra.FromBgra(230, 240, 250, 255);
  1136. }
  1137. }
  1138. public static ColorBgra Magenta
  1139. {
  1140. get
  1141. {
  1142. return ColorBgra.FromBgra(255, 0, 255, 255);
  1143. }
  1144. }
  1145. public static ColorBgra Maroon
  1146. {
  1147. get
  1148. {
  1149. return ColorBgra.FromBgra(0, 0, 128, 255);
  1150. }
  1151. }
  1152. public static ColorBgra MediumAquamarine
  1153. {
  1154. get
  1155. {
  1156. return ColorBgra.FromBgra(170, 205, 102, 255);
  1157. }
  1158. }
  1159. public static ColorBgra MediumBlue
  1160. {
  1161. get
  1162. {
  1163. return ColorBgra.FromBgra(205, 0, 0, 255);
  1164. }
  1165. }
  1166. public static ColorBgra MediumOrchid
  1167. {
  1168. get
  1169. {
  1170. return ColorBgra.FromBgra(211, 85, 186, 255);
  1171. }
  1172. }
  1173. public static ColorBgra MediumPurple
  1174. {
  1175. get
  1176. {
  1177. return ColorBgra.FromBgra(219, 112, 147, 255);
  1178. }
  1179. }
  1180. public static ColorBgra MediumSeaGreen
  1181. {
  1182. get
  1183. {
  1184. return ColorBgra.FromBgra(113, 179, 60, 255);
  1185. }
  1186. }
  1187. public static ColorBgra MediumSlateBlue
  1188. {
  1189. get
  1190. {
  1191. return ColorBgra.FromBgra(238, 104, 123, 255);
  1192. }
  1193. }
  1194. public static ColorBgra MediumSpringGreen
  1195. {
  1196. get
  1197. {
  1198. return ColorBgra.FromBgra(154, 250, 0, 255);
  1199. }
  1200. }
  1201. public static ColorBgra MediumTurquoise
  1202. {
  1203. get
  1204. {
  1205. return ColorBgra.FromBgra(204, 209, 72, 255);
  1206. }
  1207. }
  1208. public static ColorBgra MediumVioletRed
  1209. {
  1210. get
  1211. {
  1212. return ColorBgra.FromBgra(133, 21, 199, 255);
  1213. }
  1214. }
  1215. public static ColorBgra MidnightBlue
  1216. {
  1217. get
  1218. {
  1219. return ColorBgra.FromBgra(112, 25, 25, 255);
  1220. }
  1221. }
  1222. public static ColorBgra MintCream
  1223. {
  1224. get
  1225. {
  1226. return ColorBgra.FromBgra(250, 255, 245, 255);
  1227. }
  1228. }
  1229. public static ColorBgra MistyRose
  1230. {
  1231. get
  1232. {
  1233. return ColorBgra.FromBgra(225, 228, 255, 255);
  1234. }
  1235. }
  1236. public static ColorBgra Moccasin
  1237. {
  1238. get
  1239. {
  1240. return ColorBgra.FromBgra(181, 228, 255, 255);
  1241. }
  1242. }
  1243. public static ColorBgra NavajoWhite
  1244. {
  1245. get
  1246. {
  1247. return ColorBgra.FromBgra(173, 222, 255, 255);
  1248. }
  1249. }
  1250. public static ColorBgra Navy
  1251. {
  1252. get
  1253. {
  1254. return ColorBgra.FromBgra(128, 0, 0, 255);
  1255. }
  1256. }
  1257. public static ColorBgra OldLace
  1258. {
  1259. get
  1260. {
  1261. return ColorBgra.FromBgra(230, 245, 253, 255);
  1262. }
  1263. }
  1264. public static ColorBgra Olive
  1265. {
  1266. get
  1267. {
  1268. return ColorBgra.FromBgra(0, 128, 128, 255);
  1269. }
  1270. }
  1271. public static ColorBgra OliveDrab
  1272. {
  1273. get
  1274. {
  1275. return ColorBgra.FromBgra(35, 142, 107, 255);
  1276. }
  1277. }
  1278. public static ColorBgra Orange
  1279. {
  1280. get
  1281. {
  1282. return ColorBgra.FromBgra(0, 165, 255, 255);
  1283. }
  1284. }
  1285. public static ColorBgra OrangeRed
  1286. {
  1287. get
  1288. {
  1289. return ColorBgra.FromBgra(0, 69, 255, 255);
  1290. }
  1291. }
  1292. public static ColorBgra Orchid
  1293. {
  1294. get
  1295. {
  1296. return ColorBgra.FromBgra(214, 112, 218, 255);
  1297. }
  1298. }
  1299. public static ColorBgra PaleGoldenrod
  1300. {
  1301. get
  1302. {
  1303. return ColorBgra.FromBgra(170, 232, 238, 255);
  1304. }
  1305. }
  1306. public static ColorBgra PaleGreen
  1307. {
  1308. get
  1309. {
  1310. return ColorBgra.FromBgra(152, 251, 152, 255);
  1311. }
  1312. }
  1313. public static ColorBgra PaleTurquoise
  1314. {
  1315. get
  1316. {
  1317. return ColorBgra.FromBgra(238, 238, 175, 255);
  1318. }
  1319. }
  1320. public static ColorBgra PaleVioletRed
  1321. {
  1322. get
  1323. {
  1324. return ColorBgra.FromBgra(147, 112, 219, 255);
  1325. }
  1326. }
  1327. public static ColorBgra PapayaWhip
  1328. {
  1329. get
  1330. {
  1331. return ColorBgra.FromBgra(213, 239, 255, 255);
  1332. }
  1333. }
  1334. public static ColorBgra PeachPuff
  1335. {
  1336. get
  1337. {
  1338. return ColorBgra.FromBgra(185, 218, 255, 255);
  1339. }
  1340. }
  1341. public static ColorBgra Peru
  1342. {
  1343. get
  1344. {
  1345. return ColorBgra.FromBgra(63, 133, 205, 255);
  1346. }
  1347. }
  1348. public static ColorBgra Pink
  1349. {
  1350. get
  1351. {
  1352. return ColorBgra.FromBgra(203, 192, 255, 255);
  1353. }
  1354. }
  1355. public static ColorBgra Plum
  1356. {
  1357. get
  1358. {
  1359. return ColorBgra.FromBgra(221, 160, 221, 255);
  1360. }
  1361. }
  1362. public static ColorBgra PowderBlue
  1363. {
  1364. get
  1365. {
  1366. return ColorBgra.FromBgra(230, 224, 176, 255);
  1367. }
  1368. }
  1369. public static ColorBgra Purple
  1370. {
  1371. get
  1372. {
  1373. return ColorBgra.FromBgra(128, 0, 128, 255);
  1374. }
  1375. }
  1376. public static ColorBgra Red
  1377. {
  1378. get
  1379. {
  1380. return ColorBgra.FromBgra(0, 0, 255, 255);
  1381. }
  1382. }
  1383. public static ColorBgra RosyBrown
  1384. {
  1385. get
  1386. {
  1387. return ColorBgra.FromBgra(143, 143, 188, 255);
  1388. }
  1389. }
  1390. public static ColorBgra RoyalBlue
  1391. {
  1392. get
  1393. {
  1394. return ColorBgra.FromBgra(225, 105, 65, 255);
  1395. }
  1396. }
  1397. public static ColorBgra SaddleBrown
  1398. {
  1399. get
  1400. {
  1401. return ColorBgra.FromBgra(19, 69, 139, 255);
  1402. }
  1403. }
  1404. public static ColorBgra Salmon
  1405. {
  1406. get
  1407. {
  1408. return ColorBgra.FromBgra(114, 128, 250, 255);
  1409. }
  1410. }
  1411. public static ColorBgra SandyBrown
  1412. {
  1413. get
  1414. {
  1415. return ColorBgra.FromBgra(96, 164, 244, 255);
  1416. }
  1417. }
  1418. public static ColorBgra SeaGreen
  1419. {
  1420. get
  1421. {
  1422. return ColorBgra.FromBgra(87, 139, 46, 255);
  1423. }
  1424. }
  1425. public static ColorBgra SeaShell
  1426. {
  1427. get
  1428. {
  1429. return ColorBgra.FromBgra(238, 245, 255, 255);
  1430. }
  1431. }
  1432. public static ColorBgra Sienna
  1433. {
  1434. get
  1435. {
  1436. return ColorBgra.FromBgra(45, 82, 160, 255);
  1437. }
  1438. }
  1439. public static ColorBgra Silver
  1440. {
  1441. get
  1442. {
  1443. return ColorBgra.FromBgra(192, 192, 192, 255);
  1444. }
  1445. }
  1446. public static ColorBgra SkyBlue
  1447. {
  1448. get
  1449. {
  1450. return ColorBgra.FromBgra(235, 206, 135, 255);
  1451. }
  1452. }
  1453. public static ColorBgra SlateBlue
  1454. {
  1455. get
  1456. {
  1457. return ColorBgra.FromBgra(205, 90, 106, 255);
  1458. }
  1459. }
  1460. public static ColorBgra SlateGray
  1461. {
  1462. get
  1463. {
  1464. return ColorBgra.FromBgra(144, 128, 112, 255);
  1465. }
  1466. }
  1467. public static ColorBgra Snow
  1468. {
  1469. get
  1470. {
  1471. return ColorBgra.FromBgra(250, 250, 255, 255);
  1472. }
  1473. }
  1474. public static ColorBgra SpringGreen
  1475. {
  1476. get
  1477. {
  1478. return ColorBgra.FromBgra(127, 255, 0, 255);
  1479. }
  1480. }
  1481. public static ColorBgra SteelBlue
  1482. {
  1483. get
  1484. {
  1485. return ColorBgra.FromBgra(180, 130, 70, 255);
  1486. }
  1487. }
  1488. public static ColorBgra Tan
  1489. {
  1490. get
  1491. {
  1492. return ColorBgra.FromBgra(140, 180, 210, 255);
  1493. }
  1494. }
  1495. public static ColorBgra Teal
  1496. {
  1497. get
  1498. {
  1499. return ColorBgra.FromBgra(128, 128, 0, 255);
  1500. }
  1501. }
  1502. public static ColorBgra Thistle
  1503. {
  1504. get
  1505. {
  1506. return ColorBgra.FromBgra(216, 191, 216, 255);
  1507. }
  1508. }
  1509. public static ColorBgra Tomato
  1510. {
  1511. get
  1512. {
  1513. return ColorBgra.FromBgra(71, 99, 255, 255);
  1514. }
  1515. }
  1516. public static ColorBgra Turquoise
  1517. {
  1518. get
  1519. {
  1520. return ColorBgra.FromBgra(208, 224, 64, 255);
  1521. }
  1522. }
  1523. public static ColorBgra Violet
  1524. {
  1525. get
  1526. {
  1527. return ColorBgra.FromBgra(238, 130, 238, 255);
  1528. }
  1529. }
  1530. public static ColorBgra Wheat
  1531. {
  1532. get
  1533. {
  1534. return ColorBgra.FromBgra(179, 222, 245, 255);
  1535. }
  1536. }
  1537. public static ColorBgra White
  1538. {
  1539. get
  1540. {
  1541. return ColorBgra.FromBgra(255, 255, 255, 255);
  1542. }
  1543. }
  1544. public static ColorBgra WhiteSmoke
  1545. {
  1546. get
  1547. {
  1548. return ColorBgra.FromBgra(245, 245, 245, 255);
  1549. }
  1550. }
  1551. public static ColorBgra Yellow
  1552. {
  1553. get
  1554. {
  1555. return ColorBgra.FromBgra(0, 255, 255, 255);
  1556. }
  1557. }
  1558. public static ColorBgra YellowGreen
  1559. {
  1560. get
  1561. {
  1562. return ColorBgra.FromBgra(50, 205, 154, 255);
  1563. }
  1564. }
  1565. public static ColorBgra Zero
  1566. {
  1567. get
  1568. {
  1569. return (ColorBgra)0;
  1570. }
  1571. }
  1572. private static Dictionary<string, ColorBgra> predefinedColors;
  1573. /// <summary>
  1574. /// Gets a hashtable that contains a list of all the predefined colors.
  1575. /// These are the same color values that are defined as public static properties
  1576. /// in System.Drawing.Color. The hashtable uses strings for the keys, and
  1577. /// ColorBgras for the values.
  1578. /// </summary>
  1579. public static Dictionary<string, ColorBgra> PredefinedColors
  1580. {
  1581. get
  1582. {
  1583. if (predefinedColors != null)
  1584. {
  1585. Type colorBgraType = typeof(ColorBgra);
  1586. PropertyInfo[] propInfos = colorBgraType.GetProperties(BindingFlags.Static | BindingFlags.Public);
  1587. Hashtable colors = new Hashtable();
  1588. foreach (PropertyInfo pi in propInfos)
  1589. {
  1590. if (pi.PropertyType == colorBgraType)
  1591. {
  1592. colors.Add(pi.Name, (ColorBgra)pi.GetValue(null, null));
  1593. }
  1594. }
  1595. }
  1596. return new Dictionary<string, ColorBgra>(predefinedColors);
  1597. }
  1598. }
  1599. }
  1600. }