12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Reflection;
- using System.Runtime.InteropServices;
- namespace PaintDotNet
- {
- /// <summary>
- /// This is our pixel format that we will work with. It is always 32-bits / 4-bytes and is
- /// always laid out in BGRA order.
- /// Generally used with the Surface class.
- /// </summary>
- [Serializable]
- [StructLayout(LayoutKind.Explicit)]
- public struct ColorBgra
- {
- [FieldOffset(0)]
- public byte B;
- [FieldOffset(1)]
- public byte G;
- [FieldOffset(2)]
- public byte R;
- [FieldOffset(3)]
- public byte A;
- /// <summary>
- /// Lets you change B, G, R, and A at the same time.
- /// </summary>
- [NonSerialized]
- [FieldOffset(0)]
- public uint Bgra;
- public const int BlueChannel = 0;
- public const int GreenChannel = 1;
- public const int RedChannel = 2;
- public const int AlphaChannel = 3;
- public const int SizeOf = 4;
- public static ColorBgra ParseHexString(string hexString)
- {
- uint value = Convert.ToUInt32(hexString, 16);
- return ColorBgra.FromUInt32(value);
- }
- public string ToHexString()
- {
- int rgbNumber = (this.R << 16) | (this.G << 8) | this.B;
- string colorString = Convert.ToString(rgbNumber, 16);
- while (colorString.Length < 6)
- {
- colorString = "0" + colorString;
- }
- string alphaString = System.Convert.ToString(this.A, 16);
- while (alphaString.Length < 2)
- {
- alphaString = "0" + alphaString;
- }
- colorString = alphaString + colorString;
- return colorString.ToUpper();
- }
- /// <summary>
- /// Gets or sets the byte value of the specified color channel.
- /// </summary>
- public unsafe byte this[int channel]
- {
- get
- {
- if (channel < 0 || channel > 3)
- {
- throw new ArgumentOutOfRangeException("channel", channel, "valid range is [0,3]");
- }
- fixed (byte* p = &B)
- {
- return p[channel];
- }
- }
- set
- {
- if (channel < 0 || channel > 3)
- {
- throw new ArgumentOutOfRangeException("channel", channel, "valid range is [0,3]");
- }
- fixed (byte* p = &B)
- {
- p[channel] = value;
- }
- }
- }
- /// <summary>
- /// Gets the luminance intensity of the pixel based on the values of the red, green, and blue components. Alpha is ignored.
- /// </summary>
- /// <returns>A value in the range 0 to 1 inclusive.</returns>
- public double GetIntensity()
- {
- return ((0.114 * (double)B) + (0.587 * (double)G) + (0.299 * (double)R)) / 255.0;
- }
- /// <summary>
- /// Gets the luminance intensity of the pixel based on the values of the red, green, and blue components. Alpha is ignored.
- /// </summary>
- /// <returns>A value in the range 0 to 255 inclusive.</returns>
- public byte GetIntensityByte()
- {
- return (byte)((7471 * B + 38470 * G + 19595 * R) >> 16);
- }
- /// <summary>
- /// Returns the maximum value out of the B, G, and R values. Alpha is ignored.
- /// </summary>
- /// <returns></returns>
- public byte GetMaxColorChannelValue()
- {
- return Math.Max(this.B, Math.Max(this.G, this.R));
- }
- /// <summary>
- /// Returns the average of the B, G, and R values. Alpha is ignored.
- /// </summary>
- /// <returns></returns>
- public byte GetAverageColorChannelValue()
- {
- return (byte)((this.B + this.G + this.R) / 3);
- }
- /// <summary>
- /// Compares two ColorBgra instance to determine if they are equal.
- /// </summary>
- public static bool operator ==(ColorBgra lhs, ColorBgra rhs)
- {
- return lhs.Bgra == rhs.Bgra;
- }
- /// <summary>
- /// Compares two ColorBgra instance to determine if they are not equal.
- /// </summary>
- public static bool operator !=(ColorBgra lhs, ColorBgra rhs)
- {
- return lhs.Bgra != rhs.Bgra;
- }
- /// <summary>
- /// Compares two ColorBgra instance to determine if they are equal.
- /// </summary>
- public override bool Equals(object obj)
- {
- if (obj != null && obj is ColorBgra && ((ColorBgra)obj).Bgra == this.Bgra)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// Returns a hash code for this color value.
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- unchecked
- {
- return (int)Bgra;
- }
- }
- /// <summary>
- /// Gets the equivalent GDI+ PixelFormat.
- /// </summary>
- /// <remarks>
- /// This property always returns PixelFormat.Format32bppArgb.
- /// </remarks>
- public static PixelFormat PixelFormat
- {
- get
- {
- return PixelFormat.Format32bppArgb;
- }
- }
- /// <summary>
- /// Returns a new ColorBgra with the same color values but with a new alpha component value.
- /// </summary>
- public ColorBgra NewAlpha(byte newA)
- {
- return ColorBgra.FromBgra(B, G, R, newA);
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color and alpha values.
- /// </summary>
- [Obsolete("Use FromBgra() instead (make sure to swap the order of your b and r parameters)")]
- public static ColorBgra FromRgba(byte r, byte g, byte b, byte a)
- {
- return FromBgra(b, g, r, a);
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color values, and 255 for alpha.
- /// </summary>
- [Obsolete("Use FromBgr() instead (make sure to swap the order of your b and r parameters)")]
- public static ColorBgra FromRgb(byte r, byte g, byte b)
- {
- return FromBgr(b, g, r);
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color and alpha values.
- /// </summary>
- public static ColorBgra FromBgra(byte b, byte g, byte r, byte a)
- {
- ColorBgra color = new ColorBgra();
- color.Bgra = BgraToUInt32(b, g, r, a);
- return color;
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color and alpha values.
- /// </summary>
- public static ColorBgra FromBgraClamped(int b, int g, int r, int a)
- {
- return FromBgra(
- Utility.ClampToByte(b),
- Utility.ClampToByte(g),
- Utility.ClampToByte(r),
- Utility.ClampToByte(a));
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color and alpha values.
- /// </summary>
- public static ColorBgra FromBgraClamped(float b, float g, float r, float a)
- {
- return FromBgra(
- Utility.ClampToByte(b),
- Utility.ClampToByte(g),
- Utility.ClampToByte(r),
- Utility.ClampToByte(a));
- }
- /// <summary>
- /// Packs color and alpha values into a 32-bit integer.
- /// </summary>
- public static UInt32 BgraToUInt32(byte b, byte g, byte r, byte a)
- {
- return (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24);
- }
- /// <summary>
- /// Packs color and alpha values into a 32-bit integer.
- /// </summary>
- public static UInt32 BgraToUInt32(int b, int g, int r, int a)
- {
- return (uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24);
- }
- /// <summary>
- /// Creates a new ColorBgra instance with the given color values, and 255 for alpha.
- /// </summary>
- public static ColorBgra FromBgr(byte b, byte g, byte r)
- {
- return FromBgra(b, g, r, 255);
- }
- /// <summary>
- /// Constructs a new ColorBgra instance with the given 32-bit value.
- /// </summary>
- public static ColorBgra FromUInt32(UInt32 bgra)
- {
- ColorBgra color = new ColorBgra();
- color.Bgra = bgra;
- return color;
- }
- /// <summary>
- /// Constructs a new ColorBgra instance given a 32-bit signed integer that represents an R,G,B triple.
- /// Alpha will be initialized to 255.
- /// </summary>
- public static ColorBgra FromOpaqueInt32(Int32 bgr)
- {
- if (bgr < 0 || bgr > 0xffffff)
- {
- throw new ArgumentOutOfRangeException("bgr", "must be in the range [0, 0xffffff]");
- }
- ColorBgra color = new ColorBgra();
- color.Bgra = (uint)bgr;
- color.A = 255;
- return color;
- }
- public static int ToOpaqueInt32(ColorBgra color)
- {
- if (color.A != 255)
- {
- throw new InvalidOperationException("Alpha value must be 255 for this to work");
- }
- return (int)(color.Bgra & 0xffffff);
- }
- /// <summary>
- /// Constructs a new ColorBgra instance from the values in the given Color instance.
- /// </summary>
- public static ColorBgra FromColor(Color c)
- {
- return FromBgra(c.B, c.G, c.R, c.A);
- }
- /// <summary>
- /// Converts this ColorBgra instance to a Color instance.
- /// </summary>
- public Color ToColor()
- {
- return Color.FromArgb(A, R, G, B);
- }
- /// <summary>
- /// Smoothly blends between two colors.
- /// </summary>
- public static ColorBgra Blend(ColorBgra ca, ColorBgra cb, byte cbAlpha)
- {
- uint caA = (uint)Utility.FastScaleByteByByte((byte)(255 - cbAlpha), ca.A);
- uint cbA = (uint)Utility.FastScaleByteByByte(cbAlpha, cb.A);
- uint cbAT = caA + cbA;
- uint r;
- uint g;
- uint b;
- if (cbAT == 0)
- {
- r = 0;
- g = 0;
- b = 0;
- }
- else
- {
- r = ((ca.R * caA) + (cb.R * cbA)) / cbAT;
- g = ((ca.G * caA) + (cb.G * cbA)) / cbAT;
- b = ((ca.B * caA) + (cb.B * cbA)) / cbAT;
- }
- return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)cbAT);
- }
- /// <summary>
- /// Linearly interpolates between two color values.
- /// </summary>
- /// <param name="from">The color value that represents 0 on the lerp number line.</param>
- /// <param name="to">The color value that represents 1 on the lerp number line.</param>
- /// <param name="frac">A value in the range [0, 1].</param>
- /// <remarks>
- /// This method does a simple lerp on each color value and on the alpha channel. It does
- /// not properly take into account the alpha channel's effect on color blending.
- /// </remarks>
- public static ColorBgra Lerp(ColorBgra from, ColorBgra to, float frac)
- {
- ColorBgra ret = new ColorBgra();
- ret.B = (byte)Utility.ClampToByte(Utility.Lerp(from.B, to.B, frac));
- ret.G = (byte)Utility.ClampToByte(Utility.Lerp(from.G, to.G, frac));
- ret.R = (byte)Utility.ClampToByte(Utility.Lerp(from.R, to.R, frac));
- ret.A = (byte)Utility.ClampToByte(Utility.Lerp(from.A, to.A, frac));
- return ret;
- }
- /// <summary>
- /// Linearly interpolates between two color values.
- /// </summary>
- /// <param name="from">The color value that represents 0 on the lerp number line.</param>
- /// <param name="to">The color value that represents 1 on the lerp number line.</param>
- /// <param name="frac">A value in the range [0, 1].</param>
- /// <remarks>
- /// This method does a simple lerp on each color value and on the alpha channel. It does
- /// not properly take into account the alpha channel's effect on color blending.
- /// </remarks>
- public static ColorBgra Lerp(ColorBgra from, ColorBgra to, double frac)
- {
- ColorBgra ret = new ColorBgra();
- ret.B = (byte)Utility.ClampToByte(Utility.Lerp(from.B, to.B, frac));
- ret.G = (byte)Utility.ClampToByte(Utility.Lerp(from.G, to.G, frac));
- ret.R = (byte)Utility.ClampToByte(Utility.Lerp(from.R, to.R, frac));
- ret.A = (byte)Utility.ClampToByte(Utility.Lerp(from.A, to.A, frac));
- return ret;
- }
- /// <summary>
- /// Blends four colors together based on the given weight values.
- /// </summary>
- /// <returns>The blended color.</returns>
- /// <remarks>
- /// The weights should be 16-bit fixed point numbers that add up to 65536 ("1.0").
- /// 4W16IP means "4 colors, weights, 16-bit integer precision"
- /// </remarks>
- public static ColorBgra BlendColors4W16IP(ColorBgra c1, uint w1, ColorBgra c2, uint w2, ColorBgra c3, uint w3, ColorBgra c4, uint w4)
- {
- #if DEBUG
- /*
- if ((w1 + w2 + w3 + w4) != 65536)
- {
- throw new ArgumentOutOfRangeException("w1 + w2 + w3 + w4 must equal 65536!");
- }
- * */
- #endif
- const uint ww = 32768;
- uint af = (c1.A * w1) + (c2.A * w2) + (c3.A * w3) + (c4.A * w4);
- uint a = (af + ww) >> 16;
- uint b;
- uint g;
- uint r;
- if (a == 0)
- {
- b = 0;
- g = 0;
- r = 0;
- }
- else
- {
- 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);
- 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);
- 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);
- }
- return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
- }
- /// <summary>
- /// Blends the colors based on the given weight values.
- /// </summary>
- /// <param name="c">The array of color values.</param>
- /// <param name="w">The array of weight values.</param>
- /// <returns>
- /// The weights should be fixed point numbers.
- /// The total summation of the weight values will be treated as "1.0".
- /// Each color will be blended in proportionally to its weight value respective to
- /// the total summation of the weight values.
- /// </returns>
- /// <remarks>
- /// "WAIP" stands for "weights, arbitrary integer precision"</remarks>
- public static ColorBgra BlendColorsWAIP(ColorBgra[] c, uint[] w)
- {
- if (c.Length != w.Length)
- {
- throw new ArgumentException("c.Length != w.Length");
- }
- if (c.Length == 0)
- {
- return ColorBgra.FromUInt32(0);
- }
- long wsum = 0;
- long asum = 0;
- for (int i = 0; i < w.Length; ++i)
- {
- wsum += w[i];
- asum += c[i].A * w[i];
- }
- uint a = (uint)((asum + (wsum >> 1)) / wsum);
- long b;
- long g;
- long r;
- if (a == 0)
- {
- b = 0;
- g = 0;
- r = 0;
- }
- else
- {
- b = 0;
- g = 0;
- r = 0;
- for (int i = 0; i < c.Length; ++i)
- {
- b += (long)c[i].A * c[i].B * w[i];
- g += (long)c[i].A * c[i].G * w[i];
- r += (long)c[i].A * c[i].R * w[i];
- }
- b /= asum;
- g /= asum;
- r /= asum;
- }
- return ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24));
- }
- /// <summary>
- /// Blends the colors based on the given weight values.
- /// </summary>
- /// <param name="c">The array of color values.</param>
- /// <param name="w">The array of weight values.</param>
- /// <returns>
- /// Each color will be blended in proportionally to its weight value respective to
- /// the total summation of the weight values.
- /// </returns>
- /// <remarks>
- /// "WAIP" stands for "weights, floating-point"</remarks>
- public static ColorBgra BlendColorsWFP(ColorBgra[] c, double[] w)
- {
- if (c.Length != w.Length)
- {
- throw new ArgumentException("c.Length != w.Length");
- }
- if (c.Length == 0)
- {
- return ColorBgra.Transparent;
- }
- double wsum = 0;
- double asum = 0;
- for (int i = 0; i < w.Length; ++i)
- {
- wsum += w[i];
- asum += (double)c[i].A * w[i];
- }
- double a = asum / wsum;
- double aMultWsum = a * wsum;
- double b;
- double g;
- double r;
- if (asum == 0)
- {
- b = 0;
- g = 0;
- r = 0;
- }
- else
- {
- b = 0;
- g = 0;
- r = 0;
- for (int i = 0; i < c.Length; ++i)
- {
- b += (double)c[i].A * c[i].B * w[i];
- g += (double)c[i].A * c[i].G * w[i];
- r += (double)c[i].A * c[i].R * w[i];
- }
- b /= aMultWsum;
- g /= aMultWsum;
- r /= aMultWsum;
- }
- return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
- }
- public static ColorBgra Blend(ColorBgra[] colors)
- {
- unsafe
- {
- fixed (ColorBgra* pColors = colors)
- {
- return Blend(pColors, colors.Length);
- }
- }
- }
- /// <summary>
- /// Smoothly blends the given colors together, assuming equal weighting for each one.
- /// </summary>
- /// <param name="colors"></param>
- /// <param name="colorCount"></param>
- /// <returns></returns>
- public unsafe static ColorBgra Blend(ColorBgra* colors, int count)
- {
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("count must be 0 or greater");
- }
- if (count == 0)
- {
- return ColorBgra.Transparent;
- }
- ulong aSum = 0;
- for (int i = 0; i < count; ++i)
- {
- aSum += (ulong)colors[i].A;
- }
- byte b = 0;
- byte g = 0;
- byte r = 0;
- byte a = (byte)(aSum / (ulong)count);
- if (aSum != 0)
- {
- ulong bSum = 0;
- ulong gSum = 0;
- ulong rSum = 0;
- for (int i = 0; i < count; ++i)
- {
- bSum += (ulong)(colors[i].A * colors[i].B);
- gSum += (ulong)(colors[i].A * colors[i].G);
- rSum += (ulong)(colors[i].A * colors[i].R);
- }
- b = (byte)(bSum / aSum);
- g = (byte)(gSum / aSum);
- r = (byte)(rSum / aSum);
- }
- return ColorBgra.FromBgra(b, g, r, a);
- }
- public override string ToString()
- {
- return "B: " + B + ", G: " + G + ", R: " + R + ", A: " + A;
- }
- /// <summary>
- /// Casts a ColorBgra to a UInt32.
- /// </summary>
- public static explicit operator UInt32(ColorBgra color)
- {
- return color.Bgra;
- }
- /// <summary>
- /// Casts a UInt32 to a ColorBgra.
- /// </summary>
- public static explicit operator ColorBgra(UInt32 uint32)
- {
- return ColorBgra.FromUInt32(uint32);
- }
- // Colors: copied from System.Drawing.Color's list (don't worry I didn't type it in
- // manually, I used a code generator w/ reflection ...)
- public static ColorBgra Transparent
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 255, 0);
- }
- }
- public static ColorBgra AliceBlue
- {
- get
- {
- return ColorBgra.FromBgra(255, 248, 240, 255);
- }
- }
- public static ColorBgra AntiqueWhite
- {
- get
- {
- return ColorBgra.FromBgra(215, 235, 250, 255);
- }
- }
- public static ColorBgra Aqua
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 0, 255);
- }
- }
- public static ColorBgra Aquamarine
- {
- get
- {
- return ColorBgra.FromBgra(212, 255, 127, 255);
- }
- }
- public static ColorBgra Azure
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 240, 255);
- }
- }
- public static ColorBgra Beige
- {
- get
- {
- return ColorBgra.FromBgra(220, 245, 245, 255);
- }
- }
- public static ColorBgra Bisque
- {
- get
- {
- return ColorBgra.FromBgra(196, 228, 255, 255);
- }
- }
- public static ColorBgra Black
- {
- get
- {
- return ColorBgra.FromBgra(0, 0, 0, 255);
- }
- }
- public static ColorBgra BlanchedAlmond
- {
- get
- {
- return ColorBgra.FromBgra(205, 235, 255, 255);
- }
- }
- public static ColorBgra Blue
- {
- get
- {
- return ColorBgra.FromBgra(255, 0, 0, 255);
- }
- }
- public static ColorBgra BlueViolet
- {
- get
- {
- return ColorBgra.FromBgra(226, 43, 138, 255);
- }
- }
- public static ColorBgra Brown
- {
- get
- {
- return ColorBgra.FromBgra(42, 42, 165, 255);
- }
- }
- public static ColorBgra BurlyWood
- {
- get
- {
- return ColorBgra.FromBgra(135, 184, 222, 255);
- }
- }
- public static ColorBgra CadetBlue
- {
- get
- {
- return ColorBgra.FromBgra(160, 158, 95, 255);
- }
- }
- public static ColorBgra Chartreuse
- {
- get
- {
- return ColorBgra.FromBgra(0, 255, 127, 255);
- }
- }
- public static ColorBgra Chocolate
- {
- get
- {
- return ColorBgra.FromBgra(30, 105, 210, 255);
- }
- }
- public static ColorBgra Coral
- {
- get
- {
- return ColorBgra.FromBgra(80, 127, 255, 255);
- }
- }
- public static ColorBgra CornflowerBlue
- {
- get
- {
- return ColorBgra.FromBgra(237, 149, 100, 255);
- }
- }
- public static ColorBgra Cornsilk
- {
- get
- {
- return ColorBgra.FromBgra(220, 248, 255, 255);
- }
- }
- public static ColorBgra Crimson
- {
- get
- {
- return ColorBgra.FromBgra(60, 20, 220, 255);
- }
- }
- public static ColorBgra Cyan
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 0, 255);
- }
- }
- public static ColorBgra DarkBlue
- {
- get
- {
- return ColorBgra.FromBgra(139, 0, 0, 255);
- }
- }
- public static ColorBgra DarkCyan
- {
- get
- {
- return ColorBgra.FromBgra(139, 139, 0, 255);
- }
- }
- public static ColorBgra DarkGoldenrod
- {
- get
- {
- return ColorBgra.FromBgra(11, 134, 184, 255);
- }
- }
- public static ColorBgra DarkGray
- {
- get
- {
- return ColorBgra.FromBgra(169, 169, 169, 255);
- }
- }
- public static ColorBgra DarkGreen
- {
- get
- {
- return ColorBgra.FromBgra(0, 100, 0, 255);
- }
- }
- public static ColorBgra DarkKhaki
- {
- get
- {
- return ColorBgra.FromBgra(107, 183, 189, 255);
- }
- }
- public static ColorBgra DarkMagenta
- {
- get
- {
- return ColorBgra.FromBgra(139, 0, 139, 255);
- }
- }
- public static ColorBgra DarkOliveGreen
- {
- get
- {
- return ColorBgra.FromBgra(47, 107, 85, 255);
- }
- }
- public static ColorBgra DarkOrange
- {
- get
- {
- return ColorBgra.FromBgra(0, 140, 255, 255);
- }
- }
- public static ColorBgra DarkOrchid
- {
- get
- {
- return ColorBgra.FromBgra(204, 50, 153, 255);
- }
- }
- public static ColorBgra DarkRed
- {
- get
- {
- return ColorBgra.FromBgra(0, 0, 139, 255);
- }
- }
- public static ColorBgra DarkSalmon
- {
- get
- {
- return ColorBgra.FromBgra(122, 150, 233, 255);
- }
- }
- public static ColorBgra DarkSeaGreen
- {
- get
- {
- return ColorBgra.FromBgra(139, 188, 143, 255);
- }
- }
- public static ColorBgra DarkSlateBlue
- {
- get
- {
- return ColorBgra.FromBgra(139, 61, 72, 255);
- }
- }
- public static ColorBgra DarkSlateGray
- {
- get
- {
- return ColorBgra.FromBgra(79, 79, 47, 255);
- }
- }
- public static ColorBgra DarkTurquoise
- {
- get
- {
- return ColorBgra.FromBgra(209, 206, 0, 255);
- }
- }
- public static ColorBgra DarkViolet
- {
- get
- {
- return ColorBgra.FromBgra(211, 0, 148, 255);
- }
- }
- public static ColorBgra DeepPink
- {
- get
- {
- return ColorBgra.FromBgra(147, 20, 255, 255);
- }
- }
- public static ColorBgra DeepSkyBlue
- {
- get
- {
- return ColorBgra.FromBgra(255, 191, 0, 255);
- }
- }
- public static ColorBgra DimGray
- {
- get
- {
- return ColorBgra.FromBgra(105, 105, 105, 255);
- }
- }
- public static ColorBgra DodgerBlue
- {
- get
- {
- return ColorBgra.FromBgra(255, 144, 30, 255);
- }
- }
- public static ColorBgra Firebrick
- {
- get
- {
- return ColorBgra.FromBgra(34, 34, 178, 255);
- }
- }
- public static ColorBgra FloralWhite
- {
- get
- {
- return ColorBgra.FromBgra(240, 250, 255, 255);
- }
- }
- public static ColorBgra ForestGreen
- {
- get
- {
- return ColorBgra.FromBgra(34, 139, 34, 255);
- }
- }
- public static ColorBgra Fuchsia
- {
- get
- {
- return ColorBgra.FromBgra(255, 0, 255, 255);
- }
- }
- public static ColorBgra Gainsboro
- {
- get
- {
- return ColorBgra.FromBgra(220, 220, 220, 255);
- }
- }
- public static ColorBgra GhostWhite
- {
- get
- {
- return ColorBgra.FromBgra(255, 248, 248, 255);
- }
- }
- public static ColorBgra Gold
- {
- get
- {
- return ColorBgra.FromBgra(0, 215, 255, 255);
- }
- }
- public static ColorBgra Goldenrod
- {
- get
- {
- return ColorBgra.FromBgra(32, 165, 218, 255);
- }
- }
- public static ColorBgra Gray
- {
- get
- {
- return ColorBgra.FromBgra(128, 128, 128, 255);
- }
- }
- public static ColorBgra Green
- {
- get
- {
- return ColorBgra.FromBgra(0, 128, 0, 255);
- }
- }
- public static ColorBgra GreenYellow
- {
- get
- {
- return ColorBgra.FromBgra(47, 255, 173, 255);
- }
- }
- public static ColorBgra Honeydew
- {
- get
- {
- return ColorBgra.FromBgra(240, 255, 240, 255);
- }
- }
- public static ColorBgra HotPink
- {
- get
- {
- return ColorBgra.FromBgra(180, 105, 255, 255);
- }
- }
- public static ColorBgra IndianRed
- {
- get
- {
- return ColorBgra.FromBgra(92, 92, 205, 255);
- }
- }
- public static ColorBgra Indigo
- {
- get
- {
- return ColorBgra.FromBgra(130, 0, 75, 255);
- }
- }
- public static ColorBgra Ivory
- {
- get
- {
- return ColorBgra.FromBgra(240, 255, 255, 255);
- }
- }
- public static ColorBgra Khaki
- {
- get
- {
- return ColorBgra.FromBgra(140, 230, 240, 255);
- }
- }
- public static ColorBgra Lavender
- {
- get
- {
- return ColorBgra.FromBgra(250, 230, 230, 255);
- }
- }
- public static ColorBgra LavenderBlush
- {
- get
- {
- return ColorBgra.FromBgra(245, 240, 255, 255);
- }
- }
- public static ColorBgra LawnGreen
- {
- get
- {
- return ColorBgra.FromBgra(0, 252, 124, 255);
- }
- }
- public static ColorBgra LemonChiffon
- {
- get
- {
- return ColorBgra.FromBgra(205, 250, 255, 255);
- }
- }
- public static ColorBgra LightBlue
- {
- get
- {
- return ColorBgra.FromBgra(230, 216, 173, 255);
- }
- }
- public static ColorBgra LightCoral
- {
- get
- {
- return ColorBgra.FromBgra(128, 128, 240, 255);
- }
- }
- public static ColorBgra LightCyan
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 224, 255);
- }
- }
- public static ColorBgra LightGoldenrodYellow
- {
- get
- {
- return ColorBgra.FromBgra(210, 250, 250, 255);
- }
- }
- public static ColorBgra LightGreen
- {
- get
- {
- return ColorBgra.FromBgra(144, 238, 144, 255);
- }
- }
- public static ColorBgra LightGray
- {
- get
- {
- return ColorBgra.FromBgra(211, 211, 211, 255);
- }
- }
- public static ColorBgra LightPink
- {
- get
- {
- return ColorBgra.FromBgra(193, 182, 255, 255);
- }
- }
- public static ColorBgra LightSalmon
- {
- get
- {
- return ColorBgra.FromBgra(122, 160, 255, 255);
- }
- }
- public static ColorBgra LightSeaGreen
- {
- get
- {
- return ColorBgra.FromBgra(170, 178, 32, 255);
- }
- }
- public static ColorBgra LightSkyBlue
- {
- get
- {
- return ColorBgra.FromBgra(250, 206, 135, 255);
- }
- }
- public static ColorBgra LightSlateGray
- {
- get
- {
- return ColorBgra.FromBgra(153, 136, 119, 255);
- }
- }
- public static ColorBgra LightSteelBlue
- {
- get
- {
- return ColorBgra.FromBgra(222, 196, 176, 255);
- }
- }
- public static ColorBgra LightYellow
- {
- get
- {
- return ColorBgra.FromBgra(224, 255, 255, 255);
- }
- }
- public static ColorBgra Lime
- {
- get
- {
- return ColorBgra.FromBgra(0, 255, 0, 255);
- }
- }
- public static ColorBgra LimeGreen
- {
- get
- {
- return ColorBgra.FromBgra(50, 205, 50, 255);
- }
- }
- public static ColorBgra Linen
- {
- get
- {
- return ColorBgra.FromBgra(230, 240, 250, 255);
- }
- }
- public static ColorBgra Magenta
- {
- get
- {
- return ColorBgra.FromBgra(255, 0, 255, 255);
- }
- }
- public static ColorBgra Maroon
- {
- get
- {
- return ColorBgra.FromBgra(0, 0, 128, 255);
- }
- }
- public static ColorBgra MediumAquamarine
- {
- get
- {
- return ColorBgra.FromBgra(170, 205, 102, 255);
- }
- }
- public static ColorBgra MediumBlue
- {
- get
- {
- return ColorBgra.FromBgra(205, 0, 0, 255);
- }
- }
- public static ColorBgra MediumOrchid
- {
- get
- {
- return ColorBgra.FromBgra(211, 85, 186, 255);
- }
- }
- public static ColorBgra MediumPurple
- {
- get
- {
- return ColorBgra.FromBgra(219, 112, 147, 255);
- }
- }
- public static ColorBgra MediumSeaGreen
- {
- get
- {
- return ColorBgra.FromBgra(113, 179, 60, 255);
- }
- }
- public static ColorBgra MediumSlateBlue
- {
- get
- {
- return ColorBgra.FromBgra(238, 104, 123, 255);
- }
- }
- public static ColorBgra MediumSpringGreen
- {
- get
- {
- return ColorBgra.FromBgra(154, 250, 0, 255);
- }
- }
- public static ColorBgra MediumTurquoise
- {
- get
- {
- return ColorBgra.FromBgra(204, 209, 72, 255);
- }
- }
- public static ColorBgra MediumVioletRed
- {
- get
- {
- return ColorBgra.FromBgra(133, 21, 199, 255);
- }
- }
- public static ColorBgra MidnightBlue
- {
- get
- {
- return ColorBgra.FromBgra(112, 25, 25, 255);
- }
- }
- public static ColorBgra MintCream
- {
- get
- {
- return ColorBgra.FromBgra(250, 255, 245, 255);
- }
- }
- public static ColorBgra MistyRose
- {
- get
- {
- return ColorBgra.FromBgra(225, 228, 255, 255);
- }
- }
- public static ColorBgra Moccasin
- {
- get
- {
- return ColorBgra.FromBgra(181, 228, 255, 255);
- }
- }
- public static ColorBgra NavajoWhite
- {
- get
- {
- return ColorBgra.FromBgra(173, 222, 255, 255);
- }
- }
- public static ColorBgra Navy
- {
- get
- {
- return ColorBgra.FromBgra(128, 0, 0, 255);
- }
- }
- public static ColorBgra OldLace
- {
- get
- {
- return ColorBgra.FromBgra(230, 245, 253, 255);
- }
- }
- public static ColorBgra Olive
- {
- get
- {
- return ColorBgra.FromBgra(0, 128, 128, 255);
- }
- }
- public static ColorBgra OliveDrab
- {
- get
- {
- return ColorBgra.FromBgra(35, 142, 107, 255);
- }
- }
- public static ColorBgra Orange
- {
- get
- {
- return ColorBgra.FromBgra(0, 165, 255, 255);
- }
- }
- public static ColorBgra OrangeRed
- {
- get
- {
- return ColorBgra.FromBgra(0, 69, 255, 255);
- }
- }
- public static ColorBgra Orchid
- {
- get
- {
- return ColorBgra.FromBgra(214, 112, 218, 255);
- }
- }
- public static ColorBgra PaleGoldenrod
- {
- get
- {
- return ColorBgra.FromBgra(170, 232, 238, 255);
- }
- }
- public static ColorBgra PaleGreen
- {
- get
- {
- return ColorBgra.FromBgra(152, 251, 152, 255);
- }
- }
- public static ColorBgra PaleTurquoise
- {
- get
- {
- return ColorBgra.FromBgra(238, 238, 175, 255);
- }
- }
- public static ColorBgra PaleVioletRed
- {
- get
- {
- return ColorBgra.FromBgra(147, 112, 219, 255);
- }
- }
- public static ColorBgra PapayaWhip
- {
- get
- {
- return ColorBgra.FromBgra(213, 239, 255, 255);
- }
- }
- public static ColorBgra PeachPuff
- {
- get
- {
- return ColorBgra.FromBgra(185, 218, 255, 255);
- }
- }
- public static ColorBgra Peru
- {
- get
- {
- return ColorBgra.FromBgra(63, 133, 205, 255);
- }
- }
- public static ColorBgra Pink
- {
- get
- {
- return ColorBgra.FromBgra(203, 192, 255, 255);
- }
- }
- public static ColorBgra Plum
- {
- get
- {
- return ColorBgra.FromBgra(221, 160, 221, 255);
- }
- }
- public static ColorBgra PowderBlue
- {
- get
- {
- return ColorBgra.FromBgra(230, 224, 176, 255);
- }
- }
- public static ColorBgra Purple
- {
- get
- {
- return ColorBgra.FromBgra(128, 0, 128, 255);
- }
- }
- public static ColorBgra Red
- {
- get
- {
- return ColorBgra.FromBgra(0, 0, 255, 255);
- }
- }
- public static ColorBgra RosyBrown
- {
- get
- {
- return ColorBgra.FromBgra(143, 143, 188, 255);
- }
- }
- public static ColorBgra RoyalBlue
- {
- get
- {
- return ColorBgra.FromBgra(225, 105, 65, 255);
- }
- }
- public static ColorBgra SaddleBrown
- {
- get
- {
- return ColorBgra.FromBgra(19, 69, 139, 255);
- }
- }
- public static ColorBgra Salmon
- {
- get
- {
- return ColorBgra.FromBgra(114, 128, 250, 255);
- }
- }
- public static ColorBgra SandyBrown
- {
- get
- {
- return ColorBgra.FromBgra(96, 164, 244, 255);
- }
- }
- public static ColorBgra SeaGreen
- {
- get
- {
- return ColorBgra.FromBgra(87, 139, 46, 255);
- }
- }
- public static ColorBgra SeaShell
- {
- get
- {
- return ColorBgra.FromBgra(238, 245, 255, 255);
- }
- }
- public static ColorBgra Sienna
- {
- get
- {
- return ColorBgra.FromBgra(45, 82, 160, 255);
- }
- }
- public static ColorBgra Silver
- {
- get
- {
- return ColorBgra.FromBgra(192, 192, 192, 255);
- }
- }
- public static ColorBgra SkyBlue
- {
- get
- {
- return ColorBgra.FromBgra(235, 206, 135, 255);
- }
- }
- public static ColorBgra SlateBlue
- {
- get
- {
- return ColorBgra.FromBgra(205, 90, 106, 255);
- }
- }
- public static ColorBgra SlateGray
- {
- get
- {
- return ColorBgra.FromBgra(144, 128, 112, 255);
- }
- }
- public static ColorBgra Snow
- {
- get
- {
- return ColorBgra.FromBgra(250, 250, 255, 255);
- }
- }
- public static ColorBgra SpringGreen
- {
- get
- {
- return ColorBgra.FromBgra(127, 255, 0, 255);
- }
- }
- public static ColorBgra SteelBlue
- {
- get
- {
- return ColorBgra.FromBgra(180, 130, 70, 255);
- }
- }
- public static ColorBgra Tan
- {
- get
- {
- return ColorBgra.FromBgra(140, 180, 210, 255);
- }
- }
- public static ColorBgra Teal
- {
- get
- {
- return ColorBgra.FromBgra(128, 128, 0, 255);
- }
- }
- public static ColorBgra Thistle
- {
- get
- {
- return ColorBgra.FromBgra(216, 191, 216, 255);
- }
- }
- public static ColorBgra Tomato
- {
- get
- {
- return ColorBgra.FromBgra(71, 99, 255, 255);
- }
- }
- public static ColorBgra Turquoise
- {
- get
- {
- return ColorBgra.FromBgra(208, 224, 64, 255);
- }
- }
- public static ColorBgra Violet
- {
- get
- {
- return ColorBgra.FromBgra(238, 130, 238, 255);
- }
- }
- public static ColorBgra Wheat
- {
- get
- {
- return ColorBgra.FromBgra(179, 222, 245, 255);
- }
- }
- public static ColorBgra White
- {
- get
- {
- return ColorBgra.FromBgra(255, 255, 255, 255);
- }
- }
- public static ColorBgra WhiteSmoke
- {
- get
- {
- return ColorBgra.FromBgra(245, 245, 245, 255);
- }
- }
- public static ColorBgra Yellow
- {
- get
- {
- return ColorBgra.FromBgra(0, 255, 255, 255);
- }
- }
- public static ColorBgra YellowGreen
- {
- get
- {
- return ColorBgra.FromBgra(50, 205, 154, 255);
- }
- }
- public static ColorBgra Zero
- {
- get
- {
- return (ColorBgra)0;
- }
- }
- private static Dictionary<string, ColorBgra> predefinedColors;
- /// <summary>
- /// Gets a hashtable that contains a list of all the predefined colors.
- /// These are the same color values that are defined as public static properties
- /// in System.Drawing.Color. The hashtable uses strings for the keys, and
- /// ColorBgras for the values.
- /// </summary>
- public static Dictionary<string, ColorBgra> PredefinedColors
- {
- get
- {
- if (predefinedColors != null)
- {
- Type colorBgraType = typeof(ColorBgra);
- PropertyInfo[] propInfos = colorBgraType.GetProperties(BindingFlags.Static | BindingFlags.Public);
- Hashtable colors = new Hashtable();
- foreach (PropertyInfo pi in propInfos)
- {
- if (pi.PropertyType == colorBgraType)
- {
- colors.Add(pi.Name, (ColorBgra)pi.GetValue(null, null));
- }
- }
- }
- return new Dictionary<string, ColorBgra>(predefinedColors);
- }
- }
- }
- }
|