~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

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

ImportĀ upstreamĀ versionĀ 1.97~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2006,2007,2009  Free Software Foundation, Inc.
4
 
 *
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.
9
 
 *
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.
14
 
 *
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/>.
17
 
 */
18
 
 
19
 
#include <grub/machine/vbeutil.h>
20
 
#include <grub/types.h>
21
 
#include <grub/video.h>
22
 
 
23
 
grub_uint8_t *
24
 
get_data_ptr (struct grub_video_i386_vbeblit_info *source,
25
 
              unsigned int x, unsigned int y)
26
 
{
27
 
  grub_uint8_t *ptr = 0;
28
 
 
29
 
  switch (source->mode_info->bpp)
30
 
    {
31
 
    case 32:
32
 
      ptr = (grub_uint8_t *)source->data
33
 
            + y * source->mode_info->pitch
34
 
            + x * 4;
35
 
      break;
36
 
 
37
 
    case 24:
38
 
      ptr = (grub_uint8_t *)source->data
39
 
            + y * source->mode_info->pitch
40
 
            + x * 3;
41
 
      break;
42
 
 
43
 
    case 16:
44
 
    case 15:
45
 
      ptr = (grub_uint8_t *)source->data
46
 
            + y * source->mode_info->pitch
47
 
            + x * 2;
48
 
      break;
49
 
 
50
 
    case 8:
51
 
      ptr = (grub_uint8_t *)source->data
52
 
            + y * source->mode_info->pitch
53
 
            + x;
54
 
      break;
55
 
 
56
 
    case 1:
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.  */
60
 
      break;
61
 
    }
62
 
 
63
 
  return ptr;
64
 
}
65
 
 
66
 
grub_video_color_t
67
 
get_pixel (struct grub_video_i386_vbeblit_info *source,
68
 
           unsigned int x, unsigned int y)
69
 
{
70
 
  grub_video_color_t color = 0;
71
 
 
72
 
  switch (source->mode_info->bpp)
73
 
    {
74
 
    case 32:
75
 
      color = *(grub_uint32_t *)get_data_ptr (source, x, y);
76
 
      break;
77
 
 
78
 
    case 24:
79
 
      {
80
 
        grub_uint8_t *ptr;
81
 
        ptr = get_data_ptr (source, x, y);
82
 
        color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
83
 
      }
84
 
      break;
85
 
 
86
 
    case 16:
87
 
    case 15:
88
 
      color = *(grub_uint16_t *)get_data_ptr (source, x, y);
89
 
      break;
90
 
 
91
 
    case 8:
92
 
      color = *(grub_uint8_t *)get_data_ptr (source, x, y);
93
 
      break;
94
 
 
95
 
    case 1:
96
 
      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
97
 
        {
98
 
          int bit_index = y * source->mode_info->width + x;
99
 
          grub_uint8_t *ptr = (grub_uint8_t *)source->data
100
 
                              + bit_index / 8;
101
 
          int bit_pos = 7 - bit_index % 8;
102
 
          color = (*ptr >> bit_pos) & 0x01;
103
 
        }
104
 
      break;
105
 
 
106
 
    default:
107
 
      break;
108
 
    }
109
 
 
110
 
  return color;
111
 
}
112
 
 
113
 
void
114
 
set_pixel (struct grub_video_i386_vbeblit_info *source,
115
 
           unsigned int x, unsigned int y, grub_video_color_t color)
116
 
{
117
 
  switch (source->mode_info->bpp)
118
 
    {
119
 
    case 32:
120
 
      {
121
 
        grub_uint32_t *ptr;
122
 
 
123
 
        ptr = (grub_uint32_t *)get_data_ptr (source, x, y);
124
 
 
125
 
        *ptr = color;
126
 
      }
127
 
      break;
128
 
 
129
 
    case 24:
130
 
      {
131
 
        grub_uint8_t *ptr;
132
 
        grub_uint8_t *colorptr = (grub_uint8_t *)&color;
133
 
 
134
 
        ptr = get_data_ptr (source, x, y);
135
 
 
136
 
        ptr[0] = colorptr[0];
137
 
        ptr[1] = colorptr[1];
138
 
        ptr[2] = colorptr[2];
139
 
      }
140
 
      break;
141
 
 
142
 
    case 16:
143
 
    case 15:
144
 
      {
145
 
        grub_uint16_t *ptr;
146
 
 
147
 
        ptr = (grub_uint16_t *)get_data_ptr (source, x, y);
148
 
 
149
 
        *ptr = (grub_uint16_t) (color & 0xFFFF);
150
 
      }
151
 
      break;
152
 
 
153
 
    case 8:
154
 
      {
155
 
        grub_uint8_t *ptr;
156
 
 
157
 
        ptr = (grub_uint8_t *)get_data_ptr (source, x, y);
158
 
 
159
 
        *ptr = (grub_uint8_t) (color & 0xFF);
160
 
      }
161
 
      break;
162
 
 
163
 
    case 1:
164
 
      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
165
 
        {
166
 
          int bit_index = y * source->mode_info->width + x;
167
 
          grub_uint8_t *ptr = (grub_uint8_t *)source->data
168
 
                              + bit_index / 8;
169
 
          int bit_pos = 7 - bit_index % 8;
170
 
          *ptr = (*ptr & ~(1 << bit_pos)) | ((color & 0x01) << bit_pos);
171
 
        }
172
 
      break;
173
 
 
174
 
    default:
175
 
      break;
176
 
    }
177
 
}