mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Added test app for AlphaBlend()
svn path=/trunk/; revision=8219
This commit is contained in:
parent
b84451d1c3
commit
d3a4b4244c
6 changed files with 242 additions and 1 deletions
|
@ -7,7 +7,7 @@ PATH_TO_TOP = ../..
|
|||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
||||
# test_old tests
|
||||
TEST_APPS = accelerator alive apc args atomtest bench bitblt button \
|
||||
TEST_APPS = accelerator alive alphablend apc args atomtest bench bitblt button \
|
||||
button2 capclock carets combo consume copymove count dibtest dump_shared_data \
|
||||
edit enumwnd enumws event global_mem gradient hello mdi \
|
||||
hivetest icontest isotest lineclip linetest lpc \
|
||||
|
|
6
reactos/apps/tests/alphablend/.cvsignore
Normal file
6
reactos/apps/tests/alphablend/.cvsignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
*.o
|
||||
*.d
|
||||
*.exe
|
||||
*.coff
|
||||
*.sym
|
||||
*.map
|
213
reactos/apps/tests/alphablend/alphablend.c
Normal file
213
reactos/apps/tests/alphablend/alphablend.c
Normal file
|
@ -0,0 +1,213 @@
|
|||
#include <windows.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef AC_SRC_ALPHA
|
||||
#define AC_SRC_ALPHA (0x1)
|
||||
#endif
|
||||
|
||||
HINSTANCE HInst;
|
||||
const char* WndClassName = "GMainWnd";
|
||||
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
|
||||
LPARAM LParam);
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
GdiAlphaBlend(HDC hdcDst,LONG DstX,LONG DstY,LONG DstCx,LONG DstCy,HDC hdcSrc,LONG SrcX,LONG SrcY,LONG SrcCx,LONG SrcCy,BLENDFUNCTION BlendFunction);
|
||||
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
|
||||
LPTSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
MSG msg;
|
||||
|
||||
HInst = HInstance;
|
||||
|
||||
memset(&wc, 0, sizeof(WNDCLASS));
|
||||
|
||||
wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
|
||||
wc.lpfnWndProc = MainWndProc;
|
||||
wc.hInstance = HInstance;
|
||||
wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
|
||||
/* wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1); */
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||
wc.lpszClassName = WndClassName;
|
||||
|
||||
if (RegisterClass(&wc))
|
||||
{
|
||||
HWND HWnd =
|
||||
CreateWindow(
|
||||
WndClassName, TEXT("AlphaBlend Rendering Demo"),
|
||||
WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION |
|
||||
WS_VISIBLE | WS_CLIPSIBLINGS,
|
||||
0, 0, 320, 430,
|
||||
NULL, NULL, HInst, NULL
|
||||
);
|
||||
|
||||
if (HWnd)
|
||||
{
|
||||
ShowWindow(HWnd, nCmdShow);
|
||||
UpdateWindow(HWnd);
|
||||
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* image related */
|
||||
BITMAP bmp;
|
||||
LPCSTR filename = TEXT("lena.bmp");
|
||||
HDC HMemDC = NULL, HMemDC2 = NULL;
|
||||
HBITMAP HOldBmp = NULL;
|
||||
PVOID pBmpBits = NULL;
|
||||
HBITMAP H32BppBitmap = NULL;
|
||||
BITMAPINFO bmpi;
|
||||
|
||||
BOOL ConvertBitmapTo32Bpp(HDC hDC, BITMAP *bmp)
|
||||
{
|
||||
ZeroMemory(&bmpi, sizeof(BITMAPINFO));
|
||||
bmpi.bmiHeader.biSize = sizeof(BITMAPINFO);
|
||||
bmpi.bmiHeader.biWidth = bmp->bmWidth;
|
||||
bmpi.bmiHeader.biHeight = bmp->bmHeight;
|
||||
bmpi.bmiHeader.biPlanes = 1;
|
||||
bmpi.bmiHeader.biBitCount = 32;
|
||||
bmpi.bmiHeader.biCompression = BI_RGB;
|
||||
bmpi.bmiHeader.biSizeImage = 4 * bmpi.bmiHeader.biWidth * bmpi.bmiHeader.biHeight;
|
||||
H32BppBitmap = CreateDIBSection(hDC, &bmpi, DIB_RGB_COLORS, &pBmpBits, 0, 0);
|
||||
if(H32BppBitmap)
|
||||
{
|
||||
HBITMAP bmpalpha;
|
||||
SelectObject(hDC, H32BppBitmap);
|
||||
BitBlt(hDC, 0, 0, bmp->bmWidth, bmp->bmHeight, HMemDC, 0, 0, SRCCOPY);
|
||||
|
||||
/* load and apply alpha channel */
|
||||
bmpalpha = LoadImage(HInst, TEXT("lenaalpha.bmp"), IMAGE_BITMAP,
|
||||
0, 0, LR_LOADFROMFILE);
|
||||
if(bmpalpha)
|
||||
{
|
||||
COLORREF *col = pBmpBits;
|
||||
int x, y;
|
||||
HDC hdcTemp = CreateCompatibleDC(NULL);
|
||||
if(!hdcTemp)
|
||||
{
|
||||
DeleteObject(bmpalpha);
|
||||
return FALSE;
|
||||
}
|
||||
SelectObject(hdcTemp, bmpalpha);
|
||||
|
||||
for(y = 0; y < bmp->bmHeight; y++)
|
||||
{
|
||||
for(x = 0; x < bmp->bmWidth; x++)
|
||||
{
|
||||
COLORREF Color = (COLORREF)GetRValue(GetPixel(hdcTemp, x, y)) << 24;
|
||||
*col++ |= Color;
|
||||
}
|
||||
}
|
||||
|
||||
DeleteObject(bmpalpha);
|
||||
DeleteDC(hdcTemp);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
|
||||
LPARAM LParam)
|
||||
{
|
||||
switch (Msg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
{
|
||||
/* create a memory DC */
|
||||
HMemDC = CreateCompatibleDC(NULL);
|
||||
if (HMemDC)
|
||||
{
|
||||
/* load a bitmap from file */
|
||||
HBITMAP HBmp =
|
||||
/* static_cast<HBITMAP> */(
|
||||
LoadImage(HInst, filename, IMAGE_BITMAP,
|
||||
0, 0, LR_LOADFROMFILE)
|
||||
);
|
||||
if (HBmp)
|
||||
{
|
||||
/* extract dimensions of the bitmap */
|
||||
GetObject(HBmp, sizeof(BITMAP), &bmp);
|
||||
|
||||
/* associate the bitmap with the memory DC */
|
||||
/* HOldBmp = static_cast<HBITMAP> */
|
||||
(SelectObject(HMemDC, HBmp)
|
||||
);
|
||||
HMemDC2 = CreateCompatibleDC(NULL);
|
||||
if(!ConvertBitmapTo32Bpp(HMemDC2, &bmp))
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
BLENDFUNCTION BlendFunc;
|
||||
HDC Hdc = BeginPaint(HWnd, &ps);
|
||||
#if 0
|
||||
try
|
||||
#endif
|
||||
{
|
||||
|
||||
BlendFunc.BlendOp = AC_SRC_OVER;
|
||||
BlendFunc.BlendFlags = 0;
|
||||
BlendFunc.SourceConstantAlpha = 128;
|
||||
BlendFunc.AlphaFormat = 0;
|
||||
|
||||
BitBlt(Hdc, 100, 90,
|
||||
bmp.bmWidth, bmp.bmHeight,
|
||||
HMemDC2, 0, 0,
|
||||
SRCCOPY);
|
||||
GdiAlphaBlend(Hdc, 0, 0, bmp.bmWidth, bmp.bmHeight,
|
||||
HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
|
||||
BlendFunc);
|
||||
GdiAlphaBlend(Hdc, bmp.bmWidth - 15, 10, bmp.bmWidth / 2, bmp.bmHeight / 2,
|
||||
HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
|
||||
BlendFunc);
|
||||
|
||||
BlendFunc.SourceConstantAlpha = 255;
|
||||
BlendFunc.AlphaFormat = AC_SRC_ALPHA;
|
||||
|
||||
GdiAlphaBlend(Hdc, 140, 200, bmp.bmWidth, bmp.bmHeight,
|
||||
HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
|
||||
BlendFunc);
|
||||
GdiAlphaBlend(Hdc, 20, 210, (bmp.bmWidth / 3) * 2, (bmp.bmHeight / 3) * 2,
|
||||
HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
|
||||
BlendFunc);
|
||||
}
|
||||
#if 0
|
||||
catch (...)
|
||||
{
|
||||
EndPaint(HWnd, &ps);
|
||||
}
|
||||
#endif
|
||||
EndPaint(HWnd, &ps);
|
||||
break;
|
||||
}
|
||||
case WM_DESTROY:
|
||||
{
|
||||
/* clean up */
|
||||
DeleteObject(SelectObject(HMemDC, HOldBmp));
|
||||
DeleteDC(HMemDC);
|
||||
DeleteDC(HMemDC2);
|
||||
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return DefWindowProc(HWnd, Msg, WParam, LParam);
|
||||
}
|
BIN
reactos/apps/tests/alphablend/lena.bmp
Normal file
BIN
reactos/apps/tests/alphablend/lena.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 87 KiB |
BIN
reactos/apps/tests/alphablend/lenaalpha.bmp
Normal file
BIN
reactos/apps/tests/alphablend/lenaalpha.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 87 KiB |
22
reactos/apps/tests/alphablend/makefile
Normal file
22
reactos/apps/tests/alphablend/makefile
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
PATH_TO_TOP = ../../..
|
||||
|
||||
TARGET_NORC = yes
|
||||
|
||||
TARGET_TYPE = program
|
||||
|
||||
TARGET_APPTYPE = windows
|
||||
|
||||
TARGET_NAME = alphablend
|
||||
|
||||
TARGET_SDKLIBS = kernel32.a gdi32.a
|
||||
|
||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||
|
||||
TARGET_CFLAGS = -Wall -Werror -D__USE_W32API
|
||||
|
||||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
||||
include $(TOOLS_PATH)/helper.mk
|
||||
|
||||
# EOF
|
Loading…
Reference in a new issue