Hello,
I'm playing around with an application were I use a QImage with a RGB32 format.
I used the QColor method saturation() and value() to compute these values (I do not
need hue), and found out that these functions (and naturally also getHSV()) are incredibly slow.
I wrote a straightforward implementation of a RGB-to-SV conversion, which on my
PC is 12-15 times faster than using QColor's getHSV() method.
Wikipedia has a good explanation of HSV: http://en.wikipedia.org/wiki/HSL_and_HSV
The only difference between my function and the QColor method(s) is that
the LSB of 'saturation' is not always the same. I guess this is a rounding issue.
So my question is:
Are these QColor methods so slow or am I doing something wrong?
(The Qt version I'm using is 4.8.2 (mingw open source) on Windows XP.)
My function looks like this:
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned long u32;
//--------------------------------------------------------------
u8 max3(u8 a, u8 b, u8 c)
{
u8 max = (a > b) ? a : b;
max = (max > c) ? max : c;
return max;
}
//--------------------------------------------------------------
u8 min3(u8 a, u8 b, u8 c)
{
u8 min = (a > b) ? b : a;
min = (min > c) ? c : min;
return min;
}
//--------------------------------------------------------------
u16 rgb_to_sv(u32 rgb)
{
u8 red = (rgb >> 16) & 0xff;
u8 green = (rgb >> 8) & 0xff;
u8 blue = rgb & 0xff;
u8 max = max3(red,green,blue);
u8 min = min3(red,green,blue);
if(max == 0) return 0;
double saturation = (double)(max - min)/max;
double tmp = saturation * 255;
tmp += 0.5;
u8 saturation_u8 = tmp;
return (saturation_u8 << 8) + max; // value = max
}
{
u8 max = (a > b) ? a : b;
max = (max > c) ? max : c;
return max;
}
//--------------------------------------------------------------
u8 min3(u8 a, u8 b, u8 c)
{
u8 min = (a > b) ? b : a;
min = (min > c) ? c : min;
return min;
}
//--------------------------------------------------------------
u16 rgb_to_sv(u32 rgb)
{
u8 red = (rgb >> 16) & 0xff;
u8 green = (rgb >> 8) & 0xff;
u8 blue = rgb & 0xff;
u8 max = max3(red,green,blue);
u8 min = min3(red,green,blue);
if(max == 0) return 0;
double saturation = (double)(max - min)/max;
double tmp = saturation * 255;
tmp += 0.5;
u8 saturation_u8 = tmp;
return (saturation_u8 << 8) + max; // value = max
}
//--------------------------------------------------------------
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest