diff --git a/src/core/colorpipeline.cpp b/src/core/colorpipeline.cpp index 1f4c8f278d..0aa0173fdf 100644 --- a/src/core/colorpipeline.cpp +++ b/src/core/colorpipeline.cpp @@ -152,9 +152,25 @@ void ColorPipeline::addInverseTransferFunction(TransferFunction tf, double refer } } +static bool isFuzzyIdentity(const QMatrix4x4 &mat) +{ + // matrix calculations with floating point numbers can result in very small errors + // -> ignore them, as that just causes inefficiencies and more rounding errors + constexpr float maxResolution = 0.0000001; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + const float targetValue = i == j ? 1 : 0; + if (std::abs(mat(i, j) - targetValue) > maxResolution) { + return false; + } + } + } + return true; +} + void ColorPipeline::addMatrix(const QMatrix4x4 &mat, const ValueRange &output) { - if (mat.isIdentity()) { + if (isFuzzyIdentity(mat)) { return; } if (!ops.empty()) {