diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c index 9dde3223e5..8382fa4e9a 100644 --- a/app/pdb/drawable-color-cmds.c +++ b/app/pdb/drawable-color-cmds.c @@ -293,6 +293,53 @@ drawable_curves_spline_invoker (GimpProcedure *procedure, error ? *error : NULL); } +static GimpValueArray * +drawable_extract_component_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpDrawable *drawable; + guint8 component; + gboolean invert; + gboolean linear; + + drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp); + component = g_value_get_uint (gimp_value_array_index (args, 1)); + invert = g_value_get_boolean (gimp_value_array_index (args, 2)); + linear = g_value_get_boolean (gimp_value_array_index (args, 3)); + + if (success) + { + if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, + GIMP_PDB_ITEM_CONTENT, error) && + gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) && + gimp_drawable_is_rgb (drawable)) + { + GeglNode *node = + gegl_node_new_child (NULL, + "operation", "gegl:component-extract", + "component", component, + "invert", invert, + "linear", linear, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Extract Component"), + node); + g_object_unref (node); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * drawable_desaturate_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1010,6 +1057,47 @@ register_drawable_color_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-drawable-extract-component + */ + procedure = gimp_procedure_new (drawable_extract_component_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-drawable-extract-component"); + gimp_procedure_set_static_strings (procedure, + "gimp-drawable-extract-component", + "Extract a color model component.", + "Extract a color model component.", + "", + "", + "2021", + NULL); + gimp_procedure_add_argument (procedure, + gimp_param_spec_drawable_id ("drawable", + "drawable", + "The drawable", + pdb->gimp, FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_int8 ("component", + "component", + "Commponent (RGB Red (0), RGB Green (1), RGB Blue (2), Hue (3), HSV Saturation (4), HSV Value (5), HSL Saturation (6), HSL Lightness (7), CMYK Cyan (8), CMYK Magenta (9), CMYK Yellow (10), CMYK Key (11), Y'CbCr Y' (12), Y'CbCr Cb (13), Y'CbCr Cr (14), LAB L (15), LAB A (16), LAB B (17), LCH C(ab) (18), LCH H(ab) (19), Alpha (20))", + 0, 20, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_boolean ("invert", + "invert", + "Invert the extracted component", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_boolean ("linear", + "linear", + "Use linear output instead of gamma corrected", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-drawable-desaturate */ diff --git a/libgimp/gimp.def b/libgimp/gimp.def index deb318f33c..b65b730017 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -222,6 +222,7 @@ EXPORTS gimp_drawable_edit_stroke_item gimp_drawable_edit_stroke_selection gimp_drawable_equalize + gimp_drawable_extract_component gimp_drawable_fill gimp_drawable_flush gimp_drawable_foreground_extract diff --git a/libgimp/gimpdrawablecolor_pdb.c b/libgimp/gimpdrawablecolor_pdb.c index dd56daca51..4ff638767d 100644 --- a/libgimp/gimpdrawablecolor_pdb.c +++ b/libgimp/gimpdrawablecolor_pdb.c @@ -260,6 +260,44 @@ gimp_drawable_curves_spline (gint32 drawable_ID, return success; } +/** + * gimp_drawable_extract_component: + * @drawable_ID: The drawable. + * @component: Commponent (RGB Red (0), RGB Green (1), RGB Blue (2), Hue (3), HSV Saturation (4), HSV Value (5), HSL Saturation (6), HSL Lightness (7), CMYK Cyan (8), CMYK Magenta (9), CMYK Yellow (10), CMYK Key (11), Y'CbCr Y' (12), Y'CbCr Cb (13), Y'CbCr Cr (14), LAB L (15), LAB A (16), LAB B (17), LCH C(ab) (18), LCH H(ab) (19), Alpha (20)). + * @invert: Invert the extracted component. + * @linear: Use linear output instead of gamma corrected. + * + * Extract a color model component. + * + * Extract a color model component. + * + * Returns: TRUE on success. + **/ +gboolean +gimp_drawable_extract_component (gint32 drawable_ID, + guint8 component, + gboolean invert, + gboolean linear) +{ + GimpParam *return_vals; + gint nreturn_vals; + gboolean success = TRUE; + + return_vals = gimp_run_procedure ("gimp-drawable-extract-component", + &nreturn_vals, + GIMP_PDB_DRAWABLE, drawable_ID, + GIMP_PDB_INT8, component, + GIMP_PDB_INT32, invert, + GIMP_PDB_INT32, linear, + GIMP_PDB_END); + + success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS; + + gimp_destroy_params (return_vals, nreturn_vals); + + return success; +} + /** * gimp_drawable_desaturate: * @drawable_ID: The drawable. diff --git a/libgimp/gimpdrawablecolor_pdb.h b/libgimp/gimpdrawablecolor_pdb.h index c327b13874..5d7aa9e6de 100644 --- a/libgimp/gimpdrawablecolor_pdb.h +++ b/libgimp/gimpdrawablecolor_pdb.h @@ -53,6 +53,10 @@ gboolean gimp_drawable_curves_spline (gint32 drawable_ID, GimpHistogramChannel channel, gint num_points, const gdouble *points); +gboolean gimp_drawable_extract_component (gint32 drawable_ID, + guint8 component, + gboolean invert, + gboolean linear); gboolean gimp_drawable_desaturate (gint32 drawable_ID, GimpDesaturateMode desaturate_mode); gboolean gimp_drawable_equalize (gint32 drawable_ID, diff --git a/pdb/groups/drawable_color.pdb b/pdb/groups/drawable_color.pdb index 02c324bf1b..aa528c2a79 100644 --- a/pdb/groups/drawable_color.pdb +++ b/pdb/groups/drawable_color.pdb @@ -292,6 +292,55 @@ CODE ); } +sub drawable_extract_component { + $blurb = 'Extract a color model component.'; + + $help = 'Extract a color model component.'; + + $date = '2021'; + + @inargs = ( + { name => 'drawable', type => 'drawable', + desc => 'The drawable' }, + { name => 'component', type => '0 <= int8 <= 20', + desc => 'Commponent (RGB Red (0), RGB Green (1), RGB Blue (2), Hue (3), HSV Saturation (4), HSV Value (5),' . + ' HSL Saturation (6), HSL Lightness (7), CMYK Cyan (8), CMYK Magenta (9), CMYK Yellow (10), CMYK Key (11),' . + ' Y\'CbCr Y\' (12), Y\'CbCr Cb (13), Y\'CbCr Cr (14), LAB L (15), LAB A (16), LAB B (17), LCH C(ab) (18),' . + ' LCH H(ab) (19), Alpha (20))' }, + { name => 'invert', type => 'boolean', + desc => 'Invert the extracted component' }, + { name => 'linear', type => 'boolean', + desc => 'Use linear output instead of gamma corrected' } + ); + + %invoke = ( + code => <<'CODE' +{ + if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, + GIMP_PDB_ITEM_CONTENT, error) && + gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) && + gimp_drawable_is_rgb (drawable)) + { + GeglNode *node = + gegl_node_new_child (NULL, + "operation", "gegl:component-extract", + "component", component, + "invert", invert, + "linear", linear, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Extract Component"), + node); + g_object_unref (node); + } + else + success = FALSE; +} +CODE + ); +} + sub drawable_desaturate { $blurb = <<'BLURB'; Desaturate the contents of the specified drawable, with the specified formula. @@ -886,6 +935,7 @@ CODE drawable_colorize_hsl drawable_curves_explicit drawable_curves_spline + drawable_extract_component drawable_desaturate drawable_equalize drawable_histogram