private void GetMap(Dictionary <T, byte>[] maps, ProductColorTable colorTable) { foreach (ProductColor c in colorTable.ProductColors) { maps[0].Add(Float2T(c.MinValue), c.Color.R); maps[1].Add(Float2T(c.MinValue), c.Color.G); maps[2].Add(Float2T(c.MinValue), c.Color.B); } }
private static ProductColorTable[] XmlToColorTables(IEnumerable <XElement> eles) { List <ProductColorTable> tables = new List <ProductColorTable>(); ProductColorTable table = null; foreach (XElement ele in eles) { table = XmlToColorTable(ele); if (table != null) { tables.Add(table); } } return(tables == null ? null : tables.ToArray()); }
private static XElement ToXElement(ProductColorTable colorTable) { if (colorTable == null) { return(null); } XElement[] eleColors = ColorsToXElements(colorTable.ProductColors); XElement ele = new XElement("ProductColorTable", new XAttribute("identify", colorTable.Identify), new XAttribute("subIdentify", colorTable.SubIdentify), new XAttribute("colortablename", colorTable.ColorTableName), new XAttribute("description", colorTable.Description), new XAttribute("labeltext", colorTable.LabelText), new XElement("Colors", eleColors) ); return(ele); }
public static object[] GetStretcher <T>(ProductColorTable colorTable) { Type type = typeof(T); if (type.Equals(typeof(byte))) { return((new ColorTable2RgbStretcherByte()).GetStretcher(colorTable)); } else if (type.Equals(typeof(Int16))) { return((new ColorTable2RgbStretcherInt16()).GetStretcher(colorTable)); } else if (type.Equals(typeof(UInt16))) { return((new ColorTable2RgbStretcherUInt16()).GetStretcher(colorTable)); } else if (type.Equals(typeof(Int32))) { return((new ColorTable2RgbStretcherInt32()).GetStretcher(colorTable)); } else if (type.Equals(typeof(UInt32))) { return((new ColorTable2RgbStretcherUInt32()).GetStretcher(colorTable)); } else if (type.Equals(typeof(Int64))) { return((new ColorTable2RgbStretcherInt64()).GetStretcher(colorTable)); } else if (type.Equals(typeof(UInt64))) { return((new ColorTable2RgbStretcherUInt64()).GetStretcher(colorTable)); } else if (type.Equals(typeof(float))) { return((new ColorTable2RgbStretcherFloat()).GetStretcher(colorTable)); } else if (type.Equals(typeof(double))) { return((new ColorTable2RgbStretcherDouble()).GetStretcher(colorTable)); } return(null); }
public object[] GetStretcher(ProductColorTable colorTable) { if (colorTable == null) { return(null); } Dictionary <T, byte>[] map = new Dictionary <T, byte>[3] { new Dictionary <T, byte>(), new Dictionary <T, byte>(), new Dictionary <T, byte>() }; GetMap(map, colorTable); Func <T, byte>[] sts = new Func <T, byte>[] { GetStretcherFunc(map[0], colorTable), GetStretcherFunc(map[1], colorTable), GetStretcherFunc(map[2], colorTable) }; return(sts.ToArray().Cast <object>().ToArray()); }
private Func <T, byte> GetStretcherFunc(Dictionary <T, byte> map, ProductColorTable colorTable) { if (colorTable.ProductColors == null || colorTable.ProductColors.Length == 0) { return(null); } return((v) => { int count = colorTable.ProductColors.Length; ProductColor[] pc = colorTable.ProductColors; byte[] values = map.Values.ToArray(); for (int i = 0; i < count; i++) { if (pc[i].IsContains(T2Float(v))) { return values[i]; } } return 0; }); }
private static ProductColorTable XmlToColorTable(XElement ele) { if (ele == null) { return(null); } IEnumerable <XAttribute> atts = ele.Attributes(); if (atts == null || atts.Count() == 0) { return(null); } string identify = null; string subIdentify = null; string description = null; string colortablename = null; string labeltext = null; ProductColorTable table = null; foreach (XAttribute att in atts) { switch (att.Name.ToString().ToLower()) { case "identify": if (!String.IsNullOrEmpty(att.Value)) { identify = att.Value; } break; case "subidentify": if (!String.IsNullOrEmpty(att.Value)) { subIdentify = att.Value; } break; case "description": if (!String.IsNullOrEmpty(att.Value)) { description = att.Value; } break; case "colortablename": if (!String.IsNullOrEmpty(att.Value)) { colortablename = att.Value; } break; case "labeltext": labeltext = att.Value; break; } } if (identify == null || subIdentify == null) { return(null); } table = new ProductColorTable(identify, subIdentify, colortablename, labeltext); table.Description = description; table.ProductColors = XmlToProductColors(ele); return(table); }