[gnome-color-manager] Add the color temperature into the profie viewer details



commit 79c12c672f8534ad7ff0403d0eeec00dc1895343
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 10 20:59:59 2010 +0100

    Add the color temperature into the profie viewer details

 data/gcm-viewer.ui            |   65 +++++++++++++++++++++++++++++++++++++++--
 libcolor-glib/gcm-profile.c   |   44 +++++++++++++++++++++++++++
 libcolor-glib/gcm-profile.h   |    1 +
 libcolor-glib/gcm-self-test.c |    2 +
 src/gcm-viewer.c              |   10 ++++++
 5 files changed, 119 insertions(+), 3 deletions(-)
---
diff --git a/data/gcm-viewer.ui b/data/gcm-viewer.ui
index eb6ee1b..089238d 100644
--- a/data/gcm-viewer.ui
+++ b/data/gcm-viewer.ui
@@ -843,6 +843,64 @@
                                           </packing>
                                         </child>
                                         <child>
+                                          <object class="GtkHBox" id="hbox_temp">
+                                            <property name="visible">True</property>
+                                            <property name="spacing">12</property>
+                                            <child>
+                                              <object class="GtkHBox" id="hbox1">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <object class="GtkLabel" id="label_title_temp">
+                                                    <property name="visible">True</property>
+                                                    <property name="label" translatable="yes" comments="The basename (the last section of the filename) of the profile">White point:</property>
+                                                    <attributes>
+                                                      <attribute name="weight" value="bold"/>
+                                                    </attributes>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="pack_type">end</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkHBox" id="hbox2">
+                                                <property name="visible">True</property>
+                                                <child>
+                                                  <object class="GtkLabel" id="label_temp">
+                                                    <property name="visible">True</property>
+                                                    <property name="label">3000°K</property>
+                                                    <property name="use_markup">True</property>
+                                                    <property name="wrap">True</property>
+                                                    <property name="wrap_mode">word-char</property>
+                                                    <property name="selectable">True</property>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="padding">3</property>
+                                            <property name="position">6</property>
+                                          </packing>
+                                        </child>
+                                        <child>
                                           <object class="GtkHBox" id="hbox_copyright">
                                             <property name="visible">True</property>
                                             <property name="spacing">12</property>
@@ -896,7 +954,7 @@
                                             <property name="expand">False</property>
                                             <property name="fill">False</property>
                                             <property name="padding">3</property>
-                                            <property name="position">6</property>
+                                            <property name="position">7</property>
                                           </packing>
                                         </child>
                                         <child>
@@ -953,7 +1011,7 @@
                                             <property name="expand">False</property>
                                             <property name="fill">False</property>
                                             <property name="padding">3</property>
-                                            <property name="position">7</property>
+                                            <property name="position">8</property>
                                           </packing>
                                         </child>
                                         <child>
@@ -1011,7 +1069,7 @@
                                             <property name="expand">False</property>
                                             <property name="fill">False</property>
                                             <property name="padding">3</property>
-                                            <property name="position">8</property>
+                                            <property name="position">9</property>
                                           </packing>
                                         </child>
                                       </object>
@@ -1126,6 +1184,7 @@
       <widget name="hbox6"/>
       <widget name="hbox61"/>
       <widget name="hbox19"/>
+      <widget name="hbox1"/>
     </widgets>
   </object>
 </interface>
diff --git a/libcolor-glib/gcm-profile.c b/libcolor-glib/gcm-profile.c
index e5958d4..3513147 100644
--- a/libcolor-glib/gcm-profile.c
+++ b/libcolor-glib/gcm-profile.c
@@ -63,6 +63,7 @@ struct _GcmProfilePrivate
 	gchar			*model;
 	gchar			*datetime;
 	gchar			*checksum;
+	guint			 temperature;
 	GcmColorXYZ		*white;
 	GcmColorXYZ		*black;
 	GcmColorXYZ		*red;
@@ -93,6 +94,7 @@ enum {
 	PROP_RED,
 	PROP_GREEN,
 	PROP_BLUE,
+	PROP_TEMPERATURE,
 	PROP_LAST
 };
 
@@ -203,6 +205,23 @@ gcm_profile_has_colorspace_description (GcmProfile *profile)
 }
 
 /**
+ * gcm_profile_get_temperature:
+ * @profile: A valid #GcmProfile
+ *
+ * Gets the profile color temperature, rounded to the nearest 100K.
+ *
+ * Return value: The color temperature in Kelvins, or 0 for error.
+ *
+ * Since: 0.0.1
+ **/
+guint
+gcm_profile_get_temperature (GcmProfile *profile)
+{
+	g_return_val_if_fail (GCM_IS_PROFILE (profile), 0);
+	return profile->priv->temperature;
+}
+
+/**
  * gcm_profile_get_file:
  * @profile: A valid #GcmProfile
  *
@@ -634,8 +653,22 @@ gcm_profile_parse_data (GcmProfile *profile, const guint8 *data, gsize length, G
 	/* get white point */
 	cie_xyz = cmsReadTag (priv->lcms_profile, cmsSigMediaWhitePointTag);
 	if (cie_xyz != NULL) {
+		GcmColorYxy yxy;
+		cmsCIExyY xyY;
+		gdouble temp_float;
 		gcm_color_set_XYZ (priv->white,
 				   cie_xyz->X, cie_xyz->Y, cie_xyz->Z);
+
+		/* convert to lcms xyY values */
+		gcm_color_convert_XYZ_to_Yxy (priv->white, &yxy);
+		xyY.x = yxy.x;
+		xyY.y = yxy.y;
+		xyY.Y = yxy.Y;
+		cmsTempFromWhitePoint (&temp_float, &xyY);
+
+		/* round to nearest 100K */
+		priv->temperature = (((guint) temp_float) / 100) * 100;
+
 	} else {
 		gcm_color_clear_XYZ (priv->white);
 		egg_warning ("failed to get white point");
@@ -1262,6 +1295,9 @@ gcm_profile_get_property (GObject *object, guint prop_id, GValue *value, GParamS
 	case PROP_BLUE:
 		g_value_set_boxed (value, g_boxed_copy (GCM_TYPE_COLOR_XYZ, priv->blue));
 		break;
+	case PROP_TEMPERATURE:
+		g_value_set_uint (value, priv->temperature);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -1477,6 +1513,14 @@ gcm_profile_class_init (GcmProfileClass *klass)
 				    G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_BLUE, pspec);
 
+	/**
+	 * GcmProfile:temperature:
+	 */
+	pspec = g_param_spec_uint ("temperature", NULL, NULL,
+				   0, G_MAXUINT, 0,
+				   G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_TEMPERATURE, pspec);
+
 	g_type_class_add_private (klass, sizeof (GcmProfilePrivate));
 }
 
diff --git a/libcolor-glib/gcm-profile.h b/libcolor-glib/gcm-profile.h
index 92fc9d0..7812db2 100644
--- a/libcolor-glib/gcm-profile.h
+++ b/libcolor-glib/gcm-profile.h
@@ -118,6 +118,7 @@ void		 gcm_profile_set_colorspace		(GcmProfile	*profile,
 							 GcmColorspace	 colorspace);
 gboolean	 gcm_profile_get_has_vcgt		(GcmProfile	*profile);
 gboolean	 gcm_profile_has_colorspace_description	(GcmProfile	*profile);
+guint		 gcm_profile_get_temperature		(GcmProfile	*profile);
 
 G_END_DECLS
 
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index 799f2f5..ff3e8a9 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -363,6 +363,7 @@ gcm_test_profile_func (void)
 	g_assert_cmpstr (gcm_profile_get_checksum (profile), ==, "8e2aed5dac6f8b5d8da75610a65b7f27");
 	g_assert_cmpint (gcm_profile_get_kind (profile), ==, GCM_PROFILE_KIND_DISPLAY_DEVICE);
 	g_assert_cmpint (gcm_profile_get_colorspace (profile), ==, GCM_COLORSPACE_RGB);
+	g_assert_cmpint (gcm_profile_get_temperature (profile), ==, 6500);
 	g_assert (gcm_profile_get_has_vcgt (profile));
 
 	/* get extra data */
@@ -393,6 +394,7 @@ gcm_test_profile_func (void)
 	g_assert_cmpstr (gcm_profile_get_checksum (profile), ==, "bd847723f676e2b846daaf6759330624");
 	g_assert_cmpint (gcm_profile_get_kind (profile), ==, GCM_PROFILE_KIND_DISPLAY_DEVICE);
 	g_assert_cmpint (gcm_profile_get_colorspace (profile), ==, GCM_COLORSPACE_RGB);
+	g_assert_cmpint (gcm_profile_get_temperature (profile), ==, 6500);
 	g_assert (gcm_profile_get_has_vcgt (profile));
 
 	g_object_unref (profile);
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index 00c764e..873e48f 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -645,6 +645,7 @@ gcm_viewer_profiles_treeview_clicked_cb (GtkTreeSelection *selection, GcmViewerP
 	gboolean ret;
 	gboolean has_vcgt;
 	guint size = 0;
+	guint temperature;
 	guint filesize;
 	gboolean show_section = FALSE;
 
@@ -759,6 +760,15 @@ gcm_viewer_profiles_treeview_clicked_cb (GtkTreeSelection *selection, GcmViewerP
 	gtk_label_set_label (GTK_LABEL (widget), temp);
 	g_free (temp);
 
+	/* set whitepoint */
+	temperature = gcm_profile_get_temperature (profile);
+	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "label_temp"));
+	temp = g_strdup_printf ("%i°K", temperature);
+	gtk_label_set_label (GTK_LABEL (widget), temp);
+	g_free (temp);
+	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "hbox_temp"));
+	gtk_widget_set_visible (widget, (temperature > 0));
+
 	/* set size */
 	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "hbox_size"));
 	filesize = gcm_profile_get_size (profile);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]