ReactOS 0.4.16-dev-197-g92996da
alphablend.c
Go to the documentation of this file.
1#include <windows.h>
2#include <string.h>
3
4BOOL WINAPI GdiAlphaBlend(HDC hdcDst, int xDst, int yDst, int widthDst, int heightDst,
5 HDC hdcSrc, int xSrc, int ySrc, int widthSrc, int heightSrc,
6 BLENDFUNCTION blendFunction);
7
8#ifndef AC_SRC_ALPHA
9#define AC_SRC_ALPHA (0x1)
10#endif
11
13const char* WndClassName = "GMainWnd";
15 LPARAM LParam);
16
17int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
18 LPTSTR lpCmdLine, int nCmdShow)
19{
20 WNDCLASS wc;
21 MSG msg;
22
23 HInst = HInstance;
24
25 memset(&wc, 0, sizeof(WNDCLASS));
26
29 wc.hInstance = HInstance;
31 /* wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1); */
32 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
34
35 if (RegisterClass(&wc))
36 {
37 HWND HWnd =
39 WndClassName, TEXT("AlphaBlend Rendering Demo"),
42 0, 0, 320, 430,
44 );
45
46 if (HWnd)
47 {
48 ShowWindow(HWnd, nCmdShow);
49 UpdateWindow(HWnd);
50
51 while (GetMessage(&msg, NULL, 0, 0))
52 {
55 }
56 }
57 }
58 return 0;
59}
60
61/* image related */
63LPCSTR filename = TEXT("lena.bmp");
69
71{
72 ZeroMemory(&bmpi, sizeof(BITMAPINFO));
74 bmpi.bmiHeader.biWidth = bmp->bmWidth;
75 bmpi.bmiHeader.biHeight = bmp->bmHeight;
81 if(H32BppBitmap)
82 {
83 HBITMAP bmpalpha;
85 BitBlt(hDC, 0, 0, bmp->bmWidth, bmp->bmHeight, HMemDC, 0, 0, SRCCOPY);
86
87 /* load and apply alpha channel */
89 0, 0, 0);
90 if(bmpalpha)
91 {
92 COLORREF *col = pBmpBits;
93 int x, y;
94 HDC hdcTemp = CreateCompatibleDC(NULL);
95 if(!hdcTemp)
96 {
97 DeleteObject(bmpalpha);
98 return FALSE;
99 }
100 SelectObject(hdcTemp, bmpalpha);
101
102 for(y = 0; y < bmp->bmHeight; y++)
103 {
104 for(x = 0; x < bmp->bmWidth; x++)
105 {
106 COLORREF Color = (COLORREF)GetRValue(GetPixel(hdcTemp, x, y)) << 24;
107 *col++ |= Color;
108 }
109 }
110
111 DeleteObject(bmpalpha);
112 DeleteDC(hdcTemp);
113 return TRUE;
114 }
115 return FALSE;
116 }
117 return FALSE;
118}
119
121 LPARAM LParam)
122{
123 switch (Msg)
124 {
125 case WM_CREATE:
126 {
127 /* create a memory DC */
129 if (HMemDC)
130 {
131 /* load a bitmap from file */
132 HBITMAP HBmp =
133 /* static_cast<HBITMAP> */(
135 0, 0, 0)
136 );
137 if (HBmp)
138 {
139 /* extract dimensions of the bitmap */
140 GetObject(HBmp, sizeof(BITMAP), &bmp);
141
142 /* associate the bitmap with the memory DC */
143 /* HOldBmp = static_cast<HBITMAP> */
145 );
148 {
150 return 0;
151 }
152 }
153 }
154 }
155 case WM_PAINT:
156 {
157 PAINTSTRUCT ps;
159 HDC Hdc = BeginPaint(HWnd, &ps);
160#if 0
161 try
162#endif
163 {
164
169
170 BitBlt(Hdc, 100, 90,
171 bmp.bmWidth, bmp.bmHeight,
172 HMemDC2, 0, 0,
173 SRCCOPY);
174 GdiAlphaBlend(Hdc, 0, 0, bmp.bmWidth, bmp.bmHeight,
175 HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
176 BlendFunc);
177 GdiAlphaBlend(Hdc, bmp.bmWidth - 15, 10, bmp.bmWidth / 2, bmp.bmHeight / 2,
178 HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
179 BlendFunc);
180
183
184 GdiAlphaBlend(Hdc, 140, 200, bmp.bmWidth, bmp.bmHeight,
185 HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
186 BlendFunc);
187 GdiAlphaBlend(Hdc, 20, 210, (bmp.bmWidth / 3) * 2, (bmp.bmHeight / 3) * 2,
188 HMemDC2, 0, 0, bmp.bmWidth, bmp.bmHeight,
189 BlendFunc);
190 }
191#if 0
192 catch (...)
193 {
194 EndPaint(HWnd, &ps);
195 }
196#endif
197 EndPaint(HWnd, &ps);
198 break;
199 }
200 case WM_DESTROY:
201 {
202 /* clean up */
206
208 return 0;
209 }
210 }
211 return DefWindowProc(HWnd, Msg, WParam, LParam);
212}
static HDC hDC
Definition: 3dtext.c:33
#define msg(x)
Definition: auth_time.c:54
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
struct @1636 Msg[]
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const BLENDFUNCTION BlendFunc
Definition: general.c:34
#define APIENTRY
Definition: api.h:79
#define CALLBACK
Definition: compat.h:35
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
#define BI_RGB
Definition: precomp.h:56
#define GetRValue(quad)
Definition: precomp.h:73
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const char * filename
Definition: ioapi.h:137
#define TEXT(s)
Definition: k32.h:26
const char * WndClassName
Definition: alphablend.c:13
BITMAPINFO bmpi
Definition: alphablend.c:68
BITMAP bmp
Definition: alphablend.c:62
HDC HMemDC
Definition: alphablend.c:64
HBITMAP H32BppBitmap
Definition: alphablend.c:67
HDC HMemDC2
Definition: alphablend.c:64
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Definition: alphablend.c:17
PVOID pBmpBits
Definition: alphablend.c:66
BOOL ConvertBitmapTo32Bpp(HDC hDC, BITMAP *bmp)
Definition: alphablend.c:70
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: alphablend.c:120
BOOL WINAPI GdiAlphaBlend(HDC hdcDst, int xDst, int yDst, int widthDst, int heightDst, HDC hdcSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, BLENDFUNCTION blendFunction)
HINSTANCE HInst
Definition: alphablend.c:12
#define AC_SRC_ALPHA
Definition: alphablend.c:9
HBITMAP HOldBmp
Definition: alphablend.c:65
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
unsigned int UINT
Definition: ndis.h:50
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPED
Definition: pedump.c:615
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
Definition: bl.h:1331
BYTE BlendOp
Definition: wingdi.h:2759
BYTE BlendFlags
Definition: wingdi.h:2760
BYTE AlphaFormat
Definition: wingdi.h:2762
BYTE SourceConstantAlpha
Definition: wingdi.h:2761
HBRUSH hbrBackground
Definition: winuser.h:3173
HINSTANCE hInstance
Definition: winuser.h:3170
HCURSOR hCursor
Definition: winuser.h:3172
UINT style
Definition: winuser.h:3166
LPCSTR lpszClassName
Definition: winuser.h:3175
WNDPROC lpfnWndProc
Definition: winuser.h:3167
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#define ZeroMemory
Definition: winbase.h:1736
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
#define AC_SRC_OVER
Definition: wingdi.h:1369
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
struct tagBITMAPINFO BITMAPINFO
#define GetObject
Definition: wingdi.h:4468
BOOL WINAPI DeleteDC(_In_ HDC)
#define WM_PAINT
Definition: winuser.h:1623
#define CS_VREDRAW
Definition: winuser.h:658
#define IMAGE_BITMAP
Definition: winuser.h:211
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define CS_DBLCLKS
Definition: winuser.h:651
#define CreateWindow
Definition: winuser.h:5766
#define GetMessage
Definition: winuser.h:5802
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5824
#define LoadImage
Definition: winuser.h:5827
#define RegisterClass
Definition: winuser.h:5848
#define WM_DESTROY
Definition: winuser.h:1612
#define DispatchMessage
Definition: winuser.h:5777
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define COLOR_BTNFACE
Definition: winuser.h:931
HBITMAP HBmp
static HDC hdcSrc
Definition: xlate.c:32
static HDC hdcDst
Definition: xlate.c:32
const char * LPCSTR
Definition: xmlstorage.h:183
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192