Qt World Summit: Submit your Presentation

Understanding QColor's Grayscale formula

  • Looking at QColor's qGray documentation 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

  • Lifetime Qt Champion

    @bpetty Hi and welcome!
    You should rather ask Qt developers on their mailing list as this is user forum.

  • Lifetime Qt Champion

    Why do you ask the same question again when you got an answer here: https://www.qtcentre.org/threads/70230-Understanding-QColor-s-Grayscale-formula ?

  • Thank you @jsulm, I'll check out the mailing list.

    @Christian-Ehrlicher, I asked it again because I thought this forum might provide better exposure to the question. You are right that I did receive an answer in the other forum. It was about a month since I had originally asked it, and I had missed the response. Not sure I have the notifications setup correctly. I am glad you pointed it out.

    The answer seems to make sense, although it raises more questions than it answers. For example, why such an atypical implementation? Is the real reason it is off by so much on purpose, ex: Different White Point, or did someone think it might optimize better?

    There was also another part of the question about what it is actually doing. Are all of the RGB values assumed to be gamma corrected, thus providing a Luma function?

    It does seem closest to a 601 approximation, but since there are a 1000 of these magic ratios floating around, I might confirm on the dev mailing list.


Log in to reply