Commit 18b9b33d authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Reduce aliasing in reference images

BUG: 396257
parent eb5d9f4d
......@@ -266,6 +266,8 @@ QSize levelSize = image.size();
QImage KisQImagePyramid::createImage(KisDabShape const& shape,
qreal subPixelX, qreal subPixelY) const
{
if (m_levels.isEmpty()) return QImage();
qreal baseScale = -1.0;
int level = findNearestLevel(shape.scale(), &baseScale);
......@@ -316,3 +318,16 @@ QImage KisQImagePyramid::createImage(KisDabShape const& shape,
return dstImage;
}
QImage KisQImagePyramid::getClosest(QTransform transform, qreal *scale) const
{
if (m_levels.isEmpty()) return QImage();
// Estimate scale
QSizeF transformedUnitSquare = transform.mapRect(QRectF(0, 0, 1, 1)).size();
qreal x = qAbs(transformedUnitSquare.width());
qreal y = qAbs(transformedUnitSquare.height());
qreal estimatedScale = (x > y) ? transformedUnitSquare.width() : transformedUnitSquare.height();
int level = findNearestLevel(estimatedScale, scale);
return m_levels[level].image;
}
......@@ -28,6 +28,7 @@
class BRUSH_EXPORT KisQImagePyramid
{
public:
KisQImagePyramid() = default;
KisQImagePyramid(const QImage &baseImage);
~KisQImagePyramid();
......@@ -40,6 +41,8 @@ public:
QImage createImage(KisDabShape const&,
qreal subPixelX, qreal subPixelY) const;
QImage getClosest(QTransform transform, qreal *scale) const;
private:
friend class KisGbrBrushTest;
int findNearestLevel(qreal scale, qreal *baseScale) const;
......
......@@ -32,10 +32,9 @@
#include <kis_dom_utils.h>
#include <SvgUtil.h>
#include <libs/flake/svg/parsers/SvgTransformParser.h>
#include <libs/brush/kis_qimage_pyramid.h>
struct KisReferenceImage::Private {
KisReferenceImage *q;
// Filename within .kra (for embedding)
QString internalFilename;
......@@ -44,15 +43,12 @@ struct KisReferenceImage::Private {
QImage image;
QImage cachedImage;
KisQImagePyramid mipmap;
qreal saturation{1.0};
int id{-1};
bool embed{true};
explicit Private(KisReferenceImage *q)
: q(q)
{}
bool loadFromFile() {
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!externalFilename.isEmpty(), false);
return image.load(externalFilename);
......@@ -70,6 +66,8 @@ struct KisReferenceImage::Private {
} else {
cachedImage = image;
}
mipmap = KisQImagePyramid(cachedImage);
}
};
......@@ -110,7 +108,7 @@ void KisReferenceImage::SetSaturationCommand::redo()
}
KisReferenceImage::KisReferenceImage()
: d(new Private(this))
: d(new Private())
{
setKeepAspectRatio(true);
}
......@@ -161,10 +159,14 @@ void KisReferenceImage::paint(QPainter &gc, const KoViewConverter &converter, Ko
d->updateCache();
}
gc.setRenderHint(QPainter::SmoothPixmapTransform);
qreal scale;
QImage prescaled = d->mipmap.getClosest(gc.transform() * transform, &scale);
transform.scale(1.0 / scale, 1.0 / scale);
gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
gc.setTransform(transform, true);
gc.drawImage(QPoint(), d->cachedImage);
gc.drawImage(QPoint(), prescaled);
gc.restore();
}
......
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