1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#if BITS == 8
22#define COPY_PIXEL(to, r, g, b) \
23 do { \
24 *to = rgb_to_pixel8(r, g, b); \
25 to += 1; \
26 } while (0)
27#elif BITS == 15
28#define COPY_PIXEL(to, r, g, b) \
29 do { \
30 *(uint16_t *)to = rgb_to_pixel15(r, g, b); \
31 to += 2; \
32 } while (0)
33#elif BITS == 16
34#define COPY_PIXEL(to, r, g, b) \
35 do { \
36 *(uint16_t *)to = rgb_to_pixel16(r, g, b); \
37 to += 2; \
38 } while (0)
39#elif BITS == 24
40#define COPY_PIXEL(to, r, g, b) \
41 do { \
42 uint32_t tmp = rgb_to_pixel24(r, g, b); \
43 *(to++) = tmp & 0xff; \
44 *(to++) = (tmp >> 8) & 0xff; \
45 *(to++) = (tmp >> 16) & 0xff; \
46 } while (0)
47#elif BITS == 32
48#define COPY_PIXEL(to, r, g, b) \
49 do { \
50 *(uint32_t *)to = rgb_to_pixel32(r, g, b); \
51 to += 4; \
52 } while (0)
53#else
54#error unknown bit depth
55#endif
56
57static void glue(draw_line_, BITS)(void *opaque, uint8_t *d, const uint8_t *s,
58 int width, int deststep)
59{
60 uint16_t rgb565;
61 uint8_t r, g, b;
62
63 while (width--) {
64 rgb565 = lduw_be_p(s);
65 r = ((rgb565 >> 11) & 0x1f) << 3;
66 g = ((rgb565 >> 5) & 0x3f) << 2;
67 b = ((rgb565 >> 0) & 0x1f) << 3;
68 COPY_PIXEL(d, r, g, b);
69 s += 2;
70 }
71}
72
73#undef BITS
74#undef COPY_PIXEL
75