GdkRGBA: Use floats instead of doubles

This commit is contained in:
Timm Bäder 2019-12-10 14:22:52 +01:00
parent 0956c30ee5
commit 095a378dbc
10 changed files with 68 additions and 52 deletions

View 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:

View 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 ())

View 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));
}

View 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);

View 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,

View 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);

View 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;

View 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;

View File

@ -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);

View File

@ -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