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

« back to all changes in this revision

Viewing changes to plug-ins/common/exchange.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:
37
37
 
38
38
#include "config.h"
39
39
 
40
 
#include <stdio.h>
41
 
#include <stdlib.h>
42
 
#include <string.h>
43
 
 
44
 
#include <gtk/gtk.h>
45
 
 
46
40
#include <libgimp/gimp.h>
47
41
#include <libgimp/gimpui.h>
48
42
 
49
43
#include "libgimp/stdplugins-intl.h"
50
44
 
51
45
 
52
 
#define SCALE_WIDTH  128
53
 
#define PREVIEW_SIZE 128
 
46
#define PLUG_IN_PROC   "plug-in-exchange"
 
47
#define PLUG_IN_BINARY "exchange"
 
48
 
 
49
#define SCALE_WIDTH    128
 
50
 
54
51
 
55
52
/* datastructure to store parameters in */
56
53
typedef struct
92
89
static gboolean      lock_threshold = FALSE;
93
90
 
94
91
/* lets declare what we want to do */
95
 
GimpPlugInInfo PLUG_IN_INFO =
 
92
const GimpPlugInInfo PLUG_IN_INFO =
96
93
{
97
94
  NULL,  /* init_proc  */
98
95
  NULL,  /* quit_proc  */
107
104
static void
108
105
query (void)
109
106
{
110
 
  static GimpParamDef args[] =
 
107
  static const GimpParamDef args[] =
111
108
  {
112
 
    { GIMP_PDB_INT32, "run_mode", "Interactive" },
113
 
    { GIMP_PDB_IMAGE, "image", "Input image" },
114
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
115
 
    { GIMP_PDB_INT8, "fromred", "Red value (from)" },
116
 
    { GIMP_PDB_INT8, "fromgreen", "Green value (from)" },
117
 
    { GIMP_PDB_INT8, "fromblue", "Blue value (from)" },
118
 
    { GIMP_PDB_INT8, "tored", "Red value (to)" },
119
 
    { GIMP_PDB_INT8, "togreen", "Green value (to)" },
120
 
    { GIMP_PDB_INT8, "toblue", "Blue value (to)" },
121
 
    { GIMP_PDB_INT8, "red_threshold", "Red threshold" },
122
 
    { GIMP_PDB_INT8, "green_threshold", "Green threshold" },
123
 
    { GIMP_PDB_INT8, "blue_threshold", "Blue threshold" }
 
109
    { GIMP_PDB_INT32,    "run-mode",        "Interactive"        },
 
110
    { GIMP_PDB_IMAGE,    "image",           "Input image"        },
 
111
    { GIMP_PDB_DRAWABLE, "drawable",        "Input drawable"     },
 
112
    { GIMP_PDB_INT8,     "from-red",        "Red value (from)"   },
 
113
    { GIMP_PDB_INT8,     "from-green",      "Green value (from)" },
 
114
    { GIMP_PDB_INT8,     "from-blue",       "Blue value (from)"  },
 
115
    { GIMP_PDB_INT8,     "to-red",          "Red value (to)"     },
 
116
    { GIMP_PDB_INT8,     "to-green",        "Green value (to)"   },
 
117
    { GIMP_PDB_INT8,     "to-blue",         "Blue value (to)"    },
 
118
    { GIMP_PDB_INT8,     "red-threshold",   "Red threshold"      },
 
119
    { GIMP_PDB_INT8,     "green-threshold", "Green threshold"    },
 
120
    { GIMP_PDB_INT8,     "blue-threshold",  "Blue threshold"     }
124
121
  };
125
122
 
126
 
  gimp_install_procedure ("plug_in_exchange",
127
 
                          "Color Exchange",
 
123
  gimp_install_procedure (PLUG_IN_PROC,
 
124
                          N_("Swap one color with another"),
128
125
                          "Exchange one color with another, optionally setting a threshold "
129
126
                          "to convert from one shade to another",
130
127
                          "robert@experimental.net",
136
133
                          G_N_ELEMENTS (args), 0,
137
134
                          args, NULL);
138
135
 
139
 
  gimp_plugin_menu_register ("plug_in_exchange", "<Image>/Filters/Colors/Map");
 
136
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Map");
140
137
}
141
138
 
142
139
/* main function */
167
164
    {
168
165
    case GIMP_RUN_INTERACTIVE:
169
166
      /* retrieve stored arguments (if any) */
170
 
      gimp_get_data ("plug_in_exchange", &xargs);
 
167
      gimp_get_data (PLUG_IN_PROC, &xargs);
171
168
      /* initialize using foreground color */
172
169
      gimp_context_get_foreground (&xargs.from);
173
170
 
176
173
      break;
177
174
 
178
175
    case GIMP_RUN_WITH_LAST_VALS:
179
 
      gimp_get_data ("plug_in_exchange", &xargs);
 
176
      gimp_get_data (PLUG_IN_PROC, &xargs);
180
177
      /*
181
178
       * instead of recalling the last-set values,
182
179
       * run with the current foreground as 'from'
215
212
    {
216
213
      if (gimp_drawable_is_rgb (drawable->drawable_id))
217
214
        {
218
 
          gimp_progress_init (_("Color Exchange..."));
 
215
          gimp_progress_init (_("Color Exchange"));
219
216
          gimp_tile_cache_ntiles (2 * (drawable->width /
220
217
                                       gimp_tile_width () + 1));
221
218
          exchange (drawable, NULL);
223
220
 
224
221
          /* store our settings */
225
222
          if (runmode == GIMP_RUN_INTERACTIVE)
226
 
            gimp_set_data ("plug_in_exchange", &xargs, sizeof (myParams));
 
223
            gimp_set_data (PLUG_IN_PROC, &xargs, sizeof (myParams));
227
224
 
228
225
          /* and flush */
229
226
          if (runmode != GIMP_RUN_NONINTERACTIVE)
287
284
  gint          framenumber;
288
285
  gboolean      run;
289
286
 
290
 
  gimp_ui_init ("exchange", TRUE);
 
287
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
291
288
 
292
 
  /* set up the dialog */
293
 
  dialog = gimp_dialog_new (_("Color Exchange"), "exchange",
 
289
  dialog = gimp_dialog_new (_("Color Exchange"), PLUG_IN_BINARY,
294
290
                            NULL, 0,
295
 
                            gimp_standard_help_func, "plug-in-exchange",
 
291
                            gimp_standard_help_func, PLUG_IN_PROC,
296
292
 
297
293
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
298
294
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
299
295
 
300
296
                            NULL);
301
297
 
 
298
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
299
                                           GTK_RESPONSE_OK,
 
300
                                           GTK_RESPONSE_CANCEL,
 
301
                                           -1);
 
302
 
 
303
  gimp_window_set_transient (GTK_WINDOW (dialog));
 
304
 
302
305
  /* do some boxes here */
303
306
  main_vbox = gtk_vbox_new (FALSE, 12);
304
307
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
305
308
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
306
309
  gtk_widget_show (main_vbox);
307
310
 
308
 
  frame = gimp_frame_new (_("Middle-click inside preview to pick \"From Color\""));
 
311
  frame = gimp_frame_new (_("Middle-Click Inside Preview to Pick \"From Color\""));
309
312
  gtk_box_pack_start_defaults (GTK_BOX (main_vbox), frame);
310
313
  gtk_widget_show (frame);
311
314
 
325
328
                                     &xargs.threshold,
326
329
                                     GIMP_COLOR_AREA_FLAT);
327
330
 
328
 
  g_signal_connect (threshold, "color_changed",
 
331
  g_signal_connect (threshold, "color-changed",
329
332
                    G_CALLBACK (gimp_color_button_get_color),
330
333
                    &xargs.threshold);
331
 
  g_signal_connect (threshold, "color_changed",
 
334
  g_signal_connect (threshold, "color-changed",
332
335
                    G_CALLBACK (color_button_callback),
333
336
                    &xargs.threshold);
334
 
  g_signal_connect_swapped (threshold, "color_changed",
 
337
  g_signal_connect_swapped (threshold, "color-changed",
335
338
                            G_CALLBACK (gimp_preview_invalidate),
336
339
                            preview);
337
340
 
371
374
                                 NULL, 0.0, 0.0,
372
375
                                 colorbutton, 1, FALSE);
373
376
 
374
 
      g_signal_connect (colorbutton, "color_changed",
 
377
      g_signal_connect (colorbutton, "color-changed",
375
378
                        G_CALLBACK (gimp_color_button_get_color),
376
379
                        framenumber ? &xargs.to : &xargs.from);
377
 
      g_signal_connect (colorbutton, "color_changed",
 
380
      g_signal_connect (colorbutton, "color-changed",
378
381
                        G_CALLBACK (color_button_callback),
379
382
                        framenumber ? &xargs.to : &xargs.from);
380
 
      g_signal_connect_swapped (colorbutton, "color_changed",
 
383
      g_signal_connect_swapped (colorbutton, "color-changed",
381
384
                                G_CALLBACK (gimp_preview_invalidate),
382
385
                                preview);
383
386
 
403
406
      g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
404
407
      g_object_set_data (G_OBJECT (colorbutton), "red", adj);
405
408
 
406
 
      g_signal_connect (adj, "value_changed",
 
409
      g_signal_connect (adj, "value-changed",
407
410
                        G_CALLBACK (gimp_double_adjustment_update),
408
411
                        framenumber ? &xargs.to.r : &xargs.from.r);
409
 
      g_signal_connect (adj, "value_changed",
 
412
      g_signal_connect (adj, "value-changed",
410
413
                        G_CALLBACK (scale_callback),
411
414
                        framenumber ? &xargs.to : &xargs.from);
412
 
      g_signal_connect_swapped (adj, "value_changed",
 
415
      g_signal_connect_swapped (adj, "value-changed",
413
416
                                G_CALLBACK (gimp_preview_invalidate),
414
417
                                preview);
415
418
 
429
432
          g_object_set_data (G_OBJECT (adj), "colorbutton", threshold);
430
433
          g_object_set_data (G_OBJECT (threshold), "red", adj);
431
434
 
432
 
          g_signal_connect (adj, "value_changed",
 
435
          g_signal_connect (adj, "value-changed",
433
436
                            G_CALLBACK (gimp_double_adjustment_update),
434
437
                            &xargs.threshold.r);
435
 
          g_signal_connect (adj, "value_changed",
 
438
          g_signal_connect (adj, "value-changed",
436
439
                            G_CALLBACK (scale_callback),
437
440
                            &xargs.threshold);
438
 
          g_signal_connect_swapped (adj, "value_changed",
 
441
          g_signal_connect_swapped (adj, "value-changed",
439
442
                                    G_CALLBACK (gimp_preview_invalidate),
440
443
                                    preview);
441
444
 
463
466
      g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
464
467
      g_object_set_data (G_OBJECT (colorbutton), "green", adj);
465
468
 
466
 
      g_signal_connect (adj, "value_changed",
 
469
      g_signal_connect (adj, "value-changed",
467
470
                        G_CALLBACK (gimp_double_adjustment_update),
468
471
                        framenumber ? &xargs.to.g : &xargs.from.g);
469
 
      g_signal_connect (adj, "value_changed",
 
472
      g_signal_connect (adj, "value-changed",
470
473
                        G_CALLBACK (scale_callback),
471
474
                        framenumber ? &xargs.to : &xargs.from);
472
 
      g_signal_connect_swapped (adj, "value_changed",
 
475
      g_signal_connect_swapped (adj, "value-changed",
473
476
                                G_CALLBACK (gimp_preview_invalidate),
474
477
                                preview);
475
478
 
476
 
 
477
479
      scale = GTK_WIDGET (GIMP_SCALE_ENTRY_SCALE (adj));
478
480
      gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
479
481
      gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (adj));
490
492
          g_object_set_data (G_OBJECT (adj), "colorbutton", threshold);
491
493
          g_object_set_data (G_OBJECT (threshold), "green", adj);
492
494
 
493
 
          g_signal_connect (adj, "value_changed",
 
495
          g_signal_connect (adj, "value-changed",
494
496
                            G_CALLBACK (gimp_double_adjustment_update),
495
497
                            &xargs.threshold.g);
496
 
          g_signal_connect (adj, "value_changed",
 
498
          g_signal_connect (adj, "value-changed",
497
499
                            G_CALLBACK (scale_callback),
498
500
                            &xargs.threshold);
499
 
          g_signal_connect_swapped (adj, "value_changed",
 
501
          g_signal_connect_swapped (adj, "value-changed",
500
502
                                    G_CALLBACK (gimp_preview_invalidate),
501
503
                                    preview);
502
504
 
525
527
      g_object_set_data (G_OBJECT (adj), "colorbutton", colorbutton);
526
528
      g_object_set_data (G_OBJECT (colorbutton), "blue", adj);
527
529
 
528
 
      g_signal_connect (adj, "value_changed",
 
530
      g_signal_connect (adj, "value-changed",
529
531
                        G_CALLBACK (gimp_double_adjustment_update),
530
532
                        framenumber ? &xargs.to.b : &xargs.from.b);
531
 
      g_signal_connect (adj, "value_changed",
 
533
      g_signal_connect (adj, "value-changed",
532
534
                        G_CALLBACK (scale_callback),
533
535
                        framenumber ? &xargs.to : &xargs.from);
534
 
      g_signal_connect_swapped (adj, "value_changed",
 
536
      g_signal_connect_swapped (adj, "value-changed",
535
537
                                G_CALLBACK (gimp_preview_invalidate),
536
538
                                preview);
537
539
 
551
553
          g_object_set_data (G_OBJECT (adj), "colorbutton", threshold);
552
554
          g_object_set_data (G_OBJECT (threshold), "blue", adj);
553
555
 
554
 
          g_signal_connect (adj, "value_changed",
 
556
          g_signal_connect (adj, "value-changed",
555
557
                            G_CALLBACK (gimp_double_adjustment_update),
556
558
                            &xargs.threshold.b);
557
 
          g_signal_connect (adj, "value_changed",
 
559
          g_signal_connect (adj, "value-changed",
558
560
                            G_CALLBACK (scale_callback),
559
561
                            &xargs.threshold);
560
 
          g_signal_connect_swapped (adj, "value_changed",
 
562
          g_signal_connect_swapped (adj, "value-changed",
561
563
                                    G_CALLBACK (gimp_preview_invalidate),
562
564
                                    preview);
563
565
 
652
654
  guchar        from_red, from_green, from_blue;
653
655
  guchar        to_red,   to_green,   to_blue;
654
656
  guchar       *src_row, *dest_row;
655
 
  guint         x, y, bpp = drawable->bpp;
 
657
  gint          x, y, bpp = drawable->bpp;
656
658
  gboolean      has_alpha;
657
659
  gint          x1, y1, x2, y2;
658
 
  guint         width, height;
 
660
  gint          width, height;
659
661
  GimpRGB       min;
660
662
  GimpRGB       max;
661
663
 
703
705
  for (y = y1; y < y2; y++)
704
706
    {
705
707
      gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y, width);
 
708
 
706
709
      for (x = 0; x < width; x++)
707
710
        {
708
711
          guchar pixel_red, pixel_green, pixel_blue;
732
735
                pixel_green - from_green : from_green - pixel_green;
733
736
              blue_delta  = pixel_blue > from_blue ?
734
737
                pixel_blue - from_blue : from_blue - pixel_blue;
 
738
 
735
739
              new_red   = CLAMP (to_red   + red_delta,   0, 255);
736
740
              new_green = CLAMP (to_green + green_delta, 0, 255);
737
741
              new_blue  = CLAMP (to_blue  + blue_delta,  0, 255);
760
764
        gimp_progress_update ((gdouble) y / (gdouble) height);
761
765
    }
762
766
 
763
 
  g_free(src_row);
764
 
  g_free(dest_row);
 
767
  g_free (src_row);
 
768
  g_free (dest_row);
765
769
 
766
770
  if (preview)
767
771
    {