mirror of https://github.com/GNOME/gimp.git
app: add compress-threshold-range prop to color-to-alpha-plus gui
When set, the opacity and transparenct threshold range is compressed to the minimal extent that would produce different results. When the property is toggled, update the opacity and transparency thresholds, such that the result remains the same.
This commit is contained in:
parent
4165ba2a03
commit
78aff4dde6
|
@ -37,38 +37,99 @@
|
||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
|
|
||||||
|
static gdouble
|
||||||
|
get_max_color_extent (GObject *config)
|
||||||
|
{
|
||||||
|
GimpRGB *color;
|
||||||
|
gdouble max_extent = 0.0;
|
||||||
|
|
||||||
|
g_object_get (config,
|
||||||
|
"color", &color,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
max_extent = MAX (max_extent, MAX (color->r, 1.0 - color->r));
|
||||||
|
max_extent = MAX (max_extent, MAX (color->g, 1.0 - color->g));
|
||||||
|
max_extent = MAX (max_extent, MAX (color->b, 1.0 - color->b));
|
||||||
|
|
||||||
|
g_free (color);
|
||||||
|
|
||||||
|
return max_extent;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gdouble
|
||||||
|
compress_threshold (GObject *config,
|
||||||
|
gdouble threshold)
|
||||||
|
{
|
||||||
|
return MIN (threshold / get_max_color_extent (config), 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gdouble
|
||||||
|
uncompress_threshold (GObject *config,
|
||||||
|
gdouble threshold)
|
||||||
|
{
|
||||||
|
return threshold * get_max_color_extent (config);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
threshold_picked (GObject *config,
|
threshold_picked (GObject *config,
|
||||||
gpointer identifier,
|
gpointer identifier,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y,
|
gdouble y,
|
||||||
const Babl *sample_format,
|
const Babl *sample_format,
|
||||||
const GimpRGB *color)
|
const GimpRGB *picked_color)
|
||||||
{
|
{
|
||||||
GimpRGB *bg_color;
|
GimpRGB *color;
|
||||||
gdouble radius = 0.0;
|
gboolean compress_threshold_range;
|
||||||
gdouble target_radius = 0.0;
|
gdouble threshold = 0.0;
|
||||||
gdouble threshold;
|
|
||||||
|
|
||||||
g_object_get (config,
|
g_object_get (config,
|
||||||
"color", &bg_color,
|
"color", &color,
|
||||||
|
"compress-threshold-range", &compress_threshold_range,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
radius = MAX (radius, MAX (bg_color->r, 1.0 - bg_color->r));
|
threshold = MAX (threshold, fabs (picked_color->r - color->r));
|
||||||
radius = MAX (radius, MAX (bg_color->g, 1.0 - bg_color->g));
|
threshold = MAX (threshold, fabs (picked_color->g - color->g));
|
||||||
radius = MAX (radius, MAX (bg_color->b, 1.0 - bg_color->b));
|
threshold = MAX (threshold, fabs (picked_color->b - color->b));
|
||||||
|
|
||||||
target_radius = MAX (target_radius, fabs (color->r - bg_color->r));
|
if (compress_threshold_range)
|
||||||
target_radius = MAX (target_radius, fabs (color->g - bg_color->g));
|
threshold = compress_threshold (config, threshold);
|
||||||
target_radius = MAX (target_radius, fabs (color->b - bg_color->b));
|
|
||||||
|
|
||||||
threshold = target_radius / radius;
|
|
||||||
|
|
||||||
g_object_set (config,
|
g_object_set (config,
|
||||||
identifier, threshold,
|
identifier, threshold,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_free (bg_color);
|
g_free (color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
compress_threshold_range_clicked (GtkWidget *toggle,
|
||||||
|
GObject *config)
|
||||||
|
{
|
||||||
|
gdouble transparency_threshold;
|
||||||
|
gdouble opacity_threshold;
|
||||||
|
gboolean compress_threshold_range;
|
||||||
|
|
||||||
|
g_object_get (config,
|
||||||
|
"transparency-threshold", &transparency_threshold,
|
||||||
|
"opacity-threshold", &opacity_threshold,
|
||||||
|
"compress-threshold-range", &compress_threshold_range,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (compress_threshold_range)
|
||||||
|
{
|
||||||
|
transparency_threshold = compress_threshold (config, transparency_threshold);
|
||||||
|
opacity_threshold = compress_threshold (config, opacity_threshold);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transparency_threshold = uncompress_threshold (config, transparency_threshold);
|
||||||
|
opacity_threshold = uncompress_threshold (config, opacity_threshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_set (config,
|
||||||
|
"transparency-threshold", transparency_threshold,
|
||||||
|
"opacity-threshold", opacity_threshold,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
|
@ -85,6 +146,7 @@ _gimp_prop_gui_new_color_to_alpha (GObject *config,
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
GtkWidget *scale;
|
GtkWidget *scale;
|
||||||
|
GtkWidget *toggle;
|
||||||
const gchar *label;
|
const gchar *label;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
|
||||||
|
@ -144,5 +206,14 @@ _gimp_prop_gui_new_color_to_alpha (GObject *config,
|
||||||
gtk_widget_show (button);
|
gtk_widget_show (button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggle = gimp_prop_widget_new (config, "compress-threshold-range",
|
||||||
|
area, context, NULL, NULL, NULL, &label);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_show (toggle);
|
||||||
|
|
||||||
|
g_signal_connect (toggle, "clicked",
|
||||||
|
G_CALLBACK (compress_threshold_range_clicked),
|
||||||
|
config);
|
||||||
|
|
||||||
return vbox;
|
return vbox;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue