2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 Please note following when reading the code below:
23 - In this driver we assume that every memory can be accessed by same memory
24 bus. If there are different address spaces do not use this code as a base
27 - Every function in this code assumes that bounds checking has been done in
28 previous phase and they are opted out in here. */
30 #include <grub/machine/vbe.h>
31 #include <grub/machine/vbeblit.h>
32 #include <grub/machine/vbeutil.h>
33 #include <grub/misc.h>
34 #include <grub/types.h>
35 #include <grub/video.h>
38 grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_i386_vbeblit_info
*dst
,
39 struct grub_video_i386_vbeblit_info
*src
,
40 int x
, int y
, int width
, int height
,
41 int offset_x
, int offset_y
)
46 grub_uint32_t
*srcptr
;
47 grub_uint32_t
*dstptr
;
56 /* We do not need to worry about data being out of bounds
57 as we assume that everything has been checked before. */
59 for (j
= 0; j
< height
; j
++)
61 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
62 dstptr
= (grub_uint32_t
*)get_data_ptr (dst
, x
, y
+ j
);
64 for (i
= 0; i
< width
; i
++)
82 sr
= (color
>> 0) & 0xFF;
83 sg
= (color
>> 8) & 0xFF;
84 sb
= (color
>> 16) & 0xFF;
88 dr
= (color
>> 0) & 0xFF;
89 dg
= (color
>> 8) & 0xFF;
90 db
= (color
>> 16) & 0xFF;
92 dr
= (dr
* (255 - a
) + sr
* a
) / 255;
93 dg
= (dg
* (255 - a
) + sg
* a
) / 255;
94 db
= (db
* (255 - a
) + sb
* a
) / 255;
96 color
= (a
<< 24) | (db
<< 16) | (dg
<< 8) | dr
;
104 grub_video_i386_vbeblit_R8G8B8X8_R8G8B8X8 (struct grub_video_i386_vbeblit_info
*dst
,
105 struct grub_video_i386_vbeblit_info
*src
,
106 int x
, int y
, int width
, int height
,
107 int offset_x
, int offset_y
)
110 grub_uint32_t
*srcptr
;
111 grub_uint32_t
*dstptr
;
114 pitch
= src
->mode_info
->bytes_per_pixel
;
116 /* We do not need to worry about data being out of bounds
117 as we assume that everything has been checked before. */
119 for (j
= 0; j
< height
; j
++)
121 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
122 dstptr
= (grub_uint32_t
*)get_data_ptr (dst
, x
, y
+ j
);
124 grub_memmove (dstptr
, srcptr
, width
* pitch
);
129 grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_i386_vbeblit_info
*dst
,
130 struct grub_video_i386_vbeblit_info
*src
,
131 int x
, int y
, int width
, int height
,
132 int offset_x
, int offset_y
)
137 grub_uint32_t
*srcptr
;
138 grub_uint8_t
*dstptr
;
147 /* We do not need to worry about data being out of bounds
148 as we assume that everything has been checked before. */
150 for (j
= 0; j
< height
; j
++)
152 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
153 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
155 for (i
= 0; i
< width
; i
++)
167 sr
= (color
>> 0) & 0xFF;
168 sg
= (color
>> 8) & 0xFF;
169 sb
= (color
>> 16) & 0xFF;
184 dr
= (dr
* (255 - a
) + sr
* a
) / 255;
185 dg
= (dg
* (255 - a
) + sg
* a
) / 255;
186 db
= (db
* (255 - a
) + sb
* a
) / 255;
196 grub_video_i386_vbeblit_R8G8B8_R8G8B8X8 (struct grub_video_i386_vbeblit_info
*dst
,
197 struct grub_video_i386_vbeblit_info
*src
,
198 int x
, int y
, int width
, int height
,
199 int offset_x
, int offset_y
)
204 grub_uint32_t
*srcptr
;
205 grub_uint8_t
*dstptr
;
210 /* We do not need to worry about data being out of bounds
211 as we assume that everything has been checked before. */
213 for (j
= 0; j
< height
; j
++)
215 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
216 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
218 for (i
= 0; i
< width
; i
++)
222 sr
= (color
>> 0) & 0xFF;
223 sg
= (color
>> 8) & 0xFF;
224 sb
= (color
>> 16) & 0xFF;
234 grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_i386_vbeblit_info
*dst
,
235 struct grub_video_i386_vbeblit_info
*src
,
236 int x
, int y
, int width
, int height
,
237 int offset_x
, int offset_y
)
242 grub_uint32_t
*srcptr
;
243 grub_uint8_t
*dstptr
;
253 /* We do not need to worry about data being out of bounds
254 as we assume that everything has been checked before. */
256 for (j
= 0; j
< height
; j
++)
258 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
259 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
261 for (i
= 0; i
< width
; i
++)
273 sr
= (color
>> 0) & 0xFF;
274 sg
= (color
>> 8) & 0xFF;
275 sb
= (color
>> 16) & 0xFF;
279 color
= grub_video_vbe_map_rgb(sr
, sg
, sb
);
280 *dstptr
++ = color
& 0xFF;
284 grub_video_vbe_unmap_color_int (dst
, *dstptr
, &dr
, &dg
, &db
, &da
);
286 dr
= (dr
* (255 - a
) + sr
* a
) / 255;
287 dg
= (dg
* (255 - a
) + sg
* a
) / 255;
288 db
= (db
* (255 - a
) + sb
* a
) / 255;
290 color
= grub_video_vbe_map_rgb(dr
, dg
, db
);
292 *dstptr
++ = color
& 0xFF;
298 grub_video_i386_vbeblit_index_R8G8B8X8 (struct grub_video_i386_vbeblit_info
*dst
,
299 struct grub_video_i386_vbeblit_info
*src
,
300 int x
, int y
, int width
, int height
,
301 int offset_x
, int offset_y
)
306 grub_uint32_t
*srcptr
;
307 grub_uint8_t
*dstptr
;
312 /* We do not need to worry about data being out of bounds
313 as we assume that everything has been checked before. */
315 for (j
= 0; j
< height
; j
++)
317 srcptr
= (grub_uint32_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
318 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
320 for (i
= 0; i
< width
; i
++)
324 sr
= (color
>> 0) & 0xFF;
325 sg
= (color
>> 8) & 0xFF;
326 sb
= (color
>> 16) & 0xFF;
328 color
= grub_video_vbe_map_rgb(sr
, sg
, sb
);
329 *dstptr
++ = color
& 0xFF;
335 grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_i386_vbeblit_info
*dst
,
336 struct grub_video_i386_vbeblit_info
*src
,
337 int x
, int y
, int width
, int height
,
338 int offset_x
, int offset_y
)
343 grub_uint8_t
*srcptr
;
344 grub_uint32_t
*dstptr
;
349 /* We do not need to worry about data being out of bounds
350 as we assume that everything has been checked before. */
352 for (j
= 0; j
< height
; j
++)
354 srcptr
= (grub_uint8_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
355 dstptr
= (grub_uint32_t
*)get_data_ptr (dst
, x
, y
+ j
);
357 for (i
= 0; i
< width
; i
++)
363 color
= 0xFF000000 | (sb
<< 16) | (sg
<< 8) | sr
;
371 grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_i386_vbeblit_info
*dst
,
372 struct grub_video_i386_vbeblit_info
*src
,
373 int x
, int y
, int width
, int height
,
374 int offset_x
, int offset_y
)
377 grub_uint8_t
*srcptr
;
378 grub_uint8_t
*dstptr
;
381 pitch
= src
->mode_info
->bytes_per_pixel
;
383 /* We do not need to worry about data being out of bounds
384 as we assume that everything has been checked before. */
386 for (j
= 0; j
< height
; j
++)
388 srcptr
= (grub_uint8_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
389 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
391 grub_memmove (dstptr
, srcptr
, width
* pitch
);
396 grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_i386_vbeblit_info
*dst
,
397 struct grub_video_i386_vbeblit_info
*src
,
398 int x
, int y
, int width
, int height
,
399 int offset_x
, int offset_y
)
404 grub_uint8_t
*srcptr
;
405 grub_uint8_t
*dstptr
;
410 /* We do not need to worry about data being out of bounds
411 as we assume that everything has been checked before. */
413 for (j
= 0; j
< height
; j
++)
415 srcptr
= (grub_uint8_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
416 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
418 for (i
= 0; i
< width
; i
++)
424 color
= grub_video_vbe_map_rgb(sr
, sg
, sb
);
426 *dstptr
++ = color
& 0xFF;
432 grub_video_i386_vbeblit_index_index (struct grub_video_i386_vbeblit_info
*dst
,
433 struct grub_video_i386_vbeblit_info
*src
,
434 int x
, int y
, int width
, int height
,
435 int offset_x
, int offset_y
)
438 grub_uint8_t
*srcptr
;
439 grub_uint8_t
*dstptr
;
442 pitch
= src
->mode_info
->bytes_per_pixel
;
444 /* We do not need to worry about data being out of bounds
445 as we assume that everything has been checked before. */
447 for (j
= 0; j
< height
; j
++)
449 srcptr
= (grub_uint8_t
*)get_data_ptr (src
, offset_x
, j
+ offset_y
);
450 dstptr
= (grub_uint8_t
*)get_data_ptr (dst
, x
, y
+ j
);
452 grub_memmove (dstptr
, srcptr
, width
* pitch
);
457 grub_video_i386_vbeblit_blend (struct grub_video_i386_vbeblit_info
*dst
,
458 struct grub_video_i386_vbeblit_info
*src
,
459 int x
, int y
, int width
, int height
,
460 int offset_x
, int offset_y
)
465 /* We do not need to worry about data being out of bounds
466 as we assume that everything has been checked before. */
468 for (j
= 0; j
< height
; j
++)
470 for (i
= 0; i
< width
; i
++)
472 grub_uint8_t src_red
;
473 grub_uint8_t src_green
;
474 grub_uint8_t src_blue
;
475 grub_uint8_t src_alpha
;
476 grub_uint8_t dst_red
;
477 grub_uint8_t dst_green
;
478 grub_uint8_t dst_blue
;
479 grub_uint8_t dst_alpha
;
480 grub_video_color_t src_color
;
481 grub_video_color_t dst_color
;
483 src_color
= get_pixel (src
, i
+ offset_x
, j
+ offset_y
);
484 grub_video_vbe_unmap_color_int (src
, src_color
, &src_red
, &src_green
,
485 &src_blue
, &src_alpha
);
490 if (src_alpha
== 255)
492 dst_color
= grub_video_vbe_map_rgba (src_red
, src_green
,
493 src_blue
, src_alpha
);
494 set_pixel (dst
, x
+ i
, y
+ j
, dst_color
);
498 dst_color
= get_pixel (dst
, x
+ i
, y
+ j
);
500 grub_video_vbe_unmap_color_int (dst
, dst_color
, &dst_red
,
501 &dst_green
, &dst_blue
, &dst_alpha
);
503 dst_red
= (((src_red
* src_alpha
)
504 + (dst_red
* (255 - src_alpha
))) / 255);
505 dst_green
= (((src_green
* src_alpha
)
506 + (dst_green
* (255 - src_alpha
))) / 255);
507 dst_blue
= (((src_blue
* src_alpha
)
508 + (dst_blue
* (255 - src_alpha
))) / 255);
510 dst_alpha
= src_alpha
;
511 dst_color
= grub_video_vbe_map_rgba (dst_red
, dst_green
, dst_blue
,
514 set_pixel (dst
, x
+ i
, y
+ j
, dst_color
);
520 grub_video_i386_vbeblit_replace (struct grub_video_i386_vbeblit_info
*dst
,
521 struct grub_video_i386_vbeblit_info
*src
,
522 int x
, int y
, int width
, int height
,
523 int offset_x
, int offset_y
)
527 grub_uint8_t src_red
;
528 grub_uint8_t src_green
;
529 grub_uint8_t src_blue
;
530 grub_uint8_t src_alpha
;
531 grub_video_color_t src_color
;
532 grub_video_color_t dst_color
;
534 /* We do not need to worry about data being out of bounds
535 as we assume that everything has been checked before. */
537 for (j
= 0; j
< height
; j
++)
539 for (i
= 0; i
< width
; i
++)
541 src_color
= get_pixel (src
, i
+ offset_x
, j
+ offset_y
);
542 grub_video_vbe_unmap_color_int (src
, src_color
, &src_red
, &src_green
,
543 &src_blue
, &src_alpha
);
545 dst_color
= grub_video_vbe_map_rgba (src_red
, src_green
,
546 src_blue
, src_alpha
);
547 set_pixel (dst
, x
+ i
, y
+ j
, dst_color
);