root / hw / omap_lcd_template.h @ 84f15818
History | View | Annotate | Download (4.9 kB)
1 | c3d2689d | balrog | /*
|
---|---|---|---|
2 | c3d2689d | balrog | * QEMU OMAP LCD Emulator templates
|
3 | c3d2689d | balrog | *
|
4 | c3d2689d | balrog | * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
|
5 | c3d2689d | balrog | *
|
6 | c3d2689d | balrog | * Redistribution and use in source and binary forms, with or without
|
7 | c3d2689d | balrog | * modification, are permitted provided that the following conditions
|
8 | c3d2689d | balrog | * are met:
|
9 | c3d2689d | balrog | *
|
10 | c3d2689d | balrog | * 1. Redistributions of source code must retain the above copyright
|
11 | c3d2689d | balrog | * notice, this list of conditions and the following disclaimer.
|
12 | c3d2689d | balrog | * 2. Redistributions in binary form must reproduce the above copyright
|
13 | c3d2689d | balrog | * notice, this list of conditions and the following disclaimer in
|
14 | c3d2689d | balrog | * the documentation and/or other materials provided with the
|
15 | c3d2689d | balrog | * distribution.
|
16 | c3d2689d | balrog | *
|
17 | c3d2689d | balrog | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
|
18 | c3d2689d | balrog | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
19 | c3d2689d | balrog | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
20 | c3d2689d | balrog | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
21 | c3d2689d | balrog | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
22 | c3d2689d | balrog | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
23 | c3d2689d | balrog | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
24 | c3d2689d | balrog | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
25 | c3d2689d | balrog | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26 | c3d2689d | balrog | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27 | c3d2689d | balrog | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 | c3d2689d | balrog | */
|
29 | c3d2689d | balrog | |
30 | c3d2689d | balrog | #if DEPTH == 8 |
31 | c3d2689d | balrog | # define BPP 1 |
32 | 5fafdf24 | ths | # define PIXEL_TYPE uint8_t
|
33 | c3d2689d | balrog | #elif DEPTH == 15 || DEPTH == 16 |
34 | c3d2689d | balrog | # define BPP 2 |
35 | 5fafdf24 | ths | # define PIXEL_TYPE uint16_t
|
36 | c3d2689d | balrog | #elif DEPTH == 32 |
37 | c3d2689d | balrog | # define BPP 4 |
38 | 5fafdf24 | ths | # define PIXEL_TYPE uint32_t
|
39 | c3d2689d | balrog | #else
|
40 | c3d2689d | balrog | # error unsupport depth
|
41 | c3d2689d | balrog | #endif
|
42 | c3d2689d | balrog | |
43 | 5fafdf24 | ths | /*
|
44 | c3d2689d | balrog | * 2-bit colour
|
45 | c3d2689d | balrog | */
|
46 | 714fa308 | pbrook | static void glue(draw_line2_, DEPTH)(void *opaque, |
47 | 714fa308 | pbrook | uint8_t *d, const uint8_t *s, int width, int deststep) |
48 | c3d2689d | balrog | { |
49 | 714fa308 | pbrook | uint16_t *pal = opaque; |
50 | c3d2689d | balrog | uint8_t v, r, g, b; |
51 | c3d2689d | balrog | |
52 | c3d2689d | balrog | do {
|
53 | c3d2689d | balrog | v = ldub_raw((void *) s);
|
54 | c3d2689d | balrog | r = (pal[v & 3] >> 4) & 0xf0; |
55 | c3d2689d | balrog | g = pal[v & 3] & 0xf0; |
56 | c3d2689d | balrog | b = (pal[v & 3] << 4) & 0xf0; |
57 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
58 | c3d2689d | balrog | d += BPP; |
59 | c3d2689d | balrog | v >>= 2;
|
60 | c3d2689d | balrog | r = (pal[v & 3] >> 4) & 0xf0; |
61 | c3d2689d | balrog | g = pal[v & 3] & 0xf0; |
62 | c3d2689d | balrog | b = (pal[v & 3] << 4) & 0xf0; |
63 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
64 | c3d2689d | balrog | d += BPP; |
65 | c3d2689d | balrog | v >>= 2;
|
66 | c3d2689d | balrog | r = (pal[v & 3] >> 4) & 0xf0; |
67 | c3d2689d | balrog | g = pal[v & 3] & 0xf0; |
68 | c3d2689d | balrog | b = (pal[v & 3] << 4) & 0xf0; |
69 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
70 | c3d2689d | balrog | d += BPP; |
71 | c3d2689d | balrog | v >>= 2;
|
72 | c3d2689d | balrog | r = (pal[v & 3] >> 4) & 0xf0; |
73 | c3d2689d | balrog | g = pal[v & 3] & 0xf0; |
74 | c3d2689d | balrog | b = (pal[v & 3] << 4) & 0xf0; |
75 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
76 | c3d2689d | balrog | d += BPP; |
77 | c3d2689d | balrog | s ++; |
78 | c3d2689d | balrog | width -= 4;
|
79 | c3d2689d | balrog | } while (width > 0); |
80 | c3d2689d | balrog | } |
81 | c3d2689d | balrog | |
82 | 5fafdf24 | ths | /*
|
83 | c3d2689d | balrog | * 4-bit colour
|
84 | c3d2689d | balrog | */
|
85 | 714fa308 | pbrook | static void glue(draw_line4_, DEPTH)(void *opaque, |
86 | 714fa308 | pbrook | uint8_t *d, const uint8_t *s, int width, int deststep) |
87 | c3d2689d | balrog | { |
88 | 714fa308 | pbrook | uint16_t *pal = opaque; |
89 | c3d2689d | balrog | uint8_t v, r, g, b; |
90 | c3d2689d | balrog | |
91 | c3d2689d | balrog | do {
|
92 | c3d2689d | balrog | v = ldub_raw((void *) s);
|
93 | c3d2689d | balrog | r = (pal[v & 0xf] >> 4) & 0xf0; |
94 | c3d2689d | balrog | g = pal[v & 0xf] & 0xf0; |
95 | c3d2689d | balrog | b = (pal[v & 0xf] << 4) & 0xf0; |
96 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
97 | c3d2689d | balrog | d += BPP; |
98 | c3d2689d | balrog | v >>= 4;
|
99 | c3d2689d | balrog | r = (pal[v & 0xf] >> 4) & 0xf0; |
100 | c3d2689d | balrog | g = pal[v & 0xf] & 0xf0; |
101 | c3d2689d | balrog | b = (pal[v & 0xf] << 4) & 0xf0; |
102 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
103 | c3d2689d | balrog | d += BPP; |
104 | c3d2689d | balrog | s ++; |
105 | c3d2689d | balrog | width -= 2;
|
106 | c3d2689d | balrog | } while (width > 0); |
107 | c3d2689d | balrog | } |
108 | c3d2689d | balrog | |
109 | 5fafdf24 | ths | /*
|
110 | c3d2689d | balrog | * 8-bit colour
|
111 | c3d2689d | balrog | */
|
112 | 714fa308 | pbrook | static void glue(draw_line8_, DEPTH)(void *opaque, |
113 | 714fa308 | pbrook | uint8_t *d, const uint8_t *s, int width, int deststep) |
114 | c3d2689d | balrog | { |
115 | 714fa308 | pbrook | uint16_t *pal = opaque; |
116 | c3d2689d | balrog | uint8_t v, r, g, b; |
117 | c3d2689d | balrog | |
118 | c3d2689d | balrog | do {
|
119 | c3d2689d | balrog | v = ldub_raw((void *) s);
|
120 | c3d2689d | balrog | r = (pal[v] >> 4) & 0xf0; |
121 | c3d2689d | balrog | g = pal[v] & 0xf0;
|
122 | c3d2689d | balrog | b = (pal[v] << 4) & 0xf0; |
123 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
124 | c3d2689d | balrog | s ++; |
125 | c3d2689d | balrog | d += BPP; |
126 | c3d2689d | balrog | } while (-- width != 0); |
127 | c3d2689d | balrog | } |
128 | c3d2689d | balrog | |
129 | 5fafdf24 | ths | /*
|
130 | c3d2689d | balrog | * 12-bit colour
|
131 | c3d2689d | balrog | */
|
132 | 714fa308 | pbrook | static void glue(draw_line12_, DEPTH)(void *opaque, |
133 | 714fa308 | pbrook | uint8_t *d, const uint8_t *s, int width, int deststep) |
134 | c3d2689d | balrog | { |
135 | c3d2689d | balrog | uint16_t v; |
136 | c3d2689d | balrog | uint8_t r, g, b; |
137 | c3d2689d | balrog | |
138 | c3d2689d | balrog | do {
|
139 | c3d2689d | balrog | v = lduw_raw((void *) s);
|
140 | c3d2689d | balrog | r = (v >> 4) & 0xf0; |
141 | c3d2689d | balrog | g = v & 0xf0;
|
142 | c3d2689d | balrog | b = (v << 4) & 0xf0; |
143 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
144 | c3d2689d | balrog | s += 2;
|
145 | c3d2689d | balrog | d += BPP; |
146 | c3d2689d | balrog | } while (-- width != 0); |
147 | c3d2689d | balrog | } |
148 | c3d2689d | balrog | |
149 | 5fafdf24 | ths | /*
|
150 | c3d2689d | balrog | * 16-bit colour
|
151 | c3d2689d | balrog | */
|
152 | 714fa308 | pbrook | static void glue(draw_line16_, DEPTH)(void *opaque, |
153 | 714fa308 | pbrook | uint8_t *d, const uint8_t *s, int width, int deststep) |
154 | c3d2689d | balrog | { |
155 | c3d2689d | balrog | #if DEPTH == 16 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN) |
156 | c3d2689d | balrog | memcpy(d, s, width * 2);
|
157 | c3d2689d | balrog | #else
|
158 | c3d2689d | balrog | uint16_t v; |
159 | c3d2689d | balrog | uint8_t r, g, b; |
160 | c3d2689d | balrog | |
161 | c3d2689d | balrog | do {
|
162 | c3d2689d | balrog | v = lduw_raw((void *) s);
|
163 | c3d2689d | balrog | r = (v >> 8) & 0xf8; |
164 | c3d2689d | balrog | g = (v >> 3) & 0xfc; |
165 | c3d2689d | balrog | b = (v << 3) & 0xf8; |
166 | c3d2689d | balrog | ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
|
167 | c3d2689d | balrog | s += 2;
|
168 | c3d2689d | balrog | d += BPP; |
169 | c3d2689d | balrog | } while (-- width != 0); |
170 | c3d2689d | balrog | #endif
|
171 | c3d2689d | balrog | } |
172 | c3d2689d | balrog | |
173 | c3d2689d | balrog | #undef DEPTH
|
174 | c3d2689d | balrog | #undef BPP
|
175 | c3d2689d | balrog | #undef PIXEL_TYPE |