Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/tool/kis_tool_utils.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org> | 2 | * Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org> | ||
3 | * Copyright (c) 2018 Emmet & Eoin O'Neill <emmetoneill.pdx@gmail.com> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by | ||
Context not available. | |||||
15 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 18 | */ | ||
19 | | ||||
18 | #include <kis_tool_utils.h> | 20 | #include <kis_tool_utils.h> | ||
19 | 21 | | |||
20 | #include <KoColorSpace.h> | | |||
21 | #include <KoMixColorsOp.h> | 22 | #include <KoMixColorsOp.h> | ||
22 | #include <kis_paint_device.h> | | |||
23 | #include <kis_layer.h> | | |||
24 | #include <kis_group_layer.h> | 23 | #include <kis_group_layer.h> | ||
25 | #include <kis_wrapped_rect.h> | | |||
26 | #include <kis_image.h> | | |||
27 | #include <kis_transaction.h> | 24 | #include <kis_transaction.h> | ||
28 | #include <kis_sequential_iterator.h> | 25 | #include <kis_sequential_iterator.h> | ||
29 | #include <kis_properties_configuration.h> | 26 | #include <kis_properties_configuration.h> | ||
Context not available. | |||||
32 | 29 | | |||
33 | namespace KisToolUtils { | 30 | namespace KisToolUtils { | ||
34 | 31 | | |||
35 | bool pick(KisPaintDeviceSP dev, const QPoint& pos, KoColor *color, int radius) | 32 | bool pick(KisPaintDeviceSP dev, const QPoint &pos, KoColor *color, KoColor *previousColor, int radius, int blend) | ||
36 | { | 33 | { | ||
37 | KIS_ASSERT(dev); | 34 | KIS_ASSERT(dev); | ||
38 | const KoColorSpace* cs = dev->colorSpace(); | 35 | const KoColorSpace* cs = dev->colorSpace(); | ||
39 | KoColor pickedColor(Qt::transparent, cs); | 36 | KoColor pickedColor(Qt::transparent, cs); | ||
40 | 37 | | |||
38 | // Ctrl picker sampling radius. | ||||
41 | if (radius <= 1) { | 39 | if (radius <= 1) { | ||
42 | dev->pixel(pos.x(), pos.y(), &pickedColor); | 40 | dev->pixel(pos.x(), pos.y(), &pickedColor); | ||
43 | } else { | 41 | } else { | ||
Context not available. | |||||
59 | } | 57 | } | ||
60 | } | 58 | } | ||
61 | 59 | | |||
62 | const quint8** cpixels = const_cast<const quint8**>(pixels.constData()); | 60 | const quint8 **cpixels = const_cast<const quint8**>(pixels.constData()); | ||
63 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | 61 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | ||
64 | } | 62 | } | ||
63 | | ||||
64 | // Ctrl picker color blending. | ||||
65 | if (previousColor && blend < 100) { | ||||
66 | //Scale from 0..100% to 0..255 range for mixOp weights. | ||||
67 | quint8 blendScaled = static_cast<quint8>(blend * 2.55f); | ||||
68 | | ||||
69 | const quint8 *colors[2]; | ||||
70 | colors[0] = previousColor->data(); | ||||
71 | colors[1] = pickedColor.data(); | ||||
72 | qint16 weights[2]; | ||||
73 | weights[0] = 255 - blendScaled; | ||||
74 | weights[1] = blendScaled; | ||||
75 | | ||||
76 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | ||||
77 | mixOp->mixColors(colors, weights, 2, pickedColor.data()); | ||||
78 | } | ||||
65 | 79 | | |||
66 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | 80 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | ||
67 | 81 | | |||
Context not available. | |||||
146 | , normaliseValues(false) | 160 | , normaliseValues(false) | ||
147 | , sampleMerged(true) | 161 | , sampleMerged(true) | ||
148 | , radius(1) | 162 | , radius(1) | ||
163 | , blend(100) | ||||
149 | { | 164 | { | ||
150 | } | 165 | } | ||
151 | 166 | | |||
Context not available. | |||||
163 | props.setProperty("normaliseValues", normaliseValues); | 178 | props.setProperty("normaliseValues", normaliseValues); | ||
164 | props.setProperty("sampleMerged", sampleMerged); | 179 | props.setProperty("sampleMerged", sampleMerged); | ||
165 | props.setProperty("radius", radius); | 180 | props.setProperty("radius", radius); | ||
181 | props.setProperty("blend", blend); | ||||
166 | 182 | | |||
167 | KConfigGroup config = KSharedConfig::openConfig()->group(CONFIG_GROUP_NAME); | 183 | KConfigGroup config = KSharedConfig::openConfig()->group(CONFIG_GROUP_NAME); | ||
168 | 184 | | |||
Context not available. | |||||
182 | normaliseValues = props.getBool("normaliseValues", false); | 198 | normaliseValues = props.getBool("normaliseValues", false); | ||
183 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | 199 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | ||
184 | radius = props.getInt("radius", 1); | 200 | radius = props.getInt("radius", 1); | ||
201 | blend = props.getInt("blend", 100); | ||||
185 | } | 202 | } | ||
186 | 203 | | |||
187 | } | 204 | } | ||
Context not available. |