2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2009 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/>.
19 #include <grub/fbutil.h>
20 #include <grub/types.h>
21 #include <grub/video.h>
24 get_data_ptr (struct grub_video_fbblit_info
*source
,
25 unsigned int x
, unsigned int y
)
27 grub_uint8_t
*ptr
= 0;
29 switch (source
->mode_info
->bpp
)
32 ptr
= (grub_uint8_t
*)source
->data
33 + y
* source
->mode_info
->pitch
38 ptr
= (grub_uint8_t
*)source
->data
39 + y
* source
->mode_info
->pitch
45 ptr
= (grub_uint8_t
*)source
->data
46 + y
* source
->mode_info
->pitch
51 ptr
= (grub_uint8_t
*)source
->data
52 + y
* source
->mode_info
->pitch
57 /* For 1-bit bitmaps, addressing needs to be done at the bit level
58 and it doesn't make sense, in general, to ask for a pointer
59 to a particular pixel's data. */
67 get_pixel (struct grub_video_fbblit_info
*source
,
68 unsigned int x
, unsigned int y
)
70 grub_video_color_t color
= 0;
72 switch (source
->mode_info
->bpp
)
75 color
= *(grub_uint32_t
*)get_data_ptr (source
, x
, y
);
81 ptr
= get_data_ptr (source
, x
, y
);
82 color
= ptr
[0] | (ptr
[1] << 8) | (ptr
[2] << 16);
88 color
= *(grub_uint16_t
*)get_data_ptr (source
, x
, y
);
92 color
= *(grub_uint8_t
*)get_data_ptr (source
, x
, y
);
96 if (source
->mode_info
->blit_format
== GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
)
98 int bit_index
= y
* source
->mode_info
->width
+ x
;
99 grub_uint8_t
*ptr
= (grub_uint8_t
*)source
->data
101 int bit_pos
= 7 - bit_index
% 8;
102 color
= (*ptr
>> bit_pos
) & 0x01;
114 set_pixel (struct grub_video_fbblit_info
*source
,
115 unsigned int x
, unsigned int y
, grub_video_color_t color
)
117 switch (source
->mode_info
->bpp
)
123 ptr
= (grub_uint32_t
*)get_data_ptr (source
, x
, y
);
132 grub_uint8_t
*colorptr
= (grub_uint8_t
*)&color
;
134 ptr
= get_data_ptr (source
, x
, y
);
136 ptr
[0] = colorptr
[0];
137 ptr
[1] = colorptr
[1];
138 ptr
[2] = colorptr
[2];
147 ptr
= (grub_uint16_t
*)get_data_ptr (source
, x
, y
);
149 *ptr
= (grub_uint16_t
) (color
& 0xFFFF);
157 ptr
= (grub_uint8_t
*)get_data_ptr (source
, x
, y
);
159 *ptr
= (grub_uint8_t
) (color
& 0xFF);
164 if (source
->mode_info
->blit_format
== GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED
)
166 int bit_index
= y
* source
->mode_info
->width
+ x
;
167 grub_uint8_t
*ptr
= (grub_uint8_t
*)source
->data
169 int bit_pos
= 7 - bit_index
% 8;
170 *ptr
= (*ptr
& ~(1 << bit_pos
)) | ((color
& 0x01) << bit_pos
);