[gnome-color-manager: 76/80] trivial: Split out the color routines as a seporate file



commit 782fc875e5c2a9304aad723d10daed522dc30821
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jul 19 11:30:07 2010 +0100

    trivial: Split out the color routines as a seporate file

 libcolor-glib/Makefile.am        |    3 +
 libcolor-glib/gcm-color.c        |  157 ++++++++++++++++++++++++++++++++++++++
 libcolor-glib/gcm-color.h        |   77 +++++++++++++++++++
 libcolor-glib/gcm-common.c       |  111 +--------------------------
 libcolor-glib/gcm-common.h       |   42 ----------
 libcolor-glib/gcm-self-test.c    |   68 ++++++++--------
 libcolor-glib/gcm-sensor-dummy.c |    4 +-
 libcolor-glib/gcm-sensor-huey.c  |   47 ++++++------
 libcolor-glib/gcm-sensor.h       |    2 +-
 libcolor-glib/libcolor-glib.h    |    1 +
 src/gcm-picker.c                 |    8 +-
 11 files changed, 306 insertions(+), 214 deletions(-)
---
diff --git a/libcolor-glib/Makefile.am b/libcolor-glib/Makefile.am
index 3c1aae7..34c32d8 100644
--- a/libcolor-glib/Makefile.am
+++ b/libcolor-glib/Makefile.am
@@ -33,6 +33,7 @@ libcolor_glib_includedir = $(includedir)/libcolor-glib
 libcolor_glib_include_HEADERS =					\
 	libcolor-glib.h						\
 	gcm-common.h						\
+	gcm-color.h						\
 	gcm-ddc-client.h					\
 	gcm-ddc-device.h					\
 	gcm-ddc-control.h					\
@@ -55,6 +56,8 @@ libcolor_glib_la_SOURCES =					\
 	egg-debug.h						\
 	gcm-common.c						\
 	gcm-common.h						\
+	gcm-color.c						\
+	gcm-color.h						\
 	gcm-sensor.c						\
 	gcm-sensor.h						\
 	gcm-sensor-client.c					\
diff --git a/libcolor-glib/gcm-color.c b/libcolor-glib/gcm-color.c
new file mode 100644
index 0000000..c6b7bb2
--- /dev/null
+++ b/libcolor-glib/gcm-color.c
@@ -0,0 +1,157 @@
+/* -*- 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 Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+/**
+ * SECTION:gcm-color
+ * @short_description: color functionality
+ *
+ * Functions to manipulate color.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <glib-object.h>
+
+#include <gcm-color.h>
+
+/**
+ * gcm_color_copy_XYZ:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Deep copies a color value.
+ **/
+void
+gcm_color_copy_XYZ (GcmColorXYZ *src, GcmColorXYZ *dest)
+{
+	dest->X = src->X;
+	dest->Y = src->Y;
+	dest->Z = src->Z;
+}
+
+/**
+ * gcm_color_copy_RGB:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Deep copies a color value.
+ **/
+void
+gcm_color_copy_RGB (GcmColorRGB *src, GcmColorRGB *dest)
+{
+	dest->R = src->R;
+	dest->G = src->G;
+	dest->B = src->B;
+}
+
+/**
+ * gcm_color_convert_RGBint_to_RGB:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Convert from one color format to another.
+ **/
+void
+gcm_color_convert_RGBint_to_RGB (GcmColorRGBint *rgb_int, GcmColorRGB *rgb)
+{
+	rgb->R = (gdouble) rgb_int->R / 255.0f;
+	rgb->G = (gdouble) rgb_int->G / 255.0f;
+	rgb->B = (gdouble) rgb_int->B / 255.0f;
+}
+
+/**
+ * gcm_color_convert_RGB_to_RGBint:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Convert from one color format to another.
+ **/
+void
+gcm_color_convert_RGB_to_RGBint (GcmColorRGB *rgb, GcmColorRGBint *rgb_int)
+{
+	rgb_int->R = (gdouble) rgb->R * 255.0f;
+	rgb_int->G = (gdouble) rgb->G * 255.0f;
+	rgb_int->B = (gdouble) rgb->B * 255.0f;
+}
+
+/**
+ * gcm_color_convert_Yxy_to_XYZ:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Convert from one color format to another.
+ **/
+void
+gcm_color_convert_Yxy_to_XYZ (GcmColorYxy *src, GcmColorXYZ *dest)
+{
+	g_assert (src->Y >= 0.0f);
+	g_assert (src->x >= 0.0f);
+	g_assert (src->y >= 0.0f);
+	g_assert (src->Y <= 100.0f);
+	g_assert (src->x <= 1.0f);
+	g_assert (src->y <= 1.0f);
+
+	/* very small luminance */
+	if (src->Y < 1e-6) {
+		dest->X = 0.0f;
+		dest->Y = 0.0f;
+		dest->Z = 0.0f;
+		return;
+	}
+
+	dest->X = (src->x * src->Y) / src->y;
+	dest->Y = src->Y;
+	dest->Z = (1.0f - src->x - src->y) * src->Y / src->y;
+}
+
+/**
+ * gcm_color_convert_XYZ_to_Yxy:
+ * @src: the source color
+ * @dest: the destination color
+ *
+ * Convert from one color format to another.
+ **/
+void
+gcm_color_convert_XYZ_to_Yxy (GcmColorXYZ *src, GcmColorYxy *dest)
+{
+	gdouble sum;
+
+	g_assert (src->X >= 0.0f);
+	g_assert (src->Y >= 0.0f);
+	g_assert (src->Z >= 0.0f);
+	g_assert (src->X < 96.0f);
+	g_assert (src->Y < 100.0f);
+	g_assert (src->Z < 109.0f);
+
+	/* prevent division by zero */
+	sum = src->X + src->Y + src->Z;
+	if (fabs (sum) < 1e-6) {
+		dest->Y = 0.0f;
+		dest->x = 0.0f;
+		dest->y = 0.0f;
+		return;
+	}
+
+	dest->Y = src->Y;
+	dest->x = src->X / sum;
+	dest->y = src->Y / sum;
+}
diff --git a/libcolor-glib/gcm-color.h b/libcolor-glib/gcm-color.h
new file mode 100644
index 0000000..a6ed886
--- /dev/null
+++ b/libcolor-glib/gcm-color.h
@@ -0,0 +1,77 @@
+/* -*- 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_COLOR_H__
+#define __GCM_COLOR_H__
+
+#define __GCM_COLOR_H_INSIDE__
+
+typedef struct {
+	guint8	 R;
+	guint8	 G;
+	guint8	 B;
+} GcmColorRGBint;
+
+typedef struct {
+	gdouble	 L;
+	gdouble	 a;
+	gdouble	 b;
+} GcmColorLab;
+
+typedef struct {
+	gdouble	 Y;
+	gdouble	 x;
+	gdouble	 y;
+} GcmColorYxy;
+
+typedef struct {
+	gdouble	 X;
+	gdouble	 Y;
+	gdouble	 Z;
+} GcmColorXYZ;
+
+typedef struct {
+	gdouble	 R;
+	gdouble	 G;
+	gdouble	 B;
+} GcmColorRGB;
+
+void		 gcm_color_copy_XYZ			(GcmColorXYZ		*src,
+							 GcmColorXYZ		*dest);
+void		 gcm_color_copy_RGB			(GcmColorRGB		*src,
+							 GcmColorRGB		*dest);
+void		 gcm_color_convert_RGBint_to_RGB	(GcmColorRGBint		*rgb_int,
+							 GcmColorRGB		*rgb);
+void		 gcm_color_convert_RGB_to_RGBint	(GcmColorRGB		*rgb,
+							 GcmColorRGBint		*rgb_int);
+void		 gcm_color_convert_Yxy_to_XYZ		(GcmColorYxy		*src,
+							 GcmColorXYZ		*dest);
+void		 gcm_color_convert_XYZ_to_Yxy		(GcmColorXYZ		*src,
+							 GcmColorYxy		*dest);
+
+#undef __GCM_COLOR_H_INSIDE__
+
+#endif /* __GCM_COLOR_H__ */
+
diff --git a/libcolor-glib/gcm-common.c b/libcolor-glib/gcm-common.c
index 0e1a063..04c29bc 100644
--- a/libcolor-glib/gcm-common.c
+++ b/libcolor-glib/gcm-common.c
@@ -21,9 +21,9 @@
 
 /**
  * SECTION:gcm-common
- * @short_description: Common functionality
+ * @short_description: Common maths functionality
  *
- * A GObject to use for common shizzle.
+ * A GObject to use for common maths functionality like vectors and matrices.
  */
 
 #include "config.h"
@@ -34,113 +34,6 @@
 #include <gcm-common.h>
 
 /**
- * gcm_color_copy_XYZ:
- * @src: the source color.
- * @dest: the destination color
- *
- * Deep copies a color value.
- **/
-void
-gcm_color_copy_XYZ (GcmColorXYZ *src, GcmColorXYZ *dest)
-{
-	dest->X = src->X;
-	dest->Y = src->Y;
-	dest->Z = src->Z;
-}
-
-/**
- * gcm_color_copy_RGB:
- * @src: the source color.
- * @dest: the destination color
- *
- * Deep copies a color value.
- **/
-void
-gcm_color_copy_RGB (GcmColorRgb *src, GcmColorRgb *dest)
-{
-	dest->red = src->red;
-	dest->green = src->green;
-	dest->blue = src->blue;
-}
-
-/**
- * gcm_convert_rgb_int_to_rgb:
- **/
-void
-gcm_convert_rgb_int_to_rgb (GcmColorRgbInt *rgb_int, GcmColorRgb *rgb)
-{
-	rgb->red = (gdouble) rgb_int->red / 255.0f;
-	rgb->green = (gdouble) rgb_int->green / 255.0f;
-	rgb->blue = (gdouble) rgb_int->blue / 255.0f;
-}
-
-/**
- * gcm_convert_rgb_to_rgb_int:
- **/
-void
-gcm_convert_rgb_to_rgb_int (GcmColorRgb *rgb, GcmColorRgbInt *rgb_int)
-{
-	rgb_int->red = (gdouble) rgb->red * 255.0f;
-	rgb_int->green = (gdouble) rgb->green * 255.0f;
-	rgb_int->blue = (gdouble) rgb->blue * 255.0f;
-}
-
-/**
- * gcm_convert_Yxy_to_XYZ:
- **/
-void
-gcm_convert_Yxy_to_XYZ (GcmColorYxy *src, GcmColorXYZ *dest)
-{
-	g_assert (src->Y >= 0.0f);
-	g_assert (src->x >= 0.0f);
-	g_assert (src->y >= 0.0f);
-	g_assert (src->Y <= 100.0f);
-	g_assert (src->x <= 1.0f);
-	g_assert (src->y <= 1.0f);
-
-	/* very small luminance */
-	if (src->Y < 1e-6) {
-		dest->X = 0.0f;
-		dest->Y = 0.0f;
-		dest->Z = 0.0f;
-		return;
-	}
-
-	dest->X = (src->x * src->Y) / src->y;
-	dest->Y = src->Y;
-	dest->Z = (1.0f - src->x - src->y) * src->Y / src->y;
-}
-
-/**
- * gcm_convert_XYZ_to_Yxy:
- **/
-void
-gcm_convert_XYZ_to_Yxy (GcmColorXYZ *src, GcmColorYxy *dest)
-{
-	gdouble sum;
-
-	g_assert (src->X >= 0.0f);
-	g_assert (src->Y >= 0.0f);
-	g_assert (src->Z >= 0.0f);
-	g_assert (src->X < 96.0f);
-	g_assert (src->Y < 100.0f);
-	g_assert (src->Z < 109.0f);
-
-	/* prevent division by zero */
-	sum = src->X + src->Y + src->Z;
-	if (fabs (sum) < 1e-6) {
-		dest->Y = 0.0f;
-		dest->x = 0.0f;
-		dest->y = 0.0f;
-		return;
-	}
-
-	dest->Y = src->Y;
-	dest->x = src->X / sum;
-	dest->y = src->Y / sum;
-}
-
-/**
  * gcm_vec3_clear:
  **/
 void
diff --git a/libcolor-glib/gcm-common.h b/libcolor-glib/gcm-common.h
index 1b9adb9..4cb20f0 100644
--- a/libcolor-glib/gcm-common.h
+++ b/libcolor-glib/gcm-common.h
@@ -29,36 +29,6 @@
 #define __GCM_COMMON_H_INSIDE__
 
 typedef struct {
-	guint8	 red;
-	guint8	 green;
-	guint8	 blue;
-} GcmColorRgbInt;
-
-typedef struct {
-	gdouble	 L;
-	gdouble	 a;
-	gdouble	 b;
-} GcmColorLab;
-
-typedef struct {
-	gdouble	 Y;
-	gdouble	 x;
-	gdouble	 y;
-} GcmColorYxy;
-
-typedef struct {
-	gdouble	 X;
-	gdouble	 Y;
-	gdouble	 Z;
-} GcmColorXYZ;
-
-typedef struct {
-	gdouble	 red;
-	gdouble	 green;
-	gdouble	 blue;
-} GcmColorRgb;
-
-typedef struct {
 	gdouble	 m00, m01, m02;
 	gdouble	 m10, m11, m12;
 	gdouble	 m20, m21, m22;
@@ -70,18 +40,6 @@ typedef struct {
 	/* any addition fields go *after* the data */
 } GcmVec3;
 
-void		 gcm_color_copy_XYZ		(GcmColorXYZ		*src,
-						 GcmColorXYZ		*dest);
-void		 gcm_color_copy_RGB		(GcmColorRgb		*src,
-						 GcmColorRgb		*dest);
-void		 gcm_convert_rgb_int_to_rgb	(GcmColorRgbInt		*rgb_int,
-						 GcmColorRgb		*rgb);
-void		 gcm_convert_rgb_to_rgb_int	(GcmColorRgb		*rgb,
-						 GcmColorRgbInt		*rgb_int);
-void		 gcm_convert_Yxy_to_XYZ		(GcmColorYxy		*src,
-						 GcmColorXYZ		*dest);
-void		 gcm_convert_XYZ_to_Yxy		(GcmColorXYZ		*src,
-						 GcmColorYxy		*dest);
 void		 gcm_vec3_clear			(GcmVec3		*src);
 void		 gcm_vec3_scalar_multiply	(GcmVec3		*src,
 						 gdouble		 value,
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index b0569c4..3d4eea9 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -41,51 +41,51 @@
 static void
 gcm_test_common_func (void)
 {
-	GcmColorRgbInt rgb_int;
-	GcmColorRgb rgb;
+	GcmColorRGBint rgb_int;
+	GcmColorRGB rgb;
 	GcmColorYxy Yxy;
 	GcmColorXYZ XYZ;
 	GcmMat3x3 mat;
 	GcmMat3x3 matsrc;
 
 	/* black */
-	rgb_int.red = 0x00; rgb_int.green = 0x00; rgb_int.blue = 0x00;
-	gcm_convert_rgb_int_to_rgb (&rgb_int, &rgb);
-	g_assert_cmpfloat (rgb.red, <, 0.01);
-	g_assert_cmpfloat (rgb.green, <, 0.01);
-	g_assert_cmpfloat (rgb.blue, <, 0.01);
-	g_assert_cmpfloat (rgb.red, >, -0.01);
-	g_assert_cmpfloat (rgb.green, >, -0.01);
-	g_assert_cmpfloat (rgb.blue, >, -0.01);
+	rgb_int.R = 0x00; rgb_int.G = 0x00; rgb_int.B = 0x00;
+	gcm_color_convert_RGBint_to_RGB (&rgb_int, &rgb);
+	g_assert_cmpfloat (rgb.R, <, 0.01);
+	g_assert_cmpfloat (rgb.G, <, 0.01);
+	g_assert_cmpfloat (rgb.B, <, 0.01);
+	g_assert_cmpfloat (rgb.R, >, -0.01);
+	g_assert_cmpfloat (rgb.G, >, -0.01);
+	g_assert_cmpfloat (rgb.B, >, -0.01);
 
 	/* white */
-	rgb_int.red = 0xff; rgb_int.green = 0xff; rgb_int.blue = 0xff;
-	gcm_convert_rgb_int_to_rgb (&rgb_int, &rgb);
-	g_assert_cmpfloat (rgb.red, <, 1.01);
-	g_assert_cmpfloat (rgb.green, <, 1.01);
-	g_assert_cmpfloat (rgb.blue, <, 1.01);
-	g_assert_cmpfloat (rgb.red, >, 0.99);
-	g_assert_cmpfloat (rgb.green, >, 0.99);
-	g_assert_cmpfloat (rgb.blue, >, 0.99);
+	rgb_int.R = 0xff; rgb_int.G = 0xff; rgb_int.B = 0xff;
+	gcm_color_convert_RGBint_to_RGB (&rgb_int, &rgb);
+	g_assert_cmpfloat (rgb.R, <, 1.01);
+	g_assert_cmpfloat (rgb.G, <, 1.01);
+	g_assert_cmpfloat (rgb.B, <, 1.01);
+	g_assert_cmpfloat (rgb.R, >, 0.99);
+	g_assert_cmpfloat (rgb.G, >, 0.99);
+	g_assert_cmpfloat (rgb.B, >, 0.99);
 
 	/* and back */
-	gcm_convert_rgb_to_rgb_int (&rgb, &rgb_int);
-	g_assert_cmpint (rgb_int.red, ==, 0xff);
-	g_assert_cmpint (rgb_int.green, ==, 0xff);
-	g_assert_cmpint (rgb_int.blue, ==, 0xff);
+	gcm_color_convert_RGB_to_RGBint (&rgb, &rgb_int);
+	g_assert_cmpint (rgb_int.R, ==, 0xff);
+	g_assert_cmpint (rgb_int.G, ==, 0xff);
+	g_assert_cmpint (rgb_int.B, ==, 0xff);
 
 	/* black */
-	rgb.red = 0.0f; rgb.green = 0.0f; rgb.blue = 0.0f;
-	gcm_convert_rgb_to_rgb_int (&rgb, &rgb_int);
-	g_assert_cmpint (rgb_int.red, ==, 0x00);
-	g_assert_cmpint (rgb_int.green, ==, 0x00);
-	g_assert_cmpint (rgb_int.blue, ==, 0x00);
+	rgb.R = 0.0f; rgb.G = 0.0f; rgb.B = 0.0f;
+	gcm_color_convert_RGB_to_RGBint (&rgb, &rgb_int);
+	g_assert_cmpint (rgb_int.R, ==, 0x00);
+	g_assert_cmpint (rgb_int.G, ==, 0x00);
+	g_assert_cmpint (rgb_int.B, ==, 0x00);
 
 	/* Yxy -> XYZ */
 	Yxy.Y = 21.5;
 	Yxy.x = 0.31;
 	Yxy.y = 0.32;
-	gcm_convert_Yxy_to_XYZ (&Yxy, &XYZ);
+	gcm_color_convert_Yxy_to_XYZ (&Yxy, &XYZ);
 	g_assert_cmpfloat (XYZ.X, <, 21.0);
 	g_assert_cmpfloat (XYZ.X, >, 20.5);
 	g_assert_cmpfloat (XYZ.Y, <, 22.0);
@@ -94,7 +94,7 @@ gcm_test_common_func (void)
 	g_assert_cmpfloat (XYZ.Z, >, 24.5);
 
 	/* and back */
-	gcm_convert_XYZ_to_Yxy (&XYZ, &Yxy);
+	gcm_color_convert_XYZ_to_Yxy (&XYZ, &Yxy);
 	g_assert_cmpfloat (Yxy.Y, <, 22.0);
 	g_assert_cmpfloat (Yxy.Y, >, 21.0);
 	g_assert_cmpfloat (Yxy.x, <, 0.35);
@@ -156,13 +156,13 @@ gcm_test_sensor_func (void)
 	/* start sensor */
 	sensor = gcm_sensor_dummy_new ();
 	ret = gcm_sensor_startup (sensor, &error);
-	g_assert (ret);
 	g_assert_no_error (error);
+	g_assert (ret);
 
 	/* set LEDs */
 	ret = gcm_sensor_set_leds (sensor, 0x0f, &error);
-	g_assert (ret);
 	g_assert_no_error (error);
+	g_assert (ret);
 
 	/* set mode */
 	gcm_sensor_set_output_type (sensor, GCM_SENSOR_OUTPUT_TYPE_LCD);
@@ -170,20 +170,20 @@ gcm_test_sensor_func (void)
 
 	/* get ambient */
 	ret = gcm_sensor_get_ambient (sensor, &value, &error);
-	g_assert (ret);
 	g_assert_no_error (error);
+	g_assert (ret);
 	g_debug ("ambient = %.1lf Lux", value);
 
 	/* sample color */
 	ret = gcm_sensor_sample (sensor, &values, &error);
-	g_assert (ret);
 	g_assert_no_error (error);
+	g_assert (ret);
 	g_debug ("X=%0.4lf, Y=%0.4lf, Z=%0.4lf", values.X, values.Y, values.Z);
 
 	/* set LEDs */
 	ret = gcm_sensor_set_leds (sensor, 0x00, &error);
-	g_assert (ret);
 	g_assert_no_error (error);
+	g_assert (ret);
 
 	g_object_unref (sensor);
 }
diff --git a/libcolor-glib/gcm-sensor-dummy.c b/libcolor-glib/gcm-sensor-dummy.c
index fe5c2ce..5b93f2c 100644
--- a/libcolor-glib/gcm-sensor-dummy.c
+++ b/libcolor-glib/gcm-sensor-dummy.c
@@ -106,7 +106,9 @@ GcmSensor *
 gcm_sensor_dummy_new (void)
 {
 	GcmSensorDummy *sensor;
-	sensor = g_object_new (GCM_TYPE_SENSOR_DUMMY, NULL);
+	sensor = g_object_new (GCM_TYPE_SENSOR_DUMMY,
+			       "native", TRUE,
+			       NULL);
 	return GCM_SENSOR (sensor);
 }
 
diff --git a/libcolor-glib/gcm-sensor-huey.c b/libcolor-glib/gcm-sensor-huey.c
index a94fa10..ede0393 100644
--- a/libcolor-glib/gcm-sensor-huey.c
+++ b/libcolor-glib/gcm-sensor-huey.c
@@ -31,6 +31,7 @@
 #include <glib-object.h>
 #include <libusb-1.0/libusb.h>
 
+#include "gcm-common.h"
 #include "gcm-sensor-huey.h"
 
 static void     gcm_sensor_huey_finalize	(GObject     *object);
@@ -594,9 +595,9 @@ gcm_sensor_huey_set_leds (GcmSensor *sensor, guint8 value, GError **error)
  * gcm_sensor_huey_sample_for_threshold:
  **/
 static gboolean
-gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmColorRgbInt *threshold, GcmColorRgb *values, GError **error)
+gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmColorRGBint *threshold, GcmColorRGB *values, GError **error)
 {
-	guchar request[] = { HUEY_COMMAND_SENSOR_MEASURE_RGB, 0x00, threshold->red, 0x00, threshold->green, 0x00, threshold->blue, 0x00 };
+	guchar request[] = { HUEY_COMMAND_SENSOR_MEASURE_RGB, 0x00, threshold->R, 0x00, threshold->G, 0x00, threshold->B, 0x00 };
 	guchar reply[8];
 	gboolean ret;
 	gsize reply_read;
@@ -607,7 +608,7 @@ gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmColorRgbInt
 		goto out;
 
 	/* get value */
-	values->red = 1.0f / ((reply[3] * 0xff) + reply[4]);
+	values->R = 1.0f / ((reply[3] * 0xff) + reply[4]);
 
 	/* get green */
 	request[0] = HUEY_COMMAND_READ_GREEN;
@@ -616,7 +617,7 @@ gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmColorRgbInt
 		goto out;
 
 	/* get value */
-	values->green = 1.0f / ((reply[3] * 0xff) + reply[4]);
+	values->G = 1.0f / ((reply[3] * 0xff) + reply[4]);
 
 	/* get blue */
 	request[0] = HUEY_COMMAND_READ_BLUE;
@@ -625,7 +626,7 @@ gcm_sensor_huey_sample_for_threshold (GcmSensorHuey *sensor_huey, GcmColorRgbInt
 		goto out;
 
 	/* get value */
-	values->blue = 1.0f / ((reply[3] * 0xff) + reply[4]);
+	values->B = 1.0f / ((reply[3] * 0xff) + reply[4]);
 out:
 	return ret;
 }
@@ -638,38 +639,38 @@ gcm_sensor_huey_sample (GcmSensor *sensor, GcmColorXYZ *value, GError **error)
 {
 	gboolean ret;
 	gdouble precision_value;
-	GcmColorRgb native;
-	GcmColorRgbInt multiplier;
+	GcmColorRGB native;
+	GcmColorRGBint multiplier;
 	GcmVec3 *input = (GcmVec3 *) &native;
 	GcmVec3 *output = (GcmVec3 *) value;
 	GcmSensorHuey *sensor_huey = GCM_SENSOR_HUEY (sensor);
 
 	/* set this to one value for a quick approximate value */
-	multiplier.red = 1;
-	multiplier.green = 1;
-	multiplier.blue = 1;
+	multiplier.R = 1;
+	multiplier.G = 1;
+	multiplier.B = 1;
 	ret = gcm_sensor_huey_sample_for_threshold (sensor_huey, &multiplier, &native, error);
 	if (!ret)
 		goto out;
-	g_debug ("initial values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.red, native.green, native.blue);
+	g_debug ("initial values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.R, native.G, native.B);
 
 	/* compromise between the amount of time and the precision */
 	precision_value = (gdouble) HUEY_PRECISION_TIME_VALUE;
-	if (native.red < precision_value)
-		multiplier.red = precision_value / native.red;
-	if (native.green < precision_value)
-		multiplier.green = precision_value / native.green;
-	if (native.blue < precision_value)
-		multiplier.blue = precision_value / native.blue;
-	g_debug ("using multiplier factor: red=%i, green=%i, blue=%i", multiplier.red, multiplier.green, multiplier.blue);
+	if (native.R < precision_value)
+		multiplier.R = precision_value / native.R;
+	if (native.G < precision_value)
+		multiplier.G = precision_value / native.G;
+	if (native.B < precision_value)
+		multiplier.B = precision_value / native.B;
+	g_debug ("using multiplier factor: red=%i, green=%i, blue=%i", multiplier.R, multiplier.G, multiplier.B);
 	ret = gcm_sensor_huey_sample_for_threshold (sensor_huey, &multiplier, &native, error);
 	if (!ret)
 		goto out;
-	g_debug ("prescaled values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.red, native.green, native.blue);
-	native.red = native.red * (gdouble)multiplier.red;
-	native.green = native.green * (gdouble)multiplier.green;
-	native.blue = native.blue * (gdouble)multiplier.blue;
-	g_debug ("scaled values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.red, native.green, native.blue);
+	g_debug ("prescaled values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.R, native.G, native.B);
+	native.R = native.R * (gdouble)multiplier.R;
+	native.G = native.G * (gdouble)multiplier.G;
+	native.B = native.B * (gdouble)multiplier.B;
+	g_debug ("scaled values: red=%0.4lf, green=%0.4lf, blue=%0.4lf", native.R, native.G, native.B);
 
 	g_print ("PRE MULTIPLY: %s\n", gcm_vec3_to_string (input));
 
diff --git a/libcolor-glib/gcm-sensor.h b/libcolor-glib/gcm-sensor.h
index ec46885..6ef1ede 100644
--- a/libcolor-glib/gcm-sensor.h
+++ b/libcolor-glib/gcm-sensor.h
@@ -29,7 +29,7 @@
 #include <glib-object.h>
 #include <gudev/gudev.h>
 
-#include <gcm-common.h>
+#include <gcm-color.h>
 
 G_BEGIN_DECLS
 
diff --git a/libcolor-glib/libcolor-glib.h b/libcolor-glib/libcolor-glib.h
index f3f887c..d5e94f6 100644
--- a/libcolor-glib/libcolor-glib.h
+++ b/libcolor-glib/libcolor-glib.h
@@ -29,6 +29,7 @@
 #define __LIBCOLOR_GLIB_H_INSIDE__
 
 #include <gcm-common.h>
+#include <gcm-color.h>
 #include <gcm-ddc-common.h>
 #include <gcm-ddc-device.h>
 #include <gcm-ddc-client.h>
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
index 5c69800..793a4c6 100644
--- a/src/gcm-picker.c
+++ b/src/gcm-picker.c
@@ -90,7 +90,7 @@ gcm_picker_refresh_results (void)
 	GtkImage *image;
 	GtkLabel *label;
 	GdkPixbuf *pixbuf = NULL;
-	GcmColorRgbInt color_rgb;
+	GcmColorRGBint color_rgb;
 	GcmColorLab color_lab;
 	GcmColorXYZ color_xyz;
 	GcmColorXYZ color_error;
@@ -151,10 +151,10 @@ gcm_picker_refresh_results (void)
 	/* set RGB */
 	label = GTK_LABEL (gtk_builder_get_object (builder, "label_rgb"));
 	text_rgb = g_strdup_printf ("%i, %i, %i (#%02X%02X%02X)",
-				    color_rgb.red, color_rgb.green, color_rgb.blue,
-				    color_rgb.red, color_rgb.green, color_rgb.blue);
+				    color_rgb.R, color_rgb.G, color_rgb.B,
+				    color_rgb.R, color_rgb.G, color_rgb.B);
 	gtk_label_set_label (label, text_rgb);
-	gcm_picker_set_pixbuf_color (pixbuf, color_rgb.red, color_rgb.green, color_rgb.blue);
+	gcm_picker_set_pixbuf_color (pixbuf, color_rgb.R, color_rgb.G, color_rgb.B);
 
 	/* set error */
 	label = GTK_LABEL (gtk_builder_get_object (builder, "label_error"));



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