Krita Source Code Documentation
Loading...
Searching...
No Matches
KisScreentoneBrightnessContrastFunctions.cpp
Go to the documentation of this file.
1/*
2 * KDE. Krita Project.
3 *
4 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
10
12
13BrightnessContrast::BrightnessContrast(qreal brightness, qreal contrast)
14{
15 if (contrast > 0.0) {
16 if (qFuzzyCompare(contrast, 1.0)) {
17 m_m = 10000.0;
18 } else {
19 m_m = 1.0 / (1.0 - contrast);
20 }
21 m_b = -m_m * (contrast / 2.0);
22 } else {
23 m_m = 1.0 + contrast;
24 m_b = -contrast / 2.0;
25 }
26 m_b += (1.0 - m_b) * brightness;
27}
28
30{
31 return m_m * x + m_b;
32}
33
34Threshold::Threshold(qreal threshold)
35 : m_threshold(threshold)
36 , m_thresholdIsOne(qFuzzyCompare(threshold, 1.0))
37{}
38
39qreal Threshold::operator()(qreal x) const
40{
41 // In the extreme case where the threshold value is 1.0, we need to compare
42 // the value with 1.0, otherwise a value of 1.0 with a threshold of 1.0 will
43 // produce 1.0 as an output. The effect would be some white dots in an all
44 // black image, something not desirable.
45 return m_thresholdIsOne || x < m_threshold ? 0.0 : 1.0;
46}
47
48}
static bool qFuzzyCompare(half p1, half p2)