From e238ea07ca201ed602bda13057e15050cf3f22eb Mon Sep 17 00:00:00 2001 From: Ian Martins Date: Wed, 12 May 2021 08:09:25 -0400 Subject: [PATCH] pdb: add a PDB procedure for shadows-highlights (cherry picked from commit 0b96363e107e0c550d1fa7995939b66813c747c9) Reviewer's (Jehan) note: the generated source files were re-generated and amended in this commit. --- app/pdb/drawable-color-cmds.c | 123 ++++++++++++++++++++++++++++++++ app/pdb/internal-procs.c | 2 +- libgimp/gimp.def | 1 + libgimp/gimpdrawablecolor_pdb.c | 58 +++++++++++++++ libgimp/gimpdrawablecolor_pdb.h | 8 +++ pdb/groups/drawable_color.pdb | 63 ++++++++++++++++ 6 files changed, 254 insertions(+), 1 deletion(-) diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c index 1790293999..0128f86912 100644 --- a/app/pdb/drawable-color-cmds.c +++ b/app/pdb/drawable-color-cmds.c @@ -641,6 +641,64 @@ drawable_levels_stretch_invoker (GimpProcedure *procedure, error ? *error : NULL); } +static GimpValueArray * +drawable_shadows_highlights_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpDrawable *drawable; + gdouble shadows; + gdouble highlights; + gdouble whitepoint; + gdouble radius; + gdouble compress; + gdouble shadows_ccorrect; + gdouble highlights_ccorrect; + + drawable = g_value_get_object (gimp_value_array_index (args, 0)); + shadows = g_value_get_double (gimp_value_array_index (args, 1)); + highlights = g_value_get_double (gimp_value_array_index (args, 2)); + whitepoint = g_value_get_double (gimp_value_array_index (args, 3)); + radius = g_value_get_double (gimp_value_array_index (args, 4)); + compress = g_value_get_double (gimp_value_array_index (args, 5)); + shadows_ccorrect = g_value_get_double (gimp_value_array_index (args, 6)); + highlights_ccorrect = g_value_get_double (gimp_value_array_index (args, 7)); + + 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)) + { + GeglNode *node; + node = gegl_node_new_child (NULL, + "operation", "gegl:shadows-highlights", + "shadows", shadows, + "highlights", highlights, + "whitepoint", whitepoint, + "radius", radius, + "compress", compress, + "shadows_correct", shadows_ccorrect, + "highlights_correct", highlights_ccorrect, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Shadows-Highlights"), + node); + g_object_unref (node); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * drawable_posterize_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1259,6 +1317,71 @@ register_drawable_color_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-drawable-shadows-highlights + */ + procedure = gimp_procedure_new (drawable_shadows_highlights_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-drawable-shadows-highlights"); + gimp_procedure_set_static_help (procedure, + "Perform shadows and highlights correction.", + "This filter allows adjusting shadows and highlights in the image separately. The implementation closely follow its counterpart in the Darktable photography software.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "", + "", + "2021"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_drawable ("drawable", + "drawable", + "The drawable", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("shadows", + "shadows", + "Adjust exposure of shadows", + -100, 100, -100, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("highlights", + "highlights", + "Adjust exposure of highlights", + -100, 100, -100, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("whitepoint", + "whitepoint", + "Shift white point", + -10, 10, -10, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("radius", + "radius", + "Spatial extent", + 0.1, 1500, 0.1, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("compress", + "compress", + "Compress the effect on shadows/highlights and preserve midtones", + 0, 100, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("shadows-ccorrect", + "shadows ccorrect", + "Adjust saturation of shadows", + 0, 100, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + g_param_spec_double ("highlights-ccorrect", + "highlights ccorrect", + "Adjust saturation of highlights", + 0, 100, 0, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-drawable-posterize */ diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 6d5cb9599c..3bd69778c4 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 772 procedures registered total */ +/* 773 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 6659774f40..9165dd8b0e 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -244,6 +244,7 @@ EXPORTS gimp_drawable_offset gimp_drawable_posterize gimp_drawable_set_pixel + gimp_drawable_shadows_highlights gimp_drawable_threshold gimp_drawable_type gimp_drawable_type_with_alpha diff --git a/libgimp/gimpdrawablecolor_pdb.c b/libgimp/gimpdrawablecolor_pdb.c index 67e2932c85..6719f67acc 100644 --- a/libgimp/gimpdrawablecolor_pdb.c +++ b/libgimp/gimpdrawablecolor_pdb.c @@ -660,6 +660,64 @@ gimp_drawable_levels_stretch (GimpDrawable *drawable) return success; } +/** + * gimp_drawable_shadows_highlights: + * @drawable: The drawable. + * @shadows: Adjust exposure of shadows. + * @highlights: Adjust exposure of highlights. + * @whitepoint: Shift white point. + * @radius: Spatial extent. + * @compress: Compress the effect on shadows/highlights and preserve midtones. + * @shadows_ccorrect: Adjust saturation of shadows. + * @highlights_ccorrect: Adjust saturation of highlights. + * + * Perform shadows and highlights correction. + * + * This filter allows adjusting shadows and highlights in the image + * separately. The implementation closely follow its counterpart in the + * Darktable photography software. + * + * Returns: TRUE on success. + * + * Since: 2.10 + **/ +gboolean +gimp_drawable_shadows_highlights (GimpDrawable *drawable, + gdouble shadows, + gdouble highlights, + gdouble whitepoint, + gdouble radius, + gdouble compress, + gdouble shadows_ccorrect, + gdouble highlights_ccorrect) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean success = TRUE; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_DRAWABLE, drawable, + G_TYPE_DOUBLE, shadows, + G_TYPE_DOUBLE, highlights, + G_TYPE_DOUBLE, whitepoint, + G_TYPE_DOUBLE, radius, + G_TYPE_DOUBLE, compress, + G_TYPE_DOUBLE, shadows_ccorrect, + G_TYPE_DOUBLE, highlights_ccorrect, + G_TYPE_NONE); + + return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-drawable-shadows-highlights", + args); + gimp_value_array_unref (args); + + success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; + + gimp_value_array_unref (return_vals); + + return success; +} + /** * gimp_drawable_posterize: * @drawable: The drawable. diff --git a/libgimp/gimpdrawablecolor_pdb.h b/libgimp/gimpdrawablecolor_pdb.h index 0d1ebf3b69..1ca673a841 100644 --- a/libgimp/gimpdrawablecolor_pdb.h +++ b/libgimp/gimpdrawablecolor_pdb.h @@ -85,6 +85,14 @@ gboolean gimp_drawable_levels (GimpDrawable *drawable, gdouble high_output, gboolean clamp_output); gboolean gimp_drawable_levels_stretch (GimpDrawable *drawable); +gboolean gimp_drawable_shadows_highlights (GimpDrawable *drawable, + gdouble shadows, + gdouble highlights, + gdouble whitepoint, + gdouble radius, + gdouble compress, + gdouble shadows_ccorrect, + gdouble highlights_ccorrect); gboolean gimp_drawable_posterize (GimpDrawable *drawable, gint levels); gboolean gimp_drawable_threshold (GimpDrawable *drawable, diff --git a/pdb/groups/drawable_color.pdb b/pdb/groups/drawable_color.pdb index 1f0628d8f8..ef21f112a3 100644 --- a/pdb/groups/drawable_color.pdb +++ b/pdb/groups/drawable_color.pdb @@ -705,6 +705,68 @@ CODE ); } +sub drawable_shadows_highlights { + $blurb = 'Perform shadows and highlights correction.'; + + $help = <<'HELP'; +This filter allows adjusting shadows and highlights in the image +separately. The implementation closely follow its counterpart in the +Darktable photography software. +HELP + + $date = '2021'; + $since = '2.10'; + + @inargs = ( + { name => 'drawable', type => 'drawable', + desc => 'The drawable' }, + { name => 'shadows', type => '-100 <= float <= 100', + desc => 'Adjust exposure of shadows' }, + { name => 'highlights', type => '-100 <= float <= 100', + desc => 'Adjust exposure of highlights' }, + { name => 'whitepoint', type => '-10 <= float <= 10', + desc => 'Shift white point' }, + { name => 'radius', type => '0.1 <= float <= 1500', + desc => 'Spatial extent' }, + { name => 'compress', type => '0 <= float <= 100', + desc => 'Compress the effect on shadows/highlights and preserve midtones' }, + { name => 'shadows_ccorrect', type => '0 <= float <= 100', + desc => 'Adjust saturation of shadows' }, + { name => 'highlights_ccorrect', type => '0 <= float <= 100', + desc => 'Adjust saturation of highlights' }, + ); + + %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)) + { + GeglNode *node; + node = gegl_node_new_child (NULL, + "operation", "gegl:shadows-highlights", + "shadows", shadows, + "highlights", highlights, + "whitepoint", whitepoint, + "radius", radius, + "compress", compress, + "shadows_correct", shadows_ccorrect, + "highlights_correct", highlights_ccorrect, + NULL); + + gimp_drawable_apply_operation (drawable, progress, + C_("undo-type", "Shadows-Highlights"), + node); + g_object_unref (node); + } + else + success = FALSE; +} +CODE + ); +} + sub drawable_posterize { $blurb = 'Posterize the specified drawable.'; @@ -821,6 +883,7 @@ CODE drawable_invert drawable_levels drawable_levels_stretch + drawable_shadows_highlights drawable_posterize drawable_threshold);