Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 377da7a9 authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Fix color picking from reference images

Desaturation now affects the picked color, and reference images are
ignored for picking if hidden.
parent 7d82d370
......@@ -53,6 +53,20 @@ struct KisReferenceImage::Private {
QString filename = src.mid(7);
image.load(filename);
}
void updateCache() {
if (saturation < 1.0) {
cachedImage = KritaUtils::convertQImageToGrayA(image);
if (saturation > 0.0) {
QPainter gc2(&cachedImage);
gc2.setOpacity(saturation);
gc2.drawImage(QPoint(), image);
}
} else {
cachedImage = image;
}
}
};
......@@ -130,18 +144,9 @@ void KisReferenceImage::paint(QPainter &gc, const KoViewConverter &converter, Ko
QTransform transform = QTransform::fromScale(shapeSize.width() / d->image.width(), shapeSize.height() / d->image.height());
if (d->cachedImage.isNull()) {
if (d->saturation < 1.0) {
d->cachedImage = KritaUtils::convertQImageToGrayA(d->image);
if (d->saturation > 0.0) {
QPainter gc2(&d->cachedImage);
gc2.setOpacity(d->saturation);
gc2.drawImage(QPoint(), d->image);
}
} else {
d->cachedImage = d->image;
}
d->updateCache();
}
gc.setRenderHint(QPainter::SmoothPixmapTransform);
gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
gc.setTransform(transform, true);
......@@ -185,7 +190,11 @@ QColor KisReferenceImage::getPixel(QPointF position)
const QTransform transform = absoluteTransformation(nullptr).inverted() * scale;
const QPointF localPosition = position * transform;
return d->image.pixelColor(localPosition.toPoint());
if (d->cachedImage.isNull()) {
d->updateCache();
}
return d->cachedImage.pixelColor(localPosition.toPoint());
}
void KisReferenceImage::saveXml(QDomDocument &document, QDomElement &parentElement, int id)
......
......@@ -383,7 +383,7 @@ void KisToolPaint::addPickerJob(const PickingJob &pickingJob)
auto *kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas);
KisSharedPtr<KisReferenceImagesLayer> referencesLayer = kisCanvas->imageView()->document()->referenceImagesLayer();
if (referencesLayer) {
if (referencesLayer && kisCanvas->referenceImagesDecoration()->visible()) {
QColor color = referencesLayer->getPixel(imagePoint);
if (color.isValid() && color.alpha() != 0) {
slotColorPickingFinished(KoColor(color, image()->colorSpace()));
......
......@@ -102,7 +102,7 @@ void KisToolColorPicker::pickColor(const QPointF &pos)
KisSharedPtr<KisReferenceImagesLayer> referenceImageLayer =
kisCanvas->imageView()->document()->referenceImagesLayer();
if (referenceImageLayer) {
if (referenceImageLayer && kisCanvas->referenceImagesDecoration()->visible()) {
QColor color = referenceImageLayer->getPixel(pos);
if (color.isValid()) {
m_pickedColor.fromQColor(color);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment