hw/display/omap_lcdc: Expand out macros in template header
[qemu/ar7.git] / hw / display / omap_lcd_template.h
blobc7c5025fb047f1822feb15b828bdc5f93f54ff97
1 /*
2 * QEMU OMAP LCD Emulator templates
4 * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
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.
31 * 2-bit colour
33 static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
34 int width, int deststep)
36 uint16_t *pal = opaque;
37 uint8_t v, r, g, b;
39 do {
40 v = ldub_p((void *) s);
41 r = (pal[v & 3] >> 4) & 0xf0;
42 g = pal[v & 3] & 0xf0;
43 b = (pal[v & 3] << 4) & 0xf0;
44 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
45 d += 4;
46 v >>= 2;
47 r = (pal[v & 3] >> 4) & 0xf0;
48 g = pal[v & 3] & 0xf0;
49 b = (pal[v & 3] << 4) & 0xf0;
50 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
51 d += 4;
52 v >>= 2;
53 r = (pal[v & 3] >> 4) & 0xf0;
54 g = pal[v & 3] & 0xf0;
55 b = (pal[v & 3] << 4) & 0xf0;
56 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
57 d += 4;
58 v >>= 2;
59 r = (pal[v & 3] >> 4) & 0xf0;
60 g = pal[v & 3] & 0xf0;
61 b = (pal[v & 3] << 4) & 0xf0;
62 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
63 d += 4;
64 s ++;
65 width -= 4;
66 } while (width > 0);
70 * 4-bit colour
72 static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
73 int width, int deststep)
75 uint16_t *pal = opaque;
76 uint8_t v, r, g, b;
78 do {
79 v = ldub_p((void *) s);
80 r = (pal[v & 0xf] >> 4) & 0xf0;
81 g = pal[v & 0xf] & 0xf0;
82 b = (pal[v & 0xf] << 4) & 0xf0;
83 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
84 d += 4;
85 v >>= 4;
86 r = (pal[v & 0xf] >> 4) & 0xf0;
87 g = pal[v & 0xf] & 0xf0;
88 b = (pal[v & 0xf] << 4) & 0xf0;
89 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
90 d += 4;
91 s ++;
92 width -= 2;
93 } while (width > 0);
97 * 8-bit colour
99 static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
100 int width, int deststep)
102 uint16_t *pal = opaque;
103 uint8_t v, r, g, b;
105 do {
106 v = ldub_p((void *) s);
107 r = (pal[v] >> 4) & 0xf0;
108 g = pal[v] & 0xf0;
109 b = (pal[v] << 4) & 0xf0;
110 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
111 s ++;
112 d += 4;
113 } while (-- width != 0);
117 * 12-bit colour
119 static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
120 int width, int deststep)
122 uint16_t v;
123 uint8_t r, g, b;
125 do {
126 v = lduw_le_p((void *) s);
127 r = (v >> 4) & 0xf0;
128 g = v & 0xf0;
129 b = (v << 4) & 0xf0;
130 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
131 s += 2;
132 d += 4;
133 } while (-- width != 0);
137 * 16-bit colour
139 static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
140 int width, int deststep)
142 #if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
143 memcpy(d, s, width * 2);
144 #else
145 uint16_t v;
146 uint8_t r, g, b;
148 do {
149 v = lduw_le_p((void *) s);
150 r = (v >> 8) & 0xf8;
151 g = (v >> 3) & 0xfc;
152 b = (v << 3) & 0xf8;
153 ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
154 s += 2;
155 d += 4;
156 } while (-- width != 0);
157 #endif