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