diff options
author | George Hazan <george.hazan@gmail.com> | 2013-08-11 10:41:37 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-08-11 10:41:37 +0000 |
commit | 94dcc72f13094157f344f284aec4edf0c0f5faa1 (patch) | |
tree | 74c078daadd4abe5aea9e9e0a73b4dd7c4a7fde1 /plugins/AVS | |
parent | 42ff2169dbddd25d06404623dba2fff222d17c73 (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/AVS')
-rw-r--r-- | plugins/AVS/src/acc.cpp | 6 | ||||
-rw-r--r-- | plugins/AVS/src/cache.cpp | 4 | ||||
-rw-r--r-- | plugins/AVS/src/commonheaders.h | 2 | ||||
-rw-r--r-- | plugins/AVS/src/image_utils.cpp | 2 | ||||
-rw-r--r-- | plugins/AVS/src/services.cpp | 53 | ||||
-rw-r--r-- | plugins/AVS/src/utils.cpp | 82 |
6 files changed, 37 insertions, 112 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;
}
|