public static List <ColorDescriptor> ParseColorDescriptorRaws(List <RawToken> tokenList) { List <ColorDescriptor> colorList = new List <ColorDescriptor>(); ColorDescriptor tempColor = new ColorDescriptor(); if (tokenList[0].Token != "OBJECT" || tokenList[0][0] != "DESCRIPTOR_COLOR") { throw new FormatException("Not a color descriptor raw."); } foreach (var token in tokenList) { switch (token.Token) { case "COLOR": tempColor = new ColorDescriptor(); tempColor.Token = token[0]; colorList.Add(tempColor); break; case "NAME": tempColor.Name = token[0]; break; case "RGB": tempColor.RGB = Color.FromArgb(byte.Parse(token[0]), byte.Parse(token[1]), byte.Parse(token[2])); break; default: break; } } return(colorList); }
public int CompareTo(object obj) { if (!(obj is ColorDescriptor)) { return(1); } ColorDescriptor other = (ColorDescriptor)obj; if (RGB.GetSaturation() < 0.01f && other.RGB.GetSaturation() < 0.01f) { return(RGB.GetBrightness().CompareTo(other.RGB.GetBrightness())); } if (RGB.GetSaturation() < 0.01f && other.RGB.GetSaturation() >= 0.01f) { return(-1); } if (RGB.GetSaturation() >= 0.01f && other.RGB.GetSaturation() < 0.01f) { return(1); } var h = RGB.GetHue().CompareTo(other.RGB.GetHue()); if (h != 0) { return(h); } var v = RGB.GetBrightness().CompareTo(other.RGB.GetBrightness()); if (v != 0) { return(v); } return(RGB.GetSaturation().CompareTo(other.RGB.GetSaturation())); }