Commit cd568483 authored by Maciej Suminski's avatar Maciej Suminski

Added one more function to convert colors.

parent 7d4aed10
...@@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T aColor ) ...@@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T aColor )
EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
{ {
EDA_COLOR_T candidate = BLACK; return ColorFindNearest( aColor.Red(), aColor.Green(), aColor.Blue() );
}
// These are ints because we will subtract them later EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB )
int r = aColor.Red(); {
int g = aColor.Green(); EDA_COLOR_T candidate = BLACK;
int b = aColor.Blue();
/* Find the 'nearest' color in the palette. This is fun. There is /* Find the 'nearest' color in the palette. This is fun. There is
a gazilion of metrics for the color space and no one of the a gazilion of metrics for the color space and no one of the
...@@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) ...@@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) )
{ {
const StructColors &c = g_ColorRefs[trying]; const StructColors &c = g_ColorRefs[trying];
int distance = (r - c.m_Red) * (r - c.m_Red) + int distance = (aR - c.m_Red) * (aR - c.m_Red) +
(g - c.m_Green) * (g - c.m_Green) + (aG - c.m_Green) * (aG - c.m_Green) +
(b - c.m_Blue) * (b - c.m_Blue); (aB - c.m_Blue) * (aB - c.m_Blue);
if( distance < nearest_distance && c.m_Red >= r && if( distance < nearest_distance && c.m_Red >= aR &&
c.m_Green >= g && c.m_Blue >= b ) c.m_Green >= aG && c.m_Blue >= aB )
{ {
nearest_distance = distance; nearest_distance = distance;
candidate = trying; candidate = trying;
......
...@@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName ); ...@@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName );
/// Find the nearest color match /// Find the nearest color match
EDA_COLOR_T ColorFindNearest( const wxColour &aColor ); EDA_COLOR_T ColorFindNearest( const wxColour &aColor );
/**
* Find the nearest color match
* @param aR is the red component of the color to be matched (in range 0-255)
* @param aG is the green component of the color to be matched (in range 0-255)
* @param aG is the blue component of the color to be matched (in range 0-255)
*/
EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB );
/** /**
* Check if a color is light i.e. if black would be more readable than * Check if a color is light i.e. if black would be more readable than
* white on it * white on it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment