Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84168

Inconsisent rounding for QColor rgb

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.12.9, 5.15.0 RC
    • Fix Version/s: 5.15.1, 6.0.0
    • Component/s: GUI: Painting
    • Labels:
      None
    • Environment:
      Windows 10
    • Platform/s:
      All
    • Commits:
      0e526ed3f93f9aab1f499f80d703fc4e93314223 (qt/qtbase/5.15)

      Description

      It appears Qt is using different policy when convert color component.

      In most of the code it is using qRound to calculate different component, but for integral value it is using floor to get the component (in unsigned short fixed point). That result in some weird result, for example:

      auto hsl = QColor::fromHslF(179 / 360.0, 62 / 100.0, 37 / 100.0);
      auto rgb = hsl.toRgb();
      qDebug() << "hsl:" << hsl;
      qDebug() << "rgb:" << rgb;
      qDebug() << "rf:" << rgb.redF() * 255 << "gf:" << rgb.greenF() * 255 << "bf:" << rgb.blueF() * 255;
      qDebug() << "ri:" << rgb.red() << "gi:" << rgb.green() << "bi:" << rgb.blue(); 

      that prints:

      hsl: QColor(AHSL 1, 0.497222, 0.620005, 0.370001) 
      rgb: QColor(ARGB 1, 0.140597, 0.599405, 0.59176)
      rf: 35.8521 gf: 152.848 bf: 150.899
      ri: 35 gi: 153 bi: 151

       

      as you can see 35.8521 becomes 35, while 152.848 becomes 153 

       

        Attachments

        For Gerrit Dashboard: QTBUG-84168
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            allan.jensen Allan Sandfeld Jensen
            Reporter:
            steve.k.chiu Steve K. Chiu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes