Commit 392fd207 authored by Mathias Wein's avatar Mathias Wein
Browse files

Fix saving files with extreme aspect ratio

Saving failed because thumbnail generation didn't take into account
that scaling a QSize with KeepAspectRatio may round one dimension down
to zero.
This caused even the recovery path to generate an invalid thumbnail
image and saving aborted.

parent 1df0007f
Pipeline #249715 passed with stage
in 49 minutes and 18 seconds
......@@ -1662,8 +1662,8 @@ QPixmap KisDocument::generatePreview(const QSize& size)
if (image) {
QRect bounds = image->bounds();
QSize originalSize = bounds.size();
QSize newSize = bounds.size();
newSize.scale(size, Qt::KeepAspectRatio);
// QSize may round down one dimension to zero on extreme aspect rations, so ensure 1px minimum
QSize newSize = originalSize.scaled(size, Qt::KeepAspectRatio).expandedTo({1, 1});
bool pixelArt = false;
// determine if the image is pixel art or not
......@@ -288,9 +288,10 @@ KisImportExportErrorCode KraConverter::savePreview(KoStore *store)
QPixmap pix = m_doc->generatePreview(QSize(256, 256));
QImage preview(pix.toImage().convertToFormat(QImage::Format_ARGB32, Qt::ColorOnly));
if (preview.size() == QSize(0,0)) {
if (preview.size().isEmpty()) {
QSize newSize = m_doc->savingImage()->bounds().size();
newSize.scale(QSize(256, 256), Qt::KeepAspectRatio);
// make sure dimensions are at least one pixel, because extreme aspect ratios may cause rounding to zero
newSize = newSize.scaled(QSize(256, 256), Qt::KeepAspectRatio).expandedTo({1, 1});
preview = QImage(newSize, QImage::Format_ARGB32);
preview.fill(QColor(0, 0, 0, 0));
Supports Markdown
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