- Restructure dib related tests, 2nd try.
[reactos.git] / rostests / dibtests / vbltest / vbltest.c
1 /*
2 * Tests various blit and blend operations with different src
3 * bit depths and scaling where possbile.
4 *
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
6 */
7
8 #include <windows.h>
9 #include <tchar.h>
10
11 #define CURRENT_BMPS 4
12 #define SCALE 1.5
13 #define OFFSET 5
14
15 HINSTANCE hInst;
16 TCHAR szWindowClass[] = _T("testclass");
17
18 static LRESULT CALLBACK
19 WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
20 {
21 static HBITMAP hbmList[CURRENT_BMPS];
22
23 switch (message)
24 {
25 case WM_CREATE:
26 {
27 hbmList[0] = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(100), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
28 hbmList[1] = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(400), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
29 hbmList[2] = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(800), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
30 hbmList[3] = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(2400), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
31 break;
32 }
33
34 case WM_PAINT:
35 {
36 PAINTSTRUCT ps;
37 HDC hdc, hdcMem;
38 BITMAP bitmap;
39 BLENDFUNCTION bfunc;
40 int x = 0, y = 0, i;
41
42 hdc = BeginPaint(hWnd, &ps);
43 hdcMem = CreateCompatibleDC(hdc);
44
45 bfunc.AlphaFormat = AC_SRC_ALPHA;
46 bfunc.BlendFlags = 0;
47 bfunc.BlendOp = AC_SRC_OVER;
48 bfunc.SourceConstantAlpha = 128;
49
50 for(i = 0; i < CURRENT_BMPS; i++)
51 {
52 y = 0;
53 SelectObject(hdcMem, hbmList[i]);
54 GetObject(hbmList[i], sizeof(BITMAP), &bitmap);
55
56 /* bit blt */
57 BitBlt(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
58 y += bitmap.bmHeight + OFFSET;
59
60 /* stretch blt, org size */
61 StretchBlt(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
62 y += bitmap.bmHeight + OFFSET;
63
64 /* stretch blt, scaled */
65 StretchBlt(hdc, x, y, bitmap.bmWidth*SCALE, bitmap.bmHeight*SCALE, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
66 y += bitmap.bmHeight*SCALE + OFFSET;
67
68 /* transparent blt, transparency: grey */
69 TransparentBlt(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, 128*256*256+128*256+128);
70 y += bitmap.bmHeight + OFFSET;
71
72 /* transparent blt, transparency: grey, scaled */
73 TransparentBlt(hdc, x, y, bitmap.bmWidth*SCALE, bitmap.bmHeight*SCALE, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, 128*256*256+128*256+128);
74 y += bitmap.bmHeight*SCALE + OFFSET;
75
76 /* alpha blend, org size */
77 AlphaBlend(hdc, x, y, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, bfunc);
78 y += bitmap.bmHeight + OFFSET;
79
80 /* alpha blend, scaled */
81 AlphaBlend(hdc, x, y, bitmap.bmWidth*SCALE, bitmap.bmHeight*SCALE, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, bfunc);
82
83 x += bitmap.bmWidth*SCALE + OFFSET;
84 }
85
86 DeleteDC(hdcMem);
87 EndPaint(hWnd, &ps);
88 break;
89 }
90
91 case WM_DESTROY:
92 PostQuitMessage(0);
93 break;
94 default:
95 return DefWindowProc(hWnd, message, wParam, lParam);
96 }
97 return 0;
98 }
99
100
101 static ATOM
102 MyRegisterClass(HINSTANCE hInstance)
103 {
104 WNDCLASSEX wcex;
105
106 wcex.cbSize = sizeof(WNDCLASSEX);
107
108 wcex.style = CS_HREDRAW | CS_VREDRAW;
109 wcex.lpfnWndProc = WndProc;
110 wcex.cbClsExtra = 0;
111 wcex.cbWndExtra = 0;
112 wcex.hInstance = hInstance;
113 wcex.hIcon = NULL;
114 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
115 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
116 wcex.lpszMenuName = NULL;
117 wcex.lpszClassName = szWindowClass;
118 wcex.hIconSm = NULL;
119
120 return RegisterClassEx(&wcex);
121 }
122
123
124 static BOOL
125 InitInstance(HINSTANCE hInstance, int nCmdShow)
126 {
127 HWND hWnd;
128
129 hInst = hInstance;
130
131 hWnd = CreateWindowEx(0,
132 szWindowClass,
133 _T("Various blit and blend operations"),
134 WS_OVERLAPPEDWINDOW,
135 CW_USEDEFAULT,
136 CW_USEDEFAULT,
137 640,
138 640,
139 NULL,
140 NULL,
141 hInstance,
142 NULL);
143
144 if (!hWnd)
145 {
146 return FALSE;
147 }
148
149 ShowWindow(hWnd, nCmdShow);
150 UpdateWindow(hWnd);
151
152 return TRUE;
153 }
154
155
156 int WINAPI
157 _tWinMain(HINSTANCE hInstance,
158 HINSTANCE hPrevInstance,
159 LPTSTR lpCmdLine,
160 int nCmdShow)
161 {
162 MSG msg;
163
164 MyRegisterClass(hInstance);
165
166 if (!InitInstance(hInstance, nCmdShow))
167 {
168 return FALSE;
169 }
170
171 while (GetMessage(&msg, NULL, 0, 0))
172 {
173 TranslateMessage(&msg);
174 DispatchMessage(&msg);
175 }
176
177 return (int)msg.wParam;
178 }