KiCad PCB EDA Suite
KIGFX::COLOR4D Class Reference

A color representation with 4 components: red, green, blue, alpha. More...

#include <color4d.h>

Public Member Functions

 COLOR4D ()
 
constexpr COLOR4D (double aRed, double aGreen, double aBlue, double aAlpha)
 
 COLOR4D (EDA_COLOR_T aColor)
 
COLOR4DFromCSSRGBA (int aRed, int aGreen, int aBlue, double aAlpha=1.0)
 Initialize the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha. More...
 
void ToHSL (double &aOutHue, double &aOutSaturation, double &aOutValue) const
 Converts current color (stored in RGB) to HSL format. More...
 
void FromHSL (double aInHue, double aInSaturation, double aInLightness)
 Change currently used color to the one given by hue, saturation and lightness parameters. More...
 
COLOR4DBrighten (double aFactor)
 Makes the color brighter by a given factor. More...
 
COLOR4DDarken (double aFactor)
 Makes the color darker by a given factor. More...
 
COLOR4DInvert ()
 Makes the color inverted, alpha remains the same. More...
 
COLOR4DSaturate (double aFactor)
 Saturates the color to a given factor (in HSV model) More...
 
COLOR4D Brightened (double aFactor) const
 Return a color that is brighter by a given factor, without modifying object. More...
 
COLOR4D Darkened (double aFactor) const
 Return a color that is darker by a given factor, without modifying object. More...
 
COLOR4D Mix (const COLOR4D &aColor, double aFactor) const
 Return a color that is mixed with the input by a factor. More...
 
COLOR4D WithAlpha (double aAlpha) const
 Return a color with the same color, but the given alpha. More...
 
COLOR4D Inverted () const
 Returns an inverted color, alpha remains the same. More...
 
double GetBrightness () const
 Returns the brightness value of the color ranged from 0.0 to 1.0. More...
 
void ToHSV (double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
 Convert current color (stored in RGB) to HSV format. More...
 
void FromHSV (double aInH, double aInS, double aInV)
 Changes currently used color to the one given by hue, saturation and value parameters. More...
 

Static Public Member Functions

static EDA_COLOR_T FindNearestLegacyColor (int aR, int aG, int aB)
 Returns a legacy color ID that is closest to the given 8-bit RGB values. More...
 

Public Attributes

double r
 Red component. More...
 
double g
 Green component. More...
 
double b
 Blue component. More...
 
double a
 Alpha component. More...
 

Static Public Attributes

static const COLOR4D UNSPECIFIED
 For legacy support; used as a value to indicate color hasn't been set yet. More...
 
static const COLOR4D WHITE
 
static const COLOR4D BLACK
 
static const COLOR4D CLEAR
 

Detailed Description

A color representation with 4 components: red, green, blue, alpha.

Definition at line 103 of file color4d.h.

Constructor & Destructor Documentation

◆ COLOR4D() [1/3]

KIGFX::COLOR4D::COLOR4D ( )
inline

Definition at line 107 of file color4d.h.

107  :
108  r( 0 ), g( 0 ), b( 0 ), a( 1.0 )
109  {
110  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

Referenced by Brightened(), Darkened(), Inverted(), Mix(), and WithAlpha().

◆ COLOR4D() [2/3]

constexpr KIGFX::COLOR4D::COLOR4D ( double  aRed,
double  aGreen,
double  aBlue,
double  aAlpha 
)
inline
Parameters
aRedis the red component [0.0 .. 1.0].
aGreenis the green component [0.0 .. 1.0].
aBlueis the blue component [0.0 .. 1.0].
aAlphais the alpha value [0.0 .. 1.0].

Definition at line 118 of file color4d.h.

118  :
119  r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha )
120  {
121  assert( r >= 0.0 && r <= 1.0 );
122  assert( g >= 0.0 && g <= 1.0 );
123  assert( b >= 0.0 && b <= 1.0 );
124  assert( a >= 0.0 && a <= 1.0 );
125  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, g, and r.

◆ COLOR4D() [3/3]

COLOR4D::COLOR4D ( EDA_COLOR_T  aColor)
Parameters
aColoris one of KiCad's palette colors.
See also
EDA_COLOR_T

Definition at line 81 of file color4d.cpp.

82 {
83  if( aColor <= UNSPECIFIED_COLOR || aColor >= NBCOLORS )
84  {
85  *this = COLOR4D::UNSPECIFIED;
86  return;
87  }
88 
89  int candidate = 0;
90 
91  for( ; candidate < NBCOLORS; ++candidate )
92  {
93  if( colorRefs()[candidate].m_Numcolor == aColor )
94  break;
95  }
96 
97  if( candidate >= NBCOLORS )
98  {
99  *this = COLOR4D::UNSPECIFIED;
100  return;
101  }
102 
103  r = colorRefs()[candidate].m_Red / 255.0;
104  g = colorRefs()[candidate].m_Green / 255.0;
105  b = colorRefs()[candidate].m_Blue / 255.0;
106  a = 1.0;
107 }
unsigned char m_Red
Definition: color4d.h:88
unsigned char m_Green
Definition: color4d.h:87
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
Number of colors.
Definition: color4d.h:79
double a
Alpha component.
Definition: color4d.h:366
unsigned char m_Blue
Definition: color4d.h:86
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
Definition: color4d.cpp:37
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:369
double r
Red component.
Definition: color4d.h:363

References a, b, colorRefs(), g, StructColors::m_Blue, StructColors::m_Green, StructColors::m_Red, NBCOLORS, r, and UNSPECIFIED.

Member Function Documentation

◆ Brighten()

COLOR4D& KIGFX::COLOR4D::Brighten ( double  aFactor)
inline

Makes the color brighter by a given factor.

Parameters
aFactorSpecifies how bright the color should become (valid values: 0.0 .. 1.0).
Returns
COLOR4D& Brightened color.

Definition at line 209 of file color4d.h.

210  {
211  assert( aFactor >= 0.0 && aFactor <= 1.0 );
212 
213  r = r * ( 1.0 - aFactor ) + aFactor;
214  g = g * ( 1.0 - aFactor ) + aFactor;
215  b = b * ( 1.0 - aFactor ) + aFactor;
216 
217  return *this;
218  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by KIGFX::PCB_RENDER_SETTINGS::GetColor().

◆ Brightened()

COLOR4D KIGFX::COLOR4D::Brightened ( double  aFactor) const
inline

Return a color that is brighter by a given factor, without modifying object.

Parameters
aFactorSpecifies how bright the color should become (valid values: 0.0 .. 1.0).
Returns
COLOR4D Highlighted color.

Definition at line 262 of file color4d.h.

263  {
264  assert( aFactor >= 0.0 && aFactor <= 1.0 );
265 
266  return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor,
267  b * ( 1.0 - aFactor ) + aFactor, a );
268  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, COLOR4D(), g, and r.

Referenced by KIGFX::DS_RENDER_SETTINGS::DS_RENDER_SETTINGS(), KIGFX::GERBVIEW_RENDER_SETTINGS::LoadColors(), COLOR_SWATCH::MakeBitmap(), and KIGFX::RENDER_SETTINGS::update().

◆ Darken()

COLOR4D& KIGFX::COLOR4D::Darken ( double  aFactor)
inline

Makes the color darker by a given factor.

Parameters
aFactorSpecifies how dark the color should become (valid values: 0.0 .. 1.0).
Returns
COLOR4D& Darkened color.

Definition at line 226 of file color4d.h.

227  {
228  assert( aFactor >= 0.0 && aFactor <= 1.0 );
229 
230  r = r * ( 1.0 - aFactor );
231  g = g * ( 1.0 - aFactor );
232  b = b * ( 1.0 - aFactor );
233 
234  return *this;
235  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by KIGFX::PCB_RENDER_SETTINGS::GetColor().

◆ Darkened()

COLOR4D KIGFX::COLOR4D::Darkened ( double  aFactor) const
inline

Return a color that is darker by a given factor, without modifying object.

Parameters
aFactorSpecifies how dark the color should become (valid values: 0.0 .. 1.0).
Returns
COLOR4D Darkened color.

Definition at line 276 of file color4d.h.

277  {
278  assert( aFactor >= 0.0 && aFactor <= 1.0 );
279 
280  return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), a );
281  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, COLOR4D(), g, and r.

Referenced by KIGFX::GERBVIEW_RENDER_SETTINGS::LoadColors(), COLOR_SWATCH::MakeBitmap(), KIGFX::RENDER_SETTINGS::update(), and EDIT_POINTS::ViewDraw().

◆ FindNearestLegacyColor()

EDA_COLOR_T COLOR4D::FindNearestLegacyColor ( int  aR,
int  aG,
int  aB 
)
static

Returns a legacy color ID that is closest to the given 8-bit RGB values.

Definition at line 459 of file color4d.cpp.

460 {
461  EDA_COLOR_T candidate = EDA_COLOR_T::BLACK;
462 
463  /* Find the 'nearest' color in the palette. This is fun. There is
464  a gazilion of metrics for the color space and no one of the
465  useful one is in the RGB color space. Who cares, this is a CAD,
466  not a photosomething...
467 
468  I hereby declare that the distance is the sum of the square of the
469  component difference. Think about the RGB color cube. Now get the
470  euclidean distance, but without the square root... for ordering
471  purposes it's the same, obviously. Also each component can't be
472  less of the target one, since I found this currently work better...
473  */
474  int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this
475 
476  for( EDA_COLOR_T trying = EDA_COLOR_T::BLACK; trying < EDA_COLOR_T::NBCOLORS;
477  trying = static_cast<EDA_COLOR_T>( int( trying ) + 1 ) )
478  {
479  const StructColors &c = colorRefs()[trying];
480  int distance = (aR - c.m_Red) * (aR - c.m_Red) +
481  (aG - c.m_Green) * (aG - c.m_Green) +
482  (aB - c.m_Blue) * (aB - c.m_Blue);
483 
484  if( distance < nearest_distance && c.m_Red >= aR &&
485  c.m_Green >= aG && c.m_Blue >= aB )
486  {
487  nearest_distance = distance;
488  candidate = trying;
489  }
490  }
491 
492  return candidate;
493 }
unsigned char m_Red
Definition: color4d.h:88
unsigned char m_Green
Definition: color4d.h:87
Definition: color4d.h:44
Number of colors.
Definition: color4d.h:79
unsigned char m_Blue
Definition: color4d.h:86
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
Definition: color4d.cpp:37
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
EDA_COLOR_T
Legacy color enumeration.
Definition: color4d.h:41

References BLACK, colorRefs(), distance(), StructColors::m_Blue, StructColors::m_Green, StructColors::m_Red, and NBCOLORS.

◆ FromCSSRGBA()

COLOR4D & COLOR4D::FromCSSRGBA ( int  aRed,
int  aGreen,
int  aBlue,
double  aAlpha = 1.0 
)

Initialize the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha.

Suitable for taking the values directly from the "CSS syntax" from ToWxString.

Returns
this color.

Definition at line 495 of file color4d.cpp.

496 {
497  r = std::max( 0, std::min( 255, aRed ) ) / 255.0;
498  g = std::max( 0, std::min( 255, aGreen ) ) / 255.0;
499  b = std::max( 0, std::min( 255, aBlue ) ) / 255.0;
500  a = std::max( 0.0, std::min( 1.0, aAlpha ) );
501 
502  return *this;
503 }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, g, and r.

Referenced by GetColorFromInt().

◆ FromHSL()

void COLOR4D::FromHSL ( double  aInHue,
double  aInSaturation,
double  aInLightness 
)

Change currently used color to the one given by hue, saturation and lightness parameters.

Parameters
aInHueis hue component, in degrees (0.0 - 360.0).
aInSaturationis saturation component (0.0 - 1.0).
aInLightnessis lightness component (0.0 - 1.0).

Definition at line 271 of file color4d.cpp.

272 {
273  const auto P = ( 1.0 - std::abs( 2.0 * aInLightness - 1.0 ) ) * aInSaturation;
274  const auto scaled_hue = aInHue / 60.0;
275  const auto Q = P * ( 1.0 - std::abs( std::fmod( scaled_hue, 2.0 ) - 1.0 ) );
276 
277  r = g = b = aInLightness - P / 2.0;
278 
279  if (scaled_hue < 1.0)
280  {
281  r += P;
282  g += Q;
283  }
284  else if (scaled_hue < 2.0)
285  {
286  r += Q;
287  g += P;
288  }
289  else if (scaled_hue < 3.0)
290  {
291  g += P;
292  b += Q;
293  }
294  else if (scaled_hue < 4.0)
295  {
296  g += Q;
297  b += P;
298  }
299  else if (scaled_hue < 5.0)
300  {
301  r += Q;
302  b += P;
303  }
304  else
305  {
306  r += P;
307  b += Q;
308  }
309 }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by BOOST_AUTO_TEST_CASE().

◆ FromHSV()

void COLOR4D::FromHSV ( double  aInH,
double  aInS,
double  aInV 
)

Changes currently used color to the one given by hue, saturation and value parameters.

Parameters
aInHis hue component, in degrees.
aInSis saturation component.
aInVis value component.

Definition at line 365 of file color4d.cpp.

366 {
367  if( aInS <= 0.0 )
368  {
369  r = aInV;
370  g = aInV;
371  b = aInV;
372  return;
373  }
374 
375  double hh = aInH;
376 
377  while( hh >= 360.0 )
378  hh -= 360.0;
379 
380  /* Hue in degrees (0...360) is coded according to this table
381  * 0 or 360 : red
382  * 60 : yellow
383  * 120 : green
384  * 180 : cyan
385  * 240 : blue
386  * 300 : magenta
387  */
388  hh /= 60.0;
389 
390  int i = (int) hh;
391  double ff = hh - i;
392 
393  double p = aInV * ( 1.0 - aInS );
394  double q = aInV * ( 1.0 - ( aInS * ff ) );
395  double t = aInV * ( 1.0 - ( aInS * ( 1.0 - ff ) ) );
396 
397  switch( i )
398  {
399  case 0:
400  r = aInV;
401  g = t;
402  b = p;
403  break;
404 
405  case 1:
406  r = q;
407  g = aInV;
408  b = p;
409  break;
410 
411  case 2:
412  r = p;
413  g = aInV;
414  b = t;
415  break;
416 
417  case 3:
418  r = p;
419  g = q;
420  b = aInV;
421  break;
422 
423  case 4:
424  r = t;
425  g = p;
426  b = aInV;
427  break;
428 
429  case 5:
430  default:
431  r = aInV;
432  g = p;
433  b = q;
434  break;
435  }
436 }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_COLOR_PICKER::OnChangeBrightness(), DIALOG_COLOR_PICKER::OnChangeEditHue(), DIALOG_COLOR_PICKER::OnChangeEditSat(), Saturate(), and DIALOG_COLOR_PICKER::setHSvaluesFromCursor().

◆ GetBrightness()

double KIGFX::COLOR4D::GetBrightness ( ) const
inline

Returns the brightness value of the color ranged from 0.0 to 1.0.

Returns
The brightness value.

Definition at line 327 of file color4d.h.

328  {
329  // Weighted W3C formula
330  return r * 0.299 + g * 0.587 + b * 0.117;
331  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by KIGFX::PREVIEW::GetShadowColor(), GRHaloText(), KIGFX::DS_RENDER_SETTINGS::IsBackgroundDark(), KIGFX::SCH_RENDER_SETTINGS::IsBackgroundDark(), KIGFX::PCB_RENDER_SETTINGS::IsBackgroundDark(), and COLOR_SWATCH::MakeBitmap().

◆ Invert()

COLOR4D& KIGFX::COLOR4D::Invert ( )
inline

Makes the color inverted, alpha remains the same.

Returns
COLOR4D& Inverted color.

Definition at line 242 of file color4d.h.

243  {
244  r = ( 1.0 - r );
245  g = ( 1.0 - g );
246  b = ( 1.0 - b );
247 
248  return *this;
249  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

◆ Inverted()

COLOR4D KIGFX::COLOR4D::Inverted ( ) const
inline

Returns an inverted color, alpha remains the same.

Returns
COLOR4D& Inverted color.

Definition at line 317 of file color4d.h.

318  {
319  return COLOR4D( 1.0 - r, 1.0 - g, 1.0 - b, a );
320  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, COLOR4D(), g, and r.

Referenced by KIGFX::PCB_RENDER_SETTINGS::LoadColors().

◆ Mix()

COLOR4D KIGFX::COLOR4D::Mix ( const COLOR4D aColor,
double  aFactor 
) const
inline

Return a color that is mixed with the input by a factor.

Parameters
aFactorSpecifies how much of the original color to keep (valid values: 0.0 .. 1.0).
Returns
COLOR4D Mixed color.

Definition at line 289 of file color4d.h.

290  {
291  assert( aFactor >= 0.0 && aFactor <= 1.0 );
292 
293  return COLOR4D( aColor.r * ( 1.0 - aFactor ) + r * aFactor,
294  aColor.g * ( 1.0 - aFactor ) + g * aFactor,
295  aColor.b * ( 1.0 - aFactor ) + b * aFactor,
296  a );
297  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double a
Alpha component.
Definition: color4d.h:366
double r
Red component.
Definition: color4d.h:363

References a, b, COLOR4D(), g, and r.

Referenced by KIGFX::RENDER_SETTINGS::update().

◆ Saturate()

COLOR4D & COLOR4D::Saturate ( double  aFactor)

Saturates the color to a given factor (in HSV model)

Definition at line 439 of file color4d.cpp.

440 {
441  // One can saturate a color only when r, v, b are not equal
442  if( r == g && r == b )
443  return *this;
444 
445  double h, s, v;
446 
447  ToHSV( h, s, v, true );
448  FromHSV( h, aFactor, 1.0 );
449 
450  return *this;
451 }
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
Definition: color4d.cpp:312
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
Definition: color4d.cpp:365
double r
Red component.
Definition: color4d.h:363

References b, FromHSV(), g, r, and ToHSV().

◆ ToHSL()

void COLOR4D::ToHSL ( double &  aOutHue,
double &  aOutSaturation,
double &  aOutValue 
) const

Converts current color (stored in RGB) to HSL format.

Parameters
aOutHueis the conversion result for hue component, in degrees 0 ... 360.0.
aOutSaturationis the conversion result for saturation component (0 ... 1.0).
aOutLightnessis conversion result for value component (0 ... 1.0).
Note
saturation is set to 0.0 for black color if r = g = b,

Definition at line 240 of file color4d.cpp.

241 {
242  auto min = std::min( r, std::min( g, b ) );
243  auto max = std::max( r, std::max( g, b ) );
244  auto diff = max - min;
245 
246  aOutLightness = ( max + min ) / 2.0;
247 
248  if( aOutLightness >= 1.0 )
249  aOutSaturation = 0.0;
250  else
251  aOutSaturation = diff / ( 1.0 - std::abs( 2.0 * aOutLightness - 1.0 ) );
252 
253  double hue;
254 
255  if( diff <= 0.0 )
256  hue = 0.0;
257  else if( max == r )
258  hue = ( g - b ) / diff;
259  else if( max == g )
260  hue = ( b - r ) / diff + 2.0;
261  else
262  hue = ( r - g ) / diff + 4.0;
263 
264  aOutHue = hue > 0.0 ? hue * 60.0 : hue * 60.0 + 360.0;
265 
266  while( aOutHue < 0.0 )
267  aOutHue += 360.0;
268 }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by PNS_TUNE_STATUS_POPUP::UpdateStatus().

◆ ToHSV()

void COLOR4D::ToHSV ( double &  aOutHue,
double &  aOutSaturation,
double &  aOutValue,
bool  aAlwaysDefineHue = false 
) const

Convert current color (stored in RGB) to HSV format.

Parameters
aOutHueis the conversion result for hue component, in degrees 0 ... 360.0.
aOutSaturationis the conversion result for saturation component (0 ... 1.0).
aOutValueis conversion result for value component (0 ... 1.0).
aAlwaysDefineHuecontrols the way hue is defined when r = v = b
Note
saturation is set to 0.0 for black color (r = v = b = 0), and if r = v = b, hue is set to 0.0 if aAlwaysDefineHue = true, and set to NAN if aAlwaysDefineHue = false. this option is useful to convert a 4D color to a legacy color, because Red has hue = 0, therefore aAlwaysDefineHue = false makes difference between Red and Gray colors.

Definition at line 312 of file color4d.cpp.

313 {
314  double min, max, delta;
315 
316  min = r < g ? r : g;
317  min = min < b ? min : b;
318 
319  max = r > g ? r : g;
320  max = max > b ? max : b;
321 
322  aOutValue = max; // value
323  delta = max - min;
324 
325  if( max > 0.0 )
326  {
327  aOutSaturation = ( delta / max );
328  }
329  else // for black color (r = g = b = 0 ) saturation is set to 0.
330  {
331  aOutSaturation = 0.0;
332  aOutHue = aAlwaysDefineHue ? 0.0 : NAN;
333  return;
334  }
335 
336  /* Hue in degrees (0...360) is coded according to this table
337  * 0 or 360 : red
338  * 60 : yellow
339  * 120 : green
340  * 180 : cyan
341  * 240 : blue
342  * 300 : magenta
343  */
344  if( delta != 0.0 )
345  {
346  if( r >= max )
347  aOutHue = ( g - b ) / delta; // between yellow & magenta
348  else if( g >= max )
349  aOutHue = 2.0 + ( b - r ) / delta; // between cyan & yellow
350  else
351  aOutHue = 4.0 + ( r - g ) / delta; // between magenta & cyan
352 
353  aOutHue *= 60.0; // degrees
354 
355  if( aOutHue < 0.0 )
356  aOutHue += 360.0;
357  }
358  else // delta = 0 means r = g = b. hue is set to 0.0
359  {
360  aOutHue = aAlwaysDefineHue ? 0.0 : NAN;
361  }
362 }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, g, and r.

Referenced by DIALOG_COLOR_PICKER::buttColorClick(), DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER(), DIALOG_COLOR_PICKER::OnColorValueText(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), Saturate(), and DIALOG_COLOR_PICKER::SetEditVals().

◆ WithAlpha()

COLOR4D KIGFX::COLOR4D::WithAlpha ( double  aAlpha) const
inline

Return a color with the same color, but the given alpha.

Parameters
aAlphaspecifies the alpha of the new color
Returns
COLOR4D color with that alpha

Definition at line 305 of file color4d.h.

306  {
307  assert( aAlpha >= 0.0 && aAlpha <= 1.0 );
308 
309  return COLOR4D( r, g, b, aAlpha );
310  }
double g
Green component.
Definition: color4d.h:364
double b
Blue component.
Definition: color4d.h:365
double r
Red component.
Definition: color4d.h:363

References b, COLOR4D(), g, and r.

Referenced by deemphasise(), LAYER_SELECTOR::DrawColorSwatch(), BOARD_PRINTOUT::DrawPage(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), COLOR_SWATCH::MakeBitmap(), PCB_GRID_HELPER::PCB_GRID_HELPER(), PCB_EDIT_FRAME::PrepareLayerIndicator(), and EDIT_POINTS::ViewDraw().

Member Data Documentation

◆ a

double KIGFX::COLOR4D::a

Alpha component.

Definition at line 366 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::CAIRO_GAL_BASE::blitCursor(), KIGFX::OPENGL_GAL::blitCursor(), Brightened(), DIALOG_COLOR_PICKER::buttColorClick(), KIGFX::CAIRO_GAL_BASE::ChangeGroupColor(), KIGFX::VERTEX_MANAGER::ChangeItemColor(), KIGFX::VERTEX_MANAGER::Color(), COLOR4D(), CUSTOM_COLOR_ITEM::CUSTOM_COLOR_ITEM(), Darkened(), DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::CAIRO_GAL_BASE::drawAxes(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::CAIRO_GAL_BASE::drawGridCross(), KIGFX::CAIRO_GAL_BASE::drawGridLine(), KIGFX::CAIRO_GAL_BASE::drawGridPoint(), KIGFX::CAIRO_GAL_BASE::DrawGroup(), KIGFX::OPENGL_GAL::DrawLine(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::drawPolyline(), KIGFX::OPENGL_GAL::DrawRectangle(), KIGFX::CAIRO_GAL_BASE::DrawSegment(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawSemiCircle(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), KIGFX::CAIRO_GAL_BASE::flushPath(), formatStroke(), FromCSSRGBA(), BOARD_ADAPTER::GetColor(), Inverted(), KI_TEST::IsColorNear(), KI_TEST::IsColorNearHex(), PCB_CONTROL::LayerAlphaDec(), PCB_CONTROL::LayerAlphaInc(), KIGFX::GERBVIEW_RENDER_SETTINGS::LoadColors(), KIGFX::PCB_RENDER_SETTINGS::LoadColors(), EDA_3D_VIEWER_FRAME::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeAlpha(), APPEARANCE_CONTROLS::OnLayerAlphaChanged(), DIALOG_COLOR_PICKER::OnResetButton(), KIGFX::operator<(), KIGFX::operator==(), SCH_SEXPR_PLUGIN::saveJunction(), EDA_3D_VIEWER_FRAME::SaveSettings(), SCH_SEXPR_PLUGIN::saveSheet(), DIALOG_COLOR_PICKER::SetEditVals(), KIGFX::CAIRO_GAL_BASE::SetFillColor(), SCH_LINE::SetLineColor(), KIGFX::CAIRO_GAL_BASE::SetStrokeColor(), KIGFX::CAIRO_GAL_BASE::storePath(), and ROUTER_PREVIEW_ITEM::Update().

◆ b

double KIGFX::COLOR4D::b

Blue component.

Definition at line 365 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::CAIRO_GAL_BASE::blitCursor(), KIGFX::OPENGL_GAL::blitCursor(), Brighten(), Brightened(), DIALOG_COLOR_PICKER::buttColorClick(), KIGFX::CAIRO_GAL_BASE::ChangeGroupColor(), KIGFX::VERTEX_MANAGER::ChangeItemColor(), KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), KIGFX::CAIRO_GAL_BASE::ClearScreen(), KIGFX::VERTEX_MANAGER::Color(), COLOR4D(), CUSTOM_COLOR_ITEM::CUSTOM_COLOR_ITEM(), Darken(), Darkened(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::CAIRO_GAL_BASE::drawAxes(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::CAIRO_GAL_BASE::drawGridCross(), KIGFX::CAIRO_GAL_BASE::drawGridLine(), KIGFX::CAIRO_GAL_BASE::drawGridPoint(), KIGFX::CAIRO_GAL_BASE::DrawGroup(), KIGFX::OPENGL_GAL::DrawLine(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::drawPolyline(), KIGFX::OPENGL_GAL::DrawRectangle(), DIALOG_COLOR_PICKER::drawRGBPalette(), KIGFX::CAIRO_GAL_BASE::DrawSegment(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawSemiCircle(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), KIGFX::CAIRO_GAL_BASE::flushPath(), formatStroke(), FromCSSRGBA(), FromHSL(), FromHSV(), GetBrightness(), BOARD_ADAPTER::GetColor(), getDXFColorName(), TRANSLINE::Init(), Invert(), Inverted(), KI_TEST::IsColorNear(), KI_TEST::IsColorNearHex(), EDA_3D_VIEWER_FRAME::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditBlue(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), EDA_3D_VIEWER_FRAME::SaveSettings(), SCH_SEXPR_PLUGIN::saveSheet(), DIALOG_COLOR_PICKER::SetEditVals(), KIGFX::CAIRO_GAL_BASE::SetFillColor(), PCB_CALCULATOR_FRAME::SetPrmBgColor(), KIGFX::CAIRO_GAL_BASE::SetStrokeColor(), KIGFX::CAIRO_GAL_BASE::storePath(), ToHSL(), ToHSV(), PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow(), and WithAlpha().

◆ BLACK

◆ CLEAR

const COLOR4D COLOR4D::CLEAR
static

Definition at line 374 of file color4d.h.

Referenced by KIGFX::PCB_PAINTER::draw(), and KIGFX::PCB_RENDER_SETTINGS::GetColor().

◆ g

double KIGFX::COLOR4D::g

Green component.

Definition at line 364 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::CAIRO_GAL_BASE::blitCursor(), KIGFX::OPENGL_GAL::blitCursor(), Brighten(), Brightened(), DIALOG_COLOR_PICKER::buttColorClick(), KIGFX::CAIRO_GAL_BASE::ChangeGroupColor(), KIGFX::VERTEX_MANAGER::ChangeItemColor(), KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), KIGFX::CAIRO_GAL_BASE::ClearScreen(), KIGFX::VERTEX_MANAGER::Color(), COLOR4D(), CUSTOM_COLOR_ITEM::CUSTOM_COLOR_ITEM(), Darken(), Darkened(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::CAIRO_GAL_BASE::drawAxes(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::CAIRO_GAL_BASE::drawGridCross(), KIGFX::CAIRO_GAL_BASE::drawGridLine(), KIGFX::CAIRO_GAL_BASE::drawGridPoint(), KIGFX::CAIRO_GAL_BASE::DrawGroup(), KIGFX::OPENGL_GAL::DrawLine(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::drawPolyline(), KIGFX::OPENGL_GAL::DrawRectangle(), DIALOG_COLOR_PICKER::drawRGBPalette(), KIGFX::CAIRO_GAL_BASE::DrawSegment(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawSemiCircle(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), KIGFX::CAIRO_GAL_BASE::flushPath(), formatStroke(), FromCSSRGBA(), FromHSL(), FromHSV(), GetBrightness(), BOARD_ADAPTER::GetColor(), getDXFColorName(), TRANSLINE::Init(), Invert(), Inverted(), KI_TEST::IsColorNear(), KI_TEST::IsColorNearHex(), EDA_3D_VIEWER_FRAME::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditGreen(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), EDA_3D_VIEWER_FRAME::SaveSettings(), SCH_SEXPR_PLUGIN::saveSheet(), DIALOG_COLOR_PICKER::SetEditVals(), KIGFX::CAIRO_GAL_BASE::SetFillColor(), PCB_CALCULATOR_FRAME::SetPrmBgColor(), KIGFX::CAIRO_GAL_BASE::SetStrokeColor(), KIGFX::CAIRO_GAL_BASE::storePath(), ToHSL(), ToHSV(), PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow(), and WithAlpha().

◆ r

double KIGFX::COLOR4D::r

Red component.

Definition at line 363 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), KIGFX::CAIRO_GAL_BASE::blitCursor(), KIGFX::OPENGL_GAL::blitCursor(), Brighten(), Brightened(), DIALOG_COLOR_PICKER::buttColorClick(), KIGFX::CAIRO_GAL_BASE::ChangeGroupColor(), KIGFX::VERTEX_MANAGER::ChangeItemColor(), KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), KIGFX::CAIRO_GAL_BASE::ClearScreen(), KIGFX::VERTEX_MANAGER::Color(), COLOR4D(), CUSTOM_COLOR_ITEM::CUSTOM_COLOR_ITEM(), Darken(), Darkened(), KIGFX::OPENGL_GAL::DrawArc(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), KIGFX::OPENGL_GAL::DrawArcSegment(), KIGFX::CAIRO_GAL_BASE::drawAxes(), KIGFX::OPENGL_GAL::drawBitmapOverbar(), KIGFX::OPENGL_GAL::DrawCircle(), KIGFX::OPENGL_GAL::DrawGrid(), KIGFX::CAIRO_GAL_BASE::drawGridCross(), KIGFX::CAIRO_GAL_BASE::drawGridLine(), KIGFX::CAIRO_GAL_BASE::drawGridPoint(), KIGFX::CAIRO_GAL_BASE::DrawGroup(), KIGFX::OPENGL_GAL::DrawLine(), KIGFX::OPENGL_GAL::drawPolygon(), KIGFX::OPENGL_GAL::drawPolyline(), KIGFX::OPENGL_GAL::DrawRectangle(), DIALOG_COLOR_PICKER::drawRGBPalette(), KIGFX::CAIRO_GAL_BASE::DrawSegment(), KIGFX::OPENGL_GAL::DrawSegment(), KIGFX::OPENGL_GAL::drawSemiCircle(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), KIGFX::CAIRO_GAL_BASE::flushPath(), formatStroke(), FromCSSRGBA(), FromHSL(), FromHSV(), GetBrightness(), BOARD_ADAPTER::GetColor(), getDXFColorName(), TRANSLINE::Init(), Invert(), Inverted(), KI_TEST::IsColorNear(), KI_TEST::IsColorNearHex(), EDA_3D_VIEWER_FRAME::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditRed(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), EDA_3D_VIEWER_FRAME::SaveSettings(), SCH_SEXPR_PLUGIN::saveSheet(), DIALOG_COLOR_PICKER::SetEditVals(), KIGFX::CAIRO_GAL_BASE::SetFillColor(), PCB_CALCULATOR_FRAME::SetPrmBgColor(), KIGFX::CAIRO_GAL_BASE::SetStrokeColor(), KIGFX::CAIRO_GAL_BASE::storePath(), ToHSL(), ToHSV(), PANEL_3D_OPENGL_OPTIONS::TransferDataFromWindow(), and WithAlpha().

◆ UNSPECIFIED

const COLOR4D COLOR4D::UNSPECIFIED
static

For legacy support; used as a value to indicate color hasn't been set yet.

Definition at line 369 of file color4d.h.

Referenced by COLOR4D(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), KIGFX::SCH_PAINTER::getRenderColor(), and KIGFX::GERBVIEW_RENDER_SETTINGS::LoadColors().

◆ WHITE

const COLOR4D COLOR4D::WHITE
static

Definition at line 372 of file color4d.h.

Referenced by PNS_TEST_DEBUG_DECORATOR::DEBUG_ENT::DEBUG_ENT().


The documentation for this class was generated from the following files: