File indexing completed on 2025-01-26 04:11:17
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisBrushOpResources.h" 0008 0009 #include "kis_brush.h" 0010 0011 #include <KoColorSpace.h> 0012 #include <KoColorTransformation.h> 0013 0014 #include "kis_color_source.h" 0015 #include "kis_color_source_option.h" 0016 #include "KisSharpnessOption.h" 0017 #include "KisStandardOptions.h" 0018 #include "KisDarkenOption.h" 0019 #include "KisHSVOption.h" 0020 #include "kis_texture_option.h" 0021 #include "kis_painter.h" 0022 #include "kis_paintop_settings.h" 0023 0024 struct KisBrushOpResources::Private 0025 { 0026 Private(const KisPaintOpSettings *setting) 0027 : mixOption(setting) 0028 , darkenOption(setting) 0029 { 0030 } 0031 0032 QList<KisHSVOption*> hsvOptions; 0033 KoColorTransformation *hsvTransformation = 0; 0034 KisMixOption mixOption; 0035 KisDarkenOption darkenOption; 0036 }; 0037 0038 0039 KisBrushOpResources::KisBrushOpResources(const KisPaintOpSettingsSP settings, KisPainter *painter) 0040 : m_d(new Private(settings.data())) 0041 { 0042 KisColorSourceOption colorSourceOption(settings.data()); 0043 colorSource.reset(colorSourceOption.createColorSource(painter)); 0044 0045 sharpnessOption.reset(new KisSharpnessOption(settings.data())); 0046 0047 textureOption.reset(new KisTextureOption(settings.data(), 0048 settings->resourcesInterface(), 0049 settings->canvasResourcesInterface(), 0050 painter->device()->defaultBounds()->currentLevelOfDetail(), 0051 SupportsGradientMode | SupportsLightnessMode)); 0052 0053 m_d->hsvOptions.append(KisHSVOption::createHueOption(settings.data())); 0054 m_d->hsvOptions.append(KisHSVOption::createSaturationOption(settings.data())); 0055 m_d->hsvOptions.append(KisHSVOption::createValueOption(settings.data())); 0056 0057 Q_FOREACH (KisHSVOption *option, m_d->hsvOptions) { 0058 if (option->isChecked() && !m_d->hsvTransformation) { 0059 m_d->hsvTransformation = painter->backgroundColor().colorSpace()->createColorTransformation("hsv_adjustment", QHash<QString, QVariant>()); 0060 } 0061 } 0062 0063 // the brush should be initialized explicitly by the caller later 0064 KIS_SAFE_ASSERT_RECOVER_NOOP(!brush); 0065 } 0066 0067 KisBrushOpResources::~KisBrushOpResources() 0068 { 0069 qDeleteAll(m_d->hsvOptions); 0070 delete m_d->hsvTransformation; 0071 } 0072 0073 void KisBrushOpResources::syncResourcesToSeqNo(int seqNo, const KisPaintInformation &info) 0074 { 0075 colorSource->selectColor(m_d->mixOption.apply(info), info); 0076 m_d->darkenOption.apply(colorSource.data(), info); 0077 0078 if (m_d->hsvTransformation) { 0079 Q_FOREACH (KisHSVOption * option, m_d->hsvOptions) { 0080 option->apply(m_d->hsvTransformation, info); 0081 } 0082 colorSource->applyColorTransformation(m_d->hsvTransformation); 0083 } 0084 0085 KisDabCacheUtils::DabRenderingResources::syncResourcesToSeqNo(seqNo, info); 0086 }