Blur small thumbnails.

This commit is contained in:
John Preston 2019-12-25 13:12:00 +03:00
parent 08e04cdcb1
commit dc146cb1fe
1 changed files with 12 additions and 2 deletions

View File

@ -38,6 +38,7 @@ namespace HistoryView {
namespace {
constexpr auto kMaxGifForwardedBarLines = 4;
constexpr auto kUseNonBlurredThreshold = 160;
int gifMaxStatusWidth(DocumentData *document) {
auto result = st::normalFont->width(formatDownloadText(document->size, document->size));
@ -392,7 +393,12 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
}
const auto normal = _data->thumbnail();
if (normal && normal->loaded()) {
p.drawPixmap(rthumb.topLeft(), normal->pixSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners));
if (normal->width() >= kUseNonBlurredThreshold
&& normal->height() >= kUseNonBlurredThreshold) {
p.drawPixmap(rthumb.topLeft(), normal->pixSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners));
} else {
p.drawPixmap(rthumb.topLeft(), normal->pixBlurredSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners));
}
} else if (const auto blurred = _data->thumbnailInline()) {
p.drawPixmap(rthumb.topLeft(), blurred->pixBlurredSingle(_realParent->fullId(), _thumbw, _thumbh, usew, painth, roundRadius, roundCorners));
} else if (!isRound) {
@ -1091,6 +1097,10 @@ void Gif::validateGroupedCache(
: useThumb
? thumb
: _data->thumbnailInline();
const auto blur = !useGood
&& (!useThumb
|| (thumb->width() < kUseNonBlurredThreshold)
|| (thumb->height() < kUseNonBlurredThreshold));
if (good && !useGood) {
good->load({});
}
@ -1100,7 +1110,7 @@ void Gif::validateGroupedCache(
const auto height = geometry.height();
const auto options = Option::Smooth
| Option::RoundedLarge
| (useGood ? Option(0) : Option::Blurred)
| (blur ? Option(0) : Option::Blurred)
| ((corners & RectPart::TopLeft) ? Option::RoundedTopLeft : Option::None)
| ((corners & RectPart::TopRight) ? Option::RoundedTopRight : Option::None)
| ((corners & RectPart::BottomLeft) ? Option::RoundedBottomLeft : Option::None)