1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
From 0710dde4d5526454318b2748331e887c01ecfdce Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Tue, 9 Jul 2019 13:43:57 +0200
Subject: [PATCH] Use private Qt color API only in official build.
Fixes #6219.
---
.../SourceFiles/ffmpeg/ffmpeg_utility.cpp | 100 ++++++++++++------
Telegram/gyp/lib_ffmpeg.gyp | 6 +-
2 files changed, 71 insertions(+), 35 deletions(-)
diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
index 5d0e50926..3775f7503 100644
--- a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
+++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
@@ -11,7 +11,10 @@ For license and copyright information please follow this link:
#include "logs.h"
#include <QImage>
+
+#ifdef TDESKTOP_OFFICIAL_TARGET
#include <private/qdrawhelper_p.h>
+#endif // TDESKTOP_OFFICIAL_TARGET
extern "C" {
#include <libavutil/opt.h>
@@ -44,6 +47,58 @@ void AlignedImageBufferCleanupHandler(void* data) {
&& !(image.bytesPerLine() % kAlignImageBy);
}
+void UnPremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
+#ifdef TDESKTOP_OFFICIAL_TARGET
+ const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
+ const auto convert = layout->convertFromARGB32PM;
+#else // TDESKTOP_OFFICIAL_TARGET
+ const auto layout = nullptr;
+ const auto convert = [](
+ uint *dst,
+ const uint *src,
+ int count,
+ std::nullptr_t,
+ std::nullptr_t) {
+ for (auto i = 0; i != count; ++i) {
+ dst[i] = qUnpremultiply(src[i]);
+ }
+ };
+#endif // TDESKTOP_OFFICIAL_TARGET
+
+ convert(
+ reinterpret_cast<uint*>(dst),
+ reinterpret_cast<const uint*>(src),
+ intsCount,
+ layout,
+ nullptr);
+}
+
+void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
+#ifdef TDESKTOP_OFFICIAL_TARGET
+ const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
+ const auto convert = layout->convertToARGB32PM;
+#else // TDESKTOP_OFFICIAL_TARGET
+ const auto layout = nullptr;
+ const auto convert = [](
+ uint *dst,
+ const uint *src,
+ int count,
+ std::nullptr_t,
+ std::nullptr_t) {
+ for (auto i = 0; i != count; ++i) {
+ dst[i] = qPremultiply(src[i]);
+ }
+ };
+#endif // TDESKTOP_OFFICIAL_TARGET
+
+ convert(
+ reinterpret_cast<uint*>(dst),
+ reinterpret_cast<const uint*>(src),
+ intsCount,
+ layout,
+ nullptr);
+}
+
} // namespace
IOPointer MakeIOPointer(
@@ -360,58 +415,35 @@ void UnPremultiply(QImage &to, const QImage &from) {
if (!GoodStorageForFrame(to, from.size())) {
to = CreateFrameStorage(from.size());
}
-
- const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
- const auto convert = layout->convertFromARGB32PM;
const auto fromPerLine = from.bytesPerLine();
const auto toPerLine = to.bytesPerLine();
const auto width = from.width();
+ const auto height = from.height();
+ auto fromBytes = from.bits();
+ auto toBytes = to.bits();
if (fromPerLine != width * 4 || toPerLine != width * 4) {
- auto fromBytes = from.bits();
- auto toBytes = to.bits();
- for (auto i = 0; i != to.height(); ++i) {
- convert(
- reinterpret_cast<uint*>(toBytes),
- reinterpret_cast<const uint*>(fromBytes),
- width,
- layout,
- nullptr);
+ for (auto i = 0; i != height; ++i) {
+ UnPremultiplyLine(toBytes, fromBytes, width);
fromBytes += fromPerLine;
toBytes += toPerLine;
}
} else {
- convert(
- reinterpret_cast<uint*>(to.bits()),
- reinterpret_cast<const uint*>(from.bits()),
- from.width() * from.height(),
- layout,
- nullptr);
+ UnPremultiplyLine(toBytes, fromBytes, width * height);
}
}
void PremultiplyInplace(QImage &image) {
- const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
- const auto convert = layout->convertToARGB32PM;
const auto perLine = image.bytesPerLine();
const auto width = image.width();
+ const auto height = image.height();
+ auto bytes = image.bits();
if (perLine != width * 4) {
- auto bytes = image.bits();
- for (auto i = 0; i != image.height(); ++i) {
- convert(
- reinterpret_cast<uint*>(bytes),
- reinterpret_cast<const uint*>(bytes),
- width,
- layout,
- nullptr);
+ for (auto i = 0; i != height; ++i) {
+ PremultiplyLine(bytes, bytes, width);
bytes += perLine;
}
} else {
- convert(
- reinterpret_cast<uint*>(image.bits()),
- reinterpret_cast<const uint*>(image.bits()),
- image.width() * image.height(),
- layout,
- nullptr);
+ PremultiplyLine(bytes, bytes, width * height);
}
}
diff --git a/Telegram/gyp/lib_ffmpeg.gyp b/Telegram/gyp/lib_ffmpeg.gyp
index 9971d76ae..b9ada5362 100644
--- a/Telegram/gyp/lib_ffmpeg.gyp
+++ b/Telegram/gyp/lib_ffmpeg.gyp
@@ -46,7 +46,11 @@
'<(src_loc)/ffmpeg/ffmpeg_utility.cpp',
'<(src_loc)/ffmpeg/ffmpeg_utility.h',
],
- 'conditions': [[ 'build_macold', {
+ 'conditions': [[ '"<(official_build_target)" != ""', {
+ 'defines': [
+ 'TDESKTOP_OFFICIAL_TARGET=<(official_build_target)',
+ ],
+ }], [ 'build_macold', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '-nostdinc++' ],
},
|