summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-25 12:42:08 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-25 16:08:44 +0100
commitf493d41722fc76a04f699ea26128fdf3d215d913 (patch)
tree555d88e091aaf5e7567243588b2978e1555f155a /src
parent0e22001a3bb070d4e9956e89543ec0e5ac6f23f8 (diff)
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 <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/painting/qcolortransfertable_p.h10
-rw-r--r--src/gui/painting/qicc.cpp2
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<uint32_t>(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<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))) + 1;
+ uint32_t i = static_cast<uint32_t>(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<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))) + 1;
+ uint32_t i = static_cast<uint32_t>(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);