Created
January 7, 2022 15:30
-
-
Save cuteribs-1/76e072369b25bd6f85da588a3427c21b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
var folder = @"F:\git\blog\ugc\datacolor-spyderx"; | |
var files = new[] { | |
Path.Combine(folder, "xsmax.xml"), | |
Path.Combine(folder, "xsmax1.xml"), | |
}; | |
var file = files[0]; | |
var doc = new XmlDocument(); | |
doc.Load(file); | |
var accuracyNode = doc.SelectSingleNode("//coloraccuracy"); | |
var accuracy1 = new | |
{ | |
min = float.Parse(accuracyNode.SelectSingleNode("min").InnerText), | |
max = float.Parse(accuracyNode.SelectSingleNode("max").InnerText), | |
avg = float.Parse(accuracyNode.SelectSingleNode("avg").InnerText), | |
samples = accuracyNode | |
.SelectNodes("sample") | |
.OfType<XmlNode>() | |
.Select(n => new | |
{ | |
name = n.SelectSingleNode("name").InnerText, | |
oLab = n.SelectSingleNode("oLab").InnerText, | |
mLab = n.SelectSingleNode("mLab").InnerText, | |
deltaE = float.Parse(n.SelectSingleNode("deltaE").InnerText), | |
mRGB = n.SelectSingleNode("mRGB").InnerText | |
}).ToArray() | |
}; | |
file = files[1]; | |
doc.Load(file); | |
accuracyNode = doc.SelectSingleNode("//coloraccuracy"); | |
var accuracy2 = new | |
{ | |
min = float.Parse(accuracyNode.SelectSingleNode("min").InnerText), | |
max = float.Parse(accuracyNode.SelectSingleNode("max").InnerText), | |
avg = float.Parse(accuracyNode.SelectSingleNode("avg").InnerText), | |
samples = accuracyNode | |
.SelectNodes("sample") | |
.OfType<XmlNode>() | |
.Select(n => new | |
{ | |
name = n.SelectSingleNode("name").InnerText, | |
oLab = n.SelectSingleNode("oLab").InnerText, | |
mLab = n.SelectSingleNode("mLab").InnerText, | |
deltaE = float.Parse(n.SelectSingleNode("deltaE").InnerText), | |
mRGB = n.SelectSingleNode("mRGB").InnerText | |
}).ToArray() | |
}; | |
for(var i = 0; i < accuracy1.samples.Length; i++) { | |
if(accuracy1.samples[i].deltaE > accuracy2.samples[i].deltaE) { | |
accuracy1.samples[i] = accuracy2.samples[i]; | |
} | |
} | |
var accuracy = new | |
{ | |
min = accuracy1.samples.Min(s => s.deltaE), | |
max = accuracy1.samples.Max(s => s.deltaE), | |
avg = accuracy1.samples.Average(s => s.deltaE), | |
samples = accuracy1.samples | |
}; | |
accuracy.Dump(); | |
var node = new XElement("coloraccuracy", | |
new XElement("min", accuracy.min), | |
new XElement("max", accuracy.max), | |
new XElement("avg", accuracy.avg), | |
accuracy.samples.Select(s => new XElement("sample", | |
new XElement("name", s.name), | |
new XElement("oLab", s.oLab), | |
new XElement("mLab", s.mLab), | |
new XElement("deltaE", s.deltaE), | |
new XElement("mRGB", s.mRGB) | |
)) | |
); | |
node.Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment