[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita/rempt/impex-refactoring] libs/image: Fix assert in Thumbnail Cache
From: Dmitry Kazakov <dimula73 () gmail ! com>
Date: 2016-11-09 11:00:03
Message-ID: E1c4Qbr-0005yj-34 () code ! kde ! org
[Download RAW message or body]
Git commit e7a1e787d060b6407fce6dc344e5cdb13d9f55fc by Dmitry Kazakov.
Committed on 09/11/2016 at 10:29.
Pushed by dkazakov into branch 'rempt/impex-refactoring'.
Fix assert in Thumbnail Cache
Limit the size of the thumbnail by 1px to get sane results
BUG:372156
M +36 -15 libs/image/kis_paint_device.cc
M +0 -1 libs/image/kis_paint_device_cache.h
http://commits.kde.org/krita/e7a1e787d060b6407fce6dc344e5cdb13d9f55fc
diff --git a/libs/image/kis_paint_device.cc b/libs/image/kis_paint_device.cc
index a7cc28b..b119cbb 100644
--- a/libs/image/kis_paint_device.cc
+++ b/libs/image/kis_paint_device.cc
@@ -1553,25 +1553,40 @@ static KisPaintDeviceSP createThumbnailDeviceInternal(const \
KisPaintDevice* srcD return thumbnail;
}
+QSize fixThumbnailSize(QSize size)
+{
+ if (!size.width() && size.height()) {
+ size.setWidth(1);
+ }
+
+ if (size.width() && !size.height()) {
+ size.setHeight(1);
+ }
+
+ return size;
+}
+
KisPaintDeviceSP KisPaintDevice::createThumbnailDevice(qint32 w, qint32 h, QRect \
rect, QRect outputRect) const {
QSize thumbnailSize(w, h);
- int srcWidth, srcHeight;
- int srcX0, srcY0;
QRect imageRect = rect.isValid() ? rect : extent();
+ if ((thumbnailSize.width() > imageRect.width()) || (thumbnailSize.height() > \
imageRect.height())) { + thumbnailSize.scale(imageRect.size(), \
Qt::KeepAspectRatio); + }
+
+ thumbnailSize = fixThumbnailSize(thumbnailSize);
+
//can't create thumbnail for an empty device, e.g. layer thumbnail for empty \
image
- if (imageRect.isEmpty() || !imageRect.isValid()) {
+ if (imageRect.isEmpty() || thumbnailSize.isEmpty()) {
return new KisPaintDevice(colorSpace());
}
+ int srcWidth, srcHeight;
+ int srcX0, srcY0;
imageRect.getRect(&srcX0, &srcY0, &srcWidth, &srcHeight);
- if ((thumbnailSize.width() > imageRect.width()) || (thumbnailSize.height() > \
imageRect.height())) {
- thumbnailSize.scale(imageRect.size(), Qt::KeepAspectRatio);
- }
-
if (!outputRect.isValid()) {
outputRect = QRect(0, 0, w, h);
}
@@ -1589,12 +1604,7 @@ KisPaintDeviceSP \
KisPaintDevice::createThumbnailDeviceOversampled(qint32 w, qint QSize \
thumbnailOversampledSize = oversampleAdjusted * thumbnailSize;
QRect outputRect;
- QRect imageRect = (rect.isValid() && !rect.isNull()) ? rect : extent();
-
- //can't create thumbnail for an empty device, e.g. layer thumbnail for empty \
image
- if (imageRect.isEmpty() || !imageRect.isValid()) {
- return new KisPaintDevice(colorSpace());
- }
+ QRect imageRect = rect.isValid() ? rect : extent();
qint32 hstart = thumbnailOversampledSize.height();
@@ -1602,6 +1612,13 @@ KisPaintDeviceSP \
KisPaintDevice::createThumbnailDeviceOversampled(qint32 w, qint
thumbnailOversampledSize.scale(imageRect.size(), Qt::KeepAspectRatio);
}
+ thumbnailOversampledSize = fixThumbnailSize(thumbnailOversampledSize);
+
+ //can't create thumbnail for an empty device, e.g. layer thumbnail for empty \
image + if (imageRect.isEmpty() || thumbnailSize.isEmpty() || \
thumbnailOversampledSize.isEmpty()) { + return new \
KisPaintDevice(colorSpace()); + }
+
oversampleAdjusted *= (hstart > 0) ? ((qreal)thumbnailOversampledSize.height() / \
hstart) : 1.; //readjusting oversample ratio, given that we had to adjust thumbnail \
size
outputRect = QRect(0, 0, thumbnailOversampledSize.width(), \
thumbnailOversampledSize.height()); @@ -1626,14 +1643,18 @@ KisPaintDeviceSP \
KisPaintDevice::createThumbnailDeviceOversampled(qint32 w, qint
QImage KisPaintDevice::createThumbnail(qint32 w, qint32 h, QRect rect, qreal \
oversample, KoColorConversionTransformation::Intent renderingIntent, \
KoColorConversionTransformation::ConversionFlags conversionFlags) {
- KisPaintDeviceSP dev = createThumbnailDeviceOversampled(w, h, oversample, rect);
+ QSize size = fixThumbnailSize(QSize(w, h));
+
+ KisPaintDeviceSP dev = createThumbnailDeviceOversampled(size.width(), \
size.height(), oversample, rect);
QImage thumbnail = \
dev->convertToQImage(KoColorSpaceRegistry::instance()->rgb8()->profile(), 0, 0, w, h, \
renderingIntent, conversionFlags); return thumbnail;
}
QImage KisPaintDevice::createThumbnail(qint32 w, qint32 h, qreal oversample, \
KoColorConversionTransformation::Intent renderingIntent, \
KoColorConversionTransformation::ConversionFlags conversionFlags) {
- return m_d->cache()->createThumbnail(w, h, oversample, renderingIntent, \
conversionFlags); + QSize size = fixThumbnailSize(QSize(w, h));
+
+ return m_d->cache()->createThumbnail(size.width(), size.height(), oversample, \
renderingIntent, conversionFlags); }
KisHLineIteratorSP KisPaintDevice::createHLineIteratorNG(qint32 x, qint32 y, qint32 \
w)
diff --git a/libs/image/kis_paint_device_cache.h \
b/libs/image/kis_paint_device_cache.h index 9fcd545..f783981 100644
--- a/libs/image/kis_paint_device_cache.h
+++ b/libs/image/kis_paint_device_cache.h
@@ -101,7 +101,6 @@ public:
cacheThumbnail(w, h, oversample, thumbnail);
}
- Q_ASSERT(!thumbnail.isNull() || m_paintDevice->extent().isEmpty());
return thumbnail;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic