23namespace Experimental {
35 explicit operator float()
const {
return fVal; }
71 using RGBA = std::array<float, 4>;
185 void GetHLS(
float &hue,
float &light,
float &satur) {
186 hue = light = satur = 0.;
188 float rnorm, gnorm, bnorm, minval, maxval, msum, mdiff;
198 rnorm = gnorm = bnorm = 0;
199 mdiff = maxval - minval;
200 msum = maxval + minval;
202 if (maxval != minval) {
204 gnorm = (maxval -
fGreen)/mdiff;
205 bnorm = (maxval -
fBlue)/mdiff;
211 if (light < 0.5) satur = mdiff/msum;
212 else satur = mdiff/(2.0 - msum);
215 else if (
fGreen == maxval) hue = 60.0 * (2.0 + rnorm - bnorm);
216 else hue = 60.0 * (4.0 + gnorm - rnorm);
218 if (hue > 360) hue = hue - 360;
225 float rh, rl, rs, rm1, rm2;
227 if (hue > 0) { rh = hue;
if (rh > 360) rh = 360; }
228 if (light > 0) { rl = light;
if (rl > 1) rl = 1; }
229 if (satur > 0) { rs = satur;
if (rs > 1) rs = 1; }
231 if (rl <= 0.5) rm2 = rl*(1.0 + rs);
232 else rm2 = rl + rs - rl*rs;
237 auto toRGB = [rm1, rm2] (
float h) {
238 if (
h > 360)
h =
h - 360;
239 if (
h < 0)
h =
h + 360;
240 if (
h < 60 )
return rm1 + (rm2-rm1)*
h/60;
241 if (
h < 180)
return rm2;
242 if (
h < 240)
return rm1 + (rm2-rm1)*(240-
h)/60;
248 fBlue = toRGB(rh-120);
Used to signal that this color shall be automatically chosen by the drawing routines,...
A color: Red|Green|Blue|Alpha, or a position in a RPalette.
constexpr RColor(const RGBA &rgba)
Initialize a RColor with red, green, blue and alpha component as an array.
friend bool operator==(const RColor &lhs, const RColor &rhs)
static constexpr RGBA kInvisible
bool AssertNotPalettePos() const
throw an exception if the color isn't specified as kRGBA or kAuto, the two cases where asking for RBG...
void SetAlpha(Alpha a)
For RGBA or auto colors, set the alpha component.
void SetRed(float r)
For RGBA or auto colors, set the red component.
void SetAlpha(float a)
For RGBA or auto colors, set the alpha component.
float GetAlpha() const
For RGBA or auto colors, get the alpha component (0..1).
@ kAuto
The color will be set upon drawing the canvas choosing a RPalette color, see RColor(Auto_t)
@ kRGBA
The color is defined as specific RGBA values.
@ kPalettePos
The color is defined as a value in the RFrame's RPalette.
bool IsAuto() const
Determine whether this RColor will be assigned a actual color upon drawing.
bool IsRGBA() const
Determine whether this RColor is storing RGBA (in contrast to an ordinal of a RPalette).
float GetRed() const
For RGBA or auto colors, get the red component (0..1).
static constexpr AutoTag kAuto
static constexpr Alpha kOpaque
An opaque color.
float GetBlue() const
For RGBA or auto colors, get the blue component (0..1).
static constexpr Alpha kTransparent
A completely transparent color.
constexpr RColor(AutoTag)
Constructs an automatically assigned color. Call as RColor col(RColor::kAuto).
EKind fKind
How the color is defined.
void SetRGBFromHLS(float hue, float light, float satur)
Set the Red Green and Blue (RGB) values from the Hue, Light, Saturation (HLS).
void SetBlue(float b)
For RGBA or auto colors, set the blue component.
float GetPaletteOrdinal() const
If this is an ordinal in a palette, resolve the.
std::array< float, 4 > RGBA
static constexpr RGBA kWhite
float GetGreen() const
For RGBA or auto colors, get the green component (0..1).
static constexpr RGBA kBlue
bool IsPaletteOrdinal() const
Determine whether this RColor is storing an ordinal of a RPalette (in contrast to RGBA).
constexpr RColor(float r, float g, float b, float alpha)
Initialize a RColor with red, green, blue and alpha component.
static constexpr RGBA kGreen
float fBlue
The "B" in RGBA (0 <= B <= 1). Unused if fKind != kRGBA.
static constexpr RGBA kBlack
constexpr RColor()=default
static constexpr RGBA kRed
float fGreen
The "G" in RGBA (0 <= G <= 1). Unused if fKind != kRGBA.
float fRedOrPalettePos
The "R" in RGBA (0 <= R <= 1), or the palette pos if fKind is kPalettePos.
constexpr RColor(float paletteOrdinal)
Initialize a RColor with a RPalette ordinal.
constexpr RColor(float r, float g, float b, Alpha alpha=kOpaque)
Initialize a RColor with red, green, blue and alpha component.
void GetHLS(float &hue, float &light, float &satur)
Return the Hue, Light, Saturation (HLS) definition of this RColor.
float fAlpha
The "A" in RGBA (0 <= A <= 1).
void SetGreen(float g)
For RGBA or auto colors, set the green component.
std::string ToAttributeString(const RColor &val)
Return a std::string representation of a RColor, suitable as input to ColorFromString().
RColor FromAttributeString(const std::string &str, const std::string &name, RColor *)
Initialize a RColor from a string value.
Namespace for new ROOT classes and functions.