Changeset View
Changeset View
Standalone View
Standalone View
plugins/tools/basictools/kis_tool_colorpicker.cc
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
77 | { | 77 | { | ||
78 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | 78 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | ||
79 | m_isActivated = false; | 79 | m_isActivated = false; | ||
80 | KisTool::deactivate(); | 80 | KisTool::deactivate(); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | void KisToolColorPicker::pickColor(const QPointF &pos) | 83 | void KisToolColorPicker::pickColor(const QPointF &pos) | ||
84 | { | 84 | { | ||
85 | // Timer check. | ||||
85 | if (m_colorPickerDelayTimer.isActive()) { | 86 | if (m_colorPickerDelayTimer.isActive()) { | ||
86 | return; | 87 | return; | ||
87 | } | 88 | } | ||
88 | else { | 89 | else { | ||
89 | m_colorPickerDelayTimer.setSingleShot(true); | 90 | m_colorPickerDelayTimer.setSingleShot(true); | ||
90 | m_colorPickerDelayTimer.start(100); | 91 | m_colorPickerDelayTimer.start(100); | ||
91 | } | 92 | } | ||
92 | 93 | | |||
93 | QScopedPointer<boost::lock_guard<KisImage>> imageLocker; | 94 | QScopedPointer<boost::lock_guard<KisImage>> imageLocker; | ||
94 | 95 | | |||
95 | m_pickedColor.setOpacity(0.0); | 96 | m_pickedColor.setOpacity(0.0); | ||
96 | 97 | | |||
98 | // Pick from reference images. | ||||
97 | if (m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED) { | 99 | if (m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED) { | ||
98 | auto *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas()); | 100 | auto *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas()); | ||
99 | KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas); | 101 | KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas); | ||
100 | KisReferenceImagesLayer *referenceImageLayer = | 102 | KisReferenceImagesLayer *referenceImageLayer = | ||
101 | kisCanvas->imageView()->document()->referenceImagesLayer(); | 103 | kisCanvas->imageView()->document()->referenceImagesLayer(); | ||
102 | 104 | | |||
103 | if (referenceImageLayer) { | 105 | if (referenceImageLayer) { | ||
104 | QColor color = referenceImageLayer->getPixel(pos); | 106 | QColor color = referenceImageLayer->getPixel(pos); | ||
Show All 10 Lines | 116 | if (m_optionsWidget->cmbSources->currentIndex() != SAMPLE_MERGED && | |||
115 | currentNode() && currentNode()->colorPickSourceDevice()) { | 117 | currentNode() && currentNode()->colorPickSourceDevice()) { | ||
116 | dev = currentNode()->colorPickSourceDevice(); | 118 | dev = currentNode()->colorPickSourceDevice(); | ||
117 | } | 119 | } | ||
118 | else { | 120 | else { | ||
119 | imageLocker.reset(new boost::lock_guard<KisImage>(*currentImage())); | 121 | imageLocker.reset(new boost::lock_guard<KisImage>(*currentImage())); | ||
120 | dev = currentImage()->projection(); | 122 | dev = currentImage()->projection(); | ||
121 | } | 123 | } | ||
122 | 124 | | |||
123 | // Color sampling radius. | | |||
124 | if (m_config->radius == 1) { | | |||
125 | QPoint realPos = pos.toPoint(); | | |||
126 | if (currentImage()->wrapAroundModePermitted()) { | | |||
127 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | | |||
128 | } | | |||
129 | | ||||
130 | dev->pixel(realPos.x(), realPos.y(), &m_pickedColor); | | |||
131 | } | | |||
132 | else { | | |||
133 | const KoColorSpace *cs = dev->colorSpace(); | | |||
134 | int pixelSize = cs->pixelSize(); | | |||
135 | | ||||
136 | quint8 *dstColor = new quint8[pixelSize]; | | |||
137 | QVector<const quint8 *> pixels; | | |||
138 | | ||||
139 | KisRandomConstAccessorSP accessor = dev->createRandomConstAccessorNG(0, 0); | | |||
140 | | ||||
141 | for (int y = -m_config->radius; y <= m_config->radius; y++) { | | |||
142 | for (int x = -m_config->radius; x <= m_config->radius; x++) { | | |||
143 | if (((x * x) + (y * y)) < m_config->radius * m_config->radius) { | | |||
144 | | ||||
145 | QPoint realPos(pos.x() + x, pos.y() + y); | | |||
146 | | ||||
147 | if (currentImage()->wrapAroundModePermitted()) { | | |||
148 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | | |||
149 | } | | |||
150 | | ||||
151 | accessor->moveTo(realPos.x(), realPos.y()); | | |||
152 | pixels << accessor->oldRawData(); | | |||
153 | } | | |||
154 | } | | |||
155 | } | | |||
156 | | ||||
157 | const quint8 **cpixels = const_cast<const quint8 **>(pixels.constData()); | | |||
158 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), dstColor); | | |||
159 | | ||||
160 | m_pickedColor = KoColor(dstColor, cs); | | |||
161 | | ||||
162 | delete[] dstColor; | | |||
163 | } | | |||
164 | | ||||
165 | // Color blending. | | |||
166 | if(m_config->blend < 100){ | | |||
167 | //Scale from 0..100% to 0..255 range for mixOp weights. | | |||
168 | quint8 blendScaled = static_cast<quint8>(m_config->blend * 2.55f); | | |||
169 | | ||||
170 | KoColor previousColor = canvas()->resourceManager()->foregroundColor(); | 125 | KoColor previousColor = canvas()->resourceManager()->foregroundColor(); | ||
171 | 126 | | |||
172 | const quint8 *colors[2]; | 127 | KisToolUtils::pickColor(m_pickedColor, dev, pos.toPoint(), &previousColor, m_config->radius, m_config->blend); /*!*/ | ||
173 | colors[0] = previousColor.data(); | | |||
174 | colors[1] = m_pickedColor.data(); | | |||
175 | qint16 weights[2]; | | |||
176 | weights[0] = 255 - blendScaled; | | |||
177 | weights[1] = blendScaled; | | |||
178 | | ||||
179 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | | |||
180 | mixOp->mixColors(colors, weights, 2, m_pickedColor.data()); | | |||
181 | } | | |||
182 | | ||||
183 | m_pickedColor.convertTo(dev->compositionSourceColorSpace()); | | |||
184 | 128 | | |||
185 | if (m_config->updateColor && | 129 | if (m_config->updateColor && | ||
186 | m_pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8) { | 130 | m_pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8) { | ||
187 | 131 | | |||
188 | KoColor publicColor = m_pickedColor; | 132 | KoColor publicColor = m_pickedColor; | ||
189 | publicColor.setOpacity(OPACITY_OPAQUE_U8); | 133 | publicColor.setOpacity(OPACITY_OPAQUE_U8); | ||
190 | 134 | | |||
191 | if (m_config->toForegroundColor) { | 135 | if (m_config->toForegroundColor) { | ||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |