本文整理汇总了C++中COLOR4D::ToHSV方法的典型用法代码示例。如果您正苦于以下问题:C++ COLOR4D::ToHSV方法的具体用法?C++ COLOR4D::ToHSV怎么用?C++ COLOR4D::ToHSV使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COLOR4D
的用法示例。
在下文中一共展示了COLOR4D::ToHSV方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ColorFindNearest
EDA_COLOR_T COLOR4D::GetNearestLegacyColor( const COLOR4D &aColor )
{
// Cache layer implemented here, because all callers are using wxColour
static std::map< unsigned int, unsigned int > nearestCache;
static double hues[NBCOLORS];
static double values[NBCOLORS];
unsigned int colorInt = aColor.ToU32();
auto search = nearestCache.find( colorInt );
if( search != nearestCache.end() )
return static_cast<EDA_COLOR_T>( search->second );
// First use ColorFindNearest to check for exact matches
EDA_COLOR_T nearest = ColorFindNearest( aColor.r * 255.0, aColor.g * 255.0, aColor.b * 255.0 );
if( COLOR4D( nearest ) == aColor )
{
nearestCache.insert( std::pair< unsigned int, unsigned int >(
colorInt, static_cast<unsigned int>( nearest ) ) );
return nearest;
}
// If not, use hue and value to match.
// Hue will be NAN for grayscale colors.
// The legacy color palette is a grid across hue and value.
// We can exploit that to find a good match -- hue is most apparent to the user.
// So, first we determine the closest hue match, and then the closest value from that
// "grid row" in the legacy palette.
double h, s, v;
aColor.ToHSV( h, s, v );
double minDist = 360.0;
double legacyHue = 0.0;
if( std::isnan( h ) )
{
legacyHue = NAN;
}
else
{
for( EDA_COLOR_T candidate = ::BLACK;
candidate < NBCOLORS; candidate = NextColor( candidate ) )
{
double ch;
if( hues[candidate] == 0.0 && values[candidate] == 0.0 )
{
COLOR4D candidate4d( candidate );
double cs, cv;
candidate4d.ToHSV( ch, cs, cv );
values[candidate] = cv;
// Set the hue to non-zero for black so that we won't do this more than once
hues[candidate] = ( cv == 0.0 ) ? 1.0 : ch;
}
else
{
ch = hues[candidate];
}
if( fabs( ch - h ) < minDist )
{
minDist = fabs( ch - h );
legacyHue = ch;
}
}
}
// Now we have the desired hue; let's find the nearest value
minDist = 1.0;
for( EDA_COLOR_T candidate = ::BLACK;
candidate < NBCOLORS; candidate = NextColor( candidate ) )
{
// If the target hue is NAN, we didn't extract the value for any colors above
if( std::isnan( legacyHue ) )
{
double ch, cs, cv;
COLOR4D candidate4d( candidate );
candidate4d.ToHSV( ch, cs, cv );
values[candidate] = cv;
hues[candidate] = ( cv == 0.0 ) ? 1.0 : ch;
}
if( ( std::isnan( legacyHue ) != std::isnan( hues[candidate] ) ) || hues[candidate] != legacyHue )
continue;
if( fabs( values[candidate] - v ) < minDist )
{
minDist = fabs( values[candidate] - v );
nearest = candidate;
}
}
nearestCache.insert( std::pair< unsigned int, unsigned int >(
colorInt, static_cast<unsigned int>( nearest ) ) );
//.........这里部分代码省略.........