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

« back to all changes in this revision

Viewing changes to plug-ins/common/wind.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:
29
29
 
30
30
#include "config.h"
31
31
 
32
 
#include <stdio.h>
33
32
#include <stdlib.h>
34
33
#include <string.h>
35
34
 
36
 
#include <gtk/gtk.h>
37
 
 
38
35
#include <libgimp/gimp.h>
39
36
#include <libgimp/gimpui.h>
40
37
 
41
38
#include "libgimp/stdplugins-intl.h"
42
39
 
43
 
#define PLUG_IN_NAME "wind"
44
 
 
45
 
#define COMPARE_WIDTH   3
46
 
 
47
 
#define SCALE_WIDTH   200
48
 
#define MIN_THRESHOLD   0
49
 
#define MAX_THRESHOLD  50
50
 
#define MIN_STRENGTH    1
51
 
#define MAX_STRENGTH   50
 
40
 
 
41
#define PLUG_IN_PROC   "plug-in-wind"
 
42
#define PLUG_IN_BINARY "wind"
 
43
 
 
44
#define COMPARE_WIDTH    3
 
45
 
 
46
#define SCALE_WIDTH    200
 
47
#define MIN_THRESHOLD    0
 
48
#define MAX_THRESHOLD   50
 
49
#define MIN_STRENGTH     1
 
50
#define MAX_STRENGTH   100
52
51
 
53
52
typedef enum
54
53
{
123
122
                                    gint      length,
124
123
                                    gint      bytes);
125
124
 
126
 
GimpPlugInInfo PLUG_IN_INFO =
 
125
const GimpPlugInInfo PLUG_IN_INFO =
127
126
{
128
127
  NULL,  /* init_proc  */
129
128
  NULL,  /* quit_proc  */
162
161
static void
163
162
query (void)
164
163
{
165
 
  static GimpParamDef args[] =
 
164
  static const GimpParamDef args[] =
166
165
  {
167
 
    { GIMP_PDB_INT32,    "run_mode",  "Interactive, non-interactive" },
 
166
    { GIMP_PDB_INT32,    "run-mode",  "Interactive, non-interactive" },
168
167
    { GIMP_PDB_IMAGE,    "image",     "Input image (unused)" },
169
168
    { GIMP_PDB_DRAWABLE, "drawable",  "Input drawable" },
170
169
    { GIMP_PDB_INT32,    "threshold", "Controls where blending will be done >= 0" },
171
170
    { GIMP_PDB_INT32,    "direction", "Left or Right: 0 or 1" },
172
171
    { GIMP_PDB_INT32,    "strength",  "Controls the extent of the blending > 1" },
173
 
    { GIMP_PDB_INT32,    "alg",       "WIND, BLAST" },
 
172
    { GIMP_PDB_INT32,    "algorithm", "WIND, BLAST" },
174
173
    { GIMP_PDB_INT32,    "edge",      "LEADING, TRAILING, or BOTH" }
175
174
  };
176
175
 
177
 
  gimp_install_procedure ("plug_in_wind",
178
 
                          "Renders a wind effect.",
 
176
  gimp_install_procedure (PLUG_IN_PROC,
 
177
                          N_("Smear image to give windblown effect"),
179
178
                          "Renders a wind effect.",
180
179
                          "Nigel Wetten",
181
180
                          "Nigel Wetten",
186
185
                          G_N_ELEMENTS (args), 0,
187
186
                          args, NULL);
188
187
 
189
 
  gimp_plugin_menu_register ("plug_in_wind", "<Image>/Filters/Distorts");
 
188
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Distorts");
190
189
}
191
190
 
192
191
static void
228
227
      break;
229
228
 
230
229
    case GIMP_RUN_INTERACTIVE:
231
 
      gimp_get_data ("plug_in_wind", &config);
 
230
      gimp_get_data (PLUG_IN_PROC, &config);
232
231
      if (! dialog_box (drawable))
233
232
        {
234
233
          status = GIMP_PDB_CANCEL;
239
238
          status = GIMP_PDB_CALLING_ERROR;
240
239
          break;
241
240
        }
242
 
      gimp_set_data ("plug_in_wind", &config, sizeof (config_t));
 
241
      gimp_set_data (PLUG_IN_PROC, &config, sizeof (config_t));
243
242
      gimp_displays_flush ();
244
243
      break;
245
244
 
246
245
    case GIMP_RUN_WITH_LAST_VALS:
247
 
      gimp_get_data ("plug_in_wind", &config);
 
246
      gimp_get_data (PLUG_IN_PROC, &config);
248
247
      if (render_effect (drawable, NULL) == -1)
249
248
        {
250
249
          status = GIMP_PDB_EXECUTION_ERROR;
251
 
          gimp_message ("An execution error occured.");
 
250
          gimp_message ("An execution error occurred.");
252
251
        }
253
252
      else
254
253
        {
312
311
    }
313
312
  else
314
313
    {
315
 
      gimp_progress_init (_("Rendering Blast..."));
316
 
      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
317
 
 
318
 
      width = x2 - x1;
319
 
      height = y2 - y1;
320
 
 
321
 
      gimp_pixel_rgn_init (&dest_region, drawable,
322
 
                           x1, y1, width, height, TRUE, TRUE);
 
314
      if (gimp_drawable_mask_intersect (drawable->drawable_id,
 
315
                                        &x1, &y1, &x2, &y2))
 
316
        {
 
317
          gimp_progress_init (_("Rendering blast"));
 
318
 
 
319
          width = x2 - x1;
 
320
          height = y2 - y1;
 
321
 
 
322
          gimp_pixel_rgn_init (&dest_region, drawable,
 
323
                               x1, y1, width, height, TRUE, TRUE);
 
324
        }
 
325
      else
 
326
        return;
323
327
    }
324
328
 
325
329
  gimp_pixel_rgn_init (&src_region,  drawable,
435
439
    }
436
440
  else
437
441
    {
438
 
      gimp_progress_init (_("Rendering Wind..."));
439
 
      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
440
 
 
441
 
      width = x2 - x1;
442
 
      height = y2 - y1;
443
 
 
444
 
      gimp_pixel_rgn_init (&dest_region, drawable,
445
 
                           x1, y1, width, height, TRUE, TRUE);
 
442
      if (gimp_drawable_mask_intersect (drawable->drawable_id, &x1, &y1, &x2, &y2))
 
443
        {
 
444
          gimp_progress_init (_("Rendering wind"));
 
445
 
 
446
          width = x2 - x1;
 
447
          height = y2 - y1;
 
448
 
 
449
          gimp_pixel_rgn_init (&dest_region, drawable,
 
450
                               x1, y1, width, height, TRUE, TRUE);
 
451
        }
 
452
      else
 
453
        return;
446
454
    }
447
455
 
448
456
  gimp_pixel_rgn_init (&src_region, drawable,
518
526
                              buffer + Ri + bytes,
519
527
                              edge,
520
528
                              threshold,
521
 
                              (bytes > 3)))
 
529
                              bytes > 3))
522
530
        {
523
531
          /* we have found an edge, do bleeding */
524
532
          sbi = Ri;
564
572
              buffer[i] = buffer[Ri];
565
573
              buffer[i+1] = buffer[Gi];
566
574
              buffer[i+2] = buffer[Bi];
567
 
              if(bytes > 3)
 
575
              if (bytes > 3)
568
576
                buffer[i+3] = buffer[Ai];
569
577
            }
570
578
          j = lbi - bytes;
666
674
                                       sb + i,
667
675
                                       edge,
668
676
                                       threshold,
669
 
                                       (bytes>3))
 
677
                                       bytes > 3)
670
678
                  && g_random_boolean ())
671
679
                {
672
680
                  break;
676
684
              blend_colour_G += blend_amt_G * n * denominator;
677
685
              blend_colour_B += blend_amt_B * n * denominator;
678
686
 
679
 
              if(bytes > 3)
 
687
              if (bytes > 3)
680
688
                {
681
689
                  blend_colour_A += blend_amt_A * n * denominator;
682
690
                  if (blend_colour_A > 255)
711
719
                                      sb + i + comp_stride,
712
720
                                      BOTH,
713
721
                                      threshold,
714
 
                                      (bytes>3)))
 
722
                                      bytes > 3))
715
723
                {
716
724
                  target_colour_R = sb[i + comp_stride + 0];
717
725
                  target_colour_G = sb[i + comp_stride + 1];
718
726
                  target_colour_B = sb[i + comp_stride + 2];
719
 
                  if(bytes > 3)
 
727
                  if (bytes > 3)
720
728
                    target_colour_A = sb[i + comp_stride + 3];
721
729
                  blend_amt_R = target_colour_R - blend_colour_R;
722
730
                  blend_amt_G = target_colour_G - blend_colour_G;
723
731
                  blend_amt_B = target_colour_B - blend_colour_B;
724
 
                  if(bytes > 3)
 
732
                  if (bytes > 3)
725
733
                    blend_amt_A = target_colour_A - blend_colour_A;
726
734
                  denominator = n * n + n;
727
735
                  denominator = 2.0 / denominator;
739
747
                    gint     threshold,
740
748
                    gboolean has_alpha)
741
749
{
742
 
  gint     derivative_R, derivative_G, derivative_B, derivative_A;
743
 
  gboolean return_value;
 
750
  gint derivative_R, derivative_G, derivative_B, derivative_A;
744
751
 
745
752
  get_derivative (pixel_R1, pixel_R2, edge, has_alpha,
746
753
                  &derivative_R, &derivative_G, &derivative_B, &derivative_A);
747
754
 
748
 
  if(((derivative_R +
749
 
       derivative_G +
750
 
       derivative_B +
751
 
       derivative_A) / 4) > threshold)
752
 
    {
753
 
      return_value = TRUE;
754
 
    }
755
 
  else
756
 
    {
757
 
      return_value = FALSE;
758
 
    }
759
 
  return return_value;
 
755
  return (((derivative_R +
 
756
            derivative_G +
 
757
            derivative_B +
 
758
            derivative_A) / 4) > threshold);
760
759
}
761
760
 
762
761
static void
868
867
  GtkWidget *edge3;
869
868
  gboolean   run;
870
869
 
871
 
  gimp_ui_init ("wind", TRUE);
 
870
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
872
871
 
873
 
  dialog = gimp_dialog_new (_("Wind"), "wind",
 
872
  dialog = gimp_dialog_new (_("Wind"), PLUG_IN_BINARY,
874
873
                            NULL, 0,
875
 
                            gimp_standard_help_func, "plug-in-wind",
 
874
                            gimp_standard_help_func, PLUG_IN_PROC,
876
875
 
877
876
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
878
877
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
879
878
 
880
879
                            NULL);
881
880
 
 
881
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
882
                                           GTK_RESPONSE_OK,
 
883
                                           GTK_RESPONSE_CANCEL,
 
884
                                           -1);
 
885
 
 
886
  gimp_window_set_transient (GTK_WINDOW (dialog));
 
887
 
882
888
  main_vbox = gtk_vbox_new (FALSE, 12);
883
889
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
884
890
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
996
1002
                              TRUE, 0, 0,
997
1003
                              _("Higher values restrict the effect to fewer areas of the image"), NULL);
998
1004
 
999
 
  g_signal_connect (adj, "value_changed",
 
1005
  g_signal_connect (adj, "value-changed",
1000
1006
                    G_CALLBACK (gimp_int_adjustment_update),
1001
1007
                    &config.threshold);
1002
1008
 
1003
 
  g_signal_connect_swapped (adj, "value_changed",
 
1009
  g_signal_connect_swapped (adj, "value-changed",
1004
1010
                            G_CALLBACK (gimp_preview_invalidate),
1005
1011
                            preview);
1006
1012
 
1015
1021
                              TRUE, 0, 0,
1016
1022
                              _("Higher values increase the magnitude of the effect"), NULL);
1017
1023
 
1018
 
  g_signal_connect (adj, "value_changed",
 
1024
  g_signal_connect (adj, "value-changed",
1019
1025
                    G_CALLBACK (gimp_int_adjustment_update),
1020
1026
                    &config.strength);
1021
1027
 
1022
 
  g_signal_connect_swapped (adj, "value_changed",
 
1028
  g_signal_connect_swapped (adj, "value-changed",
1023
1029
                            G_CALLBACK (gimp_preview_invalidate),
1024
1030
                            preview);
1025
1031