Exemple #1
0
HICON MakeGrayscaleIcon(HICON SourceIcon)
{
	ICONINFO TargetIconInfo;
	BITMAP TargetBitmapInfo;
	HICON TargetIcon, TempIcon;

	TempIcon = CopyIcon(SourceIcon);
	if (! GetIconInfo(TempIcon, &TargetIconInfo) || GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo)==0) return NULL;

	MakeGrayscale(&TargetIconInfo.hbmColor);

	TargetIcon = CreateIconIndirect(&TargetIconInfo);
	DestroyIcon(TempIcon);

	return TargetIcon;
}
Exemple #2
0
int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto)
{
	ptrT  tszValue;
	TCHAR tszFilename[MAX_PATH]; tszFilename[0] = 0;

	ace->hbmPic = 0;
	ace->dwFlags = 0;
	ace->bmHeight = 0;
	ace->bmWidth = 0;
	ace->lpDIBSection = NULL;
	ace->szFilename[0] = 0;

	if (szProto == NULL) {
		char *proto = GetContactProto(hContact);
		if (proto == NULL || !db_get_b(NULL, AVS_MODULE, proto, 1))
			return -1;

		if (db_get_b(hContact, "ContactPhoto", "Locked", 0) && (tszValue = db_get_tsa(hContact, "ContactPhoto", "Backup")))
			MyPathToAbsolute(tszValue, tszFilename);
		else if (tszValue = db_get_tsa(hContact, "ContactPhoto", "RFile"))
			MyPathToAbsolute(tszValue, tszFilename);
		else if (tszValue = db_get_tsa(hContact, "ContactPhoto", "File"))
			MyPathToAbsolute(tszValue, tszFilename);
		else return -2;
	}
	else {
		if (hContact == 0) {				// create a protocol picture in the proto picture cache
			if (tszValue = db_get_tsa(NULL, PPICT_MODULE, szProto))
				MyPathToAbsolute(tszValue, tszFilename);
			else if (mir_strcmp(szProto, AVS_DEFAULT)) {
				if (tszValue = db_get_tsa(NULL, PPICT_MODULE, AVS_DEFAULT))
					MyPathToAbsolute(tszValue, tszFilename);

				if (!strstr(szProto, "Global avatar for")) {
					PROTOACCOUNT* pdescr = (PROTOACCOUNT*)CallService(MS_PROTO_GETACCOUNT, 0, (LPARAM)szProto);
					if (pdescr == NULL)
						return -1;
					char key[MAX_PATH];
					mir_snprintf(key, SIZEOF(key), "Global avatar for %s accounts", pdescr->szProtoName);
					if (tszValue = db_get_tsa(NULL, PPICT_MODULE, key))
						MyPathToAbsolute(tszValue, tszFilename);
				}
			}
		}
		else if (hContact == INVALID_CONTACT_ID) {
			// create own picture - note, own avatars are not on demand, they are loaded once at
			// startup and everytime they are changed.
			if (szProto[0] == '\0') {
				// Global avatar
				if (tszValue = db_get_tsa(NULL, AVS_MODULE, "GlobalUserAvatarFile"))
					MyPathToAbsolute(tszValue, tszFilename);
				else
					return -10;
			}
			else if (ProtoServiceExists(szProto, PS_GETMYAVATART)) {
				if (CallProtoService(szProto, PS_GETMYAVATART, (WPARAM)tszFilename, (LPARAM)MAX_PATH))
					tszFilename[0] = '\0';
			}
			else if (ProtoServiceExists(szProto, PS_GETMYAVATAR)) {
				char szFileName[MAX_PATH];
				if (CallProtoService(szProto, PS_GETMYAVATAR, (WPARAM)szFileName, (LPARAM)MAX_PATH))
					tszFilename[0] = '\0';
				else
					MultiByteToWideChar(CP_ACP, 0, szFileName, -1, tszFilename, SIZEOF(tszFilename));
			}
			else if (tszValue = db_get_tsa(NULL, szProto, "AvatarFile"))
				MyPathToAbsolute(tszValue, tszFilename);
			else return -1;
		}
	}

	if (mir_tstrlen(tszFilename) < 4)
		return -1;

	_tcsncpy_s(tszFilename, VARST(tszFilename), _TRUNCATE);
	if (_taccess(tszFilename, 4) == -1)
		return -2;

	BOOL isTransparentImage = 0;
	ace->hbmPic = BmpFilterLoadBitmap(&isTransparentImage, tszFilename);
	ace->dwFlags = 0;
	ace->bmHeight = 0;
	ace->bmWidth = 0;
	ace->lpDIBSection = NULL;
	_tcsncpy(ace->szFilename, tszFilename, MAX_PATH);
	ace->szFilename[MAX_PATH - 1] = 0;
	if (ace->hbmPic == 0)
		return -1;

	BITMAP bminfo;
	GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);

	ace->cbSize = sizeof(avatarCacheEntry);
	ace->dwFlags = AVS_BITMAP_VALID;
	if (hContact != NULL && db_get_b(hContact, "ContactPhoto", "Hidden", 0))
		ace->dwFlags |= AVS_HIDEONCLIST;
	ace->hContact = hContact;
	ace->bmHeight = bminfo.bmHeight;
	ace->bmWidth = bminfo.bmWidth;

	BOOL noTransparency = db_get_b(0, AVS_MODULE, "RemoveAllTransparency", 0);

	// Calc image hash
	if (hContact != 0 && hContact != INVALID_CONTACT_ID) {
		// Have to reset settings? -> do it if image changed
		DWORD imgHash = GetImgHash(ace->hbmPic);
		if (imgHash != db_get_dw(hContact, "ContactPhoto", "ImageHash", 0)) {
			db_unset(hContact, "ContactPhoto", "MakeTransparentBkg");
			db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints");
			db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff");

			db_set_dw(hContact, "ContactPhoto", "ImageHash", imgHash);
		}

		// Make transparent?
		if (!noTransparency && !isTransparentImage && db_get_b(hContact, "ContactPhoto", "MakeTransparentBkg", db_get_b(0, AVS_MODULE, "MakeTransparentBkg", 0))) {
			if (MakeTransparentBkg(hContact, &ace->hbmPic)) {
				ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
				GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
				isTransparentImage = TRUE;
			}
		}
	}
	else if (hContact == INVALID_CONTACT_ID) { // My avatars
		if (!noTransparency && !isTransparentImage && db_get_b(0, AVS_MODULE, "MakeTransparentBkg", 0) && db_get_b(0, AVS_MODULE, "MakeMyAvatarsTransparent", 0)) {
			if (MakeTransparentBkg(0, &ace->hbmPic)) {
				ace->dwFlags |= AVS_CUSTOMTRANSPBKG | AVS_HASTRANSPARENCY;
				GetObject(ace->hbmPic, sizeof(bminfo), &bminfo);
				isTransparentImage = TRUE;
			}
		}
	}

	if (db_get_b(0, AVS_MODULE, "MakeGrayscale", 0))
		ace->hbmPic = MakeGrayscale(ace->hbmPic);

	if (noTransparency) {
		fei->FI_CorrectBitmap32Alpha(ace->hbmPic, TRUE);
		isTransparentImage = FALSE;
	}

	if (bminfo.bmBitsPixel == 32 && isTransparentImage) {
		if (fei->FI_Premultiply(ace->hbmPic))
			ace->dwFlags |= AVS_HASTRANSPARENCY;

		ace->dwFlags |= AVS_PREMULTIPLIED;
	}

	if (szProto) {
		protoPicCacheEntry *pAce = (protoPicCacheEntry *)ace;
		if (hContact == 0)
			pAce->dwFlags |= AVS_PROTOPIC;
		else if (hContact == INVALID_CONTACT_ID)
			pAce->dwFlags |= AVS_OWNAVATAR;
	}

	return 1;
}