[gnome-color-manager] Add GcmSampleWindow so we can measure known colors in gcm-picker
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add GcmSampleWindow so we can measure known colors in gcm-picker
- Date: Mon, 26 Jul 2010 15:12:43 +0000 (UTC)
commit 0e6f7205174aef7acf0ab26f5e86f70f4545c570
Author: Richard Hughes <richard hughsie com>
Date: Sun Jul 25 18:11:02 2010 +0100
Add GcmSampleWindow so we can measure known colors in gcm-picker
libcolor-glib/Makefile.am | 3 +
libcolor-glib/gcm-sample-window.c | 167 +++++++++++++++++++++++++++++++++++++
libcolor-glib/gcm-sample-window.h | 63 ++++++++++++++
libcolor-glib/gcm-self-test.c | 29 ++++++-
4 files changed, 260 insertions(+), 2 deletions(-)
---
diff --git a/libcolor-glib/Makefile.am b/libcolor-glib/Makefile.am
index e032d13..71b8c89 100644
--- a/libcolor-glib/Makefile.am
+++ b/libcolor-glib/Makefile.am
@@ -47,12 +47,15 @@ libcolor_glib_include_HEADERS = \
gcm-profile-store.h \
gcm-dmi.h \
gcm-version.h \
+ gcm-sample-window.h \
$(NULL)
libcolor_glib_la_SOURCES = \
libcolor-glib.h \
egg-debug.c \
egg-debug.h \
+ gcm-sample-window.c \
+ gcm-sample-window.h \
gcm-common.c \
gcm-common.h \
gcm-color.c \
diff --git a/libcolor-glib/gcm-sample-window.c b/libcolor-glib/gcm-sample-window.c
new file mode 100644
index 0000000..0557c7a
--- /dev/null
+++ b/libcolor-glib/gcm-sample-window.c
@@ -0,0 +1,167 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009-2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * SECTION:gcm-sample_window
+ * @short_description: Color lookup table object
+ *
+ * This object represents a color lookup table that is useful to manipulating
+ * gamma values in a trivial RGB color space.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include "gcm-sample-window.h"
+
+#include "egg-debug.h"
+
+static void gcm_sample_window_finalize (GObject *object);
+
+#define GCM_SAMPLE_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_SAMPLE_WINDOW, GcmSampleWindowPrivate))
+
+/**
+ * GcmSampleWindowPrivate:
+ *
+ * Private #GcmSampleWindow data
+ **/
+struct _GcmSampleWindowPrivate
+{
+ GtkWidget *image;
+};
+
+G_DEFINE_TYPE (GcmSampleWindow, gcm_sample_window, GTK_TYPE_WINDOW)
+
+/**
+ * gcm_sample_window_set_color:
+ * @sample_window: a valid #GcmSampleWindow instance
+ * @red: the red color value
+ * @green: the green color value
+ * @blue: the blue color value
+ *
+ * Sets the window to a specific color.
+ *
+ * Since: 0.0.1
+ **/
+void
+gcm_sample_window_set_color (GcmSampleWindow *sample_window, guint8 red, guint8 green, guint8 blue)
+{
+ GdkPixbuf *pixbuf;
+ gint width;
+ gint height;
+ gint i;
+ guchar *data;
+ guchar *pixels;
+ GtkWindow *window = GTK_WINDOW (sample_window);
+
+ /* get the window size */
+ gtk_window_get_size (window, &width, &height);
+
+ /* if no pixbuf, create it */
+ pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (sample_window->priv->image));
+ if (pixbuf == NULL) {
+ data = g_new0 (guchar, width*height*3);
+ pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, width*3, (GdkPixbufDestroyNotify) g_free, NULL);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (sample_window->priv->image), pixbuf);
+ }
+
+ /* set the pixel array */
+ pixels = gdk_pixbuf_get_pixels (pixbuf);
+ for (i=0; i<width*height*3; i+=3) {
+ pixels[i+0] = red;
+ pixels[i+1] = green;
+ pixels[i+2] = blue;
+ }
+}
+
+/**
+ * gcm_sample_window_class_init:
+ **/
+static void
+gcm_sample_window_class_init (GcmSampleWindowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gcm_sample_window_finalize;
+ g_type_class_add_private (klass, sizeof (GcmSampleWindowPrivate));
+}
+
+/**
+ * gcm_sample_window_init:
+ **/
+static void
+gcm_sample_window_init (GcmSampleWindow *sample_window)
+{
+ GtkWindow *window = GTK_WINDOW (sample_window);
+ sample_window->priv = GCM_SAMPLE_WINDOW_GET_PRIVATE (sample_window);
+ sample_window->priv->image = gtk_image_new ();
+ gtk_widget_set_size_request (sample_window->priv->image, 200, 200);
+ gtk_container_add (GTK_CONTAINER (sample_window), sample_window->priv->image);
+ gtk_widget_show (sample_window->priv->image);
+
+ /* show on all virtual desktops */
+ gtk_window_stick (window);
+ gtk_window_set_default_size (window, 200, 200);
+
+}
+
+/**
+ * gcm_sample_window_finalize:
+ **/
+static void
+gcm_sample_window_finalize (GObject *object)
+{
+ GcmSampleWindow *sample_window = GCM_SAMPLE_WINDOW (object);
+ GcmSampleWindowPrivate *priv = sample_window->priv;
+
+ g_object_unref (priv->image);
+
+ G_OBJECT_CLASS (gcm_sample_window_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_sample_window_new:
+ *
+ * Return value: a new #GcmSampleWindow object.
+ **/
+GtkWindow *
+gcm_sample_window_new (void)
+{
+ GcmSampleWindow *sample_window;
+ sample_window = g_object_new (GCM_TYPE_SAMPLE_WINDOW,
+ "accept-focus", FALSE,
+ "decorated", FALSE,
+ "default-height", 200,
+ "default-width", 200,
+ "deletable", FALSE,
+ "destroy-with-parent", TRUE,
+ "icon-name", "icc-profile",
+ "modal", TRUE,
+ "resizable", FALSE,
+ "skip-pager-hint", TRUE,
+ "skip-taskbar-hint", TRUE,
+ "title", "calibration square",
+ "type-hint", GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
+ "urgency-hint", TRUE,
+ "window-position", GTK_WIN_POS_CENTER_ALWAYS,
+ NULL);
+ return GTK_WINDOW (sample_window);
+}
+
diff --git a/libcolor-glib/gcm-sample-window.h b/libcolor-glib/gcm-sample-window.h
new file mode 100644
index 0000000..73f8f87
--- /dev/null
+++ b/libcolor-glib/gcm-sample-window.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#if !defined (__LIBCOLOR_GLIB_H_INSIDE__) && !defined (LIBCOLOR_GLIB_COMPILATION)
+#error "Only <libcolor-glib.h> can be included directly."
+#endif
+
+#ifndef __GCM_SAMPLE_WINDOW_H
+#define __GCM_SAMPLE_WINDOW_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_SAMPLE_WINDOW (gcm_sample_window_get_type ())
+#define GCM_SAMPLE_WINDOW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_SAMPLE_WINDOW, GcmSampleWindow))
+#define GCM_IS_SAMPLE_WINDOW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_SAMPLE_WINDOW))
+
+typedef struct _GcmSampleWindowPrivate GcmSampleWindowPrivate;
+typedef struct _GcmSampleWindow GcmSampleWindow;
+typedef struct _GcmSampleWindowClass GcmSampleWindowClass;
+
+struct _GcmSampleWindow
+{
+ GtkWindow parent;
+ GcmSampleWindowPrivate *priv;
+};
+
+struct _GcmSampleWindowClass
+{
+ GtkWindowClass parent_class;
+};
+
+GType gcm_sample_window_get_type (void);
+GtkWindow *gcm_sample_window_new (void);
+void gcm_sample_window_set_color (GcmSampleWindow *sample_window,
+ guint8 red,
+ guint8 green,
+ guint8 blue);
+
+G_END_DECLS
+
+#endif /* __GCM_SAMPLE_WINDOW_H */
+
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index 8a7928d..f24e0d0 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -39,6 +39,7 @@
#include "gcm-image.h"
#include "gcm-usb.h"
#include "gcm-buffer.h"
+#include "gcm-sample-window.h"
static void
gcm_test_common_func (void)
@@ -689,11 +690,34 @@ gcm_test_buffer_func (void)
g_assert_cmpint (gcm_buffer_read_uint16_le (buffer), ==, 8192);
}
+static gboolean
+gcm_test_sample_window_loop_cb (GMainLoop *loop)
+{
+ g_main_loop_quit (loop);
+ return FALSE;
+}
+
+static void
+gcm_test_sample_window_func (void)
+{
+ GtkWindow *window;
+ GMainLoop *loop;
+ window = gcm_sample_window_new ();
+ g_assert (window != NULL);
+ gcm_sample_window_set_color (GCM_SAMPLE_WINDOW (window), 0xff, 0xff, 0x00);
+ gtk_window_present (window);
+ loop = g_main_loop_new (NULL, FALSE);
+ g_timeout_add_seconds (2, (GSourceFunc) gcm_test_sample_window_loop_cb, loop);
+ g_main_loop_run (loop);
+ g_main_loop_unref (loop);
+ g_object_unref (window);
+}
+
int
main (int argc, char **argv)
{
g_type_init ();
-
+ gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
/* tests go here */
@@ -708,8 +732,9 @@ main (int argc, char **argv)
g_test_add_func ("/libcolor-glib/xyz", gcm_test_xyz_func);
g_test_add_func ("/libcolor-glib/dmi", gcm_test_dmi_func);
g_test_add_func ("/libcolor-glib/profile_store", gcm_test_profile_store_func);
- g_test_add_func ("/libcolor-glib/usb", gcm_test_usb_func);
g_test_add_func ("/libcolor-glib/buffer", gcm_test_buffer_func);
+ g_test_add_func ("/libcolor-glib/sample-window", gcm_test_sample_window_func);
+ g_test_add_func ("/libcolor-glib/usb", gcm_test_usb_func);
if (g_test_thorough ()) {
g_test_add_func ("/libcolor-glib/brightness", gcm_test_brightness_func);
g_test_add_func ("/libcolor-glib/image", gcm_test_image_func);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]