Received: from eggs.gnu.org ([208.118.235.92]:49873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S753B-00039n-O7 for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:12:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S752i-0002VJ-GL for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:12:32 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:46114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S752i-0002SZ-7y for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:12:04 -0400 Received: by mail-ee0-f45.google.com with SMTP id t10so1280919eei.4 for ; Mon, 12 Mar 2012 06:12:02 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" Date: Mon, 12 Mar 2012 14:11:32 +0100 Message-Id: <1331557893-30806-7-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com> References: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com> Subject: [Qemu-devel] [PATCH/RFC 6/7] Isolate color conversion from PPM handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= --- hw/vga.c | 62 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 45 insertions(+), 17 deletions(-) diff --git a/hw/vga.c b/hw/vga.c index bb5df70..9f7ca89 100644 --- a/hw/vga.c +++ b/hw/vga.c @@ -2422,32 +2422,37 @@ QEMUFile *qemu_fopen_uri(const char *uri, const char *mode) return f; } -int ppm_save(const char *uri, struct DisplaySurface *ds) +static int ppm_line_handler(void *opaque, uint8_t *line, size_t length) { - QEMUFile *f; + QEMUFile *f = opaque; + + qemu_put_buffer(f, line, length); + + return length; +} + +static int screen_dump_lines(struct DisplaySurface *ds, + int (*line_handler) (void *opaque, uint8_t *data, size_t length), + void *opaque) +{ + char *linebuf, *pbuf; uint8_t *d, *d1; uint32_t v; int y, x; uint8_t r, g, b; - char *linebuf, *pbuf; - gchar *header; - - f = qemu_fopen_uri(uri, "wb"); - g_return_val_if_fail(f != NULL, -1); - - header = g_strdup_printf("P6\n%d %d\n%d\n", ds->width, ds->height, 255); - qemu_put_buffer(f, (uint8_t*)header, strlen(header)); + int ret = -1; linebuf = g_malloc(ds->width * 3); d1 = ds->data; - for(y = 0; y < ds->height; y++) { + for (y = 0; y < ds->height; y++) { d = d1; pbuf = linebuf; - for(x = 0; x < ds->width; x++) { - if (ds->pf.bits_per_pixel == 32) + for (x = 0; x < ds->width; x++) { + if (ds->pf.bits_per_pixel == 32) { v = *(uint32_t *)d; - else + } else { v = (uint32_t) (*(uint16_t *)d); + } /* Limited to 8 or fewer bits per channel: */ r = ((v >> ds->pf.rshift) & ds->pf.rmax) << (8 - ds->pf.rbits); g = ((v >> ds->pf.gshift) & ds->pf.gmax) << (8 - ds->pf.gbits); @@ -2458,13 +2463,36 @@ int ppm_save(const char *uri, struct DisplaySurface *ds) d += ds->pf.bytes_per_pixel; } d1 += ds->linesize; - qemu_put_buffer(f, (uint8_t*)linebuf, pbuf - linebuf); + + if (line_handler(opaque, (uint8_t*)linebuf, pbuf - linebuf) < 0) + goto out; } + ret = 0; +out: g_free(linebuf); - g_free(header); + return ret; +} + +int ppm_save(const char *uri, struct DisplaySurface *ds) +{ + QEMUFile *f; + int ret = -1; + + f = qemu_fopen_uri(uri, "wb"); + g_return_val_if_fail(f != NULL, -1); + + { + gchar *header; + header = g_strdup_printf("P6\n%d %d\n%d\n", ds->width, ds->height, 255); + qemu_put_buffer(f, (uint8_t*)header, strlen(header)); + screen_dump_lines(ds, ppm_line_handler, f); + g_free(header); + } + + ret = 0; qemu_fclose(f); - return 0; + return ret; } /* save the vga display in a PPM image even if no display is -- 1.7.7.6