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

« back to all changes in this revision

Viewing changes to plug-ins/common/whirlpinch.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:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * Whirl and Pinch plug-in --- two common distortions in one place
47
47
 
48
48
#include "config.h"
49
49
 
50
 
#include <stdlib.h>
51
 
#include <stdio.h>
52
 
#ifdef HAVE_UNISTD_H
53
 
#include <unistd.h>
54
 
#endif
55
 
 
56
 
#include <gtk/gtk.h>
57
 
 
58
50
#include <libgimp/gimp.h>
59
51
#include <libgimp/gimpui.h>
60
52
 
61
53
#include "libgimp/stdplugins-intl.h"
62
54
 
63
55
 
64
 
#define PLUG_IN_NAME    "plug_in_whirl_pinch"
 
56
#define PLUG_IN_PROC    "plug-in-whirl-pinch"
 
57
#define PLUG_IN_BINARY  "whirlpinch"
65
58
#define PLUG_IN_VERSION "May 1997, 2.09"
66
 
#define HELP_ID         "plug-in-whirl-pinch"
67
59
 
68
60
/***** Magic numbers *****/
69
61
 
70
62
#define SCALE_WIDTH  200
71
 
#define ENTRY_WIDTH  60
72
63
 
73
64
/***** Types *****/
74
65
 
77
68
  gdouble  whirl;
78
69
  gdouble  pinch;
79
70
  gdouble  radius;
80
 
  gboolean preview;
81
71
} whirl_pinch_vals_t;
82
72
 
83
73
/***** Prototypes *****/
104
94
 
105
95
/***** Variables *****/
106
96
 
107
 
GimpPlugInInfo PLUG_IN_INFO =
 
97
const GimpPlugInInfo PLUG_IN_INFO =
108
98
{
109
99
  NULL,   /* init_proc  */
110
100
  NULL,   /* quit_proc  */
116
106
{
117
107
  90.0, /* whirl   */
118
108
  0.0,  /* pinch   */
119
 
  1.0,  /* radius  */
120
 
  TRUE  /* preview */
 
109
  1.0   /* radius  */
121
110
};
122
111
 
123
112
static gint img_bpp, img_has_alpha;
135
124
static void
136
125
query (void)
137
126
{
138
 
  static GimpParamDef args[] =
 
127
  static const GimpParamDef args[] =
139
128
  {
140
 
    { GIMP_PDB_INT32,    "run_mode",  "Interactive, non-interactive" },
141
 
    { GIMP_PDB_IMAGE,    "image",     "Input image" },
142
 
    { GIMP_PDB_DRAWABLE, "drawable",  "Input drawable" },
143
 
    { GIMP_PDB_FLOAT,    "whirl",     "Whirl angle (degrees)" },
144
 
    { GIMP_PDB_FLOAT,    "pinch",     "Pinch amount" },
145
 
    { GIMP_PDB_FLOAT,    "radius",    "Radius (1.0 is the largest circle that fits in the image, "
146
 
      "and 2.0 goes all the way to the corners)" }
 
129
    { GIMP_PDB_INT32,    "run-mode",  "Interactive, non-interactive" },
 
130
    { GIMP_PDB_IMAGE,    "image",     "Input image"                  },
 
131
    { GIMP_PDB_DRAWABLE, "drawable",  "Input drawable"               },
 
132
    { GIMP_PDB_FLOAT,    "whirl",     "Whirl angle (degrees)"        },
 
133
    { GIMP_PDB_FLOAT,    "pinch",     "Pinch amount"                 },
 
134
    { GIMP_PDB_FLOAT,    "radius",    "Radius (1.0 is the largest circle that fits in the image, and 2.0 goes all the way to the corners)" }
147
135
  };
148
136
 
149
 
  gimp_install_procedure (PLUG_IN_NAME,
150
 
                          "Distort an image by whirling and pinching",
 
137
  gimp_install_procedure (PLUG_IN_PROC,
 
138
                          N_("Distort an image by whirling and pinching"),
151
139
                          "Distorts the image by whirling and pinching, which "
152
140
                          "are two common center-based, circular distortions.  "
153
141
                          "Whirling is like projecting the image onto the "
164
152
                          G_N_ELEMENTS (args), 0,
165
153
                          args, NULL);
166
154
 
167
 
  gimp_plugin_menu_register (PLUG_IN_NAME, "<Image>/Filters/Distorts");
 
155
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Distorts");
168
156
}
169
157
 
170
158
static void
198
186
  img_bpp       = gimp_drawable_bpp (drawable->drawable_id);
199
187
  img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
200
188
 
201
 
  gimp_drawable_mask_bounds (drawable->drawable_id,
202
 
                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);
 
189
  if (! gimp_drawable_mask_intersect (drawable->drawable_id,
 
190
                                      &sel_x1, &sel_y1, &sel_x2, &sel_y2))
 
191
    {
 
192
      g_message (_("Region affected by plug-in is empty"));
 
193
      return;
 
194
    }
203
195
 
204
196
      /* Set the tile cache size */
205
197
  gimp_tile_cache_ntiles (2 * drawable->ntile_cols);
239
231
    {
240
232
    case GIMP_RUN_INTERACTIVE:
241
233
      /* Possibly retrieve data */
242
 
      gimp_get_data (PLUG_IN_NAME, &wpvals);
 
234
      gimp_get_data (PLUG_IN_PROC, &wpvals);
243
235
 
244
236
      /* Get information from the dialog */
245
237
      if (!whirl_pinch_dialog (drawable))
264
256
 
265
257
    case GIMP_RUN_WITH_LAST_VALS:
266
258
      /* Possibly retrieve data */
267
 
      gimp_get_data (PLUG_IN_NAME, &wpvals);
 
259
      gimp_get_data (PLUG_IN_PROC, &wpvals);
268
260
      break;
269
261
 
270
262
    default:
287
279
      /* Store data */
288
280
 
289
281
      if (run_mode == GIMP_RUN_INTERACTIVE)
290
 
        gimp_set_data (PLUG_IN_NAME, &wpvals, sizeof (whirl_pinch_vals_t));
 
282
        gimp_set_data (PLUG_IN_PROC, &wpvals, sizeof (whirl_pinch_vals_t));
291
283
    }
292
284
  else if (status == GIMP_PDB_SUCCESS)
293
285
    status = GIMP_PDB_EXECUTION_ERROR;
345
337
  progress     = 0;
346
338
  max_progress = sel_width * sel_height;
347
339
 
348
 
  gimp_progress_init (_("Whirling and Pinching..."));
 
340
  gimp_progress_init (_("Whirling and pinching"));
349
341
 
350
342
  whirl   = wpvals.whirl * G_PI / 180;
351
343
  radius2 = radius * radius * wpvals.radius;
530
522
  GtkObject *adj;
531
523
  gboolean   run;
532
524
 
533
 
  gimp_ui_init ("whirlpinch", TRUE);
 
525
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
534
526
 
535
 
  dialog = gimp_dialog_new (_("Whirl and Pinch"), "whirlpinch",
 
527
  dialog = gimp_dialog_new (_("Whirl and Pinch"), PLUG_IN_BINARY,
536
528
                            NULL, 0,
537
 
                            gimp_standard_help_func, HELP_ID,
 
529
                            gimp_standard_help_func, PLUG_IN_PROC,
538
530
 
539
531
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
540
532
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
541
533
 
542
534
                            NULL);
543
535
 
 
536
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
537
                                           GTK_RESPONSE_OK,
 
538
                                           GTK_RESPONSE_CANCEL,
 
539
                                           -1);
 
540
 
 
541
  gimp_window_set_transient (GTK_WINDOW (dialog));
 
542
 
544
543
  main_vbox = gtk_vbox_new (FALSE, 12);
545
544
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
546
545
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
547
546
  gtk_widget_show (main_vbox);
548
547
 
549
 
  preview = gimp_aspect_preview_new (drawable, &wpvals.preview);
 
548
  preview = gimp_zoom_preview_new (drawable);
550
549
  gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
551
550
  gtk_widget_show (preview);
552
551
  g_signal_connect_swapped (preview, "invalidated",
565
564
                              wpvals.whirl, -360.0, 360.0, 1.0, 15.0, 2,
566
565
                              TRUE, 0, 0,
567
566
                              NULL, NULL);
568
 
  g_signal_connect (adj, "value_changed",
 
567
  g_signal_connect (adj, "value-changed",
569
568
                    G_CALLBACK (gimp_double_adjustment_update),
570
569
                    &wpvals.whirl);
571
 
  g_signal_connect_swapped (adj, "value_changed",
 
570
  g_signal_connect_swapped (adj, "value-changed",
572
571
                            G_CALLBACK (gimp_preview_invalidate),
573
572
                            preview);
574
573
 
577
576
                              wpvals.pinch, -1.0, 1.0, 0.01, 0.1, 3,
578
577
                              TRUE, 0, 0,
579
578
                              NULL, NULL);
580
 
  g_signal_connect (adj, "value_changed",
 
579
  g_signal_connect (adj, "value-changed",
581
580
                    G_CALLBACK (gimp_double_adjustment_update),
582
581
                    &wpvals.pinch);
583
 
  g_signal_connect_swapped (adj, "value_changed",
 
582
  g_signal_connect_swapped (adj, "value-changed",
584
583
                            G_CALLBACK (gimp_preview_invalidate),
585
584
                            preview);
586
585
 
589
588
                              wpvals.radius, 0.0, 2.0, 0.01, 0.1, 3,
590
589
                              TRUE, 0, 0,
591
590
                              NULL, NULL);
592
 
  g_signal_connect (adj, "value_changed",
 
591
  g_signal_connect (adj, "value-changed",
593
592
                    G_CALLBACK (gimp_double_adjustment_update),
594
593
                    &wpvals.radius);
595
 
  g_signal_connect_swapped (adj, "value_changed",
 
594
  g_signal_connect_swapped (adj, "value-changed",
596
595
                            G_CALLBACK (gimp_preview_invalidate),
597
596
                            preview);
598
597
 
631
630
  switch (img_bpp)
632
631
    {
633
632
    case 1:
634
 
      outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background);
 
633
      outside[0] = outside[1] = outside [2] = gimp_rgb_luminance_uchar (&background);
635
634
      outside[3] = 255;
636
635
      break;
637
636
 
638
637
    case 2:
639
 
      outside[0] = outside[1] = outside [2] = gimp_rgb_intensity_uchar (&background);
 
638
      outside[0] = outside[1] = outside [2] = gimp_rgb_luminance_uchar (&background);
640
639
      outside[3] = 0;
641
640
      break;
642
641
 
658
657
  bottom = sel_y2 - 1;
659
658
  top    = sel_y1;
660
659
 
661
 
  gimp_preview_get_size (preview, &width, &height);
662
 
  src = gimp_drawable_get_thumbnail_data (drawable->drawable_id,
663
 
                                          &width, &height, &img_bpp);
 
660
  src = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
 
661
                                      &width, &height, &img_bpp);
664
662
  dest = g_new (guchar, width * height * img_bpp);
665
663
 
666
664
  dx = (right - left) / (width - 1);
731
729
  g_free (src);
732
730
  g_free (dest);
733
731
}
734