"Fossies" - the Fresh Open Source Software Archive 
Member "tdesktop-2.6.1/Telegram/SourceFiles/chat_helpers/stickers_emoji_image_loader.cpp" (24 Feb 2021, 2415 Bytes) of package /linux/misc/tdesktop-2.6.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "stickers_emoji_image_loader.cpp" see the
Fossies "Dox" file reference documentation.
1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #include "chat_helpers/stickers_emoji_image_loader.h"
9
10 #include "styles/style_chat.h"
11
12 namespace Stickers {
13
14 EmojiImageLoader::EmojiImageLoader(crl::weak_on_queue<EmojiImageLoader> weak)
15 : _weak(std::move(weak)) {
16 }
17
18 void EmojiImageLoader::init(
19 std::shared_ptr<UniversalImages> images,
20 bool largeEnabled) {
21 Expects(images != nullptr);
22
23 _images = std::move(images);
24 if (largeEnabled) {
25 _images->ensureLoaded();
26 }
27 }
28
29 QImage EmojiImageLoader::prepare(EmojiPtr emoji) const {
30 const auto loaded = _images->ensureLoaded();
31 const auto factor = cIntRetinaFactor();
32 const auto side = st::largeEmojiSize + 2 * st::largeEmojiOutline;
33 auto tinted = QImage(
34 QSize(st::largeEmojiSize, st::largeEmojiSize) * factor,
35 QImage::Format_ARGB32_Premultiplied);
36 tinted.fill(Qt::white);
37 if (loaded) {
38 QPainter p(&tinted);
39 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
40 _images->draw(
41 p,
42 emoji,
43 st::largeEmojiSize * factor,
44 0,
45 0);
46 }
47 auto result = QImage(
48 QSize(side, side) * factor,
49 QImage::Format_ARGB32_Premultiplied);
50 result.fill(Qt::transparent);
51 if (loaded) {
52 QPainter p(&result);
53 const auto delta = st::largeEmojiOutline * factor;
54 const auto planar = std::array<QPoint, 4>{ {
55 { 0, -1 },
56 { -1, 0 },
57 { 1, 0 },
58 { 0, 1 },
59 } };
60 for (const auto &shift : planar) {
61 for (auto i = 0; i != delta; ++i) {
62 p.drawImage(QPoint(delta, delta) + shift * (i + 1), tinted);
63 }
64 }
65 const auto diagonal = std::array<QPoint, 4>{ {
66 { -1, -1 },
67 { 1, -1 },
68 { -1, 1 },
69 { 1, 1 },
70 } };
71 const auto corrected = int(std::round(delta / sqrt(2.)));
72 for (const auto &shift : diagonal) {
73 for (auto i = 0; i != corrected; ++i) {
74 p.drawImage(QPoint(delta, delta) + shift * (i + 1), tinted);
75 }
76 }
77 _images->draw(
78 p,
79 emoji,
80 st::largeEmojiSize * factor,
81 delta,
82 delta);
83 }
84 return result;
85 }
86
87 void EmojiImageLoader::switchTo(std::shared_ptr<UniversalImages> images) {
88 _images = std::move(images);
89 }
90
91 auto EmojiImageLoader::releaseImages() -> std::shared_ptr<UniversalImages> {
92 return std::exchange(
93 _images,
94 std::make_shared<UniversalImages>(_images->id()));
95 }
96
97 } // namespace Stickers