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
)(void *opaque
,
34 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
36 uint32_t *palette
= opaque
;
39 data
= *(uint32_t *) src
;
40 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
58 static void glue(pxa2xx_draw_line4_
, BITS
)(void *opaque
,
59 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
61 uint32_t *palette
= opaque
;
64 data
= *(uint32_t *) src
;
65 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
83 static void glue(pxa2xx_draw_line8_
, BITS
)(void *opaque
,
84 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
86 uint32_t *palette
= opaque
;
89 data
= *(uint32_t *) src
;
90 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
108 static void glue(pxa2xx_draw_line16_
, BITS
)(void *opaque
,
109 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
112 unsigned int r
, g
, b
;
114 data
= *(uint32_t *) src
;
116 data
= bswap32(data
);
118 b
= (data
& 0x1f) << 3;
120 g
= (data
& 0x3f) << 2;
122 r
= (data
& 0x1f) << 3;
124 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
125 b
= (data
& 0x1f) << 3;
127 g
= (data
& 0x3f) << 2;
129 r
= (data
& 0x1f) << 3;
130 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
136 static void glue(pxa2xx_draw_line16t_
, BITS
)(void *opaque
,
137 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
140 unsigned int r
, g
, b
;
142 data
= *(uint32_t *) src
;
144 data
= bswap32(data
);
146 b
= (data
& 0x1f) << 3;
148 g
= (data
& 0x1f) << 3;
150 r
= (data
& 0x1f) << 3;
155 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
157 b
= (data
& 0x1f) << 3;
159 g
= (data
& 0x1f) << 3;
161 r
= (data
& 0x1f) << 3;
166 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
172 static void glue(pxa2xx_draw_line18_
, BITS
)(void *opaque
,
173 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
176 unsigned int r
, g
, b
;
178 data
= *(uint32_t *) src
;
180 data
= bswap32(data
);
182 b
= (data
& 0x3f) << 2;
184 g
= (data
& 0x3f) << 2;
186 r
= (data
& 0x3f) << 2;
187 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
193 /* The wicked packed format */
194 static void glue(pxa2xx_draw_line18p_
, BITS
)(void *opaque
,
195 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
198 unsigned int r
, g
, b
;
200 data
[0] = *(uint32_t *) src
;
202 data
[1] = *(uint32_t *) src
;
204 data
[2] = *(uint32_t *) src
;
207 data
[0] = bswap32(data
[0]);
208 data
[1] = bswap32(data
[1]);
209 data
[2] = bswap32(data
[2]);
211 b
= (data
[0] & 0x3f) << 2;
213 g
= (data
[0] & 0x3f) << 2;
215 r
= (data
[0] & 0x3f) << 2;
217 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
218 b
= (data
[0] & 0x3f) << 2;
220 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
222 r
= (data
[1] & 0x3f) << 2;
224 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
225 b
= (data
[1] & 0x3f) << 2;
227 g
= (data
[1] & 0x3f) << 2;
229 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
231 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
232 b
= (data
[2] & 0x3f) << 2;
234 g
= (data
[2] & 0x3f) << 2;
237 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
242 static void glue(pxa2xx_draw_line19_
, BITS
)(void *opaque
,
243 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
246 unsigned int r
, g
, b
;
248 data
= *(uint32_t *) src
;
250 data
= bswap32(data
);
252 b
= (data
& 0x3f) << 2;
254 g
= (data
& 0x3f) << 2;
256 r
= (data
& 0x3f) << 2;
261 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
267 /* The wicked packed format */
268 static void glue(pxa2xx_draw_line19p_
, BITS
)(void *opaque
,
269 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
272 unsigned int r
, g
, b
;
274 data
[0] = *(uint32_t *) src
;
276 data
[1] = *(uint32_t *) src
;
278 data
[2] = *(uint32_t *) src
;
281 data
[0] = bswap32(data
[0]);
282 data
[1] = bswap32(data
[1]);
283 data
[2] = bswap32(data
[2]);
285 b
= (data
[0] & 0x3f) << 2;
287 g
= (data
[0] & 0x3f) << 2;
289 r
= (data
[0] & 0x3f) << 2;
294 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
296 b
= (data
[0] & 0x3f) << 2;
298 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
300 r
= (data
[1] & 0x3f) << 2;
305 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
307 b
= (data
[1] & 0x3f) << 2;
309 g
= (data
[1] & 0x3f) << 2;
311 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
316 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
318 b
= (data
[2] & 0x3f) << 2;
320 g
= (data
[2] & 0x3f) << 2;
327 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
332 static void glue(pxa2xx_draw_line24_
, BITS
)(void *opaque
,
333 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
336 unsigned int r
, g
, b
;
338 data
= *(uint32_t *) src
;
340 data
= bswap32(data
);
347 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
353 static void glue(pxa2xx_draw_line24t_
, BITS
)(void *opaque
,
354 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
357 unsigned int r
, g
, b
;
359 data
= *(uint32_t *) src
;
361 data
= bswap32(data
);
363 b
= (data
& 0x7f) << 1;
372 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
378 static void glue(pxa2xx_draw_line25_
, BITS
)(void *opaque
,
379 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
382 unsigned int r
, g
, b
;
384 data
= *(uint32_t *) src
;
386 data
= bswap32(data
);
397 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
403 /* Overlay planes disabled, no transparency */
404 static drawfn
glue(pxa2xx_draw_fn_
, BITS
)[16] =
407 [pxa_lcdc_2bpp
] = glue(pxa2xx_draw_line2_
, BITS
),
408 [pxa_lcdc_4bpp
] = glue(pxa2xx_draw_line4_
, BITS
),
409 [pxa_lcdc_8bpp
] = glue(pxa2xx_draw_line8_
, BITS
),
410 [pxa_lcdc_16bpp
] = glue(pxa2xx_draw_line16_
, BITS
),
411 [pxa_lcdc_18bpp
] = glue(pxa2xx_draw_line18_
, BITS
),
412 [pxa_lcdc_18pbpp
] = glue(pxa2xx_draw_line18p_
, BITS
),
413 [pxa_lcdc_24bpp
] = glue(pxa2xx_draw_line24_
, BITS
),
416 /* Overlay planes enabled, transparency used */
417 static drawfn
glue(glue(pxa2xx_draw_fn_
, BITS
), t
)[16] =
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_line16t_
, BITS
),
423 [pxa_lcdc_19bpp
] = glue(pxa2xx_draw_line19_
, BITS
),
424 [pxa_lcdc_19pbpp
] = glue(pxa2xx_draw_line19p_
, BITS
),
425 [pxa_lcdc_24bpp
] = glue(pxa2xx_draw_line24t_
, BITS
),
426 [pxa_lcdc_25bpp
] = glue(pxa2xx_draw_line25_
, BITS
),