1 /*
2  *  Goat exercise plug-in by Øyvind Kolås, pippin@gimp.org
3  */
4 
5 /*
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "config.h"
21 
22 #include <libgimp/gimp.h>
23 
24 #include "libgimp/stdplugins-intl.h"
25 
26 
27 #define PLUG_IN_PROC "plug-in-goat-exercise"
28 
29 
30 /* Declare local functions.
31  */
32 static void   query       (void);
33 static void   run         (const gchar      *name,
34                            gint              nparams,
35                            const GimpParam  *param,
36                            gint             *nreturn_vals,
37                            GimpParam       **return_vals);
38 
39 
40 const GimpPlugInInfo PLUG_IN_INFO =
41 {
42   NULL,  /* init_proc  */
43   NULL,  /* quit_proc  */
44   query, /* query_proc */
45   run,   /* run_proc   */
46 };
47 
MAIN()48 MAIN ()
49 
50 
51 static void
52 query (void)
53 {
54   static const GimpParamDef args[] =
55   {
56     { GIMP_PDB_INT32,    "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
57     { GIMP_PDB_IMAGE,    "image",    "Input image (unused)"         },
58     { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"               }
59   };
60 
61   gimp_install_procedure (PLUG_IN_PROC,
62                           N_("Exercise a goat"),
63                           "takes a goat for a walk",
64                           "Øyvind Kolås <pippin@gimp.org>",
65                           "Øyvind Kolås <pippin@gimp.org>",
66                           "21march 2012",
67                           N_("Goat-e_xercise"),
68                           "RGB*, INDEXED*, GRAY*",
69                           GIMP_PLUGIN,
70                           G_N_ELEMENTS (args), 0,
71                           args, NULL);
72 
73   gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters");
74 }
75 
76 static void
run(const gchar * name,gint nparams,const GimpParam * param,gint * nreturn_vals,GimpParam ** return_vals)77 run (const gchar      *name,
78      gint              nparams,
79      const GimpParam  *param,
80      gint             *nreturn_vals,
81      GimpParam       **return_vals)
82 {
83   static GimpParam   values[1];
84   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
85   gint32             drawable_id;
86   gint               x, y, width, height;
87 
88   INIT_I18N();
89   gegl_init (NULL, NULL);
90 
91   *nreturn_vals = 1;
92   *return_vals = values;
93 
94   values[0].type          = GIMP_PDB_STATUS;
95   values[0].data.d_status = status;
96 
97   drawable_id = param[2].data.d_drawable;
98 
99   if (gimp_drawable_mask_intersect (drawable_id, &x, &y, &width, &height))
100     {
101       GeglBuffer *buffer;
102       GeglBuffer *shadow_buffer;
103 
104       buffer        = gimp_drawable_get_buffer (drawable_id);
105       shadow_buffer = gimp_drawable_get_shadow_buffer (drawable_id);
106 
107       gegl_render_op (buffer, shadow_buffer, "gegl:invert", NULL);
108 
109       g_object_unref (shadow_buffer); /* flushes the shadow tiles */
110       g_object_unref (buffer);
111 
112       gimp_drawable_merge_shadow (drawable_id, TRUE);
113       gimp_drawable_update (drawable_id, x, y, width, height);
114       gimp_displays_flush ();
115     }
116 
117   values[0].data.d_status = status;
118   gegl_exit ();
119 }
120