make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / common / boot / grub2 / video / i386 / pc / vbeblit.c
blobc5582f96a8713b8427092a9aa90faf953c37985a
1 /*
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/>.
19 /* SPECIAL NOTES!
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
25 code for other archs.
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>
37 void
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)
43 grub_uint32_t color;
44 int i;
45 int j;
46 grub_uint32_t *srcptr;
47 grub_uint32_t *dstptr;
48 unsigned int sr;
49 unsigned int sg;
50 unsigned int sb;
51 unsigned int a;
52 unsigned int dr;
53 unsigned int dg;
54 unsigned int db;
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++)
66 color = *srcptr++;
68 a = color >> 24;
70 if (a == 0)
72 dstptr++;
73 continue;
76 if (a == 255)
78 *dstptr++ = color;
79 continue;
82 sr = (color >> 0) & 0xFF;
83 sg = (color >> 8) & 0xFF;
84 sb = (color >> 16) & 0xFF;
86 color = *dstptr;
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;
98 *dstptr++ = color;
103 void
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)
109 int j;
110 grub_uint32_t *srcptr;
111 grub_uint32_t *dstptr;
112 int pitch;
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);
128 void
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)
134 grub_uint32_t color;
135 int i;
136 int j;
137 grub_uint32_t *srcptr;
138 grub_uint8_t *dstptr;
139 unsigned int sr;
140 unsigned int sg;
141 unsigned int sb;
142 unsigned int a;
143 unsigned int dr;
144 unsigned int dg;
145 unsigned int db;
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++)
157 color = *srcptr++;
159 a = color >> 24;
161 if (a == 0)
163 dstptr += 3;
164 continue;
167 sr = (color >> 0) & 0xFF;
168 sg = (color >> 8) & 0xFF;
169 sb = (color >> 16) & 0xFF;
171 if (a == 255)
173 *dstptr++ = sr;
174 *dstptr++ = sg;
175 *dstptr++ = sb;
177 continue;
180 dr = dstptr[0];
181 dg = dstptr[1];
182 db = dstptr[2];
184 dr = (dr * (255 - a) + sr * a) / 255;
185 dg = (dg * (255 - a) + sg * a) / 255;
186 db = (db * (255 - a) + sb * a) / 255;
188 *dstptr++ = dr;
189 *dstptr++ = dg;
190 *dstptr++ = db;
195 void
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)
201 grub_uint32_t color;
202 int i;
203 int j;
204 grub_uint32_t *srcptr;
205 grub_uint8_t *dstptr;
206 unsigned int sr;
207 unsigned int sg;
208 unsigned int sb;
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++)
220 color = *srcptr++;
222 sr = (color >> 0) & 0xFF;
223 sg = (color >> 8) & 0xFF;
224 sb = (color >> 16) & 0xFF;
226 *dstptr++ = sr;
227 *dstptr++ = sg;
228 *dstptr++ = sb;
233 void
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)
239 grub_uint32_t color;
240 int i;
241 int j;
242 grub_uint32_t *srcptr;
243 grub_uint8_t *dstptr;
244 unsigned int sr;
245 unsigned int sg;
246 unsigned int sb;
247 unsigned int a;
248 unsigned char dr;
249 unsigned char dg;
250 unsigned char db;
251 unsigned char da;
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++)
263 color = *srcptr++;
265 a = color >> 24;
267 if (a == 0)
269 dstptr++;
270 continue;
273 sr = (color >> 0) & 0xFF;
274 sg = (color >> 8) & 0xFF;
275 sb = (color >> 16) & 0xFF;
277 if (a == 255)
279 color = grub_video_vbe_map_rgb(sr, sg, sb);
280 *dstptr++ = color & 0xFF;
281 continue;
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;
297 void
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)
303 grub_uint32_t color;
304 int i;
305 int j;
306 grub_uint32_t *srcptr;
307 grub_uint8_t *dstptr;
308 unsigned int sr;
309 unsigned int sg;
310 unsigned int sb;
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++)
322 color = *srcptr++;
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;
334 void
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)
340 grub_uint32_t color;
341 int i;
342 int j;
343 grub_uint8_t *srcptr;
344 grub_uint32_t *dstptr;
345 unsigned int sr;
346 unsigned int sg;
347 unsigned int sb;
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++)
359 sr = *srcptr++;
360 sg = *srcptr++;
361 sb = *srcptr++;
363 color = 0xFF000000 | (sb << 16) | (sg << 8) | sr;
365 *dstptr++ = color;
370 void
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)
376 int j;
377 grub_uint8_t *srcptr;
378 grub_uint8_t *dstptr;
379 int pitch;
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);
395 void
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)
401 grub_uint32_t color;
402 int i;
403 int j;
404 grub_uint8_t *srcptr;
405 grub_uint8_t *dstptr;
406 unsigned int sr;
407 unsigned int sg;
408 unsigned int sb;
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++)
420 sr = *srcptr++;
421 sg = *srcptr++;
422 sb = *srcptr++;
424 color = grub_video_vbe_map_rgb(sr, sg, sb);
426 *dstptr++ = color & 0xFF;
431 void
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)
437 int j;
438 grub_uint8_t *srcptr;
439 grub_uint8_t *dstptr;
440 int pitch;
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);
456 void
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)
462 int i;
463 int j;
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);
487 if (src_alpha == 0)
488 continue;
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);
495 continue;
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,
512 dst_alpha);
514 set_pixel (dst, x + i, y + j, dst_color);
519 void
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)
525 int i;
526 int j;
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);