[vlc-devel] Chroma-key plugin for VLC as class broadcast client

Juan Fernando Herrera J. juanfhj at gmail.com
Mon May 4 17:53:00 CEST 2009


This is some windows code a friend of mine gave me for achieving the
desired effect. Could you hint how to make it fit in VLC?

Thanks, Juan

void CreateLayeredWindow()
{
	global_hWnd = CreateWindowEx(
		WS_EX_LAYERED |
		WS_EX_TOPMOST |
		WS_EX_TOOLWINDOW |
		WS_EX_TRANSPARENT, // click-transparency
		TEXT("szWindowClass"),
		TEXT("WindowTitle"), WS_VISIBLE,
		WINDOW_POS_X, WINDOW_POS_Y,
		WINDOW_SIZE_X, WINDOW_SIZE_Y,
		NULL, NULL, global_hInst, NULL);
}

// A global bitmap buffer for the screen image. May be redundant with
variable bmp below.

uint8_t global_LayeredBuffer[WINDOW_SIZE_X * WINDOW_SIZE_Y * 4];

#define KeyColorR 0
#define KeyColorG 255
#define KeyColorB 0

// bmp is the bitmap from the media player.
void ProcessLayeredPicture(uint8_t *bmp)
{
	HBITMAP oldHBmp;
	BLENDFUNCTION blend;
	SIZE size = { WINDOW_SIZE_X, WINDOW_SIZE_Y };
	POINT ptSrc = {0, 0};
	POINT ptDest = {WINDOW_POS_X, WINDOW_POS_Y};

	HDC dcScreen = GetDC(NULL);
	HDC dcMem = CreateCompatibleDC(dcScreen);
	HBITMAP hbmp = CreateCompatibleBitmap(dcScreen, WINDOW_SIZE_X, WINDOW_SIZE_Y);

	BITMAPINFO* bmi = (BITMAPINFO*)malloc(sizeof(BITMAPINFOHEADER) +
256*sizeof(RGBQUAD));
	ZeroMemory(bmi, sizeof(BITMAPINFOHEADER));
	bmi->bmiHeader.biSize = sizeof(BITMAPINFO);

	// Store bitmap properties in bmi
	if (!GetDIBits(dcScreen, hbmp, 0, WINDOW_SIZE_Y, NULL, bmi, DIB_RGB_COLORS))
	{
		ReleaseDC(NULL, dcScreen);
		DeleteDC(dcMem);
		DeleteObject(hbmp);
		free(bmi);
		return;
	}

	// Use 32 bit pixels
	bmi->bmiHeader.biBitCount = 32;

	// Necessary for GetDIBits to work right, don't know why.
	if (!GetDIBits(dcScreen, hbmp, 0, 1, global_LayeredBuffer, bmi,
DIB_RGB_COLORS))
	{
		ReleaseDC(NULL, dcScreen);
		DeleteDC(dcMem);
		DeleteObject(hbmp);
		free(bmi);
		return;
	}

	// Update the image buffer
	memcpy(global_LayeredBuffer, bmp, 4*WINDOW_SIZE_X*WINDOW_SIZE_Y);

	// Copy global_LayeredBuffer to the bitmap:
	if (!SetDIBits(dcScreen, hbmp, 0, WINDOW_SIZE_Y,
global_LayeredBuffer, bmi, DIB_RGB_COLORS))
	{
		ReleaseDC(NULL, dcScreen);
		DeleteDC(dcMem);
		DeleteObject(hbmp);
		free(bmi);
		return;
	}
	
	oldHBmp = (HBITMAP)SelectObject(dcMem, hbmp);

	// This is the function that does all the magic, UpdateLayeredWindow().
	// http://msdn.microsoft.com/en-us/library/ms633556(VS.85,loband).aspx
    if (!UpdateLayeredWindow(global_hWnd, dcScreen, &ptDest, &size,
dcMem, &ptSrc, RGB(KeyColorR, KeyColorG, KeyColorB), &blend,
ULW_COLORKEY))
	{
		SelectObject(dcMem, oldHBmp);
		ReleaseDC(NULL, dcScreen);
		DeleteDC(dcMem);
		DeleteObject(hbmp);
		free(bmi);
		return;
	}

	SelectObject(dcMem, oldHBmp);
	ReleaseDC(NULL, dcScreen);
	DeleteDC(dcMem);
	DeleteObject(hbmp);
	free(bmi);
}



More information about the vlc-devel mailing list