[gimp] pdb, plug-ins: remove the newsprint plug-in and add a PDB compat procedure



commit 31fc338ab0f57c26af5e8be93b519d8b25ff0b66
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 18 12:52:18 2019 +0200

    pdb, plug-ins: remove the newsprint plug-in and add a PDB compat procedure

 app/pdb/internal-procs.c       |    2 +-
 app/pdb/plug-in-compat-cmds.c  |  239 ++++-
 pdb/groups/plug_in_compat.pdb  |  136 ++-
 plug-ins/common/.gitignore     |    2 -
 plug-ins/common/Makefile.am    |   19 -
 plug-ins/common/gimprc.common  |    1 -
 plug-ins/common/newsprint.c    | 2072 ----------------------------------------
 plug-ins/common/plugin-defs.pl |    1 -
 po-plug-ins/POTFILES.in        |    1 -
 9 files changed, 374 insertions(+), 2099 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 3cbfb383e1..3a30068838 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 741 procedures registered total */
+/* 742 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 5c12fdda07..6d22881a04 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -136,7 +136,7 @@ wrap_in_gamma_cast (GeglNode     *node,
       cast_format =
         gimp_babl_format (gimp_babl_format_get_base_type (drawable_format),
                           gimp_babl_precision (gimp_babl_format_get_component_type (drawable_format),
-                                               TRUE),
+                                               GIMP_TRC_LINEAR),
                           babl_format_has_alpha (drawable_format),
                           babl_format_get_space (drawable_format));
 
@@ -354,6 +354,47 @@ gaussian_blur (GimpDrawable  *drawable,
   return FALSE;
 }
 
+static gint
+newsprint_color_model (gint colorspace)
+{
+  switch (colorspace)
+    {
+    case 0: return 1; /* black on white */
+    case 1: return 2; /* rgb */
+    case 2: return 3; /* cmyk */
+    case 3: return 1; /* black on white */
+    }
+
+  return 2;
+}
+
+static gint
+newsprint_pattern (gint spotfn)
+{
+  switch (spotfn)
+    {
+    case 0: return 1; /* circle */
+    case 1: return 0; /* line */
+    case 2: return 2; /* diamond */
+    case 3: return 4; /* ps circle */
+    case 4: return 2; /* FIXME postscript diamond */
+    }
+
+  return 1;
+}
+
+static gdouble
+newsprint_angle (gdouble angle)
+{
+  while (angle > 180.0)
+    angle -= 360.0;
+
+  while (angle < -180.0)
+    angle += 360.0;
+
+  return angle;
+}
+
 static GimpValueArray *
 plug_in_alienmap2_invoker (GimpProcedure         *procedure,
                            Gimp                  *gimp,
@@ -2628,6 +2669,94 @@ plug_in_neon_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
+static GimpValueArray *
+plug_in_newsprint_invoker (GimpProcedure         *procedure,
+                           Gimp                  *gimp,
+                           GimpContext           *context,
+                           GimpProgress          *progress,
+                           const GimpValueArray  *args,
+                           GError               **error)
+{
+  gboolean success = TRUE;
+  GimpDrawable *drawable;
+  gint32 cell_width;
+  gint32 colorspace;
+  gint32 k_pullout;
+  gdouble gry_ang;
+  gint32 gry_spotfn;
+  gdouble red_ang;
+  gint32 red_spotfn;
+  gdouble grn_ang;
+  gint32 grn_spotfn;
+  gdouble blu_ang;
+  gint32 blu_spotfn;
+  gint32 oversample;
+
+  drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
+  cell_width = g_value_get_int (gimp_value_array_index (args, 3));
+  colorspace = g_value_get_int (gimp_value_array_index (args, 4));
+  k_pullout = g_value_get_int (gimp_value_array_index (args, 5));
+  gry_ang = g_value_get_double (gimp_value_array_index (args, 6));
+  gry_spotfn = g_value_get_int (gimp_value_array_index (args, 7));
+  red_ang = g_value_get_double (gimp_value_array_index (args, 8));
+  red_spotfn = g_value_get_int (gimp_value_array_index (args, 9));
+  grn_ang = g_value_get_double (gimp_value_array_index (args, 10));
+  grn_spotfn = g_value_get_int (gimp_value_array_index (args, 11));
+  blu_ang = g_value_get_double (gimp_value_array_index (args, 12));
+  blu_spotfn = g_value_get_int (gimp_value_array_index (args, 13));
+  oversample = g_value_get_int (gimp_value_array_index (args, 14));
+
+  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;
+          gint      color_model = newsprint_color_model (colorspace);
+          gint      pattern     = newsprint_pattern (gry_spotfn);
+          gint      pattern2    = newsprint_pattern (red_spotfn);
+          gint      pattern3    = newsprint_pattern (grn_spotfn);
+          gint      pattern4    = newsprint_pattern (blu_spotfn);
+          gdouble   angle       = newsprint_angle (gry_ang);
+          gdouble   angle2      = newsprint_angle (red_ang);
+          gdouble   angle3      = newsprint_angle (grn_ang);
+          gdouble   angle4      = newsprint_angle (blu_ang);
+
+          node = gegl_node_new_child (NULL,
+                                      "operation",     "gegl:newsprint",
+                                      "color-model",   color_model,
+                                      "black-pullout", (gdouble) k_pullout / 100.0,
+                                      "period",        (gdouble) cell_width,
+                                      "angle",         angle,
+                                      "pattern",       pattern,
+                                      "period2",       (gdouble) cell_width,
+                                      "angle2",        angle2,
+                                      "pattern2",      pattern2,
+                                      "period3",       (gdouble) cell_width,
+                                      "angle3",        angle3,
+                                      "pattern3",      pattern3,
+                                      "period4",       (gdouble) cell_width,
+                                      "angle4",        angle4,
+                                      "pattern4",      pattern4,
+                                      "aa-samples",    oversample,
+                                      NULL);
+
+          node = wrap_in_gamma_cast (node, drawable);
+
+          gimp_drawable_apply_operation (drawable, progress,
+                                         C_("undo-type", "Newsprint"),
+                                         node);
+          g_object_unref (node);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 plug_in_normalize_invoker (GimpProcedure         *procedure,
                            Gimp                  *gimp,
@@ -7012,6 +7141,114 @@ register_plug_in_compat_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-plug-in-newsprint
+   */
+  procedure = gimp_procedure_new (plug_in_newsprint_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "plug-in-newsprint");
+  gimp_procedure_set_static_strings (procedure,
+                                     "plug-in-newsprint",
+                                     "Halftone the image to give newspaper-like effect",
+                                     "Halftone the image to give newspaper-like effect",
+                                     "Compatibility procedure. Please see 'gegl:newsprint' for credits.",
+                                     "Compatibility procedure. Please see 'gegl:newsprint' for credits.",
+                                     "2019",
+                                     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,
+                               gimp_param_spec_int32 ("cell-width",
+                                                      "cell width",
+                                                      "Screen cell width in pixels",
+                                                      0, 1500, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("colorspace",
+                                                      "colorspace",
+                                                      "Separate to { GRAYSCALE (0), RGB (1), CMYK (2), 
LUMINANCE (3) }",
+                                                      0, 3, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("k-pullout",
+                                                      "k pullout",
+                                                      "Percentage of black to pullout (CMYK only)",
+                                                      0, 100, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("gry-ang",
+                                                    "gry ang",
+                                                    "Grey/black screen angle (degrees)",
+                                                    0.0, 360.0, 0.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("gry-spotfn",
+                                                      "gry spotfn",
+                                                      "Grey/black spot function { DOTS (0), LINES (1), 
DIAMONDS (2), EUCLIDIAN-DOT (3), PS-DIAMONDS (4) }",
+                                                      0, 4, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("red-ang",
+                                                    "red ang",
+                                                    "Red/cyan screen angle (degrees)",
+                                                    0.0, 360.0, 0.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("red-spotfn",
+                                                      "red spotfn",
+                                                      "Red/cyan spot function { DOTS (0), LINES (1), 
DIAMONDS (2), EUCLIDIAN-DOT (3), PS-DIAMONDS (4) }",
+                                                      0, 4, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("grn-ang",
+                                                    "grn ang",
+                                                    "Green/magenta screen angle (degrees)",
+                                                    0.0, 360.0, 0.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("grn-spotfn",
+                                                      "grn spotfn",
+                                                      "Green/magenta spot function { DOTS (0), LINES (1), 
DIAMONDS (2), EUCLIDIAN-DOT (3), PS-DIAMONDS (4) }",
+                                                      0, 4, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_double ("blu-ang",
+                                                    "blu ang",
+                                                    "Blue/yellow screen angle (degrees)",
+                                                    0.0, 360.0, 0.0,
+                                                    GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("blu-spotfn",
+                                                      "blu spotfn",
+                                                      "Blue/yellow spot function { DOTS (0), LINES (1), 
DIAMONDS (2), EUCLIDIAN-DOT (3), PS-DIAMONDS (4) }",
+                                                      0, 4, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("oversample",
+                                                      "oversample",
+                                                      "how many times to oversample spot fn",
+                                                      0, 128, 0,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-plug-in-normalize
    */
diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb
index fcd7c4e3d3..5b49418f9a 100644
--- a/pdb/groups/plug_in_compat.pdb
+++ b/pdb/groups/plug_in_compat.pdb
@@ -2620,6 +2620,98 @@ CODE
     );
 }
 
+sub plug_in_newsprint {
+    $blurb = 'Halftone the image to give newspaper-like effect';
+
+    $help = $blurb;
+
+    &std_pdb_compat('gegl:newsprint');
+    $date = '2019';
+
+    @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 => 'cell_width', type => '0 <= int32 <= 1500',
+          desc => 'Screen cell width in pixels' },
+        { name => 'colorspace', type => '0 <= int32 <= 3',
+          desc => 'Separate to { GRAYSCALE (0), RGB (1), CMYK (2), LUMINANCE (3) }' },
+        { name => 'k_pullout', type => '0 <= int32 <= 100',
+          desc => 'Percentage of black to pullout (CMYK only)' },
+        { name => 'gry_ang', type => '0.0 <= float <= 360.0',
+          desc => 'Grey/black screen angle (degrees)' },
+        { name => 'gry_spotfn', type => '0 <= int32 <= 4',
+          desc => 'Grey/black spot function { DOTS (0), LINES (1), DIAMONDS (2), EUCLIDIAN-DOT (3), 
PS-DIAMONDS (4) }' },
+        { name => 'red_ang', type => '0.0 <= float <= 360.0',
+          desc => 'Red/cyan screen angle (degrees)' },
+        { name => 'red_spotfn', type => '0 <= int32 <= 4',
+          desc => 'Red/cyan spot function { DOTS (0), LINES (1), DIAMONDS (2), EUCLIDIAN-DOT (3), 
PS-DIAMONDS (4) }' },
+        { name => 'grn_ang', type => '0.0 <= float <= 360.0',
+          desc => 'Green/magenta screen angle (degrees)' },
+        { name => 'grn_spotfn', type => '0 <= int32 <= 4',
+          desc => 'Green/magenta spot function { DOTS (0), LINES (1), DIAMONDS (2), EUCLIDIAN-DOT (3), 
PS-DIAMONDS (4) }' },
+        { name => 'blu_ang', type => '0.0 <= float <= 360.0',
+          desc => 'Blue/yellow screen angle (degrees)' },
+        { name => 'blu_spotfn', type => '0 <= int32 <= 4',
+          desc => 'Blue/yellow spot function { DOTS (0), LINES (1), DIAMONDS (2), EUCLIDIAN-DOT (3), 
PS-DIAMONDS (4) }' },
+        { name => 'oversample', type => '0 <= int32 <= 128',
+          desc => 'how many times to oversample spot fn' }
+    );
+
+    %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;
+      gint      color_model = newsprint_color_model (colorspace);
+      gint      pattern     = newsprint_pattern (gry_spotfn);
+      gint      pattern2    = newsprint_pattern (red_spotfn);
+      gint      pattern3    = newsprint_pattern (grn_spotfn);
+      gint      pattern4    = newsprint_pattern (blu_spotfn);
+      gdouble   angle       = newsprint_angle (gry_ang);
+      gdouble   angle2      = newsprint_angle (red_ang);
+      gdouble   angle3      = newsprint_angle (grn_ang);
+      gdouble   angle4      = newsprint_angle (blu_ang);
+
+      node = gegl_node_new_child (NULL,
+                                  "operation",     "gegl:newsprint",
+                                  "color-model",   color_model,
+                                  "black-pullout", (gdouble) k_pullout / 100.0,
+                                  "period",        (gdouble) cell_width,
+                                  "angle",         angle,
+                                  "pattern",       pattern,
+                                  "period2",       (gdouble) cell_width,
+                                  "angle2",        angle2,
+                                  "pattern2",      pattern2,
+                                  "period3",       (gdouble) cell_width,
+                                  "angle3",        angle3,
+                                  "pattern3",      pattern3,
+                                  "period4",       (gdouble) cell_width,
+                                  "angle4",        angle4,
+                                  "pattern4",      pattern4,
+                                 "aa-samples",    oversample,
+                                  NULL);
+
+      node = wrap_in_gamma_cast (node, drawable);
+
+      gimp_drawable_apply_operation (drawable, progress,
+                                     C_("undo-type", "Newsprint"),
+                                     node);
+      g_object_unref (node);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub plug_in_normalize {
     $blurb = 'Stretch brightness values to cover the full range';
 
@@ -4869,7 +4961,7 @@ wrap_in_gamma_cast (GeglNode     *node,
       cast_format =
         gimp_babl_format (gimp_babl_format_get_base_type (drawable_format),
                           gimp_babl_precision (gimp_babl_format_get_component_type (drawable_format),
-                                               TRUE),
+                                               GIMP_TRC_LINEAR),
                           babl_format_has_alpha (drawable_format),
                           babl_format_get_space (drawable_format));
 
@@ -5086,6 +5178,47 @@ gaussian_blur (GimpDrawable  *drawable,
 
   return FALSE;
 }
+
+static gint
+newsprint_color_model (gint colorspace)
+{
+  switch (colorspace)
+    {
+    case 0: return 1; /* black on white */
+    case 1: return 2; /* rgb */
+    case 2: return 3; /* cmyk */
+    case 3: return 1; /* black on white */
+    }
+
+  return 2;
+}
+
+static gint
+newsprint_pattern (gint spotfn)
+{
+  switch (spotfn)
+    {
+    case 0: return 1; /* circle */
+    case 1: return 0; /* line */
+    case 2: return 2; /* diamond */
+    case 3: return 4; /* ps circle */
+    case 4: return 2; /* FIXME postscript diamond */
+    }
+
+  return 1;
+}
+
+static gdouble
+newsprint_angle (gdouble angle)
+{
+  while (angle > 180.0)
+    angle -= 360.0;
+
+  while (angle < -180.0)
+    angle += 360.0;
+
+  return angle;
+}
 CODE
 
 @headers = qw("libgimpbase/gimpbase.h"
@@ -5149,6 +5282,7 @@ CODE
             plug_in_mblur_inward
             plug_in_mosaic
             plug_in_neon
+            plug_in_newsprint
             plug_in_normalize
             plug_in_nova
             plug_in_papertile
diff --git a/plug-ins/common/.gitignore b/plug-ins/common/.gitignore
index 79449671fe..6df0f80887 100644
--- a/plug-ins/common/.gitignore
+++ b/plug-ins/common/.gitignore
@@ -124,8 +124,6 @@
 /jigsaw.exe
 /mail
 /mail.exe
-/newsprint
-/newsprint.exe
 /nl-filter
 /nl-filter.exe
 /oilify
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 3725ccbbf8..95bf7a2823 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -107,7 +107,6 @@ guillotine_libexecdir = $(gimpplugindir)/plug-ins/guillotine
 hot_libexecdir = $(gimpplugindir)/plug-ins/hot
 jigsaw_libexecdir = $(gimpplugindir)/plug-ins/jigsaw
 mail_libexecdir = $(gimpplugindir)/plug-ins/mail
-newsprint_libexecdir = $(gimpplugindir)/plug-ins/newsprint
 nl_filter_libexecdir = $(gimpplugindir)/plug-ins/nl-filter
 oilify_libexecdir = $(gimpplugindir)/plug-ins/oilify
 plugin_browser_libexecdir = $(gimpplugindir)/plug-ins/plugin-browser
@@ -188,7 +187,6 @@ guillotine_libexec_PROGRAMS = guillotine
 hot_libexec_PROGRAMS = hot
 jigsaw_libexec_PROGRAMS = jigsaw
 mail_libexec_PROGRAMS = $(MAIL)
-newsprint_libexec_PROGRAMS = newsprint
 nl_filter_libexec_PROGRAMS = nl-filter
 oilify_libexec_PROGRAMS = oilify
 plugin_browser_libexec_PROGRAMS = plugin-browser
@@ -1340,23 +1338,6 @@ mail_LDADD = \
        $(INTLLIBS)             \
        $(mail_RC)
 
-newsprint_SOURCES = \
-       newsprint.c
-
-newsprint_LDADD = \
-       $(libgimpui)            \
-       $(libgimpwidgets)       \
-       $(libgimpmodule)        \
-       $(libgimp)              \
-       $(libgimpmath)          \
-       $(libgimpconfig)        \
-       $(libgimpcolor)         \
-       $(libgimpbase)          \
-       $(GTK_LIBS)             \
-       $(RT_LIBS)              \
-       $(INTLLIBS)             \
-       $(newsprint_RC)
-
 nl_filter_SOURCES = \
        nl-filter.c
 
diff --git a/plug-ins/common/gimprc.common b/plug-ins/common/gimprc.common
index bafaa906de..345245b225 100644
--- a/plug-ins/common/gimprc.common
+++ b/plug-ins/common/gimprc.common
@@ -59,7 +59,6 @@ guillotine_RC = guillotine.rc.o
 hot_RC = hot.rc.o
 jigsaw_RC = jigsaw.rc.o
 mail_RC = mail.rc.o
-newsprint_RC = newsprint.rc.o
 nl_filter_RC = nl-filter.rc.o
 oilify_RC = oilify.rc.o
 plugin_browser_RC = plugin-browser.rc.o
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index d39e1aab54..30f203b310 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -61,7 +61,6 @@
     'hot' => { ui => 1, gegl => 1 },
     'jigsaw' => { ui => 1, gegl => 1 },
     'mail' => { ui => 1, optional => 1 },
-    'newsprint' => { ui => 1 },
     'nl-filter' => { ui => 1, gegl => 1 },
     'oilify' => { ui => 1 },
     'plugin-browser' => { ui => 1 },
diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in
index db9b498996..d737657050 100644
--- a/po-plug-ins/POTFILES.in
+++ b/po-plug-ins/POTFILES.in
@@ -65,7 +65,6 @@ plug-ins/common/guillotine.c
 plug-ins/common/hot.c
 plug-ins/common/jigsaw.c
 plug-ins/common/mail.c
-plug-ins/common/newsprint.c
 plug-ins/common/nl-filter.c
 plug-ins/common/oilify.c
 plug-ins/common/plugin-browser.c


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