summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-11-27 19:24:42 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-11-27 19:24:42 +0300
commit80e5db5c24521f325c0b7cd4619631e1853566b0 (patch)
tree2452cc742775b11d7238b7a7130af21de4085125
parent0a2bac03e5bae0e72f02dbb1c6c56b8ab3822024 (diff)
fiexs #4796 (NewStory: не отображается прозрачность у смайлов)
-rw-r--r--plugins/NewStory/src/history_control.h4
-rw-r--r--plugins/NewStory/src/stdafx.h2
-rw-r--r--plugins/NewStory/src/templates.cpp4
-rw-r--r--plugins/NewStory/src/utils.cpp25
-rw-r--r--plugins/NewStory/src/utils.h2
-rw-r--r--plugins/NewStory/src/webpage.cpp92
6 files changed, 77 insertions, 52 deletions
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index e74b7b754b..5c26afb970 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -77,8 +77,8 @@ public:
NSWebPage(NewstoryListData &_1);
~NSWebPage();
- FIBITMAP* find_image(const wchar_t *pwszUrl);
- FIBITMAP* load_image(const wchar_t *pwszUrl, ItemData *pItem);
+ Bitmap* find_image(const wchar_t *pwszUrl);
+ Bitmap* load_image(const wchar_t *pwszUrl, ItemData *pItem);
void draw();
};
diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h
index 6f3d1440b1..a0edec01c5 100644
--- a/plugins/NewStory/src/stdafx.h
+++ b/plugins/NewStory/src/stdafx.h
@@ -107,7 +107,7 @@ struct CMPlugin : public PLUGIN<CMPlugin>
HANDLE m_log;
HBRUSH hBackBrush;
- FIBITMAP *m_pNoImage;
+ Bitmap *m_pNoImage;
ULONG_PTR m_gdiplusToken;
CMOption<bool> bOptVScroll, bSortAscending;
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index b0b93524fc..9d3a9cf633 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -52,8 +52,8 @@ static void AppendImage(CMStringW &buf, const CMStringW &wszUrl, const CMStringW
int iHeight = uMaxHeight;
if (auto *pImage = pItem->pOwner->webPage.find_image(wszUrl)) {
- if (FreeImage_GetHeight(pImage) < uMaxHeight)
- iHeight = FreeImage_GetHeight(pImage);
+ if (pImage->GetHeight() < uMaxHeight)
+ iHeight = pImage->GetHeight();
buf.AppendFormat(L"<img style=\"height: %dpx;\" src=\"%s\"/><br>", iHeight, wszUrl.c_str());
}
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index 811eac0e0d..f6aca92604 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -20,14 +20,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <msapi/comptr.h>
-FIBITMAP* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
+Bitmap* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
{
if (HRSRC hrsrc = FindResourceW(hInst, MAKEINTRESOURCE(resourceId), pwszType)) {
- if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
- auto *pMemory = FreeImage_OpenMemory((uint8_t*)LockResource(hRes), SizeofResource(hInst, hrsrc));
- auto *pDib = FreeImage_LoadFromMemory(FIF_PNG, pMemory);
- FreeImage_CloseMemory(pMemory);
- return pDib;
+ if (DWORD dwSize = SizeofResource(hInst, hrsrc)) {
+ if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
+ void *pImage = LockResource(hRes);
+
+ if (HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize)) {
+ void *pBuffer = ::GlobalLock(hGlobal);
+ if (pBuffer) {
+ memcpy(pBuffer, pImage, dwSize);
+
+ CComPtr<IStream> pStream;
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ if (SUCCEEDED(hr))
+ return new Gdiplus::Bitmap(pStream);
+ }
+
+ GlobalFree(hGlobal); // free memory only if the function fails
+ }
+ }
}
}
diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h
index f18a5944d9..1858c34d9c 100644
--- a/plugins/NewStory/src/utils.h
+++ b/plugins/NewStory/src/utils.h
@@ -12,6 +12,6 @@ int GetFontHeight(const LOGFONTA &lf);
void UrlAutodetect(CMStringW &str);
void RemoveBbcodes(CMStringW &pwszText);
-FIBITMAP* LoadImageFromResource(HINSTANCE, int, const wchar_t *);
+Bitmap* LoadImageFromResource(HINSTANCE, int, const wchar_t *);
int SmartSendEvent(int iEvent, MCONTACT hContact, LPARAM lParam);
diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp
index 79dbdd095b..e0453db41b 100644
--- a/plugins/NewStory/src/webpage.cpp
+++ b/plugins/NewStory/src/webpage.cpp
@@ -332,16 +332,16 @@ void NSWebPage::draw_list_marker(uint_ptr hdc, const list_marker &marker)
release_clip((HDC)hdc);
}
-FIBITMAP* NSWebPage::load_image(const wchar_t *pwszUrl, ItemData *pItem)
+Bitmap* NSWebPage::load_image(const wchar_t *pwszUrl, ItemData *pItem)
{
mir_cslockfull lck(m_csImages);
auto img = m_images.find(pwszUrl);
if (img != m_images.end() && img->second)
- return (FIBITMAP *)img->second;
+ return (Bitmap *)img->second;
if (uint_ptr newImg = get_image(pwszUrl, false)) {
add_image(pwszUrl, newImg);
- return (FIBITMAP *)newImg;
+ return (Bitmap *)newImg;
}
NSWebCache tmp(this, pwszUrl, pItem);
@@ -371,12 +371,12 @@ void NSWebPage::add_image(LPCWSTR url, uint_ptr img)
m_images[url] = img;
}
-FIBITMAP* NSWebPage::find_image(const wchar_t *pwszUrl)
+Bitmap* NSWebPage::find_image(const wchar_t *pwszUrl)
{
mir_cslock lck(m_csImages);
auto img = m_images.find(pwszUrl);
if (img != m_images.end() && img->second)
- return (FIBITMAP *)img->second;
+ return (Bitmap *)img->second;
return nullptr;
}
@@ -398,7 +398,7 @@ void NSWebPage::clear_images()
mir_cslock lck(m_csImages);
for (auto &img : m_images)
if (img.second)
- delete (FIBITMAP *)img.second;
+ delete (Bitmap *)img.second;
m_images.clear();
}
@@ -494,13 +494,6 @@ void NSWebPage::link(const document::ptr &, const element::ptr &)
/////////////////////////////////////////////////////////////////////////////////////////
// GDI+ part (former gdiplus_container)
-static void FreeImage_Draw(HDC hdc, FIBITMAP *pdib, int x, int y, int w, int h)
-{
- BITMAPINFO *pbmpi = FreeImage_GetInfo(pdib);
- BYTE *pDibBits = FreeImage_GetBits(pdib);
- ::SetDIBitsToDevice(hdc, x, y, w, h, 0, 0, 0, h, pDibBits, pbmpi, DIB_RGB_COLORS);
-}
-
static Color gdiplus_color(web_color color)
{
return Color(color.alpha, color.red, color.green, color.blue);
@@ -538,10 +531,10 @@ void NSWebPage::fill_rect(HDC hdc, int x, int y, int width, int height, web_colo
void NSWebPage::get_img_size(uint_ptr img, size &sz)
{
- FIBITMAP *bmp = (FIBITMAP *)img;
+ Bitmap *bmp = (Bitmap *)img;
if (bmp) {
- sz.width = FreeImage_GetWidth(bmp);
- sz.height = FreeImage_GetHeight(bmp);
+ sz.width = bmp->GetWidth();
+ sz.height = bmp->GetHeight();
}
}
@@ -552,7 +545,7 @@ void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std:
std::wstring url = Utf2T(src.c_str());
- FIBITMAP *bgbmp = find_image(url.c_str());
+ Bitmap *bgbmp = find_image(url.c_str());
if (!bgbmp)
bgbmp = g_plugin.m_pNoImage;
@@ -560,54 +553,62 @@ void NSWebPage::draw_image(uint_ptr _hdc, const background_layer &bg, const std:
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
- Gdiplus::Region reg(Rect(bg.border_box.left(), bg.border_box.top(), bg.border_box.width, bg.border_box.height));
+ Region reg(Rect(bg.border_box.left(), bg.border_box.top(), bg.border_box.width, bg.border_box.height));
graphics.SetClip(&reg);
- FIBITMAP *scaled_img = nullptr;
- int iWidth = FreeImage_GetHeight(bgbmp), iHeight = FreeImage_GetWidth(bgbmp);
- if (bg.origin_box.width != iWidth || bg.origin_box.height != iHeight) {
- bgbmp = scaled_img = FreeImage_Rescale(bgbmp, bg.origin_box.width, bg.origin_box.height);
- iWidth = bg.origin_box.width; iHeight = bg.origin_box.height;
+ Bitmap *scaled_img = nullptr;
+ if (bg.origin_box.width != (int)bgbmp->GetWidth() || bg.origin_box.height != (int)bgbmp->GetHeight()) {
+ scaled_img = new Bitmap(bg.origin_box.width, bg.origin_box.height);
+ Graphics gr(scaled_img);
+ gr.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
+ gr.DrawImage(bgbmp, 0, 0, bg.origin_box.width, bg.origin_box.height);
+ bgbmp = scaled_img;
}
switch (bg.repeat) {
case background_repeat_no_repeat:
- FreeImage_Draw((HDC)_hdc, bgbmp, bg.origin_box.x, bg.origin_box.y, iWidth, iHeight);
+ {
+ graphics.DrawImage(bgbmp, bg.origin_box.x, bg.origin_box.y, bgbmp->GetWidth(), bgbmp->GetHeight());
+ }
break;
-
case background_repeat_repeat_x:
{
+ CachedBitmap bmp(bgbmp, &graphics);
int x = bg.origin_box.x;
- while (x > bg.clip_box.left())
- x -= iWidth;
- for (; x < bg.clip_box.right(); x += iWidth)
- FreeImage_Draw((HDC)_hdc, bgbmp, x, bg.origin_box.y, iWidth, iHeight);
+ while (x > bg.clip_box.left()) x -= bgbmp->GetWidth();
+ for (; x < bg.clip_box.right(); x += bgbmp->GetWidth()) {
+ graphics.DrawCachedBitmap(&bmp, x, bg.origin_box.y);
+ }
}
break;
case background_repeat_repeat_y:
{
+ CachedBitmap bmp(bgbmp, &graphics);
int y = bg.origin_box.y;
- while (y > bg.clip_box.top()) y -= iHeight;
- for (; y < bg.clip_box.bottom(); y += iHeight)
- FreeImage_Draw((HDC)_hdc, bgbmp, bg.origin_box.x, y, iWidth, iHeight);
+ while (y > bg.clip_box.top()) y -= bgbmp->GetHeight();
+ for (; y < bg.clip_box.bottom(); y += bgbmp->GetHeight()) {
+ graphics.DrawCachedBitmap(&bmp, bg.origin_box.x, y);
+ }
}
break;
case background_repeat_repeat:
{
+ CachedBitmap bmp(bgbmp, &graphics);
int x = bg.origin_box.x;
- while (x > bg.clip_box.left()) x -= iWidth;
+ while (x > bg.clip_box.left()) x -= bgbmp->GetWidth();
int y0 = bg.origin_box.y;
- while (y0 > bg.clip_box.top()) y0 -= iHeight;
+ while (y0 > bg.clip_box.top()) y0 -= bgbmp->GetHeight();
- for (; x < bg.clip_box.right(); x += iWidth)
- for (int y = y0; y < bg.clip_box.bottom(); y += iHeight)
- FreeImage_Draw((HDC)_hdc, bgbmp, x, y, iWidth, iHeight);
+ for (; x < bg.clip_box.right(); x += bgbmp->GetWidth()) {
+ for (int y = y0; y < bg.clip_box.bottom(); y += bgbmp->GetHeight()) {
+ graphics.DrawCachedBitmap(&bmp, x, y);
+ }
+ }
}
break;
}
- if (scaled_img)
- FreeImage_Unload(scaled_img);
+ delete scaled_img;
}
// length of dash and space for "dashed" style, in multiples of pen width
@@ -703,7 +704,18 @@ uint_ptr NSWebPage::get_image(LPCWSTR url_or_path, bool)
if (!mir_wstrncmp(url_or_path, L"file://", 7))
url_or_path += 7;
- return (uint_ptr)FreeImage_LoadU(FreeImage_GetFIFFromFilenameU(url_or_path), url_or_path);
+ IStream *pStream = 0;
+ HRESULT hr = SHCreateStreamOnFileEx(url_or_path, STGM_READ | STGM_SHARE_DENY_NONE, 0, FALSE, 0, &pStream);
+ if (!SUCCEEDED(hr))
+ return 0;
+
+ auto *pImage = new Gdiplus::Bitmap(pStream);
+ pStream->Release();
+ if (pImage->GetLastStatus() != Ok) {
+ delete pImage;
+ return 0;
+ }
+ return (uint_ptr)pImage;
}
void NSWebPage::get_client_rect(position &pos) const