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;
162 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
168 static void glue(pxa2xx_draw_line18_
, BITS
)(uint32_t *palette
,
169 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
172 unsigned int r
, g
, b
;
174 data
= *(uint32_t *) src
;
176 data
= bswap32(data
);
178 b
= (data
& 0x3f) << 2;
180 g
= (data
& 0x3f) << 2;
182 r
= (data
& 0x3f) << 2;
183 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
189 /* The wicked packed format */
190 static void glue(pxa2xx_draw_line18p_
, BITS
)(uint32_t *palette
,
191 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
194 unsigned int r
, g
, b
;
196 data
[0] = *(uint32_t *) src
;
198 data
[1] = *(uint32_t *) src
;
200 data
[2] = *(uint32_t *) src
;
203 data
[0] = bswap32(data
[0]);
204 data
[1] = bswap32(data
[1]);
205 data
[2] = bswap32(data
[2]);
207 b
= (data
[0] & 0x3f) << 2;
209 g
= (data
[0] & 0x3f) << 2;
211 r
= (data
[0] & 0x3f) << 2;
213 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
214 b
= (data
[0] & 0x3f) << 2;
216 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
218 r
= (data
[1] & 0x3f) << 2;
220 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
221 b
= (data
[1] & 0x3f) << 2;
223 g
= (data
[1] & 0x3f) << 2;
225 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
227 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
228 b
= (data
[2] & 0x3f) << 2;
230 g
= (data
[2] & 0x3f) << 2;
233 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
238 static void glue(pxa2xx_draw_line19_
, BITS
)(uint32_t *palette
,
239 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
242 unsigned int r
, g
, b
;
244 data
= *(uint32_t *) src
;
246 data
= bswap32(data
);
248 b
= (data
& 0x3f) << 2;
250 g
= (data
& 0x3f) << 2;
252 r
= (data
& 0x3f) << 2;
257 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
263 /* The wicked packed format */
264 static void glue(pxa2xx_draw_line19p_
, BITS
)(uint32_t *palette
,
265 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
268 unsigned int r
, g
, b
;
270 data
[0] = *(uint32_t *) src
;
272 data
[1] = *(uint32_t *) src
;
274 data
[2] = *(uint32_t *) src
;
277 data
[0] = bswap32(data
[0]);
278 data
[1] = bswap32(data
[1]);
279 data
[2] = bswap32(data
[2]);
281 b
= (data
[0] & 0x3f) << 2;
283 g
= (data
[0] & 0x3f) << 2;
285 r
= (data
[0] & 0x3f) << 2;
290 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
292 b
= (data
[0] & 0x3f) << 2;
294 g
= ((data
[1] & 0xf) << 4) | (data
[0] << 2);
296 r
= (data
[1] & 0x3f) << 2;
301 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
303 b
= (data
[1] & 0x3f) << 2;
305 g
= (data
[1] & 0x3f) << 2;
307 r
= ((data
[2] & 0x3) << 6) | (data
[1] << 2);
312 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
314 b
= (data
[2] & 0x3f) << 2;
316 g
= (data
[2] & 0x3f) << 2;
323 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
328 static void glue(pxa2xx_draw_line24_
, BITS
)(uint32_t *palette
,
329 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
332 unsigned int r
, g
, b
;
334 data
= *(uint32_t *) src
;
336 data
= bswap32(data
);
343 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
349 static void glue(pxa2xx_draw_line24t_
, BITS
)(uint32_t *palette
,
350 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
353 unsigned int r
, g
, b
;
355 data
= *(uint32_t *) src
;
357 data
= bswap32(data
);
359 b
= (data
& 0x7f) << 1;
368 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
374 static void glue(pxa2xx_draw_line25_
, BITS
)(uint32_t *palette
,
375 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
378 unsigned int r
, g
, b
;
380 data
= *(uint32_t *) src
;
382 data
= bswap32(data
);
393 COPY_PIXEL(dest
, glue(rgb_to_pixel
, BITS
)(r
, g
, b
));
399 /* Overlay planes disabled, no transparency */
400 static drawfn
glue(pxa2xx_draw_fn_
, BITS
)[16] =
403 [pxa_lcdc_2bpp
] = glue(pxa2xx_draw_line2_
, BITS
),
404 [pxa_lcdc_4bpp
] = glue(pxa2xx_draw_line4_
, BITS
),
405 [pxa_lcdc_8bpp
] = glue(pxa2xx_draw_line8_
, BITS
),
406 [pxa_lcdc_16bpp
] = glue(pxa2xx_draw_line16_
, BITS
),
407 [pxa_lcdc_18bpp
] = glue(pxa2xx_draw_line18_
, BITS
),
408 [pxa_lcdc_18pbpp
] = glue(pxa2xx_draw_line18p_
, BITS
),
409 [pxa_lcdc_24bpp
] = glue(pxa2xx_draw_line24_
, BITS
),
412 /* Overlay planes enabled, transparency used */
413 static drawfn
glue(glue(pxa2xx_draw_fn_
, BITS
), t
)[16] =
416 [pxa_lcdc_4bpp
] = glue(pxa2xx_draw_line4_
, BITS
),
417 [pxa_lcdc_8bpp
] = glue(pxa2xx_draw_line8_
, BITS
),
418 [pxa_lcdc_16bpp
] = glue(pxa2xx_draw_line16t_
, BITS
),
419 [pxa_lcdc_19bpp
] = glue(pxa2xx_draw_line19_
, BITS
),
420 [pxa_lcdc_19pbpp
] = glue(pxa2xx_draw_line19p_
, BITS
),
421 [pxa_lcdc_24bpp
] = glue(pxa2xx_draw_line24t_
, BITS
),
422 [pxa_lcdc_25bpp
] = glue(pxa2xx_draw_line25_
, BITS
),