DGtal  1.2.beta
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
DGtal::Color Class Reference

Structure representing an RGB triple with alpha component. More...

#include <DGtal/io/Color.h>

Public Member Functions

 ~Color ()=default
 
 Color (const unsigned int aRgb, unsigned char aAlpha=255)
 
 Color (const Color &aColor)=default
 
 Color (const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue=255)
 
 Color (unsigned char aGrayValue, unsigned char aAlphaValue=255)
 
 Color ()
 
ColorsetRGBi (const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue=255)
 
ColorsetRGBA (DGtal::uint32_t aRGBA)
 
void red (const unsigned char aRedValue)
 
void green (const unsigned char aGreenValue)
 
void blue (const unsigned char aBlueValue)
 
void alpha (const unsigned char aAlphaValue)
 
unsigned char red () const
 
unsigned char green () const
 
unsigned char blue () const
 
unsigned char alpha () const
 
double r () const
 
double g () const
 
double b () const
 
double a () const
 
DGtal::uint32_t getRGB () const
 
DGtal::uint32_t getRGBA () const
 
bool valid () const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 
ColorsetRGBf (float red, float green, float blue, float alpha=1.0)
 
bool operator== (const Color &aColor) const
 
bool operator!= (const Color &aColor) const
 
bool operator< (const Color &aColor) const
 
bool operator> (const Color &aColor) const
 
bool operator<= (const Color &aColor) const
 
bool operator>= (const Color &aColor) const
 
Coloroperator+= (const Color &v)
 
Color operator+ (const Color &v) const
 
Coloroperator-= (const Color &v)
 
Color operator- (const Color &v) const
 
Coloroperator*= (const double coeff)
 
Color operator* (const double coeff) const
 
Coloroperator= (const Color &pv)=default
 
void flushPostscript (std::ostream &) const
 
std::string svg () const
 
std::string svgAlpha (const char *aPrefix) const
 
std::string postscript () const
 
std::string tikz () const
 

Static Public Attributes

static const Color None
 
static const Color Black
 
static const Color Gray
 
static const Color White
 
static const Color Red
 
static const Color Green
 
static const Color Lime
 
static const Color Blue
 
static const Color Cyan
 
static const Color Magenta
 
static const Color Yellow
 
static const Color Silver
 
static const Color Purple
 
static const Color Navy
 
static const Color Aqua
 

Private Member Functions

unsigned char clamp (const double value) const
 

Private Attributes

unsigned char myRed
 
unsigned char myGreen
 
unsigned char myBlue
 
unsigned char myAlpha
 

Detailed Description

Structure representing an RGB triple with alpha component.

Description of class 'Color'

Note
if compilation flag COLOR_WITH_ALPHA_ARITH is set, then the arithmetical operations on colors also consider the alpha-channel. Otherwise, the alpha channel is not changed when summing up to colors for instance.
Examples:
dec/exampleDiscreteExteriorCalculusSolve.cpp, examples/tutorial-examples/polyhedralizer.cpp, geometry/curves/exampleAlphaThickSegment.cpp, geometry/curves/exampleAlphaThickSegmentTgtCover.cpp, geometry/curves/exampleArithmeticalDSS.cpp, geometry/curves/exampleGridCurve3d-2.cpp, geometry/curves/exampleRationalConvexity.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, geometry/volumes/distance/distancetransform3D.cpp, geometry/volumes/distance/exampleFMM3D.cpp, geometry/volumes/distance/voronoimap2D.cpp, geometry/volumes/dvcm-2d.cpp, graph/graphTraversal.cpp, graph/volDistanceTraversal.cpp, io/boards/dgtalBoard2D-3-custom-classes.cpp, io/boards/dgtalBoard2D-3-custom-points.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, io/boards/dgtalBoard3D-1-points.cpp, io/boards/dgtalBoard3D-6-clipping.cpp, io/boards/dgtalBoard3DTo2D-3-objects.cpp, io/boards/dgtalBoard3DTo2D-5-custom.cpp, io/boards/dgtalBoard3DTo2D-6.cpp, io/boards/logoDGtal.cpp, io/digitalSetFromPointList.cpp, io/meshFromOFF.cpp, io/viewDualSurface.cpp, io/viewers/viewer3D-3-objects.cpp, io/viewers/viewer3D-5-custom.cpp, io/viewers/viewer3D-6-clipping.cpp, io/viewers/viewer3D-7-planes.cpp, io/viewers/viewer3D-7-stdplane.cpp, io/viewers/viewer3D-7bis-planes.cpp, io/viewers/viewer3D-7bis-stdplane.cpp, io/viewers/viewer3D-8-2DSliceImages.cpp, io/viewers/viewer3D-9-3Dimages.cpp, shapes/exampleEuclideanShapesDecorator.cpp, shapes/mesh3DConstructionAndVisualisation.cpp, shapes/viewMarchingCubes.cpp, shapes/viewPolygonalMarchingCubes.cpp, topology/3dBorderExtraction.cpp, topology/3dKSSurfaceExtraction.cpp, topology/ctopo-1.cpp, topology/ctopo-2-3d.cpp, topology/ctopo-2.cpp, topology/ctopo-fillContours.cpp, topology/cubical-complex-illustrations.cpp, topology/digitalSetToCubicalComplexes2D.cpp, topology/digitalSurfaceSlice.cpp, topology/frontierAndBoundary.cpp, topology/generateSimplicityTables2D.cpp, topology/homotopicThinning3D.cpp, topology/khalimskySpaceScanner.cpp, topology/volBreadthFirstTraversal.cpp, topology/volScanBoundary.cpp, topology/volTrackBoundary.cpp, tutorial-examples/freemanChainFromImage.cpp, tutorial-examples/polyhedralizer.cpp, and tutorial-examples/volDTGranulo.cpp.

Definition at line 66 of file Color.h.

Constructor & Destructor Documentation

◆ ~Color()

DGtal::Color::~Color ( )
default

Destructor.

◆ Color() [1/5]

DGtal::Color::Color ( const unsigned int  aRgb,
unsigned char  aAlpha = 255 
)

Constructor.

Parameters
aRgban unsigned int representing the color.
aAlphacolor transparency (default value =255);

Definition at line 44 of file Color.cpp.

References myBlue, myGreen, and myRed.

45  :myAlpha( aAlphaValue )
46 {
47  myRed = ( rgb & 0xFF0000u ) >> 16;
48  myGreen = ( rgb & 0xFF00u ) >> 8;
49  myBlue = rgb & 0xFF;
50 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ Color() [2/5]

DGtal::Color::Color ( const Color aColor)
default

Copy Constructor.

Parameters
aColorthe color to copy.

◆ Color() [3/5]

DGtal::Color::Color ( const unsigned char  aRedValue,
const unsigned char  aGreenValue,
const unsigned char  aBlueValue,
const unsigned char  aAlphaValue = 255 
)
inline

Constructor from R, G, B and Alpha parameter.

Parameters
aRedValuered component
aGreenValuegreen component
aBlueValueblue component
aAlphaValuecolor transparency.

Definition at line 105 of file Color.h.

109  : myRed(aRedValue),myGreen(aGreenValue),myBlue(aBlueValue),myAlpha(aAlphaValue) { }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ Color() [4/5]

DGtal::Color::Color ( unsigned char  aGrayValue,
unsigned char  aAlphaValue = 255 
)
inline

Constructor from gray scale value.

Parameters
aGrayValuethe color gray value.
aAlphaValuecolor transparency (default value =255);.

Definition at line 119 of file Color.h.

121  : myRed(aGrayValue),myGreen(aGrayValue), myBlue(aGrayValue), myAlpha(aAlphaValue) { }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ Color() [5/5]

DGtal::Color::Color ( )
inline

Default Constructor.

Definition at line 129 of file Color.h.

130  : myRed(0),myGreen(0),myBlue(0), myAlpha(255)
131  {
132  }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

Member Function Documentation

◆ a()

double DGtal::Color::a ( ) const

◆ alpha() [1/2]

void DGtal::Color::alpha ( const unsigned char  aAlphaValue)

◆ alpha() [2/2]

unsigned char DGtal::Color::alpha ( ) const

◆ b()

double DGtal::Color::b ( ) const

◆ blue() [1/2]

void DGtal::Color::blue ( const unsigned char  aBlueValue)

◆ blue() [2/2]

unsigned char DGtal::Color::blue ( ) const

◆ clamp()

unsigned char DGtal::Color::clamp ( const double  value) const
inlineprivate

Clamp an int to [0,255]

Parameters
[in]valuethe value to clamp
Returns
the clamped value

Definition at line 425 of file Color.h.

References max().

Referenced by operator*(), operator*=(), operator+(), operator+=(), operator-(), and operator-=().

426  {
427  return static_cast<unsigned char>(std::max( std::min(value, 255.0), 0.0));
428  }
int max(int a, int b)

◆ flushPostscript()

void DGtal::Color::flushPostscript ( std::ostream &  stream) const

Definition at line 142 of file Color.cpp.

Referenced by LibBoard::Polyline::flushPostscript(), LibBoard::QuadraticBezierCurve::flushPostscript(), and LibBoard::Arc::flushPostscript().

143 {
144  stream << ((double)myRed/255.0) << " "
145  << ((double)myGreen/255.0) << " "
146  << ((double)myBlue/255.0) << " srgb\n";
147 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myBlue
Definition: Color.h:410

◆ g()

double DGtal::Color::g ( ) const

◆ getRGB()

DGtal::uint32_t DGtal::Color::getRGB ( ) const
Returns
the unsigned integer ( DGtal::uint32_t ) coding each R, G, B canal on 8 bits starting from least significant bit.

Referenced by DGtal::functors::ColorRGBEncoder< TValue >::operator()().

◆ getRGBA()

DGtal::uint32_t DGtal::Color::getRGBA ( ) const
Returns
the unsigned integer ( DGtal::uint32_t ) coding each R, G, B, A canal on 8 bits starting from least significant bit.

◆ green() [1/2]

void DGtal::Color::green ( const unsigned char  aGreenValue)

◆ green() [2/2]

unsigned char DGtal::Color::green ( ) const

◆ isValid()

bool DGtal::Color::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 235 of file Color.cpp.

236 {
237  return true;
238 }

◆ operator!=()

bool DGtal::Color::operator!= ( const Color aColor) const

Definition at line 96 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

97 {
98  return myRed != aColor.myRed
99  || myGreen != aColor.myGreen
100  || myBlue != aColor.myBlue
101  || myAlpha != aColor.myAlpha;
102 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator*()

Color DGtal::Color::operator* ( const double  coeff) const
inline

Multiplication by a scalar (component-wise)

Note
returned components are clamped to [0,255] interval.
Parameters
coeffthe scalar.
Returns
a scaled color

Definition at line 340 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

341  {
342  Color c;
343  c.myRed = clamp((double)this->myRed*coeff);
344  c.myBlue = clamp((double)this->myBlue*coeff);
345  c.myGreen = clamp((double)this->myGreen*coeff);
346 #ifdef COLOR_WITH_ALPHA_ARITH
347  c.myAlpha = clamp((double)this->myAlpha*coeff);
348 #else
349  c.myAlpha = this->myAlpha;
350 #endif
351  return c;
352  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator*=()

Color& DGtal::Color::operator*= ( const double  coeff)
inline

Multiplication by a scalar (component-wise)

Note
returned components are clamped to [0,255] interval.
Parameters
coeffthe scalar
Returns
the scaled color

Definition at line 321 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

322  {
323  this->myRed = clamp((double)this->myRed*coeff);
324  this->myBlue = clamp((double)this->myBlue*coeff);
325  this->myGreen = clamp((double)this->myGreen*coeff);
326 #ifdef COLOR_WITH_ALPHA_ARITH
327  this->myAlpha = clamp((double)this->myAlpha*coeff);
328 #endif
329  return *this;
330  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator+()

Color DGtal::Color::operator+ ( const Color v) const
inline

Addition operator.

Note
returned components are clamped to [0,255] interval.
Parameters
vis the Color that gets added to *this.
Returns
a new Point that is the addition of 'this' to [v].

Definition at line 255 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

256  {
257  Color c;
258  c.myRed = clamp((int)this->myRed + (int)v.myRed);
259  c.myBlue =clamp((int)this->myBlue + (int)v.myBlue);
260  c.myGreen = clamp((int)this->myGreen + (int)v.myGreen);
261 #ifdef COLOR_WITH_ALPHA_ARITH
262  c.myAlpha = clamp((int)this->myAlpha + (int)v.myAlpha);
263 #else
264  c.myAlpha = this->myAlpha ;
265 #endif
266  return c;
267  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator+=()

Color& DGtal::Color::operator+= ( const Color v)
inline

Addition operator with assignement.

Note
returned components are clamped to [0,255] interval.
Parameters
vis the Color that gets added to *this.
Returns
a reference on 'this'.

Definition at line 235 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

236  {
237  this->myRed = clamp((int)this->myRed + (int)v.myRed);
238  this->myBlue = clamp((int)this->myBlue + (int)v.myBlue);
239  this->myGreen = clamp((int)this->myGreen + (int)v.myGreen);
240 #ifdef COLOR_WITH_ALPHA_ARITH
241  this->myAlpha = clamp((int)this->myAlpha + (int)v.myAlpha);
242 #endif
243  return *this;
244  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator-()

Color DGtal::Color::operator- ( const Color v) const
inline

Substraction operator.

Note
returned components are clamped to [0,255] interval.
Parameters
vis the Color that gets substacted to *this.
Returns
a new Point that is the subtraction 'this'-[v].

Definition at line 297 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

298  {
299  Color c;
300  c.myRed = clamp((int)this->myRed - (int)v.myRed);
301  c.myBlue = clamp((int)this->myBlue - (int)v.myBlue);
302  c.myGreen = clamp((int)this->myGreen - (int)v.myGreen);
303 #ifdef COLOR_WITH_ALPHA_ARITH
304  c.myAlpha = clamp((int)this->myAlpha - (int)v.myAlpha);
305 #else
306  c.myAlpha = this->myAlpha ;
307 #endif
308  return c;
309  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator-=()

Color& DGtal::Color::operator-= ( const Color v)
inline

Substraction operator with assignement.

Note
returned components are clamped to [0,255] interval.
Parameters
vis the Point that gets substracted to *this.
Returns
a reference on 'this'.

Definition at line 278 of file Color.h.

References clamp(), myAlpha, myBlue, myGreen, and myRed.

279  {
280  this->myRed = clamp((int)this->myRed - (int)v.myRed);
281  this->myBlue = clamp((int)this->myBlue - (int)v.myBlue);
282  this->myGreen = clamp((int)this->myGreen - (int)v.myGreen);
283 #ifdef COLOR_WITH_ALPHA_ARITH
284  this->myAlpha = clamp((int)this->myAlpha - (int)v.myAlpha);
285 #endif
286  return *this;
287  }
unsigned char clamp(const double value) const
Definition: Color.h:425
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator<()

bool DGtal::Color::operator< ( const Color aColor) const

Definition at line 105 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

106 {
107  if ( myRed < aColor.myRed )
108  return true;
109  if ( myRed == aColor.myRed ) {
110  if ( myGreen < aColor.myGreen )
111  return true;
112  if ( myGreen == aColor.myGreen ) {
113  if ( myBlue < aColor.myBlue )
114  return true;
115  if ( myBlue == aColor.myBlue )
116  return myAlpha < aColor.myAlpha;
117  }
118  }
119  return false;
120 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator<=()

bool DGtal::Color::operator<= ( const Color aColor) const

Definition at line 129 of file Color.cpp.

References DGtal::operator<(), and DGtal::operator==().

130 {
131  return this->operator<(aColor) || this->operator==(aColor);
132 }
bool operator<(const Color &aColor) const
Definition: Color.cpp:105
bool operator==(const Color &aColor) const
Definition: Color.cpp:87

◆ operator=()

Color& DGtal::Color::operator= ( const Color pv)
default

Assignement Operator

Parameters
pvthe object to copy.
Returns
a reference on 'this'.

◆ operator==()

bool DGtal::Color::operator== ( const Color aColor) const

Definition at line 87 of file Color.cpp.

References myAlpha, myBlue, myGreen, and myRed.

88 {
89  return myRed == aColor.myRed
90  && myGreen == aColor.myGreen
91  && myBlue == aColor.myBlue
92  && myAlpha == aColor.myAlpha;
93 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ operator>()

bool DGtal::Color::operator> ( const Color aColor) const

Definition at line 123 of file Color.cpp.

References DGtal::operator<().

124 {
125  return !this->operator<(aColor);
126 }
bool operator<(const Color &aColor) const
Definition: Color.cpp:105

◆ operator>=()

bool DGtal::Color::operator>= ( const Color aColor) const

Definition at line 135 of file Color.cpp.

References DGtal::operator==(), and DGtal::operator>().

136 {
137  return this->operator>(aColor) || this->operator==(aColor);
138 }
bool operator>(const Color &aColor) const
Definition: Color.cpp:123
bool operator==(const Color &aColor) const
Definition: Color.cpp:87

◆ postscript()

string DGtal::Color::postscript ( ) const

Definition at line 150 of file Color.cpp.

Referenced by LibBoard::Dot::flushPostscript(), LibBoard::Line::flushPostscript(), LibBoard::Arrow::flushPostscript(), LibBoard::Ellipse::flushPostscript(), LibBoard::Arc::flushPostscript(), and LibBoard::Text::flushPostscript().

151 {
152  char buffer[255];
153  secured_sprintf( buffer, 255, "%.4f %.4f %.4f", myRed/255.0, myGreen/255.0, myBlue/255.0 );
154  return buffer;
155 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myBlue
Definition: Color.h:410

◆ r()

double DGtal::Color::r ( ) const

◆ red() [1/2]

void DGtal::Color::red ( const unsigned char  aRedValue)

◆ red() [2/2]

unsigned char DGtal::Color::red ( ) const

◆ selfDisplay()

void DGtal::Color::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Definition at line 225 of file Color.cpp.

226 {
227  out << "[Color] RGBA("<<(int)myRed<<","<<(int)myGreen<<","<<(int)myBlue<<","<<(int)myAlpha<<")";
228 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ setRGBA()

DGtal::Color & DGtal::Color::setRGBA ( DGtal::uint32_t  aRGBA)

Set the color parameter from an unsigned integer coding each canal.

Parameters
aRGBAan unsigned integer on 32 bits(DGtal::unit32_t) representing the color coded with 4 bits on each components R, G, B and Alpha value.
Returns
a reference on the itself.

Definition at line 54 of file Color.cpp.

55 {
56  myRed = ( aRGBA & 0xFF000000u ) >> 24;
57  myGreen = ( aRGBA & 0xFF0000u ) >> 16;
58  myBlue = ( aRGBA & 0xFF00u ) >> 8;
59  myAlpha = aRGBA & 0xFF;
60  return *this;
61 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ setRGBf()

DGtal::Color & DGtal::Color::setRGBf ( float  red,
float  green,
float  blue,
float  alpha = 1.0 
)

Definition at line 65 of file Color.cpp.

Referenced by LibBoard::Board::setFillColorRGBf(), and LibBoard::Board::setPenColorRGBf().

68  {
69  if ( aRedValue > 1.0f ) aRedValue = 1.0f;
70  if ( aRedValue < 0.0f ) aRedValue = 0.0f;
71  myRed = static_cast<unsigned char>( 255 * aRedValue );
72  if ( aGreenValue > 1.0f ) aGreenValue = 1.0f;
73  if ( aGreenValue < 0.0f ) aGreenValue = 0.0f;
74  myGreen = static_cast<unsigned char>( 255 * aGreenValue );
75  if ( aBlueValue > 1.0f ) aBlueValue = 1.0f;
76  if ( aBlueValue < 0.0f ) aBlueValue = 0.0f;
77  myBlue = static_cast<unsigned char>( 255 * aBlueValue );
78  if ( aAlphaValue > 1.0f ) aAlphaValue = 1.0f;
79  if ( aAlphaValue < 0.0f ) aAlphaValue = 0.0f;
80  myAlpha = static_cast<unsigned char>( 255 * aAlphaValue );
81  return *this;
82 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
unsigned char myAlpha
Definition: Color.h:411
unsigned char myBlue
Definition: Color.h:410

◆ setRGBi()

Color& DGtal::Color::setRGBi ( const unsigned char  aRedValue,
const unsigned char  aGreenValue,
const unsigned char  aBlueValue,
const unsigned char  aAlphaValue = 255 
)

◆ svg()

string DGtal::Color::svg ( ) const

Definition at line 158 of file Color.cpp.

References None.

Referenced by LibBoard::Arrow::flushSVG(), LibBoard::Text::flushSVG(), and LibBoard::Shape::svgProperties().

159 {
160  char buffer[255];
161  if ( *this == DGtal::Color::None ) return "none";
162  secured_sprintf( buffer, 255, "rgb(%d,%d,%d)",myRed, myGreen, myBlue );
163  return buffer;
164 }
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
static const Color None
Definition: Color.h:388
unsigned char myBlue
Definition: Color.h:410

◆ svgAlpha()

string DGtal::Color::svgAlpha ( const char *  aPrefix) const

Return a an SVG parameter string for the opacity value.

Parameters
aPrefixA prefix string to be appended to the returned string if not empty.
Returns
An empty string if alpha == 255, otherwise the string <prefix>-opacity="<alpha-value>".

Definition at line 167 of file Color.cpp.

References None.

Referenced by LibBoard::Arrow::flushSVG(), LibBoard::Text::flushSVG(), and LibBoard::Shape::svgProperties().

168 {
169  char buffer[255];
170  if ( myAlpha == 255 || *this == DGtal::Color::None ) return "";
171  secured_sprintf( buffer, 255, " %s-opacity=\"%f\"", prefix, myAlpha/255.0f );
172  return buffer;
173 }
unsigned char myAlpha
Definition: Color.h:411
static const Color None
Definition: Color.h:388

◆ tikz()

string DGtal::Color::tikz ( ) const

Return a string representation of the color usable in TikZ commands. Use the corresponding named color (or a mixture of a named color and black) for predefined colors. Use a mixture of red, green and blue for general colors.

Returns
a string representation of the color usable in TikZ commands.

Definition at line 176 of file Color.cpp.

References Black, Blue, Gray, Green, Lime, Navy, None, Purple, Red, Silver, and White.

Referenced by LibBoard::Shape::tikzProperties().

177 {
178  // see tex/generic/pgf/utilities/pgfutil-plain.def for color definitions
179  char buffer[255];
180  if ( *this == DGtal::Color::None ) return "none";
181  if ( *this == DGtal::Color::Black ) return "black";
182  if ( *this == DGtal::Color::Gray ) return "gray";
183  if ( *this == DGtal::Color::White ) return "white";
184  if ( *this == DGtal::Color::Red ) return "red";
185  if ( *this == DGtal::Color::Green ) return "green!50!black";
186  if ( *this == DGtal::Color::Lime ) return "green";
187  if ( *this == DGtal::Color::Blue ) return "blue";
188 // if ( *this == DGtal::Color::Cyan ) return "cyan";
189 // if ( *this == DGtal::Color::Magenta ) return "magenta";
190 // if ( *this == DGtal::Color::Yellow ) return "yellow";
191  if ( *this == DGtal::Color::Silver ) return "white!75!black";
192  if ( *this == DGtal::Color::Purple ) return "gray"; // ???: Is Color::Purple meant to be equal to Color::Gray?
193  if ( *this == DGtal::Color::Navy ) return "blue!50!black";
194 // if ( *this == DGtal::Color::Aqua ) return "cyan"; // ???: Is Color::Aqua meant to be equal to Color::Cyan?
195  secured_sprintf( buffer, 255, "{rgb,255:red,%d;green,%d;blue,%d}", myRed, myGreen, myBlue );
196  return buffer;
197 }
static const Color Black
Definition: Color.h:389
unsigned char myGreen
Definition: Color.h:409
unsigned char myRed
Definition: Color.h:408
static const Color Navy
Definition: Color.h:401
static const Color None
Definition: Color.h:388
static const Color Lime
Definition: Color.h:394
static const Color Blue
Definition: Color.h:395
static const Color Gray
Definition: Color.h:390
unsigned char myBlue
Definition: Color.h:410
static const Color Silver
Definition: Color.h:399
static const Color White
Definition: Color.h:391
static const Color Red
Definition: Color.h:392
static const Color Green
Definition: Color.h:393
static const Color Purple
Definition: Color.h:400

◆ valid()

bool DGtal::Color::valid ( ) const

Field Documentation

◆ Aqua

const DGtal::Color DGtal::Color::Aqua
static

Definition at line 402 of file Color.h.

◆ Black

const DGtal::Color DGtal::Color::Black
static

◆ Blue

const DGtal::Color DGtal::Color::Blue
static

◆ Cyan

const DGtal::Color DGtal::Color::Cyan
static

Definition at line 396 of file Color.h.

◆ Gray

const DGtal::Color DGtal::Color::Gray
static

◆ Green

const DGtal::Color DGtal::Color::Green
static

◆ Lime

const DGtal::Color DGtal::Color::Lime
static

Definition at line 394 of file Color.h.

Referenced by tikz().

◆ Magenta

const DGtal::Color DGtal::Color::Magenta
static

Definition at line 397 of file Color.h.

Referenced by testAlphaThickSegmentConvexHullAndBox().

◆ myAlpha

unsigned char DGtal::Color::myAlpha
private

The opacity.

Definition at line 411 of file Color.h.

Referenced by operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), and operator==().

◆ myBlue

unsigned char DGtal::Color::myBlue
private

The blue component.

Definition at line 410 of file Color.h.

Referenced by Color(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), and operator==().

◆ myGreen

unsigned char DGtal::Color::myGreen
private

The green component.

Definition at line 409 of file Color.h.

Referenced by Color(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), and operator==().

◆ myRed

unsigned char DGtal::Color::myRed
private

The red component.

Definition at line 408 of file Color.h.

Referenced by Color(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), and operator==().

◆ Navy

const DGtal::Color DGtal::Color::Navy
static

Definition at line 401 of file Color.h.

Referenced by tikz().

◆ None

const DGtal::Color DGtal::Color::None
static

◆ Purple

const DGtal::Color DGtal::Color::Purple
static

Definition at line 400 of file Color.h.

Referenced by testAlphaThickSegmentConvexHullAndBox(), testThicknessDefinitions(), and tikz().

◆ Red

const DGtal::Color DGtal::Color::Red
static

◆ Silver

const DGtal::Color DGtal::Color::Silver
static

Definition at line 399 of file Color.h.

Referenced by tikz().

◆ White

const DGtal::Color DGtal::Color::White
static

Definition at line 391 of file Color.h.

Referenced by testMesh(), and tikz().

◆ Yellow

const DGtal::Color DGtal::Color::Yellow
static

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