ReactOS 0.4.15-dev-7659-ga55345b
pal.c
Go to the documentation of this file.
1/* The idea of this test app is inspired from tutorial *
2 * found at http://www.theparticle.com/pgraph.html *
3 * *
4 * Developed by: Aleksey Bragin <aleksey@studiocerebral.com> *
5 * Version: 1.0 */
6
7#include <windows.h>
8#include <stdlib.h>
9
10#define W_WIDTH 320
11#define W_HEIGHT 240
12
13// special version of BITMAPINFO and LOGPALETTE for max of 256 palette entries
14typedef struct
15{
17 RGBQUAD bmiColors[256];
19
20typedef struct {
23 PALETTEENTRY palPalEntry[256];
25
26// The only global variable --- contents of the DIBitmap
28
30{
31 int i;
32 for(i=0;i<256;i++)
33 {
34 p[i].rgbRed = i;
35 p[i].rgbGreen = i;
36 p[i].rgbBlue = i;
37 p[i].rgbReserved = 0;
38 }
39}
40
41void DoBlt(HBITMAP hBM)
42{
44 HWND ActiveWindow;
45 RECT dest;
46 HBITMAP dflBmp;
47
48 if((ActiveWindow = GetActiveWindow()) == NULL)
49 return;
50
51 hDC = GetDC(ActiveWindow);
52 GetClientRect(ActiveWindow,&dest);
53
55 dflBmp = SelectObject(Context, hBM);
56 BitBlt(hDC, 0, 0, dest.right, dest.bottom, Context, 0, 0, SRCCOPY);
57 SelectObject(Context, dflBmp);
59 DeleteObject(dflBmp);
60 ReleaseDC(ActiveWindow, hDC);
61}
62
64 int i,y;
65 static unsigned int c=0;
66
67 for(i=0;i<W_WIDTH;i++){
68 for(y=0;y<=W_HEIGHT-1;y++)
69 dibits[y*320+i] = c % 256;
70
71 if (c > 512)
72 c = 0;
73 else
74 c++; // It's operation of incrementing of c variable, not reference of a cool OO language :-)
75 }
76
77 DoBlt(hBM);
78}
79
81 HPALETTE PalHan;
82 HWND ActiveWindow;
83 HDC hDC;
84 RGBQUAD palette[256];
85 int i;
86 BITMAPINFO256 bmInf;
87 LOGPALETTE256 palInf;
88
89 ActiveWindow = GetActiveWindow();
90 hDC = GetDC(ActiveWindow);
91
92 bmInf.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
95 bmInf.bmiHeader.biPlanes = 1;
96 bmInf.bmiHeader.biBitCount = 8;
98 bmInf.bmiHeader.biSizeImage = 0;
99 bmInf.bmiHeader.biXPelsPerMeter = 0;
100 bmInf.bmiHeader.biYPelsPerMeter = 0;
101 bmInf.bmiHeader.biClrUsed = 256;
102 bmInf.bmiHeader.biClrImportant = 256;
103
105
106 for(i=0;i<256;i++)
107 bmInf.bmiColors[i] = palette[i];
108
109 palInf.palVersion = 0x300;
110 palInf.palNumEntries = 256;
111 for(i=0;i<256;i++){
112 palInf.palPalEntry[i].peRed = palette[i].rgbRed;
113 palInf.palPalEntry[i].peGreen = palette[i].rgbGreen;
114 palInf.palPalEntry[i].peBlue = palette[i].rgbBlue;
116 }
117
118 // Create palette
119 PalHan = CreatePalette((LOGPALETTE*)&palInf);
120
121 // Select it into hDC
122 SelectPalette(hDC,PalHan,FALSE);
123
124 // Realize palette in hDC
126
127 // Delete handle to palette
128 DeleteObject(PalHan);
129
130 // Create dib section
131 *hBM = CreateDIBSection(hDC,(BITMAPINFO*)&bmInf,
132 DIB_RGB_COLORS,(void**)&dibits,0,0);
133
134 // Release dc
135 ReleaseDC(ActiveWindow,hDC);
136}
137
139{
140 switch(msg){
141 case WM_DESTROY:
143 return 0;
144 default:
146 }
147}
148
149
150
151int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpszCmdParam,int nCmdShow)
152{
154 HWND hWnd;
155 MSG msg;
156 char szName[] = "Palette BitBlt test";
157 BOOL exit = FALSE;
158 HBITMAP hBM;
159
160 // Create and register window class (not modified!!!!!!!!!!!1)
162 WndClass.lpfnWndProc = WndProc;
163 WndClass.cbClsExtra = 0;
164 WndClass.cbWndExtra = 0;
165 WndClass.hbrBackground = NULL;//GetStockObject(BLACK_BRUSH);
166 WndClass.hIcon = NULL;//LoadIcon(hInstance,NULL);
167 WndClass.hCursor = NULL;//LoadCursor(NULL,IDC_ARROW);
168 WndClass.hInstance = hInstance;
169 WndClass.lpszClassName = szName;
170 WndClass.lpszMenuName = 0;
171
173
174 // Create and show window (change styles !!!!!!!!)
175 hWnd = CreateWindow(szName, "ReactOS palette bitblt test",
178 0,0,hInstance,0);
179 ShowWindow(hWnd,nCmdShow);
180
181 // Prepare bitmap to be bitblt
182 InitBitmap(&hBM);
183
184 // Main message loop
185 while (!exit)
186 {
187 UpdatePalette(hBM);
188 Sleep(200);
189
190 if(PeekMessage(&msg,0,0,0,PM_NOREMOVE) == TRUE)
191 {
192 if (!GetMessage(&msg,0,0,0))
193 exit = TRUE;
194
197 }
198 }
199
200 return msg.wParam;
201}
static HDC hDC
Definition: 3dtext.c:33
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
WCHAR WndClass[]
Definition: capicon.c:23
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
static VOID NTAPI 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:49
#define BI_RGB
Definition: precomp.h:47
ULONG RGBQUAD
Definition: precomp.h:50
#define abs(i)
Definition: fconv.c:206
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static char * dest
Definition: rtl.c:135
static HPALETTE palette
Definition: clipboard.c:1345
unsigned int UINT
Definition: ndis.h:50
#define W_HEIGHT
Definition: pal.c:11
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: pal.c:138
BYTE * dibits
Definition: pal.c:27
void DoBlt(HBITMAP hBM)
Definition: pal.c:41
#define W_WIDTH
Definition: pal.c:10
void UpdatePalette(HBITMAP hBM)
Definition: pal.c:63
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
Definition: pal.c:151
void GeneratePalette(RGBQUAD *p)
Definition: pal.c:29
void InitBitmap(HBITMAP *hBM)
Definition: pal.c:80
#define WS_CAPTION
Definition: pedump.c:624
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_MINIMIZEBOX
Definition: pedump.c:631
static const WCHAR szName[]
Definition: powrprof.c:45
#define DefWindowProc
Definition: ros2win.h:31
#define exit(n)
Definition: config.h:202
BITMAPINFOHEADER bmiHeader
Definition: pal.c:16
RGBQUAD bmiColors[256]
Definition: pal.c:17
LONG biYPelsPerMeter
Definition: amvideo.idl:38
DWORD biCompression
Definition: amvideo.idl:35
DWORD biClrImportant
Definition: amvideo.idl:40
LONG biXPelsPerMeter
Definition: amvideo.idl:37
DWORD biSizeImage
Definition: amvideo.idl:36
WORD palNumEntries
Definition: pal.c:22
WORD palVersion
Definition: pal.c:21
PALETTEENTRY palPalEntry[256]
Definition: pal.c:23
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
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
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define DIB_RGB_COLORS
Definition: wingdi.h:367
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
#define PC_NOCOLLAPSE
Definition: wingdi.h:881
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CS_VREDRAW
Definition: winuser.h:658
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define CreateWindow
Definition: winuser.h:5753
#define GetMessage
Definition: winuser.h:5789
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define PeekMessage
Definition: winuser.h:5829
HDC WINAPI GetDC(_In_opt_ HWND)
#define CW_USEDEFAULT
Definition: winuser.h:225
#define CS_OWNDC
Definition: winuser.h:655
#define RegisterClass
Definition: winuser.h:5835
#define WM_DESTROY
Definition: winuser.h:1608
#define DispatchMessage
Definition: winuser.h:5764
#define PM_NOREMOVE
Definition: winuser.h:1194
char * LPSTR
Definition: xmlstorage.h:182
unsigned char BYTE
Definition: xxhash.c:193