blob: 2fb96f83ae61766c9aed6e5f9c6b15d247464856 [file] [log] [blame]
balrogc3d26892007-07-29 17:57:26 +00001/*
2 * QEMU OMAP LCD Emulator templates
3 *
4 * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#if DEPTH == 8
31# define BPP 1
ths5fafdf22007-09-16 21:08:06 +000032# define PIXEL_TYPE uint8_t
balrogc3d26892007-07-29 17:57:26 +000033#elif DEPTH == 15 || DEPTH == 16
34# define BPP 2
ths5fafdf22007-09-16 21:08:06 +000035# define PIXEL_TYPE uint16_t
balrogc3d26892007-07-29 17:57:26 +000036#elif DEPTH == 32
37# define BPP 4
ths5fafdf22007-09-16 21:08:06 +000038# define PIXEL_TYPE uint32_t
balrogc3d26892007-07-29 17:57:26 +000039#else
40# error unsupport depth
41#endif
42
ths5fafdf22007-09-16 21:08:06 +000043/*
balrogc3d26892007-07-29 17:57:26 +000044 * 2-bit colour
45 */
pbrook714fa302009-04-01 12:27:59 +000046static void glue(draw_line2_, DEPTH)(void *opaque,
47 uint8_t *d, const uint8_t *s, int width, int deststep)
balrogc3d26892007-07-29 17:57:26 +000048{
pbrook714fa302009-04-01 12:27:59 +000049 uint16_t *pal = opaque;
balrogc3d26892007-07-29 17:57:26 +000050 uint8_t v, r, g, b;
51
52 do {
53 v = ldub_raw((void *) s);
54 r = (pal[v & 3] >> 4) & 0xf0;
55 g = pal[v & 3] & 0xf0;
56 b = (pal[v & 3] << 4) & 0xf0;
57 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
58 d += BPP;
59 v >>= 2;
60 r = (pal[v & 3] >> 4) & 0xf0;
61 g = pal[v & 3] & 0xf0;
62 b = (pal[v & 3] << 4) & 0xf0;
63 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
64 d += BPP;
65 v >>= 2;
66 r = (pal[v & 3] >> 4) & 0xf0;
67 g = pal[v & 3] & 0xf0;
68 b = (pal[v & 3] << 4) & 0xf0;
69 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
70 d += BPP;
71 v >>= 2;
72 r = (pal[v & 3] >> 4) & 0xf0;
73 g = pal[v & 3] & 0xf0;
74 b = (pal[v & 3] << 4) & 0xf0;
75 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
76 d += BPP;
77 s ++;
78 width -= 4;
79 } while (width > 0);
80}
81
ths5fafdf22007-09-16 21:08:06 +000082/*
balrogc3d26892007-07-29 17:57:26 +000083 * 4-bit colour
84 */
pbrook714fa302009-04-01 12:27:59 +000085static void glue(draw_line4_, DEPTH)(void *opaque,
86 uint8_t *d, const uint8_t *s, int width, int deststep)
balrogc3d26892007-07-29 17:57:26 +000087{
pbrook714fa302009-04-01 12:27:59 +000088 uint16_t *pal = opaque;
balrogc3d26892007-07-29 17:57:26 +000089 uint8_t v, r, g, b;
90
91 do {
92 v = ldub_raw((void *) s);
93 r = (pal[v & 0xf] >> 4) & 0xf0;
94 g = pal[v & 0xf] & 0xf0;
95 b = (pal[v & 0xf] << 4) & 0xf0;
96 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
97 d += BPP;
98 v >>= 4;
99 r = (pal[v & 0xf] >> 4) & 0xf0;
100 g = pal[v & 0xf] & 0xf0;
101 b = (pal[v & 0xf] << 4) & 0xf0;
102 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
103 d += BPP;
104 s ++;
105 width -= 2;
106 } while (width > 0);
107}
108
ths5fafdf22007-09-16 21:08:06 +0000109/*
balrogc3d26892007-07-29 17:57:26 +0000110 * 8-bit colour
111 */
pbrook714fa302009-04-01 12:27:59 +0000112static void glue(draw_line8_, DEPTH)(void *opaque,
113 uint8_t *d, const uint8_t *s, int width, int deststep)
balrogc3d26892007-07-29 17:57:26 +0000114{
pbrook714fa302009-04-01 12:27:59 +0000115 uint16_t *pal = opaque;
balrogc3d26892007-07-29 17:57:26 +0000116 uint8_t v, r, g, b;
117
118 do {
119 v = ldub_raw((void *) s);
120 r = (pal[v] >> 4) & 0xf0;
121 g = pal[v] & 0xf0;
122 b = (pal[v] << 4) & 0xf0;
123 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
124 s ++;
125 d += BPP;
126 } while (-- width != 0);
127}
128
ths5fafdf22007-09-16 21:08:06 +0000129/*
balrogc3d26892007-07-29 17:57:26 +0000130 * 12-bit colour
131 */
pbrook714fa302009-04-01 12:27:59 +0000132static void glue(draw_line12_, DEPTH)(void *opaque,
133 uint8_t *d, const uint8_t *s, int width, int deststep)
balrogc3d26892007-07-29 17:57:26 +0000134{
135 uint16_t v;
136 uint8_t r, g, b;
137
138 do {
139 v = lduw_raw((void *) s);
140 r = (v >> 4) & 0xf0;
141 g = v & 0xf0;
142 b = (v << 4) & 0xf0;
143 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
144 s += 2;
145 d += BPP;
146 } while (-- width != 0);
147}
148
ths5fafdf22007-09-16 21:08:06 +0000149/*
balrogc3d26892007-07-29 17:57:26 +0000150 * 16-bit colour
151 */
pbrook714fa302009-04-01 12:27:59 +0000152static void glue(draw_line16_, DEPTH)(void *opaque,
153 uint8_t *d, const uint8_t *s, int width, int deststep)
balrogc3d26892007-07-29 17:57:26 +0000154{
Juan Quintelae2542fe2009-07-27 16:13:06 +0200155#if DEPTH == 16 && defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
balrogc3d26892007-07-29 17:57:26 +0000156 memcpy(d, s, width * 2);
157#else
158 uint16_t v;
159 uint8_t r, g, b;
160
161 do {
162 v = lduw_raw((void *) s);
163 r = (v >> 8) & 0xf8;
164 g = (v >> 3) & 0xfc;
165 b = (v << 3) & 0xf8;
166 ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
167 s += 2;
168 d += BPP;
169 } while (-- width != 0);
170#endif
171}
172
173#undef DEPTH
174#undef BPP
175#undef PIXEL_TYPE