~ilya-yanok/ubuntu/precise/grub2/fix-for-948716

« back to all changes in this revision

Viewing changes to video/fb/fbutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2009-07-25 19:00:53 UTC
  • mfrom: (1.6.3 upstream)
  • mto: (17.4.13 sid)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20090725190053-uv3lm6ya3zxs77ep
ImportĀ upstreamĀ versionĀ 1.96+20090725

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
 
/* SPECIAL NOTES!
20
 
 
21
 
   Please note following when reading the code below:
22
 
 
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.
26
 
 
27
 
   - Every function in this code assumes that bounds checking has been done in
28
 
     previous phase and they are opted out in here.  */
29
 
 
30
 
#include <grub/fbutil.h>
31
 
#include <grub/types.h>
32
 
#include <grub/video.h>
33
 
 
34
 
grub_uint8_t *
35
 
grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source,
36
 
              unsigned int x, unsigned int y)
37
 
{
38
 
  grub_uint8_t *ptr = 0;
39
 
 
40
 
  switch (source->mode_info->bpp)
41
 
    {
42
 
    case 32:
43
 
      ptr = source->data + y * source->mode_info->pitch + x * 4;
44
 
      break;
45
 
 
46
 
    case 24:
47
 
      ptr = source->data + y * source->mode_info->pitch + x * 3;
48
 
      break;
49
 
 
50
 
    case 16:
51
 
    case 15:
52
 
      ptr = source->data + y * source->mode_info->pitch + x * 2;
53
 
      break;
54
 
 
55
 
    case 8:
56
 
      ptr = source->data + y * source->mode_info->pitch + x;
57
 
      break;
58
 
 
59
 
    case 1:
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.  */
63
 
      break;
64
 
    }
65
 
 
66
 
  return ptr;
67
 
}
68
 
 
69
 
grub_video_color_t
70
 
get_pixel (struct grub_video_fbblit_info *source,
71
 
           unsigned int x, unsigned int y)
72
 
{
73
 
  grub_video_color_t color = 0;
74
 
 
75
 
  switch (source->mode_info->bpp)
76
 
    {
77
 
    case 32:
78
 
      color = *(grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y);
79
 
      break;
80
 
 
81
 
    case 24:
82
 
      {
83
 
        grub_uint8_t *ptr;
84
 
        ptr = grub_video_fb_get_video_ptr (source, x, y);
85
 
        color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
86
 
      }
87
 
      break;
88
 
 
89
 
    case 16:
90
 
    case 15:
91
 
      color = *(grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y);
92
 
      break;
93
 
 
94
 
    case 8:
95
 
      color = *(grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y);
96
 
      break;
97
 
 
98
 
    case 1:
99
 
      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
100
 
        {
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;
105
 
        }
106
 
      break;
107
 
 
108
 
    default:
109
 
      break;
110
 
    }
111
 
 
112
 
  return color;
113
 
}
114
 
 
115
 
void
116
 
set_pixel (struct grub_video_fbblit_info *source,
117
 
           unsigned int x, unsigned int y, grub_video_color_t color)
118
 
{
119
 
  switch (source->mode_info->bpp)
120
 
    {
121
 
    case 32:
122
 
      {
123
 
        grub_uint32_t *ptr;
124
 
 
125
 
        ptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y);
126
 
 
127
 
        *ptr = color;
128
 
      }
129
 
      break;
130
 
 
131
 
    case 24:
132
 
      {
133
 
        grub_uint8_t *ptr;
134
 
        grub_uint8_t *colorptr = (grub_uint8_t *)&color;
135
 
 
136
 
        ptr = grub_video_fb_get_video_ptr (source, x, y);
137
 
 
138
 
        ptr[0] = colorptr[0];
139
 
        ptr[1] = colorptr[1];
140
 
        ptr[2] = colorptr[2];
141
 
      }
142
 
      break;
143
 
 
144
 
    case 16:
145
 
    case 15:
146
 
      {
147
 
        grub_uint16_t *ptr;
148
 
 
149
 
        ptr = (grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y);
150
 
 
151
 
        *ptr = (grub_uint16_t) (color & 0xFFFF);
152
 
      }
153
 
      break;
154
 
 
155
 
    case 8:
156
 
      {
157
 
        grub_uint8_t *ptr;
158
 
 
159
 
        ptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y);
160
 
 
161
 
        *ptr = (grub_uint8_t) (color & 0xFF);
162
 
      }
163
 
      break;
164
 
 
165
 
    case 1:
166
 
      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED)
167
 
        {
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);
172
 
        }
173
 
      break;
174
 
 
175
 
    default:
176
 
      break;
177
 
    }
178
 
}