Commit a90db047 authored by Stefan Brüns's avatar Stefan Brüns
Browse files

Remove white backdrop from Krita thumbnails, preserve transparency

Thumbnails have an alpha channel, so there is no need to flatten the
image.

Also remove the scaling, its alreay done in the generic code.
parent 003a5ca4
......@@ -221,7 +221,6 @@ add_library(kritathumbnail MODULE ${kritathumbnail_SRCS})
target_link_libraries(kritathumbnail
KF5::KIOWidgets
KF5::Archive
Qt5::Gui
)
install(TARGETS kritathumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR})
......
......@@ -22,7 +22,6 @@
#include <kzip.h>
// Qt
#include <QPainter>
#include <QImage>
#include <QIODevice>
#include <QFile>
......@@ -54,7 +53,6 @@ bool KritaCreator::create(const QString &path, int width, int height, QImage &im
}
QImage thumbnail;
bool biggerSizeNeeded = true;
// first check if normal thumbnail is good enough
// ORA thumbnail?
......@@ -69,35 +67,21 @@ bool KritaCreator::create(const QString &path, int width, int height, QImage &im
}
const KZipFileEntry* fileZipEntry = static_cast<const KZipFileEntry*>(entry);
bool thumbLoaded = thumbnail.loadFromData(fileZipEntry->data(), "PNG");
if (thumbLoaded) {
biggerSizeNeeded = (thumbnail.width() < width || thumbnail.height() < height);
}
if (biggerSizeNeeded || !thumbLoaded) {
entry = zip.directory()->entry(QLatin1String("mergedimage.png"));
bool thumbLoaded = image.loadFromData(fileZipEntry->data(), "PNG");
// The requested size is a boundingbox, so meeting one size is sufficient
if (thumbLoaded && ((image.width() >= width) || (image.height() >= height))) {
return true;
}
entry = zip.directory()->entry(QLatin1String("mergedimage.png"));
if (entry && entry->isFile()) {
fileZipEntry = static_cast<const KZipFileEntry*>(entry);
thumbLoaded = thumbnail.loadFromData(fileZipEntry->data(), "PNG");
if (thumbLoaded) {
thumbnail = thumbnail.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
} else {
return false;
image = thumbnail;
return true;
}
}
if (!thumbnail.isNull()) {
// transparent areas put a white background behind the thumbnail
// (or better checkerboard?)
image = QImage(thumbnail.size(), QImage::Format_RGB32);
image.fill(QColor(Qt::white).rgb());
QPainter p(&image);
p.drawImage(QPoint(0, 0), thumbnail);
return true;
}
return false;
}
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