Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix rotation. Fix zoom inaccuracies by switching to full size QImage instead of small scale mimap
Le Tien Datc815478eaae7
diff --git a/libs/ui/KisReferenceImage.cpp b/libs/ui/KisReferenceImage.cppindex 882bc8cef7..bbde5eb32e 100644--- a/libs/ui/KisReferenceImage.cpp+++ b/libs/ui/KisReferenceImage.cpp@@ -99,12 +99,14 @@ struct KisReferenceImage::Private : public QSharedData#elseimage.convertToColorSpace(QColorSpace(QColorSpace::SRgb));#endif+ // It should be ok to covert to ARGB as it's saved as PNG anyways?+ image.convertTo(QImage::Format_ARGB32);return (!image.isNull());}bool loadFromQImage(const QImage &img) {- image = img;+ image = img.convertToFormat(QImage::Format_ARGB32);return !image.isNull();}@@ -348,17 +350,28 @@ void KisReferenceImage::setFilename(const QString &filename)d->externalFilename = filename;}+<<<<<<< HEADKoColor KisReferenceImage::getPixel(QPointF position)+=======+QPoint KisReferenceImage::documentToPixel(const QPointF &docPoint)+{+ QSizeF shapeSize = size();+ QTransform scale = QTransform::fromScale(d->image.width() / shapeSize.width(), d->image.height() / shapeSize.height());++ QTransform transform = absoluteTransformation().inverted() * scale;+ QPointF localPosition = docPoint * transform;++ return localPosition.toPoint();+}++QColor KisReferenceImage::getPixel(QPointF position)+>>>>>>> 208309fd88 (Fix rotation. Fix zoom inaccuracies by switching to full size QImage instead of small scale mimap){KoColor transparent;transparent.setOpacity(0.0);if (transparency() == 1.0) return transparent;- const QSizeF shapeSize = size();- const QTransform scale = QTransform::fromScale(d->image.width() / shapeSize.width(), d->image.height() / shapeSize.height());-- const QTransform transform = absoluteTransformation().inverted() * scale;- const QPointF localPosition = position * transform;+ const QPointF localPosition = documentToPixel(position);if (d->cachedImage.isNull()) {d->updateCache();@@ -484,6 +497,13 @@ QImage KisReferenceImage::getImage()return d->image;}+QImage KisReferenceImage::getCachedImage()+{+ if (d->cachedImage.isNull()) d->updateCache();++ return d->cachedImage;+}+KoShape *KisReferenceImage::cloneShape() const{return new KisReferenceImage(*this);diff --git a/libs/ui/KisReferenceImage.h b/libs/ui/KisReferenceImage.hindex bae69b7fef..a6ac3d1d35 100644--- a/libs/ui/KisReferenceImage.h+++ b/libs/ui/KisReferenceImage.h@@ -76,6 +76,9 @@ public:KoColor getPixel(QPointF position);+ QPoint documentToPixel(const QPointF &docPoint);+ QColor getPixel(QPointF position);+void saveXml(QDomDocument &document, QDomElement &parentElement, int id);bool saveImage(KoStore *store) const;@@ -83,6 +86,7 @@ public:bool loadImage(KoStore *store);QImage getImage();+ QImage getCachedImage();private:struct Private;diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cppindex 8ccb9d1b65..98c90e3d53 100644--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp@@ -600,7 +600,7 @@ void KisAsyncColorSamplerHelper::paintCircleCanvasPreview(QPainter &gc, const QRgc.setClipPath(QPainterPath(), Qt::NoClip);}-// TODO: Fix incorrect preview position, weird wrapping stuff at edge of rotated ref image+// TODO: Fix color sampler run away when REALLY zoomed in// Won't show opacity because the color sampled doesn't respect opacity eithervoid KisAsyncColorSamplerHelper::paintCircleReferenceImagePreview(QPainter &gc, const QRectF &viewRectF, const QRectF &sampleDocRectF, const QPainterPath &clip) {KisDocument *doc = m_d->canvas->viewManager()->document();@@ -619,26 +619,25 @@ void KisAsyncColorSamplerHelper::paintCircleReferenceImagePreview(QPainter &gc,});Q_FOREACH(KisReferenceImage *refImage, refList) {// Check if sampleRect intersect with reference image- QTransform refTf = refImage->absoluteTransformation();- QPolygonF outline = refTf.map(refImage->outlineRect());+ QPolygonF outline = refImage->absoluteTransformation().map(refImage->outlineRect());if (!outline.intersects(QPolygonF(sampleDocRectF))) continue;- QRectF sampleRefRectF = refImage->documentToShape(sampleDocRectF);+ QImage image = refImage->getCachedImage();+ // image.convertTo(QImage::Format_ARGB32); Do this in KisReferenceImage to avoid having to copy? and convert- // TODO: Check if rounding like this actually OK. Probably not!- // This probably cause the ever so slighly off position- QPixmap refPixmap(refImage->size().toSize());- QPainter refPainter(&refPixmap);- refPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);- refImage->paint(refPainter);+ QPointF sampleRefPointF = refImage->documentToPixel(sampleDocRectF.center());+ QRectF shapeRectF = refImage->documentToShape(sampleDocRectF);+ qreal xScale = refImage->boundingRect().width() / image.width();+ qreal yScale = refImage->boundingRect().height() / image.height();++ QRectF sampleRefRectF = QRectF(sampleRefPointF, QSizeF(shapeRectF.width() / xScale, shapeRectF.height() / yScale));+ sampleRefRectF.moveCenter(sampleRefPointF);- // Rotate the painter, draw, rotate back is seemingly easier than- // trying to rotate the pixmap and having to deal with sourceRectgc.translate(viewRectF.center());gc.rotate(refImage->rotation());gc.translate(-viewRectF.center());- gc.drawPixmap(viewRectF, refPixmap, sampleRefRectF);+ gc.drawImage(viewRectF, image.copy(sampleRefRectF.toRect()));gc.translate(viewRectF.center());gc.rotate(-refImage->rotation());