[gimp] plug-ins,pdb: Add a compatibility wrapper for lens-distortion



commit f3d40dceec4d436510ff9b8cc6b6286a5f7dfef9
Author: Téo Mazars <teo mazars ensimag fr>
Date:   Fri Oct 11 08:42:26 2013 +0200

    plug-ins,pdb: Add a compatibility wrapper for lens-distortion
    
    ... and remove the old plug-in

 app/pdb/internal-procs.c            |    2 +-
 app/pdb/plug-in-compat-cmds.c       |  146 +++++++++
 plug-ins/common/.gitignore          |    2 -
 plug-ins/common/Makefile.am         |   18 -
 plug-ins/common/gimprc.common       |    1 -
 plug-ins/common/lens-distortion.c   |  614 -----------------------------------
 plug-ins/common/plugin-defs.pl      |    1 -
 po-plug-ins/POTFILES.in             |    1 -
 tools/pdbgen/pdb/plug_in_compat.pdb |   81 +++++
 9 files changed, 228 insertions(+), 638 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 2a26826..790cb86 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 700 procedures registered total */
+/* 701 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index c317d00..7b3d9fe 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -525,6 +525,80 @@ plug_in_laplace_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+plug_in_lens_distortion_invoker (GimpProcedure         *procedure,
+                                 Gimp                  *gimp,
+                                 GimpContext           *context,
+                                 GimpProgress          *progress,
+                                 const GimpValueArray  *args,
+                                 GError               **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+  gdouble offset_x;
+  gdouble offset_y;
+  gdouble main_adjust;
+  gdouble edge_adjust;
+  gdouble rescale;
+  gdouble brighten;
+
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+  offset_x = g_value_get_double (gimp_value_array_index (args, 3));
+  offset_y = g_value_get_double (gimp_value_array_index (args, 4));
+  main_adjust = g_value_get_double (gimp_value_array_index (args, 5));
+  edge_adjust = g_value_get_double (gimp_value_array_index (args, 6));
+  rescale = g_value_get_double (gimp_value_array_index (args, 7));
+  brighten = g_value_get_double (gimp_value_array_index (args, 8));
+
+  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 = NULL;
+          GimpRGB    color;
+          GeglColor *gegl_color;
+
+          gimp_context_get_background (context, &color);
+
+          if (gimp_drawable_has_alpha (drawable))
+            {
+              gimp_rgb_set_alpha (&color, 0.0);
+            }
+          else
+            {
+              gimp_rgb_set_alpha (&color, 1.0);
+            }
+
+          gegl_color = gimp_gegl_color_new (&color);
+
+          node =  gegl_node_new_child (NULL,
+                                       "operation", "gegl:lens-distortion",
+                                       "main",       (gdouble) main_adjust,
+                                       "edge",       (gdouble) edge_adjust,
+                                       "zoom",       (gdouble) rescale,
+                                       "x-shift",    (gdouble) offset_x,
+                                       "y-shift",    (gdouble) offset_y,
+                                       "brighten",   (gdouble) brighten,
+                                       "background", gegl_color,
+                                       NULL);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                        C_("undo-type", "Lens Distortion"),
+                                        node);
+          g_object_unref (gegl_color);
+          g_object_unref (node);
+
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 plug_in_make_seamless_invoker (GimpProcedure         *procedure,
                                Gimp                  *gimp,
                                GimpContext           *context,
@@ -2035,6 +2109,78 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-plug-in-lens-distortion
+   */
+  procedure = gimp_procedure_new (plug_in_lens_distortion_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-lens-distortion");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-lens-distortion",
+                                     "Corrects lens distortion",
+                                     "Corrects barrel or pincushion lens distortion.",
+                                     "Compatibility procedure. Please see 'gegl:lens-distortion' for 
credits.",
+                                     "Compatibility procedure. Please see 'gegl:lens-distortion' for 
credits.",
+                                     "2013",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("run-mode",
+                                                  "run mode",
+                                                  "The run mode",
+                                                  GIMP_TYPE_RUN_MODE,
+                                                  GIMP_RUN_INTERACTIVE,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_image_id ("image",
+                                                         "image",
+                                                         "Input image (unused)",
+                                                         pdb->gimp, FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_drawable_id ("drawable",
+                                                            "drawable",
+                                                            "Input drawable",
+                                                            pdb->gimp, FALSE,
+                                                            GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("offset-x",
+                                                    "offset x",
+                                                    "Effect centre offset in X",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("offset-y",
+                                                    "offset y",
+                                                    "Effect centre offset in Y",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("main-adjust",
+                                                    "main adjust",
+                                                    "Amount of second-order distortion",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("edge-adjust",
+                                                    "edge adjust",
+                                                    "Amount of fourth-order distortion",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("rescale",
+                                                    "rescale",
+                                                    "Rescale overall image size",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("brighten",
+                                                    "brighten",
+                                                    "Adjust brightness in corners",
+                                                    -100, 100, -100,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-plug-in-make-seamless
    */
   procedure = gimp_procedure_new (plug_in_make_seamless_invoker);
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 2ab2824..6cb37a8 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -176,8 +176,6 @@
 /lcms.exe
 /lens-apply
 /lens-apply.exe
-/lens-distortion
-/lens-distortion.exe
 /lens-flare
 /lens-flare.exe
 /mail
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 1094d3a..441aae7 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -131,7 +131,6 @@ libexec_PROGRAMS = \
        jigsaw \
        $(LCMS) \
        lens-apply \
-       lens-distortion \
        lens-flare \
        $(MAIL) \
        max-rgb \
@@ -1723,23 +1722,6 @@ lens_apply_LDADD = \
        $(INTLLIBS)             \
        $(lens_apply_RC)
 
-lens_distortion_SOURCES = \
-       lens-distortion.c
-
-lens_distortion_LDADD = \
-       $(libgimpui)            \
-       $(libgimpwidgets)       \
-       $(libgimpmodule)        \
-       $(libgimp)              \
-       $(libgimpmath)          \
-       $(libgimpconfig)        \
-       $(libgimpcolor)         \
-       $(libgimpbase)          \
-       $(GTK_LIBS)             \
-       $(RT_LIBS)              \
-       $(INTLLIBS)             \
-       $(lens_distortion_RC)
-
 lens_flare_SOURCES = \
        lens-flare.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index 39b7fb1..3a4bae5 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -85,7 +85,6 @@ iwarp_RC = iwarp.rc.o
 jigsaw_RC = jigsaw.rc.o
 lcms_RC = lcms.rc.o
 lens_apply_RC = lens-apply.rc.o
-lens_distortion_RC = lens-distortion.rc.o
 lens_flare_RC = lens-flare.rc.o
 mail_RC = mail.rc.o
 max_rgb_RC = max-rgb.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 100e8c0..5722c4e 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -86,7 +86,6 @@
     'jigsaw' => { ui => 1 },
     'lcms' => { ui => 1, gegl => 1, optional => 1, libs => 'LCMS_LIBS', cflags => 'LCMS_CFLAGS' },
     'lens-apply' => { ui => 1 },
-    'lens-distortion' => { ui => 1 },
     'lens-flare' => { ui => 1 },
     'mail' => { ui => 1, optional => 1 },
     'max-rgb' => { ui => 1 },
diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in
index 058f53b..d9c9502 100644
--- a/po-plug-ins/POTFILES.in
+++ b/po-plug-ins/POTFILES.in
@@ -93,7 +93,6 @@ plug-ins/common/iwarp.c
 plug-ins/common/jigsaw.c
 plug-ins/common/lcms.c
 plug-ins/common/lens-apply.c
-plug-ins/common/lens-distortion.c
 plug-ins/common/lens-flare.c
 plug-ins/common/mail.c
 plug-ins/common/max-rgb.c
diff --git a/tools/pdbgen/pdb/plug_in_compat.pdb b/tools/pdbgen/pdb/plug_in_compat.pdb
index 9302403..7c25598 100644
--- a/tools/pdbgen/pdb/plug_in_compat.pdb
+++ b/tools/pdbgen/pdb/plug_in_compat.pdb
@@ -546,6 +546,86 @@ CODE
     );
 }
 
+sub plug_in_lens_distortion {
+    $blurb = 'Corrects lens distortion';
+
+    $help = <<'HELP';
+Corrects barrel or pincushion lens distortion.
+HELP
+
+    &std_pdb_compat('gegl:lens-distortion');
+    $date = '2013';
+
+    @inargs = (
+       { name => 'run_mode', type => 'enum GimpRunMode', dead => 1,
+         desc => 'The run mode' },
+       { name => 'image', type => 'image', dead => 1,
+         desc => 'Input image (unused)' },
+       { name => 'drawable', type => 'drawable',
+         desc => 'Input drawable' },
+       { name => 'offset_x', type => '-100 <= float <= 100',
+         desc => 'Effect centre offset in X' },
+       { name => 'offset_y', type => '-100 <= float <= 100',
+         desc => 'Effect centre offset in Y' },
+       { name => 'main_adjust', type => '-100 <= float <= 100',
+         desc => 'Amount of second-order distortion' },
+       { name => 'edge_adjust', type => '-100 <= float <= 100',
+         desc => 'Amount of fourth-order distortion' },
+       { name => 'rescale', type => '-100 <= float <= 100',
+         desc => 'Rescale overall image size' },
+       { name => 'brighten', type => '-100 <= float <= 100',
+         desc => 'Adjust brightness in corners' }
+    );
+
+    %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 = NULL;
+      GimpRGB    color;
+      GeglColor *gegl_color;
+
+      gimp_context_get_background (context, &color);
+
+      if (gimp_drawable_has_alpha (drawable))
+        {
+          gimp_rgb_set_alpha (&color, 0.0);
+        }
+      else
+        {
+          gimp_rgb_set_alpha (&color, 1.0);
+        }
+
+      gegl_color = gimp_gegl_color_new (&color);
+
+      node =  gegl_node_new_child (NULL,
+                                   "operation", "gegl:lens-distortion",
+                                   "main",       (gdouble) main_adjust,
+                                   "edge",       (gdouble) edge_adjust,
+                                   "zoom",       (gdouble) rescale,
+                                   "x-shift",    (gdouble) offset_x,
+                                   "y-shift",    (gdouble) offset_y,
+                                   "brighten",   (gdouble) brighten,
+                                   "background", gegl_color,
+                                   NULL);
+ 
+      gimp_drawable_apply_operation (drawable, progress,
+                                    C_("undo-type", "Lens Distortion"),
+                                    node);
+      g_object_unref (gegl_color);
+      g_object_unref (node);
+
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_make_seamless {
     $blurb = 'Alters edges to make the image seamlessly tileable';
 
@@ -1726,6 +1806,7 @@ CODE
            plug_in_cubism
            plug_in_hsv_noise
             plug_in_laplace
+            plug_in_lens_distortion
             plug_in_make_seamless
             plug_in_mblur
             plug_in_mblur_inward


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