root / hw / pl110_template.h @ 50d3eeae
History | View | Annotate | Download (5.5 kB)
1 | bdd5003a | pbrook | /*
|
---|---|---|---|
2 | bdd5003a | pbrook | * Arm PrimeCell PL110 Color LCD Controller
|
3 | bdd5003a | pbrook | *
|
4 | bdd5003a | pbrook | * Copyright (c) 2005 CodeSourcery, LLC.
|
5 | bdd5003a | pbrook | * Written by Paul Brook
|
6 | bdd5003a | pbrook | *
|
7 | bdd5003a | pbrook | * This code is licenced under the GNU LGPL
|
8 | bdd5003a | pbrook | *
|
9 | bdd5003a | pbrook | * Framebuffer format conversion routines.
|
10 | bdd5003a | pbrook | */
|
11 | bdd5003a | pbrook | |
12 | bdd5003a | pbrook | #ifndef ORDER
|
13 | bdd5003a | pbrook | |
14 | bdd5003a | pbrook | #if BITS == 8 |
15 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(to++) = from
|
16 | bdd5003a | pbrook | #elif BITS == 15 || BITS == 16 |
17 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2; |
18 | bdd5003a | pbrook | #elif BITS == 24 |
19 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) \
|
20 | bdd5003a | pbrook | *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16 |
21 | bdd5003a | pbrook | #elif BITS == 32 |
22 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4; |
23 | bdd5003a | pbrook | #else
|
24 | bdd5003a | pbrook | #error unknown bit depth
|
25 | bdd5003a | pbrook | #endif
|
26 | bdd5003a | pbrook | |
27 | bdd5003a | pbrook | #define ORDER 0 |
28 | bdd5003a | pbrook | #include "pl110_template.h" |
29 | bdd5003a | pbrook | #define ORDER 1 |
30 | bdd5003a | pbrook | #include "pl110_template.h" |
31 | bdd5003a | pbrook | #define ORDER 2 |
32 | bdd5003a | pbrook | #include "pl110_template.h" |
33 | bdd5003a | pbrook | |
34 | bdd5003a | pbrook | static drawfn glue(pl110_draw_fn_,BITS)[18] = |
35 | bdd5003a | pbrook | { |
36 | bdd5003a | pbrook | glue(pl110_draw_line1_lblp,BITS), |
37 | bdd5003a | pbrook | glue(pl110_draw_line2_lblp,BITS), |
38 | bdd5003a | pbrook | glue(pl110_draw_line4_lblp,BITS), |
39 | bdd5003a | pbrook | glue(pl110_draw_line8_lblp,BITS), |
40 | bdd5003a | pbrook | glue(pl110_draw_line16_lblp,BITS), |
41 | bdd5003a | pbrook | glue(pl110_draw_line32_lblp,BITS), |
42 | bdd5003a | pbrook | |
43 | bdd5003a | pbrook | glue(pl110_draw_line1_bbbp,BITS), |
44 | bdd5003a | pbrook | glue(pl110_draw_line2_bbbp,BITS), |
45 | bdd5003a | pbrook | glue(pl110_draw_line4_bbbp,BITS), |
46 | bdd5003a | pbrook | glue(pl110_draw_line8_bbbp,BITS), |
47 | bdd5003a | pbrook | glue(pl110_draw_line16_bbbp,BITS), |
48 | bdd5003a | pbrook | glue(pl110_draw_line32_bbbp,BITS), |
49 | bdd5003a | pbrook | |
50 | bdd5003a | pbrook | glue(pl110_draw_line1_lbbp,BITS), |
51 | bdd5003a | pbrook | glue(pl110_draw_line2_lbbp,BITS), |
52 | bdd5003a | pbrook | glue(pl110_draw_line4_lbbp,BITS), |
53 | bdd5003a | pbrook | glue(pl110_draw_line8_lbbp,BITS), |
54 | bdd5003a | pbrook | glue(pl110_draw_line16_lbbp,BITS), |
55 | bdd5003a | pbrook | glue(pl110_draw_line32_lbbp,BITS) |
56 | bdd5003a | pbrook | }; |
57 | bdd5003a | pbrook | |
58 | bdd5003a | pbrook | #undef BITS
|
59 | bdd5003a | pbrook | #undef COPY_PIXEL
|
60 | bdd5003a | pbrook | |
61 | bdd5003a | pbrook | #else
|
62 | bdd5003a | pbrook | |
63 | bdd5003a | pbrook | #if ORDER == 0 |
64 | bdd5003a | pbrook | #define NAME glue(lblp, BITS)
|
65 | bdd5003a | pbrook | #ifdef WORDS_BIGENDIAN
|
66 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
67 | bdd5003a | pbrook | #endif
|
68 | bdd5003a | pbrook | #elif ORDER == 1 |
69 | bdd5003a | pbrook | #define NAME glue(bbbp, BITS)
|
70 | bdd5003a | pbrook | #ifndef WORDS_BIGENDIAN
|
71 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
72 | bdd5003a | pbrook | #endif
|
73 | bdd5003a | pbrook | #else
|
74 | bdd5003a | pbrook | #define SWAP_PIXELS 1 |
75 | bdd5003a | pbrook | #define NAME glue(lbbp, BITS)
|
76 | bdd5003a | pbrook | #ifdef WORDS_BIGENDIAN
|
77 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
78 | bdd5003a | pbrook | #endif
|
79 | bdd5003a | pbrook | #endif
|
80 | bdd5003a | pbrook | |
81 | bdd5003a | pbrook | #define FN_2(x, y) FN(x, y) FN(x+1, y) |
82 | 1f9519c9 | pbrook | #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y) |
83 | bdd5003a | pbrook | #define FN_8(y) FN_4(0, y) FN_4(4, y) |
84 | bdd5003a | pbrook | |
85 | bdd5003a | pbrook | static void glue(pl110_draw_line1_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
86 | bdd5003a | pbrook | { |
87 | bdd5003a | pbrook | uint32_t data; |
88 | bdd5003a | pbrook | while (width > 0) { |
89 | bdd5003a | pbrook | data = *(uint32_t *)src; |
90 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
91 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]); |
92 | bdd5003a | pbrook | #else
|
93 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]); |
94 | bdd5003a | pbrook | #endif
|
95 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
96 | bdd5003a | pbrook | FN_8(24)
|
97 | bdd5003a | pbrook | FN_8(16)
|
98 | bdd5003a | pbrook | FN_8(8)
|
99 | bdd5003a | pbrook | FN_8(0)
|
100 | bdd5003a | pbrook | #else
|
101 | bdd5003a | pbrook | FN_8(0)
|
102 | bdd5003a | pbrook | FN_8(8)
|
103 | bdd5003a | pbrook | FN_8(16)
|
104 | bdd5003a | pbrook | FN_8(24)
|
105 | bdd5003a | pbrook | #endif
|
106 | bdd5003a | pbrook | #undef FN
|
107 | bdd5003a | pbrook | width -= 32;
|
108 | bdd5003a | pbrook | src += 4;
|
109 | bdd5003a | pbrook | } |
110 | bdd5003a | pbrook | } |
111 | bdd5003a | pbrook | |
112 | bdd5003a | pbrook | static void glue(pl110_draw_line2_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
113 | bdd5003a | pbrook | { |
114 | bdd5003a | pbrook | uint32_t data; |
115 | bdd5003a | pbrook | while (width > 0) { |
116 | bdd5003a | pbrook | data = *(uint32_t *)src; |
117 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
118 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]); |
119 | bdd5003a | pbrook | #else
|
120 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]); |
121 | bdd5003a | pbrook | #endif
|
122 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
123 | bdd5003a | pbrook | FN_4(0, 24) |
124 | bdd5003a | pbrook | FN_4(0, 16) |
125 | bdd5003a | pbrook | FN_4(0, 8) |
126 | bdd5003a | pbrook | FN_4(0, 0) |
127 | bdd5003a | pbrook | #else
|
128 | bdd5003a | pbrook | FN_4(0, 0) |
129 | bdd5003a | pbrook | FN_4(0, 8) |
130 | bdd5003a | pbrook | FN_4(0, 16) |
131 | bdd5003a | pbrook | FN_4(0, 24) |
132 | bdd5003a | pbrook | #endif
|
133 | bdd5003a | pbrook | #undef FN
|
134 | bdd5003a | pbrook | width -= 16;
|
135 | bdd5003a | pbrook | src += 4;
|
136 | bdd5003a | pbrook | } |
137 | bdd5003a | pbrook | } |
138 | bdd5003a | pbrook | |
139 | bdd5003a | pbrook | static void glue(pl110_draw_line4_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
140 | bdd5003a | pbrook | { |
141 | bdd5003a | pbrook | uint32_t data; |
142 | bdd5003a | pbrook | while (width > 0) { |
143 | bdd5003a | pbrook | data = *(uint32_t *)src; |
144 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
145 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]); |
146 | bdd5003a | pbrook | #else
|
147 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]); |
148 | bdd5003a | pbrook | #endif
|
149 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
150 | bdd5003a | pbrook | FN_2(0, 24) |
151 | bdd5003a | pbrook | FN_2(0, 16) |
152 | bdd5003a | pbrook | FN_2(0, 8) |
153 | bdd5003a | pbrook | FN_2(0, 0) |
154 | bdd5003a | pbrook | #else
|
155 | bdd5003a | pbrook | FN_2(0, 0) |
156 | bdd5003a | pbrook | FN_2(0, 8) |
157 | bdd5003a | pbrook | FN_2(0, 16) |
158 | bdd5003a | pbrook | FN_2(0, 24) |
159 | bdd5003a | pbrook | #endif
|
160 | bdd5003a | pbrook | #undef FN
|
161 | bdd5003a | pbrook | width -= 8;
|
162 | bdd5003a | pbrook | src += 4;
|
163 | bdd5003a | pbrook | } |
164 | bdd5003a | pbrook | } |
165 | bdd5003a | pbrook | |
166 | bdd5003a | pbrook | static void glue(pl110_draw_line8_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
167 | bdd5003a | pbrook | { |
168 | bdd5003a | pbrook | uint32_t data; |
169 | bdd5003a | pbrook | while (width > 0) { |
170 | bdd5003a | pbrook | data = *(uint32_t *)src; |
171 | bdd5003a | pbrook | #define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]); |
172 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
173 | bdd5003a | pbrook | FN(24)
|
174 | bdd5003a | pbrook | FN(16)
|
175 | bdd5003a | pbrook | FN(8)
|
176 | bdd5003a | pbrook | FN(0)
|
177 | bdd5003a | pbrook | #else
|
178 | bdd5003a | pbrook | FN(0)
|
179 | bdd5003a | pbrook | FN(8)
|
180 | bdd5003a | pbrook | FN(16)
|
181 | bdd5003a | pbrook | FN(24)
|
182 | bdd5003a | pbrook | #endif
|
183 | bdd5003a | pbrook | #undef FN
|
184 | bdd5003a | pbrook | width -= 4;
|
185 | bdd5003a | pbrook | src += 4;
|
186 | bdd5003a | pbrook | } |
187 | bdd5003a | pbrook | } |
188 | bdd5003a | pbrook | |
189 | bdd5003a | pbrook | static void glue(pl110_draw_line16_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
190 | bdd5003a | pbrook | { |
191 | bdd5003a | pbrook | uint32_t data; |
192 | bdd5003a | pbrook | unsigned int r, g, b; |
193 | bdd5003a | pbrook | while (width > 0) { |
194 | bdd5003a | pbrook | data = *(uint32_t *)src; |
195 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
196 | bdd5003a | pbrook | data = bswap32(data); |
197 | bdd5003a | pbrook | #endif
|
198 | bdd5003a | pbrook | #if 0
|
199 | bdd5003a | pbrook | r = data & 0x1f;
|
200 | bdd5003a | pbrook | data >>= 5;
|
201 | bdd5003a | pbrook | g = data & 0x3f;
|
202 | bdd5003a | pbrook | data >>= 6;
|
203 | bdd5003a | pbrook | b = data & 0x1f;
|
204 | bdd5003a | pbrook | data >>= 5;
|
205 | bdd5003a | pbrook | #else
|
206 | bdd5003a | pbrook | r = (data & 0x1f) << 3; |
207 | bdd5003a | pbrook | data >>= 5;
|
208 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
209 | bdd5003a | pbrook | data >>= 6;
|
210 | bdd5003a | pbrook | b = (data & 0x1f) << 3; |
211 | bdd5003a | pbrook | data >>= 5;
|
212 | bdd5003a | pbrook | #endif
|
213 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
214 | bdd5003a | pbrook | r = (data & 0x1f) << 3; |
215 | bdd5003a | pbrook | data >>= 5;
|
216 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
217 | bdd5003a | pbrook | data >>= 6;
|
218 | bdd5003a | pbrook | b = (data & 0x1f) << 3; |
219 | bdd5003a | pbrook | data >>= 5;
|
220 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
221 | bdd5003a | pbrook | width -= 2;
|
222 | bdd5003a | pbrook | src += 4;
|
223 | bdd5003a | pbrook | } |
224 | bdd5003a | pbrook | } |
225 | bdd5003a | pbrook | |
226 | bdd5003a | pbrook | static void glue(pl110_draw_line32_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
227 | bdd5003a | pbrook | { |
228 | bdd5003a | pbrook | uint32_t data; |
229 | bdd5003a | pbrook | unsigned int r, g, b; |
230 | bdd5003a | pbrook | while (width > 0) { |
231 | bdd5003a | pbrook | data = *(uint32_t *)src; |
232 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
233 | bdd5003a | pbrook | r = data & 0xff;
|
234 | bdd5003a | pbrook | g = (data >> 8) & 0xff; |
235 | bdd5003a | pbrook | b = (data >> 16) & 0xff; |
236 | bdd5003a | pbrook | #else
|
237 | bdd5003a | pbrook | r = (data >> 24) & 0xff; |
238 | bdd5003a | pbrook | g = (data >> 16) & 0xff; |
239 | bdd5003a | pbrook | b = (data >> 8) & 0xff; |
240 | bdd5003a | pbrook | #endif
|
241 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
242 | bdd5003a | pbrook | width--; |
243 | bdd5003a | pbrook | src += 4;
|
244 | bdd5003a | pbrook | } |
245 | bdd5003a | pbrook | } |
246 | bdd5003a | pbrook | |
247 | bdd5003a | pbrook | #undef SWAP_PIXELS
|
248 | bdd5003a | pbrook | #undef NAME
|
249 | bdd5003a | pbrook | #undef SWAP_WORDS
|
250 | bdd5003a | pbrook | #undef ORDER
|
251 | bdd5003a | pbrook | |
252 | bdd5003a | pbrook | #endif |