Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From f81dacbb7982a66cb58facd93eabe300b6ed202b Mon Sep 17 00:00:00 2001
From 22ff87d414e97a8be0b464186cfe205a35e2b720 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <[email protected]>
Date: Sat, 19 Nov 2016 22:57:48 +0100
Subject: [PATCH] color: Add ability to change the color temperature of the
display
Date: Wed, 18 Jan 2017 21:37:42 -0500
Subject: [PATCH] color: Add ability to change the color temperature and
brightness of the display

This is an experimental feature which allows the color temperature to be
changed while still keeping further gamma correction active.
Expand All @@ -12,20 +12,20 @@ This should be used with the experimental redshift extension from:

Signed-off-by: Benjamin Berg <[email protected]>
---
...settings-daemon.plugins.color.gschema.xml.in.in | 11 +
...settings-daemon.plugins.color.gschema.xml.in.in | 17 ++
plugins/color/Makefile.am | 4 +-
plugins/color/colorramp.c | 308 +++++++++++++++++++++
plugins/color/colorramp.h | 27 ++
plugins/color/gsd-color-state.c | 69 ++++-
5 files changed, 409 insertions(+), 10 deletions(-)
plugins/color/gsd-color-state.c | 84 +++++-
5 files changed, 429 insertions(+), 11 deletions(-)
create mode 100644 plugins/color/colorramp.c
create mode 100644 plugins/color/colorramp.h

diff --git a/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
index e5bf62c..6b027ff 100644
index e5bf62c6..e658686d 100644
--- a/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
@@ -20,5 +20,16 @@
@@ -20,5 +20,22 @@
<_summary>The duration a printer profile is valid</_summary>
<_description>This is the number of days after which the printer color profile is considered invalid.</_description>
</key>
Expand All @@ -39,11 +39,17 @@ index e5bf62c..6b027ff 100644
+ <range min="1000" max="20000"/>
+ <_summary>The color temperature of the displays</_summary>
+ <_description>The color temperature of all displays that have a color profile is adjusted. A value of 6500 Kelvin is an identify transformation.</_description>
+ </key>
+ <key name="color-brightness" type="d">
+ <default>1.0</default>
+ <range min="0.1" max="1.0"/>
+ <_summary>The color brightness of the displays</_summary>
+ <_description>The color brightness of all displays that have a color profile is adjusted. Maximum standard brightness is 1.0.</_description>
+ </key>
</schema>
</schemalist>
diff --git a/plugins/color/Makefile.am b/plugins/color/Makefile.am
index 0f7497a..e15913d 100644
index 0f7497a9..e15913d2 100644
--- a/plugins/color/Makefile.am
+++ b/plugins/color/Makefile.am
@@ -14,7 +14,9 @@ libcolor_la_SOURCES = \
Expand All @@ -59,7 +65,7 @@ index 0f7497a..e15913d 100644
-I$(top_srcdir)/gnome-settings-daemon \
diff --git a/plugins/color/colorramp.c b/plugins/color/colorramp.c
new file mode 100644
index 0000000..a4949d6
index 00000000..1b4f297c
--- /dev/null
+++ b/plugins/color/colorramp.c
@@ -0,0 +1,308 @@
Expand Down Expand Up @@ -346,7 +352,7 @@ index 0000000..a4949d6
+}
+
+void
+colorramp_get_factor(int to_temp, double *r, double *g, double *b)
+colorramp_get_factor(int to_temp, double brightness, double *r, double *g, double *b)
+{
+ /* Approximate white point */
+ float white_point[3];
Expand All @@ -367,13 +373,13 @@ index 0000000..a4949d6
+ interpolate_color(alpha, &blackbody_color[temp_index],
+ &blackbody_color[temp_index+3], white_point);
+
+ *r = white_point[0];
+ *g = white_point[1];
+ *b = white_point[2];
+ *r = brightness * white_point[0];
+ *g = brightness * white_point[1];
+ *b = brightness * white_point[2];
+}
diff --git a/plugins/color/colorramp.h b/plugins/color/colorramp.h
new file mode 100644
index 0000000..436d736
index 00000000..fcc32e8f
--- /dev/null
+++ b/plugins/color/colorramp.h
@@ -0,0 +1,27 @@
Expand Down Expand Up @@ -401,11 +407,11 @@ index 0000000..436d736
+
+#include <stdint.h>
+
+void colorramp_get_factor(int to_temp, double *r, double *g, double *b);
+void colorramp_get_factor(int to_temp, double brightness, double *r, double *g, double *b);
+
+#endif /* ! REDSHIFT_COLORRAMP_H */
diff --git a/plugins/color/gsd-color-state.c b/plugins/color/gsd-color-state.c
index 9f8308f..5ab4337 100644
index 9f8308f8..a2f86d9f 100644
--- a/plugins/color/gsd-color-state.c
+++ b/plugins/color/gsd-color-state.c
@@ -27,6 +27,7 @@
Expand All @@ -429,37 +435,38 @@ index 9f8308f..5ab4337 100644
struct GsdColorStatePrivate
{
GCancellable *cancellable;
@@ -53,6 +58,8 @@ struct GsdColorStatePrivate
@@ -53,6 +58,9 @@ struct GsdColorStatePrivate
GdkWindow *gdk_window;
gboolean session_is_active;
GHashTable *device_assign_hash;
+ gint color_temperature;
+ gdouble color_brightness;
+ GSettings *settings;
};

static void gsd_color_state_class_init (GsdColorStateClass *klass);
@@ -360,7 +367,7 @@ out:
@@ -360,7 +368,7 @@ out:
}

static GPtrArray *
-gcm_session_generate_vcgt (CdProfile *profile, guint size)
+gcm_session_generate_vcgt (CdProfile *profile, gint color_temperature, guint size)
+gcm_session_generate_vcgt (CdProfile *profile, gint color_temperature, gdouble color_brightness, guint size)
{
GnomeRROutputClutItem *tmp;
GPtrArray *array = NULL;
@@ -369,6 +376,7 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
@@ -369,6 +377,7 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
guint i;
cmsHPROFILE lcms_profile;
CdIcc *icc = NULL;
+ double r, g, b;

/* invalid size */
if (size == 0)
@@ -387,14 +395,16 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
@@ -387,14 +396,16 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
goto out;
}

+ colorramp_get_factor(color_temperature, &r, &g, &b);
+ colorramp_get_factor(color_temperature, color_brightness, &r, &g, &b);
+
/* create array */
array = g_ptr_array_new_with_free_func (g_free);
Expand All @@ -475,46 +482,49 @@ index 9f8308f..5ab4337 100644
g_ptr_array_add (array, tmp);
}
out:
@@ -475,6 +485,7 @@ out:
@@ -475,6 +486,8 @@ out:
static gboolean
gcm_session_device_set_gamma (GnomeRROutput *output,
CdProfile *profile,
+ gint color_temperature,
+ gdouble color_brightness,
GError **error)
{
gboolean ret = FALSE;
@@ -487,7 +498,7 @@ gcm_session_device_set_gamma (GnomeRROutput *output,
@@ -487,7 +500,7 @@ gcm_session_device_set_gamma (GnomeRROutput *output,
ret = TRUE;
goto out;
}
- clut = gcm_session_generate_vcgt (profile, size);
+ clut = gcm_session_generate_vcgt (profile, color_temperature, size);
+ clut = gcm_session_generate_vcgt (profile, color_temperature, color_brightness, size);
if (clut == NULL) {
g_set_error_literal (error,
GSD_COLOR_MANAGER_ERROR,
@@ -507,7 +518,7 @@ out:
@@ -507,8 +520,8 @@ out:
}

static gboolean
-gcm_session_device_reset_gamma (GnomeRROutput *output,
- GError **error)
+gcm_session_device_reset_gamma (GnomeRROutput *output, gint color_temperature,
GError **error)
+ gdouble color_brightness, GError **error)
{
gboolean ret;
@@ -516,6 +527,7 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
guint i;
@@ -516,6 +529,7 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
guint32 value;
GPtrArray *clut;
GnomeRROutputClutItem *data;
+ double r, g, b;

/* create a linear ramp */
g_debug ("falling back to dummy ramp");
@@ -525,12 +537,15 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
@@ -525,12 +539,15 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
ret = TRUE;
goto out;
}
+
+ colorramp_get_factor(color_temperature, &r, &g, &b);
+ colorramp_get_factor(color_temperature, color_brightness, &r, &g, &b);
+
for (i = 0; i < size; i++) {
value = (i * 0xffff) / (size - 1);
Expand All @@ -528,52 +538,59 @@ index 9f8308f..5ab4337 100644
g_ptr_array_add (clut, data);
}

@@ -669,6 +684,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
@@ -669,6 +686,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
guint brightness_percentage;
GcmSessionAsyncHelper *helper = (GcmSessionAsyncHelper *) user_data;
GsdColorState *state = GSD_COLOR_STATE (helper->state);
+ GsdColorStatePrivate *priv = state->priv;

/* get properties */
ret = cd_profile_connect_finish (profile, res, &error);
@@ -720,6 +736,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
@@ -720,6 +738,8 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
if (ret) {
ret = gcm_session_device_set_gamma (output,
profile,
+ priv->color_temperature,
+ priv->color_brightness,
&error);
if (!ret) {
g_warning ("failed to set %s gamma tables: %s",
@@ -730,6 +747,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
@@ -730,6 +750,8 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
}
} else {
ret = gcm_session_device_reset_gamma (output,
+ priv->color_temperature,
+ priv->color_brightness,
&error);
if (!ret) {
g_warning ("failed to reset %s gamma tables: %s",
@@ -874,6 +892,7 @@ gcm_session_device_assign_connect_cb (GObject *object,
@@ -874,6 +896,8 @@ gcm_session_device_assign_connect_cb (GObject *object,

/* reset, as we want linear profiles for profiling */
ret = gcm_session_device_reset_gamma (output,
+ priv->color_temperature,
+ priv->color_brightness,
&error);
if (!ret) {
g_warning ("failed to reset %s gamma tables: %s",
@@ -1359,6 +1378,25 @@ out:
@@ -1359,6 +1383,29 @@ out:
}

static void
+engine_settings_key_changed_cb (GSettings *settings,
+ const gchar *key,
+ GsdColorState *state)
+{
+ if (g_str_equal (key, "color-temperature") || g_str_equal (key, "adjust-color-temperature")) {
+ if (g_str_equal (key, "color-temperature") || g_str_equal (key, "color-brightness") ||
+ g_str_equal (key, "adjust-color-temperature")) {
+ if (g_settings_get_boolean (state->priv->settings, "adjust-color-temperature")) {
+ state->priv->color_temperature = g_settings_get_int (state->priv->settings,
+ "color-temperature");
+ state->priv->color_brightness = g_settings_get_double (state->priv->settings,
+ "color-brightness");
+ } else {
+ state->priv->color_temperature = -1;
+ state->priv->color_brightness = 1.0;
+ }
+
+ /* Emulate a screen change event. */
Expand All @@ -586,7 +603,7 @@ index 9f8308f..5ab4337 100644
on_rr_screen_acquired (GObject *object,
GAsyncResult *result,
gpointer data)
@@ -1404,6 +1442,18 @@ gsd_color_state_start (GsdColorState *state)
@@ -1404,6 +1451,21 @@ gsd_color_state_start (GsdColorState *state)
gnome_rr_screen_new_async (gdk_screen_get_default (),
on_rr_screen_acquired,
g_object_ref (state));
Expand All @@ -599,20 +616,24 @@ index 9f8308f..5ab4337 100644
+ if (g_settings_get_boolean (state->priv->settings, "adjust-color-temperature")) {
+ state->priv->color_temperature = g_settings_get_int (state->priv->settings,
+ "color-temperature");
+ state->priv->color_brightness = g_settings_get_double (state->priv->settings,
+ "color-brightness");
+ } else {
+ state->priv->color_temperature = -1;
+ state->priv->color_brightness = 1.0;
+ }
}

void
@@ -1431,6 +1481,7 @@ gsd_color_state_init (GsdColorState *state)
@@ -1431,6 +1493,8 @@ gsd_color_state_init (GsdColorState *state)

/* track the active session */
priv->session = gnome_settings_bus_get_session_proxy ();
+ priv->color_temperature = -1;
+ priv->color_brightness = 1.0;

#ifdef GDK_WINDOWING_X11
/* set the _ICC_PROFILE atoms on the root screen */
--
2.10.2
2.11.0

Loading