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 98 of file color4d.h.

Constructor & Destructor Documentation

◆ COLOR4D() [1/3]

KIGFX::COLOR4D::COLOR4D ( )
inline

Definition at line 102 of file color4d.h.

102  :
103  r( 0 ), g( 0 ), b( 0 ), a( 1.0 )
104  {
105  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 113 of file color4d.h.

113  :
114  r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha )
115  {
116  assert( r >= 0.0 && r <= 1.0 );
117  assert( g >= 0.0 && g <= 1.0 );
118  assert( b >= 0.0 && b <= 1.0 );
119  assert( a >= 0.0 && a <= 1.0 );
120  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 76 of file color4d.cpp.

77 {
78  if( aColor <= UNSPECIFIED_COLOR || aColor >= NBCOLORS )
79  {
80  *this = COLOR4D::UNSPECIFIED;
81  return;
82  }
83 
84  r = colorRefs()[aColor].m_Red / 255.0;
85  g = colorRefs()[aColor].m_Green / 255.0;
86  b = colorRefs()[aColor].m_Blue / 255.0;
87  a = 1.0;
88 }
unsigned char m_Red
Definition: color4d.h:83
unsigned char m_Green
Definition: color4d.h:82
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
Number of colors.
Definition: color4d.h:74
double a
Alpha component.
Definition: color4d.h:361
unsigned char m_Blue
Definition: color4d.h:81
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:364
double r
Red component.
Definition: color4d.h:358

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 204 of file color4d.h.

205  {
206  assert( aFactor >= 0.0 && aFactor <= 1.0 );
207 
208  r = r * ( 1.0 - aFactor ) + aFactor;
209  g = g * ( 1.0 - aFactor ) + aFactor;
210  b = b * ( 1.0 - aFactor ) + aFactor;
211 
212  return *this;
213  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 257 of file color4d.h.

258  {
259  assert( aFactor >= 0.0 && aFactor <= 1.0 );
260 
261  return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor,
262  b * ( 1.0 - aFactor ) + aFactor, a );
263  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 221 of file color4d.h.

222  {
223  assert( aFactor >= 0.0 && aFactor <= 1.0 );
224 
225  r = r * ( 1.0 - aFactor );
226  g = g * ( 1.0 - aFactor );
227  b = b * ( 1.0 - aFactor );
228 
229  return *this;
230  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 271 of file color4d.h.

272  {
273  assert( aFactor >= 0.0 && aFactor <= 1.0 );
274 
275  return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), a );
276  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 440 of file color4d.cpp.

441 {
442  EDA_COLOR_T candidate = EDA_COLOR_T::BLACK;
443 
444  /* Find the 'nearest' color in the palette. This is fun. There is
445  a gazilion of metrics for the color space and no one of the
446  useful one is in the RGB color space. Who cares, this is a CAD,
447  not a photosomething...
448 
449  I hereby declare that the distance is the sum of the square of the
450  component difference. Think about the RGB color cube. Now get the
451  euclidean distance, but without the square root... for ordering
452  purposes it's the same, obviously. Also each component can't be
453  less of the target one, since I found this currently work better...
454  */
455  int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this
456 
457  for( EDA_COLOR_T trying = EDA_COLOR_T::BLACK; trying < EDA_COLOR_T::NBCOLORS;
458  trying = static_cast<EDA_COLOR_T>( int( trying ) + 1 ) )
459  {
460  const StructColors &c = colorRefs()[trying];
461  int distance = (aR - c.m_Red) * (aR - c.m_Red) +
462  (aG - c.m_Green) * (aG - c.m_Green) +
463  (aB - c.m_Blue) * (aB - c.m_Blue);
464 
465  if( distance < nearest_distance && c.m_Red >= aR &&
466  c.m_Green >= aG && c.m_Blue >= aB )
467  {
468  nearest_distance = distance;
469  candidate = trying;
470  }
471  }
472 
473  return candidate;
474 }
unsigned char m_Red
Definition: color4d.h:83
unsigned char m_Green
Definition: color4d.h:82
Definition: color4d.h:44
Number of colors.
Definition: color4d.h:74
unsigned char m_Blue
Definition: color4d.h:81
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 476 of file color4d.cpp.

477 {
478  r = std::max( 0, std::min( 255, aRed ) ) / 255.0;
479  g = std::max( 0, std::min( 255, aGreen ) ) / 255.0;
480  b = std::max( 0, std::min( 255, aBlue ) ) / 255.0;
481  a = std::max( 0.0, std::min( 1.0, aAlpha ) );
482 
483  return *this;
484 }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 252 of file color4d.cpp.

253 {
254  const auto P = ( 1.0 - std::abs( 2.0 * aInLightness - 1.0 ) ) * aInSaturation;
255  const auto scaled_hue = aInHue / 60.0;
256  const auto Q = P * ( 1.0 - std::abs( std::fmod( scaled_hue, 2.0 ) - 1.0 ) );
257 
258  r = g = b = aInLightness - P / 2.0;
259 
260  if (scaled_hue < 1.0)
261  {
262  r += P;
263  g += Q;
264  }
265  else if (scaled_hue < 2.0)
266  {
267  r += Q;
268  g += P;
269  }
270  else if (scaled_hue < 3.0)
271  {
272  g += P;
273  b += Q;
274  }
275  else if (scaled_hue < 4.0)
276  {
277  g += Q;
278  b += P;
279  }
280  else if (scaled_hue < 5.0)
281  {
282  r += Q;
283  b += P;
284  }
285  else
286  {
287  r += P;
288  b += Q;
289  }
290 }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 346 of file color4d.cpp.

347 {
348  if( aInS <= 0.0 )
349  {
350  r = aInV;
351  g = aInV;
352  b = aInV;
353  return;
354  }
355 
356  double hh = aInH;
357 
358  while( hh >= 360.0 )
359  hh -= 360.0;
360 
361  /* Hue in degrees (0...360) is coded according to this table
362  * 0 or 360 : red
363  * 60 : yellow
364  * 120 : green
365  * 180 : cyan
366  * 240 : blue
367  * 300 : magenta
368  */
369  hh /= 60.0;
370 
371  int i = (int) hh;
372  double ff = hh - i;
373 
374  double p = aInV * ( 1.0 - aInS );
375  double q = aInV * ( 1.0 - ( aInS * ff ) );
376  double t = aInV * ( 1.0 - ( aInS * ( 1.0 - ff ) ) );
377 
378  switch( i )
379  {
380  case 0:
381  r = aInV;
382  g = t;
383  b = p;
384  break;
385 
386  case 1:
387  r = q;
388  g = aInV;
389  b = p;
390  break;
391 
392  case 2:
393  r = p;
394  g = aInV;
395  b = t;
396  break;
397 
398  case 3:
399  r = p;
400  g = q;
401  b = aInV;
402  break;
403 
404  case 4:
405  r = t;
406  g = p;
407  b = aInV;
408  break;
409 
410  case 5:
411  default:
412  r = aInV;
413  g = p;
414  b = q;
415  break;
416  }
417 }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 322 of file color4d.h.

323  {
324  // Weighted W3C formula
325  return r * 0.299 + g * 0.587 + b * 0.117;
326  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 237 of file color4d.h.

238  {
239  r = ( 1.0 - r );
240  g = ( 1.0 - g );
241  b = ( 1.0 - b );
242 
243  return *this;
244  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 312 of file color4d.h.

313  {
314  return COLOR4D( 1.0 - r, 1.0 - g, 1.0 - b, a );
315  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 284 of file color4d.h.

285  {
286  assert( aFactor >= 0.0 && aFactor <= 1.0 );
287 
288  return COLOR4D( aColor.r * ( 1.0 - aFactor ) + r * aFactor,
289  aColor.g * ( 1.0 - aFactor ) + g * aFactor,
290  aColor.b * ( 1.0 - aFactor ) + b * aFactor,
291  a );
292  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double a
Alpha component.
Definition: color4d.h:361
double r
Red component.
Definition: color4d.h:358

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 420 of file color4d.cpp.

421 {
422  // One can saturate a color only when r, v, b are not equal
423  if( r == g && r == b )
424  return *this;
425 
426  double h, s, v;
427 
428  ToHSV( h, s, v, true );
429  FromHSV( h, aFactor, 1.0 );
430 
431  return *this;
432 }
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
Definition: color4d.cpp:293
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
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:346
double r
Red component.
Definition: color4d.h:358

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 221 of file color4d.cpp.

222 {
223  auto min = std::min( r, std::min( g, b ) );
224  auto max = std::max( r, std::max( g, b ) );
225  auto diff = max - min;
226 
227  aOutLightness = ( max + min ) / 2.0;
228 
229  if( aOutLightness >= 1.0 )
230  aOutSaturation = 0.0;
231  else
232  aOutSaturation = diff / ( 1.0 - std::abs( 2.0 * aOutLightness - 1.0 ) );
233 
234  double hue;
235 
236  if( diff <= 0.0 )
237  hue = 0.0;
238  else if( max == r )
239  hue = ( g - b ) / diff;
240  else if( max == g )
241  hue = ( b - r ) / diff + 2.0;
242  else
243  hue = ( r - g ) / diff + 4.0;
244 
245  aOutHue = hue > 0.0 ? hue * 60.0 : hue * 60.0 + 360.0;
246 
247  while( aOutHue < 0.0 )
248  aOutHue += 360.0;
249 }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 293 of file color4d.cpp.

294 {
295  double min, max, delta;
296 
297  min = r < g ? r : g;
298  min = min < b ? min : b;
299 
300  max = r > g ? r : g;
301  max = max > b ? max : b;
302 
303  aOutValue = max; // value
304  delta = max - min;
305 
306  if( max > 0.0 )
307  {
308  aOutSaturation = ( delta / max );
309  }
310  else // for black color (r = g = b = 0 ) saturation is set to 0.
311  {
312  aOutSaturation = 0.0;
313  aOutHue = aAlwaysDefineHue ? 0.0 : NAN;
314  return;
315  }
316 
317  /* Hue in degrees (0...360) is coded according to this table
318  * 0 or 360 : red
319  * 60 : yellow
320  * 120 : green
321  * 180 : cyan
322  * 240 : blue
323  * 300 : magenta
324  */
325  if( delta != 0.0 )
326  {
327  if( r >= max )
328  aOutHue = ( g - b ) / delta; // between yellow & magenta
329  else if( g >= max )
330  aOutHue = 2.0 + ( b - r ) / delta; // between cyan & yellow
331  else
332  aOutHue = 4.0 + ( r - g ) / delta; // between magenta & cyan
333 
334  aOutHue *= 60.0; // degrees
335 
336  if( aOutHue < 0.0 )
337  aOutHue += 360.0;
338  }
339  else // delta = 0 means r = g = b. hue is set to 0.0
340  {
341  aOutHue = aAlwaysDefineHue ? 0.0 : NAN;
342  }
343 }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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 300 of file color4d.h.

301  {
302  assert( aAlpha >= 0.0 && aAlpha <= 1.0 );
303 
304  return COLOR4D( r, g, b, aAlpha );
305  }
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
double r
Red component.
Definition: color4d.h:358

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

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

Member Data Documentation

◆ a

double KIGFX::COLOR4D::a

Alpha component.

Definition at line 361 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), 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::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeAlpha(), APPEARANCE_CONTROLS::OnLayerAlphaChanged(), DIALOG_COLOR_PICKER::OnResetButton(), KIGFX::operator<(), KIGFX::operator==(), SCH_SEXPR_PLUGIN::saveJunction(), SCH_SEXPR_PLUGIN::saveSheet(), EDA_3D_VIEWER::Set3DColorFromUser(), 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 360 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), 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::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditBlue(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), SCH_SEXPR_PLUGIN::saveSheet(), EDA_3D_VIEWER::Set3DColorFromUser(), 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(), and WithAlpha().

◆ BLACK

◆ CLEAR

const COLOR4D COLOR4D::CLEAR
static

Definition at line 369 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 359 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), 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::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditGreen(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), SCH_SEXPR_PLUGIN::saveSheet(), EDA_3D_VIEWER::Set3DColorFromUser(), 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(), and WithAlpha().

◆ r

double KIGFX::COLOR4D::r

Red component.

Definition at line 358 of file color4d.h.

Referenced by KIGFX::OPENGL_GAL::BitmapText(), 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::LoadSettings(), Mix(), DIALOG_COLOR_PICKER::OnChangeEditRed(), DIALOG_COLOR_PICKER::OnResetButton(), DIALOG_COLOR_PICKER::onRGBMouseDrag(), KIGFX::operator<(), KIGFX::operator==(), Saturate(), SCH_SEXPR_PLUGIN::saveJunction(), SCH_SEXPR_PLUGIN::saveSheet(), EDA_3D_VIEWER::Set3DColorFromUser(), 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(), 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 364 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 367 of file color4d.h.


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