Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/tool/kis_tool_utils.cpp
Context not available. | |||||
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); | ||
35 | const KoColorSpace* cs = dev->colorSpace(); | 36 | | ||
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, | ||
Context not available. | |||||
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; | ||
Context not available. | |||||
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; | ||
Context not available. | |||||
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 | } | ||
Context not available. |