~ubuntu-branches/debian/sid/grub2/sid-200907171837

« back to all changes in this revision

Viewing changes to video/i386/pc/vbeblit.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2006-10-14 21:19:21 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061014211921-ge29q0dowqxicngk
Tags: 1.95-1
* New upstream release.
  - patches/03_revert_partition_numbering.diff: Delete (obsoleted).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
18
 */
19
19
 
20
 
#include <grub/err.h>
21
 
#include <grub/machine/memory.h>
 
20
/* SPECIAL NOTES!
 
21
 
 
22
   Please note following when reading the code below:
 
23
 
 
24
   - In this driver we assume that every memory can be accessed by same memory
 
25
   bus.  If there are different address spaces do not use this code as a base
 
26
   code for other archs.
 
27
 
 
28
   - Every function in this code assumes that bounds checking has been done in
 
29
   previous phase and they are opted out in here.  */
 
30
 
22
31
#include <grub/machine/vbe.h>
23
32
#include <grub/machine/vbeblit.h>
 
33
#include <grub/machine/vbeutil.h>
 
34
#include <grub/misc.h>
24
35
#include <grub/types.h>
25
 
#include <grub/dl.h>
26
 
#include <grub/misc.h>
27
 
#include <grub/font.h>
28
 
#include <grub/mm.h>
29
36
#include <grub/video.h>
30
37
 
31
38
void
32
 
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_render_target *dst,
33
 
                                           struct grub_video_render_target *src,
 
39
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
 
40
                                           struct grub_video_i386_vbeblit_info *src,
34
41
                                           int x, int y, int width, int height,
35
42
                                           int offset_x, int offset_y)
36
43
{
46
53
  unsigned int dr;
47
54
  unsigned int dg;
48
55
  unsigned int db;
49
 
  
 
56
 
50
57
  /* We do not need to worry about data being out of bounds
51
58
     as we assume that everything has been checked before.  */
52
 
  
 
59
 
53
60
  for (j = 0; j < height; j++)
54
61
    {
55
 
      srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x,
56
 
                                                              j + offset_y);
57
 
 
58
 
      dstptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
 
62
      srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
63
      dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j);
59
64
 
60
65
      for (i = 0; i < width; i++)
61
66
        {
62
67
          color = *srcptr++;
63
 
          
 
68
 
64
69
          a = color >> 24;
65
 
          
 
70
 
66
71
          if (a == 0)
67
72
            {
68
73
              dstptr++;
74
79
              *dstptr++ = color;
75
80
              continue;
76
81
            }
77
 
            
 
82
 
78
83
          sr = (color >> 0) & 0xFF;
79
84
          sg = (color >> 8) & 0xFF;
80
85
          sb = (color >> 16) & 0xFF;
81
 
          
 
86
 
82
87
          color = *dstptr;
83
 
          
 
88
 
84
89
          dr = (color >> 0) & 0xFF;
85
90
          dg = (color >> 8) & 0xFF;
86
91
          db = (color >> 16) & 0xFF;
87
 
          
 
92
 
88
93
          dr = (dr * (255 - a) + sr * a) / 255;
89
94
          dg = (dg * (255 - a) + sg * a) / 255;
90
95
          db = (db * (255 - a) + sb * a) / 255;
91
 
          
 
96
 
92
97
          color = (a << 24) | (db << 16) | (dg << 8) | dr;
93
98
 
94
 
          *dstptr++ = color;          
 
99
          *dstptr++ = color;
95
100
        }
96
101
    }
97
102
}
98
103
 
99
104
void
100
 
grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_render_target *dst,
101
 
                                         struct grub_video_render_target *src,
 
105
grub_video_i386_vbeblit_R8G8B8X8_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
 
106
                                           struct grub_video_i386_vbeblit_info *src,
 
107
                                           int x, int y, int width, int height,
 
108
                                           int offset_x, int offset_y)
 
109
{
 
110
  int j;
 
111
  grub_uint32_t *srcptr;
 
112
  grub_uint32_t *dstptr;
 
113
  int pitch;
 
114
 
 
115
  pitch = src->mode_info->bytes_per_pixel;
 
116
 
 
117
  /* We do not need to worry about data being out of bounds
 
118
     as we assume that everything has been checked before.  */
 
119
 
 
120
  for (j = 0; j < height; j++)
 
121
    {
 
122
      srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
123
      dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j);
 
124
 
 
125
      grub_memmove (dstptr, srcptr, width * pitch);
 
126
    }
 
127
}
 
128
 
 
129
void
 
130
grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
 
131
                                         struct grub_video_i386_vbeblit_info *src,
102
132
                                         int x, int y, int width, int height,
103
133
                                         int offset_x, int offset_y)
104
134
{
114
144
  unsigned int dr;
115
145
  unsigned int dg;
116
146
  unsigned int db;
117
 
  
 
147
 
118
148
  /* We do not need to worry about data being out of bounds
119
149
     as we assume that everything has been checked before.  */
120
 
  
 
150
 
121
151
  for (j = 0; j < height; j++)
122
152
    {
123
 
      srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x,
124
 
                                                              j + offset_y);
125
 
 
126
 
      dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
 
153
      srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
154
      dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
127
155
 
128
156
      for (i = 0; i < width; i++)
129
157
        {
130
158
          color = *srcptr++;
131
 
          
 
159
 
132
160
          a = color >> 24;
133
 
          
 
161
 
134
162
          if (a == 0)
135
163
            {
136
164
              dstptr += 3;
146
174
              *dstptr++ = sr;
147
175
              *dstptr++ = sg;
148
176
              *dstptr++ = sb;
149
 
              
 
177
 
150
178
              continue;
151
179
            }
152
 
            
 
180
 
153
181
          dr = dstptr[0];
154
182
          dg = dstptr[1];
155
183
          db = dstptr[2];
156
 
          
 
184
 
157
185
          dr = (dr * (255 - a) + sr * a) / 255;
158
186
          dg = (dg * (255 - a) + sg * a) / 255;
159
187
          db = (db * (255 - a) + sb * a) / 255;
160
 
          
 
188
 
161
189
          *dstptr++ = dr;
162
190
          *dstptr++ = dg;
163
191
          *dstptr++ = db;
166
194
}
167
195
 
168
196
void
169
 
grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_render_target *dst,
170
 
                                        struct grub_video_render_target *src,
 
197
grub_video_i386_vbeblit_R8G8B8_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
 
198
                                         struct grub_video_i386_vbeblit_info *src,
 
199
                                         int x, int y, int width, int height,
 
200
                                         int offset_x, int offset_y)
 
201
{
 
202
  grub_uint32_t color;
 
203
  int i;
 
204
  int j;
 
205
  grub_uint32_t *srcptr;
 
206
  grub_uint8_t *dstptr;
 
207
  unsigned int sr;
 
208
  unsigned int sg;
 
209
  unsigned int sb;
 
210
 
 
211
  /* We do not need to worry about data being out of bounds
 
212
     as we assume that everything has been checked before.  */
 
213
 
 
214
  for (j = 0; j < height; j++)
 
215
  {
 
216
    srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
217
    dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
 
218
 
 
219
    for (i = 0; i < width; i++)
 
220
    {
 
221
      color = *srcptr++;
 
222
 
 
223
      sr = (color >> 0) & 0xFF;
 
224
      sg = (color >> 8) & 0xFF;
 
225
      sb = (color >> 16) & 0xFF;
 
226
 
 
227
      *dstptr++ = sr;
 
228
      *dstptr++ = sg;
 
229
      *dstptr++ = sb;
 
230
    }
 
231
  }
 
232
}
 
233
 
 
234
void
 
235
grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_i386_vbeblit_info *dst,
 
236
                                        struct grub_video_i386_vbeblit_info *src,
171
237
                                        int x, int y, int width, int height,
172
238
                                        int offset_x, int offset_y)
173
239
{
184
250
  unsigned char dg;
185
251
  unsigned char db;
186
252
  unsigned char da;
187
 
  
 
253
 
188
254
  /* We do not need to worry about data being out of bounds
189
255
     as we assume that everything has been checked before.  */
190
 
  
 
256
 
191
257
  for (j = 0; j < height; j++)
192
258
    {
193
 
      srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x,
194
 
                                                              j + offset_y);
195
 
 
196
 
      dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
 
259
      srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
260
      dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
197
261
 
198
262
      for (i = 0; i < width; i++)
199
263
        {
200
264
          color = *srcptr++;
201
 
          
 
265
 
202
266
          a = color >> 24;
203
 
          
 
267
 
204
268
          if (a == 0)
205
269
            {
206
270
              dstptr++;
210
274
          sr = (color >> 0) & 0xFF;
211
275
          sg = (color >> 8) & 0xFF;
212
276
          sb = (color >> 16) & 0xFF;
213
 
          
 
277
 
214
278
          if (a == 255)
215
279
            {
216
280
              color = grub_video_vbe_map_rgb(sr, sg, sb);
217
 
              *dstptr++ = color & 0xFF;              
 
281
              *dstptr++ = color & 0xFF;
218
282
              continue;
219
283
            }
220
 
            
 
284
 
221
285
          grub_video_vbe_unmap_color (dst, *dstptr, &dr, &dg, &db, &da);
222
 
          
 
286
 
223
287
          dr = (dr * (255 - a) + sr * a) / 255;
224
288
          dg = (dg * (255 - a) + sg * a) / 255;
225
289
          db = (db * (255 - a) + sb * a) / 255;
226
 
          
 
290
 
227
291
          color = grub_video_vbe_map_rgb(dr, dg, db);
228
292
 
229
293
          *dstptr++ = color & 0xFF;
232
296
}
233
297
 
234
298
void
235
 
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_render_target *dst,
236
 
                                         struct grub_video_render_target *src,
 
299
grub_video_i386_vbeblit_index_R8G8B8X8 (struct grub_video_i386_vbeblit_info *dst,
 
300
                                        struct grub_video_i386_vbeblit_info *src,
 
301
                                        int x, int y, int width, int height,
 
302
                                        int offset_x, int offset_y)
 
303
{
 
304
  grub_uint32_t color;
 
305
  int i;
 
306
  int j;
 
307
  grub_uint32_t *srcptr;
 
308
  grub_uint8_t *dstptr;
 
309
  unsigned int sr;
 
310
  unsigned int sg;
 
311
  unsigned int sb;
 
312
 
 
313
  /* We do not need to worry about data being out of bounds
 
314
  as we assume that everything has been checked before.  */
 
315
 
 
316
  for (j = 0; j < height; j++)
 
317
  {
 
318
    srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y);
 
319
    dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
 
320
 
 
321
    for (i = 0; i < width; i++)
 
322
    {
 
323
      color = *srcptr++;
 
324
 
 
325
      sr = (color >> 0) & 0xFF;
 
326
      sg = (color >> 8) & 0xFF;
 
327
      sb = (color >> 16) & 0xFF;
 
328
 
 
329
      color = grub_video_vbe_map_rgb(sr, sg, sb);
 
330
      *dstptr++ = color & 0xFF;
 
331
    }
 
332
  }
 
333
}
 
334
 
 
335
void
 
336
grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
 
337
                                         struct grub_video_i386_vbeblit_info *src,
237
338
                                         int x, int y, int width, int height,
238
339
                                         int offset_x, int offset_y)
239
340
{
245
346
  unsigned int sr;
246
347
  unsigned int sg;
247
348
  unsigned int sb;
248
 
  
 
349
 
249
350
  /* We do not need to worry about data being out of bounds
250
351
     as we assume that everything has been checked before.  */
251
 
  
 
352
 
252
353
  for (j = 0; j < height; j++)
253
354
    {
254
 
      srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x,
255
 
                                                             j + offset_y);
256
 
 
257
 
      dstptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
 
355
      srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
 
356
      dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j);
258
357
 
259
358
      for (i = 0; i < width; i++)
260
359
        {
263
362
          sb = *srcptr++;
264
363
 
265
364
          color = 0xFF000000 | (sb << 16) | (sg << 8) | sr;
266
 
          
 
365
 
267
366
          *dstptr++ = color;
268
367
        }
269
368
    }
270
369
}
271
370
 
272
 
 
273
371
void
274
 
grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_render_target *dst,
275
 
                                       struct grub_video_render_target *src,
 
372
grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
 
373
                                       struct grub_video_i386_vbeblit_info *src,
276
374
                                       int x, int y, int width, int height,
277
375
                                       int offset_x, int offset_y)
278
376
{
279
 
  int i;
280
377
  int j;
281
378
  grub_uint8_t *srcptr;
282
379
  grub_uint8_t *dstptr;
283
 
  
 
380
  int pitch;
 
381
 
 
382
  pitch = src->mode_info->bytes_per_pixel;
 
383
 
284
384
  /* We do not need to worry about data being out of bounds
285
385
     as we assume that everything has been checked before.  */
286
 
  
 
386
 
287
387
  for (j = 0; j < height; j++)
288
388
    {
289
 
      srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, 
290
 
                                                             offset_x,
291
 
                                                             j + offset_y);
292
 
 
293
 
      dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst,
294
 
                                                             x, 
295
 
                                                             y + j);
296
 
 
297
 
      for (i = 0; i < width; i++)
298
 
        {
299
 
          *dstptr ++ = *srcptr++;
300
 
          *dstptr ++ = *srcptr++;
301
 
          *dstptr ++ = *srcptr++;
302
 
        }
 
389
      srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
 
390
      dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
 
391
 
 
392
      grub_memmove (dstptr, srcptr, width * pitch);
303
393
    }
304
394
}
305
395
 
306
396
void
307
 
grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_render_target *dst,
308
 
                                      struct grub_video_render_target *src,
 
397
grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_i386_vbeblit_info *dst,
 
398
                                      struct grub_video_i386_vbeblit_info *src,
309
399
                                      int x, int y, int width, int height,
310
400
                                      int offset_x, int offset_y)
311
401
{
317
407
  unsigned int sr;
318
408
  unsigned int sg;
319
409
  unsigned int sb;
320
 
  
 
410
 
321
411
  /* We do not need to worry about data being out of bounds
322
412
     as we assume that everything has been checked before.  */
323
 
  
 
413
 
324
414
  for (j = 0; j < height; j++)
325
415
    {
326
 
      srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x,
327
 
                                                             j + offset_y);
328
 
 
329
 
      dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
 
416
      srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
 
417
      dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
330
418
 
331
419
      for (i = 0; i < width; i++)
332
420
        {
333
421
          sr = *srcptr++;
334
422
          sg = *srcptr++;
335
423
          sb = *srcptr++;
336
 
          
 
424
 
337
425
          color = grub_video_vbe_map_rgb(sr, sg, sb);
338
426
 
339
427
          *dstptr++ = color & 0xFF;
341
429
    }
342
430
}
343
431
 
344
 
 
345
432
void
346
 
grub_video_i386_vbeblit_index_index (struct grub_video_render_target *dst,
347
 
                                     struct grub_video_render_target *src,
 
433
grub_video_i386_vbeblit_index_index (struct grub_video_i386_vbeblit_info *dst,
 
434
                                     struct grub_video_i386_vbeblit_info *src,
348
435
                                     int x, int y, int width, int height,
349
436
                                     int offset_x, int offset_y)
350
437
{
351
 
  int i;
352
438
  int j;
353
439
  grub_uint8_t *srcptr;
354
440
  grub_uint8_t *dstptr;
355
 
  
356
 
  /* We do not need to worry about data being out of bounds
357
 
     as we assume that everything has been checked before.  */
358
 
  
359
 
  for (j = 0; j < height; j++)
360
 
    {
361
 
      srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x,
362
 
                                                             j + offset_y);
363
 
                                                              
364
 
      dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j);
365
 
 
 
441
  int pitch;
 
442
 
 
443
  pitch = src->mode_info->bytes_per_pixel;
 
444
 
 
445
  /* We do not need to worry about data being out of bounds
 
446
     as we assume that everything has been checked before.  */
 
447
 
 
448
  for (j = 0; j < height; j++)
 
449
    {
 
450
      srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y);
 
451
      dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j);
 
452
 
 
453
      grub_memmove (dstptr, srcptr, width * pitch);
 
454
    }
 
455
}
 
456
 
 
457
void
 
458
grub_video_i386_vbeblit_blend (struct grub_video_i386_vbeblit_info *dst,
 
459
                               struct grub_video_i386_vbeblit_info *src,
 
460
                               int x, int y, int width, int height,
 
461
                               int offset_x, int offset_y)
 
462
{
 
463
  int i;
 
464
  int j;
 
465
 
 
466
  /* We do not need to worry about data being out of bounds
 
467
     as we assume that everything has been checked before.  */
 
468
 
 
469
  for (j = 0; j < height; j++)
 
470
    {
366
471
      for (i = 0; i < width; i++)
367
 
          *dstptr++ = *srcptr++;
368
 
    }
 
472
        {
 
473
          grub_uint8_t src_red;
 
474
          grub_uint8_t src_green;
 
475
          grub_uint8_t src_blue;
 
476
          grub_uint8_t src_alpha;
 
477
          grub_uint8_t dst_red;
 
478
          grub_uint8_t dst_green;
 
479
          grub_uint8_t dst_blue;
 
480
          grub_uint8_t dst_alpha;
 
481
          grub_video_color_t src_color;
 
482
          grub_video_color_t dst_color;
 
483
 
 
484
          src_color = get_pixel (src, i + offset_x, j + offset_y);
 
485
          grub_video_vbe_unmap_color (src, src_color, &src_red, &src_green,
 
486
                                      &src_blue, &src_alpha);
 
487
 
 
488
          if (src_alpha == 0)
 
489
            continue;
 
490
 
 
491
          if (src_alpha == 255)
 
492
            {
 
493
              dst_color = grub_video_vbe_map_rgba (src_red, src_green,
 
494
                                                   src_blue, src_alpha);
 
495
              set_pixel (dst, x + i, y + j, dst_color);
 
496
              continue;
 
497
            }
 
498
 
 
499
          dst_color = get_pixel (dst, x + i, y + j);
 
500
 
 
501
          grub_video_vbe_unmap_color (dst, dst_color, &dst_red,
 
502
                                      &dst_green, &dst_blue, &dst_alpha);
 
503
 
 
504
          dst_red = (((src_red * src_alpha)
 
505
                      + (dst_red * (255 - src_alpha))) / 255);
 
506
          dst_green = (((src_green * src_alpha)
 
507
                        + (dst_green * (255 - src_alpha))) / 255);
 
508
          dst_blue = (((src_blue * src_alpha)
 
509
                       + (dst_blue * (255 - src_alpha))) / 255);
 
510
 
 
511
          dst_alpha = src_alpha;
 
512
          dst_color = grub_video_vbe_map_rgba (dst_red, dst_green, dst_blue,
 
513
                                               dst_alpha);
 
514
 
 
515
          set_pixel (dst, x + i, y + j, dst_color);
 
516
        }
 
517
    }
 
518
}
 
519
 
 
520
void
 
521
grub_video_i386_vbeblit_replace (struct grub_video_i386_vbeblit_info *dst,
 
522
                                 struct grub_video_i386_vbeblit_info *src,
 
523
                                 int x, int y, int width, int height,
 
524
                                 int offset_x, int offset_y)
 
525
{
 
526
  int i;
 
527
  int j;
 
528
  grub_uint8_t src_red;
 
529
  grub_uint8_t src_green;
 
530
  grub_uint8_t src_blue;
 
531
  grub_uint8_t src_alpha;
 
532
  grub_video_color_t src_color;
 
533
  grub_video_color_t dst_color;
 
534
 
 
535
  /* We do not need to worry about data being out of bounds
 
536
     as we assume that everything has been checked before.  */
 
537
 
 
538
  for (j = 0; j < height; j++)
 
539
  {
 
540
    for (i = 0; i < width; i++)
 
541
    {
 
542
      src_color = get_pixel (src, i + offset_x, j + offset_y);
 
543
      grub_video_vbe_unmap_color (src, src_color, &src_red, &src_green,
 
544
                                  &src_blue, &src_alpha);
 
545
 
 
546
      dst_color = grub_video_vbe_map_rgba (src_red, src_green,
 
547
                                           src_blue, src_alpha);
 
548
      set_pixel (dst, x + i, y + j, dst_color);
 
549
    }
 
550
  }
369
551
}