Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.3.2
-
None
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
- relates to
-
QTBUG-45858 Support 16bpc image formats
- Closed