File indexing completed on 2024-06-23 04:27:06
0001 /* 0002 * KDE. Krita Project. 0003 * 0004 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "KisScreentoneBrightnessContrastFunctions.h" 0010 0011 namespace KisScreentoneBrightnessContrastFunctions { 0012 0013 BrightnessContrast::BrightnessContrast(qreal brightness, qreal contrast) 0014 { 0015 if (contrast > 0.0) { 0016 if (qFuzzyCompare(contrast, 1.0)) { 0017 m_m = 10000.0; 0018 } else { 0019 m_m = 1.0 / (1.0 - contrast); 0020 } 0021 m_b = -m_m * (contrast / 2.0); 0022 } else { 0023 m_m = 1.0 + contrast; 0024 m_b = -contrast / 2.0; 0025 } 0026 m_b += (1.0 - m_b) * brightness; 0027 } 0028 0029 qreal BrightnessContrast::operator()(qreal x) const 0030 { 0031 return m_m * x + m_b; 0032 } 0033 0034 Threshold::Threshold(qreal threshold) 0035 : m_threshold(threshold) 0036 , m_thresholdIsOne(qFuzzyCompare(threshold, 1.0)) 0037 {} 0038 0039 qreal Threshold::operator()(qreal x) const 0040 { 0041 // In the extreme case where the threshold value is 1.0, we need to compare 0042 // the value with 1.0, otherwise a value of 1.0 with a threshold of 1.0 will 0043 // produce 1.0 as an output. The effect would be some white dots in an all 0044 // black image, something not desirable. 0045 return m_thresholdIsOne || x < m_threshold ? 0.0 : 1.0; 0046 } 0047 0048 }