Understanding QColor's Grayscale formula
Looking at QColor's qGray documentation http://doc.qt.io/qt-4.8/qcolor.html#qGray on how it converts RGB to Grayscale, it uses this formula:
(r * 11 + g * 16 + b * 5)/32
There are a few peculiarities here.
1. I can find no reference to this formula outside of this class in Qt. It is used nowhere, in any article on the subject that I can find.
2. The QColor documentation does not once talk about Gamma Correction, nor does it directly use the term Color Space.
All of that to ask, where is this grayscale conversion formula coming from and does it assume the RGB values are Linear or Non-Linear/Gamma Corrected?
Thank you
Re: Understanding QColor's Grayscale formula
Does anyone know who I can reach out to for this question? Do they have an issue tracker for their repo somewhere?
Re: Understanding QColor's Grayscale formula
Quote:
Originally Posted by
bpetty
Does anyone know who I can reach out to for this question?
One option might be to look at the code.
Best way to do that is the Woboq Code Browser
E.g. Code for QColor
Quote:
Originally Posted by
bpetty
Do they have an issue tracker for their repo somewhere?
Yes, here
Cheers,
_
Re: Understanding QColor's Grayscale formula
Quote:
Originally Posted by
bpetty
Looking at
QColor's qGray documentation
http://doc.qt.io/qt-4.8/qcolor.html#qGray on how it converts RGB to Grayscale, it uses this formula:
(r * 11 + g * 16 + b * 5)/32
There are a few peculiarities here.
1. I can find no reference to this formula outside of this class in Qt. It is used nowhere, in any article on the subject that I can find.
It looks like an approximation of the RGB->Luma conversion in ITU BT.601.
Code:
Y = 0.299 R + 0.587 G + 0.114 B
Common approximations are:
Code:
Y = 0.33 R + 0.5 G + 0.16 B ( computed like Y = (R+R+G+G+G+B)/6 )
Y = 0.375 R + 0.5 G + 0.125 B ( computed like Y = (R+R+R+G+G+G+G+B) >> 3 )
The equation in QColor is:
Code:
Y = 11/32 R + 16/32 G + 5/32 B = 0.343750 R + 0.5 G + 0.156250 B
which is in between the two.