public Block[] FindBestMatch( RgbColor color )
{
if( color.A < TransparencyThreshold*255 ) {
return transparent;
}
LabColor pixelColor = RgbToLab( color, true );
double closestDistance = double.MaxValue;
Block[] bestMatch = null;
foreach( var pair in palette ) {
double distance = ColorDifference( pixelColor, pair.Key );
if( distance < closestDistance ) {
bestMatch = pair.Value;
closestDistance = distance;
}
}
if( bestMatch == null ) {
throw new Exception( "Could not find match: palette is empty!" );
}
return bestMatch;
}