root / hw / blizzard_template.h @ 0d31cb99
History | View | Annotate | Download (4.1 kB)
1 |
/*
|
---|---|
2 |
* QEMU Epson S1D13744/S1D13745 templates
|
3 |
*
|
4 |
* Copyright (C) 2008 Nokia Corporation
|
5 |
* Written by Andrzej Zaborowski <andrew@openedhand.com>
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License as
|
9 |
* published by the Free Software Foundation; either version 2 or
|
10 |
* (at your option) version 3 of the License.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
20 |
* MA 02111-1307 USA
|
21 |
*/
|
22 |
|
23 |
#define SKIP_PIXEL(to) to += deststep
|
24 |
#if DEPTH == 8 |
25 |
# define PIXEL_TYPE uint8_t
|
26 |
# define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
|
27 |
# define COPY_PIXEL1(to, from) *to ++ = from
|
28 |
#elif DEPTH == 15 || DEPTH == 16 |
29 |
# define PIXEL_TYPE uint16_t
|
30 |
# define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
|
31 |
# define COPY_PIXEL1(to, from) *to ++ = from
|
32 |
#elif DEPTH == 24 |
33 |
# define PIXEL_TYPE uint8_t
|
34 |
# define COPY_PIXEL(to, from) \
|
35 |
to[0] = from; to[1] = (from) >> 8; to[2] = (from) >> 16; SKIP_PIXEL(to) |
36 |
# define COPY_PIXEL1(to, from) \
|
37 |
*to ++ = from; *to ++ = (from) >> 8; *to ++ = (from) >> 16 |
38 |
#elif DEPTH == 32 |
39 |
# define PIXEL_TYPE uint32_t
|
40 |
# define COPY_PIXEL(to, from) *to = from; SKIP_PIXEL(to)
|
41 |
# define COPY_PIXEL1(to, from) *to ++ = from
|
42 |
#else
|
43 |
# error unknown bit depth
|
44 |
#endif
|
45 |
|
46 |
#ifdef WORDS_BIGENDIAN
|
47 |
# define SWAP_WORDS 1 |
48 |
#endif
|
49 |
|
50 |
static void glue(blizzard_draw_line16_, DEPTH)(PIXEL_TYPE *dest, |
51 |
const uint16_t *src, unsigned int width) |
52 |
{ |
53 |
#if !defined(SWAP_WORDS) && DEPTH == 16 |
54 |
memcpy(dest, src, width); |
55 |
#else
|
56 |
uint16_t data; |
57 |
unsigned int r, g, b; |
58 |
const uint16_t *end = (const void *) src + width; |
59 |
while (src < end) {
|
60 |
data = lduw_raw(src ++); |
61 |
b = (data & 0x1f) << 3; |
62 |
data >>= 5;
|
63 |
g = (data & 0x3f) << 2; |
64 |
data >>= 6;
|
65 |
r = (data & 0x1f) << 3; |
66 |
data >>= 5;
|
67 |
COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b)); |
68 |
} |
69 |
#endif
|
70 |
} |
71 |
|
72 |
static void glue(blizzard_draw_line24mode1_, DEPTH)(PIXEL_TYPE *dest, |
73 |
const uint8_t *src, unsigned int width) |
74 |
{ |
75 |
/* TODO: check if SDL 24-bit planes are not in the same format and
|
76 |
* if so, use memcpy */
|
77 |
unsigned int r[2], g[2], b[2]; |
78 |
const uint8_t *end = src + width;
|
79 |
while (src < end) {
|
80 |
g[0] = *src ++;
|
81 |
r[0] = *src ++;
|
82 |
r[1] = *src ++;
|
83 |
b[0] = *src ++;
|
84 |
COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[0], g[0], b[0])); |
85 |
b[1] = *src ++;
|
86 |
g[1] = *src ++;
|
87 |
COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r[1], g[1], b[1])); |
88 |
} |
89 |
} |
90 |
|
91 |
static void glue(blizzard_draw_line24mode2_, DEPTH)(PIXEL_TYPE *dest, |
92 |
const uint8_t *src, unsigned int width) |
93 |
{ |
94 |
unsigned int r, g, b; |
95 |
const uint8_t *end = src + width;
|
96 |
while (src < end) {
|
97 |
r = *src ++; |
98 |
src ++; |
99 |
b = *src ++; |
100 |
g = *src ++; |
101 |
COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b)); |
102 |
} |
103 |
} |
104 |
|
105 |
/* No rotation */
|
106 |
static blizzard_fn_t glue(blizzard_draw_fn_, DEPTH)[0x10] = { |
107 |
NULL,
|
108 |
/* RGB 5:6:5*/
|
109 |
(blizzard_fn_t) glue(blizzard_draw_line16_, DEPTH), |
110 |
/* RGB 6:6:6 mode 1 */
|
111 |
(blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH), |
112 |
/* RGB 8:8:8 mode 1 */
|
113 |
(blizzard_fn_t) glue(blizzard_draw_line24mode1_, DEPTH), |
114 |
NULL, NULL, |
115 |
/* RGB 6:6:6 mode 2 */
|
116 |
(blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH), |
117 |
/* RGB 8:8:8 mode 2 */
|
118 |
(blizzard_fn_t) glue(blizzard_draw_line24mode2_, DEPTH), |
119 |
/* YUV 4:2:2 */
|
120 |
NULL,
|
121 |
/* YUV 4:2:0 */
|
122 |
NULL,
|
123 |
NULL, NULL, NULL, NULL, NULL, NULL, |
124 |
}; |
125 |
|
126 |
/* 90deg, 180deg and 270deg rotation */
|
127 |
static blizzard_fn_t glue(blizzard_draw_fn_r_, DEPTH)[0x10] = { |
128 |
/* TODO */
|
129 |
[0 ... 0xf] = NULL, |
130 |
}; |
131 |
|
132 |
#undef DEPTH
|
133 |
#undef SKIP_PIXEL
|
134 |
#undef COPY_PIXEL
|
135 |
#undef COPY_PIXEL1
|
136 |
#undef PIXEL_TYPE
|
137 |
|
138 |
#undef SWAP_WORDS
|