//	Album List for Winamp
//	Copyright (C) 1999-2001 Safai Ma
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation; either version 2 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/*
 * MSIMG32.C
 *
 * Interface glue code to the Microsoft Image Library
 */
#include "stdafx.h"

static HINSTANCE hDllMSIMG = 0L;
static DWORD	 nRef = 0L;

static BOOL (WINAPI *pAlphaBlend)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION)	= NULL;

void MSIMG32_Free();
BOOL MSIMG32_Load()
{
	// check for multiple instances and increment reference counts.
	if (nRef != 0)
	{
		nRef++;
		return TRUE;
	}

	hDllMSIMG = LoadLibrary("MSIMG32.DLL");
	if (!hDllMSIMG)
	{
		MSIMG32_Free();
		return FALSE;
	}

	pAlphaBlend	= (BOOL(WINAPI *)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION)) GetProcAddress(hDllMSIMG, "AlphaBlend");

	// increment reference counts
	nRef++;

	return TRUE;
}

void MSIMG32_Free()
{
	// check reference count first
	if (nRef == 0) return;
	if (--nRef != 0) return;

	pAlphaBlend		= NULL;

	FreeLibrary(hDllMSIMG);
	hDllMSIMG = NULL;
}

BOOL WINAPI GdiAlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int hHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION blendFunction)
{
	return pAlphaBlend ? pAlphaBlend(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, hHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, blendFunction) : FALSE;
}
