17
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <grub/machine/memory.h>
22
Please note following when reading the code below:
24
- In this driver we assume that every memory can be accessed by same memory
25
bus. If there are different address spaces do not use this code as a base
28
- Every function in this code assumes that bounds checking has been done in
29
previous phase and they are opted out in here. */
22
31
#include <grub/machine/vbe.h>
23
32
#include <grub/machine/vbeblit.h>
33
#include <grub/machine/vbeutil.h>
34
#include <grub/misc.h>
24
35
#include <grub/types.h>
26
#include <grub/misc.h>
27
#include <grub/font.h>
29
36
#include <grub/video.h>
32
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_render_target *dst,
33
struct grub_video_render_target *src,
39
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
40
struct grub_video_i386_vbeblit_info *src,
34
41
int x, int y, int width, int height,
35
42
int offset_x, int offset_y)
78
83
sr = (color >> 0) & 0xFF;
79
84
sg = (color >> 8) & 0xFF;
80
85
sb = (color >> 16) & 0xFF;
84
89
dr = (color >> 0) & 0xFF;
85
90
dg = (color >> 8) & 0xFF;
86
91
db = (color >> 16) & 0xFF;
88
93
dr = (dr * (255 - a) + sr * a) / 255;
89
94
dg = (dg * (255 - a) + sg * a) / 255;
90
95
db = (db * (255 - a) + sb * a) / 255;
92
97
color = (a << 24) | (db << 16) | (dg << 8) | dr;
100
grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_render_target *dst,
101
struct grub_video_render_target *src,
105
grub_video_i386_vbeblit_R8G8B8X8_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
106
struct grub_video_i386_vbeblit_info *src,
107
int x, int y, int width, int height,
108
int offset_x, int offset_y)
111
grub_uint32_t *srcptr;
112
grub_uint32_t *dstptr;
115
pitch = src->mode_info->bytes_per_pixel;
117
/* We do not need to worry about data being out of bounds
118
as we assume that everything has been checked before. */
120
for (j = 0; j < height; j++)
122
srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
123
dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j);
125
grub_memmove (dstptr, srcptr, width * pitch);
130
grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
131
struct grub_video_i386_vbeblit_info *src,
102
132
int x, int y, int width, int height,
103
133
int offset_x, int offset_y)
169
grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_render_target *dst,
170
struct grub_video_render_target *src,
197
grub_video_i386_vbeblit_R8G8B8_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
198
struct grub_video_i386_vbeblit_info *src,
199
int x, int y, int width, int height,
200
int offset_x, int offset_y)
205
grub_uint32_t *srcptr;
206
grub_uint8_t *dstptr;
211
/* We do not need to worry about data being out of bounds
212
as we assume that everything has been checked before. */
214
for (j = 0; j < height; j++)
216
srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
217
dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
219
for (i = 0; i < width; i++)
223
sr = (color >> 0) & 0xFF;
224
sg = (color >> 8) & 0xFF;
225
sb = (color >> 16) & 0xFF;
235
grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
236
struct grub_video_i386_vbeblit_info *src,
171
237
int x, int y, int width, int height,
172
238
int offset_x, int offset_y)
210
274
sr = (color >> 0) & 0xFF;
211
275
sg = (color >> 8) & 0xFF;
212
276
sb = (color >> 16) & 0xFF;
216
280
color = grub_video_vbe_map_rgb(sr, sg, sb);
217
*dstptr++ = color & 0xFF;
281
*dstptr++ = color & 0xFF;
221
285
grub_video_vbe_unmap_color (dst, *dstptr, &dr, &dg, &db, &da);
223
287
dr = (dr * (255 - a) + sr * a) / 255;
224
288
dg = (dg * (255 - a) + sg * a) / 255;
225
289
db = (db * (255 - a) + sb * a) / 255;
227
291
color = grub_video_vbe_map_rgb(dr, dg, db);
229
293
*dstptr++ = color & 0xFF;
235
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_render_target *dst,
236
struct grub_video_render_target *src,
299
grub_video_i386_vbeblit_index_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
300
struct grub_video_i386_vbeblit_info *src,
301
int x, int y, int width, int height,
302
int offset_x, int offset_y)
307
grub_uint32_t *srcptr;
308
grub_uint8_t *dstptr;
313
/* We do not need to worry about data being out of bounds
314
as we assume that everything has been checked before. */
316
for (j = 0; j < height; j++)
318
srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
319
dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
321
for (i = 0; i < width; i++)
325
sr = (color >> 0) & 0xFF;
326
sg = (color >> 8) & 0xFF;
327
sb = (color >> 16) & 0xFF;
329
color = grub_video_vbe_map_rgb(sr, sg, sb);
330
*dstptr++ = color & 0xFF;
336
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
337
struct grub_video_i386_vbeblit_info *src,
237
338
int x, int y, int width, int height,
238
339
int offset_x, int offset_y)
265
364
color = 0xFF000000 | (sb << 16) | (sg << 8) | sr;
267
366
*dstptr++ = color;
274
grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_render_target *dst,
275
struct grub_video_render_target *src,
372
grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
373
struct grub_video_i386_vbeblit_info *src,
276
374
int x, int y, int width, int height,
277
375
int offset_x, int offset_y)
281
378
grub_uint8_t *srcptr;
282
379
grub_uint8_t *dstptr;
382
pitch = src->mode_info->bytes_per_pixel;
284
384
/* We do not need to worry about data being out of bounds
285
385
as we assume that everything has been checked before. */
287
387
for (j = 0; j < height; j++)
289
srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src,
293
dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst,
297
for (i = 0; i < width; i++)
299
*dstptr ++ = *srcptr++;
300
*dstptr ++ = *srcptr++;
301
*dstptr ++ = *srcptr++;
389
srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
390
dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
392
grub_memmove (dstptr, srcptr, width * pitch);
307
grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_render_target *dst,
308
struct grub_video_render_target *src,
397
grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
398
struct grub_video_i386_vbeblit_info *src,
309
399
int x, int y, int width, int height,
310
400
int offset_x, int offset_y)
321
411
/* We do not need to worry about data being out of bounds
322
412
as we assume that everything has been checked before. */
324
414
for (j = 0; j < height; j++)
326
srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x,
329
dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
416
srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
417
dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
331
419
for (i = 0; i < width; i++)
337
425
color = grub_video_vbe_map_rgb(sr, sg, sb);
339
427
*dstptr++ = color & 0xFF;
346
grub_video_i386_vbeblit_index_index (struct grub_video_render_target *dst,
347
struct grub_video_render_target *src,
433
grub_video_i386_vbeblit_index_index (struct grub_video_i386_vbeblit_info *dst,
434
struct grub_video_i386_vbeblit_info *src,
348
435
int x, int y, int width, int height,
349
436
int offset_x, int offset_y)
353
439
grub_uint8_t *srcptr;
354
440
grub_uint8_t *dstptr;
356
/* We do not need to worry about data being out of bounds
357
as we assume that everything has been checked before. */
359
for (j = 0; j < height; j++)
361
srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x,
364
dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
443
pitch = src->mode_info->bytes_per_pixel;
445
/* We do not need to worry about data being out of bounds
446
as we assume that everything has been checked before. */
448
for (j = 0; j < height; j++)
450
srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
451
dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
453
grub_memmove (dstptr, srcptr, width * pitch);
458
grub_video_i386_vbeblit_blend (struct grub_video_i386_vbeblit_info *dst,
459
struct grub_video_i386_vbeblit_info *src,
460
int x, int y, int width, int height,
461
int offset_x, int offset_y)
466
/* We do not need to worry about data being out of bounds
467
as we assume that everything has been checked before. */
469
for (j = 0; j < height; j++)
366
471
for (i = 0; i < width; i++)
367
*dstptr++ = *srcptr++;
473
grub_uint8_t src_red;
474
grub_uint8_t src_green;
475
grub_uint8_t src_blue;
476
grub_uint8_t src_alpha;
477
grub_uint8_t dst_red;
478
grub_uint8_t dst_green;
479
grub_uint8_t dst_blue;
480
grub_uint8_t dst_alpha;
481
grub_video_color_t src_color;
482
grub_video_color_t dst_color;
484
src_color = get_pixel (src, i + offset_x, j + offset_y);
485
grub_video_vbe_unmap_color (src, src_color, &src_red, &src_green,
486
&src_blue, &src_alpha);
491
if (src_alpha == 255)
493
dst_color = grub_video_vbe_map_rgba (src_red, src_green,
494
src_blue, src_alpha);
495
set_pixel (dst, x + i, y + j, dst_color);
499
dst_color = get_pixel (dst, x + i, y + j);
501
grub_video_vbe_unmap_color (dst, dst_color, &dst_red,
502
&dst_green, &dst_blue, &dst_alpha);
504
dst_red = (((src_red * src_alpha)
505
+ (dst_red * (255 - src_alpha))) / 255);
506
dst_green = (((src_green * src_alpha)
507
+ (dst_green * (255 - src_alpha))) / 255);
508
dst_blue = (((src_blue * src_alpha)
509
+ (dst_blue * (255 - src_alpha))) / 255);
511
dst_alpha = src_alpha;
512
dst_color = grub_video_vbe_map_rgba (dst_red, dst_green, dst_blue,
515
set_pixel (dst, x + i, y + j, dst_color);
521
grub_video_i386_vbeblit_replace (struct grub_video_i386_vbeblit_info *dst,
522
struct grub_video_i386_vbeblit_info *src,
523
int x, int y, int width, int height,
524
int offset_x, int offset_y)
528
grub_uint8_t src_red;
529
grub_uint8_t src_green;
530
grub_uint8_t src_blue;
531
grub_uint8_t src_alpha;
532
grub_video_color_t src_color;
533
grub_video_color_t dst_color;
535
/* We do not need to worry about data being out of bounds
536
as we assume that everything has been checked before. */
538
for (j = 0; j < height; j++)
540
for (i = 0; i < width; i++)
542
src_color = get_pixel (src, i + offset_x, j + offset_y);
543
grub_video_vbe_unmap_color (src, src_color, &src_red, &src_green,
544
&src_blue, &src_alpha);
546
dst_color = grub_video_vbe_map_rgba (src_red, src_green,
547
src_blue, src_alpha);
548
set_pixel (dst, x + i, y + j, dst_color);