summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-11-04 15:43:52 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-11-04 15:43:52 +0300
commit5d20eeecbaba7102e257dae06c8cfc43f2ebce4d (patch)
treefc868b513a663cccd4f770edd0f2754bf7fb4570
parent2829883e8d5116bb7f0983022e08791aa1aa47c3 (diff)
fixes #4764 (Telegram: animated sitckers in TGA format are converted into PNG on the fly)
-rw-r--r--protocols/Telegram/src/avatars.cpp8
-rw-r--r--protocols/Telegram/src/proto.h2
-rw-r--r--protocols/Telegram/src/utils.cpp38
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<CTelegramProto>
CMStringA GetFormattedText(TD::object_ptr<TD::formattedText> &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");