[graphics/krita] libs/ui: Fix scaling of file layers with transparent background
Dmitry Kazakov
null at kde.org
Thu Aug 13 14:59:27 BST 2020
Git commit ab91d8ee40021a5ce35d4da40191a545996f281e by Dmitry Kazakov.
Committed on 13/08/2020 at 13:59.
Pushed by dkazakov into branch 'master'.
Fix scaling of file layers with transparent background
For upscaling/downscaling the image we should use its physical
size saved in the original file, not just the bounding rect
calculated with exactBounds().
This patch may change the look of existing .kra files, but we
can consider this case inexistent, because the offset of
transparent file layers has always been calculated incorrectly.
I don't think anyone could use the feature for transparent
layers because of that.
BUG:396131
CC:kimageshop at kde.org
M +9 -7 libs/ui/kis_file_layer.cpp
M +1 -1 libs/ui/kis_file_layer.h
M +4 -1 libs/ui/kis_safe_document_loader.cpp
M +1 -1 libs/ui/kis_safe_document_loader.h
https://invent.kde.org/graphics/krita/commit/ab91d8ee40021a5ce35d4da40191a545996f281e
diff --git a/libs/ui/kis_file_layer.cpp b/libs/ui/kis_file_layer.cpp
index 843836d904..c12b1e32ec 100644
--- a/libs/ui/kis_file_layer.cpp
+++ b/libs/ui/kis_file_layer.cpp
@@ -45,7 +45,7 @@ KisFileLayer::KisFileLayer(KisImageWSP image, const QString &name, quint8 opacit
m_paintDevice = new KisPaintDevice(image->colorSpace());
m_paintDevice->setDefaultBounds(new KisDefaultBounds(image));
- connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int)));
+ connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)), SLOT(slotLoadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)));
}
KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QString &filename, ScalingMethod scaleToImageResolution, const QString &name, quint8 opacity)
@@ -62,7 +62,7 @@ KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QSt
m_paintDevice = new KisPaintDevice(image->colorSpace());
m_paintDevice->setDefaultBounds(new KisDefaultBounds(image));
- connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int)));
+ connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)), SLOT(slotLoadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)));
QFileInfo fi(path());
if (fi.exists()) {
@@ -86,7 +86,7 @@ KisFileLayer::KisFileLayer(const KisFileLayer &rhs)
m_paintDevice = new KisPaintDevice(*rhs.m_paintDevice);
- connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,int,int)), SLOT(slotLoadingFinished(KisPaintDeviceSP,int,int)));
+ connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)), SLOT(slotLoadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)));
m_loader.setPath(path());
}
@@ -184,7 +184,9 @@ void KisFileLayer::setScalingMethod(ScalingMethod method)
m_scalingMethod = method;
}
-void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xRes, int yRes)
+void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection,
+ qreal xRes, qreal yRes,
+ const QSize &size)
{
qint32 oldX = x();
qint32 oldY = y();
@@ -193,10 +195,10 @@ void KisFileLayer::slotLoadingFinished(KisPaintDeviceSP projection, int xRes, in
m_paintDevice->makeCloneFrom(projection, projection->extent());
m_paintDevice->setDefaultBounds(new KisDefaultBounds(image()));
- QSize size = projection->exactBounds().size();
+ if (m_scalingMethod == ToImagePPI &&
+ (!qFuzzyCompare(image()->xRes(), xRes) ||
+ !qFuzzyCompare(image()->yRes(), yRes))) {
- if (m_scalingMethod == ToImagePPI && (image()->xRes() != xRes
- || image()->yRes() != yRes)) {
qreal xscale = image()->xRes() / xRes;
qreal yscale = image()->yRes() / yRes;
diff --git a/libs/ui/kis_file_layer.h b/libs/ui/kis_file_layer.h
index 5a31c67eef..625a095359 100644
--- a/libs/ui/kis_file_layer.h
+++ b/libs/ui/kis_file_layer.h
@@ -87,7 +87,7 @@ public:
void setImage(KisImageWSP image) override;
public Q_SLOTS:
- void slotLoadingFinished(KisPaintDeviceSP projection, int xRes, int yRes);
+ void slotLoadingFinished(KisPaintDeviceSP projection, qreal xRes, qreal yRes, const QSize &size);
private:
QString m_basePath;
diff --git a/libs/ui/kis_safe_document_loader.cpp b/libs/ui/kis_safe_document_loader.cpp
index 6e49742353..3f3a737461 100644
--- a/libs/ui/kis_safe_document_loader.cpp
+++ b/libs/ui/kis_safe_document_loader.cpp
@@ -316,7 +316,10 @@ void KisSafeDocumentLoader::delayedLoadStart()
KisPaintDeviceSP paintDevice = new KisPaintDevice(m_d->doc->image()->colorSpace());
KisPaintDeviceSP projection = m_d->doc->image()->projection();
paintDevice->makeCloneFrom(projection, projection->extent());
- emit loadingFinished(paintDevice, m_d->doc->image()->xRes(), m_d->doc->image()->yRes());
+ emit loadingFinished(paintDevice,
+ m_d->doc->image()->xRes(),
+ m_d->doc->image()->yRes(),
+ m_d->doc->image()->size());
}
m_d->doc.reset();
diff --git a/libs/ui/kis_safe_document_loader.h b/libs/ui/kis_safe_document_loader.h
index b955a4635f..a54a9e374e 100644
--- a/libs/ui/kis_safe_document_loader.h
+++ b/libs/ui/kis_safe_document_loader.h
@@ -39,7 +39,7 @@ private Q_SLOTS:
void delayedLoadStart();
Q_SIGNALS:
- void loadingFinished(KisPaintDeviceSP paintDevice, int xRes, int yRes);
+ void loadingFinished(KisPaintDeviceSP paintDevice, qreal xRes, qreal yRes, const QSize &size);
private:
struct Private;
More information about the kimageshop
mailing list