ReactOS  0.4.15-dev-439-g292f67a
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
14 typedef struct
15 {
17  RGBQUAD bmiColors[256];
19 
20 typedef 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 
41 void DoBlt(HBITMAP hBM)
42 {
43  HDC hDC,Context;
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 
80 void InitBitmap(HBITMAP *hBM){
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);
93  bmInf.bmiHeader.biWidth = W_WIDTH;
94  bmInf.bmiHeader.biHeight = -abs(W_HEIGHT);
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:
142  PostQuitMessage(0);
143  return 0;
144  default:
146  }
147 }
148 
149 
150 
151 int 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 }
#define W_HEIGHT
Definition: pal.c:11
#define W_WIDTH
Definition: pal.c:10
#define abs(i)
Definition: fconv.c:206
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5805
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define CreateWindow
Definition: winuser.h:5729
DWORD biClrImportant
Definition: amvideo.idl:40
BYTE * dibits
Definition: pal.c:27
HDC WINAPI GetDC(_In_opt_ HWND)
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
void GeneratePalette(RGBQUAD *p)
Definition: pal.c:29
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
void UpdatePalette(HBITMAP hBM)
Definition: pal.c:63
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_OWNDC
Definition: winuser.h:650
char * LPSTR
Definition: xmlstorage.h:182
LONG biYPelsPerMeter
Definition: amvideo.idl:38
PALETTEENTRY palPalEntry[256]
Definition: pal.c:23
WPARAM wParam
Definition: combotst.c:138
#define PM_NOREMOVE
Definition: winuser.h:1181
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
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
RGBQUAD bmiColors[256]
Definition: pal.c:17
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
DWORD biCompression
Definition: amvideo.idl:35
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
Definition: pal.c:151
#define CW_USEDEFAULT
Definition: winuser.h:225
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: common.c:49
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WS_CAPTION
Definition: pedump.c:624
#define CS_VREDRAW
Definition: winuser.h:653
ULONG RGBQUAD
Definition: precomp.h:50
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
BITMAPINFOHEADER bmiHeader
Definition: pal.c:16
#define WINAPI
Definition: msvc.h:6
const GLubyte * c
Definition: glext.h:8905
unsigned short WORD
Definition: ntddk_ex.h:93
DWORD biSizeImage
Definition: amvideo.idl:36
void DoBlt(HBITMAP hBM)
Definition: pal.c:41
#define PC_NOCOLLAPSE
Definition: wingdi.h:880
unsigned char BYTE
Definition: xxhash.c:193
static HPALETTE palette
Definition: clipboard.c:1345
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WS_MINIMIZEBOX
Definition: pedump.c:631
BOOL WINAPI DeleteDC(_In_ HDC)
WORD palNumEntries
Definition: pal.c:22
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
unsigned int UINT
Definition: ndis.h:50
#define GetMessage
Definition: winuser.h:5765
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define msg(x)
Definition: auth_time.c:54
static const WCHAR szName[]
Definition: msipriv.h:1194
struct tagContext Context
Definition: acpixf.h:1034
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: pal.c:138
static char * dest
Definition: rtl.c:135
static HBITMAP
Definition: button.c:44
#define RegisterClass
Definition: winuser.h:5811
void exit(int exitcode)
Definition: _exit.c:33
void InitBitmap(HBITMAP *hBM)
Definition: pal.c:80
GLfloat GLfloat p
Definition: glext.h:8902
LONG_PTR LRESULT
Definition: windef.h:209
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define WS_SYSMENU
Definition: pedump.c:629
#define BI_RGB
Definition: precomp.h:47
LPARAM lParam
Definition: combotst.c:139
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
#define SRCCOPY
Definition: wingdi.h:332
WORD palVersion
Definition: pal.c:21
WCHAR WndClass[]
Definition: capicon.c:23