make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / boot / grub2 / video / i386 / pc / vbeutil.c
blob4556928ef7382343b6c6ff48a9fd87222dc4b3a8
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007 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/machine/vbeutil.h>
20 #include <grub/types.h>
21 #include <grub/video.h>
23 grub_uint8_t *
24 get_data_ptr (struct grub_video_i386_vbeblit_info *source,
25 unsigned int x, unsigned int y)
27 grub_uint8_t *ptr = 0;
29 switch (source->mode_info->bpp)
31 case 32:
32 ptr = (grub_uint8_t *)source->data
33 + y * source->mode_info->pitch
34 + x * 4;
35 break;
37 case 24:
38 ptr = (grub_uint8_t *)source->data
39 + y * source->mode_info->pitch
40 + x * 3;
41 break;
43 case 16:
44 case 15:
45 ptr = (grub_uint8_t *)source->data
46 + y * source->mode_info->pitch
47 + x * 2;
48 break;
50 case 8:
51 ptr = (grub_uint8_t *)source->data
52 + y * source->mode_info->pitch
53 + x;
54 break;
57 return ptr;
60 grub_video_color_t
61 get_pixel (struct grub_video_i386_vbeblit_info *source,
62 unsigned int x, unsigned int y)
64 grub_video_color_t color = 0;
66 switch (source->mode_info->bpp)
68 case 32:
69 color = *(grub_uint32_t *)get_data_ptr (source, x, y);
70 break;
72 case 24:
74 grub_uint8_t *ptr;
75 ptr = get_data_ptr (source, x, y);
76 color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
78 break;
80 case 16:
81 case 15:
82 color = *(grub_uint16_t *)get_data_ptr (source, x, y);
83 break;
85 case 8:
86 color = *(grub_uint8_t *)get_data_ptr (source, x, y);
87 break;
89 default:
90 break;
93 return color;
96 void
97 set_pixel (struct grub_video_i386_vbeblit_info *source,
98 unsigned int x, unsigned int y, grub_video_color_t color)
100 switch (source->mode_info->bpp)
102 case 32:
104 grub_uint32_t *ptr;
106 ptr = (grub_uint32_t *)get_data_ptr (source, x, y);
108 *ptr = color;
110 break;
112 case 24:
114 grub_uint8_t *ptr;
115 grub_uint8_t *colorptr = (grub_uint8_t *)&color;
117 ptr = get_data_ptr (source, x, y);
119 ptr[0] = colorptr[0];
120 ptr[1] = colorptr[1];
121 ptr[2] = colorptr[2];
123 break;
125 case 16:
126 case 15:
128 grub_uint16_t *ptr;
130 ptr = (grub_uint16_t *)get_data_ptr (source, x, y);
132 *ptr = (grub_uint16_t) (color & 0xFFFF);
134 break;
136 case 8:
138 grub_uint8_t *ptr;
140 ptr = (grub_uint8_t *)get_data_ptr (source, x, y);
142 *ptr = (grub_uint8_t) (color & 0xFF);
144 break;
146 default:
147 break;