[Rawstudio-commit] r3224 - trunk/librawstudio

Anders Brander anders at brander.dk
Sun Feb 14 16:59:28 CET 2010


Author: abrander
Date: 2010-02-14 16:59:28 +0100 (Sun, 14 Feb 2010)
New Revision: 3224

Added:
   trunk/librawstudio/rs-color-space-selector.c
   trunk/librawstudio/rs-color-space-selector.h
Modified:
   trunk/librawstudio/Makefile.am
   trunk/librawstudio/rawstudio.h
   trunk/librawstudio/rs-output.c
Log:
Added generic profile selection to output profiles.

Modified: trunk/librawstudio/Makefile.am
===================================================================
--- trunk/librawstudio/Makefile.am	2010-02-14 15:22:54 UTC (rev 3223)
+++ trunk/librawstudio/Makefile.am	2010-02-14 15:59:28 UTC (rev 3224)
@@ -98,6 +98,7 @@
 	rs-profile-factory.c rs-profile-factory.h rs-profile-factory-model.h \
 	rs-profile-selector.c rs-profile-selector.h \
 	rs-profile-camera.c rs-profile-camera.h \
+	rs-color-space-selector.c rs-color-space-selector.h \
 	rs-stock.c rs-stock.h
 
 librawstudio_1_1_la_LIBADD = @PACKAGE_LIBS@ @LIBJPEG@ @LIBTIFF@ $(INTLLIBS)

Modified: trunk/librawstudio/rawstudio.h
===================================================================
--- trunk/librawstudio/rawstudio.h	2010-02-14 15:22:54 UTC (rev 3223)
+++ trunk/librawstudio/rawstudio.h	2010-02-14 15:59:28 UTC (rev 3224)
@@ -70,6 +70,7 @@
 #include "rs-dcp-file.h"
 #include "rs-profile-factory.h"
 #include "rs-profile-selector.h"
+#include "rs-color-space-selector.h"
 
 #include "x86-cpu.h"
 

Added: trunk/librawstudio/rs-color-space-selector.c
===================================================================
--- trunk/librawstudio/rs-color-space-selector.c	                        (rev 0)
+++ trunk/librawstudio/rs-color-space-selector.c	2010-02-14 15:59:28 UTC (rev 3224)
@@ -0,0 +1,183 @@
+/*
+ * * Copyright (C) 2006-2010 Anders Brander <anders at brander.dk>, 
+ * * Anders Kvist <akv at lnxbx.dk> and Klaus Post <klauspost at gmail.com>
+ *
+ * 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.
+ */
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include "rawstudio.h"
+#include "rs-color-space-selector.h"
+
+G_DEFINE_TYPE(RSColorSpaceSelector, rs_color_space_selector, GTK_TYPE_COMBO_BOX)
+
+enum {
+	COLUMN_TEXT,
+	COLUMN_TYPENAME,
+	COLUMN_COLORSPACE,
+	NUM_COLUMNS
+};
+
+enum {
+	SELECTED_SIGNAL,
+	SIGNAL_LAST
+};
+
+static gint signals[SIGNAL_LAST];
+
+#define COLOR_SPACE_SELECTOR_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RS_TYPE_COLOR_SPACE_SELECTOR, RSColorSpaceSelectorPrivate))
+
+struct _RSColorSpaceSelectorPrivate {
+	GtkTreeModel *model;
+
+	gboolean dispose_has_run;
+};
+
+static void
+rs_color_space_selector_dispose(GObject *object)
+{
+	RSColorSpaceSelector *selector = RS_COLOR_SPACE_SELECTOR(object);
+
+	if (!selector->priv->dispose_has_run)
+	{
+		selector->priv->dispose_has_run = TRUE;
+	}
+
+	G_OBJECT_CLASS(rs_color_space_selector_parent_class)->dispose(object);
+}
+
+static void
+changed(GtkComboBox *combo_box)
+{
+	RSColorSpace *colorspace = NULL;
+	GtkTreeIter iter;
+	RSColorSpaceSelector *selector = RS_COLOR_SPACE_SELECTOR(combo_box);
+
+	if (gtk_combo_box_get_active_iter(combo_box, &iter))
+	{
+		gtk_tree_model_get(selector->priv->model, &iter, COLUMN_COLORSPACE, &colorspace, -1);
+
+		if (colorspace)
+			g_signal_emit(selector, signals[SELECTED_SIGNAL], 0, colorspace);
+	}
+}
+
+static void
+rs_color_space_selector_class_init(RSColorSpaceSelectorClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS(klass);
+	GtkComboBoxClass *combo_class = GTK_COMBO_BOX_CLASS(klass);
+
+	g_type_class_add_private(klass, sizeof(RSColorSpaceSelectorPrivate));
+
+	object_class->dispose = rs_color_space_selector_dispose;
+
+	combo_class->changed = changed;
+
+	signals[SELECTED_SIGNAL] = g_signal_new("colorspace-selected",
+		G_TYPE_FROM_CLASS(klass),
+		G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+		0,
+		NULL,
+		NULL,
+		g_cclosure_marshal_VOID__OBJECT,
+		G_TYPE_NONE, 1, RS_TYPE_COLOR_SPACE);
+}
+
+static void
+rs_color_space_selector_init(RSColorSpaceSelector *selector)
+{
+	GtkComboBox *combo = GTK_COMBO_BOX(selector);
+
+	selector->priv = COLOR_SPACE_SELECTOR_PRIVATE(selector);
+
+	selector->priv->model = GTK_TREE_MODEL(gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, RS_TYPE_COLOR_SPACE));
+
+	GtkCellRenderer *cell = gtk_cell_renderer_text_new();
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE );
+	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
+		"markup", COLUMN_TEXT,
+		NULL);
+
+	gtk_combo_box_set_model(combo, selector->priv->model);
+
+}
+
+GtkWidget *
+rs_color_space_selector_new(void)
+{
+	return g_object_new(RS_TYPE_COLOR_SPACE_SELECTOR, NULL);
+}
+
+void
+rs_color_space_selector_add_all(RSColorSpaceSelector *selector)
+{
+	GType *spaces;
+	guint n_spaces, i;
+	GtkTreeIter iter;
+
+	g_return_if_fail(RS_IS_COLOR_SPACE_SELECTOR(selector));
+
+	spaces = g_type_children (RS_TYPE_COLOR_SPACE, &n_spaces);
+	for (i = 0; i < n_spaces; i++)
+	{
+		RSColorSpaceClass *klass;
+		klass = g_type_class_ref(spaces[i]);
+
+		gtk_list_store_append(GTK_LIST_STORE(selector->priv->model), &iter);
+		gtk_list_store_set(GTK_LIST_STORE(selector->priv->model), &iter,
+			COLUMN_TEXT, klass->name,
+		    COLUMN_TYPENAME, g_type_name(spaces[i]),
+			COLUMN_COLORSPACE, rs_color_space_new_singleton(g_type_name(spaces[i])),
+			-1);
+
+		g_type_class_unref(klass);
+	}
+}
+
+RSColorSpace *
+rs_color_space_selector_set_selected_by_name(RSColorSpaceSelector *selector, const gchar *type_name)
+{
+
+	
+	RSColorSpace *ret = NULL;
+	GtkTreeIter iter;
+	gchar *type_name_haystack;
+
+	g_return_val_if_fail(RS_IS_COLOR_SPACE_SELECTOR(selector), NULL);
+	g_return_val_if_fail(type_name != NULL, NULL);
+
+	if (gtk_tree_model_get_iter_first(selector->priv->model, &iter))
+	{
+		do {
+			gtk_tree_model_get(selector->priv->model, &iter,
+							    COLUMN_TYPENAME, &type_name_haystack,
+							    COLUMN_COLORSPACE, &ret,
+								-1);
+			if (type_name_haystack)
+			{
+				if (g_strcmp0(type_name_haystack, type_name) == 0)
+				{
+					gtk_combo_box_set_active_iter(GTK_COMBO_BOX(selector), &iter);
+					break;
+				}
+				g_free(type_name_haystack);
+			}
+		} while (gtk_tree_model_iter_next(selector->priv->model, &iter));
+	}
+
+	return ret;
+}
\ No newline at end of file

Added: trunk/librawstudio/rs-color-space-selector.h
===================================================================
--- trunk/librawstudio/rs-color-space-selector.h	                        (rev 0)
+++ trunk/librawstudio/rs-color-space-selector.h	2010-02-14 15:59:28 UTC (rev 3224)
@@ -0,0 +1,60 @@
+/*
+ * * Copyright (C) 2006-2010 Anders Brander <anders at brander.dk>, 
+ * * Anders Kvist <akv at lnxbx.dk> and Klaus Post <klauspost at gmail.com>
+ *
+ * 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.
+ */
+
+#ifndef RSCOLOR_SPACE_SELECTOR_H
+#define RSCOLOR_SPACE_SELECTOR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define RS_TYPE_COLOR_SPACE_SELECTOR rs_color_space_selector_get_type()
+#define RS_COLOR_SPACE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_COLOR_SPACE_SELECTOR, RSColorSpaceSelector))
+#define RS_COLOR_SPACE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_COLOR_SPACE_SELECTOR, RSColorSpaceSelectorClass))
+#define RS_IS_COLOR_SPACE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_COLOR_SPACE_SELECTOR))
+#define RS_IS_COLOR_SPACE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RS_TYPE_COLOR_SPACE_SELECTOR))
+#define RS_COLOR_SPACE_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RS_TYPE_COLOR_SPACE_SELECTOR, RSColorSpaceSelectorClass))
+
+typedef struct _RSColorSpaceSelectorPrivate RSColorSpaceSelectorPrivate;
+
+typedef struct {
+	GtkComboBox parent;
+
+	RSColorSpaceSelectorPrivate *priv;
+} RSColorSpaceSelector;
+
+typedef struct {
+	GtkComboBoxClass parent_class;
+} RSColorSpaceSelectorClass;
+
+GType
+rs_color_space_selector_get_type(void);
+
+GtkWidget *
+rs_color_space_selector_new(void);
+
+void
+rs_color_space_selector_add_all(RSColorSpaceSelector *selector);
+
+RSColorSpace *
+rs_color_space_selector_set_selected_by_name(RSColorSpaceSelector *selector, const gchar *type_name);
+
+G_END_DECLS
+
+#endif /* RSCOLOR_SPACE_SELECTOR_H */

Modified: trunk/librawstudio/rs-output.c
===================================================================
--- trunk/librawstudio/rs-output.c	2010-02-14 15:22:54 UTC (rev 3223)
+++ trunk/librawstudio/rs-output.c	2010-02-14 15:59:28 UTC (rev 3224)
@@ -153,6 +153,21 @@
 		rs_conf_set_string(confpath, value);
 }
 
+static void
+colorspace_changed(RSColorSpaceSelector *selector, RSColorSpace *color_space, gpointer user_data)
+{
+	RSOutput *output = RS_OUTPUT(user_data);
+
+	const gchar *name = g_object_get_data(G_OBJECT(selector), "spec-name");
+	const gchar *confpath = g_object_get_data(G_OBJECT(selector), "conf-path");
+
+	if (name)
+		g_object_set(output, name, color_space, NULL);
+
+	if (confpath)
+		rs_conf_set_string(confpath, G_OBJECT_TYPE_NAME(color_space));
+}
+
 /**
  * Load parameters from config for a RSOutput
  * @param output A RSOutput
@@ -172,12 +187,25 @@
 	specs = g_object_class_list_properties(G_OBJECT_CLASS(klass), &n_specs);
 	for(i=0; i<n_specs; i++)
 	{
+		GType type = G_PARAM_SPEC_VALUE_TYPE(specs[i]);
 		gchar *confpath = NULL;
 
 		confpath = g_strdup_printf("%s:%s:%s", conf_prefix, G_OBJECT_TYPE_NAME(output), specs[i]->name);
 
-		switch (G_PARAM_SPEC_VALUE_TYPE(specs[i]))
+		if (type)
 		{
+			gchar *str;
+
+			if (confpath && (str = rs_conf_get_string(confpath)))
+			{
+				RSColorSpace *color_space;
+				color_space = rs_color_space_new_singleton(str);
+				if (color_space)
+					g_object_set(output, specs[i]->name, color_space, NULL);
+			}
+		}
+		else switch (type)
+		{
 			case G_TYPE_BOOLEAN:
 			{
 				gboolean boolean = FALSE;
@@ -224,6 +252,7 @@
 	GParamSpec **specs;
 	guint n_specs = 0;
 	gint i;
+	gchar *str;
 
 	/* Maintain a reference to the RSOutput */
 	g_object_ref(output);
@@ -250,7 +279,26 @@
 		if (type == GTK_TYPE_WIDGET)
 		{
 			g_object_get(output, specs[i]->name, &widget, NULL);
-		} 
+		}
+		else if (type == RS_TYPE_COLOR_SPACE)
+		{
+			widget = rs_color_space_selector_new();
+			g_object_set_data(G_OBJECT(widget), "spec-name", specs[i]->name);
+			g_object_set_data_full(G_OBJECT(widget), "conf-path", confpath, g_free);
+
+			rs_color_space_selector_add_all(RS_COLOR_SPACE_SELECTOR(widget));
+			rs_color_space_selector_set_selected_by_name(RS_COLOR_SPACE_SELECTOR(widget), "RSSrgb");
+
+			if (confpath && (str = rs_conf_get_string(confpath)))
+			{
+				RSColorSpace *color_space;
+				color_space = rs_color_space_selector_set_selected_by_name(RS_COLOR_SPACE_SELECTOR(widget), str);
+				if (color_space)
+					g_object_set(output, specs[i]->name, color_space, NULL);
+			}
+
+			g_signal_connect(widget, "colorspace-selected", G_CALLBACK(colorspace_changed), output);
+		}
 		else switch (type)
 		{
 			case G_TYPE_BOOLEAN:
@@ -305,7 +353,6 @@
 			}
 			case G_TYPE_STRING:
 			{
-				gchar *str;
 				GtkWidget *label = gtk_label_new(g_param_spec_get_blurb(specs[i]));
 				GtkWidget *entry = gtk_entry_new();
 




More information about the Rawstudio-commit mailing list