[gimp] pdb, libgimp: rename gimp_drawable_invert() to _invert_non_linear()



commit 2e6c39ed9c9868bdfc34cc877b3b89103b7188bc
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 30 12:27:17 2017 +0200

    pdb, libgimp: rename gimp_drawable_invert() to _invert_non_linear()
    
    and add gimp_drawable_invert_linear(). Also, finally deprecate
    gimp_invert() and port all its uses in plug-ins and scripts to
    gimp_drawable_invert_non_linear() so the result is the same.

 app/pdb/color-cmds.c                          |   12 ++--
 app/pdb/drawable-color-cmds.c                 |   77 +++++++++++++++++++++----
 app/pdb/internal-procs.c                      |    2 +-
 libgimp/gimp.def                              |    3 +-
 libgimp/gimpcolor_pdb.c                       |    6 +--
 libgimp/gimpcolor_pdb.h                       |    1 +
 libgimp/gimpdrawablecolor_pdb.c               |   41 ++++++++++++-
 libgimp/gimpdrawablecolor_pdb.h               |    3 +-
 plug-ins/pygimp/plug-ins/shadow_bevel.py      |    2 +-
 plug-ins/script-fu/scripts/carve-it.scm       |    2 +-
 plug-ins/script-fu/scripts/chrome-it.scm      |    4 +-
 plug-ins/script-fu/scripts/fuzzyborder.scm    |    2 +-
 plug-ins/script-fu/scripts/script-fu-util.scm |    4 +-
 tools/pdbgen/pdb/color.pdb                    |   10 +---
 tools/pdbgen/pdb/drawable_color.pdb           |   48 ++++++++++++++--
 15 files changed, 167 insertions(+), 50 deletions(-)
---
diff --git a/app/pdb/color-cmds.c b/app/pdb/color-cmds.c
index 2297f4d..a9e548c 100644
--- a/app/pdb/color-cmds.c
+++ b/app/pdb/color-cmds.c
@@ -1054,12 +1054,12 @@ register_color_procs (GimpPDB *pdb)
                                "gimp-invert");
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-invert",
-                                     "Invert the contents of the specified drawable.",
-                                     "This procedure inverts the contents of the specified drawable. Each 
intensity channel is inverted independently. The inverted intensity is given as inten' = (255 - inten).",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "1995-1996",
-                                     NULL);
+                                     "Deprecated: Use 'gimp-drawable-invert-non-linear' instead.",
+                                     "Deprecated: Use 'gimp-drawable-invert-non-linear' instead.",
+                                     "",
+                                     "",
+                                     "",
+                                     "gimp-drawable-invert-non-linear");
   gimp_procedure_add_argument (procedure,
                                gimp_param_spec_drawable_id ("drawable",
                                                             "drawable",
diff --git a/app/pdb/drawable-color-cmds.c b/app/pdb/drawable-color-cmds.c
index 30347b0..d87a9e6 100644
--- a/app/pdb/drawable-color-cmds.c
+++ b/app/pdb/drawable-color-cmds.c
@@ -518,12 +518,44 @@ drawable_hue_saturation_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
-drawable_invert_invoker (GimpProcedure         *procedure,
-                         Gimp                  *gimp,
-                         GimpContext           *context,
-                         GimpProgress          *progress,
-                         const GimpValueArray  *args,
-                         GError               **error)
+drawable_invert_linear_invoker (GimpProcedure         *procedure,
+                                Gimp                  *gimp,
+                                GimpContext           *context,
+                                GimpProgress          *progress,
+                                const GimpValueArray  *args,
+                                GError               **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
+
+  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_apply_operation_by_name (drawable, progress,
+                                                 C_("undo-type", "Invert"),
+                                                 "gegl:invert-linear",
+                                                 NULL);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
+drawable_invert_non_linear_invoker (GimpProcedure         *procedure,
+                                    Gimp                  *gimp,
+                                    GimpContext           *context,
+                                    GimpProgress          *progress,
+                                    const GimpValueArray  *args,
+                                    GError               **error)
 {
   gboolean success = TRUE;
   GimpDrawable *drawable;
@@ -1134,14 +1166,37 @@ register_drawable_color_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
-   * gimp-drawable-invert
+   * gimp-drawable-invert-linear
+   */
+  procedure = gimp_procedure_new (drawable_invert_linear_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-drawable-invert-linear");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-drawable-invert-linear",
+                                     "Invert the contents of the specified drawable in linear light.",
+                                     "This procedure inverts the contents of the specified drawable. Each 
component inverted independently. This procedure works on linear RGB or Gray values.",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "Spencer Kimball & Peter Mattis",
+                                     "1995-1996",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_drawable_id ("drawable",
+                                                            "drawable",
+                                                            "The drawable",
+                                                            pdb->gimp, FALSE,
+                                                            GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-drawable-invert-non-linear
    */
-  procedure = gimp_procedure_new (drawable_invert_invoker);
+  procedure = gimp_procedure_new (drawable_invert_non_linear_invoker);
   gimp_object_set_static_name (GIMP_OBJECT (procedure),
-                               "gimp-drawable-invert");
+                               "gimp-drawable-invert-non-linear");
   gimp_procedure_set_static_strings (procedure,
-                                     "gimp-drawable-invert",
-                                     "Invert the contents of the specified drawable.",
+                                     "gimp-drawable-invert-non-linear",
+                                     "Invert the contents of the specified drawable in perceptual space.",
                                      "This procedure inverts the contents of the specified drawable. Each 
intensity channel is inverted independently. The inverted intensity is given as inten' = (255 - inten).",
                                      "Spencer Kimball & Peter Mattis",
                                      "Spencer Kimball & Peter Mattis",
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 9083d52..40ca864 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 812 procedures registered total */
+/* 813 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 3c3ddc7..34418b7 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -229,7 +229,8 @@ EXPORTS
        gimp_drawable_height
        gimp_drawable_histogram
        gimp_drawable_hue_saturation
-       gimp_drawable_invert
+       gimp_drawable_invert_linear
+       gimp_drawable_invert_non_linear
        gimp_drawable_is_channel
        gimp_drawable_is_gray
        gimp_drawable_is_indexed
diff --git a/libgimp/gimpcolor_pdb.c b/libgimp/gimpcolor_pdb.c
index b8f0c42..76e22fc 100644
--- a/libgimp/gimpcolor_pdb.c
+++ b/libgimp/gimpcolor_pdb.c
@@ -289,11 +289,7 @@ gimp_equalize (gint32   drawable_ID,
  * gimp_invert:
  * @drawable_ID: The drawable.
  *
- * Invert the contents of the specified drawable.
- *
- * This procedure inverts the contents of the specified drawable. Each
- * intensity channel is inverted independently. The inverted intensity
- * is given as inten' = (255 - inten).
+ * Deprecated: Use gimp_drawable_invert_non_linear() instead.
  *
  * Returns: TRUE on success.
  **/
diff --git a/libgimp/gimpcolor_pdb.h b/libgimp/gimpcolor_pdb.h
index 00cd452..1b7130f 100644
--- a/libgimp/gimpcolor_pdb.h
+++ b/libgimp/gimpcolor_pdb.h
@@ -59,6 +59,7 @@ gboolean gimp_desaturate_full     (gint32                drawable_ID,
 GIMP_DEPRECATED_FOR(gimp_drawable_equalize)
 gboolean gimp_equalize            (gint32                drawable_ID,
                                    gboolean              mask_only);
+GIMP_DEPRECATED_FOR(gimp_drawable_invert_non_linear)
 gboolean gimp_invert              (gint32                drawable_ID);
 GIMP_DEPRECATED_FOR(gimp_drawable_curves_spline)
 gboolean gimp_curves_spline       (gint32                drawable_ID,
diff --git a/libgimp/gimpdrawablecolor_pdb.c b/libgimp/gimpdrawablecolor_pdb.c
index 7541d49..c66901c 100644
--- a/libgimp/gimpdrawablecolor_pdb.c
+++ b/libgimp/gimpdrawablecolor_pdb.c
@@ -472,10 +472,43 @@ gimp_drawable_hue_saturation (gint32       drawable_ID,
 }
 
 /**
- * gimp_drawable_invert:
+ * gimp_drawable_invert_linear:
  * @drawable_ID: The drawable.
  *
- * Invert the contents of the specified drawable.
+ * Invert the contents of the specified drawable in linear light.
+ *
+ * This procedure inverts the contents of the specified drawable. Each
+ * component inverted independently. This procedure works on linear RGB
+ * or Gray values.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_drawable_invert_linear (gint32 drawable_ID)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-drawable-invert-linear",
+                                    &nreturn_vals,
+                                    GIMP_PDB_DRAWABLE, drawable_ID,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
+ * gimp_drawable_invert_non_linear:
+ * @drawable_ID: The drawable.
+ *
+ * Invert the contents of the specified drawable in perceptual space.
  *
  * This procedure inverts the contents of the specified drawable. Each
  * intensity channel is inverted independently. The inverted intensity
@@ -486,13 +519,13 @@ gimp_drawable_hue_saturation (gint32       drawable_ID,
  * Since: 2.10
  **/
 gboolean
-gimp_drawable_invert (gint32 drawable_ID)
+gimp_drawable_invert_non_linear (gint32 drawable_ID)
 {
   GimpParam *return_vals;
   gint nreturn_vals;
   gboolean success = TRUE;
 
-  return_vals = gimp_run_procedure ("gimp-drawable-invert",
+  return_vals = gimp_run_procedure ("gimp-drawable-invert-non-linear",
                                     &nreturn_vals,
                                     GIMP_PDB_DRAWABLE, drawable_ID,
                                     GIMP_PDB_END);
diff --git a/libgimp/gimpdrawablecolor_pdb.h b/libgimp/gimpdrawablecolor_pdb.h
index a30f1dd..519a993 100644
--- a/libgimp/gimpdrawablecolor_pdb.h
+++ b/libgimp/gimpdrawablecolor_pdb.h
@@ -73,7 +73,8 @@ gboolean gimp_drawable_hue_saturation      (gint32                drawable_ID,
                                             gdouble               lightness,
                                             gdouble               saturation,
                                             gdouble               overlap);
-gboolean gimp_drawable_invert              (gint32                drawable_ID);
+gboolean gimp_drawable_invert_linear       (gint32                drawable_ID);
+gboolean gimp_drawable_invert_non_linear   (gint32                drawable_ID);
 gboolean gimp_drawable_levels              (gint32                drawable_ID,
                                             GimpHistogramChannel  channel,
                                             gdouble               low_input,
diff --git a/plug-ins/pygimp/plug-ins/shadow_bevel.py b/plug-ins/pygimp/plug-ins/shadow_bevel.py
index 3bd40dd..4667896 100755
--- a/plug-ins/pygimp/plug-ins/shadow_bevel.py
+++ b/plug-ins/pygimp/plug-ins/shadow_bevel.py
@@ -42,7 +42,7 @@ def shadow_bevel(img, drawable, blur, bevel, do_shadow, drop_x, drop_y):
                              0, 0, 0, 0, True, False, 0)
 
     # make the shadow layer black now ...
-    pdb.gimp_invert(shadow)
+    pdb.gimp_drawable_invert_non_linear(shadow)
 
     # translate the drop shadow
     shadow.translate(drop_x, drop_y)
diff --git a/plug-ins/script-fu/scripts/carve-it.scm b/plug-ins/script-fu/scripts/carve-it.scm
index 5cda3da..d5d5193 100644
--- a/plug-ins/script-fu/scripts/carve-it.scm
+++ b/plug-ins/script-fu/scripts/carve-it.scm
@@ -95,7 +95,7 @@
     (set! mask-fs (car (gimp-edit-paste mask FALSE)))
     (gimp-floating-sel-anchor mask-fs)
     (if (= carve-white FALSE)
-        (gimp-invert mask))
+        (gimp-drawable-invert-non-linear mask))
 
     (set! mask-fat (car (gimp-channel-copy mask)))
     (gimp-image-insert-channel img mask-fat -1 0)
diff --git a/plug-ins/script-fu/scripts/chrome-it.scm b/plug-ins/script-fu/scripts/chrome-it.scm
index ca6b38f..96bc3b5 100644
--- a/plug-ins/script-fu/scripts/chrome-it.scm
+++ b/plug-ins/script-fu/scripts/chrome-it.scm
@@ -124,7 +124,7 @@
     (set! mask-fs (car (gimp-edit-paste mask FALSE)))
     (gimp-floating-sel-anchor mask-fs)
     (if (= carve-white FALSE)
-        (gimp-invert mask)
+        (gimp-drawable-invert-non-linear mask)
     )
 
     (gimp-context-set-background '(255 255 255))
@@ -145,7 +145,7 @@
     (gimp-edit-fill layer3 FILL-BACKGROUND)
     (gimp-selection-none img)
     (set! layer2 (car (gimp-image-merge-visible-layers img CLIP-TO-IMAGE)))
-    (gimp-invert layer2)
+    (gimp-drawable-invert-non-linear layer2)
 
     (gimp-image-insert-layer img layer1 0 0)
     (copy-layer-chrome-it img layer1 banding-img banding-layer)
diff --git a/plug-ins/script-fu/scripts/fuzzyborder.scm b/plug-ins/script-fu/scripts/fuzzyborder.scm
index cefdcad..bda183c 100644
--- a/plug-ins/script-fu/scripts/fuzzyborder.scm
+++ b/plug-ins/script-fu/scripts/fuzzyborder.scm
@@ -112,7 +112,7 @@
                             (- theWidth inSize) (- theHeight inSize) TRUE)
           (gimp-drawable-desaturate theLayer DESATURATE-LIGHTNESS)
           (gimp-drawable-brightness-contrast theLayer 0.5 0.5)
-          (gimp-invert theLayer)
+          (gimp-drawable-invert-non-linear theLayer)
           (gimp-layer-resize theLayer
                              theWidth
                              theHeight
diff --git a/plug-ins/script-fu/scripts/script-fu-util.scm b/plug-ins/script-fu/scripts/script-fu-util.scm
index e9e7adf..61d610b 100644
--- a/plug-ins/script-fu/scripts/script-fu-util.scm
+++ b/plug-ins/script-fu/scripts/script-fu-util.scm
@@ -60,12 +60,12 @@
 ; For example, to invert the colors of all of the PNG files in the
 ; start directory:
 ;
-;    gimp -i -b '(with-files "*.png" (gimp-invert layer) \
+;    gimp -i -b '(with-files "*.png" (gimp-drawable-invert-non-linear layer) \
 ;                 (gimp-file-save 1 image layer filename filename ))'
 ;
 ; To do the same thing, but saving them as jpeg instead:
 ;
-;    gimp -i -b '(with-files "*.png" (gimp-invert layer) \
+;    gimp -i -b '(with-files "*.png" (gimp-drawable-invert-non-linear layer) \
 ;                 (gimp-file-save 1 image layer \
 ;                  (string-append basename ".jpg") \
 ;                  (string-append basename ".jpg") ))'
diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb
index 75c8cfd..d597a5e 100644
--- a/tools/pdbgen/pdb/color.pdb
+++ b/tools/pdbgen/pdb/color.pdb
@@ -294,15 +294,7 @@ CODE
 }
 
 sub invert {
-    $blurb = 'Invert the contents of the specified drawable.';
-
-    $help = <<'HELP';
-This procedure inverts the contents of the specified drawable. Each intensity
-channel is inverted independently. The inverted intensity is given as inten' =
-(255 - inten).
-HELP
-
-    &std_pdb_misc;
+    &std_pdb_deprecated ('gimp-drawable-invert-non-linear');
 
     @inargs = (
        { name => 'drawable', type => 'drawable',
diff --git a/tools/pdbgen/pdb/drawable_color.pdb b/tools/pdbgen/pdb/drawable_color.pdb
index 3c86c92..9d710fe 100644
--- a/tools/pdbgen/pdb/drawable_color.pdb
+++ b/tools/pdbgen/pdb/drawable_color.pdb
@@ -558,8 +558,43 @@ CODE
     );
 }
 
-sub drawable_invert {
-    $blurb = 'Invert the contents of the specified drawable.';
+sub drawable_invert_linear {
+    $blurb = 'Invert the contents of the specified drawable in linear light.';
+
+    $help = <<'HELP';
+This procedure inverts the contents of the specified drawable. Each component
+inverted independently. This procedure works on linear RGB or Gray values.
+HELP
+
+    &std_pdb_misc;
+    $since = '2.10';
+
+    @inargs = (
+       { name => 'drawable', type => 'drawable',
+         desc => 'The drawable' }
+    );
+
+    %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_apply_operation_by_name (drawable, progress,
+                                             C_("undo-type", "Invert"),
+                                             "gegl:invert-linear",
+                                             NULL);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub drawable_invert_non_linear {
+    $blurb = 'Invert the contents of the specified drawable in perceptual space.';
 
     $help = <<'HELP';
 This procedure inverts the contents of the specified drawable. Each intensity
@@ -811,13 +846,16 @@ CODE
 @procs = qw(drawable_brightness_contrast
             drawable_color_balance
             drawable_colorize_hsl
-            drawable_curves_explicit drawable_curves_spline
+            drawable_curves_explicit
+            drawable_curves_spline
             drawable_desaturate
             drawable_equalize
             drawable_histogram
             drawable_hue_saturation
-            drawable_invert
-            drawable_levels drawable_levels_stretch
+            drawable_invert_linear
+            drawable_invert_non_linear
+            drawable_levels
+            drawable_levels_stretch
             drawable_posterize
             drawable_threshold);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]