diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 7eaef89d57..8c7f70131d 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T 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 - int r = aColor.Red(); - int g = aColor.Green(); - int b = aColor.Blue(); +EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB ) +{ + EDA_COLOR_T candidate = BLACK; /* 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 @@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) { const StructColors &c = g_ColorRefs[trying]; - int distance = (r - c.m_Red) * (r - c.m_Red) + - (g - c.m_Green) * (g - c.m_Green) + - (b - c.m_Blue) * (b - c.m_Blue); - if( distance < nearest_distance && c.m_Red >= r && - c.m_Green >= g && c.m_Blue >= b ) + int distance = (aR - c.m_Red) * (aR - c.m_Red) + + (aG - c.m_Green) * (aG - c.m_Green) + + (aB - c.m_Blue) * (aB - c.m_Blue); + if( distance < nearest_distance && c.m_Red >= aR && + c.m_Green >= aG && c.m_Blue >= aB ) { nearest_distance = distance; candidate = trying; diff --git a/include/colors.h b/include/colors.h index 7074b68abb..4cca37efa9 100644 --- a/include/colors.h +++ b/include/colors.h @@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName ); /// Find the nearest color match 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 * white on it