From 07a65fecbff0be2a1e89399ed38bb5cf46dac33b Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 25 Feb 2021 12:42:08 +0100 Subject: [PATCH] Fix logic problems with table based grayscale ICC profiles White-point was calculated wrongly and some tables could cause bad behavior in the tables. Change-Id: I24e8f5f3cc1306f5f898a4acbf7b008e26bd04e2 Reviewed-by: Eirik Aavitsland (cherry picked from commit f493d41722fc76a04f699ea26128fdf3d215d913) --- src/gui/painting/qcolortransfertable_p.h | 8 ++++---- src/gui/painting/qicc.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/painting/qcolortransfertable_p.h b/src/gui/painting/qcolortransfertable_p.h index fdf68b78da6..2d8f41e0860 100644 --- a/src/gui/painting/qcolortransfertable_p.h +++ b/src/gui/painting/qcolortransfertable_p.h @@ -136,7 +136,7 @@ public: return 1.0f; if (!m_table16.isEmpty()) { float v = x * 65535.0f; - uint32_t i = std::floor(resultLargerThan * (m_tableSize - 1)) + 1; + uint32_t i = std::floor(resultLargerThan * (m_tableSize - 1)); for ( ; i < m_tableSize; ++i) { if (m_table16[i] > v) break; @@ -145,14 +145,14 @@ public: return 1.0f; float y1 = m_table16[i - 1]; float y2 = m_table16[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); float fr = (v - y1) / (y2 - y1); return (i + fr) * (1.0f / (m_tableSize - 1)); } if (!m_table8.isEmpty()) { float v = x * 255.0f; - uint32_t i = std::floor(resultLargerThan * (m_tableSize - 1)) + 1; + uint32_t i = std::floor(resultLargerThan * (m_tableSize - 1)); for ( ; i < m_tableSize; ++i) { if (m_table8[i] > v) break; @@ -161,7 +161,7 @@ public: return 1.0f; float y1 = m_table8[i - 1]; float y2 = m_table8[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); float fr = (v - y1) / (y2 - y1); return (i + fr) * (1.0f / (m_tableSize - 1)); } diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp index 0acd458eff3..028e800c48e 100644 --- a/src/gui/painting/qicc.cpp +++ b/src/gui/painting/qicc.cpp @@ -759,7 +759,7 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace) } else { colorspaceDPtr->primaries = QColorSpace::Primaries::Custom; // Calculate chromaticity from xyz (assuming y == 1.0f). - float y = 1.0f / (1.0f + whitePoint.z - whitePoint.x); + float y = 1.0f / (1.0f + whitePoint.z + whitePoint.x); float x = whitePoint.x * y; QColorSpacePrimaries primaries(QColorSpace::Primaries::SRgb); primaries.whitePoint = QPointF(x,y);