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

« back to all changes in this revision

Viewing changes to app/tools/gimpthresholdtool.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
 * This program is free software; you can redistribute it and/or modify
27
27
#include "base/gimphistogram.h"
28
28
#include "base/threshold.h"
29
29
 
30
 
#include "config/gimpbaseconfig.h"
31
 
 
32
 
#include "core/gimp.h"
33
30
#include "core/gimpdrawable.h"
34
31
#include "core/gimpdrawable-histogram.h"
35
32
#include "core/gimpimage.h"
36
33
#include "core/gimpimagemap.h"
37
 
#include "core/gimptoolinfo.h"
38
34
 
39
35
#include "widgets/gimphelp-ids.h"
40
36
#include "widgets/gimphistogrambox.h"
41
37
#include "widgets/gimphistogramview.h"
42
 
#include "widgets/gimppropwidgets.h"
43
38
 
44
39
#include "display/gimpdisplay.h"
45
40
 
49
44
#include "gimp-intl.h"
50
45
 
51
46
 
52
 
#define LOW        0x1
53
 
#define HIGH       0x2
54
 
#define HISTOGRAM  0x4
55
 
#define ALL       (LOW | HIGH | HISTOGRAM)
56
 
 
57
 
 
58
47
/*  local function prototypes  */
59
48
 
60
 
static void     gimp_threshold_tool_class_init (GimpThresholdToolClass *klass);
61
 
static void     gimp_threshold_tool_init       (GimpThresholdTool      *threshold_tool);
62
 
 
63
 
static void     gimp_threshold_tool_finalize   (GObject          *object);
64
 
 
65
 
static gboolean gimp_threshold_tool_initialize (GimpTool         *tool,
66
 
                                                GimpDisplay      *gdisp);
67
 
 
68
 
static void     gimp_threshold_tool_map        (GimpImageMapTool *image_map_tool);
69
 
static void     gimp_threshold_tool_dialog     (GimpImageMapTool *image_map_tool);
70
 
static void     gimp_threshold_tool_reset      (GimpImageMapTool *image_map_tool);
 
49
static void     gimp_threshold_tool_finalize        (GObject           *object);
 
50
 
 
51
static gboolean gimp_threshold_tool_initialize      (GimpTool          *tool,
 
52
                                                     GimpDisplay       *display,
 
53
                                                     GError           **error);
 
54
 
 
55
static void     gimp_threshold_tool_map             (GimpImageMapTool  *im_tool);
 
56
static void     gimp_threshold_tool_dialog          (GimpImageMapTool  *im_tool);
 
57
static void     gimp_threshold_tool_reset           (GimpImageMapTool  *im_tool);
71
58
 
72
59
static void     gimp_threshold_tool_histogram_range (GimpHistogramView *view,
73
60
                                                     gint               start,
74
61
                                                     gint               end,
75
62
                                                     GimpThresholdTool *t_tool);
76
 
 
77
 
 
78
 
static GimpImageMapToolClass *parent_class = NULL;
79
 
 
80
 
 
81
 
/*  public functions  */
 
63
static void     gimp_threshold_tool_auto_clicked    (GtkWidget         *button,
 
64
                                                     GimpThresholdTool *t_tool);
 
65
 
 
66
 
 
67
G_DEFINE_TYPE (GimpThresholdTool, gimp_threshold_tool,
 
68
               GIMP_TYPE_IMAGE_MAP_TOOL)
 
69
 
 
70
#define parent_class gimp_threshold_tool_parent_class
 
71
 
82
72
 
83
73
void
84
74
gimp_threshold_tool_register (GimpToolRegisterCallback  callback,
90
80
                0,
91
81
                "gimp-threshold-tool",
92
82
                _("Threshold"),
93
 
                _("Reduce image to two colors using a threshold"),
 
83
                _("Threshold Tool: Reduce image to two colors using a threshold"),
94
84
                N_("_Threshold..."), NULL,
95
85
                NULL, GIMP_HELP_TOOL_THRESHOLD,
96
86
                GIMP_STOCK_TOOL_THRESHOLD,
97
87
                data);
98
88
}
99
89
 
100
 
GType
101
 
gimp_threshold_tool_get_type (void)
102
 
{
103
 
  static GType tool_type = 0;
104
 
 
105
 
  if (! tool_type)
106
 
    {
107
 
      static const GTypeInfo tool_info =
108
 
      {
109
 
        sizeof (GimpThresholdToolClass),
110
 
        (GBaseInitFunc) NULL,
111
 
        (GBaseFinalizeFunc) NULL,
112
 
        (GClassInitFunc) gimp_threshold_tool_class_init,
113
 
        NULL,           /* class_finalize */
114
 
        NULL,           /* class_data     */
115
 
        sizeof (GimpThresholdTool),
116
 
        0,              /* n_preallocs    */
117
 
        (GInstanceInitFunc) gimp_threshold_tool_init,
118
 
      };
119
 
 
120
 
      tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
121
 
                                          "GimpThresholdTool",
122
 
                                          &tool_info, 0);
123
 
    }
124
 
 
125
 
  return tool_type;
126
 
}
127
 
 
128
 
 
129
 
/*  private functions  */
130
 
 
131
90
static void
132
91
gimp_threshold_tool_class_init (GimpThresholdToolClass *klass)
133
92
{
134
 
  GObjectClass          *object_class;
135
 
  GimpToolClass         *tool_class;
136
 
  GimpImageMapToolClass *image_map_tool_class;
137
 
 
138
 
  object_class         = G_OBJECT_CLASS (klass);
139
 
  tool_class           = GIMP_TOOL_CLASS (klass);
140
 
  image_map_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
141
 
 
142
 
  parent_class = g_type_class_peek_parent (klass);
143
 
 
144
 
  object_class->finalize       = gimp_threshold_tool_finalize;
145
 
 
146
 
  tool_class->initialize       = gimp_threshold_tool_initialize;
147
 
 
148
 
  image_map_tool_class->shell_desc = _("Apply Threshold");
149
 
 
150
 
  image_map_tool_class->map    = gimp_threshold_tool_map;
151
 
  image_map_tool_class->dialog = gimp_threshold_tool_dialog;
152
 
  image_map_tool_class->reset  = gimp_threshold_tool_reset;
 
93
  GObjectClass          *object_class  = G_OBJECT_CLASS (klass);
 
94
  GimpToolClass         *tool_class    = GIMP_TOOL_CLASS (klass);
 
95
  GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
 
96
 
 
97
  object_class->finalize    = gimp_threshold_tool_finalize;
 
98
 
 
99
  tool_class->initialize    = gimp_threshold_tool_initialize;
 
100
 
 
101
  im_tool_class->shell_desc = _("Apply Threshold");
 
102
 
 
103
  im_tool_class->map        = gimp_threshold_tool_map;
 
104
  im_tool_class->dialog     = gimp_threshold_tool_dialog;
 
105
  im_tool_class->reset      = gimp_threshold_tool_reset;
153
106
}
154
107
 
155
108
static void
183
136
}
184
137
 
185
138
static gboolean
186
 
gimp_threshold_tool_initialize (GimpTool    *tool,
187
 
                                GimpDisplay *gdisp)
 
139
gimp_threshold_tool_initialize (GimpTool     *tool,
 
140
                                GimpDisplay  *display,
 
141
                                GError      **error)
188
142
{
189
143
  GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (tool);
190
144
  GimpDrawable      *drawable;
191
145
 
192
 
  drawable = gimp_image_active_drawable (gdisp->gimage);
 
146
  drawable = gimp_image_active_drawable (display->image);
193
147
 
194
148
  if (! drawable)
195
149
    return FALSE;
196
150
 
197
151
  if (gimp_drawable_is_indexed (drawable))
198
152
    {
199
 
      g_message (_("Threshold does not operate on indexed layers."));
 
153
      g_set_error (error, 0, 0,
 
154
                   _("Threshold does not operate on indexed layers."));
200
155
      return FALSE;
201
156
    }
202
157
 
203
158
  if (!t_tool->hist)
204
 
    {
205
 
      Gimp *gimp = GIMP_TOOL (t_tool)->tool_info->gimp;
206
 
 
207
 
      t_tool->hist = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
208
 
    }
 
159
    t_tool->hist = gimp_histogram_new ();
209
160
 
210
161
  t_tool->threshold->color          = gimp_drawable_is_rgb (drawable);
211
162
  t_tool->threshold->low_threshold  = 127;
212
163
  t_tool->threshold->high_threshold = 255;
213
164
 
214
 
  GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
 
165
  GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
215
166
 
216
167
  gimp_drawable_calculate_histogram (drawable, t_tool->hist);
217
168
 
238
189
  GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
239
190
 
240
191
  gimp_image_map_apply (image_map_tool->image_map,
241
 
                        threshold,
 
192
                        (GimpImageMapApplyFunc) threshold,
242
193
                        t_tool->threshold);
243
194
}
244
195
 
250
201
static void
251
202
gimp_threshold_tool_dialog (GimpImageMapTool *image_map_tool)
252
203
{
253
 
  GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
254
 
  GimpToolOptions   *tool_options;
 
204
  GimpThresholdTool *t_tool       = GIMP_THRESHOLD_TOOL (image_map_tool);
 
205
  GimpToolOptions   *tool_options = GIMP_TOOL_GET_OPTIONS (image_map_tool);
255
206
  GtkWidget         *vbox;
256
207
  GtkWidget         *hbox;
257
208
  GtkWidget         *menu;
258
209
  GtkWidget         *box;
259
 
 
260
 
  tool_options = GIMP_TOOL (t_tool)->tool_info->tool_options;
 
210
  GtkWidget         *button;
261
211
 
262
212
  vbox = image_map_tool->main_vbox;
263
213
 
277
227
 
278
228
  t_tool->histogram_box = GIMP_HISTOGRAM_BOX (box);
279
229
 
280
 
  g_signal_connect (t_tool->histogram_box->view, "range_changed",
 
230
  g_signal_connect (t_tool->histogram_box->view, "range-changed",
281
231
                    G_CALLBACK (gimp_threshold_tool_histogram_range),
282
232
                    t_tool);
283
233
 
284
234
  gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
285
235
                                       t_tool->histogram_box->view);
 
236
 
 
237
  hbox = gtk_hbox_new (FALSE, 6);
 
238
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
 
239
  gtk_widget_show (hbox);
 
240
 
 
241
  button = gtk_button_new_with_mnemonic (_("_Auto"));
 
242
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
243
  gimp_help_set_help_data (button, _("Automatically adjust to optimal "
 
244
                                     "binarization threshold"), NULL);
 
245
  gtk_widget_show (button);
 
246
 
 
247
  g_signal_connect (button, "clicked",
 
248
                    G_CALLBACK (gimp_threshold_tool_auto_clicked),
 
249
                    t_tool);
286
250
}
287
251
 
288
252
static void
290
254
{
291
255
  GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool);
292
256
 
293
 
  t_tool->threshold->low_threshold  = 127.0;
294
 
  t_tool->threshold->high_threshold = 255.0;
295
 
 
296
 
  gimp_histogram_view_set_range (t_tool->histogram_box->view,
297
 
                                 t_tool->threshold->low_threshold,
298
 
                                 t_tool->threshold->high_threshold);
 
257
  gimp_histogram_view_set_range (t_tool->histogram_box->view, 127.0, 255.0);
299
258
}
300
259
 
301
260
static void
313
272
      gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (t_tool));
314
273
    }
315
274
}
 
275
 
 
276
static void
 
277
gimp_threshold_tool_auto_clicked (GtkWidget         *button,
 
278
                                  GimpThresholdTool *t_tool)
 
279
{
 
280
  gdouble low_threshold;
 
281
 
 
282
  low_threshold =
 
283
    gimp_histogram_get_threshold (t_tool->hist,
 
284
                                  (t_tool->threshold->color ?
 
285
                                   GIMP_HISTOGRAM_RGB : GIMP_HISTOGRAM_VALUE),
 
286
                                  0, 255);
 
287
 
 
288
  gimp_histogram_view_set_range (t_tool->histogram_box->view,
 
289
                                 low_threshold, 255.0);
 
290
}