ReactOS 0.4.15-dev-8417-gb6b82fe
pal.c File Reference
#include <windows.h>
#include <stdlib.h>
Include dependency graph for pal.c:

Go to the source code of this file.

Classes

struct  BITMAPINFO256
 
struct  LOGPALETTE256
 

Macros

#define W_WIDTH   320
 
#define W_HEIGHT   240
 

Functions

void GeneratePalette (RGBQUAD *p)
 
void DoBlt (HBITMAP hBM)
 
void UpdatePalette (HBITMAP hBM)
 
void InitBitmap (HBITMAP *hBM)
 
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
 

Variables

BYTEdibits
 

Macro Definition Documentation

◆ W_HEIGHT

#define W_HEIGHT   240

Definition at line 11 of file pal.c.

◆ W_WIDTH

#define W_WIDTH   320

Definition at line 10 of file pal.c.

Function Documentation

◆ DoBlt()

void DoBlt ( HBITMAP  hBM)

Definition at line 41 of file pal.c.

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}
static HDC hDC
Definition: 3dtext.c:33
#define NULL
Definition: types.h:112
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
pKey DeleteObject()
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static char * dest
Definition: rtl.c:135
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by UpdatePalette().

◆ GeneratePalette()

void GeneratePalette ( RGBQUAD p)

Definition at line 29 of file pal.c.

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}
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

Referenced by InitBitmap().

◆ InitBitmap()

void InitBitmap ( HBITMAP hBM)

Definition at line 80 of file pal.c.

80 {
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}
#define FALSE
Definition: types.h:117
#define BI_RGB
Definition: precomp.h:56
ULONG RGBQUAD
Definition: precomp.h:59
#define abs(i)
Definition: fconv.c:206
static HPALETTE palette
Definition: clipboard.c:1345
#define W_HEIGHT
Definition: pal.c:11
BYTE * dibits
Definition: pal.c:27
#define W_WIDTH
Definition: pal.c:10
void GeneratePalette(RGBQUAD *p)
Definition: pal.c:29
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
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
#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)
#define PC_NOCOLLAPSE
Definition: wingdi.h:881

Referenced by WinMain().

◆ UpdatePalette()

void UpdatePalette ( HBITMAP  hBM)

Definition at line 63 of file pal.c.

63 {
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}
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const GLubyte * c
Definition: glext.h:8905
void DoBlt(HBITMAP hBM)
Definition: pal.c:41

Referenced by WinMain().

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpszCmdParam,
int  nCmdShow 
)

Definition at line 151 of file pal.c.

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 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
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: pal.c:138
void UpdatePalette(HBITMAP hBM)
Definition: pal.c:63
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 exit(n)
Definition: config.h:202
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define CreateWindow
Definition: winuser.h:5763
#define GetMessage
Definition: winuser.h:5799
#define PeekMessage
Definition: winuser.h:5839
#define CW_USEDEFAULT
Definition: winuser.h:225
#define CS_OWNDC
Definition: winuser.h:655
#define RegisterClass
Definition: winuser.h:5845
#define DispatchMessage
Definition: winuser.h:5774
#define PM_NOREMOVE
Definition: winuser.h:1195

◆ WndProc()

LRESULT CALLBACK WndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 138 of file pal.c.

139{
140 switch(msg){
141 case WM_DESTROY:
143 return 0;
144 default:
146 }
147}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define DefWindowProc
Definition: ros2win.h:31
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_DESTROY
Definition: winuser.h:1609

Referenced by WinMain().

Variable Documentation

◆ dibits