static void GenPng(double[,] dumpArray, Pallet pallet, string outPngPath) { Bitmap outPng = new Bitmap(dumpArray.GetLength(0), dumpArray.GetLength(1)); for (int x = 0; x < outPng.Width; x++) { for (int y = 0; y < outPng.Height; y++) { double dumpVal = dumpArray[x, y]; outPng.SetPixel(x, y, pallet.undefinedvalue.color); if (dumpVal == pallet.invalidvalue.value) { outPng.SetPixel(x, y, pallet.invalidvalue.color); } else if (dumpVal == pallet.notrequiredvalue.value) { outPng.SetPixel(x, y, pallet.notrequiredvalue.color); } else if (dumpVal == pallet.underthresholdvalue.value) { outPng.SetPixel(x, y, pallet.underthresholdvalue.color); } else if (dumpVal < pallet.seqfloatassociation.Min(fa => fa.lowerbound) || dumpVal >= pallet.seqfloatassociation.Max(fa => fa.upperbound)) { outPng.SetPixel(x, y, pallet.notrequiredvalue.color); } else { foreach (ColorFloatIntervalAssociation cfia in pallet.seqfloatassociation) { if (dumpVal >= cfia.lowerbound && dumpVal < cfia.upperbound) { outPng.SetPixel(x, y, cfia.color); } } } } } outPng = ImageUtils.CreateIndexedPng(outPng); outPng.Save(outPngPath, System.Drawing.Imaging.ImageFormat.Png); }
static Pallet ReadPal(string filepath, string qualifname, string qualifunit) { XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlNode node = doc.DocumentElement.SelectSingleNode(string.Format("/root/pallet[qualifname=\"{0}\"][qualifunit=\"{1}\"]", qualifname, qualifunit)); Pallet pallet = new Pallet(); pallet.qualifname = node.SelectSingleNode("qualifname").InnerText; pallet.qualifunit = node.SelectSingleNode("qualifunit").InnerText; pallet.undefinedvalue = ParseNodeToColorIntAssociation(node.SelectSingleNode("undefinedvalue")); pallet.invalidvalue = ParseNodeToColorIntAssociation(node.SelectSingleNode("invalidvalue")); pallet.notrequiredvalue = ParseNodeToColorIntAssociation(node.SelectSingleNode("notrequiredvalue")); pallet.underthresholdvalue = ParseNodeToColorIntAssociation(node.SelectSingleNode("underthresholdvalue")); foreach (XmlNode n in node.SelectNodes("seqfloatassociation/floatassociation")) { pallet.seqfloatassociation.Add(ParseNodeToColorFloatIntervalAssociation(n)); } return(pallet); }
static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); string dumpFilepath = @"dump.dmp"; string palletFilepath = @"volcano_def.RES.vpf"; string qualifname = "received_power"; string qualifunit = "db_mw"; string outPngPath = @"out.png"; for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { switch (args[i]) { case "-d": dumpFilepath = args[i + 1]; break; case "-p": palletFilepath = args[i + 1]; break; case "-qn": qualifname = args[i + 1]; break; case "-qu": qualifunit = args[i + 1]; break; case "-o": outPngPath = args[i + 1]; break; case "-h": Help(); Environment.Exit(0); break; default: Console.WriteLine("Unknown argument " + args[i]); break; } } } if (!File.Exists(dumpFilepath) && dumpFilepath != "dump.dmp") { Console.WriteLine("ERROR : File not found dumpFilepath " + dumpFilepath); Help(); Environment.Exit(-1); } else if (!File.Exists(palletFilepath)) { Console.WriteLine("ERROR : File not found palletFilepath " + palletFilepath); Help(); Environment.Exit(-1); } //Read dump double[,] dumpArray = ReadDump(dumpFilepath); //Read Palette Pallet pallet = ReadPal(palletFilepath, qualifname, qualifunit); //Gen Png GenPng(dumpArray, pallet, outPngPath); }