[gtk/wip/baedert/for-master: 59/59] GdkRGBA: Use floats instead of doubles



commit 87b3f1ffb417ad91987f3ab71eed6ea971d00070
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 10 14:22:52 2019 +0100

    GdkRGBA: Use floats instead of doubles

 gdk/gdkrgba.c               | 17 ++++++++++-------
 gdk/gdkrgba.h               |  8 ++++----
 gtk/gtkcolorchooserwidget.c | 25 +++++++++++++++++++------
 gtk/gtkcoloreditor.c        |  4 ++--
 gtk/gtkcolorplane.c         |  4 ++--
 gtk/gtkcolorscale.c         |  2 +-
 gtk/gtkcolorutils.c         | 32 ++++++++++++++++----------------
 gtk/gtkcolorutils.h         |  8 ++++----
 8 files changed, 58 insertions(+), 42 deletions(-)
---
diff --git a/gdk/gdkrgba.c b/gdk/gdkrgba.c
index b52e0254e6..49a9102367 100644
--- a/gdk/gdkrgba.c
+++ b/gdk/gdkrgba.c
@@ -398,23 +398,25 @@ gdk_rgba_to_string (const GdkRGBA *rgba)
 
 static gboolean
 parse_color_channel_value (GtkCssParser *parser,
-                           double       *value,
+                           float        *value,
                            gboolean      is_percentage)
 {
+  double dvalue;
+
   if (is_percentage)
     {
-      if (!gtk_css_parser_consume_percentage (parser, value))
+      if (!gtk_css_parser_consume_percentage (parser, &dvalue))
         return FALSE;
 
-      *value = CLAMP (*value, 0.0, 100.0) / 100.0;
+      *value = CLAMP (dvalue, 0.0, 100.0) / 100.0;
       return TRUE;
     }
   else
     {
-      if (!gtk_css_parser_consume_number (parser, value))
+      if (!gtk_css_parser_consume_number (parser, &dvalue))
         return FALSE;
 
-      *value = CLAMP (*value, 0.0, 255.0) / 255.0;
+      *value = CLAMP (dvalue, 0.0, 255.0) / 255.0;
       return TRUE;
     }
 }
@@ -425,6 +427,7 @@ parse_color_channel (GtkCssParser *parser,
                      gpointer      data)
 {
   GdkRGBA *rgba = data;
+  double dvalue;
 
   switch (arg)
   {
@@ -450,10 +453,10 @@ parse_color_channel (GtkCssParser *parser,
       return 1;
 
     case 3:
-      if (!gtk_css_parser_consume_number (parser, &rgba->alpha))
+      if (!gtk_css_parser_consume_number (parser, &dvalue))
         return 0;
 
-      rgba->alpha = CLAMP (rgba->alpha, 0.0, 1.0);
+      rgba->alpha = CLAMP (dvalue, 0.0, 1.0);
       return 1;
 
     default:
diff --git a/gdk/gdkrgba.h b/gdk/gdkrgba.h
index d5f8d80cae..5e486a5d4a 100644
--- a/gdk/gdkrgba.h
+++ b/gdk/gdkrgba.h
@@ -36,10 +36,10 @@ G_BEGIN_DECLS
 
 struct _GdkRGBA
 {
-  gdouble red;
-  gdouble green;
-  gdouble blue;
-  gdouble alpha;
+  float red;
+  float green;
+  float blue;
+  float alpha;
 };
 
 #define GDK_TYPE_RGBA (gdk_rgba_get_type ())
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 17131ef199..21c32f3a4f 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -530,7 +530,8 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
   GtkWidget *button;
   GtkWidget *label;
   gint i;
-  GdkRGBA color;
+  double color[4];
+  GdkRGBA rgba;
   GVariant *variant;
   GVariantIter iter;
   gboolean selected;
@@ -568,14 +569,20 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
   g_variant_iter_init (&iter, variant);
   i = 0;
   p = NULL;
-  while (g_variant_iter_loop (&iter, "(dddd)", &color.red, &color.green, &color.blue, &color.alpha))
+  while (g_variant_iter_loop (&iter, "(dddd)", &color[0], &color[1], &color[2], &color[3]))
     {
       i++;
       p = gtk_color_swatch_new ();
-      gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &color);
+
+      rgba.red = color[0];
+      rgba.green = color[1];
+      rgba.blue = color[2];
+      rgba.alpha = color[3];
+
+      gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (p), &rgba);
       gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
       atk_obj = gtk_widget_get_accessible (p);
-      name = accessible_color_name (&color);
+      name = accessible_color_name (&rgba);
       text = g_strdup_printf (_("Custom color %d: %s"), i, name);
       atk_object_set_name (atk_obj, text);
       g_free (text);
@@ -598,9 +605,15 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
 
   g_settings_get (priv->settings, I_("selected-color"), "(bdddd)",
                   &selected,
-                  &color.red, &color.green, &color.blue, &color.alpha);
+                  &color[0], &color[1], &color[2], &color[3]);
   if (selected)
-    gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &color);
+    {
+      rgba.red = color[0];
+      rgba.green = color[1];
+      rgba.blue = color[2];
+      rgba.alpha = color[3];
+      gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &rgba);
+    }
 
   gtk_widget_hide (GTK_WIDGET (priv->editor));
 }
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c
index 6a43b7e3d2..d9665a7c52 100644
--- a/gtk/gtkcoloreditor.c
+++ b/gtk/gtkcoloreditor.c
@@ -555,7 +555,7 @@ gtk_color_editor_get_rgba (GtkColorChooser *chooser,
                            GdkRGBA         *color)
 {
   GtkColorEditor *editor = GTK_COLOR_EDITOR (chooser);
-  gdouble h, s, v;
+  float h, s, v;
 
   h = gtk_adjustment_get_value (editor->priv->h_adj);
   s = gtk_adjustment_get_value (editor->priv->s_adj);
@@ -569,7 +569,7 @@ gtk_color_editor_set_rgba (GtkColorChooser *chooser,
                            const GdkRGBA   *color)
 {
   GtkColorEditor *editor = GTK_COLOR_EDITOR (chooser);
-  gdouble h, s, v;
+  float h, s, v;
 
   gtk_rgb_to_hsv (color->red, color->green, color->blue, &h, &s, &v);
 
diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c
index f6eaf311a0..c73b9eec22 100644
--- a/gtk/gtkcolorplane.c
+++ b/gtk/gtkcolorplane.c
@@ -118,8 +118,8 @@ create_texture (GtkColorPlane *plane)
   gint width, height, stride;
   guint red, green, blue;
   guint32 *data, *p;
-  gdouble h, s, v;
-  gdouble r, g, b;
+  float h, s, v;
+  float r, g, b;
   gdouble sf, vf;
   gint x, y;
 
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index daf350ebb0..efead89d8d 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -78,7 +78,7 @@ gtk_color_scale_snapshot_trough (GtkColorScale  *scale,
           GBytes *bytes;
           guchar *data, *p;
           gdouble h;
-          gdouble r, g, b;
+          float r, g, b;
           gdouble f;
           int hue_x, hue_y;
 
diff --git a/gtk/gtkcolorutils.c b/gtk/gtkcolorutils.c
index 97954c5b16..1740485cb9 100644
--- a/gtk/gtkcolorutils.c
+++ b/gtk/gtkcolorutils.c
@@ -39,12 +39,12 @@
 
 /* Converts from HSV to RGB */
 static void
-hsv_to_rgb (gdouble *h,
-            gdouble *s,
-            gdouble *v)
+hsv_to_rgb (float *h,
+            float *s,
+            float *v)
 {
-  gdouble hue, saturation, value;
-  gdouble f, p, q, t;
+  float hue, saturation, value;
+  float f, p, q, t;
 
   if (*s == 0.0)
     {
@@ -112,14 +112,14 @@ hsv_to_rgb (gdouble *h,
 
 /* Converts from RGB to HSV */
 static void
-rgb_to_hsv (gdouble *r,
-            gdouble *g,
-            gdouble *b)
+rgb_to_hsv (float *r,
+            float *g,
+            float *b)
 {
-  gdouble red, green, blue;
-  gdouble h, s, v;
-  gdouble min, max;
-  gdouble delta;
+  float red, green, blue;
+  float h, s, v;
+  float min, max;
+  float delta;
 
   red = *r;
   green = *g;
@@ -200,8 +200,8 @@ rgb_to_hsv (gdouble *r,
  * output values will be in the same range.
  */
 void
-gtk_hsv_to_rgb (gdouble  h, gdouble  s, gdouble  v,
-                gdouble *r, gdouble *g, gdouble *b)
+gtk_hsv_to_rgb (float  h, float  s, float  v,
+                float *r, float *g, float *b)
 {
   g_return_if_fail (h >= 0.0 && h <= 1.0);
   g_return_if_fail (s >= 0.0 && s <= 1.0);
@@ -234,8 +234,8 @@ gtk_hsv_to_rgb (gdouble  h, gdouble  s, gdouble  v,
  * output values will be in the same range.
  */
 void
-gtk_rgb_to_hsv (gdouble  r, gdouble  g, gdouble  b,
-                gdouble *h, gdouble *s, gdouble *v)
+gtk_rgb_to_hsv (float  r, float  g, float  b,
+                float *h, float *s, float *v)
 {
   g_return_if_fail (r >= 0.0 && r <= 1.0);
   g_return_if_fail (g >= 0.0 && g <= 1.0);
diff --git a/gtk/gtkcolorutils.h b/gtk/gtkcolorutils.h
index 4d1f188d8b..0bf8804ef6 100644
--- a/gtk/gtkcolorutils.h
+++ b/gtk/gtkcolorutils.h
@@ -40,11 +40,11 @@
 G_BEGIN_DECLS
 
 GDK_AVAILABLE_IN_ALL
-void gtk_hsv_to_rgb (gdouble  h, gdouble  s, gdouble  v,
-                     gdouble *r, gdouble *g, gdouble *b);
+void gtk_hsv_to_rgb (float  h, float  s, float  v,
+                     float *r, float *g, float *b);
 GDK_AVAILABLE_IN_ALL
-void gtk_rgb_to_hsv (gdouble  r, gdouble  g, gdouble  b,
-                     gdouble *h, gdouble *s, gdouble *v);
+void gtk_rgb_to_hsv (float  r, float  g, float  b,
+                     float *h, float *s, float *v);
 
 G_END_DECLS
 


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