25 #define M_PI 3.1415926535897932384626433832795
49 unsigned char val8 = 0;
50 unsigned int val32 = 0;
53 val8 =
static_cast<unsigned char>(
r * 255);
57 val8 =
static_cast<unsigned char>(
g * 255);
61 val8 =
static_cast<unsigned char>(
b * 255);
65 val8 =
static_cast<unsigned char>(
a * 255);
76 unsigned int val32 = val;
79 r = ((val32 >> 24) & 0xFF) / 255.0f;
82 g = ((val32 >> 16) & 0xFF) / 255.0f;
85 b = ((val32 >> 8) & 0xFF) / 255.0f;
88 a = (val32 & 0xFF) / 255.0f;
97 float min = std::min<float>(std::min<float>(
c.r,
c.g),
c.b);
98 float max = std::max<float>(std::max<float>(
c.r,
c.g),
c.b);
101 float delta = max -
min;
115 saturation = delta / max;
119 hue = ((
c.g -
c.b) / delta) / 6.0f;
123 hue = (2.0f + (
c.b -
c.r) / delta) / 6.0f;
127 hue = (4.0f + (
c.r -
c.g) / delta) / 6.0f;
144 float s = saturation;
145 float br = brightness;
161 s = std::min<float>(
s, 1.0f);
162 s = std::max<float>(
s, 0.0f);
163 br = std::min<float>(br, 1.0f);
164 br = std::max<float>(br, 0.0f);
181 float hueDomain = h * 6.0f;
182 if (hueDomain >= 6.0f)
187 unsigned short domain = (
unsigned short)hueDomain;
188 float f1 = br * (1 -
s);
189 float f2 = br * (1 -
s * (hueDomain - domain));
190 float f3 = br * (1 -
s * (1 - (hueDomain - domain)));
284 const float* saturationRange,
const float* valueRange,
287 outColors.resize(nbColors);
289 float hueStep = (hueRange[1] - hueRange[0]) / (nbColors - 1);
290 float saturationStep = (saturationRange[1] - saturationRange[0]) / (nbColors - 1);
291 float valueStep = (valueRange[1] - valueRange[0]) / (nbColors - 1);
293 float h = NAN,
s = NAN, v = NAN;
295 for (
unsigned int i = 0; i < nbColors; ++i)
297 h = hueRange[0] + i * hueStep;
298 s = saturationRange[0] + i * saturationStep;
299 v = valueRange[0] + i * valueStep;
302 outColors[i].r = (1.0f - cos(rgb.
r *
static_cast<float>(
M_PI))) * 0.5f;
303 outColors[i].g = (1.0f - cos(rgb.
g *
static_cast<float>(
M_PI))) * 0.5f;
304 outColors[i].b = (1.0f - cos(rgb.
b *
static_cast<float>(
M_PI))) * 0.5f;
309 const float* saturationRange,
const float* valueRange,
312 outColors.resize(nbColors);
314 float hueStep = (hueRange[1] - hueRange[0]) / (nbColors - 1);
315 float saturationStep = (saturationRange[1] - saturationRange[0]) / (nbColors - 1);
316 float valueStep = (valueRange[1] - valueRange[0]) / (nbColors - 1);
318 float h = NAN,
s = NAN, v = NAN;
320 for (
unsigned int i = 0; i < nbColors; ++i)
322 h = hueRange[0] + i * hueStep;
323 s = saturationRange[0] + i * saturationStep;
324 v = valueRange[0] + i * valueStep;
328 outColors[i].r = rgb.
r + 0.5f / 255.0f;
329 outColors[i].g = rgb.
g + 0.5f / 255.0f;
330 outColors[i].b = rgb.
b + 0.5f / 255.0f;
335 const float* saturationRange,
const float* valueRange,
338 outColors.resize(nbColors);
340 float hueStep = (hueRange[1] - hueRange[0]) / (nbColors - 1);
341 float saturationStep = (saturationRange[1] - saturationRange[0]) / (nbColors - 1);
342 float valueStep = (valueRange[1] - valueRange[0]) / (nbColors - 1);
344 float h = NAN,
s = NAN, v = NAN;
346 for (
unsigned int i = 0; i < nbColors; ++i)
348 h = hueRange[0] + i * hueStep;
349 s = saturationRange[0] + i * saturationStep;
350 v = valueRange[0] + i * valueStep;
353 outColors[i].r = std::sqrt(rgb.
r) + 0.5f / 255.0f;
354 outColors[i].g = std::sqrt(rgb.
g) + 0.5f / 255.0f;
355 outColors[i].b = std::sqrt(rgb.
b) + 0.5f / 255.0f;
362 outColors.resize(nbColors);
364 float colors =
static_cast<float>(nbColors);
365 for (
unsigned int i = 0; i < nbColors; ++i)
367 OColor& color = outColors[i];
368 color.
r = exp(-(colors - i) * (colors - i) * alpha2 * alpha2 / (colors * colors));
369 color.
g = exp(-(i - colors / 2) * (i - colors / 2) * alpha1 * alpha1 / (colors * colors));
370 color.
b = exp(-(i * i * alpha2 * alpha2 / (colors * colors)));
static const OColor GREEN
unsigned int getAsRGBA() const
static const OColor BLACK
static const OColor WHITE
void getAsHSB(float &hue, float &saturation, float &brightness) const
static const float equality_threshold
static const OColor YELLOW
void setAsHSB(const float hue, const float saturation, const float brightness)
static bool float_eq(float a, float b, float epsilon=equality_threshold)
void setAsRGBA(const unsigned int val)
static const OColor MAGENTA
bool operator==(const OColor &other) const
static void getLinearColorTable(const unsigned int &nbColors, const float *hueRange, const float *saturationRange, const float *valueRange, OLookupTable &outColors)
Generation de la table de couleurs basee sur une rampe lineaire ( y = x+0.5/255 )
static void getGaussColorTable(const unsigned int &nbColors, const float &alpha1, const float &alpha2, OLookupTable &outColors)
Generation de la table de couleurs a partir d'une repartition gaussienne en R, G, B.
static void getSqrtColorTable(const unsigned int &nbColors, const float *hueRange, const float *saturationRange, const float *valueRange, OLookupTable &outColors)
Generation de la table de couleurs basee sur une rampe sqrt ( y = sqrt(x)+0.5/255 )
static void getSCurveColorTable(const unsigned int &nbColors, const float *hueRange, const float *saturationRange, const float *valueRange, OLookupTable &outColors)
Generation de la table de couleurs basee sur une rampe S-Curve ( y = (1-cos(pi*x))/2 )
std::vector< OColor > OLookupTable
Collection de OColor.