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
)(uint32_t *palette
,
35 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
39 data
= *(uint32_t *) src
;
40 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 1]);
58 static void glue(s3c_draw_line2_
, BITS
)(uint32_t *palette
,
59 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
63 data
= *(uint32_t *) src
;
64 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 2)) & 3]);
82 static void glue(s3c_draw_line4_
, BITS
)(uint32_t *palette
,
83 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
87 data
= *(uint32_t *) src
;
88 #define FN(x) COPY_PIXEL(dest, palette[(data >> ((x) * 4)) & 0xf]);
106 static void glue(s3c_draw_line8_
, BITS
)(uint32_t *palette
,
107 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
111 data
= *(uint32_t *) src
;
112 #define FN(x) COPY_PIXEL(dest, palette[(data >> (x)) & 0xff]);
130 static void glue(s3c_draw_line16a_
, BITS
)(uint32_t *palette
,
131 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
134 unsigned int r
, g
, b
;
136 data
= *(uint32_t *) src
;
138 data
= bswap32(data
);
140 b
= (data
& 0x1f) << 3;
142 g
= (data
& 0x3f) << 2;
144 r
= (data
& 0x1f) << 3;
146 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
147 b
= (data
& 0x1f) << 3;
149 g
= (data
& 0x3f) << 2;
151 r
= (data
& 0x1f) << 3;
152 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
158 static void glue(s3c_draw_line16b_
, BITS
)(uint32_t *palette
,
159 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
162 unsigned int r
, g
, b
;
164 data
= *(uint32_t *) src
;
166 data
= bswap32(data
);
168 b
= (data
& 0x1f) << 3;
170 g
= (data
& 0x1f) << 3;
172 r
= (data
& 0x3f) << 2;
174 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
175 b
= (data
& 0x1f) << 3;
177 g
= (data
& 0x1f) << 3;
179 r
= (data
& 0x3f) << 2;
180 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
186 static void glue(s3c_draw_line12_
, BITS
)(uint32_t *palette
,
187 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
190 unsigned int r
, g
, b
;
192 data
= *(uint32_t *) src
;
195 data
= bswap32(data
);
197 /* XXX should use (x & 0xf) << 4) | (x & 0xf) for natural
198 * colours. Otherwise the image may be a bit darkened. */
199 b
= (data
& 0xf00) >> 4;
200 g
= (data
& 0xf0) << 0;
201 r
= (data
& 0xf) << 4;
203 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
204 b
= (data
& 0xf00) >> 4;
205 g
= (data
& 0xf0) << 0;
206 r
= (data
& 0xf) << 4;
208 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
209 b
= (data
& 0xf00) >> 4;
210 g
= (data
& 0xf0) << 0;
211 r
= (data
& 0xf) << 4;
213 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
214 b
= (data
& 0xf00) >> 4;
215 g
= (data
& 0xf0) << 0;
216 r
= (data
& 0xf) << 4;
218 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
223 static void glue(s3c_draw_line24_
, BITS
)(uint32_t *palette
,
224 uint8_t *dest
, const uint8_t *src
, int width
, int deststep
)
227 unsigned int r
, g
, b
;
229 data
= *(uint32_t *) src
;
231 data
= bswap32(data
);
238 COPY_PIXEL(dest
, glue(s3c_rgb_to_pixel
, BITS
)(r
, g
, b
));
244 static s3c_drawfn_t
glue(s3c_draw_fn_
, BITS
)[] =
246 glue(s3c_draw_line1_
, BITS
),
247 glue(s3c_draw_line2_
, BITS
),
248 glue(s3c_draw_line4_
, BITS
),
249 glue(s3c_draw_line8_
, BITS
),
250 glue(s3c_draw_line12_
, BITS
),
251 glue(s3c_draw_line16a_
, BITS
),
252 glue(s3c_draw_line16b_
, BITS
),
253 glue(s3c_draw_line24_
, BITS
),