ReactOS 0.4.17-dev-1321-g5c122a9
common.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Boot Video Driver
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Platform-independent common helpers and defines
5 * COPYRIGHT: Copyright 2010 Gregor Schneider <gregor.schneider@reactos.org>
6 * Copyright 2011 Rafal Harabien <rafalh@reactos.org>
7 * Copyright 2020 Stanislav Motylkov <x86corez@gmail.com>
8 */
9
10#include "precomp.h"
11
12/* GLOBALS ********************************************************************/
13
14/*
15 * Boot video driver default palette is similar to the standard 16-color
16 * CGA palette, but it has Red and Blue channels swapped, and also dark
17 * and light gray colors swapped.
18 */
20{
21 RGB( 0, 0, 0), /* Black */
22 RGB(128, 0, 0), /* Red */
23 RGB( 0, 128, 0), /* Green */
24 RGB(128, 128, 0), /* Brown */
25 RGB( 0, 0, 128), /* Blue */
26 RGB(128, 0, 128), /* Magenta */
27 RGB( 0, 128, 128), /* Cyan */
28 RGB(128, 128, 128), /* Dark Gray */
29 RGB(192, 192, 192), /* Light Gray */
30 RGB(255, 0, 0), /* Light Red */
31 RGB( 0, 255, 0), /* Light Green */
32 RGB(255, 255, 0), /* Yellow */
33 RGB( 0, 0, 255), /* Light Blue */
34 RGB(255, 0, 255), /* Light Magenta */
35 RGB( 0, 255, 255), /* Light Cyan */
36 RGB(255, 255, 255), /* White */
37};
38
39/* PRIVATE FUNCTIONS **********************************************************/
40
41static VOID
43 _In_ ULONG Left,
48 _In_ ULONG BitsPerPixel,
49 _In_ ULONG Stride)
50{
51 ULONG X, Y;
53 const ULONG Bottom = Top + Height;
54 const ULONG Right = Left + Width;
55
56 if ((Width == 0) || (Height == 0))
57 return;
58
59 if (BitsPerPixel != 4)
60 {
61 /* FIXME: TODO */
62#if DBG
63 DbgPrint("Unhandled BitBlt\n"
64 "%lux%lu @ (%lu|%lu)\n"
65 "Bits Per Pixel %lu\n"
66 "Buffer: %p. Stride: %lu\n",
67 Width,
68 Height,
69 Left,
70 Top,
71 BitsPerPixel,
72 Buffer,
73 Stride);
74#endif
75 return;
76 }
77
79
80 /* 4bpp blitting */
81 for (Y = Top; Y < Bottom; ++Y)
82 {
83 ULONG PxlToggle = 0;
84 UCHAR Colors = 0, Color;
85
87
88 for (X = Left; X < Right; ++X)
89 {
90 if ((PxlToggle ^= 1))
91 {
92 /* Extract colors at every two pixels */
94 Color = Colors >> 4;
95 }
96 else
97 {
98 Color = Colors & 0x0F;
99 }
100 SetPixel(X, Y, Color);
101 }
102
103 Buffer += Stride;
104 }
105}
106
107static VOID
109 _In_ ULONG Left,
110 _In_ ULONG Top,
114{
115 ULONG YDelta;
116 ULONG x;
117 ULONG RleValue, NewRleValue;
118 ULONG Color, Color2;
119 ULONG i, j;
120 ULONG Code;
121
122 if ((Width == 0) || (Height == 0))
123 return;
124
126
127 /* Set Y height and current X value and start loop */
128 YDelta = Top + Height - 1;
129 x = Left;
130 for (;;)
131 {
132 /* Get the current value and advance in the buffer */
133 RleValue = *Buffer;
134 Buffer++;
135 if (RleValue)
136 {
137 /* Check if we've gone past the edge */
138 if ((x + RleValue) > (Width + Left))
139 {
140 /* Fixup the pixel value */
141 RleValue = Left - x + Width;
142 }
143
144 /* Get the new value */
145 NewRleValue = *Buffer;
146
147 /* Get the two colors */
148 Color = NewRleValue >> 4;
149 Color2 = NewRleValue & 0xF;
150
151 /* Increase buffer position */
152 Buffer++;
153
154 /* Check if we need to do a fill */
155 if (Color == Color2)
156 {
157 /* Do a fill and continue the loop */
158 RleValue += x;
159 VidSolidColorFill(x, YDelta, RleValue - 1, YDelta, (UCHAR)Color);
160 x = RleValue;
161 continue;
162 }
163
164 /* Check if the pixel value is 1 or below */
165 if (RleValue > 1)
166 {
167 /* Set loop variables */
168 for (i = (RleValue - 2) / 2 + 1; i > 0; --i)
169 {
170 /* Set the pixels */
171 SetPixel(x, YDelta, (UCHAR)Color);
172 x++;
173 SetPixel(x, YDelta, (UCHAR)Color2);
174 x++;
175
176 /* Decrease pixel value */
177 RleValue -= 2;
178 }
179 }
180
181 /* Check if there is any value at all */
182 if (RleValue)
183 {
184 /* Set the pixel and increase position */
185 SetPixel(x, YDelta, (UCHAR)Color);
186 x++;
187 }
188
189 /* Start over */
190 continue;
191 }
192
193 /* Get the current pixel value */
194 RleValue = *Buffer;
195 Code = RleValue;
196 switch (Code)
197 {
198 /* Case 0 */
199 case 0:
200 {
201 /* Set new x value, decrease distance and restart */
202 x = Left;
203 YDelta--;
204 Buffer++;
205 continue;
206 }
207
208 /* Case 1 */
209 case 1:
210 {
211 /* Done */
212 return;
213 }
214
215 /* Case 2 */
216 case 2:
217 {
218 /* Set new x value, decrease distance and restart */
219 Buffer++;
220 x += *Buffer;
221 Buffer++;
222 YDelta -= *Buffer;
223 Buffer++;
224 continue;
225 }
226
227 /* Other values */
228 default:
229 {
230 Buffer++;
231 break;
232 }
233 }
234
235 /* Check if we've gone past the edge */
236 if ((x + RleValue) > (Width + Left))
237 {
238 /* Set fixed up loop count */
239 i = RleValue - Left - Width + x;
240
241 /* Fixup pixel value */
242 RleValue -= i;
243 }
244 else
245 {
246 /* Clear loop count */
247 i = 0;
248 }
249
250 /* Check the value now */
251 if (RleValue > 1)
252 {
253 /* Set loop variables */
254 for (j = (RleValue - 2) / 2 + 1; j > 0; --j)
255 {
256 /* Get the new value */
257 NewRleValue = *Buffer;
258
259 /* Get the two colors */
260 Color = NewRleValue >> 4;
261 Color2 = NewRleValue & 0xF;
262
263 /* Increase buffer position */
264 Buffer++;
265
266 /* Set the pixels */
267 SetPixel(x, YDelta, (UCHAR)Color);
268 x++;
269 SetPixel(x, YDelta, (UCHAR)Color2);
270 x++;
271
272 /* Decrease pixel value */
273 RleValue -= 2;
274 }
275 }
276
277 /* Check if there is any value at all */
278 if (RleValue)
279 {
280 /* Set the pixel and increase position */
281 Color = *Buffer >> 4;
282 Buffer++;
283 SetPixel(x, YDelta, (UCHAR)Color);
284 x++;
285 i--;
286 }
287
288 /* Check loop count now */
289 if ((LONG)i > 0)
290 {
291 /* Decrease it */
292 i--;
293
294 /* Set new position */
295 Buffer = Buffer + (i / 2) + 1;
296 }
297
298 /* Check if we need to increase the buffer */
299 if ((ULONG_PTR)Buffer & 1) Buffer++;
300 }
301}
302
303/* PUBLIC FUNCTIONS ***********************************************************/
304
305VOID
306NTAPI
309 _In_ ULONG Left,
310 _In_ ULONG Top,
313 _In_ ULONG Stride)
314{
315 /* Invoke the helper function, expecting a 4bpp format buffer */
316 BitBlt(Left, Top, Width, Height, Buffer, 4, Stride);
317}
318
319VOID
320NTAPI
323 _In_ ULONG Left,
324 _In_ ULONG Top)
325{
327 LONG Stride;
328 PUCHAR BitmapOffset;
329 ULONG PaletteCount;
330
331 /* Get the Bitmap Header */
333
334 /* Initialize the palette */
335 PaletteCount = BitmapInfoHeader->biClrUsed ?
338 PaletteCount);
339
340 /* Make sure we can support this bitmap */
342
343 /*
344 * Calculate the stride and align it on 32-bytes, then calculate
345 * the actual start of the bitmap data.
346 */
348 Stride >>= 3;
349 Stride &= ~3;
350 BitmapOffset = Buffer + sizeof(BITMAPINFOHEADER) + PaletteCount * sizeof(ULONG);
351
352 /* Check the compression of the bitmap */
354 {
355 RleBitBlt(Left,
356 Top,
359 BitmapOffset);
360 }
361 else
362 {
363 if (BitmapInfoHeader->biHeight < 0)
364 {
365 /* Top-down DIB */
367 }
368 else
369 {
370 /* Bottom-up DIB */
371 BitmapOffset += ((BitmapInfoHeader->biHeight - 1) * Stride);
372 Stride *= -1;
373 }
374
375 BitBlt(Left,
376 Top,
379 BitmapOffset,
381 Stride);
382 }
383}
Colors
Definition: ansiprsr.h:4
VOID NTAPI VidSolidColorFill(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom, _In_ UCHAR Color)
Definition: bootvid.c:298
VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: bootvid.c:52
#define PrepareForSetPixel()
Definition: arm.h:21
VOID InitPaletteWithTable(_In_reads_(Count) const ULONG *Table, _In_ ULONG Count)
Definition: bootvid.c:220
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY Top
Definition: history.c:53
Definition: bufpool.h:45
#define Code
Definition: deflate.h:80
_Check_return_ _In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ PDXGKARG_SYSTEM_DISPLAY_ENABLE_FLAGS _Out_ UINT _Out_ UINT * Height
Definition: dispmprt.h:1445
_Check_return_ _In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ PDXGKARG_SYSTEM_DISPLAY_ENABLE_FLAGS _Out_ UINT * Width
Definition: dispmprt.h:1444
#define Y(I)
VOID NTAPI VidBitBlt(_In_ PUCHAR Buffer, _In_ ULONG Left, _In_ ULONG Top)
Definition: common.c:321
const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS]
Definition: common.c:19
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Height *Stride) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Stride)
Definition: common.c:42
VOID NTAPI VidBufferToScreenBlt(_In_reads_bytes_(Height *Stride) PUCHAR Buffer, _In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_ ULONG Stride)
Definition: common.c:307
static VOID RleBitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_ PUCHAR Buffer)
Definition: common.c:108
#define BI_RLE4
Definition: precomp.h:47
struct tagBITMAPINFOHEADER * PBITMAPINFOHEADER
#define RGB(r, g, b)
Definition: precomp.h:88
ULONG RGBQUAD
Definition: precomp.h:49
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
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
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 GLint GLint j
Definition: glfuncs.h:250
#define DbgPrint
Definition: hal.h:12
#define X(b, s)
#define ASSERT(a)
Definition: mode.c:44
#define _In_reads_bytes_(s)
Definition: no_sal2.h:170
#define _In_
Definition: no_sal2.h:158
long LONG
Definition: pedump.c:60
#define BV_MAX_COLORS
Definition: display.h:32
DWORD biCompression
Definition: amvideo.idl:35
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1707
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953