Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/tool/kis_tool_utils.cpp
Show All 23 Lines | |||||
24 | #include <kis_transaction.h> | 24 | #include <kis_transaction.h> | ||
25 | #include <kis_sequential_iterator.h> | 25 | #include <kis_sequential_iterator.h> | ||
26 | #include <kis_properties_configuration.h> | 26 | #include <kis_properties_configuration.h> | ||
27 | #include <kconfiggroup.h> | 27 | #include <kconfiggroup.h> | ||
28 | #include <ksharedconfig.h> | 28 | #include <ksharedconfig.h> | ||
29 | 29 | | |||
30 | namespace KisToolUtils { | 30 | namespace KisToolUtils { | ||
31 | 31 | | |||
32 | bool pick(KisPaintDeviceSP dev, const QPoint &pos, KoColor *color, KoColor *previousColor, int radius, int blend) | 32 | bool pickColor(KoColor &out_color, KisPaintDeviceSP dev, const QPoint &pos, | ||
33 | KoColor const *const blendColor, int radius, int blend, bool pure) | ||||
33 | { | 34 | { | ||
34 | KIS_ASSERT(dev); | 35 | KIS_ASSERT(dev); | ||
36 | | ||||
35 | const KoColorSpace* cs = dev->colorSpace(); | 37 | const KoColorSpace *cs = dev->colorSpace(); | ||
36 | KoColor pickedColor(Qt::transparent, cs); | 38 | KoColor pickedColor(Qt::transparent, cs); | ||
37 | 39 | | |||
38 | // Ctrl picker sampling radius. | 40 | // Sampling radius. | ||
39 | if (radius <= 1) { | 41 | if (!pure && radius > 1) { | ||
40 | dev->pixel(pos.x(), pos.y(), &pickedColor); | | |||
41 | } else { | | |||
42 | QVector<const quint8*> pixels; | 42 | QVector<const quint8*> pixels; | ||
43 | | ||||
44 | const int effectiveRadius = radius - 1; | 43 | const int effectiveRadius = radius - 1; | ||
45 | 44 | | |||
46 | const QRect pickRect(pos.x() - effectiveRadius, pos.y() - effectiveRadius, | 45 | const QRect pickRect(pos.x() - effectiveRadius, pos.y() - effectiveRadius, | ||
47 | 2 * effectiveRadius + 1, 2 * effectiveRadius + 1); | 46 | 2 * effectiveRadius + 1, 2 * effectiveRadius + 1); | ||
48 | KisSequentialConstIterator it(dev, pickRect); | 47 | KisSequentialConstIterator it(dev, pickRect); | ||
49 | 48 | | |||
50 | const int radiusSq = pow2(effectiveRadius); | 49 | const int radiusSq = pow2(effectiveRadius); | ||
51 | 50 | | |||
52 | while (it.nextPixel()) { | 51 | while (it.nextPixel()) { | ||
53 | const QPoint realPos(it.x(), it.y()); | 52 | const QPoint realPos(it.x(), it.y()); | ||
54 | const QPoint pt = realPos - pos; | 53 | const QPoint pt = realPos - pos; | ||
55 | if (pow2(pt.x()) + pow2(pt.y()) < radiusSq) { | 54 | if (pow2(pt.x()) + pow2(pt.y()) < radiusSq) { | ||
56 | pixels << it.oldRawData(); | 55 | pixels << it.oldRawData(); | ||
57 | } | 56 | } | ||
58 | } | 57 | } | ||
59 | 58 | | |||
60 | const quint8 **cpixels = const_cast<const quint8**>(pixels.constData()); | 59 | const quint8 **cpixels = const_cast<const quint8**>(pixels.constData()); | ||
61 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | 60 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), pickedColor.data()); | ||
61 | } else { | ||||
62 | dev->pixel(pos.x(), pos.y(), &pickedColor); | ||||
62 | } | 63 | } | ||
63 | 64 | | |||
64 | // Ctrl picker color blending. | 65 | // Color blending. | ||
65 | if (previousColor && blend < 100) { | 66 | if (!pure && blendColor && blend < 100) { | ||
66 | //Scale from 0..100% to 0..255 range for mixOp weights. | 67 | //Scale from 0..100% to 0..255 range for mixOp weights. | ||
67 | quint8 blendScaled = static_cast<quint8>(blend * 2.55f); | 68 | quint8 blendScaled = static_cast<quint8>(blend * 2.55f); | ||
68 | 69 | | |||
69 | const quint8 *colors[2]; | 70 | const quint8 *colors[2]; | ||
70 | colors[0] = previousColor->data(); | 71 | colors[0] = blendColor->data(); | ||
71 | colors[1] = pickedColor.data(); | 72 | colors[1] = pickedColor.data(); | ||
72 | qint16 weights[2]; | 73 | qint16 weights[2]; | ||
73 | weights[0] = 255 - blendScaled; | 74 | weights[0] = 255 - blendScaled; | ||
74 | weights[1] = blendScaled; | 75 | weights[1] = blendScaled; | ||
75 | 76 | | |||
76 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | 77 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | ||
77 | mixOp->mixColors(colors, weights, 2, pickedColor.data()); | 78 | mixOp->mixColors(colors, weights, 2, pickedColor.data()); | ||
78 | } | 79 | } | ||
79 | 80 | | |||
80 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | 81 | pickedColor.convertTo(dev->compositionSourceColorSpace()); | ||
81 | 82 | | |||
82 | bool validColorPicked = | 83 | bool validColorPicked = pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8; | ||
83 | pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8; | | |||
84 | 84 | | |||
85 | if (validColorPicked) { | 85 | if (validColorPicked) { | ||
86 | pickedColor.setOpacity(OPACITY_OPAQUE_U8); | 86 | pickedColor.setOpacity(OPACITY_OPAQUE_U8); | ||
87 | *color = pickedColor; | 87 | out_color = pickedColor; | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | return validColorPicked; | 90 | return validColorPicked; | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | KisNodeSP findNode(KisNodeSP node, const QPoint &point, bool wholeGroup, bool editableOnly) | 93 | KisNodeSP findNode(KisNodeSP node, const QPoint &point, bool wholeGroup, bool editableOnly) | ||
94 | { | 94 | { | ||
95 | KisNodeSP foundNode = 0; | 95 | KisNodeSP foundNode = 0; | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 189 | { | |||
195 | toForegroundColor = props.getBool("toForegroundColor", true); | 195 | toForegroundColor = props.getBool("toForegroundColor", true); | ||
196 | updateColor = props.getBool("updateColor", true); | 196 | updateColor = props.getBool("updateColor", true); | ||
197 | addPalette = props.getBool("addPalette", false); | 197 | addPalette = props.getBool("addPalette", false); | ||
198 | normaliseValues = props.getBool("normaliseValues", false); | 198 | normaliseValues = props.getBool("normaliseValues", false); | ||
199 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | 199 | sampleMerged = props.getBool("sampleMerged", !defaultActivation ? false : true); | ||
200 | radius = props.getInt("radius", 1); | 200 | radius = props.getInt("radius", 1); | ||
201 | blend = props.getInt("blend", 100); | 201 | blend = props.getInt("blend", 100); | ||
202 | } | 202 | } | ||
203 | | ||||
204 | } | 203 | } |