| 640 | } |
| 641 | |
| 642 | void BackgroundBox::Inner::validatePaperThumbnail( |
| 643 | const Paper &paper) const { |
| 644 | if (!paper.thumbnail.isNull()) { |
| 645 | return; |
| 646 | } |
| 647 | const auto localThumbnail = paper.data.localThumbnail(); |
| 648 | if (!localThumbnail) { |
| 649 | if (const auto document = paper.data.document()) { |
| 650 | if (!paper.dataMedia) { |
| 651 | paper.dataMedia = document->createMediaView(); |
| 652 | paper.dataMedia->thumbnailWanted(paper.data.fileOrigin()); |
| 653 | } |
| 654 | if (!paper.dataMedia->thumbnail()) { |
| 655 | return; |
| 656 | } |
| 657 | } else if (!paper.data.backgroundColors().empty()) { |
| 658 | paper.thumbnail = Ui::PixmapFromImage( |
| 659 | Ui::GenerateBackgroundImage( |
| 660 | st::backgroundSize * style::DevicePixelRatio(), |
| 661 | paper.data.backgroundColors(), |
| 662 | paper.data.gradientRotation())); |
| 663 | paper.thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); |
| 664 | return; |
| 665 | } else { |
| 666 | return; |
| 667 | } |
| 668 | } |
| 669 | const auto thumbnail = localThumbnail |
| 670 | ? localThumbnail |
| 671 | : paper.dataMedia->thumbnail(); |
| 672 | auto original = thumbnail->original(); |
| 673 | if (paper.data.isPattern()) { |
| 674 | original = Ui::PreparePatternImage( |
| 675 | std::move(original), |
| 676 | paper.data.backgroundColors(), |
| 677 | paper.data.gradientRotation(), |
| 678 | paper.data.patternOpacity()); |
| 679 | } |
| 680 | paper.thumbnail = Ui::PixmapFromImage(TakeMiddleSample( |
| 681 | original, |
| 682 | st::backgroundSize)); |
| 683 | paper.thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); |
| 684 | } |
| 685 | |
| 686 | bool BackgroundBox::Inner::forChannel() const { |
| 687 | return _forPeer && _forPeer->isChannel(); |
nothing calls this directly
no test coverage detected