diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 8247ff530..a6a21e31d 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1710,14 +1710,16 @@ void MediaView::initThemePreview() { Window::Theme::CurrentData current; current.backgroundId = Window::Theme::Background()->id(); - current.backgroundImage = Window::Theme::Background()->pixmap(); + current.backgroundImage = Window::Theme::Background()->pixmap().toImage(); current.backgroundTiled = Window::Theme::Background()->tile(); const auto path = _doc->location().name(); const auto id = _themePreviewId = rand_value(); const auto weak = make_weak(this); - crl::async([=] { - auto preview = Window::Theme::GeneratePreview(path, current); + crl::async([=, data = std::move(current)]() mutable { + auto preview = Window::Theme::GeneratePreview( + path, + std::move(data)); crl::on_main(weak, [=, result = std::move(preview)]() mutable { if (id != _themePreviewId) { return; @@ -2261,12 +2263,19 @@ void MediaView::paintThemePreview(Painter &p, QRect clip) { auto fill = _themePreviewRect.intersected(clip); if (!fill.isEmpty()) { if (_themePreview) { - p.drawPixmapLeft(_themePreviewRect.x(), _themePreviewRect.y(), width(), _themePreview->preview); + p.drawImage( + myrtlrect(_themePreviewRect).topLeft(), + _themePreview->preview); } else { p.fillRect(fill, st::themePreviewBg); p.setFont(st::themePreviewLoadingFont); p.setPen(st::themePreviewLoadingFg); - p.drawText(_themePreviewRect, lang(_themePreviewId ? lng_theme_preview_generating : lng_theme_preview_invalid), QTextOption(style::al_center)); + p.drawText( + _themePreviewRect, + lang(_themePreviewId + ? lng_theme_preview_generating + : lng_theme_preview_invalid), + QTextOption(style::al_center)); } } diff --git a/Telegram/SourceFiles/ui/images.cpp b/Telegram/SourceFiles/ui/images.cpp index 57f772d23..0b6e7e0ab 100644 --- a/Telegram/SourceFiles/ui/images.cpp +++ b/Telegram/SourceFiles/ui/images.cpp @@ -59,6 +59,13 @@ const QPixmap &circleMask(int width, int height) { } // namespace +QPixmap PixmapFast(QImage &&image) { + Expects(image.format() == QImage::Format_ARGB32_Premultiplied + || image.format() == QImage::Format_RGB32); + + return QPixmap::fromImage(std::move(image), Qt::NoFormatConversion); +} + QImage prepareBlur(QImage img) { auto ratio = img.devicePixelRatio(); auto fmt = img.format(); diff --git a/Telegram/SourceFiles/ui/images.h b/Telegram/SourceFiles/ui/images.h index ff9060b94..80f6a0b50 100644 --- a/Telegram/SourceFiles/ui/images.h +++ b/Telegram/SourceFiles/ui/images.h @@ -22,6 +22,62 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "base/flags.h" +enum class ImageRoundRadius { + None, + Large, + Small, + Ellipse, +}; + +namespace Images { + +QPixmap PixmapFast(QImage &&image); + +QImage prepareBlur(QImage image); +void prepareRound( + QImage &image, + ImageRoundRadius radius, + RectParts corners = RectPart::AllCorners, + QRect target = QRect()); +void prepareRound( + QImage &image, + QImage *cornerMasks, + RectParts corners = RectPart::AllCorners, + QRect target = QRect()); +void prepareCircle(QImage &image); +QImage prepareColored(style::color add, QImage image); +QImage prepareOpaque(QImage image); + +enum class Option { + None = 0, + Smooth = (1 << 0), + Blurred = (1 << 1), + Circled = (1 << 2), + RoundedLarge = (1 << 3), + RoundedSmall = (1 << 4), + RoundedTopLeft = (1 << 5), + RoundedTopRight = (1 << 6), + RoundedBottomLeft = (1 << 7), + RoundedBottomRight = (1 << 8), + RoundedAll = (None + | RoundedTopLeft + | RoundedTopRight + | RoundedBottomLeft + | RoundedBottomRight), + Colored = (1 << 9), + TransparentBackground = (1 << 10), +}; +using Options = base::flags