mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-04 01:43:24 +00:00
plug-ins: script-fu is now GimpRGB-free.
This commit is contained in:
parent
6a85efe92c
commit
d51cde85c1
5 changed files with 39 additions and 40 deletions
|
@ -185,7 +185,8 @@ script_fu_arg_reset (SFArg *arg, gboolean should_reset_ids)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SF_COLOR:
|
case SF_COLOR:
|
||||||
value->sfa_color = default_value->sfa_color;
|
g_clear_object (&value->sfa_color);
|
||||||
|
value->sfa_color = gegl_color_duplicate (default_value->sfa_color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SF_TOGGLE:
|
case SF_TOGGLE:
|
||||||
|
@ -632,7 +633,7 @@ script_fu_arg_append_repr_from_self (SFArg *arg,
|
||||||
|
|
||||||
case SF_COLOR:
|
case SF_COLOR:
|
||||||
{
|
{
|
||||||
gchar *repr = sf_color_get_repr (&arg_value->sfa_color);
|
gchar *repr = sf_color_get_repr (arg_value->sfa_color);
|
||||||
g_string_append (result_string, repr);
|
g_string_append (result_string, repr);
|
||||||
g_free (repr);
|
g_free (repr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,9 @@
|
||||||
* Since a GimpProcedureConfig carries the values
|
* Since a GimpProcedureConfig carries the values
|
||||||
* and GParamSpec carries the defaults.
|
* and GParamSpec carries the defaults.
|
||||||
* - ScriptFu might not support RGB triplet repr
|
* - ScriptFu might not support RGB triplet repr
|
||||||
* - GimpRGB may go away?
|
|
||||||
*
|
*
|
||||||
* Complex:
|
* Complex:
|
||||||
* PDB and widgets traffic in GeglColor but SF converts to GimpRGB
|
* PDB and widgets traffic in GeglColor but SF dumbs it down to a Scheme list (r g b)
|
||||||
* and dumbs down to a Scheme list (r g b)
|
|
||||||
*
|
*
|
||||||
* More SF code deals with GeglColor:
|
* More SF code deals with GeglColor:
|
||||||
* see scheme_marshall.c we marshall from GeglColor to/from Scheme lists of numbers.
|
* see scheme_marshall.c we marshall from GeglColor to/from Scheme lists of numbers.
|
||||||
|
@ -53,25 +51,24 @@
|
||||||
* Caller owns returned string.
|
* Caller owns returned string.
|
||||||
*/
|
*/
|
||||||
gchar*
|
gchar*
|
||||||
sf_color_get_repr (SFColorType *arg_value)
|
sf_color_get_repr (SFColorType arg_value)
|
||||||
{
|
{
|
||||||
guchar r, g, b;
|
guchar rgb[3] = { 0 };
|
||||||
|
|
||||||
gimp_rgb_get_uchar (arg_value, &r, &g, &b);
|
if (arg_value)
|
||||||
return g_strdup_printf ("'(%d %d %d)", (gint) r, (gint) g, (gint) b);
|
gegl_color_get_pixel (arg_value, babl_format ("R'G'B' u8"), rgb);
|
||||||
|
|
||||||
|
return g_strdup_printf ("'(%d %d %d)", (gint) rgb[0], (gint) rgb[1], (gint) rgb[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns GeglColor from SFColorType: GimpRGB w format quad of double.
|
/* Returns GeglColor from SFColorType.
|
||||||
*
|
*
|
||||||
* Returned GeglColor is owned by caller.
|
* Returned GeglColor is owned by caller.
|
||||||
*/
|
*/
|
||||||
GeglColor *
|
GeglColor *
|
||||||
sf_color_get_gegl_color (SFColorType *arg_value)
|
sf_color_get_gegl_color (SFColorType arg_value)
|
||||||
{
|
{
|
||||||
GeglColor *result = gegl_color_new (NULL);
|
return arg_value ? gegl_color_duplicate (arg_value) : gegl_color_new ("transparent");
|
||||||
|
|
||||||
gegl_color_set_pixel (result, babl_format ("R'G'B'A double"), arg_value);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set an SFArg of type SFColorType from a GeglColor.
|
/* Set an SFArg of type SFColorType from a GeglColor.
|
||||||
|
@ -81,7 +78,14 @@ void
|
||||||
sf_color_set_from_gegl_color (SFColorType *arg_value,
|
sf_color_set_from_gegl_color (SFColorType *arg_value,
|
||||||
GeglColor *color)
|
GeglColor *color)
|
||||||
{
|
{
|
||||||
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), arg_value);
|
const Babl *format = gegl_color_get_format (color);
|
||||||
|
guint8 pixel[48];
|
||||||
|
|
||||||
|
gegl_color_get_pixel (color, format, pixel);
|
||||||
|
if (*arg_value)
|
||||||
|
gegl_color_set_pixel (*arg_value, format, pixel);
|
||||||
|
else
|
||||||
|
*arg_value = gegl_color_duplicate (color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the default for an arg of type SFColorType from a string name.
|
/* Set the default for an arg of type SFColorType from a string name.
|
||||||
|
@ -100,23 +104,23 @@ gboolean
|
||||||
sf_color_arg_set_default_by_name (SFArg *arg,
|
sf_color_arg_set_default_by_name (SFArg *arg,
|
||||||
gchar *name_of_default)
|
gchar *name_of_default)
|
||||||
{
|
{
|
||||||
gboolean result = TRUE;
|
gboolean result = TRUE;
|
||||||
GimpRGB pixel;
|
GeglColor *color;
|
||||||
|
|
||||||
/* Create a default value for the old-style interface.
|
/* Create a default value for the old-style interface.
|
||||||
* This knows SF keeps values of type GimpRGB.
|
|
||||||
*/
|
*/
|
||||||
if (! gimp_rgb_parse_css (&pixel, name_of_default, -1))
|
if (! (color = gimp_color_parse_css (name_of_default, -1)))
|
||||||
{
|
{
|
||||||
result = FALSE;
|
result = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* ScriptFu does not let an author specify RGBA, only RGB. */
|
/* ScriptFu does not let an author specify RGBA, only RGB. */
|
||||||
gimp_rgb_set_alpha (&pixel, 1.0);
|
gimp_color_set_alpha (color, 1.0);
|
||||||
|
|
||||||
/* Copying a struct that is not allocated, not setting a pointer. */
|
/* Copying a struct that is not allocated, not setting a pointer. */
|
||||||
arg->default_value.sfa_color = pixel;
|
g_clear_object (&arg->default_value.sfa_color);
|
||||||
|
arg->default_value.sfa_color = color;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -143,9 +147,8 @@ sf_color_arg_get_default_color (SFArg *arg)
|
||||||
{
|
{
|
||||||
/* require the default was set earlier.
|
/* require the default was set earlier.
|
||||||
* No easy way to assert it was set,
|
* No easy way to assert it was set,
|
||||||
* its a struct GimpRGB where all zeros is valid.
|
|
||||||
*/
|
*/
|
||||||
return sf_color_get_gegl_color (&arg->default_value.sfa_color);
|
return sf_color_get_gegl_color (arg->default_value.sfa_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,20 +19,15 @@
|
||||||
#define __SCRIPT_FU_COLOR_H__
|
#define __SCRIPT_FU_COLOR_H__
|
||||||
|
|
||||||
|
|
||||||
/* ScriptFu stores colors as GimpRGB.
|
typedef GeglColor * SFColorType;
|
||||||
* I.E. as a pixel, a set of component intensity values,
|
|
||||||
* and not as a representation of perceived color GeglColor.
|
|
||||||
* I.E. simplified, with loss of capability.
|
|
||||||
*/
|
|
||||||
typedef GimpRGB SFColorType;
|
|
||||||
|
|
||||||
|
|
||||||
/* Methods on SFColorType. */
|
/* Methods on SFColorType. */
|
||||||
GeglColor* sf_color_get_gegl_color (SFColorType *arg_value);
|
GeglColor* sf_color_get_gegl_color (SFColorType arg_value);
|
||||||
void sf_color_set_from_gegl_color (SFColorType *arg_value,
|
void sf_color_set_from_gegl_color (SFColorType *arg_value,
|
||||||
GeglColor *color);
|
GeglColor *color);
|
||||||
|
|
||||||
gchar* sf_color_get_repr (SFColorType *arg_value);
|
gchar* sf_color_get_repr (SFColorType arg_value);
|
||||||
|
|
||||||
/* Other conversions. */
|
/* Other conversions. */
|
||||||
gchar* sf_color_get_repr_from_gegl_color (GeglColor *color);
|
gchar* sf_color_get_repr_from_gegl_color (GeglColor *color);
|
||||||
|
|
|
@ -77,7 +77,7 @@ static void script_fu_file_callback (GtkWidget *widget,
|
||||||
static void script_fu_combo_callback (GtkWidget *widget,
|
static void script_fu_combo_callback (GtkWidget *widget,
|
||||||
SFOption *option);
|
SFOption *option);
|
||||||
static void script_fu_color_button_update (GimpColorButton *button,
|
static void script_fu_color_button_update (GimpColorButton *button,
|
||||||
GimpRGB *rgb);
|
SFColorType color);
|
||||||
|
|
||||||
static void script_fu_resource_set_handler (gpointer data,
|
static void script_fu_resource_set_handler (gpointer data,
|
||||||
gpointer resource,
|
gpointer resource,
|
||||||
|
@ -266,7 +266,7 @@ script_fu_interface_dialog (SFScript *script,
|
||||||
case SF_COLOR:
|
case SF_COLOR:
|
||||||
{
|
{
|
||||||
GimpColorConfig *config;
|
GimpColorConfig *config;
|
||||||
GeglColor *color = sf_color_get_gegl_color (&arg->value.sfa_color);
|
GeglColor *color = sf_color_get_gegl_color (arg->value.sfa_color);
|
||||||
|
|
||||||
left_align = TRUE;
|
left_align = TRUE;
|
||||||
widget = gimp_color_button_new (_("Script-Fu Color Selection"),
|
widget = gimp_color_button_new (_("Script-Fu Color Selection"),
|
||||||
|
@ -283,7 +283,7 @@ script_fu_interface_dialog (SFScript *script,
|
||||||
|
|
||||||
g_signal_connect (widget, "color-changed",
|
g_signal_connect (widget, "color-changed",
|
||||||
G_CALLBACK (script_fu_color_button_update),
|
G_CALLBACK (script_fu_color_button_update),
|
||||||
&arg->value.sfa_color);
|
arg->value.sfa_color);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -629,11 +629,11 @@ script_fu_combo_callback (GtkWidget *widget,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
script_fu_color_button_update (GimpColorButton *button,
|
script_fu_color_button_update (GimpColorButton *button,
|
||||||
SFColorType *arg_value)
|
SFColorType arg_value)
|
||||||
{
|
{
|
||||||
GeglColor *color = gimp_color_button_get_color (button);
|
GeglColor *color = gimp_color_button_get_color (button);
|
||||||
|
|
||||||
sf_color_set_from_gegl_color (arg_value, color);
|
sf_color_set_from_gegl_color (&arg_value, color);
|
||||||
|
|
||||||
g_object_unref (color);
|
g_object_unref (color);
|
||||||
}
|
}
|
||||||
|
@ -835,7 +835,7 @@ script_fu_reset (SFScript *script)
|
||||||
|
|
||||||
case SF_COLOR:
|
case SF_COLOR:
|
||||||
{
|
{
|
||||||
GeglColor *color = sf_color_get_gegl_color (&value->sfa_color);
|
GeglColor *color = sf_color_get_gegl_color (value->sfa_color);
|
||||||
|
|
||||||
gimp_color_button_set_color (GIMP_COLOR_BUTTON (widget), color);
|
gimp_color_button_set_color (GIMP_COLOR_BUTTON (widget), color);
|
||||||
g_object_unref (color);
|
g_object_unref (color);
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
; int
|
; int
|
||||||
; float
|
; float
|
||||||
|
|
||||||
; GimpRGB is tested e.g. with Palette
|
; Colors (GeglColor) are tested e.g. with Palette
|
||||||
; GimpRGBArray is tested e.g.
|
; GimpColorArray is tested e.g.
|
||||||
; from palette-get-colormap
|
; from palette-get-colormap
|
||||||
; to is not tested: not an arg to any PDB proc
|
; to is not tested: not an arg to any PDB proc
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue