0

In the code presented below the hsl hue component of the color has a diffrent value than expected.

For: r:255 g:168 b:177 it gives a hsl hue of 353 but on other web tools it yields 354

QColor rgb(c);
QColor hsl = rgb.toHsl();
QColor hsv = rgb.toHsv();

// RGB
int r = rgb.red();
int g = rgb.green();
int b = rgb.blue();

// HSB
int hslh = qMax(hsl.hslHue(), 0);
int hsls = hsl.hslSaturation();
int hsll = hsl.lightness();

Is this a known problem?

László Papp
  • 51,870
  • 39
  • 111
  • 135
SiWM
  • 90
  • 1
  • 9

1 Answers1

1

The issue seems to be simply how Qt rounds the colour component values when requesting an integer output. To illustrate on your example:

QColor col(255,168,177);
std::cout << "hue_float " << col.hslHueF()*360.0f << std::endl;
std::cout << "hue_int " << col.hslHue() << std::endl;

Outputs:

hue_float 353.79
hue_int 353
Martin Prazak
  • 1,476
  • 12
  • 20