DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Static 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 ()
 
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
 
ColorsetRGBi (const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue=255)
 
ColorsetRGBA (DGtal::uint32_t aRGBA)
 
ColorsetFromHSV (const double h, const double s, const double v)
 
std::array< double, 3 > getHSV () 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 Member Functions

static void HSVtoRGB (double &r, double &g, double &b, double h, const double s, const double v)
 
static void RGBtoHSV (double &h, double &s, double &v, const unsigned char r, const unsigned char g, const unsigned char b)
 

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/meshes/curvature-comparator-ii-cnc-3d.cpp, geometry/meshes/curvature-measures-icnc-3d.cpp, geometry/meshes/curvature-measures-icnc-XY-3d.cpp, geometry/meshes/curvature-measures-nc-3d.cpp, geometry/meshes/curvature-measures-nc-XY-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-3d.cpp, geometry/meshes/digpoly-curvature-measures-cnc-XY-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-3d.cpp, geometry/meshes/obj-curvature-measures-icnc-XY-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-3d.cpp, geometry/meshes/vol-curvature-measures-icnc-XY-3d.cpp, geometry/surfaces/dvcm-3d.cpp, geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, geometry/volumes/digitalPolyhedronBuilder3D.cpp, geometry/volumes/distance/distancetransform3D.cpp, geometry/volumes/distance/exampleFMM3D.cpp, geometry/volumes/distance/voronoimap2D.cpp, geometry/volumes/dvcm-2d.cpp, geometry/volumes/fullConvexityAnalysis3D.cpp, geometry/volumes/fullConvexityCollapsiblePoints2D.cpp, geometry/volumes/fullConvexityLUT2D.cpp, geometry/volumes/fullConvexityShortestPaths3D.cpp, geometry/volumes/fullConvexityThinning3D.cpp, geometry/volumes/standardDigitalPolyhedronBuilder3D.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 67 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.

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

References myBlue, myGreen, and myRed.

◆ 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 106 of file Color.h.

110 : myRed(aRedValue),myGreen(aGreenValue),myBlue(aBlueValue),myAlpha(aAlphaValue) { }

◆ 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 120 of file Color.h.

122 : myRed(aGrayValue),myGreen(aGrayValue), myBlue(aGrayValue), myAlpha(aAlphaValue) { }

◆ Color() [5/5]

DGtal::Color::Color ( )
inline

Default Constructor.

Definition at line 130 of file Color.h.

131 : myRed(0),myGreen(0),myBlue(0), myAlpha(255)
132 {
133 }

Member Function Documentation

◆ a()

double DGtal::Color::a ( ) const

◆ alpha() [1/2]

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

◆ alpha() [2/2]

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

◆ b()

double DGtal::Color::b ( ) const

Referenced by getHSV(), and setFromHSV().

◆ blue() [1/2]

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

◆ blue() [2/2]

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

◆ 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 450 of file Color.h.

451 {
452 return static_cast<unsigned char>(std::max( std::min(value, 255.0), 0.0));
453 }

◆ flushPostscript()

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

Definition at line 142 of file Color.cpp.

143{
144 stream << ((double)myRed/255.0) << " "
145 << ((double)myGreen/255.0) << " "
146 << ((double)myBlue/255.0) << " srgb\n";
147}

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

◆ g()

double DGtal::Color::g ( ) const

Referenced by getHSV(), and setFromHSV().

◆ getHSV()

std::array< double, 3 > DGtal::Color::getHSV ( ) const
inline
Returns
the HSV values of a DGtal::Color (array of three doubles).

Definition at line 192 of file Color.h.

193 {
194 double h,s,v;
195 Color::RGBtoHSV(h,s,v, this->r(), this->g(), this->b());
196 return {h,s,v};
197 }
double g() const
double b() const
static void RGBtoHSV(double &h, double &s, double &v, const unsigned char r, const unsigned char g, const unsigned char b)
double r() const

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

◆ 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]

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

◆ green() [2/2]

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

◆ HSVtoRGB()

static void DGtal::Color::HSVtoRGB ( double &  r,
double &  g,
double &  b,
double  h,
const double  s,
const double  v 
)
static

Converts a color from the HSV (Hue,Saturation,Value) space to the RGB space.

Parameters
rThe red component (out).
gThe green component (out).
bThe blue component (out).
hThe hue of the color in [0..360)
sThe saturation of the color in [0..1].
vThe value of the color in [0..1].

Referenced by setFromHSV().

◆ 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.

97{
98 return myRed != aColor.myRed
99 || myGreen != aColor.myGreen
100 || myBlue != aColor.myBlue
101 || myAlpha != aColor.myAlpha;
102}

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 364 of file Color.h.

365 {
366 Color c;
367 c.myRed = clamp((double)this->myRed*coeff);
368 c.myBlue = clamp((double)this->myBlue*coeff);
369 c.myGreen = clamp((double)this->myGreen*coeff);
370#ifdef COLOR_WITH_ALPHA_ARITH
371 c.myAlpha = clamp((double)this->myAlpha*coeff);
372#else
373 c.myAlpha = this->myAlpha;
374#endif
375 return c;
376 }

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 345 of file Color.h.

346 {
347 this->myRed = clamp((double)this->myRed*coeff);
348 this->myBlue = clamp((double)this->myBlue*coeff);
349 this->myGreen = clamp((double)this->myGreen*coeff);
350#ifdef COLOR_WITH_ALPHA_ARITH
351 this->myAlpha = clamp((double)this->myAlpha*coeff);
352#endif
353 return *this;
354 }

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 279 of file Color.h.

280 {
281 Color c;
282 c.myRed = clamp((int)this->myRed + (int)v.myRed);
283 c.myBlue =clamp((int)this->myBlue + (int)v.myBlue);
284 c.myGreen = clamp((int)this->myGreen + (int)v.myGreen);
285#ifdef COLOR_WITH_ALPHA_ARITH
286 c.myAlpha = clamp((int)this->myAlpha + (int)v.myAlpha);
287#else
288 c.myAlpha = this->myAlpha ;
289#endif
290 return c;
291 }

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 259 of file Color.h.

260 {
261 this->myRed = clamp((int)this->myRed + (int)v.myRed);
262 this->myBlue = clamp((int)this->myBlue + (int)v.myBlue);
263 this->myGreen = clamp((int)this->myGreen + (int)v.myGreen);
264#ifdef COLOR_WITH_ALPHA_ARITH
265 this->myAlpha = clamp((int)this->myAlpha + (int)v.myAlpha);
266#endif
267 return *this;
268 }

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 321 of file Color.h.

322 {
323 Color c;
324 c.myRed = clamp((int)this->myRed - (int)v.myRed);
325 c.myBlue = clamp((int)this->myBlue - (int)v.myBlue);
326 c.myGreen = clamp((int)this->myGreen - (int)v.myGreen);
327#ifdef COLOR_WITH_ALPHA_ARITH
328 c.myAlpha = clamp((int)this->myAlpha - (int)v.myAlpha);
329#else
330 c.myAlpha = this->myAlpha ;
331#endif
332 return c;
333 }

References myAlpha, myBlue, myGreen, and myRed.

◆ 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 302 of file Color.h.

303 {
304 this->myRed = clamp((int)this->myRed - (int)v.myRed);
305 this->myBlue = clamp((int)this->myBlue - (int)v.myBlue);
306 this->myGreen = clamp((int)this->myGreen - (int)v.myGreen);
307#ifdef COLOR_WITH_ALPHA_ARITH
308 this->myAlpha = clamp((int)this->myAlpha - (int)v.myAlpha);
309#endif
310 return *this;
311 }

References myAlpha, myBlue, myGreen, and myRed.

◆ operator<()

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

Definition at line 104 of file Color.cpp.

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}

References myAlpha, myBlue, myGreen, and myRed.

◆ operator<=()

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

Definition at line 128 of file Color.cpp.

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

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

◆ 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.

88{
89 return myRed == aColor.myRed
90 && myGreen == aColor.myGreen
91 && myBlue == aColor.myBlue
92 && myAlpha == aColor.myAlpha;
93}

References myAlpha, myBlue, myGreen, and myRed.

◆ operator>()

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

Definition at line 123 of file Color.cpp.

124{
125 return !this->operator<(aColor);
126}

References DGtal::operator<().

◆ operator>=()

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

Definition at line 135 of file Color.cpp.

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

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

◆ postscript()

string DGtal::Color::postscript ( ) const

Definition at line 150 of file Color.cpp.

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}

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

◆ r()

double DGtal::Color::r ( ) const

Referenced by getHSV(), and setFromHSV().

◆ red() [1/2]

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

◆ red() [2/2]

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

◆ RGBtoHSV()

static void DGtal::Color::RGBtoHSV ( double &  h,
double &  s,
double &  v,
const unsigned char  r,
const unsigned char  g,
const unsigned char  b 
)
static

Converts a color from the RGB space to the HSV (Hue,Saturation,Value) space.

Parameters
h(out) The hue of the color in [0..360)
s(out) The saturation of the color in [0..1].
v(out) The value of the color in [0..1].
rThe red component.
gThe green component.
bThe blue component.

Referenced by getHSV().

◆ 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}

◆ setFromHSV()

Color & DGtal::Color::setFromHSV ( const double  h,
const double  s,
const double  v 
)
inline

Set the color from HSV values

Parameters
hhue
ssaturation
vvalue
Returns
the color

Definition at line 184 of file Color.h.

185 {
186 double r,g,b;
187 Color::HSVtoRGB(r,g,b,h,s,v);
188 return this->setRGBf((float)r,(float)g,(float)b);
189 }
static void HSVtoRGB(double &r, double &g, double &b, double h, const double s, const double v)
Color & setRGBf(float red, float green, float blue, float alpha=1.0)
Definition: Color.cpp:65

References b(), g(), HSVtoRGB(), r(), and setRGBf().

◆ 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}

◆ setRGBf()

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

Definition at line 65 of file Color.cpp.

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}

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

◆ 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.

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}
static const Color None
Definition: Color.h:412

References None.

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

◆ 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.

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}

References None.

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

◆ 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.

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 "purple";
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 Purple
Definition: Color.h:424
static const Color Green
Definition: Color.h:417
static const Color Navy
Definition: Color.h:425
static const Color Gray
Definition: Color.h:414
static const Color Silver
Definition: Color.h:423
static const Color Red
Definition: Color.h:416
static const Color Lime
Definition: Color.h:418
static const Color White
Definition: Color.h:415
static const Color Blue
Definition: Color.h:419
static const Color Black
Definition: Color.h:413

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

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

◆ valid()

bool DGtal::Color::valid ( ) const

Field Documentation

◆ Aqua

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

Definition at line 426 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 420 of file Color.h.

Referenced by main().

◆ 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 418 of file Color.h.

Referenced by tikz().

◆ Magenta

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

Definition at line 421 of file Color.h.

Referenced by main(), and testAlphaThickSegmentConvexHullAndBox().

◆ myAlpha

unsigned char DGtal::Color::myAlpha
private

The opacity.

Definition at line 436 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 435 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 434 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 433 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 425 of file Color.h.

Referenced by tikz().

◆ None

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

◆ Purple

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

◆ Red

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

◆ Silver

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

Definition at line 423 of file Color.h.

Referenced by tikz().

◆ White

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

Definition at line 415 of file Color.h.

Referenced by main(), testGrayscaleColorMap(), testMesh(), testTickedColorMap(), and tikz().

◆ Yellow

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

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