2 * Intel XScale PXA255/270 LCDC emulation.
4 * Copyright (c) 2006 Openedhand Ltd.
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) do { *to = from; SKIP_PIXEL(to); } while (0)
15 #elif BITS == 15 || BITS == 16
16 # define COPY_PIXEL(to, from) \
18 *(uint16_t *) to = from; \
22 # define COPY_PIXEL(to, from) \
24 *(uint16_t *) to = from; \
25 *(to + 2) = (from) >> 16; \
29 # define COPY_PIXEL(to, from) \
31 *(uint32_t *) to = from; \
35 # error unknown bit depth
38 #ifdef HOST_WORDS_BIGENDIAN
42 #define FN_2(x) FN(x + 1) FN(x)
43 #define FN_4(x) FN_2(x + 2) FN_2(x)
45 static void glue(pxa2xx_draw_line2_, BITS)(void *opaque,
46 uint8_t *dest, const uint8_t *src, int width, int deststep)
48 uint32_t *palette = opaque;
51 data = *(uint32_t *) src;
52 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
70 static void glue(pxa2xx_draw_line4_, BITS)(void *opaque,
71 uint8_t *dest, const uint8_t *src, int width, int deststep)
73 uint32_t *palette = opaque;
76 data = *(uint32_t *) src;
77 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
95 static void glue(pxa2xx_draw_line8_, BITS)(void *opaque,
96 uint8_t *dest, const uint8_t *src, int width, int deststep)
98 uint32_t *palette = opaque;
101 data = *(uint32_t *) src;
102 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
120 static void glue(pxa2xx_draw_line16_, BITS)(void *opaque,
121 uint8_t *dest, const uint8_t *src, int width, int deststep)
124 unsigned int r, g, b;
126 data = *(uint32_t *) src;
128 data = bswap32(data);
130 b = (data & 0x1f) << 3;
132 g = (data & 0x3f) << 2;
134 r = (data & 0x1f) << 3;
136 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
137 b = (data & 0x1f) << 3;
139 g = (data & 0x3f) << 2;
141 r = (data & 0x1f) << 3;
142 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
148 static void glue(pxa2xx_draw_line16t_, BITS)(void *opaque,
149 uint8_t *dest, const uint8_t *src, int width, int deststep)
152 unsigned int r, g, b;
154 data = *(uint32_t *) src;
156 data = bswap32(data);
158 b = (data & 0x1f) << 3;
160 g = (data & 0x1f) << 3;
162 r = (data & 0x1f) << 3;
167 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
169 b = (data & 0x1f) << 3;
171 g = (data & 0x1f) << 3;
173 r = (data & 0x1f) << 3;
178 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
184 static void glue(pxa2xx_draw_line18_, BITS)(void *opaque,
185 uint8_t *dest, const uint8_t *src, int width, int deststep)
188 unsigned int r, g, b;
190 data = *(uint32_t *) src;
192 data = bswap32(data);
194 b = (data & 0x3f) << 2;
196 g = (data & 0x3f) << 2;
198 r = (data & 0x3f) << 2;
199 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
205 /* The wicked packed format */
206 static void glue(pxa2xx_draw_line18p_, BITS)(void *opaque,
207 uint8_t *dest, const uint8_t *src, int width, int deststep)
210 unsigned int r, g, b;
212 data[0] = *(uint32_t *) src;
214 data[1] = *(uint32_t *) src;
216 data[2] = *(uint32_t *) src;
219 data[0] = bswap32(data[0]);
220 data[1] = bswap32(data[1]);
221 data[2] = bswap32(data[2]);
223 b = (data[0] & 0x3f) << 2;
225 g = (data[0] & 0x3f) << 2;
227 r = (data[0] & 0x3f) << 2;
229 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
230 b = (data[0] & 0x3f) << 2;
232 g = ((data[1] & 0xf) << 4) | (data[0] << 2);
234 r = (data[1] & 0x3f) << 2;
236 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
237 b = (data[1] & 0x3f) << 2;
239 g = (data[1] & 0x3f) << 2;
241 r = ((data[2] & 0x3) << 6) | (data[1] << 2);
243 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
244 b = (data[2] & 0x3f) << 2;
246 g = (data[2] & 0x3f) << 2;
249 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
254 static void glue(pxa2xx_draw_line19_, BITS)(void *opaque,
255 uint8_t *dest, const uint8_t *src, int width, int deststep)
258 unsigned int r, g, b;
260 data = *(uint32_t *) src;
262 data = bswap32(data);
264 b = (data & 0x3f) << 2;
266 g = (data & 0x3f) << 2;
268 r = (data & 0x3f) << 2;
273 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
279 /* The wicked packed format */
280 static void glue(pxa2xx_draw_line19p_, BITS)(void *opaque,
281 uint8_t *dest, const uint8_t *src, int width, int deststep)
284 unsigned int r, g, b;
286 data[0] = *(uint32_t *) src;
288 data[1] = *(uint32_t *) src;
290 data[2] = *(uint32_t *) src;
293 data[0] = bswap32(data[0]);
294 data[1] = bswap32(data[1]);
295 data[2] = bswap32(data[2]);
297 b = (data[0] & 0x3f) << 2;
299 g = (data[0] & 0x3f) << 2;
301 r = (data[0] & 0x3f) << 2;
306 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
308 b = (data[0] & 0x3f) << 2;
310 g = ((data[1] & 0xf) << 4) | (data[0] << 2);
312 r = (data[1] & 0x3f) << 2;
317 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
319 b = (data[1] & 0x3f) << 2;
321 g = (data[1] & 0x3f) << 2;
323 r = ((data[2] & 0x3) << 6) | (data[1] << 2);
328 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
330 b = (data[2] & 0x3f) << 2;
332 g = (data[2] & 0x3f) << 2;
339 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
344 static void glue(pxa2xx_draw_line24_, BITS)(void *opaque,
345 uint8_t *dest, const uint8_t *src, int width, int deststep)
348 unsigned int r, g, b;
350 data = *(uint32_t *) src;
352 data = bswap32(data);
359 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
365 static void glue(pxa2xx_draw_line24t_, BITS)(void *opaque,
366 uint8_t *dest, const uint8_t *src, int width, int deststep)
369 unsigned int r, g, b;
371 data = *(uint32_t *) src;
373 data = bswap32(data);
375 b = (data & 0x7f) << 1;
384 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
390 static void glue(pxa2xx_draw_line25_, BITS)(void *opaque,
391 uint8_t *dest, const uint8_t *src, int width, int deststep)
394 unsigned int r, g, b;
396 data = *(uint32_t *) src;
398 data = bswap32(data);
409 COPY_PIXEL(dest, glue(rgb_to_pixel, BITS)(r, g, b));
415 /* Overlay planes disabled, no transparency */
416 static drawfn glue(pxa2xx_draw_fn_, BITS)[16] =
419 [pxa_lcdc_2bpp] = glue(pxa2xx_draw_line2_, BITS),
420 [pxa_lcdc_4bpp] = glue(pxa2xx_draw_line4_, BITS),
421 [pxa_lcdc_8bpp] = glue(pxa2xx_draw_line8_, BITS),
422 [pxa_lcdc_16bpp] = glue(pxa2xx_draw_line16_, BITS),
423 [pxa_lcdc_18bpp] = glue(pxa2xx_draw_line18_, BITS),
424 [pxa_lcdc_18pbpp] = glue(pxa2xx_draw_line18p_, BITS),
425 [pxa_lcdc_24bpp] = glue(pxa2xx_draw_line24_, BITS),
428 /* Overlay planes enabled, transparency used */
429 static drawfn glue(glue(pxa2xx_draw_fn_, BITS), t)[16] =
432 [pxa_lcdc_4bpp] = glue(pxa2xx_draw_line4_, BITS),
433 [pxa_lcdc_8bpp] = glue(pxa2xx_draw_line8_, BITS),
434 [pxa_lcdc_16bpp] = glue(pxa2xx_draw_line16t_, BITS),
435 [pxa_lcdc_19bpp] = glue(pxa2xx_draw_line19_, BITS),
436 [pxa_lcdc_19pbpp] = glue(pxa2xx_draw_line19p_, BITS),
437 [pxa_lcdc_24bpp] = glue(pxa2xx_draw_line24t_, BITS),
438 [pxa_lcdc_25bpp] = glue(pxa2xx_draw_line25_, BITS),