ReactOS  0.4.15-dev-980-ge160524
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 {
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 }
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI DeleteDC(_In_ HDC)
struct tagContext Context
Definition: acpixf.h:1034
static char * dest
Definition: rtl.c:135
static HBITMAP
Definition: button.c:44
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define SRCCOPY
Definition: wingdi.h:332
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

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 }
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
GLfloat GLfloat p
Definition: glext.h:8902

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);
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 }
#define W_HEIGHT
Definition: pal.c:11
#define W_WIDTH
Definition: pal.c:10
#define abs(i)
Definition: fconv.c:206
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
static HDC
Definition: imagelist.c:92
void GeneratePalette(RGBQUAD *p)
Definition: pal.c:29
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
LONG biYPelsPerMeter
Definition: amvideo.idl:38
PALETTEENTRY palPalEntry[256]
Definition: pal.c:23
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
#define FALSE
Definition: types.h:117
RGBQUAD bmiColors[256]
Definition: pal.c:17
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
DWORD biCompression
Definition: amvideo.idl:35
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
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
DWORD biSizeImage
Definition: amvideo.idl:36
#define PC_NOCOLLAPSE
Definition: wingdi.h:880
static HPALETTE palette
Definition: clipboard.c:1345
static HDC hDC
Definition: 3dtext.c:33
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
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define BI_RGB
Definition: precomp.h:47
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
WORD palVersion
Definition: pal.c:21

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 }
#define W_HEIGHT
Definition: pal.c:11
#define W_WIDTH
Definition: pal.c:10
BYTE * dibits
Definition: pal.c:27
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
const GLubyte * c
Definition: glext.h:8905
void DoBlt(HBITMAP hBM)
Definition: pal.c:41
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548

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 W_HEIGHT
Definition: pal.c:11
#define W_WIDTH
Definition: pal.c:10
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define PeekMessage
Definition: winuser.h:5805
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define CreateWindow
Definition: winuser.h:5729
#define TRUE
Definition: types.h:120
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
HWND hWnd
Definition: settings.c:17
#define CS_HREDRAW
Definition: winuser.h:648
void UpdatePalette(HBITMAP hBM)
Definition: pal.c:63
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_OWNDC
Definition: winuser.h:650
#define PM_NOREMOVE
Definition: winuser.h:1181
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define WS_CAPTION
Definition: pedump.c:624
#define CS_VREDRAW
Definition: winuser.h:653
#define WS_MINIMIZEBOX
Definition: pedump.c:631
#define GetMessage
Definition: winuser.h:5765
#define msg(x)
Definition: auth_time.c:54
static const WCHAR szName[]
Definition: msipriv.h:1194
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: pal.c:138
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
#define WS_SYSMENU
Definition: pedump.c:629
WCHAR WndClass[]
Definition: capicon.c:23

◆ 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:
142  PostQuitMessage(0);
143  return 0;
144  default:
146  }
147 }
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define msg(x)
Definition: auth_time.c:54
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

Referenced by WinMain().

Variable Documentation

◆ dibits

BYTE* dibits

Definition at line 27 of file pal.c.

Referenced by InitBitmap(), and UpdatePalette().