From 5d20eeecbaba7102e257dae06c8cfc43f2ebce4d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 4 Nov 2024 15:43:52 +0300 Subject: fixes #4764 (Telegram: animated sitckers in TGA format are converted into PNG on the fly) --- protocols/Telegram/src/avatars.cpp | 8 ++++++++ protocols/Telegram/src/proto.h | 2 +- protocols/Telegram/src/utils.cpp | 38 +++++++++++++++----------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 873db7663f..0636af1f04 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -253,6 +253,14 @@ void CTelegramProto::ProcessFile(TD::updateFile *pObj) FreeImage_Unload(pImage); } } + else if (F->m_fileName.Right(4).MakeLower() == L".tga") { + if (auto *pImage = FreeImage_LoadU(FIF_TARGA, wszExistingFile)) { + wszFullName.Truncate(wszFullName.GetLength() - 5); + wszFullName += L".png"; + FreeImage_SaveU(FIF_PNG, pImage, wszFullName); + FreeImage_Unload(pImage); + } + } else MoveFileW(wszExistingFile, wszFullName); if (F->m_isSmiley) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index f79a7f6028..dec95199dc 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -304,7 +304,7 @@ class CTelegramProto : public PROTO CMStringA GetFormattedText(TD::object_ptr &pText); CMStringA GetMessagePreview(const TD::file *pFile); - CMStringA GetMessageSticker(const TD::file *pFile, const char *pwszExtension); + CMStringA GetMessageSticker(const TD::file *pFile, const TD::ThumbnailFormat *pFormat); CMStringA GetMessageText(TG_USER *pUser, const TD::message *pMsg, bool bSkipJoin = false, bool bRead = false); void UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str); diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 65d9292d68..768c7972f3 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -508,7 +508,7 @@ CMStringA CTelegramProto::GetMessagePreview(const TD::file *pFile) return T2Utf(pRequest->m_destPath + L"\\" + pRequest->m_fileName).get(); } -CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *pwszExtension) +CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const TD::ThumbnailFormat *pFormat) { auto *pFileId = pFile->remote_->unique_id_.c_str(); @@ -517,7 +517,18 @@ CMStringA CTelegramProto::GetMessageSticker(const TD::file *pFile, const char *p pRequest->m_destPath = GetAvatarPath() + L"\\Stickers"; CreateDirectoryW(pRequest->m_destPath, 0); - pRequest->m_fileName.Format(L"STK{%S}.%S", pFileId, pwszExtension); + const char *pszFileExt; + switch (pFormat->get_id()) { + case TD::thumbnailFormatGif::ID: pszFileExt = "gif"; break; + case TD::thumbnailFormatPng::ID: pszFileExt = "png"; break; + case TD::thumbnailFormatTgs::ID: pszFileExt = "tga"; break; + case TD::thumbnailFormatJpeg::ID: pszFileExt = "jpg"; break; + case TD::thumbnailFormatWebm::ID: pszFileExt = "webm"; break; + case TD::thumbnailFormatWebp::ID: pszFileExt = "webp"; break; + default:pszFileExt = "jpeg"; break; + } + + pRequest->m_fileName.Format(L"STK{%S}.%S", pFileId, pszFileExt); { mir_cslock lck(m_csFiles); m_arFiles.insert(pRequest); @@ -713,18 +724,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg break; } - const char *pwszFileExt; - switch (pSticker->thumbnail_->format_->get_id()) { - case TD::thumbnailFormatGif::ID: pwszFileExt = "gif"; break; - case TD::thumbnailFormatPng::ID: pwszFileExt = "png"; break; - case TD::thumbnailFormatTgs::ID: pwszFileExt = "tga"; break; - case TD::thumbnailFormatJpeg::ID: pwszFileExt = "jpg"; break; - case TD::thumbnailFormatWebm::ID: pwszFileExt = "webm"; break; - case TD::thumbnailFormatWebp::ID: pwszFileExt = "webp"; break; - default:pwszFileExt = "jpeg"; break; - } - - ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt); + ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pSticker->thumbnail_->format_.get()); break; } } @@ -742,15 +742,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg if (m_bSmileyAdd) { if (pSticker->thumbnail_.get()) { - const char *pwszFileExt; - switch (pSticker->format_->get_id()) { - case TD::stickerFormatTgs::ID: pwszFileExt = "tga"; break; - case TD::stickerFormatWebm::ID: pwszFileExt = "webm"; break; - case TD::stickerFormatWebp::ID: pwszFileExt = "webp"; break; - default: - pwszFileExt = "jpeg"; break; - } - ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pwszFileExt); + ret = GetMessageSticker(pSticker->thumbnail_->file_.get(), pSticker->thumbnail_->format_.get()); } else { debugLogA("Strange sticker without preview"); -- cgit v1.2.3