2 * Samsung S3C2410A LCD controller emulation.
4 * Copyright (c) 2007 OpenMoko, Inc.
5 * Author: Andrzej Zaborowski <andrew@openedhand.com>
7 * This code is licensed under the GNU GPL v2.
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)
32 #define FN_8(x) FN_4(x + 4) FN_4(x)
34 static void glue(s3c_draw_line1_
, BITS
)(void *opaque
,
35 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
37 uint32_t *palette
= opaque
;
40 data
= *(uint32_t *) src
;
41 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 1]);
59 static void glue(s3c_draw_line2_
, BITS
)(void *opaque
,
60 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
62 uint32_t *palette
= opaque
;
65 data
= *(uint32_t *) src
;
66 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
84 static void glue(s3c_draw_line4_
, BITS
)(void *opaque
,
85 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
87 uint32_t *palette
= opaque
;
90 data
= *(uint32_t *) src
;
91 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
109 static void glue(s3c_draw_line8_
, BITS
)(void *opaque
,
110 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
112 uint32_t *palette
= opaque
;
115 data
= *(uint32_t *) src
;
116 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
134 static void glue(s3c_draw_line16a_
, BITS
)(void *opaque
,
135 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
138 unsigned int r
, g
, b
;
140 data
= *(uint32_t *) src
;
142 data
= bswap32(data
);
144 b
= (data
& 0x1f) << 3;
146 g
= (data
& 0x3f) << 2;
148 r
= (data
& 0x1f) << 3;
150 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
151 b
= (data
& 0x1f) << 3;
153 g
= (data
& 0x3f) << 2;
155 r
= (data
& 0x1f) << 3;
156 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
162 static void glue(s3c_draw_line16b_
, BITS
)(void *opaque
,
163 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
166 unsigned int r
, g
, b
;
168 data
= *(uint32_t *) src
;
170 data
= bswap32(data
);
172 b
= (data
& 0x1f) << 3;
174 g
= (data
& 0x1f) << 3;
176 r
= (data
& 0x3f) << 2;
178 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
179 b
= (data
& 0x1f) << 3;
181 g
= (data
& 0x1f) << 3;
183 r
= (data
& 0x3f) << 2;
184 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
190 static void glue(s3c_draw_line12_
, BITS
)(void *opaque
,
191 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
194 unsigned int r
, g
, b
;
196 data
= *(uint32_t *) src
;
199 data
= bswap32(data
);
201 /* XXX should use (x & 0xf) << 4) | (x & 0xf) for natural
202 * colours. Otherwise the image may be a bit darkened. */
203 b
= (data
& 0xf00) >> 4;
204 g
= (data
& 0xf0) << 0;
205 r
= (data
& 0xf) << 4;
207 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
208 b
= (data
& 0xf00) >> 4;
209 g
= (data
& 0xf0) << 0;
210 r
= (data
& 0xf) << 4;
212 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
213 b
= (data
& 0xf00) >> 4;
214 g
= (data
& 0xf0) << 0;
215 r
= (data
& 0xf) << 4;
217 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
218 b
= (data
& 0xf00) >> 4;
219 g
= (data
& 0xf0) << 0;
220 r
= (data
& 0xf) << 4;
222 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
227 static void glue(s3c_draw_line24_
, BITS
)(void *opaque
,
228 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
231 unsigned int r
, g
, b
;
233 data
= *(uint32_t *) src
;
235 data
= bswap32(data
);
242 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
248 static drawfn
glue(s3c_draw_fn_
, BITS
)[] =
250 glue(s3c_draw_line1_
, BITS
),
251 glue(s3c_draw_line2_
, BITS
),
252 glue(s3c_draw_line4_
, BITS
),
253 glue(s3c_draw_line8_
, BITS
),
254 glue(s3c_draw_line12_
, BITS
),
255 glue(s3c_draw_line16a_
, BITS
),
256 glue(s3c_draw_line16b_
, BITS
),
257 glue(s3c_draw_line24_
, BITS
),