summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Vignatti <tiago.vignatti@intel.com>2011-07-26 11:42:59 +0300
committerKristian Høgsberg <krh@bitplanet.net>2011-07-26 08:23:37 -0700
commit4d0d2037ea16a2b57f384e13180fe0a74d19bf7c (patch)
tree785fe91dfdc2eb2b63a5e8809eaacb894a98315f
parentc1ace8c465079b8d5fc8f60ba9f0f5078de62cfe (diff)
screenshot: use gdk-pixbuf for writing png images
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
-rw-r--r--clients/screenshot.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/clients/screenshot.c b/clients/screenshot.c
index b6ca48e6..81d75135 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "wayland-client.h"
#include "wayland-glib.h"
@@ -151,11 +152,27 @@ create_shm_buffer(int width, int height, void **data_out)
return buffer;
}
+static void
+write_png(int width, int height, void **data_out) {
+ GdkPixbuf *pixbuf, *normal;
+ GError *error = NULL;
+
+ g_type_init();
+ pixbuf = gdk_pixbuf_new_from_data(*data_out, GDK_COLORSPACE_RGB, TRUE,
+ 8, width, height, width * 4, NULL,
+ NULL);
+
+ normal = gdk_pixbuf_flip(pixbuf, FALSE);
+ gdk_pixbuf_save(normal, "wayland-screenshot.png", "png", &error, NULL);
+ g_object_unref(normal);
+ g_object_unref(pixbuf);
+}
+
int main(int argc, char *argv[])
{
struct wl_display *display;
struct wl_buffer *buffer;
- void *data;
+ void *data = NULL;
display = wl_display_connect(NULL);
if (display == NULL) {
@@ -175,7 +192,7 @@ int main(int argc, char *argv[])
screenshooter_shoot(screenshooter, output, buffer);
roundtrip(display);
- /* FIXME: write png */
+ write_png(output_width, output_height, &data);
return 0;
}