diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-11-21 13:33:55 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-01-24 20:42:32 +0000 |
commit | 21f27c9a4d0f2ab0976c144f631c9171c899014b (patch) | |
tree | 01270b13f790565a30ba1a6931e3b786901d9f42 /src/gui/painting | |
parent | d2758b2f1dd88d273ff70864a0dd03a7c4e9dc78 (diff) |
Enable gamma-correction on a face-by-face basis
Changes how we control if gamma-correction is done, and enables it for
the freetype CFF engine when stem-darkening is available.
The new code replaces existing hacks to force gamma-correction off
when using Freetype on X11 and Windows.
Change-Id: Ic703ca6965a3d81b204349e10f406c991b292edd
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qdrawhelper.cpp | 30 | ||||
-rw-r--r-- | src/gui/painting/qdrawhelper_neon.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qdrawhelper_neon_p.h | 2 | ||||
-rw-r--r-- | src/gui/painting/qdrawhelper_p.h | 4 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 15 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_raster_p.h | 2 |
6 files changed, 27 insertions, 28 deletions
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 8a9f8b8bdc..6f82ab871c 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -5547,7 +5547,7 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *map, int mapWidth, int mapHeight, int mapStride, - const QClipData *) + const QClipData *, bool /*useGammaCorrection*/) { const quint16 c = color.toRgb16(); quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x; @@ -5572,18 +5572,16 @@ static void qt_alphamapblit_quint16(QRasterBuffer *rasterBuffer, } } -static inline void rgbBlendPixel(quint32 *dst, int coverage, QRgba64 slinear, const QColorProfile *colorProfile) +static inline void rgbBlendPixel(quint32 *dst, int coverage, QRgba64 slinear, const QColorProfile *colorProfile, bool useGammaCorrection) { // Do a gammacorrected RGB alphablend... - const QRgba64 dlinear = colorProfile->toLinear64(*dst); + const QRgba64 dlinear = useGammaCorrection ? colorProfile->toLinear64(*dst) : QRgba64::fromArgb32(*dst); QRgba64 blend = rgbBlend(dlinear, slinear, coverage); - *dst = colorProfile->fromLinear64(blend); + *dst = useGammaCorrection ? colorProfile->fromLinear64(blend) : toArgb32(blend); } -Q_GUI_EXPORT bool qt_needs_a8_gamma_correction = false; - static inline void grayBlendPixel(quint32 *dst, int coverage, QRgba64 slinear, const QColorProfile *colorProfile) { // Do a gammacorrected gray alphablend... @@ -5598,7 +5596,7 @@ static void qt_alphamapblit_uint32(QRasterBuffer *rasterBuffer, int x, int y, quint32 color, const uchar *map, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip) + const QClipData *clip, bool useGammaCorrection) { const quint32 c = color; const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32); @@ -5610,7 +5608,7 @@ static void qt_alphamapblit_uint32(QRasterBuffer *rasterBuffer, const QRgba64 slinear = colorProfile->toLinear64(c); bool opaque_src = (qAlpha(color) == 255); - bool doGrayBlendPixel = opaque_src && qt_needs_a8_gamma_correction; + bool doGrayBlendPixel = opaque_src && useGammaCorrection; if (!clip) { quint32 *dest = reinterpret_cast<quint32*>(rasterBuffer->scanLine(y)) + x; @@ -5680,9 +5678,9 @@ static void qt_alphamapblit_argb32(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *map, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip) + const QClipData *clip, bool useGammaCorrection) { - qt_alphamapblit_uint32(rasterBuffer, x, y, color.toArgb32(), map, mapWidth, mapHeight, mapStride, clip); + qt_alphamapblit_uint32(rasterBuffer, x, y, color.toArgb32(), map, mapWidth, mapHeight, mapStride, clip, useGammaCorrection); } #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN @@ -5690,9 +5688,9 @@ static void qt_alphamapblit_rgba8888(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *map, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip) + const QClipData *clip, bool useGammaCorrection) { - qt_alphamapblit_uint32(rasterBuffer, x, y, ARGB2RGBA(color.toArgb32()), map, mapWidth, mapHeight, mapStride, clip); + qt_alphamapblit_uint32(rasterBuffer, x, y, ARGB2RGBA(color.toArgb32()), map, mapWidth, mapHeight, mapStride, clip, useGammaCorrection); } #endif @@ -5704,7 +5702,7 @@ inline static int qRgbAvg(QRgb rgb) static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uint *src, int mapWidth, int mapHeight, int srcStride, - const QClipData *clip) + const QClipData *clip, bool useGammaCorrection) { const quint32 c = color.toArgb32(); @@ -5714,7 +5712,7 @@ static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer, if (!colorProfile) return; - const QRgba64 slinear = colorProfile->toLinear64(c); + const QRgba64 slinear = useGammaCorrection ? colorProfile->toLinear64(c) : color; if (sa == 0) return; @@ -5729,7 +5727,7 @@ static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer, dst[i] = c; } else if (coverage != 0xff000000) { if (dst[i] >= 0xff000000) { - rgbBlendPixel(dst+i, coverage, slinear, colorProfile); + rgbBlendPixel(dst+i, coverage, slinear, colorProfile, useGammaCorrection); } else { // Give up and do a naive blend. const int a = qRgbAvg(coverage); @@ -5765,7 +5763,7 @@ static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer, dst[xp] = c; } else if (coverage != 0xff000000) { if (dst[xp] >= 0xff000000) { - rgbBlendPixel(dst+xp, coverage, slinear, colorProfile); + rgbBlendPixel(dst+xp, coverage, slinear, colorProfile, useGammaCorrection); } else { // Give up and do a naive blend. const int a = qRgbAvg(coverage); diff --git a/src/gui/painting/qdrawhelper_neon.cpp b/src/gui/painting/qdrawhelper_neon.cpp index a833520b00..cdb374f823 100644 --- a/src/gui/painting/qdrawhelper_neon.cpp +++ b/src/gui/painting/qdrawhelper_neon.cpp @@ -539,7 +539,7 @@ void qt_alphamapblit_quint16_neon(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *bitmap, int mapWidth, int mapHeight, int mapStride, - const QClipData *) + const QClipData *, bool /*useGammaCorrection*/) { quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x; const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16); diff --git a/src/gui/painting/qdrawhelper_neon_p.h b/src/gui/painting/qdrawhelper_neon_p.h index 3cf949fc32..40475a9bde 100644 --- a/src/gui/painting/qdrawhelper_neon_p.h +++ b/src/gui/painting/qdrawhelper_neon_p.h @@ -91,7 +91,7 @@ void qt_alphamapblit_quint16_neon(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *bitmap, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip); + const QClipData *clip, bool /*useGammaCorrection*/); void qt_scale_image_argb32_on_rgb16_neon(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 933da56095..f35b763f93 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -111,13 +111,13 @@ typedef void (*AlphamapBlitFunc)(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uchar *bitmap, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip); + const QClipData *clip, bool useGammaCorrection); typedef void (*AlphaRGBBlitFunc)(QRasterBuffer *rasterBuffer, int x, int y, const QRgba64 &color, const uint *rgbmask, int mapWidth, int mapHeight, int mapStride, - const QClipData *clip); + const QClipData *clip, bool useGammaCorrection); typedef void (*RectFillFunc)(QRasterBuffer *rasterBuffer, int x, int y, int width, int height, diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 647bd5cb2c..68b8d78ac6 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -2555,7 +2555,7 @@ QRasterBuffer *QRasterPaintEngine::rasterBuffer() /*! \internal */ -void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h) +void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h, bool useGammaCorrection) { Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -2610,14 +2610,14 @@ void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx } else if (depth == 8) { if (s->penData.alphamapBlit) { s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color, - scanline, w, h, bpl, 0); + scanline, w, h, bpl, 0, useGammaCorrection); return; } } else if (depth == 32) { // (A)RGB Alpha mask where the alpha component is not used. if (s->penData.alphaRGBBlit) { s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color, - (const uint *) scanline, w, h, bpl / 4, 0); + (const uint *) scanline, w, h, bpl / 4, 0, useGammaCorrection); return; } } @@ -2646,10 +2646,10 @@ void QRasterPaintEngine::alphaPenBlt(const void* src, int bpl, int depth, int rx } if (depth == 8) s->penData.alphamapBlit(rb, rx, ry, s->penData.solid.color, - scanline, w, h, bpl, clip); + scanline, w, h, bpl, clip, useGammaCorrection); else if (depth == 32) s->penData.alphaRGBBlit(rb, rx, ry, s->penData.solid.color, - (const uint *) scanline, w, h, bpl / 4, clip); + (const uint *) scanline, w, h, bpl / 4, clip, useGammaCorrection); return; } } @@ -2807,7 +2807,8 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, alphaPenBlt(alphaMap->constBits(), alphaMap->bytesPerLine(), alphaMap->depth(), qFloor(positions[i].x) + offset.x(), qRound(positions[i].y) + offset.y(), - alphaMap->width(), alphaMap->height()); + alphaMap->width(), alphaMap->height(), + fontEngine->expectsGammaCorrectedBlending()); fontEngine->unlockAlphaMapForGlyph(); } @@ -2868,7 +2869,7 @@ bool QRasterPaintEngine::drawCachedGlyphs(int numGlyphs, const glyph_t *glyphs, drawImage(QPoint(x, y), QImage(glyphBits, c.w, c.h, bpl, image.format())); s->matrix = originalTransform; } else { - alphaPenBlt(glyphBits, bpl, depth, x, y, c.w, c.h); + alphaPenBlt(glyphBits, bpl, depth, x, y, c.w, c.h, fontEngine->expectsGammaCorrectedBlending()); } } } diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 59213220a6..d0b82b3a93 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -225,7 +225,7 @@ public: #endif QRasterBuffer *rasterBuffer(); - void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h); + void alphaPenBlt(const void* src, int bpl, int depth, int rx,int ry,int w,int h, bool useGammaCorrection); Type type() const Q_DECL_OVERRIDE { return Raster; } |