GdkRGBA: Use floats instead of doubles
authorTimm Bäder <mail@baedert.org>
Tue, 10 Dec 2019 13:22:52 +0000 (14:22 +0100)
committerTimm Bäder <mail@baedert.org>
Tue, 7 Jan 2020 16:27:15 +0000 (17:27 +0100)
gdk/gdkrgba.c
gdk/gdkrgba.h
gtk/gtkcolorchooserwidget.c
gtk/gtkcoloreditor.c
gtk/gtkcolorpickerportal.c
gtk/gtkcolorpickershell.c
gtk/gtkcolorplane.c
gtk/gtkcolorscale.c
gtk/gtkcolorutils.c
gtk/gtkcolorutils.h

index b52e0254e6f101f4419fe0da99cb4dcaead80909..0242e8f945a29f7f169bd4226bc7b550be90ef22 100644 (file)
@@ -100,7 +100,7 @@ gdk_rgba_free (GdkRGBA *rgba)
 gboolean
 gdk_rgba_is_clear (const GdkRGBA *rgba)
 {
-  return rgba->alpha < ((double) 0x00ff / (double) 0xffff);
+  return rgba->alpha < ((float) 0x00ff / (float) 0xffff);
 }
 
 /**
@@ -115,7 +115,7 @@ gdk_rgba_is_clear (const GdkRGBA *rgba)
 gboolean
 gdk_rgba_is_opaque (const GdkRGBA *rgba)
 {
-  return rgba->alpha > ((double)0xff00 / (double)0xffff);
+  return rgba->alpha > ((float)0xff00 / (float)0xffff);
 }
 
 #define SKIP_WHITESPACES(s) while (*(s) == ' ') (s)++;
@@ -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:
index d5f8d80cae5e1085ee8944ca6dd1feac093092f2..5e486a5d4a19125d82b039e2759e20340b11a5e3 100644 (file)
@@ -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 ())
index 526726fce7e3ef3efefb9e1ab1d08b202a75f712..a9c4f129620ea8c827c611cb359044698affa26e 100644 (file)
@@ -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));
 }
index 6a43b7e3d2f388e2ca53c1a348d3ba12e859c100..d9665a7c52c5a9564ea7262a98cc54dd0d4226c5 100644 (file)
@@ -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);
 
index 993427bb6e9e673c3dcd888054008fea0a4d2547..a382f5105604be49d76c5e7416dd1ba04dd2475a 100644 (file)
@@ -149,11 +149,11 @@ portal_response_received (GDBusConnection *connection,
 
   if (response == 0)
     {
-      GdkRGBA c;
+      double d1, d2, d3;
 
-      c.alpha = 1.0;
-      if (g_variant_lookup (ret, "color", "(ddd)", &c.red, &c.green, &c.blue))
-        g_task_return_pointer (picker->task, gdk_rgba_copy (&c), (GDestroyNotify)gdk_rgba_free);
+      if (g_variant_lookup (ret, "color", "(ddd)", &d1, &d2, &d3))
+        g_task_return_pointer (picker->task,
+                               gdk_rgba_copy (&(GdkRGBA){d1, d2, d3, 1.0f}), (GDestroyNotify)gdk_rgba_free);
       else
         g_task_return_new_error (picker->task,
                                  G_IO_ERROR,
index 6dfa299c50bb790c6fc9bbfca244e7699827dc7a..12e77f6a45e0c66ec2a37a5ac61940642c5d59a3 100644 (file)
@@ -129,15 +129,15 @@ color_picked (GObject      *source,
     }
   else
     {
-      GdkRGBA c;
+      double d1, d2, d3;
 
       g_variant_get (ret, "(@a{sv})", &dict);
 
-      c.alpha = 1;
-      if (!g_variant_lookup (dict, "color", "(ddd)", &c.red, &c.green, &c.blue))
+      if (!g_variant_lookup (dict, "color", "(ddd)", &d1, &d2, &d3))
         g_task_return_new_error (picker->task, G_IO_ERROR, G_IO_ERROR_FAILED, "No color received");
       else
-        g_task_return_pointer (picker->task, gdk_rgba_copy (&c), (GDestroyNotify)gdk_rgba_free);
+        g_task_return_pointer (picker->task,
+                               gdk_rgba_copy (&(GdkRGBA){d1, d2, d3, 1.0f}), (GDestroyNotify)gdk_rgba_free);
 
       g_variant_unref (dict);
       g_variant_unref (ret);
index f6eaf311a065d2d60411ea25701dfacb75c143a4..c73b9eec22829eec5bbf63a72f22ebcb7324033e 100644 (file)
@@ -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;
 
index daf350ebb069f3a9e736260d00ebf37814729b86..efead89d8da14278ce3042d726c502914f9ccbd5 100644 (file)
@@ -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;
 
index 97954c5b16c560c9fd78b4d066fd9dea09be2068..1740485cb9227e7a8f5424dbdec0db358384b2d8 100644 (file)
 
 /* 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);
index 4d1f188d8b0f0bd077c15fe5c1531b99471474c3..0bf8804ef606b4731b10ea48f4b4093499e38d30 100644 (file)
 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