190
190
static const GimpParamDef args[] =
192
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
192
{ GIMP_PDB_INT32, "run_mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
193
193
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
194
194
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
195
195
{ GIMP_PDB_FLOAT, "rndm_pct", "Randomization percentage (1.0 - 100.0)" },
196
196
{ GIMP_PDB_FLOAT, "rndm_rcount", "Repeat count (1.0 - 100.0)" },
197
{ GIMP_PDB_INT32, "randomize", "Use random seed (TRUE, FALSE)" },
197
{ GIMP_PDB_INT32, "randomize", "Use random seed { TRUE, FALSE }" },
198
198
{ GIMP_PDB_INT32, "seed", "Seed value (used only if randomize is FALSE)" }
318
318
gimp_tile_cache_ntiles (2 * drawable->ntile_cols);
320
320
switch (run_mode)
323
* If we're running interactively, pop up the dialog box.
325
case GIMP_RUN_INTERACTIVE:
326
gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
323
* If we're running interactively, pop up the dialog box.
325
case GIMP_RUN_INTERACTIVE:
326
gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
328
if (! randomize_dialog (drawable)) /* return on Cancel */
332
* If we're not interactive (probably scripting), we
333
* get the parameters from the param[] array, since
334
* we don't use the dialog box. Make sure they all
335
* parameters have legitimate values.
337
case GIMP_RUN_NONINTERACTIVE:
340
status = GIMP_PDB_CALLING_ERROR;
344
pivals.rndm_pct = (gdouble) param[3].data.d_float;
345
pivals.rndm_rcount = (gdouble) param[4].data.d_float;
346
pivals.randomize = (gboolean) param[5].data.d_int32;
347
pivals.seed = (gint) param[6].data.d_int32;
328
if (! randomize_dialog (drawable)) /* return on Cancel */
332
* If we're not interactive (probably scripting), we
333
* get the parameters from the param[] array, since
334
* we don't use the dialog box. Make sure they all
335
* parameters have legitimate values.
337
case GIMP_RUN_NONINTERACTIVE:
340
status = GIMP_PDB_CALLING_ERROR;
344
pivals.rndm_pct = (gdouble) param[3].data.d_float;
345
pivals.rndm_rcount = (gdouble) param[4].data.d_float;
346
pivals.randomize = (gboolean) param[5].data.d_int32;
347
pivals.seed = (gint) param[6].data.d_int32;
349
349
if (pivals.randomize)
350
350
pivals.seed = g_random_int ();
352
if ((rndm_type != RNDM_PICK &&
353
rndm_type != RNDM_SLUR &&
354
rndm_type != RNDM_HURL) ||
355
(pivals.rndm_pct < 1.0 || pivals.rndm_pct > 100.0) ||
356
(pivals.rndm_rcount < 1.0 || pivals.rndm_rcount > 100.0))
358
status = GIMP_PDB_CALLING_ERROR;
363
* If we're running with the last set of values, get those values.
365
case GIMP_RUN_WITH_LAST_VALS:
366
gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
352
if ((rndm_type != RNDM_PICK &&
353
rndm_type != RNDM_SLUR &&
354
rndm_type != RNDM_HURL) ||
355
(pivals.rndm_pct < 1.0 || pivals.rndm_pct > 100.0) ||
356
(pivals.rndm_rcount < 1.0 || pivals.rndm_rcount > 100.0))
358
status = GIMP_PDB_CALLING_ERROR;
363
* If we're running with the last set of values, get those values.
365
case GIMP_RUN_WITH_LAST_VALS:
366
gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);
368
368
if (pivals.randomize)
369
369
pivals.seed = g_random_int ();
372
* Hopefully we never get here!
372
* Hopefully we never get here!
378
378
if (status == GIMP_PDB_SUCCESS)
380
380
gimp_progress_init_printf ("%s", gettext (RNDM_NAME[rndm_type - 1]));
383
* Initialize the g_rand() function seed
383
* Initialize the g_rand() function seed
385
385
g_rand_set_seed (gr, pivals.seed);
387
randomize (drawable, NULL);
389
* If we ran interactively (even repeating) update the display.
391
if (run_mode != GIMP_RUN_NONINTERACTIVE)
393
gimp_displays_flush ();
387
randomize (drawable, NULL);
389
* If we ran interactively (even repeating) update the display.
391
if (run_mode != GIMP_RUN_NONINTERACTIVE)
393
gimp_displays_flush ();
396
* If we use the dialog popup, set the data for future use.
398
if (run_mode == GIMP_RUN_INTERACTIVE)
400
gimp_set_data (PLUG_IN_PROC[rndm_type - 1], &pivals,
396
* If we use the dialog popup, set the data for future use.
398
if (run_mode == GIMP_RUN_INTERACTIVE)
400
gimp_set_data (PLUG_IN_PROC[rndm_type - 1], &pivals,
401
401
sizeof (RandomizeVals));
480
480
guchar *next_row, *nr;
490
gimp_preview_get_position (preview, &x1, &y1);
489
gimp_preview_get_position (preview, &x, &y);
491
490
gimp_preview_get_size (preview, &width, &height);
497
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
494
if (! gimp_drawable_mask_intersect (drawable->drawable_id,
495
&x, &y, &width, &height))
502
499
bytes = drawable->bpp;
503
has_alpha = gimp_drawable_has_alpha(drawable->drawable_id);
506
502
* allocate row buffers
508
prev_row = g_new (guchar, (x2 - x1 + 2) * bytes);
509
cur_row = g_new (guchar, (x2 - x1 + 2) * bytes);
510
next_row = g_new (guchar, (x2 - x1 + 2) * bytes);
511
dest = g_new (guchar, (x2 - x1) * bytes);
504
prev_row = g_new (guchar, (width + 2) * bytes);
505
cur_row = g_new (guchar, (width + 2) * bytes);
506
next_row = g_new (guchar, (width + 2) * bytes);
507
dest = g_new (guchar, width * bytes);
514
510
* initialize the pixel regions
516
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, width, height, FALSE, FALSE);
517
gimp_pixel_rgn_init (&destPR, drawable, x1, y1, width, height, TRUE, TRUE);
518
gimp_pixel_rgn_init (&destPR2, drawable, x1, y1, width, height, TRUE, TRUE);
512
gimp_pixel_rgn_init (&srcPR, drawable, x, y, width, height, FALSE, FALSE);
513
gimp_pixel_rgn_init (&destPR, drawable, x, y, width, height, TRUE, TRUE);
514
gimp_pixel_rgn_init (&destPR2, drawable, x, y, width, height, TRUE, TRUE);
530
526
* prepare the first row and previous row
532
randomize_prepare_row (sp, pr, x1, y1 - 1, (x2 - x1));
533
randomize_prepare_row (dp, cr, x1, y1, (x2 - x1));
528
randomize_prepare_row (sp, pr, x, y - 1, width);
529
randomize_prepare_row (sp, cr, x, y, width);
535
531
* loop through the rows, applying the selected convolution
537
for (row = y1; row < y2; row++)
539
/* prepare the next row */
540
randomize_prepare_row (sp, nr, x1, row + 1, (x2 - x1));
533
for (row = y; row < y + height; row++)
535
/* prepare the next row */
536
randomize_prepare_row (sp, nr, x, row + 1, width);
544
for (col = 0; col < (x2 - x1); col++)
546
if (g_rand_int_range (gr, 0, 100) <= (gint) pivals.rndm_pct)
552
* Just assign a random value.
539
for (col = 0; col < width; col++)
541
if (g_rand_int_range (gr, 0, 100) <= (gint) pivals.rndm_pct)
547
* Just assign a random value.
555
550
for (j = 0; j < bytes; j++)
556
551
*d++ = g_rand_int_range (gr, 0, 256);
560
* pick at random from a neighboring pixel.
555
* pick at random from a neighboring pixel.
563
558
k = g_rand_int_range (gr, 0, 9);
564
559
for (j = 0; j < bytes; j++)
628
623
* Otherwise, this pixel was not selected for randomization,
629
* so use the current value.
624
* so use the current value.
634
629
for (j = 0; j < bytes; j++)
635
630
*d++ = (gint) cr[col*bytes + j];
639
* Save the modified row, shuffle the row pointers, and every
640
* so often, update the progress meter.
642
gimp_pixel_rgn_set_row (dp, dest, x1, row, (x2 - x1));
634
* Save the modified row, shuffle the row pointers, and every
635
* so often, update the progress meter.
637
gimp_pixel_rgn_set_row (dp, dest, x, row, width);
649
644
if (! preview && PROG_UPDATE_TIME)
651
646
gdouble base = (gdouble) cnt / pivals.rndm_rcount;
652
gdouble inc = (gdouble) row / ((y2 - y1) * pivals.rndm_rcount);
647
gdouble inc = (gdouble) row / (height * pivals.rndm_rcount);
654
649
gimp_progress_update (base + inc);
730
725
gimp_ui_init (PLUG_IN_BINARY, FALSE);
732
dlg = gimp_dialog_new (gettext (RNDM_NAME[rndm_type - 1]), PLUG_IN_BINARY,
727
dlg = gimp_dialog_new (gettext (RNDM_NAME[rndm_type - 1]), PLUG_IN_ROLE,
734
gimp_standard_help_func, PLUG_IN_PROC[rndm_type - 1],
736
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
737
GTK_STOCK_OK, GTK_RESPONSE_OK,
729
gimp_standard_help_func, PLUG_IN_PROC[rndm_type - 1],
731
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
732
GTK_STOCK_OK, GTK_RESPONSE_OK,
741
736
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
746
741
gimp_window_set_transient (GTK_WINDOW (dlg));
748
main_vbox = gtk_vbox_new (FALSE, 12);
743
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
749
744
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
750
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dlg)->vbox), main_vbox);
745
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
746
main_vbox, TRUE, TRUE, 0);
751
747
gtk_widget_show (main_vbox);
753
749
preview = gimp_drawable_preview_new (drawable, NULL);
768
764
/* Random Seed */
769
765
seed_hbox = gimp_random_seed_new (&pivals.seed, &pivals.randomize);
770
766
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
771
_("_Random seed:"), 0.0, 0.5,
767
_("_Random seed:"), 0.0, 0.5,
773
769
gtk_label_set_mnemonic_widget (GTK_LABEL (label),
774
GIMP_RANDOM_SEED_SPINBUTTON (seed_hbox));
770
GIMP_RANDOM_SEED_SPINBUTTON (seed_hbox));
777
773
* Randomization percentage label & scale (1 to 100)
779
775
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
780
_("R_andomization (%):"), SCALE_WIDTH, 0,
781
pivals.rndm_pct, 1.0, 100.0, 1.0, 10.0, 0,
783
_("Percentage of pixels to be filtered"), NULL);
776
_("R_andomization (%):"), SCALE_WIDTH, 0,
777
pivals.rndm_pct, 1.0, 100.0, 1.0, 10.0, 0,
779
_("Percentage of pixels to be filtered"), NULL);
784
780
g_signal_connect (adj, "value-changed",
785
781
G_CALLBACK (gimp_double_adjustment_update),
786
782
&pivals.rndm_pct);
792
788
* Repeat count label & scale (1 to 100)
794
790
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
795
_("R_epeat:"), SCALE_WIDTH, 0,
796
pivals.rndm_rcount, 1.0, 100.0, 1.0, 10.0, 0,
798
_("Number of times to apply filter"), NULL);
791
_("R_epeat:"), SCALE_WIDTH, 0,
792
pivals.rndm_rcount, 1.0, 100.0, 1.0, 10.0, 0,
794
_("Number of times to apply filter"), NULL);
799
795
g_signal_connect (adj, "value-changed",
800
796
G_CALLBACK (gimp_double_adjustment_update),
801
797
&pivals.rndm_rcount);