2 * Tests various blit and blend operations with different src
3 * bit depths and scaling where possbile.
5 * Created by Gregor Schneider <grschneider AT gmail DOT com>, November 2008
11 #define CURRENT_BMPS 4
16 TCHAR szWindowClass
[] = _T("testclass");
18 static LRESULT CALLBACK
19 WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
21 static HBITMAP hbmList
[CURRENT_BMPS
];
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
);
42 hdc
= BeginPaint(hWnd
, &ps
);
43 hdcMem
= CreateCompatibleDC(hdc
);
45 bfunc
.AlphaFormat
= AC_SRC_ALPHA
;
47 bfunc
.BlendOp
= AC_SRC_OVER
;
48 bfunc
.SourceConstantAlpha
= 128;
50 for(i
= 0; i
< CURRENT_BMPS
; i
++)
53 SelectObject(hdcMem
, hbmList
[i
]);
54 GetObject(hbmList
[i
], sizeof(BITMAP
), &bitmap
);
57 BitBlt(hdc
, x
, y
, bitmap
.bmWidth
, bitmap
.bmHeight
, hdcMem
, 0, 0, SRCCOPY
);
58 y
+= bitmap
.bmHeight
+ OFFSET
;
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
;
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
;
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
;
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
;
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
;
80 /* alpha blend, scaled */
81 AlphaBlend(hdc
, x
, y
, bitmap
.bmWidth
*SCALE
, bitmap
.bmHeight
*SCALE
, hdcMem
, 0, 0, bitmap
.bmWidth
, bitmap
.bmHeight
, bfunc
);
83 x
+= bitmap
.bmWidth
*SCALE
+ OFFSET
;
95 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
102 MyRegisterClass(HINSTANCE hInstance
)
106 wcex
.cbSize
= sizeof(WNDCLASSEX
);
108 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
109 wcex
.lpfnWndProc
= WndProc
;
112 wcex
.hInstance
= hInstance
;
114 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
115 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
116 wcex
.lpszMenuName
= NULL
;
117 wcex
.lpszClassName
= szWindowClass
;
120 return RegisterClassEx(&wcex
);
125 InitInstance(HINSTANCE hInstance
, int nCmdShow
)
131 hWnd
= CreateWindowEx(0,
133 _T("Various blit and blend operations"),
149 ShowWindow(hWnd
, nCmdShow
);
157 _tWinMain(HINSTANCE hInstance
,
158 HINSTANCE hPrevInstance
,
164 MyRegisterClass(hInstance
);
166 if (!InitInstance(hInstance
, nCmdShow
))
171 while (GetMessage(&msg
, NULL
, 0, 0))
173 TranslateMessage(&msg
);
174 DispatchMessage(&msg
);
177 return (int)msg
.wParam
;