[gnome-builder] gstyle: add blindness color filters



commit ce2b13909dea385cf74c99281cce4822bf253a7f
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun Jul 24 17:17:49 2016 +0200

    gstyle: add blindness color filters

 contrib/gstyle/gstyle-color-filter.c |  210 +++++++++++++++++++++++++++++++++-
 contrib/gstyle/gstyle-color-filter.h |   32 +++++
 contrib/gstyle/gstyle-color-panel.c  |   32 +++++
 3 files changed, 270 insertions(+), 4 deletions(-)
---
diff --git a/contrib/gstyle/gstyle-color-filter.c b/contrib/gstyle/gstyle-color-filter.c
index 547a3b5..2a5adfb 100644
--- a/contrib/gstyle/gstyle-color-filter.c
+++ b/contrib/gstyle/gstyle-color-filter.c
@@ -21,13 +21,71 @@
 static gdouble web_colors [] = {0.0, 0.2, 0.2, 0.4, 0.4 , 0.6 , 0.6, 0.8, 0.8, 1.0, 1.0};
 #define TO_WEB_COLOR(x) (web_colors [(gint)(x * 10.0)])
 
+/* http://web.archive.org/web/20081014161121/http://www.colorjack.com/labs/colormatrix/ */
+static gdouble blindness [][9] =
+{
+  /* achromatopsia */
+  { 0.299, 0.587, 0.114,      0.299, 0.587, 0.114,       0.299, 0.587, 0.114   },
+  /* achromatomaly */
+  { 0.618, 0.32, 0.062,       0.163, 0.775, 0.062,       0.163, 0.32, 0.516    },
+  /* deuteranopia */
+  { 0.625, 0.375, 0.0,        0.7, 0.3, 0.0,             0.0, 0.3, 0.7         },
+  /* deuteranomaly */
+  { 0.80, 0.20, 0.0,          0.25833, 0.74167, 0.0,     0.0, 0.14167, 0.85833 },
+  /* protanopia */
+  { 0.56667, 0.43333, 0.0,    0.55833, 0.44167, 0.0,     0.0, 0.24167, 0.75833 },
+  /* protanomaly */
+  { 0.81667, 0.18333, 0.0,    0.33333, 0.66667, 0.0,     0.0, 0.125, 0.875     },
+  /* tritanopia */
+  { 0.950, 0.50, 0.0,         0.0, 0.43333, 0.56667,     0.0, 0.475, 0.525     },
+  /* tritanomaly */
+  { 0.96667, 0.3333, 0.0,     0.0, 0.73333, 0.26667,     0.0, 0.18333, 0.81667 },
+};
+
+typedef enum
+{
+  BLINDNESS_KIND_ACHROMATOPSIA,
+  BLINDNESS_KIND_ACHROMATOMALY,
+  BLINDNESS_KIND_DEUTERANOPIA,
+  BLINDNESS_KIND_DEUTERANOMALY,
+  BLINDNESS_KIND_PROTANOPIA,
+  BLINDNESS_KIND_PROTANOMALY,
+  BLINDNESS_KIND_TRITANOPIA,
+  BLINDNESS_KIND_TRITANOMALY
+} BlindnessKind;
+
+static inline void
+blindness_convert (GdkRGBA       *src_rgba,
+                   GdkRGBA       *dst_rgba,
+                   BlindnessKind  kind)
+{
+  GdkRGBA rgba;
+  gdouble *base = &blindness [kind][0];
+
+  rgba.red = src_rgba->red * base [0] + src_rgba->green * base [1] + src_rgba->blue * base [2];
+  rgba.green = src_rgba->red * base [3] + src_rgba->green * base [4] + src_rgba->blue * base [5];
+  rgba.blue = src_rgba->red * base [6] + src_rgba->green * base [7] + src_rgba->blue * base [8];
+
+  if (rgba.red > 1.0)
+    rgba.red = 1.0;
+
+  if (rgba.green > 1.0)
+    rgba.green = 1.0;
+
+  if (rgba.blue > 1.0)
+    rgba.blue = 1.0;
+
+  rgba.alpha = src_rgba->alpha;
+  *dst_rgba = rgba;
+}
+
 /**
- * gstyle_color_filter_func:
+ * gstyle_color_filter_websafe:
  * @rgba: The source #GdkRGBA color
  * @filter_rgba: (out): the filtered #GdkRGBA color
  * @user_data: A user data pointer
  *
- * A WebSafe Color filter usable with #GstyleColorScale and GstyleColorPlane.
+ * A WebSafe color filter usable with #GstyleColorScale and GstyleColorPlane.
  *
  */
 void
@@ -41,13 +99,157 @@ gstyle_color_filter_websafe (GdkRGBA  *rgba,
   filter_rgba->alpha = rgba->alpha;
 }
 
+/**
+ * gstyle_color_filter_achromatopsia:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A achromatopsia (color agnosia) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_achromatopsia (GdkRGBA  *rgba,
+                                   GdkRGBA  *filter_rgba,
+                                   gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_ACHROMATOPSIA);
+}
+
+/**
+ * gstyle_color_filter_achromatomaly:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A achromatomaly (Blue Cone Monochromacy) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_achromatomaly (GdkRGBA  *rgba,
+                                   GdkRGBA  *filter_rgba,
+                                   gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_ACHROMATOMALY);
+}
+
+/**
+ * gstyle_color_filter_deuteranopia:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A deuteranopia (green-blind) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_deuteranopia (GdkRGBA  *rgba,
+                                  GdkRGBA  *filter_rgba,
+                                  gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_DEUTERANOPIA);
+}
+
+/**
+ * gstyle_color_filter_deuteranomaly:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A deuteranomaly (green-weak) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_deuteranomaly (GdkRGBA  *rgba,
+                                   GdkRGBA  *filter_rgba,
+                                   gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_DEUTERANOMALY);
+}
+
+/**
+ * gstyle_color_filter_protanopia:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A protanopia (red-blind) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_protanopia (GdkRGBA  *rgba,
+                                GdkRGBA  *filter_rgba,
+                                gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_PROTANOPIA);
+}
+
+/**
+ * gstyle_color_filter_protanomaly:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A protanomaly (red-weak) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_protanomaly (GdkRGBA  *rgba,
+                                 GdkRGBA  *filter_rgba,
+                                 gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_PROTANOMALY);
+}
+
+/**
+ * gstyle_color_filter_tritanopia:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A tritanopia (blue-blind) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_tritanopia (GdkRGBA  *rgba,
+                                GdkRGBA  *filter_rgba,
+                                gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_TRITANOPIA);
+}
+
+/**
+ * gstyle_color_filter_tritanomaly:
+ * @rgba: The source #GdkRGBA color
+ * @filter_rgba: (out): the filtered #GdkRGBA color
+ * @user_data: A user data pointer
+ *
+ * A tritanomaly (blue-weak) color filter usable with #GstyleColorScale and GstyleColorPlane.
+ *
+ */
+void
+gstyle_color_filter_tritanomaly (GdkRGBA  *rgba,
+                                 GdkRGBA  *filter_rgba,
+                                 gpointer  user_data)
+{
+  blindness_convert (rgba, filter_rgba, BLINDNESS_KIND_TRITANOMALY);
+}
+
 GType
 gstyle_color_filter_get_type (void)
 {
   static GType filter_type_id;
   static const GEnumValue values[] = {
-    { GSTYLE_COLOR_FILTER_NONE,    "GSTYLE_COLOR_FILTER_NONE",    "none" },
-    { GSTYLE_COLOR_FILTER_WEBSAFE, "GSTYLE_COLOR_FILTER_WEBSAFE", "websafe" },
+    { GSTYLE_COLOR_FILTER_NONE,          "GSTYLE_COLOR_FILTER_NONE",          "none" },
+    { GSTYLE_COLOR_FILTER_ACHROMATOPSIA, "GSTYLE_COLOR_FILTER_ACHROMATOPSIA", "achromatopsia" },
+    { GSTYLE_COLOR_FILTER_ACHROMATOMALY, "GSTYLE_COLOR_FILTER_ACHROMATOMALY", "achromatomaly" },
+    { GSTYLE_COLOR_FILTER_DEUTERANOPIA,  "GSTYLE_COLOR_FILTER_DEUTERANOPIA",  "deuteranopia" },
+    { GSTYLE_COLOR_FILTER_DEUTERANOMALY, "GSTYLE_COLOR_FILTER_DEUTERANOMALY", "deuteranomaly" },
+    { GSTYLE_COLOR_FILTER_PROTANOPIA,    "GSTYLE_COLOR_FILTER_PROTANOPIA",    "protanopia" },
+    { GSTYLE_COLOR_FILTER_PROTANOMALY,   "GSTYLE_COLOR_FILTER_PROTANOMALY",   "protanomaly" },
+    { GSTYLE_COLOR_FILTER_TRITANOPIA,    "GSTYLE_COLOR_FILTER_TRITANOPIA",    "tritanopia" },
+    { GSTYLE_COLOR_FILTER_TRITANOMALY,   "GSTYLE_COLOR_FILTER_TRITANOMALY",   "tritanomaly" },
+    { GSTYLE_COLOR_FILTER_WEBSAFE,       "GSTYLE_COLOR_FILTER_WEBSAFE",       "websafe" },
     { 0 }
   };
 
diff --git a/contrib/gstyle/gstyle-color-filter.h b/contrib/gstyle/gstyle-color-filter.h
index d72ed40..d202fb4 100644
--- a/contrib/gstyle/gstyle-color-filter.h
+++ b/contrib/gstyle/gstyle-color-filter.h
@@ -31,11 +31,43 @@ typedef void (*GstyleColorFilterFunc)(GdkRGBA *rgba, GdkRGBA *filter_rgba, gpoin
 typedef enum
 {
   GSTYLE_COLOR_FILTER_NONE,
+  GSTYLE_COLOR_FILTER_ACHROMATOPSIA,
+  GSTYLE_COLOR_FILTER_ACHROMATOMALY,
+  GSTYLE_COLOR_FILTER_DEUTERANOPIA,
+  GSTYLE_COLOR_FILTER_DEUTERANOMALY,
+  GSTYLE_COLOR_FILTER_PROTANOPIA,
+  GSTYLE_COLOR_FILTER_PROTANOMALY,
+  GSTYLE_COLOR_FILTER_TRITANOPIA,
+  GSTYLE_COLOR_FILTER_TRITANOMALY,
   GSTYLE_COLOR_FILTER_WEBSAFE
 } GstyleColorFilter;
 
 GType          gstyle_color_filter_get_type       (void);
 
+void           gstyle_color_filter_achromatopsia  (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_achromatomaly  (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_deuteranopia   (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_deuteranomaly  (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_protanopia     (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_protanomaly    (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_tritanopia     (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
+void           gstyle_color_filter_tritanomaly    (GdkRGBA          *rgba,
+                                                   GdkRGBA          *filter_rgba,
+                                                   gpointer          user_data);
 void           gstyle_color_filter_websafe        (GdkRGBA          *rgba,
                                                    GdkRGBA          *filter_rgba,
                                                    gpointer          user_data);
diff --git a/contrib/gstyle/gstyle-color-panel.c b/contrib/gstyle/gstyle-color-panel.c
index 815ac2e..ba95125 100644
--- a/contrib/gstyle/gstyle-color-panel.c
+++ b/contrib/gstyle/gstyle-color-panel.c
@@ -194,6 +194,38 @@ gstyle_color_panel_set_filter (GstyleColorPanel  *self,
       filter_func = NULL;
       break;
 
+    case GSTYLE_COLOR_FILTER_ACHROMATOPSIA:
+      filter_func = gstyle_color_filter_achromatopsia;
+      break;
+
+    case GSTYLE_COLOR_FILTER_ACHROMATOMALY:
+      filter_func = gstyle_color_filter_achromatomaly;
+      break;
+
+    case GSTYLE_COLOR_FILTER_DEUTERANOPIA:
+      filter_func = gstyle_color_filter_deuteranopia;
+      break;
+
+    case GSTYLE_COLOR_FILTER_DEUTERANOMALY:
+      filter_func = gstyle_color_filter_deuteranomaly;
+      break;
+
+    case GSTYLE_COLOR_FILTER_PROTANOPIA:
+      filter_func = gstyle_color_filter_protanopia;
+      break;
+
+    case GSTYLE_COLOR_FILTER_PROTANOMALY:
+      filter_func = gstyle_color_filter_protanomaly;
+      break;
+
+    case GSTYLE_COLOR_FILTER_TRITANOPIA:
+      filter_func = gstyle_color_filter_tritanopia;
+      break;
+
+    case GSTYLE_COLOR_FILTER_TRITANOMALY:
+      filter_func = gstyle_color_filter_tritanomaly;
+      break;
+
     case GSTYLE_COLOR_FILTER_WEBSAFE:
       filter_func = gstyle_color_filter_websafe;
       break;


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