summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
commit94dcc72f13094157f344f284aec4edf0c0f5faa1 (patch)
tree74c078daadd4abe5aea9e9e0a73b4dd7c4a7fde1 /plugins
parent42ff2169dbddd25d06404623dba2fff222d17c73 (diff)
ProtoGetAvatarFormat, ProtoGetAvatarFileFormat, ProtoGetBufferFormat, ProtoGetAvatarExtension - standard helpers for protocol avatars' processing instead of the zoo that existed previously
git-svn-id: http://svn.miranda-ng.org/main/trunk@5645 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/AVS/src/acc.cpp6
-rw-r--r--plugins/AVS/src/cache.cpp4
-rw-r--r--plugins/AVS/src/commonheaders.h2
-rw-r--r--plugins/AVS/src/image_utils.cpp2
-rw-r--r--plugins/AVS/src/services.cpp53
-rw-r--r--plugins/AVS/src/utils.cpp82
-rw-r--r--plugins/AdvaImg/src/main.cpp33
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp8
-rw-r--r--plugins/NewsAggregator/Src/Common.h1
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp26
10 files changed, 48 insertions, 169 deletions
diff --git a/plugins/AVS/src/acc.cpp b/plugins/AVS/src/acc.cpp
index 971b29005f..a0d63c6b81 100644
--- a/plugins/AVS/src/acc.cpp
+++ b/plugins/AVS/src/acc.cpp
@@ -149,7 +149,7 @@ void StartFlash(HWND hwnd, ACCData* data)
else if (data->proto[0] != '\0')
{
protoPicCacheEntry *ace = NULL;
- for(int i = 0; i < g_MyAvatars.getCount(); i++)
+ for (int i = 0; i < g_MyAvatars.getCount(); i++)
{
if (!lstrcmpA(data->proto, g_MyAvatars[i].szProtoname))
{
@@ -159,7 +159,7 @@ void StartFlash(HWND hwnd, ACCData* data)
}
if (ace != NULL && ace->szFilename != NULL)
- format = GetImageFormat(ace->szFilename);
+ format = ProtoGetAvatarFormat(ace->szFilename);
else
format = 0;
}
@@ -365,7 +365,7 @@ void StartAnimatedGif(HWND hwnd, ACCData* data)
if (ace == NULL)
return;
- int format = GetImageFormat(ace->szFilename);
+ int format = ProtoGetAvatarFormat(ace->szFilename);
if (format != PA_FORMAT_GIF)
return;
diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp
index a59119508f..846ec14013 100644
--- a/plugins/AVS/src/cache.cpp
+++ b/plugins/AVS/src/cache.cpp
@@ -35,7 +35,7 @@ static CacheNode *AllocCacheBlock()
CacheNode *allocedBlock = (CacheNode*)malloc(CACHE_BLOCKSIZE * sizeof(struct CacheNode));
ZeroMemory((void *)allocedBlock, sizeof(struct CacheNode) * CACHE_BLOCKSIZE);
- for(int i = 0; i < CACHE_BLOCKSIZE - 1; i++)
+ for (int i = 0; i < CACHE_BLOCKSIZE - 1; i++)
allocedBlock[i].pNextNode = &allocedBlock[i + 1]; // pre-link the alloced block
if (g_Cache == NULL) // first time only...
@@ -65,7 +65,7 @@ void UnloadCache(void)
if (cc->ace.hbmPic != 0)
DeleteObject(cc->ace.hbmPic);
- for(int i = 0; i < g_curBlock; i++)
+ for (int i = 0; i < g_curBlock; i++)
free(g_cacheBlocks[i]);
free(g_cacheBlocks);
diff --git a/plugins/AVS/src/commonheaders.h b/plugins/AVS/src/commonheaders.h
index 0cab3148b9..063a5ece20 100644
--- a/plugins/AVS/src/commonheaders.h
+++ b/plugins/AVS/src/commonheaders.h
@@ -122,8 +122,6 @@ extern HANDLE hEventChanged, hEventContactAvatarChanged, hMyAvatarChanged;
int GetFileHash(TCHAR* filename);
DWORD GetFileSize(TCHAR *szFilename);
-const TCHAR *GetFormatExtension(int format);
-int GetImageFormat(TCHAR *filename);
void MakePathRelative(HANDLE hContact);
void MakePathRelative(HANDLE hContact, TCHAR *dest);
diff --git a/plugins/AVS/src/image_utils.cpp b/plugins/AVS/src/image_utils.cpp
index 9b926ccbee..3092e47519 100644
--- a/plugins/AVS/src/image_utils.cpp
+++ b/plugins/AVS/src/image_utils.cpp
@@ -339,7 +339,7 @@ void AddToStack(int *stack, int *topPos, int x, int y)
int i;
// Already is in stack?
- for(i = 0 ; i < *topPos ; i += 2)
+ for (i = 0 ; i < *topPos ; i += 2)
{
if (stack[i] == x && stack[i+1] == y)
return;
diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp
index bb1014d70a..56dd9e1661 100644
--- a/plugins/AVS/src/services.cpp
+++ b/plugins/AVS/src/services.cpp
@@ -406,36 +406,29 @@ struct SaveProtocolData {
void SaveImage(SaveProtocolData &d, char *protocol, int format)
{
- if (Proto_IsAvatarFormatSupported(protocol, format))
- {
- mir_sntprintf(d.image_file_name, SIZEOF(d.image_file_name), _T("%s%s"), d.temp_file, GetFormatExtension(format));
- if (!BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0))
- {
- if (d.max_size != 0 && GetFileSize(d.image_file_name) > d.max_size)
- {
- DeleteFile(d.image_file_name);
+ if ( !Proto_IsAvatarFormatSupported(protocol, format))
+ return;
- if (format == PA_FORMAT_JPEG)
- {
- // Try with lower quality
- if (!BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, JPEG_QUALITYGOOD))
- {
- if (GetFileSize(d.image_file_name) > d.max_size)
- {
- DeleteFile(d.image_file_name);
- d.need_smaller_size = TRUE;
- }
- else
- d.saved = TRUE;
- }
- }
- else
+ mir_sntprintf(d.image_file_name, SIZEOF(d.image_file_name), _T("%s%s"), d.temp_file, ProtoGetAvatarExtension(format));
+ if ( BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0))
+ return;
+
+ if (d.max_size != 0 && GetFileSize(d.image_file_name) > d.max_size) {
+ DeleteFile(d.image_file_name);
+
+ if (format == PA_FORMAT_JPEG) {
+ // Try with lower quality
+ if (!BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, JPEG_QUALITYGOOD)) {
+ if (GetFileSize(d.image_file_name) > d.max_size) {
+ DeleteFile(d.image_file_name);
d.need_smaller_size = TRUE;
+ }
+ else d.saved = TRUE;
}
- else
- d.saved = TRUE;
}
+ else d.need_smaller_size = TRUE;
}
+ else d.saved = TRUE;
}
static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilename, int originalFormat, BOOL square, BOOL grow)
@@ -576,7 +569,7 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo
{
HANDLE hFile = 0;
- int format = GetImageFormat(szFinalName);
+ int format = ProtoGetAvatarFormat(szFinalName);
if (format == PA_FORMAT_UNKNOWN || (hFile = CreateFile(szFinalName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
return -3;
@@ -867,7 +860,7 @@ INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam)
if (r->szProto == NULL)
return 0;
- for(int i = 0; i < g_ProtoPictures.getCount(); i++) {
+ for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
if ( !lstrcmpA(p.szProtoname, r->szProto) && lstrlenA(r->szProto) == lstrlenA(p.szProtoname) && p.hbmPic != 0) {
ace = (AVATARCACHEENTRY *)&g_ProtoPictures[i];
@@ -911,7 +904,7 @@ INT_PTR GetMyAvatar(WPARAM wParam, LPARAM lParam)
if (lParam == 0 || IsBadReadPtr(szProto, 4))
return 0;
- for(int i = 0; i < g_MyAvatars.getCount(); i++)
+ for (int i = 0; i < g_MyAvatars.getCount(); i++)
if (!lstrcmpA(szProto, g_MyAvatars[i].szProtoname) && g_MyAvatars[i].hbmPic != 0)
return (INT_PTR)&g_MyAvatars[i];
@@ -925,7 +918,7 @@ static void ReloadMyAvatar(LPVOID lpParam)
char *szProto = (char *)lpParam;
mir_sleep(500);
- for(int i = 0; !g_shutDown && i < g_MyAvatars.getCount(); i++) {
+ for (int i = 0; !g_shutDown && i < g_MyAvatars.getCount(); i++) {
char *myAvatarProto = g_MyAvatars[i].szProtoname;
if (szProto[0] == 0) {
@@ -959,7 +952,7 @@ INT_PTR ReportMyAvatarChanged(WPARAM wParam, LPARAM lParam)
if (proto == NULL)
return -1;
- for(int i = 0; i < g_MyAvatars.getCount(); i++) {
+ for (int i = 0; i < g_MyAvatars.getCount(); i++) {
if (g_MyAvatars[i].dwFlags & AVS_IGNORENOTIFY)
continue;
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp
index 1d0494e258..7aa9f205d3 100644
--- a/plugins/AVS/src/utils.cpp
+++ b/plugins/AVS/src/utils.cpp
@@ -398,6 +398,8 @@ void protoPicCacheEntry::clear()
memset(this, 0, sizeof(avatarCacheEntry));
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
BOOL Proto_IsAvatarsEnabled(const char *proto)
{
if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
@@ -451,13 +453,8 @@ void Proto_GetAvatarMaxSize(const char *proto, int *width, int *height)
BOOL Proto_NeedDelaysForAvatars(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS)) {
- int ret = CallProtoService(proto, PS_GETAVATARCAPS, AF_DONTNEEDDELAYS, 0);
- if (ret > 0)
- return FALSE;
- else
- return TRUE;
- }
+ if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ return CallProtoService(proto, PS_GETAVATARCAPS, AF_DONTNEEDDELAYS, 0) <= 0;
return TRUE;
}
@@ -492,7 +489,7 @@ protoPicCacheEntry *GetProtoDefaultAvatar(HANDLE hContact)
{
char *szProto = GetContactProto(hContact);
if (szProto) {
- for(int i = 0; i < g_ProtoPictures.getCount(); i++) {
+ for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
if ( !lstrcmpA(p.szProtoname, szProto) && p.hbmPic != NULL)
return &g_ProtoPictures[i];
@@ -552,7 +549,7 @@ void DeleteGlobalUserAvatar()
void SetIgnoreNotify(char *protocol, BOOL ignore)
{
- for(int i = 0; i < g_MyAvatars.getCount(); i++) {
+ for (int i = 0; i < g_MyAvatars.getCount(); i++) {
if (protocol == NULL || !lstrcmpA(g_MyAvatars[i].szProtoname, protocol)) {
if (ignore)
g_MyAvatars[i].dwFlags |= AVS_IGNORENOTIFY;
@@ -562,73 +559,10 @@ void SetIgnoreNotify(char *protocol, BOOL ignore)
}
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-const TCHAR *GetFormatExtension(int format)
-{
- if (format == PA_FORMAT_PNG)
- return _T(".png");
- if (format == PA_FORMAT_JPEG)
- return _T(".jpg");
- if (format == PA_FORMAT_ICON)
- return _T(".ico");
- if (format == PA_FORMAT_BMP)
- return _T(".bmp");
- if (format == PA_FORMAT_GIF)
- return _T(".gif");
- if (format == PA_FORMAT_SWF)
- return _T(".swf");
- if (format == PA_FORMAT_XML)
- return _T(".xml");
-
- return NULL;
-}
-
-int GetImageFormat(TCHAR *filename)
-{
- size_t len = lstrlen(filename);
-
- if (len < 5)
- return PA_FORMAT_UNKNOWN;
-
- if (_tcsicmp(_T(".png"), &filename[len-4]) == 0)
- return PA_FORMAT_PNG;
-
- if (_tcsicmp(_T(".jpg"), &filename[len-4]) == 0 || _tcsicmp(_T(".jpeg"), &filename[len-4]) == 0)
- return PA_FORMAT_JPEG;
-
- if (_tcsicmp(_T(".ico"), &filename[len-4]) == 0)
- return PA_FORMAT_ICON;
-
- if (_tcsicmp(_T(".bmp"), &filename[len-4]) == 0 || _tcsicmp(_T(".rle"), &filename[len-4]) == 0)
- return PA_FORMAT_BMP;
-
- if (_tcsicmp(_T(".gif"), &filename[len-4]) == 0)
- return PA_FORMAT_GIF;
-
- if (_tcsicmp(_T(".swf"), &filename[len-4]) == 0)
- return PA_FORMAT_SWF;
-
- if (_tcsicmp(_T(".xml"), &filename[len-4]) == 0)
- return PA_FORMAT_XML;
-
- return PA_FORMAT_UNKNOWN;
-}
-
///////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD GetFileSize(TCHAR *szFilename)
{
- HANDLE hFile = CreateFile(szFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- return 0;
-
- DWORD low = GetFileSize(hFile, NULL);
-
- CloseHandle(hFile);
-
- if (low == INVALID_FILE_SIZE)
- return 0;
-
- return low;
+ struct _stat info;
+ return ( _tstat(szFilename, &info) == -1) ? 0 : info.st_size;
}
diff --git a/plugins/AdvaImg/src/main.cpp b/plugins/AdvaImg/src/main.cpp
index cb4500501d..4fcd79905f 100644
--- a/plugins/AdvaImg/src/main.cpp
+++ b/plugins/AdvaImg/src/main.cpp
@@ -795,12 +795,6 @@ extern "C" BOOL __declspec(dllexport) dib2mempng( BITMAPINFO* pbmi, png_byte* pD
return TRUE;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-// Standard Miranda structures & functions
-
-static HANDLE hDib2mempng = NULL;
-static HANDLE hMempng2Dib = NULL;
-
///////////////////////////////////////////////////////////////////////////////
// Load - initializes the plugin instance
@@ -1195,21 +1189,17 @@ void FI_Populate(void)
feif.FI_CorrectBitmap32Alpha = FI_CorrectBitmap32Alpha;
}
-static HANDLE hGetIF, hLoad, hLoadFromMem, hSave, hUnload, hResize, hGetVersion;
-
static int IMGSERVICE_Load()
{
FI_Populate();
- hDib2mempng = CreateServiceFunction( MS_DIB2PNG, serviceDib2Png );
- hMempng2Dib = CreateServiceFunction( MS_PNG2DIB, servicePng2Dib );
- hGetIF = CreateServiceFunction(MS_IMG_GETINTERFACE, serviceGetInterface);
- hLoad = CreateServiceFunction(MS_IMG_LOAD, serviceLoad);
- hLoadFromMem = CreateServiceFunction(MS_IMG_LOADFROMMEM, serviceLoadFromMem);
- hSave = CreateServiceFunction(MS_IMG_SAVE, serviceSave);
- hUnload = CreateServiceFunction(MS_IMG_UNLOAD, serviceUnload);
- hResize = CreateServiceFunction(MS_IMG_RESIZE, serviceBmpFilterResizeBitmap);
- hGetVersion = CreateServiceFunction(MS_IMG_GETIFVERSION, serviceGetVersion);
+ CreateServiceFunction(MS_IMG_GETINTERFACE, serviceGetInterface);
+ CreateServiceFunction(MS_IMG_LOAD, serviceLoad);
+ CreateServiceFunction(MS_IMG_LOADFROMMEM, serviceLoadFromMem);
+ CreateServiceFunction(MS_IMG_SAVE, serviceSave);
+ CreateServiceFunction(MS_IMG_UNLOAD, serviceUnload);
+ CreateServiceFunction(MS_IMG_RESIZE, serviceBmpFilterResizeBitmap);
+ CreateServiceFunction(MS_IMG_GETIFVERSION, serviceGetVersion);
return 0;
}
@@ -1223,15 +1213,6 @@ extern "C" int __declspec(dllexport) Load(void)
static int IMGSERVICE_Unload( void )
{
- DestroyServiceFunction( hDib2mempng );
- DestroyServiceFunction( hMempng2Dib );
- DestroyServiceFunction( hGetIF );
- DestroyServiceFunction( hLoad );
- DestroyServiceFunction( hLoadFromMem );
- DestroyServiceFunction( hSave );
- DestroyServiceFunction( hUnload );
- DestroyServiceFunction( hResize );
- DestroyServiceFunction( hGetVersion );
return 0;
}
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index 36ef8165a1..b0286357ce 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -177,7 +177,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
+ pai.format = ProtoGetAvatarFormat(ext);
TCHAR *filename = dbVar.ptszVal;
mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
@@ -412,7 +412,7 @@ VOID CheckCurrentFeed(HANDLE hContact)
if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
+ pai.format = ProtoGetAvatarFormat(ext);
TCHAR *filename = dbVar.ptszVal;
mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
@@ -639,7 +639,7 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
+ pai.format = ProtoGetAvatarFormat(ext);
TCHAR *filename = dbVar.ptszVal;
mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
@@ -673,7 +673,7 @@ VOID CheckCurrentFeedAvatar(HANDLE hContact)
if (!db_get_ts(hContact, MODULE, "Nick", &dbVar)) {
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
- pai.format = GetImageFormat(ext);
+ pai.format = ProtoGetAvatarFormat(ext);
TCHAR *filename = dbVar.ptszVal;
mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h
index fa9117462d..ed19e6b132 100644
--- a/plugins/NewsAggregator/Src/Common.h
+++ b/plugins/NewsAggregator/Src/Common.h
@@ -131,7 +131,6 @@ TCHAR* CheckFeed(TCHAR* tszURL, HWND hwndDlg);
void UpdateMenu(BOOL State);
int ImportFeedsDialog();
VOID ClearText(TCHAR *&message);
-int GetImageFormat(const TCHAR *ext);
BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
int StrReplace(TCHAR *lpszOld, TCHAR *lpszNew, TCHAR *&lpszStr);
void CreateAuthString(char *auth, HANDLE hContact, HWND hwndDlg);
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index 336d67993d..a47e6d261f 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -58,32 +58,6 @@ static void arrayToHex(BYTE *data, size_t datasz, char *res)
*resptr = '\0';
}
-int GetImageFormat(const TCHAR *ext)
-{
- if (!lstrcmp(ext, _T(".jpg")) || !lstrcmp(ext, _T(".jpeg")))
- return PA_FORMAT_JPEG;
-
- if (!lstrcmp(ext, _T(".png")))
- return PA_FORMAT_PNG;
-
- if (!lstrcmp(ext, _T(".gif")))
- return PA_FORMAT_GIF;
-
- if (!lstrcmp(ext, _T(".ico")))
- return PA_FORMAT_ICON;
-
- if (!lstrcmp(ext, _T(".bmp")))
- return PA_FORMAT_BMP;
-
- if (!lstrcmp(ext, _T(".swf")))
- return PA_FORMAT_SWF;
-
- if (!lstrcmp(ext, _T(".xml")))
- return PA_FORMAT_XML;
-
- return PA_FORMAT_UNKNOWN;
-}
-
VOID GetNewsData(TCHAR *tszUrl, char **szData, HANDLE hContact, HWND hwndDlg)
{
NETLIBHTTPREQUEST nlhr = {0};