2 * Arm PrimeCell PL110 Color LCD Controller
4 * Copyright (c) 2005 CodeSourcery, LLC.
5 * Written by Paul Brook
7 * This code is licensed under the GNU LGPL
9 * Framebuffer format conversion routines.
15 #define COPY_PIXEL(to, from) *(to++) = from
16 #elif BITS == 15 || BITS == 16
17 #define COPY_PIXEL(to, from) do { *(uint16_t *)to = from; to += 2; } while (0)
19 #define COPY_PIXEL(to, from) \
22 *(to++) = (from) >> 8; \
23 *(to++) = (from) >> 16; \
26 #define COPY_PIXEL(to, from) do { *(uint32_t *)to = from; to += 4; } while (0)
28 #error unknown bit depth
34 #include "pl110_template.h"
36 #include "pl110_template.h"
38 #include "pl110_template.h"
43 #include "pl110_template.h"
45 #include "pl110_template.h"
47 #include "pl110_template.h"
50 static drawfn
glue(pl110_draw_fn_
,BITS
)[48] =
52 glue(pl110_draw_line1_lblp_bgr
,BITS
),
53 glue(pl110_draw_line2_lblp_bgr
,BITS
),
54 glue(pl110_draw_line4_lblp_bgr
,BITS
),
55 glue(pl110_draw_line8_lblp_bgr
,BITS
),
56 glue(pl110_draw_line16_555_lblp_bgr
,BITS
),
57 glue(pl110_draw_line32_lblp_bgr
,BITS
),
58 glue(pl110_draw_line16_lblp_bgr
,BITS
),
59 glue(pl110_draw_line12_lblp_bgr
,BITS
),
61 glue(pl110_draw_line1_bbbp_bgr
,BITS
),
62 glue(pl110_draw_line2_bbbp_bgr
,BITS
),
63 glue(pl110_draw_line4_bbbp_bgr
,BITS
),
64 glue(pl110_draw_line8_bbbp_bgr
,BITS
),
65 glue(pl110_draw_line16_555_bbbp_bgr
,BITS
),
66 glue(pl110_draw_line32_bbbp_bgr
,BITS
),
67 glue(pl110_draw_line16_bbbp_bgr
,BITS
),
68 glue(pl110_draw_line12_bbbp_bgr
,BITS
),
70 glue(pl110_draw_line1_lbbp_bgr
,BITS
),
71 glue(pl110_draw_line2_lbbp_bgr
,BITS
),
72 glue(pl110_draw_line4_lbbp_bgr
,BITS
),
73 glue(pl110_draw_line8_lbbp_bgr
,BITS
),
74 glue(pl110_draw_line16_555_lbbp_bgr
,BITS
),
75 glue(pl110_draw_line32_lbbp_bgr
,BITS
),
76 glue(pl110_draw_line16_lbbp_bgr
,BITS
),
77 glue(pl110_draw_line12_lbbp_bgr
,BITS
),
79 glue(pl110_draw_line1_lblp_rgb
,BITS
),
80 glue(pl110_draw_line2_lblp_rgb
,BITS
),
81 glue(pl110_draw_line4_lblp_rgb
,BITS
),
82 glue(pl110_draw_line8_lblp_rgb
,BITS
),
83 glue(pl110_draw_line16_555_lblp_rgb
,BITS
),
84 glue(pl110_draw_line32_lblp_rgb
,BITS
),
85 glue(pl110_draw_line16_lblp_rgb
,BITS
),
86 glue(pl110_draw_line12_lblp_rgb
,BITS
),
88 glue(pl110_draw_line1_bbbp_rgb
,BITS
),
89 glue(pl110_draw_line2_bbbp_rgb
,BITS
),
90 glue(pl110_draw_line4_bbbp_rgb
,BITS
),
91 glue(pl110_draw_line8_bbbp_rgb
,BITS
),
92 glue(pl110_draw_line16_555_bbbp_rgb
,BITS
),
93 glue(pl110_draw_line32_bbbp_rgb
,BITS
),
94 glue(pl110_draw_line16_bbbp_rgb
,BITS
),
95 glue(pl110_draw_line12_bbbp_rgb
,BITS
),
97 glue(pl110_draw_line1_lbbp_rgb
,BITS
),
98 glue(pl110_draw_line2_lbbp_rgb
,BITS
),
99 glue(pl110_draw_line4_lbbp_rgb
,BITS
),
100 glue(pl110_draw_line8_lbbp_rgb
,BITS
),
101 glue(pl110_draw_line16_555_lbbp_rgb
,BITS
),
102 glue(pl110_draw_line32_lbbp_rgb
,BITS
),
103 glue(pl110_draw_line16_lbbp_rgb
,BITS
),
104 glue(pl110_draw_line12_lbbp_rgb
,BITS
),
113 #define NAME glue(glue(lblp_, BORDER), BITS)
114 #ifdef HOST_WORDS_BIGENDIAN
118 #define NAME glue(glue(bbbp_, BORDER), BITS)
119 #ifndef HOST_WORDS_BIGENDIAN
123 #define SWAP_PIXELS 1
124 #define NAME glue(glue(lbbp_, BORDER), BITS)
125 #ifdef HOST_WORDS_BIGENDIAN
130 #define FN_2(x, y) FN(x, y) FN(x+1, y)
131 #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
132 #define FN_8(y) FN_4(0, y) FN_4(4, y)
134 static void glue(pl110_draw_line1_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
136 uint32_t *palette
= opaque
;
139 data
= *(uint32_t *)src
;
141 #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 7 - (x))) & 1]);
143 #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x) + y)) & 1]);
162 static void glue(pl110_draw_line2_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
164 uint32_t *palette
= opaque
;
167 data
= *(uint32_t *)src
;
169 #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 6 - (x)*2)) & 3]);
171 #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x)*2 + y)) & 3]);
190 static void glue(pl110_draw_line4_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
192 uint32_t *palette
= opaque
;
195 data
= *(uint32_t *)src
;
197 #define FN(x, y) COPY_PIXEL(d, palette[(data >> (y + 4 - (x)*4)) & 0xf]);
199 #define FN(x, y) COPY_PIXEL(d, palette[(data >> ((x)*4 + y)) & 0xf]);
218 static void glue(pl110_draw_line8_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
220 uint32_t *palette
= opaque
;
223 data
= *(uint32_t *)src
;
224 #define FN(x) COPY_PIXEL(d, palette[(data >> (x)) & 0xff]);
242 static void glue(pl110_draw_line16_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
245 unsigned int r
, g
, b
;
247 data
= *(uint32_t *)src
;
249 data
= bswap32(data
);
266 LSB
= (data
& 0x1f) << 3;
268 g
= (data
& 0x3f) << 2;
270 MSB
= (data
& 0x1f) << 3;
273 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
274 LSB
= (data
& 0x1f) << 3;
276 g
= (data
& 0x3f) << 2;
278 MSB
= (data
& 0x1f) << 3;
280 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
288 static void glue(pl110_draw_line32_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
291 unsigned int r
, g
, b
;
293 data
= *(uint32_t *)src
;
303 g
= (data
>> 8) & 0xff;
304 MSB
= (data
>> 16) & 0xff;
306 LSB
= (data
>> 24) & 0xff;
307 g
= (data
>> 16) & 0xff;
308 MSB
= (data
>> 8) & 0xff;
310 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
318 static void glue(pl110_draw_line16_555_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
320 /* RGB 555 plus an intensity bit (which we ignore) */
322 unsigned int r
, g
, b
;
324 data
= *(uint32_t *)src
;
326 data
= bswap32(data
);
335 LSB
= (data
& 0x1f) << 3;
337 g
= (data
& 0x1f) << 3;
339 MSB
= (data
& 0x1f) << 3;
341 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
342 LSB
= (data
& 0x1f) << 3;
344 g
= (data
& 0x1f) << 3;
346 MSB
= (data
& 0x1f) << 3;
348 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
356 static void glue(pl110_draw_line12_
,NAME
)(void *opaque
, uint8_t *d
, const uint8_t *src
, int width
, int deststep
)
358 /* RGB 444 with 4 bits of zeroes at the top of each halfword */
360 unsigned int r
, g
, b
;
362 data
= *(uint32_t *)src
;
364 data
= bswap32(data
);
373 LSB
= (data
& 0xf) << 4;
375 g
= (data
& 0xf) << 4;
377 MSB
= (data
& 0xf) << 4;
379 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));
380 LSB
= (data
& 0xf) << 4;
382 g
= (data
& 0xf) << 4;
384 MSB
= (data
& 0xf) << 4;
386 COPY_PIXEL(d
, glue(rgb_to_pixel
,BITS
)(r
, g
, b
));