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/>.
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/fbutil.h>
31
#include <grub/types.h>
32
#include <grub/video.h>
35
grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source,
36
unsigned int x, unsigned int y)
38
grub_uint8_t *ptr = 0;
40
switch (source->mode_info->bpp)
43
ptr = source->data + y * source->mode_info->pitch + x * 4;
47
ptr = source->data + y * source->mode_info->pitch + x * 3;
52
ptr = source->data + y * source->mode_info->pitch + x * 2;
56
ptr = source->data + y * source->mode_info->pitch + x;
60
/* For 1-bit bitmaps, addressing needs to be done at the bit level
61
and it doesn't make sense, in general, to ask for a pointer
62
to a particular pixel's data. */
70
get_pixel (struct grub_video_fbblit_info *source,
71
unsigned int x, unsigned int y)
73
grub_video_color_t color = 0;
75
switch (source->mode_info->bpp)
78
color = *(grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y);
84
ptr = grub_video_fb_get_video_ptr (source, x, y);
85
color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
91
color = *(grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y);
95
color = *(grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y);
99
if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
101
int bit_index = y * source->mode_info->width + x;
102
grub_uint8_t *ptr = source->data + bit_index / 8;
103
int bit_pos = 7 - bit_index % 8;
104
color = (*ptr >> bit_pos) & 0x01;
116
set_pixel (struct grub_video_fbblit_info *source,
117
unsigned int x, unsigned int y, grub_video_color_t color)
119
switch (source->mode_info->bpp)
125
ptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y);
134
grub_uint8_t *colorptr = (grub_uint8_t *)&color;
136
ptr = grub_video_fb_get_video_ptr (source, x, y);
138
ptr[0] = colorptr[0];
139
ptr[1] = colorptr[1];
140
ptr[2] = colorptr[2];
149
ptr = (grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y);
151
*ptr = (grub_uint16_t) (color & 0xFFFF);
159
ptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y);
161
*ptr = (grub_uint8_t) (color & 0xFF);
166
if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
168
int bit_index = y * source->mode_info->width + x;
169
grub_uint8_t *ptr = source->data + bit_index / 8;
170
int bit_pos = 7 - bit_index % 8;
171
*ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);