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

« back to all changes in this revision

Viewing changes to plug-ins/common/colortoalpha.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:
3
3
 *  with algorithm by clahey
4
4
 */
5
5
 
6
 
/* The GIMP -- an image manipulation program
 
6
/* GIMP - The GNU Image Manipulation Program
7
7
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or modify
23
23
 
24
24
#include "config.h"
25
25
 
26
 
#include <stdio.h>
27
 
#include <stdlib.h>
28
 
 
29
26
#include <libgimp/gimp.h>
30
27
#include <libgimp/gimpui.h>
31
28
 
32
29
#include "libgimp/stdplugins-intl.h"
33
30
 
34
31
 
35
 
#define PRV_WIDTH  40
36
 
#define PRV_HEIGHT 20
 
32
#define PLUG_IN_PROC   "plug-in-colortoalpha"
 
33
#define PLUG_IN_BINARY "colortoaplha"
 
34
#define PRV_WIDTH      40
 
35
#define PRV_HEIGHT     20
37
36
 
38
37
 
39
38
typedef struct
52
51
                                           gint              *nreturn_vals,
53
52
                                           GimpParam        **return_vals);
54
53
 
55
 
static void inline color_to_alpha         (GimpRGB           *src,
 
54
static inline void color_to_alpha         (GimpRGB           *src,
56
55
                                           const GimpRGB     *color);
57
56
static void        to_alpha_func          (const guchar      *src,
58
57
                                           guchar            *dest,
65
64
                                           GimpDrawable      *drawable);
66
65
 
67
66
 
68
 
GimpPlugInInfo PLUG_IN_INFO =
 
67
const GimpPlugInInfo PLUG_IN_INFO =
69
68
{
70
69
  NULL,  /* init_proc  */
71
70
  NULL,  /* quit_proc  */
85
84
static void
86
85
query (void)
87
86
{
88
 
  static GimpParamDef args[] =
 
87
  static const GimpParamDef args[] =
89
88
  {
90
 
    { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive" },
91
 
    { GIMP_PDB_IMAGE,    "image",    "Input image (unused)" },
92
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
93
 
    { GIMP_PDB_COLOR,    "color",    "Color to remove" }
 
89
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive" },
 
90
    { GIMP_PDB_IMAGE,    "image",    "Input image (unused)"         },
 
91
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"               },
 
92
    { GIMP_PDB_COLOR,    "color",    "Color to remove"              }
94
93
  };
95
94
 
96
 
  gimp_install_procedure ("plug_in_colortoalpha",
97
 
                          "Convert the color in an image to alpha",
 
95
  gimp_install_procedure (PLUG_IN_PROC,
 
96
                          N_("Convert a specified color to transparency"),
98
97
                          "This replaces as much of a given color as possible "
99
98
                          "in each pixel with a corresponding amount of alpha, "
100
99
                          "then readjusts the color accordingly.",
107
106
                          G_N_ELEMENTS (args), 0,
108
107
                          args, NULL);
109
108
 
110
 
  gimp_plugin_menu_register ("plug_in_colortoalpha",
111
 
                             "<Image>/Filters/Colors");
112
 
  gimp_plugin_menu_register ("plug_in_colortoalpha",
 
109
  gimp_plugin_menu_register (PLUG_IN_PROC,
 
110
                             "<Image>/Colors/Modify");
 
111
  gimp_plugin_menu_register (PLUG_IN_PROC,
113
112
                             "<Image>/Layer/Transparency/Modify");
114
113
}
115
114
 
142
141
  switch (run_mode)
143
142
    {
144
143
    case GIMP_RUN_INTERACTIVE:
145
 
      gimp_get_data ("plug_in_colortoalpha", &pvals);
 
144
      gimp_get_data (PLUG_IN_PROC, &pvals);
146
145
      if (! color_to_alpha_dialog (drawable))
147
146
        {
148
147
          gimp_drawable_detach (drawable);
159
158
      break;
160
159
 
161
160
    case GIMP_RUN_WITH_LAST_VALS:
162
 
      gimp_get_data ("plug_in_colortoalpha", &pvals);
 
161
      gimp_get_data (PLUG_IN_PROC, &pvals);
163
162
      break;
164
163
 
165
164
    default:
170
169
      gimp_drawable_is_rgb (drawable->drawable_id) &&
171
170
      gimp_drawable_is_layer (drawable->drawable_id))
172
171
    {
173
 
      gboolean preserve_trans;
 
172
      gboolean lock_alpha;
174
173
 
175
174
      gimp_image_undo_group_start (image_ID);
176
175
 
180
179
      /*  Reget the drawable, bpp might have changed  */
181
180
      drawable = gimp_drawable_get (drawable->drawable_id);
182
181
 
183
 
      /*  Unset 'Keep transparency'  */
184
 
      preserve_trans = gimp_layer_get_preserve_trans (drawable->drawable_id);
185
 
      gimp_layer_set_preserve_trans (drawable->drawable_id, FALSE);
 
182
      /*  Unset 'Lock alpha'  */
 
183
      lock_alpha = gimp_layer_get_lock_alpha (drawable->drawable_id);
 
184
      gimp_layer_set_lock_alpha (drawable->drawable_id, FALSE);
186
185
 
187
 
      gimp_progress_init (_("Removing color..."));
 
186
      gimp_progress_init (_("Removing color"));
188
187
      gimp_rgn_iterate2 (drawable, 0 /* unused */, to_alpha_func, NULL);
189
188
 
190
 
      gimp_layer_set_preserve_trans (drawable->drawable_id, preserve_trans);
 
189
      gimp_layer_set_lock_alpha (drawable->drawable_id, lock_alpha);
191
190
 
192
191
      gimp_image_undo_group_end (image_ID);
193
192
 
198
197
  gimp_drawable_detach (drawable);
199
198
 
200
199
  if (run_mode == GIMP_RUN_INTERACTIVE)
201
 
    gimp_set_data ("plug_in_colortoalpha", &pvals, sizeof (pvals));
 
200
    gimp_set_data (PLUG_IN_PROC, &pvals, sizeof (pvals));
202
201
 
203
202
  values[0].data.d_status = status;
204
203
}
375
374
  GtkWidget *label;
376
375
  gboolean   run;
377
376
 
378
 
  gimp_ui_init ("colortoalpha", TRUE);
 
377
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
379
378
 
380
 
  dialog = gimp_dialog_new (_("Color to Alpha"), "colortoalpha",
 
379
  dialog = gimp_dialog_new (_("Color to Alpha"), PLUG_IN_BINARY,
381
380
                            NULL, 0,
382
 
                            gimp_standard_help_func, "plug-in-colortoalpha",
 
381
                            gimp_standard_help_func, PLUG_IN_PROC,
383
382
 
384
383
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
385
384
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
386
385
 
387
386
                            NULL);
388
387
 
 
388
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
389
                                           GTK_RESPONSE_OK,
 
390
                                           GTK_RESPONSE_CANCEL,
 
391
                                           -1);
 
392
 
 
393
  gimp_window_set_transient (GTK_WINDOW (dialog));
 
394
 
389
395
  main_vbox = gtk_vbox_new (FALSE, 12);
390
396
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
391
397
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
410
416
                                  PRV_WIDTH, PRV_HEIGHT,
411
417
                                  &pvals.color,
412
418
                                  GIMP_COLOR_AREA_FLAT);
 
419
  gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
413
420
  gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
414
421
  gtk_widget_show (button);
415
422
 
416
 
  g_signal_connect (button, "color_changed",
 
423
  g_signal_connect (button, "color-changed",
417
424
                    G_CALLBACK (gimp_color_button_get_color),
418
425
                    &pvals.color);
419
 
  g_signal_connect_swapped (button, "color_changed",
 
426
  g_signal_connect_swapped (button, "color-changed",
420
427
                            G_CALLBACK (gimp_preview_invalidate),
421
428
                            preview);
422
429