Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDarkenOption.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#include "KisDarkenOption.h"
9
12#include <kis_paint_device.h>
14#include <kis_painter.h>
16
17#include "kis_color_source.h"
18
19namespace kpou = KisPaintOpOptionUtils;
20
21
26
28{
29 if (!isChecked()) {
30 return painter->paintColor();
31 }
32
33 KoColor darkened = painter->paintColor();
34 KoColor origColor = darkened;
35
36 // Darken docs aren't really clear about what exactly the amount param can have as value...
37 quint32 darkenAmount = (qint32)(255 - 255 * computeSizeLikeValue(info));
38
39 KoColorTransformation* darkenTransformation = darkened.colorSpace()->createDarkenAdjustment(darkenAmount, false, 0.0);
40 if (!darkenTransformation) return origColor;
41 darkenTransformation ->transform(painter->paintColor().data(), darkened.data(), 1);
42 painter->setPaintColor(darkened);
43 delete darkenTransformation;
44
45 return origColor;
46}
47
48void KisDarkenOption::apply(KisColorSource* colorSource, const KisPaintInformation& info) const
49{
50 if (!isChecked()) return;
51
52 // Darken docs aren't really clear about what exactly the amount param can have as value...
53 quint32 darkenAmount = (qint32)(255 - 255 * computeSizeLikeValue(info));
54
55 KoColorTransformation* darkenTransformation = colorSource->colorSpace()->createDarkenAdjustment(darkenAmount, false, 0.0);
56 if (!darkenTransformation) return;
57 colorSource->applyColorTransformation(darkenTransformation);
58
59 delete darkenTransformation;
60}
virtual void applyColorTransformation(const KoColorTransformation *transfo)=0
virtual const KoColorSpace * colorSpace() const =0
bool isChecked() const
qreal computeSizeLikeValue(const KisPaintInformation &info, bool useStrengthValue=true) const
KoColor apply(KisPainter *painter, const KisPaintInformation &info) const
KisDarkenOption(const KisPropertiesConfiguration *setting)
KoColor paintColor
void setPaintColor(const KoColor &color)
virtual KoColorTransformation * createDarkenAdjustment(qint32 shade, bool compensate, qreal compensation) const =0
virtual void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const =0
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82