File indexing completed on 2025-02-23 04:12:35
0001 /* 0002 * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "KisDarkenOption.h" 0009 0010 #include <KisPaintOpOptionUtils.h> 0011 #include <KisStandardOptionData.h> 0012 #include <kis_paint_device.h> 0013 #include <kis_paint_information.h> 0014 #include <kis_painter.h> 0015 #include <kis_properties_configuration.h> 0016 0017 #include "kis_color_source.h" 0018 0019 namespace kpou = KisPaintOpOptionUtils; 0020 0021 0022 KisDarkenOption::KisDarkenOption(const KisPropertiesConfiguration *setting) 0023 : KisCurveOption(kpou::loadOptionData<KisDarkenOptionData>(setting)) 0024 { 0025 } 0026 0027 KoColor KisDarkenOption::apply(KisPainter * painter, const KisPaintInformation& info) const 0028 { 0029 if (!isChecked()) { 0030 return painter->paintColor(); 0031 } 0032 0033 KoColor darkened = painter->paintColor(); 0034 KoColor origColor = darkened; 0035 0036 // Darken docs aren't really clear about what exactly the amount param can have as value... 0037 quint32 darkenAmount = (qint32)(255 - 255 * computeSizeLikeValue(info)); 0038 0039 KoColorTransformation* darkenTransformation = darkened.colorSpace()->createDarkenAdjustment(darkenAmount, false, 0.0); 0040 if (!darkenTransformation) return origColor; 0041 darkenTransformation ->transform(painter->paintColor().data(), darkened.data(), 1); 0042 painter->setPaintColor(darkened); 0043 delete darkenTransformation; 0044 0045 return origColor; 0046 } 0047 0048 void KisDarkenOption::apply(KisColorSource* colorSource, const KisPaintInformation& info) const 0049 { 0050 if (!isChecked()) return; 0051 0052 // Darken docs aren't really clear about what exactly the amount param can have as value... 0053 quint32 darkenAmount = (qint32)(255 - 255 * computeSizeLikeValue(info)); 0054 0055 KoColorTransformation* darkenTransformation = colorSource->colorSpace()->createDarkenAdjustment(darkenAmount, false, 0.0); 0056 if (!darkenTransformation) return; 0057 colorSource->applyColorTransformation(darkenTransformation); 0058 0059 delete darkenTransformation; 0060 }