root / hw / pl110_template.h @ 43f20196
History | View | Annotate | Download (7 kB)
1 |
/*
|
---|---|
2 |
* Arm PrimeCell PL110 Color LCD Controller
|
3 |
*
|
4 |
* Copyright (c) 2005 CodeSourcery, LLC.
|
5 |
* Written by Paul Brook
|
6 |
*
|
7 |
* This code is licenced under the GNU LGPL
|
8 |
*
|
9 |
* Framebuffer format conversion routines.
|
10 |
*/
|
11 |
|
12 |
#ifndef ORDER
|
13 |
|
14 |
#if BITS == 8 |
15 |
#define COPY_PIXEL(to, from) *(to++) = from
|
16 |
#elif BITS == 15 || BITS == 16 |
17 |
#define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2; |
18 |
#elif BITS == 24 |
19 |
#define COPY_PIXEL(to, from) \
|
20 |
*(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16 |
21 |
#elif BITS == 32 |
22 |
#define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4; |
23 |
#else
|
24 |
#error unknown bit depth
|
25 |
#endif
|
26 |
|
27 |
#undef RGB
|
28 |
#define BORDER bgr
|
29 |
#define ORDER 0 |
30 |
#include "pl110_template.h" |
31 |
#define ORDER 1 |
32 |
#include "pl110_template.h" |
33 |
#define ORDER 2 |
34 |
#include "pl110_template.h" |
35 |
#undef BORDER
|
36 |
#define RGB
|
37 |
#define BORDER rgb
|
38 |
#define ORDER 0 |
39 |
#include "pl110_template.h" |
40 |
#define ORDER 1 |
41 |
#include "pl110_template.h" |
42 |
#define ORDER 2 |
43 |
#include "pl110_template.h" |
44 |
#undef BORDER
|
45 |
|
46 |
static drawfn glue(pl110_draw_fn_,BITS)[36] = |
47 |
{ |
48 |
glue(pl110_draw_line1_lblp_bgr,BITS), |
49 |
glue(pl110_draw_line2_lblp_bgr,BITS), |
50 |
glue(pl110_draw_line4_lblp_bgr,BITS), |
51 |
glue(pl110_draw_line8_lblp_bgr,BITS), |
52 |
glue(pl110_draw_line16_lblp_bgr,BITS), |
53 |
glue(pl110_draw_line32_lblp_bgr,BITS), |
54 |
|
55 |
glue(pl110_draw_line1_bbbp_bgr,BITS), |
56 |
glue(pl110_draw_line2_bbbp_bgr,BITS), |
57 |
glue(pl110_draw_line4_bbbp_bgr,BITS), |
58 |
glue(pl110_draw_line8_bbbp_bgr,BITS), |
59 |
glue(pl110_draw_line16_bbbp_bgr,BITS), |
60 |
glue(pl110_draw_line32_bbbp_bgr,BITS), |
61 |
|
62 |
glue(pl110_draw_line1_lbbp_bgr,BITS), |
63 |
glue(pl110_draw_line2_lbbp_bgr,BITS), |
64 |
glue(pl110_draw_line4_lbbp_bgr,BITS), |
65 |
glue(pl110_draw_line8_lbbp_bgr,BITS), |
66 |
glue(pl110_draw_line16_lbbp_bgr,BITS), |
67 |
glue(pl110_draw_line32_lbbp_bgr,BITS), |
68 |
|
69 |
glue(pl110_draw_line1_lblp_rgb,BITS), |
70 |
glue(pl110_draw_line2_lblp_rgb,BITS), |
71 |
glue(pl110_draw_line4_lblp_rgb,BITS), |
72 |
glue(pl110_draw_line8_lblp_rgb,BITS), |
73 |
glue(pl110_draw_line16_lblp_rgb,BITS), |
74 |
glue(pl110_draw_line32_lblp_rgb,BITS), |
75 |
|
76 |
glue(pl110_draw_line1_bbbp_rgb,BITS), |
77 |
glue(pl110_draw_line2_bbbp_rgb,BITS), |
78 |
glue(pl110_draw_line4_bbbp_rgb,BITS), |
79 |
glue(pl110_draw_line8_bbbp_rgb,BITS), |
80 |
glue(pl110_draw_line16_bbbp_rgb,BITS), |
81 |
glue(pl110_draw_line32_bbbp_rgb,BITS), |
82 |
|
83 |
glue(pl110_draw_line1_lbbp_rgb,BITS), |
84 |
glue(pl110_draw_line2_lbbp_rgb,BITS), |
85 |
glue(pl110_draw_line4_lbbp_rgb,BITS), |
86 |
glue(pl110_draw_line8_lbbp_rgb,BITS), |
87 |
glue(pl110_draw_line16_lbbp_rgb,BITS), |
88 |
glue(pl110_draw_line32_lbbp_rgb,BITS), |
89 |
}; |
90 |
|
91 |
#undef BITS
|
92 |
#undef COPY_PIXEL
|
93 |
|
94 |
#else
|
95 |
|
96 |
#if ORDER == 0 |
97 |
#define NAME glue(glue(lblp_, BORDER), BITS)
|
98 |
#ifdef HOST_WORDS_BIGENDIAN
|
99 |
#define SWAP_WORDS 1 |
100 |
#endif
|
101 |
#elif ORDER == 1 |
102 |
#define NAME glue(glue(bbbp_, BORDER), BITS)
|
103 |
#ifndef HOST_WORDS_BIGENDIAN
|
104 |
#define SWAP_WORDS 1 |
105 |
#endif
|
106 |
#else
|
107 |
#define SWAP_PIXELS 1 |
108 |
#define NAME glue(glue(lbbp_, BORDER), BITS)
|
109 |
#ifdef HOST_WORDS_BIGENDIAN
|
110 |
#define SWAP_WORDS 1 |
111 |
#endif
|
112 |
#endif
|
113 |
|
114 |
#define FN_2(x, y) FN(x, y) FN(x+1, y) |
115 |
#define FN_4(x, y) FN_2(x, y) FN_2(x+2, y) |
116 |
#define FN_8(y) FN_4(0, y) FN_4(4, y) |
117 |
|
118 |
static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
119 |
{ |
120 |
uint32_t *pallette = opaque; |
121 |
uint32_t data; |
122 |
while (width > 0) { |
123 |
data = *(uint32_t *)src; |
124 |
#ifdef SWAP_PIXELS
|
125 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]); |
126 |
#else
|
127 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]); |
128 |
#endif
|
129 |
#ifdef SWAP_WORDS
|
130 |
FN_8(24)
|
131 |
FN_8(16)
|
132 |
FN_8(8)
|
133 |
FN_8(0)
|
134 |
#else
|
135 |
FN_8(0)
|
136 |
FN_8(8)
|
137 |
FN_8(16)
|
138 |
FN_8(24)
|
139 |
#endif
|
140 |
#undef FN
|
141 |
width -= 32;
|
142 |
src += 4;
|
143 |
} |
144 |
} |
145 |
|
146 |
static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
147 |
{ |
148 |
uint32_t *pallette = opaque; |
149 |
uint32_t data; |
150 |
while (width > 0) { |
151 |
data = *(uint32_t *)src; |
152 |
#ifdef SWAP_PIXELS
|
153 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]); |
154 |
#else
|
155 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]); |
156 |
#endif
|
157 |
#ifdef SWAP_WORDS
|
158 |
FN_4(0, 24) |
159 |
FN_4(0, 16) |
160 |
FN_4(0, 8) |
161 |
FN_4(0, 0) |
162 |
#else
|
163 |
FN_4(0, 0) |
164 |
FN_4(0, 8) |
165 |
FN_4(0, 16) |
166 |
FN_4(0, 24) |
167 |
#endif
|
168 |
#undef FN
|
169 |
width -= 16;
|
170 |
src += 4;
|
171 |
} |
172 |
} |
173 |
|
174 |
static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
175 |
{ |
176 |
uint32_t *pallette = opaque; |
177 |
uint32_t data; |
178 |
while (width > 0) { |
179 |
data = *(uint32_t *)src; |
180 |
#ifdef SWAP_PIXELS
|
181 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]); |
182 |
#else
|
183 |
#define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]); |
184 |
#endif
|
185 |
#ifdef SWAP_WORDS
|
186 |
FN_2(0, 24) |
187 |
FN_2(0, 16) |
188 |
FN_2(0, 8) |
189 |
FN_2(0, 0) |
190 |
#else
|
191 |
FN_2(0, 0) |
192 |
FN_2(0, 8) |
193 |
FN_2(0, 16) |
194 |
FN_2(0, 24) |
195 |
#endif
|
196 |
#undef FN
|
197 |
width -= 8;
|
198 |
src += 4;
|
199 |
} |
200 |
} |
201 |
|
202 |
static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
203 |
{ |
204 |
uint32_t *pallette = opaque; |
205 |
uint32_t data; |
206 |
while (width > 0) { |
207 |
data = *(uint32_t *)src; |
208 |
#define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]); |
209 |
#ifdef SWAP_WORDS
|
210 |
FN(24)
|
211 |
FN(16)
|
212 |
FN(8)
|
213 |
FN(0)
|
214 |
#else
|
215 |
FN(0)
|
216 |
FN(8)
|
217 |
FN(16)
|
218 |
FN(24)
|
219 |
#endif
|
220 |
#undef FN
|
221 |
width -= 4;
|
222 |
src += 4;
|
223 |
} |
224 |
} |
225 |
|
226 |
static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
227 |
{ |
228 |
uint32_t data; |
229 |
unsigned int r, g, b; |
230 |
while (width > 0) { |
231 |
data = *(uint32_t *)src; |
232 |
#ifdef SWAP_WORDS
|
233 |
data = bswap32(data); |
234 |
#endif
|
235 |
#ifdef RGB
|
236 |
#define LSB r
|
237 |
#define MSB b
|
238 |
#else
|
239 |
#define LSB b
|
240 |
#define MSB r
|
241 |
#endif
|
242 |
#if 0
|
243 |
LSB = data & 0x1f;
|
244 |
data >>= 5;
|
245 |
g = data & 0x3f;
|
246 |
data >>= 6;
|
247 |
MSB = data & 0x1f;
|
248 |
data >>= 5;
|
249 |
#else
|
250 |
LSB = (data & 0x1f) << 3; |
251 |
data >>= 5;
|
252 |
g = (data & 0x3f) << 2; |
253 |
data >>= 6;
|
254 |
MSB = (data & 0x1f) << 3; |
255 |
data >>= 5;
|
256 |
#endif
|
257 |
COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
258 |
LSB = (data & 0x1f) << 3; |
259 |
data >>= 5;
|
260 |
g = (data & 0x3f) << 2; |
261 |
data >>= 6;
|
262 |
MSB = (data & 0x1f) << 3; |
263 |
data >>= 5;
|
264 |
COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
265 |
#undef MSB
|
266 |
#undef LSB
|
267 |
width -= 2;
|
268 |
src += 4;
|
269 |
} |
270 |
} |
271 |
|
272 |
static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
273 |
{ |
274 |
uint32_t data; |
275 |
unsigned int r, g, b; |
276 |
while (width > 0) { |
277 |
data = *(uint32_t *)src; |
278 |
#ifdef RGB
|
279 |
#define LSB r
|
280 |
#define MSB b
|
281 |
#else
|
282 |
#define LSB b
|
283 |
#define MSB r
|
284 |
#endif
|
285 |
#ifndef SWAP_WORDS
|
286 |
LSB = data & 0xff;
|
287 |
g = (data >> 8) & 0xff; |
288 |
MSB = (data >> 16) & 0xff; |
289 |
#else
|
290 |
LSB = (data >> 24) & 0xff; |
291 |
g = (data >> 16) & 0xff; |
292 |
MSB = (data >> 8) & 0xff; |
293 |
#endif
|
294 |
COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
295 |
#undef MSB
|
296 |
#undef LSB
|
297 |
width--; |
298 |
src += 4;
|
299 |
} |
300 |
} |
301 |
|
302 |
#undef SWAP_PIXELS
|
303 |
#undef NAME
|
304 |
#undef SWAP_WORDS
|
305 |
#undef ORDER
|
306 |
|
307 |
#endif
|