From f493d41722fc76a04f699ea26128fdf3d215d913 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. Pick-to: 6.1 6.0 5.15 Change-Id: I24e8f5f3cc1306f5f898a4acbf7b008e26bd04e2 Reviewed-by: Eirik Aavitsland --- src/gui/painting/qcolortransfertable_p.h | 10 +++++----- src/gui/painting/qicc.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/painting/qcolortransfertable_p.h b/src/gui/painting/qcolortransfertable_p.h index 2812ed5685..bbc9f08dcc 100644 --- a/src/gui/painting/qcolortransfertable_p.h +++ b/src/gui/painting/qcolortransfertable_p.h @@ -119,7 +119,7 @@ public: x = std::clamp(x, 0.0f, 1.0f); x *= m_tableSize - 1; const uint32_t lo = static_cast(std::floor(x)); - const uint32_t hi = std::min(lo + 1, m_tableSize); + const uint32_t hi = std::min(lo + 1, m_tableSize - 1); const float frac = x - lo; if (!m_table16.isEmpty()) return (m_table16[lo] * (1.0f - frac) + m_table16[hi] * frac) * (1.0f/65535.0f); @@ -138,28 +138,28 @@ public: return 1.0f; if (!m_table16.isEmpty()) { const float v = x * 65535.0f; - uint32_t i = static_cast(std::floor(resultLargerThan * (m_tableSize - 1))) + 1; + uint32_t i = static_cast(std::floor(resultLargerThan * (m_tableSize - 1))); auto it = std::lower_bound(m_table16.cbegin() + i, m_table16.cend(), v); i = it - m_table16.cbegin(); if (i >= m_tableSize - 1) return 1.0f; const float y1 = m_table16[i - 1]; const float y2 = m_table16[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); const float fr = (v - y1) / (y2 - y1); return (i + fr) * (1.0f / (m_tableSize - 1)); } if (!m_table8.isEmpty()) { const float v = x * 255.0f; - uint32_t i = static_cast(std::floor(resultLargerThan * (m_tableSize - 1))) + 1; + uint32_t i = static_cast(std::floor(resultLargerThan * (m_tableSize - 1))); auto it = std::lower_bound(m_table8.cbegin() + i, m_table8.cend(), v); i = it - m_table8.cbegin(); if (i >= m_tableSize - 1) return 1.0f; const float y1 = m_table8[i - 1]; const float y2 = m_table8[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); const 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 bacf76997f..25389121f3 100644 --- a/src/gui/painting/qicc.cpp +++ b/src/gui/painting/qicc.cpp @@ -757,7 +757,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);