~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to plug-ins/common/edge-laplace.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
 
 * This program is free software; you can redistribute it and/or modify
 
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * the Free Software Foundation; either version 3 of the License, or
7
7
 * (at your option) any later version.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
12
12
 * GNU General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
16
 */
18
17
 
19
18
/* This plugin by thorsten@arch.usyd.edu.au.
31
30
 
32
31
#define PLUG_IN_PROC   "plug-in-laplace"
33
32
#define PLUG_IN_BINARY "edge-laplace"
 
33
#define PLUG_IN_ROLE   "gimp-edge-laplace"
34
34
 
35
35
 
36
36
/* Declare local functions.
66
66
{
67
67
  static const GimpParamDef args[] =
68
68
  {
69
 
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive" },
70
 
    { GIMP_PDB_IMAGE,    "image",    "Input image (unused)"         },
71
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"               }
 
69
    { GIMP_PDB_INT32,    "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
 
70
    { GIMP_PDB_IMAGE,    "image",    "Input image (unused)" },
 
71
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"       }
72
72
  };
73
73
 
74
74
  gimp_install_procedure (PLUG_IN_PROC,
75
 
                          N_("High-resolution edge detection"),
76
 
                          "This plugin creates one-pixel wide edges from the "
77
 
                          "image, with the value proportional to the gradient. "
78
 
                          "It uses the Laplace operator (a 3x3 kernel with -8 "
79
 
                          "in the middle). The image has to be laplacered to "
80
 
                          "get useful results, a gauss_iir with 1.5 - 5.0 "
81
 
                          "depending on the noise in the image is best.",
82
 
                          "Thorsten Schnier",
83
 
                          "Thorsten Schnier",
84
 
                          "1997",
85
 
                          N_("_Laplace"),
86
 
                          "RGB*, GRAY*",
87
 
                          GIMP_PLUGIN,
88
 
                          G_N_ELEMENTS (args), 0,
89
 
                          args, NULL);
 
75
                          N_("High-resolution edge detection"),
 
76
                          "This plugin creates one-pixel wide edges from the "
 
77
                          "image, with the value proportional to the gradient. "
 
78
                          "It uses the Laplace operator (a 3x3 kernel with -8 "
 
79
                          "in the middle). The image has to be laplacered to "
 
80
                          "get useful results, a gauss_iir with 1.5 - 5.0 "
 
81
                          "depending on the noise in the image is best.",
 
82
                          "Thorsten Schnier",
 
83
                          "Thorsten Schnier",
 
84
                          "1997",
 
85
                          N_("_Laplace"),
 
86
                          "RGB*, GRAY*",
 
87
                          GIMP_PLUGIN,
 
88
                          G_N_ELEMENTS (args), 0,
 
89
                          args, NULL);
90
90
 
91
91
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Edge-Detect");
92
92
}
118
118
      laplace (drawable);
119
119
 
120
120
      if (run_mode != GIMP_RUN_NONINTERACTIVE)
121
 
        gimp_displays_flush ();
 
121
        gimp_displays_flush ();
122
122
    }
123
123
  else
124
124
    {
137
137
 
138
138
static void
139
139
laplace_prepare_row (GimpPixelRgn *pixel_rgn,
140
 
                     guchar       *data,
141
 
                     gint          x,
142
 
                     gint          y,
143
 
                     gint          w)
 
140
                     guchar       *data,
 
141
                     gint          x,
 
142
                     gint          y,
 
143
                     gint          w)
144
144
{
145
145
  gint bpp = pixel_rgn->bpp;
146
146
  gint b;
171
171
 
172
172
static void
173
173
minmax  (gint  x1,
174
 
         gint  x2,
175
 
         gint  x3,
176
 
         gint  x4,
177
 
         gint  x5,
178
 
         gint *min_result,
179
 
         gint *max_result)
 
174
         gint  x2,
 
175
         gint  x3,
 
176
         gint  x4,
 
177
         gint  x5,
 
178
         gint *min_result,
 
179
         gint *max_result)
180
180
{
181
181
  gint min1, min2, max1, max2;
182
182
 
275
275
 
276
276
      d = dest;
277
277
      for (col = 0; col < (x2 - x1) * bytes; col++)
278
 
        if (alpha && (((col + 1) % bytes) == 0)) /* the alpha channel */
 
278
        if (alpha && (((col + 1) % bytes) == 0)) /* the alpha channel */
279
279
          {
280
280
            *d++ = cr[col];
281
281
          }
282
 
        else
283
 
          {
284
 
            minmax (pr[col], cr[col - bytes], cr[col], cr[col + bytes],
285
 
                    nr[col], &minval, &maxval); /* four-neighbourhood */
286
 
 
287
 
            gradient = (0.5 * MAX ((maxval - cr [col]), (cr[col]- minval)));
288
 
 
289
 
            *d++ = (((pr[col - bytes] + pr[col]       + pr[col + bytes] +
 
282
        else
 
283
          {
 
284
            minmax (pr[col], cr[col - bytes], cr[col], cr[col + bytes],
 
285
                    nr[col], &minval, &maxval); /* four-neighbourhood */
 
286
 
 
287
            gradient = (0.5 * MAX ((maxval - cr [col]), (cr[col]- minval)));
 
288
 
 
289
            *d++ = (((pr[col - bytes] + pr[col]       + pr[col + bytes] +
290
290
                      cr[col - bytes] - (8 * cr[col]) + cr[col + bytes] +
291
291
                      nr[col - bytes] + nr[col]       + nr[col + bytes]) > 0) ?
292
292
                    gradient : (128 + gradient));
293
 
          }
 
293
          }
294
294
 
295
295
      /*  store the dest  */
296
296
      gimp_pixel_rgn_set_row (&destPR, dest, x1, row, (x2 - x1));
302
302
      nr = tmp;
303
303
 
304
304
      if ((row % 20) == 0)
305
 
        gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
 
305
        gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
306
306
    }
307
307
 
308
308
 
366
366
      nr = tmp;
367
367
 
368
368
      if ((row % 20) == 0)
369
 
        gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
 
369
        gimp_progress_update ((gdouble) row / (gdouble) (y2 - y1));
370
370
    }
371
371
 
 
372
  gimp_progress_update (1.0);
372
373
  /*  update the laplaced region  */
373
374
  gimp_drawable_flush (drawable);
374
375
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);