some asserts added to imagePix()

This commit is contained in:
John Preston 2016-02-28 16:23:03 +03:00
parent b678913da5
commit 5b345cbc2d
2 changed files with 24 additions and 4 deletions

View File

@ -264,6 +264,7 @@ QImage imageBlur(QImage img) {
QImage::Format fmt = img.format();
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_ARGB32_Premultiplied) {
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
t_assert(!img.isNull());
}
uchar *pix = img.bits();
@ -287,6 +288,8 @@ QImage imageBlur(QImage img) {
QImage was = img;
img = imgsmall;
imgsmall = QImage();
t_assert(!img.isNull());
pix = img.bits();
if (!pix) return was;
}
@ -373,12 +376,18 @@ yi += stride;
}
void imageRound(QImage &img) {
t_assert(!img.isNull());
img.setDevicePixelRatio(cRetinaFactor());
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
t_assert(!img.isNull());
QImage **masks = App::cornersMask();
int32 w = masks[0]->width(), h = masks[0]->height();
int32 tw = img.width(), th = img.height();
if (tw < 2 * w || th < 2 * h) {
return;
}
uchar *bits = img.bits();
const uchar *c0 = masks[0]->constBits(), *c1 = masks[1]->constBits(), *c2 = masks[2]->constBits(), *c3 = masks[3]->constBits();
@ -427,12 +436,18 @@ QImage imageColored(const style::color &add, QImage img) {
}
QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) {
if (blurred) img = imageBlur(img);
t_assert(!img.isNull());
if (blurred) {
img = imageBlur(img);
t_assert(!img.isNull());
}
if (w <= 0 || (w == img.width() && (h <= 0 || h == img.height()))) {
} else if (h <= 0) {
img = img.scaledToWidth(w, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
t_assert(!img.isNull());
} else {
img = img.scaled(w, h, Qt::IgnoreAspectRatio, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
t_assert(!img.isNull());
}
if (outerw > 0 && outerh > 0) {
outerw *= cIntRetinaFactor();
@ -449,9 +464,13 @@ QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool r
p.drawImage((result.width() - img.width()) / (2 * cIntRetinaFactor()), (result.height() - img.height()) / (2 * cIntRetinaFactor()), img);
}
img = result;
t_assert(!img.isNull());
}
}
if (rounded) imageRound(img);
if (rounded) {
imageRound(img);
t_assert(!img.isNull());
}
img.setDevicePixelRatio(cRetinaFactor());
return QPixmap::fromImage(img, Qt::ColorOnly);
}
@ -459,6 +478,7 @@ QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool r
QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) const {
if (!loading()) const_cast<Image*>(this)->load();
restore();
if (_data.isNull()) {
if (h <= 0 && height() > 0) {
h = qRound(width() * w / float64(height()));
@ -489,6 +509,7 @@ QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool roun
if (rounded) imageRound(result);
return QPixmap::fromImage(result, Qt::ColorOnly);
}
return imagePix(_data.toImage(), w, h, smooth, blurred, rounded, outerw, outerh);
}

View File

@ -422,8 +422,7 @@ void LayoutOverviewVideo::paint(Painter &p, const QRect &clip, uint32 selection,
if (_thumbLoaded && !_data->thumb->isNull()) {
int32 size = _width * cIntRetinaFactor();
QImage img = _data->thumb->pix().toImage();
img = imageBlur(img);
QImage img = imageBlur(_data->thumb->pix().toImage());
if (img.width() == img.height()) {
if (img.width() != size) {
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);