[gnome-color-manager: 6/18] Add functionality for a virtual profile to be generated from the EDID data
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager: 6/18] Add functionality for a virtual profile to be generated from the EDID data
- Date: Fri, 8 Oct 2010 16:08:40 +0000 (UTC)
commit f271724d8dbe3126fbf43c1a6498b758d899c3c8
Author: Richard Hughes <richard hughsie com>
Date: Fri Oct 8 12:31:18 2010 +0100
Add functionality for a virtual profile to be generated from the EDID data
libcolor-glib/gcm-profile.c | 58 +++++++++++++++++++++++++++++++++++++++++++
libcolor-glib/gcm-profile.h | 8 ++++++
src/gcm-device-xrandr.c | 16 +++++++++++-
src/gcm-self-test.c | 34 +++++++++++++++++++++++++
4 files changed, 115 insertions(+), 1 deletions(-)
---
diff --git a/libcolor-glib/gcm-profile.c b/libcolor-glib/gcm-profile.c
index aa45177..a0035f6 100644
--- a/libcolor-glib/gcm-profile.c
+++ b/libcolor-glib/gcm-profile.c
@@ -902,6 +902,64 @@ out:
}
/**
+ * gcm_profile_create_from_chroma:
+ * @profile: A valid #GcmProfile
+ * @filename: the data to parse
+ * @error: A #GError, or %NULL
+ *
+ * Saves the profile data to a file.
+ *
+ * Return value: %TRUE for success
+ *
+ * Since: 0.0.1
+ **/
+gboolean
+gcm_profile_create_from_chroma (GcmProfile *profile, gdouble gamma,
+ const GcmColorYxy *red,
+ const GcmColorYxy *green,
+ const GcmColorYxy *blue,
+ const GcmColorYxy *white,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ cmsCIExyYTRIPLE chroma;
+ cmsToneCurve *transfer_curve[3];
+ cmsCIExyY white_point;
+ GcmProfilePrivate *priv = profile->priv;
+
+ /* not loaded */
+ if (priv->lcms_profile != NULL) {
+ g_set_error_literal (error, 1, 0, "already loaded or generated");
+ goto out;
+ }
+
+ /* copy data from our structures (which are the wrong packing
+ * size for lcms2) */
+ chroma.Red.x = red->x;
+ chroma.Red.y = red->y;
+ chroma.Green.x = green->x;
+ chroma.Green.y = green->y;
+ chroma.Blue.x = blue->x;
+ chroma.Blue.y = blue->y;
+ white_point.x = white->x;
+ white_point.y = white->y;
+ white_point.Y = 1.0;
+
+ /* estimate the transfer function for the gamma */
+ transfer_curve[0] = transfer_curve[1] = transfer_curve[2] = cmsBuildGamma (NULL, gamma);
+
+ /* create our generated profile */
+ priv->lcms_profile = cmsCreateRGBProfile (&white_point, &chroma, transfer_curve);
+ cmsSetEncodedICCversion (priv->lcms_profile, 2);
+ cmsFreeToneCurve (*transfer_curve);
+
+ /* success */
+ ret = TRUE;
+out:
+ return ret;
+}
+
+/**
* gcm_profile_generate_vcgt:
* @profile: A valid #GcmProfile
* @size: the size of the table to generate
diff --git a/libcolor-glib/gcm-profile.h b/libcolor-glib/gcm-profile.h
index ec53c9b..92fc9d0 100644
--- a/libcolor-glib/gcm-profile.h
+++ b/libcolor-glib/gcm-profile.h
@@ -31,6 +31,7 @@
#include "gcm-clut.h"
#include "gcm-enum.h"
+#include "gcm-color.h"
G_BEGIN_DECLS
@@ -82,6 +83,13 @@ GcmClut *gcm_profile_generate_vcgt (GcmProfile *profile,
guint size);
GcmClut *gcm_profile_generate_curve (GcmProfile *profile,
guint size);
+gboolean gcm_profile_create_from_chroma (GcmProfile *profile,
+ gdouble gamma,
+ const GcmColorYxy *red,
+ const GcmColorYxy *green,
+ const GcmColorYxy *blue,
+ const GcmColorYxy *white,
+ GError **error);
const gchar *gcm_profile_get_description (GcmProfile *profile);
void gcm_profile_set_description (GcmProfile *profile,
const gchar *description);
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 9e40484..88de7bd 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -395,6 +395,7 @@ gcm_device_xrandr_get_config_data (GcmDevice *device)
static GcmProfile *
gcm_device_xrandr_generate_profile (GcmDevice *device, GError **error)
{
+ gboolean ret;
const gchar *data;
GcmProfile *profile;
GcmDeviceXrandr *device_xrandr = GCM_DEVICE_XRANDR (device);
@@ -419,7 +420,20 @@ gcm_device_xrandr_generate_profile (GcmDevice *device, GError **error)
data = "Unknown monitor";
gcm_profile_set_model (profile, data);
- /* TODO: generate a profile from the chroma data */
+ /* generate a profile from the chroma data */
+ ret = gcm_profile_create_from_chroma (profile,
+ gcm_edid_get_gamma (priv->edid),
+ gcm_edid_get_red (priv->edid),
+ gcm_edid_get_green (priv->edid),
+ gcm_edid_get_blue (priv->edid),
+ gcm_edid_get_white (priv->edid),
+ error);
+ if (!ret) {
+ g_object_unref (profile);
+ profile = NULL;
+ goto out;
+ }
+out:
return profile;
}
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 7cd28ed..3691489 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -287,6 +287,8 @@ gcm_test_device_func (void)
gchar *data;
gchar **split;
gchar *contents;
+ GcmX11Screen *screen;
+ GcmX11Output *output;
device = gcm_device_udev_new ();
g_assert (device != NULL);
@@ -404,6 +406,38 @@ gcm_test_device_func (void)
g_ptr_array_unref (profiles);
g_object_unref (device);
+
+ /* test auto-generation of the profile */
+ device = gcm_device_xrandr_new ();
+ screen = gcm_x11_screen_new ();
+ ret = gcm_x11_screen_assign (screen, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ output = gcm_x11_screen_get_output_by_name (screen, "LVDS-1", &error);
+ g_assert_no_error (error);
+ g_assert (output != NULL);
+ g_object_unref (screen);
+
+ /* setup device */
+ ret = gcm_device_xrandr_set_from_output (device, output, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_object_unref (output);
+
+ /* generate profile */
+ profile = gcm_device_generate_profile (device, &error);
+ g_assert_no_error (error);
+ g_assert (profile != NULL);
+
+ g_assert_cmpstr (gcm_profile_get_copyright (profile), ==, "No copyright");
+
+ /* DEBUG */
+// ret = gcm_profile_save (profile, "./moo.icc", &error);
+// g_assert_no_error (error);
+// g_assert (ret);
+
+ g_object_unref (profile);
+ g_object_unref (device);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]