diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/painting/qdrawhelper.cpp | 2 | ||||
| -rw-r--r-- | src/gui/painting/qdrawhelper_p.h | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 141688b8264..8aef64c7801 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -274,7 +274,7 @@ static const uint *QT_FASTCALL convertFromARGB32PM(uint *buffer, const uint *src if (!layout->premultiplied) { for (int i = 0; i < count; ++i) - buffer[i] = qAlpha(src[i]) == 255 ? src[i] : INV_PREMUL(src[i]); + buffer[i] = INV_PREMUL(src[i]); src = buffer; } for (int i = 0; i < count; ++i) { diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 6af4aa4943e..4b11a8e92b2 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -691,12 +691,16 @@ static Q_ALWAYS_INLINE uint BYTE_MUL_RGB16_32(uint x, uint a) { return t; } -#define INV_PREMUL(p) \ - (qAlpha(p) == 0 ? 0 : \ - ((qAlpha(p) << 24) \ - | (((255*qRed(p))/ qAlpha(p)) << 16) \ - | (((255*qGreen(p)) / qAlpha(p)) << 8) \ - | ((255*qBlue(p)) / qAlpha(p)))) +static Q_ALWAYS_INLINE uint INV_PREMUL(uint p) { + const uint alpha = qAlpha(p); + if (alpha == 255) + return p; + if (alpha == 0) + return 0; + // (p*(0x00ff00ff/alpha)) >> 16 == (p*255)/alpha for all p and alpha <= 256. + const uint invAlpha = 0x00ff00ffU / alpha; + return qRgba((qRed(p)*invAlpha)>>16, (qGreen(p)*invAlpha)>>16, (qBlue(p)*invAlpha)>>16, alpha); +} struct quint24 { quint24(uint value); |
