summaryrefslogtreecommitdiff
path: root/plugins/SmileyAdd/src/imagecache.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-11-10 11:41:26 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-11-10 11:41:26 +0000
commit0f954168b4bac9877e79f9150e7689cf67b98d10 (patch)
tree5132ce0e6550ff96acadfc34b685ea24218f0da4 /plugins/SmileyAdd/src/imagecache.cpp
parent09fba0e6c57fe19189150de73a7a9ad7f3462224 (diff)
last portion of fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@6855 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SmileyAdd/src/imagecache.cpp')
-rw-r--r--plugins/SmileyAdd/src/imagecache.cpp294
1 files changed, 50 insertions, 244 deletions
diff --git a/plugins/SmileyAdd/src/imagecache.cpp b/plugins/SmileyAdd/src/imagecache.cpp
index 87b95f5a60..e9cd07afa6 100644
--- a/plugins/SmileyAdd/src/imagecache.cpp
+++ b/plugins/SmileyAdd/src/imagecache.cpp
@@ -32,8 +32,7 @@ static void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
{
WaitForSingleObject(g_hMutexIm, 3000);
const time_t ts = time(NULL) - 10;
- if ( lastmodule && ts > laststamp)
- {
+ if ( lastmodule && ts > laststamp) {
FreeLibrary(lastmodule);
lastmodule = NULL;
lastdllname.Empty();
@@ -65,8 +64,7 @@ static HMODULE LoadDll(const CMString& file)
{
WaitForSingleObject(g_hMutexIm, 3000);
- if (lastdllname != file)
- {
+ if (lastdllname != file) {
FreeLibrary(lastmodule);
lastdllname = file;
@@ -112,10 +110,9 @@ void ImageBase::ProcessTimerTick(time_t ts)
{
WaitForSingleObject(g_hMutexIm, 3000);
if (m_lRefCount == 0 && m_timestamp < ts )
- {
if (!g_imagecache.remove(this))
delete this;
- }
+
ReleaseMutex(g_hMutexIm);
}
@@ -131,8 +128,7 @@ int ImageBase::CompareImg(const ImageBase* p1, const ImageBase* p2)
void ImageBase::Draw(HDC hdc, RECT& rc, bool clip)
{
HRGN hrgn = NULL;
- if (clip)
- {
+ if (clip) {
hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
SelectClipRgn(hdc, hrgn);
}
@@ -151,8 +147,7 @@ void ImageBase::Draw(HDC hdc, RECT& rc, bool clip)
DrawInternal(hdc, x, y, scaleX, scaleY);
- if (clip)
- {
+ if (clip) {
SelectClipRgn(hdc, NULL);
DeleteObject(hrgn);
}
@@ -163,8 +158,7 @@ HBITMAP ImageBase::GetBitmap(COLORREF bkgClr, int sizeX, int sizeY)
{
RECT rc = { 0, 0, sizeX, sizeY };
- if (sizeX == 0 || sizeY == 0)
- {
+ if (sizeX == 0 || sizeY == 0) {
SIZE iSize;
GetSize(iSize);
@@ -203,8 +197,7 @@ IconType::IconType(const unsigned id, const CMString& file, const int index, con
{
m_SmileyIcon = NULL;
- switch (type)
- {
+ switch (type) {
case icoDll:
{
const HMODULE hModule = LoadDll(file);
@@ -241,17 +234,18 @@ HICON IconType::GetIcon(void)
void IconType::GetSize(SIZE& size)
{
- if (m_SmileyIcon != NULL)
- {
- ICONINFO ii;
- BITMAP bm;
- GetIconInfo(m_SmileyIcon, &ii);
- GetObject(ii.hbmColor, sizeof(bm), &bm);
- size.cx = bm.bmWidth;
- size.cy = bm.bmHeight;
- DeleteObject(ii.hbmMask);
- DeleteObject(ii.hbmColor);
- }
+ if (m_SmileyIcon == NULL)
+ return;
+
+ ICONINFO ii;
+ GetIconInfo(m_SmileyIcon, &ii);
+
+ BITMAP bm;
+ GetObject(ii.hbmColor, sizeof(bm), &bm);
+ size.cx = bm.bmWidth;
+ size.cy = bm.bmHeight;
+ DeleteObject(ii.hbmMask);
+ DeleteObject(ii.hbmColor);
}
@@ -270,8 +264,7 @@ void ImageListItemType::DrawInternal(HDC hdc, int x, int y, int sizeX, int sizeY
if (sizeX >= iSize.cx && sizeY >= iSize.cy)
ImageList_Draw(m_hImList, m_index, hdc, x, y, ILD_TRANSPARENT);
- else
- {
+ else {
HICON hIcon = ImageList_GetIconFixed(m_hImList, m_index, ILD_TRANSPARENT);
DrawIconEx(hdc, x, y, hIcon, sizeX, sizeY, 0, NULL, DI_NORMAL);
DestroyIcon(hIcon);
@@ -303,8 +296,7 @@ ImageType::ImageType(const unsigned id, const CMString& file, IStream* pStream)
else
m_bmp = new Gdiplus::Bitmap(T2W_SM(file.c_str()));
- if (m_bmp->GetLastStatus() != Gdiplus::Ok)
- {
+ if (m_bmp->GetLastStatus() != Gdiplus::Ok) {
delete m_bmp;
m_bmp = NULL;
return;
@@ -313,8 +305,7 @@ ImageType::ImageType(const unsigned id, const CMString& file, IStream* pStream)
GUID pageGuid = Gdiplus::FrameDimensionTime;
m_nFrameCount = m_bmp->GetFrameCount(&pageGuid);
- if (IsAnimated())
- {
+ if (IsAnimated()) {
int nSize = m_bmp->GetPropertyItemSize(PropertyTagFrameDelay);
m_pPropertyItem = (Gdiplus::PropertyItem*) new char[nSize];
m_bmp->GetPropertyItem(PropertyTagFrameDelay, nSize, m_pPropertyItem);
@@ -327,17 +318,15 @@ ImageType::ImageType(const unsigned id, const CMString& file, const int index, c
m_bmp = NULL;
m_pPropertyItem = NULL;
m_nCurrentFrame = 0;
- m_nFrameCount = 0;
+ m_nFrameCount = 0;
if (!InitGdiPlus()) return;
- switch (type)
- {
+ switch (type) {
case icoDll:
{
const HMODULE hModule = LoadDll(file);
- if (hModule != NULL)
- {
+ if (hModule != NULL) {
HICON hIcon = (HICON) LoadImage(hModule, MAKEINTRESOURCE(-index), IMAGE_ICON, 0, 0, 0);
m_bmp = new Gdiplus::Bitmap(hIcon);
DestroyIcon(hIcon);
@@ -357,8 +346,7 @@ ImageType::ImageType(const unsigned id, const CMString& file, const int index, c
break;
}
- if (m_bmp->GetLastStatus() != Gdiplus::Ok)
- {
+ if (m_bmp->GetLastStatus() != Gdiplus::Ok) {
delete m_bmp;
m_bmp = NULL;
return;
@@ -375,8 +363,7 @@ ImageType::~ImageType(void)
void ImageType::SelectFrame(int frame)
{
if ((unsigned)frame >= (unsigned)m_nFrameCount) frame = 0;
- if (IsAnimated() && frame != m_nCurrentFrame)
- {
+ if (IsAnimated() && frame != m_nCurrentFrame) {
m_nCurrentFrame = frame;
GUID pageGuid = Gdiplus::FrameDimensionTime;
m_bmp->SelectActiveFrame(&pageGuid, frame);
@@ -389,11 +376,10 @@ void ImageType::DrawInternal(HDC hdc, int x, int y, int sizeX, int sizeY)
if (m_bmp == NULL) return;
WaitForSingleObject(g_hMutexIm, 3000);
- {
- Gdiplus::Graphics grp(hdc);
-// if (opt.HQScaling) grp.SetInterpolationMode(Gdiplus::InterpolationModeBicubic);
- grp.DrawImage(m_bmp, x, y, sizeX, sizeY);
- }
+
+ Gdiplus::Graphics grp(hdc);
+ grp.DrawImage(m_bmp, x, y, sizeX, sizeY);
+
ReleaseMutex(g_hMutexIm);
}
@@ -418,16 +404,11 @@ HICON ImageType::GetIcon(void)
void ImageType::GetSize(SIZE& size)
{
- if (m_bmp)
- {
+ if (m_bmp) {
size.cx = m_bmp->GetWidth();
size.cy = m_bmp->GetHeight();
}
- else
- {
- size.cx = 0;
- size.cy = 0;
- }
+ else size.cx = size.cy = 0;
}
@@ -454,14 +435,12 @@ ImageFType::ImageFType(const unsigned id, const CMString& file)
FREE_IMAGE_TYPE imt = fei->FI_GetImageType(dib);
unsigned bpp = fei->FI_GetBPP(dib);
- if (transp && bpp != 32 || imt == FIT_RGBA16)
- {
+ if (transp && bpp != 32 || imt == FIT_RGBA16) {
FIBITMAP *tdib = fei->FI_ConvertTo32Bits(dib);
fei->FI_Unload(dib);
dib = tdib;
}
- else if (!transp && bpp > 24)
- {
+ else if (!transp && bpp > 24) {
FIBITMAP *tdib = fei->FI_ConvertTo24Bits(dib);
fei->FI_Unload(dib);
dib = tdib;
@@ -489,17 +468,13 @@ void ImageFType::DrawInternal(HDC hdc, int x, int y, int sizeX, int sizeY)
BITMAP bm;
GetObject(m_bmp, sizeof(bm), &bm);
- if (bm.bmBitsPixel == 32)
- {
+ if (bm.bmBitsPixel == 32) {
BLENDFUNCTION bf = {0};
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;
GdiAlphaBlend(hdc, x, y, sizeX, sizeY, hdcImg, 0, 0, bm.bmWidth, bm.bmHeight, bf);
}
- else
- {
- BitBlt(hdc, x, y, sizeX, sizeY, hdcImg, 0, 0, SRCCOPY);
- }
+ else BitBlt(hdc, x, y, sizeX, sizeY, hdcImg, 0, 0, SRCCOPY);
SelectObject(hdcImg, oldBmp);
DeleteDC(hdcImg);
@@ -507,9 +482,8 @@ void ImageFType::DrawInternal(HDC hdc, int x, int y, int sizeX, int sizeY)
HICON ImageFType::GetIcon(void)
{
- if (m_bmp == NULL) return NULL;
-
- HICON hIcon;
+ if (m_bmp == NULL)
+ return NULL;
BITMAP bm;
GetObject(m_bmp, sizeof(bm), &bm);
@@ -518,187 +492,23 @@ HICON ImageFType::GetIcon(void)
ii.fIcon = TRUE;
ii.xHotspot = 0;
ii.yHotspot = 0;
-
- if (bm.bmBitsPixel == 32 && GetWinVer() < 0x0501)
- {
- int slen = bm.bmWidth * 4;
- int len = bm.bmHeight * slen;
-
- BYTE* p = (BYTE*)mir_alloc(len);
- BYTE* maskBits = (BYTE*)mir_calloc(len);
- BYTE* colorBits = (BYTE*)mir_calloc(len);
-
- GetBitmapBits(m_bmp, len, p);
-
- for (int y = 0; y < bm.bmHeight; ++y)
- {
- int shift = y * slen;
- BYTE *px = p + shift;
- BYTE *color = colorBits + shift;
- BYTE *mask = maskBits + shift;
-
- for (int x = 0; x < bm.bmWidth; ++x)
- {
- for(int i = 0; i < 4; i++)
- {
- mask[i] = px[3];
- color[i] = px[i];
- }
-
- px += 4;
- mask += 4;
- color += 4;
- }
- }
-
- ii.hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 32, maskBits);
- ii.hbmColor = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 32, colorBits);
-
- hIcon = CreateIconIndirect(&ii);
-
- DeleteObject(ii.hbmMask);
- DeleteObject(ii.hbmColor);
-
- mir_free(p);
- mir_free(maskBits);
- mir_free(colorBits);
- }
- else
- {
- ii.hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
- ii.hbmColor = m_bmp;
- hIcon = CreateIconIndirect(&ii);
- DeleteObject(ii.hbmMask);
- }
+ ii.hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
+ ii.hbmColor = m_bmp;
+ HICON hIcon = CreateIconIndirect(&ii);
+ DeleteObject(ii.hbmMask);
return hIcon;
}
void ImageFType::GetSize(SIZE& size)
{
- if (m_bmp)
- {
+ if (m_bmp) {
BITMAP bm;
GetObject(m_bmp, sizeof(bm), &bm);
size.cx = bm.bmWidth;
size.cy = bm.bmHeight;
}
- else
- {
- size.cx = 0;
- size.cy = 0;
- }
-}
-/*
-ImageFAniType::ImageFAniType(const unsigned id, const CMString& file)
-: ImageFType(id)
-{
- m_fmbmp = NULL;
- m_nCurrentFrame = -1;
- m_FrameDelay = NULL;
-
- FREE_IMAGE_FORMAT fif = fei->FI_GetFileTypeT(file.c_str(), 0);
- if (fif == FIF_UNKNOWN)
- fif = fei->FI_GetFIFFromFilenameT(file.c_str());
-
- m_fmbmp = fei->FI_OpenMultiBitmap(fif, T2A_SM(file.c_str()), FALSE, TRUE, TRUE, GIF_PLAYBACK);
- if (m_fmbmp == NULL) return;
-
- m_nFrameCount = fei->FI_GetPageCount(m_fmbmp);
- m_bmpl = (HBITMAP*)mir_calloc(m_nFrameCount*sizeof(HBITMAP));
- m_FrameDelay = (int*)mir_calloc(m_nFrameCount*sizeof(int));
- SelectFrame(0);
-}
-
-ImageFAniType::~ImageFAniType()
-{
- if (m_fmbmp) fei->FI_CloseMultiBitmap(m_fmbmp, 0);
- for (int i=0; i<m_nFrameCount; ++i)
- if (m_bmp) DeleteObject(m_bmpl[i]);
-
- mir_free(m_bmpl);
- mir_free(m_FrameDelay);
-}
-
-void ImageFAniType::SelectFrame(int frame)
-{
- if ((unsigned)frame >= (unsigned)m_nFrameCount) frame = 0;
- if (frame == m_nCurrentFrame) return;
- m_nCurrentFrame = frame;
-
- if (m_bmpl[frame])
- {
- m_bmp = m_bmpl[frame];
- return;
- }
-
- FITAG *tag = NULL;
-
- FIBITMAP *dib = fei->FI_LockPage(m_fmbmp, frame);
- if (dib == NULL)
- return;
-
- if (fei->FI_GetMetadata(FIMD_ANIMATION, dib, "FrameTime", &tag))
- m_FrameDelay[frame] = *(LONG *)fei->FI_GetTagValue(tag) / 10;
-
- m_bmpl[frame] = m_bmp = fei->FI_CreateHBITMAPFromDIB(dib);
-
- if (fei->FI_IsTransparent(dib))
- fei->FI_Premultiply(m_bmp);
-
- fei->FI_UnlockPage(m_fmbmp, dib, FALSE);
+ else size.cx = size.cy = 0;
}
-*/
-
-#pragma optimize("gt", on)
-
-// MurmurHash2, by Austin Appleby
-unsigned int __fastcall hash( const void * key, unsigned int len )
-{
- // 'm' and 'r' are mixing constants generated offline.
- // They're not really 'magic', they just happen to work well.
- const unsigned int m = 0x5bd1e995;
- const int r = 24;
-
- // Initialize the hash to a 'random' value
- unsigned int h = len;
-
- // Mix 4 bytes at a time into the hash
- const unsigned char * data = (const unsigned char *)key;
-
- while(len >= 4)
- {
- unsigned int k = *(unsigned int *)data;
-
- k *= m;
- k ^= k >> r;
- k *= m;
-
- h *= m;
- h ^= k;
-
- data += 4;
- len -= 4;
- }
-
- // Handle the last few bytes of the input array
- switch(len)
- {
- case 3: h ^= data[2] << 16;
- case 2: h ^= data[1] << 8;
- case 1: h ^= data[0];
- h *= m;
- };
-
- // Do a few final mixes of the hash to ensure the last few
- // bytes are well-incorporated.
- h ^= h >> 13;
- h *= m;
- h ^= h >> 15;
-
- return h;
-}
-#pragma optimize("", on)
-
void InitImageCache(void)
{
@@ -719,23 +529,21 @@ void DestroyImageCache(void)
CloseHandle(g_hMutexIm);
}
-
ImageBase* AddCacheImage(const CMString& file, int index)
{
CMString tmpfile(file); tmpfile.AppendFormat(_T("#%d"), index);
- unsigned id = hash(tmpfile.c_str(), (unsigned int)tmpfile.GetLength() * sizeof(TCHAR));
+ unsigned id = mir_hash(tmpfile.c_str(), tmpfile.GetLength() * sizeof(TCHAR));
WaitForSingleObject(g_hMutexIm, 3000);
ImageBase srch(id);
ImageBase *img = g_imagecache.find(&srch);
- if (img == NULL)
- {
+ if (img == NULL) {
int ind = file.ReverseFind('.');
if (ind == -1)
return NULL;
- CMString ext = file.Right(ind+1);
+ CMString ext = file.Mid(ind+1);
ext.MakeLower();
if (ext == _T("dll") || ext == _T("exe"))
img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoDll) : (ImageBase*)new IconType(id, file, index, icoDll);
@@ -752,14 +560,12 @@ ImageBase* AddCacheImage(const CMString& file, int index)
g_imagecache.insert(img);
- if (timerId == 0)
- {
+ if (timerId == 0) {
timerId = 0xffffffff;
CallFunctionAsync(sttMainThreadCallback, NULL);
}
}
- else
- img->AddRef();
+ else img->AddRef();
ReleaseMutex(g_hMutexIm);