ReactOS  0.4.11-dev-195-gef016bf
alphablend.c File Reference
#include <windows.h>
#include <string.h>
Include dependency graph for alphablend.c:

Go to the source code of this file.

Macros

#define AC_SRC_ALPHA   (0x1)
 

Functions

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)
 
LRESULT CALLBACK MainWndProc (HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
 
int APIENTRY WinMain (HINSTANCE HInstance, HINSTANCE HPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
 
BOOL ConvertBitmapTo32Bpp (HDC hDC, BITMAP *bmp)
 

Variables

HINSTANCE HInst
 
const charWndClassName = "GMainWnd"
 
BITMAP bmp
 
LPCSTR filename = TEXT("lena.bmp")
 
HDC HMemDC = NULL
 
HDC HMemDC2 = NULL
 
HBITMAP HOldBmp = NULL
 
PVOID pBmpBits = NULL
 
HBITMAP H32BppBitmap = NULL
 
BITMAPINFO bmpi
 

Macro Definition Documentation

Function Documentation

BOOL ConvertBitmapTo32Bpp ( HDC  hDC,
BITMAP bmp 
)

Definition at line 70 of file alphablend.c.

Referenced by MainWndProc().

71 {
72  ZeroMemory(&bmpi, sizeof(BITMAPINFO));
73  bmpi.bmiHeader.biSize = 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 */
88  bmpalpha = LoadImage(HInst, MAKEINTRESOURCE(2000), IMAGE_BITMAP,
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 }
#define HDC
Definition: msvc.h:22
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define TRUE
Definition: types.h:120
#define HBITMAP
Definition: msvc.h:28
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1453
#define GetRValue(rgb)
Definition: wingdi.h:2912
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
HINSTANCE HInst
Definition: alphablend.c:12
struct Color Color
#define FALSE
Definition: types.h:117
DWORD biCompression
Definition: amvideo.idl:35
smooth NULL
Definition: ftsmooth.c:416
HDC hDC
Definition: wglext.h:521
DWORD biSizeImage
Definition: amvideo.idl:36
#define COLORREF
Definition: msvc.h:35
BITMAPINFO bmpi
Definition: alphablend.c:68
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
#define IMAGE_BITMAP
Definition: winuser.h:211
HDC HMemDC
Definition: alphablend.c:64
PVOID pBmpBits
Definition: alphablend.c:66
#define LoadImage
Definition: winuser.h:5681
#define DIB_RGB_COLORS
Definition: wingdi.h:365
DWORD COLORREF
Definition: windef.h:290
INT INT y
Definition: msvc.h:62
HBITMAP H32BppBitmap
Definition: alphablend.c:67
#define BI_RGB
Definition: precomp.h:35
#define SRCCOPY
Definition: wingdi.h:331
struct tagBITMAPINFO BITMAPINFO
INT x
Definition: msvc.h:62
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 
)
LRESULT CALLBACK MainWndProc ( HWND  HWnd,
UINT  Msg,
WPARAM  WParam,
LPARAM  LParam 
)

Definition at line 120 of file alphablend.c.

Referenced by WinMain().

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> */
144  (SelectObject(HMemDC, HBmp)
145  );
148  {
149  PostQuitMessage(0);
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 
165  BlendFunc.BlendOp = AC_SRC_OVER;
166  BlendFunc.BlendFlags = 0;
167  BlendFunc.SourceConstantAlpha = 128;
168  BlendFunc.AlphaFormat = 0;
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 
181  BlendFunc.SourceConstantAlpha = 255;
182  BlendFunc.AlphaFormat = AC_SRC_ALPHA;
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 */
204  DeleteDC(HMemDC);
205  DeleteDC(HMemDC2);
206 
207  PostQuitMessage(0);
208  return 0;
209  }
210  }
211  return DefWindowProc(HWnd, Msg, WParam, LParam);
212 }
#define HDC
Definition: msvc.h:22
#define MAKEINTRESOURCE
Definition: winuser.h:591
struct @1570 Msg[]
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)
#define HBITMAP
Definition: msvc.h:28
BOOL ConvertBitmapTo32Bpp(HDC hDC, BITMAP *bmp)
Definition: alphablend.c:70
HDC HMemDC2
Definition: alphablend.c:64
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define AC_SRC_ALPHA
Definition: alphablend.c:9
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:416
HINSTANCE HInst
Definition: alphablend.c:12
BYTE BlendOp
Definition: wingdi.h:2736
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
smooth NULL
Definition: ftsmooth.c:416
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
BYTE SourceConstantAlpha
Definition: wingdi.h:2738
#define GetObject
Definition: wingdi.h:4445
BITMAP bmp
Definition: alphablend.c:62
#define WM_PAINT
Definition: winuser.h:1602
BYTE BlendFlags
Definition: wingdi.h:2737
#define AC_SRC_OVER
Definition: wingdi.h:1350
BOOL WINAPI DeleteDC(_In_ HDC)
Definition: bl.h:1331
#define IMAGE_BITMAP
Definition: winuser.h:211
HBITMAP HOldBmp
Definition: alphablend.c:65
#define WM_CREATE
Definition: winuser.h:1590
HDC HMemDC
Definition: alphablend.c:64
#define LoadImage
Definition: winuser.h:5681
BYTE AlphaFormat
Definition: wingdi.h:2739
BLENDFUNCTION BlendFunc
Definition: general.c:32
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SRCCOPY
Definition: wingdi.h:331
HBITMAP HBmp
int APIENTRY WinMain ( HINSTANCE  HInstance,
HINSTANCE  HPrevInstance,
LPTSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 17 of file alphablend.c.

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,
43  NULL, NULL, HInst, NULL
44  );
45 
46  if (HWnd)
47  {
48  ShowWindow(HWnd, nCmdShow);
49  UpdateWindow(HWnd);
50 
51  while (GetMessage(&msg, NULL, 0, 0))
52  {
53  TranslateMessage(&msg);
54  DispatchMessage(&msg);
55  }
56  }
57  }
58  return 0;
59 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: alphablend.c:120
#define CreateWindow
Definition: winuser.h:5620
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
HANDLE HWND
Definition: compat.h:13
#define CS_HREDRAW
Definition: winuser.h:648
HBRUSH hbrBackground
Definition: winuser.h:3123
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
HINSTANCE HInst
Definition: alphablend.c:12
HCURSOR hCursor
Definition: winuser.h:3122
const char * WndClassName
Definition: alphablend.c:13
smooth NULL
Definition: ftsmooth.c:416
#define WS_CAPTION
Definition: pedump.c:624
#define CS_VREDRAW
Definition: winuser.h:653
#define WS_OVERLAPPED
Definition: pedump.c:615
#define COLOR_BTNFACE
Definition: winuser.h:918
#define CS_DBLCLKS
Definition: winuser.h:646
LPCSTR lpszClassName
Definition: winuser.h:3125
#define LoadCursor
Definition: winuser.h:5678
UINT style
Definition: winuser.h:3116
#define TEXT(s)
Definition: k32.h:26
HINSTANCE hInstance
Definition: winuser.h:3120
#define GetMessage
Definition: winuser.h:5656
WNDPROC lpfnWndProc
Definition: winuser.h:3117
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define RegisterClass
Definition: winuser.h:5702
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_SYSMENU
Definition: pedump.c:629
#define memset(x, y, z)
Definition: compat.h:39

Variable Documentation

BITMAP bmp

Definition at line 62 of file alphablend.c.

Referenced by add_checksum_entry(), add_tb_button(), alpha_blend_image(), balance_data_chunk(), BitBltFromClipboard(), brush_fill_path(), cert_mgr_advanced_dlg_proc(), cert_mgr_dlg_proc(), cert_properties_general_dlg_proc(), COMCTL32_EnsureBitmapSize(), DIB_CreateDIBSection(), draw_graphics(), get_graphics_device_bounds(), get_icon_size(), GetBookmark(), GetClipboardDataDimensions(), HEADER_DrawItem(), ImageList_Add(), ImageList_AddMasked(), ImageList_LoadImageW(), ImageList_Replace(), ImageList_ReplaceIcon(), init_hierarchy_page(), LISTVIEW_SetColumnWidth(), load_stored_free_space_tree(), LoadCardBitmapsFromLibrary(), MainWndProc(), MENU_DrawBitmapItem(), MENU_GetBitmapItemSize(), NotifyArea::Paint(), StartMenuRoot::Paint(), PictureButton::PictureButton(), scrub_chunk(), START_TEST(), test_bitmap_font_glyph_index(), test_bmBits(), test_brush_pens(), test_CreateBitmap(), test_D3DKMTCreateDCFromMemory(), test_DIB_PAL_COLORS(), test_GdiGradientFill(), test_GdipDrawImagePointsRectOnMemoryDC(), test_GdipFillRectanglesOnMemoryDCSolidBrush(), test_GdipFillRectanglesOnMemoryDCTextureBrush(), test_GdipGetVisibleClipBounds_memoryDC(), test_GetCursorFrameInfo(), test_himetric(), test_layered_window(), test_LoadIconWithScaleDown(), test_LoadImage(), test_multiframegif(), test_pic_with_stream(), test_printer_dc(), test_ps_alternate(), User32CallOBMFromKernel(), UXTHEME_LoadImage(), UXTHEME_SelectImage(), WDML_DataHandle2Global(), and WDML_Global2DataHandle().

BITMAPINFO bmpi

Definition at line 68 of file alphablend.c.

Referenced by InitLogo().

LPCSTR filename = TEXT("lena.bmp")

Definition at line 63 of file alphablend.c.

HBITMAP H32BppBitmap = NULL

Definition at line 67 of file alphablend.c.

Referenced by ConvertBitmapTo32Bpp().

HINSTANCE HInst

Definition at line 12 of file alphablend.c.

Referenced by ConvertBitmapTo32Bpp(), MainWndProc(), and WinMain().

HDC HMemDC = NULL

Definition at line 64 of file alphablend.c.

Referenced by ConvertBitmapTo32Bpp(), and MainWndProc().

HDC HMemDC2 = NULL

Definition at line 64 of file alphablend.c.

Referenced by MainWndProc().

HBITMAP HOldBmp = NULL

Definition at line 65 of file alphablend.c.

Referenced by MainWndProc().

PVOID pBmpBits = NULL

Definition at line 66 of file alphablend.c.

Referenced by ConvertBitmapTo32Bpp().

const char* WndClassName = "GMainWnd"

Definition at line 13 of file alphablend.c.

Referenced by WinMain().