diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp index 5d0e50926e..3775f7503b 100644 --- a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp +++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp @@ -11,7 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "logs.h" #include + +#ifdef TDESKTOP_OFFICIAL_TARGET #include +#endif // TDESKTOP_OFFICIAL_TARGET extern "C" { #include @@ -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(dst), + reinterpret_cast(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(dst), + reinterpret_cast(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(toBytes), - reinterpret_cast(fromBytes), - width, - layout, - nullptr); + for (auto i = 0; i != height; ++i) { + UnPremultiplyLine(toBytes, fromBytes, width); fromBytes += fromPerLine; toBytes += toPerLine; } } else { - convert( - reinterpret_cast(to.bits()), - reinterpret_cast(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(bytes), - reinterpret_cast(bytes), - width, - layout, - nullptr); + for (auto i = 0; i != height; ++i) { + PremultiplyLine(bytes, bytes, width); bytes += perLine; } } else { - convert( - reinterpret_cast(image.bits()), - reinterpret_cast(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 9971d76ae6..b9ada5362f 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++' ], },