diff options
author | Anders Hafreager <andershaf@gmail.com> | 2018-02-19 20:51:02 +0100 |
---|---|---|
committer | Anders Hafreager <andershaf@gmail.com> | 2018-02-22 13:03:45 +0000 |
commit | e813fb36e782c5e0ab7c25b9c069cee709692506 (patch) | |
tree | 48c69d8b8a9fb647027c1f2a3e0035659360d7e3 | |
parent | 05185633763b9916331be868f33a36018dcf2b4b (diff) |
Fix color scaling in copyGLFramebufferDataToImage
Previous implementation used a component conversion for
QAbstractTexture::RGBA32F (when GL_TYPE is GL_FLOAT) which results in a
non-linear mapping from [0,1] to [0,127]. A non-linear mapping should
only be used for some GL_TYPE other than GL_FLOAT.
See https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/
glReadPixels.xhtml for more.
This change maps color linearly to the range [0,255] when
QAbstractTexture::TextureFormat is QAbstractTexture::RGBA32F.
Task-number: QTBUG-66514
Change-Id: I4aa36b59acd193c7342ba4b0577f132e0c19ef85
Reviewed-by: Svenn-Arne Dragly <svenn-arne.dragly@qt.io>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/render/graphicshelpers/graphicscontext.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index 5c3128f30..a8fdcefa9 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -1829,9 +1829,9 @@ static void copyGLFramebufferDataToImage(QImage &img, const uchar *srcData, uint uchar *dstScanline = img.scanLine(i); float *pSrc = (float*)srcScanline; for (uint j = 0; j < width; j++) { - *dstScanline++ = (uchar)(255.0f * (pSrc[4*j+2] / (1.0f + pSrc[4*j+2]))); - *dstScanline++ = (uchar)(255.0f * (pSrc[4*j+1] / (1.0f + pSrc[4*j+1]))); - *dstScanline++ = (uchar)(255.0f * (pSrc[4*j+0] / (1.0f + pSrc[4*j+0]))); + *dstScanline++ = (uchar)(255.0f * qBound(0.0f, pSrc[4*j+2], 1.0f)); + *dstScanline++ = (uchar)(255.0f * qBound(0.0f, pSrc[4*j+1], 1.0f)); + *dstScanline++ = (uchar)(255.0f * qBound(0.0f, pSrc[4*j+0], 1.0f)); *dstScanline++ = (uchar)(255.0f * qBound(0.0f, pSrc[4*j+3], 1.0f)); } srcScanline -= stride; |