From patchwork Thu May 20 12:49:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 53061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8B9D5B7D2F for ; Thu, 20 May 2010 22:51:18 +1000 (EST) Received: from localhost ([127.0.0.1]:36234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OF5D8-0000kr-Px for incoming@patchwork.ozlabs.org; Thu, 20 May 2010 08:50:50 -0400 Received: from [140.186.70.92] (port=42763 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OF5CK-0000kj-Cf for qemu-devel@nongnu.org; Thu, 20 May 2010 08:50:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OF5CD-00032R-Sg for qemu-devel@nongnu.org; Thu, 20 May 2010 08:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2728) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OF5CD-00032J-IC for qemu-devel@nongnu.org; Thu, 20 May 2010 08:49:53 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4KCnoJ4016700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 May 2010 08:49:50 -0400 Received: from zweiblum.home.kraxel.org (vpn1-7-100.ams2.redhat.com [10.36.7.100]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4KCniVZ031472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 20 May 2010 08:49:46 -0400 Message-ID: <4BF52FE7.6000202@redhat.com> Date: Thu, 20 May 2010 14:49:43 +0200 From: Gerd Hoffmann User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-2.fc12 Thunderbird/3.0.4 MIME-Version: 1.0 To: Anthony Liguori Subject: Re: [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions. References: <1273063904-6028-1-git-send-email-kraxel@redhat.com> <1273063904-6028-2-git-send-email-kraxel@redhat.com> <4BE3BBA1.3010007@redhat.com> <4BF39E72.6070906@redhat.com> <4BF4372C.7060000@codemonkey.ws> In-Reply-To: <4BF4372C.7060000@codemonkey.ws> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Blue Swirl , Paolo Bonzini , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi, >>> Well. You can't have both. We can have a efficiently packed format (i.e. >>> two bitmaps). Or we can do it in a way which doesn't need parsing, >>> but that >>> wouldn't be the most compact format ... >> You're right, so packing or introducing a small conversion function is >> not critical. I'd still prefer a standard format if possible. > > Personally, I'd rather see Gerd's original format but read from a file > instead of hard coded in a .c file. IOW, a > /usr/share/qemu/default-cursor.qpm that contained the appropriate > strings. A couple extra lines that made it an xpm I think would be worth > it too. xpms are designed to be easily #include-able, and parsing them that way is easier than loading them at runtime. At least without adding a dependency to libXpm. So how about the following incremental RfC patch? It adds the cursors as separate files which are standard xpm format. Nevertheless they are compiled in, i.e. they can't be changed at runtime. cheers, Gerd From 7066e5a759ec887191601e6a96deab59a1dda721 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 20 May 2010 14:39:26 +0200 Subject: [PATCH] cursor: switch to xpm --- cursor.c | 94 ++++++++++++++++++++++++++------------------------- cursor_hidden.xpm | 37 ++++++++++++++++++++ cursor_left_ptr.xpm | 39 +++++++++++++++++++++ 3 files changed, 124 insertions(+), 46 deletions(-) create mode 100644 cursor_hidden.xpm create mode 100644 cursor_left_ptr.xpm diff --git a/cursor.c b/cursor.c index 3995a31..dfb9eef 100644 --- a/cursor.c +++ b/cursor.c @@ -1,51 +1,57 @@ #include "qemu-common.h" #include "console.h" -static const char cursor_hidden_32[32*32]; -static const char cursor_left_ptr_32[32*32] = { - " " - " X " - " XX " - " X.X " - " X..X " - " X...X " - " X....X " - " X.....X " - " X......X " - " X.......X " - " X........X " - " X.....XXXXX " - " X..X..X " - " X.X X..X " - " XX X..X " - " X X..X " - " X..X " - " X..X " - " X..X " - " XX " - " " -}; +#include "cursor_hidden.xpm" +#include "cursor_left_ptr.xpm" /* for creating built-in cursors */ -static void cursor_parse_ascii_art(QEMUCursor *c, const char *ptr) +static QEMUCursor *cursor_parse_xpm(const char *xpm[]) { - int i, pixels; - - pixels = c->width * c->height; - for (i = 0; i < pixels; i++) { - switch (ptr[i]) { - case 'X': /* black */ - c->data[i] = 0xff000000; - break; - case '.': /* white */ - c->data[i] = 0xffffffff; - break; - case ' ': /* transparent */ - default: - c->data[i] = 0x00000000; - break; + QEMUCursor *c; + uint32_t ctab[128]; + unsigned int width, height, colors, chars; + unsigned int line = 0, i, r, g, b, x, y, pixel; + char name[16]; + uint8_t idx; + + /* parse header line: width, height, #colors, #chars */ + if (sscanf(xpm[line], "%d %d %d %d", &width, &height, &colors, &chars) != 4) { + fprintf(stderr, "%s: header parse error: \"%s\"\n", + __FUNCTION__, xpm[line]); + return NULL; + } + if (chars != 1) { + fprintf(stderr, "%s: chars != 1 not supported\n", __FUNCTION__); + return NULL; + } + line++; + + /* parse color table */ + for (i = 0; i < colors; i++, line++) { + if (sscanf(xpm[line], "%c c %15s", &idx, name) == 2) { + if (sscanf(name, "#%02x%02x%02x", &r, &g, &b) == 3) { + ctab[idx] = (0xff << 24) | (b << 16) | (g << 8) | r; + continue; + } + if (strcmp(name, "None") == 0) { + ctab[idx] = 0x00000000; + continue; + } } + fprintf(stderr, "%s: color parse error: \"%s\"\n", + __FUNCTION__, xpm[line]); + return NULL; } + + /* parse pixel data */ + c = cursor_alloc(width, height); + for (pixel = 0, y = 0; y < height; y++, line++) { + for (x = 0; x < height; x++, pixel++) { + idx = xpm[line][x]; + c->data[pixel] = ctab[idx]; + } + } + return c; } /* nice for debugging */ @@ -75,8 +81,7 @@ QEMUCursor *cursor_builtin_hidden(void) { QEMUCursor *c; - c = cursor_alloc(32, 32); - cursor_parse_ascii_art(c, cursor_hidden_32); + c = cursor_parse_xpm(cursor_hidden_xpm); return c; } @@ -84,10 +89,7 @@ QEMUCursor *cursor_builtin_left_ptr(void) { QEMUCursor *c; - c = cursor_alloc(32, 32); - cursor_parse_ascii_art(c, cursor_left_ptr_32); - c->hot_x = 1; - c->hot_y = 1; + c = cursor_parse_xpm(cursor_left_ptr_xpm); return c; } diff --git a/cursor_hidden.xpm b/cursor_hidden.xpm new file mode 100644 index 0000000..354e7a9 --- /dev/null +++ b/cursor_hidden.xpm @@ -0,0 +1,37 @@ +/* XPM */ +static const char *cursor_hidden_xpm[] = { + "32 32 1 1", + " c None", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", +}; diff --git a/cursor_left_ptr.xpm b/cursor_left_ptr.xpm new file mode 100644 index 0000000..6c9ada9 --- /dev/null +++ b/cursor_left_ptr.xpm @@ -0,0 +1,39 @@ +/* XPM */ +static const char *cursor_left_ptr_xpm[] = { + "32 32 3 1", + "X c #000000", + ". c #ffffff", + " c None", + "X ", + "XX ", + "X.X ", + "X..X ", + "X...X ", + "X....X ", + "X.....X ", + "X......X ", + "X.......X ", + "X........X ", + "X.....XXXXX ", + "X..X..X ", + "X.X X..X ", + "XX X..X ", + "X X..X ", + " X..X ", + " X..X ", + " X..X ", + " XX ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", +};