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 { ...@@ -53,6 +53,20 @@ struct KisReferenceImage::Private {
QString filename = src.mid(7); QString filename = src.mid(7);
image.load(filename); 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 ...@@ -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()); QTransform transform = QTransform::fromScale(shapeSize.width() / d->image.width(), shapeSize.height() / d->image.height());
if (d->cachedImage.isNull()) { if (d->cachedImage.isNull()) {
if (d->saturation < 1.0) { d->updateCache();
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;
}
} }
gc.setRenderHint(QPainter::SmoothPixmapTransform); gc.setRenderHint(QPainter::SmoothPixmapTransform);
gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip); gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
gc.setTransform(transform, true); gc.setTransform(transform, true);
...@@ -185,7 +190,11 @@ QColor KisReferenceImage::getPixel(QPointF position) ...@@ -185,7 +190,11 @@ QColor KisReferenceImage::getPixel(QPointF position)
const QTransform transform = absoluteTransformation(nullptr).inverted() * scale; const QTransform transform = absoluteTransformation(nullptr).inverted() * scale;
const QPointF localPosition = position * transform; 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) void KisReferenceImage::saveXml(QDomDocument &document, QDomElement &parentElement, int id)
......
...@@ -383,7 +383,7 @@ void KisToolPaint::addPickerJob(const PickingJob &pickingJob) ...@@ -383,7 +383,7 @@ void KisToolPaint::addPickerJob(const PickingJob &pickingJob)
auto *kisCanvas = dynamic_cast<KisCanvas2*>(canvas()); auto *kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas); KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas);
KisSharedPtr<KisReferenceImagesLayer> referencesLayer = kisCanvas->imageView()->document()->referenceImagesLayer(); KisSharedPtr<KisReferenceImagesLayer> referencesLayer = kisCanvas->imageView()->document()->referenceImagesLayer();
if (referencesLayer) { if (referencesLayer && kisCanvas->referenceImagesDecoration()->visible()) {
QColor color = referencesLayer->getPixel(imagePoint); QColor color = referencesLayer->getPixel(imagePoint);
if (color.isValid() && color.alpha() != 0) { if (color.isValid() && color.alpha() != 0) {
slotColorPickingFinished(KoColor(color, image()->colorSpace())); slotColorPickingFinished(KoColor(color, image()->colorSpace()));
......
...@@ -102,7 +102,7 @@ void KisToolColorPicker::pickColor(const QPointF &pos) ...@@ -102,7 +102,7 @@ void KisToolColorPicker::pickColor(const QPointF &pos)
KisSharedPtr<KisReferenceImagesLayer> referenceImageLayer = KisSharedPtr<KisReferenceImagesLayer> referenceImageLayer =
kisCanvas->imageView()->document()->referenceImagesLayer(); kisCanvas->imageView()->document()->referenceImagesLayer();
if (referenceImageLayer) { if (referenceImageLayer && kisCanvas->referenceImagesDecoration()->visible()) {
QColor color = referenceImageLayer->getPixel(pos); QColor color = referenceImageLayer->getPixel(pos);
if (color.isValid()) { if (color.isValid()) {
m_pickedColor.fromQColor(color); 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