1 #include "qemu-common.h"
4 #include "cursor_hidden.xpm"
5 #include "cursor_left_ptr.xpm"
7 /* for creating built-in cursors */
8 static QEMUCursor
*cursor_parse_xpm(const char *xpm
[])
12 unsigned int width
, height
, colors
, chars
;
13 unsigned int line
= 0, i
, r
, g
, b
, x
, y
, pixel
;
17 /* parse header line: width, height, #colors, #chars */
18 if (sscanf(xpm
[line
], "%d %d %d %d", &width
, &height
, &colors
, &chars
) != 4) {
19 fprintf(stderr
, "%s: header parse error: \"%s\"\n",
20 __FUNCTION__
, xpm
[line
]);
24 fprintf(stderr
, "%s: chars != 1 not supported\n", __FUNCTION__
);
29 /* parse color table */
30 for (i
= 0; i
< colors
; i
++, line
++) {
31 if (sscanf(xpm
[line
], "%c c %15s", &idx
, name
) == 2) {
32 if (sscanf(name
, "#%02x%02x%02x", &r
, &g
, &b
) == 3) {
33 ctab
[idx
] = (0xff << 24) | (b
<< 16) | (g
<< 8) | r
;
36 if (strcmp(name
, "None") == 0) {
37 ctab
[idx
] = 0x00000000;
41 fprintf(stderr
, "%s: color parse error: \"%s\"\n",
42 __FUNCTION__
, xpm
[line
]);
46 /* parse pixel data */
47 c
= cursor_alloc(width
, height
);
48 for (pixel
= 0, y
= 0; y
< height
; y
++, line
++) {
49 for (x
= 0; x
< height
; x
++, pixel
++) {
51 c
->data
[pixel
] = ctab
[idx
];
57 /* nice for debugging */
58 void cursor_print_ascii_art(QEMUCursor
*c
, const char *prefix
)
60 uint32_t *data
= c
->data
;
63 for (y
= 0; y
< c
->height
; y
++) {
64 fprintf(stderr
, "%s: %2d: |", prefix
, y
);
65 for (x
= 0; x
< c
->width
; x
++, data
++) {
66 if ((*data
& 0xff000000) != 0xff000000) {
67 fprintf(stderr
, " "); /* transparent */
68 } else if ((*data
& 0x00ffffff) == 0x00ffffff) {
69 fprintf(stderr
, "."); /* white */
70 } else if ((*data
& 0x00ffffff) == 0x00000000) {
71 fprintf(stderr
, "X"); /* black */
73 fprintf(stderr
, "o"); /* other */
76 fprintf(stderr
, "|\n");
80 QEMUCursor
*cursor_builtin_hidden(void)
84 c
= cursor_parse_xpm(cursor_hidden_xpm
);
88 QEMUCursor
*cursor_builtin_left_ptr(void)
92 c
= cursor_parse_xpm(cursor_left_ptr_xpm
);
96 QEMUCursor
*cursor_alloc(int width
, int height
)
99 int datasize
= width
* height
* sizeof(uint32_t);
101 c
= qemu_mallocz(sizeof(QEMUCursor
) + datasize
);
108 void cursor_get(QEMUCursor
*c
)
113 void cursor_put(QEMUCursor
*c
)
123 int cursor_get_mono_bpl(QEMUCursor
*c
)
125 return (c
->width
+ 7) / 8;
128 void cursor_set_mono(QEMUCursor
*c
,
129 uint32_t foreground
, uint32_t background
, uint8_t *image
,
130 int transparent
, uint8_t *mask
)
132 uint32_t *data
= c
->data
;
136 bpl
= cursor_get_mono_bpl(c
);
137 for (y
= 0; y
< c
->height
; y
++) {
139 for (x
= 0; x
< c
->width
; x
++, data
++) {
140 if (transparent
&& mask
[x
/8] & bit
) {
142 } else if (!transparent
&& !(mask
[x
/8] & bit
)) {
144 } else if (image
[x
/8] & bit
) {
145 *data
= 0xff000000 | foreground
;
147 *data
= 0xff000000 | background
;
159 void cursor_get_mono_image(QEMUCursor
*c
, int foreground
, uint8_t *image
)
161 uint32_t *data
= c
->data
;
165 bpl
= cursor_get_mono_bpl(c
);
166 memset(image
, 0, bpl
* c
->height
);
167 for (y
= 0; y
< c
->height
; y
++) {
169 for (x
= 0; x
< c
->width
; x
++, data
++) {
170 if (((*data
& 0xff000000) == 0xff000000) &&
171 ((*data
& 0x00ffffff) == foreground
)) {
183 void cursor_get_mono_mask(QEMUCursor
*c
, int transparent
, uint8_t *mask
)
185 uint32_t *data
= c
->data
;
189 bpl
= cursor_get_mono_bpl(c
);
190 memset(mask
, 0, bpl
* c
->height
);
191 for (y
= 0; y
< c
->height
; y
++) {
193 for (x
= 0; x
< c
->width
; x
++, data
++) {
194 if ((*data
& 0xff000000) != 0xff000000) {
195 if (transparent
!= 0) {
199 if (transparent
== 0) {