mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added workaround for icon.
http://rainmeter.net/forum/viewtopic.php?f=14&t=10946
This commit is contained in:
parent
e3df01ed48
commit
3e1dc73e0e
@ -60,7 +60,7 @@ public:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddCache(const std::wstring& key, Bitmap* bitmap)
|
static void AddCache(const std::wstring& key, Bitmap* bitmap, HGLOBAL hBuffer)
|
||||||
{
|
{
|
||||||
std::unordered_map<std::wstring, ImageCache*>::const_iterator iter = c_CacheMap.find(key);
|
std::unordered_map<std::wstring, ImageCache*>::const_iterator iter = c_CacheMap.find(key);
|
||||||
if (iter != c_CacheMap.end())
|
if (iter != c_CacheMap.end())
|
||||||
@ -70,7 +70,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c_CacheMap[key] = new ImageCache(bitmap);
|
c_CacheMap[key] = new ImageCache(bitmap, hBuffer);
|
||||||
//LogWithArgs(LOG_DEBUG, L"* ADD: key=%s, ref=new", key.c_str());
|
//LogWithArgs(LOG_DEBUG, L"* ADD: key=%s, ref=new", key.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ private:
|
|||||||
class ImageCache
|
class ImageCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageCache(Bitmap* bitmap) : m_Bitmap(bitmap), m_Ref(1) {}
|
ImageCache(Bitmap* bitmap, HGLOBAL hBuffer) : m_Bitmap(bitmap), m_hBuffer(hBuffer), m_Ref(1) {}
|
||||||
~ImageCache() { Dispose(); }
|
~ImageCache() { Dispose(); }
|
||||||
|
|
||||||
void AddRef() { ++m_Ref; }
|
void AddRef() { ++m_Ref; }
|
||||||
@ -111,9 +111,10 @@ private:
|
|||||||
ImageCache() {}
|
ImageCache() {}
|
||||||
ImageCache(const ImageCache& cache) {}
|
ImageCache(const ImageCache& cache) {}
|
||||||
|
|
||||||
void Dispose() { delete m_Bitmap; m_Bitmap = NULL; }
|
void Dispose() { delete m_Bitmap; m_Bitmap = NULL; if (m_hBuffer) { ::GlobalFree(m_hBuffer); m_hBuffer = NULL; } }
|
||||||
|
|
||||||
Bitmap* m_Bitmap;
|
Bitmap* m_Bitmap;
|
||||||
|
HGLOBAL m_hBuffer;
|
||||||
int m_Ref;
|
int m_Ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ void CTintedImage::DisposeImage()
|
|||||||
** Loads the image from file handle
|
** Loads the image from file handle
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize)
|
Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, HGLOBAL* phBuffer)
|
||||||
{
|
{
|
||||||
HGLOBAL hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, fileSize);
|
HGLOBAL hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, fileSize);
|
||||||
if (hBuffer)
|
if (hBuffer)
|
||||||
@ -230,10 +231,12 @@ Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize)
|
|||||||
pStream->Release();
|
pStream->Release();
|
||||||
|
|
||||||
if (Ok == bitmap->GetLastStatus())
|
if (Ok == bitmap->GetLastStatus())
|
||||||
|
{
|
||||||
|
GUID guid;
|
||||||
|
if (Ok == bitmap->GetRawFormat(&guid) && guid != ImageFormatIcon)
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Convert loaded image to faster blittable bitmap (may increase memory usage slightly)
|
// Convert loaded image to faster blittable bitmap (may increase memory usage slightly)
|
||||||
{
|
|
||||||
Rect r(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
|
Rect r(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
|
||||||
Bitmap* clone = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
Bitmap* clone = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB);
|
||||||
{
|
{
|
||||||
@ -244,8 +247,10 @@ Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize)
|
|||||||
bitmap = clone;
|
bitmap = clone;
|
||||||
|
|
||||||
::GlobalFree(hBuffer);
|
::GlobalFree(hBuffer);
|
||||||
}
|
hBuffer = NULL;
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
|
}
|
||||||
|
*phBuffer = hBuffer;
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +261,7 @@ Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize)
|
|||||||
::GlobalFree(hBuffer);
|
::GlobalFree(hBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*phBuffer = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,15 +300,16 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
|
|||||||
DisposeImage();
|
DisposeImage();
|
||||||
|
|
||||||
Bitmap* bitmap = ImageCachePool::GetCache(key);
|
Bitmap* bitmap = ImageCachePool::GetCache(key);
|
||||||
|
HGLOBAL hBuffer = NULL;
|
||||||
|
|
||||||
m_Bitmap = (bitmap) ?
|
m_Bitmap = (bitmap) ?
|
||||||
bitmap :
|
bitmap :
|
||||||
LoadImageFromFileHandle(fileHandle, fileSize);
|
LoadImageFromFileHandle(fileHandle, fileSize, &hBuffer);
|
||||||
|
|
||||||
if (m_Bitmap)
|
if (m_Bitmap)
|
||||||
{
|
{
|
||||||
m_CacheKey = key;
|
m_CacheKey = key;
|
||||||
ImageCachePool::AddCache(key, m_Bitmap);
|
ImageCachePool::AddCache(key, m_Bitmap, hBuffer);
|
||||||
|
|
||||||
// Check whether the new image needs tinting (or cropping, flipping, rotating)
|
// Check whether the new image needs tinting (or cropping, flipping, rotating)
|
||||||
if (!m_NeedsCrop)
|
if (!m_NeedsCrop)
|
||||||
|
@ -98,7 +98,7 @@ protected:
|
|||||||
void ApplyTint();
|
void ApplyTint();
|
||||||
void ApplyTransform();
|
void ApplyTransform();
|
||||||
|
|
||||||
Gdiplus::Bitmap* LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize);
|
Gdiplus::Bitmap* LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, HGLOBAL* phBuffer);
|
||||||
|
|
||||||
static Gdiplus::Bitmap* TurnGreyscale(Gdiplus::Bitmap* source);
|
static Gdiplus::Bitmap* TurnGreyscale(Gdiplus::Bitmap* source);
|
||||||
static bool CompareColorMatrix(const Gdiplus::ColorMatrix* a, const Gdiplus::ColorMatrix* b);
|
static bool CompareColorMatrix(const Gdiplus::ColorMatrix* a, const Gdiplus::ColorMatrix* b);
|
||||||
|
Loading…
Reference in New Issue
Block a user