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

Implement gamma-corrected blending

    XMLWordPrintable

Details

    Description

      The simple method that computes the alpha blending and pixel coverage in Qt and several other libraries and software involves this formula:

      /* a ........... alpha or "coverage" value.
       * src ...... source colour.
       * dest ...... destination colour.
       * result ........... output colour. */
      
      result = src*alpha + dest*( 1.0 - alpha );

      The problem is that this formula is doing a linear blend of colours that are in a non-linear space (sRGB).
      This causes artifacts such as the unexpected darkening of blending areas between bright colours like pure red and pure green.

      More examples and analysis of the artifacts produced by the blending method used in Qt can be seen in this Linear gamma colour mixing article.

      The correct formula needs to convert the colours first to linear space, perform the blend and then convert them back to sRGB space.

      #define GAMMA 2.2
      
      temp = pow( src, GAMMA )*alpha + pow( dest, GAMMA )*( 1.0 - alpha );
      result = pow( temp, 1.0 / GAMMA );

      The power conversions can be replaced with sampling of static look-up tables, guaranteeing precision and performance.
      Qt has some gamma table code in the function 'rgbBlendPixel' of 'src/gui/painting/qdrawhelper.cpp,' but the rest of the painting functionality does not use this.

      The low-level programming for composition modes and blend functions is affected by this.

      Files involved (in 'src/gui/painting/'):

      • qblendfunctions_p.h
      • qblendfunctions.cpp
      • qdrawhelper_p.h
      • qdrawhelper.cpp
      • qdrawhelper_sse2.cpp
      • qdrawherlper_ssse3.cpp
      • qdrawherlper_mips_dsp.cpp
      • qdrawherlper_neon.cpp

      REFERENCES:

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sletta Gunnar Sletta
              kryzon Rafael Navega
              Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes