2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Written by Andrzej Zaborowski <balrog@zabor.org>
7 * This code is licensed under the GPLv2.
9 * Framebuffer format conversion routines.
12 # define SKIP_PIXEL(to) to += deststep
14 # define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
15 #elif BITS == 15 || BITS == 16
16 # define COPY_PIXEL(to, from) *(uint16_t *) to = from; SKIP_PIXEL(to)
18 # define COPY_PIXEL(to, from) \
19 *(uint16_t *) to = from; *(to + 2) = (from) >> 16; SKIP_PIXEL(to)
21 # define COPY_PIXEL(to, from) *(uint32_t *) to = from; SKIP_PIXEL(to)
23 # error unknown bit depth
26 #ifdef WORDS_BIGENDIAN
30 #define FN_2(x) FN(x + 1) FN(x)
31 #define FN_4(x) FN_2(x + 2) FN_2(x)
33 static void glue(pxa2xx_draw_line2_, BITS)(uint32_t *palette,
34 uint8_t *dest, const uint8_t *src, int width, int deststep)
38 data = *(uint32_t *) src;
39 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
57 static void glue(pxa2xx_draw_line4_, BITS)(uint32_t *palette,
58 uint8_t *dest, const uint8_t *src, int width, int deststep)
62 data = *(uint32_t *) src;
63 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
81 static void glue(pxa2xx_draw_line8_, BITS)(uint32_t *palette,
82 uint8_t *dest, const uint8_t *src, int width, int deststep)
86 data = *(uint32_t *) src;
87 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
105 static void glue(pxa2xx_draw_line16_, BITS)(uint32_t *palette,
106 uint8_t *dest, const uint8_t *src, int width, int deststep)
109 unsigned int r, g, b;
111 data = *(uint32_t *) src;
113 data = bswap32(data);
115 b = (data & 0x1f) << 3;
117 g = (data & 0x3f) << 2;
119 r = (data & 0x1f) << 3;
121 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
122 b = (data & 0x1f) << 3;
124 g = (data & 0x3f) << 2;
126 r = (data & 0x1f) << 3;
127 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
133 static void glue(pxa2xx_draw_line16t_, BITS)(uint32_t *palette,
134 uint8_t *dest, const uint8_t *src, int width, int deststep)
137 unsigned int r, g, b;
139 data = *(uint32_t *) src;
141 data = bswap32(data);
143 b = (data & 0x1f) << 3;
145 g = (data & 0x1f) << 3;
147 r = (data & 0x1f) << 3;
152 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
154 b = (data & 0x1f) << 3;
156 g = (data & 0x1f) << 3;
158 r = (data & 0x1f) << 3;
163 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
169 static void glue(pxa2xx_draw_line18_, BITS)(uint32_t *palette,
170 uint8_t *dest, const uint8_t *src, int width, int deststep)
173 unsigned int r, g, b;
175 data = *(uint32_t *) src;
177 data = bswap32(data);
179 b = (data & 0x3f) << 2;
181 g = (data & 0x3f) << 2;
183 r = (data & 0x3f) << 2;
184 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
190 /* The wicked packed format */
191 static void glue(pxa2xx_draw_line18p_, BITS)(uint32_t *palette,
192 uint8_t *dest, const uint8_t *src, int width, int deststep)
195 unsigned int r, g, b;
197 data[0] = *(uint32_t *) src;
199 data[1] = *(uint32_t *) src;
201 data[2] = *(uint32_t *) src;
204 data[0] = bswap32(data[0]);
205 data[1] = bswap32(data[1]);
206 data[2] = bswap32(data[2]);
208 b = (data[0] & 0x3f) << 2;
210 g = (data[0] & 0x3f) << 2;
212 r = (data[0] & 0x3f) << 2;
214 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
215 b = (data[0] & 0x3f) << 2;
217 g = ((data[1] & 0xf) << 4) | (data[0] << 2);
219 r = (data[1] & 0x3f) << 2;
221 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
222 b = (data[1] & 0x3f) << 2;
224 g = (data[1] & 0x3f) << 2;
226 r = ((data[2] & 0x3) << 6) | (data[1] << 2);
228 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
229 b = (data[2] & 0x3f) << 2;
231 g = (data[2] & 0x3f) << 2;
234 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
239 static void glue(pxa2xx_draw_line19_, BITS)(uint32_t *palette,
240 uint8_t *dest, const uint8_t *src, int width, int deststep)
243 unsigned int r, g, b;
245 data = *(uint32_t *) src;
247 data = bswap32(data);
249 b = (data & 0x3f) << 2;
251 g = (data & 0x3f) << 2;
253 r = (data & 0x3f) << 2;
258 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
264 /* The wicked packed format */
265 static void glue(pxa2xx_draw_line19p_, BITS)(uint32_t *palette,
266 uint8_t *dest, const uint8_t *src, int width, int deststep)
269 unsigned int r, g, b;
271 data[0] = *(uint32_t *) src;
273 data[1] = *(uint32_t *) src;
275 data[2] = *(uint32_t *) src;
278 data[0] = bswap32(data[0]);
279 data[1] = bswap32(data[1]);
280 data[2] = bswap32(data[2]);
282 b = (data[0] & 0x3f) << 2;
284 g = (data[0] & 0x3f) << 2;
286 r = (data[0] & 0x3f) << 2;
291 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
293 b = (data[0] & 0x3f) << 2;
295 g = ((data[1] & 0xf) << 4) | (data[0] << 2);
297 r = (data[1] & 0x3f) << 2;
302 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
304 b = (data[1] & 0x3f) << 2;
306 g = (data[1] & 0x3f) << 2;
308 r = ((data[2] & 0x3) << 6) | (data[1] << 2);
313 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
315 b = (data[2] & 0x3f) << 2;
317 g = (data[2] & 0x3f) << 2;
324 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
329 static void glue(pxa2xx_draw_line24_, BITS)(uint32_t *palette,
330 uint8_t *dest, const uint8_t *src, int width, int deststep)
333 unsigned int r, g, b;
335 data = *(uint32_t *) src;
337 data = bswap32(data);
344 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
350 static void glue(pxa2xx_draw_line24t_, BITS)(uint32_t *palette,
351 uint8_t *dest, const uint8_t *src, int width, int deststep)
354 unsigned int r, g, b;
356 data = *(uint32_t *) src;
358 data = bswap32(data);
360 b = (data & 0x7f) << 1;
369 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
375 static void glue(pxa2xx_draw_line25_, BITS)(uint32_t *palette,
376 uint8_t *dest, const uint8_t *src, int width, int deststep)
379 unsigned int r, g, b;
381 data = *(uint32_t *) src;
383 data = bswap32(data);
394 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
400 /* Overlay planes disabled, no transparency */
401 static drawfn glue(pxa2xx_draw_fn_, BITS)[16] =
404 [pxa_lcdc_2bpp] = glue(pxa2xx_draw_line2_, BITS),
405 [pxa_lcdc_4bpp] = glue(pxa2xx_draw_line4_, BITS),
406 [pxa_lcdc_8bpp] = glue(pxa2xx_draw_line8_, BITS),
407 [pxa_lcdc_16bpp] = glue(pxa2xx_draw_line16_, BITS),
408 [pxa_lcdc_18bpp] = glue(pxa2xx_draw_line18_, BITS),
409 [pxa_lcdc_18pbpp] = glue(pxa2xx_draw_line18p_, BITS),
410 [pxa_lcdc_24bpp] = glue(pxa2xx_draw_line24_, BITS),
413 /* Overlay planes enabled, transparency used */
414 static drawfn glue(glue(pxa2xx_draw_fn_, BITS), t)[16] =
417 [pxa_lcdc_4bpp] = glue(pxa2xx_draw_line4_, BITS),
418 [pxa_lcdc_8bpp] = glue(pxa2xx_draw_line8_, BITS),
419 [pxa_lcdc_16bpp] = glue(pxa2xx_draw_line16t_, BITS),
420 [pxa_lcdc_19bpp] = glue(pxa2xx_draw_line19_, BITS),
421 [pxa_lcdc_19pbpp] = glue(pxa2xx_draw_line19p_, BITS),
422 [pxa_lcdc_24bpp] = glue(pxa2xx_draw_line24t_, BITS),
423 [pxa_lcdc_25bpp] = glue(pxa2xx_draw_line25_, BITS),