mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
some asserts added to imagePix()
This commit is contained in:
parent
b678913da5
commit
5b345cbc2d
2 changed files with 24 additions and 4 deletions
|
@ -264,6 +264,7 @@ QImage imageBlur(QImage img) {
|
||||||
QImage::Format fmt = img.format();
|
QImage::Format fmt = img.format();
|
||||||
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_ARGB32_Premultiplied) {
|
if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_ARGB32_Premultiplied) {
|
||||||
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||||
|
t_assert(!img.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
uchar *pix = img.bits();
|
uchar *pix = img.bits();
|
||||||
|
@ -287,6 +288,8 @@ QImage imageBlur(QImage img) {
|
||||||
QImage was = img;
|
QImage was = img;
|
||||||
img = imgsmall;
|
img = imgsmall;
|
||||||
imgsmall = QImage();
|
imgsmall = QImage();
|
||||||
|
t_assert(!img.isNull());
|
||||||
|
|
||||||
pix = img.bits();
|
pix = img.bits();
|
||||||
if (!pix) return was;
|
if (!pix) return was;
|
||||||
}
|
}
|
||||||
|
@ -373,12 +376,18 @@ yi += stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imageRound(QImage &img) {
|
void imageRound(QImage &img) {
|
||||||
|
t_assert(!img.isNull());
|
||||||
|
|
||||||
img.setDevicePixelRatio(cRetinaFactor());
|
img.setDevicePixelRatio(cRetinaFactor());
|
||||||
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||||
|
t_assert(!img.isNull());
|
||||||
|
|
||||||
QImage **masks = App::cornersMask();
|
QImage **masks = App::cornersMask();
|
||||||
int32 w = masks[0]->width(), h = masks[0]->height();
|
int32 w = masks[0]->width(), h = masks[0]->height();
|
||||||
int32 tw = img.width(), th = img.height();
|
int32 tw = img.width(), th = img.height();
|
||||||
|
if (tw < 2 * w || th < 2 * h) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uchar *bits = img.bits();
|
uchar *bits = img.bits();
|
||||||
const uchar *c0 = masks[0]->constBits(), *c1 = masks[1]->constBits(), *c2 = masks[2]->constBits(), *c3 = masks[3]->constBits();
|
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) {
|
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()))) {
|
if (w <= 0 || (w == img.width() && (h <= 0 || h == img.height()))) {
|
||||||
} else if (h <= 0) {
|
} else if (h <= 0) {
|
||||||
img = img.scaledToWidth(w, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
|
img = img.scaledToWidth(w, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
|
||||||
|
t_assert(!img.isNull());
|
||||||
} else {
|
} else {
|
||||||
img = img.scaled(w, h, Qt::IgnoreAspectRatio, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
|
img = img.scaled(w, h, Qt::IgnoreAspectRatio, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
|
||||||
|
t_assert(!img.isNull());
|
||||||
}
|
}
|
||||||
if (outerw > 0 && outerh > 0) {
|
if (outerw > 0 && outerh > 0) {
|
||||||
outerw *= cIntRetinaFactor();
|
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);
|
p.drawImage((result.width() - img.width()) / (2 * cIntRetinaFactor()), (result.height() - img.height()) / (2 * cIntRetinaFactor()), img);
|
||||||
}
|
}
|
||||||
img = result;
|
img = result;
|
||||||
|
t_assert(!img.isNull());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rounded) imageRound(img);
|
if (rounded) {
|
||||||
|
imageRound(img);
|
||||||
|
t_assert(!img.isNull());
|
||||||
|
}
|
||||||
img.setDevicePixelRatio(cRetinaFactor());
|
img.setDevicePixelRatio(cRetinaFactor());
|
||||||
return QPixmap::fromImage(img, Qt::ColorOnly);
|
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 {
|
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();
|
if (!loading()) const_cast<Image*>(this)->load();
|
||||||
restore();
|
restore();
|
||||||
|
|
||||||
if (_data.isNull()) {
|
if (_data.isNull()) {
|
||||||
if (h <= 0 && height() > 0) {
|
if (h <= 0 && height() > 0) {
|
||||||
h = qRound(width() * w / float64(height()));
|
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);
|
if (rounded) imageRound(result);
|
||||||
return QPixmap::fromImage(result, Qt::ColorOnly);
|
return QPixmap::fromImage(result, Qt::ColorOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return imagePix(_data.toImage(), w, h, smooth, blurred, rounded, outerw, outerh);
|
return imagePix(_data.toImage(), w, h, smooth, blurred, rounded, outerw, outerh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,8 +422,7 @@ void LayoutOverviewVideo::paint(Painter &p, const QRect &clip, uint32 selection,
|
||||||
|
|
||||||
if (_thumbLoaded && !_data->thumb->isNull()) {
|
if (_thumbLoaded && !_data->thumb->isNull()) {
|
||||||
int32 size = _width * cIntRetinaFactor();
|
int32 size = _width * cIntRetinaFactor();
|
||||||
QImage img = _data->thumb->pix().toImage();
|
QImage img = imageBlur(_data->thumb->pix().toImage());
|
||||||
img = imageBlur(img);
|
|
||||||
if (img.width() == img.height()) {
|
if (img.width() == img.height()) {
|
||||||
if (img.width() != size) {
|
if (img.width() != size) {
|
||||||
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||||
|
|
Loading…
Add table
Reference in a new issue