Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Understanding QColor's Grayscale formula
Forum Updated to NodeBB v4.3 + New Features

Understanding QColor's Grayscale formula

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bpetty
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • B bpetty

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • B Offline
          B Offline
          bpetty
          wrote on last edited by
          #4

          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.

          Thanks!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved