~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/randomize.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 *  - add a real melt function
68
68
 ****************************************************************************/
69
69
 
70
 
#ifdef HAVE_CONFIG_H
71
70
#include "config.h"
72
 
#endif
73
71
 
74
 
#include <stdio.h>
75
 
#include <stdlib.h>
76
72
#include <string.h>
77
 
#include <time.h>
78
 
 
79
 
#include <gtk/gtk.h>
80
73
 
81
74
#include <libgimp/gimp.h>
82
75
#include <libgimp/gimpui.h>
90
83
 *
91
84
 ********************************/
92
85
 
 
86
#define PLUG_IN_BINARY "randomize"
 
87
 
93
88
/*
94
89
 *  progress meter update frequency
95
90
 */
96
 
#define PROG_UPDATE_TIME ((row % 10) == 0)
97
 
 
98
 
gchar *PLUG_IN_NAME[] =
99
 
{
100
 
  "plug_in_randomize_hurl",
101
 
  "plug_in_randomize_pick",
102
 
  "plug_in_randomize_slur",
103
 
};
104
 
 
105
 
gchar *RNDM_VERSION[] =
106
 
{
107
 
  N_("Random Hurl 1.7"),
108
 
  N_("Random Pick 1.7"),
109
 
  N_("Random Slur 1.7"),
110
 
};
111
 
 
112
 
gchar *HELP_ID[] =
 
91
#define PROG_UPDATE_TIME ((row % 12) == 0)
 
92
 
 
93
gchar *PLUG_IN_PROC[] =
113
94
{
114
95
  "plug-in-randomize-hurl",
115
96
  "plug-in-randomize-pick",
116
97
  "plug-in-randomize-slur",
117
98
};
118
99
 
119
 
#define RNDM_HURL 1
120
 
#define RNDM_PICK 2
121
 
#define RNDM_SLUR 3
122
 
 
123
 
#define SEED_DEFAULT 10
124
 
#define SEED_USER 11
125
 
 
126
 
#define SCALE_WIDTH 100
 
100
gchar *RNDM_NAME[] =
 
101
{
 
102
  N_("Random Hurl"),
 
103
  N_("Random Pick"),
 
104
  N_("Random Slur"),
 
105
};
 
106
 
 
107
#define RNDM_HURL      1
 
108
#define RNDM_PICK      2
 
109
#define RNDM_SLUR      3
 
110
 
 
111
#define SEED_DEFAULT  10
 
112
 
 
113
#define SCALE_WIDTH  100
127
114
 
128
115
gint rndm_type = RNDM_HURL;  /* hurl, pick, etc. */
129
116
 
177
164
 
178
165
/************************************ Guts ***********************************/
179
166
 
180
 
GimpPlugInInfo PLUG_IN_INFO =
 
167
const GimpPlugInInfo PLUG_IN_INFO =
181
168
{
182
169
  NULL,  /* init_proc  */
183
170
  NULL,  /* quit_proc  */
198
185
static void
199
186
query (void)
200
187
{
201
 
  static GimpParamDef args[] =
 
188
  static const GimpParamDef args[] =
202
189
  {
203
190
    { GIMP_PDB_INT32,    "run_mode",    "Interactive, non-interactive" },
204
191
    { GIMP_PDB_IMAGE,    "image",       "Input image (unused)" },
210
197
  };
211
198
 
212
199
  const gchar *hurl_blurb =
213
 
    "Add a random factor to the image by hurling random data at it.";
 
200
    N_("Completely randomize a fraction of pixels");
214
201
  const gchar *pick_blurb =
215
 
    "Add a random factor to the image by picking a random adjacent pixel.";
 
202
    N_("Randomly interchange some pixels with neighbors");
216
203
  const gchar *slur_blurb =
217
 
    "Add a random factor to the image by slurring (similar to melting).";
 
204
    N_("Randomly slide some pixels downward (similar to melting)");
218
205
 
219
206
  const gchar *hurl_help =
220
207
    "This plug-in ``hurls'' randomly-valued pixels onto the selection or "
235
222
    "Norris, Daniel Cotting";
236
223
  const gchar *copyright_date = "1995-1998";
237
224
 
238
 
  gimp_install_procedure (PLUG_IN_NAME[0],
 
225
  gimp_install_procedure (PLUG_IN_PROC[0],
239
226
                          hurl_blurb,
240
227
                          hurl_help,
241
228
                          author,
247
234
                          G_N_ELEMENTS (args), 0,
248
235
                          args, NULL);
249
236
 
250
 
  gimp_install_procedure (PLUG_IN_NAME[1],
 
237
  gimp_install_procedure (PLUG_IN_PROC[1],
251
238
                          pick_blurb,
252
239
                          pick_help,
253
240
                          author,
259
246
                          G_N_ELEMENTS (args), 0,
260
247
                          args, NULL);
261
248
 
262
 
  gimp_install_procedure (PLUG_IN_NAME[2],
 
249
  gimp_install_procedure (PLUG_IN_PROC[2],
263
250
                          slur_blurb,
264
251
                          slur_help,
265
252
                          author,
271
258
                          G_N_ELEMENTS (args), 0,
272
259
                          args, NULL);
273
260
 
274
 
  gimp_plugin_menu_register (PLUG_IN_NAME[0], "<Image>/Filters/Noise");
275
 
  gimp_plugin_menu_register (PLUG_IN_NAME[1], "<Image>/Filters/Noise");
276
 
  gimp_plugin_menu_register (PLUG_IN_NAME[2], "<Image>/Filters/Noise");
 
261
  gimp_plugin_menu_register (PLUG_IN_PROC[0], "<Image>/Filters/Noise");
 
262
  gimp_plugin_menu_register (PLUG_IN_PROC[1], "<Image>/Filters/Noise");
 
263
  gimp_plugin_menu_register (PLUG_IN_PROC[2], "<Image>/Filters/Noise");
277
264
}
278
265
 
279
266
/*********************************
295
282
  GimpDrawable      *drawable;
296
283
  GimpRunMode        run_mode;
297
284
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;        /* assume the best! */
298
 
  gchar             *rndm_type_str = "";
299
 
  gchar              prog_label[32];
300
285
  static GimpParam   values[1];
301
286
  GRand             *gr; /* The GRand object which generates the
302
287
                          * random numbers */
306
291
  /*
307
292
   *  Get the specified drawable, do standard initialization.
308
293
   */
309
 
  if (strcmp (name, PLUG_IN_NAME[0]) == 0)
 
294
  if (strcmp (name, PLUG_IN_PROC[0]) == 0)
310
295
    rndm_type = RNDM_HURL;
311
 
  else if (strcmp (name, PLUG_IN_NAME[1]) == 0)
 
296
  else if (strcmp (name, PLUG_IN_PROC[1]) == 0)
312
297
    rndm_type = RNDM_PICK;
313
 
  else if (strcmp (name, PLUG_IN_NAME[2]) == 0)
 
298
  else if (strcmp (name, PLUG_IN_PROC[2]) == 0)
314
299
    rndm_type = RNDM_SLUR;
315
300
 
316
301
  run_mode = param[0].data.d_int32;
336
321
           *  If we're running interactively, pop up the dialog box.
337
322
           */
338
323
        case GIMP_RUN_INTERACTIVE:
339
 
          gimp_get_data (PLUG_IN_NAME[rndm_type - 1], &pivals);
 
324
          gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
340
325
 
341
326
          if (! randomize_dialog ()) /* return on Cancel */
342
327
            return;
376
361
           *  If we're running with the last set of values, get those values.
377
362
           */
378
363
        case GIMP_RUN_WITH_LAST_VALS:
379
 
          gimp_get_data (PLUG_IN_NAME[rndm_type - 1], &pivals);
 
364
          gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
380
365
 
381
366
          if (pivals.randomize)
382
367
            pivals.seed = g_random_int ();
390
375
 
391
376
      if (status == GIMP_PDB_SUCCESS)
392
377
        {
393
 
          /*
394
 
           *  JUST DO IT!
395
 
           */
396
 
          switch (rndm_type)
397
 
            {
398
 
            case RNDM_HURL: rndm_type_str = "hurl"; break;
399
 
            case RNDM_PICK: rndm_type_str = "pick"; break;
400
 
            case RNDM_SLUR: rndm_type_str = "slur"; break;
401
 
            }
402
 
 
403
 
          sprintf (prog_label, "%s (%s)...",
404
 
                   gettext (RNDM_VERSION[rndm_type - 1]),
405
 
                   gettext (rndm_type_str));
406
 
          gimp_progress_init (prog_label);
407
 
          gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
 
378
          gimp_tile_cache_ntiles (2 *
 
379
                                  (drawable->width / gimp_tile_width () + 1));
 
380
 
 
381
          gimp_progress_init_printf ("%s", gettext (RNDM_NAME[rndm_type - 1]));
 
382
 
408
383
          /*
409
384
           *  Initialize the g_rand() function seed
410
385
           */
423
398
           */
424
399
          if (run_mode == GIMP_RUN_INTERACTIVE)
425
400
            {
426
 
              gimp_set_data (PLUG_IN_NAME[rndm_type - 1], &pivals,
 
401
              gimp_set_data (PLUG_IN_PROC[rndm_type - 1], &pivals,
427
402
                             sizeof (RandomizeVals));
428
403
            }
429
404
        }
554
529
      /*
555
530
       *  prepare the first row and previous row
556
531
       */
557
 
      randomize_prepare_row(sp, pr, x1, y1 - 1, (x2 - x1));
558
 
      randomize_prepare_row(dp, cr, x1, y1, (x2 - x1));
 
532
      randomize_prepare_row (sp, pr, x1, y1 - 1, (x2 - x1));
 
533
      randomize_prepare_row (dp, cr, x1, y1, (x2 - x1));
559
534
      /*
560
535
       *  loop through the rows, applying the selected convolution
561
536
       */
562
537
      for (row = y1; row < y2; row++)
563
538
        {
564
539
          /*  prepare the next row  */
565
 
          randomize_prepare_row(sp, nr, x1, row + 1, (x2 - x1));
 
540
          randomize_prepare_row (sp, nr, x1, row + 1, (x2 - x1));
566
541
 
567
542
          d = dest;
568
543
          ind = 0;
664
639
           *  Save the modified row, shuffle the row pointers, and every
665
640
           *  so often, update the progress meter.
666
641
           */
667
 
          gimp_pixel_rgn_set_row(dp, dest, x1, row, (x2 - x1));
 
642
          gimp_pixel_rgn_set_row (dp, dest, x1, row, (x2 - x1));
668
643
 
669
644
          tmp = pr;
670
645
          pr = cr;
672
647
          nr = tmp;
673
648
 
674
649
          if (PROG_UPDATE_TIME)
675
 
            gimp_progress_update((double) row / (double) (y2 - y1));
 
650
            gimp_progress_update ((cnt - 1 +
 
651
                                   (double) row / (double) (y2 - y1)) /
 
652
                                  pivals.rndm_rcount);
676
653
        }
 
654
 
677
655
      /*
678
656
       *  if we have more cycles to perform, swap the src and dest Pixel Regions
679
657
       */
693
671
            }
694
672
        }
695
673
    }
696
 
  gimp_progress_update((double) 100);
 
674
 
 
675
  gimp_progress_update (1.0);
 
676
 
697
677
  /*
698
678
   *  update the randomized region
699
679
   */
700
 
  gimp_drawable_flush(drawable);
701
 
  gimp_drawable_merge_shadow(drawable->drawable_id, TRUE);
702
 
  gimp_drawable_update(drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
 
680
  gimp_drawable_flush (drawable);
 
681
  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
 
682
  gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
 
683
 
703
684
  /*
704
685
   *  clean up after ourselves.
705
686
   */
732
713
  GtkObject *adj;
733
714
  gboolean   run;
734
715
 
735
 
  gimp_ui_init ("randomize", FALSE);
 
716
  gimp_ui_init (PLUG_IN_BINARY, FALSE);
736
717
 
737
 
  dlg = gimp_dialog_new (gettext (RNDM_VERSION[rndm_type - 1]), "randomize",
 
718
  dlg = gimp_dialog_new (gettext (RNDM_NAME[rndm_type - 1]), PLUG_IN_BINARY,
738
719
                         NULL, 0,
739
 
                         gimp_standard_help_func, HELP_ID[rndm_type - 1],
 
720
                         gimp_standard_help_func, PLUG_IN_PROC[rndm_type - 1],
740
721
 
741
722
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
742
723
                         GTK_STOCK_OK,     GTK_RESPONSE_OK,
743
724
 
744
725
                         NULL);
745
726
 
 
727
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
 
728
                                           GTK_RESPONSE_OK,
 
729
                                           GTK_RESPONSE_CANCEL,
 
730
                                           -1);
 
731
 
 
732
  gimp_window_set_transient (GTK_WINDOW (dlg));
 
733
 
746
734
  table = gtk_table_new (3, 3, FALSE);
747
735
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
748
736
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
766
754
                              pivals.rndm_pct, 1.0, 100.0, 1.0, 10.0, 0,
767
755
                              TRUE, 0, 0,
768
756
                              _("Percentage of pixels to be filtered"), NULL);
769
 
  g_signal_connect (adj, "value_changed",
 
757
  g_signal_connect (adj, "value-changed",
770
758
                    G_CALLBACK (gimp_double_adjustment_update),
771
759
                    &pivals.rndm_pct);
772
760
 
778
766
                              pivals.rndm_rcount, 1.0, 100.0, 1.0, 10.0, 0,
779
767
                              TRUE, 0, 0,
780
768
                              _("Number of times to apply filter"), NULL);
781
 
  g_signal_connect (adj, "value_changed",
 
769
  g_signal_connect (adj, "value-changed",
782
770
                    G_CALLBACK (gimp_double_adjustment_update),
783
771
                    &pivals.rndm_rcount);
784
772