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 | KoColor pickedColor; | 35 | KoColor pickedColor; | ||
39 | 36 | | |||
37 | // Ctrl picker sampling radius. | ||||
40 | if (radius <= 1) { | 38 | if (radius <= 1) { | ||
41 | dev->pixel(pos.x(), pos.y(), &pickedColor); | 39 | dev->pixel(pos.x(), pos.y(), &pickedColor); | ||
42 | } else { | 40 | } else { | ||
Context not available. | |||||
61 | } | 59 | } | ||
62 | } | 60 | } | ||
63 | 61 | | |||
64 | const quint8** cpixels = const_cast<const quint8**>(pixels.constData()); | 62 | const quint8 **cpixels = const_cast<const quint8**>(pixels.constData()); | ||
65 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | 63 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | ||
66 | } | 64 | } | ||
65 | | ||||
66 | // Ctrl picker color blending. | ||||
67 | if (previousColor && blend < 100) { | ||||
68 | //Scale from 0..100% to 0..255 range for mixOp weights. | ||||
69 | quint8 blendScaled = static_cast<quint8>(blend * 2.55f); | ||||
70 | | ||||
71 | const quint8 *colors[2]; | ||||
72 | colors[0] = previousColor->data(); | ||||
73 | colors[1] = pickedColor.data(); | ||||
74 | qint16 weights[2]; | ||||
75 | weights[0] = 255 - blendScaled; | ||||
76 | weights[1] = blendScaled; | ||||
77 | | ||||
78 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | ||||
79 | mixOp->mixColors(colors, weights, 2, pickedColor.data()); | ||||
80 | } | ||||
67 | 81 | | |||
68 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | 82 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | ||
69 | 83 | | |||
Context not available. | |||||
148 | , normaliseValues(false) | 162 | , normaliseValues(false) | ||
149 | , sampleMerged(true) | 163 | , sampleMerged(true) | ||
150 | , radius(1) | 164 | , radius(1) | ||
165 | , blend(100) | ||||
151 | { | 166 | { | ||
152 | } | 167 | } | ||
153 | 168 | | |||
Context not available. | |||||
165 | props.setProperty("normaliseValues", normaliseValues); | 180 | props.setProperty("normaliseValues", normaliseValues); | ||
166 | props.setProperty("sampleMerged", sampleMerged); | 181 | props.setProperty("sampleMerged", sampleMerged); | ||
167 | props.setProperty("radius", radius); | 182 | props.setProperty("radius", radius); | ||
183 | props.setProperty("blend", blend); | ||||
168 | 184 | | |||
169 | KConfigGroup config = KSharedConfig::openConfig()->group(CONFIG_GROUP_NAME); | 185 | KConfigGroup config = KSharedConfig::openConfig()->group(CONFIG_GROUP_NAME); | ||
170 | 186 | | |||
Context not available. | |||||
184 | normaliseValues = props.getBool("normaliseValues", false); | 200 | normaliseValues = props.getBool("normaliseValues", false); | ||
185 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | 201 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | ||
186 | radius = props.getInt("radius", 1); | 202 | radius = props.getInt("radius", 1); | ||
203 | blend = props.getInt("blend", 100); | ||||
187 | } | 204 | } | ||
188 | 205 | | |||
189 | } | 206 | } | ||
Context not available. |